ATLAS Offline Software
Loading...
Searching...
No Matches
BCM_RDOAnalysis.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include "BCM_RDOAnalysis.h"
8
10 ATH_MSG_DEBUG( "Initializing BCM_RDOAnalysis" );
11
12 // This will check that the properties were initialized
13 // properly by job configuration.
14 ATH_CHECK( m_inputKey.initialize() );
15 ATH_CHECK( m_inputTruthKey.initialize() );
16
17
18 m_tree = new TTree(m_ntupleTreeName.value().c_str(), "BCM_RDOAna");
19 std::string fullNtupleName = "/" + m_ntupleFileName + "/" + m_ntupleDirName + "/" + m_ntupleTreeName;
20 ATH_CHECK(histSvc()->regTree(fullNtupleName,m_tree));
21 // BCM RDO
22 m_tree->Branch("word1", &m_word1);
23 m_tree->Branch("word2", &m_word2);
24 m_tree->Branch("chan", &m_chan);
25 m_tree->Branch("pulse1Pos", &m_pulse1Pos);
26 m_tree->Branch("pulse1Width", &m_pulse1Width);
27 m_tree->Branch("pulse2Pos", &m_pulse2Pos);
28 m_tree->Branch("pulse2Width", &m_pulse2Width);
29 m_tree->Branch("LVL1A", &m_LVL1A);
30 m_tree->Branch("BCID", &m_BCID);
31 m_tree->Branch("LVL1ID", &m_LVL1ID);
32 m_tree->Branch("err", &m_err);
33 // BCM SDO
34 m_tree->Branch("sdoID", &m_sdoID);
35 m_tree->Branch("sdoWord", &m_sdoWord);
36 m_tree->Branch("barcode", &m_barcode);
37 m_tree->Branch("eventIndex", &m_eventIndex);
38 m_tree->Branch("charge", &m_charge);
39 m_tree->Branch("barcode_vec", &m_barcode_vec);
40 m_tree->Branch("eventIndex_vec", &m_eventIndex_vec);
41 m_tree->Branch("charge_vec", &m_charge_vec);
42
43 // HISTOGRAMS
44 m_h_word1 = new TH1F("h_word1", "word 1", 100, 0, 4.5e7);
45 m_h_word1->StatOverflows();
46 ATH_CHECK(histSvc()->regHist(m_path + m_h_word1->GetName(), m_h_word1));
47
48 m_h_word2 = new TH1F("h_word2", "word 2", 100, 0, 10);
49 m_h_word2->StatOverflows();
50 ATH_CHECK(histSvc()->regHist(m_path + m_h_word2->GetName(), m_h_word2));
51
52 m_h_chan = new TH1F("h_chan", "channel ID", 100, 0, 20);
53 m_h_chan->StatOverflows();
54 ATH_CHECK(histSvc()->regHist(m_path + m_h_chan->GetName(), m_h_chan));
55
56 m_h_pulse1Pos = new TH1F("h_pulse1Pos", "pulse 1 position", 100, 0, 70);
57 m_h_pulse1Pos->StatOverflows();
58 ATH_CHECK(histSvc()->regHist(m_path + m_h_pulse1Pos->GetName(), m_h_pulse1Pos));
59
60 m_h_pulse1Width = new TH1F("h_pulse1Width", "pulse 1 width", 100, 0, 30);
61 m_h_pulse1Width->StatOverflows();
62 ATH_CHECK(histSvc()->regHist(m_path + m_h_pulse1Width->GetName(), m_h_pulse1Width));
63
64 m_h_pulse2Pos = new TH1F("h_pulse2Pos", "pulse 2 position", 100, 0, 70);
65 m_h_pulse2Pos->StatOverflows();
66 ATH_CHECK(histSvc()->regHist(m_path + m_h_pulse2Pos->GetName(), m_h_pulse2Pos));
67
68 m_h_pulse2Width = new TH1F("h_pulse2Width", "pulse 2 width", 100, 0, 30);
69 m_h_pulse2Width->StatOverflows();
70 ATH_CHECK(histSvc()->regHist(m_path + m_h_pulse2Width->GetName(), m_h_pulse2Width));
71
72 m_h_sdoID = new TH1F("h_sdoID", "sdoID", 100, 0, 10);
73 m_h_sdoID->StatOverflows();
74 ATH_CHECK(histSvc()->regHist(m_path + m_h_sdoID->GetName(), m_h_sdoID));
75
76 m_h_sdoWord = new TH1F("h_sdoWord", "sdoWord", 100, 0, 10);
77 m_h_sdoWord->StatOverflows();
78 ATH_CHECK(histSvc()->regHist(m_path + m_h_sdoWord->GetName(), m_h_sdoWord));
79
80 m_h_barcode = new TH1F("h_barcode", "Barcode (SDO)", 100, 0, 2.2e9);
81 m_h_barcode->StatOverflows();
82 ATH_CHECK(histSvc()->regHist(m_path + m_h_barcode->GetName(), m_h_barcode));
83
84 m_h_eventIndex = new TH1F("h_eventIndex", "Event index (SDO)", 100, 0, 1000);
85 m_h_eventIndex->StatOverflows();
86 ATH_CHECK(histSvc()->regHist(m_path + m_h_eventIndex->GetName(), m_h_eventIndex));
87
88 m_h_charge = new TH1F("h_charge", "Charge (SDO)", 100, 0, 10);
89 m_h_charge->StatOverflows();
90 ATH_CHECK(histSvc()->regHist(m_path + m_h_charge->GetName(), m_h_charge));
91
92 return StatusCode::SUCCESS;
93
94}
95
97 ATH_MSG_DEBUG( "In BCM_RDOAnalysis::execute()" );
98
99 m_word1->clear();
100 m_word2->clear();
101 m_chan->clear();
102 m_pulse1Pos->clear();
103 m_pulse1Width->clear();
104 m_pulse2Pos->clear();
105 m_pulse2Width->clear();
106 m_LVL1A->clear();
107 m_BCID->clear();
108 m_LVL1ID->clear();
109 m_err->clear();
110 m_sdoID->clear();
111 m_sdoWord->clear();
112 m_barcode->clear();
113 m_eventIndex->clear();
114 m_charge->clear();
115 m_barcode_vec->clear();
116 m_eventIndex_vec->clear();
117 m_charge_vec->clear();
118
119 // RDO
120 const EventContext& ctx{Gaudi::Hive::currentContext()};
121 const BCM_RDO_Container* p_BCM_RDO_cont{nullptr};
122
123 ATH_CHECK(SG::get(p_BCM_RDO_cont, m_inputKey, ctx));
124 if(p_BCM_RDO_cont) {
125 // loop over RDO container
126 BCM_RDO_Container::const_iterator rdoCont_itr(p_BCM_RDO_cont->begin());
127 const BCM_RDO_Container::const_iterator rdoCont_end(p_BCM_RDO_cont->end());
128
129 for ( ; rdoCont_itr != rdoCont_end; ++rdoCont_itr ) {
130 const DataVector<BCM_RawData>* p_BCM_RDO_coll(*rdoCont_itr);
131 DataVector<BCM_RawData>::const_iterator rdo_itr(p_BCM_RDO_coll->begin());
132 const DataVector<BCM_RawData>::const_iterator rdo_end(p_BCM_RDO_coll->end());
133
134 for ( ; rdo_itr != rdo_end; ++rdo_itr ) {
135 const int word1((*rdo_itr)->getWord1());
136 const int word2((*rdo_itr)->getWord2());
137 const int chan((*rdo_itr)->getChannel());
138 const int pulse1Pos((*rdo_itr)->getPulse1Position());
139 const int pulse1Width((*rdo_itr)->getPulse1Width());
140 const int pulse2Pos((*rdo_itr)->getPulse2Position());
141 const int pulse2Width((*rdo_itr)->getPulse2Width());
142 const int LVL1A((*rdo_itr)->getLVL1A());
143 const int BCID((*rdo_itr)->getBCID());
144 const int LVL1ID((*rdo_itr)->getLVL1ID());
145 const int err((*rdo_itr)->getError());
146
147 m_word1->push_back(word1);
148 m_word2->push_back(word2);
149 m_chan->push_back(chan);
150 m_pulse1Pos->push_back(pulse1Pos);
151 m_pulse1Width->push_back(pulse1Width);
152 m_pulse2Pos->push_back(pulse2Pos);
153 m_pulse2Width->push_back(pulse2Width);
154 m_LVL1A->push_back(LVL1A);
155 m_BCID->push_back(BCID);
156 m_LVL1ID->push_back(LVL1ID);
157 m_err->push_back(err);
158
159 m_h_word1->Fill(word1);
160 m_h_word2->Fill(word2);
161 m_h_chan->Fill(chan);
162 m_h_pulse1Pos->Fill(pulse1Pos);
163 m_h_pulse1Width->Fill(pulse1Width);
164 m_h_pulse2Pos->Fill(pulse2Pos);
165 m_h_pulse2Width->Fill(pulse2Width);
166 }
167 }
168 }
169
170 // SDO
171 const InDetSimDataCollection* simDataMapBCM{nullptr};
172 ATH_CHECK(SG::get(simDataMapBCM, m_inputTruthKey, ctx));
173 if(simDataMapBCM) {
174 // loop over SDO container
175 InDetSimDataCollection::const_iterator sdo_itr(simDataMapBCM->begin());
176 const InDetSimDataCollection::const_iterator sdo_end(simDataMapBCM->end());
177
178 std::vector<int> barcode_vec;
179 std::vector<int> eventIndex_vec;
180 std::vector<float> charge_vec;
181 for ( ; sdo_itr != sdo_end; ++sdo_itr ) {
182 const Identifier sdoID((*sdo_itr).first);
183 const InDetSimData& sdo((*sdo_itr).second);
184
185 const unsigned long long sdoID_int = sdoID.get_compact();
186 const int sdoWord(sdo.word());
187
188 m_sdoID->push_back(sdoID_int);
189 m_sdoWord->push_back(sdoWord);
190
191 m_h_sdoID->Fill(sdoID_int);
192 m_h_sdoWord->Fill(sdoWord);
193
194 // loop over deposits
195 const std::vector<InDetSimData::Deposit>& deposits = sdo.getdeposits();
196 std::vector<InDetSimData::Deposit>::const_iterator dep_itr(deposits.begin());
197 const std::vector<InDetSimData::Deposit>::const_iterator dep_end(deposits.end());
198
199 for ( ; dep_itr != dep_end; ++dep_itr ) {
200 const HepMcParticleLink& particleLink = (*dep_itr).first;
201 const int bar(HepMC::barcode(particleLink)); // FIXME barcode-based
202 const int eventIx(particleLink.eventIndex());
203 const float charge((*dep_itr).second);
204
205 m_barcode->push_back(bar);
206 m_eventIndex->push_back(eventIx);
207 m_charge->push_back(charge);
208
209 m_h_barcode->Fill(bar);
210 m_h_eventIndex->Fill(eventIx);
211 m_h_charge->Fill(charge);
212
213 barcode_vec.push_back(bar);
214 eventIndex_vec.push_back(eventIx);
215 charge_vec.push_back(charge);
216 }
217 m_barcode_vec->push_back(barcode_vec);
218 m_eventIndex_vec->push_back(eventIndex_vec);
219 m_charge_vec->push_back(charge_vec);
220 barcode_vec.clear();
221 eventIndex_vec.clear();
222 charge_vec.clear();
223 }
224 }
225
226 m_tree->Fill();
227
228 return StatusCode::SUCCESS;
229
230}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
Handle class for reading from StoreGate.
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
std::vector< int > * m_pulse2Pos
std::vector< int > * m_word1
virtual StatusCode execute() override final
std::vector< int > * m_pulse2Width
Gaudi::Property< std::string > m_ntupleFileName
Gaudi::Property< std::string > m_ntupleDirName
std::vector< unsigned long long > * m_sdoID
std::vector< int > * m_LVL1ID
std::vector< int > * m_pulse1Pos
std::vector< std::vector< int > > * m_barcode_vec
std::vector< int > * m_LVL1A
std::vector< int > * m_barcode
std::vector< std::vector< float > > * m_charge_vec
std::vector< int > * m_err
std::vector< float > * m_charge
std::vector< int > * m_eventIndex
Gaudi::Property< std::string > m_ntupleTreeName
SG::ReadHandleKey< InDetSimDataCollection > m_inputTruthKey
std::vector< std::vector< int > > * m_eventIndex_vec
std::vector< int > * m_pulse1Width
Gaudi::Property< std::string > m_path
std::vector< int > * m_word2
virtual StatusCode initialize() override final
SG::ReadHandleKey< BCM_RDO_Container > m_inputKey
std::vector< int > * m_sdoWord
std::vector< int > * m_BCID
std::vector< int > * m_chan
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
value_type get_compact() const
Get the compact id.
int word() const
const std::vector< Deposit > & getdeposits() const
int barcode(const T *p)
Definition Barcode.h:16
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.