ATLAS Offline Software
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 
10 LArSC2NtupleEB::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 
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 }
LArCond2NtupleBaseEB::m_ntTitle
std::string m_ntTitle
Definition: LArCond2NtupleBaseEB.h:63
LArRawSC
Liquid Argon SuperCell raw data.
Definition: LArRawSC.h:19
LArSC2NtupleEB::m_reccontKey
SG::ReadHandleKey< LArRawSCContainer > m_reccontKey
Definition: LArSC2NtupleEB.h:54
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
LArSC2NtupleEB::m_IEvent
NTuple::Item< unsigned long long > m_IEvent
Definition: LArSC2NtupleEB.h:35
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
LArSC2NtupleEB::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
Definition: LArSC2NtupleEB.h:57
LArSC2NtupleEB::m_ROD_energy
NTuple::Matrix< float > m_ROD_energy
Definition: LArSC2NtupleEB.h:49
LArSC2NtupleEB::m_saturVec_Reco
NTuple::Matrix< bool > m_saturVec_Reco
Definition: LArSC2NtupleEB.h:47
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
LArRawSCContainer
Container class for LArRawSC.
Definition: LArRawSCContainer.h:17
LArRawSC::hardwareID
const HWIdentifier & hardwareID() const
Definition: LArRawSC.h:89
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArSC2NtupleEB::m_ROD_id
NTuple::Matrix< float > m_ROD_id
Definition: LArSC2NtupleEB.h:51
LArCond2NtupleBaseEB::initialize
StatusCode initialize()
Definition: LArCond2NtupleBaseEB.cxx:29
LArCond2NtupleBaseEB::m_SC
const int m_SC
Definition: LArCond2NtupleBaseEB.h:80
DataVector::cend
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
LArSC2NtupleEB::m_passVec_ET
NTuple::Matrix< bool > m_passVec_ET
Definition: LArSC2NtupleEB.h:41
LArSC2NtupleEB::m_bcidVec_ET
NTuple::Matrix< float > m_bcidVec_ET
Definition: LArSC2NtupleEB.h:39
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
LArCond2NtupleBaseEB::m_ntpath
std::string m_ntpath
Definition: LArCond2NtupleBaseEB.h:63
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
HWIdentifier
Definition: HWIdentifier.h:13
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
LArSC2NtupleEB::m_fillBCID
Gaudi::Property< bool > m_fillBCID
Definition: LArSC2NtupleEB.h:31
LArRawSC::satur
const std::vector< bool > & satur() const
Definition: LArRawSC.h:107
LArRawSC::tauEnergies
const std::vector< int > & tauEnergies() const
Definition: LArRawSC.h:110
LArSC2NtupleEB::m_scNet
Gaudi::Property< unsigned int > m_scNet
Definition: LArSC2NtupleEB.h:29
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArSC2NtupleEB::m_recoNet
Gaudi::Property< unsigned int > m_recoNet
Definition: LArSC2NtupleEB.h:30
LArSC2NtupleEB::m_bcid
NTuple::Item< short > m_bcid
Definition: LArSC2NtupleEB.h:36
LArSC2NtupleEB::m_tauVec_Reco
NTuple::Matrix< float > m_tauVec_Reco
Definition: LArSC2NtupleEB.h:44
LArSC2NtupleEB::m_sccontKey
SG::ReadHandleKey< LArRawSCContainer > m_sccontKey
Definition: LArSC2NtupleEB.h:53
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArRawChannel
Liquid Argon ROD output object base class.
Definition: LArRawChannel.h:40
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
LArSC2NtupleEB::m_scidtool
ToolHandle< ICaloSuperCellIDTool > m_scidtool
Definition: LArSC2NtupleEB.h:61
LArSCDigit.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArSC2NtupleEB::m_energyVec_Reco
NTuple::Matrix< float > m_energyVec_Reco
Definition: LArSC2NtupleEB.h:43
LArSC2NtupleEB::m_rawcontKey
SG::ReadHandleKey< LArRawChannelContainer > m_rawcontKey
Definition: LArSC2NtupleEB.h:55
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
LArCond2NtupleBaseEB::fillFromIdentifier
bool fillFromIdentifier(const HWIdentifier &id, int C)
Definition: LArCond2NtupleBaseEB.cxx:280
LArOnOffIdMapping::createSignalChannelID
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Definition: LArOnOffIdMapping.h:126
LArCond2NtupleBaseEB
Definition: LArCond2NtupleBaseEB.h:32
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LArSC2NtupleEB::execute
virtual StatusCode execute() override
Definition: LArSC2NtupleEB.cxx:130
LArCond2NtupleBaseEB::cablingKey
const SG::ReadCondHandleKey< LArOnOffIdMapping > & cablingKey() const
Definition: LArCond2NtupleBaseEB.cxx:441
LArCond2NtupleBaseEB::m_nt
NTuple::Tuple * m_nt
Definition: LArCond2NtupleBaseEB.h:66
LArSC2NtupleEB::initialize
virtual StatusCode initialize() override
Definition: LArSC2NtupleEB.cxx:19
HWIdentifier.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArSC2NtupleEB::m_energyVec_ET
NTuple::Matrix< float > m_energyVec_ET
Definition: LArSC2NtupleEB.h:38
LArSC2NtupleEB::m_bcidVec_Reco
NTuple::Matrix< float > m_bcidVec_Reco
Definition: LArSC2NtupleEB.h:45
LArSC2NtupleEB::m_passVec_Reco
NTuple::Matrix< bool > m_passVec_Reco
Definition: LArSC2NtupleEB.h:46
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArRawSC::passTauSelection
const std::vector< bool > & passTauSelection() const
Definition: LArRawSC.h:113
LArDigitContainer.h
LArRawSC::bcids
const std::vector< unsigned short > & bcids() const
Definition: LArRawSC.h:104
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArSC2NtupleEB::m_cablingKeyAdditional
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeyAdditional
Definition: LArSC2NtupleEB.h:59
LArSC2NtupleEB::fillRODEnergy
void fillRODEnergy(HWIdentifier SCId, unsigned cell, rawChanMap_t &rawChanMap, const LArOnOffIdMapping *cabling, const LArOnOffIdMapping *cablingROD)
Definition: LArSC2NtupleEB.cxx:305
LArSC2NtupleEB::m_saturVec_ET
NTuple::Matrix< bool > m_saturVec_ET
Definition: LArSC2NtupleEB.h:40
LArSC2NtupleEB::m_ROD_time
NTuple::Matrix< float > m_ROD_time
Definition: LArSC2NtupleEB.h:50
DataVector::cbegin
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArSC2NtupleEB::rawChanMap_t
std::map< HWIdentifier, const LArRawChannel * > rawChanMap_t
Definition: LArSC2NtupleEB.h:63
LArSC2NtupleEB.h
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
LArSC2NtupleEB::rawSCMap_t
std::map< HWIdentifier, const LArRawSC * > rawSCMap_t
Definition: LArSC2NtupleEB.h:67
LArSC2NtupleEB::m_eCut
Gaudi::Property< float > m_eCut
Definition: LArSC2NtupleEB.h:33
LArSC2NtupleEB::LArSC2NtupleEB
LArSC2NtupleEB(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArSC2NtupleEB.cxx:10
LArRawChannelContainer
Container for LArRawChannel (IDC using LArRawChannelCollection)
Definition: LArRawChannelContainer.h:26
LArCond2NtupleBaseEB::m_isSC
Gaudi::Property< bool > m_isSC
Definition: LArCond2NtupleBaseEB.h:53
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
LArRawSC::energies
const std::vector< int > & energies() const
Definition: LArRawSC.h:101
Identifier
Definition: IdentifierFieldParser.cxx:14