ATLAS Offline Software
KinematicSelectorCore.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*****************************************************************************
6  * @Project: AnalysisUtils
7  *
8  * @class KinematicSelectorCore
9  *
10  * @author Amir Farbin <amir.farbin@cernSPAMNOT.ch>
11  * @author Karsten Koeneke <karsten.koeneke@cernSPAMNOT.ch>
12  *
13  * @date June 2009
14  *
15  * @brief Dual use tool (athena/ARA) for kinematic cuts.
16  *
17  *****************************************************************************/
18 
19 // This class's header
21 
22 // STL includes
23 #include <string>
24 #include <cfloat>
25 
26 // Atlas includes
28 
29 
30 //=============================================================================
31 // The contructor
32 //=============================================================================
34  AraToolBase(pmgr),
35  ISelectorCore(pmgr)
36 {
37 
38  //Need a mechanism to turn on/off a cut
39  // The default values are such that the cut is effectefly turned off.
40 
41  declareProperty( "minPt", m_minPt=-DBL_MAX, "Min Pt");
42  declareProperty( "maxPt", m_maxPt=DBL_MAX, "Max Pt");
43 
44  declareProperty( "minP", m_minP=-DBL_MAX, "Min P");
45  declareProperty( "maxP", m_maxP=DBL_MAX, "Max P");
46 
47  declareProperty( "minEt", m_minEt=-DBL_MAX, "Min Et");
48  declareProperty( "maxEt", m_maxEt=DBL_MAX, "Max Et");
49 
50  declareProperty( "minE", m_minE=-DBL_MAX, "Min E");
51  declareProperty( "maxE", m_maxE=DBL_MAX, "Max E");
52 
53  declareProperty( "minEta", m_minEta=-DBL_MAX, "Min Eta");
54  declareProperty( "maxEta", m_maxEta=DBL_MAX, "Max Eta");
55 
56  declareProperty( "minAbsEta", m_minAbsEta=-DBL_MAX, "Min AbsEta");
57  declareProperty( "maxAbsEta", m_maxAbsEta=DBL_MAX, "Max AbsEta");
58 
59  declareProperty( "etaVetoRanges", m_etaVetoRanges="",
60  "Eta ranges in which the object should NOT be. Example: [[-1.52, -1.37], [1.37, 1.52]]");
61 
62  declareProperty( "minPhi", m_minPhi=-DBL_MAX, "Min Phi");
63  declareProperty( "maxPhi", m_maxPhi=DBL_MAX, "Max Phi");
64 
65  declareProperty( "phiVetoRanges", m_phiVetoRanges="",
66  "Phi ranges in which the object should NOT be. Example: [[-1.4, -1.2], [1.1, 1.5]]");
67 
68  declareProperty( "minMass", m_minMass=-DBL_MAX, "Min Mass");
69  declareProperty( "maxMass", m_maxMass=DBL_MAX, "Max Mass");
70 
71 }
72 
73 
74 
75 //=============================================================================
76 // Athena initialize method
77 //=============================================================================
79 {
80  // The standard status code
81  StatusCode sc = StatusCode::SUCCESS ;
82 
83  //-----------------------------------------------------------------
84  // Process the strings of veto ranges
85  // and translate it into the double boundaries
86 
87  // Make sure the eta string is not empty
88  if ( !(m_etaVetoRanges.empty()) )
89  {
91  } // End: if m_etaVetoRanges is not empty
92 
93  // Make sure the phi string is not empty
94  if ( !(m_phiVetoRanges.empty()) )
95  {
97  } // End: if m_phiVetoRanges is not empty
98 
99  // End processing of the veto ranges string
100  //-----------------------------------------------------------------
101 
102 
103  return sc ;
104 }
105 
106 
107 
108 //=============================================================================
109 // Athena finalize method
110 //=============================================================================
112 {
113  // The standard status code
114  StatusCode sc = StatusCode::SUCCESS ;
115 
116  return sc ;
117 }
118 
119 
120 
121 //=============================================================================
122 // The main accept method for IParticle
123 //=============================================================================
125 {
126  // Default return
127  //bool pass(true);
128 
129  // Try to cast the IParticle to INavigable4Momentum
130  // and then use the accept(INavigable4Momentum*) methods.
131  // This should always work since the IParticle class inherits
132  // from INavigable4Momentum.
133  const INavigable4Momentum* inav(NULL);
134  inav = dynamic_cast< const INavigable4Momentum* >(part);
135  if ( inav != NULL )
136  {
137  return accept(inav);
138  }
139  else
140  {
141  std::cerr << "ERROR! Couldn't cast to INavigable4Momentum!"
142  << " But this should always work from an IParticle!"
143  << std::endl;
144  }
145 
146  return false;
147 }
148 
149 
150 //=============================================================================
151 // The main accept method for INavigable4Momentum
152 //=============================================================================
154 {
155  // This can be a lot smarter.
156  bool pass(true);
157 
158  pass = pass && passPt(part) ;
159  pass = pass && passP(part) ;
160  pass = pass && passEt(part) ;
161  pass = pass && passE(part) ;
162  pass = pass && passEta(part) ;
163  pass = pass && passAbsEta(part) ;
164  pass = pass && passEtaVetoRanges(part) ;
165  pass = pass && passPhi(part) ;
166  pass = pass && passPhiVetoRanges(part) ;
167  pass = pass && passMass(part) ;
168 
169  return pass;
170 }
171 
172 
173 
174 // The check if the object (part) is in an eta veto region
176 {
177  // Default return
178  bool isInVetoRange = false;
179 
180  double eta = part->eta();
181  if ( (std::isinf(eta) || std::isnan(eta)) ) return true;
182 
183  // Check consistency of upper and lower range boundaries
184  // and a non-empty string
185  if ( !(m_etaVetoRanges.empty())
186  && m_minEtaVeto.size() == m_maxEtaVeto.size() )
187  {
188  // Loop over all ranges
189  for ( unsigned int i=0; i<m_minEtaVeto.size(); ++i )
190  {
191  if ( eta > m_minEtaVeto[i] && eta < m_maxEtaVeto[i] )
192  {
193  isInVetoRange = true;
194  }
195  }
196  } // End: if ( m_minEtaVeto.size() == m_maxEtaVeto.size() )
197 
198  return !isInVetoRange;
199 }
200 
201 
202 
203 // The check if the object (part) is in an phi veto region
205 {
206  // Default return
207  bool isInVetoRange = false;
208 
209  double phi = part->phi();
210  if ( (std::isinf(phi) || std::isnan(phi)) ) return true;
211 
212  // Check consistency of upper and lower range boundaries
213  // and a non-empty string
214  if ( !(m_phiVetoRanges.empty())
215  && m_minPhiVeto.size() == m_maxPhiVeto.size() )
216  {
217  // Loop over all ranges
218  for ( unsigned int i=0; i<m_minPhiVeto.size(); ++i )
219  {
220  if ( phi > m_minPhiVeto[i] && phi < m_maxPhiVeto[i] )
221  {
222  isInVetoRange = true;
223  }
224  }
225  } // End: if ( m_minPhiVeto.size() == m_maxPhiVeto.size() )
226 
227  return !isInVetoRange;
228 }
229 
230 
231 
232 // Convert the string ranges in range into double min and max vectors
234  std::vector<double> &minVals,
235  std::vector<double> &maxVals )
236 {
237  // Copy the string for further prcessing
238  std::string rangeCopy(range);
239 
240  // Remove all spaces
241  for ( unsigned int i=0; i<rangeCopy.length(); i++ )
242  {
243  if ( rangeCopy[i]==' ' )
244  {
245  rangeCopy.erase(i,1);
246  i--;
247  }
248  }
249 
250  // Find the position of all open and closed brackets
251  std::vector<size_t> openBracketPositions;
252  std::vector<size_t> closedBracketPositions;
253  for ( size_t i=0; i < rangeCopy.size(); ++i )
254  {
255  if ( rangeCopy.compare( i, 1, "[") == 0 )
256  {
257  openBracketPositions.push_back( i );
258  }
259  if ( rangeCopy.compare( i, 1, "]") == 0 )
260  {
261  closedBracketPositions.push_back( i );
262  }
263  }
264 
265  // Consistency checks: number([) == number(])
266  if ( openBracketPositions.size() != closedBracketPositions.size() )
267  {
268 // if (msgLvl(MSG::WARNING))
269 // {
270 // msg(MSG::WARNING)
271  std::cerr
272  << "Inconsistent number of open and closed brackets! "
273  << " numberOpen=" << openBracketPositions.size()
274  << " numberClosed=" << closedBracketPositions.size()
275  << " and cut string=" << rangeCopy
276  << std::endl;
277 // << endmsg ;
278 // }
279  }
280 
281  // Now, get the actual boundaries
282  for ( unsigned int i=0; i<openBracketPositions.size(); ++i )
283  {
284  std::string newRange;
285  newRange = rangeCopy.substr( openBracketPositions[i]+1,
286  closedBracketPositions[i] );
287  size_t comma = newRange.find(",");
288  minVals.push_back( (double)strtod( (newRange.substr( 0, comma )).c_str(),
289  NULL ) );
290  maxVals.push_back( (double)strtod( (newRange.substr( comma+1 )).c_str(),
291  NULL ) );
292  }
293 
294 }
295 
296 
297 
298 
299 // Convert the string ranges in range into double min and max vectors
301 {
302  // Set the member variable to the given input
304 
305  // Decode the other member variables again
306 
307  // Make sure the eta string is not empty
308  if ( !(m_etaVetoRanges.empty()) )
309  {
311  } // End: if m_etaVetoRanges is not empty
312 
313 }
314 
315 
316 
317 
318 // Convert the string ranges in range into double min and max vectors
320 {
321  // Set the member variable to the given input
323 
324  // Decode the other member variables again
325 
326  // Make sure the phi string is not empty
327  if ( !(m_phiVetoRanges.empty()) )
328  {
330  } // End: if m_phiVetoRanges is not empty
331 
332 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
KinematicSelectorCore::passPt
bool passPt(const INavigable4Momentum *part) const
Only transverse momentum cut is applied.
Definition: KinematicSelectorCore.h:70
KinematicSelectorCore::m_maxEtaVeto
std::vector< double > m_maxEtaVeto
eta veto ranges upper range boundaries
Definition: KinematicSelectorCore.h:328
KinematicSelectorCore::m_maxEta
double m_maxEta
maximum eta cut value
Definition: KinematicSelectorCore.h:311
ISelectorCore
Dual use tool (athena/ARA) for any cuts. This is the base class.
Definition: ISelectorCore.h:29
KinematicSelectorCore::passE
bool passE(const INavigable4Momentum *part) const
Only energy cut is applied.
Definition: KinematicSelectorCore.h:97
KinematicSelectorCore::passPhi
bool passPhi(const INavigable4Momentum *part) const
Only phi cut is applied.
Definition: KinematicSelectorCore.h:128
KinematicSelectorCore::m_maxPt
double m_maxPt
maximum transverse momentum cut value
Definition: KinematicSelectorCore.h:283
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
KinematicSelectorCore::m_maxPhiVeto
std::vector< double > m_maxPhiVeto
phi veto ranges upper range boundaries
Definition: KinematicSelectorCore.h:345
KinematicSelectorCore::passPhiVetoRanges
bool passPhiVetoRanges(const INavigable4Momentum *part) const
Only the phi veto ranges cut is applied.
Definition: KinematicSelectorCore.cxx:204
INavigable4Momentum.h
KinematicSelectorCore::m_minEtaVeto
std::vector< double > m_minEtaVeto
eta veto ranges lower range boundaries
Definition: KinematicSelectorCore.h:325
KinematicSelectorCore::initialize
virtual StatusCode initialize()
Gaudi Service Interface method implementations.
Definition: KinematicSelectorCore.cxx:78
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
KinematicSelectorCore::passP
bool passP(const INavigable4Momentum *part) const
Only momentum cut is applied.
Definition: KinematicSelectorCore.h:79
KinematicSelectorCore::setPhiVetoRanges
void setPhiVetoRanges(std::string &range)
set phi veto ranges
Definition: KinematicSelectorCore.cxx:319
KinematicSelectorCore.h
KinematicSelectorCore::passMass
bool passMass(const INavigable4Momentum *part) const
Only mass cut is applied.
Definition: KinematicSelectorCore.h:141
KinematicSelectorCore::passEtaVetoRanges
bool passEtaVetoRanges(const INavigable4Momentum *part) const
Only the eta veto ranges cut is applied.
Definition: KinematicSelectorCore.cxx:175
KinematicSelectorCore::m_minE
double m_minE
minimum energy cut value
Definition: KinematicSelectorCore.h:294
KinematicSelectorCore::accept
bool accept(const IParticle *part) const
Main method for IParticle, all cuts are applied (const method)
Definition: KinematicSelectorCore.cxx:124
KinematicSelectorCore::m_etaVetoRanges
std::string m_etaVetoRanges
eta veto ranges string
Definition: KinematicSelectorCore.h:322
KinematicSelectorCore::KinematicSelectorCore
KinematicSelectorCore(PropertyMgr *pmgr=0)
Default contructor.
Definition: KinematicSelectorCore.cxx:33
KinematicSelectorCore::convertStringRange
void convertStringRange(std::string &range, std::vector< double > &minVals, std::vector< double > &maxVals)
Helper function.
Definition: KinematicSelectorCore.cxx:233
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
KinematicSelectorCore::m_maxMass
double m_maxMass
maximum mass cut value
Definition: KinematicSelectorCore.h:352
KinematicSelectorCore::m_minPt
double m_minPt
minimum transverse momentum cut value
Definition: KinematicSelectorCore.h:280
KinematicSelectorCore::m_minEt
double m_minEt
minimum transverse energy cut value
Definition: KinematicSelectorCore.h:301
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
KinematicSelectorCore::m_maxAbsEta
double m_maxAbsEta
maximum |eta| cut value
Definition: KinematicSelectorCore.h:318
KinematicSelectorCore::passEta
bool passEta(const INavigable4Momentum *part) const
Only eta cut is applied.
Definition: KinematicSelectorCore.h:106
MakeTH3DFromTH2Ds.maxVals
maxVals
Definition: MakeTH3DFromTH2Ds.py:74
KinematicSelectorCore::m_minMass
double m_minMass
minimum mass cut value
Definition: KinematicSelectorCore.h:349
KinematicSelectorCore::m_minAbsEta
double m_minAbsEta
minimum |eta| cut value
Definition: KinematicSelectorCore.h:315
KinematicSelectorCore::m_minPhi
double m_minPhi
minimum phi cut value
Definition: KinematicSelectorCore.h:332
AraToolBase::PropertyMgr
PropertyHolder< CommonMessaging< implements< IAlgTool, IDataHandleHolder, IProperty, IStateful > > > PropertyMgr
Definition: AraToolBase.h:19
KinematicSelectorCore::finalize
virtual StatusCode finalize()
Gaudi Service Interface method implementations.
Definition: KinematicSelectorCore.cxx:111
AraToolBase::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Definition: AraToolBase.h:52
KinematicSelectorCore::passEt
bool passEt(const INavigable4Momentum *part) const
Only transverse energy cut is applied.
Definition: KinematicSelectorCore.h:88
KinematicSelectorCore::passAbsEta
bool passAbsEta(const INavigable4Momentum *part) const
Only |eta| cut is applied.
Definition: KinematicSelectorCore.h:115
INavigable4Momentum
Definition: INavigable4Momentum.h:21
AraToolBase
Definition: AraToolBase.h:17
KinematicSelectorCore::m_minEta
double m_minEta
minimum eta cut value
Definition: KinematicSelectorCore.h:308
KinematicSelectorCore::m_maxPhi
double m_maxPhi
maximum phi cut value
Definition: KinematicSelectorCore.h:335
MakeTH3DFromTH2Ds.minVals
minVals
Definition: MakeTH3DFromTH2Ds.py:73
KinematicSelectorCore::m_maxE
double m_maxE
maximum energy cut value
Definition: KinematicSelectorCore.h:297
KinematicSelectorCore::setEtaVetoRanges
void setEtaVetoRanges(std::string &range)
set eta veto ranges
Definition: KinematicSelectorCore.cxx:300
IParticle
Definition: Event/EventKernel/EventKernel/IParticle.h:43
KinematicSelectorCore::m_minP
double m_minP
minimum momentum cut value
Definition: KinematicSelectorCore.h:287
KinematicSelectorCore::m_phiVetoRanges
std::string m_phiVetoRanges
phi veto ranges string
Definition: KinematicSelectorCore.h:339
KinematicSelectorCore::m_maxP
double m_maxP
maximum momentum cut value
Definition: KinematicSelectorCore.h:290
KinematicSelectorCore::m_minPhiVeto
std::vector< double > m_minPhiVeto
phi veto ranges lower range boundaries
Definition: KinematicSelectorCore.h:342
KinematicSelectorCore::m_maxEt
double m_maxEt
maximum transverse energy cut value
Definition: KinematicSelectorCore.h:304