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
181 changes: 181 additions & 0 deletions Plotter.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
enum PlotVariable{
ETA,
PU_EB,
PU_EE,
ET_EB,
ET_EE,
ET_ETA
};
enum PlotObject{
ELE,
PHO,
SC,
ELE_500To1000,
ELE_1000To1500,
ELE_1500To3000,
PHO_1000To1500,
PHO_1500To3000,
PHO_3000To4000,
QCD_30To50,
QCD_300ToInf,
ELE_ALL_ENERGY,
PHO_ALL_ENERGY
};
void plot(bool dcbFit,PlotVariable plotVar,PlotObject plotObj);

void Plotter()
{
gSystem->Exec("gmake RegressionTrainerExe -j 8");
gSystem->Exec("gmake RegressionApplierExe -j 8");

gROOT->ProcessLine("gROOT->SetBatch(true)");
gROOT->ProcessLine(".x rootScripts/setupResPlotter.c");
gROOT->ProcessLine("ResPlotter res");

// list of physics objects to plot
vector<PlotObject> plotObj = {
ELE,
// PHO,
// SC,
// ELE_500To1000,
// ELE_1000To1500,
// ELE_1500To3000,
// PHO_1000To1500,
// PHO_1500To3000,
// PHO_3000To4000,
// QCD_30To50,
// QCD_300ToInf,
// ELE_ALL_ENERGY,
// PHO_ALL_ENERGY
};
int nObjects = plotObj.size();

// list of variables to plot
vector<PlotVariable> plotVar = {
ETA,
// PU_EB,
// PU_EE,
// ET_EB,
// ET_EE,
// ET_ETA
};
int nVariables = plotVar.size();

for(int i=0;i<nObjects;i++){
for(int j=0;j<nVariables;j++){
plot(false,plotVar.at(j),plotObj.at(i));
plot(true,plotVar.at(j),plotObj.at(i));
}
}
}

void plot(bool dcbFit,PlotVariable plotVar,PlotObject plotObj)
{
TString var1,var2,binning1,binning2,saveTag;
TString fitType;

if(dcbFit){
gROOT->ProcessLine("res.setFitType(ResFitter::FitType::DCB)");
fitType = "DCB";
}
else{
gROOT->ProcessLine("res.setFitType(ResFitter::FitType::Cruijff)");
fitType = "CRUIJF";
}

TString baseCuts = "mc.energy>0 && ssFrac.sigmaIEtaIEta>0 && ssFrac.sigmaIPhiIPhi>0";
TString treeName1;
TString treeName2 = "nullptr";
TString puBinning,etBinning,etaBinning,oneBinRange,saveLoc,fitsArg;

//ch looks like it is up to 3.0) Object settings
if(plotObj == ELE){
treeName1 = "treeEle";
baseCuts += " && evt.eventnr%5>2 && ele.et>0";
etBinning = "etBins";
oneBinRange = "ptOneBin";
saveLoc = "electrons";
fitsArg = "0,1";
etaBinning = "etaBins";
puBinning = "puBins";
}
else if(plotObj == PHO){
treeName1 = "treePho";
treeName2 = "treePho2018";
baseCuts += " && evt.eventnr%5>1 && pho.et>0";
etBinning = "etBinsLow3";
oneBinRange = "ptOneBinLow";
saveLoc = "photons";
fitsArg = "3,4";
etaBinning = "etaBinsFine3";
puBinning = "puBins";
}
else if(plotObj == SC){
treeName1 = "treeSCStep3";
treeName2 = "treeRun2Step3";
baseCuts += " && evt.eventnr%5>1 && sc.et>0";
etBinning = "etBinsLow3";
oneBinRange = "ptOneBinLow";
saveLoc = "/SC_update";
fitsArg = "3,4";
etaBinning = "etaBinsFine3";
puBinning = "puBins";
}
// Variable settings
if(plotVar==ETA){
var1 = "mc.pt";
binning1 = etBinning;
var2 = "abs(sc.seedEta)";
binning2 = etaBinning;
saveTag = "Eta";
}
else if(plotVar==PU_EB){
var1 = "mc.pt";
binning1 = etBinning;
var2 = "nrVert";
binning2 = puBinning;
saveTag = "PU_EB";
baseCuts += " && abs(sc.seedEta)<1.442";
}
else if(plotVar==PU_EE){
var1 = "mc.pt";
binning1 = etBinning;
var2 = "nrVert";
binning2 = puBinning;
saveTag = "PU_EE";
baseCuts += " && abs(sc.seedEta)>1.566";
}
else if(plotVar==ET_EB){
var1 = "mc.pt";
binning1 = oneBinRange;
var2 = "mc.pt";
binning2 = etBinning;
saveTag = "ET_EB";
baseCuts += " && abs(sc.seedEta)<1.442";
}
else if(plotVar==ET_EE){
var1 = "mc.pt";
binning1 = oneBinRange;
var2 = "mc.pt";
binning2 = etBinning;
saveTag = "ET_EE";
baseCuts += " && abs(sc.seedEta)>1.566";
}
else if(plotVar==ET_ETA){
var1 = "sc.seedEta";
binning1 = etaBinning;
var2 = "mc.pt";
binning2 = etBinning;
saveTag = "EtEta";
}
else{
cout << "PLOTTING ERROR: plotVar not correctly chosen" << endl;
return;
}

TString printFits = "res.printFits({"+fitsArg+"},\"plots/"+saveLoc+"/"+fitType+"_"+saveTag+"_\")";
TString makeHists = "res.makeHists({"+treeName1+","+treeName2+"},\"\",\""+baseCuts+"\",\""+var1+"\",\""+var2+"\","+binning1+","+binning2+")";
gROOT->ProcessLine(makeHists);
gROOT->ProcessLine(printFits);

}
13 changes: 1 addition & 12 deletions packages/ResAnalysis/src/ResPlotter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,11 @@ void ResPlotter::Config::setDefaults()

