ATLAS Offline Software
HIJetClusterSubtractorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 #include <TH3F.h>
14 #include <TFile.h>
15 #include <iomanip>
16 
18  m_init(false),
19  m_h3W(nullptr),
20  m_h3Eta(nullptr),
21  m_h3Phi(nullptr),
22  m_useSamplings(true)
23 {
24  declareProperty("UseSamplings",m_useSamplings=true);
25  setUseCells(false);
26 }
27 
28 void HIJetClusterSubtractorTool::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
29 {
30 
31  const xAOD::CaloCluster* cl=static_cast<const xAOD::CaloCluster*>(cl_in);
32  float E_unsubtr=cl->e(HIJetRec::unsubtractedClusterState());
33  float eta_unsubtr=cl->eta(HIJetRec::unsubtractedClusterState());
34  float phi_unsubtr=cl->phi(HIJetRec::unsubtractedClusterState());
35 
36  float E_subtr=0;
37  float E_eta_subtr=0;
38  float E_phi_subtr=0;
39  const float eta0=cl->eta0();
40  const float phi0=cl->phi0();
41  float mod=1;
42  if(modulator) mod=modulator->getModulation(phi0, eshape);
43 
44  float energy=E_unsubtr;
45  float eta=eta0;
46  float phi=phi0;
47 
48  static const SG::ConstAccessor<float> HIEtaPhiWeightAcc("HIEtaPhiWeight");
49  if(HIEtaPhiWeightAcc.isAvailable(*cl))
50  {
51  float DF_weight=HIEtaPhiWeightAcc(*cl);
52  if(DF_weight!=0.) mod/=DF_weight;
53  }
54 
55  if(shape==nullptr)
56  {
57  ATH_MSG_ERROR("No HIEventShape supplied, cannot do subtraction");
58  return;
59  }
60 
61  if(m_useSamplings)
62  {
63  if(index==nullptr)
64  {
65  ATH_MSG_ERROR("No HIEventShapeIndex supplied, cannot do subtraction");
66  return;
67  }
68 
69  for(unsigned int sample=0; sample<24; sample++)
70  {
72  if(!cl->hasSampling(s)) continue;
73 
74  float nCells=index->getShape(eta0,sample,shape)->nCells();
75  float rho=0;
76  if(nCells!=0.) rho=index->getShape(eta0,sample,shape)->rho()/nCells;
77  rho*=mod*std::cosh(eta0);
78 
79  E_subtr+=rho*getWeight(eta0,phi0,sample);
80  E_eta_subtr+=rho*getWeightEta(eta0,phi0,sample);
81  E_phi_subtr+=rho*getWeightPhi(eta0,phi0,sample);
82  }
83 
84  energy=E_unsubtr-E_subtr;
85  if(energy!=0.)
86  {
87  eta=eta_unsubtr+(eta_unsubtr*E_subtr-E_eta_subtr)/energy;
88  phi=phi_unsubtr+(phi_unsubtr*E_subtr-E_phi_subtr)/energy;
89  }
91  }
92  else
93  {
94  unsigned int es_bin=HI::TowerBins::findBinEta(eta0);
95 
96  float area=shape->at(es_bin)->area();
97  float rho=(area==0.) ? 0. : shape->at(es_bin)->et()/area;
98 
99  rho*=mod*std::cosh(eta0);
100  E_subtr=rho*HI::TowerBins::getBinArea();
101  energy=E_unsubtr-E_subtr;
102  eta=eta_unsubtr;
103  phi=phi_unsubtr;
104 
105  ATH_MSG_VERBOSE("Subtracting"
106  << std::setw(8) << eta0
107  << std::setw(8) << phi0
108  << std::setw(10) << std::setprecision(3) << modulator->getModulation(phi0, eshape)
109  << std::setw(10) << std::setprecision(3) << mod
110  << std::setw(10) << std::setprecision(3) << modulator->getModulation(phi0, eshape)/mod
111  << std::setw(10) << std::setprecision(3) << area
112  << std::setw(10) << std::setprecision(3) << rho*area
113  << std::setw(10) << std::setprecision(3) << E_unsubtr*1e-3
114  << std::setw(10) << std::setprecision(3) << E_subtr*1e-3
115  << std::setw(10) << std::setprecision(3) << E_unsubtr*1e-3/std::cosh(eta0)
116  << std::setw(10) << std::setprecision(3) << E_subtr*1e-3/std::cosh(eta0));
117 
118 
119 
120 
121  }
122  float ET=energy/std::cosh(eta);
123  subtr_mom.SetPxPyPzE(ET*std::cos(phi),ET*std::sin(phi),ET*std::sinh(eta),energy);
124 }
125 
127 {
128 
129  float eta0=cl->eta0();
130  float phi0=cl->phi0();
131 
132  if(m_useSamplings)
133  {
134  for(unsigned int sample=0; sample<24; sample++)
135  {
137  if(!cl->hasSampling(s)) continue;
138  float esamp=cl->eSample(s);
139  float ET=esamp/std::cosh(eta0);
140  xAOD::HIEventShape* slice=shape->at(index->getIndex(eta0,sample));
141  float area_cluster=getWeight(eta0,phi0,sample);
142  //update members
143  updateSlice(slice,ET,phi0,area_cluster);
144  }
145  }
146  else
147  {
148  unsigned int es_bin=HI::TowerBins::findBinEta(eta0);
149  xAOD::HIEventShape* slice=shape->at(es_bin);
150  constexpr float area_cluster=HI::TowerBins::getBinArea();
151  float ET=cl->e(HIJetRec::unsubtractedClusterState())/std::cosh(eta0);
152  static const SG::ConstAccessor<float> HIEtaPhiWeightAcc("HIEtaPhiWeight");
153  if(HIEtaPhiWeightAcc.isAvailable(*cl))
154  {
155  float HI_weight=HIEtaPhiWeightAcc(*cl);
156  ET*=HI_weight;
157  }
158  //update members
159  updateSlice(slice,ET,phi0,area_cluster);
160  }
161 }
162 
163 
164 void HIJetClusterSubtractorTool::subtractWithMoments(xAOD::CaloCluster* cl, const xAOD::HIEventShapeContainer* shape, const HIEventShapeIndex* index, const ToolHandle<IHIUEModulatorTool>& modulator, const xAOD::HIEventShape* eshape) const
165 {
166  xAOD::IParticle::FourMom_t subtr_mom;
167  subtract(subtr_mom, cl, shape, index, modulator, eshape);
169 }
170 
172 {
173  if(m_useSamplings)
174  {
175  std::string local_path=static_cast<std::string>(m_configDir)+m_inputFile;
176  std::string full_path=PathResolverFindCalibFile(local_path);
177  ATH_MSG_INFO("Reading input file "<< m_inputFile << " from " << full_path);
178  TFile* f=TFile::Open(full_path.c_str());
179  if(f==nullptr)
180  {
181  ATH_MSG_FATAL("Cannot read config file " << full_path );
182  return StatusCode::FAILURE;
183  }
184 
185  m_h3W=(TH3F*)f->GetObjectChecked("h3_w","TH3F");
186  if(m_h3W==nullptr)
187  {
188  ATH_MSG_FATAL("Cannot find TH3F m_h3W in config file " << full_path );
189  return StatusCode::FAILURE;
190  }
191 
192  m_h3Eta=(TH3F*)f->GetObjectChecked("h3_eta","TH3F");
193  if(m_h3Eta==nullptr)
194  {
195  ATH_MSG_FATAL("Cannot find TH3F m_h3Eta in config file " << full_path );
196  return StatusCode::FAILURE;
197  }
198 
199  m_h3Phi=(TH3F*)f->GetObjectChecked("h3_phi","TH3F");
200  if(m_h3Phi==nullptr)
201  {
202  ATH_MSG_FATAL("Cannot find TH3F m_h3Phi in config file " << full_path );
203  return StatusCode::FAILURE;
204  }
205  m_h3W->SetDirectory(0);
206  m_h3Eta->SetDirectory(0);
207  m_h3Phi->SetDirectory(0);
208 
209  f->Close();
210  }
211  m_init=true;
212  return StatusCode::SUCCESS;
213 
214 }
215 
216 
218 {
219  return initializeTool();
220 
221 }
222 
223 
224 float HIJetClusterSubtractorTool::getWeight(float eta, float phi, int sample) const
225 {
226  return m_h3W->GetBinContent(m_h3W->FindFixBin(eta,phi,sample));
227 }
229 {
230  return m_h3Eta->GetBinContent(m_h3Eta->FindFixBin(eta,phi,sample));
231 }
233 {
234  return m_h3Phi->GetBinContent(m_h3Phi->FindFixBin(eta,phi,sample));
235 }
236 
237 void HIJetClusterSubtractorTool::updateSlice(xAOD::HIEventShape* slice, float ET, float phi0, float area_cluster) const
238 {
239  if(area_cluster==0.)
240  {
241  area_cluster=1.;
242 
243  if(ET==0.)
244  {
245  ATH_MSG_INFO("Provided cluster area was 0, check if the input file " << m_inputFile << " from " << PathResolverFindCalibFile(static_cast<std::string>(m_configDir)+m_inputFile) << " was generated with the currently used geometry. See ATLHI-472");
246  }
247  else
248  {
249  ATH_MSG_ERROR("Provided cluster area was 0, the HIEventShape will be incorrect! Check if the input file " << m_inputFile << " from " << PathResolverFindCalibFile(static_cast<std::string>(m_configDir)+m_inputFile) << " was generated with the currently used geometry. See ATLHI-472");
250  }
251  }
252 
253  float area_slice=slice->area();
254  float area_sf=1.;
255 
256  if(area_slice!=0.) area_sf-=area_cluster/area_slice;
257  slice->setNCells( std::floor(area_sf*slice->nCells()) );
258  slice->setEt(slice->et()-ET);
259  slice->setArea(area_slice-area_cluster);
260 
261  slice->setRho(slice->rho() - ET/area_cluster);
262 
263 
264  for(unsigned int ih=0; ih<slice->etCos().size(); ih++)
265  {
266  float ih_f=ih+1;
267  float tmp_cos = slice->etCos().at(ih);
268  slice->etCos()[ih] = tmp_cos + cos(ih_f*phi0)*ET;
269 
270  float tmp_sin = slice->etSin().at(ih);
271  slice->etSin()[ih] = tmp_sin + sin(ih_f*phi0)*ET;
272  }
273 }
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
HIJetClusterSubtractorTool::m_h3W
TH3F * m_h3W
Definition: HIJetClusterSubtractorTool.h:64
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
HIEventShapeIndex.h
HIJetClusterSubtractorTool::getWeightEta
float getWeightEta(float eta, float phi, int sample) const
Definition: HIJetClusterSubtractorTool.cxx:228
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
HI::TowerBins::findBinEta
unsigned int findBinEta(float eta)
Definition: HIEventDefs.h:46
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
HIJetSubtractorToolBase::setUseCells
void setUseCells(bool v)
Definition: HIJetSubtractorToolBase.h:64
HIJetClusterSubtractorTool::HIJetClusterSubtractorTool
HIJetClusterSubtractorTool(const std::string &myname)
Implements method defined in base First argument is reference to four vector that is updated to refle...
Definition: HIJetClusterSubtractorTool.cxx:17
SG::ConstAccessor< float >
HIJetClusterSubtractorTool::updateSlice
void updateSlice(xAOD::HIEventShape *slice, float ET, float phi0, float area_cluster) const
Definition: HIJetClusterSubtractorTool.cxx:237
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
HI::TowerBins::getBinArea
constexpr float getBinArea()
Definition: HIEventDefs.h:34
HIJetClusterSubtractorTool::m_h3Eta
TH3F * m_h3Eta
Definition: HIJetClusterSubtractorTool.h:65
xAOD::IParticle::FourMom_t
TLorentzVector FourMom_t
Definition of the 4-momentum type.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:68
HIJetClusterSubtractorTool::m_init
bool m_init
Definition: HIJetClusterSubtractorTool.h:53
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::HIEventShape_v2
Interface class for the HI reconstruction EDM.
Definition: HIEventShape_v2.h:31
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
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:100
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
HIJetClusterSubtractorTool::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: HIJetClusterSubtractorTool.cxx:126
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HIJetClusterSubtractorTool::m_useSamplings
Gaudi::Property< bool > m_useSamplings
Definition: HIJetClusterSubtractorTool.h:68
HIJetClusterSubtractorTool::subtractWithMoments
virtual void subtractWithMoments(xAOD::CaloCluster *, const xAOD::HIEventShapeContainer *, const HIEventShapeIndex *index, const ToolHandle< IHIUEModulatorTool > &, const xAOD::HIEventShape *eshape) const override
Definition: HIJetClusterSubtractorTool.cxx:164
HIJetSubtractorToolBase
Abstract base for JetModifiers applying constituent based subtraction.
Definition: HIJetSubtractorToolBase.h:24
HIJetClusterSubtractorTool::getWeightPhi
float getWeightPhi(float eta, float phi, int sample) const
Definition: HIJetClusterSubtractorTool.cxx:232
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TH3F::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:500
PathResolver.h
TH3F
Definition: rootspy.cxx:495
HIEventShapeIndex
Definition: HIEventShapeIndex.h:17
HIJetClusterSubtractorTool::m_inputFile
Gaudi::Property< std::string > m_inputFile
Definition: HIJetClusterSubtractorTool.h:60
EventInfo.h
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
HIJetClusterSubtractorTool::m_h3Phi
TH3F * m_h3Phi
Definition: HIJetClusterSubtractorTool.h:66
HIJetClusterSubtractorTool::initializeTool
virtual StatusCode initializeTool()
Definition: HIJetClusterSubtractorTool.cxx:171
IHIUEModulatorTool.h
HIJetRec::unsubtractedClusterState
constexpr xAOD::CaloCluster::State unsubtractedClusterState()
Definition: HIJetRecDefs.h:25
HIJetClusterSubtractorTool::getWeight
float getWeight(float eta, float phi, int sample) const
Definition: HIJetClusterSubtractorTool.cxx:224
HIJetClusterSubtractorTool::m_configDir
Gaudi::Property< std::string > m_configDir
Definition: HIJetClusterSubtractorTool.h:62
HIJetSubtractorToolBase::setSubtractedEtaPhi
void setSubtractedEtaPhi(float E, float &eta, float &phi, float eta0, float phi0, float sig) const
Definition: HIJetSubtractorToolBase.cxx:24
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
HIJetClusterSubtractorTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: HIJetClusterSubtractorTool.cxx:217
HIJetRecDefs.h
HIJetClusterSubtractorTool::subtract
virtual void subtract(xAOD::IParticle::FourMom_t &, const xAOD::IParticle *, const xAOD::HIEventShapeContainer *, const HIEventShapeIndex *, const ToolHandle< IHIUEModulatorTool > &, const xAOD::HIEventShape *eshape) const override
Abstract method where particle itself is not modified IParticle::FourMom_t containing kinematics afte...
Definition: HIJetClusterSubtractorTool.cxx:28
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
HIJetClusterSubtractorTool.h
fitman.rho
rho
Definition: fitman.py:532