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
131{
132
133 StatusCode sc;
134
135 const EventContext& ctx = Gaudi::Hive::currentContext();
136
137 ATH_MSG_DEBUG( "LArSC2NtupleEB in execute" );
138 unsigned long long thisevent;
139 unsigned long thisbcid = 0;
140
142 thisevent = evt->eventNumber();
143
144 thisbcid = evt->bcid();
145
146 const LArRawSCContainer* etcontainer = nullptr;
147 if (!m_sccontKey.empty()) {
149
150 if(!hdlSc.isValid()) {
151 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_sccontKey << " from DetectorStore. " );
152 return StatusCode::SUCCESS;
153 } else {
154 ATH_MSG_DEBUG( "Got LArRAwSCContainer with key " << m_sccontKey.key() );
155 etcontainer = &*hdlSc;
156 }
157 }
158
159 const LArRawSCContainer* recocontainer = nullptr;
160 if (!m_reccontKey.empty()) {
162
163 if(!hdlReco.isValid()) {
164 ATH_MSG_WARNING( "Unable to retrieve LArRawSCContainer with key " << m_reccontKey << " from DetectorStore. " );
165 return StatusCode::SUCCESS;
166 } else {
167 ATH_MSG_DEBUG( "Got LArRAwSCContainer with key " << m_reccontKey.key() );
168 recocontainer = &*hdlReco;
169 }
170 }
171
172 if(! (etcontainer || recocontainer)) {
173
174 ATH_MSG_WARNING( "Do not have any containers to loop on. " );
175 return StatusCode::SUCCESS;
176 }
177
178 const LArRawChannelContainer* rawcontainer = nullptr;
179 if (!m_rawcontKey.empty()) {
181
182 if(!hdlRaw.isValid()) {
183 ATH_MSG_WARNING( "Unable to retrieve LArRawChannelContainer with key " << m_rawcontKey << " from DetectorStore. " );
184 return StatusCode::SUCCESS;
185 } else {
186 ATH_MSG_DEBUG( "Got LArRAwChannelContainer with key " << m_rawcontKey.key() );
187 rawcontainer = &*hdlRaw;
188 }
189 }
190
191 unsigned cellCounter=0;
192
193 if(m_fillBCID) m_bcid = thisbcid;
194 m_IEvent = thisevent;
195
196 rawChanMap_t rawChannelMap;
197 rawSCMap_t rawSuperCellMap;
198
199 if(rawcontainer){
200 for (const LArRawChannel& raw : *rawcontainer) {
201 rawChannelMap.try_emplace( raw.channelID(), &raw );
202 }
203
204 }
205
206 const LArOnOffIdMapping* cabling=nullptr;
207 const LArOnOffIdMapping* cablingROD=nullptr;
208 if(rawcontainer){
210 cabling=*cablingHdl;
211 if(!cabling) {
212 ATH_MSG_ERROR( "Do not have cabling for SC!" );
213 return StatusCode::FAILURE;
214 }
216 cablingROD=*cablingHdlROD;
217 if(!cablingROD) {
218 ATH_MSG_ERROR( "Do not have cabling for ROD!" );
219 return StatusCode::FAILURE;
220 }
221 }
222
223
224 const LArRawSCContainer *itercont = nullptr;
225 const LArRawSCContainer *secondcont = nullptr;
226 if(etcontainer) {
227 itercont = etcontainer;
228 if(recocontainer) {
229 secondcont = recocontainer;
230 auto cbiter=secondcont->cbegin();
231 auto ceiter=secondcont->cend();
232 for ( ; cbiter<ceiter; ++cbiter) {
233 rawSuperCellMap.try_emplace( (*cbiter)->hardwareID(), *cbiter );
234 }
235 }
236 } else {
237 if(recocontainer) itercont = recocontainer;
238 }
239
240
241 auto cbsciter=itercont->cbegin();
242 auto cesciter=itercont->cend();
243 for( ; cbsciter<cesciter; ++cbsciter ){
244
245 const LArRawSC *iterSC = *cbsciter;
246 fillFromIdentifier(iterSC->hardwareID(), cellCounter);
247
248 const LArRawSC* secondSC = nullptr;
249 if( secondcont ){ // find corresponding LArRawSC
250 secondSC = rawSuperCellMap[iterSC->hardwareID()];
251 }
252
253 unsigned int truenet = etcontainer ? m_scNet : m_recoNet;
254
255 if(truenet > iterSC->energies().size()) truenet=iterSC->energies().size();
256 for( unsigned i=0; i<truenet;++i){
257 if(std::abs(iterSC->energies().at(i)) > m_eCut) {
258 if(etcontainer) {
259 m_energyVec_ET[cellCounter][i] = iterSC->energies().at(i);
260 if(iterSC->bcids().size()) m_bcidVec_ET[cellCounter][i] = iterSC->bcids().at(i);
261 if(iterSC->passTauSelection().size()) m_passVec_ET[cellCounter][i] = iterSC->passTauSelection().at(i);
262 if(iterSC->satur().size()) m_saturVec_ET[cellCounter][i] = iterSC->satur().at(i);
263 m_scNet = truenet;
264 } else {
265 m_energyVec_Reco[cellCounter][i] = iterSC->energies().at(i);
266 if(m_energyVec_Reco[cellCounter][i] !=0) m_tauVec_Reco[cellCounter][i] = iterSC->tauEnergies().at(i)/m_energyVec_Reco[cellCounter][i];
267 m_passVec_Reco[cellCounter][i] = iterSC->passTauSelection().at(i);
268 m_saturVec_Reco[cellCounter][i] = iterSC->satur().at(i);
269 m_bcidVec_Reco[cellCounter][i] = iterSC->bcids().at(i);
270 m_recoNet = truenet;
271 }
272 } //m_eCut
273 }
274
275 if(etcontainer && recocontainer) {
276 truenet = m_recoNet;
277 if(truenet > secondSC->energies().size()) truenet=secondSC->energies().size();
278 for( unsigned i=0; i<truenet;++i){
279 if(std::abs(secondSC->energies().at(i)) > m_eCut) {
280 m_energyVec_Reco[cellCounter][i] = secondSC->energies().at(i);
281 if(m_energyVec_Reco[cellCounter][i] !=0) m_tauVec_Reco[cellCounter][i] = secondSC->tauEnergies().at(i)/m_energyVec_Reco[cellCounter][i];
282 m_passVec_Reco[cellCounter][i] = secondSC->passTauSelection().at(i);
283 m_saturVec_Reco[cellCounter][i] = secondSC->satur().at(i);
284 m_bcidVec_Reco[cellCounter][i] = secondSC->bcids().at(i);
285 }
286 }
287 m_recoNet = truenet;
288 }
289
290
291 if(rawcontainer) {
292 fillRODEnergy(iterSC->hardwareID(), cellCounter, rawChannelMap, cabling, cablingROD);
293 }
294
295 cellCounter++;
296 }// over iter+second container
297
298
299 ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
300
301 ATH_MSG_DEBUG( "LArSC2NtupleEB has finished, filled"<< cellCounter << " cells" );
302 return StatusCode::SUCCESS;
303}// end finalize-method.
304
306 rawChanMap_t &rawChanMap, const LArOnOffIdMapping* cabling, const LArOnOffIdMapping* cablingROD)
307{
308 const Identifier offId = cabling->cnvToIdentifier(SCId);
309 const std::vector<Identifier> cellIds = m_scidtool->superCellToOfflineID(offId);
310 for(unsigned i=0; i<16; ++i) {
311 m_ROD_energy[cell][i] = 0.;
312 m_ROD_time[cell][i] = 0.;
313 m_ROD_id[cell][i] = 0.;
314 }
315 for(unsigned i=0; i<cellIds.size(); ++i ) {
316 const HWIdentifier hwcell=cablingROD->createSignalChannelID(cellIds[i]);
317 if (hwcell.is_valid() && (rawChanMap.count(hwcell) != 0) ) {
318 m_ROD_energy[cell][i] = rawChanMap[hwcell]->energy();
319 m_ROD_time[cell][i] = rawChanMap[hwcell]->time();
320 m_ROD_id[cell][i] = rawChanMap[hwcell]->hardwareID().get_identifier32().get_compact();
321 } else {
322 ATH_MSG_DEBUG(i<<"-th cell invalid Id");
323 }
324 }
325
326}
#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
virtual StatusCode execute() override
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 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?