std::vector<std::pair<std::string,std::string> > varsTree1 = {
{"sc.rawEnergy/mc.energy","raw energy"},
{"sc.corrEnergy/mc.energy","74X correction"},
{"sc.corrEnergyAlt/mc.energy","2018 UL correction"},
{"eleAltEnergy1.ecal/mc.energy","80X ecal"},
{"eleAltEnergy1.ecalTrk/mc.energy","80X ecal-trk"},
{"phoAltEnergy1.ecal/mc.energy","80X pho"},
{"ele.ecalEnergy/mc.energy","2018UL ecal"},
{"ele.energy/mc.energy","2018UL ecal-trk"},
{"pho.energy/mc.energy","2018UL pho"}
{"mean*invTar","2016UL corrected energy"},
};

std::vector<std::pair<std::string,std::string> > varsTree2 = {
{"sc.rawEnergy/mc.energy","raw energy, 102X"},
{"sc.corrEnergy/mc.energy","74X corr, 102X"},
{"ele.ecalEnergy/mc.energy","80X ecal, 102X"},
{"ele.energy/mc.energy","80X ecal-trk, 102X"},
{"pho.energy/mc.energy","80X pho, 102X"}
};
vars.clear();
vars.push_back(varsTree1);
Expand Down
11 changes: 8 additions & 3 deletions python/regtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,23 @@ def run_eb_and_ee(self):

self.do_eb = True
self.make_cfg()

# Scram arch has to be set manually
# This also must be done in the training script in scripts/
arch = "slc7_amd64_gcc700"

print "starting: {}".format(self.name())
subprocess.Popen(["bin/slc6_amd64_gcc700/RegressionTrainerExe",self.cfg_name()]).communicate()
subprocess.Popen(["bin/"+arch+"/RegressionTrainerExe",self.cfg_name()]).communicate()
forest_eb_file = self.output_name()

self.do_eb = False
self.make_cfg()
print "starting: {}".format(self.name())
subprocess.Popen(["bin/slc6_amd64_gcc700/RegressionTrainerExe",self.cfg_name()]).communicate()
subprocess.Popen(["bin/"+arch+"/RegressionTrainerExe",self.cfg_name()]).communicate()
forest_ee_file = self.output_name()


