21 , m_smearResolutionMC()
22 , m_smearResolutionData()
24 , m_cachedProjResData()
30 , m_jetAlgo(std::move(jetAlgo))
31 , m_calibAreaTag(std::move(calibAreaTag))
37 , m_smearResolutionMC()
38 , m_smearResolutionData()
40 , m_cachedProjResData()
48 ATH_MSG_INFO(
"Initializing the jet smearing correction tool");
53 return StatusCode::FAILURE;
58 return StatusCode::FAILURE;
67 TString smearType =
m_config->GetValue(
"SmearType",
"");
70 ATH_MSG_FATAL(
"No jet smearing type was specified. Aborting.");
71 return StatusCode::FAILURE;
73 else if (!smearType.CompareTo(
"pt",TString::kIgnoreCase))
75 else if (!smearType.CompareTo(
"mass",TString::kIgnoreCase))
77 else if (!smearType.CompareTo(
"FourVec",TString::kIgnoreCase))
81 ATH_MSG_FATAL(
"Unrecognized jet smearing type: " << smearType.Data());
82 return StatusCode::FAILURE;
86 TString histType =
m_config->GetValue(
"SmearingCorrectionHistType",
"");
89 ATH_MSG_FATAL(
"No jet smearing histogram parametrization was specified. Aborting.");
90 return StatusCode::FAILURE;
92 else if (!histType.CompareTo(
"pt",TString::kIgnoreCase))
94 else if (!histType.CompareTo(
"PtEta",TString::kIgnoreCase))
96 else if (!histType.CompareTo(
"PtAbsEta",TString::kIgnoreCase))
100 ATH_MSG_FATAL(
"Unrecognized jet smearing histogram parametrization: " << histType.Data());
101 return StatusCode::FAILURE;
105 TString interpType =
m_config->GetValue(
"SmearingCorrectionInterpType",
"");
106 if (interpType ==
"")
108 ATH_MSG_FATAL(
"No jet smearing histogram interpolation type was specified. Aborting.");
109 return StatusCode::FAILURE;
111 else if (!interpType.CompareTo(
"full",TString::kIgnoreCase))
113 else if (!interpType.CompareTo(
"none",TString::kIgnoreCase))
115 else if (!interpType.CompareTo(
"onlyx",TString::kIgnoreCase))
117 else if (!interpType.CompareTo(
"onlyy",TString::kIgnoreCase))
121 ATH_MSG_FATAL(
"Unrecognized jet smearing interpolation type: " << interpType.Data());
122 return StatusCode::FAILURE;
126 TString smearingFile =
m_config->GetValue(
"SmearingCorrectionFile",
"");
127 if (smearingFile ==
"")
129 ATH_MSG_FATAL(
"No jet smearing correction file specified. Aborting.");
130 return StatusCode::FAILURE;
134 TString smearingHistNameMC =
m_config->GetValue(
"SmearingHistNameResolutionMC",
"");
135 if (smearingHistNameMC ==
"")
137 ATH_MSG_FATAL(
"No MC jet smearing histogram name specified. Aborting.");
138 return StatusCode::FAILURE;
140 TString smearingHistNameData =
m_config->GetValue(
"SmearingHistNameResolutionData",
"");
141 if (smearingHistNameData ==
"")
143 ATH_MSG_FATAL(
"No data jet smearing histogram name specified. Aborting.");
144 return StatusCode::FAILURE;
150 smearingFile.Remove(0,33);
151 smearingFile.Insert(0,
"JetCalibTools/");
161 return StatusCode::FAILURE;
168 ATH_MSG_FATAL(
"Failed to get specified histogram from the file: " << smearingHistNameMC.Data());
169 return StatusCode::FAILURE;
176 ATH_MSG_FATAL(
"Failed to get specified histogram from the file: " << smearingHistNameData.Data());
177 return StatusCode::FAILURE;
192 return StatusCode::FAILURE;
197 return StatusCode::FAILURE;
206 return StatusCode::FAILURE;
211 return StatusCode::FAILURE;
216 ATH_MSG_FATAL(
"Read the histogram, but the parametrization is UNKNOWN");
217 return StatusCode::FAILURE;
224 return StatusCode::FAILURE;
226 return StatusCode::FAILURE;
229 return StatusCode::SUCCESS;
238 return StatusCode::FAILURE;
242 if (
histo->GetDimension() != 1)
244 ATH_MSG_ERROR(
"Blocking reading of a " <<
histo->GetDimension() <<
"D histogram as a 1D histogram");
245 return StatusCode::FAILURE;
249 const double minX =
histo->GetXaxis()->GetBinLowEdge(1);
250 const double maxX =
histo->GetXaxis()->GetBinLowEdge(
histo->GetNbinsX()+1);
253 else if (
x <= minX )
261 returnValue =
histo->Interpolate(
x);
265 returnValue =
histo->GetBinContent(
histo->GetXaxis()->FindBin(
x));
269 ATH_MSG_ERROR(
"Unsupported interpolation type for a 1D histogram");
270 return StatusCode::FAILURE;
273 return StatusCode::SUCCESS;
282 return StatusCode::FAILURE;
286 if (
histo->GetDimension() != 2)
288 ATH_MSG_ERROR(
"Blocking reading of a " <<
histo->GetDimension() <<
"D histogram as a 2D histogram");
289 return StatusCode::FAILURE;
293 const double minX =
histo->GetXaxis()->GetBinLowEdge(1);
294 const double maxX =
histo->GetXaxis()->GetBinLowEdge(
histo->GetNbinsX()+1);
297 else if (
x <= minX )
299 const double minY =
histo->GetYaxis()->GetBinLowEdge(1);
300 const double maxY =
histo->GetYaxis()->GetBinLowEdge(
histo->GetNbinsY()+1);
303 else if (
y <= minY )
310 returnValue =
histo->Interpolate(
x,
y);
314 returnValue =
histo->GetBinContent(
histo->GetXaxis()->FindBin(
x),
histo->GetYaxis()->FindBin(
y));
319 returnValue = projections.at(
histo->GetYaxis()->FindBin(
y))->Interpolate(
x);
324 returnValue = projections.at(
histo->GetXaxis()->FindBin(
x))->Interpolate(
y);
328 ATH_MSG_ERROR(
"Unsupported interpolation type for a 2D histogram");
329 return StatusCode::FAILURE;
332 return StatusCode::SUCCESS;
352 double resolutionMC = 0;
354 return StatusCode::FAILURE;
356 double resolutionData = 0;
358 return StatusCode::FAILURE;
363 if (resolutionMC < resolutionData)
364 sigmaSmear = sqrt(resolutionData*resolutionData - resolutionMC*resolutionMC);
368 return StatusCode::SUCCESS;
378 return StatusCode::FAILURE;
383 return StatusCode::FAILURE;
388 return StatusCode::FAILURE;
393 ATH_MSG_ERROR(
"Cannot get the nominal resolution, the smearing histogram type was not set");
394 return StatusCode::FAILURE;
400 return StatusCode::SUCCESS;
417 random =
new TRandom3();
420 random->SetSeed(seed);
429 double sigmaSmear = 0;
431 return StatusCode::FAILURE;
434 unsigned long seed =
static_cast<unsigned long>(1.e5*fabs(
jet.phi()));
436 if(seed == 0) seed = 45583453;
442 double smearingFactor = -1;
443 while (smearingFactor < 0)
444 smearingFactor =
rng->Gaus(1.,sigmaSmear);
464 ATH_MSG_ERROR(
"Cannot smear the jet, the smearing type was not set");
465 return StatusCode::FAILURE;
470 jet.setJetP4(calibP4);
473 return StatusCode::SUCCESS;
482 return StatusCode::FAILURE;
486 if (fullHistogram->GetDimension() < 1 || fullHistogram->GetDimension() > 2)
488 ATH_MSG_FATAL(
"Unsupported histogram dimensionality for projection caching: " << fullHistogram->GetDimension());
489 return StatusCode::FAILURE;
497 if (fullHistogram->GetDimension() == 1)
498 return StatusCode::SUCCESS;
503 if (fullHistogram->GetDimension() == 1)
506 return StatusCode::FAILURE;
512 return StatusCode::FAILURE;
520 if (fullHistogram->GetDimension() == 2)
522 TH2* localHist =
dynamic_cast<TH2*
>(fullHistogram);
525 ATH_MSG_FATAL(
"Failed to convert histogram to a TH2, please check inputs: " <<
type);
526 return StatusCode::FAILURE;
530 for (Long64_t
binY = 0;
binY < localHist->GetNbinsY()+1; ++
binY)
533 cacheLocation.emplace_back(localHist->ProjectionX(Form(
"projx_%s_%lld",
type.c_str(),
binY),
binY,
binY));
538 for (Long64_t
binX = 0;
binX < localHist->GetNbinsX()+1; ++
binX)
541 cacheLocation.emplace_back(localHist->ProjectionY(Form(
"projy_%s_%lld",
type.c_str(),
binX),
binX,
binX));
547 ATH_MSG_FATAL(
"Unexpected interpolation type, somehow escaped earlier checks: " <<
type);
548 return StatusCode::FAILURE;
554 ATH_MSG_FATAL(
"Unexpected dimensionality: " << fullHistogram->GetDimension());
555 return StatusCode::FAILURE;
559 for (
auto&
hist : cacheLocation)
561 hist->SetDirectory(
nullptr);
565 return StatusCode::SUCCESS;