ATLAS Offline Software
PixelClusterAnalysis.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 "PixelClusterAnalysis.h"
6 #include "StoreGate/ReadHandle.h"
7 #include "GaudiKernel/EventContext.h"
8 
9 #include "TTree.h"
10 #include "TString.h"
11 
12 #include <algorithm>
13 #include <cmath>
14 #include <functional>
15 #include <iostream>
16 
17 PixelClusterAnalysis::PixelClusterAnalysis(const std::string& name, ISvcLocator *pSvcLocator)
18 : AthAlgorithm(name, pSvcLocator) {}
19 
21  ATH_MSG_DEBUG( "Initializing PixelClusterAnalysis" );
22 
24 
25  ATH_CHECK(detStore()->retrieve(m_pixelID, "PixelID"));
26 
27  ATH_CHECK(m_thistSvc.retrieve());
28 
29  m_tree = new TTree(TString(m_ntupleTreeName.value()), "PixelClusterAna");
30  std::string fullNtupleName = m_ntupleFileName.value() + m_ntupleDirName.value() + m_ntupleTreeName.value();
31  ATH_CHECK(m_thistSvc->regTree(fullNtupleName, m_tree));
32 
33  if (m_tree) {
34  m_tree->Branch("barrelEndcap", &m_barrelEndcap);
35  m_tree->Branch("layerDisk", &m_layerDisk);
36  m_tree->Branch("phiModule", &m_phiModule);
37  m_tree->Branch("etaModule", &m_etaModule);
38  m_tree->Branch("isInnermost", &m_isInnermost);
39  m_tree->Branch("isNextToInnermost", &m_isNextToInnermost);
40  m_tree->Branch("eta", &m_eta);
41  m_tree->Branch("globalX", &m_globalX);
42  m_tree->Branch("globalY", &m_globalY);
43  m_tree->Branch("globalZ", &m_globalZ);
44  m_tree->Branch("localX", &m_localX);
45  m_tree->Branch("localY", &m_localY);
46  m_tree->Branch("localCovXX", &m_localCovXX);
47  m_tree->Branch("localCovYY", &m_localCovYY);
48  m_tree->Branch("sizeX", &m_sizeX);
49  m_tree->Branch("sizeY", &m_sizeY);
50  } else {
51  ATH_MSG_ERROR("No tree found!");
52  }
53 
54  m_h_globalZR = new TH2F("h_globalZR","h_globalZR; z [mm]; r [mm]",1500,-3000.,3000,400,0.,400);
55  ATH_CHECK(m_thistSvc->regHist(m_path.value() + m_h_globalZR->GetName(), m_h_globalZR));
56 
57  m_h_etaCluster = new TH1F("m_h_etaCluster","m_h_etaCluster; cluster #eta",100, -5, 5);
58  ATH_CHECK(m_thistSvc->regHist(m_path.value() + m_h_etaCluster->GetName(), m_h_etaCluster));
59 
60  return StatusCode::SUCCESS;
61 }
62 
64  ATH_MSG_DEBUG(" In PixelClusterAnalysis::execute()" );
65 
66  m_barrelEndcap->clear();
67  m_layerDisk->clear();
68  m_phiModule->clear();
69  m_etaModule->clear();
70  m_isInnermost->clear();
71  m_isNextToInnermost->clear();
72  m_eta->clear();
73  m_globalX->clear();
74  m_globalY->clear();
75  m_globalZ->clear();
76  m_localX->clear();
77  m_localY->clear();
78  m_localCovXX->clear();
79  m_localCovYY->clear();
80  m_sizeX->clear();
81  m_sizeY->clear();
82 
83  const EventContext& ctx = Algorithm::getContext();
84 
86  if(pixelContainer.isValid()) {
87  for( const InDet::PixelClusterCollection* pixelCollection : *pixelContainer) {
88  if (!pixelCollection) continue;
89  for( const InDet::PixelCluster* pCluster : *pixelCollection) {
90  const Identifier idColl(pixelCollection->identify());
91  const int pixBrlEc(m_pixelID->barrel_ec(idColl));
92  const int pixLayerDisk(m_pixelID->layer_disk(idColl));
93  const int pixPhiMod(m_pixelID->phi_module(idColl));
94  const int pixEtaMod(m_pixelID->eta_module(idColl));
95 
96  bool isInnermost = (pixLayerDisk==0);
97  bool isNextToInnermost = (pixLayerDisk==1) or (pixBrlEc!=0 and pixLayerDisk==2);
98 
99  m_barrelEndcap->push_back(pixBrlEc);
100  m_layerDisk->push_back(pixLayerDisk);
101  m_phiModule->push_back(pixPhiMod);
102  m_etaModule->push_back(pixEtaMod);
103  m_isInnermost->push_back(int(isInnermost));
104  m_isNextToInnermost->push_back(int(isNextToInnermost));
105 
106  auto localPos = pCluster->localPosition();
107  auto localCov = pCluster->localCovariance();
108  auto globalPos = pCluster->globalPosition();
109  auto width = pCluster->width();
110 
111  m_eta->push_back(globalPos.eta());
112  m_globalX->push_back(globalPos.x());
113  m_globalY->push_back(globalPos.y());
114  m_globalZ->push_back(globalPos.z());
115 
116  m_localX->push_back(localPos[0]);
117  m_localY->push_back(localPos[1]);
118 
119  m_localCovXX->push_back(localCov(0, 0));
120  m_localCovYY->push_back(localCov(1, 1));
121 
122  m_sizeX->push_back(width.colRow()[0]);
123  m_sizeY->push_back(width.colRow()[1]);
124 
125  m_h_globalZR->Fill(globalPos.z(), globalPos.perp());
126  m_h_etaCluster->Fill(globalPos.eta());
127 
128  }
129  }
130  }
131 
132  if (m_tree) {
133  m_tree->Fill();
134  }
135 
136  return StatusCode::SUCCESS;
137 }
PixelClusterAnalysis::m_etaModule
std::vector< int > * m_etaModule
Definition: PixelClusterAnalysis.h:42
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelClusterAnalysis::m_sizeY
std::vector< int > * m_sizeY
Definition: PixelClusterAnalysis.h:54
PixelClusterAnalysis::m_localCovXX
std::vector< double > * m_localCovXX
Definition: PixelClusterAnalysis.h:51
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
PixelClusterAnalysis::m_h_globalZR
TH2 * m_h_globalZR
Definition: PixelClusterAnalysis.h:56
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
PixelClusterAnalysis::m_inputKey
SG::ReadHandleKey< InDet::PixelClusterContainer > m_inputKey
Definition: PixelClusterAnalysis.h:36
PixelClusterAnalysis::m_isNextToInnermost
std::vector< int > * m_isNextToInnermost
Definition: PixelClusterAnalysis.h:44
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
PixelClusterAnalysis::m_pixelID
const PixelID * m_pixelID
Definition: PixelClusterAnalysis.h:37
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
PixelClusterAnalysis::m_path
StringProperty m_path
Definition: PixelClusterAnalysis.h:63
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
PixelClusterAnalysis.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PixelClusterAnalysis::execute
virtual StatusCode execute() override final
Definition: PixelClusterAnalysis.cxx:63
PixelClusterAnalysis::m_layerDisk
std::vector< int > * m_layerDisk
Definition: PixelClusterAnalysis.h:40
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
PixelClusterAnalysis::m_globalZ
std::vector< double > * m_globalZ
Definition: PixelClusterAnalysis.h:48
PixelClusterAnalysis::m_h_etaCluster
TH1 * m_h_etaCluster
Definition: PixelClusterAnalysis.h:57
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
PixelClusterAnalysis::m_localCovYY
std::vector< double > * m_localCovYY
Definition: PixelClusterAnalysis.h:52
PixelID::eta_module
int eta_module(const Identifier &id) const
Definition: PixelID.h:651
PixelClusterAnalysis::m_localX
std::vector< double > * m_localX
Definition: PixelClusterAnalysis.h:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
PixelClusterAnalysis::m_localY
std::vector< double > * m_localY
Definition: PixelClusterAnalysis.h:50
PixelClusterAnalysis::m_ntupleTreeName
StringProperty m_ntupleTreeName
Definition: PixelClusterAnalysis.h:62
InDet::PixelCluster
Definition: InnerDetector/InDetRecEvent/InDetPrepRawData/InDetPrepRawData/PixelCluster.h:49
PixelClusterAnalysis::m_eta
std::vector< double > * m_eta
Definition: PixelClusterAnalysis.h:45
PixelClusterAnalysis::m_barrelEndcap
std::vector< int > * m_barrelEndcap
Definition: PixelClusterAnalysis.h:39
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
PixelClusterAnalysis::m_sizeX
std::vector< int > * m_sizeX
Definition: PixelClusterAnalysis.h:53
PixelClusterAnalysis::PixelClusterAnalysis
PixelClusterAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PixelClusterAnalysis.cxx:17
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
PixelClusterAnalysis::m_globalX
std::vector< double > * m_globalX
Definition: PixelClusterAnalysis.h:46
ReadHandle.h
Handle class for reading from StoreGate.
PixelClusterAnalysis::m_isInnermost
std::vector< int > * m_isInnermost
Definition: PixelClusterAnalysis.h:43
PixelID::phi_module
int phi_module(const Identifier &id) const
Definition: PixelID.h:644
PixelClusterAnalysis::m_globalY
std::vector< double > * m_globalY
Definition: PixelClusterAnalysis.h:47
PixelClusterAnalysis::m_phiModule
std::vector< int > * m_phiModule
Definition: PixelClusterAnalysis.h:41
PixelClusterAnalysis::initialize
virtual StatusCode initialize() override final
Definition: PixelClusterAnalysis.cxx:20
PixelClusterAnalysis::m_ntupleFileName
StringProperty m_ntupleFileName
Definition: PixelClusterAnalysis.h:60
PixelClusterAnalysis::m_tree
TTree * m_tree
Definition: PixelClusterAnalysis.h:59
InDet::PixelClusterCollection
Trk::PrepRawDataCollection< PixelCluster > PixelClusterCollection
Definition: PixelClusterCollection.h:26
PixelClusterAnalysis::m_ntupleDirName
StringProperty m_ntupleDirName
Definition: PixelClusterAnalysis.h:61
PixelClusterAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: PixelClusterAnalysis.h:64
Identifier
Definition: IdentifierFieldParser.cxx:14