ATLAS Offline Software
FastHitConvertTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // FastHitConvertTool.cxx, (c) ATLAS Detector software
8 
9 #include "FastHitConvertTool.h"
10 
11 #include "GaudiKernel/ConcurrencyFlags.h"
12 
19 #include "CaloIdentifier/TileID.h"
22 #include "EventInfo/EventType.h"
25 #include "LArSimEvent/LArHit.h"
28 #include "StoreGate/StoreGateSvc.h"
31 #include "TileSimEvent/TileHit.h"
33 
34 //================ Constructor =================================================
35 
37  const std::string& name,
38  const IInterface* parent )
39  :
40  base_class(type,name,parent),
41  m_storeGateFastCalo("StoreGateSvc/FastCalo",name)
42 {
43 }
44 
45 //================ Destructor =================================================
46 
47 // FastHitConvertTool::~FastHitConvertTool()
48 //{}
49 
50 
51 //================ Initialisation =================================================
52 
54 {
55 
56  //Service for Pileup
57  if(m_pileup)
58  {
59  CHECK(service("PileUpMergeSvc", m_pMergeSvc));
60  CHECK(m_storeGateFastCalo.retrieve());
61  }
62  ATH_MSG_DEBUG("StoreGateFastCalo Svc structure at Initialisation"<<(*m_storeGateFastCalo).dump());
63  const CaloIdManager* caloIdManager = nullptr;
64  CHECK(detStore()->retrieve(caloIdManager));
65  m_larEmID=caloIdManager->getEM_ID();
66  if(m_larEmID==0)
67  throw std::runtime_error("FastHitConvertTool: Invalid LAr EM ID helper");
68  m_larFcalID=caloIdManager->getFCAL_ID();
69  if(m_larFcalID==0)
70  throw std::runtime_error("FastHitConvertTool: Invalid FCAL ID helper");
71  m_larHecID=caloIdManager->getHEC_ID();
72  if(m_larHecID==0)
73  throw std::runtime_error("FastHitConvertTool: Invalid HEC ID helper");
74  m_tileID=caloIdManager->getTileID();
75  if(m_tileID==0)
76  throw std::runtime_error("FastHitConvertTool: Invalid Tile ID helper");
77 
78  // LAr and Tile Sampling Fractions
80 
83 
84  ATH_CHECK( m_tileCablingSvc.retrieve() );
85  m_tileCabling = m_tileCablingSvc->cablingService();
86 
87  // Output keys
92  ATH_CHECK(m_tileHitVectorKey.initialize());
93 
94  // Inputs for pileup (only initialized if m_pileup==true)
97 
98  return StatusCode::SUCCESS;
99 }
100 
101 StatusCode FastHitConvertTool::process(CaloCellContainer* theCellCont, const EventContext& ctx) const
102 {
103  ATH_MSG_DEBUG("initEvent()");
104  auto embHitContainer = SG::makeHandle<LArHitContainer>( m_embHitContainerKey, ctx );
105  auto emecHitContainer = SG::makeHandle<LArHitContainer>( m_emecHitContainerKey, ctx );
106  auto fcalHitContainer = SG::makeHandle<LArHitContainer>( m_fcalHitContainerKey, ctx );
107  auto hecHitContainer = SG::makeHandle<LArHitContainer>( m_hecHitContainerKey, ctx );
108  auto tileHitVector = SG::makeHandle<TileHitVector>( m_tileHitVectorKey, ctx );
109  embHitContainer = std::make_unique<LArHitContainer>( m_embHitContainerKey.key() );
110  emecHitContainer = std::make_unique<LArHitContainer>( m_emecHitContainerKey.key() );
111  fcalHitContainer = std::make_unique<LArHitContainer>( m_fcalHitContainerKey.key() );
112  hecHitContainer = std::make_unique<LArHitContainer>( m_hecHitContainerKey.key() );
113  tileHitVector = std::make_unique<TileHitVector>( m_tileHitVectorKey.key() );
114 
115  ATH_MSG_DEBUG("ATLFASTIIDigi "<<this->name()<<" hitConstruction");
116  const double minEnergy=1e-9;
117  double hitTime=0.0;
118  Identifier cellid((unsigned int) 0);
119  double energy=0.0;
120  double energyConv=0.0;
121  float SampFrac=0.0;
122 
123  int countFastCell=0;
124 
125  double eLArEMRead=0.0;
126  double eLArHECRead=0.0;
127  double eLArFCALRead=0.0;
128  double eTileRead=0.0;
129 
130  double eLArEMConv=0.0;
131  double eLArHECConv=0.0;
132  double eLArFCALConv=0.0;
133  double eTileConv=0.0;
134 
136  const ILArfSampl* fSampl=*fSamplHdl;
137 
140  for(;it1!=it2;++it1)
141  {
142  ATH_MSG_DEBUG("FastCell LArEM"<<countFastCell);
143 
144  cellid=(*it1)->ID();
145  energy=(*it1)->energy();
146  SampFrac=fSampl->FSAMPL(cellid);
147  energyConv=energy*SampFrac;
148 
149  eLArEMRead+=energy;
150  eLArEMConv+=energyConv;
151 
152  ATH_MSG_DEBUG("ReadFastCell id= "<<cellid<<"E= "<<energy<<" SampFrac= "<<SampFrac);
153  if(energyConv > minEnergy)
154  {
155  if(m_larEmID->is_lar_em(cellid))
156  {
157  if(m_larEmID->is_em_barrel(cellid))
158  {
159  ATH_MSG_DEBUG("Storing em barrel hit");
160  embHitContainer->push_back(new LArHit(cellid,energyConv,hitTime));
161  }
162  else if(m_larEmID->is_em_endcap(cellid))
163  {
164  ATH_MSG_DEBUG("Storing em endcap hit");
165  emecHitContainer->push_back(new LArHit(cellid,energyConv,hitTime));
166  }
167  }
168  }
169  countFastCell++;
170  }
171 
172  it1=theCellCont->beginConstCalo(CaloCell_ID::LARHEC);
173  it2=theCellCont->endConstCalo(CaloCell_ID::LARHEC);
174 
175  countFastCell=0;
176  for(;it1!=it2;++it1)
177  {
178  ATH_MSG_DEBUG("FastCell LArHEC"<<countFastCell);
179 
180  cellid=(*it1)->ID();
181  energy=(*it1)->energy();
182  SampFrac=fSampl->FSAMPL(cellid);
183  energyConv=energy*SampFrac;
184 
185  eLArHECRead+=energy;
186  eLArHECConv+=energyConv;
187 
188  ATH_MSG_DEBUG("ReadFastCell id= "<<cellid<<"E= "<<energy<<"SampFrac= "<<SampFrac);
189 
190  if(energyConv>minEnergy)
191  {
192  if(m_larHecID->is_lar_hec(cellid))
193  {
194  ATH_MSG_DEBUG("Storing hec hit");
195  hecHitContainer->push_back(new LArHit(cellid,energyConv,hitTime));
196  }
197  }
198  countFastCell++;
199  }
200 
202  it2=theCellCont->endConstCalo(CaloCell_ID::LARFCAL);
203  countFastCell=0;
204  for(;it1!=it2;++it1)
205  {
206  ATH_MSG_DEBUG("FastCell LArFCAL"<<countFastCell);
207  cellid=(*it1)->ID();
208  energy=(*it1)->energy();
209  SampFrac=fSampl->FSAMPL(cellid);
210  energyConv=energy*SampFrac;
211 
212  eLArHECRead+=energy;
213  eLArHECConv+=energyConv;
214 
215  ATH_MSG_DEBUG("ReadFastCell id= "<<cellid<<"E="<<energy<<"SampFrac="<<SampFrac);
216  if(energyConv>minEnergy)
217  {
218  if(m_larFcalID->is_lar_fcal(cellid))
219  {
220  ATH_MSG_DEBUG("Storing fcal hit");
221  fcalHitContainer->push_back(new LArHit(cellid,energyConv,hitTime));
222  }
223  }
224  countFastCell++;
225  }
226 
228  ATH_CHECK( tileSamplingFraction.isValid() );
229 
230  it1=theCellCont->beginConstCalo(CaloCell_ID::TILE);
231  it2=theCellCont->endConstCalo(CaloCell_ID::TILE);
232 
233  countFastCell=0;
234  Identifier pmt_id0((unsigned int) 0);
235  Identifier pmt_id1((unsigned int) 0);
236 
237  for(;it1!=it2;++it1)
238  {
239  ATH_MSG_DEBUG("FastCell Tile Cal"<<countFastCell);
240  cellid=(*it1)->ID();
241  energy=(*it1)->energy();
242 
243  pmt_id0=m_tileID->pmt_id(cellid,0);
244  pmt_id1=m_tileID->pmt_id(cellid,1);
245 
248  int drawerIdx = m_tileHWID->drawerIdx(channel_id);
249  SampFrac = tileSamplingFraction->getSamplingFraction(drawerIdx, channel);
250  energyConv=energy/SampFrac;
251 
252  eTileRead+=energy;
253  eTileConv+=energyConv;
254 
255  ATH_MSG_DEBUG("ReadFastCell id= "<<cellid<<"E="<<energy<<"SampFrac"<<SampFrac);
256  ATH_MSG_DEBUG("PMT_id0="<<pmt_id0<<"PMT_id1="<<pmt_id1);
257  if(energyConv>minEnergy)
258  {
259  if(m_tileID->is_tile(cellid))
260  {
261  ATH_MSG_DEBUG("Storing tile hit");
262  if(m_tileID->is_tile_gapscin(cellid))
263  {
264  tileHitVector->push_back(TileHit(pmt_id0,energyConv,hitTime));
265  }
266  else
267  {
268  tileHitVector->push_back(TileHit(pmt_id0,energyConv/2.0,hitTime));
269  tileHitVector->push_back(TileHit(pmt_id1,energyConv/2.0,hitTime));
270  }
271  }
272  }
273  countFastCell++;
274  }
275  ATH_MSG_DEBUG("eReadTot= "<<eLArEMRead+eLArHECRead+eLArFCALRead+eTileRead);
276  ATH_MSG_DEBUG("eLArEMRead= "<<eLArEMRead<<" eLArHECRead= "<<eLArHECRead<<" eLArFCALRead= "<<eLArFCALRead<<" eTileRead= "<<eTileRead);
277  ATH_MSG_DEBUG("eConvTot= "<<eLArEMConv+eLArHECConv+eLArFCALConv+eTileConv);
278  ATH_MSG_DEBUG("eLArEMConv= "<<eLArEMConv<<" eLArHECConv= "<<eLArHECConv<<"eLArFCALConv"<<eLArFCALConv<<"eTileConv"<<eTileConv);
279 
280  ATH_MSG_DEBUG("finaliseEvent()");
281  ATH_MSG_DEBUG(embHitContainer.name()<<" : "<<embHitContainer->size()<<" hits ");
282  ATH_MSG_DEBUG(emecHitContainer.name()<<" : "<<emecHitContainer->size()<<" hits ");
283  ATH_MSG_DEBUG(fcalHitContainer.name()<<" : "<<fcalHitContainer->size()<<" hits ");
284  ATH_MSG_DEBUG(hecHitContainer.name()<<" : "<<hecHitContainer->size()<<" hits ");
285  ATH_MSG_DEBUG(tileHitVector.name()<<" : "<<tileHitVector->size()<<" hits ");
286 
287  if(m_pileup)
288  {
289  CHECK((*m_storeGateFastCalo).clearStore(true));
290  auto evt = SG::makeHandle<EventInfo>(m_pileup_evt, ctx);
291  const EventInfo* newEvt=new EventInfo(*evt);
292 
293  // Migration note: this was an evtStore()->retrieve for a non-const pointer
294  // Using a const_cast to preserve the old behaviour, but this is MT-unfriendly
295  if (Gaudi::Concurrency::ConcurrencyFlags::numConcurrentEvents() > 1) {
296  ATH_MSG_ERROR ("FastHitConvertTool doesn't support pileup in AthenaMT");
297  return StatusCode::FAILURE;
298  }
299  auto pOverEventHandle = SG::makeHandle<PileUpEventInfo>(m_pileup_pOverEvent, ctx);
300  auto pOverEvent ATLAS_THREAD_SAFE = // we checked above that this is not MT
301  const_cast<PileUpEventInfo*>(pOverEventHandle.get());
303  }
304  return StatusCode::SUCCESS;
305 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileSamplingFraction::getSamplingFraction
float getSamplingFraction(unsigned int drawerIdx, unsigned int channel) const
Return Tile Calorimeter sampling fraction.
Definition: TileSamplingFraction.h:53
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
LArEM_ID.h
FastHitConvertTool::process
virtual StatusCode process(CaloCellContainer *theCellContainer, const EventContext &ctx) const override
standard Athena-Algorithm method
Definition: FastHitConvertTool.cxx:101
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
AthCheckMacros.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
FastHitConvertTool::m_larEmID
const LArEM_ID * m_larEmID
Definition: FastHitConvertTool.h:90
PileUpEventInfo.h
This class provides information about an overlaid event. It extends EventInfo with a list of sub-evts...
AtlasDetectorID::is_lar_fcal
bool is_lar_fcal(Identifier id) const
Definition: AtlasDetectorID.h:839
FastHitConvertTool::initialize
virtual StatusCode initialize() override final
standard Athena-Algorithm method
Definition: FastHitConvertTool.cxx:53
FastHitConvertTool.h
FastHitConvertTool::m_embHitContainerKey
SG::WriteHandleKey< LArHitContainer > m_embHitContainerKey
Definition: FastHitConvertTool.h:67
CaloIdManager::getEM_ID
const LArEM_ID * getEM_ID(void) const
Definition: CaloIdManager.cxx:80
EventInfo
EventInfo
Definition: EventTPCnv.cxx:47
CaloCellContainer::beginConstCalo
CaloCellContainer::const_iterator beginConstCalo(CaloCell_ID::SUBCALO caloNum) const
get const iterators on cell of just one calo
Definition: CaloCellContainer.cxx:119
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
FastHitConvertTool::m_fcalHitContainerKey
SG::WriteHandleKey< LArHitContainer > m_fcalHitContainerKey
Definition: FastHitConvertTool.h:69
CaloCell_Base_ID::LARHEC
@ LARHEC
Definition: CaloCell_Base_ID.h:46
FastHitConvertTool::m_storeGateFastCalo
ServiceHandle< StoreGateSvc > m_storeGateFastCalo
Definition: FastHitConvertTool.h:73
EventType.h
This class provides general information about an event. It extends EventInfo with a list of sub-evts ...
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
FastHitConvertTool::m_hecHitContainerKey
SG::WriteHandleKey< LArHitContainer > m_hecHitContainerKey
Definition: FastHitConvertTool.h:70
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
LArHEC_ID.h
LArHitFloatContainer.h
HWIdentifier
Definition: HWIdentifier.h:13
FastHitConvertTool::m_tileSamplingFractionKey
SG::ReadCondHandleKey< TileSamplingFraction > m_tileSamplingFractionKey
Name of TileSamplingFraction in condition store.
Definition: FastHitConvertTool.h:81
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
TileID.h
FastHitConvertTool::m_pMergeSvc
PileUpMergeSvc * m_pMergeSvc
Definition: FastHitConvertTool.h:74
FastHitConvertTool::m_pileup_pOverEvent
SG::ReadHandleKey< PileUpEventInfo > m_pileup_pOverEvent
Definition: FastHitConvertTool.h:99
FastHitConvertTool::FastHitConvertTool
FastHitConvertTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: FastHitConvertTool.cxx:36
FastHitConvertTool::m_tileHitVectorKey
SG::WriteHandleKey< TileHitVector > m_tileHitVectorKey
Definition: FastHitConvertTool.h:71
CaloIdManager::getTileID
const TileID * getTileID(void) const
Definition: CaloIdManager.cxx:100
CaloIdManager::getHEC_ID
const LArHEC_ID * getHEC_ID(void) const
Definition: CaloIdManager.cxx:95
TileHWID.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Tile_Base_ID::is_tile_gapscin
bool is_tile_gapscin(const Identifier &id) const
Definition: Tile_Base_ID.cxx:268
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
CaloIdManager
This class initializes the Calo (LAr and Tile) offline identifiers.
Definition: CaloIdManager.h:45
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
DetDescrDictionaryDict::it1
std::vector< HWIdentifier >::iterator it1
Definition: DetDescrDictionaryDict.h:17
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FastHitConvertTool::m_tileHWID
const TileHWID * m_tileHWID
Definition: FastHitConvertTool.h:94
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ILArfSampl::FSAMPL
virtual const float & FSAMPL(const HWIdentifier &id) const =0
FastHitConvertTool::m_pileup_evt
SG::ReadHandleKey< EventInfo > m_pileup_evt
Definition: FastHitConvertTool.h:98
CaloIdManager::getFCAL_ID
const LArFCAL_ID * getFCAL_ID(void) const
Definition: CaloIdManager.cxx:85
FastHitConvertTool::m_pileup
Gaudi::Property< bool > m_pileup
Definition: FastHitConvertTool.h:97
createCoolChannelIdFile.channel_id
channel_id
Definition: createCoolChannelIdFile.py:52
PileUpTimeEventIndex::Signal
@ Signal
Definition: PileUpTimeEventIndex.h:16
PileUpEventInfo::addSubEvt
void addSubEvt(time_type t, PileUpTimeEventIndex::PileUpType puType, const EventInfo *pse, StoreGateSvc *psg)
setter for the subEvt collection t=0(ns) for the original event
Definition: PileUpEventInfo.h:104
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AtlasDetectorID::is_tile
bool is_tile(Identifier id) const
Definition: AtlasDetectorID.h:695
AtlasDetectorID::is_lar_hec
bool is_lar_hec(Identifier id) const
Definition: AtlasDetectorID.h:829
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LArHitFloat.h
FastHitConvertTool::m_tileCabling
const TileCablingService * m_tileCabling
Definition: FastHitConvertTool.h:95
FastHitConvertTool::m_larFcalID
const LArFCAL_ID * m_larFcalID
Definition: FastHitConvertTool.h:91
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
TileHitVector.h
TileHit.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TileHWID::drawerIdx
int drawerIdx(const HWIdentifier &id) const
construct drawer index from HW identifier
Definition: TileHWID.h:175
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:42
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TileHit
Definition: TileSimEvent/TileSimEvent/TileHit.h:30
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition: LArHit.h:25
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
LArFCAL_ID.h
LArHit.h
PileUpEventInfo
This class provides information about an overlaid event. It extends EventInfo with a list of sub-evts...
Definition: PileUpEventInfo.h:37
FastHitConvertTool::m_tileID
const TileID * m_tileID
Definition: FastHitConvertTool.h:93
FastHitConvertTool::m_emecHitContainerKey
SG::WriteHandleKey< LArHitContainer > m_emecHitContainerKey
Definition: FastHitConvertTool.h:68
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
LArEM_Base_ID::is_em_barrel
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
LArHitContainer.h
Tile_Base_ID::pmt_id
Identifier pmt_id(const Identifier &any_id) const
Definition: Tile_Base_ID.cxx:640
PileUpMergeSvc.h
the preferred mechanism to access information from the different event stores in a pileup job.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CaloCellContainer::endConstCalo
CaloCellContainer::const_iterator endConstCalo(CaloCell_ID::SUBCALO caloNum) const
Definition: CaloCellContainer.cxx:133
FastHitConvertTool::m_tileCablingSvc
ServiceHandle< TileCablingSvc > m_tileCablingSvc
Name of Tile cabling service.
Definition: FastHitConvertTool.h:87
CaloIdManager.h
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
hitTime
float hitTime(const AFP_SIDSimHit &hit)
Definition: AFP_SIDSimHit.h:39
FastHitConvertTool::m_larHecID
const LArHEC_ID * m_larHecID
Definition: FastHitConvertTool.h:92
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:46
checker_macros.h
Define macros for attributes used to control the static checker.
FastHitConvertTool::m_fSamplKey
SG::ReadCondHandleKey< ILArfSampl > m_fSamplKey
Definition: FastHitConvertTool.h:76
StoreGateSvc.h
AtlasDetectorID::is_lar_em
bool is_lar_em(Identifier id) const
Definition: AtlasDetectorID.h:818
LArEM_Base_ID::is_em_endcap
bool is_em_endcap(const Identifier id) const
test if the id belongs to the EM Endcap
ILArfSampl
Definition: ILArfSampl.h:14
TileCablingService::s2h_channel_id
HWIdentifier s2h_channel_id(const Identifier &id) const
Definition: TileCablingService.cxx:1076
TileCellContainer.h