ATLAS Offline Software
AFPHitAnalysis.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 "AFPHitAnalysis.h"
6 
9 
10 #include "TH1.h"
11 #include "TTree.h"
12 #include "TString.h"
13 
14 #include <algorithm>
15 #include <math.h>
16 #include <functional>
17 #include <iostream>
18 #include <stdio.h>
19 
20 AFPHitAnalysis::AFPHitAnalysis(const std::string& name, ISvcLocator* pSvcLocator)
21  : AthAlgorithm(name, pSvcLocator)
22  , m_h_hitID(0)
23  , m_h_pdgID(0)
24  , m_h_trackID(0)
25  , m_h_kine(0)
26  , m_h_edep(0)
27  , m_h_stepX(0)
28  , m_h_stepY(0)
29  , m_h_stepZ(0)
30  , m_h_time(0)
31  , m_h_stationID(0)
32  , m_h_detID(0)
33  , m_h_pixelRow(0)
34  , m_h_pixelCol(0)
35  , m_hitID(0)
36  , m_pdgID(0)
37  , m_trackID(0)
38  , m_kine(0)
39  , m_edep(0)
40  , m_stepX(0)
41  , m_stepY(0)
42  , m_stepZ(0)
43  , m_time(0)
44  , m_stationID(0)
45  , m_detID(0)
46  , m_pixelRow(0)
47  , m_pixelCol(0)
48  , m_tree(0)
49  , m_ntupleFileName("/AFPHitAnalysis/")
50  , m_path("/AFPHitAnalysis/")
51  , m_thistSvc("THistSvc", name)
52 {
53  declareProperty("NtupleFileName", m_ntupleFileName);
54  declareProperty("HistPath", m_path);
55 }
56 
57 
59  ATH_MSG_DEBUG( "Initializing AFPHitAnalysis" );
60 
61  // Grab the Ntuple and histogramming service for the tree
62  CHECK(m_thistSvc.retrieve());
63 
65  m_h_hitID = new TH1D("h_hitID", "hitID",100, 0., 100.);
66  m_h_hitID->StatOverflows();
67  CHECK(m_thistSvc->regHist(m_path+m_h_hitID->GetName(), m_h_hitID));
68 
69  m_h_pdgID = new TH1D("h_pdgID", "pdgID", 200, -100,100);
70  m_h_pdgID->StatOverflows();
71  CHECK(m_thistSvc->regHist(m_path+m_h_pdgID->GetName(), m_h_pdgID));
72 
73  m_h_trackID = new TH1D("h_trackID", "trackID", 100, 0,100);
74  m_h_trackID->StatOverflows();
75  CHECK(m_thistSvc->regHist(m_path+m_h_trackID->GetName(), m_h_trackID));
76 
77  m_h_kine = new TH1D("h_kine", "kine", 100, 0,1000);
78  m_h_kine->StatOverflows();
79  CHECK(m_thistSvc->regHist(m_path+m_h_kine->GetName(), m_h_kine));
80 
81  m_h_edep = new TH1D("h_edep", "edep", 100, 0,1000);
82  m_h_edep->StatOverflows();
83  CHECK(m_thistSvc->regHist(m_path+m_h_edep->GetName(), m_h_edep));
84 
85  m_h_stepX = new TH1D("h_stepX", "stepX", 100, 0,1000);
86  m_h_stepX->StatOverflows();
87  CHECK(m_thistSvc->regHist(m_path+m_h_stepX->GetName(), m_h_stepX));
88 
89  m_h_stepY = new TH1D("h_stepY", "stepY", 100, 0,1000);
90  m_h_stepY->StatOverflows();
91  CHECK(m_thistSvc->regHist(m_path+m_h_stepY->GetName(), m_h_stepY));
92 
93  m_h_stepZ = new TH1D("h_stepZ", "stepZ", 100, 0,1000);
94  m_h_stepZ->StatOverflows();
95  CHECK(m_thistSvc->regHist(m_path+m_h_stepZ->GetName(), m_h_stepZ));
96 
97  m_h_stationID = new TH1D("h_stationID", "stationID", 50, 0,50);
98  m_h_stationID->StatOverflows();
99  CHECK(m_thistSvc->regHist(m_path+m_h_stationID->GetName(), m_h_stationID));
100 
101  m_h_detID = new TH1D("h_detID", "detID", 50, 0,50);
102  m_h_detID->StatOverflows();
103  CHECK(m_thistSvc->regHist(m_path+m_h_detID->GetName(), m_h_detID));
104 
105  m_h_pixelRow = new TH1D("h_pixelRow", "pixelRow", 20, 0,20);
106  m_h_pixelRow->StatOverflows();
107  CHECK(m_thistSvc->regHist(m_path+m_h_pixelRow->GetName(), m_h_pixelRow));
108 
109  m_h_pixelCol = new TH1D("h_pixelCol", "pixelCol", 20, 0,20);
110  m_h_pixelCol->StatOverflows();
111  CHECK(m_thistSvc->regHist(m_path+m_h_pixelCol->GetName(), m_h_pixelCol));
112 
114  m_tree = new TTree("AFP","AFP");
115  std::string fullNtupleName = "/" + m_ntupleFileName + "/";
116  CHECK(m_thistSvc->regTree(fullNtupleName,m_tree));
117 
118  if (m_tree){
119  m_tree->Branch("hitID", &m_hitID);
120  m_tree->Branch("pdgID", &m_pdgID);
121  m_tree->Branch("trackID", &m_trackID);
122  m_tree->Branch("kine", &m_kine);
123  m_tree->Branch("edep", &m_edep);
124  m_tree->Branch("stepX", &m_stepX);
125  m_tree->Branch("stepY", &m_stepY);
126  m_tree->Branch("stepZ", &m_stepZ);
127  m_tree->Branch("stationID", &m_stationID);
128  m_tree->Branch("detID", &m_detID);
129  m_tree->Branch("pixelRow", &m_pixelRow);
130  m_tree->Branch("pixelCol", &m_pixelCol);
131  }
132  else {
133  ATH_MSG_ERROR("No tree found!");
134  }
135 
136  ATH_MSG_INFO("Exiting AFPHitAnalysis::initialize()");
137 
138  return StatusCode::SUCCESS;
139 }
140 
141 
143  ATH_MSG_DEBUG( "In AFPHitAnalysis::execute()" );
144 
145  m_hitID->clear();
146  m_pdgID->clear();
147  m_trackID->clear();
148  m_kine->clear();
149  m_edep->clear();
150  m_stepX->clear();
151  m_stepY->clear();
152  m_stepZ->clear();
153  m_time->clear();
154  m_stationID->clear();
155  m_detID->clear();
156  m_pixelRow->clear();
157  m_pixelCol->clear();
158 
159  ATH_MSG_INFO( "AFPHitAnalysis tree branches cleared" );
160 
162  const AFP_SIDSimHitCollection* iter;
163  CHECK( evtStore()->retrieve(iter,"AFP_SIDSimHitCollection") );
164 
165  ATH_MSG_DEBUG( "AFP_SIDSSimHitCollection retrieved" );
166 
167  for ( hi=(*iter).begin(); hi != (*iter).end(); ++hi ) {
168  AFP_SIDSimHit ghit(*hi);
169  m_h_hitID->Fill(ghit.m_nHitID);
171  m_h_trackID->Fill(ghit.m_nTrackID);
177  m_h_time->Fill(ghit.m_fGlobalTime);
182 
183  m_hitID->push_back(ghit.m_nHitID);
184  m_pdgID->push_back(ghit.m_nParticleEncoding);
185  m_trackID->push_back(ghit.m_nTrackID);
186  m_kine->push_back(ghit.m_fKineticEnergy);
187  m_edep->push_back(ghit.m_fEnergyDeposit);
188  m_stepX->push_back(ghit.m_fPostStepX-ghit.m_fPreStepX);
189  m_stepY->push_back(ghit.m_fPostStepY-ghit.m_fPreStepY);
190  m_stepX->push_back(ghit.m_fPostStepZ-ghit.m_fPreStepZ);
191  m_time->push_back(ghit.m_fGlobalTime);
192  m_stationID->push_back(ghit.m_nStationID);
193  m_detID->push_back(ghit.m_nDetectorID);
194  m_pixelRow->push_back(ghit.m_nPixelRow);
195  m_pixelCol->push_back(ghit.m_nPixelCol);
196  }
197 
198  if (m_tree) m_tree->Fill();
199 
200  return StatusCode::SUCCESS;
201 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AFP_SIDSimHit::m_fPreStepX
float m_fPreStepX
Definition: AFP_SIDSimHit.h:22
AFP_SIDSimHitConstIter
AtlasHitsVector< AFP_SIDSimHit >::const_iterator AFP_SIDSimHitConstIter
Definition: AFP_SIDSimHitCollection.h:15
AFPHitAnalysis.h
AFP_SIDSimHit::m_nHitID
int m_nHitID
Definition: AFP_SIDSimHit.h:17
AFP_SIDSimHit::m_fKineticEnergy
float m_fKineticEnergy
Definition: AFP_SIDSimHit.h:20
AFP_SIDSimHit::m_fPostStepY
float m_fPostStepY
Definition: AFP_SIDSimHit.h:26
AFP_SIDSimHit
Definition: AFP_SIDSimHit.h:9
AFPHitAnalysis::m_stepY
std::vector< float > * m_stepY
Definition: AFPHitAnalysis.h:55
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AFPHitAnalysis::m_h_stepX
TH1 * m_h_stepX
Definition: AFPHitAnalysis.h:40
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AtlasHitsVector< AFP_SIDSimHit >
TH1D
Definition: rootspy.cxx:342
AFPHitAnalysis::m_path
std::string m_path
Definition: AFPHitAnalysis.h:65
AFPHitAnalysis::m_h_pdgID
TH1 * m_h_pdgID
Definition: AFPHitAnalysis.h:36
AFPHitAnalysis::m_h_stationID
TH1 * m_h_stationID
Definition: AFPHitAnalysis.h:44
AFPHitAnalysis::m_h_pixelRow
TH1 * m_h_pixelRow
Definition: AFPHitAnalysis.h:46
AFP_SIDSimHit::m_fEnergyDeposit
float m_fEnergyDeposit
Definition: AFP_SIDSimHit.h:21
AFPHitAnalysis::m_edep
std::vector< float > * m_edep
Definition: AFPHitAnalysis.h:53
AFPHitAnalysis::m_h_time
TH1 * m_h_time
Definition: AFPHitAnalysis.h:43
AFPHitAnalysis::execute
virtual StatusCode execute()
Definition: AFPHitAnalysis.cxx:142
AFPHitAnalysis::m_h_stepZ
TH1 * m_h_stepZ
Definition: AFPHitAnalysis.h:42
AFPHitAnalysis::m_stationID
std::vector< int > * m_stationID
Definition: AFPHitAnalysis.h:58
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AFP_SIDSimHit::m_nStationID
int m_nStationID
Definition: AFP_SIDSimHit.h:30
AFP_SIDSimHit::m_nPixelRow
int m_nPixelRow
Definition: AFP_SIDSimHit.h:34
AFP_SIDSimHit::m_fPostStepX
float m_fPostStepX
Definition: AFP_SIDSimHit.h:25
AFPHitAnalysis::m_tree
TTree * m_tree
Definition: AFPHitAnalysis.h:63
AFPHitAnalysis::m_h_detID
TH1 * m_h_detID
Definition: AFPHitAnalysis.h:45
AFP_SIDSimHit::m_fPostStepZ
float m_fPostStepZ
Definition: AFP_SIDSimHit.h:27
AFPHitAnalysis::m_pdgID
std::vector< float > * m_pdgID
Definition: AFPHitAnalysis.h:50
AFP_SIDSimHit::m_nDetectorID
int m_nDetectorID
Definition: AFP_SIDSimHit.h:31
AFPHitAnalysis::m_ntupleFileName
std::string m_ntupleFileName
Definition: AFPHitAnalysis.h:64
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AFPHitAnalysis::m_trackID
std::vector< float > * m_trackID
Definition: AFPHitAnalysis.h:51
AFPHitAnalysis::m_h_pixelCol
TH1 * m_h_pixelCol
Definition: AFPHitAnalysis.h:47
AFPHitAnalysis::m_stepZ
std::vector< float > * m_stepZ
Definition: AFPHitAnalysis.h:56
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AFPHitAnalysis::m_h_edep
TH1 * m_h_edep
Definition: AFPHitAnalysis.h:39
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
m_path
std::string m_path
the path being used
Definition: OutputStreamData.cxx:88
AFP_SIDSimHit::m_fPreStepY
float m_fPreStepY
Definition: AFP_SIDSimHit.h:23
AFPHitAnalysis::m_stepX
std::vector< float > * m_stepX
Definition: AFPHitAnalysis.h:54
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AFPHitAnalysis::m_h_trackID
TH1 * m_h_trackID
Definition: AFPHitAnalysis.h:37
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
AFPHitAnalysis::initialize
virtual StatusCode initialize()
Definition: AFPHitAnalysis.cxx:58
AthAlgorithm
Definition: AthAlgorithm.h:47
AFPHitAnalysis::AFPHitAnalysis
AFPHitAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: AFPHitAnalysis.cxx:20
AFPHitAnalysis::m_kine
std::vector< float > * m_kine
Definition: AFPHitAnalysis.h:52
AFPHitAnalysis::m_pixelRow
std::vector< int > * m_pixelRow
Definition: AFPHitAnalysis.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AFP_SIDSimHit::m_nTrackID
int m_nTrackID
Definition: AFP_SIDSimHit.h:18
AFP_SIDSimHit::m_fPreStepZ
float m_fPreStepZ
Definition: AFP_SIDSimHit.h:24
AFPHitAnalysis::m_time
std::vector< float > * m_time
Definition: AFPHitAnalysis.h:57
AFP_SIDSimHitCollection.h
AFPHitAnalysis::m_h_stepY
TH1 * m_h_stepY
Definition: AFPHitAnalysis.h:41
AFPHitAnalysis::m_h_hitID
TH1 * m_h_hitID
Some histograms.
Definition: AFPHitAnalysis.h:35
AFPHitAnalysis::m_hitID
std::vector< float > * m_hitID
Definition: AFPHitAnalysis.h:49
AFP_SIDSimHit::m_fGlobalTime
float m_fGlobalTime
Definition: AFP_SIDSimHit.h:28
AFPHitAnalysis::m_pixelCol
std::vector< int > * m_pixelCol
Definition: AFPHitAnalysis.h:61
AFPHitAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: AFPHitAnalysis.h:66
AFPHitAnalysis::m_detID
std::vector< int > * m_detID
Definition: AFPHitAnalysis.h:59
AFP_SIDSimHit::m_nPixelCol
int m_nPixelCol
Definition: AFP_SIDSimHit.h:35
AFP_SIDSimHit::m_nParticleEncoding
int m_nParticleEncoding
Definition: AFP_SIDSimHit.h:19
AFPHitAnalysis::m_h_kine
TH1 * m_h_kine
Definition: AFPHitAnalysis.h:38
AFP_SIDSimHit.h