ATLAS Offline Software
MultiParticleFilter.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 // File: GeneratorFilters/MultiParticleFilter.cxx
7 // Description:
8 //
9 // Allows the user to search for Np particles with multiple statuses passing pT and Eta cuts.
10 // The particles are required to be listed in the vectors particlePDG[] and particleStatus[].
11 // The filter will search for these particles and if Np particles are found which fulfil these requirements and the kinematic cuts, the filter returns success,
12 // e.g., setting Np = 2, particlePDG = [23,24] with particleStatus = [23] and ptMinParticle = 10 in the jobOptions,
13 // will accepts events with at least two W/Z bosons with status=23 and pT > 10 GeV.
14 //
15 // This filter was tested and used only for Alpgen/Jimmy/Herwig events.
16 // User should check if the filter works for other generators.
17 //
18 //
19 // AuthorList:
20 // Orel Gueta March 2014
21 
22 // Header for this module:-
23 
25 
26 // Other classes used by this class:-
27 #include <math.h>
28 
29 
30 //--------------------------------------------------------------------------
31 MultiParticleFilter::MultiParticleFilter(const std::string& name, ISvcLocator* pSvcLocator): GenFilter(name,pSvcLocator)
32  , m_total(0)
33  , m_passed(0)
34 {
35 //--------------------------------------------------------------------------
36 
37  declareProperty("particlePDG",m_particlePDG);
38  declareProperty("particleStatus",m_particleStatus);
39  declareProperty("ptMinParticle",m_ptMinParticle = 0.);
40  declareProperty("ptMaxParticle",m_ptMaxParticle = 1e9);
41  declareProperty("etaRangeParticle",m_etaRangeParticle = 999.0);
42  declareProperty("Np",m_Np = 1);
43 
44 }
45 
46 //--------------------------------------------------------------------------
48 //--------------------------------------------------------------------------
49 
50 }
51 
52 //---------------------------------------------------------------------------
54 //---------------------------------------------------------------------------
55 
56  msg(MSG:: INFO) << "MultiParticleFilter INITIALISING " << endmsg;
57 
58  if(m_particlePDG.size()==0)
59  msg(MSG:: ERROR) << "particlePDG[] not set " << endmsg;
60  if(m_particleStatus.size()==0)
61  msg( MSG:: ERROR) << "particleStatus[] not set " << endmsg;
62 
63  for(unsigned int i=0; i<m_particlePDG.size(); i++)
64  msg(MSG:: INFO) << "particlePDG["<<i<<"] = " << m_particlePDG[i] << endmsg;
65  for(unsigned int i=0; i<m_particleStatus.size(); i++)
66  msg( MSG:: INFO) << "particleStatus["<<i<<"] = " << m_particleStatus[i] << endmsg;
67 
68  msg(MSG:: INFO) << "ptMinParticle = " << m_ptMinParticle << endmsg;
69  msg(MSG:: INFO) << "ptMaxParticle = " << m_ptMaxParticle << endmsg;
70  msg(MSG:: INFO) << "etaRangeParticle = " << m_etaRangeParticle << endmsg;
71  msg(MSG:: INFO) << "Np = " << m_Np << endmsg;
72 
73  return StatusCode::SUCCESS;
74 
75 }
76 
77 //---------------------------------------------------------------------------
79 //---------------------------------------------------------------------------
80  msg(MSG:: INFO) << "Total efficiency: " << 100.*double(m_passed)/double(m_total) << "%" << endmsg;
81  return StatusCode::SUCCESS;
82 }
83 
84 
85 //---------------------------------------------------------------------------
87 //---------------------------------------------------------------------------
88 
89  // Loop over all events in McEventCollection
90 
92  for (itr = events()->begin(); itr != events()->end(); ++itr) {
93 
94  m_total++; // Bookkeeping
95  unsigned int Np(0);
96 
97  // Loop over all particles in the event
98  const HepMC::GenEvent* genEvt = (*itr);
99  for(const auto& pitr: *genEvt){
100  bool passedPDG = false;
101  bool passedStatus = false;
102  if (find(m_particlePDG.begin(),m_particlePDG.end(),std::abs(pitr->pdg_id()))!=m_particlePDG.end()) passedPDG = true;
103  if (find(m_particleStatus.begin(),m_particleStatus.end(),pitr->status())!=m_particleStatus.end()) passedStatus = true;
104 
105  if(passedPDG && passedStatus)
106  if (pitr->momentum().perp() >= m_ptMinParticle && pitr->momentum().perp() <= m_ptMaxParticle && std::abs(pitr->momentum().eta()) <= m_etaRangeParticle)
107  Np++; // Found a particle passing all the cuts.
108 
109  // Test if we fulfilled all the requirements and return in that case.
110  if (Np >= m_Np){
111  setFilterPassed(true);
112  m_passed++;
113  return StatusCode::SUCCESS;
114  }
115  }
116  }
117 
118  // if we got here, we failed
119  setFilterPassed(false);
120  return StatusCode::SUCCESS;
121 
122 }
123 
124 
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
MultiParticleFilter::m_particlePDG
std::vector< int > m_particlePDG
Definition: MultiParticleFilter.h:37
MultiParticleFilter::~MultiParticleFilter
virtual ~MultiParticleFilter()
Definition: MultiParticleFilter.cxx:47
MultiParticleFilter.h
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
MultiParticleFilter::m_ptMaxParticle
double m_ptMaxParticle
Definition: MultiParticleFilter.h:40
MultiParticleFilter::m_total
long m_total
Definition: MultiParticleFilter.h:44
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
MultiParticleFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: MultiParticleFilter.cxx:53
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MultiParticleFilter::MultiParticleFilter
MultiParticleFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MultiParticleFilter.cxx:31
MultiParticleFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: MultiParticleFilter.cxx:78
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MultiParticleFilter::m_particleStatus
std::vector< int > m_particleStatus
Definition: MultiParticleFilter.h:38
MultiParticleFilter::filterEvent
virtual StatusCode filterEvent()
Definition: MultiParticleFilter.cxx:86
MultiParticleFilter::m_ptMinParticle
double m_ptMinParticle
Definition: MultiParticleFilter.h:39
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
MultiParticleFilter::m_etaRangeParticle
double m_etaRangeParticle
Definition: MultiParticleFilter.h:41
MultiParticleFilter::m_passed
long m_passed
Definition: MultiParticleFilter.h:45
MultiParticleFilter::m_Np
unsigned int m_Np
Definition: MultiParticleFilter.h:42