ATLAS Offline Software
ALFAHitAnalysis.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 "ALFAHitAnalysis.h"
6 
7 // Section of includes for Pixel and SCT tests
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 
19 ALFAHitAnalysis::ALFAHitAnalysis(const std::string& name, ISvcLocator* pSvcLocator)
20  : AthAlgorithm(name, pSvcLocator)
21  , m_station(0)
22  , m_plate(0)
23  , m_fiber(0)
24  , m_sign(0)
25  , m_energy(0)
26 
27  , m_tree(0)
28  , m_ntupleFileName("/ALFAHitsAnalysis/")
29  , m_path("/ALFAHitsAnalysis/")
30  , m_thistSvc("THistSvc", name)
31 {
32  for (int i(0); i<8; i++) {
35  m_h_hit_layer[i]=0;
36  m_h_hit_fiber[i]=0;
37  }
38  declareProperty("NtupleFileName", m_ntupleFileName);
39  declareProperty("HistPath", m_path);
40 }
41 
42 
44  ATH_MSG_DEBUG( "Initializing ALFAHitAnalysis" );
45 
46  // Grab the Ntuple and histogramming service for the tree
47  CHECK(m_thistSvc.retrieve());
48 
50  std::stringstream s;
51  for (unsigned int j=0; j<8; j++) {
52  s.str("");
53  s << "edep_in_det_no." << j+1;
54  float Emax = 5;
55  if (j==3) Emax = 150;
56  m_h_E_full_sum_h[j] = new TH1D(s.str().c_str(), s.str().c_str(), 100, 0, Emax);
57  m_h_E_full_sum_h[j]->StatOverflows();
58  CHECK( m_thistSvc->regHist( m_path + m_h_E_full_sum_h[j]->GetName(), m_h_E_full_sum_h[j] ) );
59 
60  s.str("");
61  s << "edep_per_layer_det_no." << j+1;
62  m_h_E_layer_sum_h[j] = new TH1D(s.str().c_str(), s.str().c_str(), 100, 0, 15);
63  m_h_E_layer_sum_h[j]->StatOverflows();
64  CHECK( m_thistSvc->regHist( m_path + m_h_E_layer_sum_h[j]->GetName(), m_h_E_layer_sum_h[j] ) );
65 
66  s.str("");
67  s << "hit_layer_det_no." << j+1;
68  m_h_hit_layer[j] = new TH1D(s.str().c_str(), s.str().c_str(), 50, 0, 50);
69  m_h_hit_layer[j]->StatOverflows();
70  CHECK( m_thistSvc->regHist( m_path + m_h_hit_layer[j]->GetName(), m_h_hit_layer[j] ) );
71 
72  s.str("");
73  s << "hit_fiber_det_no." << j+1;
74  m_h_hit_fiber[j] = new TH1D(s.str().c_str(), s.str().c_str(), 100, 0, 60);
75  m_h_hit_fiber[j]->StatOverflows();
76  CHECK( m_thistSvc->regHist( m_path + m_h_hit_fiber[j]->GetName(), m_h_hit_fiber[j] ) );
77  }
78 
79  m_tree = new TTree("ALFA", "ALFA");
80  std::string fullNtupleName = "/" + m_ntupleFileName + "/" ;
81  CHECK(m_thistSvc->regTree(fullNtupleName,m_tree));
82 
83  if (m_tree) {
84  m_tree->Branch("station", &m_station);
85  m_tree->Branch("plate", &m_plate);
86  m_tree->Branch("fiber", &m_fiber);
87  m_tree->Branch("energy", &m_energy);
88  }
89  else {
90  ATH_MSG_ERROR("No tree found!");
91  }
92 
93  return StatusCode::SUCCESS;
94 }
95 
96 
98  ATH_MSG_DEBUG( "In ALFAHitAnalysis::execute()" );
99 
100  m_station->clear();
101  m_plate->clear();
102  m_fiber->clear();
103  m_sign->clear();
104  m_energy->clear();
105 
106  //cleaning
107  int fiber, plate, sign, station;
108  double E_fiber_sum[8][10][64][2], E_full_sum[8], E_layer_sum[8][20];
109  for (int l= 0; l<8; l++) {
110  E_full_sum[l] = 0.;
111  for (int i = 0; i < 10; i++) {
112  E_layer_sum[l][i] = 0.;
113  E_layer_sum[l][i+10] = 0.;
114  for (int j = 0; j < 64; j++) {
115  for (int k = 0; k < 2; k++) {
116  E_fiber_sum[l][i][j][k] = 0.;
117  }
118  }
119  }
120  }
121 
122  ALFA_HitConstIter iter;
123  const ALFA_HitCollection* col_alfa;
124  CHECK( evtStore()->retrieve( col_alfa, "ALFA_HitCollection" ) );
125  for (iter = (*col_alfa).begin(); iter != (*col_alfa).end(); ++iter) {
126  station = (*iter).GetStationNumber();
127  plate = (*iter).GetPlateNumber();
128  fiber = (*iter).GetFiberNumber();
129  sign = (*iter).GetSignFiber();
130  E_fiber_sum[station-1][plate-1][fiber-1][(1-sign)/2] += ((*iter).GetEnergyDeposit());
131 
132  m_station->push_back(station);
133  m_plate->push_back(plate);
134  m_fiber->push_back(fiber);
135  m_sign->push_back(sign);
136  m_energy->push_back((*iter).GetEnergyDeposit());
137  } // End iteration
138 
139  for (int l=0; l<8; l++){
140  for (int i=0; i<10; i++){
141  for (int j=0; j<64; j++){
142  for (int k=0; k<2; k++){
143  E_full_sum[l] += E_fiber_sum[l][i][j][k];
144  E_layer_sum[l][2*i+k] += E_fiber_sum[l][i][j][k];
145  if (E_fiber_sum[l][i][j][k] > 0.) {
146  m_h_hit_layer[l]->Fill(2*i+k+1);
147  m_h_hit_fiber[l]->Fill(j+1);
148  }
149  }
150  }
151  }
152  }
153  for (int l=0; l<8; l++) {
154  m_h_E_full_sum_h[l]->Fill(E_full_sum[l]);
155  for (int i = 0; i< 20; i++) {
156  m_h_E_layer_sum_h[l]->Fill(E_layer_sum[l][i]);
157  }
158  }
159 
160  if (m_tree) m_tree->Fill();
161 
162  return StatusCode::SUCCESS;
163 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ALFAHitAnalysis::execute
virtual StatusCode execute()
Definition: ALFAHitAnalysis.cxx:97
ALFAHitAnalysis::m_h_hit_fiber
TH1 * m_h_hit_fiber[8]
Definition: ALFAHitAnalysis.h:38
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ALFAHitAnalysis::m_fiber
std::vector< int > * m_fiber
Definition: ALFAHitAnalysis.h:42
ALFAHitAnalysis::m_plate
std::vector< int > * m_plate
Definition: ALFAHitAnalysis.h:41
ALFAHitAnalysis.h
ALFAHitAnalysis::m_h_hit_layer
TH1 * m_h_hit_layer[8]
Definition: ALFAHitAnalysis.h:37
AtlasHitsVector
Definition: AtlasHitsVector.h:33
TH1D
Definition: rootspy.cxx:342
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
ALFA_HitConstIter
AtlasHitsVector< ALFA_Hit >::const_iterator ALFA_HitConstIter
Definition: ALFA_HitCollection.h:15
ALFAHitAnalysis::m_tree
TTree * m_tree
Definition: ALFAHitAnalysis.h:48
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ALFAHitAnalysis::m_path
std::string m_path
Definition: ALFAHitAnalysis.h:50
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ALFAHitAnalysis::m_h_E_layer_sum_h
TH1 * m_h_E_layer_sum_h[8]
Definition: ALFAHitAnalysis.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:92
ALFAHitAnalysis::initialize
virtual StatusCode initialize()
Definition: ALFAHitAnalysis.cxx:43
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
m_path
std::string m_path
the path being used
Definition: OutputStreamData.cxx:88
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:127
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
ALFAHitAnalysis::m_energy
std::vector< double > * m_energy
Definition: ALFAHitAnalysis.h:44
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ALFAHitAnalysis::m_sign
std::vector< int > * m_sign
Definition: ALFAHitAnalysis.h:43
ALFA_HitCollection.h
GlobalVariables.Emax
Emax
Definition: GlobalVariables.py:185
ALFAHitAnalysis::m_ntupleFileName
std::string m_ntupleFileName
Definition: ALFAHitAnalysis.h:49
ALFAHitAnalysis::m_station
std::vector< int > * m_station
Definition: ALFAHitAnalysis.h:40
ALFAHitAnalysis::m_h_E_full_sum_h
TH1 * m_h_E_full_sum_h[8]
Some variables.
Definition: ALFAHitAnalysis.h:35
ALFAHitAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: ALFAHitAnalysis.h:51
fitman.k
k
Definition: fitman.py:528
ALFAHitAnalysis::ALFAHitAnalysis
ALFAHitAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ALFAHitAnalysis.cxx:19