ATLAS Offline Software
LArRDOAnalysis.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "LArRDOAnalysis.h"
7 #include "StoreGate/ReadHandle.h"
8 
9 #include "TTree.h"
10 #include "TString.h"
11 
12 #include <algorithm>
13 #include <math.h>
14 #include <functional>
15 #include <iostream>
16 
17 LArRDOAnalysis::LArRDOAnalysis(const std::string& name, ISvcLocator* pSvcLocator)
18  : AthAlgorithm(name, pSvcLocator)
19  , m_inputRawChannelKey("LArRawChannels")
20  , m_inputTTL1HADKey("LArTTL1HAD")
21  , m_inputTTL1EMKey("LArTTL1EM")
22  , m_inputDigitKey("LArDigitContainer_MC_Thinned")
23  , m_larID(0)
24  , m_energy(0)
25  , m_time(0)
26  , m_qual(0)
27  , m_prov(0)
28  , m_gain(0)
29  , m_hadOnID(0)
30  , m_hadOffID(0)
31  , m_hadSamples(0)
32  , m_emOnID(0)
33  , m_emOffID(0)
34  , m_emSamples(0)
35  , m_digiID(0)
36  , m_digiGain(0)
37  , m_digiSamples(0)
38 
39  , m_h_larID(0)
40  , m_h_energy(0)
41  , m_h_time(0)
42  , m_h_qual(0)
43  , m_h_prov(0)
44  , m_h_gain(0)
45  , m_h_hadOnID(0)
46  , m_h_hadOffID(0)
47  , m_h_hadSamples(0)
48  , m_h_emOnID(0)
49  , m_h_emOffID(0)
50  , m_h_emSamples(0)
51  , m_h_digiID(0)
52  , m_h_digiGain(0)
53  , m_h_digiSamples(0)
54 
55  , m_tree(0)
56  , m_ntupleFileName("/ntuples/file1")
57  , m_ntupleDirName("/LArRDOAnalysis/")
58  , m_ntupleTreeName("LArRDOAna")
59  , m_path("/LArRDOAnalysis/")
60  , m_thistSvc("THistSvc", name)
61 {
62  declareProperty("InputRawChannelKey", m_inputRawChannelKey);
63  declareProperty("InputTTL1HADKey", m_inputTTL1HADKey);
64  declareProperty("InputTTL1EMKey", m_inputTTL1EMKey);
65  declareProperty("InputDigitKey", m_inputDigitKey);
66  declareProperty("NtupleFileName", m_ntupleFileName);
67  declareProperty("NtupleDirectoryName", m_ntupleDirName);
68  declareProperty("NtupleTreeName", m_ntupleTreeName);
69  declareProperty("HistPath", m_path);
70 }
71 
73  ATH_MSG_DEBUG( "Initializing LArRDOAnalysis" );
74 
75  // This will check that the properties were initialized
76  // properly by job configuration.
81 
82  // Grab Ntuple and histogramming service for tree
83  ATH_CHECK(m_thistSvc.retrieve());
84 
85  m_tree = new TTree(TString(m_ntupleTreeName), "LArRDOAna");
86  std::string fullNtupleName = m_ntupleFileName + m_ntupleDirName + m_ntupleTreeName;
87  ATH_CHECK(m_thistSvc->regTree(fullNtupleName, m_tree));
88  if (m_tree) {
89  m_tree->Branch("larID", &m_larID);
90  m_tree->Branch("energy", &m_energy);
91  m_tree->Branch("time", &m_time);
92  m_tree->Branch("qual", &m_qual);
93  m_tree->Branch("prov", &m_prov);
94  m_tree->Branch("gain", &m_gain);
95  m_tree->Branch("hadOnID", &m_hadOnID);
96  m_tree->Branch("hadOffID", &m_hadOffID);
97  m_tree->Branch("hadSamples", &m_hadSamples);
98  m_tree->Branch("emOnID", &m_emOnID);
99  m_tree->Branch("emOffID", &m_emOffID);
100  m_tree->Branch("emSamples", &m_emSamples);
101  m_tree->Branch("digiID", &m_digiID);
102  m_tree->Branch("digiGain", &m_digiGain);
103  m_tree->Branch("digiSamples", &m_digiSamples);
104  }
105  else {
106  ATH_MSG_ERROR("No tree found!");
107  }
108 
109  m_h_larID = new TH1F("h_larID", "LAr ID", 100, 0, 5e18);
110  m_h_larID->StatOverflows();
111  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_larID->GetName(), m_h_larID));
112 
113  m_h_energy = new TH1F("h_energy", "LAr energy", 100, -1e5, 5e5);
114  m_h_energy->StatOverflows();
115  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_energy->GetName(), m_h_energy));
116 
117  m_h_time = new TH1F("h_time", "LAr time", 100, -1e7, 1e7);
118  m_h_time->StatOverflows();
119  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_time->GetName(), m_h_time));
120 
121  m_h_qual = new TH1F("h_qual", "LAr quality", 100, 0, 70000);
122  m_h_qual->StatOverflows();
123  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_qual->GetName(), m_h_qual));
124 
125  m_h_prov = new TH1F("h_prov", "LAr provenance", 100, 0, 9000);
126  m_h_prov->StatOverflows();
127  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_prov->GetName(), m_h_prov));
128 
129  m_h_gain = new TH1F("h_gain", "LAr gain", 100, 0, 5);
130  m_h_gain->StatOverflows();
131  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_gain->GetName(), m_h_gain));
132 
133  m_h_hadOnID = new TH1F("h_hadOnID", "Had LAr TTL1 online ID", 100, 0, 3e19);
134  m_h_hadOnID->StatOverflows();
135  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_hadOnID->GetName(), m_h_hadOnID));
136 
137  m_h_hadOffID = new TH1F("h_hadOffID", "Had LAr TTL1 offline ID", 100, 0, 3e19);
138  m_h_hadOffID->StatOverflows();
139  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_hadOffID->GetName(), m_h_hadOffID));
140 
141  m_h_hadSamples = new TH1F("h_hadSamples", "Had LAr TTL1 sample values", 100, -15000, 35000);
142  m_h_hadSamples->StatOverflows();
143  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_hadSamples->GetName(), m_h_hadSamples));
144 
145  m_h_emOnID = new TH1F("h_emOnID", "EM LAr TTL1 online ID", 100, 0, 3e19);
146  m_h_emOnID->StatOverflows();
147  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_emOnID->GetName(), m_h_emOnID));
148 
149  m_h_emOffID = new TH1F("h_emOffID", "EM LAr TTL1 offline ID", 100, 0, 3e19);
150  m_h_emOffID->StatOverflows();
151  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_emOffID->GetName(), m_h_emOffID));
152 
153  m_h_emSamples = new TH1F("h_emSamples", "EM LAr TTL1 sample values", 100, -1e5, 3.5e5);
154  m_h_emSamples->StatOverflows();
155  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_emSamples->GetName(), m_h_emSamples));
156 
157  m_h_digiID = new TH1F("h_digiID", "LAr digit ID", 100, 0, 5e18);
158  m_h_digiID->StatOverflows();
159  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_digiID->GetName(), m_h_digiID));
160 
161  m_h_digiGain = new TH1F("h_digiGain", "LAr digit gain", 100, 0, 5);
162  m_h_digiGain->StatOverflows();
163  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_digiGain->GetName(), m_h_digiGain));
164 
165  m_h_digiSamples = new TH1F("h_digiSamples", "LAr digit sample values", 100, 0, 5000);
166  m_h_digiSamples->StatOverflows();
167  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_digiSamples->GetName(), m_h_digiSamples));
168 
169  return StatusCode::SUCCESS;
170 }
171 
173  ATH_MSG_DEBUG( "In LArRDOAnalysis::execute()" );
174 
175  m_larID->clear();
176  m_energy->clear();
177  m_time->clear();
178  m_qual->clear();
179  m_prov->clear();
180  m_gain->clear();
181  m_hadOnID->clear();
182  m_hadOffID->clear();
183  m_hadSamples->clear();
184  m_emOnID->clear();
185  m_emOffID->clear();
186  m_emSamples->clear();
187  m_digiID->clear();
188  m_digiGain->clear();
189  m_digiSamples->clear();
190 
191  if (!m_presampling)
192  {
193  // LAr Raw Channels
195  if (p_larRawCont.isValid()) {
196  // loop over LAr raw channels container
197  LArRawChannelContainer::const_iterator lar_itr(p_larRawCont->begin());
198  const LArRawChannelContainer::const_iterator lar_end(p_larRawCont->end());
199  for ( ; lar_itr != lar_end; ++lar_itr ) {
200  const HWIdentifier larID(lar_itr->identify());
201  const int rawEnergy(lar_itr->energy());
202  const int rawTime(lar_itr->time());
203  const uint16_t rawQual(lar_itr->quality());
204  const uint16_t rawProv(lar_itr->provenance());
205  CaloGain::CaloGain larGain(lar_itr->gain());
206 
207  const unsigned long long larID_int = larID.get_compact();
208  const int larGain_int = (int)larGain;
209  m_larID->push_back(larID_int);
210  m_energy->push_back(rawEnergy);
211  m_time->push_back(rawTime);
212  m_qual->push_back(rawQual);
213  m_prov->push_back(rawProv);
214  m_gain->push_back(larGain_int);
215 
216  m_h_larID->Fill(larID_int);
217  m_h_energy->Fill(rawEnergy);
218  m_h_time->Fill(rawTime);
219  m_h_qual->Fill(rawQual);
220  m_h_prov->Fill(rawProv);
221  m_h_gain->Fill(larGain_int);
222  }
223  }
224 
225 
226  // LAr TTL1 - Had
228  if (p_larTTL1Cont_had.isValid()) {
229  LArTTL1Container::const_iterator ttl1Had_itr(p_larTTL1Cont_had->begin());
230  const LArTTL1Container::const_iterator ttl1Had_end(p_larTTL1Cont_had->end());
231  for ( ; ttl1Had_itr != ttl1Had_end; ++ttl1Had_itr ) {
232  const HWIdentifier& hadOnID((*ttl1Had_itr)->ttOnlineID());
233  const Identifier& hadOffID((*ttl1Had_itr)->ttOfflineID());
234  const std::vector<float>& hadSamples = (*ttl1Had_itr)->samples();
235 
236  const unsigned long long hadOnID_int = hadOnID.get_compact();
237  const unsigned long long hadOffID_int = hadOffID.get_compact();
238  m_hadOnID->push_back(hadOnID_int);
239  m_hadOffID->push_back(hadOffID_int);
240  for (std::vector<float>::size_type i = 0; i != hadSamples.size(); ++i) {
241  m_hadSamples->push_back(hadSamples.at(i));
242  m_h_hadSamples->Fill(hadSamples.at(i));
243  }
244 
245  m_h_hadOnID->Fill(hadOnID_int);
246  m_h_hadOffID->Fill(hadOffID_int);
247  }
248  }
249 
250  // LAr TTL1 - EM
252  if (p_larTTL1Cont_em.isValid()) {
253  LArTTL1Container::const_iterator ttl1EM_itr(p_larTTL1Cont_em->begin());
254  const LArTTL1Container::const_iterator ttl1EM_end(p_larTTL1Cont_em->end());
255  for ( ; ttl1EM_itr != ttl1EM_end; ++ttl1EM_itr ) {
256  const HWIdentifier& emOnID((*ttl1EM_itr)->ttOnlineID());
257  const Identifier& emOffID((*ttl1EM_itr)->ttOfflineID());
258  const std::vector<float>& emSamples((*ttl1EM_itr)->samples());
259 
260  const unsigned long long emOnID_int = emOnID.get_compact();
261  const unsigned long long emOffID_int = emOffID.get_compact();
262  m_emOnID->push_back(emOnID_int);
263  m_emOffID->push_back(emOffID_int);
264  for (std::vector<float>::size_type j = 0; j != emSamples.size(); ++j) {
265  m_emSamples->push_back(emSamples.at(j));
266  m_h_emSamples->Fill(emSamples.at(j));
267  }
268 
269  m_h_emOnID->Fill(emOnID_int);
270  m_h_emOffID->Fill(emOffID_int);
271  }
272  }
273  }
274 
275  // LAr Digits
277  if (p_larDigiCont.isValid()) {
278  LArDigitContainer::const_iterator digi_itr(p_larDigiCont->begin());
279  const LArDigitContainer::const_iterator digi_end(p_larDigiCont->end());
280  for ( ; digi_itr != digi_end; ++digi_itr ) {
281  const HWIdentifier& digiID((*digi_itr)->hardwareID());
282  CaloGain::CaloGain digiGain((*digi_itr)->gain());
283  const std::vector<short>& digiSamples = (*digi_itr)->samples();
284 
285  const unsigned long long digiID_int = digiID.get_compact();
286  const int digiGain_int = (int)digiGain;
287  m_digiID->push_back(digiID_int);
288  m_digiGain->push_back(digiGain_int);
289  for (std::vector<short>::size_type k = 0; k != digiSamples.size(); ++k) {
290  m_digiSamples->push_back(digiSamples.at(k));
291  m_h_digiSamples->Fill(digiSamples.at(k));
292  }
293 
294  m_h_digiID->Fill(digiID_int);
295  m_h_digiGain->Fill(digiGain_int);
296  }
297  }
298 
299  if (m_tree) {
300  m_tree->Fill();
301  }
302 
303  return StatusCode::SUCCESS;
304 }
305 
307  return StatusCode::SUCCESS;
308 }
LArRDOAnalysis::m_gain
std::vector< int > * m_gain
Definition: LArRDOAnalysis.h:48
LArRDOAnalysis::finalize
virtual StatusCode finalize() override final
Definition: LArRDOAnalysis.cxx:306
LArRDOAnalysis::m_h_qual
TH1 * m_h_qual
Definition: LArRDOAnalysis.h:65
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
LArRDOAnalysis::m_hadOnID
std::vector< unsigned long long > * m_hadOnID
Definition: LArRDOAnalysis.h:50
LArRDOAnalysis::m_inputTTL1EMKey
SG::ReadHandleKey< LArTTL1Container > m_inputTTL1EMKey
Definition: LArRDOAnalysis.h:38
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArRDOAnalysis::initialize
virtual StatusCode initialize() override final
Definition: LArRDOAnalysis.cxx:72
LArRDOAnalysis::m_h_emOffID
TH1 * m_h_emOffID
Definition: LArRDOAnalysis.h:72
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArRDOAnalysis::m_qual
std::vector< uint16_t > * m_qual
Definition: LArRDOAnalysis.h:46
LArRDOAnalysis::m_h_time
TH1 * m_h_time
Definition: LArRDOAnalysis.h:64
LArRDOAnalysis::m_time
std::vector< int > * m_time
Definition: LArRDOAnalysis.h:45
LArRDOAnalysis::m_prov
std::vector< uint16_t > * m_prov
Definition: LArRDOAnalysis.h:47
LArRDOAnalysis::m_h_hadOffID
TH1 * m_h_hadOffID
Definition: LArRDOAnalysis.h:69
LArRDOAnalysis::m_hadOffID
std::vector< unsigned long long > * m_hadOffID
Definition: LArRDOAnalysis.h:51
LArRDOAnalysis::m_h_emSamples
TH1 * m_h_emSamples
Definition: LArRDOAnalysis.h:73
HWIdentifier
Definition: HWIdentifier.h:13
LArRDOAnalysis::m_hadSamples
std::vector< float > * m_hadSamples
Definition: LArRDOAnalysis.h:52
LArRDOAnalysis::m_h_emOnID
TH1 * m_h_emOnID
Definition: LArRDOAnalysis.h:71
LArRDOAnalysis::m_h_hadSamples
TH1 * m_h_hadSamples
Definition: LArRDOAnalysis.h:70
LArRDOAnalysis::m_h_digiID
TH1 * m_h_digiID
Definition: LArRDOAnalysis.h:74
LArRDOAnalysis.h
LArRDOAnalysis::m_inputTTL1HADKey
SG::ReadHandleKey< LArTTL1Container > m_inputTTL1HADKey
Definition: LArRDOAnalysis.h:37
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
LArRDOAnalysis::m_emOffID
std::vector< unsigned long long > * m_emOffID
Definition: LArRDOAnalysis.h:54
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArRDOAnalysis::m_h_digiGain
TH1 * m_h_digiGain
Definition: LArRDOAnalysis.h:75
LArRDOAnalysis::LArRDOAnalysis
LArRDOAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArRDOAnalysis.cxx:17
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArRDOAnalysis::m_inputRawChannelKey
SG::ReadHandleKey< LArRawChannelContainer > m_inputRawChannelKey
Definition: LArRDOAnalysis.h:36
LArRDOAnalysis::m_larID
std::vector< unsigned long long > * m_larID
Definition: LArRDOAnalysis.h:43
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArRDOAnalysis::m_emOnID
std::vector< unsigned long long > * m_emOnID
Definition: LArRDOAnalysis.h:53
m_path
std::string m_path
the path being used
Definition: OutputStreamData.cxx:88
LArRDOAnalysis::m_energy
std::vector< int > * m_energy
Definition: LArRDOAnalysis.h:44
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.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
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LArRDOAnalysis::m_path
std::string m_path
Definition: LArRDOAnalysis.h:82
LArRDOAnalysis::m_ntupleDirName
std::string m_ntupleDirName
Definition: LArRDOAnalysis.h:80
LArRDOAnalysis::m_ntupleFileName
std::string m_ntupleFileName
Definition: LArRDOAnalysis.h:79
LArRDOAnalysis::m_tree
TTree * m_tree
Definition: LArRDOAnalysis.h:78
LArRDOAnalysis::execute
virtual StatusCode execute() override final
Definition: LArRDOAnalysis.cxx:172
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArRDOAnalysis::m_presampling
BooleanProperty m_presampling
Definition: LArRDOAnalysis.h:40
LArRDOAnalysis::m_h_larID
TH1 * m_h_larID
Definition: LArRDOAnalysis.h:62
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
LArRDOAnalysis::m_h_energy
TH1 * m_h_energy
Definition: LArRDOAnalysis.h:63
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
LArRDOAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: LArRDOAnalysis.h:83
LArRDOAnalysis::m_inputDigitKey
SG::ReadHandleKey< LArDigitContainer > m_inputDigitKey
Definition: LArRDOAnalysis.h:39
LArRDOAnalysis::m_h_digiSamples
TH1 * m_h_digiSamples
Definition: LArRDOAnalysis.h:76
LArRDOAnalysis::m_digiGain
std::vector< int > * m_digiGain
Definition: LArRDOAnalysis.h:58
LArRDOAnalysis::m_h_prov
TH1 * m_h_prov
Definition: LArRDOAnalysis.h:66
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
ReadHandle.h
Handle class for reading from StoreGate.
LArRDOAnalysis::m_h_gain
TH1 * m_h_gain
Definition: LArRDOAnalysis.h:67
LArRDOAnalysis::m_emSamples
std::vector< float > * m_emSamples
Definition: LArRDOAnalysis.h:55
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
LArRDOAnalysis::m_digiSamples
std::vector< short > * m_digiSamples
Definition: LArRDOAnalysis.h:59
LArRDOAnalysis::m_h_hadOnID
TH1 * m_h_hadOnID
Definition: LArRDOAnalysis.h:68
LArRDOAnalysis::m_digiID
std::vector< unsigned long long > * m_digiID
Definition: LArRDOAnalysis.h:57
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
fitman.k
k
Definition: fitman.py:528
LArRDOAnalysis::m_ntupleTreeName
std::string m_ntupleTreeName
Definition: LArRDOAnalysis.h:81