subprocess.Popen(["bin/slc6_amd64_gcc700/RegressionApplierExe",self.input_testing,self.applied_name(),"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",self.tree_name,"--writeFullTree",self.write_full_tree,"--regOutTag",self.reg_out_tag]).communicate()
subprocess.Popen(["bin/"+arch+"/RegressionApplierExe",self.input_testing,self.applied_name(),"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",self.tree_name,"--writeFullTree",self.write_full_tree,"--regOutTag",self.reg_out_tag]).communicate()

print "made ",self.applied_name()

Expand Down
10 changes: 8 additions & 2 deletions rootScripts/setupResPlotter.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
std::vector<double> etaBins = {0.,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.4442,1.566,1.7,1.8,1.9,2.,2.25,2.5};//,2.75,3.0}
std::vector<double> etaBinsPho = {0.,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.4442,1.566,1.7,1.8,1.9,2.,2.25,2.5,2.75,3.0};
std::vector<double> etBins = {5,15,30,50,100,150,300};
std::vector<double> ptOneBin = {5,300};
std::vector<double> etBinsPho = {10,20,30,50,100,150,300};
std::vector<double> etBinsSC = {25,40,50,60};

Expand All @@ -23,9 +24,14 @@
gErrorIgnoreLevel = kError;

//trees
//with 102X regression applied by default
TTree* regTreeEleReal2018V52018Reg = HistFuncs::makeChain("egRegTree","/eos/cms/store/group/phys_egamma/ReleaseInputsArchive/2018UL_ElePhoReg/input_trees_with_regapplied/DoubleElectron_FlatPt-1To300_2018ConditionsFlatPU0to70RAW_105X_upgrade2018_realistic_v4-v1_AODSIM_EgRegTreeV5Refined2018Reg.root",1,1,1);

std::string resultsDirectory = "/home/hep/wrtabb/Egamma/results/2016UL/";
std::string inputDirectory = "/home/hep/wrtabb/Egamma/input_trees/2016UL/";
std::string input_file = "DoubleElectron_FlatPt-1To300_2016ConditionsFlatPU0to70RAW_105X_realistic_v2-v2.root";
std::string results_file = "regEleEcalTrk2016UL_RealIC_stdVar_stdCuts_ntrees1500_applied.root";
TTree*treeEle = HistFuncs::makeChain("egRegTree",inputDirectory+input_file,1,1,1);
TTree*treeEleFriend = HistFuncs::makeChain("egRegTreeFriend",resultsDirectory+results_file,1,1,1);
treeEle->AddFriend(treeEleFriend);

