TCanvas* drawFish(TTree *&tree, TString selection = "PID>1000", TString digidata = "", int layout = 3, double maxz = -2, double minz = -2) { // assign mcpid and pixid from the hits tree int mcpid(0), pixid(0); tree->SetBranchAddress("mcp",&mcpid); tree->SetBranchAddress("pix",&pixid); // entry by entry selection TTreeFormula* tform = new TTreeFormula("tree selection",selection.Data(),tree); // initialize pad and color scale from prttools initDigi(); SetRootPalette(1); int entries = tree->GetEntries(); cout << "selection: " << selection << endl; cout << "entries in tree: " << entries << endl; for (int i_entry=0; i_entry<entries; i_entry++) { tree->GetEntry(i_entry); //cout << "entry " << i_entry << endl; //cout << "\tmcp: " << mcpid << endl; //cout << "\tpix: " << pixid << endl; if(tform->EvalInstance()) fhDigi[mcpid]->Fill(pixid%8, pixid/8); } drawDigi("m,p,v\n",3,-2,-2); cDigi->cd(); (new TPaletteAxis(0.90,0.1,0.94,0.90,fhDigi[14]))->Draw(); return cDigi; }
void GetBeamInformation(int runNumber) { TTree* tree = (TTree*) _file0->Get("t1041"); TTreeFormula* momentum = new TTreeFormula("momentum","tbspill.GetMomentum()",tree); tree->GetEntry(0); float value_momentum = momentum->EvalInstance(); std::cout << " momentum = " << value_momentum << std::endl; ofstream myfile; myfile.open ("runNumber_momentum.txt", std::ofstream::app); myfile << runNumber << " " << value_momentum << std::endl; myfile.close(); }
//////////////////////////////////////////////////////////////////////////////// /// Main /// //////////////////////////////////////////////////////////////////////////////// void GrowTree(TString process, std::string regMethod="BDTG", Long64_t beginEntry=0, Long64_t endEntry=-1) { gROOT->SetBatch(1); TH1::SetDefaultSumw2(1); gROOT->LoadMacro("HelperFunctions.h"); //< make functions visible to TTreeFormula if (!TString(gROOT->GetVersion()).Contains("5.34")) { std::cout << "INCORRECT ROOT VERSION! Please use 5.34:" << std::endl; std::cout << "source /uscmst1/prod/sw/cms/slc5_amd64_gcc462/lcg/root/5.34.02-cms/bin/thisroot.csh" << std::endl; std::cout << "Return without doing anything." << std::endl; return; } const TString indir = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Phys14_PU20bx25/skimV11/"; const TString outdir = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Phys14_PU20bx25/skimV11/step3/"; const TString prefix = "skim_"; const TString suffix = ".root"; TFile *input = TFile::Open(indir + prefix + process + suffix); if (!input) { std::cout << "ERROR: Could not open input file." << std::endl; exit(1); } /// Make output directory if it doesn't exist if (gSystem->AccessPathName(outdir)) gSystem->mkdir(outdir); std::cout << "--- GrowTree : Using input file: " << input->GetName() << std::endl; TTree *inTree = (TTree *) input->Get("tree"); TH1F *hcount = (TH1F *) input->Get("Count"); TFile *output(0); if (beginEntry == 0 && endEntry == -1) output = TFile::Open(outdir + "Step3_" + process + suffix, "RECREATE"); else output = TFile::Open(outdir + "Step3_" + process + TString::Format("_%Li_%Li", beginEntry, endEntry) + suffix, "RECREATE"); TTree *outTree = inTree->CloneTree(0); // Do no copy the data yet /// The clone should not delete any shared i/o buffers. ResetDeleteBranches(outTree); ///-- Set branch addresses ------------------------------------------------- EventInfo EVENT; double hJet_pt[MAXJ], hJet_eta[MAXJ], hJet_phi[MAXJ], hJet_m[MAXJ], hJet_ptRaw[MAXJ], hJet_genPt[MAXJ]; int hJCidx[2]; inTree->SetBranchStatus("*", 1); inTree->SetBranchStatus("hJCidx",1); inTree->SetBranchStatus("Jet_*",1); inTree->SetBranchAddress("hJCidx", &hJCidx); inTree->SetBranchAddress("Jet_pt", &hJet_pt); inTree->SetBranchAddress("Jet_eta", &hJet_eta); inTree->SetBranchAddress("Jet_phi", &hJet_phi); inTree->SetBranchAddress("Jet_mass", &hJet_m); inTree->SetBranchAddress("Jet_rawPt", &hJet_ptRaw); inTree->SetBranchAddress("Jet_mcPt", &hJet_genPt); ///-- Make new branches ---------------------------------------------------- int EVENT_run, EVENT_event; // set these as TTree index? float lumi_ = lumi, efflumi, efflumi_old, efflumi_UEPS_up, efflumi_UEPS_down; float hJet_ptReg[2]; float HptNorm, HptGen, HptReg; float HmassNorm, HmassGen, HmassReg; outTree->Branch("EVENT_run", &EVENT_run, "EVENT_run/I"); outTree->Branch("EVENT_event", &EVENT_event, "EVENT_event/I"); outTree->Branch("lumi", &lumi_, "lumi/F"); outTree->Branch("efflumi", &efflumi, "efflumi/F"); outTree->Branch("efflumi_old", &efflumi_old, "efflumi_old/F"); outTree->Branch("efflumi_UEPS_up", &efflumi_UEPS_up, "efflumi_UEPS_up/F"); outTree->Branch("efflumi_UEPS_down", &efflumi_UEPS_down, "efflumi_UEPS_down/F"); outTree->Branch("hJet_ptReg", &hJet_ptReg, "hJet_ptReg[2]/F"); outTree->Branch("HptNorm", &HptNorm, "HptNorm/F"); outTree->Branch("HptGen", &HptGen, "HptGen/F"); outTree->Branch("HptReg", &HptReg, "HptReg/F"); outTree->Branch("HmassNorm", &HmassNorm, "HmassNorm/F"); outTree->Branch("HmassGen", &HmassGen, "HmassGen/F"); outTree->Branch("HmassReg", &HmassReg, "HmassReg/F"); /// Get effective lumis std::map < std::string, float > efflumis = GetLumis(); efflumi = efflumis[process.Data()]; assert(efflumi > 0); efflumi_old = efflumi; efflumi_UEPS_up = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(3); efflumi_UEPS_down = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(4); TTreeFormula* ttf_lheweight = new TTreeFormula("ttf_lheweight", Form("%f", efflumi), inTree); #ifdef STITCH std::map < std::string, std::string > lheweights = GetLHEWeights(); TString process_lhe = process; if (process_lhe.BeginsWith("WJets") && process_lhe != "WJetsHW") process_lhe = "WJets"; else if (process_lhe.BeginsWith("ZJets") && process_lhe != "ZJetsHW") process_lhe = "ZJets"; else process_lhe = ""; TString lheweight = lheweights[process_lhe.Data()]; if (lheweight != "") { delete ttf_lheweight; // Bug fix for ZJetsPtZ100 if (process == "ZJetsPtZ100") lheweight.ReplaceAll("lheV_pt", "999"); std::cout << "BUGFIX: " << lheweight << std::endl; ttf_lheweight = new TTreeFormula("ttf_lheweight", lheweight, inTree); } #endif ttf_lheweight->SetQuickLoad(1); // regression stuff here ///-- Setup TMVA Reader ---------------------------------------------------- TMVA::Tools::Instance(); //< This loads the library TMVA::Reader * reader = new TMVA::Reader("!Color:!Silent"); /// Get the variables const std::vector < std::string > & inputExpressionsReg = GetInputExpressionsReg(); const UInt_t nvars = inputExpressionsReg.size(); Float_t readerVars[nvars]; int idx_rawpt = -1, idx_pt = -1, idx_et = -1, idx_mt = -1; for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) { const TString& expr = inputExpressionsReg.at(iexpr); reader->AddVariable(expr, &readerVars[iexpr]); if (expr.BeginsWith("breg_rawptJER := ")) idx_rawpt = iexpr; else if (expr.BeginsWith("breg_pt := ")) idx_pt = iexpr; else if (expr.BeginsWith("breg_et := ")) idx_et = iexpr; else if (expr.BeginsWith("breg_mt := ")) idx_mt = iexpr; } // assert(idx_rawpt!=-1 && idx_pt!=-1 && idx_et!=-1 && idx_mt!=-1); assert(idx_rawpt!=-1 && idx_pt!=-1 ); /// Setup TMVA regression inputs const std::vector < std::string > & inputExpressionsReg0 = GetInputExpressionsReg0(); const std::vector < std::string > & inputExpressionsReg1 = GetInputExpressionsReg1(); assert(inputExpressionsReg0.size() == nvars); assert(inputExpressionsReg1.size() == nvars); /// Load TMVA weights TString weightdir = "weights/"; TString weightfile = weightdir + "TMVARegression_" + regMethod + ".testweights.xml"; reader->BookMVA(regMethod + " method", weightfile); TStopwatch sw; sw.Start(); /// Create TTreeFormulas TTreeFormula *ttf = 0; std::vector < TTreeFormula * >::const_iterator formIt, formItEnd; std::vector < TTreeFormula * > inputFormulasReg0; std::vector < TTreeFormula * > inputFormulasReg1; std::vector < TTreeFormula * > inputFormulasFJReg0; std::vector < TTreeFormula * > inputFormulasFJReg1; std::vector < TTreeFormula * > inputFormulasFJReg2; for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) { ttf = new TTreeFormula(Form("ttfreg%i_0", iexpr), inputExpressionsReg0.at(iexpr).c_str(), inTree); ttf->SetQuickLoad(1); inputFormulasReg0.push_back(ttf); ttf = new TTreeFormula(Form("ttfreg%i_1", iexpr), inputExpressionsReg1.at(iexpr).c_str(), inTree); ttf->SetQuickLoad(1); inputFormulasReg1.push_back(ttf); } ///-- Loop over events ----------------------------------------------------- Int_t curTree = inTree->GetTreeNumber(); const Long64_t nentries = inTree->GetEntries(); if (endEntry < 0) endEntry = nentries; Long64_t ievt = 0; for (ievt=TMath::Max(ievt, beginEntry); ievt<TMath::Min(nentries, endEntry); ievt++) { if (ievt % 2000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl; const Long64_t local_entry = inTree->LoadTree(ievt); // faster, but only for TTreeFormula if (local_entry < 0) break; inTree->GetEntry(ievt); // same event as received by LoadTree() if (inTree->GetTreeNumber() != curTree) { curTree = inTree->GetTreeNumber(); for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++) (*formIt)->UpdateFormulaLeaves(); // if using TChain ttf_lheweight->UpdateFormulaLeaves(); } /// These need to be called when arrays of variable size are used in TTree. for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++) (*formIt)->GetNdata(); ttf_lheweight->GetNdata(); /// Fill branches EVENT_run = EVENT.run; EVENT_event = EVENT.event; #ifdef STITCH efflumi = ttf_lheweight->EvalInstance(); // efflumi_UEPS_up = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(3); //efflumi_UEPS_down = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(4); #endif bool verbose = false; for (Int_t ihj = 0; ihj < 2; ihj++) { /// Evaluate TMVA regression output for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) { if (ihj==0) { readerVars[iexpr] = inputFormulasReg0.at(iexpr)->EvalInstance(); } else if (ihj==1) { readerVars[iexpr] = inputFormulasReg1.at(iexpr)->EvalInstance(); } } hJet_ptReg[ihj] = (reader->EvaluateRegression(regMethod + " method"))[0]; if (verbose) std::cout << readerVars[idx_pt] << " " << readerVars[idx_rawpt] << " " << hJet_pt[ihj] << " " << hJet_ptReg[ihj] << " " << hJet_genPt[ihj] << std::endl; const TLorentzVector p4Zero = TLorentzVector(0., 0., 0., 0.); // int idx = hJCidx[0] ; // std::cout << "the regressed pt for jet 0 is " << hJet_ptReg[0] << "; the hJCidx is " << hJCidx[0] << ", hence the origianl pt is " << hJet_pt[idx] << std::endl; const TLorentzVector& hJet_p4Norm_0 = makePtEtaPhiM(hJet_pt[hJCidx[0]] , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]); const TLorentzVector& hJet_p4Norm_1 = makePtEtaPhiM(hJet_pt[hJCidx[1]] , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]); const TLorentzVector& hJet_p4Gen_0 = hJet_genPt[hJCidx[0]] > 0 ? makePtEtaPhiM(hJet_genPt[hJCidx[0]] , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]) : p4Zero; const TLorentzVector& hJet_p4Gen_1 = hJet_genPt[hJCidx[1]] > 0 ? makePtEtaPhiM(hJet_genPt[hJCidx[1]] , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]) : p4Zero; const TLorentzVector& hJet_p4Reg_0 = makePtEtaPhiM(hJet_ptReg[0] , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]); const TLorentzVector& hJet_p4Reg_1 = makePtEtaPhiM(hJet_ptReg[1] , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]); HptNorm = (hJet_p4Norm_0 + hJet_p4Norm_1 ).Pt(); HptGen = (hJet_p4Gen_0 + hJet_p4Gen_1 ).Pt(); HptReg = (hJet_p4Reg_0 + hJet_p4Reg_1 ).Pt(); HmassNorm = (hJet_p4Norm_0 + hJet_p4Norm_1 ).M(); HmassGen = (hJet_p4Gen_0 + hJet_p4Gen_1 ).M(); HmassReg = (hJet_p4Reg_0 + hJet_p4Reg_1 ).M(); // std::cout << "HmassReg is " << HmassReg << std::endl; } outTree->Fill(); // fill it! } // end loop over TTree entries /// Get elapsed time sw.Stop(); std::cout << "--- End of event loop: "; sw.Print(); output->cd(); outTree->Write(); output->Close(); input->Close(); delete input; delete output; for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++) delete *formIt; for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++) delete *formIt; delete ttf_lheweight; std::cout << "==> GrowTree is done!" << std::endl << std::endl; return; }
void applyenergy() { ROOT::Cintex::Cintex::Enable(); //printf("include: %s\n",gSystem->GetIncludePath()); //return; Long64_t maxentries = -1; //TFile *fmc = new TFile("/home/bendavid/cms/hist/hgg-v0-Sept1/local/filefi/merged/hgg-v0_s11-h120gg-gf-v11-pu_noskim.root","READ"); //TFile *fmc = new TFile("/scratch/bendavid/cms/hist/hgg-v0/merged/hgg-v0_f11--h121gg-gf-v14b-pu_noskim.root","READ"); TFile *fmc = new TFile("/scratch/bendavid/cms/hist/hgg-v0/merged/hgg-v0_f11-zjets-v14b-pu_noskim.root","READ"); //TFile *fmc = new TFile("/scratch/bendavid/cms/hist/hgg-v0/t2mit/filefi/025/f11--h121gg-gf-v14b-pu/hgg-v0_f11--h121gg-gf-v14b-pu_noskim_0000.root","READ"); TDirectory *dir = (TDirectory*)fmc->FindObjectAny("PhotonTreeWriterPresel"); TTree *hmcph = (TTree*)dir->Get("hPhotonTree"); TDirectory *dirsingle = (TDirectory*)fmc->FindObjectAny("PhotonTreeWriterSingle"); TTree *hmcsingleph = (TTree*)dirsingle->Get("hPhotonTree"); TFile *fmcele = new TFile("/scratch/bendavid/cms/hist/hgg-v0/merged/hgg-v0_f11-zjets-v14b-pu_noskim.root","READ"); TDirectory *direle = (TDirectory*)fmcele->FindObjectAny("PhotonTreeWriterE"); TTree *hmcele = (TTree*)direle->Get("hPhotonTree"); TDirectory *direlesingle = (TDirectory*)fmcele->FindObjectAny("PhotonTreeWriterE"); TTree *hmcelesingle = (TTree*)direlesingle->Get("hPhotonTreeSingle"); TFile *fdele = new TFile("/scratch/bendavid/cms/hist/hgg-v0/MergedDel2011J16.root","READ"); TDirectory *dirdele = (TDirectory*)fdele->FindObjectAny("PhotonTreeWriterE"); TTree *hdele = (TTree*)dirdele->Get("hPhotonTree"); TDirectory *dirdelesingle = (TDirectory*)fdele->FindObjectAny("PhotonTreeWriterE"); TTree *hdelesingle = (TTree*)dirdelesingle->Get("hPhotonTreeSingle"); TFile *fgbropt = new TFile("fgbrtraintest.root","READ"); const GBRForest *gbropt = (GBRForest*)fgbropt->Get("gbrtrain"); std::vector<std::string> *varlist = (std::vector<std::string>*)fgbropt->Get("varlist"); std::vector<std::string> *varlisteb = varlist; std::vector<std::string> *varlistee = varlist; const GBRForest *gbr = 0; const GBRForest *gbreb = gbropt; const GBRForest *gbree = gbropt; UInt_t nvarseb = varlisteb->size(); UInt_t nvarsee = varlistee->size(); Float_t *vals = 0; Float_t *valseb = new Float_t[nvarseb]; Float_t *valsee = new Float_t[nvarsee]; TFile *fmvacor = new TFile("fmvacor.root","RECREATE"); TTree *hmvacorph = new TTree("hmvacorph",""); TTree *hmvacorele = new TTree("hmvacorele",""); TTree *hmvacorelesingle = new TTree("hmvacorelesingle",""); TTree *hmvacordele = new TTree("hmvacordele",""); TTree *hmvacordelesingle = new TTree("hmvacordelesingle",""); TTree *hmvacorqcdsingle = new TTree("hmvacorqcdsingle",""); hmvacorele->SetAutoFlush(-1000000000); hmvacorelesingle->SetAutoFlush(-1000000000); hmvacordele->SetAutoFlush(-1000000000); hmvacordelesingle->SetAutoFlush(-1000000000); Float_t massmvacor=0.; Float_t massmvacorerr=0.; Float_t massmvacorerrlo=0.; Float_t massmvacorerrhi=0.; Float_t ph1emvacor=0.; Float_t ph1emvacorerr=0.; Float_t ph1emvacorerrlo=0.; Float_t ph1emvacorerrhi=0.; Float_t ph1bdt = 0.; Float_t ph1bdtvar = 0.; Int_t ph1dcoridx=0; Float_t ph1emvadcor=0.; Float_t ph2emvacor=0.; Float_t ph2emvacorerr=0.; Float_t ph2emvacorerrlo=0.; Float_t ph2emvacorerrhi=0.; Float_t ph2bdt = 0.; Float_t ph2bdtvar = 0.; Int_t ph2dcoridx=0; Float_t ph2emvadcor=0.; Float_t phemvacor=0.; Float_t phemvacorerr=0.; Float_t phbdt=0.; Float_t phbdtvar=0.; Int_t phdcoridx = 0; Float_t phemvadcor=0; Float_t phregtarget = 0.; for (UInt_t isample=1; isample<3; ++isample) { TTree *hmc = 0; TTree *hmvacor = 0; TTree *hmcsingle = 0; TTree *hmvacorsingle = 0; if (isample==0) { hmc = hmcph; hmvacor = hmvacorph; //hmcsingle = hmcqcdsingle; //hmvacorsingle = hmvacorqcdsingle; } else if (isample==1) { hmc = hmcele; hmvacor = hmvacorele; hmcsingle = hmcelesingle; hmvacorsingle = hmvacorelesingle; } else if (isample==2) { hmc = hdele; hmvacor = hmvacordele; hmcsingle = hdelesingle; hmvacorsingle = hmvacordelesingle; } // std::vector<TTreeFormula*> forms1; // std::vector<TTreeFormula*> forms2; // std::vector<TTreeFormula*> formssingle; TTreeFormula **formseb1 = new TTreeFormula*[nvarseb]; TTreeFormula **formseb2 = new TTreeFormula*[nvarseb]; TTreeFormula **formsebsingle = new TTreeFormula*[nvarseb]; for (UInt_t ivar=0; ivar<varlisteb->size(); ++ivar) { TString expression = varlisteb->at(ivar); expression.ReplaceAll("ph.genz","vtxZ"); TString expr1(expression); expr1.ReplaceAll("ph.","ph1."); TString expr2(expression); expr2.ReplaceAll("ph.","ph2."); printf("expr = %s, expr1 = %s, expr2 = %s\n",expression.Data(),expr1.Data(),expr2.Data()); formseb1[ivar] = new TTreeFormula(expr1,expr1,hmc); formseb2[ivar] = new TTreeFormula(expr2,expr2,hmc); if (hmcsingle) formsebsingle[ivar] = new TTreeFormula(expression,expression,hmcsingle); } TTreeFormula **formsee1 = new TTreeFormula*[nvarsee]; TTreeFormula **formsee2 = new TTreeFormula*[nvarsee]; TTreeFormula **formseesingle = new TTreeFormula*[nvarsee]; for (UInt_t ivar=0; ivar<varlistee->size(); ++ivar) { TString expression = varlistee->at(ivar); expression.ReplaceAll("ph.genz","vtxZ"); if (expression=="(1.0-(!ismc)*0.072)*ph.scpse/ph.scrawe") expression = "ph.scpse/ph.scrawe"; TString expr1(expression); expr1.ReplaceAll("ph.","ph1."); TString expr2(expression); expr2.ReplaceAll("ph.","ph2."); printf("expr = %s, expr1 = %s, expr2 = %s\n",expression.Data(),expr1.Data(),expr2.Data()); formsee1[ivar] = new TTreeFormula(expr1,expr1,hmc); formsee2[ivar] = new TTreeFormula(expr2,expr2,hmc); if (hmcsingle) formseesingle[ivar] = new TTreeFormula(expression,expression,hmcsingle); } TString denebexpr1 = "ph1.scrawe"; TString denebexpr2 = "ph2.scrawe"; TString denebexprsingle = "ph.scrawe"; TTreeFormula *denebform1 = new TTreeFormula(denebexpr1,denebexpr1,hmc); TTreeFormula *denebform2 = new TTreeFormula(denebexpr2,denebexpr2,hmc); TTreeFormula *denebformsingle = 0; if (hmcsingle) denebformsingle = new TTreeFormula(denebexprsingle,denebexprsingle,hmcsingle); // TString deneeexpr1 = "ph1.scrawe + (1.0-(!ismc)*0.072)*ph1.scpse"; // TString deneeexpr2 = "ph2.scrawe + (1.0-(!ismc)*0.072)*ph2.scpse"; TString deneeexpr1 = "ph1.scrawe + ph1.scpse"; TString deneeexpr2 = "ph2.scrawe + ph2.scpse"; TString deneeexprsingle = "ph.scrawe + ph.scpse"; TTreeFormula *deneeform1 = new TTreeFormula(deneeexpr1,deneeexpr1,hmc); TTreeFormula *deneeform2 = new TTreeFormula(deneeexpr2,deneeexpr2,hmc); TTreeFormula *deneeformsingle = 0; if (hmcsingle) deneeformsingle = new TTreeFormula(deneeexprsingle,deneeexprsingle,hmcsingle); TTreeFormula *costhetaform = new TTreeFormula("costheta","costheta",hmc); TString isbexpr1 = "ph1.isbarrel"; TString isbexpr2 = "ph2.isbarrel"; TString isbexprsingle = "ph.isbarrel"; TTreeFormula *isbform1 = new TTreeFormula(isbexpr1,isbexpr1,hmc); TTreeFormula *isbform2 = new TTreeFormula(isbexpr2,isbexpr2,hmc); TTreeFormula *isbformsingle = 0; if (hmcsingle) isbformsingle = new TTreeFormula(isbexprsingle,isbexprsingle,hmcsingle); hmvacor->Branch("massmvacor",&massmvacor,"massmvacor/F"); hmvacor->Branch("massmvacorerr",&massmvacorerr,"massmvacorerr/F"); //hmvacor->Branch("massmvacorerrlo",&massmvacorerrlo,"massmvacorerrlo/F"); //hmvacor->Branch("massmvacorerrhi",&massmvacorerrhi,"massmvacorerrhi/F"); hmvacor->Branch("ph1.emvacor",&ph1emvacor,"ph1.emvacor/F"); hmvacor->Branch("ph1.emvacorerr",&ph1emvacorerr,"ph1.emvacorerr/F"); hmvacor->Branch("ph1.bdt",&ph1bdt,"ph1.bdt/F"); hmvacor->Branch("ph1.bdtvar",&ph1bdtvar,"ph1.bdtvar/F"); hmvacor->Branch("ph1.dcoridx",&ph1dcoridx,"ph1.dcoridx/I"); hmvacor->Branch("ph1.emvadcor",&ph1emvadcor,"ph1.emvadcor/F"); //hmvacor->Branch("ph1.emvacorerrlo",&ph1emvacorerrlo,"ph1.emvacorerrlo/F"); //hmvacor->Branch("ph1.emvacorerrhi",&ph1emvacorerrhi,"ph1.emvacorerrhi/F"); hmvacor->Branch("ph2.emvacor",&ph2emvacor,"ph2.emvacor/F"); hmvacor->Branch("ph2.emvacorerr",&ph2emvacorerr,"ph2.emvacorerr/F"); hmvacor->Branch("ph2.bdt",&ph2bdt,"ph2.bdt/F"); hmvacor->Branch("ph2.bdtvar",&ph2bdtvar,"ph2.bdtvar/F"); hmvacor->Branch("ph2.dcoridx",&ph2dcoridx,"ph2.dcoridx/I"); hmvacor->Branch("ph2.emvadcor",&ph2emvadcor,"ph2.emvadcor/F"); //hmvacor->Branch("ph2.emvacorerrlo",&ph2emvacorerrlo,"ph2.emvacorerrlo/F"); //hmvacor->Branch("ph2.emvacorerrhi",&ph2emvacorerrhi,"ph2.emvacorerrhi/F"); if (hmvacorsingle) { hmvacorsingle->Branch("ph.emvacor",&phemvacor,"ph.emvacor/F"); hmvacorsingle->Branch("ph.emvacorerr",&phemvacorerr,"ph.emvacorerr/F"); hmvacorsingle->Branch("ph.dcoridx",&phdcoridx,"ph.dcoridx/I"); hmvacorsingle->Branch("ph.emvadcor",&phemvadcor,"ph.emvadcor/F"); //hmvacor->Branch("ph.bdt",&ph1bdt,"ph.bdt/F"); //hmvacor->Branch("ph.bdtvar",&ph1bdtvar,"ph.bdtvar/F"); } //TString method = "MLP method"; //TString method = "BDT method"; TString method = "BDTG method"; //TString method = "PDEFoam method"; for (Long64_t i=0; i<hmc->GetEntries(); ++i) { hmc->LoadTree(i); float den1, den2; bool isb1 = isbform1->EvalInstance(); bool isb2 = isbform2->EvalInstance(); if (isb1) { gbr = gbreb; //gbrvar = gbrvareb; //gbrdcor = gbrdcoreb; vals = valseb; den1 = denebform1->EvalInstance(); for (UInt_t ivar=0; ivar<nvarseb; ++ivar) { valseb[ivar] = formseb1[ivar]->EvalInstance(); } } else { gbr = gbree; //gbrvar = gbrvaree; //gbrdcor = gbrdcoree; vals = valsee; den1 = deneeform1->EvalInstance(); for (UInt_t ivar=0; ivar<nvarsee; ++ivar) { valsee[ivar] = formsee1[ivar]->EvalInstance(); } } phregtarget = gbr->GetResponse(vals); ph1emvacor = phregtarget*den1; //printf("phregtarget = %5f, ph1emvacor = %5f\n",phregtarget,ph1emvacor); if (isb2) { gbr = gbreb; vals = valseb; den2 = denebform2->EvalInstance(); for (UInt_t ivar=0; ivar<nvarseb; ++ivar) { valseb[ivar] = formseb2[ivar]->EvalInstance(); } } else { gbr = gbree; vals = valsee; den2 = deneeform2->EvalInstance(); for (UInt_t ivar=0; ivar<nvarsee; ++ivar) { valsee[ivar] = formsee2[ivar]->EvalInstance(); } } phregtarget = gbr->GetResponse(vals); ph2emvacor = phregtarget*den2; massmvacor = TMath::Sqrt(2.0*ph1emvacor*ph2emvacor*(1.0-costhetaform->EvalInstance())); //massmvacorerr = 0.5*massmvacor*TMath::Sqrt(ph1emvacorerr*ph1emvacorerr/ph1emvacor/ph1emvacor + ph2emvacorerr*ph2emvacorerr/ph2emvacor/ph2emvacor); //massmvacorerrlo = 0.5*massmvacor*TMath::Sqrt(ph1emvacorerrlo*ph1emvacorerrlo/ph1emvacor/ph1emvacor + ph2emvacorerrlo*ph2emvacorerrlo/ph2emvacor/ph2emvacor); //massmvacorerrhi = 0.5*massmvacor*TMath::Sqrt(ph1emvacorerrhi*ph1emvacorerrhi/ph1emvacor/ph1emvacor + ph2emvacorerrhi*ph2emvacorerrhi/ph2emvacor/ph2emvacor); hmvacor->Fill(); } hmc->AddFriend(hmvacor); hmvacor->Write(); if (hmcsingle) { for (Long64_t i=0; i<hmcsingle->GetEntries(); ++i) { hmcsingle->LoadTree(i); float den; bool isbsingle = isbformsingle->EvalInstance(); if (isbsingle) { gbr = gbreb; vals = valseb; den = denebformsingle->EvalInstance(); for (UInt_t ivar=0; ivar<nvarseb; ++ivar) { valseb[ivar] = formsebsingle[ivar]->EvalInstance(); } } else { gbr = gbree; vals = valsee; den = deneeformsingle->EvalInstance(); for (UInt_t ivar=0; ivar<nvarsee; ++ivar) { valsee[ivar] = formseesingle[ivar]->EvalInstance(); } } phregtarget = gbr->GetResponse(vals); phemvacor = phregtarget*den; hmvacorsingle->Fill(); } hmcsingle->AddFriend(hmvacorsingle); hmvacorsingle->Write(); } } // }
void SkimClassification(TString process="ZnnH125") { gROOT->LoadMacro("HelperFunctions.h" ); // make functions visible to TTreeFormula gROOT->SetBatch(1); //TChain * chain = new TChain("tree"); //TString fname = ""; //TString dijet = "DiJetPt_"; //TString dirMC = "dcache:/pnfs/cms/WAX/resilient/jiafu/ZnunuHbb/" + tagMC + "/"; //TString dirData = "dcache:/pnfs/cms/WAX/resilient/jiafu/ZnunuHbb/" + tagData + "/"; TString indir = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Spring15_PU20bx25/skimV12_v2/step3/"; TString outdir = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Spring15_PU20bx25/skimV12_v2/step3/skim_ZnnH_classification/"; TString prefix = "Step3_"; TString suffix = ".root"; TFile *input = TFile::Open(indir + prefix + process + suffix); if (!input) { std::cout << "ERROR: Could not open input file." << std::endl; exit(1); } TTree *tree = (TTree *) input->Get("tree"); Long64_t entries = tree->GetEntriesFast(); // Make output directory if it doesn't exist if (gSystem->AccessPathName(outdir)) gSystem->mkdir(outdir); TString outname = outdir + prefix + Form("%s.root", process.Data()); TFile* output = TFile::Open(outname, "RECREATE"); // Get selections const std::vector < std::string > & selExpressions = GetSelExpressions("ZnunuHighPt") ; // const UInt_t nsels = 3; // ZnunuHighPt, ZnunuLowPt, ZnunuLowCSV const UInt_t nsels = 1; // just one now... ZnunuHighPt, ZnunuLowPt, ZnunuLowCSV // assert(nsels == selExpressions.size()); <-- fixME // even-number events for training, odd-number events for testing TCut evenselection = "evt %2 == 0"; TCut oddselection = "evt %2 == 1"; TTreeFormula *ttf = 0; std::vector < TTreeFormula * >::const_iterator formIt, formItEnd; // Loop over selections std::vector<Long64_t> ventries; for (unsigned int i = 0; i < nsels; i++) { TString selname = "ZnunuHighPt"; if (i == 1) { selname = "ZnunuMedPt"; // selExpressions = GetSelExpressions("ZnunuMedPt") ; } else if (i == 2) { selname = "ZnunuLowPt"; // selExpressions = GetSelExpressions("ZnunuLowPt") ; } TTree *t1 = (TTree*) tree->CloneTree(0); TTree *t2 = (TTree*) tree->CloneTree(0); t1->SetName(TString::Format("%s_%s_train", tree->GetName(), selname.Data())); t2->SetName(TString::Format("%s_%s", tree->GetName(), selname.Data())); // The clones should not delete any shared i/o buffers. ResetDeleteBranches(t1); ResetDeleteBranches(t2); ttf = new TTreeFormula(Form("ttfsel%i", i), selExpressions.at(i).c_str(), tree); ttf->SetQuickLoad(1); TTreeFormula *ttf1 = new TTreeFormula(Form("ttfeven%i", i), evenselection, tree); ttf1->SetQuickLoad(1); TTreeFormula *ttf2 = new TTreeFormula(Form("ttfodd%i", i), oddselection, tree); ttf2->SetQuickLoad(1); if (!ttf || !ttf->GetNdim()) { std::cerr << "ERROR: Failed to find any TTree variable from the selection: " << selExpressions.at(i) << std::endl; return; } /// Loop over events Int_t curTree = tree->GetTreeNumber(); const Long64_t nentries = tree->GetEntries(); for (Long64_t ievt = 0; ievt < nentries; ievt++) { Long64_t entryNumber = tree->GetEntryNumber(ievt); if (entryNumber < 0) break; Long64_t localEntry = tree->LoadTree(entryNumber); if (localEntry < 0) break; if (tree->GetTreeNumber() != curTree) { curTree = tree->GetTreeNumber(); ttf ->UpdateFormulaLeaves(); // if using TChain ttf1->UpdateFormulaLeaves(); // if using TChain ttf2->UpdateFormulaLeaves(); // if using TChain } const Int_t ndata = ttf->GetNdata(); Bool_t keep = kFALSE; for(Int_t current = 0; current<ndata && !keep; current++) { keep |= (bool(ttf->EvalInstance(current)) != 0); } if (!keep) continue; bool even = (bool) ttf1->EvalInstance(); bool odd = (bool) ttf2->EvalInstance(); if (even && odd) { std::cerr << "ERROR: An event cannot be even and odd at the same time." << std::cout; return; } tree->GetEntry(entryNumber, 1); // get all branches if (even) { t1->Fill(); } else { t2->Fill(); } } // end loop over events t1->Write(); t2->Write(); ventries.push_back(t1->GetEntriesFast() + t2->GetEntriesFast()); delete ttf; delete ttf1; delete ttf2; } std::clog << process << ": skimmed from " << entries << " to " << ventries[0] << " (ZnunuHighPt), " << ventries[1] << " (ZnunuLowPt), " << ventries[2] << " (ZnunuLowCSV) " << " entries." << std::endl; output->Close(); input->Close(); delete output; delete input; return; }
void GetOptimization() { struct path thisPath; std::vector<path> paths; std::vector<TString> pathNames; struct filter thisFilter; std::vector<filter> filters; std::vector<std::pair<std::vector<TString>,Double_t> > xSections; std::vector<TString> filenamesBkg; std::vector<TString> filenamesSig; /* Parameters */ Int_t nCuts = 120; Bool_t doBandE = true; // if true, do seperate for cuts in barrel and endcap Double_t luminosity = 2.0E33; // in cm^-2 s^-1 // Cross-sections in mb filenamesBkg.push_back("../test/QCD-HLTVars-1.root"); // filenamesBkg.push_back("sameXSection"); xSections.push_back(make_pair(filenamesBkg, 2.16E-2)); filenamesBkg.clear(); // filenamesBkg.push_back("newXSection.root"); // ... // xSections.push_back(make_pair(filenamesBkg, xSection)); // filenamesBkg.clear(); filenamesSig.push_back("../test/ZEE-HLTVars.root"); /* ********** */ // Filters thisFilter.name = "l1Match"; thisFilter.pathNum = 0; thisFilter.direction = 0; thisFilter.hltBarrelCut = 0.; thisFilter.hltEndcapCut = 0.; thisFilter.maxCut = 0.; filters.push_back(thisFilter); thisFilter.name = "Et"; thisFilter.pathNum = 0; thisFilter.direction = 1; thisFilter.hltBarrelCut = 15.; thisFilter.hltEndcapCut = 15.; thisFilter.maxCut = 60.; filters.push_back(thisFilter); thisFilter.name = "IHcal"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 3.; thisFilter.hltEndcapCut = 3.; thisFilter.maxCut = 6.; filters.push_back(thisFilter); thisFilter.name = "pixMatch"; thisFilter.pathNum = 0; thisFilter.direction = 1; thisFilter.hltBarrelCut = 0; thisFilter.hltEndcapCut = 0; thisFilter.maxCut = 0; filters.push_back(thisFilter); thisFilter.name = "Eoverp"; thisFilter.pathNum = 1; thisFilter.direction = -1; thisFilter.hltBarrelCut = 1.5; thisFilter.hltEndcapCut = 2.45; thisFilter.maxCut = 5.; filters.push_back(thisFilter); thisFilter.name = "Itrack"; thisFilter.pathNum = 1; thisFilter.direction = -1; thisFilter.hltBarrelCut = 0.06; thisFilter.hltEndcapCut = 0.06; thisFilter.maxCut = 0.24; filters.push_back(thisFilter); pathNames.push_back("SingleElecsPT."); pathNames.push_back("SingleElecs."); thisPath.names = pathNames; thisPath.nCandsCut = 1; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); pathNames.push_back("RelaxedSingleElecsPT."); pathNames.push_back("RelaxedSingleElecs."); thisPath.names = pathNames; thisPath.nCandsCut = 1; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); filters.clear(); thisFilter.name = "l1Match"; thisFilter.pathNum = 0; thisFilter.direction = 0; thisFilter.hltBarrelCut = 0.; thisFilter.hltEndcapCut = 0.; thisFilter.maxCut = 0.; filters.push_back(thisFilter); thisFilter.name = "Et"; thisFilter.pathNum = 0; thisFilter.direction = 1; thisFilter.hltBarrelCut = 10.; thisFilter.hltEndcapCut = 10.; thisFilter.maxCut = 40.; filters.push_back(thisFilter); thisFilter.name = "IHcal"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 9.; thisFilter.hltEndcapCut = 9.; thisFilter.maxCut = 18.; filters.push_back(thisFilter); thisFilter.name = "pixMatch"; thisFilter.pathNum = 0; thisFilter.direction = 1; thisFilter.hltBarrelCut = 0; thisFilter.hltEndcapCut = 0; thisFilter.maxCut = 0; filters.push_back(thisFilter); thisFilter.name = "Eoverp"; thisFilter.pathNum = 1; thisFilter.direction = -1; thisFilter.hltBarrelCut = 15000; thisFilter.hltEndcapCut = 24500; thisFilter.maxCut = 5.; filters.push_back(thisFilter); thisFilter.name = "Itrack"; thisFilter.pathNum = 1; thisFilter.direction = -1; thisFilter.hltBarrelCut = 0.4; thisFilter.hltEndcapCut = 0.4; thisFilter.maxCut = 0.12; filters.push_back(thisFilter); pathNames.push_back("DoubleElecsPT."); pathNames.push_back("DoubleElecs."); thisPath.names = pathNames; thisPath.nCandsCut = 2; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); pathNames.push_back("RelaxedDoubleElecsPT."); pathNames.push_back("RelaxedDoubleElecs."); thisPath.names = pathNames; thisPath.nCandsCut = 2; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); filters.clear(); thisFilter.name = "l1Match"; thisFilter.pathNum = 0; thisFilter.direction = 0; thisFilter.hltBarrelCut = 0.; thisFilter.hltEndcapCut = 0.; thisFilter.maxCut = 0.; filters.push_back(thisFilter); thisFilter.name = "Et"; thisFilter.pathNum = 0; thisFilter.direction = 1; thisFilter.hltBarrelCut = 30.; thisFilter.hltEndcapCut = 30.; thisFilter.maxCut = 60.; filters.push_back(thisFilter); thisFilter.name = "IEcal"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 1.5; thisFilter.hltEndcapCut = 1.5; thisFilter.maxCut = 6.; filters.push_back(thisFilter); thisFilter.name = "IHcal"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 4.; thisFilter.hltEndcapCut = 6.; thisFilter.maxCut = 12.; filters.push_back(thisFilter); thisFilter.name = "Itrack"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 1; thisFilter.hltEndcapCut = 1; thisFilter.maxCut = 5; filters.push_back(thisFilter); pathNames.push_back("SinglePhots."); thisPath.names = pathNames; thisPath.nCandsCut = 1; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); pathNames.push_back("RelaxedSinglePhots."); thisPath.names = pathNames; thisPath.nCandsCut = 1; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); filters.clear(); thisFilter.name = "l1Match"; thisFilter.pathNum = 0; thisFilter.direction = 0; thisFilter.hltBarrelCut = 0.; thisFilter.hltEndcapCut = 0.; thisFilter.maxCut = 0.; filters.push_back(thisFilter); thisFilter.name = "Et"; thisFilter.pathNum = 0; thisFilter.direction = 1; thisFilter.hltBarrelCut = 20.; thisFilter.hltEndcapCut = 20.; thisFilter.maxCut = 40.; filters.push_back(thisFilter); thisFilter.name = "IEcal"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 2.5; thisFilter.hltEndcapCut = 2.5; thisFilter.maxCut = 5.; filters.push_back(thisFilter); thisFilter.name = "IHcal"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 6.; thisFilter.hltEndcapCut = 8.; thisFilter.maxCut = 24.; filters.push_back(thisFilter); thisFilter.name = "Itrack"; thisFilter.pathNum = 0; thisFilter.direction = -1; thisFilter.hltBarrelCut = 3; thisFilter.hltEndcapCut = 3; thisFilter.maxCut = 6; filters.push_back(thisFilter); pathNames.push_back("DoublePhots."); thisPath.names = pathNames; thisPath.nCandsCut = 2; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); pathNames.push_back("RelaxedDoublePhots."); thisPath.names = pathNames; thisPath.nCandsCut = 2; thisPath.filters = filters; paths.push_back(thisPath); pathNames.clear(); filters.clear(); /* *********** */ Int_t cutNum = 0, pathNum = 0, filterNum = 0, oldFilterNum = 0, fileNum = 0, xSecNum = 0; Double_t cut = 0.; Long64_t passSig = 0, totalSig = 0; Long64_t passBkg = 0, totalBkg = 0; Double_t effSig = 0., errSig = 0.; Double_t effBkg = 0., errBkg = 0., rateTotBkg = 0., errTotBkg = 0.; Double_t conversion = 1.0E-27; std::vector<std::pair<Double_t,Double_t> > sigPass; std::vector<std::pair<Double_t,Double_t> > bkgPass; TString cutText; TString cutTextEcap; TString baseCutText; TString baseCutTextEcap; TString cutBasePT1; TString cutBasePT2; TString cutBase1; TString cutBase2; // cutBasePT1 = "ElecHLTCutVarsPreTracks_hltCutVars_"; // cutBasePT2 = "ElecsPT_EGAMMAHLT.obj."; // cutBase1 = ""; // cutBase2 = "Elecs_EGAMMAHLT.obj."; std::vector<std::vector<TGraphErrors> > EffVBkg; std::vector<std::vector<TGraphErrors> > EffVBkgEcap; std::vector<TGraphErrors> pathEffVBkgs; TGraphErrors filterEffVBkgs(nCuts); for (pathNum = 0; pathNum < paths.size(); pathNum++) { for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) { // filterEffVBkgs = new TGraphErrors(nCuts); pathEffVBkgs.push_back(filterEffVBkgs); } EffVBkg.push_back(pathEffVBkgs); if (doBandE) { EffVBkgEcap.push_back(pathEffVBkgs); } } std::vector<std::pair<TChain*,Double_t> > bkgEvents; for (xSecNum = 0; xSecNum < xSections.size(); xSecNum++) { TChain *bkgProc = new TChain("Events"); for (fileNum = 0; fileNum < (xSections[xSecNum].first).size(); fileNum++) { bkgProc->Add((xSections[xSecNum].first)[fileNum]); } bkgEvents.push_back(make_pair(bkgProc,xSections[xSecNum].second)); } TChain *sigEvents = new TChain("Events"); for (fileNum = 0; fileNum < filenamesSig.size(); fileNum++) { sigEvents->Add(filenamesSig[fileNum]); } Double_t testX, testY, testdX, testdY; Double_t thisBCut = 0., thisECut = 0.; TString pathName, filterName; for (cutNum = 0; cutNum < nCuts; cutNum++) { cout<<"Cut "<<cutNum<<endl; for (pathNum = 0; pathNum < paths.size(); pathNum++) { for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) { if ((paths[pathNum].filters)[filterNum].maxCut != 0.) { cutText = "(Sum$("; for (oldFilterNum = 0; oldFilterNum < filterNum; oldFilterNum++) { pathName = (paths[pathNum].names)[(paths[pathNum].filters)[filterNum].pathNum]; filterName = (paths[pathNum].filters)[oldFilterNum].name; thisBCut = (paths[pathNum].filters)[oldFilterNum].hltBarrelCut; thisECut = (paths[pathNum].filters)[oldFilterNum].hltEndcapCut; if (thisBCut == thisECut) { cutText += pathName; cutText += filterName; switch ((paths[pathNum].filters)[oldFilterNum].direction) { case -1: cutText += " < "; cutText += (paths[pathNum].filters)[oldFilterNum].hltBarrelCut; break; case 0: break; case 1: cutText += " > "; cutText += (paths[pathNum].filters)[oldFilterNum].hltBarrelCut; break; default: cout<<"Invalid value of direction in "<<pathName<<filterName<<endl; break; } } else { cutText += "(("; cutText += pathName; cutText += filterName; switch ((paths[pathNum].filters)[oldFilterNum].direction) { case -1: cutText += " < "; cutText += thisBCut; break; case 0: break; case 1: cutText += " > "; cutText += thisBCut; break; default: cout<<"Invalid value of direction in "<<pathName<<filterName<<endl; break; } cutText += " && abs("; cutText += pathName; cutText += "eta) < 1.5) || ("; cutText += pathName; cutText += filterName; switch ((paths[pathNum].filters)[oldFilterNum].direction) { case -1: cutText += " < "; cutText += thisECut; break; case 0: break; case 1: cutText += " > "; cutText += thisECut; break; default: cout<<"Invalid value of direction in "<<pathName<<filterName<<endl; break; } cutText += " && abs("; cutText += pathName; cutText += "eta) > 1.5 && abs("; cutText += pathName; cutText += "eta) < 2.5))"; } if (oldFilterNum != filterNum - 1) cutText += " && "; } baseCutText = cutText; pathName = paths[pathNum].names[(paths[pathNum].filters)[filterNum].pathNum]; filterName = (paths[pathNum].filters)[filterNum].name; cutText += " && "; cutText += pathName; cutText += filterName; cut = (Double_t)cutNum / (Double_t)nCuts * (paths[pathNum].filters)[oldFilterNum].maxCut; switch ((paths[pathNum].filters)[filterNum].direction) { case -1: cutText += " < "; cutText += cut; break; case 0: break; case 1: cutText += " > "; cutText += cut; break; default: cout<<"Invalid value of direction in "<<pathName<<filterName<<endl; break; } if (doBandE) { cutTextEcap = cutText; cutText += " && abs("; cutText += pathName; cutText += "eta) < 1.5"; cutTextEcap += " && abs("; cutTextEcap += pathName; cutTextEcap += "eta) > 1.5 && abs("; cutTextEcap += pathName; cutTextEcap += ") < 2.5"; baseCutText += " && abs("; baseCutText += pathName; baseCutTextEcap = baseCutText; baseCutText += "eta) < 1.5"; baseCutTextEcap += "eta) > 1.5 && abs("; baseCutTextEcap += pathName; baseCutTextEcap += "eta) < 2.5"; } cutText += ") >= "; cutText += paths[pathNum].nCandsCut; cutText += ")"; cutTextEcap += ") >= "; cutTextEcap += paths[pathNum].nCandsCut; cutTextEcap += ")"; baseCutText += ") >= "; baseCutText += paths[pathNum].nCandsCut; baseCutText += ")"; baseCutTextEcap += ") >= "; baseCutTextEcap += paths[pathNum].nCandsCut; baseCutTextEcap += ")"; cout<<cutText<<endl; cout<<cutTextEcap<<endl; // cout<<cutText<<endl; // cout<<baseCutText<<endl; passSig = sigEvents->Draw("",cutText); totalSig = sigEvents->Draw("",baseCutText); if (totalSig != 0) { effSig = (Double_t)passSig / (Double_t)totalSig; errSig = sqrt(effSig * (1. - effSig) / (Double_t)totalSig); } else { effSig = 0.; errSig = 0.; } rateTotBkg = 0.; errTotBkg = 0.; for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) { passBkg = bkgEvents[xSecNum].first->Draw("",cutText); totalBkg = bkgEvents[xSecNum].first->Draw("",""); if (totalBkg != 0) { effBkg = (Double_t)passBkg / (Double_t)totalBkg; errBkg = sqrt(effBkg * (1. - effBkg) / (Double_t)totalBkg); } else { effBkg = 0.; errBkg = 0.; } rateTotBkg += effBkg * bkgEvents[xSecNum].second * luminosity * conversion; errTotBkg = sqrt(errTotBkg * errTotBkg + errBkg * errBkg * bkgEvents[xSecNum].second * luminosity * conversion * bkgEvents[xSecNum].second * luminosity * conversion); } if (cutNum == 6) { cout<<cutText<<endl; cout<<rateTotBkg<<" +- "<<errTotBkg<<", "<<effSig<<" +- "<<errSig<<endl;; } EffVBkg[pathNum][filterNum].SetPoint(cutNum, rateTotBkg, effSig); EffVBkg[pathNum][filterNum].SetPointError(cutNum, errTotBkg, errSig); if (cutNum == 6) { EffVBkg[pathNum][filterNum].GetPoint(cutNum, testX, testY); cout<<testX<<", "<<testY<<endl; } if (doBandE) { passSig = sigEvents->Draw("",cutTextEcap); totalSig = sigEvents->Draw("",baseCutText); if (totalSig != 0) { effSig = (Double_t)passSig / (Double_t)totalSig; errSig = sqrt(effSig * (1. - effSig) / (Double_t)totalSig); } else { effSig = 0.; errSig = 0.; } rateTotBkg = 0.; errTotBkg = 0.; for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) { passBkg = bkgEvents[xSecNum].first->Draw("",cutText); totalBkg = bkgEvents[xSecNum].first->Draw("",""); if (totalBkg != 0) { effBkg = (Double_t)passBkg / (Double_t)totalBkg; errBkg = sqrt(effBkg * (1. - effBkg) / (Double_t)totalBkg); } else { effBkg = 0.; errBkg = 0.; } rateTotBkg += effBkg * bkgEvents[xSecNum].second * luminosity * conversion; errTotBkg = sqrt(errTotBkg * errTotBkg + errBkg * errBkg * bkgEvents[xSecNum].second * luminosity * conversion * bkgEvents[xSecNum].second * luminosity * conversion); } if (cutNum == 6) { cout<<cutText<<endl; cout<<rateTotBkg<<" +- "<<errTotBkg<<", "<<effSig<<" +- "<<errSig<<endl;; } EffVBkgEcap[pathNum][filterNum].SetPoint(cutNum, rateTotBkg, effSig); EffVBkgEcap[pathNum][filterNum].SetPointError(cutNum, errTotBkg, errSig); if (cutNum == 6) { EffVBkg[pathNum][filterNum].GetPoint(cutNum, testX, testY); cout<<testX<<", "<<testY<<endl; } } } } } } TCanvas *myCanvas; TString tempPathName, canvasTitle, graphTitle, outFilename; Int_t n; Int_t nGraphs, curGraph; for (pathNum = 0; pathNum < paths.size(); pathNum++) { canvasTitle = "Efficiency vs. Background for "; tempPathName = paths[pathNum].names[paths[pathNum].filters[(paths[pathNum].filters).size()-1].pathNum]; tempPathName.Resize(tempPathName.Index(".", 1, 0, TString::kExact)); outFilename = "./images/"; outFilename += tempPathName; outFilename += "EffVBkg.gif"; n = 0; while (tempPathName.Contains(TRegexp("[a-z][A-Z]")) && n < 10) { tempPathName.Insert(tempPathName.Index(TRegexp("[a-z][A-Z]"))+1, " "); n++; } canvasTitle += tempPathName; nGraphs = 0; for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) { if ((paths[pathNum].filters)[filterNum].maxCut != 0) nGraphs++; } myCanvas = new TCanvas("myCanvas", canvasTitle, 0, 0, 1000, 500*(nGraphs / 2 + 1)); myCanvas->Divide(2,nGraphs / 2 + 1); curGraph = 0; for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) { if ((paths[pathNum].filters)[filterNum].maxCut != 0.) { myCanvas->cd(curGraph+1); curGraph++; graphTitle = "Efficiency vs. Background for "; graphTitle += (paths[pathNum].filters)[filterNum].name; graphTitle += " Filter;Background Rate (Hz);Signal Eff."; EffVBkg[pathNum][filterNum].SetTitle(graphTitle); EffVBkg[pathNum][filterNum].Draw("AP"); } } myCanvas->Print(outFilename); if (doBandE) { canvasTitle = "Efficiency vs. Background for "; tempPathName = paths[pathNum].names[paths[pathNum].filters[(paths[pathNum].filters).size()-1].pathNum]; tempPathName.Resize(tempPathName.Index(".", 1, 0, TString::kExact)); tempPathName += "Endcap"; outFilename = "./images/"; outFilename += tempPathName; outFilename += "EffVBkg.gif"; n = 0; while (tempPathName.Contains(TRegexp("[a-z][A-Z]")) && n < 10) { tempPathName.Insert(tempPathName.Index(TRegexp("[a-z][A-Z]"))+1, " "); n++; } canvasTitle += tempPathName; nGraphs = 0; for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) { if ((paths[pathNum].filters)[filterNum].maxCut != 0) nGraphs++; } myCanvas = new TCanvas("myCanvas", canvasTitle, 0, 0, 1000, 500*(nGraphs / 2 + 1)); myCanvas->Divide(2,nGraphs / 2 + 1); curGraph = 0; for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) { if ((paths[pathNum].filters)[filterNum].maxCut != 0.) { myCanvas->cd(curGraph+1); curGraph++; graphTitle = "Efficiency vs. Background for "; graphTitle += (paths[pathNum].filters)[filterNum].name; graphTitle += " Filter in Endcap;Background Rate (Hz);Signal Eff."; EffVBkgEcap[pathNum][filterNum].SetTitle(graphTitle); EffVBkgEcap[pathNum][filterNum].Draw("AP"); } } myCanvas->Print(outFilename); } } TH1F *timingSig = new TH1F("timingSig", "Timing of Single Electron Filters in Signal Events", 6, 0, 6); timingSig->SetCanExtend(TH1::kAllAxes); timingSig->SetStats(0); TTreeFormula *l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",sigEvents); TTreeFormula *EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",sigEvents); TTreeFormula *IHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecIHcal",sigEvents); TTreeFormula *pixMatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.pixMatch",sigEvents); TTreeFormula *EoverpTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Eoverp",sigEvents); TTreeFormula *ItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecItrack",sigEvents); Long64_t event = 0; Double_t avgL1Match = 0.; Double_t avgEt = 0.; Double_t avgIHcal = 0.; Double_t avgPixMatch = 0.; Double_t avgEoverp = 0.; Double_t avgItrack = 0.; for (event = 0; event < sigEvents->GetEntries(); event++) { sigEvents->LoadTree(event); avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgIHcal = (event*avgIHcal + IHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgPixMatch = (event*avgPixMatch + pixMatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgEoverp = (event*avgEoverp + EoverpTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgItrack = (event*avgItrack + ItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); } timingSig->Fill("L1 Match", avgL1Match); timingSig->Fill("Et", avgEt); timingSig->Fill("IHcal", avgIHcal); timingSig->Fill("Pix Match", avgPixMatch); timingSig->Fill("E/p", avgEoverp); timingSig->Fill("Itrack", avgItrack); timingSig->LabelsDeflate("X"); timingSig->LabelsOption("v"); TH1F *timingBkg = new TH1F("timingBkg", "Timing of Single Electron Filters in Background Events", 6, 0, 6); timingBkg->SetCanExtend(TH1::kAllAxes); timingBkg->SetStats(0); avgL1Match = 0.; avgEt = 0.; avgIHcal = 0.; avgPixMatch = 0.; avgEoverp = 0.; avgItrack = 0.; for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) { delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",bkgEvents[xSecNum].first); delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",bkgEvents[xSecNum].first); delete IHcalTiming; IHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecIHcal",bkgEvents[xSecNum].first); delete pixMatchTiming; pixMatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.pixMatch",bkgEvents[xSecNum].first); delete EoverpTiming; EoverpTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Eoverp",bkgEvents[xSecNum].first); delete ItrackTiming; ItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecItrack",bkgEvents[xSecNum].first); event = 0; for (event = 0; event < bkgEvents[xSecNum].first->GetEntries(); event++) { bkgEvents[xSecNum].first->LoadTree(event); avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgIHcal = (event*avgIHcal + IHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgPixMatch = (event*avgPixMatch + pixMatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgEoverp = (event*avgEoverp + EoverpTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgItrack = (event*avgItrack + ItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); } } timingBkg->Fill("L1 Match", avgL1Match); timingBkg->Fill("Et", avgEt); timingBkg->Fill("IHcal", avgIHcal); timingBkg->Fill("Pix Match", avgPixMatch); timingBkg->Fill("E/p", avgEoverp); timingBkg->Fill("Itrack", avgItrack); timingBkg->LabelsDeflate("X"); timingBkg->LabelsOption("v"); myCanvas = new TCanvas("myCanvas", "Timing vs. Filter for Isolated Electron Filters", 1000, 500); myCanvas->Divide(2,1); myCanvas->cd(1); timingSig->Draw(); myCanvas->cd(2); timingBkg->Draw(); myCanvas->Print("images/TimingIso.gif"); delete myCanvas; delete timingSig; delete timingBkg; timingSig = new TH1F("timingSig", "Timing of Single Photon Filters in Signal Events", 6, 0, 6); timingSig->SetCanExtend(TH1::kAllAxes); timingSig->SetStats(0); delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",sigEvents); delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",sigEvents); TTreeFormula *IEcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.IEcal",sigEvents); TTreeFormula *PhotIHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotIHcal",sigEvents); TTreeFormula *PhotItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotItrack",sigEvents); event = 0; avgL1Match = 0.; avgEt = 0.; Double_t avgIEcal = 0.; Double_t avgPhotIHcal = 0.; Double_t avgPhotItrack = 0.; for (event = 0; event < sigEvents->GetEntries(); event++) { sigEvents->LoadTree(event); avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgIEcal = (event*avgIEcal + IEcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgPhotIHcal = (event*avgPhotIHcal + PhotIHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgPhotItrack = (event*avgPhotItrack + PhotItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); } timingSig->Fill("L1 Match", avgL1Match); timingSig->Fill("Et", avgEt); timingSig->Fill("IEcal", avgIEcal); timingSig->Fill("IHcal", avgPhotIHcal); timingSig->Fill("Itrack", avgPhotItrack); timingSig->LabelsDeflate("X"); timingSig->LabelsOption("v"); timingBkg = new TH1F("timingBkg", "Timing of Single Photon Filters in Background Events", 6, 0, 6); timingBkg->SetCanExtend(TH1::kAllAxes); timingBkg->SetStats(0); avgL1Match = 0.; avgEt = 0.; avgIEcal = 0.; avgPhotIHcal = 0.; avgPhotItrack = 0.; for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) { delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",bkgEvents[xSecNum].first); delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",bkgEvents[xSecNum].first); delete IEcalTiming; IEcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.IEcal",bkgEvents[xSecNum].first); delete PhotIHcalTiming; PhotIHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotIHcal",bkgEvents[xSecNum].first); delete PhotItrackTiming; PhotItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotItrack",bkgEvents[xSecNum].first); event = 0; for (event = 0; event < bkgEvents[xSecNum].first->GetEntries(); event++) { bkgEvents[xSecNum].first->LoadTree(event); avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgIEcal = (event*avgIEcal + IEcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgPhotIHcal = (event*avgPhotIHcal + PhotIHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); avgPhotItrack = (event*avgPhotItrack + PhotItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); } } timingBkg->Fill("L1 Match", avgL1Match); timingBkg->Fill("Et", avgEt); timingBkg->Fill("IEcal", avgIEcal); timingBkg->Fill("IHcal", avgPhotIHcal); timingBkg->Fill("Itrack", avgPhotItrack); timingBkg->LabelsDeflate("X"); timingBkg->LabelsOption("v"); myCanvas = new TCanvas("myCanvas", "Timing vs. Filter for Isolated Photon Filters", 1000, 500); myCanvas->Divide(2,1); myCanvas->cd(1); timingSig->Draw(); myCanvas->cd(2); timingBkg->Draw(); myCanvas->Print("images/TimingIsoPhot.gif"); }