ATLAS Offline Software
Loading...
Searching...
No Matches
HIJetCellSubtractorTool.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#include "HICaloCellHelper.h"
7#include "CxxUtils/prefetch.h"
12//forward class decl in base class.
16
18{
19
20}
21
22void HIJetCellSubtractorTool::subtract(xAOD::IParticle::FourMom_t& subtr_mom, const xAOD::IParticle* cl_in, const xAOD::HIEventShapeContainer* shape, const HIEventShapeIndex* index, const ToolHandle<IHIUEModulatorTool>& modulator, const xAOD::HIEventShape* eshape) const
23{
24 //if( cl_in->type() == xAOD::Type::CaloCluster )
25 //use static cast, derived type of IParticle checked explicitly upstream
26 const xAOD::CaloCluster* cl=static_cast<const xAOD::CaloCluster*>(cl_in);
27 float E_cl=0;
28 float eta_cl=0;
29 float phi_cl=0;
30
31 const float eta0=cl->eta0();
32 const float phi0=cl->phi0();
33
34 float mod=modulator->getModulation(phi0, eshape);
35 //unsigned int eta_phi_index=HICaloCellHelper::FindEtaPhiBin(cl->eta0(),cl->phi0());
36 xAOD::CaloCluster::const_cell_iterator cellIterEnd = cl->cell_end();
37
38 for(xAOD::CaloCluster::const_cell_iterator cellIter=cl->cell_begin(); cellIter != cellIterEnd; cellIter++ )
39 {
40 CxxUtils::prefetchNext(cellIter, cellIterEnd);
41
42 unsigned int sample = (CaloSampling::CaloSample) (*cellIter)->caloDDE()->getSampling();
43 float eta=(*cellIter)->eta();
44 float phi=(*cellIter)->phi();
45
46 float nCells=index->getShape(eta0,sample,shape)->nCells();
47 float rho=0;
48 if(nCells!=0.) rho=index->getShape(eta0,sample,shape)->rho()/nCells;
49 rho*=mod;
50 float geoWeight=cellIter.weight();
51 float cell_E_w=(*cellIter)->energy()*geoWeight;
52 cell_E_w-=rho*HICaloCellHelper::getAreaEtaPhi(*cellIter)*geoWeight*std::cosh(eta0);
53
54
55 E_cl+=cell_E_w;
56 eta_cl+=cell_E_w*eta;
57 phi_cl+=cell_E_w*phi;
58
59 }
60
61 if(E_cl!=0.)
62 {
63 eta_cl/=E_cl;
64 phi_cl/=E_cl;
65 }
66 //rare case E_cl==0 is also handled by setSubtractedEtaPhi
67 float E_unsubtr=cl->e(HIJetRec::unsubtractedClusterState());
68 float sig=(E_unsubtr!=0. ? E_cl/E_unsubtr : 0.);
69 setSubtractedEtaPhi(E_cl,eta_cl,phi_cl,eta0,phi0,sig);
70 float ET_cl=(std::abs(eta_cl)>99. ? 0. : E_cl/std::cosh(eta_cl));
71 subtr_mom.SetPxPyPzE(ET_cl*std::cos(phi_cl),ET_cl*std::sin(phi_cl),ET_cl*std::sinh(eta_cl),E_cl);
72}
73
75{
76 float eta0=cl->eta0();
77 float phi0=cl->phi0();
78
79 xAOD::CaloCluster::const_cell_iterator cellIterEnd = cl->cell_end();
80 for(xAOD::CaloCluster::const_cell_iterator cellIter=cl->cell_begin(); cellIter != cellIterEnd; cellIter++ )
81 {
82 CxxUtils::prefetchNext(cellIter, cellIterEnd);
83 UpdateShape(shape,index,*cellIter,cellIter.weight(),eta0,phi0,true);
84 }
85}
86
87void HIJetCellSubtractorTool::UpdateShape(xAOD::HIEventShapeContainer* shape, const HIEventShapeIndex* index, const CaloCell* theCell, float geoWeight, float eta0, float phi0, bool isNeg) const
88{
89 float sgn=(isNeg) ? -1 : 1;
90
91 int layer = theCell->caloDDE()->getSampling();
92 float cell_et = theCell->et();
93
94 unsigned int iSlice=index->getIndex(eta0,layer);
95
96
97 xAOD::HIEventShape* slice=shape->at(iSlice);
98 //update members
99 slice->setNCells(slice->nCells()+sgn);
100 slice->setEt(slice->et()+sgn*cell_et*geoWeight);
102 float rho=0;
103 if(area!=0.) rho=cell_et/area;
104 slice->setArea(slice->area() + sgn*area*geoWeight);
105 slice->setRho(slice->rho() + sgn*rho);
106
107 for(unsigned int ih=0; ih<shape->at(iSlice)->etCos().size(); ih++)
108 {
109 float ih_f=ih+1;
110 float tmp_cos = shape->at(iSlice)->etCos().at(ih);
111 shape->at(iSlice)->etCos()[ih] = tmp_cos + cell_et*cos(ih_f*phi0)*geoWeight;
112
113 float tmp_sin = shape->at(iSlice)->etSin().at(ih);
114 shape->at(iSlice)->etSin()[ih] = tmp_sin + cell_et*sin(ih_f*phi0)*geoWeight;
115 }
116
117}
118
119void HIJetCellSubtractorTool::subtractWithMoments(xAOD::CaloCluster* cl, const xAOD::HIEventShapeContainer* shape, const HIEventShapeIndex* index, const ToolHandle<IHIUEModulatorTool>& modulator, const xAOD::HIEventShape* eshape) const
120{
121 //if( cl_in->type() == xAOD::Type::CaloCluster )
122 //use static cast, derived type of IParticle checked explicitly upstream
123
124 float E_cl=0;
125 float eta_cl=0;
126 float phi_cl=0;
127
128 const float eta0=cl->eta0();
129 const float phi0=cl->phi0();
130
131 float mod=modulator->getModulation(phi0, eshape);
132
133 //declaring quantities to be summed during cell loop
134 //using same variable names as original implementation in HIEventShapeFillerTool
135 float etot2=0; //sum of the weights, in this case weights are |E|
136 float er2=0; //sum of weight x moment, in this case moments are magnitudes of cell coordinate three vectors
137
138 std::vector<float> E_sample(CaloSampling::Unknown,0);
139 uint32_t samplingPattern=0;
140
141 const auto *cellLink = cl->getCellLinks();
142 if( cellLink == NULL){
143 ATH_MSG_ERROR("HIJetCellSubtraction: cellLink null - returning");
144 return;
145 }
146 //unsigned int eta_phi_index=HICaloCellHelper::FindEtaPhiBin(cl->eta0(),cl->phi0());
147 xAOD::CaloCluster::cell_iterator cellIterEnd = cl->cell_end();
148 for(xAOD::CaloCluster::cell_iterator cellIter=cl->cell_begin(); cellIter != cellIterEnd; cellIter++ )
149 {
150 CxxUtils::prefetchNext(cellIter, cellIterEnd);
151
152 unsigned int sample = (CaloSampling::CaloSample) (*cellIter)->caloDDE()->getSampling();
153 samplingPattern |= (0x1U<<sample);
154 float eta=(*cellIter)->eta();
155 float phi=(*cellIter)->phi();
156
157 float nCells=index->getShape(eta0,sample,shape)->nCells();
158 float rho=0;
159 if(nCells!=0.) rho=index->getShape(eta0,sample,shape)->rho()/nCells;
160
161 rho*=mod;
162 float geoWeight=cellIter.weight();
163 float cell_E_w=(*cellIter)->energy()*geoWeight;
164 cell_E_w-=rho*HICaloCellHelper::getAreaEtaPhi(*cellIter)*geoWeight*std::cosh(eta0);
165
166 E_cl+=cell_E_w;
167 eta_cl+=cell_E_w*eta;
168 phi_cl+=cell_E_w*phi;
169
170 E_sample[sample]+=cell_E_w;
171
172 float abs_weight=std::abs(cell_E_w);
173 float cell_x=(*cellIter)->x();
174 float cell_y=(*cellIter)->y();
175 float cell_z=(*cellIter)->z();
176 etot2+=abs_weight;
177 er2+=std::sqrt(cell_x*cell_x+cell_y*cell_y+cell_z*cell_z)*abs_weight;
178 }
179 if(E_cl!=0.)
180 {
181 eta_cl/=E_cl;
182 phi_cl/=E_cl;
183 }
184 //rare case E_cl==0 is also handled by setSubtractedEtaPhi
185 float E_unsubtr=cl->e(HIJetRec::unsubtractedClusterState());
186 float sig=(E_unsubtr!=0. ? E_cl/E_unsubtr : 0.);
187 setSubtractedEtaPhi(E_cl,eta_cl,phi_cl,eta0,phi0,sig);
188 float ET_cl=(std::abs(eta_cl)>99. ? 0. : E_cl/std::cosh(eta_cl));
190 subtr_mom.SetPxPyPzE(ET_cl*std::cos(phi_cl),ET_cl*std::sin(phi_cl),ET_cl*std::sinh(eta_cl),E_cl);
192
193 cl->setSamplingPattern(samplingPattern);
194 for(unsigned int isample=0; isample < E_sample.size(); isample++)
195 {
196 if( samplingPattern & (0x1U << isample) )
197 {
198 float current_energy=E_sample.at(isample);
200 cl->setEnergy(s,current_energy);
201 }
202 }
203
204 float cm=0.;
205 if(etot2!=0.) cm=er2/etot2;
206
207 //attach the moment to the cluster
208 static const SG::Accessor<float> HIMagAcc("HIMag");
209 if(HIMagAcc.isAvailable(*cl)) HIMagAcc(*cl)=cm;
210 else cl->insertMoment(xAOD::CaloCluster::CENTER_MAG,cm);
211}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
Helper class to provide constant type-safe access to aux data.
Helper class to provide type-safe access to aux data.
double area(double R)
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
virtual double et() const override final
get et
Definition CaloCell.h:423
CaloCell_ID::CaloSample getSampling() const
cell sampling
const T * at(size_type n) const
Access an element, as an rvalue.
virtual void subtractWithMoments(xAOD::CaloCluster *cl, const xAOD::HIEventShapeContainer *shape, const HIEventShapeIndex *index, const ToolHandle< IHIUEModulatorTool > &modulator, const xAOD::HIEventShape *eshape) const override
virtual void updateUsingCluster(xAOD::HIEventShapeContainer *shape, const HIEventShapeIndex *index, const xAOD::CaloCluster *cl) const override
Method to update the shape based on a given cluster two sets of indices are passed by reference and u...
virtual void subtract(xAOD::IParticle::FourMom_t &subtr_mom, const xAOD::IParticle *cl_in, const xAOD::HIEventShapeContainer *shape, const HIEventShapeIndex *index, const ToolHandle< IHIUEModulatorTool > &modulator, const xAOD::HIEventShape *eshape) const override
Implements method defined in base Navigates back to cells to do subtraction First argument is referen...
HIJetCellSubtractorTool(const std::string &myname)
void UpdateShape(xAOD::HIEventShapeContainer *shape, const HIEventShapeIndex *index, const CaloCell *theCell, float geoWeight, float eta0, float phi0, bool isNeg) const
void setSubtractedEtaPhi(float E, float &eta, float &phi, float eta0, float phi0, float sig) const
HIJetSubtractorToolBase(const std::string &myname)
Helper class to provide type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
CaloClusterCellLink::iterator cell_iterator
Iterator of the underlying CaloClusterCellLink (non-const version)
CaloClusterCellLink::const_iterator const_cell_iterator
Iterator of the underlying CaloClusterCellLink (explicitly const version)
@ CENTER_MAG
Cluster Centroid ( )
CaloSampling::CaloSample CaloSample
Class providing the definition of the 4-vector interface.
TLorentzVector FourMom_t
Definition of the 4-momentum type.
void prefetchNext(Iter iter, Iter endIter)
Prefetch next object in sequence.
Definition prefetch.h:130
float getAreaEtaPhi(const CaloCell *theCell)
constexpr xAOD::CaloCluster::State unsubtractedClusterState()
constexpr xAOD::CaloCluster::State subtractedClusterState()
void setClusterP4(const xAOD::CaloCluster::FourMom_t &p, xAOD::CaloCluster *cl, xAOD::CaloCluster::State s)
Definition index.py:1
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
HIEventShapeContainer_v2 HIEventShapeContainer
Define the latest version of the container.
HIEventShape_v2 HIEventShape
Definition of the latest event info version.
Functions to prefetch blocks of memory.