ATLAS Offline Software
Loading...
Searching...
No Matches
LArSC2NtupleEB.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10LArSC2NtupleEB::LArSC2NtupleEB(const std::string& name, ISvcLocator* pSvcLocator):
11 LArCond2NtupleBaseEB(name, pSvcLocator)
12{
13 m_isSC = true;
14 m_ntTitle = "LAr SC Energies";
15 m_ntpath = "/NTUPLES/FILE1/LARSC";
16}
17
18
20{
21 ATH_MSG_DEBUG( "in initialize" );
22
24
25 StatusCode sc = m_nt->addItem("IEvent",m_IEvent);
26 if (sc!=StatusCode::SUCCESS) {
27 ATH_MSG_ERROR( "addItem 'IEvent' failed" );
28 return sc;
29 }
30
31 if(m_fillBCID){
32 sc = m_nt->addItem("BCID",m_bcid);
33 if (sc!=StatusCode::SUCCESS) {
34 ATH_MSG_ERROR( "addItem 'BCID' failed" );
35 return sc;
36 }
37 }
38
39
40 if(!m_sccontKey.empty()){ // SC_ET RawSCContainer
41 sc = m_nt->addItem("energyVec_ET", m_SC, m_scNet, m_energyVec_ET);
42 if (sc.isFailure()) {
43 ATH_MSG_ERROR( "addItem 'energyVec_ET' failed" );
44 return sc;
45 }
46
47 sc = m_nt->addItem("bcidVec_ET", m_SC, m_scNet, m_bcidVec_ET);
48 if (sc.isFailure()) {
49 ATH_MSG_ERROR( "addItem 'bcidVec_ET_ID' failed" );
50 return sc;
51 }
52
53 sc = m_nt->addItem("saturVec_ET", m_SC, m_scNet, m_saturVec_ET);
54 if (sc.isFailure()) {
55 ATH_MSG_ERROR( "addItem 'saturVec_ET' failed" );
56 return sc;
57 }
58
59 sc = m_nt->addItem("passVec_ET", m_SC, m_scNet, m_passVec_ET);
60 if (sc.isFailure()) {
61 ATH_MSG_ERROR( "addItem 'passVec_ET' failed" );
62 return sc;
63 }
64 }
65
66 if(!m_reccontKey.empty()){ // SC Reco RawSCContainer
67 sc = m_nt->addItem("energyVec_Reco", m_SC, m_recoNet, m_energyVec_Reco);
68 if (sc.isFailure()) {
69 ATH_MSG_ERROR( "addItem 'energyVec_Reco' failed" );
70 return sc;
71 }
72
73 sc = m_nt->addItem("tauVec_Reco", m_SC, m_recoNet, m_tauVec_Reco);
74 if (sc.isFailure()) {
75 ATH_MSG_ERROR( "addItem 'tauVec_Reco' failed" );
76 return sc;
77 }
78
79 sc = m_nt->addItem("bcidVec_Reco", m_SC, m_recoNet, m_bcidVec_Reco);
80 if (sc.isFailure()) {
81 ATH_MSG_ERROR( "addItem 'bcidVec_Reco' failed" );
82 return sc;
83 }
84
85 sc = m_nt->addItem("passVec_Reco", m_SC, m_recoNet, m_passVec_Reco);
86 if (sc.isFailure()) {
87 ATH_MSG_ERROR( "addItem 'passVec_Reco' failed" );
88 return sc;
89 }
90
91 sc = m_nt->addItem("saturVec_Reco", m_SC, m_recoNet, m_saturVec_Reco);
92 if (sc.isFailure()) {
93 ATH_MSG_ERROR( "addItem 'saturVec_Reco' failed" );
94 return sc;
95 }
96 }
97
98 if(!m_rawcontKey.empty()) {
99 sc = m_nt->addItem("ROD_energy", m_SC, 16, m_ROD_energy);
100 if (sc.isFailure()) {
101 ATH_MSG_ERROR( "addItem 'ROD_energy' failed" );
102 return sc;
103 }
104
105 sc = m_nt->addItem("ROD_time", m_SC, 16, m_ROD_time);
106 if (sc.isFailure()) {
107 ATH_MSG_ERROR( "addItem 'ROD_time' failed" );
108 return sc;
109 }
110 sc = m_nt->addItem("ROD_id", m_SC, 16, m_ROD_id);
111 if (sc.isFailure()) {
112 ATH_MSG_ERROR( "addItem 'ROD_id' failed" );
113 return sc;
114 }
115
116
117 }
118
119 ATH_CHECK(m_sccontKey.initialize(!m_sccontKey.empty()) );
120 ATH_CHECK(m_reccontKey.initialize(!m_reccontKey.empty()) );
121 ATH_CHECK(m_rawcontKey.initialize(!m_rawcontKey.empty()) );
122 ATH_CHECK(m_evtInfoKey.initialize() );
123 ATH_CHECK(m_cablingKeyAdditional.initialize() );
124
125
126 return StatusCode::SUCCESS;
127
128}
129
130StatusCode LArSC2NtupleEB::execute(const EventContext& ctx)
131{
132
133 StatusCode sc;
134
135
136 ATH_MSG_DEBUG( "LArSC2NtupleEB in execute" );
137 unsigned long long thisevent;
138 unsigned long thisbcid = 0;
139
141 thisevent = evt->eventNumber();
142
143 thisbcid = evt->bcid();
144
145 const LArRawSCContainer* etcontainer = nullptr;
146 if (!m_sccontKey.empty()) {
148
149 if(!hdlSc.isValid()) {
150 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_sccontKey << " from DetectorStore. " );
151 return StatusCode::SUCCESS;
152 } else {
153 ATH_MSG_DEBUG( "Got LArRAwSCContainer with key " << m_sccontKey.key() );
154 etcontainer = &*hdlSc;
155 }
156 }
157
158 const LArRawSCContainer* recocontainer = nullptr;
159 if (!m_reccontKey.empty()) {
161
162 if(!hdlReco.isValid()) {
163 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_reccontKey << " from DetectorStore. " );
164 return StatusCode::SUCCESS;
165 } else {
166 ATH_MSG_DEBUG( "Got LArRAwSCContainer with key " << m_reccontKey.key() );
167 recocontainer = &*hdlReco;
168 }
169 }
170
171 if(! (etcontainer || recocontainer)) {
172
173 ATH_MSG_WARNING( "Do not have any containers to loop on. " );
174 return StatusCode::SUCCESS;
175 }
176
177 const LArRawChannelContainer* rawcontainer = nullptr;
178 if (!m_rawcontKey.empty()) {
180
181 if(!hdlRaw.isValid()) {
182 ATH_MSG_WARNING( "Unable to retrieve LArRawChannelContainer with key " << m_rawcontKey << " from DetectorStore. " );
183 return StatusCode::SUCCESS;
184 } else {
185 ATH_MSG_DEBUG( "Got LArRAwChannelContainer with key " << m_rawcontKey.key() );
186 rawcontainer = &*hdlRaw;
187 }
188 }
189
190 unsigned cellCounter=0;
191
192 if(m_fillBCID) m_bcid = thisbcid;
193 m_IEvent = thisevent;
194
195 rawChanMap_t rawChannelMap;
196 rawSCMap_t rawSuperCellMap;
197
198 if(rawcontainer){
199 for (const LArRawChannel& raw : *rawcontainer) {
200 rawChannelMap.try_emplace( raw.channelID(), &raw );
201 }
202
203 }
204
205 const LArOnOffIdMapping* cabling=nullptr;
206 const LArOnOffIdMapping* cablingROD=nullptr;
207 if(rawcontainer){
209 cabling=*cablingHdl;
210 if(!cabling) {
211 ATH_MSG_ERROR( "Do not have cabling for SC!" );
212 return StatusCode::FAILURE;
213 }
215 cablingROD=*cablingHdlROD;
216 if(!cablingROD) {
217 ATH_MSG_ERROR( "Do not have cabling for ROD!" );
218 return StatusCode::FAILURE;
219 }
220 }
221
222
223 const LArRawSCContainer *itercont = nullptr;
224 const LArRawSCContainer *secondcont = nullptr;
225 if(etcontainer) {
226 itercont = etcontainer;
227 if(recocontainer) {
228 secondcont = recocontainer;
229 auto cbiter=secondcont->cbegin();
230 auto ceiter=secondcont->cend();
231 for ( ; cbiter<ceiter; ++cbiter) {
232 rawSuperCellMap.try_emplace( (*cbiter)->hardwareID(), *cbiter );
233 }
234 }
235 } else {
236 if(recocontainer) itercont = recocontainer;
237 }
238
239
240 auto cbsciter=itercont->cbegin();
241 auto cesciter=itercont->cend();
242 for( ; cbsciter<cesciter; ++cbsciter ){
243
244 const LArRawSC *iterSC = *cbsciter;
245 fillFromIdentifier(iterSC->hardwareID(), cellCounter);
246
247 const LArRawSC* secondSC = nullptr;
248 if( secondcont ){ // find corresponding LArRawSC
249 secondSC = rawSuperCellMap[iterSC->hardwareID()];
250 }
251
252 unsigned int truenet = etcontainer ? m_scNet : m_recoNet;
253
254 if(truenet > iterSC->energies().size()) truenet=iterSC->energies().size();
255 for( unsigned i=0; i<truenet;++i){
256 if(std::abs(iterSC->energies().at(i)) > m_eCut) {
257 if(etcontainer) {
258 m_energyVec_ET[cellCounter][i] = iterSC->energies().at(i);
259 if(iterSC->bcids().size()) m_bcidVec_ET[cellCounter][i] = iterSC->bcids().at(i);
260 if(iterSC->passTauSelection().size()) m_passVec_ET[cellCounter][i] = iterSC->passTauSelection().at(i);
261 if(iterSC->satur().size()) m_saturVec_ET[cellCounter][i] = iterSC->satur().at(i);
262 m_scNet = truenet;
263 } else {
264 m_energyVec_Reco[cellCounter][i] = iterSC->energies().at(i);
265 if(m_energyVec_Reco[cellCounter][i] !=0) m_tauVec_Reco[cellCounter][i] = iterSC->tauEnergies().at(i)/m_energyVec_Reco[cellCounter][i];
266 m_passVec_Reco[cellCounter][i] = iterSC->passTauSelection().at(i);
267 m_saturVec_Reco[cellCounter][i] = iterSC->satur().at(i);
268 m_bcidVec_Reco[cellCounter][i] = iterSC->bcids().at(i);
269 m_recoNet = truenet;
270 }
271 } //m_eCut
272 }
273
274 if(etcontainer && recocontainer) {
275 truenet = m_recoNet;
276 if(truenet > secondSC->energies().size()) truenet=secondSC->energies().size();
277 for( unsigned i=0; i<truenet;++i){
278 if(std::abs(secondSC->energies().at(i)) > m_eCut) {
279 m_energyVec_Reco[cellCounter][i] = secondSC->energies().at(i);
280 if(m_energyVec_Reco[cellCounter][i] !=0) m_tauVec_Reco[cellCounter][i] = secondSC->tauEnergies().at(i)/m_energyVec_Reco[cellCounter][i];
281 m_passVec_Reco[cellCounter][i] = secondSC->passTauSelection().at(i);
282 m_saturVec_Reco[cellCounter][i] = secondSC->satur().at(i);
283 m_bcidVec_Reco[cellCounter][i] = secondSC->bcids().at(i);
284 }
285 }
286 m_recoNet = truenet;
287 }
288
289
290 if(rawcontainer) {
291 fillRODEnergy(iterSC->hardwareID(), cellCounter, rawChannelMap, cabling, cablingROD);
292 }
293
294 cellCounter++;
295 }// over iter+second container
296
297
298 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
299
300 ATH_MSG_DEBUG( "LArSC2NtupleEB has finished, filled"<< cellCounter << " cells" );
301 return StatusCode::SUCCESS;
302}// end finalize-method.
303
305 rawChanMap_t &rawChanMap, const LArOnOffIdMapping* cabling, const LArOnOffIdMapping* cablingROD)
306{
307 const Identifier offId = cabling->cnvToIdentifier(SCId);
308 const std::vector<Identifier> cellIds = m_scidtool->superCellToOfflineID(offId);
309 for(unsigned i=0; i<16; ++i) {
310 m_ROD_energy[cell][i] = 0.;
311 m_ROD_time[cell][i] = 0.;
312 m_ROD_id[cell][i] = 0.;
313 }
314 for(unsigned i=0; i<cellIds.size(); ++i ) {
315 const HWIdentifier hwcell=cablingROD->createSignalChannelID(cellIds[i]);
316 if (hwcell.is_valid() && (rawChanMap.count(hwcell) != 0) ) {
317 m_ROD_energy[cell][i] = rawChanMap[hwcell]->energy();
318 m_ROD_time[cell][i] = rawChanMap[hwcell]->time();
319 m_ROD_id[cell][i] = rawChanMap[hwcell]->hardwareID().get_identifier32().get_compact();
320 } else {
321 ATH_MSG_DEBUG(i<<"-th cell invalid Id");
322 }
323 }
324
325}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
INTupleSvc * ntupleSvc()
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
bool is_valid() const
Check if id is in a valid state.
Gaudi::Property< bool > m_isSC
const SG::ReadCondHandleKey< LArOnOffIdMapping > & cablingKey() const
bool fillFromIdentifier(const HWIdentifier &id, int C)
LArCond2NtupleBaseEB(const std::string &name, ISvcLocator *pSvcLocator)
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Container for LArRawChannel (IDC using LArRawChannelCollection).
Liquid Argon ROD output object base class.
Container class for LArRawSC.
Liquid Argon SuperCell raw data.
Definition LArRawSC.h:19
const std::vector< bool > & satur() const
Definition LArRawSC.h:107
const std::vector< bool > & passTauSelection() const
Definition LArRawSC.h:113
const std::vector< unsigned short > & bcids() const
Definition LArRawSC.h:104
const std::vector< int > & tauEnergies() const
Definition LArRawSC.h:110
const std::vector< int > & energies() const
Definition LArRawSC.h:101
const HWIdentifier & hardwareID() const
Definition LArRawSC.h:89
SG::ReadHandleKey< LArRawSCContainer > m_reccontKey
NTuple::Matrix< float > m_ROD_energy
SG::ReadHandleKey< LArRawChannelContainer > m_rawcontKey
SG::ReadHandleKey< LArRawSCContainer > m_sccontKey
NTuple::Matrix< float > m_ROD_time
Gaudi::Property< bool > m_fillBCID
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeyAdditional
void fillRODEnergy(HWIdentifier SCId, unsigned cell, rawChanMap_t &rawChanMap, const LArOnOffIdMapping *cabling, const LArOnOffIdMapping *cablingROD)
NTuple::Matrix< float > m_tauVec_Reco
NTuple::Matrix< float > m_energyVec_ET
NTuple::Item< unsigned long long > m_IEvent
NTuple::Matrix< bool > m_passVec_ET
NTuple::Matrix< bool > m_passVec_Reco
NTuple::Matrix< float > m_bcidVec_Reco
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
virtual StatusCode initialize() override
NTuple::Item< short > m_bcid
Gaudi::Property< unsigned int > m_recoNet
NTuple::Matrix< bool > m_saturVec_Reco
std::map< HWIdentifier, const LArRawChannel * > rawChanMap_t
Gaudi::Property< unsigned int > m_scNet
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
ToolHandle< ICaloSuperCellIDTool > m_scidtool
Gaudi::Property< float > m_eCut
NTuple::Matrix< bool > m_saturVec_ET
std::map< HWIdentifier, const LArRawSC * > rawSCMap_t
NTuple::Matrix< float > m_energyVec_Reco
NTuple::Matrix< float > m_bcidVec_ET
NTuple::Matrix< float > m_ROD_id
LArSC2NtupleEB(const std::string &name, ISvcLocator *pSvcLocator)
virtual bool isValid() override final
Can the handle be successfully dereferenced?