ATLAS Offline Software
Loading...
Searching...
No Matches
ReadLArDigits.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "ReadLArDigits.h"
7#include <vector>
8// #include "GaudiKernel/IToolSvc.h"
11
12
14{m_onlineHelper=onlineHelper;
15}
16
17ReadLArDigits::ReadLArDigits(const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator),
18 m_emId(nullptr),
19 m_onlineHelper(nullptr),
20 m_ntuplePtr(nullptr)
21
22{m_count=0;
23 declareProperty("DumpFile",m_dumpFile="");
24 declareProperty("PrintCellLocation",m_printCellLoc=false);
25 declareProperty("PrintFebChan",m_printFebChan=true);
26
27}
28
32
34{
35 ATH_MSG_INFO( "Initialize" );
36
37 const CaloCell_ID* idHelper = nullptr;
38 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
39 m_emId=idHelper->em_idHelper();
40
41 ATH_CHECK(m_cablingKey.initialize());
42 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
43
44 if (!m_dumpFile.empty())
45 m_outfile.open(m_dumpFile.c_str(),std::ios::out);
46 //Ntuple booking
47
48
49 NTupleFilePtr file1(ntupleSvc(),"/NTUPLES/FILE1");
50 if (!file1) {
51 ATH_MSG_ERROR( "Booking of NTuple failed" );
52 return StatusCode::FAILURE;
53 }
54 NTuplePtr nt(ntupleSvc(),"/NTUPLES/FILE1/LARDIGITS");
55 if (!nt) {
56 nt=ntupleSvc()->book("/NTUPLES/FILE1/LARDIGITS",CLID_ColumnWiseTuple,"LArDigits");
57 }
58 if (!nt) {
59 ATH_MSG_ERROR( "Booking of NTuple failed" );
60 return StatusCode::FAILURE;
61 }
62
63 ATH_CHECK( nt->addItem("icell",m_cellIndex,0,3600) );
64 ATH_CHECK( nt->addItem("layer",m_cellIndex,m_layer) );
65 ATH_CHECK( nt->addItem("ieta",m_cellIndex,m_eta) );
66 ATH_CHECK( nt->addItem("iphi",m_cellIndex,m_phi) );
67 ATH_CHECK( nt->addItem("barrel_ec",m_cellIndex,m_barrel_ec) );
68 ATH_CHECK( nt->addItem("pos_neg",m_cellIndex,m_pos_neg) );
69 ATH_CHECK( nt->addItem("FT",m_cellIndex,m_FT) );
70 ATH_CHECK( nt->addItem("slot",m_cellIndex,m_slot) );
71 ATH_CHECK( nt->addItem("channel",m_cellIndex,m_channel) );
72 ATH_CHECK( nt->addItem("gain",m_cellIndex,m_gain) );
73 ATH_CHECK( nt->addItem("NSamples",m_Nsamples,0,32) );
74 ATH_CHECK( nt->addItem("Samples",m_cellIndex,m_samples,32) );
75
76 ATH_CHECK( m_containerKey.initialize() );
77
78 m_ntuplePtr=nt;
79 m_count=0;
80 ATH_MSG_INFO( "======== ReadLArDigits initialize successfully ========" );
81 return StatusCode::SUCCESS;
82}
83
84
86{
87 m_count++;
88 ATH_MSG_VERBOSE( "======== executing event "<< m_count << " ========" );
89 ATH_MSG_VERBOSE( "Retrieving LArDigitContainer. Key= " << m_containerKey.key() );
90 const EventContext& ctx = Gaudi::Hive::currentContext();
92
93 // View container copy.
94 LArDigitContainer larDigitCont (*larDigitContIn);
95
97 const LArOnOffIdMapping* cabling{*cablingHdl};
98 if(!cabling) {
99 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
100 return StatusCode::FAILURE;
101 }
102
103
104 if (m_outfile.is_open()) {
105 SortDigits sortDigits(m_onlineHelper);
106 std::sort(larDigitCont.begin(),larDigitCont.end(),sortDigits);
107 }
108 unsigned cellCounter=0;
109 m_cellIndex=0;
110 if (!larDigitCont.empty())
111 m_Nsamples=larDigitCont.front()->samples().size();
112 else
113 m_Nsamples=0;
114 for (const LArDigit* digit : larDigitCont) {
115 HWIdentifier chid=digit->hardwareID();
116 const std::vector<short>& vSamples=digit->samples();
117 m_cellIndex++;
118 try {
119 const Identifier id=cabling->cnvToIdentifier(chid);
120 if (m_emId->is_lar_em(id))
121 {m_eta[cellCounter]=m_emId->eta(id);
122 m_phi[cellCounter]=m_emId->phi(id);
123 m_layer[cellCounter]=m_emId->sampling(id);
124 }
125 else {
126 m_eta[cellCounter]=0;
127 m_phi[cellCounter]=0;
128 m_layer[cellCounter]=0;
129 }
130 }
131 catch (LArID_Exception & except) {
132 m_eta[cellCounter]=-999;
133 m_phi[cellCounter]=-999;
134 m_layer[cellCounter]=-999;
135 }
136 m_barrel_ec[cellCounter]=m_onlineHelper->barrel_ec(chid);
137 m_pos_neg[cellCounter] = m_onlineHelper->pos_neg(chid);
138 m_FT[cellCounter] = m_onlineHelper->feedthrough(chid);
139 m_slot[cellCounter] = m_onlineHelper->slot(chid);
140 m_channel[cellCounter] = m_onlineHelper->channel(chid);
141 m_gain[cellCounter]=digit->gain();
142
143 int nSamples=vSamples.size();
144 for (int i=0;i<nSamples && i<32;i++)
145 m_samples[cellCounter][i]=vSamples[i];
146
147 if (m_outfile.is_open()) {
148 if (m_printCellLoc) {
149 if (m_eta[cellCounter]==-999 && m_phi[cellCounter]==-999 && m_layer[cellCounter]==-999)
150 m_outfile << "Cell l/e/p= <ILLEGAL IDENTIFIER> ";
151 else
152 m_outfile << "Cell l/e/p= " << m_layer[cellCounter] << "/" << m_eta[cellCounter]
153 << "/" << m_phi[cellCounter] << " ";
154 }
155 if (m_printFebChan)
156 m_outfile << "FebId= 0x" << std::hex << m_onlineHelper->feb_Id(chid).get_compact()
157 << std::dec << " Ch= " << m_channel[cellCounter] << " ";
158 for (int i=0;i<nSamples;i++) {
159 m_outfile << " " << vSamples[i];
160 }
161 m_outfile << " G=" << m_gain[cellCounter] << std::endl;
162 }
163 cellCounter++;
164 }
165 ATH_CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
166
167 if (m_count%1000==0)
168 ATH_MSG_INFO( "Event " << m_count << " contains " << cellCounter << " channels" );
169 return StatusCode::SUCCESS;
170}
171
173{
174 if (m_outfile.is_open())
175 m_outfile.close();
176 ATH_MSG_INFO( "finalize ReadLarDigits" );
177 return StatusCode::SUCCESS;
178}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
INTupleSvc * ntupleSvc()
Handle class for reading from StoreGate.
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 LArEM_ID * em_idHelper() const
access to EM idHelper
Definition CaloCell_ID.h:63
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.
bool empty() const noexcept
Returns true if the collection is empty.
Container class for LArDigit.
Liquid Argon digit base class.
Definition LArDigit.h:25
const std::vector< short > & samples() const
Definition LArDigit.h:78
Exception class for LAr Identifiers.
CTB: code to read digits.
SortDigits(const LArOnlineID *onlineHelper)
const LArOnlineID * m_onlineHelper
NTuple::Array< long > m_channel
NTuple::Matrix< long > m_samples
StatusCode finalize()
NTuple::Array< long > m_phi
const LArEM_ID * m_emId
NTuple::Tuple * m_ntuplePtr
NTuple::Array< long > m_layer
NTuple::Array< long > m_barrel_ec
ReadLArDigits(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
StatusCode initialize()
NTuple::Array< long > m_gain
NTuple::Item< long > m_cellIndex
SG::ReadHandleKey< LArDigitContainer > m_containerKey
NTuple::Array< long > m_slot
StatusCode execute()
NTuple::Array< long > m_pos_neg
const LArOnlineID * m_onlineHelper
NTuple::Array< long > m_eta
std::ofstream m_outfile
NTuple::Array< long > m_FT
NTuple::Item< long > m_Nsamples
std::string m_dumpFile
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.