ATLAS Offline Software
Loading...
Searching...
No Matches
ReadTBLArDigits.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include <vector>
8#include "GaudiKernel/IToolSvc.h"
11
13{
14 m_onlineHelper = onlineHelper;
15}
16
17ReadTBLArDigits::ReadTBLArDigits(const std::string& name, ISvcLocator* pSvcLocator)
18 : AthAlgorithm(name, pSvcLocator)
19{
20}
21
25
27{ MsgStream log(msgSvc(), name());
28 log << MSG::INFO << "Initialize" << endmsg;
29
30 const CaloCell_ID* idHelper = nullptr;
31 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
32 m_emId=idHelper->em_idHelper();
33 m_fcalId=idHelper->fcal_idHelper();
34 m_hecId=idHelper->hec_idHelper();
35
36 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
37
38 if (m_dumpFile.value().size()>0)
39 m_outfile.open(m_dumpFile.value().c_str(),std::ios::out);
40 //Ntuple booking
41
42
43 NTupleFilePtr file1(ntupleSvc(),"/NTUPLES/FILE1");
44 if (!file1)
45 {log << MSG::ERROR << "Booking of NTuple failed" << endmsg;
46 return StatusCode::FAILURE;
47 }
48 NTuplePtr nt(ntupleSvc(),"/NTUPLES/FILE1/LARDIGITS");
49 if (!nt) {
50 nt=ntupleSvc()->book("/NTUPLES/FILE1/LARDIGITS",CLID_ColumnWiseTuple,"LArDigits");
51 }
52 if (!nt)
53 {log << MSG::ERROR << "Booking of NTuple failed" << endmsg;
54 return StatusCode::FAILURE;
55 }
56
57 ATH_CHECK( nt->addItem("icell",m_cellIndex,0,3600) );
58 ATH_CHECK( nt->addItem("layer",m_cellIndex,m_layer) );
59 ATH_CHECK( nt->addItem("ieta",m_cellIndex,m_eta) );
60 ATH_CHECK( nt->addItem("iphi",m_cellIndex,m_phi) );
61 ATH_CHECK( nt->addItem("barrel_ec",m_cellIndex,m_barrel_ec) );
62 ATH_CHECK( nt->addItem("pos_neg",m_cellIndex,m_pos_neg) );
63 ATH_CHECK( nt->addItem("FT",m_cellIndex,m_FT) );
64 ATH_CHECK( nt->addItem("slot",m_cellIndex,m_slot) );
65 ATH_CHECK( nt->addItem("channel",m_cellIndex,m_channel) );
66 ATH_CHECK( nt->addItem("gain",m_cellIndex,m_gain) );
67 ATH_CHECK( nt->addItem("NSamples",m_Nsamples,0,32) );
68 ATH_CHECK( nt->addItem("Samples",m_cellIndex,m_samples,32) );
69
70 ATH_CHECK( m_cablingKey.initialize() );
71
72 m_ntuplePtr=nt;
73 m_count=0;
74 log << MSG::INFO << "======== ReadTBLArDigits initialize successfully ========" << endmsg;
75 return StatusCode::SUCCESS;
76}
77
78
79StatusCode ReadTBLArDigits::execute(const EventContext& ctx)
80{
81
82 MsgStream log(msgSvc(), name());
83 m_count++;
84 StatusCode sc;
85 log << MSG::DEBUG << "======== executing event "<< m_count << " ========" << endmsg;
86 log << MSG::DEBUG << "Retrieving TBLArDigitContainer. Key= " << m_containerKey.value() << endmsg;
87 TBLArDigitContainer* larDigitCont = nullptr;
88 if (m_containerKey.value().size())
89 sc = evtStore()->retrieve(larDigitCont ,m_containerKey.value());
90 else
91 sc = evtStore()->retrieve(larDigitCont);
92 if (sc.isFailure())
93 {log << MSG::FATAL << " Cannot read TBLArDigitContainer from StoreGate! key=" << m_containerKey.value() << endmsg;
94 return StatusCode::FAILURE;
95 }
96
97
98 if (m_outfile.is_open()) {
99 log << MSG::DEBUG << "Sorting digits" << endmsg;
100 SortDigits sortDigits(m_onlineHelper);
101 std::sort(larDigitCont->begin(),larDigitCont->end(),sortDigits);
102 }
103
105
106 log << MSG::DEBUG << "Finished sorting" << endmsg;
107 unsigned cellCounter=0;
108 if (larDigitCont->size()>0)
109 m_Nsamples=larDigitCont->front()->samples().size();
110 else
111 m_Nsamples=0;
112 log << MSG::DEBUG << "Now loop over digits" << endmsg;
113 for (const LArDigit* digit : *larDigitCont) {
114 HWIdentifier chid=digit->hardwareID();
115 log << MSG::DEBUG << "Get offline ID" << endmsg;
116 const Identifier id=cabling->cnvToIdentifier(chid);
117 const std::vector<short>& vSamples=digit->samples();
118 m_cellIndex=cellCounter;
119 log << MSG::DEBUG << "Now find eta/phi (EM only right now)" << endmsg;
120 if (m_emId->is_lar_em(id)) {
121 m_eta[m_cellIndex]=m_emId->eta(id);
122 m_phi[m_cellIndex]=m_emId->phi(id);
123 m_layer[m_cellIndex]=m_emId->sampling(id);
124 } else if (m_fcalId->is_lar_fcal(id)) {
125 m_eta[m_cellIndex]=m_fcalId->eta(id);
126 m_phi[m_cellIndex]=m_fcalId->phi(id);
127 m_layer[m_cellIndex]=m_fcalId->module(id);
128 } else if (m_hecId->is_lar_hec(id)) {
129 m_eta[m_cellIndex]=m_hecId->eta(id);
130 m_phi[m_cellIndex]=m_hecId->phi(id);
131 m_layer[m_cellIndex]=m_hecId->sampling(id);
132 } else {
136 }
137 log << MSG::DEBUG << "Store identifier arrays" << endmsg;
138 m_barrel_ec[m_cellIndex]=m_onlineHelper->barrel_ec(chid);
139 m_pos_neg[m_cellIndex] = m_onlineHelper->pos_neg(chid);
140 m_FT[m_cellIndex] = m_onlineHelper->feedthrough(chid);
141 m_slot[m_cellIndex] = m_onlineHelper->slot(chid);
142 m_channel[m_cellIndex] = m_onlineHelper->channel(chid);
143 m_gain[m_cellIndex]=digit->gain();
144
145 log << MSG::DEBUG << "Loop over samples" << endmsg;
146 int nSamples=vSamples.size();
147 for (int i=0;i<nSamples && i<32;i++)
148 m_samples[m_cellIndex][i]=vSamples[i];
149
150 if (m_outfile.is_open()) {
151 m_outfile << "Evt="<< m_count << " ";
152 if (m_printCellLoc)
153 m_outfile << "Cell l/e/p= " << m_layer[m_cellIndex] << "/" << m_eta[m_cellIndex]
154 << "/" << m_phi[m_cellIndex] << " ";
155 if (m_printFebChan)
156 m_outfile << "FebId= 0x" << std::hex << m_onlineHelper->feb_Id(chid).get_compact()
157 << std::dec << " Ch= " << m_onlineHelper->channel(chid) << " ";
158 for (int i=0;i<nSamples;i++) {
159 m_outfile << " " << vSamples[i];
160 }
161 m_outfile << " G=" << m_gain[m_cellIndex] << std::endl;
162 }
163 cellCounter++;
164 }
165 sc=ntupleSvc()->writeRecord(m_ntuplePtr);
166 if (sc!=StatusCode::SUCCESS) {
167 log << MSG::ERROR << "writeRecord failed" << endmsg;
168 return StatusCode::FAILURE;
169 }
170
171 if (m_count%1000==0)
172 log << MSG::INFO << "Event " << m_count << " contains " << cellCounter << " channels\n";
173 return StatusCode::SUCCESS;
174}
175
177{ MsgStream log(msgSvc(), name());
178 if (m_outfile.is_open())
179 m_outfile.close();
180 log << MSG::INFO << "finalize ReadTBLArDigits" << endmsg;
181 return StatusCode::SUCCESS;
182}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sc
INTupleSvc * ntupleSvc()
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition CaloCell_ID.h:75
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition CaloCell_ID.h:63
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition CaloCell_ID.h:69
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.
const T * front() const
Access the first element in the collection as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
Liquid Argon digit base class.
Definition LArDigit.h:25
const std::vector< short > & samples() const
Definition LArDigit.h:78
const LArOnlineID * m_onlineHelper
SortDigits(const LArOnlineID *onlineHelper)
NTuple::Array< long > m_phi
Gaudi::Property< std::string > m_dumpFile
std::ofstream m_outfile
const LArFCAL_ID * m_fcalId
const LArEM_ID * m_emId
virtual StatusCode initialize() override
virtual StatusCode finalize() override
NTuple::Array< long > m_slot
NTuple::Array< long > m_pos_neg
const LArHEC_ID * m_hecId
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
NTuple::Array< long > m_eta
Gaudi::Property< bool > m_printFebChan
NTuple::Item< long > m_cellIndex
NTuple::Item< long > m_Nsamples
Gaudi::Property< bool > m_printCellLoc
NTuple::Array< long > m_barrel_ec
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
NTuple::Array< long > m_layer
NTuple::Array< long > m_gain
const LArOnlineID * m_onlineHelper
ReadTBLArDigits(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::string > m_containerKey
NTuple::Tuple * m_ntuplePtr
NTuple::Matrix< long > m_samples
NTuple::Array< long > m_FT
NTuple::Array< long > m_channel
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.