ATLAS Offline Software
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"
23 #include "StoreGate/StoreGateSvc.h"
24 
25 
26 #include "CLHEP/Units/SystemOfUnits.h"
27 #include <iostream>
28 
29 using CLHEP::GeV;
30 
32  : m_poolMaxSize(0),
33  m_msgSvc (nullptr),
34  m_onlineID (nullptr),
35  m_ethreshold(-1.e5)
36 {
37 }
38 
39 
41 {
42  return ;
43 }
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 
244 LArCell* 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 
264 LArCell* 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.
272 LArCell* 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 
320 double
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 
grepfile.info
info
Definition: grepfile.py:38
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
MakeLArCellFromRaw::getLArCell
LArCell * getLArCell(unsigned int feb, unsigned int chan, int e, int t, int q, CaloGain::CaloGain caloGain, unsigned int &ttId) const
access by Identifier
Definition: MakeLArCellFromRaw.cxx:272
LArEM_ID.h
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
CaloGain::UNKNOWNGAIN
@ UNKNOWNGAIN
Definition: CaloGain.h:20
MakeLArCellFromRaw::getCorrection
double getCorrection(LArCell *cell, const std::vector< const CaloCellCorrection * > &vCorr, const EventContext &ctx) const
Definition: MakeLArCellFromRaw.cxx:321
MakeLArCellFromRaw::m_onlineID
const LArOnlineID * m_onlineID
Definition: MakeLArCellFromRaw.h:99
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
pool
pool namespace
Definition: libname.h:15
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CaloCellCorrection
Definition: CaloCellCorrection.h:51
Identifier::get_identifier32
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
LArHEC_ID
Helper class for LArHEC offline identifiers.
Definition: LArHEC_ID.h:85
MakeLArCellFromRaw::CellInfo
Definition: MakeLArCellFromRaw.h:35
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
LArHEC_ID.h
MakeLArCellFromRaw::CELL_VEC
std::vector< CellInfo > CELL_VEC
Definition: MakeLArCellFromRaw.h:89
HWIdentifier
Definition: HWIdentifier.h:13
LArRoIMap.h
Mapping between calorimeter trigger id to offline/online Identifier.
Identifier32::get_compact
value_type get_compact() const
Get the compact id.
Definition: Identifier32.h:44
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
CaloCell_ID.h
CaloCell_ID::hec_idHelper
const LArHEC_ID * hec_idHelper() const
access to HEC idHelper
Definition: CaloCell_ID.h:69
MakeLArCellFromRaw::initialize
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
Definition: MakeLArCellFromRaw.cxx:45
MakeLArCellFromRaw::~MakeLArCellFromRaw
~MakeLArCellFromRaw()
destructor
Definition: MakeLArCellFromRaw.cxx:40
MakeLArCellFromRaw::CellInfo::fcal
bool fcal
Definition: MakeLArCellFromRaw.h:42
LArFCAL_Base_ID::channel_ids
const std::vector< Identifier > & channel_ids() const
provide acces to channel id vector, accessed via hash
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1963
LArOnOffIdMapping.h
MakeLArCellFromRaw::CellInfo::tt
unsigned int tt
Definition: MakeLArCellFromRaw.h:43
MakeLArCellFromRaw.h
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
MakeLArCellFromRaw::CellInfo::eCorr
double eCorr
Definition: MakeLArCellFromRaw.h:45
MakeLArCellFromRaw::CellInfo::y
double y
Definition: MakeLArCellFromRaw.h:40
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MakeLArCellFromRaw::CellInfo::phi
double phi
Definition: MakeLArCellFromRaw.h:38
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
MakeLArCellFromRaw::m_ethreshold
float m_ethreshold
Definition: MakeLArCellFromRaw.h:101
LArOnOffIdMapping::createSignalChannelID
HWIdentifier createSignalChannelID(const Identifier &id) const
create a HWIdentifier from an Identifier (not inline)
Definition: LArOnOffIdMapping.h:126
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1479
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MakeLArCellFromRaw::CellInfo::eta
double eta
Definition: MakeLArCellFromRaw.h:37
MakeLArCellFromRaw::m_msgSvc
IMessageSvc * m_msgSvc
Definition: MakeLArCellFromRaw.h:97
PlotCalibFromCool.en
en
Definition: PlotCalibFromCool.py:399
LArCell
Data object for LAr calorimeter readout cell.
Definition: LArCell.h:53
MakeLArCellFromRaw::MakeLArCellFromRaw
MakeLArCellFromRaw()
constructor
Definition: MakeLArCellFromRaw.cxx:31
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
MakeLArCellFromRaw::setThreshold
void setThreshold(float t)
Definition: MakeLArCellFromRaw.cxx:341
LArFCAL_ID.h
CaloGain::LARMEDIUMGAIN
@ LARMEDIUMGAIN
Definition: CaloGain.h:18
MakeLArCellFromRaw::m_poolMaxSize
size_t m_poolMaxSize
Definition: MakeLArCellFromRaw.h:96
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
LArRoIMap
Mapping between calorimeter trigger id to offline/online Identifier.
Definition: LArRoIMap.h:31
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:63
CaloDetDescrManager::getCaloCell_ID
const CaloCell_ID * getCaloCell_ID() const
get calo cell ID helper
Definition: CaloDetDescrManager.cxx:1590
extractSporadic.q
list q
Definition: extractSporadic.py:98
MakeLArCellFromRaw::m_cellMap
CELL_MAP m_cellMap
Definition: MakeLArCellFromRaw.h:94
CaloDetDescrElement::eta
float eta() const
cell eta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:344
LArEM_ID
Helper class for LArEM offline identifiers.
Definition: LArEM_ID.h:118
CaloDetDescrElement::phi
float phi() const
cell phi
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:346
LArRoIMap::trigTowerID
TT_ID trigTowerID(const Identifier &channel_id) const
Translate offline channel identifier to trigger tower ID.
Definition: LArRoIMap.cxx:32
LArEM_Base_ID::channel_ids
const std::vector< Identifier > & channel_ids() const
provide access to channel id vector, accessed via hash
LArHEC_Base_ID::channel_ids
const std::vector< Identifier > & channel_ids() const
provide access to channel id vector, accessed via hash
LArFCAL_ID
Helper class for LArFCAL offline identifiers.
Definition: LArFCAL_ID.h:60
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
StoreGateSvc.h
python.compressB64.c
def c
Definition: compressB64.py:93
MakeLArCellFromRaw::CellInfo::z
double z
Definition: MakeLArCellFromRaw.h:41
LArID_Exception
Exception class for LAr Identifiers.
Definition: LArID_Exception.h:20
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
MakeLArCellFromRaw::CellInfo::elem
const CaloDetDescrElement * elem
Definition: MakeLArCellFromRaw.h:44
MakeLArCellFromRaw::CellInfo::x
double x
Definition: MakeLArCellFromRaw.h:39
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
Identifier
Definition: IdentifierFieldParser.cxx:14