ATLAS Offline Software
SpacePointAnalysis.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 #include "SpacePointAnalysis.h"
6 #include "StoreGate/ReadHandle.h"
7 #include "GaudiKernel/EventContext.h"
8 
10 #include "InDetIdentifier/SCT_ID.h"
11 
12 #include "TTree.h"
13 #include "TString.h"
14 
15 #include <algorithm>
16 #include <cmath>
17 #include <functional>
18 #include <iostream>
19 
20 SpacePointAnalysis::SpacePointAnalysis(const std::string& name, ISvcLocator *pSvcLocator)
21 : AthAlgorithm(name, pSvcLocator) {}
22 
24  ATH_MSG_DEBUG( "Initializing SpacePointAnalysis" );
25 
27 
29 
30  if (m_usePixel)
31  ATH_CHECK(detStore()->retrieve(m_pixelID, "PixelID"));
32  else
33  ATH_CHECK(detStore()->retrieve(m_stripID, "SCT_ID"));
34 
35  ATH_CHECK(m_thistSvc.retrieve());
36 
37  m_tree = new TTree(TString(m_ntupleTreeName.value()), "SpacePointAna");
38  std::string fullNtupleName = m_ntupleFileName.value() + m_ntupleDirName.value() + m_ntupleTreeName.value();
39  ATH_CHECK(m_thistSvc->regTree(fullNtupleName, m_tree));
40 
41  if (m_tree) {
42  m_tree->Branch("barrelEndcap", &m_barrelEndcap);
43  m_tree->Branch("layerDisk", &m_layerDisk);
44  m_tree->Branch("phiModule", &m_phiModule);
45  m_tree->Branch("etaModule", &m_etaModule);
46  m_tree->Branch("sideModule", &m_sideModule);
47  m_tree->Branch("isInnermost", &m_isInnermost);
48  m_tree->Branch("isNextToInnermost", &m_isNextToInnermost);
49  m_tree->Branch("isOverlap", &m_isOverlap);
50  m_tree->Branch("eta", &m_eta);
51  m_tree->Branch("globalX", &m_globalX);
52  m_tree->Branch("globalY", &m_globalY);
53  m_tree->Branch("globalZ", &m_globalZ);
54  m_tree->Branch("globalCovXX", &m_globalCovXX);
55  m_tree->Branch("globalCovYY", &m_globalCovYY);
56  m_tree->Branch("globalCovZZ", &m_globalCovZZ);
57  m_tree->Branch("globalCovXY", &m_globalCovXY);
58  m_tree->Branch("globalCovXZ", &m_globalCovXZ);
59  m_tree->Branch("globalCovYX", &m_globalCovYX);
60  m_tree->Branch("globalCovYZ", &m_globalCovYZ);
61  m_tree->Branch("globalCovZX", &m_globalCovZX);
62  m_tree->Branch("globalCovZY", &m_globalCovZY);
63 
64  } else {
65  ATH_MSG_ERROR("No tree found!");
66  }
67 
68  m_h_globalZR = new TH2F("h_globalZR","h_globalZR; z [mm]; r [mm]",1500,-3000.,3000,1500,0.,1500);
69  ATH_CHECK(m_thistSvc->regHist(m_path.value() + m_h_globalZR->GetName(), m_h_globalZR));
70 
71  m_h_etaSpacePoint = new TH1F("m_h_etaSpacePoint","m_h_etaSpacePoint; space point #eta",100, -5, 5);
72  ATH_CHECK(m_thistSvc->regHist(m_path.value() + m_h_etaSpacePoint->GetName(), m_h_etaSpacePoint));
73 
74  if (m_usePixel and m_useOverlap)
75  ATH_MSG_INFO("No overlap collection when enabled for pixel space points! Check your configuration if needed.");
76 
77  return StatusCode::SUCCESS;
78 }
79 
81  ATH_MSG_DEBUG(" In SpacePointAnalysis::execute()" );
82 
83  m_barrelEndcap->clear();
84  m_layerDisk->clear();
85  m_phiModule->clear();
86  m_etaModule->clear();
87  m_sideModule->clear();
88  m_isInnermost->clear();
89  m_isNextToInnermost->clear();
90  m_isOverlap->clear();
91  m_eta->clear();
92  m_globalX->clear();
93  m_globalY->clear();
94  m_globalZ->clear();
95  m_globalCovXX->clear();
96  m_globalCovYY->clear();
97  m_globalCovZZ->clear();
98  m_globalCovXY->clear();
99  m_globalCovXZ->clear();
100  m_globalCovYX->clear();
101  m_globalCovYZ->clear();
102  m_globalCovZX->clear();
103  m_globalCovZY->clear();
104 
105  const EventContext& ctx = Algorithm::getContext();
106 
108  if(spContainer.isValid()) {
109  for( const SpacePointCollection* spCollection : *spContainer) {
110  if (!spCollection) continue;
111  for( const Trk::SpacePoint* spacePoint : *spCollection) {
112  const Identifier idColl(spCollection->identify());
113  const int brlEc(m_usePixel ? m_pixelID->barrel_ec(idColl) : m_stripID->barrel_ec(idColl));
114  const int layerDisk(m_usePixel ? m_pixelID->layer_disk(idColl) : m_stripID->layer_disk(idColl));
115  const int phiMod(m_usePixel ? m_pixelID->phi_module(idColl) : m_stripID->phi_module(idColl));
116  const int etaMod(m_usePixel ? m_pixelID->eta_module(idColl) : m_stripID->eta_module(idColl));
117  const int side(m_usePixel ? 0 : m_stripID->side(idColl));
118 
119  bool isInnermost = m_usePixel ? (layerDisk==0) : false;
120  bool isNextToInnermost = m_usePixel ? ((layerDisk==1) or (brlEc!=0 and layerDisk==2)) : false;
121 
122  m_barrelEndcap->push_back(brlEc);
123  m_layerDisk->push_back(layerDisk);
124  m_phiModule->push_back(phiMod);
125  m_etaModule->push_back(etaMod);
126  m_sideModule->push_back(side);
127  m_isInnermost->push_back(int(isInnermost));
128  m_isNextToInnermost->push_back(int(isNextToInnermost));
129  m_isOverlap->push_back(0);
130 
131  auto globalPos = spacePoint->globalPosition();
132  auto globalCov = spacePoint->globCovariance();
133 
134  m_eta->push_back(globalPos.eta());
135  m_globalX->push_back(globalPos.x());
136  m_globalY->push_back(globalPos.y());
137  m_globalZ->push_back(globalPos.z());
138 
139  m_globalCovXX->push_back(globalCov(0,0));
140  m_globalCovYY->push_back(globalCov(1,1));
141  m_globalCovZZ->push_back(globalCov(2,2));
142  m_globalCovXY->push_back(globalCov(0,1));
143  m_globalCovXZ->push_back(globalCov(0,2));
144  m_globalCovYX->push_back(globalCov(1,0));
145  m_globalCovYZ->push_back(globalCov(1,2));
146  m_globalCovZX->push_back(globalCov(2,0));
147  m_globalCovZY->push_back(globalCov(2,1));
148 
149  m_h_globalZR->Fill(globalPos.z(), globalPos.perp());
150  m_h_etaSpacePoint->Fill(globalPos.eta());
151 
152  }
153  }
154  } else {
155  ATH_MSG_FATAL("Unable to get SpacePointContainer: " << m_inputKey.key());
156  }
157 
158  if (not m_usePixel and m_useOverlap) {
160  if (spCollection.isValid()) {
161  for( const Trk::SpacePoint* spacePoint : *spCollection) {
162  const IdentifierHash hashId(spacePoint->elementIdList().first);
163  const Identifier idColl = m_stripID->wafer_id(hashId);
164 
165  const int brlEc(m_stripID->barrel_ec(idColl));
166  const int layerDisk(m_stripID->layer_disk(idColl));
167  const int phiMod(m_stripID->phi_module(idColl));
168  const int etaMod(m_stripID->eta_module(idColl));
169  const int side(m_stripID->side(idColl));
170 
171  const bool isInnermost(false);
172  const bool isNextToInnermost(false);
173 
174  m_barrelEndcap->push_back(brlEc);
175  m_layerDisk->push_back(layerDisk);
176  m_phiModule->push_back(phiMod);
177  m_etaModule->push_back(etaMod);
178  m_sideModule->push_back(side);
179  m_isInnermost->push_back(int(isInnermost));
180  m_isNextToInnermost->push_back(int(isNextToInnermost));
181  m_isOverlap->push_back(1);
182 
183  auto globalPos = spacePoint->globalPosition();
184  auto globalCov = spacePoint->globCovariance();
185 
186  m_eta->push_back(globalPos.eta());
187  m_globalX->push_back(globalPos.x());
188  m_globalY->push_back(globalPos.y());
189  m_globalZ->push_back(globalPos.z());
190 
191  m_globalCovXX->push_back(globalCov(0,0));
192  m_globalCovYY->push_back(globalCov(1,1));
193  m_globalCovZZ->push_back(globalCov(2,2));
194  m_globalCovXY->push_back(globalCov(0,1));
195  m_globalCovXZ->push_back(globalCov(0,2));
196  m_globalCovYX->push_back(globalCov(1,0));
197  m_globalCovYZ->push_back(globalCov(1,2));
198  m_globalCovZX->push_back(globalCov(2,0));
199  m_globalCovZY->push_back(globalCov(2,1));
200 
201  m_h_globalZR->Fill(globalPos.z(), globalPos.perp());
202  m_h_etaSpacePoint->Fill(globalPos.eta());
203 
204  }
205  } else {
206  ATH_MSG_FATAL("Unable to get SpacePointContainer: " << m_inputOverlapKey.key());
207  }
208  }
209 
210  if (m_tree) {
211  m_tree->Fill();
212  }
213 
214  return StatusCode::SUCCESS;
215 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SpacePointAnalysis::m_globalCovXZ
std::vector< double > * m_globalCovXZ
Definition: SpacePointAnalysis.h:58
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
Trk::SpacePoint
Definition: Tracking/TrkEvent/TrkSpacePoint/TrkSpacePoint/SpacePoint.h:35
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SpacePointAnalysis::m_globalCovZX
std::vector< double > * m_globalCovZX
Definition: SpacePointAnalysis.h:61
SpacePointAnalysis::m_ntupleTreeName
StringProperty m_ntupleTreeName
Definition: SpacePointAnalysis.h:70
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
SG::ReadHandle< SpacePointContainer >
SpacePointAnalysis::initialize
virtual StatusCode initialize() override final
Definition: SpacePointAnalysis.cxx:23
SpacePointAnalysis::m_pixelID
const PixelID * m_pixelID
Definition: SpacePointAnalysis.h:39
SpacePointAnalysis::m_isOverlap
std::vector< int > * m_isOverlap
Definition: SpacePointAnalysis.h:49
SpacePointAnalysis::m_isInnermost
std::vector< int > * m_isInnermost
Definition: SpacePointAnalysis.h:47
SpacePointAnalysis::m_globalZ
std::vector< double > * m_globalZ
Definition: SpacePointAnalysis.h:53
SpacePointAnalysis::SpacePointAnalysis
SpacePointAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: SpacePointAnalysis.cxx:20
SpacePointAnalysis::m_barrelEndcap
std::vector< int > * m_barrelEndcap
Definition: SpacePointAnalysis.h:42
SpacePointAnalysis::m_globalCovYY
std::vector< double > * m_globalCovYY
Definition: SpacePointAnalysis.h:55
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TRT::Hit::side
@ side
Definition: HitInfo.h:83
SpacePointAnalysis::m_globalY
std::vector< double > * m_globalY
Definition: SpacePointAnalysis.h:52
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SpacePointAnalysis::m_usePixel
BooleanProperty m_usePixel
Definition: SpacePointAnalysis.h:74
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
SpacePointAnalysis::m_globalX
std::vector< double > * m_globalX
Definition: SpacePointAnalysis.h:51
SpacePointAnalysis::execute
virtual StatusCode execute() override final
Definition: SpacePointAnalysis.cxx:80
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SpacePointAnalysis::m_sideModule
std::vector< int > * m_sideModule
Definition: SpacePointAnalysis.h:46
SpacePointAnalysis::m_useOverlap
BooleanProperty m_useOverlap
Definition: SpacePointAnalysis.h:75
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SpacePointAnalysis::m_etaModule
std::vector< int > * m_etaModule
Definition: SpacePointAnalysis.h:45
SpacePointAnalysis::m_h_etaSpacePoint
TH1 * m_h_etaSpacePoint
Definition: SpacePointAnalysis.h:65
SpacePointAnalysis::m_globalCovXX
std::vector< double > * m_globalCovXX
Definition: SpacePointAnalysis.h:54
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
PixelID::eta_module
int eta_module(const Identifier &id) const
Definition: PixelID.h:651
SpacePointAnalysis::m_ntupleDirName
StringProperty m_ntupleDirName
Definition: SpacePointAnalysis.h:69
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SpacePointAnalysis::m_inputKey
SG::ReadHandleKey< SpacePointContainer > m_inputKey
Definition: SpacePointAnalysis.h:37
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
SpacePointAnalysis::m_eta
std::vector< double > * m_eta
Definition: SpacePointAnalysis.h:50
SpacePointAnalysis.h
SpacePointAnalysis::m_tree
TTree * m_tree
Definition: SpacePointAnalysis.h:67
SpacePointAnalysis::m_h_globalZR
TH2 * m_h_globalZR
Definition: SpacePointAnalysis.h:64
SpacePointAnalysis::m_globalCovXY
std::vector< double > * m_globalCovXY
Definition: SpacePointAnalysis.h:57
SpacePointAnalysis::m_ntupleFileName
StringProperty m_ntupleFileName
Definition: SpacePointAnalysis.h:68
SpacePointAnalysis::m_path
StringProperty m_path
Definition: SpacePointAnalysis.h:71
SpacePointAnalysis::m_inputOverlapKey
SG::ReadHandleKey< SpacePointOverlapCollection > m_inputOverlapKey
Definition: SpacePointAnalysis.h:38
SpacePointCollection
Definition: SpacePointCollection.h:40
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
SpacePointAnalysis::m_layerDisk
std::vector< int > * m_layerDisk
Definition: SpacePointAnalysis.h:43
SpacePointAnalysis::m_globalCovZZ
std::vector< double > * m_globalCovZZ
Definition: SpacePointAnalysis.h:56
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
SpacePointAnalysis::m_globalCovYX
std::vector< double > * m_globalCovYX
Definition: SpacePointAnalysis.h:59
SpacePointAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: SpacePointAnalysis.h:72
ReadHandle.h
Handle class for reading from StoreGate.
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
fillSCTHists.etaMod
etaMod
Definition: fillSCTHists.py:23
SpacePointAnalysis::m_globalCovYZ
std::vector< double > * m_globalCovYZ
Definition: SpacePointAnalysis.h:60
PixelID::phi_module
int phi_module(const Identifier &id) const
Definition: PixelID.h:644
SpacePointAnalysis::m_stripID
const SCT_ID * m_stripID
Definition: SpacePointAnalysis.h:40
SpacePointAnalysis::m_isNextToInnermost
std::vector< int > * m_isNextToInnermost
Definition: SpacePointAnalysis.h:48
SpacePointAnalysis::m_phiModule
std::vector< int > * m_phiModule
Definition: SpacePointAnalysis.h:44
SpacePointAnalysis::m_globalCovZY
std::vector< double > * m_globalCovZY
Definition: SpacePointAnalysis.h:62
Identifier
Definition: IdentifierFieldParser.cxx:14