ATLAS Offline Software
Loading...
Searching...
No Matches
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
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 m_count(0),
20 m_emId(0),
21 m_fcalId(0),
22 m_hecId(0),
25{
26 declareProperty("ContainerKey",m_containerKey="");
27 declareProperty("DumpFile",m_dumpFile="");
28 declareProperty("PrintCellLocation",m_printCellLoc=false);
29 declareProperty("PrintFebChan",m_printFebChan=true);
30
31}
32
36
38{ MsgStream log(msgSvc(), name());
39 log << MSG::INFO << "Initialize" << endmsg;
40
41 const CaloCell_ID* idHelper = nullptr;
42 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
43 m_emId=idHelper->em_idHelper();
44 m_fcalId=idHelper->fcal_idHelper();
45 m_hecId=idHelper->hec_idHelper();
46
47 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
48
49 if (m_dumpFile.size()>0)
50 m_outfile.open(m_dumpFile.c_str(),std::ios::out);
51 //Ntuple booking
52
53
54 NTupleFilePtr file1(ntupleSvc(),"/NTUPLES/FILE1");
55 if (!file1)
56 {log << MSG::ERROR << "Booking of NTuple failed" << endmsg;
57 return StatusCode::FAILURE;
58 }
59 NTuplePtr nt(ntupleSvc(),"/NTUPLES/FILE1/LARDIGITS");
60 if (!nt) {
61 nt=ntupleSvc()->book("/NTUPLES/FILE1/LARDIGITS",CLID_ColumnWiseTuple,"LArDigits");
62 }
63 if (!nt)
64 {log << MSG::ERROR << "Booking of NTuple failed" << endmsg;
65 return StatusCode::FAILURE;
66 }
67
68 ATH_CHECK( nt->addItem("icell",m_cellIndex,0,3600) );
69 ATH_CHECK( nt->addItem("layer",m_cellIndex,m_layer) );
70 ATH_CHECK( nt->addItem("ieta",m_cellIndex,m_eta) );
71 ATH_CHECK( nt->addItem("iphi",m_cellIndex,m_phi) );
72 ATH_CHECK( nt->addItem("barrel_ec",m_cellIndex,m_barrel_ec) );
73 ATH_CHECK( nt->addItem("pos_neg",m_cellIndex,m_pos_neg) );
74 ATH_CHECK( nt->addItem("FT",m_cellIndex,m_FT) );
75 ATH_CHECK( nt->addItem("slot",m_cellIndex,m_slot) );
76 ATH_CHECK( nt->addItem("channel",m_cellIndex,m_channel) );
77 ATH_CHECK( nt->addItem("gain",m_cellIndex,m_gain) );
78 ATH_CHECK( nt->addItem("NSamples",m_Nsamples,0,32) );
79 ATH_CHECK( nt->addItem("Samples",m_cellIndex,m_samples,32) );
80
81 ATH_CHECK( m_cablingKey.initialize() );
82
83 m_ntuplePtr=nt;
84 m_count=0;
85 log << MSG::INFO << "======== ReadTBLArDigits initialize successfully ========" << endmsg;
86 return StatusCode::SUCCESS;
87}
88
89
90StatusCode ReadTBLArDigits::execute(const EventContext& ctx)
91{
92
93 MsgStream log(msgSvc(), name());
94 m_count++;
95 StatusCode sc;
96 log << MSG::DEBUG << "======== executing event "<< m_count << " ========" << endmsg;
97 log << MSG::DEBUG << "Retrieving TBLArDigitContainer. Key= " << m_containerKey << endmsg;
98 TBLArDigitContainer* larDigitCont = nullptr;
99 if (m_containerKey.size())
100 sc = evtStore()->retrieve(larDigitCont ,m_containerKey);
101 else
102 sc = evtStore()->retrieve(larDigitCont);
103 if (sc.isFailure())
104 {log << MSG::FATAL << " Cannot read TBLArDigitContainer from StoreGate! key=" << m_containerKey << endmsg;
105 return StatusCode::FAILURE;
106 }
107
108
109 if (m_outfile.is_open()) {
110 log << MSG::DEBUG << "Sorting digits" << endmsg;
111 SortDigits sortDigits(m_onlineHelper);
112 std::sort(larDigitCont->begin(),larDigitCont->end(),sortDigits);
113 }
114
116
117 log << MSG::DEBUG << "Finished sorting" << endmsg;
118 unsigned cellCounter=0;
119 if (larDigitCont->size()>0)
120 m_Nsamples=larDigitCont->front()->samples().size();
121 else
122 m_Nsamples=0;
123 log << MSG::DEBUG << "Now loop over digits" << endmsg;
124 for (const LArDigit* digit : *larDigitCont) {
125 HWIdentifier chid=digit->hardwareID();
126 log << MSG::DEBUG << "Get offline ID" << endmsg;
127 const Identifier id=cabling->cnvToIdentifier(chid);
128 const std::vector<short>& vSamples=digit->samples();
129 m_cellIndex=cellCounter;
130 log << MSG::DEBUG << "Now find eta/phi (EM only right now)" << endmsg;
131 if (m_emId->is_lar_em(id)) {
132 m_eta[m_cellIndex]=m_emId->eta(id);
133 m_phi[m_cellIndex]=m_emId->phi(id);
134 m_layer[m_cellIndex]=m_emId->sampling(id);
135 } else if (m_fcalId->is_lar_fcal(id)) {
136 m_eta[m_cellIndex]=m_fcalId->eta(id);
137 m_phi[m_cellIndex]=m_fcalId->phi(id);
138 m_layer[m_cellIndex]=m_fcalId->module(id);
139 } else if (m_hecId->is_lar_hec(id)) {
140 m_eta[m_cellIndex]=m_hecId->eta(id);
141 m_phi[m_cellIndex]=m_hecId->phi(id);
142 m_layer[m_cellIndex]=m_hecId->sampling(id);
143 } else {
147 }
148 log << MSG::DEBUG << "Store identifier arrays" << endmsg;
149 m_barrel_ec[m_cellIndex]=m_onlineHelper->barrel_ec(chid);
150 m_pos_neg[m_cellIndex] = m_onlineHelper->pos_neg(chid);
151 m_FT[m_cellIndex] = m_onlineHelper->feedthrough(chid);
152 m_slot[m_cellIndex] = m_onlineHelper->slot(chid);
153 m_channel[m_cellIndex] = m_onlineHelper->channel(chid);
154 m_gain[m_cellIndex]=digit->gain();
155
156 log << MSG::DEBUG << "Loop over samples" << endmsg;
157 int nSamples=vSamples.size();
158 for (int i=0;i<nSamples && i<32;i++)
159 m_samples[m_cellIndex][i]=vSamples[i];
160
161 if (m_outfile.is_open()) {
162 m_outfile << "Evt="<< m_count << " ";
163 if (m_printCellLoc)
164 m_outfile << "Cell l/e/p= " << m_layer[m_cellIndex] << "/" << m_eta[m_cellIndex]
165 << "/" << m_phi[m_cellIndex] << " ";
166 if (m_printFebChan)
167 m_outfile << "FebId= 0x" << std::hex << m_onlineHelper->feb_Id(chid).get_compact()
168 << std::dec << " Ch= " << m_onlineHelper->channel(chid) << " ";
169 for (int i=0;i<nSamples;i++) {
170 m_outfile << " " << vSamples[i];
171 }
172 m_outfile << " G=" << m_gain[m_cellIndex] << std::endl;
173 }
174 cellCounter++;
175 }
176 sc=ntupleSvc()->writeRecord(m_ntuplePtr);
177 if (sc!=StatusCode::SUCCESS) {
178 log << MSG::ERROR << "writeRecord failed" << endmsg;
179 return StatusCode::FAILURE;
180 }
181
182 if (m_count%1000==0)
183 log << MSG::INFO << "Event " << m_count << " contains " << cellCounter << " channels\n";
184 return StatusCode::SUCCESS;
185}
186
188{ MsgStream log(msgSvc(), name());
189 if (m_outfile.is_open())
190 m_outfile.close();
191 log << MSG::INFO << "finalize ReadTBLArDigits" << endmsg;
192 return StatusCode::SUCCESS;
193}
#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.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
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
std::string m_containerKey
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
NTuple::Array< long > m_eta
NTuple::Item< long > m_cellIndex
NTuple::Item< long > m_Nsamples
std::string m_dumpFile
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)
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.