/*************************************
#now as an example do the following,
Expand Down
2 changes: 1 addition & 1 deletion scripts/applyPhoRegression.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
args = parser.parse_args()


base_cmd = "./bin/slc6_amd64_gcc700/RegressionApplierExe {input_file} {output_file} --gbrForestFileEB {gbrEB} --gbrForestFileEE {gbrEE} --nrThreads 4 --writeFullTree 1 --regOutTag {reg_out_tag}"
base_cmd = "./bin/slc7_amd64_gcc700/RegressionApplierExe {input_file} {output_file} --gbrForestFileEB {gbrEB} --gbrForestFileEE {gbrEE} --nrThreads 4 --writeFullTree 1 --regOutTag {reg_out_tag}"

ecal_ideal_file = "ecalIdealTmp.root"

Expand Down
15 changes: 12 additions & 3 deletions scripts/runEleRegTrainings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def main():

if args.era=='2016':
era_name = "2016UL"
raise ValueError("era 2016 is not yet implimented".format(era))
input_ideal_ic = "{}/DoubleElectron_FlatPt-1To300_2016ConditionsFlatPU0to70ECALGT_105X_realistic_IdealEcalIC_v2-v2.root".format(args.input_dir)
input_real_ic = "{}/DoubleElectron_FlatPt-1To300_2016ConditionsFlatPU0to70RAW_105X_realistic_v2-v2.root".format(args.input_dir)
ideal_eventnr_cut = "evt.eventnr%5==0"
real_eventnr_cut = "evt.eventnr%5==1"
ep_eventnr_cut = "evt.eventnr%5==2"

elif args.era=='2017':
era_name = "2017UL"
input_ideal_ic = "{}/DoubleElectron_FlatPt-1To300_2017ConditionsFlatPU0to70ECALGT_105X_mc2017_realistic_IdealEcalIC_v5-v2_AODSIM_EgRegTreeV5Refined.root".format(args.input_dir)
Expand Down Expand Up @@ -76,7 +81,11 @@ def main():

regArgs.base_name = "regEleEcal{era_name}_RealIC_IdealTraining".format(era_name=era_name)
input_for_res_training = str(regArgs.applied_name()) #save the output name before we change it
if run_step2: subprocess.Popen(["bin/slc6_amd64_gcc700/RegressionApplierExe",input_real_ic,input_for_res_training,"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","1","--regOutTag","Ideal"]).communicate()

# Set scram arch
arch = "slc7_amd64_gcc700"

if run_step2: subprocess.Popen(["bin/"+arch+"/RegressionApplierExe",input_real_ic,input_for_res_training,"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","1","--regOutTag","Ideal"]).communicate()

#step3 we now run over re-train with the REAL sample for the sigma, changing the target to have the correction applied
print "starting step3"
Expand Down Expand Up @@ -122,7 +131,7 @@ def main():
regArgs.run_eb_and_ee()

regArgs.base_name = "regEleEcalTrkLowHighPt{era_name}_RealIC".format(era_name=era_name)
subprocess.Popen(["bin/slc6_amd64_gcc700/RegressionApplierExe",regArgs.input_testing,regArgs.applied_name(),"--gbrForestFileEB",forest_eb,"--gbrForestFileEE",forest_ee,"--gbrForestFileEBHighEt",forest_eb_highpt,"--gbrForestFileEEHighEt",forest_ee_highpt,"--highEtThres","50.","--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","0"]).communicate()
subprocess.Popen(["bin/"+arch+"/RegressionApplierExe",regArgs.input_testing,regArgs.applied_name(),"--gbrForestFileEB",forest_eb,"--gbrForestFileEE",forest_ee,"--gbrForestFileEBHighEt",forest_eb_highpt,"--gbrForestFileEEHighEt",forest_ee_highpt,"--highEtThres","50.","--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","0"]).communicate()



Expand Down
12 changes: 10 additions & 2 deletions scripts/runPhoRegTrainings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ def main():

if args.era=='2016':
era_name = "2016UL"
raise ValueError("era 2016 is not yet implimented".format(era))
input_ideal_ic = "{}/DoublePhoton_FlatPt-5To300_2016ConditionsFlatPU0to70ECALGT_105X_realistic_IdealEcalIC_v2-v2_AODSIM_EgRegTreeV5Refined.root".format(args.input_dir)
input_real_ic = "{}/DoublePhoton_FlatPt-5To300_2016ConditionsFlatPU0to70RAW_105X_realistic_v2-v2_AODSIM_EgRegTreeV5Refined.root".format(args.input_dir)
ideal_eventnr_cut = "evt.eventnr%5==0"
real_eventnr_cut = "evt.eventnr%5==1"

elif args.era=='2017':
era_name = "2017UL"
input_ideal_ic = "{}/DoublePhoton_FlatPt-5To300_2017ConditionsFlatPU0to70ECALGT_105X_mc2017_realistic_IdealEcalIC_v5-v2_AODSIM_EgRegTreeV5Refined.root".format(args.input_dir)
input_real_ic = "{}/DoublePhoton_FlatPt-5To300_2017ConditionsFlatPU0to70_105X_mc2017_realistic_v5-v2_AODSIM_EgRegTreeV5Refined.root".format(args.input_dir)
ideal_eventnr_cut = "evt.eventnr%10==0" #2million photons
real_eventnr_cut = "evt.eventnr%10==1" #2million photons

elif args.era=='2018':
era_name = "2018UL"
input_ideal_ic = "{}/DoublePhoton_FlatPt-5To300_2018ConditionsFlatPU0to70ECALGT_105X_upgrade2018_realistic_IdealEcalIC_v4-v1_AODSIM_EgRegTreeV5Refined.root".format(args.input_dir)
Expand Down Expand Up @@ -68,7 +73,10 @@ def main():

regArgs.base_name = "regPhoEcal{era_name}_RealIC_IdealTraining".format(era_name=era_name)
input_for_res_training = str(regArgs.applied_name()) #save the output name before we change it
if run_step2: subprocess.Popen(["bin/slc6_amd64_gcc700/RegressionApplierExe",input_real_ic,input_for_res_training,"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","1","--regOutTag","Ideal"]).communicate()

# Set scram arch
arch = "slc7_amd64_gcc700"
if run_step2: subprocess.Popen(["bin/"+arch+"/RegressionApplierExe",input_real_ic,input_for_res_training,"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","1","--regOutTag","Ideal"]).communicate()

#step3 we now run over re-train with the REAL sample for the sigma, changing the target to have the correction applied
print "starting step3"
Expand Down
11 changes: 9 additions & 2 deletions scripts/runSCRegTrainings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ def main():
#prefixes all the regressions produced
if args.era=='2016':
base_reg_name = "scReg2016UL"
raise ValueError("era 2016 is not yet implimented".format(era))
input_ideal_ic = "{}/DoubleElectron_FlatPt-1To300_2016ConditionsFlatPU0to70ECALGT_105X_mcRun2_asymptotic_IdealEcalIC_newSR_v2-v2_AODSIM_EgRegTreeV5.root".format(args.input_dir)
input_real_ic = "{}/DoubleElectron_FlatPt-1To300_2016ConditionsFlatPU0to70RAW_105X_mcRun2_asymptotic_newECALSR_v2-v2_AODSIM_EgRegTreeV5.root".format(args.input_dir)
ideal_eventnr_cut = "evt.eventnr%5==0" #4million electrons
real_eventnr_cut = "evt.eventnr%5==1" #4million electrons

elif args.era=='2017':
base_reg_name = "scReg2017UL"
input_ideal_ic = "{}/DoubleElectron_FlatPt-1To300_2017ConditionsFlatPU0to70ECALGT_105X_mc2017_realistic_IdealEcalIC_v5-v2_AODSIM_EgRegTreeV1_extraVars.root".format(args.input_dir)
input_real_ic = "{}/DoubleElectron_FlatPt-1To300_2017ConditionsFlatPU0to70_105X_mc2017_realistic_v5-v2_AODSIM_EgRegTreeV1_4.root".format(args.input_dir)
ideal_eventnr_cut = "evt.eventnr%2==0"
real_eventnr_cut = "evt.eventnr%2==0" #events in the ntuple are different so can get away with this

elif args.era=='2018':
base_reg_name = "scReg2018UL"
input_ideal_ic = "{}/DoubleElectron_FlatPt-1To300_2018ConditionsFlatPU0to70ECALGT_105X_upgrade2018_realistic_IdealEcalIC_v4-v1_AODSIM_EgRegTreeV5_partStatsV2.root".format(args.input_dir)
Expand Down Expand Up @@ -83,7 +88,9 @@ def main():
input_for_res_training = str(regArgs.applied_name()) #save the output name before we change it
input_for_input_for_res_training = str(input_real_ic)

if run_step2: subprocess.Popen(["bin/slc6_amd64_gcc700/RegressionApplierExe",input_for_input_for_res_training,input_for_res_training,"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","1","--regOutTag","Ideal"]).communicate()
# Set scram arch
arch = "slc7_amd64_gcc700"
if run_step2: subprocess.Popen(["bin/"+arch+"/RegressionApplierExe",input_for_input_for_res_training,input_for_res_training,"--gbrForestFileEE",forest_ee_file,"--gbrForestFileEB",forest_eb_file,"--nrThreads","4","--treeName",regArgs.tree_name,"--writeFullTree","1","--regOutTag","Ideal"]).communicate()

regArgs.base_name = "{}_RealIC_RealTraining".format(base_reg_name)
regArgs.input_training = input_for_res_training
Expand Down