ATLAS Offline Software
Loading...
Searching...
No Matches
MakeLArCellFromRaw.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// implementation of MakeLArCellFromRaw
6// H.Ma Dec 2002
7// Updated to use DataPool HMA Jun 2003
8
10
12#include "CaloDetDescr/CaloDetDescrElement.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/ISvcLocator.h"
21#include "GaudiKernel/IToolSvc.h"
22#include "GaudiKernel/ThreadLocalContext.h"
24
25
26#include "CLHEP/Units/SystemOfUnits.h"
27#include <iostream>
28
29using CLHEP::GeV;
30
32 : m_poolMaxSize(0),
33 m_msgSvc (nullptr),
34 m_onlineID (nullptr),
35 m_ethreshold(-1.e5)
36{
37}
38
39
44
46 const LArOnOffIdMapping& onOffMap,
47 const CaloDetDescrManager& man,
48 const std::vector<const CaloCellCorrection*>* pCorr, unsigned int poolMaxSize )
49{
50 const EventContext& ctx = Gaudi::Hive::currentContext();
51
52 m_poolMaxSize = poolMaxSize;
53
54 MsgStream log(Athena::getMessageSvc(), "MakeLArCellFromRaw");
55
56 log << MSG::INFO <<" initializing MakeLArCellFromRaw"<< endmsg ;
57
58 if(pCorr) log <<MSG::INFO <<" Number of Corrections "<< pCorr->size()<< endmsg ;
59
60
61 SmartIF<StoreGateSvc> detStore{Gaudi::svcLocator( )->service("DetectorStore")};
62 if (!detStore)
63 {
64 log << MSG::ERROR << "MakeLArCellFromRaw ERROR cannot retrieve DetectorStore " << endmsg;
65 return;
66 }
67
68
69 // create DataPool if requested
70 if (poolMaxSize!=0) {
71 log << MSG::INFO << "MakeLArCellFromRaw Creating DataPool<LArCell> of size " << poolMaxSize << endmsg ;
72 }else{
73 log << MSG::INFO << "MakeLArCellFromRaw do not use DataPool" << endmsg ;
74 }
75
76
77 const CaloCell_ID* calo_id = man.getCaloCell_ID();
78 const LArEM_ID& em_id = *calo_id->em_idHelper();
79 const LArHEC_ID& hec_id = *calo_id->hec_idHelper();
80 const LArFCAL_ID& fcal_id = *calo_id->fcal_idHelper();
81
82 if (detStore->retrieve(m_onlineID, "LArOnlineID").isFailure()) {
83 log <<MSG::ERROR << "cannot find LArOnlineID in MakeLArCellFromRaw " << endmsg;
84 }
85
86
87 int n_em = 0 ;
88 int n_hec = 0 ;
89 int n_fcal = 0 ;
90
91 int n_em_err = 0 ;
92 int n_hec_err = 0 ;
93 int n_fcal_err = 0 ;
94
95
96 const std::vector<Identifier>& emIds = em_id.channel_ids();
97 const std::vector<Identifier>& hecIds = hec_id.channel_ids();
98 const std::vector<Identifier>& fcalIds = fcal_id.channel_ids();
99
100 double en=50. * GeV;
101 double time=0;
102 double qu=0;
103
104 CellInfo info0;
105 info0.eta=0;
106 info0.phi=0;
107 info0.x=0;
108 info0.y=0;
109 info0.z=0;
110 info0.fcal=false;
111 info0.tt=0;
112 info0.eCorr=1.;
113 info0.elem = nullptr ;
114
115 // EM
116 std::vector<Identifier>::const_iterator it = emIds.begin();
117 std::vector<Identifier>::const_iterator it2 = emIds.end();
118 for(; it!=it2;++it)
119 {
120 const Identifier& chan_id = *it ;
121
122 try{
123
124 HWIdentifier sigId = onOffMap.createSignalChannelID(chan_id);
125 HWIdentifier feb = m_onlineID->feb_Id(sigId);
126 CELL_VEC::size_type chan = m_onlineID->channel(sigId);
127 CELL_VEC& cellVec= m_cellMap[ feb.get_identifier32().get_compact() ] ;
128 if (cellVec.empty())cellVec.resize(128,info0);
129
130 CellInfo& cell = cellVec[chan] ;
131
132 cell.tt = roiMap.trigTowerID(sigId);
133
134 const CaloDetDescrElement* caloDDE =man.get_element( chan_id);
135
136 cell.id = chan_id ;
137 cell.eta = caloDDE->eta();
138 cell.phi = caloDDE->phi();
139 cell.fcal= false;
140 cell.elem =caloDDE;
141// to compute correction, assume that cell is in mid gain
143
144 ++n_em;
145 if(pCorr) {
146 // make a fake LArCell, and get the correction factor.
147 LArCell larCell(caloDDE,en,time,qu,g);
148 cell.eCorr = getCorrection(&larCell, *pCorr, ctx);
149 }
150 } catch (LArID_Exception& ex){
151 ++n_em_err;
152 }
153 } // end of EM
154
155
156
157 // HEC
158 it = hecIds.begin();
159 it2 = hecIds.end();
160 for(; it!=it2;++it)
161 {
162 const Identifier& chan_id = *it ;
163
164 try{
165
166 HWIdentifier sigId = onOffMap.createSignalChannelID(chan_id);
167// to change using LArOnline methods
168 HWIdentifier feb = m_onlineID->feb_Id(sigId);
169 CELL_VEC::size_type chan = m_onlineID->channel(sigId);
170 CELL_VEC& cellVec= m_cellMap[ feb.get_identifier32().get_compact() ] ;
171 if (cellVec.empty())cellVec.resize(128,info0);
172
173 CellInfo& cell = cellVec[chan] ;
174
175 cell.tt = roiMap.trigTowerID(sigId);
176
177 const CaloDetDescrElement* caloDDE =man.get_element( chan_id);
178
179 cell.id = chan_id ;
180 cell.eta = caloDDE->eta();
181 cell.phi = caloDDE->phi();
182 cell.fcal= false;
183 cell.elem =caloDDE;
185
186 if(pCorr) {
187 // make a fake LArCell, and get the correction factor.
188 LArCell larCell(caloDDE,en,time,qu,g);
189 cell.eCorr = getCorrection(&larCell, *pCorr, ctx);
190 }
191 ++n_hec;
192 } catch (LArID_Exception& ex){
193 ++n_hec_err;
194 }
195 } // end of HEC
196
197 // FCAL
198 it = fcalIds.begin();
199 it2 = fcalIds.end();
200 for(; it!=it2;++it)
201 {
202 const Identifier& chan_id = *it ;
203
204 try{
205
206 HWIdentifier sigId = onOffMap.createSignalChannelID(chan_id);
207// GU to change to use LArOnlineID method
208 HWIdentifier feb = m_onlineID->feb_Id(sigId);
209 CELL_VEC::size_type chan = m_onlineID->channel(sigId);
210 CELL_VEC& cellVec= m_cellMap[ feb.get_identifier32().get_compact() ] ;
211 if (cellVec.empty())cellVec.resize(128,info0);
212
213 CellInfo& cell = cellVec[chan] ;
214
215 cell.tt = roiMap.trigTowerID(sigId);
216
217 const CaloDetDescrElement* caloDDE =man.get_element( chan_id);
218
219 cell.id = chan_id ;
220 cell.eta = caloDDE->eta();
221 cell.phi = caloDDE->phi();
222 cell.fcal= false;
223 cell.elem =caloDDE;
225
226 if(pCorr) {
227 // make a fake LArCell, and get the correction factor.
228 LArCell larCell(caloDDE,en,time,qu,g);
229 cell.eCorr = getCorrection(&larCell, *pCorr, ctx);
230 }
231 ++n_fcal;
232 } catch (LArID_Exception& ex){
233 ++n_fcal_err;
234 }
235 } // end of FCAL
236
237
238 log <<MSG::INFO <<" number of em, hec, fcal cells="<<n_em<<" "<<n_hec<<" "<<n_fcal<<endmsg;
239 log <<MSG::INFO<<" number of exceptions for em,hec,fcal="<<n_em_err<<" "<<n_hec_err<<" "<<n_fcal_err<< endmsg;
240 log <<MSG::INFO<<" done with initializing MakeLArCellFromRaw"<< endmsg;
241 return;
242}
243
244LArCell* MakeLArCellFromRaw::getLArCell(const HWIdentifier& id, int e, int t, int q ) const
245{
246 return getLArCell(id, e, t, q, CaloGain::UNKNOWNGAIN);
247
248}
249
250
251// This method is use for converting LArRawChannel to LArCell
253{
254// GU to change
255
256 HWIdentifier feb = m_onlineID->feb_Id(id);
257 unsigned int chan = m_onlineID->channel(id);
258 unsigned int tt; // not needed for this method.
259// unsigned int ifeb = m_onlineID->feb_Hash(feb);
260 return getLArCell(feb.get_identifier32().get_compact() , chan , e, t, q, g, tt) ;
261}
262
263
264LArCell* MakeLArCellFromRaw::getLArCell(unsigned int feb, unsigned int chan ,
265 int e, int t, int q, unsigned int& ttId ) const
266{
267 return getLArCell(feb, chan ,e, t, q, CaloGain::UNKNOWNGAIN, ttId );
268
269}
270
271// This method is used for converting directly from BS to LArCell.
272LArCell* MakeLArCellFromRaw::getLArCell(unsigned int feb, unsigned int chan ,
273 int e, int t, int q, CaloGain::CaloGain g, unsigned int& ttId ) const
274{
275
276 CELL_MAP::const_iterator it =m_cellMap.find( feb );
277
278 if(it == m_cellMap.end()){
279 MsgStream log(m_msgSvc, "MakeLArCellFromRaw");
280 log << MSG::ERROR <<" MakeLArCellFromRaw ERROR, failed to find existing cells. "<< endmsg;
281 std::cout <<std::hex<<"FEBID = "<< feb <<std::dec<< std::endl ;
282 //DR assert(0);
283 return nullptr;
284 }
285
286 const CELL_VEC& cellVec = (*it).second;
287 if(cellVec.size()<= chan){
288 MsgStream log(m_msgSvc, "MakeLArCellFromRaw");
289 log << MSG::FATAL <<" MakeLArCellFromRaw ERROR, channel number= "<<chan<< endmsg ;
290 assert(0);
291 return nullptr;
292 }
293
294 const CellInfo& info = cellVec[chan] ;
295 // do not create cell if it is not connected.
296 if(info.elem == nullptr) return nullptr;
297
298 //remove /1000 (GeV->MeV)
299 double de = e * info.eCorr;
300 LArCell* cell =nullptr;
301
302 // DR convert time from ps (in LArRawChannel ) to ns
303 double time = t/1000.0;
304
305 if (m_poolMaxSize > 0) {
307 cell = new ( pool.nextElementPtr()) LArCell(info.elem,de,time,q,g);
308 }
309 else
310 {
311 cell = new LArCell(info.elem,de,time,q,g);
312 }
313
314 ttId = info.tt;
315
316 return cell;
317
318}
319
320double
322 const std::vector<const CaloCellCorrection*>& vCorr,
323 const EventContext& ctx) const
324{
325// LArCell was made with energy = 50.
326 double en= 50. * GeV ;
327// cell->setEnergy(en);
328
329 // apply corrections.
330 for (const CaloCellCorrection* corr : vCorr)
331 {
332 corr->MakeCorrection (cell, ctx);
333 }
334
335 double c= cell->energy()/en;
336 return c;
337}
338
339
340
342{
343 m_ethreshold = t;
344 return;
345}
346
#define endmsg
Definition of CaloDetDescrManager.
Mapping between calorimeter trigger id to offline/online Identifier.
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
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class provides the client interface for accessing the detector description information common to...
const CaloCell_ID * getCaloCell_ID() const
get calo cell ID helper
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Data object for LAr calorimeter readout cell.
Definition LArCell.h:53
const std::vector< Identifier > & channel_ids() const
provide access to channel id vector, accessed via hash
Helper class for LArEM offline identifiers.
Definition LArEM_ID.h:111
const std::vector< Identifier > & channel_ids() const
provide acces to channel id vector, accessed via hash
Helper class for LArFCAL offline identifiers.
Definition LArFCAL_ID.h:49
const std::vector< Identifier > & channel_ids() const
provide access to channel id vector, accessed via hash
Helper class for LArHEC offline identifiers.
Definition LArHEC_ID.h:76
Exception class for LAr Identifiers.
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Mapping between calorimeter trigger id to offline/online Identifier.
Definition LArRoIMap.h:31
TT_ID trigTowerID(const Identifier &channel_id) const
Translate offline channel identifier to trigger tower ID.
Definition LArRoIMap.cxx:32
void initialize(const LArRoIMap &roiMap, const LArOnOffIdMapping &onOffMap, const CaloDetDescrManager &man, const std::vector< const CaloCellCorrection * > *pCorr, unsigned int poolMaxSize=190000)
initialize the internal map
MakeLArCellFromRaw()
constructor
const LArOnlineID * m_onlineID
double getCorrection(LArCell *cell, const std::vector< const CaloCellCorrection * > &vCorr, const EventContext &ctx) const
LArCell * getLArCell(unsigned int feb, unsigned int chan, int e, int t, int q, CaloGain::CaloGain caloGain, unsigned int &ttId) const
access by Identifier
std::vector< CellInfo > CELL_VEC
IMessageSvc * getMessageSvc(bool quiet=false)
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ UNKNOWNGAIN
Definition CaloGain.h:21
pool namespace
Definition libname.h:15
const CaloDetDescrElement * elem