ATLAS Offline Software
IAnalysisTools.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "AnalysisUtils/AnalysisMisc.h"
6 
7 #include "GaudiKernel/MsgStream.h"
8 #include "AthContainers/OwnershipPolicy.h"
9 
10 inline double IAnalysisTools::deltaPhi (const INavigable4Momentum *p1, const INavigable4Momentum *p2) const
11 {
12  return AnalysisUtils::Delta::phi(p1,p2);
13 }
14 
15 inline double IAnalysisTools::deltaR (const INavigable4Momentum *p1, const INavigable4Momentum *p2) const
16 {
17  return AnalysisUtils::Delta::R(p1,p2);
18 }
19 
20 inline double IAnalysisTools::imass2 (const INavigable4Momentum *p1, const INavigable4Momentum *p2) const
21 {
22  return AnalysisUtils::Imass::two(p1,p2);
23 }
24 
25 inline double IAnalysisTools::imass4 (const INavigable4Momentum *p1, const INavigable4Momentum *p2,
26  const INavigable4Momentum *p3, const INavigable4Momentum *p4) const
27 {
28  return AnalysisUtils::Imass::four(p1,p2,p3,p4);
29 }
30 
31 template <class COLL> inline bool IAnalysisTools::matchR
32 (const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR) const
33 {
34  return AnalysisUtils::Match::R(t,coll,index,deltaR);
35 }
36 
37 template <class COLL> inline bool IAnalysisTools::matchR
38 (const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR, double &deltaE) const
39 {
40  return AnalysisUtils::Match::R(t,coll,index,deltaR, deltaE);
41 }
42 
43 template <class COLL> inline bool IAnalysisTools::matchR
44 (const double eta, const double phi, COLL *coll, int &index, double &deltaR) const
45 {
46  return AnalysisUtils::Match::R(eta,phi,coll,index,deltaR);
47 }
48 
49 template <class COLL> inline bool IAnalysisTools::matchR
50 (const double eta, const double phi, const double e, COLL *coll, int &index,
51  double &deltaR, double &deltaE) const
52 {
53  return AnalysisUtils::Match::R(eta,phi,e,coll,index,deltaR,deltaE);
54 }
55 
56 template <class COLL, class ELEMENT > inline bool IAnalysisTools::matchR
57 (const INavigable4Momentum *t, COLL *coll, ELEMENT *&element, double &deltaR) const
58 {
59  int index = 0;
60  bool ret = AnalysisUtils::Match::R(t,coll,index,deltaR);
61  if (!ret) return false;
62  element = (*coll)[index];
63  return true;
64 }
65 
66 template <class COLL, class ELEMENT > inline bool IAnalysisTools::matchR
67 (const INavigable4Momentum *t, COLL *coll, ELEMENT *&element, double &deltaR, double &deltaE) const
68 {
69  int index = 0;
70  bool ret = AnalysisUtils::Match::R(t,coll,index,deltaR, deltaE);
71  if (!ret) return false;
72  element = (*coll)[index];
73  return true;
74 }
75 
76 template <class COLL, class ELEMENT > inline bool IAnalysisTools::matchR
77 (const double eta, const double phi, COLL *coll, ELEMENT *&element, double &deltaR) const
78 {
79  int index = 0;
80  bool ret = AnalysisUtils::Match::R(eta,phi,coll,index,deltaR);
81  if (!ret) return false;
82  element = (*coll)[index];
83  return true;
84 }
85 
86 template <class COLL, class ELEMENT > inline bool IAnalysisTools::matchR
87 (const double eta, const double phi, const double e, COLL *coll, ELEMENT *&element,
88  double &deltaR, double &deltaE) const
89 {
90  int index = 0;
91  bool ret = AnalysisUtils::Match::R(eta,phi,e, coll,index,deltaR, deltaE);
92  if (!ret) return false;
93  element = (*coll)[index];
94  return true;
95 }
96 
97 template <class COLL> inline bool IAnalysisTools::matchR
98 (const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR, int pdg) const
99 {
100  return AnalysisUtils::Match::R(t,coll,index,deltaR,pdg);
101 }
102 
103 template <class COLL> inline bool IAnalysisTools::matchR
104 (const double eta, const double phi, COLL *coll, int &index, double &deltaR, int pdg) const
105 {
106  return AnalysisUtils::Match::R(eta,phi,coll,index,deltaR,pdg);
107 }
108 
109 template <class COLL> inline bool IAnalysisTools::matchR
110 (const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR, int pdg, double &deltaE) const
111 {
112  return AnalysisUtils::Match::R(t,coll,index,deltaR,pdg,deltaE);
113 }
114 
115 template <class COLL> inline bool IAnalysisTools::matchR
116 (const double eta, const double phi, const double e, COLL *coll, int &index, double &deltaR,
117  int pdg, double &deltaE) const
118 {
119  return AnalysisUtils::Match::R(eta,phi,e,coll,index,deltaR,pdg,deltaE);
120 }
121 
122 template <class COLL, class ELEMENT> inline bool IAnalysisTools::matchR
123 (const INavigable4Momentum *t, COLL *coll, ELEMENT *&element, double &deltaR, int pdg) const
124 {
125  int index = 0;
126  bool ret = AnalysisUtils::Match::R(t,coll,index,deltaR,pdg);
127  if (!ret) return false;
128  element = (*coll)[index];
129  return true;
130 }
131 
132 template <class COLL, class ELEMENT> inline bool IAnalysisTools::matchR
133 (const INavigable4Momentum *t, COLL *coll, ELEMENT *&element, double &deltaR, int pdg, double &deltaE) const
134 {
135  int index = 0;
136  bool ret = AnalysisUtils::Match::R(t,coll,index,deltaR,pdg,deltaE);
137  if (!ret) return false;
138  element = (*coll)[index];
139  return true;
140 }
141 
142 template <class COLL, class ELEMENT> inline bool IAnalysisTools::matchR
143 (const double eta, const double phi, COLL *coll, ELEMENT *&element, double &deltaR, int pdg) const
144 {
145  int index = 0;
146  bool ret = AnalysisUtils::Match::R(eta,phi,coll,index,deltaR,pdg);
147  if (!ret) return false;
148  element = (*coll)[index];
149  return true;
150 }
151 
152 template <class COLL, class ELEMENT> inline bool IAnalysisTools::matchR
153 (const double eta, const double phi, const double e, COLL *coll, ELEMENT *&element, double &deltaR,
154  int pdg, double &deltaE) const
155 {
156  int index = 0;
157  bool ret = AnalysisUtils::Match::R(eta,phi,e,coll,index,deltaR,pdg,deltaE);
158  if (!ret) return false;
159  element = (*coll)[index];
160  return true;
161 }
162 
163 template <class COLL> inline void IAnalysisTools::sortPT (COLL *coll) const
164 {
165  AnalysisUtils::Sort::pT<COLL>(coll);
166 }
167 
168 template <class COLL> inline void IAnalysisTools::sortE (COLL *coll) const
169 {
170  AnalysisUtils::Sort::e<COLL>(coll);
171 }
172 
173 template <class COLL> inline void IAnalysisTools::sortEta (COLL *coll) const
174 {
175  AnalysisUtils::Sort::eta<COLL>(coll);
176 }
177 
178 template <class COLL> inline void IAnalysisTools::sortPhi (COLL *coll) const
179 {
180  AnalysisUtils::Sort::phi<COLL>(coll);
181 }
182 
183 template <class COLL> inline void IAnalysisTools::classifyCharge (const COLL *coll,
184  std::vector<typename COLL::value_type> &pos,
185  std::vector<typename COLL::value_type> &neg) const
186 {
187  AnalysisUtils::Classify::charge<COLL>(coll,pos,neg);
188 }
189 
190 template <class CALLER, class CRITERIA, class COLL> inline StatusCode IAnalysisTools::select
191 (CALLER *caller, CRITERIA criteria, COLL *coll, const std::string &key, const bool lock) const
192 {
193  MsgStream log(msgSvc(), name());
194 
195  // create new container with the view mode
196  COLL * newColl = new COLL(SG::VIEW_ELEMENTS);
197 
198  /// record the container in SG
199  StatusCode sc = evtStore()->record(newColl, key);
200  if (sc.isFailure())
201  {
202  log << MSG::ERROR << "Unable to record Container in SG with key=" << key << endmsg;
203  return sc;
204  }
205 
206  // loop over all elements
207  typename COLL::const_iterator it = coll->begin();
208  typename COLL::const_iterator itE = coll->end();
209  for (; it != itE; ++it)
210  // selection
211  if (criteria(*it,caller))
212  newColl->push_back(*it);
213 
214  // lock the container
215  if (lock)
216  evtStore()->setConst(newColl);
217 
218  return StatusCode::SUCCESS;
219 }