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/");
157 std::unique_ptr<TFile> inputFile(TFile::Open(fileName));
158 if (!inputFile || inputFile->IsZombie())
160 ATH_MSG_FATAL(
"Cannot open jet smearing correction file: " << fileName);
161 return StatusCode::FAILURE;
165 m_smearResolutionMC = std::unique_ptr<TH1>(
dynamic_cast<TH1*
>(inputFile->Get(smearingHistNameMC)));
168 ATH_MSG_FATAL(
"Failed to get specified histogram from the file: " << smearingHistNameMC.Data());
169 return StatusCode::FAILURE;
173 m_smearResolutionData = std::unique_ptr<TH1>(
dynamic_cast<TH1*
>(inputFile->Get(smearingHistNameData)));
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;
399 resolution = localRes;
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;
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
std::string m_jetStartScale
JetCalibrationStep(const char *name="JetCalibrationStep")
StatusCode getSigmaSmear(xAOD::Jet &jet, double &sigmaSmear) const
StatusCode readHisto(double &returnValue, const TH1 *histo, double x) const
boost::thread_specific_ptr< TRandom3 > m_rand_tls
const TString m_calibAreaTag
StatusCode cacheProjections(TH1 *fullHistogram, std::vector< std::unique_ptr< TH1 > > &cacheLocation, const std::string &type)
std::vector< std::unique_ptr< TH1 > > m_cachedProjResData
virtual StatusCode initialize() override
StatusCode getNominalResolution(const xAOD::Jet &jet, const TH1 *histo, const std::vector< std::unique_ptr< TH1 > > &projections, double &resolution) const
std::unique_ptr< TH1 > m_smearResolutionMC
TRandom3 * getTLSRandomGen(unsigned long seed) const
virtual StatusCode getNominalResolutionMC(const xAOD::Jet &jet, double &resolution) const override
std::vector< std::unique_ptr< TH1 > > m_cachedProjResMC
virtual ~JetSmearingCorrection()
virtual StatusCode calibrate(xAOD::Jet &jet, JetEventInfo &) const override
virtual StatusCode getNominalResolutionData(const xAOD::Jet &jet, double &resolution) const override
std::unique_ptr< TH1 > m_smearResolutionData
Jet_v1 Jet
Definition of the current "jet version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.