ATLAS Offline Software
MuonTruthHitsFillerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 
16 #include "AtlasHepMC/GenParticle.h"
18 
19 namespace D3PD {
27  const std::string& name,
28  const IInterface* parent)
29  : Base (type, name, parent)
30 {
31  declareProperty("PRD_TruthNames", m_PRD_TruthNames);
32  m_PRD_TruthNames.emplace_back("CSC_TruthMap");
33  m_PRD_TruthNames.emplace_back("RPC_TruthMap");
34  m_PRD_TruthNames.emplace_back("TGC_TruthMap");
35  m_PRD_TruthNames.emplace_back("MDT_TruthMap");
36  m_PRD_TruthNames.emplace_back("MM_TruthMap");
37  m_PRD_TruthNames.emplace_back("STGC_TruthMap");
38 
39 
40 }
41 
42 
47 {
48  CHECK(book());
49  CHECK( m_idHelperSvc.retrieve() );
50  return StatusCode::SUCCESS;
51 }
52 
53 
58 {
59  typedef Muon::MuonStationIndex MSI;
60 
61  CHECK( addVariable ("nprecLayers", m_nprecLayers ) );
62  CHECK( addVariable ("nphiLayers", m_nphiLayers ) );
63  CHECK( addVariable ("ntrigEtaLayers", m_ntrigEtaLayers ) );
64 
66  for( unsigned int i=0; i<MSI::ChIndexMax; ++i) {
67  MSI::ChIndex chIndex = (MSI::ChIndex)i;
68  CHECK( addVariable ( std::string("nprecHits")+MSI::chName(chIndex),
70  }
71 
72  CHECK( addVariable ( std::string("nprecHitsMMS"),
73  m_nprecHitsPerChamberLayer[MSI::ChIndexMax] ) );
74  CHECK( addVariable ( std::string("nprecHitsMML"),
75  m_nprecHitsPerChamberLayer[MSI::ChIndexMax+1] ) );
76 
77  m_nphiHitsPerChamberLayer.resize(MSI::PhiIndexMax);
78  m_ntrigEtaHitsPerChamberLayer.resize(MSI::PhiIndexMax);
79  for( unsigned int i=0; i<MSI::PhiIndexMax; ++i) {
80  MSI::PhiIndex phiIndex = (MSI::PhiIndex)i;
81  CHECK( addVariable ( std::string("nphiHits")+MSI::phiName(phiIndex),
83  CHECK( addVariable ( std::string("ntrigEtaHits")+MSI::phiName(phiIndex),
85  }
86 
87  return StatusCode::SUCCESS;
88 }
89 
90 
95 {
96  CHECK( fillHitCounts (HepMC::barcode(trackRecord)) ); // FIXME barcode-based
97  return StatusCode::SUCCESS;
98 }
99 
100 
105 {
107  return StatusCode::SUCCESS;
108 }
109 
110 
112 {
113  typedef Muon::MuonStationIndex MSI;
114 
115  bool found = false;
116  for (const std::string& key : m_PRD_TruthNames) {
117  if (!evtStore()->contains<PRD_MultiTruthCollection>(key)) {
118  ATH_MSG_DEBUG( "PRD_MultiTruthCollection " << key << " NOT found");
119  continue;
120  }
121  const PRD_MultiTruthCollection* collection = nullptr;
122  ATH_CHECK( evtStore()->retrieve(collection, key) );
123 
124  for (const PRD_MultiTruthCollection::value_type& mc : *collection) {
125  // check if gen particle same as input
126  // TODO Here barcode is being used purely as a unique
127  // identifier, so we can use HepMC::uniqueID once TrackRecord
128  // and xAOD::TruthParticle and PRD_MultiTruthCollection support
129  // it.
130  if ( !HepMC::is_same_particle(mc.second,barcode)) continue;
131  found = true;
132  const Identifier& id = mc.first;
133  ATH_MSG_VERBOSE("found matching hit " << m_idHelperSvc->toString(id) );
134  bool measPhi = m_idHelperSvc->measuresPhi(id);
135 
136  if( m_idHelperSvc->issTgc(id) ) {
137  int index = m_idHelperSvc->phiIndex(id);
138  if( measPhi ) ++*(m_nphiHitsPerChamberLayer[index]);
140  }
141  else if( m_idHelperSvc->isMM(id) ) {
142  int index = m_idHelperSvc->isSmallChamber(id) ? MSI::ChIndexMax : MSI::ChIndexMax + 1;
144  }
145  else if( m_idHelperSvc->isTrigger(id) ) {
146  MSI::PhiIndex index = m_idHelperSvc->phiIndex(id);
147  if( measPhi ) ++*(m_nphiHitsPerChamberLayer[index]);
149  }
150  else {
151  if( measPhi ) {
154  }else{
155  Muon::MuonStationIndex::ChIndex chIndex = m_idHelperSvc->chamberIndex(id);
156  ++*(m_nprecHitsPerChamberLayer[chIndex]);
157  }
158  }
159  }
160  }
161 
162  if( !found ) {
163  ATH_MSG_VERBOSE("No hits associated to muon ");
164  }
165  else {
166  // sum precision hits
167  const std::vector<int*>& nprec = m_nprecHitsPerChamberLayer;
168  const std::vector<int*>& nphi = m_nphiHitsPerChamberLayer;
169  const std::vector<int*>& ntrig = m_ntrigEtaHitsPerChamberLayer;
170 
171  if( *nprec[MSI::BIS] + *nprec[MSI::BIL] > 3 ) ++*m_nprecLayers;
172  if( *nprec[MSI::BMS] + *nprec[MSI::BML] > 2 ) ++*m_nprecLayers;
173  if( *nprec[MSI::BOS] + *nprec[MSI::BOL] > 2 ) ++*m_nprecLayers;
174  if( *nprec[MSI::EIS] + *nprec[MSI::EIL] > 3 ) ++*m_nprecLayers;
175  if( *nprec[MSI::EMS] + *nprec[MSI::EML] > 2 ) ++*m_nprecLayers;
176  if( *nprec[MSI::EOS] + *nprec[MSI::EOL] > 2 ) ++*m_nprecLayers;
177  if( *nprec[MSI::EES] + *nprec[MSI::EEL] > 3 ) ++*m_nprecLayers;
178  if( *nprec[MSI::CSS] + *nprec[MSI::CSL] > 2 ) ++*m_nprecLayers;
179  if( *nprec[MSI::BEE] > 3 ) ++*m_nprecLayers;
180  if( *nprec[MSI::ChIndexMax] + *nprec[MSI::ChIndexMax+1] > 3 ) ++*m_nprecLayers;
181 
182  if( *nphi[MSI::BM1] > 0 ) ++*m_nphiLayers;
183  if( *nphi[MSI::BM2] > 0 ) ++*m_nphiLayers;
184  if( *nphi[MSI::BO1] > 0 ) ++*m_nphiLayers;
185  if( *nphi[MSI::T1] > 0 ) ++*m_nphiLayers;
186  if( *nphi[MSI::T2] > 0 ) ++*m_nphiLayers;
187  if( *nphi[MSI::T3] > 0 ) ++*m_nphiLayers;
188  if( *nphi[MSI::T4] > 0 ) ++*m_nphiLayers;
189  if( *nphi[MSI::CSC] > 2 ) ++*m_nphiLayers;
190  if( *nphi[MSI::STGC1] + *nphi[MSI::STGC2] > 3 ) ++*m_nphiLayers;
191 
192  if( *ntrig[MSI::BM1] > 0 ) ++*m_ntrigEtaLayers;
193  if( *ntrig[MSI::BM2] > 0 ) ++*m_ntrigEtaLayers;
194  if( *ntrig[MSI::BO1] > 0 ) ++*m_ntrigEtaLayers;
195  if( *ntrig[MSI::T1] > 0 ) ++*m_ntrigEtaLayers;
196  if( *ntrig[MSI::T2] > 0 ) ++*m_ntrigEtaLayers;
197  if( *ntrig[MSI::T3] > 0 ) ++*m_ntrigEtaLayers;
198  if( *ntrig[MSI::T4] > 0 ) ++*m_ntrigEtaLayers;
199  if( *ntrig[MSI::CSC] > 2 ) ++*m_ntrigEtaLayers;
200  if( *ntrig[MSI::STGC1] +
201  *ntrig[MSI::STGC2] > 3 ) ++*m_ntrigEtaLayers;
202 
203  ATH_MSG_DEBUG("Muon hits: prec " << *m_nprecLayers <<
204  " phi " << *m_nphiLayers
205  << " trig eta " << *m_ntrigEtaLayers );
206  }
207  return StatusCode::SUCCESS;
208 }
209 
210 
211 } // namespace D3PD
BIS
@ BIS
Definition: RegSelEnums.h:11
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CSS
@ CSS
Definition: ParabolaCscClusterFitter.h:25
BIL
@ BIL
Definition: RegSelEnums.h:10
D3PD::MuonTruthHitsFillerTool::MuonTruthHitsFillerTool
MuonTruthHitsFillerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard Gaudi tool constructor.
Definition: MuonTruthHitsFillerTool.cxx:26
index
Definition: index.py:1
PRD_MultiTruthCollection
A PRD is mapped onto all contributing particles.
Definition: PRD_MultiTruthCollection.h:24
xAOD::L2MuonParameters::BEE
@ BEE
BEE measurement point.
Definition: TrigMuonDefs.h:24
D3PD::AddVariable::addVariable
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
Add a variable to the tuple.
Definition: AddVariable.cxx:85
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
BOL
@ BOL
Definition: RegSelEnums.h:14
D3PD::MuonTruthHitsFillerTool::m_ntrigEtaLayers
int * m_ntrigEtaLayers
Definition: MuonTruthHitsFillerTool.h:73
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition: MagicNumbers.h:354
Muon::MuonStationIndex::PhiIndex
PhiIndex
enum to classify the different phi layers in the muon spectrometer
Definition: MuonStationIndex.h:31
GenParticle.h
D3PD::MuonTruthHitsFillerTool::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: MuonTruthHitsFillerTool.cxx:46
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
mc
Definition: mc.PG_single_nu_valid.py:1
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
test_pyathena.parent
parent
Definition: test_pyathena.py:15
D3PD::BlockFillerTool< Types< TrackRecord, xAOD::TruthParticle > >
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
D3PD::MuonTruthHitsFillerTool::m_PRD_TruthNames
std::vector< std::string > m_PRD_TruthNames
Definition: MuonTruthHitsFillerTool.h:79
D3PD::MuonTruthHitsFillerTool::m_nprecLayers
int * m_nprecLayers
Definition: MuonTruthHitsFillerTool.h:71
MuonTruthHitsFillerTool.h
Fill truth hit information for muons.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MagicNumbers.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TrackRecord
Definition: TrackRecord.h:12
Muon::MuonStationIndex::ChIndexMax
@ ChIndexMax
Definition: MuonStationIndex.h:19
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
DeMoScan.index
string index
Definition: DeMoScan.py:364
D3PD::MuonTruthHitsFillerTool::m_ntrigEtaHitsPerChamberLayer
std::vector< int * > m_ntrigEtaHitsPerChamberLayer
Definition: MuonTruthHitsFillerTool.h:76
D3PD::MuonTruthHitsFillerTool::m_nphiLayers
int * m_nphiLayers
Definition: MuonTruthHitsFillerTool.h:72
BML
@ BML
Definition: RegSelEnums.h:12
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
BMS
@ BMS
Definition: RegSelEnums.h:13
Muon::MuonStationIndex
Definition: MuonStationIndex.h:12
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
PRD_MultiTruthCollection.h
CSC
@ CSC
Definition: RegSelEnums.h:34
D3PD::MuonTruthHitsFillerTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonTruthHitsFillerTool.h:78
CSL
@ CSL
Definition: ParabolaCscClusterFitter.h:25
D3PD::MuonTruthHitsFillerTool::fillHitCounts
StatusCode fillHitCounts(int)
Definition: MuonTruthHitsFillerTool.cxx:111
D3PD::MuonTruthHitsFillerTool::m_nprecHitsPerChamberLayer
std::vector< int * > m_nprecHitsPerChamberLayer
Definition: MuonTruthHitsFillerTool.h:74
BOS
@ BOS
Definition: RegSelEnums.h:15
D3PD::MuonTruthHitsFillerTool::m_nphiHitsPerChamberLayer
std::vector< int * > m_nphiHitsPerChamberLayer
Definition: MuonTruthHitsFillerTool.h:75
D3PD::MuonTruthHitsFillerTool::fill
virtual StatusCode fill(const TrackRecord &p)
Fill one block — type-safe version.
Definition: MuonTruthHitsFillerTool.cxx:94
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
D3PD::MuonTruthHitsFillerTool::book
virtual StatusCode book()
Book variables for this block.
Definition: MuonTruthHitsFillerTool.cxx:57
Identifier
Definition: IdentifierFieldParser.cxx:14