ATLAS Offline Software
MuonTruthHitsFillerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 
16 #include "AtlasHepMC/GenParticle.h"
18 #include <format>
19 
20 
21 using namespace Muon::MuonStationIndex;
22 namespace{
23  constexpr int chIdxMMS = toInt(ChIndex::ChIndexMax);
24  constexpr int chIdxMML = chIdxMMS + 1;
25 }
26 
27 namespace D3PD {
34 MuonTruthHitsFillerTool::MuonTruthHitsFillerTool (const std::string& type,
35  const std::string& name,
36  const IInterface* parent)
37  : Base (type, name, parent)
38 {
39  declareProperty("PRD_TruthNames", m_PRD_TruthNames);
40  m_PRD_TruthNames.emplace_back("CSC_TruthMap");
41  m_PRD_TruthNames.emplace_back("RPC_TruthMap");
42  m_PRD_TruthNames.emplace_back("TGC_TruthMap");
43  m_PRD_TruthNames.emplace_back("MDT_TruthMap");
44  m_PRD_TruthNames.emplace_back("MM_TruthMap");
45  m_PRD_TruthNames.emplace_back("STGC_TruthMap");
46 
47 
48 }
49 
50 
55 {
56  ATH_CHECK(book());
57  ATH_CHECK( m_idHelperSvc.retrieve() );
58  return StatusCode::SUCCESS;
59 }
60 
61 
66 
67 
68  ATH_CHECK( addVariable ("nprecLayers", m_nprecLayers ) );
69  ATH_CHECK( addVariable ("nphiLayers", m_nphiLayers ) );
70  ATH_CHECK( addVariable ("ntrigEtaLayers", m_ntrigEtaLayers ) );
71 
72  m_nprecHitsPerChamberLayer.resize( toInt(ChIndex::ChIndexMax)+2);
73  for( unsigned int i=0; i<toInt(ChIndex::ChIndexMax); ++i) {
74  ATH_CHECK( addVariable ( std::format("nprecHits{:}", chName(static_cast<ChIndex>(i))),
76  }
77 
78  ATH_CHECK( addVariable("nprecHitsMMS", m_nprecHitsPerChamberLayer[chIdxMMS] ) );
79  ATH_CHECK( addVariable("nprecHitsMML", m_nprecHitsPerChamberLayer[chIdxMML] ) );
80 
81  m_nphiHitsPerChamberLayer.resize(toInt(PhiIndex::PhiIndexMax));
82  m_ntrigEtaHitsPerChamberLayer.resize(toInt(PhiIndex::PhiIndexMax));
83  for( unsigned int i=0; i<toInt(PhiIndex::PhiIndexMax); ++i) {
84  ATH_CHECK(addVariable(std::format("nphiHits{:}", phiName(static_cast<PhiIndex>(i))), m_nphiHitsPerChamberLayer[i]));
85  ATH_CHECK(addVariable(std::format("ntrigEtaHits{:}", phiName(static_cast<PhiIndex>(i))), m_ntrigEtaHitsPerChamberLayer[i]));
86  }
87 
88  return StatusCode::SUCCESS;
89 }
90 
91 
96 {
97  ATH_CHECK( fillHitCounts (HepMC::uniqueID(trackRecord)) );
98  return StatusCode::SUCCESS;
99 }
100 
101 
106 {
108  return StatusCode::SUCCESS;
109 }
110 
111 
113 {
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  for (const PRD_MultiTruthCollection::value_type& mc : *collection) {
124  // check if gen particle same as input
125  // TODO Here barcode is being used purely as a unique
126  // identifier, so we can use HepMC::uniqueID once TrackRecord
127  // and xAOD::TruthParticle and PRD_MultiTruthCollection support
128  // it.
129  if ( !HepMC::is_same_particle(mc.second,uniqueID)) continue;
130  found = true;
131  const Identifier& id = mc.first;
132  ATH_MSG_VERBOSE("found matching hit " << m_idHelperSvc->toString(id) );
133  bool measPhi = m_idHelperSvc->measuresPhi(id);
134 
135  if( m_idHelperSvc->issTgc(id) ) {
136  int index = toInt(m_idHelperSvc->phiIndex(id));
137  if( measPhi ) ++*(m_nphiHitsPerChamberLayer[index]);
139  }
140  else if( m_idHelperSvc->isMM(id) ) {
141  int index = m_idHelperSvc->isSmallChamber(id) ? chIdxMMS: chIdxMML;
143  }
144  else if( m_idHelperSvc->isTrigger(id) ) {
145  const int index = toInt(m_idHelperSvc->phiIndex(id));
146  if( measPhi ) ++*(m_nphiHitsPerChamberLayer[index]);
148  }
149  else {
150  if( measPhi ) {
151  ++*(m_nphiHitsPerChamberLayer[toInt(m_idHelperSvc->phiIndex(id))]);
152  }else{
153  ++*(m_nprecHitsPerChamberLayer[toInt(m_idHelperSvc->chamberIndex(id))]);
154  }
155  }
156  }
157  }
158 
159  if( !found ) {
160  ATH_MSG_VERBOSE("No hits associated to muon ");
161  }
162  else {
163  // sum precision hits
164  const std::vector<int*>& nprec = m_nprecHitsPerChamberLayer;
165  const std::vector<int*>& nphi = m_nphiHitsPerChamberLayer;
166  const std::vector<int*>& ntrig = m_ntrigEtaHitsPerChamberLayer;
167 
168  if( *nprec[toInt(ChIndex::BIS)] + *nprec[toInt(ChIndex::BIL)] > 3 ) ++*m_nprecLayers;
169  if( *nprec[toInt(ChIndex::BMS)] + *nprec[toInt(ChIndex::BML)] > 2 ) ++*m_nprecLayers;
170  if( *nprec[toInt(ChIndex::BOS)] + *nprec[toInt(ChIndex::BOL)] > 2 ) ++*m_nprecLayers;
171  if( *nprec[toInt(ChIndex::EIS)] + *nprec[toInt(ChIndex::EIL)] > 3 ) ++*m_nprecLayers;
172  if( *nprec[toInt(ChIndex::EMS)] + *nprec[toInt(ChIndex::EML)] > 2 ) ++*m_nprecLayers;
173  if( *nprec[toInt(ChIndex::EOS)] + *nprec[toInt(ChIndex::EOL)] > 2 ) ++*m_nprecLayers;
174  if( *nprec[toInt(ChIndex::EES)] + *nprec[toInt(ChIndex::EEL)] > 3 ) ++*m_nprecLayers;
175  if( *nprec[toInt(ChIndex::CSS)] + *nprec[toInt(ChIndex::CSL)] > 2 ) ++*m_nprecLayers;
176  if( *nprec[toInt(ChIndex::BEE)] > 3 ) ++*m_nprecLayers;
177  if( *nprec[chIdxMML] + *nprec[chIdxMMS] > 3 ) ++*m_nprecLayers;
178 
179  if( *nphi[toInt(PhiIndex::BM1)] > 0 ) ++*m_nphiLayers;
180  if( *nphi[toInt(PhiIndex::BM2)] > 0 ) ++*m_nphiLayers;
181  if( *nphi[toInt(PhiIndex::BO1)] > 0 ) ++*m_nphiLayers;
182  if( *nphi[toInt(PhiIndex::T1)] > 0 ) ++*m_nphiLayers;
183  if( *nphi[toInt(PhiIndex::T2)] > 0 ) ++*m_nphiLayers;
184  if( *nphi[toInt(PhiIndex::T3)] > 0 ) ++*m_nphiLayers;
185  if( *nphi[toInt(PhiIndex::T4)] > 0 ) ++*m_nphiLayers;
186  if( *nphi[toInt(PhiIndex::CSC)] > 2 ) ++*m_nphiLayers;
187  if( *nphi[toInt(PhiIndex::STGC1)] + *nphi[toInt(PhiIndex::STGC2)] > 3 ) ++*m_nphiLayers;
188 
189  if( *ntrig[toInt(PhiIndex::BM1)] > 0 ) ++*m_ntrigEtaLayers;
190  if( *ntrig[toInt(PhiIndex::BM2)] > 0 ) ++*m_ntrigEtaLayers;
191  if( *ntrig[toInt(PhiIndex::BO1)] > 0 ) ++*m_ntrigEtaLayers;
192  if( *ntrig[toInt(PhiIndex::T1)] > 0 ) ++*m_ntrigEtaLayers;
193  if( *ntrig[toInt(PhiIndex::T2)] > 0 ) ++*m_ntrigEtaLayers;
194  if( *ntrig[toInt(PhiIndex::T3)] > 0 ) ++*m_ntrigEtaLayers;
195  if( *ntrig[toInt(PhiIndex::T4)] > 0 ) ++*m_ntrigEtaLayers;
196  if( *ntrig[toInt(PhiIndex::CSC)] > 2 ) ++*m_ntrigEtaLayers;
197  if( *ntrig[toInt(PhiIndex::STGC1)] +
198  *ntrig[toInt(PhiIndex::STGC2)] > 3 ) ++*m_ntrigEtaLayers;
199 
200  ATH_MSG_DEBUG("Muon hits: prec " << *m_nprecLayers <<
201  " phi " << *m_nphiLayers
202  << " trig eta " << *m_ntrigEtaLayers );
203  }
204  return StatusCode::SUCCESS;
205 }
206 
207 
208 } // 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
vtune_athena.format
format
Definition: vtune_athena.py:14
Muon::MuonStationIndex
Definition: MuonStationIndex.h:13
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
Muon::MuonStationIndex::ChIndex::ChIndexMax
@ ChIndexMax
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:366
GenParticle.h
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
D3PD::MuonTruthHitsFillerTool::initialize
virtual StatusCode initialize()
Standard Gaudi initialize method.
Definition: MuonTruthHitsFillerTool.cxx:54
D3PD
Block filler tool for noisy FEB information.
Definition: CaloCellDetailsFillerTool.cxx:29
mc
Definition: mc.Py8EG_A2MSTW2008LO_minbias_inelastic.py:1
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
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
Muon::MuonStationIndex::chName
const std::string & chName(ChIndex index)
convert ChIndex into a string
Definition: MuonStationIndex.cxx:119
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
test_pyathena.parent
parent
Definition: test_pyathena.py:15
D3PD::BlockFillerTool< Types< TrackRecord, xAOD::TruthParticle > >
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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:240
MagicNumbers.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
Muon::MuonStationIndex::PhiIndex
PhiIndex
enum to classify the different phi layers in the muon spectrometer
Definition: MuonStationIndex.h:31
TrackRecord
Definition: TrackRecord.h:12
DeMoScan.index
string index
Definition: DeMoScan.py:362
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
BMS
@ BMS
Definition: RegSelEnums.h:13
PRD_MultiTruthCollection.h
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
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:112
Muon::MuonStationIndex::phiName
const std::string & phiName(PhiIndex index)
convert PhiIndex into a string
Definition: MuonStationIndex.cxx:87
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:95
Muon::MuonStationIndex::toInt
constexpr int toInt(const EnumType enumVal)
Definition: MuonStationIndex.h:61
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
D3PD::MuonTruthHitsFillerTool::book
virtual StatusCode book()
Book variables for this block.
Definition: MuonTruthHitsFillerTool.cxx:65
Identifier
Definition: IdentifierFieldParser.cxx:14