57 ATH_MSG_FATAL(Form(
"Blocking re-initialization of tool named %s",AsgTool::name().c_str()));
58 return StatusCode::FAILURE;
61 ATH_MSG_INFO(Form(
"Preparing to initialize the FFJetSmearingTool named %s",AsgTool::name().c_str()));
63 if (AsgTool::name().
empty()){
65 return StatusCode::FAILURE;
70 return StatusCode::FAILURE;
75 return StatusCode::FAILURE;
87 if (settings.ReadFile( configFilePath.Data(),kEnvGlobal)){
88 ATH_MSG_ERROR(
"Cannot read config file: " << configFilePath.Data());
89 return StatusCode::FAILURE;
92 ATH_MSG_INFO(
"================================================");
93 ATH_MSG_INFO(Form(
" Initializing the FFJetSmearingTool named %s",AsgTool::name().c_str()));
97 m_release = settings.GetValue(
"UncertaintyRelease",
"UNKNOWN");
103 ATH_MSG_ERROR(
"Cannot find the truth jet collection to use in config");
104 return StatusCode::FAILURE;
111 ATH_MSG_ERROR(
"Cannot find the TruthLabelAccessor to use in config");
112 return StatusCode::FAILURE;
119 ATH_MSG_ERROR(
"Cannot find the SupportedMCTypes to use in config");
120 return StatusCode::FAILURE;
127 ATH_MSG_ERROR(
"You are not running with a supported MC type");
128 return StatusCode::FAILURE;
134 ATH_MSG_ERROR(
"Cannot find the EtaRange parameter in the config file");
135 return StatusCode::FAILURE;
140 m_MaxMass = settings.GetValue(
"MaxMass",0);
142 ATH_MSG_ERROR(
"Cannot find the MaxMass parameter in the config file");
143 return StatusCode::FAILURE;
148 m_MaxPt = settings.GetValue(
"MaxPt",0);
150 ATH_MSG_ERROR(
"Cannot find the MaxPt parameter in the config file");
151 return StatusCode::FAILURE;
159 ATH_MSG_ERROR(
"Cannot find uncertainty histogram file in the config file");
160 return StatusCode::FAILURE;
173 return StatusCode::FAILURE;
180 return StatusCode::SUCCESS;
192 return sys.find(systematic) != sys.end();
212 if ((*ci).basename().find(
"CALO_")!=std::string::npos){
213 filteredSysts.
insert(*ci);
216 return filteredSysts;
222 if ((*ci).basename().find(
"TA_") !=std::string::npos){
223 filteredSysts.
insert(*ci);
226 return filteredSysts;
232 if ((*ci).basename().find(
"COMB_")!=std::string::npos){
233 filteredSysts.
insert(*ci);
236 return filteredSysts;
242 if ((*ci).basename().find(
"JET_JMRUnc_")!=std::string::npos){
243 filteredSysts.
insert(*ci);
246 return filteredSysts;
268 filterForAffectingSystematics(
systematics, affectingSysts, filteredSysts) != StatusCode::SUCCESS ){
270 return StatusCode::FAILURE;
277 if (filteredSysts.
size() > 1){
278 ATH_MSG_ERROR(
"No support for more than one JMS/JMR sys at a time: " << filteredSysts.
name());
279 return StatusCode::FAILURE;
281 if (filteredSysts.
size() == 0) {
283 return StatusCode::SUCCESS;
300 return StatusCode::SUCCESS;
310 if (!data_file || data_file->IsZombie()){
312 return StatusCode::FAILURE;
320 TString CaloResponseMap_path = settings.GetValue(
"CaloResponseMap",
"");
322 if (CaloResponseMap_path.IsNull()){
323 ATH_MSG_ERROR(
"Cannot find the CaloResponseMap in the config file");
324 return StatusCode::FAILURE;
327 m_CALO_ResponseMap = std::unique_ptr<TH2>(
static_cast<TH2*
>(data_file->Get( CaloResponseMap_path )));
334 TString TAResponseMap_path = settings.GetValue(
"TAResponseMap",
"");
336 if (TAResponseMap_path.IsNull()){
337 ATH_MSG_ERROR(
"Cannot find the TAResponseMap in the config file");
338 return StatusCode::FAILURE;
341 m_TA_ResponseMap = std::unique_ptr<TH2>(
static_cast<TH2*
>(data_file->Get( TAResponseMap_path )));
348 TString UFOResponseMap_path = settings.GetValue(
"UFOResponseMap",
"");
350 if (UFOResponseMap_path.IsNull()){
351 ATH_MSG_ERROR(
"Cannot find the UFOResponseMap in the config file");
352 return StatusCode::FAILURE;
355 m_UFO_ResponseMap = std::unique_ptr<TH2>(
dynamic_cast<TH2*
>(data_file->Get( UFOResponseMap_path )));
362 for (
size_t iComp = 0; iComp < 999; ++iComp){
364 const TString prefix = Form(
"JMSComponent.%zu.",iComp);
365 std::string Syst_Name = settings.GetValue(prefix+
"Name",
"");
367 if (!Syst_Name.empty()){
393 const std::string to_find =
"MCTYPE";
395 for (
size_t iComp = 0; iComp < 999; ++iComp){
396 const TString prefix = Form(
"JMRComponent.%zu.",iComp);
397 std::string Syst_Name = settings.GetValue(prefix+
"Name",
"");
400 if (!Syst_Name.empty()){
443 TString Calo_TA_weight_file_name = settings.GetValue(
"JetUncertainties_UncertaintyRootFile",
"");
446 if (Calo_TA_weight_file_path.IsNull()){
447 ATH_MSG_ERROR(
"Cannot find the file with the Calo and TA weights");
448 return StatusCode::FAILURE;
451 TString Calo_weight_hist_name = settings.GetValue(
"CombMassWeightCaloHist",
"");
452 if (Calo_weight_hist_name.IsNull()){
453 ATH_MSG_ERROR(
"Cannot find the histogram name that contains the Calo weights in the config file");
454 return StatusCode::FAILURE;
457 TString TA_weight_hist_name = settings.GetValue(
"CombMassWeightTAHist",
"");
458 if (TA_weight_hist_name.IsNull()){
459 ATH_MSG_ERROR(
"Cannot find the histogram name that contains the TA weights in the config file");
460 return StatusCode::FAILURE;
463 ATH_MSG_INFO(Form(
" Calo weights hist: \"%s\"",Calo_weight_hist_name.Data()));
464 ATH_MSG_INFO(Form(
" TA weights hist: \"%s\"",TA_weight_hist_name.Data()));
465 ATH_MSG_INFO(Form(
" Location: %s",Calo_TA_weight_file_path.Data()));
468 std::unique_ptr<TFile> Calo_TA_weight_file ( TFile::Open(Calo_TA_weight_file_path));
469 if (!Calo_TA_weight_file || Calo_TA_weight_file->IsZombie()){
470 ATH_MSG_FATAL(
"Could not open the first input file: " << Calo_TA_weight_file_path );
471 return StatusCode::FAILURE;
474 m_caloMassWeight = std::unique_ptr<TH3F>(
static_cast<TH3F*
>(Calo_TA_weight_file->Get(Calo_weight_hist_name)));
475 m_TAMassWeight = std::unique_ptr<TH3F>(
static_cast<TH3F*
>(Calo_TA_weight_file->Get(TA_weight_hist_name)));
481 Calo_TA_weight_file->Close();
485 return StatusCode::SUCCESS;
500 double dRmax_truthJet = 0.75;
505 for (
const auto *
const jet_truth : *jets_truth){
506 float dR_Test = jet_reco.
p4().DeltaR(jet_truth->p4());
507 if (dR_Test < dRmax_truthJet){
508 if (dR_Test < dRmin){
509 close_jet = jet_truth;
514 if (dRmin > 999){
return StatusCode::FAILURE;}
517 return StatusCode::SUCCESS;
527 if (!accTruthLabel.isAvailable(jet_reco) )
529 ATH_MSG_ERROR(
"Unable to retrieve the FatjetTruthLabel from the jet. Please call the BoostedJetTaggers decorateTruthLabel() function before calling this function.");
530 return StatusCode::FAILURE;
544 jetTopology=
"no_match";
545 ATH_MSG_DEBUG(
"No truth jet match with this reco jet. The jet will not be smeared.");
550 ATH_MSG_VERBOSE(
"The topology of this jet correspond to a " << jetTopology <<
" large-R jet");
552 return StatusCode::SUCCESS;
579 return StatusCode::SUCCESS;
582 if (topologyAffected !=
"All" && !TString(topologyAffected).Contains(jetTopology)){
583 ATH_MSG_VERBOSE(
"The systematic does not affect to this jet topology");
584 return StatusCode::SUCCESS;
594 const TH2* hist =
nullptr;
600 if (MassDef_of_syst == calo){
602 }
else if (MassDef_of_syst == ta){
612 const TH2* hist =
nullptr;
613 const TH3F* hist3d =
nullptr;
617 if (uncertparam ==
"eLOGmOeAbsEta"){
623 if (MassDef_of_syst == calo){
624 if (uncertparam ==
"eLOGmOeAbsEta"){
629 }
else if (MassDef_of_syst == ta){
630 if (uncertparam ==
"eLOGmOeAbsEta"){
638 if (uncertparam ==
"eLOGmOeAbsEta"){
651 return StatusCode::SUCCESS;
661 ATH_MSG_VERBOSE(
"//---------------------------------------------------------------//");
662 ATH_MSG_VERBOSE(
"Reco Jet to Smear: pt = " << jet_reco.
pt() <<
", mass = " << jet_reco.
m() <<
", eta = " << jet_reco.
eta());
673 ATH_MSG_DEBUG(
"This jet exceeds the maximum pt that the tool allows jet_pt <" <<
m_MaxPt <<
" MeV)");
676 if (jet_reco.
m() <= 0){
683 jet_truth_matched.makePrivateStore();
686 ATH_MSG_VERBOSE(
"No truth jet match with this reco jet. The jet will not be smeared.");
690 ATH_MSG_VERBOSE(
"Matched truth Jet: pt = " << jet_truth_matched.
pt() <<
", mass = " << jet_truth_matched.
m() <<
", eta = " << jet_truth_matched.
eta());
693 std::string jetTopology;
699 if (jetTopology ==
"no_match"){
705 double jet_mass_UFO = 0;
706 double jet_mass_CALO = 0;
707 double jet_mass_TA = 0;
708 double calo_mass_weight=1;
710 float JetTrackAssistedMassCalibrated_from_JetCalibTools;
726 jet_mass_CALO = jet_reco_CALO.mass();
727 jet_mass_TA = jet_reco_TA.mass();
728 jet_reco.
getAttribute<
float>(
"JetTrackAssistedMassCalibrated", JetTrackAssistedMassCalibrated_from_JetCalibTools);
731 jet_mass_CALO = jet_reco.
m();
732 calo_mass_weight = 1;
734 jet_mass_TA = jet_reco.
m();
735 jet_reco.
getAttribute<
float>(
"JetTrackAssistedMassCalibrated", JetTrackAssistedMassCalibrated_from_JetCalibTools);
736 calo_mass_weight = 0;
738 jet_mass_UFO = jet_reco.
m();
739 calo_mass_weight = 1;
744 double avg_response_UFO=1;
745 double avg_response_CALO=1;
746 double avg_response_TA=1;
750 if (avg_response_CALO == 0) avg_response_CALO=1;
755 if (avg_response_TA == 0) avg_response_TA = 1;
760 if (avg_response_UFO == 0) avg_response_UFO = 1;
765 double JMS(1), JMS_err(0), JMR(1), JMR_err(0);
769 double smeared_UFO_mass = jet_mass_UFO;
770 double smeared_CALO_mass = jet_mass_CALO;
771 double smeared_TA_mass = jet_mass_TA;
773 bool is_UFO_mass_smeared =
false;
774 bool is_CALO_mass_smeared =
false;
775 bool is_TA_mass_smeared =
false;
783 scale = JMS + JMS_err;
784 resolution = JMR + JMR_err;
786 if (TMath::Abs(scale-1) > 0.0001 || TMath::Abs(resolution-1) > 0.0001){
787 is_CALO_mass_smeared =
true;
789 ATH_MSG_VERBOSE(
"Forward Folding CALO procedure will use scale=" << scale <<
", resolution=" << resolution <<
" and average respose=" << avg_response_CALO);
792 smeared_CALO_mass = jet_mass_CALO * scale + (jet_mass_CALO - avg_response_CALO*jet_truth_matched.
m())*(resolution-scale);
803 scale = JMS + JMS_err;
804 resolution = JMR + JMR_err;
806 if (TMath::Abs(scale-1) > 0.0001 || TMath::Abs(resolution-1) > 0.0001){
808 is_TA_mass_smeared =
true;
810 ATH_MSG_VERBOSE(
"Forward Folding TA procedure will use scale=" << scale <<
", resolution=" << resolution <<
" and average respose=" << avg_response_TA);
813 smeared_TA_mass = jet_mass_TA * scale + (jet_mass_TA - avg_response_TA*jet_truth_matched.
m())*(resolution-scale);
824 scale = JMS + JMS_err;
825 resolution = JMR + JMR_err;
827 if (TMath::Abs(scale-1) > 0.0001 || TMath::Abs(resolution-1) > 0.0001){
828 is_UFO_mass_smeared =
true;
830 ATH_MSG_VERBOSE(
"Forward Folding UFO procedure will use scale=" << scale <<
", resolution=" << resolution <<
" and average respose=" << avg_response_UFO);
833 smeared_UFO_mass = jet_mass_UFO * scale + (jet_mass_UFO - avg_response_UFO*jet_truth_matched.
m())*(resolution-scale);
839 if (!is_CALO_mass_smeared && !is_TA_mass_smeared && !is_UFO_mass_smeared){
840 ATH_MSG_VERBOSE(
"This jet is not affected by the systematic. The jet won't be modified");
841 ATH_MSG_VERBOSE(
"//---------------------------------------------------------------//");
864 jet_reco_CALO =
xAOD::JetFourMom_t(jet_reco_CALO.pt(),jet_reco_CALO.eta(),jet_reco_CALO.phi(),smeared_CALO_mass);
866 jet_reco_TA =
xAOD::JetFourMom_t(jet_reco_TA.pt(),jet_reco_TA.eta(),jet_reco_TA.phi(),smeared_TA_mass);
884 caloFactor = 0; TAFactor = 1;
885 }
else if (TARes == 0){
886 caloFactor = 1; TAFactor = 0;
888 caloFactor = 1./(caloRes*caloRes);
889 TAFactor = 1./(TARes*TARes);
892 calo_mass_weight = caloFactor /(caloFactor + TAFactor);
896 }
else if (JetTrackAssistedMassCalibrated_from_JetCalibTools == 0){
897 calo_mass_weight = 1;
898 }
else if (jet_mass_CALO == 0){
899 calo_mass_weight = 0;
903 double smeared_mass = 0;
905 smeared_mass = smeared_UFO_mass;
908 smeared_mass = calo_mass_weight*smeared_CALO_mass + (1 - calo_mass_weight)*smeared_TA_mass;
918 ATH_MSG_VERBOSE(
"Smeared Reco Jet: pt = " << jet_reco.
pt() <<
", mass = " << jet_reco.
m() <<
", eta = " << jet_reco.
eta());
920 ATH_MSG_VERBOSE(
"//---------------------------------------------------------------//");
945 for (
size_t iJet = 0; iJet < inputs.size(); ++iJet)
960 ATH_MSG_ERROR(
"Histogram pointer is null in FFJetSmearingTool::Read3DHistogram");
971 double xMax = histo->GetXaxis()->GetBinLowEdge(histo->GetNbinsX()+1);
972 double xMin = histo->GetXaxis()->GetBinLowEdge(1);
973 double yMax = histo->GetYaxis()->GetBinLowEdge(histo->GetNbinsY()+1);
974 double yMin = histo->GetYaxis()->GetBinLowEdge(1);
975 double zMax = histo->GetZaxis()->GetBinLowEdge(histo->GetNbinsZ()+1);
976 double zMin = histo->GetZaxis()->GetBinLowEdge(1);
978 if (
x >= xMax) aux_x = xMax-1
e-6 ;
979 if (
x <= xMin) aux_x = xMin+1
e-6 ;
980 if (std::isnan(
y))
return 0;
981 if (
y >= yMax) aux_y = yMax-1
e-6 ;
982 if (
y <= yMin) aux_y = yMin+1
e-6 ;
983 if (
z >= zMax) aux_z = zMax-1
e-6 ;
984 if (
z <= zMin) aux_z = zMin+1
e-6 ;
996 ATH_MSG_ERROR(
"Histogram pointer is null in FFJetSmearingTool::Interpolate2D");
999 Int_t bin_x = histo->GetXaxis()->FindFixBin(
x);
1000 Int_t bin_y = histo->GetYaxis()->FindFixBin(
y);
1001 if (bin_x<1 || bin_x>histo->GetNbinsX() || bin_y<1 || bin_y>histo->GetNbinsY()){
1007 return interpolated_value;
1014 while ((pos =
str.find(to_find, pos)) != std::string::npos){
1015 str.replace(pos, to_find.length(), to_replace);
1016 pos += to_replace.length();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
static const std::vector< std::string > systematics
static const Attributes_t empty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
This module implements the central registry for handling systematic uncertainties with CP tools.
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
StatusCode registerSystematics(const IReentrantSystematicsTool &tool)
effects: register all the systematics from the tool
Class to wrap a set of SystematicVariations.
std::string name() const
returns: the systematics joined into a single string.
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
const_iterator begin() const
description: const iterator to the beginning of the set
size_t size() const
returns: size of the set
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
void setJetP4(const JetFourMom_t &p4)
virtual double pt() const
The transverse momentum ( ) of the particle.
virtual double m() const
The invariant mass of the particle.
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
Select isolated Photons, Electrons and Muons.
double Interpolate(const TH1 *histo, const double x)
TypeEnum intToEnum(const int type)
TString findFilePath(const TString &fileName, const TString &path="", const TString &calibArea="")
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.