ATLAS Offline Software
Loading...
Searching...
No Matches
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"
22#include <cmath>
23#include <random>
24#include <sys/time.h>
25
26#include <mutex>
27
31LArHITtoCell::LArHITtoCell(const std::string& name,
32 ISvcLocator* pSvcLocator)
33 : AthReentrantAlgorithm(name, pSvcLocator),
34 m_calo_id_manager(nullptr)
35{
36}
37
39
40 ATH_CHECK( m_hitMapKey.initialize() );
41 if ( m_isSC ) {
42 ATH_CHECK( m_scidtool.retrieve() );
43 ATH_CHECK( m_caloSuperCellMgrKey.initialize() );
44 }
45 else {
46 ATH_CHECK( m_caloMgrKey.initialize() );
47 }
48 ATH_CHECK( detStore()->retrieve (m_calo_id_manager, "CaloIdManager") );
49
50 CHECK( detStore()->retrieve(m_OflHelper,"CaloCell_ID") );
51 ATH_CHECK( m_cablingKey.initialize() );
52 ATH_CHECK( m_fracSKey.initialize() );
53 ATH_CHECK( m_cellKey.initialize() );
54
55 //
56 //..... need of course the LVL1 helper
57 //
58 m_scHelper = m_calo_id_manager->getCaloCell_SuperCell_ID();
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
72StatusCode 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);
107 if ( m_isSC ) max = m_scHelper->calo_cell_hash_max ();
108 else max = m_OflHelper->calo_cell_hash_max ();
109 energy_time.assign(max,std::pair<float,float>(0.0,0.0));
110 for( ; it!=it_end;++it) {
111 IdentifierHash hash(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 ){
148 Identifier scId = m_scHelper->cell_id(IdentifierHash(i));
149 hw = cabling->createSignalChannelID(scId);
150 dde = dd_mgr->get_element (scId);
151 } else {
152 Identifier cellId = m_OflHelper->cell_id(IdentifierHash(i));
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Helper class for offline supercell identifiers.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t ss
#define max(a, b)
Definition cfImp.cxx:41
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
void reserve(unsigned int size)
Set the desired capacity.
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
unsigned int allocated()
return size already allocated OK
This is a "hash" representation of an Identifier.
value_type value() const
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Gaudi::Property< bool > m_isSC
if is SuperCell
LArHITtoCell(const std::string &name, ISvcLocator *pSvcLocator)
Standard Gaudi algorithm constructor.
const CaloIdManager * m_calo_id_manager
Entry point for calorimeter ID helpers.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
SG::WriteHandleKey< CaloCellContainer > m_cellKey
Property Output Container.
ToolHandle< ICaloSuperCellIDTool > m_scidtool
Property: Offline / supercell mapping tool.
const CaloCell_SuperCell_ID * m_scHelper
pointer to the offline TT helper
SG::ReadCondHandleKey< ILArfSampl > m_fracSKey
Property: Fraction of Energy Sampled (conditions input).
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSuperCellMgrKey
SG::ReadHandleKey< LArHitEMap > m_hitMapKey
hit map
const T * retrieve(const EventContext &context, const SG::ReadCondHandleKey< T > &handleKey) const
const CaloCell_ID * m_OflHelper
pointer to the offline id helper
StatusCode initialize()
Standard Gaudi initialize method.
StatusCode execute(const EventContext &context) const
Algorithm execute method.
size_t GetNbCells(void) const
Definition LArHitEMap.h:42
const LArHitList & GetCell(const unsigned int index) const
Definition LArHitEMap.h:43
const LARLIST & getData() const
Definition LArHitList.h:25
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.