ATLAS Offline Software
BCM_RDOAnalysis.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "BCM_RDOAnalysis.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 BCM_RDOAnalysis::BCM_RDOAnalysis(const std::string& name, ISvcLocator *pSvcLocator)
18  : AthAlgorithm(name, pSvcLocator)
19  , m_inputKey("BCM_RDOs")
20  , m_inputTruthKey("BCM_SDO_Map")
21  , m_word1(0)
22  , m_word2(0)
23  , m_chan(0)
24  , m_pulse1Pos(0)
25  , m_pulse1Width(0)
26  , m_pulse2Pos(0)
27  , m_pulse2Width(0)
28  , m_LVL1A(0)
29  , m_BCID(0)
30  , m_LVL1ID(0)
31  , m_err(0)
32  , m_sdoID(0)
33  , m_sdoWord(0)
34  , m_barcode(0)
35  , m_eventIndex(0)
36  , m_charge(0)
37  , m_barcode_vec(0)
38  , m_eventIndex_vec(0)
39  , m_charge_vec(0)
40 
41  , m_h_word1(0)
42  , m_h_word2(0)
43  , m_h_chan(0)
44  , m_h_pulse1Pos(0)
45  , m_h_pulse1Width(0)
46  , m_h_pulse2Pos(0)
47  , m_h_pulse2Width(0)
48  , m_h_sdoID(0)
49  , m_h_sdoWord(0)
50  , m_h_barcode(0)
51  , m_h_eventIndex(0)
52  , m_h_charge(0)
53 
54  , m_tree(0)
55  , m_ntupleFileName("/ntuples/file1")
56  , m_ntupleDirName("/BCM_RDOAnalysis/")
57  , m_ntupleTreeName("BCM_RDOAna")
58  , m_path("/BCM_RDOAnalysis/")
59  , m_thistSvc("THistSvc", name)
60 {
61  declareProperty("InputKey", m_inputKey);
62  declareProperty("InputTruthKey", m_inputTruthKey);
63  declareProperty("NtupleFileName", m_ntupleFileName);
64  declareProperty("NtupleDirectoryName", m_ntupleDirName);
65  declareProperty("NtupleTreeName", m_ntupleTreeName);
66  declareProperty("HistPath", m_path);
67 }
68 
70  ATH_MSG_DEBUG( "Initializing BCM_RDOAnalysis" );
71 
72  // This will check that the properties were initialized
73  // properly by job configuration.
76 
77  // Grab Ntuple and histgoramming service for tree
78  ATH_CHECK(m_thistSvc.retrieve());
79 
80  m_tree = new TTree(TString(m_ntupleTreeName), "BCM_RDOAna");
81  std::string fullNtupleName = "/" + m_ntupleFileName + "/" + m_ntupleDirName + "/" + m_ntupleTreeName;
82  ATH_CHECK(m_thistSvc->regTree(fullNtupleName,m_tree));
83  if (m_tree) {
84  // BCM RDO
85  m_tree->Branch("word1", &m_word1);
86  m_tree->Branch("word2", &m_word2);
87  m_tree->Branch("chan", &m_chan);
88  m_tree->Branch("pulse1Pos", &m_pulse1Pos);
89  m_tree->Branch("pulse1Width", &m_pulse1Width);
90  m_tree->Branch("pulse2Pos", &m_pulse2Pos);
91  m_tree->Branch("pulse2Width", &m_pulse2Width);
92  m_tree->Branch("LVL1A", &m_LVL1A);
93  m_tree->Branch("BCID", &m_BCID);
94  m_tree->Branch("LVL1ID", &m_LVL1ID);
95  m_tree->Branch("err", &m_err);
96  // BCM SDO
97  m_tree->Branch("sdoID", &m_sdoID);
98  m_tree->Branch("sdoWord", &m_sdoWord);
99  m_tree->Branch("barcode", &m_barcode);
100  m_tree->Branch("eventIndex", &m_eventIndex);
101  m_tree->Branch("charge", &m_charge);
102  m_tree->Branch("barcode_vec", &m_barcode_vec);
103  m_tree->Branch("eventIndex_vec", &m_eventIndex_vec);
104  m_tree->Branch("charge_vec", &m_charge_vec);
105  }
106  else {
107  ATH_MSG_ERROR( "No tree found" );
108  }
109 
110  // HISTOGRAMS
111  m_h_word1 = new TH1F("h_word1", "word 1", 100, 0, 4.5e7);
112  m_h_word1->StatOverflows();
113  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_word1->GetName(), m_h_word1));
114 
115  m_h_word2 = new TH1F("h_word2", "word 2", 100, 0, 10);
116  m_h_word2->StatOverflows();
117  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_word2->GetName(), m_h_word2));
118 
119  m_h_chan = new TH1F("h_chan", "channel ID", 100, 0, 20);
120  m_h_chan->StatOverflows();
121  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_chan->GetName(), m_h_chan));
122 
123  m_h_pulse1Pos = new TH1F("h_pulse1Pos", "pulse 1 position", 100, 0, 70);
124  m_h_pulse1Pos->StatOverflows();
125  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_pulse1Pos->GetName(), m_h_pulse1Pos));
126 
127  m_h_pulse1Width = new TH1F("h_pulse1Width", "pulse 1 width", 100, 0, 30);
128  m_h_pulse1Width->StatOverflows();
129  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_pulse1Width->GetName(), m_h_pulse1Width));
130 
131  m_h_pulse2Pos = new TH1F("h_pulse2Pos", "pulse 2 position", 100, 0, 70);
132  m_h_pulse2Pos->StatOverflows();
133  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_pulse2Pos->GetName(), m_h_pulse2Pos));
134 
135  m_h_pulse2Width = new TH1F("h_pulse2Width", "pulse 2 width", 100, 0, 30);
136  m_h_pulse2Width->StatOverflows();
137  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_pulse2Width->GetName(), m_h_pulse2Width));
138 
139  m_h_sdoID = new TH1F("h_sdoID", "sdoID", 100, 0, 10);
140  m_h_sdoID->StatOverflows();
141  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_sdoID->GetName(), m_h_sdoID));
142 
143  m_h_sdoWord = new TH1F("h_sdoWord", "sdoWord", 100, 0, 10);
144  m_h_sdoWord->StatOverflows();
145  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_sdoWord->GetName(), m_h_sdoWord));
146 
147  m_h_barcode = new TH1F("h_barcode", "Barcode (SDO)", 100, 0, 2.2e9);
148  m_h_barcode->StatOverflows();
149  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_barcode->GetName(), m_h_barcode));
150 
151  m_h_eventIndex = new TH1F("h_eventIndex", "Event index (SDO)", 100, 0, 1000);
152  m_h_eventIndex->StatOverflows();
153  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_eventIndex->GetName(), m_h_eventIndex));
154 
155  m_h_charge = new TH1F("h_charge", "Charge (SDO)", 100, 0, 10);
156  m_h_charge->StatOverflows();
157  ATH_CHECK(m_thistSvc->regHist(m_path + m_h_charge->GetName(), m_h_charge));
158 
159  return StatusCode::SUCCESS;
160 
161 }
162 
164  ATH_MSG_DEBUG( "In BCM_RDOAnalysis::execute()" );
165 
166  m_word1->clear();
167  m_word2->clear();
168  m_chan->clear();
169  m_pulse1Pos->clear();
170  m_pulse1Width->clear();
171  m_pulse2Pos->clear();
172  m_pulse2Width->clear();
173  m_LVL1A->clear();
174  m_BCID->clear();
175  m_LVL1ID->clear();
176  m_err->clear();
177  m_sdoID->clear();
178  m_sdoWord->clear();
179  m_barcode->clear();
180  m_eventIndex->clear();
181  m_charge->clear();
182  m_barcode_vec->clear();
183  m_eventIndex_vec->clear();
184  m_charge_vec->clear();
185 
186  // RDO
188  if(p_BCM_RDO_cont.isValid()) {
189  // loop over RDO container
190  BCM_RDO_Container::const_iterator rdoCont_itr(p_BCM_RDO_cont->begin());
191  const BCM_RDO_Container::const_iterator rdoCont_end(p_BCM_RDO_cont->end());
192 
193  for ( ; rdoCont_itr != rdoCont_end; ++rdoCont_itr ) {
194  const DataVector<BCM_RawData>* p_BCM_RDO_coll(*rdoCont_itr);
195  DataVector<BCM_RawData>::const_iterator rdo_itr(p_BCM_RDO_coll->begin());
196  const DataVector<BCM_RawData>::const_iterator rdo_end(p_BCM_RDO_coll->end());
197 
198  for ( ; rdo_itr != rdo_end; ++rdo_itr ) {
199  const int word1((*rdo_itr)->getWord1());
200  const int word2((*rdo_itr)->getWord2());
201  const int chan((*rdo_itr)->getChannel());
202  const int pulse1Pos((*rdo_itr)->getPulse1Position());
203  const int pulse1Width((*rdo_itr)->getPulse1Width());
204  const int pulse2Pos((*rdo_itr)->getPulse2Position());
205  const int pulse2Width((*rdo_itr)->getPulse2Width());
206  const int LVL1A((*rdo_itr)->getLVL1A());
207  const int BCID((*rdo_itr)->getBCID());
208  const int LVL1ID((*rdo_itr)->getLVL1ID());
209  const int err((*rdo_itr)->getError());
210 
211  m_word1->push_back(word1);
212  m_word2->push_back(word2);
213  m_chan->push_back(chan);
214  m_pulse1Pos->push_back(pulse1Pos);
215  m_pulse1Width->push_back(pulse1Width);
216  m_pulse2Pos->push_back(pulse2Pos);
217  m_pulse2Width->push_back(pulse2Width);
218  m_LVL1A->push_back(LVL1A);
219  m_BCID->push_back(BCID);
220  m_LVL1ID->push_back(LVL1ID);
221  m_err->push_back(err);
222 
223  m_h_word1->Fill(word1);
224  m_h_word2->Fill(word2);
225  m_h_chan->Fill(chan);
226  m_h_pulse1Pos->Fill(pulse1Pos);
227  m_h_pulse1Width->Fill(pulse1Width);
228  m_h_pulse2Pos->Fill(pulse2Pos);
229  m_h_pulse2Width->Fill(pulse2Width);
230  }
231  }
232  }
233 
234  // SDO
236  if(simDataMapBCM.isValid()) {
237  // loop over SDO container
238  InDetSimDataCollection::const_iterator sdo_itr(simDataMapBCM->begin());
239  const InDetSimDataCollection::const_iterator sdo_end(simDataMapBCM->end());
240 
241  std::vector<int> barcode_vec;
242  std::vector<int> eventIndex_vec;
243  std::vector<float> charge_vec;
244  for ( ; sdo_itr != sdo_end; ++sdo_itr ) {
245  const Identifier sdoID((*sdo_itr).first);
246  const InDetSimData& sdo((*sdo_itr).second);
247 
248  const unsigned long long sdoID_int = sdoID.get_compact();
249  const int sdoWord(sdo.word());
250 
251  m_sdoID->push_back(sdoID_int);
252  m_sdoWord->push_back(sdoWord);
253 
254  m_h_sdoID->Fill(sdoID_int);
255  m_h_sdoWord->Fill(sdoWord);
256 
257  // loop over deposits
258  const std::vector<InDetSimData::Deposit>& deposits = sdo.getdeposits();
259  std::vector<InDetSimData::Deposit>::const_iterator dep_itr(deposits.begin());
260  const std::vector<InDetSimData::Deposit>::const_iterator dep_end(deposits.end());
261 
262  for ( ; dep_itr != dep_end; ++dep_itr ) {
263  const HepMcParticleLink& particleLink = (*dep_itr).first;
264  const int bar(HepMC::barcode(particleLink)); // FIXME barcode-based
265  const int eventIx(particleLink.eventIndex());
266  const float charge((*dep_itr).second);
267 
268  m_barcode->push_back(bar);
269  m_eventIndex->push_back(eventIx);
270  m_charge->push_back(charge);
271 
272  m_h_barcode->Fill(bar);
273  m_h_eventIndex->Fill(eventIx);
274  m_h_charge->Fill(charge);
275 
276  barcode_vec.push_back(bar);
277  eventIndex_vec.push_back(eventIx);
278  charge_vec.push_back(charge);
279  }
280  m_barcode_vec->push_back(barcode_vec);
281  m_eventIndex_vec->push_back(eventIndex_vec);
282  m_charge_vec->push_back(charge_vec);
283  barcode_vec.clear();
284  eventIndex_vec.clear();
285  charge_vec.clear();
286  }
287  }
288 
289  if (m_tree) {
290  m_tree->Fill();
291  }
292 
293  return StatusCode::SUCCESS;
294 
295 }
296 
298 
299  return StatusCode::SUCCESS;
300 
301 }
BCM_RDOAnalysis::m_barcode
std::vector< int > * m_barcode
Definition: BCM_RDOAnalysis.h:53
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
BCM_RDOAnalysis::m_barcode_vec
std::vector< std::vector< int > > * m_barcode_vec
Definition: BCM_RDOAnalysis.h:56
xAOD::word1
word1
Definition: eFexEMRoI_v1.cxx:82
BCM_RDOAnalysis::m_BCID
std::vector< int > * m_BCID
Definition: BCM_RDOAnalysis.h:47
BCM_RDOAnalysis::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition: BCM_RDOAnalysis.h:80
InDetSimData::getdeposits
const std::vector< Deposit > & getdeposits() const
Definition: InDetSimData.h:74
BCM_RDOAnalysis::finalize
virtual StatusCode finalize() override final
Definition: BCM_RDOAnalysis.cxx:297
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
BCM_RDOAnalysis::m_word1
std::vector< int > * m_word1
Definition: BCM_RDOAnalysis.h:39
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
BCM_RDOAnalysis::m_h_word2
TH1 * m_h_word2
Definition: BCM_RDOAnalysis.h:62
BCM_RDOAnalysis::m_path
std::string m_path
Definition: BCM_RDOAnalysis.h:79
BCM_RDOAnalysis::m_h_word1
TH1 * m_h_word1
Definition: BCM_RDOAnalysis.h:61
BCM_RDOAnalysis::m_LVL1A
std::vector< int > * m_LVL1A
Definition: BCM_RDOAnalysis.h:46
Identifier::get_compact
value_type get_compact() const
Get the compact id.
BCM_RDOAnalysis::m_LVL1ID
std::vector< int > * m_LVL1ID
Definition: BCM_RDOAnalysis.h:48
BCM_RDOAnalysis::m_h_sdoWord
TH1 * m_h_sdoWord
Definition: BCM_RDOAnalysis.h:70
BCM_RDOAnalysis::m_word2
std::vector< int > * m_word2
Definition: BCM_RDOAnalysis.h:40
BCM_RDOAnalysis::m_eventIndex
std::vector< int > * m_eventIndex
Definition: BCM_RDOAnalysis.h:54
BCM_RDOAnalysis::m_h_barcode
TH1 * m_h_barcode
Definition: BCM_RDOAnalysis.h:71
PixelByteStreamErrors::BCID
@ BCID
Definition: PixelByteStreamErrors.h:13
BCM_RDOAnalysis::m_inputTruthKey
SG::ReadHandleKey< InDetSimDataCollection > m_inputTruthKey
Definition: BCM_RDOAnalysis.h:37
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
BCM_RDOAnalysis::m_h_eventIndex
TH1 * m_h_eventIndex
Definition: BCM_RDOAnalysis.h:72
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
BCM_RDOAnalysis::m_chan
std::vector< int > * m_chan
Definition: BCM_RDOAnalysis.h:41
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
BCM_RDOAnalysis::execute
virtual StatusCode execute() override final
Definition: BCM_RDOAnalysis.cxx:163
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
m_path
std::string m_path
the path being used
Definition: OutputStreamData.cxx:88
InDetSimData
Definition: InDetSimData.h:42
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
BCM_RDOAnalysis::m_sdoWord
std::vector< int > * m_sdoWord
Definition: BCM_RDOAnalysis.h:52
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
DataVector< BCM_RawData >
BCM_RDOAnalysis::m_eventIndex_vec
std::vector< std::vector< int > > * m_eventIndex_vec
Definition: BCM_RDOAnalysis.h:57
BCM_RDOAnalysis::m_sdoID
std::vector< unsigned long long > * m_sdoID
Definition: BCM_RDOAnalysis.h:51
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
BCM_RDOAnalysis::m_pulse1Width
std::vector< int > * m_pulse1Width
Definition: BCM_RDOAnalysis.h:43
BCM_RDOAnalysis::m_err
std::vector< int > * m_err
Definition: BCM_RDOAnalysis.h:49
BCM_RDOAnalysis::m_charge
std::vector< float > * m_charge
Definition: BCM_RDOAnalysis.h:55
python.SystemOfUnits.bar
int bar
Definition: SystemOfUnits.py:188
BCM_RDOAnalysis::m_pulse2Pos
std::vector< int > * m_pulse2Pos
Definition: BCM_RDOAnalysis.h:44
BCM_RDOAnalysis::m_h_pulse1Width
TH1 * m_h_pulse1Width
Definition: BCM_RDOAnalysis.h:65
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
BCM_RDOAnalysis::m_tree
TTree * m_tree
Definition: BCM_RDOAnalysis.h:75
charge
double charge(const T &p)
Definition: AtlasPID.h:538
BCM_RDOAnalysis::m_charge_vec
std::vector< std::vector< float > > * m_charge_vec
Definition: BCM_RDOAnalysis.h:58
BCM_RDOAnalysis::m_h_pulse2Width
TH1 * m_h_pulse2Width
Definition: BCM_RDOAnalysis.h:67
BCM_RDOAnalysis::m_ntupleFileName
std::string m_ntupleFileName
Definition: BCM_RDOAnalysis.h:76
BCM_RDOAnalysis::initialize
virtual StatusCode initialize() override final
Definition: BCM_RDOAnalysis.cxx:69
BCM_RDOAnalysis::m_h_pulse1Pos
TH1 * m_h_pulse1Pos
Definition: BCM_RDOAnalysis.h:64
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
InDetSimData::word
int word() const
Definition: InDetSimData.h:69
BCM_RDOAnalysis::m_h_chan
TH1 * m_h_chan
Definition: BCM_RDOAnalysis.h:63
BCM_RDOAnalysis::m_ntupleDirName
std::string m_ntupleDirName
Definition: BCM_RDOAnalysis.h:77
BCM_RDOAnalysis::BCM_RDOAnalysis
BCM_RDOAnalysis(const std::string &name, ISvcLocator *pSvcLocator)
Definition: BCM_RDOAnalysis.cxx:17
BCM_RDOAnalysis::m_ntupleTreeName
std::string m_ntupleTreeName
Definition: BCM_RDOAnalysis.h:78
BCM_RDOAnalysis::m_h_charge
TH1 * m_h_charge
Definition: BCM_RDOAnalysis.h:73
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
BCM_RDOAnalysis::m_pulse2Width
std::vector< int > * m_pulse2Width
Definition: BCM_RDOAnalysis.h:45
BCM_RDOAnalysis::m_pulse1Pos
std::vector< int > * m_pulse1Pos
Definition: BCM_RDOAnalysis.h:42
BCM_RDOAnalysis::m_inputKey
SG::ReadHandleKey< BCM_RDO_Container > m_inputKey
Definition: BCM_RDOAnalysis.h:36
ReadHandle.h
Handle class for reading from StoreGate.
BCM_RDOAnalysis::m_h_sdoID
TH1 * m_h_sdoID
Definition: BCM_RDOAnalysis.h:69
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
BCM_RDOAnalysis::m_h_pulse2Pos
TH1 * m_h_pulse2Pos
Definition: BCM_RDOAnalysis.h:66
PixelByteStreamErrors::LVL1ID
@ LVL1ID
Definition: PixelByteStreamErrors.h:13
BCM_RDOAnalysis.h
Identifier
Definition: IdentifierFieldParser.cxx:14