ATLAS Offline Software
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"
10 #include "HIJetRec/HIJetRecDefs.h"
12 //forward class decl in base class.
15 #include "AthContainers/Accessor.h"
16 
18 {
19 
20 }
21 
22 void 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 
87 void 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);
101  float area=HICaloCellHelper::getAreaEtaPhi(theCell);
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 
119 void 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));
189  xAOD::IParticle::FourMom_t subtr_mom;
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 }
xAOD::CaloCluster_v1::CENTER_MAG
@ CENTER_MAG
Cluster Centroid ( )
Definition: CaloCluster_v1.h:135
HIJetCellSubtractorTool::HIJetCellSubtractorTool
HIJetCellSubtractorTool(const std::string &myname)
Definition: HIJetCellSubtractorTool.cxx:17
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
HICaloCellHelper::getAreaEtaPhi
float getAreaEtaPhi(const CaloCell *theCell)
Definition: HICaloCellHelper.cxx:15
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
HIEventShapeIndex.h
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
SG::Accessor< float >
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
index
Definition: index.py:1
xAODP4Helpers.h
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
HIJetCellSubtractorTool.h
xAOD::etCos
etCos
Definition: HIEventShape_v2.cxx:27
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
HIJetCellSubtractorTool::subtractWithMoments
virtual void subtractWithMoments(xAOD::CaloCluster *cl, const xAOD::HIEventShapeContainer *shape, const HIEventShapeIndex *index, const ToolHandle< IHIUEModulatorTool > &modulator, const xAOD::HIEventShape *eshape) const override
Definition: HIJetCellSubtractorTool.cxx:119
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::IParticle::FourMom_t
TLorentzVector FourMom_t
Definition of the 4-momentum type.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:69
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::HIEventShape_v2
Interface class for the HI reconstruction EDM.
Definition: HIEventShape_v2.h:32
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HIJetRec::subtractedClusterState
constexpr xAOD::CaloCluster::State subtractedClusterState()
Definition: HIJetRecDefs.h:26
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
xAOD::nCells
setRawEt setRawPhi nCells
Definition: TrigCaloCluster_v1.cxx:33
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloCluster.h
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
HIJetCellSubtractorTool::UpdateShape
void UpdateShape(xAOD::HIEventShapeContainer *shape, const HIEventShapeIndex *index, const CaloCell *theCell, float geoWeight, float eta0, float phi0, bool isNeg) const
Definition: HIJetCellSubtractorTool.cxx:87
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:218
HIJetSubtractorToolBase
Abstract base for JetModifiers applying constituent based subtraction.
Definition: HIJetSubtractorToolBase.h:24
CaloCell::et
virtual double et() const override final
get et
Definition: CaloCell.h:407
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CxxUtils::prefetchNext
void prefetchNext(Iter iter, Iter endIter)
Prefetch next object in sequence.
Definition: prefetch.h:130
HICaloCellHelper.h
Accessor.h
Helper class to provide type-safe access to aux data.
HIEventShapeIndex
Definition: HIEventShapeIndex.h:16
HIJetCellSubtractorTool::updateUsingCluster
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...
Definition: HIJetCellSubtractorTool.cxx:74
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloDetDescrElement::getSampling
CaloCell_ID::CaloSample getSampling() const
cell sampling
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:395
IHIUEModulatorTool.h
HIJetRec::unsubtractedClusterState
constexpr xAOD::CaloCluster::State unsubtractedClusterState()
Definition: HIJetRecDefs.h:25
HIJetSubtractorToolBase::setSubtractedEtaPhi
void setSubtractedEtaPhi(float E, float &eta, float &phi, float eta0, float phi0, float sig) const
Definition: HIJetSubtractorToolBase.cxx:24
HIJetCellSubtractorTool::subtract
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...
Definition: HIJetCellSubtractorTool.cxx:22
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
HIJetRecDefs.h
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
area
double area(double R)
Definition: ConvertStaveServices.cxx:42
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
HIJetRec::setClusterP4
void setClusterP4(const xAOD::CaloCluster::FourMom_t &p, xAOD::CaloCluster *cl, xAOD::CaloCluster::State s)
Definition: HIJetRecDefs.h:36
fitman.rho
rho
Definition: fitman.py:532
prefetch.h
Functions to prefetch blocks of memory.