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#include "GaudiKernel/ThreadLocalContext.h"
12
14{
15 m_onlineHelper = onlineHelper;
16}
17
18ReadTBLArDigits::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),
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
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
82 ATH_CHECK( m_cablingKey.initialize() );
83
84 m_ntuplePtr=nt;
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);
136 m_layer[m_cellIndex]=m_emId->sampling(id);
137 } else if (m_fcalId->is_lar_fcal(id)) {
138 m_eta[m_cellIndex]=m_fcalId->eta(id);
139 m_phi[m_cellIndex]=m_fcalId->phi(id);
140 m_layer[m_cellIndex]=m_fcalId->module(id);
141 } else if (m_hecId->is_lar_hec(id)) {
142 m_eta[m_cellIndex]=m_hecId->eta(id);
143 m_phi[m_cellIndex]=m_hecId->phi(id);
144 m_layer[m_cellIndex]=m_hecId->sampling(id);
145 } else {
149 }
150 log << MSG::DEBUG << "Store identifier arrays" << endmsg;
151 m_barrel_ec[m_cellIndex]=m_onlineHelper->barrel_ec(chid);
152 m_pos_neg[m_cellIndex] = m_onlineHelper->pos_neg(chid);
153 m_FT[m_cellIndex] = m_onlineHelper->feedthrough(chid);
154 m_slot[m_cellIndex] = m_onlineHelper->slot(chid);
155 m_channel[m_cellIndex] = m_onlineHelper->channel(chid);
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}
#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 with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
virtual StatusCode execute() override
const LArHEC_ID * m_hecId
std::string m_containerKey
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.