ATLAS Offline Software
GSCCalibStep.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // GSCCalibStep.cxx
8 // Implementation file for class GSCCalibStep
10 
14 
15 GSCCalibStep::GSCCalibStep(const std::string& name)
16  : asg::AsgTool( name ){ }
17 
18 
19 
21 // Public methods:
23 
25  ATH_MSG_DEBUG ("Initializing " << name() );
26 
27  ATH_CHECK( m_vartool1.retrieve() );
28  ATH_CHECK( m_vartool2.retrieve() );
29 
30  ATH_CHECK( m_histTool2D.retrieve() );
31  ATH_CHECK( m_histTool_EM3.retrieve());
33  ATH_CHECK( m_histTool_Tile0.retrieve());
35  ATH_CHECK( m_histTool_nTrk.retrieve());
36  ATH_CHECK( m_histTool_trackWIDTH.retrieve());
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 
43 
44  ATH_MSG_DEBUG("calibrating jet collection.");
45 
46  for (xAOD::Jet* jet : jets){
47 
49 
50  xAOD::JetFourMom_t jetconstitP4 = jet->getAttribute<xAOD::JetFourMom_t>("JetConstitScaleMomentum");
51  std::vector<float> samplingFrac = jet->getAttribute<std::vector<float> >("EnergyPerSampling");
52  // get Primary Vertex index
53  int PVindex = 0;
54  ATH_MSG_DEBUG("PV index:" << PVindex);
55  // get detector Eta
56  float detectorEta = jet->getAttribute<float>("DetectorEta");
57  // get trackWIDTHPVX
58  float trackWIDTHPVX = 0;
59  static const SG::ConstAccessor<std::vector<float> > TrackWidthPt1000Acc ("TrackWidthPt1000");
60  if(TrackWidthPt1000Acc.isAvailable(*jet))
61  {
62  trackWIDTHPVX = TrackWidthPt1000Acc(*jet).at(PVindex);
63  ATH_MSG_DEBUG("trackWIDTHPVX found set to: " << trackWIDTHPVX);
64  }
65  jc.setValue("trackWIDTH", trackWIDTHPVX);
66  // get nTrkPVX
67  int nTrkPVX = 0;
68  static const SG::ConstAccessor<std::vector<int>> NumTrkPt1000Acc ("NumTrkPt1000");
69  if(NumTrkPt1000Acc.isAvailable(*jet))
70  {
71  nTrkPVX = NumTrkPt1000Acc(*jet).at(PVindex);
72  ATH_MSG_DEBUG("nTrkPVX found set to: " << nTrkPVX);
73  }
74  jc.setValue("nTrk", nTrkPVX);
75  // get Charged Fraction
76  float ChargedFraction = 0;
77  static const SG::ConstAccessor<std::vector<float>> SumPtChargedPFOPt500Acc ("SumPtChargedPFOPt500");
78  if(SumPtChargedPFOPt500Acc.isAvailable(*jet))
79  {
80  ChargedFraction = SumPtChargedPFOPt500Acc(*jet).at(PVindex)/jetconstitP4.Pt();
81  ATH_MSG_DEBUG("ChargedFraction found set to: " << ChargedFraction);
82  }
83  jc.setValue("ChargedFraction", ChargedFraction);
84  // get EM3
85  float EM3 = (samplingFrac[3]+samplingFrac[7])/jetconstitP4.e();
86  ATH_MSG_DEBUG("EM3 found set to: " << EM3);
87  jc.setValue("EM3", EM3);
88  // get Tile0
89  float Tile0 = (samplingFrac[12]+samplingFrac[18])/jetconstitP4.e();
90  ATH_MSG_DEBUG("Tile0 found set to: " << Tile0);
91  jc.setValue("Tile0", Tile0);
92  // get N90Constituents
93  double N90Constituents = 0;
94  static const SG::ConstAccessor<float> N90ConstituentsAcc ("N90Constituents");
95  if(N90ConstituentsAcc.isAvailable(*jet))
96  {
97  N90Constituents = N90ConstituentsAcc(*jet);
98  ATH_MSG_DEBUG("N90Constituents found set to: " << N90Constituents);
99  }
100  jc.setValue("N90Constituents", N90Constituents);
101  // get caloWIDTH
102  double caloWIDTH = 0;
103  static const SG::ConstAccessor<float> WidthAcc ("Width");
104  if(WidthAcc.isAvailable(*jet))
105  {
106  caloWIDTH = WidthAcc(*jet);
107  ATH_MSG_DEBUG("caloWIDTH found set to: " << caloWIDTH);
108  }
109  jc.setValue("caloWIDTH", caloWIDTH);
110  // get TG3
111  float TG3 = (samplingFrac[17])/jetconstitP4.e();
112  ATH_MSG_DEBUG("TG3 found set to: " << TG3);
113  jc.setValue("TG3", TG3);
114  // get Muon segments
115  int Nsegments = 0;
116  static const SG::ConstAccessor<int> GhostMuonSegmentCountAcc ("GhostMuonSegmentCount");
117  if(GhostMuonSegmentCountAcc.isAvailable(*jet))
118  {
119  Nsegments = GhostMuonSegmentCountAcc(*jet);
120  ATH_MSG_DEBUG("Nsegments found set to: " << Nsegments);
121  }
122  jc.setValue("Nsegments", Nsegments);
123 
124  ATH_MSG_DEBUG("Jet pt original:" << jet->pt()*1e-3);
125 
126  float getGSCCorrection = 1.0;
127  int etabin = fabs(detectorEta)/0.1;// m_binSize in old version
128  xAOD::JetFourMom_t startingP4 = jet->jetP4();
129 
130  ATH_MSG_DEBUG("ChargedFraction Response: " << getChargedFractionResponse(*jet, jc, etabin));
131  ATH_MSG_DEBUG("Tile0 Response: " <<getTile0Response(*jet, jc, etabin));
132  ATH_MSG_DEBUG("EM3 Response: " << getEM3Response(*jet, jc, etabin));
133  ATH_MSG_DEBUG("NTrk Response: " <<getNTrkResponse(*jet, jc, etabin));
134  ATH_MSG_DEBUG("TrkWidth Response: " <<getTrackWIDTHResponse(*jet, jc, etabin));
135 
136  getGSCCorrection*=1./getChargedFractionResponse(*jet, jc, etabin);
137  jet->setJetP4( startingP4*getGSCCorrection );
138  getGSCCorrection*=1./getTile0Response(*jet, jc, etabin);
139  jet->setJetP4( startingP4*getGSCCorrection );
140  getGSCCorrection*=1./getEM3Response(*jet, jc, etabin);
141  jet->setJetP4( startingP4*getGSCCorrection );
142  getGSCCorrection*=1./getNTrkResponse(*jet, jc, etabin);
143  jet->setJetP4( startingP4*getGSCCorrection );
144  getGSCCorrection*=1./getTrackWIDTHResponse(*jet, jc, etabin);
145 
146  ATH_MSG_DEBUG("GSC full correction: " << getGSCCorrection);
147 
148  jet->setAttribute<xAOD::JetFourMom_t>("JetGSCScaleMomentum",startingP4*getGSCCorrection);
149  jet->setJetP4( startingP4*getGSCCorrection );
150 
151  ATH_MSG_DEBUG("Jet pt calibrated:" << jet->pt()*1e-3);
152 
153 
154  }// loop jets
155 
156  return StatusCode::SUCCESS;
157 }
158 
160  if (jc.getValue<float>("ChargedFraction")<=0) return 1; //ChargedFraction < 0 is unphysical, ChargedFraction = 0 is a special case, so we return 1 for ChargedFraction <= 0
161  if ( etabin >= m_histTool_ChargedFraction.size() ) return 1.;
162  double ChargedFractionResponse = m_histTool_ChargedFraction[etabin]->getValue(jet, jc);
163  return ChargedFractionResponse;
164 }
165 
167  if (jc.getValue<float>("Tile0")<0) return 1; //Tile0 < 0 is unphysical, so we return 1
168  if ( etabin >= m_histTool_Tile0.size() ) return 1.;
169  double Tile0Response = m_histTool_Tile0[etabin]->getValue(jet, jc);
170  return Tile0Response;
171 }
172 
173 float GSCCalibStep::getEM3Response(const xAOD::Jet& jet, const JetHelper::JetContext& jc, uint etabin) const {
174  if (jc.getValue<float>("EM3")<=0) return 1; //EM3 < 0 is unphysical, EM3 = 0 is a special case, so we return 1 for EM3 <= 0
175  if ( etabin >= m_histTool_EM3.size() ) return 1.;
176  float EM3Response = m_histTool_EM3[etabin]->getValue(jet, jc);
177  return EM3Response;
178 }
179 
180 float GSCCalibStep::getPunchThroughResponse(const xAOD::Jet& jet, const JetHelper::JetContext& jc, double eta_det) const {
181  int etabin=-99;
182  std::vector<float> punchThroughEtaBins = {0.0, 1.3, 1.9};//variable in old version
183 
184  if (punchThroughEtaBins.empty() || m_histTool_PunchThrough.size() != punchThroughEtaBins.size()-1)
185  ATH_MSG_WARNING("Please check that the punch through eta binning is properly set in your config file");
186  if ( eta_det >= punchThroughEtaBins.back() || jc.getValue<float>("Nsegments") < 20 ) return 1;
187  for (uint i=0; i<punchThroughEtaBins.size()-1; ++i) {
188  if(eta_det >= punchThroughEtaBins[i] && eta_det < punchThroughEtaBins[i+1]) etabin = i;
189  }
190  if(etabin<0) {
191  ATH_MSG_WARNING("There was a problem determining the eta bin to use for the punch through correction.");
192  //this could probably be improved, but to avoid a seg fault...
193  return 1;
194  }
195  double PunchThroughResponse = m_histTool_PunchThrough[etabin]->getValue(jet, jc);
196  if(PunchThroughResponse>1) return 1;
197  return PunchThroughResponse;
198 }
199 
200 float GSCCalibStep::getNTrkResponse(const xAOD::Jet& jet, const JetHelper::JetContext& jc, uint etabin) const {
201  if (jc.getValue<int>("nTrk")<=0) return 1; //nTrk < 0 is unphysical, nTrk = 0 is a special case, so return 1 for nTrk <= 0
202  if ( etabin >= m_histTool_nTrk.size() ) return 1.;
203  double nTrkResponse;
204  /*if(m_turnOffTrackCorrections){
205  if(pT>=m_turnOffStartingpT && pT<=m_turnOffEndpT){
206  double responseatStartingpT = m_histTool_nTrk[etabin]->getValue(jet, jc);
207  nTrkResponse = (1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT);
208  nTrkResponse *= pT;
209  nTrkResponse += 1 - (m_turnOffEndpT*(1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT));
210  return nTrkResponse;
211  }
212  else if(pT>m_turnOffEndpT) return 1;
213  } TODO */
214  nTrkResponse = m_histTool_nTrk[etabin]->getValue(jet, jc);
215  return nTrkResponse;
216 }
217 
219  if (jc.getValue<float>("trackWIDTH")<=0) return 1;
220  if ( etabin >= m_histTool_trackWIDTH.size() ) return 1.;
221  //jets with no tracks are assigned a trackWIDTH of -1, we use the trackWIDTH=0 correction in those cases
222  double trackWIDTHResponse;
223  /*if(m_turnOffTrackCorrections){
224  if(pT>=m_turnOffStartingpT && pT<=m_turnOffEndpT){
225  double responseatStartingpT = readPtJetPropertyHisto(m_turnOffStartingpT, trackWIDTH, *m_respFactorstrackWIDTH[etabin]);
226  trackWIDTHResponse = (1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT);
227  trackWIDTHResponse *= pT;
228  trackWIDTHResponse += 1 - (m_turnOffEndpT*(1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT));
229  return trackWIDTHResponse;
230  }
231  else if(pT>m_turnOffEndpT) return 1;
232  } TODO */
233  trackWIDTHResponse = m_histTool_trackWIDTH[etabin]->getValue(jet, jc);
234  return trackWIDTHResponse;
235 }
236 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
GSCCalibStep::m_vartool1
ToolHandle< JetHelper::IVarTool > m_vartool1
Definition: GSCCalibStep.h:43
Ringer::EM3
@ EM3
Definition: CaloRingsDefs.h:49
GSCCalibStep::getEM3Response
float getEM3Response(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
Definition: GSCCalibStep.cxx:173
JetHelper::JetContext
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition: JetContext.h:24
asg
Definition: DataHandleTestTool.h:28
GSCCalibStep::m_histTool_ChargedFraction
ToolHandleArray< JetHelper::IVarTool > m_histTool_ChargedFraction
Definition: GSCCalibStep.h:47
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
GSCCalibStep::m_histTool2D
ToolHandle< JetHelper::IVarTool > m_histTool2D
Definition: GSCCalibStep.h:45
GSCCalibStep::m_vartool2
ToolHandle< JetHelper::IVarTool > m_vartool2
Definition: GSCCalibStep.h:44
GSCCalibStep::getNTrkResponse
float getNTrkResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
Definition: GSCCalibStep.cxx:200
GSCCalibStep::getTile0Response
float getTile0Response(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
Definition: GSCCalibStep.cxx:166
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
GSCCalibStep.h
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
lumiFormat.i
int i
Definition: lumiFormat.py:85
GSCCalibStep::GSCCalibStep
GSCCalibStep(const std::string &name="GSCCalibStep")
Constructor with parameters:
Definition: GSCCalibStep.cxx:15
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
GSCCalibStep::m_histTool_nTrk
ToolHandleArray< JetHelper::IVarTool > m_histTool_nTrk
Definition: GSCCalibStep.h:50
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
GSCCalibStep::getTrackWIDTHResponse
float getTrackWIDTHResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
Definition: GSCCalibStep.cxx:218
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
GSCCalibStep::getChargedFractionResponse
float getChargedFractionResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
Definition: GSCCalibStep.cxx:159
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
GSCCalibStep::m_histTool_trackWIDTH
ToolHandleArray< JetHelper::IVarTool > m_histTool_trackWIDTH
Definition: GSCCalibStep.h:51
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
GSCCalibStep::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: GSCCalibStep.cxx:24
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ReadDecorHandle.h
Handle class for reading a decoration on an object.
GSCCalibStep::m_histTool_PunchThrough
ToolHandleArray< JetHelper::IVarTool > m_histTool_PunchThrough
Definition: GSCCalibStep.h:49
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
JetHelper::JetContext::setValue
bool setValue(const std::string &name, const T value, bool allowOverwrite=false)
Definition: JetContext.h:52
GSCCalibStep::m_histTool_EM3
ToolHandleArray< JetHelper::IVarTool > m_histTool_EM3
Definition: GSCCalibStep.h:46
GSCCalibStep::calibrate
virtual StatusCode calibrate(xAOD::JetContainer &) const override
Apply calibration to a jet container.
Definition: GSCCalibStep.cxx:42
GSCCalibStep::getPunchThroughResponse
float getPunchThroughResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, double eta_det) const
Definition: GSCCalibStep.cxx:180
GSCCalibStep::m_histTool_Tile0
ToolHandleArray< JetHelper::IVarTool > m_histTool_Tile0
Definition: GSCCalibStep.h:48
JetHelper::JetContext::getValue
void getValue(const std::string &name, T &value) const
Definition: JetContext.h:39