ATLAS Offline Software
ReadTBLArDigits.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "LArRawEvent/LArDigit.h"
7 #include <vector>
8 #include "GaudiKernel/IToolSvc.h"
11 #include "GaudiKernel/ThreadLocalContext.h"
12 
14 {
15  m_onlineHelper = onlineHelper;
16 }
17 
18 ReadTBLArDigits::ReadTBLArDigits(const std::string& name, ISvcLocator* pSvcLocator)
19  : AthAlgorithm(name, pSvcLocator),
20  m_count(0),
21  m_emId(0),
22  m_fcalId(0),
23  m_hecId(0),
24  m_onlineHelper(0),
25  m_ntuplePtr(0)
26 {
27  declareProperty("ContainerKey",m_containerKey="");
28  declareProperty("DumpFile",m_dumpFile="");
29  declareProperty("PrintCellLocation",m_printCellLoc=false);
30  declareProperty("PrintFebChan",m_printFebChan=true);
31 
32 }
33 
35 {//empty
36 }
37 
39 { MsgStream log(msgSvc(), name());
40  log << MSG::INFO << "Initialize" << endmsg;
41 
42  const CaloCell_ID* idHelper = nullptr;
43  ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
44  m_emId=idHelper->em_idHelper();
45  m_fcalId=idHelper->fcal_idHelper();
46  m_hecId=idHelper->hec_idHelper();
47 
48  ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
49 
50  if (m_dumpFile.size()>0)
51  m_outfile.open(m_dumpFile.c_str(),std::ios::out);
52  //Ntuple booking
53 
54 
55  NTupleFilePtr file1(ntupleSvc(),"/NTUPLES/FILE1");
56  if (!file1)
57  {log << MSG::ERROR << "Booking of NTuple failed" << endmsg;
58  return StatusCode::FAILURE;
59  }
60  NTuplePtr nt(ntupleSvc(),"/NTUPLES/FILE1/LARDIGITS");
61  if (!nt) {
62  nt=ntupleSvc()->book("/NTUPLES/FILE1/LARDIGITS",CLID_ColumnWiseTuple,"LArDigits");
63  }
64  if (!nt)
65  {log << MSG::ERROR << "Booking of NTuple failed" << endmsg;
66  return StatusCode::FAILURE;
67  }
68 
69  ATH_CHECK( nt->addItem("icell",m_cellIndex,0,3600) );
70  ATH_CHECK( nt->addItem("layer",m_cellIndex,m_layer) );
71  ATH_CHECK( nt->addItem("ieta",m_cellIndex,m_eta) );
72  ATH_CHECK( nt->addItem("iphi",m_cellIndex,m_phi) );
73  ATH_CHECK( nt->addItem("barrel_ec",m_cellIndex,m_barrel_ec) );
74  ATH_CHECK( nt->addItem("pos_neg",m_cellIndex,m_pos_neg) );
75  ATH_CHECK( nt->addItem("FT",m_cellIndex,m_FT) );
76  ATH_CHECK( nt->addItem("slot",m_cellIndex,m_slot) );
77  ATH_CHECK( nt->addItem("channel",m_cellIndex,m_channel) );
78  ATH_CHECK( nt->addItem("gain",m_cellIndex,m_gain) );
79  ATH_CHECK( nt->addItem("NSamples",m_Nsamples,0,32) );
80  ATH_CHECK( nt->addItem("Samples",m_cellIndex,m_samples,32) );
81 
83 
85  m_count=0;
86  log << MSG::INFO << "======== ReadTBLArDigits initialize successfully ========" << endmsg;
87  return StatusCode::SUCCESS;
88 }
89 
90 
92 {
93  const EventContext& ctx = Gaudi::Hive::currentContext();
94 
95  MsgStream log(msgSvc(), name());
96  m_count++;
97  StatusCode sc;
98  log << MSG::DEBUG << "======== executing event "<< m_count << " ========" << endmsg;
99  log << MSG::DEBUG << "Retrieving TBLArDigitContainer. Key= " << m_containerKey << endmsg;
100  TBLArDigitContainer* larDigitCont = nullptr;
101  if (m_containerKey.size())
102  sc = evtStore()->retrieve(larDigitCont ,m_containerKey);
103  else
104  sc = evtStore()->retrieve(larDigitCont);
105  if (sc.isFailure())
106  {log << MSG::FATAL << " Cannot read TBLArDigitContainer from StoreGate! key=" << m_containerKey << endmsg;
107  return StatusCode::FAILURE;
108  }
109 
110 
111  if (m_outfile.is_open()) {
112  log << MSG::DEBUG << "Sorting digits" << endmsg;
113  SortDigits sortDigits(m_onlineHelper);
114  std::sort(larDigitCont->begin(),larDigitCont->end(),sortDigits);
115  }
116 
118 
119  log << MSG::DEBUG << "Finished sorting" << endmsg;
120  unsigned cellCounter=0;
121  if (larDigitCont->size()>0)
122  m_Nsamples=larDigitCont->front()->samples().size();
123  else
124  m_Nsamples=0;
125  log << MSG::DEBUG << "Now loop over digits" << endmsg;
126  for (const LArDigit* digit : *larDigitCont) {
127  HWIdentifier chid=digit->hardwareID();
128  log << MSG::DEBUG << "Get offline ID" << endmsg;
129  const Identifier id=cabling->cnvToIdentifier(chid);
130  const std::vector<short>& vSamples=digit->samples();
131  m_cellIndex=cellCounter;
132  log << MSG::DEBUG << "Now find eta/phi (EM only right now)" << endmsg;
133  if (m_emId->is_lar_em(id)) {
134  m_eta[m_cellIndex]=m_emId->eta(id);
135  m_phi[m_cellIndex]=m_emId->phi(id);
137  } else if (m_fcalId->is_lar_fcal(id)) {
138  m_eta[m_cellIndex]=m_fcalId->eta(id);
141  } else if (m_hecId->is_lar_hec(id)) {
142  m_eta[m_cellIndex]=m_hecId->eta(id);
145  } else {
146  m_eta[m_cellIndex]=0;
147  m_phi[m_cellIndex]=0;
148  m_layer[m_cellIndex]=0;
149  }
150  log << MSG::DEBUG << "Store identifier arrays" << endmsg;
156  m_gain[m_cellIndex]=digit->gain();
157 
158  log << MSG::DEBUG << "Loop over samples" << endmsg;
159  int nSamples=vSamples.size();
160  for (int i=0;i<nSamples && i<32;i++)
161  m_samples[m_cellIndex][i]=vSamples[i];
162 
163  if (m_outfile.is_open()) {
164  m_outfile << "Evt="<< m_count << " ";
165  if (m_printCellLoc)
166  m_outfile << "Cell l/e/p= " << m_layer[m_cellIndex] << "/" << m_eta[m_cellIndex]
167  << "/" << m_phi[m_cellIndex] << " ";
168  if (m_printFebChan)
169  m_outfile << "FebId= 0x" << std::hex << m_onlineHelper->feb_Id(chid).get_compact()
170  << std::dec << " Ch= " << m_onlineHelper->channel(chid) << " ";
171  for (int i=0;i<nSamples;i++) {
172  m_outfile << " " << vSamples[i];
173  }
174  m_outfile << " G=" << m_gain[m_cellIndex] << std::endl;
175  }
176  cellCounter++;
177  }
178  sc=ntupleSvc()->writeRecord(m_ntuplePtr);
179  if (sc!=StatusCode::SUCCESS) {
180  log << MSG::ERROR << "writeRecord failed" << endmsg;
181  return StatusCode::FAILURE;
182  }
183 
184  if (m_count%1000==0)
185  log << MSG::INFO << "Event " << m_count << " contains " << cellCounter << " channels\n";
186  return StatusCode::SUCCESS;
187 }
188 
190 { MsgStream log(msgSvc(), name());
191  if (m_outfile.is_open())
192  m_outfile.close();
193  log << MSG::INFO << "finalize ReadTBLArDigits" << endmsg;
194  return StatusCode::SUCCESS;
195 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ReadTBLArDigits::m_layer
NTuple::Array< long > m_layer
Definition: ReadTBLArDigits.h:55
ReadTBLArDigits::m_gain
NTuple::Array< long > m_gain
Definition: ReadTBLArDigits.h:55
LArEM_Base_ID::phi
int phi(const Identifier id) const
return phi according to :
ReadTBLArDigits.h
LArHEC_Base_ID::eta
int eta(const Identifier id) const
return eta [0,9] outer part [0,3] inner part
ReadTBLArDigits::ReadTBLArDigits
ReadTBLArDigits(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ReadTBLArDigits.cxx:18
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ReadTBLArDigits::finalize
virtual StatusCode finalize() override
Definition: ReadTBLArDigits.cxx:189
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
AtlasDetectorID::is_lar_fcal
bool is_lar_fcal(Identifier id) const
Definition: AtlasDetectorID.h:839
ReadTBLArDigits::m_dumpFile
std::string m_dumpFile
Definition: ReadTBLArDigits.h:47
ReadTBLArDigits::m_hecId
const LArHEC_ID * m_hecId
Definition: ReadTBLArDigits.h:43
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ReadTBLArDigits::m_phi
NTuple::Array< long > m_phi
Definition: ReadTBLArDigits.h:55
ReadTBLArDigits::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: ReadTBLArDigits.h:40
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArDigit::samples
const std::vector< short > & samples() const
Definition: LArDigit.h:78
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
LArOnlineID_Base::slot
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
Definition: LArOnlineID_Base.cxx:1957
ReadTBLArDigits::m_outfile
std::ofstream m_outfile
Definition: ReadTBLArDigits.h:45
LArFCAL_Base_ID::module
int module(const Identifier id) const
module [1,3]
Identifier::get_compact
value_type get_compact() const
Get the compact id.
ReadTBLArDigits::SortDigits::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: ReadTBLArDigits.h:68
LArEM_Base_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
ReadTBLArDigits::m_Nsamples
NTuple::Item< long > m_Nsamples
Definition: ReadTBLArDigits.h:58
ReadTBLArDigits::m_cellIndex
NTuple::Item< long > m_cellIndex
Definition: ReadTBLArDigits.h:54
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::barrel_ec
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
Definition: LArOnlineID_Base.cxx:1938
ReadTBLArDigits::m_emId
const LArEM_ID * m_emId
Definition: ReadTBLArDigits.h:41
LArEM_Base_ID::eta
int eta(const Identifier id) const
return eta according to :
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArFCAL_Base_ID::eta
int eta(const Identifier id) const
eta [0,63] module 1 ; [0,31] module 2 ; [0,15] module 3
CaloCell_ID.h
CaloCell_ID::hec_idHelper
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition: CaloCell_ID.h:69
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
ReadTBLArDigits::m_count
int m_count
Definition: ReadTBLArDigits.h:38
ReadTBLArDigits::m_samples
NTuple::Matrix< long > m_samples
Definition: ReadTBLArDigits.h:57
ReadTBLArDigits::m_containerKey
std::string m_containerKey
Definition: ReadTBLArDigits.h:46
LArFCAL_Base_ID::phi
int phi(const Identifier id) const
phi [0,15]
ReadTBLArDigits::m_slot
NTuple::Array< long > m_slot
Definition: ReadTBLArDigits.h:56
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1963
LArDigit.h
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadTBLArDigits::m_FT
NTuple::Array< long > m_FT
Definition: ReadTBLArDigits.h:56
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ReadTBLArDigits::~ReadTBLArDigits
~ReadTBLArDigits()
Definition: ReadTBLArDigits.cxx:34
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
LArOnlineID_Base::pos_neg
int pos_neg(const HWIdentifier id) const
Return the side of a hardware cell identifier pos_neg = [0,1] positive-side or negative-side Barrel...
Definition: LArOnlineID_Base.cxx:1950
ReadTBLArDigits::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: ReadTBLArDigits.h:44
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ReadTBLArDigits::SortDigits
Definition: ReadTBLArDigits.h:63
AtlasDetectorID::is_lar_hec
bool is_lar_hec(Identifier id) const
Definition: AtlasDetectorID.h:829
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
ReadTBLArDigits::SortDigits::SortDigits
SortDigits(const LArOnlineID *onlineHelper)
Definition: ReadTBLArDigits.cxx:13
ReadTBLArDigits::m_eta
NTuple::Array< long > m_eta
Definition: ReadTBLArDigits.h:55
AthAlgorithm
Definition: AthAlgorithm.h:47
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1479
ReadCondHandleKey.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ReadTBLArDigits::m_fcalId
const LArFCAL_ID * m_fcalId
Definition: ReadTBLArDigits.h:42
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArOnlineID
Definition: LArOnlineID.h:20
ReadTBLArDigits::m_pos_neg
NTuple::Array< long > m_pos_neg
Definition: ReadTBLArDigits.h:56
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ReadTBLArDigits::m_printFebChan
bool m_printFebChan
Definition: ReadTBLArDigits.h:49
LArOnlineID_Base::feedthrough
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
Definition: LArOnlineID_Base.cxx:1944
ReadTBLArDigits::initialize
virtual StatusCode initialize() override
Definition: ReadTBLArDigits.cxx:38
ReadTBLArDigits::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: ReadTBLArDigits.h:52
DEBUG
#define DEBUG
Definition: page_access.h:11
LArHEC_Base_ID::sampling
int sampling(const Identifier id) const
return sampling [0,3] (only 0 for supercells)
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ReadTBLArDigits::m_printCellLoc
bool m_printCellLoc
Definition: ReadTBLArDigits.h:48
ReadTBLArDigits::m_barrel_ec
NTuple::Array< long > m_barrel_ec
Definition: ReadTBLArDigits.h:56
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
TBLArDigitContainer
Gaudi Class ID.
Definition: TBLArDigitContainer.h:40
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
ReadTBLArDigits::execute
virtual StatusCode execute() override
Definition: ReadTBLArDigits.cxx:91
AtlasDetectorID::is_lar_em
bool is_lar_em(Identifier id) const
Definition: AtlasDetectorID.h:818
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
ReadTBLArDigits::m_channel
NTuple::Array< long > m_channel
Definition: ReadTBLArDigits.h:56
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArHEC_Base_ID::phi
int phi(const Identifier id) const
return phi[0,63] outer part [0,31] inner part
Identifier
Definition: IdentifierFieldParser.cxx:14