Commit d4ca3ceb authored by Nils Erik Krumnack's avatar Nils Erik Krumnack
Browse files

Merge branch 'FFJetSmearinTool_21p2' into '21.2'

FFJetSmearingTool: Fix for combined mass

See merge request !43422
parents 477c6951 2f88c5d4
......@@ -184,10 +184,12 @@ namespace CP {
CP::SystematicSet m_SysList;
//Maps that relates the systematic name with some of its caracteristics
std::map<std::string,std::string> m_Syst_HistPath_map;
std::map<std::string,std::string> m_Syst_MassDefAffected_map;
std::map<std::string,std::string> m_Syst_TopologyAffected_map;
std::map<std::string,std::string> m_Syst_HistPath_map;
std::map<std::string,std::unique_ptr<TH2D>> m_Syst_Hist_map;
std::map<std::string,std::string> m_Syst_HistTAPath_map;
std::map<std::string,std::unique_ptr<TH2D>> m_Syst_HistTA_map;
std::map<std::string,std::string> m_Syst_Affects_JMSorJMR;
//The current systematic configuration
......
......@@ -185,7 +185,32 @@ CP::SystematicSet FFJetSmearingTool::affectingSystematics() const
//-----------------------------------------------------------------------------
CP::SystematicSet FFJetSmearingTool::recommendedSystematics() const
{
return m_SysList;
CP::SystematicSet filteredSysts;
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Calo){//take only Calo-like syst
for (auto ci = m_SysList.begin(); ci != m_SysList.end(); ci++) {
if ((*ci).basename().find("CALO_")!=std::string::npos)
filteredSysts.insert(*ci);
}
return filteredSysts;
}
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::TA){//take only TA-like syst
for (auto ci = m_SysList.begin(); ci != m_SysList.end(); ci++) {
if ((*ci).basename().find("TA_") !=std::string::npos)
filteredSysts.insert(*ci);
}
return filteredSysts;
}
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Comb){//take only TA-like syst
for (auto ci = m_SysList.begin(); ci != m_SysList.end(); ci++) {
if ((*ci).basename().find("COMB_")!=std::string::npos){
filteredSysts.insert(*ci);
}
}
return filteredSysts;
}
return m_SysList;
}
//-----------------------------------------------------------------------------
......@@ -199,10 +224,8 @@ CP::SystematicCode FFJetSmearingTool::applySystematicVariation
// Look for it in our sysData map.
auto iter = m_sysData.find (systematics);
// If this is a new input set, we need to filter it.
if(iter == m_sysData.end()){
// Filter the input systematics with my affecting systematics.
const CP::SystematicSet affectingSysts = affectingSystematics();
CP::SystematicSet filteredSysts;
......@@ -224,8 +247,6 @@ CP::SystematicCode FFJetSmearingTool::applySystematicVariation
return CP::SystematicCode::Unsupported;
}
// Insert the new systematic data onto our map
SysData myData;
......@@ -259,19 +280,19 @@ StatusCode FFJetSmearingTool::readFFJetSmearingToolSimplifiedData(TEnv& settings
TString CaloResponseMap_path = settings.GetValue("CaloResponseMap","");
if(CaloResponseMap_path.IsNull())
{
ATH_MSG_ERROR("Cannot find the CaloResponseMap in the config file");
return StatusCode::FAILURE;
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Comb || m_MassDef==JetTools::FFJetAllowedMassDefEnum::Calo){
TString CaloResponseMap_path = settings.GetValue("CaloResponseMap","");
if(CaloResponseMap_path.IsNull())
{
ATH_MSG_ERROR("Cannot find the CaloResponseMap in the config file");
return StatusCode::FAILURE;
}
m_CALO_ResponseMap = std::make_unique<TH2D>(*dynamic_cast<TH2D*>(data_file->Get( CaloResponseMap_path )));
m_CALO_ResponseMap->SetDirectory(0);
}
m_CALO_ResponseMap = std::make_unique<TH2D>(*dynamic_cast<TH2D*>(data_file->Get( CaloResponseMap_path )));
m_CALO_ResponseMap->SetDirectory(0);
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Comb || m_MassDef==JetTools::FFJetAllowedMassDefEnum::TA){
TString TAResponseMap_path = settings.GetValue("TAResponseMap","");
......@@ -297,16 +318,20 @@ StatusCode FFJetSmearingTool::readFFJetSmearingToolSimplifiedData(TEnv& settings
if( !Syst_Name.empty()){
m_SysList.insert( CP::SystematicVariation(Syst_Name, 1) );
m_SysList.insert( CP::SystematicVariation(Syst_Name, -1) );
m_Syst_HistPath_map[Syst_Name] = settings.GetValue(prefix+"Hist","");
m_Syst_MassDefAffected_map[Syst_Name] = settings.GetValue(prefix+"MassDef","");
m_Syst_TopologyAffected_map[Syst_Name] = settings.GetValue(prefix+"Topology","");
m_Syst_Affects_JMSorJMR[Syst_Name] = "JMS";
m_Syst_HistPath_map[Syst_Name] = settings.GetValue(prefix+"Hist","");
m_Syst_Hist_map[Syst_Name] = std::make_unique<TH2D>(*dynamic_cast<TH2D*>(data_file->Get(m_Syst_HistPath_map[Syst_Name].c_str())));
m_Syst_Hist_map[Syst_Name]->SetDirectory(0);
}
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Comb){//for comb mass we need to read two histograms
m_Syst_HistTAPath_map[Syst_Name] = settings.GetValue(prefix+"HistTA","");
if(m_Syst_HistTAPath_map[Syst_Name]!=""){
m_Syst_HistTA_map[Syst_Name] = std::make_unique<TH2D>(*dynamic_cast<TH2D*>(data_file->Get(m_Syst_HistTAPath_map[Syst_Name].c_str())));
m_Syst_HistTA_map[Syst_Name]->SetDirectory(0);
}
}
}
}
//JMR Systematics
for (size_t iComp = 0; iComp < 999; ++iComp)
......@@ -315,20 +340,23 @@ StatusCode FFJetSmearingTool::readFFJetSmearingToolSimplifiedData(TEnv& settings
std::string Syst_Name = settings.GetValue(prefix+"Name","");
if( !Syst_Name.empty()){
m_SysList.insert( CP::SystematicVariation(Syst_Name, 1) );
m_SysList.insert( CP::SystematicVariation(Syst_Name, -1) );
m_Syst_HistPath_map[Syst_Name] = settings.GetValue(prefix+"Hist","");
m_Syst_MassDefAffected_map[Syst_Name] = settings.GetValue(prefix+"MassDef","");
m_Syst_TopologyAffected_map[Syst_Name] = settings.GetValue(prefix+"Topology","");
m_Syst_Affects_JMSorJMR[Syst_Name] = "JMR";
m_Syst_HistPath_map[Syst_Name] = settings.GetValue(prefix+"Hist","");
m_Syst_Hist_map[Syst_Name] = std::make_unique<TH2D>(*dynamic_cast<TH2D*>(data_file->Get(m_Syst_HistPath_map[Syst_Name].c_str())));
m_Syst_Hist_map[Syst_Name]->SetDirectory(0);
}
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Comb){//for comb mass we need to read two histograms
m_Syst_HistTAPath_map[Syst_Name] = settings.GetValue(prefix+"HistTA","");
if(m_Syst_HistTAPath_map[Syst_Name]!=""){
m_Syst_HistTA_map[Syst_Name] = std::make_unique<TH2D>(*dynamic_cast<TH2D*>(data_file->Get(m_Syst_HistTAPath_map[Syst_Name].c_str())));
m_Syst_HistTA_map[Syst_Name]->SetDirectory(0);
}
}
}
}
data_file->Close();
......@@ -476,20 +504,17 @@ LargeRJetTruthLabel::TypeEnum jetTruthLabel = LargeRJetTruthLabel::intToEnum(acc
//-----------------------------------------------------------------------------
// The function "getJMSJMR" read the JMS and JMR uncertainties associated with the systematic
//-----------------------------------------------------------------------------
StatusCode FFJetSmearingTool::getJMSJMR( xAOD::Jet& jet_reco, double jet_mass_value, JetTools::FFJetAllowedMassDefEnum MassDef_of_syst, std::string jetTopology, double& JMS_err, double& JMR_err) const{
//JMS/JMR systematic variations
JMS_err=0;
JMR_err=0;
if(m_Syst_MassDefAffected_map.at(m_currentSysData->SysBaseName) == JetTools::enumToString(MassDef_of_syst)){
ATH_MSG_VERBOSE("This uncertainty affects to the " << JetTools::enumToString(MassDef_of_syst) << " mass");
if(m_Syst_MassDefAffected_map.at(m_currentSysData->SysBaseName) == JetTools::enumToString(MassDef_of_syst) || m_Syst_MassDefAffected_map.at(m_currentSysData->SysBaseName) == JetTools::enumToString(JetTools::FFJetAllowedMassDefEnum::Comb) ){
ATH_MSG_VERBOSE("This uncertainty affects to the " << JetTools::enumToString(MassDef_of_syst) << " mass");
} //Only apply the systematic to the proper mass definition
else{return StatusCode::SUCCESS;}
if(m_Syst_TopologyAffected_map.at(m_currentSysData->SysBaseName) != "All" && m_Syst_TopologyAffected_map.at(m_currentSysData->SysBaseName) != jetTopology){
ATH_MSG_VERBOSE("The systematic do not affects to this jet topology");
return StatusCode::SUCCESS;
......@@ -499,24 +524,27 @@ StatusCode FFJetSmearingTool::getJMSJMR( xAOD::Jet& jet_reco, double jet_mass_va
float jet_mass = jet_mass_value*m_MeVtoGeV;//jet_reco->m()*m_MeVtoGeV; The TA mass can not be extracted this way
float jet_pT = jet_reco.pt()*m_MeVtoGeV;
if(m_Syst_Affects_JMSorJMR.at(m_currentSysData->SysBaseName) == "JMS"){
JMS_err=m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetBinContent(m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetXaxis()->FindBin(jet_pT),m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetYaxis()->FindBin(jet_mass)) * m_currentSysData->SysParameter;
JMR_err= 0;
JMS_err=m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetBinContent(m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetXaxis()->FindBin(jet_pT),m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetYaxis()->FindBin(jet_mass)) * m_currentSysData->SysParameter;
JMR_err= 0;
}
if(m_Syst_Affects_JMSorJMR.at(m_currentSysData->SysBaseName) == "JMR"){
JMS_err=0;
JMR_err= m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetBinContent(m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetXaxis()->FindBin(jet_pT),m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetYaxis()->FindBin(jet_mass)) * m_currentSysData->SysParameter;
}
if(m_Syst_Affects_JMSorJMR.at(m_currentSysData->SysBaseName) == "JMR"){
JMS_err=0;
if(m_Syst_MassDefAffected_map.at(m_currentSysData->SysBaseName)== JetTools::enumToString(JetTools::FFJetAllowedMassDefEnum::Calo) || m_Syst_MassDefAffected_map.at(m_currentSysData->SysBaseName)== JetTools::enumToString(JetTools::FFJetAllowedMassDefEnum::TA) ){//TA and Calo mass defs take values from one hisogram only
JMR_err= m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetBinContent(m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetXaxis()->FindBin(jet_pT),m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetYaxis()->FindBin(jet_mass)) * m_currentSysData->SysParameter;
}
if(m_Syst_MassDefAffected_map.at(m_currentSysData->SysBaseName)==JetTools::enumToString(JetTools::FFJetAllowedMassDefEnum::Comb) ){//Comb mass defs can take values from two histograms, depending ifits Calo- or TA- part is affected
if(MassDef_of_syst==JetTools::FFJetAllowedMassDefEnum::Calo)
JMR_err= m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetBinContent(m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetXaxis()->FindBin(jet_pT),m_Syst_Hist_map.at(m_currentSysData->SysBaseName)->GetYaxis()->FindBin(jet_mass)) * m_currentSysData->SysParameter;
if(MassDef_of_syst==JetTools::FFJetAllowedMassDefEnum::TA)
JMR_err= m_Syst_HistTA_map.at(m_currentSysData->SysBaseName)->GetBinContent(m_Syst_HistTA_map.at(m_currentSysData->SysBaseName)->GetXaxis()->FindBin(jet_pT),m_Syst_HistTA_map.at(m_currentSysData->SysBaseName)->GetYaxis()->FindBin(jet_mass)) * m_currentSysData->SysParameter;
}
}
ATH_MSG_DEBUG("Systematic applied: " << m_currentSysData->SysBaseName);
ATH_MSG_VERBOSE("JMS_err: " << JMS_err);
......@@ -596,7 +624,6 @@ CP::CorrectionCode FFJetSmearingTool::applyCorrection( xAOD::Jet& jet_reco) cons
jet_mass_CALO = jet_reco_CALO.mass();
jet_mass_TA = jet_reco_TA.mass();
jet_reco.getAttribute<float>("JetTrackAssistedMassCalibrated", JetTrackAssistedMassCalibrated_from_JetCalibTools);
}
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Calo){
......@@ -605,6 +632,7 @@ CP::CorrectionCode FFJetSmearingTool::applyCorrection( xAOD::Jet& jet_reco) cons
}
else if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::TA){
jet_mass_TA = jet_reco.m();
jet_reco.getAttribute<float>("JetTrackAssistedMassCalibrated", JetTrackAssistedMassCalibrated_from_JetCalibTools);
calo_mass_weight = 0;
}
......@@ -654,7 +682,7 @@ CP::CorrectionCode FFJetSmearingTool::applyCorrection( xAOD::Jet& jet_reco) cons
if(!(getJMSJMR( jet_reco, jet_mass_CALO, JetTools::FFJetAllowedMassDefEnum::Calo,jetTopology, JMS_err, JMR_err)).isSuccess()){
return CP::CorrectionCode::Ok;
}
}
scale = JMS + JMS_err;
resolution = JMR + JMR_err;
......@@ -700,7 +728,6 @@ CP::CorrectionCode FFJetSmearingTool::applyCorrection( xAOD::Jet& jet_reco) cons
//Recalculate the weights after the smearing
if(m_MassDef==JetTools::FFJetAllowedMassDefEnum::Comb && JetTrackAssistedMassCalibrated_from_JetCalibTools != 0 && jet_mass_CALO != 0){
//we check that JetTrackAssistedMassCalibrated_from_JetCalibTools != 0 instead of jet_mass_TA != 0 becuase
//there is a problem in the conversion between the mass itself and the four-vector representation (due to a
......@@ -730,7 +757,7 @@ CP::CorrectionCode FFJetSmearingTool::applyCorrection( xAOD::Jet& jet_reco) cons
TARes=FFJetSmearingTool::Read3DHistogram(m_TAMassWeight.get() ,jet_reco_TA.e()*m_MeVtoGeV,TMath::Log(jet_reco_TA.M()/jet_reco_TA.e()),std::abs(jet_reco_TA.eta()));
//The histograms with the weights that we are reading was deffined with the code "e_LOGmOe_eta" what means that each axis correspond to:
//The histograms with the weights that we are reading were defined with the code "e_LOGmOe_eta" which means that each axis correspond to:
//-X: Jet Energy
//-Y: Log(Jet_Energy/Jet_mass)
//-Z:Eta
......@@ -747,13 +774,12 @@ CP::CorrectionCode FFJetSmearingTool::applyCorrection( xAOD::Jet& jet_reco) cons
TAFactor = 1./(TARes*TARes);
}
calo_mass_weight = caloFactor /(caloFactor + TAFactor);
ATH_MSG_VERBOSE(" Map Calo weight = " << calo_mass_weight );
ATH_MSG_VERBOSE(" Map TA weight = " << 1 - calo_mass_weight );
}
else if( JetTrackAssistedMassCalibrated_from_JetCalibTools == 0){calo_mass_weight = 1;}
else if(JetTrackAssistedMassCalibrated_from_JetCalibTools == 0){calo_mass_weight = 1;}
else if(jet_mass_CALO == 0){calo_mass_weight = 0;}
double smeared_mass = calo_mass_weight*smeared_CALO_mass + (1 - calo_mass_weight)*smeared_TA_mass;
......@@ -763,15 +789,11 @@ CP::CorrectionCode FFJetSmearingTool::applyCorrection( xAOD::Jet& jet_reco) cons
xAOD::JetFourMom_t p4 = jet_reco.jetP4();
p4 = xAOD::JetFourMom_t(jet_reco.pt(),jet_reco.eta(),jet_reco.phi(),smeared_mass);
jet_reco.setJetP4(p4);
ATH_MSG_VERBOSE("Smeared Reco Jet: pt = " << jet_reco.pt() << ", mass = " << jet_reco.m() << ", eta = " << jet_reco.eta());
ATH_MSG_VERBOSE("Smeared Reco Jet: pt = " << jet_reco.pt() << ", mass = " << jet_reco.m() << ", eta = " << jet_reco.eta());
ATH_MSG_VERBOSE("//---------------------------------------------------------------//");
......
......@@ -99,6 +99,7 @@ int main(int argc, char* argv[]){
std::string output = "";
std::string string_configfile_path = "";
std::string string_debugtool = "";
int eventsMax=10000000;
//---------------------------
// Decoding the user settings
//---------------------------
......@@ -127,6 +128,7 @@ int main(int argc, char* argv[]){
if ( opt.find("--ConfigFile=") != std::string::npos ) string_configfile_path = v[1];
if ( opt.find("--DebugTool=") != std::string::npos ) string_debugtool = v[1];
if ( opt.find("--output=") != std::string::npos ) output = v[1];
if ( opt.find("--eventsMax=") != std::string::npos ) eventsMax = std::atoi(v[1].data());
}//End: Loop over input options
......@@ -230,6 +232,7 @@ config.makeTool (ffjetsmearingtool, cleanup);
// Print the recommended systematics
const CP::SystematicSet& recommendedSysts = ffjetsmearingtool.recommendedSystematics();//take the systematics of the FFJETSmearing Tool
printf("Recommended systematics: \n");
for(auto sysItr = recommendedSysts.begin();
sysItr != recommendedSysts.end(); ++sysItr){
......@@ -353,13 +356,13 @@ config.makeTool (ffjetsmearingtool, cleanup);
// Get the number of events
const Long64_t nevents = event.getEntries();
// Decide how many events to run over
//if(nevents>10000){nevents = 10000; }
for(Long64_t ievent = 0; ievent < nevents; ++ievent){
for(Long64_t ievent = 0; ievent < nevents && ievent < eventsMax; ++ievent){
// Load the event:
if( event.getEntry( ievent ) < 0 ) {
......@@ -480,7 +483,6 @@ config.makeTool (ffjetsmearingtool, cleanup);
if(lead_jet == true){reco_jet_mass_hist->Fill(jet_reco->m()*MeVtoGeV); matched_truth_jet_mass_hist->Fill(jet_truth_matched.m()*MeVtoGeV); }
if(kindofmass=="TA"){
Double_t aux_original_jet_mass = jet_reco->m()*MeVtoGeV;
ffjetsmearingtool.applyCorrection(*jet_reco_TA);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment