Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 138 additions & 29 deletions configs/examples/scale_factors_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,53 @@

from Logger import error

jec_mc_types = {
"2016preVFP": "Summer19UL16APV_V7_MC",
"2016postVFP": "Summer19UL16_V7_MC",
"2017": "Summer19UL17_V5_MC",
"2018": "Summer19UL18_V5_MC",
"2022preEE": "Summer22_22Sep2023_V2_MC",
"2022postEE": "Summer22EE_22Sep2023_V2_MC",
"2023preBPix": "Summer23Prompt23_V2_MC",
"2023postBPix": "Summer23BPixPrompt23_V3_MC",
}

def get_scale_factors(year):
jec_data_types = {
"2016preVFP": "Summer19UL16APV_RunBCD_V7_DATA",
"2016postVFP": "Summer19UL16_RunFGH_V7_DATA",
"2017": "Summer19UL17_RunB_V5_DATA",
"2018": "Summer19UL18_RunA_V5_DATA",
"2022preEE": "Summer22_22Sep2023_RunCD_V2_DATA",
"2022postEE": "Summer22EE_22Sep2023_RunE_V2_DATA",
"2023preBPix": "Summer23Prompt23_V2_DATA",
"2023postBPix": "Summer23BPixPrompt23_V3_DATA",
}

jer_types = {
"2016preVFP": "Summer20UL16APV_JRV3_MC",
"2016postVFP": "Summer20UL16_JRV3_MC",
"2017": "Summer19UL17_JRV2_MC",
"2018": "Summer19UL18_JRV2_MC",
"2022preEE": "Summer22_22Sep2023_JRV1_MC",
"2022postEE": "Summer22EE_22Sep2023_JRV1_MC",
"2023preBPix": "Summer23Prompt23_RunCv123_JRV1_MC",
"2023postBPix": "Summer23BPixPrompt23_RunD_JRV1_MC",
}

def get_scale_factors(year, isData=False):
run2 = True
if year == "2016preVFP" or year == "2016postVFP":
pu_type = "Collisions16_UltraLegacy_goldenJSON"
muon_trigger_type = "NUM_IsoMu24_or_IsoTkMu24_DEN_CutBasedIdTight_and_PFIsoTight"
jecType = "Summer19UL16_V7_MC"
jerType = "Summer20UL16APV_JRV3_MC"
jecAlgo = "AK4PFchs"
jecYear = "2016"
dsaYear = "2016"
if year == "2016preVFP":
jecType = "Summer19UL16APV_V7_MC"
jerType = "Summer20UL16_JRV3_MC"
elif year == "2017":
pu_type = "Collisions17_UltraLegacy_goldenJSON"
jecType = "Summer19UL17_V5_MC"
jerType = "Summer19UL17_JRV2_MC"
jecAlgo = "AK4PFchs"
jecYear = "2017"
dsaYear = "2017"
muon_trigger_type = "NUM_IsoMu27_DEN_CutBasedIdTight_and_PFIsoTight"
elif year == "2018":
pu_type = "Collisions18_UltraLegacy_goldenJSON"
jecType = "Summer19UL18_V5_MC"
jerType = "Summer19UL18_JRV2_MC"
jecAlgo = "AK4PFchs"
jecYear = "2018"
dsaYear = "2018"
muon_trigger_type = "NUM_IsoMu24_DEN_CutBasedIdTight_and_PFIsoTight"
Expand All @@ -71,16 +91,10 @@ def get_scale_factors(year):
if year == "2022preEE":
year_path = "2022_Summer22"
pu_type = "Collisions2022_355100_357900_eraBCD_GoldenJson"
jecType = "Summer22_22Sep2023_V2_MC"
jerType = "Summer22_22Sep2023_JRV1_MC"
jecAlgo = "AK4PFPuppi"
jecYear = "2022"
if year == "2022postEE":
year_path = "2022_Summer22EE"
pu_type = "Collisions2022_359022_362760_eraEFG_GoldenJson"
jecType = "Summer22EE_22Sep2023_V2_MC"
jerType = "Summer22EE_22Sep2023_JRV1_MC"
jecAlgo = "AK4PFPuppi"
jecYear = "2022EE"
elif year == "2023preBPix" or year == "2023postBPix":
run2 = False
Expand All @@ -89,27 +103,29 @@ def get_scale_factors(year):
if year == "2023preBPix":
year_path = "2023_Summer23"
pu_type = "Collisions2023_366403_369802_eraBC_GoldenJson"
jecType = "Summer23Prompt23_V2_MC"
jerType = "Summer23Prompt23_RunCv1234_JRV1_MC"
jecAlgo = "AK4PFPuppi"
jecYear = "2023"
if year == "2023postBPix":
year_path = "2023_Summer23BPix"
pu_type = "Collisions2023_369803_370790_eraD_GoldenJson"
jecType = "Summer23BPixPrompt23_V3_MC"
jerType = "Summer23BPixPrompt23_RunD_JRV1_MC"
jecAlgo = "AK4PFPuppi"
jecYear = "2023BPix"
else:
error(f"Year {year} not supported.")

jecTypeMC = jec_mc_types[year]
jecTypeData = jec_data_types[year]
jerType = jer_types[year]

if run2:
year_path = f"{year}_UL"
loose_muon_iso_type = "NUM_LooseRelIso_DEN_LooseID"
tight_muon_iso_type = "NUM_TightRelIso_DEN_TightIDandIPCut"
qjet_type = "deepJet_incl"
jecAlgo = "AK4PFchs"
else:
loose_muon_iso_type = "NUM_LoosePFIso_DEN_LooseID"
tight_muon_iso_type = "NUM_TightPFIso_DEN_TightID"
qjet_type = "deepJet_light"
jecAlgo = "AK4PFPuppi"

scaleFactors = {

Expand All @@ -131,25 +147,60 @@ def get_scale_factors(year):
"workingPoint": "T",
"flavour": "5", # 5 = b
},
"bTaggingEfficiency": {
"path": f"../tea/data/b_tagging/jet_efficiency_maps/{year}_jetTagging_efficiency.json.gz",
"type": "efficiency_B",
"flavour": "5",
},
"cTaggingEfficiency": {
"path": f"../tea/data/b_tagging/jet_efficiency_maps/{year}_jetTagging_efficiency.json.gz",
"type": "efficiency_C",
"flavour": "4",
},
"qTaggingEfficiency": {
"path": f"../tea/data/b_tagging/jet_efficiency_maps/{year}_jetTagging_efficiency.json.gz",
"type": "efficiency_Q",
"flavour": "0",
},

"bTaggingMedium_cjet": {
"path": f"../tea/jsonPOG/POG/BTV/{year_path}/btagging.json.gz",
"type": "deepJet_comb",
"systematic": "central",
"variations": "up_correlated,down_correlated,up_uncorrelated,down_uncorrelated",
"workingPoint": "M",
"flavour": "4", # 4 = c
},
"bTaggingMedium_qjet": {
"path": f"../tea/jsonPOG/POG/BTV/{year_path}/btagging.json.gz",
"type": qjet_type,
"systematic": "central",
"variations": "up_correlated,down_correlated,up_uncorrelated,down_uncorrelated",
"workingPoint": "M",
"flavour": "0", # 0 = udsg
},

# Muon ID
"muonIDLoose": {
"path": f"../tea/jsonPOG/POG/MUO/{year_path}/muon_Z.json.gz",
"type": "NUM_LooseID_DEN_TrackerMuons",
"systematic": "nominal",
"variations": "systup,systdown",
"statistical": "stat",
},
"muonIDMedium": {
"path": f"../tea/jsonPOG/POG/MUO/{year_path}/muon_Z.json.gz",
"type": "NUM_MediumID_DEN_TrackerMuons",
"systematic": "nominal",
"variations": "systup,systdown",
"statistical": "stat",
},
"muonIDTight": {
"path": f"../tea/jsonPOG/POG/MUO/{year_path}/muon_Z.json.gz",
"type": "NUM_TightID_DEN_TrackerMuons",
"systematic": "nominal",
"variations": "systup,systdown",
"statistical": "stat",
},

# Muon Iso
Expand All @@ -158,12 +209,14 @@ def get_scale_factors(year):
"type": loose_muon_iso_type,
"systematic": "nominal",
"variations": "systup,systdown",
"statistical": "stat",
},
"muonIsoTight": {
"path": f"../tea/jsonPOG/POG/MUO/{year_path}/muon_Z.json.gz",
"type": tight_muon_iso_type,
"systematic": "nominal",
"variations": "systup,systdown",
"statistical": "stat",
},

# Pileup
Expand All @@ -175,19 +228,19 @@ def get_scale_factors(year):
},

"dimuonEff_Pat": {
"path": f"../tea/data/dimuonEffSFs/dimuonEffSFs{year}_Pat_pt_irr2_v3.json",
"path": f"../tea/data/dimuonEffSFs/dimuonEffSFs{year}_Pat_pt_irr_v3.json",
"type": "dimuonEff_Pat",
"systematic": "nominal",
"variations": "up,down",
},
"dimuonEff_PatDSA": {
"path": f"../tea/data/dimuonEffSFs/dimuonEffSFs{year}_PatDSA_pt_irr2_v3.json",
"path": f"../tea/data/dimuonEffSFs/dimuonEffSFs{year}_PatDSA_pt_irr_v3.json",
"type": "dimuonEff_PatDSA",
"systematic": "nominal",
"variations": "up,down",
},
"dimuonEff_DSA": {
"path": f"../tea/data/dimuonEffSFs/dimuonEffSFs{year}_DSA_pt_irr2_v3.json",
"path": f"../tea/data/dimuonEffSFs/dimuonEffSFs{year}_DSA_pt_irr_v3.json",
"type": "dimuonEff_DSA",
"systematic": "nominal",
"variations": "up,down",
Expand All @@ -199,6 +252,7 @@ def get_scale_factors(year):
"type": muon_trigger_type,
"systematic": "nominal",
"variations": "systup,systdown",
"statistical": "stat",
},

# DSA Muon SFs
Expand Down Expand Up @@ -248,22 +302,76 @@ def get_scale_factors(year):
# Jet Energy Correction uncertainties
"jecMC": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecType}",
"type": f"{jecTypeMC}",
"level": "L1L2L3Res",
"algo": f"{jecAlgo}",
"uncertainties": f"Regrouped_Absolute,Regrouped_Absolute_{jecYear},Regrouped_FlavorQCD,Regrouped_BBEC1,Regrouped_BBEC1_{jecYear},Regrouped_EC2,Regrouped_EC2_{jecYear},Regrouped_HF,Regrouped_HF_{jecYear},Regrouped_RelativeBal,Regrouped_RelativeSample_{jecYear}",
},

"jecL1L2L3MC": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeMC}",
"level": "L1L2L3Res",
"algo": f"{jecAlgo}",
},
"jecL1L2L3Data": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeData}",
"level": "L1L2L3Res",
"algo": f"{jecAlgo}",
},

"jecL1MC": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeMC}",
"level": "L1FastJet",
"algo": f"{jecAlgo}",
},
"jecL1Data": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeData}",
"level": "L1FastJet",
"algo": f"{jecAlgo}",
},

"jecL2MC": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeMC}",
"level": "L2Relative",
"algo": f"{jecAlgo}",
},
"jecL2Data": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeData}",
"level": "L2Relative",
"algo": f"{jecAlgo}",
},

"jecL2L3MC": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeMC}",
"level": "L2L3Residual",
"algo": f"{jecAlgo}",
},
"jecL2L3Data": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jecTypeData}",
"level": "L2L3Residual",
"algo": f"{jecAlgo}",
},

# Jet Energy Resolution variables
"jerMC_ScaleFactor": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jerType}_ScaleFactor_{jecAlgo}",
"systematic": "nom",
"variations": "up,down",
"year": year_path,
},
"jerMC_PtResolution": {
"path": f"../tea/jsonPOG/POG/JME/{year_path}/jet_jerc.json.gz",
"type": f"{jerType}_PtResolution_{jecAlgo}",
"year": year_path,
},
"jerMC_smear": {
"path": f"../tea/jsonPOG/POG/JME/jer_smear.json.gz",
Expand All @@ -286,5 +394,6 @@ def get_scale_factors(year):
"type": "NUM_TrackerMuons_DEN_genTracks",
"systematic": "nominal",
"variations": "systup,systdown",
"statistical": "stat",
}
return scaleFactors
2 changes: 1 addition & 1 deletion libs/core/include/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ConfigManager {
template <typename T, typename U>
void GetPair(std::string name, std::pair<T, U>& outputPair);

void GetExtraEventCollections(insertion_ordered_map<std::string, ExtraCollection>& extraEventCollections);
void GetExtraEventCollections(insertion_ordered_map<std::string, ExtraCollection>& extraEventCollections, std::string extraEventCollectionsName = "extraEventCollections");
void GetHistogramsParams(std::map<std::string, HistogramParams>& histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, HistogramParams2D>& histogramsParams, std::string collectionName);
void GetHistogramsParams(std::map<std::string, IrregularHistogramParams>& histogramsParams, std::string collectionName);
Expand Down
9 changes: 9 additions & 0 deletions libs/core/include/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ class Event {
customValuesTypes[branchName] = "Float_t";
}

std::string GetMetBranchName() { return metBranchName; }
std::string GetUpdatedMetBranchName();
void UpdateMetVariables(std::string newBranchName, float pt, float phi);
float GetMetPt();
float GetMetPhi();

private:
ConfigManager& config = ConfigManager::GetInstance();

Expand Down Expand Up @@ -212,6 +218,9 @@ class Event {
std::map<std::string, std::string> defaultCollectionsTypes;
std::map<std::string, std::pair<unsigned, unsigned>> runRangesPerEra;

std::string metBranchName;
std::string metUpdatedBranchName;

friend class EventReader;
template <typename T>
friend class Multitype;
Expand Down
4 changes: 4 additions & 0 deletions libs/core/include/PhysicsObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class PhysicsObject {
return Multitype(this, branchName);
}

inline bool HasBranch(std::string branchName) {
return valuesTypes.count(branchName) > 0 || customValuesTypes.count(branchName) > 0;
}

inline TLorentzVector GetFourVector() {
TLorentzVector vec;
vec.SetPtEtaPhiM(GetAs<float>("pt"), GetAs<float>("eta"), GetAs<float>("phi"), GetAs<float>("mass"));
Expand Down
7 changes: 5 additions & 2 deletions libs/core/include/ScaleFactorsManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using CorrectionArgType = correction::Variable::Type;
struct DummyCorrectionRef {};
using CorrectionRef = DummyCorrectionRef;
using CompoundCorrectionRef = DummyCorrectionRef;
using CorrectionArgType = std::variant<long, double, std::string>;
using CorrectionArgType = std::variant<int, double, std::string>;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change this to fix the compile errors - because the default from correctionlib is int so I needed to match it

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is the long-standing annoying issue... We tried several things to fix it. I think the true solution is: can you please update your correctionlib to the latest version?

#endif

struct MuonID;
Expand All @@ -39,6 +39,8 @@ class ScaleFactorsManager {
std::map<std::string, float> GetDSAMuonScaleFactors(std::string name, const std::vector<CorrectionArgType>& args);
std::map<std::string, float> GetMuonTriggerScaleFactors(std::string name, float eta, float pt);
std::map<std::string, float> GetBTagScaleFactors(std::string name, float eta, float pt);
float GetJetTagEfficiency(std::string name, std::string datasetName, float pt);


std::map<std::string, float> GetPileupScaleFactorCustom(int nVertices);
std::map<std::string, float> GetPileupScaleFactor(std::string name, float nVertices);
Expand All @@ -55,7 +57,8 @@ class ScaleFactorsManager {

void ReadJetEnergyCorrections();
bool ShouldApplyJetEnergyCorrections() { return ShouldApplyScaleFactor("jec") || ShouldApplyVariation("jec"); }
std::map<std::string, float> GetJetEnergyCorrections(std::map<std::string, float> inputArguments);
std::map<std::string, float> GetJetEnergyCorrectionUncertainties(std::map<std::string, float> inputArguments);
std::map<std::string, float> GetJetEnergyCorrections(std::vector<std::string> jecNames, std::map<std::string, float> inputArguments);
std::map<std::string, float> GetJetEnergyResolutionScaleFactorAndPtResolution(float jetEta, float jetPt, float rho);
float GetJetEnergyResolutionSmearingFactor(std::map<std::string, CorrectionArgType> inputArguments);

Expand Down
4 changes: 2 additions & 2 deletions libs/core/src/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ void ConfigManager::GetPair<string, vector<string>>(string name, pair<string, ve
// Other methods
//-------------------------------------------------------------------------------------------------

void ConfigManager::GetExtraEventCollections(insertion_ordered_map<string, ExtraCollection>& extraEventCollections) {
PyObject* pythonDict = GetPythonDict("extraEventCollections");
void ConfigManager::GetExtraEventCollections(insertion_ordered_map<string, ExtraCollection> &extraEventCollections, string extraEventCollectionsName) {
PyObject *pythonDict = GetPythonDict(extraEventCollectionsName);

PyObject *collectionName, *collectionSettings;
Py_ssize_t pos = 0;
Expand Down
Loading
Loading