TH1* processFile(TString fname, double scaleFactor){ static int hcounter=0; cout<<"Doing fname="<<fname<<endl; TFile *_file2 = TFile::Open(fname); PS->cd(); TString plot = "lLV[0].lpfIso:lLV[0].fP.Eta()"; TString hname = Form("h%i",hcounter); jets2p->Draw(plot +" >> " + hname+"(24,-3,3,100,0,2)","","qn"); TH2D *aux = (TH2D*)gDirectory->Get(hname); //aux->Scale(scaleFactor); TH1D * ss = aux->ProjectionX(hname+"ss",1,10); // signal region TH1D * ni = aux->ProjectionX(hname+"ni",16,100);// nonIso region (use 11 //cout<<"h="<<hcounter<<" ss="<<ss->GetEntries()<<" ni="<<ni->GetEntries()<<endl; TString statis = Form("( %i / %i )",(int)ss->GetEntries(),(int)ni->GetEntries()); ss->Divide(ni); ss->GetYaxis()->SetTitle(TString("N_{signal}/N_{nonIso}")+statis); ss->GetXaxis()->SetTitle("#eta"); hcounter++; return ss; }
/** * End of job processing */ void Terminate(Option_t*) { fList = dynamic_cast<TList*>(GetOutputData(1)); if (!fList) { AliError(Form("No output list defined (%p)", GetOutputData(1))); if (GetOutputData(1)) GetOutputData(1)->Print(); return; } TList* output = new TList; output->SetName("triggerResults"); output->SetOwner(); fVertexMC = static_cast<TH1D*>(fList->FindObject("vertexMC")); fVertexESD = static_cast<TH1D*>(fList->FindObject("vertexESD")); fM = static_cast<TH1D*>(fList->FindObject("m")); if (fVertexMC) { TH1D* vtxMC = static_cast<TH1D*>(fVertexMC->Clone("vertexMC")); vtxMC->SetDirectory(0); if (vtxMC->GetEntries() > 0) vtxMC->Scale(1. / vtxMC->GetEntries()); else vtxMC->Scale(0); output->Add(vtxMC); } if (fVertexESD) { TH1D* vtxESD = static_cast<TH1D*>(fVertexESD->Clone("vertexESD")); vtxESD->SetDirectory(0); if (vtxESD->GetEntries() > 0) vtxESD->Scale(1. / vtxESD->GetEntries()); else vtxESD->Scale(0); output->Add(vtxESD); } if (fM) { TH1D* m = static_cast<TH1D*>(fM->Clone("m")); m->SetDirectory(0); m->SetYTitle("P(N_{ch}|_{|#eta|<1} < X)"); if (m->GetBinContent(1) > 0) m->Scale(1. / m->GetBinContent(1)); else m->Scale(0); output->Add(m); } TString vtxReq; if (fVertexRequirement & kMC) vtxReq.Append("MC "); if (fVertexRequirement & kESD) vtxReq.Append("ESD "); output->Add(new TNamed("vtxReq", vtxReq.Data())); output->Add(new TNamed("trkReq", fTrackletRequirement == kMC ? "MC" : "ESD")); fInel.Finish(fList, output); fInelGt0.Finish(fList, output); fNSD.Finish(fList, output); fNClusterGt0.Finish(fList, output); PostData(2, output); }
int testFile(TString fileName){ TFile *fd = TFile::Open(fileName); TH1D* cuts = (TH1D*)fd->Get("Cuts"); TH1D* x = (TH1D*)fd->Get("xDistrib"); cout << (int)cuts->GetEntries() << ":" << (int)x->GetEntries() << endl; return 0; }
void setNumbersInSamplesInfo(SamplesInfo& s, string histNameEta, string histHt){ std::map<string, double>::iterator it = s.Xsections.begin(); for(; it != s.Xsections.end(); it++){ TFile* f = TFile::Open(string("Wshape/Wshape_"+it->first+"_plots.root").c_str()); TH1D * h = (TH1D*)f->Get(histNameEta.c_str()); s.NFwdEta[it->first] = h->GetEntries(); h = (TH1D*)f->Get(histHt.c_str()); s.NHt[it->first] = h->GetEntries(); } }
void testIntegration(){ TFile* infile = new TFile("/Users/keithlandry/Desktop/testPtHist.root"); TH1D * h = infile->Get("Pt"); int bmin = 751; int bmax = bmin+1; double binval = 0; int numberOfPairs = 0; cout << "starting at bmin = " << bmin << " bmax = " << bmax << endl; cout << (double)h->GetEntries()/9.0 << endl; for (int i=0; i < h->GetNbinsX()-bmin; i++) { bmax++; cout << " i = " << i << " bmax = " << bmax << endl; int integ = h->Integral(bmin,bmax); cout << bmax << " " << integ << endl; binval += h->GetBinContent(bmax)*h->GetBinCenter(bmax); numberOfPairs += h->GetBinContent(bmax); if (integ > (double)h->GetEntries()/9.0) { cout << bmax << " " << integ << endl; lastI = i; break; } if (bmax == 1000) { break; } } cout << "avg val of bin " << (double)binval/numberOfPairs << endl; cout << " Pt = " << h->GetBinCenter(bmax) << endl; }
void calcAcceptance(TFile *f, TString chan, Int_t n, vector<Double_t> &scale, TString sname) { char hname[100]; for (Int_t i=0; i<n; i++) { Bool_t prnt = kFALSE; if (sname=="MMHT2014nlo68cl" && i==0) prnt = kTRUE; //cout << sname << ", i = " << i << endl; if (prnt) cout << chan << " "; sprintf(hname, "dTot_%s_%i", sname.Data(), i); TH1D *tot = (TH1D*) f->Get(hname); Double_t s = tot->Integral()/tot->GetEntries(); Double_t accept; if (chan=="wmm" || chan=="wme" || chan=="wpe" || chan=="wpm") { sprintf(hname, "dPostB_%s_%i", sname.Data(), i); TH1D *bar = (TH1D*) f->Get(hname); accept=bar->Integral()/(tot->Integral()); //cout << "Barrel Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; sprintf(hname, "dPostE_%s_%i", sname.Data(), i); TH1D *end = (TH1D*) f->Get(hname); accept=end->Integral()/(tot->Integral()); //cout << "Endcap Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; accept=(bar->Integral()+end->Integral())/(tot->Integral()); } else if (chan=="zmm" || chan=="zee") { sprintf(hname, "dPostBB_%s_%i", sname.Data(), i); TH1D *bb = (TH1D*) f->Get(hname); accept=bb->Integral()/(tot->Integral()); //cout << "Bar-bar Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; sprintf(hname, "dPostBE_%s_%i", sname.Data(), i); TH1D *be = (TH1D*) f->Get(hname); accept=be->Integral()/(tot->Integral()); //cout << "Bar-end Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; sprintf(hname, "dPostEE_%s_%i", sname.Data(), i); TH1D *ee = (TH1D*) f->Get(hname); accept=ee->Integral()/(tot->Integral()); //cout << "End-end Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; accept=(bb->Integral()+be->Integral()+ee->Integral())/(tot->Integral()); } if (prnt) cout << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; //cout << "Scale: " << tot->Integral()/tot->GetEntries() << endl; //scale.push_back(s); scale.push_back(accept); } }
/*--------------------------------------------*/ void FitCosTheta() /*--------------------------------------------*/ { //TH1F *brgauss = new TH1F("breitg","", 131, 0, 130); TFile * file = new TFile("cosTheta_allnadjieh.root","READ"); TH1D * h = (TH1D*)file->Get("cosThetaGen"); //h->Scale(1./h->Integral()); h->Sumw2(); /*TFile * file= new TFile("WPol_SelectedTTBars.root","read"); TH1D* h = (TH1D*)file->Get("costheta_mm/hCosThetaPosLepton_Gen");*/ h->Rebin(10); //h->Scale(1./h->Integral()); TF1 *f = new TF1("f",cosTheta, -1, 1 ,3); Double_t par[3]; par[0] = 1; par[1] = 1; par[2] = h->GetEntries(); f->SetParameters(par); h->Fit(f, "RBO"); h->Fit(f, "RBO"); h->Fit(f, "RBO"); h->Fit(f, "RBO"); h->Fit(f, "RBO"); }
TH1D * smartGausProfileXSQRTN (TH2F * strip, double width){ TProfile * stripProfile = strip->ProfileX () ; // (from FitSlices of TH2.h) double xmin = stripProfile->GetXaxis ()->GetXmin () ; double xmax = stripProfile->GetXaxis ()->GetXmax () ; int profileBins = stripProfile->GetNbinsX () ; std::string name = strip->GetName () ; name += "_smartGaus_X" ; TH1D * prof = new TH1D(name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ; int cut = 0 ; // minimum number of entries per fitted bin int nbins = strip->GetXaxis ()->GetNbins () ; int binmin = 1 ; int ngroup = 1 ; // bins per step int binmax = nbins ; // loop over the strip bins for (int bin=binmin ; bin<=binmax ; bin += ngroup) { TH1D *hpy = strip->ProjectionY ("_temp",bin,bin+ngroup-1,"e") ; if (hpy == 0) continue ; int nentries = Int_t (hpy->GetEntries ()) ; if (nentries == 0 || nentries < cut) {delete hpy ; continue ;} Int_t biny = bin + ngroup/2 ; TF1 * gaussian = new TF1 ("gaussian","gaus", hpy->GetMean () - width * hpy->GetRMS (), hpy->GetMean () + width * hpy->GetRMS ()) ; gaussian->SetParameter (1,hpy->GetMean ()) ; gaussian->SetParameter (2,hpy->GetRMS ()) ; hpy->Fit ("gaussian","RQL") ; // hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (), hpy->GetMean () + width * hpy->GetRMS ()) ; prof->Fill (strip->GetXaxis ()->GetBinCenter (biny), gaussian->GetParameter (1)) ; prof->SetBinError (biny,gaussian->GetParameter (2) / sqrt(hpy->GetEntries())) ; // prof->SetBinError (biny,gaussian->GetParError (1)) ; delete gaussian ; delete hpy ; } // loop over the bins delete stripProfile ; return prof ; }
void pixelVariationLowRange(const char *filenameOld = "../rootFiles/LRLScanOldSettings.root", const char *filenameNew = "../rootFiles/LRLScanNewSettings.root", const char *filenameMedium = "../rootFiles/LRLScanOldSettings.root") { TFile *f1 = new TFile(filenameOld); TFile *f2 = new TFile(filenameNew); TFile *f3 = new TFile(filenameMedium); Init(); TLegend *legend = new TLegend(0.65,0.6,0.95,0.95); cout << "test" << endl; color = 4; TH1D *oldSettings = Analysis(f1); color = 1; TH1D *newSettings = Analysis(f2); color = 2; TH1D *mediumSettings = Analysis(f3); cout << "Entries old settings = " << oldSettings->GetEntries() << endl; cout << "Entries medium settings = " << mediumSettings->GetEntries() << endl; cout << "Entries new settings = " << newSettings->GetEntries() << endl; legend->AddEntry(oldSettings,"oldSettings","L"); legend->AddEntry(mediumSettings,"mediumSettings","L"); legend->AddEntry(newSettings,"newSettings","L"); newSettings->GetYaxis()->SetTitleOffset(1.2); canvas->Clear(); newSettings->Draw(); oldSettings->Draw("same"); mediumSettings->Draw("same"); legend->Draw(); canvas->SaveAs("aoverb.png"); canvas->SaveAs("aoverb.root"); }
void calcAcceptance(TFile *f, TString chan, Int_t as, Int_t n, vector<Double_t> &scale) { char hname[100]; for (Int_t i=0; i<n; i++) { Bool_t prnt=kTRUE; if (as==18 && i==0) cout << "Nominal "; if (prnt) cout << "A (" << chan << "): "; sprintf(hname, "dTot_NNPDF30_nlo_as_01%i_%i", as, i); TH1D *tot = (TH1D*) f->Get(hname); Double_t accept; if (chan=="wmm" || chan=="wme" || chan=="wpe" || chan=="wpm") { sprintf(hname, "dPostB_NNPDF30_nlo_as_01%i_%i", as, i); TH1D *bar = (TH1D*) f->Get(hname); accept=bar->Integral()/(tot->Integral()); //if (prnt) cout << "Barrel Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; sprintf(hname, "dPostE_NNPDF30_nlo_as_01%i_%i", as, i); TH1D *end = (TH1D*) f->Get(hname); accept=end->Integral()/(tot->Integral()); //if (prnt) cout << "Endcap Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; accept=(bar->Integral()+end->Integral())/(tot->Integral()); } else if (chan=="zmm" || chan=="zee") { sprintf(hname, "dPostBB_NNPDF30_nlo_as_01%i_%i", as, i); TH1D *bb = (TH1D*) f->Get(hname); accept=bb->Integral()/(tot->Integral()); //if (prnt) cout << "Bar-bar Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; sprintf(hname, "dPostBE_NNPDF30_nlo_as_01%i_%i", as, i); TH1D *be = (TH1D*) f->Get(hname); accept=be->Integral()/(tot->Integral()); //if (prnt) cout << "Bar-end Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; sprintf(hname, "dPostEE_NNPDF30_nlo_as_01%i_%i", as, i); TH1D *ee = (TH1D*) f->Get(hname); accept=ee->Integral()/(tot->Integral()); //if (prnt) cout << "End-end Acceptance: " << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; accept=(bb->Integral()+be->Integral()+ee->Integral())/(tot->Integral()); } if (prnt) cout << accept << " +/- " << sqrt(accept*(1-accept)/tot->GetEntries()) << endl; scale.push_back(accept); } }
void checkdead(const char *run="19020_19035") { TString inname; TFile *file; TH1D *out; for(int arm=0; arm!=2; ++arm) for(int lyr=0; lyr!=8; ++lyr) for(int sen=0; sen!=24; ++sen) for(int mpd=0; mpd!=128; ++mpd) { inname = Form("%s/adc/HI_ARM%d_LYR%d_S%d_M%d.root",run,arm,lyr,sen,mpd); file = TFile::Open( inname.Data() ); out = (TH1D*) file->Get("out"); if(out->GetEntries()==0) printf("%d %d %d %d\n",arm,lyr,sen,mpd); file->Close(); } return; }
void AdjustDensityForBinWidth(TH1D &h) { double entries = h.GetEntries(); int nbins = h.GetNbinsX(); double low = h.GetBinLowEdge(1); double high = h.GetBinLowEdge(nbins+1); double width = (high-low)/nbins; for(int bin = 1; bin <= nbins; ++bin) { double content = h.GetBinContent(bin); double error = h.GetBinError(bin); double this_width = h.GetBinWidth(bin); double scale = width/this_width; h.SetBinContent(bin, content*scale); h.SetBinError(bin, error*scale); } h.SetEntries(entries); }
inputValues getInputValues(TString fileName, double pw, string cutString) { TFile * file = new TFile(fileName, "READ"); TTree * tree = (TTree*)file->Get("Channel_1"); tree->Draw("(-1)*Min>>hist(300, 0, 30)"); TH1D * hist = (TH1D*)gDirectory->Get("hist"); inputValues inVal; inVal.pw = pw; inVal.n = hist->GetEntries(); inVal.v = pow(hist->GetStdDev(), 2); inVal.e = hist->GetMean(); inVal.a = tree->Draw("Min", (TString)cutString); inVal.h = hist; return inVal; }
void addPolarizationHists(){ TFile* infile = new TFile("/star/u/klandry/ucladisk/2012IFF/results_5_19/5_19Full.root"); TH1D* polHist = new TH1D("polHist","polHist",25,0,1); for (int i=0; i<5; i++) { for (int j=0; j<32; j++) { char name[50]; sprintf(name, "hPolOfBin_Ptbin_%d_phiSRbin_%d",i,j); cout << name << endl; TH1D* tempHist = infile->Get(name); cout << tempHist->GetEntries() << endl; polHist->Add(tempHist, 1); } } polHist->Draw(); }
int GetTotalEvents(TChain *chain) { int numevents = 0; TObjArray *files = chain->GetListOfFiles(); for (int i=0; i<files->GetEntries(); ++i) { TFile *file = TFile::Open(files->At(i)->GetTitle(),"READ"); TDirectory *fwkdir = (TDirectory*)file->FindObjectAny("AnaFwkMod"); TH1D *hevents = (TH1D*)fwkdir->Get("hDAllEvents"); numevents += hevents->GetEntries(); file->Close(); } return numevents; }
inputValues getInputValues(TString fileName, double pw, bool cm, string cutString) { TFile * file = new TFile(fileName, "READ"); TTree * tree = (TTree*)file->Get("Channel_8"); tree->Draw("Charge>>hist"); TH1D * hist = (TH1D*)gDirectory->Get("hist"); inputValues inVal; inVal.pw = pw; inVal.cm = cm; inVal.n = hist->GetEntries(); inVal.v = pow(hist->GetStdDev(), 2); inVal.e = -hist->GetMean(); // Flip sign inVal.a = tree->Draw("Charge", (TString)cutString); inVal.h = hist; // Debugging cout << inVal.pw << " " << inVal.e << " " << (float)inVal.a/inVal.n << " " << inVal.cm << endl; return inVal; }
void FitHist(Double_t * d, char * path) { TH1D* hist = GetHist(path); if (hist == NULL ) { d[0]=-1; d[1]=-1; d[2]=-1; return; } TF1 *func = new TF1 ("fit",DoubleErrf,hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax(),3); func->SetParameters(0.,0.1,hist->GetEntries()); func->SetParNames ("Mean_value","Sigma","N"); hist->Fit("fit","Q"); //Double_t d[2]; d[0]=func->GetParameter(0); d[1]=func->GetParameter(1); d[2]=func->GetParameter(2); //return d; //cout<<endl<<"for "<<path<<endl<<"mean = "<<func->GetParameter(0)<<endl<<"sigma = "<<func->GetParameter(1)<<endl; }
TH1D* ChargeToMPV(TH2* InputHisto, char* Name, bool DivideByX) { TH1D* toReturn = new TH1D(Name,Name,InputHisto->GetXaxis()->GetNbins(), InputHisto->GetXaxis()->GetXmin(), InputHisto->GetXaxis()->GetXmax() ); double Results[4]; for(int i=0;i<=InputHisto->GetXaxis()->GetNbins();i++){ TH1D* proj = InputHisto->ProjectionY("",i,i); if(proj->GetEntries()<50){delete proj;continue;} TF1* landau = getLandau(proj,Results); if(DivideByX){ toReturn->SetBinContent(i,Results[0] / InputHisto->GetXaxis()->GetBinCenter(i) ); toReturn->SetBinError (i,Results[1] / InputHisto->GetXaxis()->GetBinCenter(i) ); }else{ toReturn->SetBinContent(i,Results[0]); toReturn->SetBinError (i,Results[1]); } delete landau; delete proj; } return toReturn; }
void dimuonLoop(float ptmin, float ptmax, float ymin, float ymax, int i) { TFile *infData = new TFile(inputdata); TFile *infMC = new TFile(inputmc); TTree *ntData = (TTree*) infData->Get("ntKp"); TTree *ntMC = (TTree*) infMC->Get("ntKp"); TCanvas *c = new TCanvas(Form("c%i",i),"",600,600); //if (logy) c->SetLogy(); TH1D* hData = new TH1D("hData","",50,2.85,3.35); TH1D* hMC = new TH1D("hMC","",50,2.85,3.35); ntData->Project("hData","mumumass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax)); ntMC->Project("hMC","mumumass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax)); hData->Sumw2(); double normData=0,normMC=0; normData = hData->GetEntries(); normMC = hMC->GetEntries(); cout<<normData<<" "<<normMC<<endl; hData->Scale(1./normData); hMC->Scale(1./normMC); hData->Sumw2(); hMC->SetXTitle("#mu#mu mass"); hMC->SetYTitle("#Probability"); hMC->SetTitleOffset(1.5,"Y"); if(hData->GetMaximum()>hMC->GetMaximum()) hMC->SetMaximum(hData->GetMaximum()*1.1); else hMC->SetMaximum(hMC->GetMaximum()*1.1); //hData->SetLineColor(kBlue+1); //hData->SetFillStyle(1001); //hData->SetFillColor(kBlue-9); //hData->SetLineWidth(3); hData->SetMarkerStyle(8); hData->SetStats(0); hMC->SetLineColor(kRed); hMC->SetFillStyle(3004); hMC->SetFillColor(kRed); hMC->SetLineWidth(3); hMC->SetStats(0); hMC->Draw(); hData->Draw("same lep"); TLegend *leg = new TLegend(0.11,0.75,0.50,0.9); leg->AddEntry(hData,"data","lep"); leg->AddEntry(hMC,"MC","f"); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->Draw("same"); TLegend *leg1 = new TLegend(0.60,0.7,0.90,0.9); leg1->AddEntry((TObject*)0,Form("%s",particle.Data()),""); leg1->AddEntry((TObject*)0,Form("%.0f<p_{T}<%.0f GeV",ptmin,ptmax),""); leg1->AddEntry((TObject*)0,Form("%.1f<y_{CM}<%.1f",ymin,ymax),""); leg1->SetBorderSize(0); leg1->SetFillStyle(0); leg1->Draw("same"); c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_yDM_%i.pdf",i)); //c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_%i.pdf",i)); //c->SaveAs("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_incl_1.pdf"); }
void L1Emul_macro() { //TH1::SetDefaultSumw2(); TFile *file[2]; TTree *HltTree[2]; TString L1Emul_data = "/net/hidsk0001/d00/scratch/luck/data/HiForest.root"; TString Minbias_data = "/net/hisrv0001/home/icali/hadoop/HIMinBiasUPC_skimmed/MinBias-reTracking-merged/MinBias_Merged_tracking_all.root"; file[0] = new TFile(L1Emul_data); HltTree[0] = (TTree*)file[0]->Get("hltanalysis/HltTree"); HltTree[0]->AddFriend("t=icPu5JetAnalyzer/t",L1Emul_data); file[1] = new TFile(Minbias_data); HltTree[1] = (TTree*)file[1]->Get("hltanalysis/HltTree"); HltTree[1]->AddFriend("t=icPu5JetAnalyzer/t",Minbias_data); TString L1_SingleJet = "L1_SingleJet"; TString thresholds[] = {"16", "36_BptxAND", "52_BptxAND", "68_BptxAND", "80_BptxAND", "92_BptxAND", "128_BptxAND"}; int thresholdi[] = {16, 36, 52, 68, 80, 92, 128}; // TH1D *hist_bottom = new TH1D("hist_bottom","Denominator", 30, 0, 120); // HltTree->Project("hist_bottom","t.jtpt[0]"); // for(int i = 0; i < 6; i++) // { // TH1D *hist = new TH1D(L1_SingleJet+thresholds[i], // L1_SingleJet+thresholds[i], // 30, 0, 120); // HltTree->Project(L1_SingleJet+thresholds[i], // "t.jtpt[0]", // L1_SingleJet+thresholds[i]); // hist->Divide(hist, hist_bottom, 1, 1, "b"); // TCanvas *co = new TCanvas(); // hist->GetYaxis()->SetRangeUser(0,1); // hist->Draw("p,E"); // } Double_t xbins[9] = {-2,2,30,42,62,74,86,98,158}; TH1D *efficiency_curve[4]; efficiency_curve[0] = new TH1D("efficiency_curve_0","Efficiency", 8,xbins); efficiency_curve[1] = new TH1D("efficiency_curve_1","Efficiency", 8,xbins); for(int i = 0; i < 2; i++) { efficiency_curve[i]->SetXTitle("L1 Jet Trigger Threshold"); efficiency_curve[i]->SetYTitle("Fraction of Passing Events"); efficiency_curve[i]->Fill(0.,1.); for(int j = 0; j < 7; j++) { TH1D *hist = new TH1D(L1_SingleJet+thresholds[j], L1_SingleJet+thresholds[j], 2, -0.5, 1.5); HltTree[i]->Project(L1_SingleJet+thresholds[j], L1_SingleJet+thresholds[j]); efficiency_curve[i]->Fill(thresholdi[j],hist->GetBinContent(2)/hist->GetEntries()); delete hist; } efficiency_curve[i]->GetYaxis()->SetRangeUser(0,1); efficiency_curve[i]->GetXaxis()->SetRangeUser(0,130); } TriggerPrimitivesTree_alex *min = new TriggerPrimitivesTree_alex(new TFile("minbias.root")); int total_events = 5000; TH1D *temp[2]; temp[0] = (TH1D*)min->Loop(total_events, 0, false, false)->Clone(); temp[1] = (TH1D*)min->Loop(total_events, 0, true, false)->Clone(); for(int j = 0; j < 2; j++) { stringstream s; s << "efficiency_curve_" << j+2; efficiency_curve[j+2] = new TH1D(s.str().c_str(),"efficiency_curve", temp[j]->GetNbinsX(),0,temp[j]->GetXaxis()->GetXmax()); for(int i = 0; i < temp[j]->GetNbinsX(); i++) { efficiency_curve[j+2]->Fill(temp[j]->GetBinCenter(i), temp[j]->GetBinContent(i)); } } TCanvas *c0 = new TCanvas(); efficiency_curve[0]->SetLineColor(kRed); efficiency_curve[1]->SetLineColor(kBlue); efficiency_curve[2]->SetLineColor(40); efficiency_curve[3]->SetLineColor(30); efficiency_curve[0]->Draw("L"); efficiency_curve[1]->Draw("L,same"); efficiency_curve[2]->Draw("L,same"); efficiency_curve[3]->Draw("L,same"); TLegend *leg = new TLegend(0.5,0.5,0.8,0.7); leg->SetFillColor(0); leg->AddEntry(efficiency_curve[1],"Current L1 System, official","l"); leg->AddEntry(efficiency_curve[2],"Current L1 System, ntuples","l"); leg->AddEntry(efficiency_curve[0],"Phi-Ring Subtraction at L1, official","l"); leg->AddEntry(efficiency_curve[3],"Phi-Ring Subtraction at L1, ntuples","l"); leg->Draw(); c0->Update(); }
void calculateTriggerRates( TString inFile0Name = "root://eoscms//eos/cms/store/caf/user/velicanu/PA2013_merged_HiForest/pPb_hiForest2_pilotRun_200kHz_v3.root", // TString inFile0Name = "/castor/cern.ch/user/m/miheejo/openHLT/cms442/r181530_reco_v1_2/HIExpressPhysics_hiexp-hirun2011-r181530-reco-v1_2.root", // "/castor/cern.ch/user/k/kimy/openHLT//openhlt_run181531.root", // "/castor/cern.ch/user/v/velicanu/HIHLT_Validation_Test_GRIF_v10.root", Int_t runNum = 202792, TString outdir = "output", char *projectTitle = "HIpARun2013", string source = "data" ) { char szBuf[256]; int scale = 23; // event selectoin //Form("&&Run==%d&&LumiBlock>%d",runNum,goodLumiStart) // trigger under investigation // const int ntrigs = 8; // const char* triggerPath[ntrigs] = {"","HLT_HIMinBiasHfOrBSC", // "L1_SingleMu3_BptxAND","HLT_HIL1SingleMu3","HLT_HIL2Mu3", // "L1_DoubleMuOpen_BptxAND","HLT_HIL1DoubleMuOpen","HLT_HIL2DoubleMu3"}; /* const int ntrigs = 9; const char* triggerPath[ntrigs] = { "", "HLT_PAL1SingleMuOpen_v1", "HLT_PAL1SingleMu3_v1", "HLT_PAL1SingleMu7_v1", "HLT_PAL1SingleMu12_v1", "HLT_PAL1DoubleMu0_v1", "HLT_PADimuon0_NoVertexing_v1", "HLT_PAMu5_v1", "HLT_PAMu8_v1" }; */ //trigger list for singleMu rate plot const int ntrigs = 4 ; const char* triggerPath[ntrigs] = { "", "HLT_PAMu3_v1", "HLT_PAMu7_v1", "HLT_PAMu12_v1" }; /* //trigger list for DoubleMu rate plot const int ntrigs = 4 ; const char* triggerPath[ntrigs] = { "", "HLT_PAL1DoubleMuOpen_v1", "HLT_PAL1DoubleMu0_HighQ_v1", "HLT_PAL2DoubleMu3_v1" }; //trigger list fo bJet+Mu rate plot const int ntrigs =5; const char* triggerPath[ntrigs] = { "", "HLT_PAMu3PFJet20_v1", "HLT_PAMu3PFJet40_v1", "HLT_PAMu7PFJet20_v1", "HLT_PABTagMu_Jet20_Mu4_v1" };*/ TString str; TH1D *ahTemp[ntrigs]; double ahTempRate[ntrigs]; //Rates (Integrated over lumisections) // Load input TChain * HltTree = new TChain("hltanalysis/HltTree","HI OpenHLT Tree"); HltTree->Add(inFile0Name); cout << inFile0Name << endl; cout << " # entries: " << HltTree->GetEntries() << endl; int nEvents = HltTree->GetEntries(); for(int it=1; it<ntrigs; it++) { TH1D *ph = new TH1D("ph",";Lumi Section; Counts ",1100,0,1100); HltTree->Draw("LumiBlock>>ph",str.Format("%s",triggerPath[it])); TLegend *lTemp= new TLegend(0.2,0.8,0.8,0.9); lTemp->SetHeader(str.Format("Run : %d",runNum)); lTemp->SetMargin(0.05); lTemp->SetFillStyle(0); lTemp->SetLineColor(0); lTemp->SetLineWidth(5.0); lTemp->SetTextSize(0.03); lTemp->AddEntry(ph,str.Format("%s",triggerPath[it],"l")); lTemp->Draw("same"); c1->SaveAs(str.Format("%d_%s.pdf",runNum,triggerPath[it])); TH1D *phLumi = (TH1D*)gDirectory->Get("ph"); phLumi->SetDirectory(0); phLumi->Scale(1./(phLumi->GetBinWidth(1)*23));// 1lumi unit=23 sec ahTempRate[it] = phLumi->Integral()/phLumi->GetNbinsX(); ahTemp[it] = phLumi; cout<< triggerPath[it]<<"\t"<<phLumi->GetEntries()<< "\t" << ahTempRate[it] << endl; } //---------------------------- // drawing part // axis // TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;dEvt/dLumiSec",1100,0,1100); TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;Rate [Hz]",1,0,1200); phLumiAxis->SetMinimum(0.01); phLumiAxis->SetMaximum(1e+3); gStyle->SetOptStat(kFALSE); // legend TLegend *l0= new TLegend(0.2,0.7,0.8,0.9); l0->SetHeader(str.Format("Run : %d",runNum)); l0->SetMargin(0.03); l0->SetFillStyle(0); l0->SetLineColor(0); l0->SetLineWidth(1.0); l0->SetTextSize(0.03); // canvas TCanvas *pcLumi = new TCanvas("pcLumi","pcLumi"); pcLumi->cd(); phLumiAxis->Draw(); pcLumi->SetLogy(); for(int it=1; it<ntrigs; it++) { TH1 *phLocal = (TH1 *)(ahTemp[it]->Clone("phLocal")); phLocal->SetDirectory(0); phLocal->SetLineColor(it); if (it >= 10) phLocal->SetLineColor(it+20); if(it==5) phLocal->SetLineColor(kOrange+2); phLocal->Draw("same"); l0->AddEntry(phLocal,str.Format("%s: %.2f Hz",triggerPath[it],ahTempRate[it]),"l"); pcLumi->Update(); } l0->Draw("same"); pcLumi->SaveAs(str.Format("%d_ratedMu.png",runNum)); }
int main(int argc, char * argv[]) { // first argument - config file // second argument - filelist using namespace std; // **** configuration Config cfg(argv[1]); // vertex cuts const float ndofVertexCut = cfg.get<float>("NdofVertexCut"); const float zVertexCut = cfg.get<float>("ZVertexCut"); const float dVertexCut = cfg.get<float>("DVertexCut"); // electron cuta const float ptElectronLowCut = cfg.get<float>("ptElectronLowCut"); const float ptElectronHighCut = cfg.get<float>("ptElectronHighCut"); const float etaElectronCut = cfg.get<float>("etaElectronCut"); const float dxyElectronCut = cfg.get<float>("dxyElectronCut"); const float dzElectronCut = cfg.get<float>("dzElectronCut"); const float isoElectronLowCut = cfg.get<float>("isoElectronLowCut"); const float isoElectronHighCut = cfg.get<float>("isoElectronHighCut"); const bool applyElectronId = cfg.get<bool>("ApplyElectronId"); // tau cuts const float ptTauLowCut = cfg.get<float>("ptTauLowCut"); const float ptTauHighCut = cfg.get<float>("ptTauHighCut"); const float etaTauCut = cfg.get<float>("etaTauCut"); const bool applyTauId = cfg.get<bool>("ApplyTauId"); // pair selection const float dRleptonsCut = cfg.get<float>("dRleptonsCut"); // additional lepton veto const float ptDiElectronVeto = cfg.get<float>("ptDiElectronVeto"); const float etaDiElectronVeto = cfg.get<float>("etaDiElectronVeto"); // topological cuts const float dZetaCut = cfg.get<float>("dZetaCut"); const bool oppositeSign = cfg.get<bool>("oppositeSign"); const float deltaRTrigMatch = cfg.get<float>("DRTrigMatch"); const bool isIsoR03 = cfg.get<bool>("IsIsoR03"); const float jetEtaCut = cfg.get<float>("JetEtaCut"); const float jetPtLowCut = cfg.get<float>("JetPtLowCut"); const float jetPtHighCut = cfg.get<float>("JetPtHighCut"); const float dRJetLeptonCut = cfg.get<float>("dRJetLeptonCut"); const bool applyJetPfId = cfg.get<bool>("ApplyJetPfId"); const bool applyJetPuId = cfg.get<bool>("ApplyJetPuId"); const float bJetEtaCut = cfg.get<float>("bJetEtaCut"); const float btagCut = cfg.get<float>("btagCut"); // check overlap const bool checkOverlap = cfg.get<bool>("CheckOverlap"); const bool debug = cfg.get<bool>("debug"); // **** end of configuration // file name and tree name TString rootFileName(argv[2]); std::ifstream fileList(argv[2]); std::ifstream fileList0(argv[2]); std::string ntupleName("makeroottree/AC1B"); rootFileName += "_et_Sync.root"; std::cout <<rootFileName <<std::endl; // output fileName with histograms TFile * file = new TFile( rootFileName ,"recreate"); file->cd(""); TH1F * inputEventsH = new TH1F("inputEventsH","",1,-0.5,0.5); TTree * tree = new TTree("TauCheck","TauCheck"); Spring15Tree *otree = new Spring15Tree(tree); int nTotalFiles = 0; std::string dummy; // count number of files ---> while (fileList0 >> dummy) nTotalFiles++; int nEvents = 0; int selEvents = 0; int nFiles = 0; vector<int> runList; runList.clear(); vector<int> eventList; eventList.clear(); int nonOverlap = 0; std::ifstream fileEvents("overlap.txt"); int Run, Event, Lumi; if (checkOverlap) { std::cout << "Non-overlapping events ->" << std::endl; while (fileEvents >> Run >> Event >> Lumi) { runList.push_back(Run); eventList.push_back(Event); std::cout << Run << ":" << Event << std::endl; } std::cout << std::endl; } std::ofstream fileOutput("overlap.out"); for (int iF=0; iF<nTotalFiles; ++iF) { std::string filen; fileList >> filen; std::cout << "file " << iF+1 << " out of " << nTotalFiles << " filename : " << filen << std::endl; TFile * file_ = TFile::Open(TString(filen)); TTree * _tree = NULL; _tree = (TTree*)file_->Get(TString(ntupleName)); if (_tree==NULL) continue; TH1D * histoInputEvents = NULL; histoInputEvents = (TH1D*)file_->Get("makeroottree/nEvents"); if (histoInputEvents==NULL) continue; int NE = int(histoInputEvents->GetEntries()); std::cout << " number of input events = " << NE << std::endl; for (int iE=0;iE<NE;++iE) inputEventsH->Fill(0.); AC1B analysisTree(_tree); Long64_t numberOfEntries = analysisTree.GetEntries(); std::cout << " number of entries in Tree = " << numberOfEntries << std::endl; for (Long64_t iEntry=0; iEntry<numberOfEntries; iEntry++) { analysisTree.GetEntry(iEntry); nEvents++; if (nEvents%10000==0) cout << " processed " << nEvents << " events" << endl; otree->run = int(analysisTree.event_run); otree->lumi = int(analysisTree.event_luminosityblock); otree->evt = int(analysisTree.event_nr); bool overlapEvent = true; for (unsigned int iEvent=0; iEvent<runList.size(); ++iEvent) { if (runList.at(iEvent)==otree->run && eventList.at(iEvent)==otree->evt) { overlapEvent = false; } } if (overlapEvent&&checkOverlap) continue; nonOverlap++; if (debug) { fileOutput << std::endl; fileOutput << "Run = " << otree->run << " Event = " << otree->evt << std::endl; } // weights otree->mcweight = 0; otree->puweight = 0; otree->trigweight_1 = 0; otree->trigweight_2 = 0; otree->idweight_1 = 0; otree->idweight_2 = 0; otree->isoweight_1 = 0; otree->isoweight_2 = 0; otree->effweight = 0; otree->fakeweight = 0; otree->embeddedWeight = 0; otree->signalWeight = 0; otree->weight = 1; otree->npv = analysisTree.primvertex_count; otree->npu = analysisTree.numpileupinteractions; otree->rho = analysisTree.rho; // vertex cuts if (fabs(analysisTree.primvertex_z)>zVertexCut) continue; if (analysisTree.primvertex_ndof<=ndofVertexCut) continue; float dVertex = sqrt(analysisTree.primvertex_x*analysisTree.primvertex_x+ analysisTree.primvertex_y*analysisTree.primvertex_y); if (dVertex>dVertexCut) continue; if (debug) fileOutput << "Vertex cuts are passed " << std::endl; // electron selection vector<int> electrons; electrons.clear(); if (debug) fileOutput << "# electrons = " << analysisTree.electron_count << std::endl; for (unsigned int ie = 0; ie<analysisTree.electron_count; ++ie) { bool electronMvaId = electronMvaIdTight(analysisTree.electron_superclusterEta[ie], analysisTree.electron_mva_id_nontrigPhys14[ie]); if (checkOverlap) fileOutput << " " << ie << " pt = " << analysisTree.electron_pt[ie] << " eta = " << analysisTree.electron_eta[ie] << " dxy = " << analysisTree.electron_dxy[ie] << " dz = " << analysisTree.electron_dz[ie] << " passConv = " << analysisTree.electron_pass_conversion[ie] << " nmisshits = " << int(analysisTree.electron_nmissinginnerhits[ie]) << " mvaTight = " << electronMvaId << std::endl; if (analysisTree.electron_pt[ie]<ptElectronLowCut) continue; if (fabs(analysisTree.electron_eta[ie])>etaElectronCut) continue; if (fabs(analysisTree.electron_dxy[ie])>dxyElectronCut) continue; if (fabs(analysisTree.electron_dz[ie])>dzElectronCut) continue; if (!electronMvaId&&applyElectronId) continue; if (!analysisTree.electron_pass_conversion[ie]&&applyElectronId) continue; if (analysisTree.electron_nmissinginnerhits[ie]!=0&&applyElectronId) continue; electrons.push_back(ie); } // tau selection if (debug) fileOutput << "# taus = " << analysisTree.tau_count << std::endl; vector<int> taus; taus.clear(); for (unsigned int it = 0; it<analysisTree.tau_count; ++it) { if (debug) fileOutput << " " << it << " pt = " << analysisTree.tau_pt[it] << " eta = " << analysisTree.tau_eta[it] << " decayModeFinding = " << analysisTree.tau_decayModeFinding[it] << " decayModeFindingNewDMs = " << analysisTree.tau_decayModeFindingNewDMs[it] << " tau_vertexz = " << analysisTree.tau_vertexz[it] <<std::endl; if (analysisTree.tau_pt[it]<ptTauLowCut) continue; if (fabs(analysisTree.tau_eta[it])>etaTauCut) continue; if (applyTauId && analysisTree.tau_decayModeFinding[it] < 0.5 && analysisTree.tau_decayModeFindingNewDMs[it] < 0.5) continue; float ctgTheta = analysisTree.tau_pz[it] / sqrt(analysisTree.tau_px[it]*analysisTree.tau_px[it] + analysisTree.tau_py[it]*analysisTree.tau_py[it]); float zImpact = analysisTree.tau_vertexz[it] + 130. * ctgTheta; if ( zImpact > -1.5 && zImpact < 0.5) continue; if (analysisTree.tau_vertexz[it]!=analysisTree.primvertex_z) continue; taus.push_back(it); } if (debug) { fileOutput << " # selected electron = " << electrons.size() << std::endl; fileOutput << " # selected taus = " << taus.size() << std::endl; } if (electrons.size()==0) continue; if (taus.size()==0) continue; // selecting muon and tau pair (OS or SS); int electronIndex = -1; int tauIndex = -1; float isoEleMin = 1e+10; float isoTauMin = 1e+10; for (unsigned int ie=0; ie<electrons.size(); ++ie) { bool isTrigEle22 = false; bool isTrigEle32 = false; unsigned int eIndex = electrons.at(ie); float neutralHadIsoEle = analysisTree.electron_neutralHadIso[ie]; float photonIsoEle = analysisTree.electron_photonIso[ie]; float chargedHadIsoEle = analysisTree.electron_chargedHadIso[ie]; float puIsoEle = analysisTree.electron_puIso[ie]; if (isIsoR03) { neutralHadIsoEle = analysisTree.electron_r03_sumNeutralHadronEt[ie]; photonIsoEle = analysisTree.electron_r03_sumPhotonEt[ie]; chargedHadIsoEle = analysisTree.electron_r03_sumChargedHadronPt[ie]; puIsoEle = analysisTree.electron_r03_sumPUPt[ie]; } float neutralIsoEle = neutralHadIsoEle + photonIsoEle - 0.5*puIsoEle; neutralIsoEle = TMath::Max(float(0),neutralIsoEle); float absIsoEle = chargedHadIsoEle + neutralIsoEle; float relIsoEle = absIsoEle/analysisTree.electron_pt[ie]; if (debug) fileOutput << "Electron " << eIndex << " -> relIso = "<<relIsoEle<<" absIso = "<<absIsoEle<<std::endl; for (unsigned int iT=0; iT<analysisTree.trigobject_count; ++iT) { /*if (analysisTree.trigobject_isElectron[iT] || !analysisTree.trigobject_isMuon[iT] || analysisTree.trigobject_isTau[iT]) continue;*/ float dRtrig = deltaR(analysisTree.electron_eta[eIndex],analysisTree.electron_phi[eIndex], analysisTree.trigobject_eta[iT],analysisTree.trigobject_phi[iT]); if (dRtrig < deltaRTrigMatch){ if (analysisTree.trigobject_filters[iT][7] && analysisTree.trigobject_filters[iT][8]) // Ele22 Leg isTrigEle22 = true; if (analysisTree.trigobject_filters[iT][10]) // Ele32 Leg isTrigEle32 = true; } } if (debug) fileOutput << "Electron " << eIndex << " -> isTrigEle22 = " << isTrigEle22 << " ; isTrigEle32 = " << isTrigEle32 << std::endl; if ((!isTrigEle22) && (!isTrigEle32)) continue; for (unsigned int it=0; it<taus.size(); ++it) { unsigned int tIndex = taus.at(it); float absIsoTau = analysisTree.tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[tIndex]; float relIsoTau = absIsoTau / analysisTree.tau_pt[tIndex]; if (debug) fileOutput << "tau" << tIndex << " -> relIso = "<<relIsoTau<<" absIso = "<<absIsoTau<<std::endl; float dR = deltaR(analysisTree.tau_eta[tIndex],analysisTree.tau_phi[tIndex], analysisTree.electron_eta[eIndex],analysisTree.electron_phi[eIndex]); if (debug) fileOutput << "dR(ele,tau) = " << dR << std::endl; if (dR<dRleptonsCut) continue; bool isTrigTau = false; float dRtrig_min = 9999.; for (unsigned int iT=0; iT<analysisTree.trigobject_count; ++iT) { if (debug){ if (analysisTree.trigobject_isElectron[iT] && analysisTree.trigobject_isMuon[iT]) fileOutput<<" trigObj "<<iT<<" both e and mu"<<std::endl; if (analysisTree.trigobject_isMuon[iT] && analysisTree.trigobject_isTau[iT]) fileOutput<<" trigObj "<<iT<<" both mu and tau"<<std::endl; if (analysisTree.trigobject_isElectron[iT] && analysisTree.trigobject_isTau[iT]) fileOutput<<" trigObj "<<iT<<" both e and tau"<<std::endl; } if (analysisTree.trigobject_isElectron[iT] || analysisTree.trigobject_isMuon[iT] || !analysisTree.trigobject_isTau[iT]) continue; float dRtrig = deltaR(analysisTree.tau_eta[tIndex],analysisTree.tau_phi[tIndex], analysisTree.trigobject_eta[iT],analysisTree.trigobject_phi[iT]); if (dRtrig < deltaRTrigMatch){ if (analysisTree.trigobject_filters[iT][7] && analysisTree.trigobject_filters[iT][8]){ isTrigTau = true; if (dRtrig < dRtrig_min) dRtrig_min = dRtrig; } } } if (debug) fileOutput << "Tau " << it << " -> isTrigTau = " << isTrigTau << " DR="<<dRtrig_min<<std::endl; bool trigMatch = isTrigEle32 || (isTrigEle22 && isTrigTau); if (isTrigEle32 && analysisTree.hltriggerresults_second[4]==false) if (debug) std::cout<<"IsoEle32 Trigger Mismatch"<<std::endl; if (isTrigEle22 && isTrigTau && analysisTree.hltriggerresults_second[1]==false) if (debug) std::cout<<"xEleTau Trigger Mismatch"<<std::endl; if (!trigMatch) continue; bool isKinematicMatch = false; if (isTrigEle32) { if (analysisTree.electron_pt[eIndex]>ptElectronHighCut) isKinematicMatch = true; } if (isTrigEle22 && isTrigTau) { if (analysisTree.electron_pt[eIndex]>ptElectronLowCut && analysisTree.tau_pt[tIndex]>ptTauHighCut) isKinematicMatch = true; } if (!isKinematicMatch) continue; bool changePair = false; if (relIsoEle<isoEleMin) { changePair = true; } else if (fabs(relIsoEle - isoEleMin) < 1.e-5) { if (analysisTree.electron_pt[eIndex] > analysisTree.electron_pt[electronIndex]) { changePair = true; } else if (fabs(analysisTree.electron_pt[eIndex] - analysisTree.electron_pt[electronIndex]) < 1.e-5) { if (absIsoTau < isoTauMin) { changePair = true; } else if ((absIsoTau - isoTauMin) < 1.e-5){ if (analysisTree.tau_pt[tIndex] > analysisTree.tau_pt[tauIndex]) { changePair = true; } } } } if (changePair){ isoEleMin = relIsoEle; electronIndex = eIndex; isoTauMin = absIsoTau; tauIndex = tIndex; } } } if (electronIndex<0) continue; if (tauIndex<0) continue; // filling electron variables otree->pt_1 = analysisTree.electron_pt[electronIndex]; otree->eta_1 = analysisTree.electron_eta[electronIndex]; otree->phi_1 = analysisTree.electron_phi[electronIndex]; otree->m_1 = electronMass; otree->q_1 = -1; if (analysisTree.electron_charge[electronIndex]>0) otree->q_1 = 1; otree->iso_1 = isoEleMin; otree->mva_1 = analysisTree.electron_mva_id_nontrigPhys14[electronIndex]; otree->d0_1 = analysisTree.electron_dxy[electronIndex]; otree->dZ_1 = analysisTree.electron_dz[electronIndex]; otree->byCombinedIsolationDeltaBetaCorrRaw3Hits_1 = 0; otree->againstElectronLooseMVA5_1 = 0; otree->againstElectronMediumMVA5_1 = 0; otree->againstElectronTightMVA5_1 = 0; otree->againstElectronVLooseMVA5_1 = 0; otree->againstElectronVTightMVA5_1 = 0; otree->againstMuonLoose3_1 = 0; otree->againstMuonTight3_1 = 0; // filling tau variables otree->pt_2 = analysisTree.tau_pt[tauIndex]; otree->eta_2 = analysisTree.tau_eta[tauIndex]; otree->phi_2 = analysisTree.tau_phi[tauIndex]; otree->q_2 = -1; if (analysisTree.tau_charge[tauIndex]>0) otree->q_2 = 1; otree->mva_2 = log(0); otree->d0_2 = analysisTree.tau_dxy[tauIndex]; otree->dZ_2 = analysisTree.tau_dz[tauIndex]; otree->iso_2 = analysisTree.tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[tauIndex]; otree->m_2 = analysisTree.tau_mass[tauIndex]; otree->byCombinedIsolationDeltaBetaCorrRaw3Hits_2 = analysisTree.tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[tauIndex]; otree->againstElectronLooseMVA5_2 = analysisTree.tau_againstElectronLooseMVA5[tauIndex]; otree->againstElectronMediumMVA5_2 = analysisTree.tau_againstElectronMediumMVA5[tauIndex]; otree->againstElectronTightMVA5_2 = analysisTree.tau_againstElectronTightMVA5[tauIndex]; otree->againstElectronVLooseMVA5_2 = analysisTree.tau_againstElectronVLooseMVA5[tauIndex]; otree->againstElectronVTightMVA5_2 = analysisTree.tau_againstElectronVTightMVA5[tauIndex]; otree->againstMuonLoose3_2 = analysisTree.tau_againstMuonLoose3[tauIndex]; otree->againstMuonTight3_2 = analysisTree.tau_againstMuonTight3[tauIndex]; // ditau system TLorentzVector electronLV; electronLV.SetXYZM(analysisTree.electron_px[electronIndex], analysisTree.electron_py[electronIndex], analysisTree.electron_pz[electronIndex], electronMass); TLorentzVector tauLV; tauLV.SetXYZM(analysisTree.tau_px[tauIndex], analysisTree.tau_py[tauIndex], analysisTree.tau_pz[tauIndex], tauMass); TLorentzVector dileptonLV = electronLV + tauLV; otree->m_vis = dileptonLV.M(); otree->pt_tt = dileptonLV.Pt(); // opposite charge otree->os = (otree->q_1 * otree->q_2) < 0.; // dimuon veto otree->dilepton_veto = 0; for (unsigned int ie = 0; ie<analysisTree.electron_count; ++ie) { if (analysisTree.electron_pt[ie]<ptDiElectronVeto) continue; if (fabs(analysisTree.electron_eta[ie])>etaDiElectronVeto) continue; if (fabs(analysisTree.electron_dxy[ie])>dxyElectronCut) continue; if (fabs(analysisTree.electron_dz[ie])>dzElectronCut) continue; if (otree->q_1 * analysisTree.electron_charge[ie] > 0.) continue; float neutralHadIsoEle = analysisTree.electron_neutralHadIso[ie]; float photonIsoEle = analysisTree.electron_photonIso[ie]; float chargedHadIsoEle = analysisTree.electron_chargedHadIso[ie]; float puIsoEle = analysisTree.electron_puIso[ie]; if (isIsoR03) { neutralHadIsoEle = analysisTree.electron_r03_sumNeutralHadronEt[ie]; photonIsoEle = analysisTree.electron_r03_sumPhotonEt[ie]; chargedHadIsoEle = analysisTree.electron_r03_sumChargedHadronPt[ie]; puIsoEle = analysisTree.electron_r03_sumPUPt[ie]; } float neutralIsoEle = neutralHadIsoEle + photonIsoEle - 0.5*puIsoEle; neutralIsoEle = TMath::Max(float(0),neutralIsoEle); float absIsoEle = chargedHadIsoEle + neutralIsoEle; float relIsoEle = absIsoEle/analysisTree.electron_pt[ie]; if(relIsoEle > 0.3) continue; float dr = deltaR(analysisTree.electron_eta[ie],analysisTree.electron_phi[ie], otree->eta_1,otree->phi_1); if(dr<0.15) continue; otree->dilepton_veto = 1; } // extra electron veto otree->extraelec_veto = 0; // extra muon veto otree->extramuon_veto = 0; // svfit variables otree->m_sv = -9999; otree->pt_sv = -9999; otree->eta_sv = -9999; otree->phi_sv = -9999; // pfmet variables otree->met = TMath::Sqrt(analysisTree.pfmet_ex*analysisTree.pfmet_ex + analysisTree.pfmet_ey*analysisTree.pfmet_ey); otree->metphi = TMath::ATan2(analysisTree.pfmet_ey,analysisTree.pfmet_ex); otree->metcov00 = analysisTree.pfmet_sigxx; otree->metcov01 = analysisTree.pfmet_sigxy; otree->metcov10 = analysisTree.pfmet_sigyx; otree->metcov11 = analysisTree.pfmet_sigyy; // bisector of muon and tau transverse momenta float electronUnitX = electronLV.Px()/electronLV.Pt(); float electronUnitY = electronLV.Py()/electronLV.Pt(); float tauUnitX = tauLV.Px()/tauLV.Pt(); float tauUnitY = tauLV.Py()/tauLV.Pt(); float zetaX = electronUnitX + tauUnitX; float zetaY = electronUnitY + tauUnitY; float normZeta = TMath::Sqrt(zetaX*zetaX+zetaY*zetaY); zetaX = zetaX/normZeta; zetaY = zetaY/normZeta; float vectorVisX = electronLV.Px() + tauLV.Px(); float vectorVisY = electronLV.Py() + tauLV.Py(); otree->pzetavis = vectorVisX*zetaX + vectorVisY*zetaY; // choosing mva met unsigned int iMet = 0; for (; iMet<analysisTree.mvamet_count; ++iMet) { if ((int)analysisTree.mvamet_channel[iMet]==2) break; } if (iMet>=analysisTree.mvamet_count){ if(debug) fileOutput<<"MVA MET channel ploblems.."<<std::endl; otree->mvamet = log(0); otree->mvametphi = log(0); otree->mvacov00 = log(0); otree->mvacov01 = log(0); otree->mvacov10 = log(0); otree->mvacov11 = log(0); otree->mt_1 = log(0); otree->mt_2 = log(0); otree->pzetamiss = log(0); } else { float mvamet_x = analysisTree.mvamet_ex[iMet]; float mvamet_y = analysisTree.mvamet_ey[iMet]; float mvamet_x2 = mvamet_x * mvamet_x; float mvamet_y2 = mvamet_y * mvamet_y; otree->mvamet = TMath::Sqrt(mvamet_x2+mvamet_y2); otree->mvametphi = TMath::ATan2(mvamet_y,mvamet_x); otree->mvacov00 = analysisTree.mvamet_sigxx[iMet]; otree->mvacov01 = analysisTree.mvamet_sigxy[iMet]; otree->mvacov10 = analysisTree.mvamet_sigyx[iMet]; otree->mvacov11 = analysisTree.mvamet_sigyy[iMet]; // computation of mt otree->mt_1 = sqrt(2*otree->pt_1*otree->mvamet*(1.-cos(otree->phi_1-otree->mvametphi))); otree->mt_2 = sqrt(2*otree->pt_2*otree->mvamet*(1.-cos(otree->phi_2-otree->mvametphi))); // computation of DZeta variable otree->pzetamiss = analysisTree.pfmet_ex*zetaX + analysisTree.pfmet_ey*zetaY; } // counting jets vector<unsigned int> jets; jets.clear(); vector<unsigned int> jetspt20; jetspt20.clear(); vector<unsigned int> bjets; bjets.clear(); int indexLeadingJet = -1; float ptLeadingJet = -1; int indexSubLeadingJet = -1; float ptSubLeadingJet = -1; int indexLeadingBJet = -1; float ptLeadingBJet = -1; for (unsigned int jet=0; jet<analysisTree.pfjet_count; ++jet) { float absJetEta = fabs(analysisTree.pfjet_eta[jet]); if (absJetEta>jetEtaCut) continue; float jetPt = analysisTree.pfjet_pt[jet]; if (jetPt<jetPtLowCut) continue; float dR1 = deltaR(analysisTree.pfjet_eta[jet],analysisTree.pfjet_phi[jet], otree->eta_1,otree->phi_1); float dR2 = deltaR(analysisTree.pfjet_eta[jet],analysisTree.pfjet_phi[jet], otree->eta_2,otree->phi_2); // pf jet Id float energy = analysisTree.pfjet_e[jet]; float chf = analysisTree.pfjet_chargedhadronicenergy[jet]/energy; float nhf = analysisTree.pfjet_neutralhadronicenergy[jet]/energy; float phf = analysisTree.pfjet_neutralemenergy[jet]/energy; float elf = analysisTree.pfjet_chargedemenergy[jet]/energy; float chm = analysisTree.pfjet_chargedmulti[jet]; float npr = analysisTree.pfjet_chargedmulti[jet] + analysisTree.pfjet_neutralmulti[jet]; bool isPFJetId = (npr>1 && phf<0.99 && nhf<0.99) && (absJetEta>2.4 || (elf<0.99 && chf>0 && chm>0)); // muon fraction missing if(debug) fileOutput<<" jet "<<jet<<": pt="<<analysisTree.pfjet_pt[jet]<<" eta="<<analysisTree.pfjet_eta[jet] <<" dr1="<<dR1<<" dr2="<<dR2<<" npr="<<npr<<" phf="<<phf<<" nhf="<<nhf<<std::endl; // apply dR cut if (dR1<dRJetLeptonCut) continue; if (dR2<dRJetLeptonCut) continue; // apply pf jet Id if (applyJetPfId&&!isPFJetId) continue; // pu jet Id if (applyJetPuId&&!puJetIdLoose(analysisTree.pfjet_eta[jet],analysisTree.pfjet_pu_jet_full_mva[jet])) continue; jetspt20.push_back(jet); if (absJetEta<bJetEtaCut && analysisTree.pfjet_btag[jet][6]>btagCut) { // b-jet bjets.push_back(jet); if (jetPt>ptLeadingBJet) { ptLeadingBJet = jetPt; indexLeadingBJet = jet; } } if (jetPt<jetPtHighCut) continue; jets.push_back(jet); if(jetPt>ptLeadingJet){ ptSubLeadingJet = ptLeadingJet; indexSubLeadingJet = indexLeadingJet; ptLeadingJet = jetPt; indexLeadingJet = jet; } else if(jetPt>ptSubLeadingJet){ ptSubLeadingJet = jetPt; indexSubLeadingJet = jet; } } otree->njets = jets.size(); otree->njetspt20 = jetspt20.size(); otree->nbtag = bjets.size(); otree->bpt = -9999; otree->beta = -9999; otree->bphi = -9999; if (indexLeadingBJet>=0) { otree->bpt = analysisTree.pfjet_pt[indexLeadingBJet]; otree->beta = analysisTree.pfjet_eta[indexLeadingBJet]; otree->bphi = analysisTree.pfjet_phi[indexLeadingBJet]; } otree->jpt_1 = -9999; otree->jeta_1 = -9999; otree->jphi_1 = -9999; otree->jptraw_1 = -9999; otree->jptunc_1 = -9999; otree->jmva_1 = -9999; otree->jlrm_1 = -9999; otree->jctm_1 = -9999; if (indexLeadingJet>=0&&indexSubLeadingJet>=0&&indexLeadingJet==indexSubLeadingJet) cout << "warning : indexLeadingJet ==indexSubLeadingJet = " << indexSubLeadingJet << endl; if (indexLeadingJet>=0) { otree->jpt_1 = analysisTree.pfjet_pt[indexLeadingJet]; otree->jeta_1 = analysisTree.pfjet_eta[indexLeadingJet]; otree->jphi_1 = analysisTree.pfjet_phi[indexLeadingJet]; otree->jptraw_1 = analysisTree.pfjet_pt[indexLeadingJet]*analysisTree.pfjet_energycorr[indexLeadingJet]; otree->jmva_1 = analysisTree.pfjet_pu_jet_full_mva[indexLeadingJet]; } otree->jpt_2 = -9999; otree->jeta_2 = -9999; otree->jphi_2 = -9999; otree->jptraw_2 = -9999; otree->jptunc_2 = -9999; otree->jmva_2 = -9999; otree->jlrm_2 = -9999; otree->jctm_2 = -9999; if (indexSubLeadingJet>=0) { otree->jpt_2 = analysisTree.pfjet_pt[indexSubLeadingJet]; otree->jeta_2 = analysisTree.pfjet_eta[indexSubLeadingJet]; otree->jphi_2 = analysisTree.pfjet_phi[indexSubLeadingJet]; otree->jptraw_2 = analysisTree.pfjet_pt[indexSubLeadingJet]*analysisTree.pfjet_energycorr[indexSubLeadingJet]; otree->jmva_2 = analysisTree.pfjet_pu_jet_full_mva[indexSubLeadingJet]; } otree->mjj = -9999; otree->jdeta = -9999; otree->njetingap = 0; if (indexLeadingJet>=0 && indexSubLeadingJet>=0) { TLorentzVector jet1; jet1.SetPxPyPzE(analysisTree.pfjet_px[indexLeadingJet], analysisTree.pfjet_py[indexLeadingJet], analysisTree.pfjet_pz[indexLeadingJet], analysisTree.pfjet_e[indexLeadingJet]); TLorentzVector jet2; jet2.SetPxPyPzE(analysisTree.pfjet_px[indexSubLeadingJet], analysisTree.pfjet_py[indexSubLeadingJet], analysisTree.pfjet_pz[indexSubLeadingJet], analysisTree.pfjet_e[indexSubLeadingJet]); otree->mjj = (jet1+jet2).M(); otree->jdeta = abs(analysisTree.pfjet_eta[indexLeadingJet]- analysisTree.pfjet_eta[indexSubLeadingJet]); float etamax = analysisTree.pfjet_eta[indexLeadingJet]; float etamin = analysisTree.pfjet_eta[indexSubLeadingJet]; if (etamax<etamin) { float tmp = etamax; etamax = etamin; etamin = tmp; } for (unsigned int jet=0; jet<jetspt20.size(); ++jet) { int index = jetspt20.at(jet); float etaX = analysisTree.pfjet_eta[index]; if (index!=indexLeadingJet&&index!=indexSubLeadingJet&&etaX>etamin&&etaX<etamax) otree->njetingap++; } } otree->Fill(); selEvents++; } // end of file processing (loop over events in one file) nFiles++; delete _tree; file_->Close(); delete file_; } std::cout << std::endl; int allEvents = int(inputEventsH->GetEntries()); std::cout << "Total number of input events = " << allEvents << std::endl; std::cout << "Total number of events in Tree = " << nEvents << std::endl; std::cout << "Total number of selected events = " << selEvents << std::endl; std::cout << std::endl; file->cd(""); file->Write(); file->Close(); delete file; }
//TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, float NPpar[]) TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, TString npfit) { TString tMC; if(isMC==1) tMC="MC"; else tMC="Data"; TCanvas* c = new TCanvas(Form("c_%s_%.0f",tMC.Data(),ibin),"",600,600); TFile* infile = new TFile(Form("%s_%s_%s_%s_%.0f.root",infname.Data(),collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%s_%.0f",tMC.Data(),ibin)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%s_%.0f",tMC.Data(),ibin)); //TString iNP=Form("TMath::Erf((x-%f)/%f)+1", NPpar[0], NPpar[1]); TString iNP = npfit; TF1* f = new TF1(Form("f_%s_%.0f",tMC.Data(),ibin),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); f->SetParLimits(3,0,1e5); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); if(isMC) { f->SetParLimits(3,0,1e2); f->SetParLimits(4,-100,0); } f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(5,0); h->GetEntries(); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(5); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto); f->ReleaseParameter(1); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto); h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1 *background = new TF1(Form("background_%s_%.0f",tMC.Data(),ibin),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1 *Bkpi = new TF1(Form("fBkpi_%s_%.0f",tMC.Data(),ibin),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetRange(minhisto,maxhisto); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); Bkpi->SetFillColor(kGreen+1); TF1 *mass = new TF1(Form("fmass_%s_%.0f",tMC.Data(),ibin),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"B^{+} Signal","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp")); else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb")); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; if(ibin>0) { if(isLarger==1) tex = new TLatex(0.22,0.78,Form("%s > %.3f",vartex.Data(),varval)); else tex = new TLatex(0.22,0.78,Form("%s < %.3f",vartex.Data(),varval)); } else tex = new TLatex(0.22,0.78,Form("%s",_nominalcut.Data())); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.73,Form("N_{B} = %.0f #pm %.0f",yield,yieldErr)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); c->SaveAs(Form("plotFits/DMass_%s_%s_%s_%.0f.pdf",collisionsystem.Data(),varname.Data(),tMC.Data(),ibin)); return mass; }
void plotLeadingJet(int cbin, TString infname, TString pythia, TString mix, bool useWeight, bool drawXLabel, bool drawLeg) { TString cut="et1>120 && et2>50 && dphi>2.5"; TString cutpp="et1>120 && et2>50 && dphi>2.5"; TString cstring = ""; if(cbin==0) { cstring = "0-10%"; cut+=" && bin>=0 && bin<4"; cut+=" && ((et1-et2)/(et1+et2) > 0.3)"; } else if (cbin==1) { cstring = "10-30%"; cut+=" && bin>=4 && bin<12"; cut+=" && ((et1-et2)/(et1+et2) > 0.3)"; } else { cstring = "30-100%"; cut+=" && bin>=12 && bin<40"; cut+=" && ((et1-et2)/(et1+et2) > 0.3)"; } // open the data file TFile *inf = new TFile(infname.Data()); TTree *nt =(TTree*)inf->FindObjectAny("nt"); // open the pythia (MC) file TFile *infPythia = new TFile(pythia.Data()); TTree *ntPythia = (TTree*) infPythia->FindObjectAny("nt"); // open the datamix file TFile *infMix = new TFile(mix.Data()); TTree *ntMix =(TTree*)infMix->FindObjectAny("nt"); // projection histogram TH1D *h = new TH1D("h","",10,60,135); TH1D *hPythia = new TH1D("hPythia","",10,60,135); TH1D *hDataMix = new TH1D("hDataMix","",10,60,135); nt->Draw("et2>>h",Form("(%s)",cut.Data())); if (useWeight) { // use the weight value caluculated by Matt's analysis macro ntMix->Draw("et2>>hDataMix",Form("(%s)*weight",cut.Data())); } else { // ignore centrality reweighting ntMix->Draw("et2>>hDataMix",Form("(%s)",cut.Data())); } ntPythia->Draw("et2>>hPythia",Form("(%s)",cutpp.Data())); // calculate the statistical error and normalize h->Sumw2(); h->Scale(1./h->GetEntries()); h->SetMarkerStyle(20); hPythia->Scale(1./hPythia->Integral(0,20)); hPythia->SetLineColor(kBlue); hPythia->SetFillColor(kAzure-8); hPythia->SetFillStyle(3005); hPythia->SetStats(0); hPythia->Draw("hist"); if(drawXLabel) hPythia->SetXTitle("Subleading Jet E_{T} (GeV)"); hPythia->GetXaxis()->SetLabelSize(20); hPythia->GetXaxis()->SetLabelFont(43); hPythia->GetXaxis()->SetTitleSize(22); hPythia->GetXaxis()->SetTitleFont(43); hPythia->GetXaxis()->SetTitleOffset(1.5); hPythia->GetXaxis()->CenterTitle(); hPythia->GetXaxis()->SetNdivisions(904,true); hPythia->SetYTitle("Event Fraction"); hPythia->GetYaxis()->SetLabelSize(20); hPythia->GetYaxis()->SetLabelFont(43); hPythia->GetYaxis()->SetTitleSize(20); hPythia->GetYaxis()->SetTitleFont(43); hPythia->GetYaxis()->SetTitleOffset(2.5); hPythia->GetYaxis()->CenterTitle(); hPythia->SetAxisRange(2E-3,3,"Y"); hDataMix->SetAxisRange(2E-3,3,"Y"); h->SetAxisRange(2E-3,3,"Y"); h->Draw("same"); hDataMix->Scale(1./hDataMix->Integral(0,20)); hDataMix->SetLineColor(kRed); hDataMix->SetFillColor(kRed-9); hDataMix->SetFillStyle(3004); hDataMix->Draw("same"); if(drawLeg){ TLegend *t3=new TLegend(0.25,0.74,0.79,0.90); t3->AddEntry(h,"Pb+Pb #sqrt{s}_{_{NN}}=2.76 TeV","pl"); t3->AddEntry(hPythia,"PYTHIA","lf"); t3->AddEntry(hDataMix,"embedded PYTHIA","lf"); t3->SetFillColor(0); t3->SetBorderSize(0); t3->SetFillStyle(0); t3->SetTextFont(63); t3->SetTextSize(15); t3->Draw(); } }
void swaps::Loop() { gROOT->ProcessLine(".x /home/gcowan/lhcb/lhcbStyle.C"); if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); TH1D * mKK = new TH1D("mKK", "mKK", 100, 0.99, 1.050); TH1D * mKpi = new TH1D("mKpi", "mKpi", 100, 0.826, 0.966); TH1D * mKp = new TH1D("mKp", "mKp", 50, 1.45, 1.55); TH1D * massHisto = new TH1D("mJpsiKK_DTF", "mJpsiKK_DTF", 100, 5.20, 5.55); TH1D * mBs = new TH1D("mJpsiKK", "mJpsiKK", 100, 5.20, 5.55); TH1D * mBsVeto = new TH1D("mJpsiKKveto", "mJpsiKKveto", 100, 5.20, 5.55); //TH1D * mBsKpi = new TH1D("upper_Bs_sideband", "mJpsiKpi", 40, 5.21, 5.41); //TH1D * mBspiK = new TH1D("lower_Bs_sideband", "mJpsipiK", 40, 5.04, 5.24); TH1D * mBsKpi = new TH1D("upper_Bs_sideband", "mJpsiKpi", 40, 5.51, 5.71); TH1D * mBspiK = new TH1D("lower_Bs_sideband", "mJpsipiK", 40, 5.34, 5.54); TH1D * mJpsi_ = new TH1D("mJpsi", "mJpsi", 100, 3.03, 3.15); TH1D * mJpsi_constr = new TH1D("mJpsi_constr", "mJpsi", 100, 3.03, 3.15); Long64_t nbytes = 0, nb = 0; TFile * file = TFile::Open("reflection_upper_sideband.root", "RECREATE"); TNtuple * tuple = new TNtuple("DecayTree","DecayTree", "mass"); for (Long64_t jentry=0; jentry<nentries;jentry++) { //for (Long64_t jentry=0; jentry<1000;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; if ( !(sel_cleantail==1&&sel==1&&(triggerDecisionUnbiased==1||triggerDecisionBiasedExcl==1)&&time>.3&&time<14&&sigmat>0&&sigmat<0.12 // &&(Kplus_pidK-Kplus_pidp)>-5 // &&(Kminus_pidK-Kminus_pidp)>-5 ) ) continue; //double mpi = 139.57018; double mK = 493.68; double mmu = 105.658; double mJpsi = 3096.916; double mpi = 938.27; TLorentzVector Kplus(Kplus_PX, Kplus_PY, Kplus_PZ, sqrt(Kplus_PX*Kplus_PX+Kplus_PY*Kplus_PY+Kplus_PZ*Kplus_PZ + mK*mK)); TLorentzVector Kminus(Kminus_PX, Kminus_PY, Kminus_PZ, sqrt(Kminus_PX*Kminus_PX+Kminus_PY*Kminus_PY+Kminus_PZ*Kminus_PZ + mK*mK)); TLorentzVector KplusWrong(Kplus_PX, Kplus_PY, Kplus_PZ, sqrt(Kplus_PX*Kplus_PX+Kplus_PY*Kplus_PY+Kplus_PZ*Kplus_PZ + mpi*mpi)); TLorentzVector KminusWrong(Kminus_PX, Kminus_PY, Kminus_PZ, sqrt(Kminus_PX*Kminus_PX+Kminus_PY*Kminus_PY+Kminus_PZ*Kminus_PZ + mpi*mpi)); TLorentzVector muplus(muplus_PX, muplus_PY, muplus_PZ, sqrt(muplus_P*muplus_P + mmu*mmu)); TLorentzVector muminus(muminus_PX, muminus_PY, muminus_PZ, sqrt(muminus_P*muminus_P + mmu*mmu)); TLorentzVector Jpsi = muplus + muminus; TLorentzVector Jpsi_constr(muminus_PX+muplus_PX, muminus_PY+muplus_PY, muminus_PZ+muplus_PZ, sqrt(Jpsi.P()*Jpsi.P() + mJpsi*mJpsi)); TLorentzVector KK = Kplus + Kminus; TLorentzVector Kpi = Kplus + KminusWrong; TLorentzVector piK = KplusWrong + Kminus; TLorentzVector B = Jpsi_constr + KK; TLorentzVector BKpi = Jpsi_constr + Kpi; TLorentzVector BpiK = Jpsi_constr + piK; //if ( ((BpiK.M() > 5600 && BpiK.M() < 5640) || (BKpi.M() > 5600 && BKpi.M() < 5640)) ) mBsVeto->Fill(mass/1000.); //if ( ( Kpi.M() > 1490 && Kpi.M() < 1550 ) || ( piK.M() > 1490 && piK.M() < 1550 ) ) continue;//mBsVeto->Fill(mass/1000.); mKK->Fill(KK.M()/1000.); mKp->Fill(Kpi.M()/1000.); mKp->Fill(piK.M()/1000.); mBs->Fill(B.M()/1000.); massHisto->Fill(mass/1000.); mJpsi_->Fill(Jpsi.M()/1000.); mJpsi_constr->Fill(Jpsi_constr.M()/1000.); if (mass > 5420) mBsKpi->Fill(BKpi.M()/1000.); if (mass > 5420) mBsKpi->Fill(BpiK.M()/1000.); if (mass < 5330) mBspiK->Fill(BKpi.M()/1000.); if (mass < 5330) mBspiK->Fill(BpiK.M()/1000.); if (mass > 5400) tuple->Fill(BKpi.M()); if (mass > 5400) tuple->Fill(BpiK.M()); } tuple->Write(); file->Close(); std::cout << "Number of B candidates " << mBs->GetEntries() << std::endl; std::cout << "Number of B candidates after Lambda_b veto" << mBsVeto->GetEntries() << std::endl; gROOT->SetStyle("Plain"); TCanvas * c = new TCanvas("c","c",1600,1200); c->Divide(3,2); c->cd(1); mKK->Draw(); mKK->SetTitle(""); mKK->GetXaxis()->SetTitle("m(KK) [GeV/c^{2}]"); c->cd(2); mJpsi_->Draw(); mJpsi_->SetTitle(""); mJpsi_->GetXaxis()->SetTitle("m(#mu#mu) [GeV/c^{2}]"); c->cd(3); //mKp->Draw(); mKp->SetTitle(""); mKp->GetXaxis()->SetTitle("m(Kp) [GeV/c^{2}]"); c->cd(4); massHisto->Draw(); //massHisto->SetMaximum(1500); mBs->SetLineColor(kRed); mBs->Draw("same"); mBsVeto->SetLineColor(kOrange); mBsVeto->Draw("same"); massHisto->SetTitle(""); massHisto->GetXaxis()->SetTitle("DTF m(J/#psi K^{+}K^{-}) [GeV/c^{2}]"); c->cd(5); mBspiK->Draw(); mBspiK->SetTitle(""); //mBspiK->GetXaxis()->SetTitle("m(J/#psi K#pi) [GeV/c^{2}]"); mBspiK->GetXaxis()->SetTitle("m(J/#psi Kp) [GeV/c^{2}]"); c->cd(6); mBsKpi->Draw(); mBsKpi->SetTitle(""); //mBsKpi->GetXaxis()->SetTitle("m(J/#psi K#pi) [GeV/c^{2}]"); mBsKpi->GetXaxis()->SetTitle("m(J/#psi Kp) [GeV/c^{2}]"); c->SaveAs("plots_swaps.pdf"); }
void JetFragAna::Loop() { if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t jetTreeNEntries[10] = {nentries,jetTree_[1]->GetEntries(),0,0,0}; cout << "==============" << endl; cout << " Begin Loop" << endl; cout << "Tree: " << nentries << " jetTree: " << jetTreeNEntries[jetTreeMode_] << endl; cout << "==============" << endl; for (int i=0;i<fileTrackingCorr_.size();++i) { cout << fileTrackingCorr_[i]->GetName() << endl; for (int j=0;j<trackingCentBin_.size();++j) { cout << trackingCentBin_[j]; cout << " Eff: " << trackingEffCorr_[i][j]->GetEntries(); cout << " Fak: " << trackingFakCorr_[i][j]->GetEntries(); cout << " Mul: " << trackingMulCorr_[i][j]->GetEntries(); cout << " Sec: " << trackingSecCorr_[i][j]->GetEntries(); cout << endl; } } // Random Number r3 = new TRandom3(mixOffset_); // ===================================================== // Initialize Counters // ===================================================== numDJ_=0,numDJReWeighted_=0; for (Int_t i=0; i<2; ++i) { numJ_[i]=0; numJReWeighted_[i]=0; } Int_t numTotEvt=0, numDJNoBkgLimit=0; Long64_t nbytes = 0, nb = 0; // Pt Bin TH1D * hPt = (TH1D*)hPtPDR[0]->ProjectionX(); Int_t numPtBins = hPt->GetNbinsX(); // Set Tree Pt bins jc_.resizePtBins(numPtBins); // ===================================================== // Centrality ReWeighting // ===================================================== TH1D *hCent = new TH1D("hCent","",40,0,100); fChain->Project("hCent","cent",""); // no evt sel, assume centrality distribution of bkg is independent of the signal hCent->Scale(1./hCent->GetEntries()); // Centrality Weight hCentralityWeight_->Divide(hCentralityData_,hCent); // ReWeighted Centrality distribution TH1D *hCentReWeighted = new TH1D("hCentReWeighted","",40,0,100); //======================================================================================================================= // Main Loop //======================================================================================================================= for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (jentry%500==0) cout << "jentry: " << jentry << " " << jentry/float(nentries) << endl; if (ientry < 0) break; nb = GetEntry(jentry); nbytes += nb; GetJetEntry(jetTree_[jetTreeMode_],vj_[jetTreeMode_],(jentry+mixOffset_)%jetTreeNEntries[jetTreeMode_]); ++numTotEvt; // Clear counters jettrk_.clear(); jc_.clear(); // ===================================================== // Main Event Selection // ===================================================== if (!doEvtSel_||(Cut(ientry)>=0&&!GetEvtMask())) { ++numDJNoBkgLimit; // ===================================================== // Jet Phase Space Limit (if Bkg Subtraction) // ===================================================== if (cut.BkgSubType=="EtaRefl") { if (fabs(anaJets_[0].eta())<cut.ConeSize||fabs(anaJets_[1].eta())<cut.ConeSize) continue; } if (cut.BkgSubType=="PhiRot") { if (fabs(anaJets_[0].eta()-anaJets_[1].eta())<cut.ConeSize*2) continue; } // If we want to restrict eta for j0,j1 separately // Classify events into j0 events or j1 events bool jetEvt[2] = { true, true }; if (cut.BkgSubType=="EtaReflSingle") { for (Int_t j=0; j<2; ++j) { if (fabs(anaJets_[j].eta())<cut.ConeSize) jetEvt[j]=false; } } // systematic checks on eta regions if (cut.BkgSubType=="EtaReflSingleEtaPos") { for (Int_t j=0; j<2; ++j) { if (fabs(anaJets_[j].eta())<cut.ConeSize||anaJets_[j].eta()<0) jetEvt[j]=false; } } if (cut.BkgSubType=="EtaReflSingleEtaNeg") { for (Int_t j=0; j<2; ++j) { if (fabs(anaJets_[j].eta())<cut.ConeSize||anaJets_[j].eta()>=0) jetEvt[j]=false; } } // ===================================================== // Set Centrality Weight // ===================================================== int cBin = hCent->FindBin(cent); double weight=1; if (doCentralityReweighting_) { if (hCentralityData_->GetBinContent(cBin)==0 || hCent->GetBinContent(cBin)==0) { weight = 0; } else { weight = hCentralityWeight_->GetBinContent(cBin); } } // ===================================================== // Fill Event Level Histograms // ===================================================== hJDPhi->Fill(anaJetDPhi_,weight); hAj->Fill((anaJets_[0].pt()-anaJets_[1].pt())/(anaJets_[0].pt()+anaJets_[1].pt()),weight); hJDEta->Fill(anaJets_[1].eta()-anaJets_[0].eta(),weight); hCentReWeighted->Fill(cent,weight); ++numDJ_; numDJReWeighted_+=weight; jettrk_.cent = cent; jettrk_.centwt = weight; for (Int_t j=0; j<2; ++j) { if (jetEvt[j]) { hJEt[j]->Fill(anaJets_[j].pt(),weight); hJEta[j]->Fill(anaJets_[j].eta(),weight); jettrk_.jtpt[j] = anaJets_[j].pt(); jettrk_.jteta[j] = anaJets_[j].eta(); jettrk_.jtphi[j] = anaJets_[j].phi(); ++numJ_[j]; numJReWeighted_[j]+=weight; } } jettrk_.jdphi = anaJetDPhi_; if (doJetOnly_) continue; // Initialize Counters Double_t conePtSum[2] = { 0,0 }; Double_t conePtBgSum[2] = { 0,0 }; Double_t metx=0,metx0=0,metx1=0,metx2=0,metx3=0,metx4=0,metx5=0; Double_t mety=0,mety0=0,mety1=0,mety2=0,mety3=0,mety4=0,mety5=0; Double_t metConex=0,metConex0=0,metConex1=0,metConex2=0,metConex3=0,metConex4=0,metConex5=0; Double_t metOutOfConex=0,metOutOfConex0=0,metOutOfConex1=0,metOutOfConex2=0,metOutOfConex3=0,metOutOfConex4=0,metOutOfConex5=0; // ===================================================== // Fill Particle Level Histograms // ===================================================== for (Int_t i=0; i<evtnp;++i) { // ------------------------ // Trk Cut // ------------------------ if (anaGenpType_==1 && pch[i]==0) continue; if (anaGenpType_==10 && (psube[i]>0 || pch[i]==0)) continue; if (cut.Name.Contains("PFChHad") && pfid[i]!=1) continue; if (cut.Name.Contains("PFPhoton") && pfid[i]!=4) continue; if (ppt[i]<cut.TrkPtMin||fabs(peta[i])>=2.4) continue; // ------------------------ // Track Efficiency/Fake Correction // ------------------------ Double_t trackWeight=1; Float_t trkcorr[4]={1,1,1,1}; if (doTrackingEffFakeCorr_) { trackWeight = getEffFakeCorrection(ppt[i],peta[i],anaJets_[0].pt(),cent,trkcorr); } // Dead forward pixel xcheck //if (peta[i]>2&&pphi[i]>-0.1&&pphi[i]<0.8) trackWeight=0; jettrk_.ppt.push_back(p_[i].pt()); jettrk_.peta.push_back(p_[i].eta()); jettrk_.pphi.push_back(p_[i].phi()); jettrk_.trkeff.push_back(trkcorr[0]); jettrk_.trkfak.push_back(trkcorr[1]); jettrk_.trkmul.push_back(trkcorr[2]); jettrk_.trksec.push_back(trkcorr[3]); // ------------------------ // calculate particle jet correlations // ------------------------ Double_t pdphi[2]={ 9999,9999 }; Double_t pdr[2]={ 9999,9999 }; Double_t pdrbg[2]={ 9999,9999 }; for (Int_t j=0; j<2; ++j) { // signal pdphi[j] = reco::deltaPhi(p_[i].phi(),anaJets_[j].phi()); pdr[j] = reco::deltaR(p_[i].eta(),p_[i].phi(),anaJets_[j].eta(),anaJets_[j].phi()); // bcksub // * If don't do event selection, make eta reflection the default bkg axis if (cut.BkgSubType.Contains("EtaRefl"||!doEvtSel_)) { pdrbg[j] = reco::deltaR(p_[i].eta(),p_[i].phi(),-1*anaJets_[j].eta(),anaJets_[j].phi()); } // monitor histograms hPJDPhi[j]->Fill(pdphi[j],trackWeight); jettrk_.pdr[j].push_back(pdr[j]); jettrk_.pdrbg[j].push_back(pdrbg[j]); } Float_t trkEnergy=p_[i].pt(); // ------------------------ // met calculation // ------------------------ Float_t pptx=cos(pdphi[0])*trkEnergy*trackWeight; metx+=pptx; Float_t ppty=sin(pdphi[0])*trkEnergy*trackWeight; mety+=ppty; if (fabs(pdr[0])<0.8||fabs(pdr[1])<0.8) metConex+=pptx; else metOutOfConex+=pptx; //for (int i=0;i<hPt->GetNbinsX()+2;++i) cout << "Bin " << i << " ledge: " << hPt->GetBinLowEdge(i) << endl; if (trkEnergy>=hPt->GetBinLowEdge(1)&&trkEnergy<hPt->GetBinLowEdge(2)) { metx0+=pptx; mety0+=ppty; if (fabs(pdr[0])<0.8||fabs(pdr[1])<0.8) metConex0+=pptx; else metOutOfConex0+=pptx; } else if (trkEnergy>=hPt->GetBinLowEdge(2)&&trkEnergy<hPt->GetBinLowEdge(3)) { metx1+=pptx; mety1+=ppty; if (fabs(pdr[0])<0.8||fabs(pdr[1])<0.8) metConex1+=pptx; else metOutOfConex1+=pptx; } else if (trkEnergy>=hPt->GetBinLowEdge(3)&&trkEnergy<hPt->GetBinLowEdge(4)) { metx2+=pptx; mety2+=ppty; if (fabs(pdr[0])<0.8||fabs(pdr[1])<0.8) metConex2+=pptx; else metOutOfConex2+=pptx; } else if (trkEnergy>=hPt->GetBinLowEdge(4)&&trkEnergy<hPt->GetBinLowEdge(5)) { metx3+=pptx; mety3+=ppty; if (fabs(pdr[0])<0.8||fabs(pdr[1])<0.8) metConex3+=pptx; else metOutOfConex3+=pptx; } else if (trkEnergy>=hPt->GetBinLowEdge(5)&&trkEnergy<hPt->GetBinLowEdge(6)) { metx4+=pptx; mety4+=ppty; if (fabs(pdr[0])<0.8||fabs(pdr[1])<0.8) metConex4+=pptx; else metOutOfConex4+=pptx; } else if (trkEnergy>=hPt->GetBinLowEdge(6)&&trkEnergy<hPt->GetBinLowEdge(7)) { metx5+=pptx; mety5+=ppty; if (fabs(pdr[0])<0.8||fabs(pdr[1])<0.8) metConex5+=pptx; else metOutOfConex5+=pptx; } // ===================================================== // Calculate Cone Sums // ===================================================== // cone sum for (Int_t j=0; j<2; ++j) { for (Int_t b=0; b<numPtBins; ++b) { if (trkEnergy>=hPt->GetBinLowEdge(b+1)&&trkEnergy<hPt->GetBinLowEdge(b+2)) { // Signal Cone if (pdr[j]<cut.ConeSize) { jc_.cpt[j][b]+=trkEnergy*trackWeight; jc_.cptpara[j][b]+=cos(reco::deltaPhi(p_[i].phi(),anaJets_[0].phi()))*trkEnergy*trackWeight; } // Bkg Cone if (pdrbg[j]<cut.ConeSize) { jc_.cptbg[j][b]+=trkEnergy*trackWeight; jc_.cptparabg[j][b]+=cos(reco::deltaPhi(p_[i].phi(),anaJets_[0].phi()))*trkEnergy*trackWeight; } break; } } } // ===================================================== // Take the reweighting into account for later histogram // **This should not be applied before the met calculation.** // ===================================================== trackWeight *= weight; // ===================================================== // Fill Jet-Particle Histograms // ===================================================== for (Int_t j=0; j<2; ++j) { if (jetEvt[j]) { // Signal Cone if (pdr[j]<cut.ConeSize) { conePtSum[j]+=trkEnergy*trackWeight; hCPPt[j]->Fill(trkEnergy,trackWeight); hPtPDR[j]->Fill(trkEnergy,pdr[j],trkEnergy*trackWeight); } // Background Cone if (pdrbg[j]<cut.ConeSize) { hCPPtBg[j]->Fill(trkEnergy,trackWeight); conePtBgSum[j]+=trkEnergy*trackWeight; hPtPDRBg[j]->Fill(trkEnergy,pdrbg[j],trkEnergy*trackWeight); } } } } // end of particles loop // ===================================================== // Fill Cone Sums // ===================================================== for (Int_t j=0; j<2; ++j) { if (jetEvt[j]) { hCPt[j]->Fill(conePtSum[j]); hCPtBg[j]->Fill(conePtBgSum[j]); hCPtBgSub[j]->Fill(conePtSum[j]-conePtBgSum[j]); } } // ===================================================== // Fill Ntuple // ===================================================== Float_t var[100]; var[0]=anaJets_[0].pt(); var[1]=anaJets_[0].eta(); var[2]=anaJets_[0].phi(); var[3]=anaJets_[1].pt(); var[4]=anaJets_[1].eta(); var[5]=anaJets_[1].phi(); var[6]=metx; var[7]=metx0; var[8]=metx1; var[9]=metx2; var[10]=metx3; var[11]=metx4; var[12]=metx5; var[13]=mety; var[14]=mety0; var[15]=mety1; var[16]=mety2; var[17]=mety3; var[18]=mety4; var[19]=mety5; var[20]=metConex; var[21]=metConex0; var[22]=metConex1; var[23]=metConex2; var[24]=metConex3; var[25]=metConex4; var[26]=metConex5; var[27]=metOutOfConex; var[28]=metOutOfConex0; var[29]=metOutOfConex1; var[30]=metOutOfConex2; var[31]=metOutOfConex3; var[32]=metOutOfConex4; var[33]=metOutOfConex5; var[34]=GetEvtMask(); var[35]=cent; var[36]=anaJetDPhi_; var[37]=weight; ntjt->Fill(var); // fit ntuple tjttrk->Fill(); tcone->Fill(); } // End of Main Event Selection // if (Cut(ientry) < 0) continue; } // ===================================================== // Summarize Event Loop // ===================================================== cout << "Total Events: " << numTotEvt << endl; cout << "DiJets Selected w/o Bkg Limit: " << numDJNoBkgLimit << " (same as draw cut unless there is jet eta correction)" << endl; cout << "DiJets Selected: " << numDJ_ << " Reweighted: " << numDJReWeighted_ << endl; for (Int_t j=0; j<2; ++j) { cout << "num Jet" << j << " Selected: " << numJ_[j] << " Reweighted: " << numJReWeighted_[j] << endl; } // ===================================================== // Normalize by Number of Selected Events // ===================================================== hJDPhi->Scale(1./(numDJReWeighted_)); hJDEta->Scale(1./(numDJReWeighted_)); hAj->Scale(1./(numDJReWeighted_)); hCentReWeighted->Scale(1./(numDJReWeighted_)); for (Int_t j=0; j<2; ++j) { hJEt[j]->Scale(1./(numJReWeighted_[j])); hJEta[j]->Scale(1./(numJReWeighted_[j])); hCPPt[j]->Scale(1./numJReWeighted_[j]); hCPPtBg[j]->Scale(1./numJReWeighted_[j]); hCPPtBgSub[j]->Add(hCPPt[j],hCPPtBg[j],1,-1); hCPt[j]->Scale(1./(numJReWeighted_[j])); hCPtBg[j]->Scale(1./(numJReWeighted_[j])); hCPtBgSub[j]->Scale(1./(numJReWeighted_[j])); hPtPDR[j]->Scale(1./(numJReWeighted_[j])); hPtPDRBg[j]->Scale(1./(numJReWeighted_[j])); } }
void plot_PIDs_weighted(){ // Run this at the command line by doing // root -l sidebandSubtraction.C // Import formatting template gROOT->ProcessLine(".L ~/cern/scripts/lhcbStyle.C"); // Definition of variables const std::string filename_MC = "/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/Lb2chicpK_MC_2012_signal_cut.root"; const std::string filename_weights = "/afs/cern.ch/work/a/apmorris/private/cern/ntuples/new_tuples/weighted_data_2012.root"; const std::string treename = "DecayTree"; const std::string treename_weights = "ds"; const std::string yaxis = "Candidates"; // Opening files and trees TFile* f_MC = TFile::Open( filename_MC.c_str() ); if( !f_MC ) std::cout << "file " << filename_mc << " does not exist" << std::endl; TTree* t_MC = (TTree*)f_MC->Get( treename.c_str() ); if( !t_MC ) std::cout << "tree " << treename << " does not exist" << std::endl; TFile* f_sw = TFile::Open( filename_weights.c_str() ); if( !f_sw ) std::cout << "file " << filename_weights << " does not exist" << std::endl; TTree* t_sw = (TTree*)f_sw->Get( treename_weights.c_str() ); if( !t_sw ) std::cout << "tree " << treename_weights << " does not exist" << std::endl; // Including the LHCb name, formatting lhcbName = new TPaveText(gStyle->GetPadLeftMargin() + 0.03, 0.87 - gStyle->GetPadTopMargin(), gStyle->GetPadLeftMargin() + 0.13, 0.95 - gStyle->GetPadTopMargin(), "BRNDC"); lhcbName->AddText("LHCb"); lhcbName->SetFillColor(0); lhcbName->SetTextAlign(12); lhcbName->SetBorderSize(0); gStyle->SetOptStat(0); // Defining histograms, drawing, for proton TH1D* h1_p = new TH1D ("h1_p", "proton_ProbNNpcorr", 20, 0., 1.); TH1D* h2_p = new TH1D ("h2_p", "proton_ProbNNp", 20, 0., 1.); TH1D* h3_p = new TH1D ("h3_p", "proton_ProbNNp", 20, 0., 1.); t_MC->Draw("proton_ProbNNpcorr>>h1_p", "", "goff"); t_sw->Draw("proton_ProbNNp>>h2_p", "sigYield_sw", "goff"); t_MC->Draw("proton_ProbNNp>>h3_p", "", "goff"); // Defining histograms, drawing, for kaon TH1D* h1_k = new TH1D ("h1_k", "kaon_ProbNNkcorr", 20, 0., 1.); TH1D* h2_k = new TH1D ("h2_k", "kaon_ProbNNk", 20, 0., 1.); TH1D* h3_k = new TH1D ("h3_k", "kaon_ProbNNk", 20, 0., 1.); t_MC->Draw("kaon_ProbNNkcorr>>h1_k", "", "goff"); t_sw->Draw("kaon_ProbNNk>>h2_k", "sigYield_sw", "goff"); t_MC->Draw("kaon_ProbNNk>>h3_k", "", "goff"); /* // Plotting the results of the signal selection TCanvas* c1 = new TCanvas("c1"); c1->Divide(1,1); c1->cd(1); h1->Draw(); h1->GetXaxis()->SetTitle("proton_ProbNNp"); h2->GetYaxis()->SetTitle( yaxis.c_str() ); lhcbName->Draw(); c1->SaveAs("~/cern/plots/signal_region_proton_ProbNNp.png"); // Plotting the results of the sideband selection TCanvas* c2 = new TCanvas("c2"); c2->Divide(1,1); c2->cd(1); h2->Draw(); h2->GetXaxis()->SetTitle("proton_ProbNNp"); h2->GetYaxis()->SetTitle( yaxis.c_str() ); lhcbName->Draw(); c2->SaveAs("~/cern/plots/sideband_region_proton_ProbNNp.png"); */ // Scaling the sideband histo to the signal histo, and subtracting, for proton //h_sb_p->Scale(0.5); //h_sg_p->Add(h_sb_p, -1); // Scaling the Monte Carlo data int NMC = t_MC->GetEntries(); int Ndata = t_sw->GetEntries(); TH1D* yield = new TH1D ("yield", "sigYield_sw", 25, -10., 10.); t_sw->Draw("sigYield_sw>>yield", "", "goff"); double signal = yield->GetMean() * yield->GetEntries(); h1_p->Scale( signal / double(NMC)); h3_p->Scale( signal / double(NMC)); // Plotting the results of the sideband subtraction alongside the scaled MC data, for proton h2_p->Sumw2(); h2_p->SetMarkerStyle(20); h2_p->SetMarkerColor(1); h1_p->SetMarkerColor(kRed); h1_p->SetLineColor(kRed); h3_p->SetMarkerColor(8); h3_p->SetLineColor(8); TCanvas* c_p = new TCanvas("c_p"); c_p->Divide(1,1); c_p->cd(1); h3_p->Draw(); h2_p->Draw("same"); h1_p->Draw("same"); h3_p->GetXaxis()->SetTitle("2012 proton_ProbNNp"); h3_p->GetYaxis()->SetTitle( yaxis.c_str() ); //lhcbName->Draw(); leg1 = new TLegend(0.15,0.65,0.4,0.85); leg1->SetHeader("#bf{Key:}"); leg1->AddEntry(h1_p,"MC(corrected)","l"); leg1->AddEntry(h3_p,"MC (uncorrected)","l"); leg1->AddEntry(h2_p,"sWeighted data","p"); leg1->Draw(); c_p->SaveAs("~/cern/plots/sideband_subtractions/2012_proton_ProbNNp_sweights_PID-corrected.png"); // Scaling the sideband histo to the signal histo, and subtracting, for kaon //h_sb_k->Scale(0.5); //h_sg_k->Add(h_sb_k, -1); // Scaling the Monte Carlo data int NMCk = t_MC->GetEntries(); int Ndatak = t_sw->GetEntries(); h1_k->Scale( signal / double(NMCk)); h3_k->Scale( signal / double(NMCk)); //h3_k->Scale(float(Ndata)/float(NMC_sw)); //int new_NMC = h_un_p->GetEntries(); // Plotting the results of the sideband subtraction alongside the scaled MC data, for kaon h2_k->Sumw2(); h2_k->SetMarkerStyle(20); h2_k->SetMarkerColor(1); h1_k->SetMarkerColor(kRed); h1_k->SetLineColor(kRed); h3_k->SetMarkerColor(8); h3_k->SetLineColor(8); TCanvas* c_k = new TCanvas("c_k"); c_k->Divide(1,1); c_k->cd(1); h3_k->Draw(); h2_k->Draw("same"); h1_k->Draw("same"); h3_k->GetXaxis()->SetTitle("2012 kaon_ProbNNk"); h3_k->GetYaxis()->SetTitle( yaxis.c_str() ); //lhcbName->Draw(); leg2 = new TLegend(0.15,0.65,0.4,0.85); leg2->SetHeader("#bf{Key:}"); leg2->AddEntry(h1_k,"MC(corrected)","l"); leg2->AddEntry(h3_k,"MC (uncorrected)","l"); leg2->AddEntry(h2_k,"sWeighted data","p"); leg2->Draw(); c_k->SaveAs("~/cern/plots/sideband_subtractions/2012_kaon_ProbNNk_sweights_PID-corrected.png"); std::cout << "\n" << signal << " signal events" << std::endl; std::cout << "\n" << NMC << " Monte Carlo events" << "\n" << std::endl; //std::cout << new_NMC << std::endl; }
int main(int argc, char * argv[]) { // first argument - config file // second argument - filelist using namespace std; //const int CutNumb = 8; //string CutList[CutNumb]={"No cut","Trigger","1l","lept-Veto","b-Veto","MET $>$ 50","MET $>$ 100","dPhi $>$ 1"}; // **** configuration Config cfg(argv[1]); string SelectionSign="tautau"; // kinematic cuts on electrons const Float_t ptElectronLowCut = cfg.get<Float_t>("ptElectronLowCut"); const Float_t ptElectronHighCut = cfg.get<Float_t>("ptElectronHighCut"); const Float_t etaElectronCut = cfg.get<Float_t>("etaElectronCut"); const Float_t dxyElectronCut = cfg.get<Float_t>("dxyElectronCut"); const Float_t dzElectronCut = cfg.get<Float_t>("dzElectronCut"); const Float_t isoElectronLowCut = cfg.get<Float_t>("isoElectronLowCut"); const Float_t isoElectronHighCut = cfg.get<Float_t>("isoElectronHighCut"); const bool applyElectronId = cfg.get<bool>("ApplyElectronId"); // kinematic cuts on muons const Float_t ptMuonLowCut = cfg.get<Float_t>("ptMuonLowCut"); const Float_t ptMuonHighCut = cfg.get<Float_t>("ptMuonHighCut"); const Float_t etaMuonCut = cfg.get<Float_t>("etaMuonCut"); const Float_t dxyMuonCut = cfg.get<Float_t>("dxyMuonCut"); const Float_t dzMuonCut = cfg.get<Float_t>("dzMuonCut"); const Float_t isoMuonLowCut = cfg.get<Float_t>("isoMuonLowCut"); const Float_t isoMuonHighCut = cfg.get<Float_t>("isoMuonHighCut"); const bool applyMuonId = cfg.get<bool>("ApplyMuonId"); // kinematic cuts on Jets const Float_t etaJetCut = cfg.get<Float_t>("etaJetCut"); const Float_t ptJetCut = cfg.get<Float_t>("ptJetCut"); // topological cuts const Float_t dRleptonsCut = cfg.get<Float_t>("dRleptonsCut"); const Float_t dZetaCut = cfg.get<Float_t>("dZetaCut"); const bool oppositeSign = cfg.get<bool>("oppositeSign"); const Float_t taupt = cfg.get<Float_t>("taupt"); const Float_t taueta = cfg.get<Float_t>("taueta"); const Float_t decayModeFinding = cfg.get<Float_t>("decayModeFinding"); const Float_t decayModeFindingNewDMs = cfg.get<Float_t>("decayModeFindingNewDMs"); const Float_t againstElectronVLooseMVA5 = cfg.get<Float_t>("againstElectronVLooseMVA5"); const Float_t againstMuonTight3 = cfg.get<Float_t>("againstMuonTight3"); const Float_t againstMuonLoose3 = cfg.get<Float_t>("againstMuonLoose3"); const Float_t vertexz = cfg.get<Float_t>("vertexz"); const Float_t byCombinedIsolationDeltaBetaCorrRaw3Hits = cfg.get<Float_t>("byCombinedIsolationDeltaBetaCorrRaw3Hits"); const Float_t Lumi = cfg.get<Float_t>("Lumi"); const Float_t bTag = cfg.get<Float_t>("bTag"); const Float_t metcut = cfg.get<Float_t>("metcut"); CutList.clear(); CutList.push_back("No cut"); CutList.push_back("Trigger"); CutList.push_back("$Ld tau$"); CutList.push_back("$Trail tau$"); CutList.push_back("2nd lept-Veto"); CutList.push_back("3rd lept-Veto"); CutList.push_back("b-Veto "); CutList.push_back("MET $>$ 50"); CutList.push_back("MET $>$ 100"); CutList.push_back("dPhi > 1"); int CutNumb = int(CutList.size()); xs=1;fact=1;fact2=1; ifstream ifs("xsecs"); string line; while(std::getline(ifs, line)) // read one line from ifs { fact=fact2=1; istringstream iss(line); // access line as a stream // we only need the first two columns string dt; iss >> dt >> xs >> fact >> fact2; //ifs >> dt >> xs; // no need to read further //cout<< " "<<dt<<" "<<endl; //cout<< "For sample ========================"<<dt<<" xsecs is "<<xs<<" XSec "<<XSec<<" "<<fact<<" "<<fact2<<endl; //if (dt==argv[2]) { //if (std::string::npos != dt.find(argv[2])) { if ( dt == argv[2]) { XSec= xs*fact*fact2; cout<<" Found the correct cross section "<<xs<<" for Dataset "<<dt<<" XSec "<<XSec<<endl; } } if (XSec<0) {cout<<" Something probably wrong with the xsecs...please check - the input was "<<argv[2]<<endl;return 0;} bool doThirdLeptVeto=true; bool doMuVeto=true; //CutList[CutNumb]=CutListt[CutNumb]; // file name and tree name std::string rootFileName(argv[2]); std::ifstream fileList(argv[2]); std::ifstream fileList0(argv[2]); std::string ntupleName("makeroottree/AC1B"); TString TStrName(rootFileName); std::cout <<TStrName <<std::endl; // output fileName with histograms TFile * file = new TFile(TStrName+TString(".root"),"update"); file->mkdir(SelectionSign.c_str()); file->cd(SelectionSign.c_str()); int nFiles = 0; int nEvents = 0; int selEvents = 0; int nTotalFiles = 0; int iCut=0; double CFCounter[CutNumb]; double statUnc[CutNumb]; int iCFCounter[CutNumb]; for (int i=0;i < CutNumb; i++){ CFCounter[i] = 0; iCFCounter[i] = 0; statUnc[i] =0; } std::string dummy; // count number of files ---> while (fileList0 >> dummy) nTotalFiles++; SetupHists(CutNumb); //nTotalFiles=10; for (int iF=0; iF<nTotalFiles; ++iF) { std::string filen; fileList >> filen; std::cout << "file " << iF+1 << " out of " << nTotalFiles << " filename : " << filen << std::endl; TFile * file_ = TFile::Open(TString(filen)); TTree * _tree = NULL; _tree = (TTree*)file_->Get(TString(ntupleName)); if (_tree==NULL) continue; TH1D * histoInputEvents = NULL; histoInputEvents = (TH1D*)file_->Get("makeroottree/nEvents"); if (histoInputEvents==NULL) continue; int NE = int(histoInputEvents->GetEntries()); std::cout << " number of input events = " << NE << std::endl; //NE=1000; for (int iE=0;iE<NE;++iE) inputEventsH->Fill(0.); AC1B analysisTree(_tree); Long64_t numberOfEntries = analysisTree.GetEntries(); //numberOfEntries = 1000; std::cout << " number of entries in Tree = " << numberOfEntries << std::endl; //numberOfEntries = 10000; for (Long64_t iEntry=0; iEntry<numberOfEntries; iEntry++) { analysisTree.GetEntry(iEntry); nEvents++; JetsMV.clear(); ElMV.clear(); TauMV.clear(); MuMV.clear(); LeptMV.clear(); Float_t MET = sqrt ( analysisTree.pfmet_ex*analysisTree.pfmet_ex + analysisTree.pfmet_ey*analysisTree.pfmet_ey); METV.SetPx(analysisTree.pfmet_ex); METV.SetPy(analysisTree.pfmet_ey); if (nEvents%10000==0) cout << " processed " << nEvents << " events" << endl; for (unsigned int ij = 0; ij<analysisTree.pfjet_count; ++ij) { JetsV.SetPxPyPzE(analysisTree.pfjet_px[ij], analysisTree.pfjet_py[ij], analysisTree.pfjet_pz[ij], analysisTree.pfjet_e[ij]); JetsMV.push_back(JetsV); } for (unsigned int im = 0; im<analysisTree.muon_count; ++im) { MuV.SetPtEtaPhiM(analysisTree.muon_pt[im], analysisTree.muon_eta[im], analysisTree.muon_phi[im], muonMass); MuMV.push_back(MuV); } for (unsigned int ie = 0; ie<analysisTree.electron_count; ++ie) { ElV.SetPtEtaPhiM(analysisTree.electron_pt[ie], analysisTree.electron_eta[ie], analysisTree.electron_phi[ie], electronMass); ElMV.push_back(ElV); } for (unsigned int it = 0; it<analysisTree.tau_count; ++it) { TauV.SetPtEtaPhiM(analysisTree.tau_pt[it], analysisTree.tau_eta[it], analysisTree.tau_phi[it], tauMass); TauMV.push_back(TauV); } Float_t weight = 1; iCut = 0; Double_t EvWeight = 1.0; EvWeight *= weight ; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // hnJets[->Fill(pfjet_count); // std::cout << "Entry : " << iEntry << std::endl; // std::cout << "Number of gen particles = " << analysisTree.genparticles_count << std::endl; // std::cout << "Number of taus = " << analysisTree.tau_count << std::endl; // std::cout << "Number of jets = " << analysisTree.pfjet_count << std::endl; // std::cout << "Number of muons = " << analysisTree.muon_count << std::endl; // **** Analysis of generator info // int indexW = -1; // int indexNu = -1; // int indexMu = -1; // int indexE = -1; // int nGenMuons = 0; // int nGenElectrons = 0; // for (unsigned int igen=0; igen<analysisTree.genparticles_count; ++igen) { // Float_t pxGen = analysisTree.genparticles_px[igen]; // Float_t pyGen = analysisTree.genparticles_py[igen]; // Float_t pzGen = analysisTree.genparticles_pz[igen]; // Float_t etaGen = PtoEta(pxGen,pyGen,pzGen); // Float_t ptGen = PtoPt(pxGen,pyGen); // if (fabs(analysisTree.genparticles_pdgid[igen])==24 && analysisTree.genparticles_status[igen]==62) // indexW = igen; // if ((fabs(analysisTree.genparticles_pdgid[igen])==12 // ||fabs(analysisTree.genparticles_pdgid[igen])==14 // ||fabs(analysisTree.genparticles_pdgid[igen])==16) // && analysisTree.genparticles_info[igen]== (1<<1) ) // indexNu = igen; // if (fabs(analysisTree.genparticles_pdgid[igen])==13) { // if ( analysisTree.genparticles_info[igen]== (1<<1) ) { // indexMu = igen; // if (fabs(etaGen)<2.3 && ptGen>10.) // nGenMuons++; // } // } // if (fabs(analysisTree.genparticles_pdgid[igen])==11) { // if ( analysisTree.genparticles_info[igen]== (1<<1) ) { // indexE = igen; // if (fabs(etaGen)<2.3 && ptGen>10.) // nGenElectrons++; // } // } // } // trigger selection //selecTable.Fill(1,0, weight ); bool trigAccept = false; for (int i=0; i<kMaxhltriggerresults; ++i) { //if ((i==5||i==6)&& analysisTree.hltriggerresults_second[i]==1) { // if ((i==0 || i==2)&& analysisTree.hltriggerresults_second[i]==1) { if ( i==6 && analysisTree.hltriggerresults_second[i]==1) { // std::cout << analysisTree.run_hltnames->at(i) << " : " << analysisTree.hltriggerresults_second[i] << std::endl; trigAccept = true; } } if (!trigAccept) continue; //Trigger FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV,analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; /////now clear the Mu.El.Jets again to fill them again after cleaning MuMV.clear(); ElMV.clear(); // electron selection unsigned int tauld_index=-1; unsigned int tautr_index=-1; vector<int> electrons; electrons.clear(); // muon selection vector<int> muons; muons.clear();/* for (unsigned int im = 0; im<analysisTree.muon_count; ++im) { muonPtAllH->Fill(analysisTree.muon_pt[im],weight); if (analysisTree.muon_pt[im]<ptMuonHighCut) continue; if (fabs(analysisTree.muon_eta[im])>etaMuonCut) continue; if (fabs(analysisTree.muon_dxy[im])>dxyMuonCut) continue; if (fabs(analysisTree.muon_dz[im])>dzMuonCut) continue; Float_t neutralIso = analysisTree.muon_neutralHadIso[im] + analysisTree.muon_photonIso[im] - 0.5*analysisTree.muon_puIso[im]; neutralIso = TMath::Max(Float_t(0),neutralIso); Float_t absIso = analysisTree.muon_chargedHadIso[im] + neutralIso; Float_t relIso = absIso/analysisTree.muon_pt[im]; hmu_relISO[1]->Fill(relIso,weight); if (relIso>isoMuonHighCut) continue; if (relIso<isoMuonLowCut) continue; if (applyMuonId && !analysisTree.muon_isMedium[im]) continue; muons.push_back(im); MuV.SetPtEtaPhiM(analysisTree.muon_pt[im], analysisTree.muon_eta[im], analysisTree.muon_phi[im], muonMass); MuMV.push_back(MuV); LeptMV.push_back(MuV); //hmu_miniISO[1]->Fill(analysisTree.muon_miniISO[im],weight); } mu_index=muons[0]; sort(LeptMV.begin(), LeptMV.end(),ComparePt); if (LeptMV.size() == 0 ) continue; mu_index=muons[0]; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; */ //###################### leading tau candindate ################# vector<int> tauld; tauld.clear(); for (unsigned int it = 0; it<analysisTree.tau_count; ++it) { tauPtAllH->Fill(analysisTree.tau_pt[it],weight); tauEtaAllH->Fill(analysisTree.tau_eta[it],weight); if (analysisTree.tau_pt[it] < 45 || fabs(analysisTree.tau_eta[it])> 2.1) continue; if (analysisTree.tau_decayModeFinding[it]<decayModeFinding && analysisTree.tau_decayModeFindingNewDMs[it]<decayModeFindingNewDMs) continue; if (analysisTree.tau_againstElectronVLooseMVA5[it]<againstElectronVLooseMVA5) continue; if (analysisTree.tau_againstMuonLoose3[it]<againstMuonLoose3) continue; if ( fabs(analysisTree.tau_vertexz[it] - analysisTree.primvertex_z ) > vertexz ) continue; if (analysisTree.tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[it] > 1 ) continue; tauld.push_back(it); } if (tauld.size()==0) continue; tauld_index=tauld[0]; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; vector<int> tautr; tautr.clear(); for (unsigned int itr = 0; itr<analysisTree.tau_count; ++itr) { if (itr != tauld_index ){ if (analysisTree.tau_pt[itr] < 45 || fabs(analysisTree.tau_eta[itr])> 2.1) continue; if (analysisTree.tau_decayModeFinding[itr]<decayModeFinding && analysisTree.tau_decayModeFindingNewDMs[itr]<decayModeFindingNewDMs) continue; if (analysisTree.tau_againstElectronVLooseMVA5[itr]<againstElectronVLooseMVA5) continue; if (analysisTree.tau_againstMuonLoose3[itr]<againstMuonLoose3) continue; if ( fabs(analysisTree.tau_vertexz[itr] - analysisTree.primvertex_z ) > vertexz ) continue; if (analysisTree.tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[itr] > 1 ) continue; tautr.push_back(itr); } } if (tautr.size()==0) continue; tautr_index=tautr[0]; float dR = deltaR(analysisTree.tau_eta[tauld_index],analysisTree.tau_phi[tauld_index], analysisTree.tau_eta[tautr_index],analysisTree.tau_phi[tautr_index]); if (dR<dRleptonsCut) continue; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; /* cout<<" "<<TauMV.size()<<endl; if (TauMV.size()>1){ double mVisA = TauMV[0].M(); // mass of visible object on side A. Must be >=0. double pxA = TauMV[0].Px(); // x momentum of visible object on side A. double pyA = TauMV[0].Py(); // y momentum of visible object on side A. double mVisB = TauMV[1].M(); // mass of visible object on side B. Must be >=0. double pxB = TauMV[1].Px(); // x momentum of visible object on side B. double pyB = TauMV[1].Py(); // y momentum of visible object on side B. double pxMiss = analysisTree.pfmet_ex; // x component of missing transverse momentum. double pyMiss = analysisTree.pfmet_ey; // y component of missing transverse momentum. double chiA = 0; // hypothesised mass of invisible on side A. Must be >=0. double chiB = 0; // hypothesised mass of invisible on side B. Must be >=0. double desiredPrecisionOnMt2 = 0; // Must be >=0. If 0 alg aims for machine precision. if >0, MT2 computed to supplied absolute precision. // asymm_mt2_lester_bisect::disableCopyrightMessage(); double MT2 = asymm_mt2_lester_bisect::get_mT2( mVisA, pxA, pyA, mVisB, pxB, pyB, pxMiss, pyMiss, chiA, chiB, desiredPrecisionOnMt2); cout<<" MT2 here "<<MT2<<endl; } */ bool MuVeto=false; if (doMuVeto){ if (analysisTree.muon_count>0){ for (unsigned int imv = 0; imv<analysisTree.muon_count; ++imv) { Float_t neutralIso = analysisTree.muon_neutralHadIso[imv] + analysisTree.muon_photonIso[imv] - 0.5*analysisTree.muon_puIso[imv]; neutralIso = TMath::Max(Float_t(0),neutralIso); Float_t absIso = analysisTree.muon_chargedHadIso[imv] + neutralIso; Float_t relIso = absIso/analysisTree.muon_pt[imv]; if ( analysisTree.muon_isGlobal[imv] && analysisTree.muon_isTracker[imv] && analysisTree.muon_isPF[imv] && analysisTree.muon_pt[imv]> 15 && fabs(analysisTree.muon_eta[imv])< 2.4 && fabs(analysisTree.muon_dxy[imv])<0.045 && fabs(analysisTree.muon_dz[imv] < 0.2 && relIso< 0.3 && analysisTree.muon_isMedium[imv]) ) MuVeto=true; } } } if (MuVeto) continue; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; bool ThirdLeptVeto=false; if (doThirdLeptVeto){ if (analysisTree.electron_count>0) { for (unsigned int iev = 0; iev<analysisTree.electron_count; ++iev) { Float_t neutralIsoV = analysisTree.electron_r03_sumNeutralHadronEt[iev] + analysisTree.electron_r03_sumNeutralHadronEt[iev] + analysisTree.electron_r03_sumPhotonEt[iev] - 4*TMath::Pi()*(0.3*0.3)*analysisTree.rho; Float_t IsoWithEA = analysisTree.electron_r03_sumChargedHadronPt[iev] + TMath::Max(Float_t(0), neutralIsoV); Float_t relIsoV = IsoWithEA/analysisTree.electron_pt[iev]; bool ElVetoID = electronVetoTight(analysisTree.electron_superclusterEta[iev], analysisTree.electron_eta[iev],analysisTree.electron_phi[iev], analysisTree.electron_full5x5_sigmaietaieta[iev], analysisTree.electron_ehcaloverecal[iev], analysisTree.electron_dxy[iev], analysisTree.electron_dz[iev], analysisTree.electron_ooemoop[iev], relIsoV,analysisTree.electron_nmissinginnerhits[iev],analysisTree.electron_pass_conversion[iev]); if ( analysisTree.electron_pt[iev] > 10 && fabs(analysisTree.electron_eta[iev]) < 2.5 && fabs(analysisTree.electron_dxy[iev])<0.045 && fabs(analysisTree.electron_dz[iev]) < 0.2 && relIsoV< 0.3 && ElVetoID) ThirdLeptVeto=true; } } if (analysisTree.muon_count>0){ for (unsigned int imvv = 0; imvv<analysisTree.muon_count; ++imvv) { // if ( imvv != mu_index && analysisTree.muon_charge[imvv] != analysisTree.muon_charge[mu_index] ){ Float_t neutralIso = analysisTree.muon_neutralHadIso[imvv] + analysisTree.muon_photonIso[imvv] - 0.5*analysisTree.muon_puIso[imvv]; neutralIso = TMath::Max(Float_t(0),neutralIso); Float_t absIso = analysisTree.muon_chargedHadIso[imvv] + neutralIso; Float_t relIso = absIso/analysisTree.muon_pt[imvv]; if ( analysisTree.muon_isMedium[imvv] && analysisTree.muon_pt[imvv]> 10 && fabs(analysisTree.muon_eta[imvv])< 2.4 && fabs(analysisTree.muon_dxy[imvv])<0.045 && fabs(analysisTree.muon_dz[imvv] < 0.2 && relIso< 0.3 && analysisTree.muon_isMedium[imvv]) ) ThirdLeptVeto=true; } } } if (ThirdLeptVeto) continue; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // for (unsigned int j=0;j<LeptMV.size();++j) cout<<" j "<<j<<" "<<LeptMV.at(j).Pt()<<endl; // cout<<""<<endl; ////////jets cleaning Float_t DRmax=0.4; vector<int> jets; jets.clear(); TLorentzVector leptonsV, muonJ, jetsLV; // continue; //JetsV.SetPxPyPzE(analysisTree.pfjet_px[ij], analysisTree.pfjet_py[ij], analysisTree.pfjet_pz[ij], analysisTree.pfjet_e[ij]); for (unsigned int il = 0; il<LeptMV.size(); ++il) { for (unsigned int ij = 0; ij<JetsMV.size(); ++ij) { if(fabs(JetsMV.at(ij).Eta())>etaJetCut) continue; if(fabs(JetsMV.at(ij).Pt())<ptJetCut) continue; Float_t Dr= deltaR(LeptMV.at(il).Eta(), LeptMV.at(il).Phi(),JetsMV.at(ij).Eta(),JetsMV.at(ij).Phi()); if ( Dr < DRmax) { JetsMV.erase (JetsMV.begin()+ij); } } } // selecting muon and electron pair (OS or SS); Float_t ptScalarSum = -1; bool btagged= false; for (unsigned int ib = 0; ib <analysisTree.pfjet_count;ib++){ if (analysisTree.pfjet_btag[ib][6] > bTag) btagged = true; //cout<<" pfjet_b "<<ib<<" "<<analysisTree.pfjet_btag[ib][6]<<endl; } if (btagged || JetsMV.size() > 3) continue; // Jets FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // pt Scalar // computations of kinematic variables Float_t ETmiss = TMath::Sqrt(analysisTree.pfmet_ex*analysisTree.pfmet_ex + analysisTree.pfmet_ey*analysisTree.pfmet_ey); // bisector of electron and muon transverse momenta // computation of MT variable Float_t dPhi=-999; dPhi=dPhiFrom2P( LeptMV.at(0).Px(), LeptMV.at(0).Py(), analysisTree.pfmet_ex, analysisTree.pfmet_ey ); //MT = TMath::Sqrt(2*LeptMV.at(0).Pt()*ETmiss*(1-TMath::Cos(dPhi))); // filling histograms after dilepton selection // ETmissH->Fill(ETmiss,weight); // MtH->Fill(MT,weight); if (ETmiss < metcut) continue; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; if (ETmiss < 2*metcut) continue; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // topological cut //if (DZeta<dZetaCut) continue; if (dPhi>1) continue; FillMainHists(iCut, EvWeight, ElMV, MuMV, TauMV, JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // std::cout << std::endl; selEvents++; } // end of file processing (loop over events in one file) nFiles++; delete _tree; file_->Close(); delete file_; } cout << endl << "Finished event loop" << endl; for (int i=0;i<CutNumb;++i){ CFCounter[i] *= Float_t(XSec*Lumi/inputEventsH->GetSum()); if (iCFCounter[i] <0.2) statUnc[i] =0; else statUnc[i] = CFCounter[i]/sqrt(iCFCounter[i]); } //write out cutflow ofstream tfile; // TString outname = argv[argc-1]; TString outname=argv[2]; TString textfilename = "cutflow_"+outname+"_"+SelectionSign+".txt"; tfile.open(textfilename); tfile << "########################################" << endl; //tfile << "Cut efficiency numbers:" << endl; // tfile << " Cut "<<"\t & \t"<<"#Evnts for "<<Lumi/1000<<" fb-1 & \t"<<" Uncertainty \t"<<" cnt\t"<<endl; for(int ci = 0; ci < CutNumb; ci++) { tfile << CutList[ci]<<"\t & \t" << CFCounter[ci] <<"\t & \t"<< statUnc[ci] <<"\t & \t"<< iCFCounter[ci] << endl; CutFlow->SetBinContent(1+ci,CFCounter[ci]); } tfile.close(); //ofstream tfile1; //TString textfile_Con = "CMG_cutflow_Con_Mu_"+outname+".txt"; //tfile1.open(textfile_Con); //tfile1 << "########################################" << endl; //tfile1 << "RCS:" << endl; std::cout << std::endl; int allEvents = int(inputEventsH->GetEntries()); std::cout << "Total number of input events = " << allEvents << std::endl; std::cout << "Total number of events in Tree = " << nEvents << std::endl; std::cout << "Total number of selected events = " << selEvents << std::endl; std::cout << std::endl; file->cd(SelectionSign.c_str()); hxsec->Fill(XSec); hxsec->Write(); inputEventsH->Write(); CutFlow->Write(); muonPtAllH->Write(); electronPtAllH->Write(); // histograms (dilepton selection) electronPtH->Write(); electronEtaH ->Write(); muonPtH ->Write(); muonEtaH ->Write(); dileptonMassH ->Write(); dileptonPtH ->Write(); dileptonEtaH ->Write(); dileptondRH ->Write(); ETmissH ->Write(); MtH ->Write(); DZetaH ->Write(); // histograms (dilepton selection + DZeta cut DZeta) electronPtSelH ->Write(); electronEtaSelH ->Write(); muonPtSelH ->Write(); muonEtaSelH ->Write(); dileptonMassSelH ->Write(); dileptonPtSelH ->Write(); dileptonEtaSelH ->Write(); dileptondRSelH ->Write(); ETmissSelH ->Write(); MtSelH ->Write(); DZetaSelH ->Write(); /* for(int cj = 0; cj < CutNumb; cj++) { file->cd(""); //outf->mkdir(CutList[cj]); //outf->cd(CutList[cj]); h0JetpT[cj]->Write(); hnJet[cj]->Write(); hnOver[cj]->Write(); hnBJet[cj]->Write(); hnEl[cj]->Write(); hElpt[cj]->Write(); hnMu[cj]->Write(); hMupt[cj]->Write(); hLepeta[cj]->Write(); hMET[cj]->Write(); hHT[cj]->Write(); hST[cj]->Write(); hToppT[cj]->Write(); hnTop[cj]->Write(); hWTagpT[cj]->Write(); hWTagMass[cj]->Write(); hnW[cj]->Write(); hWmassTagpT[cj]->Write(); hWmassTagMass[cj]->Write(); hnWmass[cj]->Write(); hdPhiMETLep[cj]->Write(); hdPhiJMET[cj]->Write(); } */ file->Write(); file->Close(); delete file; }
int main(int argc, char * argv[]) { // first argument - config file // second argument - filelist using namespace std; //const int CutNumb = 8; //string CutList[CutNumb]={"No cut","Trigger","1l","lept-Veto","b-Veto","MET $>$ 50","MET $>$ 100","dPhi $>$ 1"}; // **** configuration Config cfg(argv[1]); string SelectionSign="eltau"; // kinematic cuts on electrons const Float_t ptElectronLowCut = cfg.get<Float_t>("ptElectronLowCut"); const Float_t ptElectronHighCut = cfg.get<Float_t>("ptElectronHighCut"); const Float_t etaElectronCut = cfg.get<Float_t>("etaElectronCut"); const Float_t dxyElectronCut = cfg.get<Float_t>("dxyElectronCut"); const Float_t dzElectronCut = cfg.get<Float_t>("dzElectronCut"); const Float_t isoElectronLowCut = cfg.get<Float_t>("isoElectronLowCut"); const Float_t isoElectronHighCut = cfg.get<Float_t>("isoElectronHighCut"); const bool applyElectronId = cfg.get<bool>("ApplyElectronId"); // kinematic cuts on muons const Float_t ptMuonLowCut = cfg.get<Float_t>("ptMuonLowCut"); const Float_t ptMuonHighCut = cfg.get<Float_t>("ptMuonHighCut"); const Float_t etaMuonCut = cfg.get<Float_t>("etaMuonCut"); const Float_t dxyMuonCut = cfg.get<Float_t>("dxyMuonCut"); const Float_t dzMuonCut = cfg.get<Float_t>("dzMuonCut"); const Float_t isoMuonLowCut = cfg.get<Float_t>("isoMuonLowCut"); const Float_t isoMuonHighCut = cfg.get<Float_t>("isoMuonHighCut"); const bool applyMuonId = cfg.get<bool>("ApplyMuonId"); const string lowPtLegMuon = cfg.get<string>("LowPtLegMuon"); const string highPtLegMuon = cfg.get<string>("HighPtLegMuon"); const string El32Leg = cfg.get<string>("El32Leg"); const string El22Tau20ElLegA = cfg.get<string>("El22Tau20ElLegA"); const string El22Tau20ElLegB = cfg.get<string>("El22Tau20ElLegB"); const string El22Tau20TauLegA = cfg.get<string>("El22Tau20TauLegA"); const string El22Tau20TauLegB = cfg.get<string>("El22Tau20TauLegB"); const Float_t leadchargedhadrcand_dz = cfg.get<Float_t>("leadchargedhadrcand_dz"); const Float_t leadchargedhadrcand_dxy = cfg.get<Float_t>("leadchargedhadrcand_dxy"); // const float ndofVertexCut = cfg.get<float>("NdofVertexCut"); // const float zVertexCut = cfg.get<float>("ZVertexCut"); // const float dVertexCut = cfg.get<float>("DVertexCut"); // kinematic cuts on Jets const Float_t etaJetCut = cfg.get<Float_t>("etaJetCut"); const Float_t ptJetCut = cfg.get<Float_t>("ptJetCut"); // topological cuts const Float_t dRleptonsCuteltau = cfg.get<Float_t>("dRleptonsCuteltau"); const Float_t dZetaCut = cfg.get<Float_t>("dZetaCut"); const float deltaRTrigMatch = cfg.get<float>("DRTrigMatch"); const bool oppositeSign = cfg.get<bool>("oppositeSign"); const bool isIsoR03 = cfg.get<bool>("IsIsoR03"); // tau const Float_t taupt = cfg.get<Float_t>("taupt"); const Float_t taueta = cfg.get<Float_t>("taueta"); const Float_t decayModeFinding = cfg.get<Float_t>("decayModeFinding"); const Float_t decayModeFindingNewDMs = cfg.get<Float_t>("decayModeFindingNewDMs"); const Float_t againstElectronVLooseMVA5 = cfg.get<Float_t>("againstElectronVLooseMVA5"); const Float_t againstMuonTight3 = cfg.get<Float_t>("againstMuonTight3"); const Float_t vertexz = cfg.get<Float_t>("vertexz"); const Float_t byCombinedIsolationDeltaBetaCorrRaw3Hits = cfg.get<Float_t>("byCombinedIsolationDeltaBetaCorrRaw3Hits"); const unsigned int RunRangeMin = cfg.get<unsigned int>("RunRangeMin"); const unsigned int RunRangeMax = cfg.get<unsigned int>("RunRangeMax"); const string lowPtLegElectron = cfg.get<string>("LowPtLegElectron"); const string highPtLegElectron = cfg.get<string>("HighPtLegElectron"); TString LowPtLegElectron(lowPtLegElectron); TString HighPtLegElectron(highPtLegElectron); TString LowPtLegMuon(lowPtLegMuon); TString HighPtLegMuon(highPtLegMuon); TString Elecs24Leg(El32Leg); TString Elecs22Tau20ElLegA(El22Tau20ElLegA); TString Elecs22Tau20ElLegB(El22Tau20ElLegB); TString Elecs22Tau20TauLegA(El22Tau20TauLegA); TString Elecs22Tau20TauLegB(El22Tau20TauLegB); const Float_t Lumi = cfg.get<Float_t>("Lumi"); const Float_t bTag = cfg.get<Float_t>("bTag"); const Float_t metcut = cfg.get<Float_t>("metcut"); CutList.clear(); CutList.push_back("No cut"); CutList.push_back("$mu$"); CutList.push_back("$tau_h$"); CutList.push_back("$DeltaR>0.5$"); CutList.push_back("Trigger"); CutList.push_back("2nd lept-Veto"); CutList.push_back("3rd lept-Veto"); CutList.push_back("b-Veto "); CutList.push_back("ZMass cut "); CutList.push_back("MET $>$ 50"); CutList.push_back("MET $>$ 100"); CutList.push_back("dPhi > 1"); int CutNumb = int(CutList.size()); xs=1;fact=1;fact2=1; unsigned int RunMin = 9999999; unsigned int RunMax = 0; ifstream ifs("xsecs"); string line; while(std::getline(ifs, line)) // read one line from ifs { fact=fact2=1; istringstream iss(line); // access line as a stream // we only need the first two columns string dt; iss >> dt >> xs >> fact >> fact2; //ifs >> dt >> xs; // no need to read further //cout<< " "<<dt<<" "<<endl; //cout<< "For sample ========================"<<dt<<" xsecs is "<<xs<<" XSec "<<XSec<<" "<<fact<<" "<<fact2<<endl; //if (dt==argv[2]) { //if (std::string::npos != dt.find(argv[2])) { if ( dt == argv[2]) { XSec= xs*fact*fact2; cout<<" Found the correct cross section "<<xs<<" for Dataset "<<dt<<" XSec "<<XSec<<endl; } } if (XSec<0) {cout<<" Something probably wrong with the xsecs...please check - the input was "<<argv[2]<<endl;return 0;} std::vector<unsigned int> allRuns; allRuns.clear(); bool doThirdLeptVeto=true; bool doElVeto=true; //CutList[CutNumb]=CutListt[CutNumb]; char ff[100]; sprintf(ff,"%s/%s",argv[3],argv[2]); // file name and tree name std::string rootFileName(argv[2]); //std::ifstream fileList(argv[2]); std::ifstream fileList(ff); //std::ifstream fileList0(argv[2]); std::ifstream fileList0(ff); std::string ntupleName("makeroottree/AC1B"); TString era=argv[3]; TString TStrName(rootFileName); std::cout <<TStrName <<std::endl; // output fileName with histograms TFile * file = new TFile(era+"/"+TStrName+TString(".root"),"update"); file->mkdir(SelectionSign.c_str()); file->cd(SelectionSign.c_str()); int nFiles = 0; int nEvents = 0; int selEvents = 0; int nTotalFiles = 0; int iCut=0; double CFCounter[CutNumb]; double statUnc[CutNumb]; int iCFCounter[CutNumb]; for (int i=0;i < CutNumb; i++){ CFCounter[i] = 0; iCFCounter[i] = 0; statUnc[i] =0; } std::string dummy; // count number of files ---> while (fileList0 >> dummy) nTotalFiles++; SetupHists(CutNumb); // if (nTotalFiles>400) nTotalFiles=250; for (int iF=0; iF<nTotalFiles; ++iF) { std::string filen; fileList >> filen; std::cout << "file " << iF+1 << " out of " << nTotalFiles << " filename : " << filen << std::endl; TFile * file_ = TFile::Open(TString(filen)); TTree * _tree = NULL; _tree = (TTree*)file_->Get(TString(ntupleName)); if (_tree==NULL) continue; TH1D * histoInputEvents = NULL; histoInputEvents = (TH1D*)file_->Get("makeroottree/nEvents"); if (histoInputEvents==NULL) continue; int NE = int(histoInputEvents->GetEntries()); std::cout << " number of input events = " << NE << std::endl; //NE=1000; for (int iE=0;iE<NE;++iE) inputEventsH->Fill(0.); AC1B analysisTree(_tree); Long64_t numberOfEntries = analysisTree.GetEntries(); //numberOfEntries = 1000; std::cout << " number of entries in Tree = " << numberOfEntries << std::endl; //numberOfEntries = 10000; for (Long64_t iEntry=0; iEntry<numberOfEntries; iEntry++) { analysisTree.GetEntry(iEntry); nEvents++; iCut = 0; Float_t weight = 1; isData= false; bool lumi=false; if (XSec == 1) isData = true; if (!isData && XSec !=1 ) { histWeights->Fill(1,analysisTree.genweight); weight *= analysisTree.genweight; //weight *= histWeights2->GetBinContent(1); lumi=true; } if (nEvents%50000==0) cout << " processed " << nEvents << " events" << endl; if (isData){ if (analysisTree.event_run<RunRangeMin) continue; if (analysisTree.event_run>RunRangeMax) continue; if (analysisTree.event_run<RunMin) RunMin = analysisTree.event_run; if (analysisTree.event_run>RunMax) RunMax = analysisTree.event_run; //std::cout << " Run : " << analysisTree.event_run << std::endl; bool isNewRun = true; if (allRuns.size()>0) { for (unsigned int iR=0; iR<allRuns.size(); ++iR) { if (analysisTree.event_run==allRuns.at(iR)) { isNewRun = false; break; } } } if (isNewRun) allRuns.push_back(analysisTree.event_run); std::vector<Period> periods; std::fstream inputFileStream("temp", std::ios::in); for(std::string s; std::getline(inputFileStream, s); ) { periods.push_back(Period()); std::stringstream ss(s); ss >> periods.back(); } int n=analysisTree.event_run; int lum = analysisTree.event_luminosityblock; std::string num = std::to_string(n); std::string lnum = std::to_string(lum); for(const auto& a : periods) { if ( num.c_str() == a.name ) { //std::cout<< " Eureka "<<num<<" "<<a.name<<" "; // std::cout <<"min "<< last->lower << "- max last " << last->bigger << std::endl; for(auto b = a.ranges.begin(); b != std::prev(a.ranges.end()); ++b) { // cout<<b->lower<<" "<<b->bigger<<endl; if (lum >= b->lower && lum <= b->bigger ) lumi = true; } auto last = std::prev(a.ranges.end()); // std::cout <<"min "<< last->lower << "- max last " << last->bigger << std::endl; if ( (lum >=last->lower && lum <= last->bigger )) lumi=true; } } } if (!lumi) continue; JetsMV.clear(); ElMV.clear(); TauMV.clear(); MuMV.clear(); LeptMV.clear(); mu_index=-1; tau_index=-1; el_index=-1; Float_t MET = sqrt ( analysisTree.pfmet_ex*analysisTree.pfmet_ex + analysisTree.pfmet_ey*analysisTree.pfmet_ey); METV.SetPx(analysisTree.pfmet_ex); METV.SetPy(analysisTree.pfmet_ey); for (unsigned int ij = 0; ij<analysisTree.pfjet_count; ++ij) { JetsV.SetPxPyPzE(analysisTree.pfjet_px[ij], analysisTree.pfjet_py[ij], analysisTree.pfjet_pz[ij], analysisTree.pfjet_e[ij]); JetsMV.push_back(JetsV); } for (unsigned int im = 0; im<analysisTree.muon_count; ++im) { MuV.SetPtEtaPhiM(analysisTree.muon_pt[im], analysisTree.muon_eta[im], analysisTree.muon_phi[im], muonMass); MuMV.push_back(MuV); //mu_index=0; } for (unsigned int ie = 0; ie<analysisTree.electron_count; ++ie) { ElV.SetPtEtaPhiM(analysisTree.electron_pt[ie], analysisTree.electron_eta[ie], analysisTree.electron_phi[ie], electronMass); ElMV.push_back(ElV); //el_index=0; } for (unsigned int it = 0; it<analysisTree.tau_count; ++it) { TauV.SetPtEtaPhiM(analysisTree.tau_pt[it], analysisTree.tau_eta[it], analysisTree.tau_phi[it], tauMass); TauMV.push_back(TauV); //tau_index=0; } // vector <string> ss; ss.push_back(SelectionSign.c_str()); FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // hnJets[->Fill(pfjet_count); // std::cout << "Entry : " << iEntry << std::endl; // std::cout << "Number of gen particles = " << analysisTree.genparticles_count << std::endl; // std::cout << "Number of taus = " << analysisTree.tau_count << std::endl; // std::cout << "Number of jets = " << analysisTree.pfjet_count << std::endl; // std::cout << "Number of muons = " << analysisTree.muon_count << std::endl; // **** Analysis of generator info // int indexW = -1; // int indexNu = -1; // int indexMu = -1; // int indexE = -1; // int nGenMuons = 0; // int nGenElectrons = 0; // for (unsigned int igen=0; igen<analysisTree.genparticles_count; ++igen) { // Float_t pxGen = analysisTree.genparticles_px[igen]; // Float_t pyGen = analysisTree.genparticles_py[igen]; // Float_t pzGen = analysisTree.genparticles_pz[igen]; // Float_t etaGen = PtoEta(pxGen,pyGen,pzGen); // Float_t ptGen = PtoPt(pxGen,pyGen); // if (fabs(analysisTree.genparticles_pdgid[igen])==24 && analysisTree.genparticles_status[igen]==62) // indexW = igen; // if ((fabs(analysisTree.genparticles_pdgid[igen])==12 // ||fabs(analysisTree.genparticles_pdgid[igen])==14 // ||fabs(analysisTree.genparticles_pdgid[igen])==16) // && analysisTree.genparticles_info[igen]== (1<<1) ) // indexNu = igen; // if (fabs(analysisTree.genparticles_pdgid[igen])==13) { // if ( analysisTree.genparticles_info[igen]== (1<<1) ) { // indexMu = igen; // if (fabs(etaGen)<2.3 && ptGen>10.) // nGenMuons++; // } // } // if (fabs(analysisTree.genparticles_pdgid[igen])==11) { // if ( analysisTree.genparticles_info[igen]== (1<<1) ) { // indexE = igen; // if (fabs(etaGen)<2.3 && ptGen>10.) // nGenElectrons++; // } // } // } //selecTable.Fill(1,0, weight ); bool trigAccept = false; unsigned int nElecs24Leg = 0; bool isElecs24Leg = false; unsigned int nElecs22Tau20ElLegA = 0; bool isElecs22Tau20ElLegA = false; unsigned int nElecs22Tau20ElLegB = 0; bool isElecs22Tau20ElLegB = false; unsigned int nElecs22Tau20TauLegA = 0; bool isElecs22Tau20TauLegA = false; unsigned int nElecs22Tau20TauLegB = 0; bool isElecs22Tau20TauLegB = false; unsigned int nfilters = analysisTree.run_hltfilters->size(); // std::cout << "nfiltres = " << nfilters << std::endl; for (unsigned int i=0; i<nfilters; ++i) { // std::cout << "HLT Filter : " << i << " = " << analysisTree.run_hltfilters->at(i) << std::endl; TString HLTFilter(analysisTree.run_hltfilters->at(i)); if (HLTFilter==Elecs24Leg) { nElecs24Leg = i; isElecs24Leg = true; } if (HLTFilter==Elecs22Tau20ElLegA) { nElecs22Tau20ElLegA = i; isElecs22Tau20ElLegA = true; } if (HLTFilter==Elecs22Tau20ElLegB) { nElecs22Tau20ElLegB = i; isElecs22Tau20ElLegB = true; } if (HLTFilter==Elecs22Tau20ElLegB) { nElecs22Tau20ElLegB = i; isElecs22Tau20ElLegB = true; } if (HLTFilter==Elecs22Tau20TauLegA) { nElecs22Tau20TauLegA = i; isElecs22Tau20TauLegA = true; } if (HLTFilter==Elecs22Tau20TauLegB) { nElecs22Tau20TauLegB = i; isElecs22Tau20TauLegB = true; } } if (!isElecs24Leg) { std::cout << "HLT filter " << Elecs24Leg << " not found" << std::endl; return(-1); } if (!isElecs22Tau20ElLegA) { std::cout << "HLT filter " << Elecs22Tau20ElLegA << " not found" << std::endl; return(-1); } if (!isElecs22Tau20ElLegB) { std::cout << "HLT filter " << Elecs22Tau20ElLegB << " not found" << std::endl; return(-1); } if (!isElecs22Tau20TauLegA) { std::cout << "HLT filter " << Elecs22Tau20TauLegA << " not found" << std::endl; return(-1); } if (!isElecs22Tau20TauLegB) { std::cout << "HLT filter " << Elecs22Tau20TauLegB << " not found" << std::endl; return(-1); } /* std::cout << "LowPtE : " << LowPtLegElectron << " : " << nLowPtLegElectron << std::endl; std::cout << "HighPtE : " << HighPtLegElectron << " : " << nHighPtLegElectron << std::endl; std::cout << "LowPtM : " << LowPtLegMuon << " : " << nLowPtLegMuon << std::endl; std::cout << "HighPtM : " << HighPtLegMuon << " : " << nHighPtLegMuon << std::endl; std::cout << std::endl; // continue; // vertex cuts if (fabs(analysisTree.primvertex_z)>zVertexCut) continue; if (analysisTree.primvertex_ndof<ndofVertexCut) continue; float dVertex = (analysisTree.primvertex_x*analysisTree.primvertex_x+ analysisTree.primvertex_y*analysisTree.primvertex_y); if (dVertex>dVertexCut) continue; */ /////now clear the Mu.El.Jets again to fill them again after cleaning /* MuMV.clear(); ElMV.clear(); TauMV.clear(); */ float isoElMin = 9999; bool el_iso=false; vector<int> electrons; electrons.clear(); for (unsigned int ie = 0; ie<analysisTree.electron_count; ++ie) { electronPtAllH->Fill(analysisTree.electron_pt[ie],weight); if (analysisTree.electron_pt[ie]<ptElectronHighCut) continue; if (fabs(analysisTree.electron_eta[ie])>etaElectronCut) continue; if (fabs(analysisTree.electron_dxy[ie])>dxyElectronCut) continue; if (fabs(analysisTree.electron_dz[ie])>dzElectronCut) continue; Float_t neutralIso = analysisTree.electron_neutralHadIso[ie] + analysisTree.electron_photonIso[ie] - 0.5*analysisTree.electron_puIso[ie]; neutralIso = TMath::Max(Float_t(0),neutralIso); Float_t absIso = analysisTree.electron_chargedHadIso[ie] + neutralIso; Float_t relIso = absIso/analysisTree.electron_pt[ie]; hel_relISO[1]->Fill(relIso,weight); if (relIso>isoElectronHighCut) continue; if (relIso<isoElectronLowCut) continue; bool electronMvaId = electronMvaIdTight(analysisTree.electron_superclusterEta[ie], analysisTree.electron_mva_id_nontrigPhys14[ie]); if (!electronMvaId&&applyElectronId) continue; if (relIso<isoElMin) { isoElMin = relIso; el_index = ie; el_iso=true; electrons.push_back(ie); ElV.SetPtEtaPhiM(analysisTree.electron_pt[ie], analysisTree.electron_eta[ie], analysisTree.electron_phi[ie], electronMass); LeptMV.push_back(ElV); // ElMV.push_back(ElV); //cout<<" RelIso " <<relIso <<" "<<el_index<<endl; } if (relIso!=0 && relIso==isoElMin && ie != el_index) { analysisTree.electron_pt[ie] > analysisTree.electron_pt[el_index] ? el_index = ie : el_index = el_index; cout<<" found a pair " <<relIso <<" "<<el_index<<" "<<ie<<endl; } } if (electrons.size()==0 || !el_iso) continue; sort(LeptMV.begin(), LeptMV.end(),ComparePt); if (LeptMV.size() == 0 ) continue; // el_index=electrons[0]; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; float isoTauMin = 999; bool tau_iso = false; vector<int> tau; tau.clear(); for (unsigned int it = 0; it<analysisTree.tau_count; ++it) { tauPtAllH->Fill(analysisTree.tau_pt[it],weight); tauEtaAllH->Fill(analysisTree.tau_eta[it],weight); if (analysisTree.tau_pt[it] < 20 || fabs(analysisTree.tau_eta[it])> 2.3) continue; if (analysisTree.tau_decayModeFinding[it]<decayModeFinding && analysisTree.tau_decayModeFindingNewDMs[it]<decayModeFindingNewDMs) continue; if (analysisTree.tau_decayModeFindingNewDMs[it]<decayModeFindingNewDMs) continue; if ( fabs(analysisTree.tau_leadchargedhadrcand_dz[it])> leadchargedhadrcand_dz) continue; if (analysisTree.tau_againstElectronVLooseMVA5[it]<againstElectronVLooseMVA5) continue; if (analysisTree.tau_againstMuonTight3[it]<againstMuonTight3) continue; //phys14 if ( fabs(analysisTree.tau_vertexz[it] - analysisTree.primvertex_z ) > vertexz ) continue; if (analysisTree.tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[it] > byCombinedIsolationDeltaBetaCorrRaw3Hits ) continue; Float_t tauIso = analysisTree.tau_byCombinedIsolationDeltaBetaCorrRaw3Hits[it]; if (tauIso<isoTauMin ) { // cout<<" there was a chenge "<<tauIso<<" "<<isoTauMin<<" it "<<it<<" tau_index "<<tau_index<<" "<<analysisTree.tau_count<<endl; isoTauMin = tauIso; tau_iso=true; // it > 0 ? tau_index= it -1: tau_index = it; tau.push_back(it); TauV.SetPtEtaPhiM(analysisTree.tau_pt[it], analysisTree.tau_eta[it], analysisTree.tau_phi[it], tauMass); //TauMV.push_back(TauV); } if (tauIso!=0 && tauIso==isoTauMin && it != tau_index) { analysisTree.tau_pt[it] > analysisTree.tau_pt[tau_index] ? tau_index = it : tau_index = tau_index; cout<<" found a pair " <<tauIso <<" "<<tau_index<<" "<<it<<endl; } } if (tau.size()==0 || !tau_iso) continue; //cout<<" tau, elects " <<tau_index<<" "<<el_index<<" "<<endl; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; float dR = deltaR(analysisTree.tau_eta[tau_index],analysisTree.tau_phi[tau_index], analysisTree.electron_eta[el_index],analysisTree.electron_phi[el_index]); if (dR<dRleptonsCuteltau) continue; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; bool isEl32 = false; bool isEl22Tau20ElLegA = false; bool isEl22Tau20ElLegB = false; bool isEl22Tau20TauLegA = false; bool isEl22Tau20TauLegB = false; for (unsigned int ie=0; ie<electrons.size(); ++ie) { isEl32 = false; isEl22Tau20ElLegA = false; isEl22Tau20ElLegB = false; unsigned int eIndex = electrons.at(ie); /* float neutralHadIsoMu = analysisTree.muon_neutralHadIso[mIndex]; float photonIsoMu = analysisTree.muon_photonIso[mIndex]; float chargedHadIsoMu = analysisTree.muon_chargedHadIso[mIndex]; float puIsoMu = analysisTree.muon_puIso[mIndex]; if (isIsoR03) { neutralHadIsoMu = analysisTree.muon_r03_sumNeutralHadronEt[mIndex]; photonIsoMu = analysisTree.muon_r03_sumPhotonEt[mIndex]; chargedHadIsoMu = analysisTree.muon_r03_sumChargedHadronPt[mIndex]; puIsoMu = analysisTree.muon_r03_sumPUPt[mIndex]; } float neutralIsoMu = neutralHadIsoMu + photonIsoMu - 0.5*puIsoMu; neutralIsoMu = TMath::Max(float(0),neutralIsoMu); float absIsoMu = chargedHadIsoMu + neutralIsoMu; float relIsoMu = absIsoMu/analysisTree.muon_pt[mIndex]; */ for (unsigned int iT=0; iT<analysisTree.trigobject_count; ++iT) { if (analysisTree.trigobject_filters[iT][nElecs24Leg]) { float dRtrig = deltaR(analysisTree.electron_eta[eIndex],analysisTree.electron_phi[eIndex], analysisTree.trigobject_eta[iT],analysisTree.trigobject_phi[iT]); if (dRtrig<deltaRTrigMatch) { isEl32 = true; } } if (analysisTree.trigobject_filters[iT][nElecs22Tau20ElLegA]) { float dRtrig = deltaR(analysisTree.electron_eta[eIndex],analysisTree.electron_phi[eIndex], analysisTree.trigobject_eta[iT],analysisTree.trigobject_phi[iT]); if (dRtrig<deltaRTrigMatch) { isEl22Tau20ElLegA = true; } } if (analysisTree.trigobject_filters[iT][nElecs22Tau20ElLegB ]) { float dRtrig = deltaR(analysisTree.electron_eta[eIndex],analysisTree.electron_phi[eIndex], analysisTree.trigobject_eta[iT],analysisTree.trigobject_phi[iT]); if (dRtrig<deltaRTrigMatch) { isEl22Tau20ElLegB = true; } } } if ( (!isEl32) && (!isEl22Tau20ElLegA || !isEl22Tau20ElLegB) ) continue; for (unsigned int it=0; it<tau.size(); ++it) { isEl22Tau20TauLegA = false; isEl22Tau20TauLegB = false; unsigned int tIndex = tau.at(it); for (unsigned int iT=0; iT<analysisTree.trigobject_count; ++iT) { if (analysisTree.trigobject_filters[iT][nElecs22Tau20TauLegA]) { float dRtrig = deltaR(analysisTree.tau_eta[tIndex],analysisTree.tau_phi[tIndex], analysisTree.trigobject_eta[iT],analysisTree.trigobject_phi[iT]); if (dRtrig<deltaRTrigMatch) { isEl22Tau20TauLegA = true; } } if (analysisTree.trigobject_filters[iT][nElecs22Tau20TauLegB]) { float dRtrig = deltaR(analysisTree.tau_eta[tIndex],analysisTree.tau_phi[tIndex], analysisTree.trigobject_eta[iT],analysisTree.trigobject_phi[iT]); if (dRtrig<deltaRTrigMatch) { isEl22Tau20TauLegB = true; } } } } if ( isEl32 || ( ( isEl22Tau20ElLegA && isEl22Tau20ElLegB) && ( isEl22Tau20TauLegA && isEl22Tau20TauLegB) )) trigAccept=true; }//electrons if (!trigAccept) continue; //Trigger //FillMainHists(iCut, weight, ElMV, MuMV, JetsMV,METV,analysisTree, SelectionSign); FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // electron selection bool ElVeto=false; if (doElVeto){ for (unsigned int ievv = 0; ievv<analysisTree.electron_count; ++ievv) { if ( ievv != el_index ){ // Float_t neutralIsoV = analysisTree.electron_r03_sumNeutralHadronEt[iev] + analysisTree.electron_r03_sumNeutralHadronEt[iev] + analysisTree.electron_r03_sumPhotonEt[iev] - 4*TMath::Pi()*(0.3*0.3)*analysisTree.rho[iev]; // Float_t IsoWithEA = analysisTree.electron_r03_sumChargedHadronPt[iev] + TMath::Max(Float_t(0), neutralIsoV); // Float_t relIsoV = IsoWithEA/analysisTree.electron_pt[iev]; Float_t neutralIso = analysisTree.electron_neutralHadIso[ievv] + analysisTree.electron_photonIso[ievv] - 0.5*analysisTree.electron_puIso[ievv]; neutralIso = TMath::Max(Float_t(0),neutralIso); Float_t absIso = analysisTree.electron_chargedHadIso[ievv] + neutralIso; Float_t relIsoV = absIso/analysisTree.electron_pt[ievv]; hel_relISO[1]->Fill(relIsoV,weight); if (relIsoV>isoElectronHighCut) continue; if (relIsoV<isoElectronLowCut) continue; bool ElVetoID = electronVetoTight(analysisTree.electron_superclusterEta[ievv], analysisTree.electron_eta[ievv],analysisTree.electron_phi[ievv], analysisTree.electron_full5x5_sigmaietaieta[ievv], analysisTree.electron_ehcaloverecal[ievv], analysisTree.electron_dxy[ievv], analysisTree.electron_dz[ievv], analysisTree.electron_ooemoop[ievv], relIsoV,analysisTree.electron_nmissinginnerhits[ievv],analysisTree.electron_pass_conversion[ievv]); if ( analysisTree.electron_charge[ievv] != analysisTree.electron_charge[electrons[0]] && analysisTree.electron_pt[ievv] > 15 && fabs(analysisTree.electron_eta[ievv]) < 2.5 && fabs(analysisTree.electron_dxy[ievv])<0.045 && fabs(analysisTree.electron_dz[ievv]) < 0.2 && relIsoV< 0.3 && ElVetoID) ElVeto=true; } } } if (ElVeto) continue; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; bool ThirdLeptVeto=false; if (doThirdLeptVeto){ if (analysisTree.electron_count>0) { for (unsigned int iev = 0; iev<analysisTree.electron_count; ++iev) { if (iev !=el_index) { // Float_t neutralIsoV = analysisTree.electron_r03_sumNeutralHadronEt[iev] + analysisTree.electron_r03_sumNeutralHadronEt[iev] + analysisTree.electron_r03_sumPhotonEt[iev] - 4*TMath::Pi()*(0.3*0.3)*analysisTree.rho[iev]; // Float_t IsoWithEA = analysisTree.electron_r03_sumChargedHadronPt[iev] + TMath::Max(Float_t(0), neutralIsoV); // Float_t relIsoV = IsoWithEA/analysisTree.electron_pt[iev]; Float_t neutralIso = analysisTree.electron_neutralHadIso[iev] + analysisTree.electron_photonIso[iev] - 0.5*analysisTree.electron_puIso[iev]; neutralIso = TMath::Max(Float_t(0),neutralIso); Float_t absIso = analysisTree.electron_chargedHadIso[iev] + neutralIso; Float_t relIsoV = absIso/analysisTree.electron_pt[iev]; hel_relISO[1]->Fill(relIsoV,weight); if (relIsoV>isoElectronHighCut) continue; if (relIsoV<isoElectronLowCut) continue; bool ElVetoID = electronVetoTight(analysisTree.electron_superclusterEta[iev], analysisTree.electron_eta[iev],analysisTree.electron_phi[iev], analysisTree.electron_full5x5_sigmaietaieta[iev], analysisTree.electron_ehcaloverecal[iev], analysisTree.electron_dxy[iev], analysisTree.electron_dz[iev], analysisTree.electron_ooemoop[iev], relIsoV,analysisTree.electron_nmissinginnerhits[iev],analysisTree.electron_pass_conversion[iev]); if ( analysisTree.electron_pt[iev] > 10 && fabs(analysisTree.electron_eta[iev]) < 2.5 && fabs(analysisTree.electron_dxy[iev])<0.045 && fabs(analysisTree.electron_dz[iev]) < 0.2 && relIsoV< 0.3 && ElVetoID) ThirdLeptVeto=true; } } } if (analysisTree.muon_count>0){ for (unsigned int imvv = 0; imvv<analysisTree.muon_count; ++imvv) { Float_t neutralIso = analysisTree.muon_neutralHadIso[imvv] + analysisTree.muon_photonIso[imvv] - 0.5*analysisTree.muon_puIso[imvv]; neutralIso = TMath::Max(Float_t(0),neutralIso); Float_t absIso = analysisTree.muon_chargedHadIso[imvv] + neutralIso; Float_t relIso = absIso/analysisTree.muon_pt[imvv]; if ( analysisTree.muon_isMedium[imvv] && analysisTree.muon_pt[imvv]> 10 && fabs(analysisTree.muon_eta[imvv])< 2.4 && fabs(analysisTree.muon_dxy[imvv])<0.045 && fabs(analysisTree.muon_dz[imvv] < 0.2 && relIso< 0.3 && analysisTree.muon_isMedium[imvv]) ) ThirdLeptVeto=true; } } } if (ThirdLeptVeto) continue; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // for (unsigned int j=0;j<LeptMV.size();++j) cout<<" j "<<j<<" "<<LeptMV.at(j).Pt()<<endl; // cout<<""<<endl; ////////jets cleaning Float_t DRmax=0.4; vector<int> jets; jets.clear(); TLorentzVector leptonsV, muonJ, jetsLV; // continue; //JetsV.SetPxPyPzE(analysisTree.pfjet_px[ij], analysisTree.pfjet_py[ij], analysisTree.pfjet_pz[ij], analysisTree.pfjet_e[ij]); for (unsigned int il = 0; il<LeptMV.size(); ++il) { for (unsigned int ij = 0; ij<JetsMV.size(); ++ij) { if(fabs(JetsMV.at(ij).Eta())>etaJetCut) continue; if(fabs(JetsMV.at(ij).Pt())<ptJetCut) continue; Float_t Dr= deltaR(LeptMV.at(il).Eta(), LeptMV.at(il).Phi(),JetsMV.at(ij).Eta(),JetsMV.at(ij).Phi()); if ( Dr < DRmax) { JetsMV.erase (JetsMV.begin()+ij); } } } // selecting muon and electron pair (OS or SS); Float_t ptScalarSum = -1; bool btagged= false; bool JetsPt30C =false; if (JetsMV.size() >3) continue; int xj = -1; for (unsigned int ib = 0; ib <JetsMV.size();++ib){ if (JetsMV.at(ib).Pt()>30) JetsPt30C = true; for (unsigned int il = 0; il < analysisTree.pfjet_count; ++il) { if (float(JetsMV.at(ib).Pt()) == float(analysisTree.pfjet_pt[il])) {xj=il; //cout<<" found Jets "<<analysisTree.pfjet_pt[il]<<" "<<JetsMV.at(ib).Pt()<<" "<<ib<<" "<<xj<<" "<<il<<endl; } } // cout<<" Jets "<<analysisTree.pfjet_pt[xj]<<" "<<JetsMV.at(ib).Pt()<<" "<<ib<<" "<<xj<<endl; if (analysisTree.pfjet_btag[xj][8] > bTag) btagged = true; } if (JetsPt30C || btagged || JetsMV.size() >3) continue; // Jets FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign, mu_index,el_index,tau_index); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // pt Scalar // computations of kinematic variables //cout<<" "<<mu_index<<" "<<tau_index<<" "<<MuMV.at(mu_index).M()<<" "<<TauMV.at(tau_index).M()<<endl; TLorentzVector diL = MuMV.at(el_index) + TauMV.at(tau_index); if ( diL.M() <80 && diL.M()>40 ) continue; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign, mu_index,el_index,tau_index); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; Float_t ETmiss = TMath::Sqrt(analysisTree.pfmet_ex*analysisTree.pfmet_ex + analysisTree.pfmet_ey*analysisTree.pfmet_ey); // bisector of electron and muon transverse momenta // computation of MT variable Float_t dPhi=-999; dPhi=dPhiFrom2P( LeptMV.at(0).Px(), LeptMV.at(0).Py(), analysisTree.pfmet_ex, analysisTree.pfmet_ey ); //MT = TMath::Sqrt(2*LeptMV.at(0).Pt()*ETmiss*(1-TMath::Cos(dPhi))); // filling histograms after dilepton selection // ETmissH->Fill(ETmiss,weight); // MtH->Fill(MT,weight); if (ETmiss < metcut) continue; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; if (ETmiss < 2*metcut) continue; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // topological cut //if (DZeta<dZetaCut) continue; if (dPhi>1) continue; FillMainHists(iCut, weight, ElMV, MuMV, TauMV,JetsMV,METV, analysisTree, SelectionSign); CFCounter[iCut]+= weight; iCFCounter[iCut]++; iCut++; // std::cout << std::endl; selEvents++; } // end of file processing (loop over events in one file) nFiles++; delete _tree; file_->Close(); delete file_; } cout<< " " <<histWeights->GetSumOfWeights()<<" "<<inputEventsH->GetSum()<<endl; for (int i=0;i<CutNumb;++i){ CFCounter[i] *= Float_t(XSec*Lumi/( histWeights->GetSumOfWeights())); if (iCFCounter[i] <0.2) statUnc[i] =0; else statUnc[i] = CFCounter[i]/sqrt(iCFCounter[i]); } //write out cutflow ofstream tfile; // TString outname = argv[argc-1]; TString outname=argv[2]; TString textfilename = "cutflow_"+outname+"_"+SelectionSign+"_"+argv[3]+".txt"; tfile.open(textfilename); tfile << "########################################" << endl; //tfile << "Cut efficiency numbers:" << endl; // tfile << " Cut "<<"\t & \t"<<"#Evnts for "<<Lumi/1000<<" fb-1 & \t"<<" Uncertainty \t"<<" cnt\t"<<endl; for(int ci = 0; ci < CutNumb; ci++) { tfile << CutList[ci]<<"\t & \t" << CFCounter[ci] <<"\t & \t"<< statUnc[ci] <<"\t & \t"<< iCFCounter[ci] << endl; CutFlow->SetBinContent(1+ci,iCFCounter[ci]); } tfile.close(); //ofstream tfile1; //TString textfile_Con = "CMG_cutflow_Con_Mu_"+outname+".txt"; //tfile1.open(textfile_Con); //tfile1 << "########################################" << endl; //tfile1 << "RCS:" << endl; std::cout << std::endl; int allEvents = int(inputEventsH->GetEntries()); std::cout << "Total number of input events = " << allEvents << std::endl; std::cout << "Total number of events in Tree = " << nEvents << std::endl; std::cout << "Total number of selected events = " << selEvents << std::endl; std::cout << std::endl; file->cd(SelectionSign.c_str()); hxsec->Fill(XSec); hxsec->Write(); inputEventsH->Write(); histWeights->Write(); CutFlow->Write(); /* muonPtAllH->Write(); electronPtAllH->Write(); // histograms (dilepton selection) electronPtH->Write(); electronEtaH ->Write(); muonPtH ->Write(); muonEtaH ->Write(); dileptonMassH ->Write(); dileptonPtH ->Write(); dileptonEtaH ->Write(); dileptondRH ->Write(); ETmissH ->Write(); MtH ->Write(); DZetaH ->Write(); // histograms (dilepton selection + DZeta cut DZeta) electronPtSelH ->Write(); electronEtaSelH ->Write(); muonPtSelH ->Write(); muonEtaSelH ->Write(); dileptonMassSelH ->Write(); dileptonPtSelH ->Write(); dileptonEtaSelH ->Write(); dileptondRSelH ->Write(); ETmissSelH ->Write(); MtSelH ->Write(); */ DZetaSelH ->Write(); /* for(int cj = 0; cj < CutNumb; cj++) { file->cd(""); //outf->mkdir(CutList[cj]); //outf->cd(CutList[cj]); h0JetpT[cj]->Write(); hnJet[cj]->Write(); hnOver[cj]->Write(); hnBJet[cj]->Write(); hnEl[cj]->Write(); hElpt[cj]->Write(); hnMu[cj]->Write(); hMupt[cj]->Write(); hLepeta[cj]->Write(); hMET[cj]->Write(); hHT[cj]->Write(); hST[cj]->Write(); hToppT[cj]->Write(); hnTop[cj]->Write(); hWTagpT[cj]->Write(); hWTagMass[cj]->Write(); hnW[cj]->Write(); hWmassTagpT[cj]->Write(); hWmassTagMass[cj]->Write(); hnWmass[cj]->Write(); hdPhiMETLep[cj]->Write(); hdPhiJMET[cj]->Write(); } */ file->Write(); file->Close(); delete file; }
void addn2() { // open existing f1: char* fn[99]; int ni; // SR90 maps, mod D003 ni = -1; ni++; fn[ni] = "SR90-map-00a.root"; ni++; fn[ni] = "SR90-map-00b.root"; ni++; fn[ni] = "SR90-map-01a.root"; ni++; fn[ni] = "SR90-map-01b.root"; ni++; fn[ni] = "SR90-map-02.root"; ni++; fn[ni] = "SR90-map-03.root"; ni++; fn[ni] = "SR90-map-05a.root"; ni++; fn[ni] = "SR90-map-05b.root"; ni++; fn[ni] = "SR90-map-07a.root"; ni++; fn[ni] = "SR90-map-07b.root"; ni++; fn[ni] = "SR90-map-07c.root"; ni++; fn[ni] = "SR90-map-07d.root"; // direct X-rays 9.4.2014 module D0003 ni = -1; ni++; fn[ni] = "X-ray-20-modtd40000.root"; ni++; fn[ni] = "X-ray-20-vthr60-modtd1000.root"; ni++; fn[ni] = "X-ray-27-vthr60-modtd1000.root"; ni++; fn[ni] = "X-ray-35-modtd40000.root"; ni++; fn[ni] = "X-ray-35-vthr60-close-modtd65000.root"; ni++; fn[ni] = "X-ray-35-vthr60-midpos-0p1mA-modtd10000.root"; ni++; fn[ni] = "X-ray-35-vthr60-midpos-halfcur-modtd40000.root"; ni++; fn[ni] = "X-ray-35-vthr60-modtd40000.root"; int nmax = ni; TFile f1(fn[0]); if( f1.IsZombie() ) { cout << "Error opening " << fn[0] << endl; return; } cout << "opened " << fn[0] << endl; //-------------------------------------------------------------------- // create f0: TFile f0("fileA.root", "RECREATE"); cout << "created "; gDirectory->pwd(); /* TFile options: NEW or CREATE create a new file and open it for writing, if the file already exists the file is not opened. RECREATE create a new file, if the file already exists it will be overwritten. UPDATE open an existing file for writing. if no file exists, it is created. READ open an existing file for reading (default). NET used by derived remote file access classes, not a user callable option WEB used by derived remote http access class, not a user callable option "" (default), READ is assumed. */ //-------------------------------------------------------------------- // copy f1 to f0: f1.cd(); cout << "keys:\n"; f1.GetListOfKeys()->Print(); cout << "pwd: "; f1.pwd(); cout << "ls: \n"; f1.ls(); // f1 has sub-dir: cout << "First: " << f1.GetListOfKeys()->First()->GetName() << endl; cout << "First: " << f1.GetListOfKeys()->First()->ClassName() << endl; char* dir1 = f1.GetListOfKeys()->First()->GetName(); cout << "cd to " << dir1 << endl; f1.cd( dir1 ); cout << "we are in "; gDirectory->pwd(); gDirectory->ReadAll(); // load histos TList * lst = gDirectory->GetList(); cout << lst->GetName() << endl; cout << lst->GetTitle() << endl; cout << "size " << lst->GetSize() << endl; cout << "entries " << lst->GetEntries() << endl; cout << "last " << lst->LastIndex() << endl; TIterator *iter = lst->MakeIterator(); int ii = 0; TObject *obj; TH1D *h; TH1D *h0; TH2D *H; TH2D *H0; while( obj = iter->Next() ){ ii++; cout << setw(4) << ii << ": "; cout << obj->ClassName() << " "; cout << obj->InheritsFrom("TH1D") << " "; cout << obj->GetName() << " \""; cout << obj->GetTitle() << "\""; cout << endl; // if( obj->ClassName() == "TH1D" ){ if( obj->InheritsFrom("TH1D") ){ h = (TH1D*) obj; cout << " 1D"; cout << h->GetNbinsX() << " bins, "; cout << h->GetEntries() << " entries, "; cout << h->GetSumOfWeights() << " inside, "; cout << h->GetBinContent(0) << " under, "; cout << h->GetBinContent(h->GetNbinsX()+1) << " over"; cout << endl; f0.cd(); // output file // TH1D* h0 = (TH1D*) h->Clone(); h0 = h; // copy h0->Write(); // write to file f0 f1.cd(); // back to file 1 for the loop } else{ if( obj->InheritsFrom("TH2D") ){ H = (TH2D*) obj; cout << " 2D"; cout << H->GetNbinsX() << " bins, "; cout << H->GetEntries() << " entries, "; cout << H->GetSumOfWeights() << " inside, "; cout << H->GetBinContent(0) << " under, "; cout << H->GetBinContent(H->GetNbinsX()+1) << " over"; cout << endl; f0.cd(); // output file H0 = H; // copy H0->Write(); // write to file f0 f1.cd(); // back to file 1 for the loop } else cout << "other class " << obj->ClassName() << endl; } } cout << "copied " << ii << endl; cout << "f1 " << f1.GetName() << " close = " << f1.Close() << endl; f0.cd(); cout << "we are in "; gDirectory->pwd(); cout << "f0 " << f0.GetName() << " size = " << f0.GetSize() << endl; cout << "f0 " << f0.GetName() << " write = " << f0.Write() << endl; cout << "f0 " << f0.GetName() << " size = " << f0.GetSize() << endl; cout << "f0 " << f0.GetName() << " close = " << f0.Close() << endl; f0.Delete(); //-------------------------------------------------------------------- // list of files 2: bool lAB = true; for( int nn = 1; nn <= nmax; ++nn ){ cout << "\n\n"; cout << "loop " << nn << ": fn = " << fn[nn] << endl; cout << "lAB = " << lAB << endl; if( lAB ) { // A+2 -> B char* fn3 = "fileA.root"; char* fn4 = "fileB.root"; } else{ // B+2 -> A char* fn3 = "fileB.root"; char* fn4 = "fileA.root"; } // create f4: TFile f4( fn4, "recreate" ); if( f4.IsZombie() ) { cout << "Error creating f4\n"; return; } cout << "created f4 = " << f4.GetName() << endl; // re-open as f3: TFile f3( fn3 ); if( f3.IsZombie() ) { cout << "Error opening f3\n"; return; } cout << "re-opened f3 = " << f3.GetName() << endl; lAB = !lAB; cout << "lAB = " << lAB << " for next loop\n"; cout << "f4 = " << f4.GetName() << endl; cout << "f3 = " << f3.GetName() << endl; f3.cd(); gDirectory->ReadAll(); // load histos into f3 memory // cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl; cout << "f3 list size = " << gDirectory->GetList()->GetSize() << endl; TFile f2(fn[nn]); // TFile *f2 = new TFile(fn[nn]); if( f2.IsZombie() ) { // if( f2 == NULL ) { cout << "Error opening " << fn[nn] << endl; return; } cout << "opened " << fn[nn] << endl; // f2 has sub-dir: f2.cd( f2.GetListOfKeys()->First()->GetName() ); cout << "we are in "; gDirectory->pwd(); gDirectory->ReadAll(); // load histos into f2 memory // loop over f2: cout << "f2 list size = " << gDirectory->GetList()->GetSize() << endl; int jj = 0; TObject *ob2; TH1D *h2; TH1D *h3; TH2D *H2; TH2D *H3; TIterator *ite2 = gDirectory->GetList()->MakeIterator(); while( ob2 = ite2->Next() ){ jj++; // if( jj > 9 ) continue; cout << jj << ". "; cout << "ob2 is "; cout << ob2->GetName() << " "; cout << ob2->ClassName() << " "; cout << ob2->GetTitle(); cout << endl; if( ob2->InheritsFrom("TH1D") ) { h2 = (TH1D*) ob2; cout << "h2 " << h2->GetName() << " " << h2->GetNbinsX() << " bins\n"; cout << "h2 " << h2->GetName() << " " << h2->GetEntries() << " entries\n"; char* hnm2 = h2->GetName(); // search in f3: cout << "search for " << hnm2 << " in f3\n"; f3.cd(); cout << "we are in "; gDirectory->pwd(); h3 = (TH1D*) gDirectory->GetList()->FindObject(hnm2); if( h3 == NULL ) { cout << "h3 is null\n" ; continue; } cout << "found h3 = "; cout << h3->GetName() << " "; cout << h3->ClassName() << " "; cout << h3->GetTitle(); cout << endl; cout << "h3 " << h3->GetName() << " " << h3->GetNbinsX() << " bins\n"; cout << "h3 " << h3->GetName() << " " << h3->GetEntries() << " entries\n"; // add: f4.cd(); cout << "we are in "; gDirectory->pwd(); //TH1D h4 = *h3 + *h2; TH1D* h4 = (TH1D*) h3->Clone(); h4->Add(h2); cout << "h4 " << h4->GetEntries() << " entries\n"; cout << "h4 "; cout << h4->GetName() << " "; cout << h4->ClassName() << " "; cout << h4->GetTitle(); cout << endl; cout << "h4 dir " << h4->GetDirectory()->GetName() << endl; cout << "f4 size " << f4.GetSize() << endl; // back to f2 for next iter: f2.cd( f2.GetListOfKeys()->First()->GetName() ); }//1D if( ob2->InheritsFrom("TH2D") ) { H2 = (TH2D*) ob2; cout << "H2 " << H2->GetName() << " " << H2->GetNbinsX() << " bins\n"; cout << "H2 " << H2->GetName() << " " << H2->GetEntries() << " entries\n"; char* Hnm2 = H2->GetName(); // search in f3: cout << "search for " << Hnm2 << " in f3\n"; f3.cd(); cout << "we are in "; gDirectory->pwd(); H3 = (TH2D*) gDirectory->GetList()->FindObject(Hnm2); if( H3 == NULL ) { cout << "H3 is null\n" ; continue; } cout << "found H3 = "; cout << H3->GetName() << " "; cout << H3->ClassName() << " "; cout << H3->GetTitle(); cout << endl; cout << "H3 " << H3->GetName() << " " << H3->GetNbinsX() << " bins\n"; cout << "H3 " << H3->GetName() << " " << H3->GetEntries() << " entries\n"; // add: f4.cd(); cout << "we are in "; gDirectory->pwd(); TH2D* H4 = (TH2D*) H3->Clone(); H4->Add(H2); cout << "H4 " << H4->GetEntries() << " entries\n"; cout << "H4 "; cout << H4->GetName() << " "; cout << H4->ClassName() << " "; cout << H4->GetTitle(); cout << endl; cout << "H4 dir " << H4->GetDirectory()->GetName() << endl; cout << "f4 size " << f4.GetSize() << endl; // back to f2 for next iter: f2.cd( f2.GetListOfKeys()->First()->GetName() ); }//2D } //while cout << "processed " << jj << endl; cout << "f4 " << f4.GetName() << " size " << f4.GetSize() << endl; // cout << "f4 map:\n"; // f4.Map(); cout << "f4 " << f4.GetName() << " write = " << f4.Write() << endl; cout << "f4 " << f4.GetName() << " size = " << f4.GetSize() << endl; }// loop over files 2 cout << endl; cout << "combined " << nmax + 1 << " files\n"; cout << "Final file is " << f4.GetName() << endl; f2.Close(); f3.Close(); f4.Close(); }