ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSequentialCorrection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*
6 * Calculates global sequential jet calibration factors
7 * -Requires jet branches trackWIDTH, nTrk, Tile0, EM3
8 * -Apply using
9 * 1. No jet area correction: JetCalibrationTool::ApplyOffsetEtaJESGSC
10 * 2. With jet area correction (not yet supported): JetCalibrationTool::ApplyJetAreaOffsetEtaJESGSC
11 * -GSC correction factor is returned by JetCalibrationTool::GetGSC
12 * TFile* inputFile = NULL;
13 inputFile = openInputFile(m_fileName);
14 *
15 * Extension of the ApplyJetCalibrationTool
16 *
17 * Authors: Joe Taenzer (joseph.taenzer@cern.ch), Reina Camacho, Jonathan Bossio (jbossios@cern.ch)
18 *
19 */
20
21#include <TKey.h>
22
23#include <utility>
24
26
29
31#include "xAODTracking/Vertex.h"
33
42
43GlobalSequentialCorrection::GlobalSequentialCorrection(const std::string& name, TEnv* config, TString jetAlgo, const std::string& depth, TString calibAreaTag, bool useOriginVertex, bool dev)
45 m_config(config), m_jetAlgo(std::move(jetAlgo)), m_depthString(depth), m_calibAreaTag(std::move(calibAreaTag)), m_dev(dev),
46 m_binSize(0.1), m_depth(0),
49
50{ }
51
52
54
55 ATH_MSG_DEBUG("Initializing the Global Sequential Calibration tool");
56
57 if(!m_config){
58 ATH_MSG_ERROR("GSC tool received a null config pointer.");
59 return StatusCode::FAILURE;
60 }
61
62 // Set m_PFlow
63 m_PFlow = m_jetAlgo == "AntiKt4EMPFlow";
64
65 // Set m_caloBased
66 if( m_jetAlgo == "AntiKt4EMTopoTrig" && !m_PFlow ) {
67 m_caloBased = true;
68 ATH_MSG_DEBUG("Using calo based GSC");
69 } else{
70 // better to read from config which type of GSC: caloBased for trigger jets.
71 m_caloBased = m_config->GetValue("caloBasedGSC",false);
72 }
73
74 m_jetStartScale = m_config->GetValue("GSCStartingScale","JetEtaJESScaleMomentum");
75 m_turnOffTrackCorrections = m_config->GetValue("TurnOffTrackCorrections", false);
76 m_turnOffStartingpT = m_config->GetValue("TurnOffStartingpT", 1200);
77 m_turnOffEndpT = m_config->GetValue("TurnOffEndpT", 2000);
78 m_pTResponseRequirementOff = m_config->GetValue("PTResponseRequirementOff", false);
79
80 // In release 21, the nTrk and trackWIDTH corrections are also included for PFlow jets
81 // The default is set to false to maintain the backwards compatibility
82 m_nTrkwTrk_4PFlow = m_config->GetValue("nTrkwTrk4PFlow", false);
83
84 // For AFII calibrations, EM3 correction should be applied up to |eta|=3.2
85 m_EM3MaxEtaBin = m_config->GetValue("EM3MaxEtaBin", 35);
86
87 // What is the Nsegments threshold for the punch-through correction? Either 20 or 10
88 m_punchThroughMinNseg = m_config->GetValue("PunchThrough_minNseg", 20);
89 // Use GhostMuonSegmentCount or only unassociated muon segments?
90 m_ghostMuSegCountName = m_config->GetValue("MuonSegmentName", "GhostMuonSegmentCount");
92
93 if ( m_jetAlgo.EqualTo("") ) { ATH_MSG_FATAL("No jet algorithm specified. Aborting."); return StatusCode::FAILURE; }
94
95 //find the ROOT file containing response histograms, path comes from the config file.
96 TString GSCFile = m_config->GetValue("GSCFactorsFile","empty");
97 if ( GSCFile.EqualTo("empty") ) {
98 ATH_MSG_FATAL("NO GSCFactorsFile specified. Aborting.");
99 return StatusCode::FAILURE;
100 }
101 if(m_dev){
102 GSCFile.Remove(0,33);
103 GSCFile.Insert(0,"JetCalibTools/");
104 }
105 else{GSCFile.Insert(14,m_calibAreaTag);}
106 TString fileName = PathResolverFindCalibFile(GSCFile.Data());
107 std::unique_ptr<TFile> inputFile(TFile::Open(fileName));
108 if (!inputFile){
109 ATH_MSG_FATAL("Cannot open GSC factors file" << fileName);
110 return StatusCode::FAILURE;
111 }
112
113 TString depthString = "";
114 if ( m_depthString != "auto" ) depthString = m_depthString;
115 else depthString = m_config->GetValue("GSCDepth","Full");
116 if ( !depthString.Contains("ChargedFraction") && !depthString.Contains("Tile0") && !depthString.Contains("EM3") && !depthString.Contains("nTrk") && !depthString.Contains("trackWIDTH") && !depthString.Contains("PunchThrough") && !depthString.Contains("N90Constituents") && !depthString.Contains("TileGap3") && !depthString.Contains("caloWIDTH") && !depthString.Contains("Full") ) {
117 ATH_MSG_FATAL("depthString flag not properly set, please check your config file.");
118 return StatusCode::FAILURE;
119 }
120
121 // Protection against requesting nTrk or trackWIDTH corrections for PFlow jets when m_nTrkwTrk_4PFlow is false
122 if ( !m_nTrkwTrk_4PFlow && (depthString.Contains("nTrk")||depthString.Contains("trackWIDTH")) && m_PFlow ){
123 ATH_MSG_FATAL("depthString flag not properly set, please check your config file. nTrkwTrk4PFlow should be set to true to apply nTrk or trackWIDTH corrections to PFlow jets");
124 return StatusCode::FAILURE;
125 }
126
127 // Protection against requesting nTrk/trackWIDTH/ChargedFraction/PunchThrough corrections for HLT trigger jets when m_caloBased is true
128 if ( m_caloBased && (depthString.Contains("nTrk")||depthString.Contains("trackWIDTH")||depthString.Contains("ChargedFraction")||depthString.Contains("PunchThrough"))){
129 ATH_MSG_FATAL("depthString flag not properly set, please check your config file. nTrk, trackWIDTH, PunchThrough and ChargedFraction corrections not available for trigger jets");
130 return StatusCode::FAILURE;
131 }
132
133
134 //ATH_MSG_INFO(" for " << m_jetAlgo << " jets\n\n");
135
136 if ( depthString.Contains("PunchThrough") || depthString.Contains("Full") ) {
137 setPunchThroughEtaBins( JetCalibUtils::VectorizeD( m_config->GetValue("PunchThroughEtaBins","") ) );
138 setPunchThroughMinPt( m_config->GetValue("PunchThroughMinPt",50) );
139 }
140
141 //set the depth private variable, used to determine which parts of the GS calibration are applied
142 if( !m_PFlow && !m_caloBased ){
143 if ( depthString.Contains("PunchThrough") || depthString.Contains("Full") ) m_depth = ApplyTile0 | ApplyEM3 | ApplynTrk | ApplytrackWIDTH | ApplyPunchThrough;
144 else if ( depthString.Contains("trackWIDTH") ) m_depth = ApplyTile0 | ApplyEM3 | ApplynTrk | ApplytrackWIDTH;
145 else if ( depthString.Contains("nTrk") ) m_depth = ApplyTile0 | ApplyEM3 | ApplynTrk;
146 else if ( depthString.Contains("EM3") ) m_depth = ApplyTile0 | ApplyEM3;
147 else if ( depthString.Contains("Tile0") ) m_depth = ApplyTile0;
148 else { ATH_MSG_FATAL("depthString flag not properly set, please check your config file."); return StatusCode::FAILURE; }
149 }
150 else if (m_caloBased){
151 if ( depthString.Contains("caloWIDTH") || depthString.Contains("Full") ) m_depth = ApplyTile0 | ApplyEM3 | ApplyN90Constituents | ApplycaloWIDTH;
152 else if ( depthString.Contains("TileGap3") ) m_depth = ApplyTile0 | ApplyEM3 | ApplyN90Constituents | ApplyTileGap3;
153 else if ( depthString.Contains("N90Constituents") ) m_depth = ApplyTile0 | ApplyEM3 | ApplyN90Constituents;
154 else if ( depthString.Contains("EM3") ) m_depth = ApplyTile0 | ApplyEM3;
155 else if ( depthString.Contains("Tile0") ) m_depth = ApplyTile0;
156 else { ATH_MSG_FATAL("depthString flag for calo based GSC not properly set, please check your config file."); return StatusCode::FAILURE; }
157 }
158 else { // PFlow
160 if ( depthString.Contains("PunchThrough") || depthString.Contains("Full") ) m_depth = ApplyChargedFraction | ApplyTile0 | ApplyEM3 | ApplyPunchThrough;
161 else if ( depthString.Contains("EM3") ) m_depth = ApplyChargedFraction | ApplyTile0 | ApplyEM3;
162 else if ( depthString.Contains("Tile0") ) m_depth = ApplyChargedFraction | ApplyTile0;
163 else if ( depthString.Contains("ChargedFraction") ) m_depth = ApplyChargedFraction;
164 else { ATH_MSG_FATAL("depthString flag not properly set, please check your config file."); return StatusCode::FAILURE; }
165 } else {
166 if ( depthString.Contains("PunchThrough") || depthString.Contains("Full") ) m_depth = ApplyChargedFraction | ApplyTile0 | ApplyEM3 | ApplynTrk | ApplytrackWIDTH | ApplyPunchThrough;
167 else if ( depthString.Contains("trackWIDTH") ) m_depth = ApplyChargedFraction | ApplyTile0 | ApplyEM3 | ApplynTrk | ApplytrackWIDTH;
168 else if ( depthString.Contains("nTrk") ) m_depth = ApplyChargedFraction | ApplyTile0 | ApplyEM3 | ApplynTrk;
169 else if ( depthString.Contains("EM3") ) m_depth = ApplyChargedFraction | ApplyTile0 | ApplyEM3;
170 else if ( depthString.Contains("Tile0") ) m_depth = ApplyChargedFraction | ApplyTile0;
171 else if ( depthString.Contains("ChargedFraction") ) m_depth = ApplyChargedFraction;
172 else { ATH_MSG_FATAL("depthString flag not properly set, please check your config file."); return StatusCode::FAILURE; }
173 }
174 }
175
176 //Get a TList of TKeys pointing to the histograms contained in the ROOT file
177 inputFile->cd();
178 TList *keys = inputFile->GetListOfKeys();
179 std::vector<TString> histoNames;
180 //fill the names of the TKeys into a vector of TStrings
181 TIter ikeys(keys);
182 while ( TKey *iterobj = (TKey*)ikeys() ) { histoNames.emplace_back(iterobj->GetName() ); }
183
184 //Grab the TH2Fs from the ROOT file and put them into a vectors of TH2Fs
185 for (uint ihisto=0; ihisto<histoNames.size(); ++ihisto) {
186 if ( !histoNames[ihisto].Contains( m_jetAlgo.Data() ) ) continue;
187 else if ( ihisto>0 && histoNames[ihisto].Contains( histoNames[ihisto-1].Data() ) ) continue;
188 else if ( histoNames[ihisto].Contains("EM3") && m_respFactorsEM3.size() < m_EM3MaxEtaBin)
189 m_respFactorsEM3.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
190 else if ( histoNames[ihisto].Contains("nTrk") && m_respFactorsnTrk.size() < m_nTrkMaxEtaBin)
191 m_respFactorsnTrk.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
192 else if ( histoNames[ihisto].Contains("Tile0") && m_respFactorsTile0.size() < m_Tile0MaxEtaBin)
193 m_respFactorsTile0.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
194 else if ( histoNames[ihisto].Contains("chargedFraction") && m_respFactorsChargedFraction.size() < m_chargedFractionMaxEtaBin)
195 m_respFactorsChargedFraction.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
196 else if ( histoNames[ihisto].Contains("trackWIDTH") && m_respFactorstrackWIDTH.size() < m_trackWIDTHMaxEtaBin)
197 m_respFactorstrackWIDTH.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
198 else if ( histoNames[ihisto].Contains("PunchThrough") )
199 m_respFactorsPunchThrough.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
200 else if ( histoNames[ihisto].Contains("N90Constituents") && m_respFactorsN90Constituents.size() < m_N90ConstituentsMaxEtaBin)
201 m_respFactorsN90Constituents.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
202 else if ( histoNames[ihisto].Contains("caloWIDTH") && m_respFactorscaloWIDTH.size() < m_caloWIDTHMaxEtaBin)
203 m_respFactorscaloWIDTH.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
204 else if ( histoNames[ihisto].Contains("TileGap3") && m_respFactorsTileGap3.size() < m_TileGap3MaxEtaBin )
205 m_respFactorsTileGap3.push_back( JetCalibUtils::GetHisto2(*inputFile,histoNames[ihisto]) );
206 }
207
208 //Make sure we put something in the vectors of TH2Fs
209 if( !m_PFlow && !m_caloBased ){
210 if ( (m_depth & ApplyEM3) && m_respFactorsEM3.size() < 3 ) {
211 ATH_MSG_FATAL("Vector of EM3 histograms may be empty. Please check your GSCFactors file: " << GSCFile);
212 return StatusCode::FAILURE;
213 }
214 else if ( (m_depth & ApplynTrk) && m_respFactorsnTrk.size() < 3 ) {
215 ATH_MSG_FATAL("Vector of nTrk histograms may be empty. Please check your GSCFactors file: " << GSCFile);
216 return StatusCode::FAILURE;
217 }
218 else if ( (m_depth & ApplyTile0) && m_respFactorsTile0.size() < 3 ) {
219 ATH_MSG_FATAL("Vector of Tile0 histograms may be empty. Please check your GSCFactors file: " << GSCFile);
220 return StatusCode::FAILURE;
221 }
222 else if ( (m_depth & ApplytrackWIDTH) && m_respFactorstrackWIDTH.size() < 3 ) {
223 ATH_MSG_FATAL("Vector of trackWIDTH histograms may be empty. Please check your GSCFactors file: " << GSCFile);
224 return StatusCode::FAILURE;
225 }
226 else if ( (m_depth & ApplyPunchThrough) && m_respFactorsPunchThrough.size() < 2 ) {
227 ATH_MSG_FATAL("Vector of PunchThrough histograms may be empty. Please check your GSCFactors file: " << GSCFile);
228 return StatusCode::FAILURE;
229 }
230 else ATH_MSG_DEBUG("GSC Tool has been initialized with binning and eta fit factors from: " << fileName);
231 }
232 else if (m_caloBased) {
233 if ( (m_depth & ApplyEM3) && m_respFactorsEM3.size() < 3 ) {
234 ATH_MSG_FATAL("Vector of EM3 histograms may be empty. Please check your GSCFactors file: " << GSCFile);
235 return StatusCode::FAILURE;
236 }
237 else if ( (m_depth & ApplyN90Constituents) && m_respFactorsN90Constituents.size() < 3 ) {
238 ATH_MSG_FATAL("Vector of N90Constituents histograms may be empty. Please check your GSCFactors file: " << GSCFile);
239 return StatusCode::FAILURE;
240 }
241 else if ( (m_depth & ApplyTile0) && m_respFactorsTile0.size() < 3 ) {
242 ATH_MSG_FATAL("Vector of Tile0 histograms may be empty. Please check your GSCFactors file: " << GSCFile);
243 return StatusCode::FAILURE;
244 }
245 else if ( (m_depth & ApplycaloWIDTH) && m_respFactorscaloWIDTH.size() < 3 ) {
246 ATH_MSG_FATAL("Vector of caloWIDTH histograms may be empty. Please check your GSCFactors file: " << GSCFile);
247 return StatusCode::FAILURE;
248 }
249 else if ( (m_depth & ApplyTileGap3) && m_respFactorsTileGap3.size() < 3 ) {
250 ATH_MSG_FATAL("Vector of TileGap3 histograms may be empty. Please check your GSCFactors file: " << GSCFile);
251 return StatusCode::FAILURE;
252 }
253
254 else ATH_MSG_DEBUG("GSC Tool has been initialized with binning and eta fit factors from: " << fileName << "\n");
255 }
256 else{
258 ATH_MSG_FATAL("Vector of ChargedFraction histograms may be empty. Please check your GSCFactors file: " << GSCFile);
259 return StatusCode::FAILURE;
260 }
261 else if ( (m_depth & ApplyEM3) && m_respFactorsEM3.size() < 3 ) {
262 ATH_MSG_FATAL("Vector of EM3 histograms may be empty. Please check your GSCFactors file: " << GSCFile);
263 return StatusCode::FAILURE;
264 }
265 else if ( (m_depth & ApplyTile0) && m_respFactorsTile0.size() < 3 ) {
266 ATH_MSG_FATAL("Vector of Tile0 histograms may be empty. Please check your GSCFactors file: " << GSCFile);
267 return StatusCode::FAILURE;
268 }
269 else if ( m_nTrkwTrk_4PFlow && (m_depth & ApplynTrk) && m_respFactorsnTrk.size() < 3 ) {
270 ATH_MSG_FATAL("Vector of nTrk histograms may be empty. Please check your GSCFactors file: " << GSCFile);
271 return StatusCode::FAILURE;
272 }
273 else if ( m_nTrkwTrk_4PFlow && (m_depth & ApplytrackWIDTH) && m_respFactorstrackWIDTH.size() < 3 ) {
274 ATH_MSG_FATAL("Vector of trackWIDTH histograms may be empty. Please check your GSCFactors file: " << GSCFile);
275 return StatusCode::FAILURE;
276 }
277 else if ( (m_depth & ApplyPunchThrough) && m_respFactorsPunchThrough.size() < 2 ) {
278 ATH_MSG_FATAL("Vector of PunchThrough histograms may be empty. Please check your GSCFactors file: " << GSCFile);
279 return StatusCode::FAILURE;
280 }
281 else ATH_MSG_DEBUG("GSC Tool has been initialized with binning and eta fit factors from: " << fileName);
282 }
283 return StatusCode::SUCCESS;
284
285}
286
287double GlobalSequentialCorrection::readPtJetPropertyHisto(double pT, double jetProperty, const TH2& respFactors) const {
288 int pTbin = respFactors.GetXaxis()->FindBin(pT);
289 int pTMinbin = respFactors.GetXaxis()->GetFirst();
290 int pTMaxbin = respFactors.GetXaxis()->GetLast();
291 int jetPropbin = respFactors.GetYaxis()->FindBin(jetProperty);
292 int jetPropMinbin = respFactors.GetYaxis()->GetFirst();
293 int jetPropMaxbin = respFactors.GetYaxis()->GetLast();
294 //Protection against input values that are outside the histogram range, which would cause TH2::Interpolate to throw an error
295 if (pTbin < pTMinbin) pT = respFactors.GetXaxis()->GetBinLowEdge(pTMinbin)+1e-6;
296 else if (pTbin > pTMaxbin) pT = respFactors.GetXaxis()->GetBinUpEdge(pTMaxbin)-1e-6;
297 if (jetPropbin < jetPropMinbin) jetProperty = respFactors.GetYaxis()->GetBinLowEdge(jetPropMinbin)+1e-6;
298 else if (jetPropbin > jetPropMaxbin) jetProperty = respFactors.GetYaxis()->GetBinUpEdge(jetPropMaxbin)-1e-6;
299 //TH2::Interpolate is a bilinear interpolation from the bin centers.
300 return respFactors.Interpolate(pT, jetProperty);
301}
302
303double GlobalSequentialCorrection::getTrackWIDTHResponse(double pT, uint etabin, double trackWIDTH) const {
304 if (trackWIDTH<=0) return 1;
305 if ( etabin >= m_respFactorstrackWIDTH.size() ) return 1.;
306 //jets with no tracks are assigned a trackWIDTH of -1, we use the trackWIDTH=0 correction in those cases
307 double trackWIDTHResponse;
309 if(pT>=m_turnOffStartingpT && pT<=m_turnOffEndpT){
310 double responseatStartingpT = readPtJetPropertyHisto(m_turnOffStartingpT, trackWIDTH, *m_respFactorstrackWIDTH[etabin]);
311 trackWIDTHResponse = (1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT);
312 trackWIDTHResponse *= pT;
313 trackWIDTHResponse += 1 - (m_turnOffEndpT*(1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT));
314 return trackWIDTHResponse;
315 }
316 else if(pT>m_turnOffEndpT) return 1;
317 }
318 trackWIDTHResponse = readPtJetPropertyHisto(pT, trackWIDTH, *m_respFactorstrackWIDTH[etabin]);
319 return trackWIDTHResponse;
320}
321
322double GlobalSequentialCorrection::getNTrkResponse(double pT, uint etabin, double nTrk) const {
323 if (nTrk<=0) return 1; //nTrk < 0 is unphysical, nTrk = 0 is a special case, so return 1 for nTrk <= 0
324 if ( etabin >= m_respFactorsnTrk.size() ) return 1.;
325 double nTrkResponse;
327 if(pT>=m_turnOffStartingpT && pT<=m_turnOffEndpT){
328 double responseatStartingpT = readPtJetPropertyHisto(m_turnOffStartingpT, nTrk, *m_respFactorsnTrk[etabin]);
329 nTrkResponse = (1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT);
330 nTrkResponse *= pT;
331 nTrkResponse += 1 - (m_turnOffEndpT*(1-responseatStartingpT)/(m_turnOffEndpT-m_turnOffStartingpT));
332 return nTrkResponse;
333 }
334 else if(pT>m_turnOffEndpT) return 1;
335 }
336 nTrkResponse = readPtJetPropertyHisto(pT, nTrk, *m_respFactorsnTrk[etabin]);
337 return nTrkResponse;
338}
339
340double GlobalSequentialCorrection::getTile0Response(double pT, uint etabin, double Tile0) const {
341 if (Tile0<0) return 1; //Tile0 < 0 is unphysical, so we return 1
342 if ( etabin >= m_respFactorsTile0.size() ) return 1.;
343 double Tile0Response = readPtJetPropertyHisto(pT, Tile0, *m_respFactorsTile0[etabin]);
344 return Tile0Response;
345}
346
347double GlobalSequentialCorrection::getEM3Response(double pT, uint etabin, double EM3) const {
348 if (EM3<=0) return 1; //EM3 < 0 is unphysical, EM3 = 0 is a special case, so we return 1 for EM3 <= 0
349 if ( etabin >= m_respFactorsEM3.size() ) return 1.;
350 double EM3Response = readPtJetPropertyHisto(pT, EM3, *m_respFactorsEM3[etabin]);
351 return EM3Response;
352}
353
354double GlobalSequentialCorrection::getChargedFractionResponse(double pT, uint etabin, double ChargedFraction) const {
355 if (ChargedFraction<=0) return 1; //ChargedFraction < 0 is unphysical, ChargedFraction = 0 is a special case, so we return 1 for ChargedFraction <= 0
356 if ( etabin >= m_respFactorsChargedFraction.size() ) return 1.;
357 double ChargedFractionResponse = readPtJetPropertyHisto(pT, ChargedFraction, *m_respFactorsChargedFraction[etabin]);
358 return ChargedFractionResponse;
359}
360
361double GlobalSequentialCorrection::getPunchThroughResponse(double E, double eta_det, int Nsegments) const {
362 int etabin=-99;
363 //Check that the punch through eta binning defined in the config appears reasonable, otherwise throw an error.
365 ATH_MSG_WARNING("Please check that the punch through eta binning is properly set in your config file");
366 if ( eta_det >= m_punchThroughEtaBins.back() || Nsegments < m_punchThroughMinNseg ) return 1;
367 for (uint i=0; i<m_punchThroughEtaBins.size()-1; ++i) {
368 if(eta_det >= m_punchThroughEtaBins[i] && eta_det < m_punchThroughEtaBins[i+1]) etabin = i;
369 }
370 if(etabin<0) {
371 ATH_MSG_WARNING("There was a problem determining the eta bin to use for the punch through correction.");
372 //this could probably be improved, but to avoid a seg fault...
373 return 1;
374 }
375 double PunchThroughResponse = readPtJetPropertyHisto(E,Nsegments,*m_respFactorsPunchThrough[etabin]);
376 if(!m_pTResponseRequirementOff && PunchThroughResponse>1) return 1;
377 return PunchThroughResponse;
378}
379
380double GlobalSequentialCorrection::getCaloWIDTHResponse(double pT, uint etabin, double caloWIDTH) const {
381 if (caloWIDTH<=0) return 1;
382 if ( etabin >= m_respFactorscaloWIDTH.size() ) return 1.;
383 double caloWIDTHResponse = readPtJetPropertyHisto(pT, caloWIDTH, *m_respFactorscaloWIDTH[etabin]);
384 return caloWIDTHResponse;
385}
386
387double GlobalSequentialCorrection::getN90ConstituentsResponse(double pT, uint etabin, double N90Constituents) const {
388 if (N90Constituents<=0) return 1; // N90Constituents < 0 is unphysical, N90Constituents = 0 is a special case, so return 1 for N90Constituents <= 0
389 if ( etabin >= m_respFactorsN90Constituents.size() ) return 1.;
390 double N90ConstituentsResponse = readPtJetPropertyHisto(pT, N90Constituents, *m_respFactorsN90Constituents[etabin]);
391 return N90ConstituentsResponse;
392}
393
394double GlobalSequentialCorrection::getTileGap3Response(double pT, uint etabin, double TileGap3 ) const {
395 if (TileGap3<0) return 1; //TileGap3 < 0 is unphysical, so we return 1
396 if ( etabin >= m_respFactorsTileGap3.size() ) return 1.;
397 double TileGap3Response = readPtJetPropertyHisto(pT, TileGap3, *m_respFactorsTileGap3[etabin]);
398 return TileGap3Response;
399}
400
402 double trackWIDTH, double nTrk, double Tile0, double EM3, int Nsegments, double ChargedFraction, double caloWIDTH, double N90Constituents, double TileGap3) const {
403 //eta bins have size m_binSize=0.1 and are numbered sequentially from 0, so |eta|=2.4 is in eta bin #24
404 int etabin = eta/m_binSize;
405 double Corr=1;
406 //Using bit sequence check to determine which GS corrections to apply.
407 if( !m_PFlow && !m_caloBased ){
408 if (m_depth & ApplyTile0) Corr*=1./getTile0Response(jetP4.pt()/m_GeV, etabin, Tile0);
409 if (m_depth & ApplyEM3) Corr*=1./getEM3Response(jetP4.pt()/m_GeV*Corr, etabin, EM3);
410 if (m_depth & ApplynTrk) Corr*=1./getNTrkResponse(jetP4.pt()/m_GeV*Corr, etabin, nTrk);
411 if (m_depth & ApplytrackWIDTH) Corr*=1./getTrackWIDTHResponse(jetP4.pt()/m_GeV*Corr,etabin,trackWIDTH);
412 if ( jetP4.pt() < m_punchThroughMinPt ) return Corr; //Applying punch through correction to low pT jets introduces a bias, default threshold is 50 GeV
413 //eta binning for the punch through correction differs from the rest of the GSC, so the eta bin is determined in the GetPunchThroughResponse method
414 else if (m_depth & ApplyPunchThrough) {
415 jetP4*=Corr; //The punch through correction is binned in E instead of pT, so we determine E from the corrected jet here
416 Corr*=1/getPunchThroughResponse(jetP4.e()/m_GeV,eta,Nsegments);
417 }
418 }
419 else if (m_caloBased){
420 if (m_depth & ApplyTile0) Corr*=1./getTile0Response(jetP4.pt()/m_GeV*Corr, etabin, Tile0);
421 if (m_depth & ApplyEM3) Corr*=1./getEM3Response(jetP4.pt()/m_GeV*Corr, etabin, EM3);
422 if (m_depth & ApplyN90Constituents) Corr*=1/getN90ConstituentsResponse(jetP4.pt()/m_GeV*Corr, etabin, N90Constituents);
423 if (m_depth & ApplyTileGap3) Corr*=1/getTileGap3Response(jetP4.pt()/m_GeV*Corr,etabin, TileGap3);
424 if (m_depth & ApplycaloWIDTH) Corr*=1/getCaloWIDTHResponse(jetP4.pt()/m_GeV*Corr,etabin,caloWIDTH);
425 }
426 else{ // PFlow
427 if (m_depth & ApplyChargedFraction) Corr*=1./getChargedFractionResponse(jetP4.pt()/m_GeV, etabin, ChargedFraction);
428 if (m_depth & ApplyTile0) Corr*=1./getTile0Response(jetP4.pt()/m_GeV*Corr, etabin, Tile0);
429 if (m_depth & ApplyEM3) Corr*=1./getEM3Response(jetP4.pt()/m_GeV*Corr, etabin, EM3);
430 if ( m_nTrkwTrk_4PFlow && (m_depth & ApplynTrk) ) Corr*=1./getNTrkResponse(jetP4.pt()/m_GeV*Corr, etabin, nTrk);
431 if ( m_nTrkwTrk_4PFlow && (m_depth & ApplytrackWIDTH) ) Corr*=1./getTrackWIDTHResponse(jetP4.pt()/m_GeV*Corr,etabin,trackWIDTH);
432 if ( jetP4.pt() < m_punchThroughMinPt ) return Corr; //Applying punch through correction to low pT jets introduces a bias, default threshold is 50 GeV
433 //eta binning for the punch through correction differs from the rest of the GSC, so the eta bin is determined in the GetPunchThroughResponse method
434 else if (m_depth & ApplyPunchThrough) {
435 jetP4*=Corr; //The punch through correction is binned in E instead of pT, so we determine E from the corrected jet here
436 Corr*=1/getPunchThroughResponse(jetP4.e()/m_GeV,eta,Nsegments);
437 }
438 }
439 return Corr;
440}
441
443
444 //vector<float> that holds the fractional energy deposited by the jet in different layers of the calorimetery
445 /* Map of the entries in the vector to different layers of the calorimeter
446 Retrieved on July 14th 2014 from https://twiki.cern.ch/twiki/bin/view/AtlasProtected/Run2JetMoments
447 If July 14th 2014 was awhile ago, it might be worth double checking this is still valid...
448
449 Layer Index
450 LAr barrel
451 PreSamplerB 0
452 EMB1 1
453 EMB2 2
454 EMB3 3
455 LAr EM endcap
456 PreSamplerE 4
457 EME1 5
458 EME2 6
459 EME3 7
460 Hadronic endcap
461 HEC0 8
462 HEC1 9
463 HEC2 10
464 HEC3 11
465 Tile barrel
466 TileBar0 12
467 TileBar1 13
468 TileBar2 14
469 Tile gap (ITC & scint)
470 TileGap1 15
471 TileGap2 16
472 TileGap3 17
473 Tile extended barrel
474 TileExt0 18
475 TileExt1 19
476 TileExt2 20
477 Forward EM endcap
478 FCAL0 21
479 FCAL1 22
480 FCAL2 23
481 Mini FCAL
482 MINIFCAL0 24
483 MINIFCAL1 25
484 MINIFCAL2 26
485 MINIFCAL3 27
486 */
487
488 std::vector<float> samplingFrac = jet.getAttribute<std::vector<float> >("EnergyPerSampling");
489 //vector<int> that holds the number of tracks with pT > 1 GeV for different primary vertices
490 std::vector<int> nTrk;
491 if(m_depth & ApplynTrk){
492 if( !jet.getAttribute<std::vector<int> >("NumTrkPt1000",nTrk) ) {
493 ATH_MSG_ERROR("Failed to retrieve NumTrkPt1000!");
494 return StatusCode::FAILURE;
495 }
496 }
497 //vector<float> that holds the trackWIDTH variable calculated with tracks of pT > 1 GeV for different primary vertices
498 std::vector<float> trackWIDTH;
500 if( !jet.getAttribute<std::vector<float> >("TrackWidthPt1000",trackWIDTH) ) {
501 ATH_MSG_ERROR("Failed to retrieve TrackWidthPt1000!");
502 return StatusCode::FAILURE;
503 }
504 }
505 //Nsegments number of ghost associated muon segments behind each jet
506 int Nsegments = 0;
508 if( m_ghostMuSegCountAcc.isAvailable(jet) ) {
509 Nsegments = m_ghostMuSegCountAcc(jet);
510 } else {
511 ATH_MSG_WARNING(m_ghostMuSegCountName << " is not available, Nsegments=0 will be used, so NO PunchThrough Correction will be applied!");
512 }
513 }
514
515 xAOD::JetFourMom_t jetconstitP4 = jet.getAttribute<xAOD::JetFourMom_t>("JetConstitScaleMomentum");
516
517 //Entry 0 of the ChargedFraction, nTrk, and trackWIDTH vectors should correspond to PV0
518 //other entries are for other primary vertices in the event
519 //Check what index the user wants just in case (default to PVIndex, which is typically PV0)
520 int PVindex = jetEventInfo.PVIndex();
521
523 // Retrieve the vertex the jet was reconstructed with respect to
524 PVindex = jet.getAssociatedObject<xAOD::Vertex>("OriginVertex")->index();
525 }
526
527 double ChargedFraction = 0;
528 if( m_PFlow ) ChargedFraction = (jet.getAttribute<std::vector<float> >("SumPtChargedPFOPt500"))[PVindex]/jetconstitP4.Pt();
529
530 xAOD::JetFourMom_t jetStartP4;
532 jetStartP4 = jet.jetP4();
533
534 float jetE_constitscale = jetconstitP4.e();
535 float detectorEta = jet.getAttribute<float>("DetectorEta");
536
537 int nTrkPVX = (m_depth & ApplynTrk) ? nTrk[PVindex] : 0;
538 float trackWIDTHPVX = (m_depth & ApplytrackWIDTH) ? trackWIDTH[PVindex] : 0;
539 //EM3 and Tile0 fraction calculations
540 //EM3 = (EMB3+EME3)/energy, Tile0 = (TileBar0+TileExt0)/energy
541 //Check the map above to make sure the correct entries of samplingFrac are being used
542 float EM3 = (samplingFrac[3]+samplingFrac[7])/jetE_constitscale;
543 float Tile0 = (samplingFrac[12]+samplingFrac[18])/jetE_constitscale;
544
545 double N90Constituents = 0;
546 double caloWIDTH = 0;
547 float TG3 = 0;
548 if (m_caloBased) {
550 //numConstituents = jet.numConstituents();
551 N90Constituents = jet.getAttribute<float>("N90Constituents");
552 }
553 if (m_depth & ApplycaloWIDTH) {
554 caloWIDTH = jet.getAttribute<double>("Width");
555 }
556 if (m_depth & ApplyTileGap3) {
557 //TileGap3 at index 17 of samplingFrac, see map above
558 TG3 = (samplingFrac[17])/jetE_constitscale;
559 }
560 }
561
562 xAOD::JetFourMom_t calibP4 = jetStartP4*getGSCCorrection( jetStartP4, fabs(detectorEta), trackWIDTHPVX, nTrkPVX, Tile0, EM3, Nsegments, ChargedFraction, caloWIDTH, N90Constituents, TG3);
563
564 //Transfer calibrated jet properties to the Jet object
565 jet.setAttribute<xAOD::JetFourMom_t>("JetGSCScaleMomentum",calibP4);
566 jet.setJetP4( calibP4 );
567
568 return StatusCode::SUCCESS;
569
570}
571
572
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_FATAL(x,...)
@ Data
Definition BaseObject.h:11
Helper class to provide constant type-safe access to aux data.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
double getChargedFractionResponse(double pT, uint etabin, double ChargedFraction) const
void setPunchThroughEtaBins(const VecD &etabins)
double getEM3Response(double pT, uint etabin, double EM3) const
double getGSCCorrection(xAOD::JetFourMom_t jetP4, double eta, double trackWIDTH, double nTrk, double Tile0, double EM3, int Nsegments, double ChargedFraction, double caloWIDTH, double N90Constituents, double TileGap3) const
double getN90ConstituentsResponse(double pT, uint etabin, double N90Constituents) const
double getCaloWIDTHResponse(double pT, uint etabin, double caloWIDTH) const
virtual StatusCode initialize() override
double readPtJetPropertyHisto(double pT, double jetProperty, const TH2 &respFactors) const
virtual StatusCode calibrate(xAOD::Jet &jet, JetEventInfo &) const override
double getTrackWIDTHResponse(double pT, uint etabin, double trackWIDTH) const
double getTileGap3Response(double pT, uint etabin, double TileGap3) const
double getPunchThroughResponse(double E, double eta_det, int Nsegments) const
double getNTrkResponse(double pT, uint etabin, double nTrk) const
SG::ConstAccessor< int > m_ghostMuSegCountAcc
double getTile0Response(double pT, uint etabin, double Tile0) const
virtual StatusCode setStartP4(xAOD::Jet &jet) const
JetCalibrationStep(const char *name="JetCalibrationStep")
Helper class to provide constant type-safe access to aux data.
std::string depth
tag string for intendation
Definition fastadd.cxx:46
std::unique_ptr< const TH2 > GetHisto2(TFile &file, const TString &hname)
VecD VectorizeD(const TString &str, const TString &sep=" ")
Definition index.py:1
STL namespace.
Jet_v1 Jet
Definition of the current "jet version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17