ATLAS Offline Software
Loading...
Searching...
No Matches
HIClusterMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "HIClusterMaker.h"
12#include "CxxUtils/prefetch.h"
13#include <cmath>
14#include <TVector2.h>
15
18
21#include "CaloDetDescr/CaloDetDescrElement.h"
22
23HIClusterMaker::HIClusterMaker(const std::string& name, ISvcLocator* pSvcLocator)
24 : AthReentrantAlgorithm(name,pSvcLocator)
25{
26}
27
29{
30 //First we initialize keys - after initialization they are frozen
31 ATH_CHECK( m_towerContainerKey.initialize() );
32 ATH_CHECK( m_cellContainerKey.initialize() );
33 ATH_CHECK( m_outputKey.initialize() );
34
35 ATH_CHECK( detStore()->retrieve(m_calo_id, "CaloCell_ID") );
36
37 return StatusCode::SUCCESS;
38}
39
40StatusCode HIClusterMaker::execute(const EventContext &ctx) const
41{
42
43 //retrieve the tower container from store
44 const INavigable4MomentumCollection* navInColl = 0;
46 ATH_CHECK( readHandleTower.isValid() );
47 navInColl = readHandleTower.cptr();
48
49 const CaloCellContainer * cellColl ;
51 ATH_CHECK( readHandleCell.isValid() );
52 cellColl = readHandleCell.cptr();
53
54 //make the container
55 //Tricky migration: here we don't have to migrate our methods but what we use from CaloClusterStoreHelper
56 SG::WriteHandle<xAOD::CaloClusterContainer> writeHandleContainer ( m_outputKey, ctx );
58
59 //loop on towers
60 for(const auto *towerItr : *navInColl)
61 {
62 //initialize variables
63 float E_cl=0;
64 float eta_cl=0;
65 float phi_cl=0;
66 float time_cl=0;
67 float E2_cl=0;
68 uint32_t samplingPattern=0;
69
70 //navigate back to cells
71 //Default is to sort the cells by either pointer values leading to irreproducible output
72 //CaloCellIDFcn ensures cells are ordered by their IDs
74 towerItr->fillToken(cellToken,double(1.));
75
76 // Make the cluster:
77 std::unique_ptr<xAOD::CaloCluster> cl(CaloClusterStoreHelper::makeCluster(cellColl));
78
79 float mirror_cell_sumE = 0;
80
81 if ( cellToken.size() == 0 ) continue;
82 for(NavigationToken<CaloCell,double,CaloCellIDFcn>::const_iterator cellItr = cellToken.begin(); cellItr != cellToken.end(); ++cellItr )
83 {
84 //Bad cell policy - to be kept
85 //if(m_bad_cell_tool->SkipCell(*cellItr))
86 //{
87 //if(m_skipBadCells && (*cellItr)->badcell()) continue;
88 //}
89
90 double geoWeight = cellToken.getParameter(*cellItr);
91
92 const CaloCell* cell=*cellItr;
93 std::unique_ptr<const CaloCell> mirroredCell{};
94
95 bool isDeadFEB = (!cell->caloDDE()->is_tile() && LArProv::test(cell->provenance(),LArProv::DEADFEB));
96
97 if (isDeadFEB) {
98 mirroredCell=getMirroredCell(cell,readHandleCell.cptr());
99 if (mirroredCell) {
100 cell=mirroredCell.get();
101 mirror_cell_sumE+= cell->energy()*geoWeight;
102 }
103 else {
104 ATH_MSG_WARNING("Failed to obtain mirrored cell for deadFEB cell with id" << std::hex << cell->ID().get_compact());
105 }
106
107 }//end if dead FEB
108
109 double cell_E_w=(*cellItr)->energy()*geoWeight;
110
111 IdentifierHash hashid =(*cellItr)->caloDDE()->calo_hash();
112 size_t iCell=cellColl->findIndex(hashid);
113 cl->addCell(iCell,geoWeight);
114
115 E_cl+=cell_E_w;
116 eta_cl+=cell_E_w*(*cellItr)->eta();
117 phi_cl+=cell_E_w*(*cellItr)->phi();
118 E2_cl+=cell_E_w*cell_E_w;
119 time_cl+=cell_E_w*cell_E_w*(*cellItr)->time();
120
121 unsigned int sample = (CaloSampling::CaloSample) (*cellItr)->caloDDE()->getSampling();
122 samplingPattern |= (0x1U<<sample);
123 }//end cell loop
124
125 ATH_MSG_VERBOSE("Energy Sum of mirror deadFEB: " << mirror_cell_sumE);
126 //decorating cluster with sum of mirror cell energy
127 static const SG::AuxElement::Decorator<float> Mcell_sumE("mcell_sumE");
128 Mcell_sumE(*cl) = mirror_cell_sumE;
129
130 float eta0=towerItr->eta();
131 float phi0=towerItr->phi();
132
133 if(E_cl < m_EminMoment || E_cl==0)
134 {
135 eta_cl=eta0;
136 phi_cl=phi0;
137 }
138 else
139 {
140 eta_cl/=E_cl;
141 phi_cl/=E_cl;
142 }
143 //phi moment does not respect wrap-around
144 phi_cl=TVector2::Phi_mpi_pi(phi_cl);
145 if(!HIJetRec::inTowerBoundary(eta0,phi0,eta_cl,phi_cl))
146 {
147 eta_cl=eta0;
148 phi_cl=phi0;
149 }
150
151 if(E2_cl < 1e-8) time_cl=0.;
152 else time_cl/=E2_cl;
153
154 //set initial tower position
155 cl->setEta0(eta0);
156 cl->setPhi0(phi0);
157
158 //set initial kinematics to be the same for all signal states
159 //update upstream
160 cl->setRawE(E_cl);
161 cl->setRawEta(eta_cl);
162 cl->setRawPhi(phi_cl);
163 cl->setRawM(0);
164
165 cl->setAltE(E_cl);
166 cl->setAltEta(eta_cl);
167 cl->setAltPhi(phi_cl);
168 cl->setAltM(0);
169
170 cl->setCalE(E_cl);
171 cl->setCalEta(eta_cl);
172 cl->setCalPhi(phi_cl);
173 cl->setCalM(0);
174
175 //extra info
176 cl->setTime(time_cl);
177 cl->setSamplingPattern(samplingPattern);
178
179 ATH_MSG_VERBOSE( std::setw(20) << "PUSHING CLUSTER"
180 << std::setw(15) << cl->e()
181 << std::setw(15) << cl->eta()
182 << std::setw(15) << cl->phi() );
183
184 writeHandleContainer->push_back(std::move(cl));
185 }//end tower loop
186 return StatusCode::SUCCESS;
187}
188
190{
191 return StatusCode::SUCCESS;
192}
193
194
196{
197 ATH_MSG_INFO("Dumping PseudoJets");
198 for(xAOD::CaloClusterContainer::iterator clusCollIter= clusColl->begin();
199 clusCollIter!= clusColl->end(); ++clusCollIter)
200 {
201 xAOD::CaloCluster* cl = (*clusCollIter);
202
203 float E_cl=0;
204 float eta_cl=0;
205 float phi_cl=0;
206
207 CaloClusterCellLink* cellLinks=cl->getOwnCellLinks();
208
209 if (!cellLinks)
210 {
211 ATH_MSG_ERROR("Can't get valid links to CaloCells (CaloClusterCellLink)!");
212 return StatusCode::FAILURE;
213 }
214
215 unsigned int ncells=0;
216 float sumw=0;
217 // CaloClusterCellLink::iterator cellIterEnd=cellLinks->end();
218 // for(CaloClusterCellLink::iterator cellIter=cellLinks->end();
219 // cellIter != cellIterEnd; cellIter++, ncells++ )
220 // {
221 xAOD::CaloCluster::cell_iterator cellIterEnd = cl->cell_end();
222 for(xAOD::CaloCluster::cell_iterator cellIter= cl->cell_begin(); cellIter != cellIterEnd; ++cellIter )
223 {
224 CxxUtils::prefetchNext (cellIter, cellIterEnd);
225 const CaloCell* pCell=(*cellIter);
226 //double geoWeight =cellIter.weight(); //weird synatx, "." on iterator
227 double cell_E_w=pCell->energy();//*geoWeight;
228
229 E_cl+=cell_E_w;
230 eta_cl+=cell_E_w*pCell->eta();
231 phi_cl+=cell_E_w*pCell->phi();
232 //sumw+=geoWeight;
233 }
234 if(E_cl!=0.)
235 {
236 eta_cl/=E_cl;
237 phi_cl/=E_cl;
238 }
239
240 ATH_MSG_INFO( std::setw(10) << "DUMPING CLUSTER"
241 << std::setw(15) << cl->e()
242 << std::setw(15) << cl->eta()
243 << std::setw(15) << cl->phi()
244 << std::setw(15) << E_cl
245 << std::setw(15) << eta_cl
246 << std::setw(15) << phi_cl
247 << std::setw(15) << ncells
248 << std::setw(15) << sumw );
249 }
250 return StatusCode::SUCCESS;
251}
252
253std::unique_ptr<const CaloCell> HIClusterMaker::getMirroredCell(const CaloCell* pCell, const CaloCellContainer* ccc) const {
254
255 const Identifier id = pCell->ID();
256 const int subCalo = m_calo_id->sub_calo(id);
257 const int pos_neg = m_calo_id->pos_neg(id);
258 const int sampling = m_calo_id->sampling(id);
259 const int region = m_calo_id->region(id);
260 const int eta = m_calo_id->eta(id);
261 const int phi = m_calo_id->phi(id);
262
263 ATH_MSG_VERBOSE("DeadFEB cell parameter: (" << subCalo << "," << pos_neg << "," << sampling << "," << region << "," << eta << "," << phi << ")");
264
265 const Identifier mirroredID = m_calo_id->cell_id(subCalo,
266 -pos_neg, // flip to get cell in oposite eta
267 sampling, region, eta, phi);
268
269 const CaloCell* mirroredCell = ccc->findCell(m_calo_id->calo_cell_hash(mirroredID));
270 if (!mirroredCell) {
271 return nullptr;
272 }
273 ATH_MSG_VERBOSE("DeadFEB cell (et,layer,deta,dphi): (" << pCell->et() << "," << pCell->caloDDE()->getSampling() << "," << pCell->caloDDE()->eta() << ","
274 << pCell->caloDDE()->phi() << ")");
275
276 ATH_MSG_VERBOSE("Mirror cell (et,layer,deta,dphi): " << mirroredCell->et() << "," << mirroredCell->caloDDE()->getSampling() << ","
277 << mirroredCell->caloDDE()->eta() << "," << mirroredCell->caloDDE()->phi() << ")");
278
279 // Build a fake-cell with the DDE of the cell we are replacing and
280 // energy,time,etc from the eta-mirrored cell
281 return std::make_unique<const CaloCell>(pCell->caloDDE(), mirroredCell->energy(), mirroredCell->time(), mirroredCell->quality(), mirroredCell->provenance(),
282 mirroredCell->gain());
283}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
DataVector< INavigable4Momentum > INavigable4MomentumCollection
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
An algorithm that can be simultaneously executed in multiple threads.
Container class for CaloCell.
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
int findIndex(const IdentifierHash theHash) const
Return index of the cell with a given hash.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
float time() const
get time (data member)
Definition CaloCell.h:368
virtual double phi() const override final
get phi (through CaloDetDescrElement)
Definition CaloCell.h:375
double energy() const
get energy (data member)
Definition CaloCell.h:327
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
uint16_t provenance() const
get provenance (data member)
Definition CaloCell.h:354
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition CaloCell.h:382
uint16_t quality() const
get quality (data member)
Definition CaloCell.h:348
CaloGain::CaloGain gain() const
get gain (data member )
Definition CaloCell.h:361
virtual double et() const override final
get et
Definition CaloCell.h:423
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition CaloCell.h:295
static std::unique_ptr< xAOD::CaloCluster > makeCluster(const CaloCellContainer *cellCont)
Creates a valid CaloCluster with a private Aux-Store and CellLink container.
static StatusCode AddContainerWriteHandle(SG::WriteHandle< xAOD::CaloClusterContainer > &clusColl)
Creates a new xAOD::CaloClusterContainer in the given WriteHandle + CaloClusterAuxContainer and recor...
CaloCell_ID::CaloSample getSampling() const
cell sampling
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
std::unique_ptr< const CaloCell > getMirroredCell(const CaloCell *pCell, const CaloCellContainer *ccc) const
SG::ReadHandleKey< INavigable4MomentumCollection > m_towerContainerKey
Name of input CaloTowerContainer, e.g CmbTower.
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Name of input CaloCellContainer, e.g. AllCalo.
virtual StatusCode initialize()
virtual StatusCode finalize()
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputKey
Name of output CaloClusterContainer, e.g. HIClusters.
StatusCode dumpClusters(xAOD::CaloClusterContainer *clusColl)
Gaudi::Property< float > m_EminMoment
For clusters w/ E less than this, set their eta/phi to tower eta/phi.
HIClusterMaker(const std::string &name, ISvcLocator *pSvcLocator)
const CaloCell_ID * m_calo_id
virtual StatusCode execute(const EventContext &ctx) const
This is a "hash" representation of an Identifier.
const_iterator begin() const
CHILDPAR getParameter(const_child_ptr data) const
NavigationTokenIterator const_iterator
const_iterator end() const
unsigned int size()
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:575
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
CaloClusterCellLink::iterator cell_iterator
Iterator of the underlying CaloClusterCellLink (non-const version)
void prefetchNext(Iter iter, Iter endIter)
Prefetch next object in sequence.
Definition prefetch.h:130
bool inTowerBoundary(float eta0, float phi0, float eta, float phi)
bool test(const uint16_t prov, const LArProvenance check)
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Functions to prefetch blocks of memory.