ATLAS Offline Software
TrimuMassRangeFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // -------------------------------------------------------------
6 // File: GeneratorFilters/TrimuMassRangeFilter.cxx
7 // Description:
8 // Based on MassFilter.cxx
9 //
10 // Allows the user to search for the events where 2 particles of user defined type that
11 // will pass if they have p_t, eta, and invariant mass in the specified range.
12 // If there are more than 1 combinations which pass the eta and pT
13 // selection in the event, take the pair which has the largest invariant mass and then
14 // apply the invariant mass selection in order to avoid duplication.(Original MassFilter
15 // takes the events where at least one pair passes the invariant mass selection.)
16 // default is 2 muons with p_t>=10 GeV, |eta| <= 10, and Mass between 0-14TeV.
17 // Always allow same sign events.
18 //
19 // AuthorList:
20 //
21 // Jeremy Love and Akimasa Ishikawa Sep 2010
22 
23 // Header for this module:-
24 
26 
27 #include "GaudiKernel/MsgStream.h"
28 
29 #include <math.h>
30 
32  ISvcLocator* pSvcLocator): GenFilter(name,pSvcLocator) {
33  declareProperty("PtCut1",m_Ptmin1 = 3500.);
34  declareProperty("PtCut2",m_Ptmin2 = 3500.);
35  declareProperty("PtCut3",m_Ptmin3 = 3500.);
36  declareProperty("EtaCut1",m_EtaRange1 = 4.5);
37  declareProperty("EtaCut2",m_EtaRange2 = 4.5);
38  declareProperty("EtaCut3",m_EtaRange3 = 4.5);
39  declareProperty("InvMassMin",m_InvMassMin=500.);
40  declareProperty("InvMassMax",m_InvMassMax=5000.);
41  declareProperty("PartId1",m_PartId1=13);
42  declareProperty("PartId2",m_PartId2=13);
43  declareProperty("PartId3",m_PartId3=13);
44  declareProperty("PartStatus",m_PartStatus=1);
45 }
46 
48 
50  ATH_MSG_INFO( "TrimuMassRangeFilter " );
51  ATH_MSG_INFO( " PtCut1 " << m_Ptmin1 );
52  ATH_MSG_INFO( " PtCut2 " << m_Ptmin2 );
53  ATH_MSG_INFO( " PtCut3 " << m_Ptmin3 );
54  ATH_MSG_INFO( " EtaCut1 " << m_EtaRange1 );
55  ATH_MSG_INFO( " EtaCut2 " << m_EtaRange2 );
56  ATH_MSG_INFO( " EtaCut3 " << m_EtaRange3 );
57  ATH_MSG_INFO( " InvMassMin " << m_InvMassMin );
58  ATH_MSG_INFO( " InvMassMax " << m_InvMassMax );
59  ATH_MSG_INFO( " PartId1 " << m_PartId1 );
60  ATH_MSG_INFO( " PartId2 " << m_PartId2 );
61  ATH_MSG_INFO( " PartId3 " << m_PartId3 );
62  ATH_MSG_INFO( " PartStatus " << m_PartStatus );
63 
64  return StatusCode::SUCCESS;
65  }
66 
68  return StatusCode::SUCCESS;
69 }
70 
72 
73  ATH_MSG_INFO( " TEST MESSAGE " );
74 
75  // Loop over all events in McEventCollection
76 
77  bool samePDGID12 = ( std::abs(m_PartId1) == std::abs(m_PartId2) );
78  bool samePDGID123 = ( std::abs(m_PartId1) == std::abs(m_PartId2) && std::abs(m_PartId1) == std::abs(m_PartId3) );
79 
81  for (McEventCollection::const_iterator itr = events()->begin(); itr != events()->end(); ++itr) {
82 
83  // Loop over all particles in the event
84  const HepMC::GenEvent* genEvt = (*itr);
85  auto genEvt_particles_begin = HepMC::begin(*genEvt);
86  auto genEvt_particles_end = HepMC::end(*genEvt);
87  for (auto pitr1 = genEvt_particles_begin;
88  pitr1!=genEvt_particles_end; ++pitr1 ){
89  if( ( std::abs((*pitr1)->pdg_id()) != std::abs(m_PartId1) && 99999 != std::abs(m_PartId1) ) || //PDG ID selection
90  (*pitr1)->status() != m_PartStatus || //status of the particle
91  (*pitr1)->momentum().perp() < m_Ptmin1 || // pT cut
92  std::abs((*pitr1)->momentum().pseudoRapidity()) > m_EtaRange1
93  ) continue;//eta cut
94 
95  ATH_MSG_INFO( " type1 " << (*pitr1));
96 
97  auto pitr2 = genEvt_particles_begin;
98  if( samePDGID12 ){
99  pitr2 = pitr1;
100  pitr2++;//pirt2 = pitr1 + 1 is not allowed. operator+ is not defined....
101  }
102 
103  for(; pitr2!=genEvt_particles_end; ++pitr2 ){
104 
105  if( pitr1 == pitr2 ) continue;//if the pointers are the same.
106 
107  if( ( std::abs((*pitr2)->pdg_id()) != std::abs(m_PartId2) && 99999 != std::abs(m_PartId2) ) || //PDG ID selection
108  (*pitr2)->status() != m_PartStatus || //status of the particle
109  (*pitr2)->momentum().perp() < m_Ptmin2 || // pT cut
110  std::abs((*pitr2)->momentum().pseudoRapidity()) > m_EtaRange2
111  ) continue;//eta cut
112  if( samePDGID12 && !samePDGID123 && (*pitr1)->pdg_id()==(*pitr2)->pdg_id()) continue;
113 
114  ATH_MSG_INFO( " type2 " << (*pitr2));
115 
116  auto pitr3 = genEvt_particles_begin;
117  if( samePDGID123 ){
118  pitr3 = pitr2;
119  pitr3++;//pirt2 = pitr1 + 1 is not allowed. operator+ is not defined....
120  }
121 
122  for(; pitr3!=genEvt_particles_end; ++pitr3 ){
123 
124  if( pitr1 == pitr3 || pitr2 == pitr3 ) continue;//if the pointers are the same.
125 
126  if( ( std::abs((*pitr3)->pdg_id()) != std::abs(m_PartId3) && 99999 != std::abs(m_PartId3) ) || //PDG ID selection
127  (*pitr3)->status() != m_PartStatus || //status of the particle
128  (*pitr3)->momentum().perp() < m_Ptmin3 || // pT cut
129  std::abs((*pitr3)->momentum().pseudoRapidity()) > m_EtaRange3
130  ) continue;//eta cut
131 
132  ATH_MSG_INFO( " type3 " << (*pitr3));
133 
134  if( ( std::abs(m_PartId1) != 99999 && std::abs(m_PartId2) != 99999 && std::abs(m_PartId3) != 99999 ) &&
135  ( (*pitr1)->pdg_id() + (*pitr2)->pdg_id() + (*pitr3)->pdg_id() != m_PartId1 + m_PartId2 + m_PartId3 ) ) continue;
136  HepMC::FourVector vec((*pitr1)->momentum().px() + (*pitr2)->momentum().px() + (*pitr3)->momentum().px(),
137  (*pitr1)->momentum().py() + (*pitr2)->momentum().py() + (*pitr3)->momentum().py(),
138  (*pitr1)->momentum().pz() + (*pitr2)->momentum().pz() + (*pitr3)->momentum().pz(),
139  (*pitr1)->momentum().e() + (*pitr2)->momentum().e() + (*pitr3)->momentum().e());
140 
141  double invMass = vec.m();
142 
143  ATH_MSG_INFO( " Mass " << invMass );
144 
146  ATH_MSG_INFO( "TrimuMassRangeFilter passed : MassMin <= Mass < MassMax " << m_InvMassMin << " <= " << invMass << " < " << m_InvMassMax );
147  return StatusCode::SUCCESS;
148  }
149  ATH_MSG_INFO( "TrimuMassRangeFilter not passed : MassMin <= Mass < MassMax " << m_InvMassMin << " <= " << invMass << " < " << m_InvMassMax );
150 
151  }//pitr3
152  }//pitr2
153  }//pitr1
154  }//McEventCollection
155 
156  ATH_MSG_INFO( "TrimuMassRangeFilter not passed at all" );
157 
158  //Haven't found anything...
159  setFilterPassed(false);
160  return StatusCode::SUCCESS;
161 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TrimuMassRangeFilter::m_EtaRange3
double m_EtaRange3
Definition: TrimuMassRangeFilter.h:49
P4Helpers::invMass
double invMass(const I4Momentum &pA, const I4Momentum &pB)
invariant mass from two I4momentum references
Definition: P4Helpers.h:239
TrimuMassRangeFilter::m_PartId1
int m_PartId1
Definition: TrimuMassRangeFilter.h:52
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrimuMassRangeFilter::m_Ptmin2
double m_Ptmin2
Definition: TrimuMassRangeFilter.h:45
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TrimuMassRangeFilter::filterFinalize
virtual StatusCode filterFinalize()
Definition: TrimuMassRangeFilter.cxx:67
TrimuMassRangeFilter::m_EtaRange1
double m_EtaRange1
Definition: TrimuMassRangeFilter.h:47
TrimuMassRangeFilter::m_Ptmin3
double m_Ptmin3
Definition: TrimuMassRangeFilter.h:46
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
TrimuMassRangeFilter::~TrimuMassRangeFilter
virtual ~TrimuMassRangeFilter()
Definition: TrimuMassRangeFilter.cxx:47
TrimuMassRangeFilter::m_InvMassMin
double m_InvMassMin
Definition: TrimuMassRangeFilter.h:50
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
TrimuMassRangeFilter::m_InvMassMax
double m_InvMassMax
Definition: TrimuMassRangeFilter.h:51
HepMC::end
GenEvent::particle_iterator end(HepMC::GenEvent &e)
Definition: GenEvent.h:499
CxxUtils::vec
typename vecDetail::vec_typedef< T, N >::type vec
Define a nice alias for the vectorized type.
Definition: vec.h:207
GenFilter
Base class for event generator filtering modules.
Definition: GenFilter.h:30
TrimuMassRangeFilter::m_Ptmin1
double m_Ptmin1
Definition: TrimuMassRangeFilter.h:44
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TrimuMassRangeFilter::m_PartStatus
int m_PartStatus
Definition: TrimuMassRangeFilter.h:55
TrimuMassRangeFilter::m_PartId3
int m_PartId3
Definition: TrimuMassRangeFilter.h:54
TrimuMassRangeFilter::filterEvent
virtual StatusCode filterEvent()
Definition: TrimuMassRangeFilter.cxx:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrimuMassRangeFilter::m_PartId2
int m_PartId2
Definition: TrimuMassRangeFilter.h:53
TrimuMassRangeFilter.h
TrimuMassRangeFilter::m_EtaRange2
double m_EtaRange2
Definition: TrimuMassRangeFilter.h:48
HepMC::begin
GenEvent::particle_iterator begin(HepMC::GenEvent &e)
Definition: GenEvent.h:498
TrimuMassRangeFilter::filterInitialize
virtual StatusCode filterInitialize()
Definition: TrimuMassRangeFilter.cxx:49
TrimuMassRangeFilter::TrimuMassRangeFilter
TrimuMassRangeFilter(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrimuMassRangeFilter.cxx:31