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
85StatusCode ReadLArDigits::execute(const EventContext& ctx)
86{
87 m_count++;
88 ATH_MSG_VERBOSE( "======== executing event "<< m_count << " ========" );
89 ATH_MSG_VERBOSE( "Retrieving LArDigitContainer. Key= " << m_containerKey.key() );
91
92 // View container copy.
93 LArDigitContainer larDigitCont (*larDigitContIn);
94
96 const LArOnOffIdMapping* cabling{*cablingHdl};
97 if(!cabling) {
98 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
99 return StatusCode::FAILURE;
100 }
101
102
103 if (m_outfile.is_open()) {
104 SortDigits sortDigits(m_onlineHelper);
105 std::sort(larDigitCont.begin(),larDigitCont.end(),sortDigits);
106 }
107 unsigned cellCounter=0;
108 m_cellIndex=0;
109 if (!larDigitCont.empty())
110 m_Nsamples=larDigitCont.front()->samples().size();
111 else
112 m_Nsamples=0;
113 for (const LArDigit* digit : larDigitCont) {
114 HWIdentifier chid=digit->hardwareID();
115 const std::vector<short>& vSamples=digit->samples();
116 m_cellIndex++;
117 try {
118 const Identifier id=cabling->cnvToIdentifier(chid);
119 if (m_emId->is_lar_em(id))
120 {m_eta[cellCounter]=m_emId->eta(id);
121 m_phi[cellCounter]=m_emId->phi(id);
122 m_layer[cellCounter]=m_emId->sampling(id);
123 }
124 else {
125 m_eta[cellCounter]=0;
126 m_phi[cellCounter]=0;
127 m_layer[cellCounter]=0;
128 }
129 }
130 catch (LArID_Exception & except) {
131 m_eta[cellCounter]=-999;
132 m_phi[cellCounter]=-999;
133 m_layer[cellCounter]=-999;
134 }
135 m_barrel_ec[cellCounter]=m_onlineHelper->barrel_ec(chid);
136 m_pos_neg[cellCounter] = m_onlineHelper->pos_neg(chid);
137 m_FT[cellCounter] = m_onlineHelper->feedthrough(chid);
138 m_slot[cellCounter] = m_onlineHelper->slot(chid);
139 m_channel[cellCounter] = m_onlineHelper->channel(chid);
140 m_gain[cellCounter]=digit->gain();
141
142 int nSamples=vSamples.size();
143 for (int i=0;i<nSamples && i<32;i++)
144 m_samples[cellCounter][i]=vSamples[i];
145
146 if (m_outfile.is_open()) {
147 if (m_printCellLoc) {
148 if (m_eta[cellCounter]==-999 && m_phi[cellCounter]==-999 && m_layer[cellCounter]==-999)
149 m_outfile << "Cell l/e/p= <ILLEGAL IDENTIFIER> ";
150 else
151 m_outfile << "Cell l/e/p= " << m_layer[cellCounter] << "/" << m_eta[cellCounter]
152 << "/" << m_phi[cellCounter] << " ";
153 }
154 if (m_printFebChan)
155 m_outfile << "FebId= 0x" << std::hex << m_onlineHelper->feb_Id(chid).get_compact()
156 << std::dec << " Ch= " << m_channel[cellCounter] << " ";
157 for (int i=0;i<nSamples;i++) {
158 m_outfile << " " << vSamples[i];
159 }
160 m_outfile << " G=" << m_gain[cellCounter] << std::endl;
161 }
162 cellCounter++;
163 }
164 ATH_CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
165
166 if (m_count%1000==0)
167 ATH_MSG_INFO( "Event " << m_count << " contains " << cellCounter << " channels" );
168 return StatusCode::SUCCESS;
169}
170
172{
173 if (m_outfile.is_open())
174 m_outfile.close();
175 ATH_MSG_INFO( "finalize ReadLarDigits" );
176 return StatusCode::SUCCESS;
177}
#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.
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()
StatusCode execute(const EventContext &ctx)
Execute method.
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
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.