int MC_Ratio(int leptonId, double* par1, int npar1bins, double* par2, int npar2bins, TString sel_den , TString sel_num, double cut_num , TString par_x , TString par_y , TString option ){ setTDRStyle(); /////////////// //Get the TTree /////////////// //Location of the .root file TString location2 = "/Users/GLP/Desktop/CERN_data/dyjetsnew/postprocessed/"; //Reading the tree // TChain* tree = new TChain("treeProducerSusyMultilepton"); //DY events //tree->Add(location+"DYJetsToLLM50_PU_S14_POSTLS170.root"); tree->Add(location2+"dyjets_good.root"); //Plot the result Long64_t n = tree->GetEntries(); //Path for input and output file. Written in FitDataPath.txt TString _path = "/Users/GLP/Dropbox/Physique/Master_Thesis/plots_root/MC_eff/"; ////////////////////// //Name for the plots// ////////////////////// TString _filetag = ""; TString pname; TString _pname; TString _par; TString _sel_num; TString _sel_den; TString _option; ////Writing string //particle string if(abs(leptonId) == 11){pname = "e"; _pname = "e";} if(abs(leptonId) == 13){pname = " #mu"; _pname = "mu";} //Parameter string if(par_x == "Pt"){_par = "P_{t}";} else if(par_x == "eta"){_par = "#eta";} else if(par_x == "phi"){_par = "#phi";} //sel_den string if((sel_den == "tightmva")&&(leptonId == 13)){cout<<"ERROR: no tightId MVA defined for the muon !"<<endl;return 1;} if(sel_den == "tightcut"){_sel_den = "tightcut";} else if(sel_den == "tightmva"){_sel_den = "tightmva";} else if(sel_den == "loose"){_sel_den = "loose";} else if(sel_den == ""){_sel_den = "";} else{cout<<"ERROR: wrong sel_denion !";return 1;} //sel_num string if((sel_num == "tightmva")&&(leptonId == 13)){cout<<"ERROR: no tightId MVA defined for the muon !"<<endl;return 1;} if(sel_num == "tightcut"){_sel_num = "tightcut";} else if(sel_num == "tightmva"){_sel_num = "tightmva";} else if(sel_num == ""){_sel_num = "";} else if(sel_num == "loose"){_sel_num = "loose";} else if(sel_num == "reliso3"){_sel_num = Form("reliso3_%0.3lf",cut_num);} else if(sel_num == "reliso4"){_sel_num = Form("reliso4_%0.3lf",cut_num);} else if(sel_num == "chiso3"){_sel_num = Form("chiso3_%0.3lf",cut_num);} else if(sel_num == "chiso4"){_sel_num = Form("chiso4_%0.3lf",cut_num);} else if(sel_num == "dxy"){_sel_num = Form("dxy_%0.3lf",cut_num);} else if(sel_num == "dz"){_sel_num = Form("dz_%0.3lf",cut_num);} else{cout<<"ERROR: wrong numerator name !";return 1;} //option string option.Append(" "); option.Prepend(" "); if(option.Contains(" ll ")){_option += "_ll";} if(option.Contains(" unmatched ")){_option += "_unmatched";} if(option.Contains(" alleta ")){_option += "_alleta";} if(option.Contains(" short ")){_option += "_short";} _option += "_"; //parameter range string TString _par1range; _par1range = Form("%0.3f_"+par_x+"%0.3f",par1[0],par1[npar1bins]); TString _par2range; _par2range = Form("%0.3f_"+par_y+"%0.3f",par2[0],par2[npar2bins]); ///////////////////////////////////// //Write the name of the output file// ///////////////////////////////////// TString _fname = "MCeff"+_filetag+_option+_pname+_par1range+"_"+_par2range+"_den_"+_sel_den+"_num_"+_sel_num; //Output file cout<<"going to create the file"<<endl; //Check if the file exists TFile *fcheck = TFile::Open(_path+_fname+".root", "READ"); if (fcheck) { cout << "File "<<_fname<<" exists ! Please change name" << endl; return 1; } TFile* file_out = new TFile(_path+_fname+".root","recreate"); cout<<"done ! "<<endl; //Declaration of histogram TH1D **histo_num = new TH1D*[npar2bins]; TH1D **histo_den = new TH1D*[npar2bins]; TH1D **eff = new TH1D*[npar2bins]; //Par1 distribution histogram TH1D** histo_par1 = new TH1D*[npar2bins]; //Distribution of the cut parameter whose efficiency is studied TH1D *histo_other_sel = new TH1D("histo_other_sel","h",5,0,5); TH1D *histo_good_sel = new TH1D("histo_good_sel","h",5,0,5); //Histo separate in Lep_good Lep_other // TH1D **histo_num_O = new TH1D*[npar2bins]; TH1D **histo_den_O = new TH1D*[npar2bins]; TH1D **eff_O = new TH1D*[npar2bins]; TH1D **histo_num_G = new TH1D*[npar2bins]; TH1D **histo_den_G = new TH1D*[npar2bins]; TH1D **eff_G = new TH1D*[npar2bins]; //Counter LepGood vs LepOther TH1D **histo_counter = new TH1D*[npar2bins]; TH1D **histo_counter_G_par1 = new TH1D*[npar2bins]; TH1D **histo_counter_O_par1 = new TH1D*[npar2bins]; TH1D **histo_counter_par1 = new TH1D*[npar2bins]; for(int _i = 0; _i < npar2bins; ++_i){ histo_num[_i] = new TH1D("histo_num","Pt",npar1bins,par1[0],par1[npar1bins]); histo_den[_i] = new TH1D("histo_den","Pt",npar1bins,par1[0],par1[npar1bins]); eff[_i] = new TH1D("eff","Pt",npar1bins,par1[0],par1[npar1bins]); // histo_par1[_i] = new TH1D("histo_par1","par1",npar1bins*25,par1[0],par1[npar1bins]); // histo_num_O[_i] = new TH1D("histo_num_O","Pt",npar1bins,par1[0],par1[npar1bins]); histo_den_O[_i] = new TH1D("histo_den_O","Pt",npar1bins,par1[0],par1[npar1bins]); eff_O[_i] = new TH1D("eff_O","Pt",npar1bins,par1[0],par1[npar1bins]); histo_num_G[_i] = new TH1D("histo_num_G","Pt",npar1bins,par1[0],par1[npar1bins]); histo_den_G[_i] = new TH1D("histo_den_G","Pt",npar1bins,par1[0],par1[npar1bins]); eff_G[_i] = new TH1D("eff_G","Pt",npar1bins,par1[0],par1[npar1bins]); histo_counter_G_par1[_i] = new TH1D("histo_counter_G_par1","count",npar1bins,par1[0],par1[npar1bins]); histo_counter_O_par1[_i] = new TH1D("histo_counter_O_par1","count",npar1bins,par1[0],par1[npar1bins]); histo_counter_par1[_i] = new TH1D("histo_counter_par1","count",npar1bins,par1[0],par1[npar1bins]); histo_counter[_i] = new TH1D("histo_counter","count",2,0,2); } //Event variables Int_t evt_id; Double_t scale; //Generated Double_t gen_phi[200]; Double_t gen_eta[200]; Double_t Pt[200]; Double_t m[200]; Int_t Id[200]; Int_t Mo[200]; Double_t charge[200]; Int_t status[200]; Int_t GrMa[200]; Int_t ngenPart; Int_t source[200]; Int_t pile_up; //not loose Int_t On; Int_t Oid[200]; Double_t Opt[200]; Double_t Om[200]; Double_t Oeta[200]; Double_t Ophi[200]; Int_t Oq[200]; Int_t Otight[200]; Int_t Otighte[200]; //Double_t Omvaid[200]; Int_t Oloose[200]; Double_t Oiso3[200]; Double_t Oiso4[200]; Double_t Ochiso3[200]; Double_t Ochiso4[200]; Double_t Odxy[200]; Double_t Odz[200]; //loose Int_t Gn; Int_t Gid[200]; Double_t Gpt[200]; Double_t Gm[200]; Double_t Geta[200]; Double_t Gphi[200]; Int_t Gq[200]; Int_t Gtight[200]; Int_t Gtighte[200]; Int_t Gloose[200]; Double_t Giso3[200]; Double_t Giso4[200]; Double_t Gchiso3[200]; Double_t Gchiso4[200]; Double_t Gdxy[200]; Double_t Gdz[200]; //Assigne branches tree->SetBranchAddress("evt_scale1fb", &scale); tree->SetBranchAddress("evt_id", &evt_id); //generated tree->SetBranchAddress("nGenPart", &ngenPart); tree->SetBranchAddress("GenPart_pdgId", &Id); tree->SetBranchAddress("GenPart_sourceId", &source); tree->SetBranchAddress("GenPart_eta", &gen_eta); tree->SetBranchAddress("GenPart_phi", &gen_phi); tree->SetBranchAddress("GenPart_pt", &Pt); tree->SetBranchAddress("GenPart_mass", &m); tree->SetBranchAddress("GenPart_charge", &charge); tree->SetBranchAddress("GenPart_status", &status); //not loose tree->SetBranchAddress("nLepOther",&On); tree->SetBranchAddress("LepOther_pdgId",&Oid); tree->SetBranchAddress("LepOther_pt",&Opt); tree->SetBranchAddress("LepOther_mass",&Om); tree->SetBranchAddress("LepOther_eta",&Oeta); tree->SetBranchAddress("LepOther_phi",&Ophi); tree->SetBranchAddress("LepOther_charge",&Oq); tree->SetBranchAddress("LepOther_tightId",&Otight); tree->SetBranchAddress("LepOther_eleCutIdCSA14_50ns_v1",&Otighte); tree->SetBranchAddress("LepOther_relIso03",&Oiso3); tree->SetBranchAddress("LepOther_relIso04",&Oiso4); tree->SetBranchAddress("LepOther_chargedHadRelIso03",&Ochiso3); tree->SetBranchAddress("LepOther_chargedHadRelIso04",&Ochiso4); tree->SetBranchAddress("LepOther_dxy",&Odxy); tree->SetBranchAddress("LepOther_dz",&Odz); //Loose tree->SetBranchAddress("nLepGood",&Gn); tree->SetBranchAddress("LepGood_pdgId",&Gid); tree->SetBranchAddress("LepGood_pt",&Gpt); tree->SetBranchAddress("LepGood_mass",&Gm); tree->SetBranchAddress("LepGood_eta",&Geta); tree->SetBranchAddress("LepGood_phi",&Gphi); tree->SetBranchAddress("LepGood_charge",&Gq); tree->SetBranchAddress("LepGood_tightId",&Gtight); tree->SetBranchAddress("LepGood_eleCutIdCSA14_50ns_v1",&Gtighte); tree->SetBranchAddress("LepGood_relIso03",&Giso3); tree->SetBranchAddress("LepGood_relIso04",&Giso4); tree->SetBranchAddress("LepGood_chargedHadRelIso03",&Gchiso3); tree->SetBranchAddress("LepGood_chargedHadRelIso04",&Gchiso4); tree->SetBranchAddress("LepGood_dxy",&Gdxy); tree->SetBranchAddress("LepGood_dz",&Gdz); int count = 0; //Count lepgood/other int goodcount = 0; int othercount = 0; if(option.Contains(" short ")){n = 100000;} //Start loop over all events for (int k = 0; k < n; ++k) { //Declaration of event parameters Int_t evtn; Int_t evtloose[200]; Int_t evtid[200]; Double_t evtpt[200]; Double_t evtm[200]; Double_t evteta[200]; Double_t evtphi[200]; Int_t evtq[200]; Int_t evttight[200]; Int_t evttighte[200]; Double_t evtiso3[200]; Double_t evtiso4[200]; Double_t evtchiso3[200]; Double_t evtchiso4[200]; Double_t evtdxy[200]; Double_t evtdz[200]; if( 100*(double)k/n> count){cout<<count<<endl;++count;} tree->GetEntry(k); //Selection on denominator for(int j = 0; j < Gn+On; ++j){ //Separate here other from loose if(j < On){ evtloose[j] = 0; evtid[j] = Oid[j]; evtpt[j] = Opt[j]; evtm[j] = Om[j]; evteta[j] = Oeta[j]; evtphi[j] = Ophi[j]; evtq[j] = Oq[j]; evttight[j] = Otight[j]; evttighte[j] = Otighte[j]; evtiso3[j] = Oiso3[j]; evtiso4[j] = Oiso4[j]; evtchiso3[j] = Ochiso3[j]; evtchiso4[j] = Ochiso4[j]; evtdxy[j] = Odxy[j]; evtdz[j] = Odz[j]; }else if((j >= On)&&(j < Gn+On)){ evtloose[j] = 1; evtid[j] = Gid[j-On]; evtpt[j] = Gpt[j-On]; evtm[j] = Gm[j-On]; evteta[j] = Geta[j-On]; evtphi[j] = Gphi[j-On]; evtq[j] = Gq[j-On]; evttight[j] = Gtight[j-On]; evttighte[j] = Gtighte[j-On]; evtiso3[j] = Giso3[j-On]; evtiso4[j] = Giso4[j-On]; evtchiso3[j] = Gchiso3[j-On]; evtchiso4[j] = Gchiso4[j-On]; evtdxy[j] = Gdxy[j-On]; evtdz[j] = Gdz[j-On]; } if((!option.Contains(" ll "))||((option.Contains(" ll "))&&(Gn+On == 2)&&(evtq[0] == -evtq[1]))){ if(abs(evtid[j]) == leptonId){ //Cut on the denominator //if((sel_den != "loose")||(evtloose[j] == 1)){ //if(evtloose[j] == 1){ if((sel_den != "tightcut")||(((abs(evtid[j]) == 13)&&(sel_den == "tightcut")&&(evttight[j] == 1 ))||((abs(evtid[j]) == 11)&&(sel_den == "tightcut")&&(evttighte[j] >= 3)))){ if((sel_den != "tightmva")||((abs(evtid[j]) == 11)&&(sel_den == "tightmva")&&(evttight[j] == 1))){ //Veto the EE-EB gape //Variable for matching double R = 999; double delta_P = 999; double delta_charge = 999; //Parameter on the xaxis double par; double par_2; //loop over all generated particles to do the matching for (int i = 0; i < ngenPart; ++i) { if((abs(Id[i]) == leptonId)){ //Electrons selection double R2 = DeltaR(gen_eta[i],evteta[j],gen_phi[i],evtphi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(evtpt[j]-Pt[i])/Pt[i]; delta_charge = abs(evtq[j] - charge[i]); } } } //Choose the parameter to be filled for the eff. if(par_x == "Pt"){par = evtpt[j];} else if(par_x == "eta"){par = evteta[j];} else if(par_x == "phi"){par = evtphi[j];} if(par_y == "Pt"){par_2 = evtpt[j];} else if(par_y == "eta"){par_2 = abs(evteta[j]);} else if(par_y == "phi"){par_2 = abs(evtphi[j]);} //Fill Pt only for matched events if(((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5))||option.Contains(" unmatched ")){ for(int ii = 0; ii < npar2bins; ++ii){ if((par_2 > par2[ii])&&(par_2 <= par2[ii+1])){histo_den[ii]->Fill(par);histo_par1[ii]->Fill(par); if(evtloose[j] == 1){histo_good_sel->Fill(evttighte[j]);} else if(evtloose[j] == 0){histo_other_sel->Fill(evttighte[j]);} else{cout<<"Error !"<<endl; return 1;} } } //Additional cut on the numerator int a = 0; if((sel_num == "tightcut")&&(abs(evtid[j]) == 13)&&(evttight[j] == 1)){a = 1;} if((sel_num == "tightcut")&&(abs(evtid[j]) == 11)&&(evttighte[j] >= 3)){a = 1;} if((sel_num == "reliso3")&&(evtiso3[j] <= cut_num)){a = 2;} if((sel_num == "reliso4")&&(evtiso4[j] <= cut_num)){a = 3;} if((sel_num == "chiso3")&&(evtchiso3[j] <= cut_num)){a = 4;} if((sel_num == "chiso4")&&(evtchiso4[j] <= cut_num)){a = 5;} if((sel_num == "dxy")&&(abs(evtdxy[j]) <= cut_num)){a = 6;} if((sel_num == "dz")&&(abs(evtdz[j]) <= cut_num)){a = 7;} if((sel_num == "tightmva")&&(abs(evtid[j]) == 11)&&(evttight[j] == 1)){a = 9;} if((sel_num == "loose")&&(evtloose[j]) == 1){a = 8;} //Find the corresponding histogram for par2 TH1D* hist; TH1D* hist_evt; bool found = false; for(int _i = 0; _i < npar2bins; ++_i){ if((par_2 > par2[_i])&&(par_2 <= par2[_i+1])){hist = histo_num[_i];found = true;} } if(!found){a = 0;} switch(a){ case 0: break; case 1: hist->Fill(par); break; case 2: hist->Fill(par); break; case 3: hist->Fill(par); break; case 4: hist->Fill(par); break; case 5: hist->Fill(par); break; case 6: hist->Fill(par); break; case 7: hist->Fill(par); break; case 8: hist->Fill(par); break; case 9: hist->Fill(par); break; } } } } } //} } } } mkdir(_path+_fname+"_PDF/", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); /////////////////// //Draw histograms// /////////////////// //Canvas declaration for(int i = 0; i < npar2bins; ++i){ //////////////////// //Build histograms// //////////////////// histo_num[i]->Sumw2(); histo_den[i]->Sumw2(); eff[i]->Divide(histo_num[i],histo_den[i],1,1,"B"); //histo_num_O[i]->Sumw2(); //histo_den_O[i]->Sumw2(); //eff_O[i]->Divide(histo_num_O[i],histo_den_O[i],1,1,"B"); //histo_num_G[i]->Sumw2(); //histo_den_G[i]->Sumw2(); //eff_G[i]->Divide(histo_num_G[i],histo_den_G[i],1,1,"B"); //histo_counter_G_par1[i]->Sumw2(); //histo_counter_O_par1[i]->Sumw2(); //histo_counter_par1[i]->Divide(histo_counter_O_par1[i],histo_counter_G_par1[i],1,1,"B"); //histo_counter[i]->Fill(0.5,goodcount); //histo_counter[i]->Fill(1.5,othercount); //String for name of the ouput files and histograms titles // TString _parybin; //Parameter string if(par_y == "Pt"){_parybin = Form("%0.f_Pt%0.f",par2[i],par2[i+1]);} else if(par_y == "eta"){_parybin = Form("%0.3f_eta%0.3f",par2[i],par2[i+1]);cout<<"it works !"<<endl;} else if(par_y == "phi"){_parybin = Form("%0.3f_phi%0.3f",par2[i],par2[i+1]);} TString _parytitle; //Title string if(par_y == "Pt"){_parytitle = Form("%0.f #leq P_{t} #leq %0.f",par2[i],par2[i+1]);} else if(par_y == "eta"){_parytitle = Form("%0.3f #leq #||{#eta} #leq %0.3f",par2[i],par2[i+1]);cout<<"it works !"<<endl;} else if(par_y == "phi"){_parytitle = Form("%0.3f #leq #||{#phi} #leq %0.3f",par2[i],par2[i+1]);} //Draw histograms TCanvas* c1 = new TCanvas("c1","c1"); c1->cd(); eff[i]->Draw(); eff[i]->GetYaxis()->SetTitle("#epsilon"); eff[i]->GetXaxis()->SetTitle(_par); eff[i]->GetYaxis()->SetRangeUser(0,1.1); eff[i]->SetMarkerStyle(20); eff[i]->SetMarkerSize(1); eff[i]->SetMarkerColor(4); eff[i]->SetLineColor(4); eff[i]->SetTitle(_sel_num+" for "+_sel_den+" "+pname+" "+_parytitle); TCanvas* c_par1 = new TCanvas("cpar1","cpar1"); TString _partitle = _par + (TString)" distribution for "+pname+", "+_parytitle+", "+sel_num; c_par1->cd(); histo_par1[i]->Draw(); histo_par1[i]->SetTitle(_partitle); histo_par1[i]->GetXaxis()->SetTitle(_par); histo_par1[i]->SetLineWidth(2); histo_par1[i]->SetLineColor(4); histo_par1[i]->SetMarkerColor(4); histo_good_sel->Add(histo_other_sel); TCanvas* csel = new TCanvas("csel","csel"); csel->cd(); histo_good_sel->Draw(); ///////////////////// //Saving the output// ///////////////////// //Write pdf TString cname = "eff"+_filetag+_option+_pname+_par1range+"_"+_parybin+"_den_"+_sel_den+"_num_"+_sel_num; c1->SaveAs(_path+_fname+"_PDF/"+cname+".pdf"); c_par1->SaveAs(_path+_fname+"_PDF/"+cname+"par_distr.pdf"); csel->SaveAs(_path+_fname+"_PDF/"+cname+"sel.pdf"); //Write in output file file_out->cd(); eff[i]->Write("eff"+_parybin); histo_good_sel->Write("sel"+_parybin); //histo_par1[i]->Write("histo_par1_"+_parybin); } file_out->Close(); return 0; }
int Compare(TString option = "short"){ //Retrieve the trees TString location = "/Users/GLP/Desktop/CERN_data/dyjetsnew/postprocessed/"; TChain* tree_new = new TChain("treeProducerSusyMultilepton"); TChain* tree_good = new TChain("treeProducerSusyMultilepton"); tree_good->Add(location+"dyjets_good.root"); tree_new->Add(location+"dyjetsnew.root"); Int_t ngood = tree_good->GetEntries(); Int_t nnew = tree_new->GetEntries(); map<int, vector<Event> > map_good; map<int, vector<Event> > map_new = getdyjetsnewmap(tree_new, option); ///////////////////// //Define histograms// ///////////////////// TH1D* h_dRlep = new TH1D("h_dRlep","h",50,-10,10); TH1D* h_dGenlep = new TH1D("h_dGenlep","h",50,-10,10); TH1D* h_dRmatch = new TH1D("h_dRmatch","h",50,-10,10); /////////////// //dyjets_new // /////////////// //Event variables Int_t evt; //Generated Double_t gen_phi[200]; Double_t gen_eta[200]; Double_t Pt[200]; Double_t m[200]; Int_t Id[200]; Int_t Mo[200]; Double_t charge[200]; Int_t status[200]; Int_t GrMa[200]; Int_t ngenPart; Int_t source[200]; //not loose Int_t On; Int_t Oid[200]; Double_t Opt[200]; Double_t Oeta[200]; Double_t Ophi[200]; Int_t Otighte[200]; Int_t Otight[200]; //loose Int_t Gn; Int_t Gid[200]; Double_t Gpt[200]; Double_t Geta[200]; Double_t Gphi[200]; Int_t Gtighte[200]; Int_t Gtight[200]; tree_good->SetBranchAddress("evt", &evt); //generated tree_good->SetBranchAddress("nGenPart", &ngenPart); tree_good->SetBranchAddress("GenPart_pdgId", &Id); tree_good->SetBranchAddress("GenPart_motherId", &Mo); tree_good->SetBranchAddress("GenPart_eta", &gen_eta); tree_good->SetBranchAddress("GenPart_phi", &gen_phi); tree_good->SetBranchAddress("GenPart_pt", &Pt); //not loose tree_good->SetBranchAddress("nLepOther",&On); tree_good->SetBranchAddress("LepOther_pdgId",&Oid); tree_good->SetBranchAddress("LepOther_pt",&Opt); tree_good->SetBranchAddress("LepOther_eta",&Oeta); tree_good->SetBranchAddress("LepOther_phi",&Ophi); tree_good->SetBranchAddress("LepOther_tightId",&Otight); tree_good->SetBranchAddress("LepOther_eleCutIdCSA14_50ns_v1",&Otighte); //Loose tree_good->SetBranchAddress("nLepGood",&Gn); tree_good->SetBranchAddress("LepGood_pdgId",&Gid); tree_good->SetBranchAddress("LepGood_pt",&Gpt); tree_good->SetBranchAddress("LepGood_eta",&Geta); tree_good->SetBranchAddress("LepGood_phi",&Gphi); tree_good->SetBranchAddress("LepGood_tightId",&Gtight); tree_good->SetBranchAddress("LepGood_eleCutIdCSA14_50ns_v1",&Gtighte); if(option == "short"){ngood = 10000;} for (int k = 0; k < ngood; ++k){ //Check if event is contained in the map_new tree_good->GetEntry(k); if(map_new.count(evt) > 0){ //cout<<"is contained !"<<endl; //Declaration of Event parameters Int_t evtloose[200]; Int_t evtid[200]; Double_t evtpt[200]; Double_t evteta[200]; Double_t evtphi[200]; Int_t evttighte[200]; Int_t evttight[200]; //run in all leptons in the events to store vector of pt vector<Event> vect; Event ev; for(int j = 0; j < Gn+On; ++j){ //cout<<"LepGood + LepOther is "<<Gn+On<<endl; //Loose events if(j < On){ evtloose[j] = 0; evtid[j] = Oid[j]; evtpt[j] = Opt[j]; evteta[j] = Oeta[j]; evtphi[j] = Ophi[j]; evttighte[j] = Otighte[j]; evttight[j] = Otight[j]; //Good events }else if((j >= On)&&(j < Gn+On)){ evtloose[j] = 1; evtid[j] = Gid[j-On]; evtpt[j] = Gpt[j-On]; evteta[j] = Geta[j-On]; evtphi[j] = Gphi[j-On]; evttighte[j] = Gtighte[j-On]; evttight[j] = Gtight[j-On]; } if(abs(evtid[j]) == 13){//Only interested in electrons //Variable for matching double R = 999; double delta_P = 999; int nlep = 0;//count the number of generated leptons //loop over all generated particles to do the matching for (int i = 0; i < ngenPart; ++i) {//to count the number of electrons in the genpart //if((abs(Id[i]) == 13)&&(abs(Mo[i]) != 15)){ if((abs(Id[i]) == 13)){ ++nlep; if(Id[i] == evtid[j]){ //Electrons selection double R2 = DeltaR(gen_eta[i],evteta[j],gen_phi[i],evtphi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(evtpt[j]-Pt[i])/Pt[i]; } } } } //This is only filled if the rec particle is an electron ev.DR = R; ev.NGEN = nlep; ev.PHI = evtphi[j]; ev.ETA = evteta[j]; ev.PT = evtpt[j]; vect.push_back(ev); } } //cout<<"Good: The size of the event "<<evt<<" is "<<vect.size()<<endl; //Put vector in increasing pt order sort(vect.begin(),vect.end(),mycompare); //Add vector to the map with the corresponding evt number map_good[evt] = vect; //////////////////////// //Compare the two maps// //////////////////////// if(map_good[evt].size() == map_new[evt].size()){//Should have same number of lepton in the events for(int i = 0; i< map_good[evt].size();++i){ double dRlep = 9999;//The difference between the _new and _good leptons int dGenlep = 9999;//The difference of the number of generated lep double dRmatch = 9999;//The diffrence of the matching dR between two leptons dRlep = DeltaR(map_new[evt][i].ETA,map_good[evt][i].ETA,map_new[evt][i].PHI,map_new[evt][i].PHI); dGenlep = map_new[evt][i].NGEN - map_good[evt][i].NGEN; dRmatch = (map_new[evt][i].DR - map_good[evt][i].DR); if(dRlep != 0){dRlep = dRlep/map_new[evt][i].DR;} h_dRlep->Fill(dRlep); h_dGenlep->Fill(dGenlep); h_dRmatch->Fill(dRmatch); if((dRlep !=0)||(dGenlep != 0)||(dRmatch != 0)){ cout<<"this is the event "<<evt<<endl; cout<<"the pt of the new is "<<map_new[evt][i].PT<<endl; cout<<"the pt of the good is "<<map_good[evt][i].PT<<endl; cout<<"the phi of the new is "<<map_new[evt][i].PHI<<endl; cout<<"the phi of the good is "<<map_good[evt][i].PHI<<endl; cout<<"the eta of the new is "<<map_new[evt][i].ETA<<endl; cout<<"the eta of the good is "<<map_good[evt][i].ETA<<endl; cout<<"dRmatch is "<<dRmatch<<endl; cout<<"dGenlep is "<<dGenlep<<endl; cout<<"dRlep is "<<dRlep<<endl; cout<<""<<endl; if(dGenlep == 0){cout<<"Error, same number of genlep and different !"<<endl;return 1;} } } }else{cout<<"Error have different size !"<<endl; //cout<<"This happens in event "<<evt<<endl; //cout<<"Size of the new is "<<map_new[evt].size()<<endl; //cout<<"Size of the good is "<<map_good[evt].size()<<endl; return 1;} } } /////////////////////// //Plot the histograms// /////////////////////// TCanvas* c1 = new TCanvas("c1","c1"); h_dRlep->Draw(); TCanvas* c2 = new TCanvas("c2","c2"); h_dGenlep->Draw(); TCanvas* c3 = new TCanvas("c3","c3"); h_dRmatch->Draw(); return 0; }
int MC_Ratio(int leptonId, double par_low, double par_upp, int nbins, TString sel_den , TString sel_num, double cut_den = 0., double cut_num = 0., TString par_x = "Pt", TString option = ""){ setTDRStyle(); /////////////// //Get the TTree /////////////// //Location of the .root file TString location = "/Users/GLP/Desktop/CERN_data/2014-11-13_skim2ll-mva-softbtag/postprocessed/"; //Reading the tree // TChain* tree = new TChain("treeProducerSusyMultilepton"); //DY events tree->Add(location+"DYJetsToLLM50_PU_S14_POSTLS170.root"); //Plot the result Long64_t n = tree->GetEntries(); //Path for input and output file. Written in FitDataPath.txt TString _path = "/Users/GLP/Dropbox/Physique/Master_Thesis/plots_root/MC_ratio/"; ////////////////////// //Name for the plots// ////////////////////// TString pname; TString _pname; TString _par; TString _sel_num; TString _sel_den; TString _cut_den; TString _option; //Writing string if (leptonId == 11) {pname = "e";_pname = "e";} else if (leptonId == 13){pname = " #mu";_pname = "mu";} if(par_x == "Pt"){_par = "P_{t}";} else if(par_x == "eta"){_par = "#eta";} else if(par_x == "phi"){_par = "#phi";} else{cout<<"ERROR: wrong parameter name !";return 1;} if(sel_num == ""){_sel_num = "unsel";} else if(sel_num == "tight"){_sel_num = "tight";} else if(sel_num == "tightmva"){_sel_num = "tightmva";} if((sel_num == "tightmva")&&(leptonId == 13)){cout<<"ERROR: no tightId MVA defined for the muon !";return 1;} //else if(sel_num == "mvaid"){_sel_num = Form("tightmva%0.3lf",cut_num) ;} else if(sel_num == "loose"){_sel_num = "loose";} else if(sel_num == "reliso3"){_sel_num = Form("reliso3_%0.3lf",cut_num);} else if(sel_num == "reliso4"){_sel_num = Form("reliso4_%0.3lf",cut_num);} else if(sel_num == "chiso3"){_sel_num = Form("chiso3_%0.3lf",cut_num);} else if(sel_num == "chiso4"){_sel_num = Form("chiso4_%0.3lf",cut_num);} else if(sel_num == "dxy"){_sel_num = Form("dxy_%0.3lf",cut_num);} else if(sel_num == "dz"){_sel_num = Form("dz_%0.3lf",cut_num);} else{cout<<"ERROR: wrong numerator name !";return 1;} //Selection on the denominator if(sel_den == ""){_sel_den = "unsel";} else if(sel_den == "tight"){_sel_den = "tight";} else if(sel_den == "tightmva"){_sel_den = "tightmva";} if((sel_den == "tightmva")&&(leptonId == 13)){cout<<"ERROR: no tightId MVA defined for the muon !";return 1;} //else if(sel_den == "mvaid"){_sel_den = Form("tightmva%0.3lf",cut_den) ;} else if(sel_den == "loose"){_sel_den = "loose";} else{cout<<"ERROR: wrong denominator selection name !";return 1;} option.Append(" "); option.Prepend(" "); if(option.Contains(" ll ")){_option += "_ll";} if(option.Contains(" unmatched ")){_option += "_unmatched";} if(option.Contains(" alleta ")){_option += "_alleta";} _option += "_"; //Name of the output //TString _fname = file_name("eff3",leptonId, par_low,par_upp,sel_den,sel_num,cut_den,cut_num,par_x,option); //TString _output= _path+_fname + ".root"; TString _output = _path+"eff4"+_option+_pname+"_den_"+_sel_den+"_num_"+_sel_num+"_"+par_x+".root"; //Declaration of histogram // //Preparation for general range in eta/pt //TH1D **histo_num = new TH1D*[nrange]; //TH1D **histo_den = new TH1D*[nrange]; //TH1D **eff = new TH1D*[nrange]; //int nrange = 3; //double par2[nrange] = {0,1.2,2.4}; //for(int _i = 0; _i < nrange; ++_i){ // //Barrel // histo_num[_i] = new TH1D("histo_num","Pt",nbins,min(par_low,0.),par_upp); // histo_den[_i] = new TH1D("histo_den","Pt",nbins,min(par_low,0.),par_upp); // eff[_i] = new TH1D("eff","Pt",nbins,min(par_low,0.),par_upp); // //} //efficiency of the isolation cut TH1D *histo_numB= new TH1D("histo_numB","Pt",nbins,min(par_low,0.),par_upp); TH1D *histo_denB= new TH1D("histo_denB","Pt",nbins,min(par_low,0.),par_upp); TH1D *histo_numE= new TH1D("histo_numE","Pt",nbins,min(par_low,0.),par_upp); TH1D *histo_denE= new TH1D("histo_denE","Pt",nbins,min(par_low,0.),par_upp); //Histo in all eta region TH1D *histo_num= new TH1D("histo_num","Pt",nbins,min(par_low,0.),par_upp); TH1D *histo_den= new TH1D("histo_den","Pt",nbins,min(par_low,0.),par_upp); //efficiency of the selection TH1D* effB = new TH1D ("effB","Pt",nbins,min(par_low,0.),par_upp); TH1D* effE = new TH1D ("effE","Pt",nbins,min(par_low,0.),par_upp); //efficiency all eta TH1D* eff = new TH1D ("eff","Pt",nbins,min(par_low,0.),par_upp);k //Event variables Int_t evt_id; Float_t scale; //Generated Float_t gen_phi[200]; Float_t gen_eta[200]; Float_t Pt[200]; Float_t m[200]; Int_t Id[200]; Int_t Mo[200]; Float_t charge[200]; Int_t status[200]; Int_t GrMa[200]; Int_t ngenPart; Int_t source[200]; Int_t pile_up; //not loose Int_t On; Int_t Oid[200]; Float_t Opt[200]; Float_t Om[200]; Float_t Oeta[200]; Float_t Ophi[200]; Int_t Oq[200]; Int_t Otight[200]; Int_t Otighte[200]; //Float_t Omvaid[200]; Int_t Oloose[200]; Float_t Oiso3[200]; Float_t Oiso4[200]; Float_t Ochiso3[200]; Float_t Ochiso4[200]; Float_t Odxy[200]; Float_t Odz[200]; //loose Int_t Gn; Int_t Gid[200]; Float_t Gpt[200]; Float_t Gm[200]; Float_t Geta[200]; Float_t Gphi[200]; Int_t Gq[200]; Int_t Gtight[200]; Int_t Gtighte[200]; //Float_t Gmvaid[200]; Int_t Gloose[200]; Float_t Giso3[200]; Float_t Giso4[200]; Float_t Gchiso3[200]; Float_t Gchiso4[200]; Float_t Gdxy[200]; Float_t Gdz[200]; //Assigne branches tree->SetBranchAddress("evt_scale1fb", &scale); tree->SetBranchAddress("evt_id", &evt_id); //generated tree->SetBranchAddress("ngenLep", &ngenPart); tree->SetBranchAddress("genLep_pdgId", &Id); tree->SetBranchAddress("genLep_sourceId", &source); tree->SetBranchAddress("genLep_eta", &gen_eta); tree->SetBranchAddress("genLep_phi", &gen_phi); tree->SetBranchAddress("genLep_pt", &Pt); tree->SetBranchAddress("genLep_mass", &m); tree->SetBranchAddress("genLep_charge", &charge); tree->SetBranchAddress("genLep_status", &status); tree->SetBranchAddress("nTrueInt",&pile_up); //not loose tree->SetBranchAddress("nLepOther",&On); tree->SetBranchAddress("LepOther_pdgId",&Oid); tree->SetBranchAddress("LepOther_pt",&Opt); tree->SetBranchAddress("LepOther_mass",&Om); tree->SetBranchAddress("LepOther_eta",&Oeta); tree->SetBranchAddress("LepOther_phi",&Ophi); tree->SetBranchAddress("LepOther_charge",&Oq); tree->SetBranchAddress("LepOther_tightId",&Otight); tree->SetBranchAddress("LepOther_eleCutIdCSA14_50ns_v1",&Otighte); //tree->SetBranchAddress("LepOther_mvaId",&Omvaid); tree->SetBranchAddress("LepOther_looseIdSusy",Oloose); tree->SetBranchAddress("LepOther_relIso03",&Oiso3); tree->SetBranchAddress("LepOther_relIso04",&Oiso4); tree->SetBranchAddress("LepOther_chargedHadRelIso03",&Ochiso3); tree->SetBranchAddress("LepOther_chargedHadRelIso04",&Ochiso4); tree->SetBranchAddress("LepOther_dxy",&Odxy); tree->SetBranchAddress("LepOther_dz",&Odz); //Loose tree->SetBranchAddress("nLepGood",&Gn); tree->SetBranchAddress("LepGood_pdgId",&Gid); tree->SetBranchAddress("LepGood_pt",&Gpt); tree->SetBranchAddress("LepGood_mass",&Gm); tree->SetBranchAddress("LepGood_eta",&Geta); tree->SetBranchAddress("LepGood_phi",&Gphi); tree->SetBranchAddress("LepGood_charge",&Gq); tree->SetBranchAddress("LepGood_tightId",&Gtight); tree->SetBranchAddress("LepGood_eleCutIdCSA14_50ns_v1",&Gtighte); //tree->SetBranchAddress("LepGood_mvaId",&Gmvaid); tree->SetBranchAddress("LepGood_looseIdSusy",&Gloose); tree->SetBranchAddress("LepGood_relIso03",&Giso3); tree->SetBranchAddress("LepGood_relIso04",&Giso4); tree->SetBranchAddress("LepGood_chargedHadRelIso03",&Gchiso3); tree->SetBranchAddress("LepGood_chargedHadRelIso04",&Gchiso4); tree->SetBranchAddress("LepGood_dxy",&Gdxy); tree->SetBranchAddress("LepGood_dz",&Gdz); int count = 0; //Start loop over all events for (int k = 0; k < 100000; ++k) { if( 100*(double)k/n> count){cout<<count<<endl;++count;} tree->GetEntry(k); //loop on loose if(sel_den != "loose"){ for(int j=0; j<On;++j){ if((!option.Contains(" ll "))||((option.Contains(" ll "))&&(On == 2)&&(Oid[0] == -Oid[1]))){ if(abs(Oid[j]) == leptonId){ if((sel_den != "tight")||((sel_den == "tight")&&(Otight[j] == 1 ))){ //if((sel_den != "mvaid")||((sel_den == "mvaid")&&(abs(Omvaid[j]) > cut_den))){ //Veto the EE-EB gape //Variable for matching double R = 999; double delta_P = 999; double delta_charge = 999; //Parameter on the xaxis double par; //loop over all generated particles to do the matching for (int i = 0; i < ngenPart; ++i) { if((abs(Id[i]) == leptonId)&&(status[i]== 1)){ //Electrons selection double R2 = DeltaR(gen_eta[i],Oeta[j],gen_phi[i],Ophi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(Opt[j]-Pt[i])/Pt[i]; delta_charge = abs(Oq[j] - charge[i]); } } } //Choose the parameter to be filled for the eff. if(par_x == "Pt"){par = Opt[j];} else if(par_x == "eta"){par = Oeta[j];} else if(par_x == "phi"){par = Ophi[j];} //Fill Pt only for matched events if(((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5))||option.Contains("unmat")){ //Filling the den if(option.Contains(" alleta ")){ histo_den->Fill(par); }else{ if(abs(Oeta[j]) < 1.2){histo_denB->Fill(par);} if(abs(Oeta[j]) >= 1.2){histo_denE->Fill(par);} } //Additional cut on the numerator int a = 0; if((sel_num == "tight")&&(Otight[j] == 1)){a = 1;} if((sel_num == "reliso3")&&(Oiso3[j] <= cut_num)){a = 2;} if((sel_num == "reliso4")&&(Oiso4[j] <= cut_num)){a = 3;} if((sel_num == "chiso3")&&(Ochiso3[j] <= cut_num)){a = 4;} if((sel_num == "chiso4")&&(Ochiso4[j] <= cut_num)){a = 5;} if((sel_num == "dxy")&&(abs(Odxy[j]) <= cut_num)){a = 6;} if((sel_num == "dz")&&(abs(Odz[j]) <= cut_num)){a = 7;} //Never filled here if(sel_num == "loose"){a = 8;} //cout<<"again, the mva value is"<<abs(Omvaid[j])<<endl; //if((sel_num == "mvaid")&&(abs(Omvaid[j]) >= cut_num)){a = 9;} switch(a){ case 0: break; case 1: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2){histo_numB->Fill(par);} if(abs(Oeta[j]) >= 1.2){histo_numE->Fill(par);}; } break; case 2: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2)histo_numB->Fill(par); if(abs(Oeta[j]) >= 1.2)histo_numE->Fill(par); } break; case 3: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2)histo_numB->Fill(par); if(abs(Oeta[j]) >= 1.2)histo_numE->Fill(par); } break; case 4: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2)histo_numB->Fill(par); if(abs(Oeta[j]) >= 1.2)histo_numE->Fill(par); } break; case 5: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2)histo_numB->Fill(par); if(abs(Oeta[j]) >= 1.2)histo_numE->Fill(par); } break; case 6: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2)histo_numB->Fill(par); if(abs(Oeta[j]) >= 1.2)histo_numE->Fill(par); } break; case 7: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2)histo_numB->Fill(par); if(abs(Oeta[j]) >= 1.2)histo_numE->Fill(par); } break; case 8: //Nothing to fill break; case 9: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Oeta[j]) < 1.2)histo_numB->Fill(par); if(abs(Oeta[j]) >= 1.2)histo_numE->Fill(par); } break; } } } } } } } //} //loop on tight for(int j=0; j<Gn;++j){ if((!option.Contains(" ll "))||((option.Contains(" ll "))&&(Gn == 2)&&(Gid[0] == -Gid[1]))){ if(abs(Gid[j]) == leptonId){ //Cut on the denominator if((sel_den != "tight")||((sel_den == "tight")&&(Gtight[j] == 1 ))){ //if((sel_den != "mvaid")||((sel_den == "mvaid")&&(abs(Gmvaid[j]) > cut_den))){ //Veto the EE-EB gape //Variable for matching double R = 999; double delta_P = 999; double delta_charge = 999; //Parameter on the xaxis double par; //loop over all generated particles to do the matching for (int i = 0; i < ngenPart; ++i) { if((abs(Id[i]) == leptonId)&&(status[i]== 1)){ //Electrons selection double R2 = DeltaR(gen_eta[i],Geta[j],gen_phi[i],Gphi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(Gpt[j]-Pt[i])/Pt[i]; delta_charge = abs(Gq[j] - charge[i]); } } } //Choose the parameter to be filled for the eff. if(par_x == "Pt"){par = Gpt[j];} else if(par_x == "eta"){par = Geta[j];} else if(par_x == "phi"){par = Gphi[j];} //Fill Pt only for matched events if(((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5))||option.Contains("unmat")){ //Filling the den if(option.Contains(" alleta ")){ histo_den->Fill(par); }else{ if(abs(Geta[j]) < 1.2){histo_denB->Fill(par);} if(abs(Geta[j]) >= 1.2){histo_denE->Fill(par);} } //Additional cut on the numerator int a = 0; if((sel_num == "tight")&&(Gtight[j] == 1)){a = 1;} if((sel_num == "reliso3")&&(Giso3[j] <= cut_num)){a = 2;} if((sel_num == "reliso4")&&(Giso4[j] <= cut_num)){a = 3;} if((sel_num == "chiso3")&&(Gchiso3[j] <= cut_num)){a = 4;} if((sel_num == "chiso4")&&(Gchiso4[j] <= cut_num)){a = 5;} if((sel_num == "dxy")&&(abs(Gdxy[j]) <= cut_num)){a = 6;} if((sel_num == "dz")&&(abs(Gdz[j]) <= cut_num)){a = 7;} //Only loose leptons here, so this is filled anyway if((sel_num == "loose")){a = 8;} //if((sel_num == "mvaid")&&(abs(Gmvaid[j]) >= cut_num)){a = 9;} switch(a){ case 0: break; case 1: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2){histo_numB->Fill(par);} if(abs(Geta[j]) >= 1.2){histo_numE->Fill(par);} } break; case 2: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; case 3: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; case 4: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; case 5: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; case 6: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; case 7: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; case 8: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; case 9: if(option.Contains(" alleta ")){ histo_num->Fill(par); }else{ if(abs(Geta[j]) < 1.2)histo_numB->Fill(par); if(abs(Geta[j]) >= 1.2)histo_numE->Fill(par); } break; } } } } } } } //} if(option.Contains(" alleta ")){ histo_num->Sumw2(); histo_den->Sumw2(); //Divide histograms to get the efficiency eff->Divide(histo_num,histo_den,1,1,"B"); //Efficiency of the iso cut. TCanvas* c = new TCanvas("c","c"); eff->Draw(); eff->GetYaxis()->SetTitle("#epsilon"); eff->GetXaxis()->SetTitle(_par); //eff->GetXaxis()->SetRangeUser(0,250); eff->SetMarkerStyle(20); eff->SetMarkerSize(1); eff->SetMarkerColor(4); eff->SetLineColor(4); eff->SetTitle(_sel_num+" for "+_sel_den+" "+pname); //Define the name of the canvas TString cname = "eff4"+option+_pname+"_den_"+_sel_den+"_num_"+_sel_num+"_"+par_x; c->SaveAs(_path+"PDF/"+cname+".pdf"); TFile* output = new TFile(_output,"recreate"); eff->Write("eff"); output->Close(); }else{ //cout<<"Problem"<<endl; histo_numB->Sumw2(); histo_numE->Sumw2(); histo_denB->Sumw2(); histo_denE->Sumw2(); //Divide histograms to get the efficiency effB->Divide(histo_numB,histo_denB,1,1,"B"); effE->Divide(histo_numE,histo_denE,1,1,"B"); //Efficiency of the iso cut. TCanvas* c1 = new TCanvas("c1","c1"); effB->Draw(); effB->GetYaxis()->SetTitle("#epsilon"); effB->GetXaxis()->SetTitle(_par); //effB->GetXaxis()->SetRangeUser(0,250); effB->SetMarkerStyle(20); effB->SetMarkerSize(1); effB->SetMarkerColor(4); effB->SetLineColor(4); effB->SetTitle(_sel_num+" for "+_sel_den+" "+pname+" #||{#eta}<1.2"); TCanvas* c2 = new TCanvas("c2","c2"); effE->Draw(); effE->GetYaxis()->SetRangeUser(0,1.1); effE->GetYaxis()->SetTitle("#epsilon"); effE->GetXaxis()->SetTitle(_par); //effE->GetXaxis()->SetRangeUser(0,250); effE->SetMarkerStyle(20); effE->SetMarkerSize(1); effE->SetMarkerColor(4); effE->SetLineColor(4); effE->SetTitle(_sel_num+" for "+_sel_den+" "+pname+" #||{#eta}>1.2"); //Define the name of the canvas TString c1name = "eff4"+option+_pname+"_den_"+_sel_den+"_num_"+_sel_num+"_"+par_x+"_eta<1.2"; TString c2name = "eff4"+option+_pname+"_den_"+_sel_den+"_num_"+_sel_num+"_"+par_x+"_eta>1.2"; c1->SaveAs(_path+"PDF/"+c1name+".pdf"); c2->SaveAs(_path+"PDF/"+c2name+".pdf"); TFile* output = new TFile(_output,"recreate"); //c1->Write(); //c2->Write(); effB->Write("eff_eta<1.2"); effE->Write("eff_eta>1.2"); output->Close(); } return 0; }
int Efficiency_v2(TTree* tree, int narray, int* leptonId, int* mother_Id, TString* sel_den , TString* sel_num, TString* par_x, double* cut_den, double* cut_num){ setTDRStyle(); Long64_t n = tree->GetEntries(); //Path for input and output file. Written in FitDataPath.txt ifstream file("EfficiencyPath.txt"); string str; getline(file,str); TString _path = str; //Histogram parameter int nbins[narray]; double par_low[narray]; double par_upp[narray]; //Declaration of histogram // //efficiency of the isolation cut TH1D **histo_num= new TH1D*[narray]; TH1D **histo_den= new TH1D*[narray]; //efficiency of the selection TH1D **eff = new TH1D*[narray]; //Name for storing and final plots // TString* pname = new TString[narray]; TString* _pname = new TString[narray]; TString* treename = new TString[narray]; TString* _par = new TString[narray]; TString* _sel_num = new TString[narray]; TString* _sel_den = new TString[narray]; TString* _cut_num = new TString[narray]; TString* _cut_den = new TString[narray]; TString* _mother_Id = new TString[narray]; //Name of the output TString _output; _output = _path+"eff.root"; TFile* output = new TFile(_output,"recreate"); for(int i =0; i < narray; ++i){ //Set parameter range if(par_x[i] == "Pt"){nbins[i] = 10;par_low[i] = 0;par_upp[i] = 250;} else if(par_x[i] == "eta"){nbins[i] = 20;par_low[i] = -3;par_upp[i] = 3;} else if(par_x[i] == "phi"){nbins[i] = 10;par_low[i] = -3.5;par_upp[i] = 3.5;} //Writing string if(mother_Id[i] == 23){_mother_Id[i] = "Z";} else if(mother_Id[i] == 24){_mother_Id[i] = "W";} if (leptonId[i] == 11) {pname[i] = "e";_pname[i] = "e";} else if (leptonId[i] == 13){pname[i] = " #mu";_pname[i] = "mu";} if (mother_Id[i] == 23){treename[i] = "from Z";} else if (mother_Id[i] == 24){treename[i] = "from W";} if(par_x[i] == "Pt"){_par[i] = "P_{t}";} else if(par_x[i] == "eta"){_par[i] = "#eta";} else if(par_x[i] == "phi"){_par[i] = "#phi";} else{cout<<"ERROR: wrong parameter name !";return 1;} if(sel_num[i] == ""){_sel_num[i] = "unsel";} else if(sel_num[i] == "tightId"){_sel_num[i] = "tightId";} else if(sel_num[i] == "dz"){_sel_num[i] = Form("IP dz < %0.3lf ",cut_num[i]);} else if(sel_num[i] == "dxy"){_sel_num[i] = Form("IP dxy < %0.3lf ", cut_num[i]) ;} else{cout<<"ERROR: wrong numeretor selection name !";return 1;} if(sel_den[i] == ""){_sel_den[i] = "unsel";} else if(sel_den[i] == "tightId"){_sel_den[i] = "tight";} else{cout<<"ERROR: wrong denominator selection name !";return 1;} if(cut_den[i] == 0.){_cut_den[i] = "";} else{_cut_den[i] = Form("%0.3lf",cut_den[i]);} if(cut_num[i] == 0.){_cut_num[i] = "";} else{_cut_num[i] = Form("%0.3lf",cut_num[i]);} //Assigning histo histo_num[i] = new TH1D("histo_num","Pt",nbins[i],par_low[i],par_upp[i]); histo_den[i] = new TH1D("histo_den","Pt",nbins[i],par_low[i],par_upp[i]); eff[i] = new TH1D("histo_eff","Pt",nbins[i],par_low[i],par_upp[i]); } //Event variables // //Generated Float_t gen_phi[200]; Float_t gen_eta[200]; Float_t Pt[200]; Float_t m[200]; Int_t Id[200]; Int_t Mo[200]; Float_t charge[200]; Int_t status[200]; Int_t GrMa[200]; Int_t ngenPart; Int_t source[200]; Int_t pile_up; //Reconstructed //Electrons Int_t nrecel; Int_t receltightid[200]; Float_t recelPt[200]; Float_t recelm[200]; Float_t recel_eta[200]; Float_t recel_phi[200]; Int_t recelcharge[200]; Float_t receliso03[200]; Float_t receliso04[200]; Float_t receldz[200]; Float_t receldxy[200]; //Muons Int_t nrecmu; Int_t recmutightid[200]; Float_t recmuPt[200]; Float_t recmum[200]; Float_t recmu_eta[200]; Float_t recmu_phi[200]; Int_t recmucharge[200]; Float_t recmuiso03[200]; Float_t recmuiso04[200]; Float_t recmudz[200]; Float_t recmudxy[200]; //Assigne branches //generated tree->SetBranchAddress("ngenLep", &ngenPart); tree->SetBranchAddress("genLep_pdgId", &Id); tree->SetBranchAddress("genLep_sourceId", &source); tree->SetBranchAddress("genLep_eta", &gen_eta); tree->SetBranchAddress("genLep_phi", &gen_phi); tree->SetBranchAddress("genLep_pt", &Pt); tree->SetBranchAddress("genLep_mass", &m); tree->SetBranchAddress("genLep_charge", &charge); tree->SetBranchAddress("genLep_status", &status); tree->SetBranchAddress("nTrueInt",&pile_up); //reconstructed //electron tree->SetBranchAddress("nel", &nrecel); tree->SetBranchAddress("el_tightId", &receltightid); tree->SetBranchAddress("el_pt", &recelPt); tree->SetBranchAddress("el_mass", &recelm); tree->SetBranchAddress("el_eta", &recel_eta); tree->SetBranchAddress("el_phi", &recel_phi); tree->SetBranchAddress("el_charge", &recelcharge); tree->SetBranchAddress("el_relIso03", &receliso03); tree->SetBranchAddress("el_relIso04", &receliso04); tree->SetBranchAddress("el_chargedHadRelIso03", &receliso03); tree->SetBranchAddress("el_chargedHadRelIso04", &receliso04); tree->SetBranchAddress("el_dz",&receldz); tree->SetBranchAddress("el_dxy",&receldxy); //muons tree->SetBranchAddress("nmu", &nrecmu); tree->SetBranchAddress("mu_tightId", &recmutightid); tree->SetBranchAddress("mu_pt", &recmuPt); tree->SetBranchAddress("mu_mass", &recmum); tree->SetBranchAddress("mu_eta", &recmu_eta); tree->SetBranchAddress("mu_phi", &recmu_phi); tree->SetBranchAddress("mu_charge", &recmucharge); tree->SetBranchAddress("mu_relIso03", &recmuiso03); tree->SetBranchAddress("mu_relIso04", &recmuiso04); tree->SetBranchAddress("mu_chargedHadRelIso03", &recmuiso03); tree->SetBranchAddress("mu_chargedHadRelIso04", &recmuiso04); tree->SetBranchAddress("mu_dz",&recmudz); tree->SetBranchAddress("mu_dxy",&recmudxy); int counter = 1; //Start loop over all events for (int k = 0; k < n; ++k) { tree->GetEntry(k); for(int ii = 0; ii <narray; ++ii){ if(k%n > counter*100000){cout<<100.*k/n<<" completed"<<endl;++counter;} if(leptonId[ii] == 11){ for(int j=0; j<nrecel;++j){ //Cut on the denominator if((sel_den[ii] != "tightId")||((sel_den[ii] == "tightId")&&(receltightid[j] == 1 ))){ //Veto the EE-EB gape if(((abs(recel_eta[j]) < 1.479)||(abs(recel_eta[j]) > 1.653))){ //Variable for matching double R = 999; double delta_P = 999; double delta_charge = 999; //Parameter on the xaxis double par; //if(abs(recel_eta[j]) < 2.4){ //loop over all generated particles to do the matching for (int i = 0; i < ngenPart; ++i) { if((abs(Id[i]) == leptonId[ii])&&(status[i]== 1)&&(abs(gen_eta[i]) < 2.4)&&(abs(source[i]) == mother_Id[ii])){ //Electrons selection double R2 = DeltaR(gen_eta[i],recel_eta[j],gen_phi[i],recel_phi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(recelPt[j]-Pt[i])/Pt[i]; delta_charge = abs(recelcharge[j] - charge[i]); } } } //} //Choose the parameter to be filled for the eff. if(par_x[ii] == "Pt"){par = recelPt[j];} else if(par_x[ii] == "eta"){par = recel_eta[j];} else if(par_x[ii] == "phi"){par = recel_phi[j];} //Fill Pt only for matched events if((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5)){ //Filling the den histo_den[ii]->Fill(par); //Additional cut on the numerator if((sel_num[ii] != "tightId")||((sel_num[ii] == "tightId")&&(receltightid[j] == 1 ))){ if((sel_num[ii] != "dxy")||((sel_num[ii] == "dxy")&&(abs(receldxy[j]) < cut_num[ii] ))){ if((sel_num[ii] != "dz")||((sel_num[ii] == "dz")&&(abs(receldz[j]) < cut_num[ii] ))){ histo_num[ii]->Fill(par); } } } } } } } } if(leptonId[ii] == 13){ for(int j=0; j<nrecmu;++j){ //Cut on the denominator if((sel_den[ii] != "tightId")||((sel_den[ii] == "tightId")&&(recmutightid[j] == 1 ))){ //Veto the EE-EB gape if(((abs(recmu_eta[j]) < 1.479)||(abs(recmu_eta[j]) > 1.653))){ //Variable for matching double R = 999; double delta_P = 999; double delta_charge = 999; //Parameter on the xaxis double par; //if(abs(recmu_eta[j]) < 2.4){ //loop over all generated particles to do the matching for (int i = 0; i < ngenPart; ++i) { if((abs(Id[i]) == leptonId[ii])&&(status[i]== 1)&&(abs(gen_eta[i]) < 2.4)&&(abs(source[i]) == mother_Id[ii])){ //Electrons selection double R2 = DeltaR(gen_eta[i],recmu_eta[j],gen_phi[i],recmu_phi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(recmuPt[j]-Pt[i])/Pt[i]; delta_charge = abs(recmucharge[j] - charge[i]); } } } //} //Choose the parameter to be filled for the eff. if(par_x[ii] == "Pt"){par = recmuPt[j];} else if(par_x[ii] == "eta"){par = recmu_eta[j];} else if(par_x[ii] == "phi"){par = recmu_phi[j];} //Fill Pt only for matched events if((R<0.1)&&(delta_P < 0.2)&&(delta_charge < 0.5)){ //Filling the den histo_den[ii]->Fill(par); //Additional cut on the numerator if((sel_num[ii] != "tightId")||((sel_num[ii] == "tightId")&&(recmutightid[j] == 1 ))){ if((sel_num[ii] != "dxy")||((sel_num[ii] == "dxy")&&(abs(recmudxy[j]) < cut_num[ii] ))){ if((sel_num[ii] != "dz")||((sel_num[ii] == "dz")&&(abs(recmudz[j]) < cut_num[ii] ))){ histo_num[ii]->Fill(par); } } } } } } } } } } for(int ii = 0; ii < narray;++ii){ histo_num[ii]->Sumw2(); histo_den[ii]->Sumw2(); //Divide histograms to get the efficiency eff[ii]->Divide(histo_num[ii],histo_den[ii],1,1,"B"); //Efficiency of the iso cut. TCanvas* c1 = new TCanvas("c1","c1"); eff[ii]->Draw(); eff[ii]->GetYaxis()->SetRangeUser(0,1.1); eff[ii]->GetYaxis()->SetTitle("#epsilon"); eff[ii]->GetXaxis()->SetTitle(_par[ii]); eff[ii]->SetMarkerStyle(20); eff[ii]->SetMarkerSize(1); eff[ii]->SetMarkerColor(4); eff[ii]->SetLineColor(4); eff[ii]->SetTitle(_sel_num[ii]+" for "+_sel_den[ii]+" "+pname[ii]+" "+treename[ii]); //Define the name of the canvas TString cname = (TString)"eff_"+_pname[ii]+"_"+treename[ii]+"_den_"+_sel_den[ii]+"_num_"+_sel_num[ii]+"_"+par_x[ii]; c1->SaveAs(_path+"/PDF/"+cname+".pdf"); output->cd(); c1->Write(cname); } output->Close(); }
map<int, vector<Event> > getdyjetsnewmap(TTree* tree_new, TString option){ Int_t nnew = tree_new->GetEntries(); map<int, vector<Event> > map_new; /////////////// //dyjets_new // /////////////// //Define histogram to save _new only TH1D* histo = new TH1D("histo","h",5,0,5); //Event variables Int_t evt; //Generated Float_t gen_phi[200]; Float_t gen_eta[200]; Float_t Pt[200]; Float_t m[200]; Int_t Id[200]; Int_t Mo[200]; Float_t charge[200]; Int_t status[200]; Int_t GrMa[200]; Int_t ngenPart; Int_t source[200]; //Generated from tau Float_t tgen_phi[200]; Float_t tgen_eta[200]; Float_t tPt[200]; Float_t tm[200]; Int_t tId[200]; Int_t tMo[200]; Float_t tcharge[200]; Int_t tstatus[200]; Int_t tGrMa[200]; Int_t tngenPart; Int_t tsource[200]; //not loose Int_t On; Int_t Oid[200]; Float_t Opt[200]; Float_t Oeta[200]; Float_t Ophi[200]; Int_t Otighte[200]; Int_t Otight[200]; //loose Int_t Gn; Int_t Gid[200]; Float_t Gpt[200]; Float_t Geta[200]; Float_t Gphi[200]; Int_t Gtighte[200]; Int_t Gtight[200]; //generated tree_new->SetBranchAddress("ngenLep", &ngenPart); tree_new->SetBranchAddress("genLep_pdgId", &Id); tree_new->SetBranchAddress("genLep_sourceId", &source); tree_new->SetBranchAddress("genLep_eta", &gen_eta); tree_new->SetBranchAddress("genLep_phi", &gen_phi); tree_new->SetBranchAddress("genLep_pt", &Pt); tree_new->SetBranchAddress("genLep_mass", &m); tree_new->SetBranchAddress("genLep_charge", &charge); tree_new->SetBranchAddress("genLep_status", &status); tree_new->SetBranchAddress("evt", &evt); //generated from tau tree_new->SetBranchAddress("ngenLepFromTau", &tngenPart); tree_new->SetBranchAddress("genLepFromTau_pdgId", &tId); tree_new->SetBranchAddress("genLepFromTau_sourceId", &tsource); tree_new->SetBranchAddress("genLepFromTau_eta", &tgen_eta); tree_new->SetBranchAddress("genLepFromTau_phi", &tgen_phi); tree_new->SetBranchAddress("genLepFromTau_pt", &tPt); tree_new->SetBranchAddress("genLepFromTau_mass", &tm); tree_new->SetBranchAddress("genLepFromTau_charge", &tcharge); tree_new->SetBranchAddress("genLepFromTau_status", &tstatus); //not loose tree_new->SetBranchAddress("nLepOther",&On); tree_new->SetBranchAddress("LepOther_pdgId",&Oid); tree_new->SetBranchAddress("LepOther_pt",&Opt); tree_new->SetBranchAddress("LepOther_eta",&Oeta); tree_new->SetBranchAddress("LepOther_phi",&Ophi); tree_new->SetBranchAddress("LepOther_tightId",&Otight); tree_new->SetBranchAddress("LepOther_eleCutIdCSA14_50ns_v1",&Otighte); //Loose tree_new->SetBranchAddress("nLepGood",&Gn); tree_new->SetBranchAddress("LepGood_pdgId",&Gid); tree_new->SetBranchAddress("LepGood_pt",&Gpt); tree_new->SetBranchAddress("LepGood_eta",&Geta); tree_new->SetBranchAddress("LepGood_phi",&Gphi); tree_new->SetBranchAddress("LepGood_tightId",&Gtight); tree_new->SetBranchAddress("LepGood_eleCutIdCSA14_50ns_v1",&Gtighte); if(option == "short"){nnew = 10000;} for (int k = 0; k < nnew; ++k){ tree_new->GetEntry(k); //Declaration of Event parameters Int_t evtloose[200]; Int_t evtid[200]; Float_t evtpt[200]; Float_t evteta[200]; Float_t evtphi[200]; Int_t evttighte[200]; Int_t evttight[200]; //run in all leptons in the events to store vector of pt vector<Event> vect; Event ev; for(int j = 0; j < Gn+On; ++j){ //cout<<"LepGood + LepOther is "<<Gn+On<<endl; //Loose events if(j < On){ evtloose[j] = 0; evtid[j] = Oid[j]; evtpt[j] = Opt[j]; evteta[j] = Oeta[j]; evtphi[j] = Ophi[j]; evttighte[j] = Otighte[j]; evttight[j] = Otight[j]; //Good events }else if((j >= On)&&(j < Gn+On)){ evtloose[j] = 1; evtid[j] = Gid[j-On]; evtpt[j] = Gpt[j-On]; evteta[j] = Geta[j-On]; evtphi[j] = Gphi[j-On]; evttighte[j] = Gtighte[j-On]; evttight[j] = Gtight[j-On]; } if(abs(evtid[j]) == 13){//Only interested in electrons //Matching here // //Variable for matching double R = 999; double delta_P = 999; int nlep = 0;//count the number of generated leptons Float_t evtgen_phi[200]; Float_t evtgen_eta[200]; Float_t evtPt[200]; Float_t evtm[200]; Int_t evtId[200]; Int_t evtMo[200]; Float_t evtcharge[200]; Int_t evtstatus[200]; Int_t evtGrMa[200]; Int_t evtngenPart; Int_t evtsource[200]; for(int gen_i = 0; gen_i < ngenPart + tngenPart; ++gen_i){ if(gen_i < ngenPart){ evtgen_phi[gen_i] = gen_phi[gen_i]; evtgen_eta[gen_i] = gen_eta[gen_i]; evtPt[gen_i] = Pt[gen_i]; evtm[gen_i] = m[gen_i]; evtId[gen_i] = Id[gen_i]; evtMo[gen_i] = Mo[gen_i]; evtcharge[gen_i] = charge[gen_i]; evtstatus[gen_i] = status[gen_i]; evtGrMa[gen_i] = GrMa[gen_i]; evtsource[gen_i] = source[gen_i]; }else if((gen_i >= ngenPart)&&(gen_i < ngenPart + tngenPart)){ evtgen_phi[gen_i] = tgen_phi[gen_i-ngenPart]; evtgen_eta[gen_i] = tgen_eta[gen_i-ngenPart]; evtPt[gen_i] = tPt[gen_i-ngenPart]; evtm[gen_i] = tm[gen_i-ngenPart]; evtId[gen_i] = tId[gen_i-ngenPart]; evtMo[gen_i] = tMo[gen_i-ngenPart]; evtcharge[gen_i] = tcharge[gen_i-ngenPart]; evtstatus[gen_i] = tstatus[gen_i-ngenPart]; evtGrMa[gen_i] = tGrMa[gen_i-ngenPart]; evtsource[gen_i] = tsource[gen_i-ngenPart]; } } //loop over all generated particles to do the matching for (int i = 0; i < ngenPart+tngenPart; ++i) {//to count the number of electrons in the genpart if(abs(evtId[i]) == 13){ ++nlep; if(evtId[i] == evtid[j]){ //Electrons selection double R2 = DeltaR(evtgen_eta[i],evteta[j],evtgen_phi[i],evtphi[j] ); //Minimise DeltaR and Fill the other variables if (R > R2) { R = R2; delta_P = abs(evtpt[j]-evtPt[i])/evtPt[i]; } } } } //This is only filled if the rec particle is an electron ev.DR = R; ev.NGEN = nlep; ev.PHI = evtphi[j]; ev.ETA = evteta[j]; ev.PT = evtpt[j]; vect.push_back(ev); } } //Put vector in increasing pt order sort(vect.begin(),vect.end(),mycompare); //Add vector to the map with the corresponding evt number map_new[evt] = vect; //cout<<"The size of the event "<<evt<<" is "<<vect.size()<<endl; } return map_new; }
void analysisClassL1::loop(){ std::string MyTrigger="HLT_Any"; std::vector<std::string> triggerList = {"L1_SingleJet092","L1_SingleJet128","L1_SingleJet176","L1_SingleJet200","L1_SingleJet240"}; std::vector<std::string> preTriggerList = {"L1_SingleJet092","L1_SingleJet128","L1_SingleJet176","L1_SingleJet200","L1_SingleJet240"}; L1Tree * l1Tree = getTree<L1Tree>("l1Tree"); int n_events = l1Tree -> fChain -> GetEntries(); l1Tree -> fChain -> SetBranchStatus("*", kFALSE); l1Tree -> fChain -> SetBranchStatus("lumi",kTRUE); l1Tree -> fChain -> SetBranchStatus("Njet",kTRUE); l1Tree -> fChain -> SetBranchStatus("Bxjet",kTRUE); l1Tree -> fChain -> SetBranchStatus("Rankjet",kTRUE); l1Tree -> fChain -> SetBranchStatus("Etajet",kTRUE); l1Tree -> fChain -> SetBranchStatus("Phijet",kTRUE); l1Tree -> fChain -> SetBranchStatus("Fwdjet",kTRUE); l1Tree -> fChain -> SetBranchStatus("tw1",kTRUE); l1Tree -> fChain -> SetBranchStatus("tw2",kTRUE); std::map<std::string,TH1F*> etaHistList; std::map<std::string,TH2F*> etaPhiHistList; std::map<std::string,TH1F*> l1BitHistList; std::map<std::string,std::map<std::string,TH1F*>> preFireEtaHistList; std::map<std::string,std::map<std::string,TH2F*>> prePreFireEtaPhiHistList; std::map<std::string,std::map<std::string,TH2F*>> preFireEtaPhiHistList; std::map<std::string,std::map<std::string,TH2F*>> postFireEtaPhiHistList; std::map<std::string,std::map<std::string,TH2F*>> postPostFireEtaPhiHistList; std::map<std::string,std::map<std::string,TH1F*>> deltaRHistList; std::map<std::string,std::map<std::string,TH1F*>> postDeltaRHistList; std::map<std::string,std::map<std::string,TH1F*>> postPostDeltaRHistList; std::map<std::string,std::map<std::string,TH1F*>> prePreDeltaRHistList; char histName[100]; for (std::vector<std::string>::iterator it = triggerList.begin(); it != triggerList.end(); it++){ sprintf(histName,"h_etaBin_%s",it->c_str()); etaHistList[*it] = makeTH1F(histName,22,-0.5,21.5); sprintf(histName,"h_etaPhiBin_%s",it->c_str()); etaPhiHistList[*it] = makeTH2F(histName,22,-0.5,21.5,18,-0.5,17.5); sprintf(histName,"h_l1Bit_%s",it->c_str()); l1BitHistList[*it] = makeTH1F(histName,2,-0.5,1.5); preFireEtaHistList[*it] = std::map<std::string,TH1F*>(); for (std::vector<std::string>::iterator it2 = preTriggerList.begin(); it2 != preTriggerList.end(); it2++){ sprintf(histName,"h_preFireEtaBin%s_%s",it->c_str(),it2->c_str()); preFireEtaHistList[*it][*it2] = makeTH1F(histName,22,-0.5,21.5); sprintf(histName,"h_prePreFireEtaPhiBin%s_%s",it->c_str(),it2->c_str()); prePreFireEtaPhiHistList[*it][*it2] = makeTH2F(histName,22,-0.5,21.5,18,-0.5,17.5); sprintf(histName,"h_preFireEtaPhiBin%s_%s",it->c_str(),it2->c_str()); preFireEtaPhiHistList[*it][*it2] = makeTH2F(histName,22,-0.5,21.5,18,-0.5,17.5); sprintf(histName,"h_postFireEtaPhiBin%s_%s",it->c_str(),it2->c_str()); postFireEtaPhiHistList[*it][*it2] = makeTH2F(histName,22,-0.5,21.5,18,-0.5,17.5); sprintf(histName,"h_postPostFireEtaPhiBin%s_%s",it->c_str(),it2->c_str()); postPostFireEtaPhiHistList[*it][*it2] = makeTH2F(histName,22,-0.5,21.5,18,-0.5,17.5); sprintf(histName,"h_deltaR%s_%s",it->c_str(),it2->c_str()); deltaRHistList[*it][*it2] = makeTH1F(histName,50,-0.5,5.5); sprintf(histName,"h_postDeltaR%s_%s",it->c_str(),it2->c_str()); postDeltaRHistList[*it][*it2] = makeTH1F(histName,50,-0.5,5.5); sprintf(histName,"h_prePreDeltaR%s_%s",it->c_str(),it2->c_str()); prePreDeltaRHistList[*it][*it2] = makeTH1F(histName,50,-0.5,5.5); sprintf(histName,"h_postPostDeltaR%s_%s",it->c_str(),it2->c_str()); postPostDeltaRHistList[*it][*it2] = makeTH1F(histName,50,-0.5,5.5); }; }; loadPrescaleMap(); loadBitMap(); for (int i = 0; i < n_events; ++i){ l1Tree -> GetEntry(i); if ( (i + 1) % 10000 == 0 ) std::cout << "Processing event " << i + 1 << "/" << n_events << std::endl; int lumi = l1Tree -> lumi; if (lumi < 126) continue; int prescaleIndex; if (lumi < 317){ prescaleIndex = 6; }else{ prescaleIndex = 7; }; tw1 = l1Tree -> tw1; tw2 = l1Tree -> tw2; Njet = l1Tree -> Njet; Bxjet = l1Tree -> Bxjet; Rankjet = l1Tree -> Rankjet; Etajet = l1Tree -> Etajet; Phijet = l1Tree -> Phijet; Fwdjet = l1Tree -> Fwdjet; tw1 = l1Tree -> tw1; tw2 = l1Tree -> tw2; for (std::vector<std::string>::iterator it = triggerList.begin(); it != triggerList.end(); it++){ bool Bx2Fired = checkTriggerBit(BitMap[*it],2); float ptThreshold = (float)std::stoi(it -> substr(12)); int jetEtaBin = SingleJetEtaBin(ptThreshold,0); int jetPhiBin = SingleJetPhiBin(ptThreshold,0); if (Bx2Fired){ l1BitHistList[*it] -> Fill(1,PrescaleMap[prescaleIndex][*it]); }; if ((jetEtaBin != -10) && (jetPhiBin != -10)){ etaHistList[*it] -> Fill(jetEtaBin,PrescaleMap[prescaleIndex][*it]); etaPhiHistList[*it] -> Fill(jetEtaBin,jetPhiBin,PrescaleMap[prescaleIndex][*it]); for (std::vector<std::string>::iterator it2 = preTriggerList.begin(); it2 != preTriggerList.end(); it2++){ float ptThreshold_OtherBx = (float)std::stoi(it2 -> substr(12)); int jetEtaBin_BxM1 = SingleJetEtaBin(ptThreshold_OtherBx,-1); int jetPhiBin_BxM1 = SingleJetPhiBin(ptThreshold_OtherBx,-1); if ((jetEtaBin_BxM1 != -10) && (jetPhiBin_BxM1 != -10)){ preFireEtaHistList[*it][*it2] -> Fill(jetEtaBin_BxM1,PrescaleMap[prescaleIndex][*it2]); preFireEtaPhiHistList[*it][*it2] -> Fill(jetEtaBin_BxM1,jetPhiBin_BxM1,PrescaleMap[prescaleIndex][*it2]); double jetEta_BxM1 = SingleJetEta(ptThreshold_OtherBx,-1); double jetPhi_BxM1 = SingleJetPhi(ptThreshold_OtherBx,-1); double jetEta = SingleJetEta(ptThreshold,0); double jetPhi = SingleJetPhi(ptThreshold,0); deltaRHistList[*it][*it2] -> Fill(DeltaR(jetEta_BxM1,jetEta,jetPhi_BxM1,jetPhi)); }; int jetEtaBin_BxP1 = SingleJetEtaBin(ptThreshold_OtherBx,1); int jetPhiBin_BxP1 = SingleJetPhiBin(ptThreshold_OtherBx,1); if ((jetEtaBin_BxP1 != -10) && (jetPhiBin_BxP1 != -10)){ double jetEta = SingleJetEta(ptThreshold,0); double jetPhi = SingleJetPhi(ptThreshold,0); postFireEtaPhiHistList[*it][*it2] -> Fill(jetEtaBin_BxP1,jetPhiBin_BxP1,PrescaleMap[prescaleIndex][*it2]); postDeltaRHistList[*it][*it2] -> Fill(DeltaR(jetEtaBin_BxP1,jetEta,jetPhiBin_BxP1,jetPhi)); }; int jetEtaBin_BxM2 = SingleJetEtaBin(ptThreshold_OtherBx,-2); int jetPhiBin_BxM2 = SingleJetPhiBin(ptThreshold_OtherBx,-2); if ((jetEtaBin_BxM2 != -10) && (jetPhiBin_BxM2 != -10)){ double jetEta = SingleJetEta(ptThreshold,0); double jetPhi = SingleJetPhi(ptThreshold,0); prePreFireEtaPhiHistList[*it][*it2] -> Fill(jetEtaBin_BxM2,jetPhiBin_BxM2,PrescaleMap[prescaleIndex][*it2]); prePreDeltaRHistList[*it][*it2] -> Fill(DeltaR(jetEtaBin_BxM2,jetEta,jetPhiBin_BxM2,jetPhi)); }; int jetEtaBin_BxP2 = SingleJetEtaBin(ptThreshold_OtherBx,2); int jetPhiBin_BxP2 = SingleJetPhiBin(ptThreshold_OtherBx,2); if ((jetEtaBin_BxP2 != -10) && (jetPhiBin_BxP2 != -10)){ double jetEta = SingleJetEta(ptThreshold,0); double jetPhi = SingleJetPhi(ptThreshold,0); postPostFireEtaPhiHistList[*it][*it2] -> Fill(jetEtaBin_BxP2,jetPhiBin_BxP2,PrescaleMap[prescaleIndex][*it2]); postPostDeltaRHistList[*it][*it2] -> Fill(DeltaR(jetEtaBin_BxP2,jetEta,jetPhiBin_BxP2,jetPhi)); }; }; }; }; }; char titleName[100]; for (std::map<std::string,TH1F*>::iterator itr = etaHistList.begin(); itr != etaHistList.end(); ++itr){ sprintf(titleName,"%s, L1Object:%4.0f, L1Bit:%4.0f ; Eta Bin ( 0 - 21 ); Number of Event",itr->first.c_str(),itr -> second -> Integral(),l1BitHistList[itr->first]->Integral()); itr -> second -> SetTitle(titleName); sprintf(titleName,"%s, L1Object:%4.0f, L1Bit:%4.0f ; Eta Bin ( 0 - 21 ); Phi Bin ( 0 - 17 )",itr->first.c_str(),etaPhiHistList[itr -> first],l1BitHistList[itr->first]->Integral()); etaPhiHistList[itr -> first] -> SetTitle(titleName); for (std::vector<std::string>::iterator it2 = preTriggerList.begin(); it2 != preTriggerList.end(); it2++){ sprintf(titleName,"Bx2: %s, Bx1: %s, Prefire Rate: %4.3f ; Eta Bin ( 0 - 21 ); Number of Event",itr->first.c_str(),it2->c_str(),preFireEtaHistList[itr->first][*it2]->Integral()/itr->second->Integral()); preFireEtaHistList[itr->first][*it2] -> SetTitle(titleName); sprintf(titleName,"Bx2: %s, Bx1: %s, Prefire Rate: %4.3f ; Eta Bin ( 0 - 21 ); Phi Bin (0 - 17)",itr->first.c_str(),it2->c_str(),preFireEtaHistList[itr->first][*it2]->Integral()/itr->second->Integral()); preFireEtaPhiHistList[itr->first][*it2] -> SetTitle(titleName); sprintf(titleName,"Bx2: %s, Bx1: %s, Prefire Rate: %4.3f ; Eta Bin ( 0 - 21 ); Phi Bin (0 - 17)",itr->first.c_str(),it2->c_str(),preFireEtaHistList[itr->first][*it2]->Integral()/itr->second->Integral()); postFireEtaPhiHistList[itr->first][*it2] -> SetTitle(titleName); }; }; }
void analysis_bgtemplate(){//main gSystem->Load("/uscms/home/mengleis/work/SUSYAnalysis/lib/libAnaClasses.so"); char outputname[50] = "plot_bgtemplate_2016D.root"; ofstream logfile; logfile.open("plot_bgtemplate_2016D.log"); logfile << "analysis_bgtemplate()" << std::endl; RunType datatype(SingleMuon2016); TChain* es = new TChain("ggNtuplizer/EventTree"); es->Add("root://cmseos.fnal.gov//store/user/msun/2016ggNtuple/skim-SingleMu_Run2016D_private.root"); logfile << "Add: root://cmseos.fnal.gov//store/user/msun/2016ggNtuple/skim-SingleMu_Run2016D_private.root" << std::endl; TFile *outputfile = TFile::Open(outputname,"NEW"); outputfile->cd(); int tracks(0); int nVertex(0); int mcType = MCType::NOMC; if(datatype == MC && mcType == MCType::NOMC){std::cout << "wrong MC type" << std::endl; throw;} logfile << "mcType" << mcType << std::endl; TTree *mtree = new TTree("BGTree","BGTree"); float tagEta_mg; float tagPhi_mg; float tagPt_mg; float probeEta_mg; float probePhi_mg; float probePt_mg; float probeUncalibPt_mg; float invmass_mg; bool vetovalue_mg; mtree->Branch("tracks", &tracks); mtree->Branch("nVertex", &nVertex); mtree->Branch("tagEta", &tagEta_mg); mtree->Branch("tagPhi", &tagPhi_mg); mtree->Branch("tagPt", &tagPt_mg); mtree->Branch("probeEta", &probeEta_mg); mtree->Branch("probePhi", &probePhi_mg); mtree->Branch("probePt", &probePt_mg); mtree->Branch("probeUncalibPt", &probeUncalibPt_mg); mtree->Branch("invmass", &invmass_mg); mtree->Branch("vetovalue", &vetovalue_mg); const unsigned nEvts = es->GetEntries(); logfile << "Total event: " << nEvts << std::endl; logfile << "Output file: " << outputname << std::endl; rawData raw(es, datatype); std::vector<recoPhoton> Photon; std::vector<recoMuon> Muon; std::vector<recoEle> Ele; float MET(0); float METPhi(0); int ntrks(0); int nvtx(0); for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on entries if (ievt%1000000==0) std::cout << " -- Processing event " << ievt << std::endl; raw.GetData(es, ievt); Photon.clear(); Muon.clear(); Ele.clear(); for(int iPho(0); iPho < raw.nPho; iPho++){Photon.push_back(recoPhoton(raw, iPho));} for(int iMu(0); iMu < raw.nMu; iMu++){Muon.push_back(recoMuon(raw, iMu));} for(int iEle(0); iEle < raw.nEle; iEle++){Ele.push_back(recoEle(raw, iEle));} MET = raw.pfMET; METPhi = raw.pfMETPhi; ntrks = raw.nTrksPV; nvtx = raw.nVtx; tracks = ntrks; nVertex = nvtx; if(MET > 70.0)continue; if(!raw.passHLT())continue; std::vector< std::vector<recoMuon>::iterator > bgMuCollection; bgMuCollection.clear(); for(std::vector<recoMuon>::iterator itMu = Muon.begin(); itMu != Muon.end(); itMu++){ if(itMu->passSignalSelection()){ bgMuCollection.push_back(itMu); } } std::vector< std::vector<recoPhoton>::iterator > bgPhoCollection; bgPhoCollection.clear(); for(std::vector<recoPhoton>::iterator itpho = Photon.begin() ; itpho != Photon.end(); ++itpho){ if(itpho->getCalibEt() < 25 || !itpho->isEB())continue; bool FSRVeto(true); for(std::vector<recoEle>::iterator ie = Ele.begin(); ie != Ele.end(); ie++){ if(DeltaR(itpho->getEta(), itpho->getPhi(), ie->getEta(), ie->getPhi()) < 0.3 && ie->getCalibEt()>2.0 && DeltaR(itpho->getEta(), itpho->getPhi(), ie->getEta(), ie->getPhi()) > 0.05)FSRVeto=false; } for(std::vector<recoMuon>::iterator im = Muon.begin(); im != Muon.end(); im++) if(DeltaR(itpho->getEta(), itpho->getPhi(), im->getEta(), im->getPhi()) < 0.3 && im->getEt()>2.0)FSRVeto=false; if(FSRVeto && itpho->isLoose()){ bgPhoCollection.push_back(itpho); } } for(unsigned iPho(0); iPho < bgPhoCollection.size(); iPho++){ for(unsigned iMu(0); iMu < bgMuCollection.size(); iMu++){ std::vector<recoMuon>::iterator bgMu = bgMuCollection[iMu]; std::vector<recoPhoton>::iterator bgPho = bgPhoCollection[iPho]; bool PixelVeto = bgPho->PixelSeed()==0? true: false; bool GSFveto(true); for(std::vector<recoEle>::iterator ire = Ele.begin(); ire != Ele.end(); ire++) if(ire->getCalibEt() > 2.0 && DeltaR(bgPho->getEta(), bgPho->getPhi(), ire->getEta(), ire->getPhi()) < 0.02)GSFveto=false; tagEta_mg = bgMu->getEta(); tagPhi_mg = bgMu->getPhi(); tagPt_mg = bgMu->getPt(); probeEta_mg = bgPho->getEta(); probePhi_mg = bgPho->getPhi(); probePt_mg = bgPho->getCalibEt(); probeUncalibPt_mg = bgPho->getEt(); invmass_mg = (bgPho->getCalibP4()+bgMu->getP4()).M(); vetovalue_mg = (PixelVeto && GSFveto); mtree->Fill(); } } }//loop on events outputfile->Write(); }
void analysis_mg(){//main gSystem->Load("/uscms/home/mengleis/work/SUSYAnalysis/lib/libAnaClasses.so"); char outputname[50] = "resTree_mgsignal_2016DoubleEG.root"; ofstream logfile; logfile.open("resTree_mgsignal_2016DoubleEG.log"); logfile << "analysis_mg()" << std::endl; RunType datatype(MuonEG2016); TChain* es = new TChain("ggNtuplizer/EventTree"); es->Add("root://cmseos.fnal.gov//store/user/msun/2016ggNtuple/skim-DoubleEG_Run2016B_PRv2.root"); logfile << "Add file: 2016ggNtuple/skim-DoubleEG_Run2016B_PRv2.root" << std::endl; es->Add("root://cmseos.fnal.gov//store/user/msun/2016ggNtuple/skim-DoubleEG_Run2016C_PRv2.root"); logfile << "Add file: 2016ggNtuple/skim-DoubleEG_Run2016C_PRv2.root" << std::endl; es->Add("root://cmseos.fnal.gov//store/user/msun/2016ggNtuple/skim-DoubleEG_Run2016D_PRv2.root"); logfile << "Add file: 2016ggNtuple/skim-DoubleEG_Run2016D_PRv2.root" << std::endl; const unsigned nEvts = es->GetEntries(); logfile << "Total event: " << nEvts << std::endl; logfile << "Output file: " << outputname << std::endl; int nTotal(0),npassHLT(0), npassPho(0), npassMu(0), npassdR(0), npassZ(0), npassMETFilter(0); TFile *outputfile = TFile::Open(outputname,"RECREATE"); outputfile->cd(); //************* MC Tree **************************// TTree *mctree = new TTree("MCTree","MCTree"); int mcType = MCType::NOMC; if(datatype == MC && mcType == MCType::NOMC){std::cout << "wrong MC type" << std::endl; throw;} logfile << "mcType" << mcType << std::endl; std::vector<int> mcPID; std::vector<float> mcEta; std::vector<float> mcPhi; std::vector<float> mcPt; std::vector<int> mcMomPID; mctree->Branch("mcType", &mcType); mctree->Branch("mcPID", &mcPID); mctree->Branch("mcEta", &mcEta); mctree->Branch("mcPhi", &mcPhi); mctree->Branch("mcPt", &mcPt); mctree->Branch("mcMomPID", &mcMomPID); //************ Signal Tree **********************// TTree *sigtree = new TTree("signalTree","signalTree"); float phoEt(0); float phoEta(0); float phoPhi(0); float lepPt(0); float lepEta(0); float lepPhi(0); float sigMT(0); float sigMET(0); float sigMETPhi(0); float dPhiLepMET(0); int nVertex(0); float dRPhoLep(0); float HT(0); float nJet(0); sigtree->Branch("phoEt", &phoEt); sigtree->Branch("phoEta", &phoEta); sigtree->Branch("phoPhi", &phoPhi); sigtree->Branch("lepPt", &lepPt); sigtree->Branch("lepEta", &lepEta); sigtree->Branch("lepPhi", &lepPhi); sigtree->Branch("sigMT", &sigMT); sigtree->Branch("sigMET", &sigMET); sigtree->Branch("sigMETPhi", &sigMETPhi); sigtree->Branch("dPhiLepMET",&dPhiLepMET); sigtree->Branch("nVertex", &nVertex); sigtree->Branch("dRPhoLep", &dRPhoLep); sigtree->Branch("HT", &HT); sigtree->Branch("nJet", &nJet); //************ Signal Tree **********************// TTree *proxytree = new TTree("proxyTree","proxyTree"); float proxyphoEt(0); float proxyphoEta(0); float proxyphoPhi(0); float proxylepPt(0); float proxylepEta(0); float proxylepPhi(0); float proxysigMT(0); float proxysigMET(0); float proxysigMETPhi(0); float proxydPhiLepMET(0); int proxynVertex(0); float proxydRPhoLep(0); float proxyHT(0); float proxynJet(0); proxytree->Branch("phoEt", &proxyphoEt); proxytree->Branch("phoEta", &proxyphoEta); proxytree->Branch("phoPhi", &proxyphoPhi); proxytree->Branch("lepPt", &proxylepPt); proxytree->Branch("lepEta", &proxylepEta); proxytree->Branch("lepPhi", &proxylepPhi); proxytree->Branch("sigMT", &proxysigMT); proxytree->Branch("sigMET", &proxysigMET); proxytree->Branch("sigMETPhi", &proxysigMETPhi); proxytree->Branch("dPhiLepMET",&proxydPhiLepMET); proxytree->Branch("nVertex", &proxynVertex); proxytree->Branch("dRPhoLep", &proxydRPhoLep); proxytree->Branch("HT", &proxyHT); proxytree->Branch("nJet", &proxynJet); //************ Signal Tree **********************// TTree *jettree = new TTree("jetTree","jetTree"); float jetphoEt(0); float jetphoEta(0); float jetphoPhi(0); float jetlepPt(0); float jetlepEta(0); float jetlepPhi(0); float jetsigMT(0); float jetsigMET(0); float jetsigMETPhi(0); float jetdPhiLepMET(0); int jetnVertex(0); float jetdRPhoLep(0); float jetHT(0); float jetnJet(0); jettree->Branch("phoEt", &jetphoEt); jettree->Branch("phoEta", &jetphoEta); jettree->Branch("phoPhi", &jetphoPhi); jettree->Branch("lepPt", &jetlepPt); jettree->Branch("lepEta", &jetlepEta); jettree->Branch("lepPhi", &jetlepPhi); jettree->Branch("sigMT", &jetsigMT); jettree->Branch("sigMET", &jetsigMET); jettree->Branch("sigMETPhi", &jetsigMETPhi); jettree->Branch("dPhiLepMET",&jetdPhiLepMET); jettree->Branch("nVertex", &jetnVertex); jettree->Branch("dRPhoLep", &jetdRPhoLep); jettree->Branch("HT", &jetHT); jettree->Branch("nJet", &jetnJet); /// histo lest TH1F *p_photonEt = new TH1F("photonET","#gamma E_{T}; E_{T} (GeV)",500,0,1500); TH1F *p_photonEta = new TH1F("photonEta","#gamma #eta; #eta;",60,-3,3); TH1F *p_lepPt = new TH1F("lepET","#mu P_{T}; P_{T} (GeV)",500,0,1000); TH1F *p_lepEta = new TH1F("lepEta","#mu #eta; #eta;",60,-3,3); TH1F *p_Mt = new TH1F("Mt","M_{T}; M_{T} (GeV);",200,0,400); TH1F *p_MET = new TH1F("MET","MET",100,0,100); TH1F *p_PhoLepDeltaR = new TH1F("p_PhoLepDeltaR","#DeltaR(e, #gamma); #DeltaR(e, #gamma);",100,0,10); TH1F *p_PhoLepMass = new TH1F("p_PhoLepMass","M_{e#gamma}; M_{e#gamma}(GeV);", 200,0,400); TH1F *p_eventcount = new TH1F("p_eventcount","p_eventcount",7,0,7); rawData raw(es, datatype); std::vector<mcData> MCData; std::vector<recoPhoton> Photon; std::vector<recoMuon> Muon; std::vector<recoEle> Ele; float MET(0); float METPhi(0); int nVtx(0); int jetNumber(0); int METFilter(0); logfile << "RunType: " << datatype << std::endl; std::cout << "Total evetns : " << nEvts << std::endl; for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on entries if (ievt%100000==0) std::cout << " -- Processing event " << ievt << std::endl; raw.GetData(es, ievt); MCData.clear(); Photon.clear(); Muon.clear(); Ele.clear(); if(datatype == MC)for(int iMC(0); iMC < raw.nMC; iMC++){MCData.push_back(mcData(raw, iMC));} for(int iPho(0); iPho < raw.nPho; iPho++){Photon.push_back(recoPhoton(raw, iPho));} for(int iMu(0); iMu < raw.nMu; iMu++){Muon.push_back(recoMuon(raw, iMu));} for(int iEle(0); iEle < raw.nEle; iEle++){Ele.push_back(recoEle(raw, iEle));} MET = raw.pfMET; METPhi = raw.pfMETPhi; METFilter = raw.metFilters; nVtx = raw.nVtx; jetNumber = raw.nJet; nTotal+=1; if(!raw.passHLT())continue; npassHLT+=1; if(raw.nMu < 1 || raw.nPho <1)continue; bool hasPho(false); std::vector<recoPhoton>::iterator signalPho = Photon.begin(); std::vector< std::vector<recoPhoton>::iterator > proxyPhoCollection; proxyPhoCollection.clear(); std::vector< std::vector<recoPhoton>::iterator > jetPhoCollection; jetPhoCollection.clear(); std::vector< std::vector<recoPhoton>::iterator > mcmatchPhoCollection; mcmatchPhoCollection.clear(); for(std::vector<recoPhoton>::iterator itpho = Photon.begin() ; itpho != Photon.end(); ++itpho){ if(itpho->getEt() > 35)mcmatchPhoCollection.push_back(itpho); if(!itpho->isEB())continue; if(!itpho->passHLTSelection())continue; bool passHoverE = itpho->passHoverE(1); bool passNeuIso = itpho->passNeuIso(1); bool passPhoIso = itpho->passPhoIso(1); bool passSigma = itpho->passSigma(1); bool passChIso = itpho->passChIso(1); bool PixelVeto = itpho->PixelSeed()==0? true: false; bool GSFveto(true); bool FSRVeto(true); for(std::vector<recoEle>::iterator ie = Ele.begin(); ie != Ele.end(); ie++){ if(DeltaR(itpho->getEta(), itpho->getPhi(), ie->getEta(), ie->getPhi()) < 0.02)GSFveto = false; if(DeltaR(itpho->getEta(), itpho->getPhi(), ie->getEta(), ie->getPhi()) < 0.3 && DeltaR(itpho->getEta(), itpho->getPhi(), ie->getEta(), ie->getPhi()) > 0.02 && ie->getEt()>2.0)FSRVeto=false; } for(std::vector<recoMuon>::iterator im = Muon.begin(); im != Muon.end(); im++) if(DeltaR(itpho->getEta(), itpho->getPhi(), im->getEta(), im->getPhi()) < 0.3 && im->getEt()>2.0)FSRVeto=false; if(passHoverE && passNeuIso && passPhoIso && itpho->getChIso()<15 && itpho->getSigma()< 0.02){ if(!passSigma || !passChIso){ if(GSFveto && PixelVeto && FSRVeto)jetPhoCollection.push_back(itpho); } } if(!itpho->passSignalSelection())continue; if(GSFveto && PixelVeto && FSRVeto){ if(!hasPho){ hasPho=true; npassPho +=1; signalPho = itpho; } } if(FSRVeto && (!PixelVeto || !GSFveto))proxyPhoCollection.push_back(itpho); } bool hasMu(false); std::vector<recoMuon>::iterator signalMu = Muon.begin(); std::vector< std::vector<recoMuon>::iterator > proxyMuonCollection; proxyMuonCollection.clear(); for(std::vector<recoMuon>::iterator itMu = Muon.begin(); itMu != Muon.end(); itMu++){ if(hasMu)break; if(itMu->passSignalSelection()){ proxyMuonCollection.push_back(itMu); if(!hasMu && hasPho){ hasMu=true; npassMu +=1; signalMu = itMu; } } } bool saveMC(false); if(hasPho && hasMu){ double dRmg = DeltaR(signalPho->getEta(), signalPho->getPhi(), signalMu->getEta(), signalMu->getPhi()); p_PhoLepDeltaR->Fill(dRmg); if(dRmg>0.8){ npassdR+=1; p_PhoLepMass->Fill((signalPho->getCalibP4()+signalMu->getP4()).M()); if(METFilter == 0){ npassMETFilter +=1; if(fabs((signalPho->getCalibP4()+signalMu->getP4()).M() - 91.188) > 10.0)npassZ+=1; float deltaPhi = DeltaPhi(signalMu->getPhi(), METPhi); float MT = sqrt(2*MET*signalMu->getPt()*(1-std::cos(deltaPhi))); phoEt = signalPho->getCalibEt(); phoEta= signalPho->getEta(); phoPhi= signalPho->getPhi(); lepPt = signalMu->getPt(); lepEta= signalMu->getEta(); lepPhi= signalMu->getPhi(); sigMT = MT; sigMET= MET; sigMETPhi = METPhi; dPhiLepMET = deltaPhi; nVertex = nVtx; nJet = jetNumber; p_photonEt->Fill(signalPho->getCalibEt()); p_photonEta->Fill(signalPho->getEta()); p_lepPt->Fill(signalMu->getPt()); p_lepEta->Fill(signalMu->getEta()); p_Mt->Fill(MT); p_MET->Fill(MET); sigtree->Fill(); if(datatype == MC)saveMC=true; }//MET Filter }//dR Filter }//Candidate Filter for(unsigned ip(0); ip < proxyPhoCollection.size(); ip++){ for(unsigned ie(0); ie < proxyMuonCollection.size(); ie++){ std::vector<recoPhoton>::iterator proxyPho = proxyPhoCollection[ip]; std::vector<recoMuon>::iterator proxyMuon = proxyMuonCollection[ie]; double dRmg = DeltaR(proxyPho->getEta(), proxyPho->getPhi(), proxyMuon->getEta(), proxyMuon->getPhi()); if(dRmg>0.8){ if(METFilter == 0){ float proxy_deltaPhi = DeltaPhi(proxyMuon->getPhi(), METPhi); float proxy_MT = sqrt(2*MET*proxyMuon->getPt()*(1-std::cos(proxy_deltaPhi))); proxyphoEt = proxyPho->getCalibEt(); proxyphoEta= proxyPho->getEta(); proxyphoPhi= proxyPho->getPhi(); proxylepPt = proxyMuon->getPt(); proxylepEta= proxyMuon->getEta(); proxylepPhi= proxyMuon->getPhi(); proxysigMT = proxy_MT; proxysigMET= MET; proxysigMETPhi = METPhi; proxydPhiLepMET = proxy_deltaPhi; proxynVertex = nVtx; proxydRPhoLep= dRmg; proxynJet = jetNumber; proxytree->Fill(); if(datatype == MC)saveMC=true; }//MET Filter }//dR filter }// loop on ele collection } // loop on pho collection for(unsigned ip(0); ip < jetPhoCollection.size(); ip++){ for(unsigned ie(0); ie < proxyMuonCollection.size(); ie++){ std::vector<recoPhoton>::iterator jetPho = jetPhoCollection[ip]; std::vector<recoMuon>::iterator jetMuon = proxyMuonCollection[ie]; double dRmg = DeltaR(jetPho->getEta(), jetPho->getPhi(), jetMuon->getEta(), jetMuon->getPhi()); if(dRmg>0.8){ if(METFilter == 0){ float jet_deltaPhi = DeltaPhi(jetMuon->getPhi(), METPhi); float jet_MT = sqrt(2*MET*jetMuon->getPt()*(1-std::cos(jet_deltaPhi))); jetphoEt = jetPho->getCalibEt(); jetphoEta= jetPho->getEta(); jetphoPhi= jetPho->getPhi(); jetlepPt = jetMuon->getPt(); jetlepEta= jetMuon->getEta(); jetlepPhi= jetMuon->getPhi(); jetsigMT = jet_MT; jetsigMET= MET; jetsigMETPhi = METPhi; jetdPhiLepMET = jet_deltaPhi; jetnVertex = nVtx; jetdRPhoLep= dRmg; jetnJet = jetNumber; jettree->Fill(); if(datatype == MC)saveMC=true; }//MET Filter }//dR filter }// loop on ele collection } // loop on pho collection if(datatype == MC && saveMC==true){ mcPID.clear(); mcEta.clear(); mcPhi.clear(); mcPt.clear(); mcMomPID.clear(); for(std::vector<mcData>::iterator itMC = MCData.begin(); itMC!= MCData.end(); itMC++){ for(unsigned ip(0); ip < mcmatchPhoCollection.size(); ip++){ std::vector<recoPhoton>::iterator itPho = mcmatchPhoCollection[ip]; float mcdR = DeltaR(itPho->getEta(), itPho->getPhi(), itMC->getEta(), itMC->getPhi()); if(mcdR < 0.3){ mcPID.push_back(itMC->getPID()); mcMomPID.push_back(itMC->getMomPID()); mcEta.push_back(itMC->getEta()); mcPhi.push_back(itMC->getPhi()); mcPt.push_back(itMC->getEt()); } } } mctree->Fill(); } }//loop on events p_eventcount->Fill("Total",nTotal); p_eventcount->Fill("passHLT",npassHLT); p_eventcount->Fill("passPho",npassPho); p_eventcount->Fill("passMuon",npassMu); p_eventcount->Fill("passdR",npassdR); p_eventcount->Fill("passMETFilter",npassMETFilter); p_eventcount->Fill("passZ",npassZ); outputfile->Write(); logfile.close(); }
inline void computeValidity( Object* o, float dR = 0.4) { if ( DeltaR (*o) < dR ) isValid = 0; }
void closure_elefakepho(){//main float DYJet_XS = 5943.2; float DYJet_nevt = 28747969; float TT_XS = 670.3; float TT_nevt = 37459078; float WW_XS = 63.21; float WW_nevt = 993214; TChain *proxytree = new TChain("signalTree"); proxytree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/proxyTree_egMC.root"); const unsigned nEvts = proxytree->GetEntries(); std::ostringstream outputname; outputname << "closure_DYTT.root"; TFile *outputfile = TFile::Open(outputname.str().c_str(),"RECREATE"); outputfile->cd(); //************ Signal Tree **********************// float proxyphoEt(0); float proxyphoEta(0); float proxyphoPhi(0); float proxylepPt(0); float proxylepEta(0); float proxylepPhi(0); float proxysigMT(0); float proxysigMET(0); float proxysigMETPhi(0); float proxydPhiLepMET(0); int proxynVertex(0); float proxydRPhoLep(0); float proxyHT(0); float proxynJet(0); proxytree->SetBranchAddress("phoEt", &proxyphoEt); proxytree->SetBranchAddress("phoEta", &proxyphoEta); proxytree->SetBranchAddress("phoPhi", &proxyphoPhi); proxytree->SetBranchAddress("lepPt", &proxylepPt); proxytree->SetBranchAddress("lepEta", &proxylepEta); proxytree->SetBranchAddress("lepPhi", &proxylepPhi); proxytree->SetBranchAddress("sigMT", &proxysigMT); proxytree->SetBranchAddress("sigMET", &proxysigMET); proxytree->SetBranchAddress("sigMETPhi", &proxysigMETPhi); proxytree->SetBranchAddress("dPhiLepMET",&proxydPhiLepMET); proxytree->SetBranchAddress("nVertex", &proxynVertex); proxytree->SetBranchAddress("dRPhoLep", &proxydRPhoLep); proxytree->SetBranchAddress("HT", &proxyHT); proxytree->SetBranchAddress("nJet", &proxynJet); TChain *proxymctree = new TChain("MCTree"); proxymctree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/proxyTree_egMC.root"); int proxymcType = 0; proxymctree->SetBranchAddress("mcType", &proxymcType); //*********** histo list **********************// TH1F *p_allPhoEt = new TH1F("p_allPhoEt","#gamma E_{T}; E_{T} (GeV)",500,0,1500); TH1F *p_allPhoEta = new TH1F("p_allPhoEta","#gamma #eta; #eta;",60,-3,3); TH1F *p_allMt = new TH1F("p_allMt","M_{T}; M_{T} (GeV);",200,0,400); TH1F *p_alldPhiEleMET = new TH1F("p_alldPhiEleMET","dPhiEleMET",70,-3.5,3.5); TH1F *p_elebkgPhoEt = new TH1F("p_elebkgPhoEt","#gamma E_{T}; E_{T} (GeV)",500,0,1500); TH1F *p_elebkgPhoEta = new TH1F("p_elebkgPhoEta","#gamma #eta; #eta;",60,-3,3); TH1F *p_elebkgMt = new TH1F("p_elebkgMt","M_{T}; M_{T} (GeV);",200,0,400); TH1F *p_eledPhiEleMET = new TH1F("p_eledPhiEleMET","dPhiEleMET",70,-3.5,3.5); TH1F *p_elebkgPhoEtTT = new TH1F("p_elebkgPhoEtTT","#gamma E_{T}; E_{T} (GeV)",500,0,1500); TH1F *p_elebkgPhoEtaTT = new TH1F("p_elebkgPhoEtaTT","#gamma #eta; #eta;",60,-3,3); TH1F *p_elebkgMtTT = new TH1F("p_elebkgMtTT","M_{T}; M_{T} (GeV);",200,0,400); TH1F *p_eledPhiEleMETTT = new TH1F("p_eledPhiEleMETTT","dPhiEleMET",70,-3.5,3.5); for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on entries proxytree->GetEntry(ievt); proxymctree->GetEntry(ievt); double eventweight = 1; if(proxymcType==1)eventweight = 100000.0*DYJet_XS/DYJet_nevt; else if(proxymcType==2)eventweight = 100000.0*TT_XS/TT_nevt; else if(proxymcType==4)eventweight = 100000.0*WW_XS/WW_nevt; double fakerate = pow(0.0293*proxyphoEt+3.37,-3.04); if(proxyphoEt>110.0)fakerate = 0.5*(fakerate + (243.047+48.3986)/(243.047+48.3986+39536.2+23002.2)); double w_ele = fakerate/(1-fakerate)*eventweight; float deltaPhi = proxylepPhi - proxysigMETPhi; if(fabs(deltaPhi) > TMath::Pi()){ if(deltaPhi > 0)deltaPhi = -1.0*(TMath::TwoPi() - fabs(deltaPhi)); else deltaPhi = TMath::TwoPi() - fabs(deltaPhi); } if(proxymcType==1){ p_elebkgPhoEt->Fill(proxyphoEt,w_ele); p_elebkgPhoEta->Fill(proxyphoEta, w_ele); p_elebkgMt->Fill(proxysigMT, w_ele); p_eledPhiEleMET->Fill(deltaPhi, w_ele); } else if(proxymcType==2 || proxymcType==4){ p_elebkgPhoEtTT->Fill(proxyphoEt,w_ele); p_elebkgPhoEtaTT->Fill(proxyphoEta, w_ele); p_elebkgMtTT->Fill(proxysigMT, w_ele); p_eledPhiEleMETTT->Fill(deltaPhi, w_ele); } } //************ Signal Tree **********************// TChain *sigtree = new TChain("signalTree"); sigtree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/resTree_egMC.root"); float sigphoEt(0); float sigphoEta(0); float sigphoPhi(0); float siglepPt(0); float siglepEta(0); float siglepPhi(0); float sigsigMT(0); float sigsigMET(0); float sigsigMETPhi(0); float sigdPhiLepMET(0); int signVertex(0); float sigdRPhoLep(0); float sigHT(0); float signJet(0); sigtree->SetBranchAddress("phoEt", &sigphoEt); sigtree->SetBranchAddress("phoEta", &sigphoEta); sigtree->SetBranchAddress("phoPhi", &sigphoPhi); sigtree->SetBranchAddress("lepPt", &siglepPt); sigtree->SetBranchAddress("lepEta", &siglepEta); sigtree->SetBranchAddress("lepPhi", &siglepPhi); sigtree->SetBranchAddress("sigMT", &sigsigMT); sigtree->SetBranchAddress("sigMET", &sigsigMET); sigtree->SetBranchAddress("sigMETPhi", &sigsigMETPhi); sigtree->SetBranchAddress("dPhiLepMET",&sigdPhiLepMET); sigtree->SetBranchAddress("nVertex", &signVertex); sigtree->SetBranchAddress("dRPhoLep", &sigdRPhoLep); sigtree->SetBranchAddress("HT", &sigHT); sigtree->SetBranchAddress("nJet", &signJet); TChain *mctree = new TChain("MCTree"); mctree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/resTree_egMC.root"); int mcType = 0; std::vector<int> *mcPID=0; std::vector<float> *mcEta=0; std::vector<float> *mcPhi=0; std::vector<float> *mcPt=0; std::vector<int> *mcMomPID=0; mctree->SetBranchAddress("mcType", &mcType); mctree->SetBranchAddress("mcPID", &mcPID); mctree->SetBranchAddress("mcEta", &mcEta); mctree->SetBranchAddress("mcPhi", &mcPhi); mctree->SetBranchAddress("mcPt", &mcPt); mctree->SetBranchAddress("mcMomPID", &mcMomPID); TH1F *p_dRMC = new TH1F("p_dRMC","p_dRMC",30,0,0.3); TH1F *p_dEMC = new TH1F("p_dEMC","p_dEMC",100,0,1); TH1F *p_nMatch = new TH1F("p_nMatch","p_nMatch",10,0,10); for (unsigned ievt(0); ievt<sigtree->GetEntries(); ++ievt){//loop on entries sigtree->GetEntry(ievt); mctree->GetEntry(ievt); double eventweight = 1; if(mcType==1)eventweight = 100000.0*DYJet_XS/DYJet_nevt; else if(mcType==2)eventweight = 100000.0*TT_XS/TT_nevt; else if(mcType==4)eventweight = 100000.0*WW_XS/WW_nevt; double mindR(0.3),deltaE(1); unsigned matchIndex(0); int nMatch(0); int nMatchPho(0); for(unsigned iMC(0); iMC < mcPID->size(); iMC++){ if((*mcPt)[iMC] < 10)continue; double dR = DeltaR((*mcEta)[iMC], (*mcPhi)[iMC], sigphoEta, sigphoPhi); double dE = fabs((*mcPt)[iMC] - sigphoEt)/sigphoEt; if(dR < mindR && dE < 0.5){mindR=dR; matchIndex=iMC;deltaE = dE;} } if(mindR < 0.15 && deltaE < 0.5){ if(((*mcPID)[matchIndex] == 11 || (*mcPID)[matchIndex] == -11)){ float deltaPhi = siglepPt - sigsigMETPhi; if(fabs(deltaPhi) > TMath::Pi()){ if(deltaPhi > 0)deltaPhi = -1.0*(TMath::TwoPi() - fabs(deltaPhi)); else deltaPhi = TMath::TwoPi() - fabs(deltaPhi); } p_allPhoEt->Fill(sigphoEt,eventweight); p_allPhoEta->Fill(sigphoEta, eventweight); p_allMt->Fill(sigsigMT, eventweight); p_alldPhiEleMET->Fill(deltaPhi, eventweight); } } } outputfile->Write(); gStyle->SetOptStat(0); Double_t plotPtBins[]={35,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,90,100,110,120,130,140,200}; TCanvas *c_pt = new TCanvas("Photon_Pt", "Photon P_{T}",600,600); c_pt->cd(); gPad->SetLogy(); TH1 *new_allPhoEt = p_allPhoEt->Rebin(2); TH1 *new_elebkgPhoEt = p_elebkgPhoEt->Rebin(2); TH1 *new_elebkgPhoEtTT = p_elebkgPhoEtTT->Rebin(2); new_allPhoEt->GetXaxis()->SetRangeUser(35,200); new_allPhoEt->Draw(); new_allPhoEt->SetLineColor(kBlack); new_allPhoEt->SetMarkerStyle(20); new_elebkgPhoEt->SetFillStyle(1001); new_elebkgPhoEt->SetLineColor(kRed); new_elebkgPhoEt->SetFillColor(kRed); new_elebkgPhoEt->Draw("hist same"); new_elebkgPhoEtTT->Add(new_elebkgPhoEt); new_elebkgPhoEtTT->SetLineColor(kGreen); new_elebkgPhoEtTT->SetFillStyle(1001); new_elebkgPhoEtTT->SetFillColor(kGreen); new_elebkgPhoEtTT->Draw("hist same"); new_elebkgPhoEt->Draw("hist same"); TLegend *leg = new TLegend(0.6,0.7,0.9,0.9); leg->SetFillStyle(0); gStyle->SetLegendBorderSize(1); gStyle->SetLegendFillColor(0); leg->AddEntry(new_allPhoEt,"observed"); leg->AddEntry(new_elebkgPhoEtTT,"EWK (tt, WW)"); leg->AddEntry(new_elebkgPhoEt,"DY"); leg->Draw("same"); new_allPhoEt->Draw("same"); c_pt->SaveAs("EfakePho_closure.pdf"); TCanvas *c_mt = new TCanvas("MT", "MT",600,600); c_mt->cd(); gPad->SetLogy(); TH1 *new_allMt = p_allMt->Rebin(2); TH1 *new_elebkgMt = p_elebkgMt->Rebin(2); TH1 *new_elebkgMtTT = p_elebkgMtTT->Rebin(2); new_allMt->GetXaxis()->SetRangeUser(35,200); new_allMt->Draw(); new_allMt->SetLineColor(kBlack); new_allMt->SetMarkerStyle(20); new_elebkgMt->SetFillStyle(1001); new_elebkgMt->SetLineColor(kRed); new_elebkgMt->SetFillColor(kRed); new_elebkgMt->Draw("hist same"); new_elebkgMtTT->Add(new_elebkgMt); new_elebkgMtTT->SetLineColor(kGreen); new_elebkgMtTT->SetFillStyle(1001); new_elebkgMtTT->SetFillColor(kGreen); new_elebkgMtTT->Draw("hist same"); new_elebkgMt->Draw("hist same"); TLegend *leg2 = new TLegend(0.6,0.7,0.9,0.9); leg2->SetFillStyle(0); gStyle->SetLegendBorderSize(1); gStyle->SetLegendFillColor(0); leg2->AddEntry(new_allMt,"observed"); leg2->AddEntry(new_elebkgMtTT,"EWK (tt, WW)"); leg2->AddEntry(new_elebkgMt,"DY"); leg2->Draw("same"); new_allMt->Draw("same"); c_mt->SaveAs("EfakeMT_closure.pdf"); }