ATLAS Offline Software
LArHITtoCell.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // +======================================================================+
6 // + +
7 // + Author ........: Denis Oliveira Damazio +
8 // + Institute .....: BNL +
9 // + Creation date .: 29/04/2021 +
10 // + +
11 // +======================================================================+
12 //
13 // ........ includes
14 //
15 #include "LArHITtoCell.h"
21 #include "StoreGate/StoreGateSvc.h"
22 #include <cmath>
23 #include <random>
24 #include <sys/time.h>
25 
26 #include <mutex>
27 
31 LArHITtoCell::LArHITtoCell(const std::string& name,
32  ISvcLocator* pSvcLocator)
33  : AthReentrantAlgorithm(name, pSvcLocator),
34  m_calo_id_manager(nullptr)
35 {
36 }
37 
39 
41  if ( m_isSC ) {
42  ATH_CHECK( m_scidtool.retrieve() );
44  }
45  else {
47  }
48  ATH_CHECK( detStore()->retrieve (m_calo_id_manager, "CaloIdManager") );
49 
50  CHECK( detStore()->retrieve(m_OflHelper,"CaloCell_ID") );
54 
55  //
56  //..... need of course the LVL1 helper
57  //
59  if (!m_scHelper) {
60  ATH_MSG_ERROR( "Could not access CaloCell_SuperCell_ID helper");
61  return StatusCode::FAILURE;
62  } else {
63  ATH_MSG_DEBUG( "Successfully accessed CaloCell_SuperCell_ID helper");
64  }
65 
66  return StatusCode::SUCCESS;
67 }
68 
72 StatusCode LArHITtoCell::execute(const EventContext& context) const
73 {
74 
75 
77  const LArHitEMap* hitmapPtr = hitmap.cptr();
78 
79  const LArOnOffIdMapping* cabling = this->retrieve(context, m_cablingKey);
80  if(!cabling) {
81  ATH_MSG_ERROR("Do not have cabling map !!!");
82  return StatusCode::FAILURE;
83  }
84 
85  const auto *fracS = this->retrieve(context,m_fracSKey);
86  if (!fracS ) {
87  ATH_MSG_ERROR("Do not have SC fracs !!!");
88  return StatusCode::FAILURE;
89  }
90 
91  const CaloDetDescrManager_Base* dd_mgr{nullptr};
92  if(m_isSC) {
94  ATH_CHECK(caloSuperCellMgrHandle.isValid());
95  dd_mgr = *caloSuperCellMgrHandle;
96  }
97  else {
99  ATH_CHECK(caloMgrHandle.isValid());
100  dd_mgr = *caloMgrHandle;
101  }
102 
103  int it = 0;
104  int it_end = hitmapPtr->GetNbCells();
105  std::vector< std::pair<float,float> > energy_time;
106  int max (0);
109  energy_time.assign(max,std::pair<float,float>(0.0,0.0));
110  for( ; it!=it_end;++it) {
112  const LArHitList& hitlist = hitmapPtr->GetCell(it);
113  const std::vector<std::pair<float,float> >& timeE = hitlist.getData();
114  if (timeE.empty() ) continue;
115  if ( m_isSC ){ // convert hash to sc hash
116  Identifier cellId = m_OflHelper->cell_id(hash);
117  Identifier scId = m_scidtool->offlineToSuperCellID(cellId);
118  IdentifierHash scHash = m_scHelper->calo_cell_hash(scId) ;
119  if ( scHash.value() == 999999 ) continue;
120  hash = scHash;
121  }
122  std::vector<std::pair<float,float> >::const_iterator first = timeE.begin();
123  std::vector<std::pair<float,float> >::const_iterator last = timeE.end();
124  while(first!=last) {
125  float time = (*first).second;;
126  float energy = (*first).first;
127  if ( (std::abs(time) < 13) ) {
128  energy_time[hash].first+=energy;
129  energy_time[hash].second+=(energy*time);
130  }
131  ++first;
132  }
133  } // enf of for in hits
134 
135  auto outputContainerCellPtr = std::make_unique<CaloCellContainer>();
136  DataPool<CaloCell> dataPool;
137  if (dataPool.allocated()==0)
138  dataPool.reserve (max);
139  outputContainerCellPtr->reserve( max );
140  for(int i=0;i<max;i++) {
141  float energy = energy_time[i].first;
142  if ( energy > 1 ){ // not zero
143  float time = energy_time[i].second / energy;
144  const CaloDetDescrElement* dde(nullptr);
145  CaloCell* ss = dataPool.nextElementPtr();
146  HWIdentifier hw;
147  if ( m_isSC ){
149  hw = cabling->createSignalChannelID(scId);
150  dde = dd_mgr->get_element (scId);
151  } else {
153  hw = cabling->createSignalChannelID(cellId);
154  dde = dd_mgr->get_element (cellId);
155  }
156 
157  ss->setCaloDDE(dde);
158  if ( fracS->FSAMPL(hw) < 0.00001 ) continue;
159  ss->setEnergy(energy/fracS->FSAMPL(hw));
160  ss->setTime(time);
161  ss->setGain((CaloGain::CaloGain)0);
162  // for super-cells provenance and time are slightly different
163  uint16_t prov = 0x2000;
164  ss->setProvenance(prov);
165  // misuse of a variable
166  ss->setQuality((uint16_t)1);
167 
168  outputContainerCellPtr->push_back(ss);
169  } // energy greater than 50
170  }
171  SG::WriteHandle<CaloCellContainer>outputContainer(m_cellKey,context);
172  ATH_CHECK(outputContainer.record(std::move(outputContainerCellPtr) ) );
173 
174  return StatusCode::SUCCESS;
175 }
176 
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
max
#define max(a, b)
Definition: cfImp.cxx:41
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
LArHITtoCell.h
LArHITtoCell::LArHITtoCell
LArHITtoCell(const std::string &name, ISvcLocator *pSvcLocator)
Standard Gaudi algorithm constructor.
Definition: LArHITtoCell.cxx:31
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
DataPool::reserve
void reserve(unsigned int size)
Set the desired capacity.
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArHITtoCell::m_caloSuperCellMgrKey
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSuperCellMgrKey
Definition: LArHITtoCell.h:71
LArHITtoCell::m_calo_id_manager
const CaloIdManager * m_calo_id_manager
Entry point for calorimeter ID helpers.
Definition: LArHITtoCell.h:90
CaloDetDescrManager_Base
Definition: CaloDetDescrManager.h:147
LArHITtoCell::m_scidtool
ToolHandle< ICaloSuperCellIDTool > m_scidtool
Property: Offline / supercell mapping tool.
Definition: LArHITtoCell.h:75
HWIdentifier
Definition: HWIdentifier.h:13
LArHITtoCell::m_cellKey
SG::WriteHandleKey< CaloCellContainer > m_cellKey
Property Output Container.
Definition: LArHITtoCell.h:82
LArHitEMap::GetCell
const LArHitList & GetCell(const unsigned int index) const
Definition: LArHitEMap.h:43
ICaloSuperCellIDTool.h
DataPool::allocated
unsigned int allocated()
return size already allocated OK
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LArHitEMap
Definition: LArHitEMap.h:22
LArHITtoCell::retrieve
const T * retrieve(const EventContext &context, SG::ReadCondHandleKey< T > handleKey) const
Definition: LArHITtoCell.h:99
LArHitList::getData
const LARLIST & getData() const
Definition: LArHitList.h:25
LArHITtoCell::m_OflHelper
const CaloCell_ID * m_OflHelper
pointer to the offline id helper
Definition: LArHITtoCell.h:95
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
LArHITtoCell::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArHITtoCell.h:61
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
LArHITtoCell::m_hitMapKey
SG::ReadHandleKey< LArHitEMap > m_hitMapKey
hit map
Definition: LArHITtoCell.h:79
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
DataPool::nextElementPtr
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
LArHitList
Definition: LArHitList.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell_Base_ID::cell_id
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
SG::WriteHandle< CaloCellContainer >
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
LArHitContainer.h
LArHITtoCell::initialize
StatusCode initialize()
Standard Gaudi initialize method.
Definition: LArHITtoCell.cxx:38
IdentifierHash::value
unsigned int value(void) const
DeMoScan.first
bool first
Definition: DeMoScan.py:534
LArHITtoCell::m_scHelper
const CaloCell_SuperCell_ID * m_scHelper
pointer to the offline TT helper
Definition: LArHITtoCell.h:93
CaloIdManager::getCaloCell_SuperCell_ID
const CaloCell_SuperCell_ID * getCaloCell_SuperCell_ID(void) const
Definition: CaloIdManager.cxx:110
DataPool
a typed memory pool that saves time spent allocation small object. This is typically used by containe...
Definition: DataPool.h:47
LArOnline_SuperCellID.h
CaloIdManager.h
LArHitEMap::GetNbCells
int GetNbCells(void) const
Definition: LArHitEMap.cxx:65
LArHITtoCell::m_isSC
Gaudi::Property< bool > m_isSC
if is SuperCell
Definition: LArHITtoCell.h:86
LArHITtoCell::m_fracSKey
SG::ReadCondHandleKey< ILArfSampl > m_fracSKey
Property: Fraction of Energy Sampled (conditions input).
Definition: LArHITtoCell.h:65
IdentifierHash
Definition: IdentifierHash.h:38
LArHITtoCell::execute
StatusCode execute(const EventContext &context) const
Algorithm execute method.
Definition: LArHITtoCell.cxx:72
StoreGateSvc.h
LArHITtoCell::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArHITtoCell.h:68
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max(void) const
cell 'global' hash table max size
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20