#read weights from alpSamples config["xsec_br"] = samples[sname]["xsec_br"] config["matcheff"] = samples[sname]["matcheff"] config["kfactor"] = samples[sname]["kfactor"] json_str = json.dumps(config) #define selectors list selector = ComposableSelector(alp.Event)(0, json_str) selector.addOperator(BaseOperator(alp.Event)()) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(MCTruthOperator(alp.Event)(0.5, True)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("pair")) selector.addOperator(JetPlotterOperator(alp.Event)(btagAlgo,weights_v)) selector.addOperator(DiJetPlotterOperator(alp.Event)(weights_v)) selector.addOperator(EventWriterOperator(alp.Event)(json_str,weights_v)) #create tChain and process each files tchain = TChain("pair/tree") for File in files: tchain.Add(File) nev = numEvents if (numEvents > 0 and numEvents < tchain.GetEntries()) else tchain.GetEntries() procOpt = "ofile=./"+sname+".root" if not oDir else "ofile="+oDir+"/"+sname+".root" print "max numEv {}".format(nev) tchain.Process(selector, procOpt, nev) ns+=1 print "### processed {} samples ###".format(ns)
# ROOT imports from ROOT import TChain # custom ROOT classes from ROOT import alp, ComposableSelector, CounterOperator, JetFilterOperator, BTagFilterOperator, JetPairingOperator, DiJetPlotterOperator from ROOT import BaseOperator, FolderOperator, EventWriterOperator config = {"jets_branch_name": "Jets", "hlt_names":[]} selector = ComposableSelector(alp.Event)(0, json.dumps(config)) selector.addOperator(BaseOperator(alp.Event)()) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(JetFilterOperator(alp.Event)(2.5, 30., 4)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(BTagFilterOperator(alp.Event)("pfCombinedInclusiveSecondaryVertexV2BJetTags", 0.800, 4)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("empty_one")) selector.addOperator(JetPairingOperator(alp.Event)(4)) selector.addOperator(FolderOperator(alp.Event)("4CSVM")) selector.addOperator(DiJetPlotterOperator(alp.Event)()) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(EventWriterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("empty_two")) tchain = TChain("ntuple/tree") tchain.Add("/lustre/cmswork/hh/alpha_ntuples/v0_20161004/GluGluToHHTo4B_node_SM_13TeV-madgraph_v14-v1/0000/output.root") tchain.Process(selector, "", 10000)
#read weights from alpSamples config["xsec_br"] = samples[sname]["xsec_br"] config["matcheff"] = samples[sname]["matcheff"] config["kfactor"] = samples[sname]["kfactor"] json_str = json.dumps(config) w2 = {'PUWeight', 'GenWeight'} w2_v = vector("string")() for w in w2: w2_v.push_back(w) #define selectors list selector = ComposableSelector(alp.Event)(0, json_str) selector.addOperator(BaseOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("base")) selector.addOperator(CounterOperator(alp.Event)(w2_v)) selector.addOperator(FolderOperator(alp.Event)("trigger")) selector.addOperator(TriggerOperator(alp.Event)(trg_namesD_v)) selector.addOperator(CounterOperator(alp.Event)(w2_v)) selector.addOperator(FolderOperator(alp.Event)("acc")) selector.addOperator(JetFilterOperator(alp.Event)(2.5, 30., 4)) selector.addOperator(CounterOperator(alp.Event)(w2_v)) #debug - no bTagWeight? selector.addOperator(JetPlotterOperator(alp.Event)("pt",w2_v)) selector.addOperator(MiscellPlotterOperator(alp.Event)(w2_v)) selector.addOperator(FolderOperator(alp.Event)("btag")) selector.addOperator(BTagFilterOperator(alp.Event)(btagAlgo, 0.800, 4, config["isData"], data_path)) selector.addOperator(CounterOperator(alp.Event)(weights_v))
config["matcheff"] = samples[sname]["matcheff"] config["kfactor"] = samples[sname]["kfactor"] json_str = json.dumps(config) #define selectors list selector = ComposableSelector(alp.Event)(0, json_str) selector.addOperator(BaseOperator(alp.Event)()) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(TriggerOperator(alp.Event)(trg_names_v)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(JetFilterOperator(alp.Event)(2.5, 30., 4)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("acc")) selector.addOperator(JetPlotterOperator(alp.Event)("pfCombinedInclusiveSecondaryVertexV2BJetTags",weights_v)) selector.addOperator(BTagFilterOperator(alp.Event)("pfCombinedInclusiveSecondaryVertexV2BJetTags", 0.800, 4, config["isData"], data_path)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("btag")) selector.addOperator(JetPlotterOperator(alp.Event)("pfCombinedInclusiveSecondaryVertexV2BJetTags",weights_v)) selector.addOperator(JetPairingOperator(alp.Event)(4)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("pair")) selector.addOperator(JetPlotterOperator(alp.Event)("pfCombinedInclusiveSecondaryVertexV2BJetTags",weights_v)) selector.addOperator(DiJetPlotterOperator(alp.Event)(weights_v)) selector.addOperator(EventWriterOperator(alp.Event)(json_str)) selector.addOperator(ThrustFinderOperator(alp.Event)()) selector.addOperator(HemisphereProducerOperator(alp.Event)())
if args.jetCorr == 0: print "- applying JEC Up -" selector.addOperator(JEShifterOperator(alp.Event)(+1)) elif args.jetCorr == 1: print "- applying JEC Down -" selector.addOperator(JEShifterOperator(alp.Event)(-1)) elif args.jetCorr == 2: print "- applying JER Up -" selector.addOperator(JERShifterOperator(alp.Event)(+1)) elif args.jetCorr == 3: print "- applying JER Down -" selector.addOperator(JERShifterOperator(alp.Event)(-1)) # else: # print "- default JEC-JER applied -" selector.addOperator(FolderOperator(alp.Event)("base")) selector.addOperator(WeightSumOperator(alp.Event)(w_nobTag_v)) selector.addOperator( CounterOperator(alp.Event)(config["n_gen_events"], w_nobTag_v)) selector.addOperator(GenJetPlotterOperator(alp.Event)(btagAlgo)) selector.addOperator(FolderOperator(alp.Event)("acc")) selector.addOperator(JetFilterOperator(alp.Event)(args.eta, args.pt, 4)) selector.addOperator( CounterOperator(alp.Event)(config["n_gen_events"], w_nobTag_v)) selector.addOperator(JetPlotterOperator(alp.Event)( btagAlgo, w_nobTag_v)) #with bTag since jets are sorted selector.addOperator(GenJetPlotterOperator(alp.Event)(btagAlgo)) selector.addOperator(FolderOperator(alp.Event)("btag")) selector.addOperator(
print "- applying JEC Up -" selector.addOperator(JEShifterOperator(alp.Event)(+1)) elif args.jetCorr == 1: print "- applying JEC Down -" selector.addOperator(JEShifterOperator(alp.Event)(-1)) elif args.jetCorr == 2: print "- applying JER Up -" selector.addOperator(JERShifterOperator(alp.Event)(+1)) elif args.jetCorr == 3: print "- applying JER Down -" selector.addOperator(JERShifterOperator(alp.Event)(-1)) else: print "- default JEC-JER applied -" selector.addOperator(FolderOperator(alp.Event)("base")) #selector.addOperator(WeightSumOperator(alp.Event)(w_nobTag_v)) selector.addOperator(CounterOperator(alp.Event)(config["n_gen_events"],w_nobTag_v)) #trigger if args.doTrigger: if not args.doMixed: selector.addOperator(FolderOperator(alp.Event)("trigger")) selector.addOperator(TriggerOperator(alp.Event)(trg_names_v)) selector.addOperator(CounterOperator(alp.Event)(config["n_gen_events"],w_nobTag_v)) else: print "WARNING: is Mixed sample - trigger filter applied already" selector.addOperator(FolderOperator(alp.Event)("acc")) selector.addOperator(JetFilterOperator(alp.Event)(2.4, 30., 4)) selector.addOperator(CounterOperator(alp.Event)(config["n_gen_events"],w_nobTag_v))
continue else: if "Run" in files[0]: config["isData"] = True #read weights from alpSamples config["xsec_br"] = samples[sname]["xsec_br"] config["matcheff"] = samples[sname]["matcheff"] config["kfactor"] = samples[sname]["kfactor"] json_str = json.dumps(config) #define selectors list selector = ComposableSelector(alp.Event)(0, json_str) selector.addOperator(BaseOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("base")) selector.addOperator(CounterOperator(alp.Event)(weights_v)) selector.addOperator(ReWeightingOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("reweight")) selector.addOperator(CounterOperator(alp.Event)(weights_v)) if args.savePlots: selector.addOperator( JetPlotterOperator(alp.Event)(btagAlgo, weights_v)) if args.savePlots: selector.addOperator(DiJetPlotterOperator(alp.Event)(weights_v)) selector.addOperator(EventWriterOperator(alp.Event)(json_str, weights_v)) #create tChain and process each files treename = "pair/tree"
config["kfactor"] = samples[sname]["kfactor"] json_str = json.dumps(config) #define selectors list selector = ComposableSelector(alp.Event)(0, json_str) selector.addOperator(BaseOperator(alp.Event)()) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(TriggerOperator(alp.Event)(trg_namesD_v)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(JetFilterOperator(alp.Event)(2.5, 30., 4)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("def")) selector.addOperator(JetPlotterOperator(alp.Event)("pt",weights_v)) selector.addOperator(MiscellPlotterOperator(alp.Event)(weights_v)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(BTagFilterOperator(alp.Event)("pfCombinedInclusiveSecondaryVertexV2BJetTags", 0.800, 2, config["isData"], data_path)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(IsoMuFilterOperator(alp.Event)(0.05, 30., 1)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(MetFilterOperator(alp.Event)(40.)) selector.addOperator(CounterOperator(alp.Event)()) selector.addOperator(FolderOperator(alp.Event)("trg_Iso")) selector.addOperator(JetPlotterOperator(alp.Event)("pfCombinedInclusiveSecondaryVertexV2BJetTags",weights_v))
if args.jetCorr == 0: print "- applying JEC Up -" selector.addOperator(JEShifterOperator(alp.Event)(+1)) elif args.jetCorr == 1: print "- applying JEC Down -" selector.addOperator(JEShifterOperator(alp.Event)(-1)) elif args.jetCorr == 2: print "- applying JER Up -" selector.addOperator(JERShifterOperator(alp.Event)(True)) elif args.jetCorr == 3: print "- applying JER Down -" selector.addOperator(JERShifterOperator(alp.Event)(False)) else: print "- default JEC-JER applied -" selector.addOperator(FolderOperator(alp.Event)("base")) selector.addOperator(CounterOperator(alp.Event)(w_nobTag_v)) #trigger if args.doTrigger: if not args.doMixed: selector.addOperator(FolderOperator(alp.Event)("trigger")) selector.addOperator(TriggerOperator(alp.Event)(trg_names_v)) selector.addOperator(CounterOperator(alp.Event)(w_nobTag_v)) else: print "WARNING: is Mixed sample - trigger filter applied already" selector.addOperator(FolderOperator(alp.Event)("acc")) selector.addOperator(JetFilterOperator(alp.Event)(2.4, 30., 4)) selector.addOperator(CounterOperator(alp.Event)(w_nobTag_v)) if args.savePlots: