void write() { met_->Write(); mt2_->Write(); nt_->Write(); nb_->Write(); baseline_met_->Write(); baseline_mt2_->Write(); baseline_nt_->Write(); baseline_nb_->Write(); baseline_nSearchBin_->Write(); }
// If two histograms from two files are to be ploted onto // the same plot. Open the first, and make a copy of the // histogram and place it in the 2nd file. Then void Plot2hists1D(TString hist1Name, TString hist2Name, TString file1Name, TString file2Name, TString hist1Label = "", TString hist2Label = "", Double_t scaleFactor1 = 1.0, Double_t scaleFactor2 = 1.0) { // Open the 1st file TFile *file1 = new TFile(file1Name); // Grab a copy of its histogram TH1* histTemp = (TH1*)file1->Get(hist1Name); // Open the 2nd file TFile *file2 = new TFile(file2Name,"UPDATE"); file2->cd(); // Change the name histTemp->SetName(hist1Name+"1"); // Write the histogram to the 2nd file histTemp->Write(); // Now file2 is the currently active file Plot2hists1D(hist1Name+"1",hist2Name, scaleFactor1, scaleFactor2, hist1Label, hist2Label); // Close the files, but if they close, the histograms disappear //file1->Close(); //file2->Close(); }
void turn2Dinto1Ds(char* myf, char *myh, char* myfo) { TFile* mytfile = new TFile(myf); TH2* my2dh = (TH2*) mytfile->Get(myh); my2dh->SetDirectory(0); TFile* myoftile = new TFile(myfo,"RECREATE"); myoftile->cd(); //std::vector<TH1*> vechist; Int_t ybins = my2dh->GetNbinsX(); std::cout << " Full bins " << ybins << std::endl; std::cout << " Entries " << my2dh->GetEntries(); for (Int_t Ybin = 1; Ybin <= ybins; ++Ybin) { TH1* onehist = (TH1*) my2dh->ProjectionY(Form("rap%d",Ybin), Ybin,Ybin,""); std::cout << " Entries: " << onehist->GetEntries() << std::endl; onehist->Write(); } myoftile->Write(); myoftile->Close(); mytfile->Close(); }
void analyzer() { TString processName = "ZJets"; TFile* f = TFile::Open(Form("hist_%s.root", processName.Data()), "recreate"); // Create chain of root trees TChain chain("DelphesMA5tune"); //kisti //chain.Add("/cms/home/tjkim/fcnc/sample/ZToLL50-0Jet_sm-no_masses/events_*.root"); //hep chain.Add("/Users/tjkim/Work/fcnc/samples/ZToLL50-0Jet_sm-no_masses/events_*.root"); // Create object of class ExRootTreeReader ExRootTreeReader *treeReader = new ExRootTreeReader(&chain); Long64_t numberOfEntries = treeReader->GetEntries(); // Get pointers to branches used in this analysis TClonesArray *branchMuon = treeReader->UseBranch("DelphesMA5tuneMuon"); // Book histograms TH1 *histDiMuonMass = new TH1F("dimuon_mass","Di-Muon Invariant Mass (GeV)",100, 50, 150); // Loop over all events for(Int_t entry = 0; entry < numberOfEntries; ++entry) { // Load selected branches with data from specified event treeReader->ReadEntry(entry); int nmuon = 0; for( int i = 0; i < branchMuon->GetEntries(); i++) { Muon *muon = (Muon*) branchMuon->At(i); if( muon->PT <= 20 || abs(muon->Eta) >= 2.4 ) continue; nmuon = nmuon + 1 ; } if( nmuon >= 2){ Muon *mu1 = (Muon*) branchMuon->At(0); Muon *mu2 = (Muon*) branchMuon->At(1); // Plot di-muon invariant mass histDiMuonMass->Fill(((mu1->P4()) + (mu2->P4())).M()); } } // Show resulting histograms histDiMuonMass->Write(); f->Close(); }
/*=========================================================*/ Int_t putspe(Char_t *rn, Char_t *hn) { TH1 *hist; TFile *f2;; hist = (TH1*)f1->Get(hn); f2 = new TFile(rn,"UPDATE"); hist->Write(); f2->ls(); f2->Close(); return 0; }
makeMuonTriggerEfficiencyLUT() { TH1* histoLUT = new TH2F("muonTriggerEfficiencyCorrection", "muonTriggerEfficiencyCorrection", 1, -2.5, +2.5, 1, 0., 10000.); histoLUT->SetBinContent(1, 1, 0.98); histoLUT->SetBinError(1, 1, 0.02); TFile* outputFile = new TFile("../data/muonTriggerEfficiencyCorrection.root", "RECREATE"); histoLUT->Write(); delete outputFile; }
/*=========================================================*/ Int_t getspe(Char_t *rn, Char_t *hn) { TH1 *hist; TFile *f2,*f3; f1->Close(); f2 = new TFile(rn,"READ"); hist = (TH1*)f2->Get(hn); f3 = new TFile(rootfilename,"UPDATE"); hist->Write(); f3->Close(); f2->Close(); f1 = new TFile(rootfilename,"READ"); f1->ls(hn); return 0; }
void Hijing() { TFile *fin = TFile::Open("/sphenix/user/pinkenbu/jade/hijingdat2.root"); gROOT->cd(); TH1 *hjbkg = new TH1F("hjbkg","Hijing Background",100,0.,0.5); TNtuple *de = (TNtuple *) fin->Get("de"); de->Project("hjbkg","dtotal","(ID<=2)*edep/250."); char fname [100]; sprintf(fname, "Gamma_Neutron_Hijing_Energy_Graphs.root"); TFile *fout = TFile::Open(fname,"UPDATE"); hjbkg->Write(); fout->Write(); fout->Close(); fin->Close(); }
void makefinal(TFile* fp, TFile *fm, TFile* of=0) { setTDRStyle(); TH1 *hp = (TH1*) fp->Get("MYHA"); TH1 *hm = (TH1*) fm->Get("MYHA"); TH1 *h = hp->Clone("MYNA"); for (int k=1; k<=h->GetNbinsX(); k++) { std::cout << hp->GetBinContent(k) << " " << hm->GetBinContent(k) << std::endl; h->SetBinContent(k,hp->GetBinContent(k)*.5 +hm->GetBinContent(k)*.5); std::cout << " NEW " << h->GetBinContent(k) << std::endl; //h->SetBinEntries(k,1); } if (of!=0) { of->cd(); h->Write();} }
void savehistos(const string& filewithlist, const string& outputfilename, const string& openmode="RECREATE") { FILE *fp = fopen(filewithlist.c_str(),"r"); if (!fp) { cerr << "File not found, " << filewithlist << endl; return; } TFile *rootfile = new TFile(outputfilename.c_str(),openmode.c_str()); if (rootfile->IsZombie()) { cerr << "File failed to open, " << outputfilename << endl; return; } string theline,newname; vector<string> tokens; while (getLine(fp,theline)) { if (theline[0] == '#') continue; // "comments are welcome" Tokenize(theline,tokens,"\t"); TH1 *h1 = getHisto(tokens[0]); if (!h1) { cerr << "Couldn't get histo " << tokens[0] << endl; return; } TH1 *target = h1; if( tokens.size() > 1 && tokens[1].length() ) { newname = tokens[1]; cout<<"Writing histo "<<newname<<" to file "<<outputfilename<<endl; target = (TH1 *)h1->Clone(newname.c_str()); } else cout<<"Writing histo "<<h1->GetName()<<" to file "<<outputfilename<<endl; target->SetDirectory(rootfile); rootfile->cd(); target->Write(); } rootfile->Close(); }
void HistoProofMan::Save(){ if(!fname[0])return; printf("HistoMan::Save ----> Saving %s\n",fname); TDirectory *dsave = gDirectory; TFile* pp=TFile::Open(fname,"RECREATE"); pp->cd(); hashtable<TH1*>::iterator it; for(it=hlist.begin();it!=hlist.end();it++) { TH1 *obj = it->second; if (obj && obj->GetEntries() > 0) obj->Write(); } pp->Write(); pp->Close(); printf(" ..... done\n"); if (dsave) dsave->cd(); // fdir->Purge(); return; }
void rescaleBoundaryHists(std::string infile, int numSamples=-1){ TFile* f = new TFile(infile.c_str(), "UPDATE"); TDirectory* dir = 0; TIter dir_it(f->GetListOfKeys()); TKey* dir_k; while ((dir_k = (TKey *)dir_it())) { if (TString(dir_k->GetClassName()) != "TDirectoryFile") continue; std::string dir_name = std::string(dir_k->GetTitle()); if(dir_name == "") continue; dir = (TDirectory*)dir_k->ReadObj(); if(dir == 0) continue; TIter hist_it(dir->GetListOfKeys(), kIterBackward); TKey* hist_k; while ((hist_k = (TKey *)hist_it())) { std::string hist_name = (hist_k->GetTitle()); if (hist_name.find("_HI") != std::string::npos || hist_name.find("_LOW") != std::string::npos || hist_name.find("h_n_mt2bins") != std::string::npos) { TH1* h = (TH1*)hist_k->ReadObj(); if(numSamples==-1) h->Scale(1.0/h->GetEntries()); else h->Scale(1.0/numSamples); dir->cd(); h->Write("",TObject::kOverwrite); } } } delete dir; gDirectory->GetList()->Delete(); f->Write("",TObject::kOverwrite); f->Close(); delete f; }
void Fit(TString SIGNAL,TString HISTO,double scaleSGN) { gROOT->ForceStyle(); TFile *fDat = TFile::Open("Histo_flatTree_data_tmva"+SIGNAL+".root"); TFile *fBkg = TFile::Open("Histo_flatTree_qcd_weights_tmva"+SIGNAL+".root"); TFile *fSgn = TFile::Open("Histo_flatTree_"+SIGNAL+"_weights_tmva"+SIGNAL+".root"); TH1 *hDat = (TH1*)fDat->Get(HISTO); TH1 *hBkgRaw = (TH1*)fBkg->Get(HISTO); TH1 *hSgn = (TH1*)fSgn->Get(HISTO); TH1 *hDat_JESlo = (TH1*)fDat->Get(HISTO+"_JESlo"); TH1 *hBkgRaw_JESlo = (TH1*)fBkg->Get(HISTO+"_JESlo"); TH1 *hSgn_JESlo = (TH1*)fSgn->Get(HISTO+"_JESlo"); TH1 *hDat_JESup = (TH1*)fDat->Get(HISTO+"_JESup"); TH1 *hBkgRaw_JESup = (TH1*)fBkg->Get(HISTO+"_JESup"); TH1 *hSgn_JESup = (TH1*)fSgn->Get(HISTO+"_JESup"); TH1F *hBkg = (TH1F*)hBkgRaw->Clone("Bkg"); TH1F *hBkg_JESlo = (TH1F*)hBkgRaw_JESlo->Clone("Bkg_JESlo"); TH1F *hBkg_JESup = (TH1F*)hBkgRaw_JESup->Clone("Bkg_JESup"); hBkg->Smooth(2); hBkg_JESlo->Smooth(2); hBkg_JESup->Smooth(2); hSgn->Smooth(2); hSgn_JESlo->Smooth(2); hSgn_JESup->Smooth(2); double lumi = 4967; hBkg->Scale(lumi); hBkg_JESlo->Scale(lumi); hBkg_JESup->Scale(lumi); double k_factor = hDat->Integral()/hBkg->Integral(); double k_factor_JESlo = hDat->Integral()/hBkg_JESlo->Integral(); double k_factor_JESup = hDat->Integral()/hBkg_JESup->Integral(); hBkg->Scale(k_factor); cout<<"Signal entries = "<<hSgn->GetEntries()<<endl; hSgn->Scale(lumi/scaleSGN); hBkg_JESlo->Scale(k_factor_JESlo); hSgn_JESlo->Scale(lumi/scaleSGN); hBkg_JESup->Scale(k_factor_JESup); hSgn_JESup->Scale(lumi/scaleSGN); hSgn_JESlo->Scale(hSgn->Integral()/hSgn_JESlo->Integral()); hSgn_JESup->Scale(hSgn->Integral()/hSgn_JESup->Integral()); TH1 *hBkg_STATlo = (TH1*)hBkg->Clone(HISTO+"_STATlo"); TH1 *hSgn_STATlo = (TH1*)hSgn->Clone(HISTO+"_STATlo"); TH1 *hBkg_STATup = (TH1*)hBkg->Clone(HISTO+"_STATup"); TH1 *hSgn_STATup = (TH1*)hSgn->Clone(HISTO+"_STATup"); float y1,e1; for(int i=0;i<hBkg->GetNbinsX();i++) { y1 = hBkg->GetBinContent(i+1); e1 = hBkg->GetBinError(i+1); hBkg_STATlo->SetBinContent(i+1,y1-e1); hBkg_STATup->SetBinContent(i+1,y1+e1); y1 = hSgn->GetBinContent(i+1); e1 = hSgn->GetBinError(i+1); hSgn_STATlo->SetBinContent(i+1,y1-e1); hSgn_STATup->SetBinContent(i+1,y1+e1); } hBkg_STATlo->Scale(hBkg->Integral()/hBkg_STATlo->Integral()); hBkg_STATup->Scale(hBkg->Integral()/hBkg_STATup->Integral()); hSgn_STATlo->Scale(hSgn->Integral()/hSgn_STATlo->Integral()); hSgn_STATup->Scale(hSgn->Integral()/hSgn_STATup->Integral()); double xMIN = hBkg->GetBinLowEdge(1); double xMAX = hBkg->GetBinLowEdge(hBkg->GetNbinsX()+1); double xMIN2 = hDat->GetBinLowEdge(hDat->FindFirstBinAbove(0.5)); double xMAX2 = hDat->GetBinLowEdge(hDat->FindLastBinAbove(0.5)+1); RooRealVar x("x","x",xMIN2,xMAX2); RooDataHist data("data","dataset with x",x,hDat); RooDataHist bkg("qcd","bkg with x",x,hBkg); RooDataHist sgn("signal","sgn with x",x,hSgn); RooHistPdf bkgPDF("bkgPDF","bkgPDF",x,bkg,0); RooHistPdf sgnPDF("sgnPDF","sgnPDF",x,sgn,0); RooRealVar f("f","f",0,0.,1.); RooAddPdf model("model","model",RooArgList(sgnPDF,bkgPDF),RooArgList(f)); RooFitResult* r = model.fitTo(data,Save()); r->Print("v"); double N = hDat->Integral(); double B = hBkg->Integral(); double S = hSgn->Integral(); double m = f.getVal(); double e = f.getError(); cout<<"k-factor = "<<k_factor<<endl; cout<<N<<" "<<B<<" "<<S<<endl; cout<<"Total cross section = "<<N/lumi<<" pb"<<endl; cout<<"Model cross section = "<<S/lumi<<" pb"<<endl; cout<<"Fitted signal strength = "<<m*N/S<<endl; cout<<"Fitted signal error = "<<e*N/S<<endl; double p = 0.95; double xup = (N/S)*(m+sqrt(2.)*e*TMath::ErfInverse((1-p)*TMath::Erf(m/e)+p)); cout<<"Bayesian Upper limit = "<<xup<<endl; RooPlot* frame1 = x.frame(); data.plotOn(frame1); model.plotOn(frame1,Components("sgnPDF*"),LineStyle(1),LineWidth(2),LineColor(kGreen+1)); model.plotOn(frame1,Components("bkgPDF*"),LineStyle(1),LineWidth(2),LineColor(kRed)); model.plotOn(frame1,LineStyle(1),LineWidth(2),LineColor(kBlue)); //cout<<frame1->chiSquare()<<endl; RooHist* hresid = frame1->residHist(); RooHist* hpull = frame1->pullHist(); RooPlot* frame2 = x.frame(Title("Residual Distribution")); frame2->addPlotable(hresid,"P") ; // Create a new frame to draw the pull distribution and add the distribution to the frame RooPlot* frame3 = x.frame(Title("Pull Distribution")); frame3->addPlotable(hpull,"P"); TCanvas* cFit = new TCanvas("fitANN_"+SIGNAL,"fitANN_"+SIGNAL,900,600); gPad->SetLogy(); frame1->SetMaximum(1e+4); frame1->SetMinimum(0.5); frame1->GetXaxis()->SetTitle("ANN Output"); frame1->GetYaxis()->SetTitle("Events"); frame1->Draw(); cout<<frame1->nameOf(3)<<endl; TLegend *leg = new TLegend(0.7,0.65,0.9,0.9); leg->SetHeader(SIGNAL); leg->AddEntry(frame1->findObject("h_data"),"data","P"); leg->AddEntry(frame1->findObject("model_Norm[x]"),"QCD+Signal","L"); leg->AddEntry(frame1->findObject("model_Norm[x]_Comp[bkgPDF*]"),"QCD","L"); leg->AddEntry(frame1->findObject("model_Norm[x]_Comp[sgnPDF*]"),"Signal","L"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextFont(42); leg->SetTextSize(0.04); leg->Draw(); TCanvas* cPull = new TCanvas("pullANN_"+SIGNAL,"pullANN_"+SIGNAL,900,400); frame3->GetXaxis()->SetTitle("ANN Output"); frame3->GetYaxis()->SetTitle("Pull"); frame3->Draw(); cout<<"Creating datacard"<<endl; ofstream datacard; datacard.open("datacard_"+SIGNAL+"_"+HISTO+".txt"); datacard.setf(ios::right); datacard<<"imax 1"<<"\n"; datacard<<"jmax 1"<<"\n"; datacard<<"kmax *"<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"shapes * * "<<SIGNAL+"_"+HISTO+"_input.root $PROCESS $PROCESS_$SYSTEMATIC"<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"bin 1"<<"\n"; datacard<<"observation "<<N<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"bin 1 1"<<"\n"; datacard<<"process signal background "<<"\n"; datacard<<"process 0 1"<<"\n"; datacard<<"rate "<<S<<" "<<B<<"\n"; datacard<<"----------------"<<"\n"; datacard<<"lumi lnN 1.022 1.022"<<"\n"; datacard<<"jes shape 1 1"<<"\n"; datacard<<"mcstat shape 1 1"<<"\n"; datacard<<"jer shape 0 0"<<"\n"; datacard.close(); TFile *out = new TFile(SIGNAL+"_"+HISTO+"_input.root","RECREATE"); out->cd(); hDat->Write("data_obs"); hBkg->Write("background"); hSgn->Write("signal"); hDat_JESlo->Write("data_obs_jesDown"); hBkg_JESlo->Write("background_jesDown"); hBkg_STATlo->Write("background_mcstatDown"); hSgn_STATlo->Write("signal_mcstatDown"); hSgn_JESlo->Write("signal_jesDown"); hDat_JESup->Write("data_obs_jesUp"); hBkg_JESup->Write("background_jesUp"); hBkg_STATup->Write("background_mcstatUp"); hSgn_JESup->Write("signal_jesUp"); hSgn_STATup->Write("signal_mcstatUp"); //----- JER placeholder ---------------- hBkg_JESlo->Write("background_jerDown"); hSgn_JESlo->Write("signal_jerDown"); hBkg_JESup->Write("background_jerUp"); hSgn_JESup->Write("signal_jerUp"); }
void Analyze(const TString mode="CLOSED", UShort_t maxH=6, Bool_t /*doLoops*/=false, Int_t ifile=0 ) { #ifdef __CINT__ gROOT->LoadMacro("correlations/Types.hh++"); gROOT->LoadMacro("correlations/Result.hh++"); gROOT->LoadMacro("correlations/QVector.hh++"); gROOT->LoadMacro("correlations/recursive/FromQVector.hh++"); gROOT->LoadMacro("correlations/recurrence/FromQVector.hh++"); gROOT->LoadMacro("correlations/closed/FromQVector.hh++"); gROOT->LoadMacro("correlations/test/ReadData.hh++"); #endif // --- Setup of harmonics, etc ------------------------------------- gRandom->SetSeed(54321); UShort_t emode = 0; if (mode.EqualTo("closed", TString::kIgnoreCase)) emode = 0; else if (mode.EqualTo("recurrence", TString::kIgnoreCase)) emode = 1; else if (mode.EqualTo("recursive", TString::kIgnoreCase)) emode = 2; else Warning("Analyze", "Mode %s unknown, assuming CLOSED", mode.Data()); correlations::QVector q[nbin]; correlations::FromQVector* c[nbin]; correlations::HarmonicVector h(maxH); for (UShort_t i = 0; i < maxH; i++) { // Generate random harmonicx // h[i] = -6 + gRandom->Integer(12); h[0] = 2; h[1] = -2; h[2] = 2; h[3] = -2; h[4] = 2; h[5] = -2; h[6] = -2; h[7] = 2; // Printf("h_%d:\t%d", i, h[i]); } // Resize the Q-vector to fit the harmonics for(int ibin=0;ibin<nbin;ibin++){ q[ibin] = correlations::QVector(0,0,false); q[ibin].resize(h); switch (emode) { case 0: c[ibin] = new correlations::closed::FromQVector(q[ibin]); break; case 1: c[ibin] = new correlations::recurrence::FromQVector(q[ibin]); break; case 2: c[ibin] = new correlations::recursive::FromQVector(q[ibin]); break; } } //Printf("Correlator: %s", c->name()); // --- Some histograms --------------------------------------------- TH1* sumreals[nbin]; TH1* sumimags[nbin]; TH1* weights[nbin]; TVectorD tottrk; TVectorD Nevent; tottrk.ResizeTo(nbin); tottrk.Zero(); Nevent.ResizeTo(nbin); Nevent.Zero(); //TH1* reals = new TH1D("reals", "Re(C{n})", maxH-2+1, 2+.5, maxH+1+.5); //TH1* imags = static_cast<TH1*>(reals->Clone("imags")); for(int ibin=0;ibin<nbin;ibin++){ sumreals[ibin] = new TH1D(Form("sumreals_%d",ibin), "Re(C{n})", maxH-2+1, 2+.5, maxH+1+.5); sumimags[ibin] = static_cast<TH1*>(sumreals[ibin]->Clone(Form("sumimags_%d",ibin))); weights[ibin] = static_cast<TH1*>(sumreals[ibin]->Clone(Form("weights_%d",ibin))); } TProfile* timing = new TProfile("timing", "Timing", maxH-2+1, 2+.5,maxH+1+.5); TH1* hs = new TH1I("harmonics", "Harmonics", maxH, 1.5, maxH+1.5); /*reals->SetFillColor(kGreen+1); reals->SetFillStyle(3001); reals->SetStats(0); imags->SetTitle("Im(C{n})"); imags->SetFillColor(kBlue+1); imags->SetFillStyle(3001); imags->SetStats(0); timing->SetFillColor(kRed+1); timing->SetFillStyle(3001); timing->SetStats(0); hs->SetFillColor(kMagenta+1); hs->SetFillStyle(3001); hs->SetStats(0);*/ for (UShort_t i = 0; i < maxH-1; i++) { TString label = TString::Format("C{%d}", i+2); // reals->GetXaxis()->SetBinLabel(i+1, label); // imags->GetXaxis()->SetBinLabel(i+1, label); timing->GetXaxis()->SetBinLabel(i+1, label); hs->GetXaxis()->SetBinLabel(i+1,Form("h_{%d}", i+1)); hs->SetBinContent(i+1, h[i]); } hs->GetXaxis()->SetBinLabel(maxH,Form("h_{%d}", maxH)); hs->SetBinContent(maxH, h[maxH-1]); TStopwatch timer; // --- Setup input ------------------------------------------------ TFile* file = TFile::Open(Form("%s/vndata_50k_%d.root",dir.Data(),ifile), "READ"); TTree* tree = static_cast<TTree*>(file->Get("tree")); // TArrayD phis(0); Int_t M; Float_t phi[10000],pt[10000],eta[10000]; // TArrayD weights(0); // Double_t phiR = 0; // TArrayD* pPhis = &phis; // TArrayD* pWeights = &weights; tree->SetBranchAddress("phig", phi); tree->SetBranchAddress("ptg",pt); tree->SetBranchAddress("etag",eta); tree->SetBranchAddress("n", &M); // tree->SetBranchAddress("weight", &pWeights); // tree->SetBranchAddress("event", &phiR); // --- The results ------------------------------------------------- const UShort_t nQ = maxH - 1; correlations::ResultVector qs[nbin]; for(int ibin=0;ibin<nbin;ibin++) qs[ibin] = correlations::ResultVector(nQ); // --- Event loop -------------------------------------------------- Int_t nEvents = tree->GetEntries(); for (Int_t event = 0; event < nEvents; event++) { tree->GetEntry(event); int ntrk = M; int xbin=-1; for(int j=0;j<nbin;j++) if(ntrk<trkbin[j]&&ntrk>=trkbin[j+1]) xbin=j; if(xbin<0 || xbin==nbin) continue; tottrk[xbin]+=ntrk; q[xbin].reset(); // printf("Event # %4u %4d particles ", event++, phis.GetSize()); for (UShort_t pa = 0; pa < M; pa++){ if(fabs(eta[pa])>etamax) continue; if(pt[pa]<ptmin||pt[pa]>ptmax) continue; //event selection // phis.Set(n,pPhis); q[xbin].fill(phi[pa], 1.); } for (UShort_t i = 0; i < nQ; i++) { UShort_t n = i + 2; // printf("%s%d", i == 0 ? "" : "..", n); timer.Reset(); timer.Start(); qs[xbin][i] += c[xbin]->calculate(n, h); timer.Stop(); timing->Fill(n+.5, timer.RealTime()); } // printf(" done\n"); Nevent[xbin]++; } file->Close(); for(int ibin=0;ibin<nbin;ibin++){ for (UShort_t i = 0; i < nQ; i++) { // UShort_t iq = i+2; // Double_t t = timing->GetBinContent(i+1); // correlations::Complex rc = qs[i].eval(); // Printf("QC{%2d}: %12g + %12gi <t>: %10gs", // iq, rc.real(), rc.imag(), t); // if(i==0)Printf("v2{%2d}: %3g\n",2,sqrt(qs[0].eval().real())); // if(i==2)Printf("v2{%2d}: %3g\n",4,TMath::Power(fabs(qs[2].eval().real()),1./4)); // if(i==4)Printf("v2{%2d}: %3g\n",6,TMath::Power(fabs(qs[4].eval().real()),1./6)); sumreals[ibin]->SetBinContent(i+1,qs[ibin][i]._sum.real()); sumimags[ibin]->SetBinContent(i+1,qs[ibin][i]._sum.imag()); weights[ibin]->SetBinContent(i+1,qs[ibin][i]._weights); //reals->SetBinContent(i+1, rc.real()); //imags->SetBinContent(i+1, rc.imag()); } } /* TCanvas* can = new TCanvas("C", "C"); can->SetTopMargin(0.15); can->SetBottomMargin(0.15); can->SetRightMargin(0.03); can->Divide(1,3, 0, 0); DrawInPad(can, 3, timing, true); DrawInPad(can, 1, reals); DrawInPad(can, 2, imags); can->cd(0); TLatex* ltx = new TLatex(0.5,0.995,c->name()); ltx->SetNDC(true); ltx->SetTextAlign(23); ltx->SetTextSize(0.04); ltx->Draw(); can->Modified(); can->Update(); can->cd(); */ TString out(mode); out.ToLower(); file = TFile::Open(Form("%s/%s_%d.root",outdir.Data(),out.Data(),ifile), "RECREATE"); for(int ibin=0;ibin<nbin;ibin++){ sumimags[ibin]->Write(); sumreals[ibin]->Write(); weights[ibin]->Write(); } Nevent.Write("Nevent"); tottrk.Write("tottrk"); timing->Write(); hs->Write(); file->Write(); file->Close(); for(int ibin=0;ibin<nbin;ibin++){ delete sumimags[ibin]; delete sumreals[ibin]; delete weights[ibin]; } delete timing; delete hs; }
int main(int argc, char *argv[]){ ///////////////////////////////////// if (argc != 6) { std::cout << "Please enter something like: ./run \"filelist_WJets_PU20bx25_100_200.txt\" \"WJets_PU20bx25_100_200\" \"Results\" \"00\" \"0\" " << std::endl; return EXIT_FAILURE; } //get the inputs from user const string InRootList = argv[1]; const string subSampleKey = argv[2]; const string Outdir = argv[3]; const string inputnumber = argv[4]; const string verbosity = argv[5]; ////////////////////////////////////// int verbose = atoi(verbosity.c_str()); //some varaibles char filenames[500]; vector<string> filesVec; ifstream fin(InRootList.c_str()); TChain *sample_AUX = new TChain("TreeMaker2/PreSelection"); char tempname[200]; char histname[200]; const double deltaRMax = 0.1; const double deltaPtMax = 0.2; map<string,int> binMap = utils2::BinMap_NoB(); int totNbins=binMap.size(); map<string,int> binMap_mht_nj = utils2::BinMap_mht_nj(); int totNbins_mht_nj=binMap_mht_nj.size(); TH1* hAccAll = new TH1D("hAccAll","Acceptance -- All",totNbins_mht_nj,1,totNbins_mht_nj+1); TH1* hIsoRecoAll = new TH1D("hIsoRecoAll","Efficiency -- All",totNbins,1,totNbins+1); TH1* hAccPass = new TH1D("hAccPass","Acceptance -- Pass",totNbins_mht_nj,1,totNbins_mht_nj+1); TH1* hIsoRecoPass = new TH1D("hIsoRecoPass","Efficiency -- Pass",totNbins,1,totNbins+1); hAccAll->Sumw2(); hIsoRecoAll->Sumw2(); hAccPass->Sumw2(); hIsoRecoPass->Sumw2(); int TauResponse_nBins=4; vector<TH1*> vec_resp; TFile * resp_file = new TFile("TauHad/HadTau_TauResponseTemplates_TTbar_Elog195WithDirectionalTemplates.root","R"); for(int i=0; i<TauResponse_nBins; i++){ sprintf(histname,"hTauResp_%d",i); vec_resp.push_back( (TH1D*) resp_file->Get( histname )->Clone() ); } ///read the file names from the .txt files and load them to a vector. while(fin.getline(filenames, 500) ){filesVec.push_back(filenames);} cout<< "\nProcessing " << subSampleKey << " ... " << endl; for(unsigned int in=0; in<filesVec.size(); in++){ sample_AUX->Add(filesVec.at(in).c_str()); } // --- Analyse the events -------------------------------------------- Selection * sel = new Selection(); Utils * utils = new Utils(); // Interface to the event content Events * evt = new Events(sample_AUX, subSampleKey,verbose); // Loop over the events (tree entries) int eventN=0; while( evt->loadNext() ){ // if(eventN>10000)break; eventN++; // Through out an event that contains HTjets with bad id if(evt->JetId()==0)continue; //printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@ \n event: %d \n Njet: %d HT: %g MHT: %g dphi1: %g dphi2: %g dphi3: %g \n ",eventN-1,evt->nJets(),evt->ht(),evt->mht(),evt->deltaPhi1(),evt->deltaPhi2(),evt->deltaPhi3()); //Ahmad3 // Apply the NJets baseline-cut if( !sel->Njet_4(evt->nJets()) ) continue; // Apply the HT and MHT baseline-cuts if( !sel->ht_500(evt->ht()) ) continue; if( !sel->mht_200(evt->mht()) ) continue; // Apply the delta-phi cuts // if( !sel->dphi(evt->nJets(),evt->minDeltaPhiN()) ) continue; if( !sel->dphi(evt->nJets(),evt->deltaPhi1(),evt->deltaPhi2(),evt->deltaPhi3(),evt->deltaPhi4()) ) continue; if(verbose!=0)printf("\n############ \n event: %d \n ",eventN-1); double genMuPt=0.; double genMuEta=-99.; double genMuPhi=-99.; int firstMuId=0; vector<TVector3> genMuonVec; TVector3 temp3vec; genMuonVec.clear(); bool isMuon = false; for(int i=0; i< evt->GenMuPtVec_().size(); i++){ if(evt->GenMuFromTauVec_()[i]==0){ genMuPt = evt->GenMuPtVec_().at(i); genMuEta = evt->GenMuEtaVec_().at(i); genMuPhi = evt->GenMuPhiVec_().at(i); isMuon=true; temp3vec.SetPtEtaPhi(genMuPt,genMuEta,genMuPhi); genMuonVec.push_back(temp3vec); } if(verbose!=0){ printf("Muon # %d, pt: %g, eta: %g, phi: %g \n ",i,genMuPt,genMuEta,genMuPhi); } break; // if more than one muon exist, pick the energetic one. } // ask for exactly one muon if( evt->GenMuPtVec_().size() > 1 ) continue; if( !( isMuon ) ) continue; // recompute ht mht njet double scale; if(genMuPt >=20.)scale = utils->getRandom(genMuPt,vec_resp ); else scale = utils->getRandom(20.,vec_resp ); double simTauJetPt = scale * genMuPt; double simTauJetEta = genMuEta; double simTauJetPhi = genMuPhi; // 3Vec of muon and scaledMu TVector3 SimTauJet3Vec,NewTauJet3Vec,Muon3Vec; SimTauJet3Vec.SetPtEtaPhi(simTauJetPt,simTauJetEta,simTauJetPhi); Muon3Vec.SetPtEtaPhi(genMuPt,genMuEta,genMuPhi); // New ht and mht vector<TVector3> HT3JetVec,MHT3JetVec; HT3JetVec.clear(); MHT3JetVec.clear(); TVector3 temp3Vec; int slimJetIdx=-1; utils->findMatchedObject(slimJetIdx,genMuEta,genMuPhi,evt->slimJetPtVec_(),evt->slimJetEtaVec_(), evt->slimJetPhiVec_(),deltaRMax,verbose); // If there is no match, add the tau jet as a new one if(slimJetIdx==-1){ NewTauJet3Vec=SimTauJet3Vec; if(NewTauJet3Vec.Pt()>30. && fabs(NewTauJet3Vec.Eta())<2.4)HT3JetVec.push_back(NewTauJet3Vec); if(NewTauJet3Vec.Pt()>30. && fabs(NewTauJet3Vec.Eta())<5.)MHT3JetVec.push_back(NewTauJet3Vec); } for(int i=0;i<evt->slimJetPtVec_().size();i++){ if(i!=slimJetIdx){ temp3Vec.SetPtEtaPhi(evt->slimJetPtVec_()[i],evt->slimJetEtaVec_()[i],evt->slimJetPhiVec_()[i]); if(evt->slimJetPtVec_()[i]>30. && fabs(evt->slimJetEtaVec_()[i])<2.4)HT3JetVec.push_back(temp3Vec); if(evt->slimJetPtVec_()[i]>30. && fabs(evt->slimJetEtaVec_()[i])<5.)MHT3JetVec.push_back(temp3Vec); } else if(i==slimJetIdx){ temp3Vec.SetPtEtaPhi(evt->slimJetPtVec_()[i],evt->slimJetEtaVec_()[i],evt->slimJetPhiVec_()[i]); NewTauJet3Vec=temp3Vec-Muon3Vec+SimTauJet3Vec; if(NewTauJet3Vec.Pt()>30. && fabs(NewTauJet3Vec.Eta())<2.4)HT3JetVec.push_back(NewTauJet3Vec); if(NewTauJet3Vec.Pt()>30. && fabs(NewTauJet3Vec.Eta())<5.)MHT3JetVec.push_back(NewTauJet3Vec); } } // Order the HT3JetVec and MHT3JetVec based on their pT HT3JetVec = utils->Order_the_Vec(HT3JetVec); MHT3JetVec = utils->Order_the_Vec(MHT3JetVec); double newHT=0,newMHT=0,newMHTPhi=-1; TVector3 newMHT3Vec; for(int i=0;i<HT3JetVec.size();i++){ newHT+=HT3JetVec[i].Pt(); } for(int i=0;i<MHT3JetVec.size();i++){ newMHT3Vec-=MHT3JetVec[i]; } newMHT=newMHT3Vec.Pt(); newMHTPhi=newMHT3Vec.Phi(); //New #Jet int newNJet = HT3JetVec.size(); if(verbose==1)printf("newNJet: %d \n ",newNJet); // Acceptance determination 1: Counter for all events // with muons at generator level hAccAll->Fill( binMap_mht_nj[utils2::findBin_mht_nj(evt->nJets(),evt->mht()).c_str()] ); // hAccAll->Fill( binMap_mht_nj[utils2::findBin_mht_nj(newNJet,newMHT).c_str()] ); // this doesn't work good // Check if generator-level muon is in acceptance if( genMuPt > LeptonAcceptance::muonPtMin() && std::abs(genMuEta) < LeptonAcceptance::muonEtaMax() ) { if(verbose!=0)printf("Muon is in acceptance \n "); // Acceptance determination 2: Counter for only those events // with generator-level muons inside acceptance // hAccPass->Fill( binMap[utils2::findBin(cntNJetsPt30Eta24,nbtag,HT,template_mht).c_str()] ); hAccPass->Fill( binMap_mht_nj[utils2::findBin_mht_nj(evt->nJets(),evt->mht()).c_str()] ); // hAccPass->Fill( binMap_mht_nj[utils2::findBin_mht_nj(newNJet,newMHT).c_str()] ); // Reconstruction-efficiency determination 1: Counter for all events // with generator-level muons inside acceptance, regardless of whether // the muon has also been reconstructed or not. // hIsoRecoAll->Fill( binMap[utils2::findBin(cntNJetsPt30Eta24,nbtag,HT,template_mht).c_str()]); hIsoRecoAll->Fill( binMap[utils2::findBin_NoB(evt->nJets(),evt->ht(),evt->mht()).c_str()]); // Check if the muon has been reconstructed: check if a reconstructed // muon is present in the event that matches the generator-level muon // Isolation-efficiency determination 1: Counter for all events with a // reconstructed muon that has a generator-level muon match inside the // the acceptance, regardless of whether the reconstructed muon is also // isolated or not. //if( evt->MuPtVec_().size()>0 )printf(" RecoMu--> Pt: %g eta: %g phi: %g deltaRMax: %g ",evt->MuPtVec_()[0],evt->MuEtaVec_()[0],evt->MuPhiVec_()[0],deltaRMax); // Ahmad3 //else cout << " Muon size is 0 \n " ; // in R and in pt int matchedMuonIdx = -1; if(evt->MuPtVec_().size()>0 && utils->findMatchedObject(matchedMuonIdx,genMuEta,genMuPhi,evt->MuPtVec_(),evt->MuEtaVec_(),evt->MuPhiVec_(),deltaRMax,verbose) ) { // Muon is reconstructed const double relDeltaPtMu = std::abs(genMuPt - evt->MuPtVec_().at(matchedMuonIdx) ) / evt->MuPtVec_().at(matchedMuonIdx) ; if(verbose!=0)printf(" relDeltaPtMu: %g \n ",relDeltaPtMu); if( relDeltaPtMu < deltaPtMax ) { // and matches generated pt if(verbose!=0)printf("Muon is reconstructed \n "); // Check if the muon is also isolated: check if an isolated muon is present // in the event that matches the reconstructed muon in R if( /*muonsRelIso->at(matchedMuonIdx) <= Selection::muIso()*/ true ){ //.................//.................// // Currently muons are picked if they are isolated. // So we don't need to put a cut here. //.................//.................// // Muon is isolated if(verbose!=0)printf("Muon is isolated \n "); // Reconstruction-efficiency determination 2: Counter for those events // with generator-level muons inside acceptance where the muon has also // been reconstructed. // Isolation-efficiency determination 2: Counter for those events where // the muon is also isolated. // hIsoRecoPass->Fill( binMap[utils2::findBin(cntNJetsPt30Eta24,nbtag,HT,template_mht).c_str()] ); hIsoRecoPass->Fill( binMap[utils2::findBin_NoB(evt->nJets(),evt->ht(),evt->mht()).c_str()] ); } // End of muon is isolated } // End of pt matching } // End of reconstructed muon } // End of muon in acceptance } // end of loop over events // Compute acceptance TH1* hAcc = static_cast<TH1*>(hAccPass->Clone("hAcc")); hAcc->Divide(hAccPass,hAccAll,1,1,"B");// we use B option here because the two histograms are correlated. see TH1 page in the root manual. // Compute efficiencies TH1* hEff = static_cast<TH1*>(hIsoRecoPass->Clone("hEff")); hEff->Divide(hIsoRecoPass,hIsoRecoAll,1,1,"B"); if(verbose!=0){ for(int j=1; j<= totNbins; j++){ printf("hAccAll: %g hAccPass: %g hAcc: %g hIsoRecoAll: %g hIsoRecoPass: %g hEff: %g \n ",hAccAll->GetBinContent(j),hAccPass->GetBinContent(j),hAcc->GetBinContent(j),hIsoRecoAll->GetBinContent(j),hIsoRecoPass->GetBinContent(j),hEff->GetBinContent(j)); } } // --- Save the Histograms to File ----------------------------------- sprintf(tempname,"LostLepton/LostLepton2_MuonEfficienciesFrom%s_%s.root",subSampleKey.c_str(),inputnumber.c_str()); TFile outFile(tempname,"RECREATE"); hAcc->Write(); hEff->Write(); hAccAll->Write(); hAccPass->Write(); hIsoRecoAll->Write(); hIsoRecoPass->Write(); outFile.Close(); } // end of main
// === Main Function =================================================== void hadTau1(unsigned int id = 11, int nEvts = -1) { // --- Declare the Output Histograms --------------------------------- // The tau response templates // They are filled for different bins in generated tau-lepton pt. // The binning is encapsulated in ../Utils/TauResponse.h std::vector<TH1*> hTauResp(TauResponse::nBins()); for(unsigned int i = 0; i < TauResponse::nBins(); ++i) { hTauResp.at(i) = new TH1D(TauResponse::name(i),";p_{T}(visible) / p_{T}(generated);Probability",50,0.,2.5); hTauResp.at(i)->Sumw2(); } // Control histograms for the jet-tau matching efficiency TH1* hNJetAll = new TH1D("hNJetAll",";N(jets)",10,0,10); hNJetAll->Sumw2(); TH1* hNJetPass = static_cast<TH1*>(hNJetAll->Clone("hNJetPass")); TH1* hHtAll = new TH1D("hHtAll",";H_{T} [GeV]",30,0,3000); hHtAll->Sumw2(); TH1* hHtPass = static_cast<TH1*>(hHtAll->Clone("hHtPass")); TH1* hMhtAll = new TH1D("hMhtAll",";#slash{H}_{T} [GeV]",20,0,2000); hMhtAll->Sumw2(); TH1* hMhtPass = static_cast<TH1*>(hMhtAll->Clone("hMhtPass")); // --- Analyse the events -------------------------------------------- // Interface to the event content Event* evt = new Event(Sample::fileNameFullSample(id),nEvts); // Loop over the events (tree entries) while( evt->loadNext() ) { // Select only events where the W decayed into a hadronically // decaying tau if( !(evt->flgW() == 15 && evt->flgTau() == 1) ) continue; // Kinematic variables of generator-level tau const float genTauPt = evt->genLeptonPt(); const float genTauEta = evt->genLeptonEta(); const float genTauPhi = evt->genLeptonPhi(); // Use only events where the tau is inside the muon acceptance // because lateron we will apply the response to muon+jet events if( genTauPt < TauResponse::ptMin() ) continue; if( std::abs(genTauEta) > TauResponse::etaMax() ) continue; // "Cross cleaning": find the jet that originates in the // hadronic tau-decay. Associate the jet that is closest in // deltaR to the tau. The distance has to be smaller than deltaRMax. // First, fill counters before jet-tau matching hNJetAll->Fill(evt->nJets()); hHtAll->Fill(evt->ht()); hMhtAll->Fill(evt->mht()); // Do the matching int tauJetIdx = -1; // Will store the index of the jet matched to the tau const float deltaRMax = genTauPt < 50. ? 0.2 : 0.1; // Increase deltaRMax at low pt to maintain high-enought matching efficiency if( !utils::findMatchedObject(tauJetIdx,genTauEta,genTauPhi,evt->jetsEta(),evt->jetsPhi(),evt->jetsN(),deltaRMax) ) continue; // Then, fill counters after matching hNJetPass->Fill(evt->nJets()); hHtPass->Fill(evt->ht()); hMhtPass->Fill(evt->mht()); // Calculate RA2 selection-variables from "cleaned" jets, // i.e. jets withouth the tau-jet int selNJet = 0; // Number of HT jets (jets pt > 50 GeV and |eta| < 2.5) for(int jetIdx = 0; jetIdx < evt->jetsN(); ++jetIdx) { // Loop over reco jets // Skip this jet if it is the tau if( jetIdx == tauJetIdx ) continue; // Calculate NJet if( evt->jetsPt()[jetIdx] > Selection::htJetPtMin() && std::abs(evt->jetsEta()[jetIdx]) < Selection::htJetEtaMax() ) selNJet++; } // End of loop over reco jets // Select only events with at least 2 HT jets if( selNJet < 2 ) continue; // Fill histogram with relative visible energy of the tau // ("tau response template") for hadronically decaying taus for(int jetIdx = 0; jetIdx < evt->jetsN(); ++jetIdx) { // Loop over reco jets // Select tau jet if( jetIdx == tauJetIdx ) { // Get the response pt bin for the tau const unsigned int ptBin = TauResponse::ptBin(genTauPt); // Fill the corresponding response template const double tauJetPt = evt->jetsPt()[jetIdx]; hTauResp.at(ptBin)->Fill( tauJetPt / genTauPt ); break; // End the jet loop once the tau jet has been found } } // End of loop over reco jets } // End of loop over tree entries // Normalize the response distributions to get the probability density for(unsigned int i = 0; i < hTauResp.size(); ++i) { if( hTauResp.at(i)->Integral("width") > 0. ) { hTauResp.at(i)->Scale(1./hTauResp.at(i)->Integral("width")); } } // Get the jet-tau matching efficiency TH1* hMatchEffNJet = static_cast<TH1*>(hNJetPass->Clone("hMatchEffNJet")); hMatchEffNJet->Divide(hNJetAll); TH1* hMatchEffHt = static_cast<TH1*>(hHtPass->Clone("hMatchEffHt")); hMatchEffHt->Divide(hHtAll); TH1* hMatchEffMht = static_cast<TH1*>(hMhtPass->Clone("hMatchEffMht")); hMatchEffMht->Divide(hMhtAll); // --- Save the Histograms to File ----------------------------------- TFile outFile("../data/HadTau_TauResponseTemplates.root","RECREATE"); for(unsigned int i = 0; i < hTauResp.size(); ++i) { hTauResp.at(i)->Write(); } hMatchEffNJet->Write(); hMatchEffHt->Write(); hMatchEffMht->Write(); outFile.Close(); }
// === Main Function =================================================== void general1(int sampleId) { std::cout << "Analysing the " << sampleLabel(sampleId) << " sample" << std::endl; // --- Declare the Output Histograms --------------------------------- TH1* hNJets = new TH1F("hNJets",";N(jets);N(events)",12,0,12); hNJets->Sumw2(); TH1* hHt = new TH1F("hHt",";H_{T} [GeV]",30,0,3000); hHt->Sumw2(); hHt->GetXaxis()->SetNdivisions(505); TH1* hMht = new TH1F("hMht",";#slash{H}_{T} [GeV]",30,0,1500); hMht->Sumw2(); hMht->GetXaxis()->SetNdivisions(505); TH1* hMEff = new TH1F("hMEff",";M_{eff} [GeV]",50,0,5000); hMEff->Sumw2(); hMEff->GetXaxis()->SetNdivisions(505); std::vector<TH1*> hJetPt(6); std::vector<TH1*> hJetPhi(6); std::vector<TH1*> hJetEta(6); for(unsigned int i = 0; i < hJetEta.size(); ++i) { TString name = "hJetPt_"; name += i; TString title = ";p_{T}(jet "; title += i+1; title += ") [GeV];N(events)"; hJetPt.at(i) = new TH1F(name,title,30,0,1500); hJetPt.at(i)->Sumw2(); name = "hJetPhi_"; name += i; title = ";#phi(jet "; title += i+1; title += ");N(events)"; hJetPhi.at(i) = new TH1F(name,title,24,-4,4); hJetPhi.at(i)->Sumw2(); name = "hJetEta_"; name += i; title = ";#eta(jet "; title += i+1; title += ");N(events)"; hJetEta.at(i) = new TH1F(name,title,25,-5,5); hJetEta.at(i)->Sumw2(); } // --- Declare the Variables Read from the Tree ---------------------- // Reco-level jets int nRecoJets = 0; float recoJetPt[kRecoJetColSize]; float recoJetPhi[kRecoJetColSize]; float recoJetEta[kRecoJetColSize]; // Number of reco-level muons and electrons int nRecoMus = 0; int nRecoEle = 0; // MC Event weight float evtWgt = 1.; // --- Set Up the Tree ----------------------------------------------- // Get the tree from file TChain* tr = new TChain("AnaTree"); tr->Add("/nfs/dust/test/cmsdas/school61/susy/ntuple/2013-v1/"+fileName(sampleId)+"_0.root"); // Set the branches tr->SetBranchAddress("NrecoJet",&nRecoJets); tr->SetBranchAddress("recoJetPt",recoJetPt); tr->SetBranchAddress("recoJetPhi",recoJetPhi); tr->SetBranchAddress("recoJetEta",recoJetEta); tr->SetBranchAddress("NrecoMu",&nRecoMus); tr->SetBranchAddress("NrecoEle",&nRecoEle); if( sampleId > 0 ) tr->SetBranchAddress("EvtWgt",&evtWgt); // --- Process the Events in the Tree -------------------------------- int nEvtsToProcess = tr->GetEntries(); std::cout << "Processing " << nEvtsToProcess << " events" << std::endl; // Loop over the tree entries for(int evtIdx = 0; evtIdx < nEvtsToProcess; ++evtIdx) { if( evtIdx%100000 == 0 ) std::cout<<" Event: " << evtIdx << std::endl; // Get the variables' values for this event tr->GetEntry(evtIdx); if( nRecoJets > kRecoJetColSize ) { std::cerr << "ERROR: more than " << kRecoJetColSize << " reco jets in event " << evtIdx << std::endl; exit(-1); } // Apply the lepton veto if( nRecoEle > 0 ) continue; if( nRecoMus > 0 ) continue; // Calculate RA2 selection-variables from jets float selNJet = 0; // Number of jets with pt > 50 GeV and |eta| < 2.5 (HT jets) float selHt = 0.; float selMhtX = 0.; float selMhtY = 0.; // Loop over reco jets: they are ordered in pt for(int jetIdx = 0; jetIdx < nRecoJets; ++jetIdx) { // Calculate NJet and HT if( recoJetPt[jetIdx] > kHtJetPtMin && TMath::Abs(recoJetEta[jetIdx]) < kHtJetEtaMax ) { selNJet++; selHt += recoJetPt[jetIdx]; } // Calculate MHT components if( recoJetPt[jetIdx] > kMhtJetPtMin && TMath::Abs(recoJetEta[jetIdx]) < kMhtJetEtaMax ) { selMhtX -= recoJetPt[jetIdx]*TMath::Cos(recoJetPhi[jetIdx]); selMhtY -= recoJetPt[jetIdx]*TMath::Sin(recoJetPhi[jetIdx]); } } // End of loop over reco jets float selMht = sqrt( selMhtX*selMhtX + selMhtY*selMhtY ); // Select only events with at least 2 HT jets if( selNJet < 3 ) continue; //>>> PLACE OTHER RA2 CUTS HERE // Event weight in plots float weight = 1.; if( sampleId == 1 ) weight = evtWgt; // In case of the flat QCD-MC, reweight to physical spectrum // Fill histogram hNJets->Fill(selNJet,weight); hHt->Fill(selHt,weight); hMht->Fill(selMht,weight); hMEff->Fill(selHt+selMht,weight); for(int i = 0; i < static_cast<int>(hJetPt.size()); ++i) { if( i == nRecoJets ) break; hJetPt.at(i)->Fill(recoJetPt[i],weight); hJetPhi.at(i)->Fill(recoJetPhi[i],weight); hJetEta.at(i)->Fill(recoJetEta[i],weight); } } // End of loop over events // --- Save the Histograms to File ----------------------------------- TFile outFile("General_"+fileName(sampleId)+".root","RECREATE"); hNJets->Write(); hHt->Write(); hMht->Write(); hMEff->Write(); for(unsigned int i = 0; i < hJetPt.size(); ++i) { hJetPt[i]->Write(); hJetEta[i]->Write(); hJetPhi[i]->Write(); } }
void ttreesToHistograms() { //******************************************************************** //**** Variables ****// cout << "Loading variables into vectors..." << endl; vector<TString> fileName; fileName.push_back( "rootfiles0/PhotonJetPt15_Summer09.root" );//file0 fileName.push_back( "rootfiles0/PhotonJetPt30_Summer09.root" );//file1 fileName.push_back( "rootfiles0/PhotonJetPt80_Summer09.root" );//file2 fileName.push_back( "rootfiles0/PhotonJetPt170_Summer09.root" );//file3 fileName.push_back( "rootfiles0/PhotonJetPt300_Summer09.root" );//file4 fileName.push_back( "rootfiles0/PhotonJetPt470_Summer09.root" );//file5 fileName.push_back( "rootfiles0/PhotonJetPt800_Summer09.root" );//file6 TString treeName = "TreePhotonJet"; TString outputFileName = "PhotonJetHists-2009-09-02-matchesReco.root"; //********************************* //**** Set Scale // The following 4 number set the scale // example: // scale = (integrated luminosity (1/pb))*(cross section (pb))*(filter eff)/(events analyzed) float invLuminosityToScaleTo = 200; // in pb-1 vector<float> crossSection; crossSection.push_back( 2.887E5 -3.222E4 ); // in pb crossSection.push_back( 3.222E4 -1.010E3 ); crossSection.push_back( 1.010E3 -5.143E1 ); crossSection.push_back( 5.143E1 -4.193E0 ); crossSection.push_back( 4.193E0 -4.515E-1 ); crossSection.push_back( 4.515E-1 -2.003E-2 ); crossSection.push_back( 2.003E-2 ); vector<float> filterEffeciency; filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); vector<float> eventsAnalyzied; eventsAnalyzied.push_back( 1073270 ); eventsAnalyzied.push_back( 1088546 ); eventsAnalyzied.push_back( 993509 ); eventsAnalyzied.push_back( 1483940 ); eventsAnalyzied.push_back( 1024589 ); eventsAnalyzied.push_back( 1014413 ); eventsAnalyzied.push_back( 1216320 ); // END of setting scale //********************************* //********************************* //**** Set Cuts ****// // Variables will be plotted for each "location" vector<TString> locationCut; locationCut.push_back( "abs(hardGenPhoton_eta)>1.55&&abs(hardGenPhoton_eta)<2.5" ); locationCut.push_back( "abs(hardGenPhoton_eta)<1.45" ); vector<TString> locationName; locationName.push_back( "Endcap" ); locationName.push_back( "Barrel" ); // These cuts will be merged into one giant cut, applied to all plots for all files vector<TString> cuts; cuts.push_back( "hardGenPhoton_et>15.0&&photon_et>15.0&&photon_matches_hardGen>0.5" ); // These cuts will be applied only to corresponding file vector<TString> fileCuts; fileCuts.push_back( "event_genEventScale>15&&event_genEventScale<30" ); //file0 fileCuts.push_back( "event_genEventScale>30&&event_genEventScale<80" ); //file1 fileCuts.push_back( "event_genEventScale>80&&event_genEventScale<170" ); //file2 fileCuts.push_back( "event_genEventScale>170&&event_genEventScale<300" ); //file3 fileCuts.push_back( "event_genEventScale>300&&event_genEventScale<470" ); //file4 fileCuts.push_back( "event_genEventScale>470&&event_genEventScale<800" ); //file5 fileCuts.push_back( "event_genEventScale>800&&event_genEventScale<1400" ); //file6 //**** END of setting cuts //********************************* //********************************* int locationVariablesToPlot[2][2]; // [a][b], a=number of locations, b=2 (for min,max range of variables to plot) locationVariablesToPlot[0][0] = 16; // Endcap locationVariablesToPlot[0][1] = 35; locationVariablesToPlot[1][0] = 16; // Barrel locationVariablesToPlot[1][1] = 35; /*locationVariablesToPlot[2][0] = 0; locationVariablesToPlot[2][1] = 4; locationVariablesToPlot[3][0] = 0; locationVariablesToPlot[3][1] = 4; locationVariablesToPlot[4][0] = 0; locationVariablesToPlot[4][1] = 4; locationVariablesToPlot[5][0] = 0; locationVariablesToPlot[5][1] = 4; locationVariablesToPlot[6][0] = 0; locationVariablesToPlot[6][1] = 4; locationVariablesToPlot[7][0] = 0; locationVariablesToPlot[7][1] = 4;*/ // Variables you want plotted vector<TString> variableToPlot; // --- the following require gen level info variableToPlot.push_back( "hardGenPhoton_et" ); // 0 variableToPlot.push_back( "hardGenPhoton_eta" ); variableToPlot.push_back( "hardGenPhoton_phi" ); variableToPlot.push_back( "fmod(hardGenPhoton_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" ); variableToPlot.push_back( "abs(hardGenPhoton_eta)" ); // 4 variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_energy" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:abs(hardGenPhoton_eta)" ); variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_phiMod" ); variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_et" ); variableToPlot.push_back( "photon_hadronicOverEm:abs(hardGenPhoton_eta)" ); // 10 variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_phiMod" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:hardGenPhoton_et" ); variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:abs(hardGenPhoton_eta)" ); variableToPlot.push_back( "deltaPhiGenRecPhoton" ); // 15 // --- the following require only rec photons variableToPlot.push_back( "photon_et" ); // 16 variableToPlot.push_back( "photon_eta" ); variableToPlot.push_back( "photon_phi" ); variableToPlot.push_back( "fmod(photon_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" ); variableToPlot.push_back( "abs(photon_eta)" ); // 20 variableToPlot.push_back( "photon_r9" ); variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03" ); variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03" ); variableToPlot.push_back( "photon_trkSumPtSolidConeDR03" ); variableToPlot.push_back( "photon_trkSumPtHollowConeDR03" ); //25 variableToPlot.push_back( "photon_nTrkSolidConeDR03" ); variableToPlot.push_back( "photon_nTrkHollowConeDR03" ); variableToPlot.push_back( "photon_hadronicOverEm" ); variableToPlot.push_back( "photon_r2x5" ); variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03/photon_et" ); // 30 variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03/photon_et" ); variableToPlot.push_back( "photon_trkSumPtSolidConeDR03/photon_et" ); variableToPlot.push_back( "photon_trkSumPtHollowConeDR03/photon_et" ); // --- the following require jets /*variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet_phi)" ); variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet2_phi)" ); // 35 variableToPlot.push_back( "calcDeltaPhi(jet_phi,jet2_phi)" );*/ variableToPlot.push_back( "(photon_et-jet_et)/photon_et" ); variableToPlot.push_back( "jet2_et/photon_et" ); // Histograms for the above variables vector<TH1*> histogram; // --- the following require gen level info histogram.push_back( new TH1F("photonGenEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750) ); // 0 histogram.push_back( new TH1F("photonGenEta", "Photon #eta ;#eta;entries per 0.1 bin", 61, -3.05, 3.05) ); histogram.push_back( new TH1F("photonGenPhi", "Photon #phi ;#phi;entries per bin", 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) ); histogram.push_back( new TH1F("photonGenPhiMod", "Photon #phi_{mod} ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) ); histogram.push_back( new TH1F("photonGenAbsEta", "Photon |#eta| ", 51, 0.00, 2.55) ); histogram.push_back( new TH1F("photonDeltaE", "(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) ", 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_E","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs E(#gamma_{gen}) ", 50, 0, 3000, 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_AbsEta","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs |#eta(#gamma_{gen}|) ", 51, 0.0, 2.5, 50, -0.8, 0.3) ); histogram.push_back( new TH2F("photonDeltaE_vs_PhiMod","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, -0.9, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_Et", "H/E vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 50, 0.0, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_AbsEta", "H/E vs |#eta(#gamma_{gen})| ", 51, 0.0, 2.5, 50, 0.0, 0.2) ); histogram.push_back( new TH2F("photonHoverE_vs_PhiMod", "H/E vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, 0.0, 0.2) ); histogram.push_back( new TH1F("photonDeltaEta", "#Delta#eta(#gamma_{rec},#gamma_{gen}) ;#Delta#eta(#gamma_{rec},#gamma_{gen});entries/bin", 41, -0.01, 0.01) ); histogram.push_back( new TH2F("photonDeltaEta_vs_Et", "#Delta#eta(#gamma_{rec},#gamma_{gen}) vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 41, -0.1, 0.1) ); histogram.push_back( new TH2F("photonDeltaEta_vs_AbsEta","#Delta#eta(#gamma_{rec},#gamma_{gen}) vs #eta(#gamma_{gen})", 51, 0.0, 2.55, 41, -0.1, 0.1) ); histogram.push_back( new TH1F("photonDeltaPhi", "#Delta#phi(#gamma_{rec},#gamma_{gen}) ;#Delta#phi(#gamma_{rec},#gamma_{gen});entries/bin", 41, 0.0, 0.01) ); // 15 // --- the following require only rec photons histogram.push_back( new TH1F("photonEt", "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50, 0, 750 ) ); // 16 histogram.push_back( new TH1F("photonEta", "Photon #eta ;#eta;entries per 0.1" , 61, -3.05, 3.05) ); histogram.push_back( new TH1F("photonPhi", "Photon #phi ;#phi;entries per bin" , 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) ); histogram.push_back( new TH1F("photonPhiMod", "Photon #phi_{mod} " , 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) ); histogram.push_back( new TH1F("photonAbsEta", "Photon |#eta| " , 51, 0.00, 2.55) ); // 20 histogram.push_back( new TH1F("photonR9", "R9 = E(3x3) / E(SuperCluster) ;R9;entries/bin" , 50, 0.6, 1.0) ); histogram.push_back( new TH1F("photonEcalIso", "#SigmaEcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonHcalIso", "#SigmaHcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonTrackSolidIso", "#Sigmatrack p_{T} in Solid #DeltaR cone " , 50, 0 , 15) ); histogram.push_back( new TH1F("photonTrackHollowIso", "#Sigmatrack p{T} in Hollow #DeltaR cone " , 50, 0 , 15) ); // 25 histogram.push_back( new TH1F("photonTrackCountSolid", "Number of tracks in Solid #DeltaR cone ;Number of Tracks;entries/bin" , 25, -0.5, 24.5) ); histogram.push_back( new TH1F("photonTrackCountHollow", "Number of tracks in Hollow #DeltaR cone ;Number of Tracks;entries/bin", 25, -0.5, 24.5) ); histogram.push_back( new TH1F("photonHoverE", "Hadronic / EM ", 50, 0.0, 0.2) ); histogram.push_back( new TH1F("photonScSeedE2x5over5x5", "E2x5/E5x5 " , 50, 0.6, 1.0) ); histogram.push_back( new TH1F("photonEcalIsoOverE", "#SigmaEcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // 30 histogram.push_back( new TH1F("photonHcalIsoOverE", "#SigmaHcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); histogram.push_back( new TH1F("photonTrackSolidIsoOverE" , "#SigmaTrack p_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); histogram.push_back( new TH1F("photonTrackHollowIsoOverE", "#SigmaTrack p_{T} in Hollow #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // --- the following require jets /*histogram.push_back( new TH1F("h_deltaPhi_photon_jet", "#Delta#phi between Highest E_{T} #gamma and jet;#Delta#phi(#gamma,1^{st} jet)" , 50, 0, 3.1415926) ); histogram.push_back( new TH1F("h_deltaPhi_photon_jet2","#Delta#phi between Highest E_{T} #gamma and 2^{nd} highest jet;#Delta#phi(#gamma,2^{nd} jet)", 50, 0, 3.1415926) ); histogram.push_back( new TH1F("h_deltaPhi_jet_jet2" , "#Delta#phi between Highest E_{T} jet and 2^{nd} jet;#Delta#phi(1^{st} jet,2^{nd} jet)" , 50, 0, 3.1415926) );*/ histogram.push_back( new TH1F("h_deltaEt_photon_jet" , "(E_{T}(#gamma)-E_{T}(jet))/E_{T}(#gamma) when #Delta#phi(#gamma,1^{st} jet) > 2.8;#DeltaE_{T}(#gamma,1^{st} jet)/E_{T}(#gamma)", 20, -1.0, 1.0) ); histogram.push_back( new TH1F("h_jet2_etOverPhotonEt", "E_{T}(2^{nd} highest jet) / E_{T}(#gamma);E_{T}(2^{nd} Jet)/E_{T}(#gamma)", 20, 0.0, 4.0) ); //**** END of Variables ****// //******************************************************************** //******************************************************************** //**** Main part of Program ****// // Human error checking if (variableToPlot.size() != histogram.size() ) { cout << "Should have equal entries in histogram and variableToPlot vector." << endl; return; } if (fileName.size() > crossSection.size() ) { cout << "Should have equal entries in fileName and crossSection vetor." << endl; return; } if (fileName.size() > fileCuts.size() ) { cout << "Should have equal entries in fileName and fileCuts vector." << endl; return; } // Combine all the cuts into one cout << endl << "Cuts that will be applied to everything: " << endl << " "; TCut allCuts = ""; for (int i =0; i<cuts.size(); i++) { allCuts += cuts[i]; if (i>0) cout << "&&"; cout << "(" << cuts[i] << ")"; } cout << endl << endl; // Open the files & set their scales cout << endl << "Histograms will be scaled to " << invLuminosityToScaleTo << "pb-1 " << endl; cout << "Looking for TTree named \"" << treeName << "\" in files..." << endl; vector<float> fileScale; TList *fileList = new TList(); for (int i=0; i < fileName.size(); i++) { TFile* currentFile = TFile::Open(fileName[i]); fileList->Add(currentFile); float currentScale = crossSection[i]*invLuminosityToScaleTo*filterEffeciency[i]/eventsAnalyzied[i]; fileScale.push_back( currentScale ); // Display entries in that file's TTree TTree* tree; currentFile->GetObject(treeName, tree); cout << "file" << i <<": " << fileName[i] << " contains " << tree->GetEntries(allCuts) << " entries, and will be scaled by " << currentScale << endl; } cout << endl << endl; //Create output file TFile *outputFile = TFile::Open( outputFileName, "RECREATE" ); //************************************************************ // Core of the Script // // Loop over locations for (int l=0; l<locationName.size(); l++) { TString currentLocation = locationName[l]; TCut currentCuts = allCuts; currentCuts += locationCut[l]; cout << "Creating plots for " << currentLocation << ", " << locationCut[l] << endl; // Loop over variables to plot for (int i=0; i<variableToPlot.size(); i++) { // should we plot this variable for this location? if (i<locationVariablesToPlot[l][0] || i>locationVariablesToPlot[l][1]) continue; TString currentHistType = histogram[i]->IsA()->GetName(); TString currentHistName = TString(histogram[i]->GetName()) + "_" + currentLocation; TString currentHistTitle = TString(histogram[i]->GetTitle()) + "(" + currentLocation + ")"; cout << " " << variableToPlot[i] << " >> " << currentHistName; TString currentHistDrawOpt; if (currentHistType=="TH2F") { currentHistDrawOpt="goffbox"; } else { currentHistDrawOpt="egoff"; } TH1* currentHist = (TH1*)histogram[i]->Clone(currentHistName); // Creates clone with name currentHistName currentHist->Sumw2(); // store errors currentHist->SetTitle(currentHistTitle); //cout << " from file"; // Plot from the first file int f = 0; //cout << f; TTree *tree; TFile *current_file = (TFile*)fileList->First(); current_file->cd(); current_file->GetObject(treeName, tree); tree->Draw(variableToPlot[i]+">>"+currentHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt); currentHist->Scale(fileScale[f]); f++; // Loop over files current_file = (TFile*)fileList->After( current_file ); while ( current_file ) { current_file->cd(); //cout << ", file" << f; current_file->GetObject(treeName, tree); TString tempHistName = currentHistName+"Temp"; TH1* tempHist = (TH1*)currentHist->Clone(tempHistName); tree->Draw(variableToPlot[i]+">>"+tempHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt); tempHist->Scale(fileScale[f]); currentHist->Add(tempHist); tempHist->Delete(); current_file = (TFile*)fileList->After( current_file ); f++; } // End of loop over files outputFile->cd(); currentHist->Write(); cout << endl; } // End of loop over variabls to plot } // End of loop over locations // END of Core of Script // //************************************************************ cout << endl; cout << "Wrote file " << outputFileName << endl; cout << endl; outputFile->Close(); }
void vertexAssociationFit(TFile* input, TFile* output) { // style gStyle->SetOptStat(0); gStyle->SetOptFit(111); gStyle->SetOptTitle(1); // margins gStyle->SetStatFormat("6.4g"); gStyle->SetFitFormat("5.2g"); gStyle->SetPadTopMargin(0.07); gStyle->SetPadBottomMargin(0.12); gStyle->SetPadLeftMargin(0.1); gStyle->SetPadRightMargin(0.02); // prepare the output // * canvas to put the fit per bin TCanvas* canvas_0 = new TCanvas("FitPerBin","Fit for each vertex bin",1200,900); canvas_0->Divide(4,4); // * canvas to put the plots per bin TCanvas* canvas_1 = new TCanvas("EffPerBin","Efficiency vs purity for each vertex bin",1200,900); canvas_1->Divide(4,4); // * canvas with other plots: slope vs nvertices, efficiency and purity for fixed cut, etc. TCanvas* canvas_2 = new TCanvas("jvAssociation","Efficiency vs purity summary plots",1000,600); canvas_2->Divide(4,2); // summary graphs TGraphErrors* slopeGraph = new TGraphErrors(nbins); slopeGraph->SetNameTitle("slopeGraph","expo slope in each n_PU bin"); TGraphErrors* constGraph = new TGraphErrors(nbins); constGraph->SetNameTitle("constGraph","expo normalization in each n_PU bin"); TGraphErrors* cuteffGraph = new TGraphErrors(nbins); cuteffGraph->SetNameTitle("cuteffGraph","Efficiency in each n_PU bin"); TGraphErrors* cutpurGraph = new TGraphErrors(nbins); cutpurGraph->SetNameTitle("cutpurGraph","Purity in each n_PU bin"); TGraphErrors* effcutGraph = new TGraphErrors(nbins); effcutGraph->SetNameTitle("effcutGraph","Cut for fixed efficiency in each n_PU bin"); TGraphErrors* effpurGraph = new TGraphErrors(nbins); effpurGraph->SetNameTitle("effpurGraph","Purity for fixed efficiency in each n_PU bin"); TGraphErrors* purcutGraph = new TGraphErrors(nbins); purcutGraph->SetNameTitle("purcutGraph","Cut for fixed purity in each n_PU bin"); TGraphErrors* pureffGraph = new TGraphErrors(nbins); pureffGraph->SetNameTitle("pureffGraph","Efficiency for fixed purity in each n_PU bin"); // loop over the directories double slope = 0.; double slopeError = -999.; double constnorm = 0.; double constError = -999.; TGraphErrors* result = NULL; TFitResultPtr fitRes(-1); double x,y, xe,ye; unsigned int index; TString histonames[nbins+1]; TString labelnames[nbins+1]; // get the histogram TH1* evts_per_PUbin = (TH1*)input->Get("finaldistros_ssvhpt/GoodJet/GoodJet_nvertices"); double sumTot(0), effTot(0); TLatex *latexLabel = new TLatex(); latexLabel->SetTextSize(0.05); latexLabel->SetTextFont(42); latexLabel->SetLineWidth(2); latexLabel->SetNDC(); TLatex *latexLabel2 = new TLatex(); latexLabel2->SetTextSize(0.09); latexLabel2->SetTextFont(42); latexLabel2->SetLineWidth(2); latexLabel2->SetNDC(); for(unsigned int i=0; i<=nbins; ++i) { // get the histogram labelnames[i]=Form("n_PU = %d bin",i); std::cout<<"labelnames["<<i<<"]"<<labelnames[i]<<std::endl; histonames[i]=Form("finaldistros_ssvhpt/GoodJet/GoodJet_jetvtx_ratio2b_%d_PUvtx",i); std::cout<<"seizing: histonames["<<i<<"]:"<<histonames[i]<<std::endl; TH1* fraction = (TH1*)input->Get(histonames[i]); //fraction->Rebin(2); // do it canvas_0->cd(i+1); fraction->SetTitle(""); MakeNiceHistoStyle(fraction); if(fraction) vertexAssociationAnalysis(fraction,i,slope,slopeError,constnorm,constError,result,fitRes); latexLabel2->DrawLatex(0.15, 0.85,labelnames[i]); latexLabel2->DrawLatex(0.15, 0.75,"CMS #sqrt{s}= 7 TeV"); gPad->Draw(); gPad->SetLogy(); MakeNiceStatBox(fraction); output->cd(); fraction->Write(); // plot canvas_1->cd(i+1); result->SetTitle(""); MakeNiceGraphStyle(result); result->Draw("alP"); latexLabel->DrawLatex(0.05, 0.95,labelnames[i]); result->GetXaxis()->SetTitle("Purity"); result->GetYaxis()->SetTitle("Efficiency"); result->GetXaxis()->SetRangeUser(0.8,1.2); result->GetYaxis()->SetRangeUser(0.85,1.0); output->cd(); result->Write(); // extract other quantities slopeGraph->SetPoint(i,i,slope); slopeGraph->SetPointError(i,0,slopeError); slopeGraph->GetXaxis()->SetTitle("n_{PU} vertices"); constGraph->SetPoint(i,i,constnorm); constGraph->SetPointError(i,0,constError); constGraph->GetXaxis()->SetTitle("n_{PU} vertices"); index = unsigned(((defaultCut-cutmin)/(cutmax-cutmin)*nSteps)+0.5); findWorkingPoint(result,index,x,y,xe,ye,1); // to compute the weighted efficiency int ivtx_bin=evts_per_PUbin->FindBin(i+1); sumTot+=evts_per_PUbin->GetBinContent(ivtx_bin); effTot+=y*evts_per_PUbin->GetBinContent(ivtx_bin); cuteffGraph->SetPoint(i,i,y); cuteffGraph->SetPointError(i,0,ye); cuteffGraph->GetXaxis()->SetTitle("n_{PU} vertices"); cutpurGraph->SetPoint(i,i,x); cutpurGraph->SetPointError(i,0,xe); cutpurGraph->GetXaxis()->SetTitle("n_{PU} vertices"); x = defaultPur; findWorkingPoint(result,index,x,y,xe,ye,2); purcutGraph->SetPoint(i,i,cutmin+(cutmax-cutmin)/nSteps*index); purcutGraph->GetXaxis()->SetTitle("n_{PU} vertices"); pureffGraph->SetPoint(i,i,y); pureffGraph->SetPointError(i,0,ye); pureffGraph->GetXaxis()->SetTitle("n_{PU} vertices"); y = defaultEff; findWorkingPoint(result,index,x,y,xe,ye,3); effcutGraph->SetPoint(i,i,cutmin+(cutmax-cutmin)/nSteps*index); effcutGraph->GetXaxis()->SetTitle("n_{PU} vertices"); effpurGraph->SetPoint(i,i,x); effpurGraph->SetPointError(i,0,xe); effpurGraph->GetXaxis()->SetTitle("n_{PU} vertices"); std::cout<<"end of other quantities: bin["<<i<<"]"<<std::endl; } std::cout << "Weighted Efficiency" << effTot/sumTot << std::endl; // plot summary graphs TF1* f=NULL; canvas_2->cd(1); MakeNiceGraphStyle(slopeGraph); slopeGraph->Draw("alP"); slopeGraph->Fit("pol1"); f = slopeGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) slopeGraph->Fit("pol0"); canvas_2->cd(2); MakeNiceGraphStyle(constGraph); constGraph->Draw("alP"); constGraph->Fit("pol2"); f = constGraph->GetFunction("pol2"); canvas_2->cd(3); MakeNiceGraphStyle(cuteffGraph); cuteffGraph->Draw("alP"); cuteffGraph->Fit("pol1"); f = cuteffGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) cuteffGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Jet Fraction cut: %.2f",defaultCut)); canvas_2->cd(4); MakeNiceGraphStyle(cutpurGraph); cutpurGraph->Draw("alP"); cutpurGraph->Fit("pol1"); f = cutpurGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) cutpurGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Jet Fraction cut: %.2f",defaultCut)); canvas_2->cd(5); MakeNiceGraphStyle(effcutGraph); effcutGraph->Draw("alP"); effcutGraph->Fit("expo"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed efficiency: %.2f",defaultEff)); canvas_2->cd(6); MakeNiceGraphStyle(effpurGraph); effpurGraph->Draw("alP"); effpurGraph->Fit("pol1"); f = effpurGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) effpurGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed efficiency: %.2f",defaultEff)); canvas_2->cd(7); gPad->SetLeftMargin(0.12); MakeNiceGraphStyle(purcutGraph); purcutGraph->Draw("alP"); purcutGraph->Fit("expo"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed purity: %.3f",defaultPur)); canvas_2->cd(8); MakeNiceGraphStyle(pureffGraph); pureffGraph->Draw("alP"); pureffGraph->Fit("pol1"); f = pureffGraph->GetFunction("pol1"); if(f->GetParError(1)>fabs(f->GetParameter(1))) pureffGraph->Fit("pol0"); latexLabel2->DrawLatex(0.15, 0.15,Form("Fixed purity: %.3f",defaultPur)); // save output->cd(); canvas_0->Write(); canvas_1->Write(); canvas_2->Write(); canvas_0->SaveAs((TString)(canvas_0->GetName())+".png"); canvas_1->SaveAs((TString)(canvas_1->GetName())+".png"); canvas_2->SaveAs((TString)(canvas_2->GetName())+".png"); }
void simul(int Nevents = 200000, double Twist_width = 0.04, double Asy_wdith = 0.06){ char name[200]; TFile *OutFile=new TFile("Simu3.root","recreate"); OutFile->cd(); TRandom3 ran; //20-25% events have ~1092 multiplicity const int MEAN_MULT =1092,SIGMA_MULT=86 ;//Mean and rms of total multiplicity (det0+det1+det2) int min=MEAN_MULT-5*SIGMA_MULT; int max=MEAN_MULT+5*SIGMA_MULT; if(min<0) min=0; TF1 *Mult_func=new TF1("mult_func","exp(-(x-[0])*(x-[0])/(2*[1]*[1]))",min,max); Mult_func->SetParameter(0,MEAN_MULT ); Mult_func->SetParameter(1,SIGMA_MULT); // TFile* fout = new TFile("toyout.root","recreate"); TF1* v2_func=new TF1("v2_func","x*exp(-(x*x+[0]*[0])/(2*[1]))*TMath::BesselI0(x*[0]/[1])",0,0.40); v2_func->SetParameter(0,9.13212e-02); v2_func->SetParameter(1,1.20361e-03); // Float_t v2 =0 ;//true v2 at eta=0, this will be the refer Float_t Psi2 =0 ;//true Psi2 at eta=0 float vncut[] = {0.00, 0.04, 0.06,0.1, 0.12, 0.14, 0.15}; TProfile* hpr_qn[2]; for (int iq=0; iq<2; iq++) { sprintf(name, "hpr_qn_%d", iq); hpr_qn[iq] = new TProfile(name,"", 7, 0, 7); } TH1* hebin = new TH1D("hebin","", 7, 0, 7); TH1* hmul = new TH1D("hmul","", 2000, 0, 2000); TH1* hmuleta = new TH1D("hmuleta","", NETA, -ETAMAX, ETAMAX); TH1* hmulphi = new TH1D("hmulphi","", 120 , -PI, PI); TH1* hv2 = new TH1D("hv2","",1000, 0, 0.5); TH1* hv4 = new TH1D("hv4","",1000, 0, 0.5); double q2[2]; double q4[2]; float qw; for(int iev=0; iev<Nevents; iev++){ if(iev%10000==0) cout<<iev<<endl; v2 = v2_func->GetRandom();//0.05;//True v2 Psi2 = ((ran.Rndm()-0.5)*2*PI)/2.0; //True Psi_2 angle // int ntrk = 1092; int ntrk = 8000; qw = 0; std::memset(q2, 0, sizeof(q2) ); std::memset(q4, 0, sizeof(q4) ); for(int itrk =0; itrk<ntrk; itrk++){ float phi = (ran.Rndm()-0.5)*2*PI;//random angle for the particle float trk_vn = v2 ; float trk_psin = Psi2; phi =add_flow(phi ,trk_vn, trk_psin); q2[0] += cos(2*phi); q2[1] += sin(2*phi); q4[0] += cos(4*phi); q4[1] += sin(4*phi); qw++; }//end of itrk double mv2 = sqrt(q2[0]*q2[0] + q2[1]*q2[1]); double mv4 = sqrt(q4[0]*q4[0] + q4[1]*q4[1]); mv2 = mv2/qw; mv4 = mv4/qw; int ebin = 0; for (int j=0; j<7; j++) { if(mv2>= vncut[7-1-j]){ ebin = 7-1-j; break; } } hv2->Fill( mv2 ); hv4->Fill( mv4 ); hpr_qn[0]->Fill(ebin, mv2); hpr_qn[1]->Fill(ebin, mv4); hebin->Fill( ebin ); }//end of iev float xx[7] = {0}; float xxE[7] = {0}; float yy[7] = {0}; float yyE[7] = {0}; for (int j=0; j<7; j++) { xx[j] =hpr_qn[0]->GetBinContent( j+1); xxE[j] =hpr_qn[0]->GetBinError( j+1); yy[j] =hpr_qn[1]->GetBinContent( j+1); yyE[j] =hpr_qn[1]->GetBinError( j+1); } TGraphErrors* gr = new TGraphErrors(7,xx, yy, xxE, yyE); hv2->Write(); hv4->Write(); gr->SetName("gr"); gr->Write(); hebin->Write(); hpr_qn[0]->Write(); hpr_qn[1]->Write(); v2_func->Write(); cout<<"Task ends"<<endl; }//end of sim
void splitUncertainties_byCat(TString inFileName, TString outFileName) { int numChannels = 15; TString channelNames[] = { //"ljets_j4_t2", // "j4_2t", "ljets_j4_t3", // "j4_3t", "ljets_j4_t4", // "j4_3t", //"ljets_j5_t2", // "j5_2t", "ljets_j5_t3", // "j5_3t", "ljets_j5_tge4", // "j5_3t", "ljets_jge6_t2", // "j6_2t", "ljets_jge6_t3", // "j6_3t", "ljets_jge6_tge4", // "j6_3t", "ge3t", // dilep >= 3tags "e2je2t", // dilep 2 jets 2 tags "e3je2t", // dilep 3 jets 2 tags "ge4je2t", // dilep >=4 jets 2 tags "SS_e3je1t", // dilep SS 3 jets 1 tags "SS_ge4je1t", // dilep SS >=4 jets 1 tags "SS_e3jge2t", // dilep SS 3 jets >=2 tags "SS_ge4jge2t", // dilep SS >=4 jets >=2 tags }; //Open the root file TFile *inFile = TFile::Open(inFileName); TFile *outFile = TFile::Open(outFileName,"RECREATE"); //Define the list of uncertainties we're going to split TList nuisancePars; nuisancePars.Add(new TObjString("CMS_eff_b")); nuisancePars.Add(new TObjString("CMS_fake_b")); //Now loop over all the histograms in the file and either copy or //Split as needed TList *keys = inFile->GetListOfKeys(); TIter nextKey(keys); TKey *key = 0; while ((key = (TKey *)nextKey())) { TString name = key->GetName(); TString newName = name; // std::cout << "Copying histogram " << name << std::endl; TH1 *hist = (TH1 *)inFile->Get(name); if( name.Contains("bShape") ){ for (int j=0; j<numChannels; j++) { if( name.Contains(channelNames[j]) ) newName.ReplaceAll("CMS",channelNames[j]); } } //Automatically copy the original histogram over outFile->cd(); hist->Write(newName); } }
/******************************************************************************** * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence version 3 (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ plots(Int_t nEvents = 1000, Int_t iout=1, TString mcEngine="TGeant3") { // Input data definitions //-----User Settings:----------------------------------------------- TString MCFile ="testrun_" + mcEngine + ".root"; TString ParFile ="testparams_" + mcEngine + ".root"; TString RecoFile ="testreco_"+ mcEngine + ".root";; // ----- Reconstruction run ------------------------------------------- FairRunAna *fRun= new FairRunAna(); fRun->SetInputFile(MCFile.Data()); fRun->AddFriend(RecoFile.Data()); FairRuntimeDb* rtdb = fRun->GetRuntimeDb(); FairParRootFileIo* parInput1 = new FairParRootFileIo(); parInput1->open(ParFile.Data()); rtdb->setFirstInput(parInput1); TFile *f1 = TFile::Open(MCFile); TFile *f2 = TFile::Open(RecoFile); TTree *t1 = f1->Get("cbmsim"); TTree *t2 = f2->Get("cbmsim"); FairMCEventHeader *MCEventHeader = new FairMCEventHeader(); TClonesArray *MCTracks = new TClonesArray("FairMCTrack"); TClonesArray *TutorialDetPoints = new TClonesArray("FairTutorialDet4Point"); TClonesArray *TutorialDetHits = new TClonesArray("FairTutorialDet4Hit"); t1->SetBranchAddress("MCEventHeader.",&MCEventHeader); t1->SetBranchAddress("MCTrack", &MCTracks); t1->SetBranchAddress("TutorialDetPoint", &TutorialDetPoints); t2->SetBranchAddress("TutorialDetHit", &TutorialDetHits); FairMCTrack *MCTrack; FairTutorialDet4Point *Point; FairTutorialDet4Hit *Hit; //histograms fRun->SetOutputFile("test.ana.root"); TFile *fHist = fRun->GetOutputFile(); Float_t xrange=80.; Float_t yrange=80.; TH2F* dxx = new TH2F("dxx","Hit; x; Delta x;",100,-xrange,xrange,50.,-10.,10.); TH2F* dyy = new TH2F("dyy","Hit; y; Delta y;",100,-yrange,yrange,50.,-10.,10.); TH1F* pullx = new TH1F("pullx","Hit; pullx;",100.,-5.,5.); TH1F* pully = new TH1F("pully","Hit; pully;",100.,-5.,5.); TH1F* pullz = new TH1F("pullz","Hit; pullz;",50.,-10.,10.); TH1F* pointx = new TH1F("pointx","Hit; posx;",200.,-80.,80.); TH1F* pointy = new TH1F("pointy","Hit; posy;",200.,-80.,80.); Int_t nMCTracks, nPoints, nHits; Float_t x_point, y_point, z_point, tof_point, SMtype_point, mod_point, cel_point, gap_point; Float_t x_poi, y_poi, z_poi; Float_t SMtype_poi, mod_poi, cel_poi, gap_poi; Float_t p_MC, px_MC, py_MC, pz_MC; Float_t x_hit, y_hit, z_hit, dy_hit; Int_t nevent = t1->GetEntries(); if (nevent > nEvents) nevent=nEvents; cout << "total number of events to process: " << nevent <<endl; // Event loop for (Int_t iev=0; iev< nevent; iev++) { // get entry t1->GetEntry(iev); t2->GetEntry(iev); nMCTracks = MCTracks->GetEntriesFast(); nPoints = TutorialDetPoints->GetEntriesFast(); nHits = TutorialDetHits->GetEntriesFast(); cout << " Event" << iev << ":"; cout << nMCTracks << " MC tracks "; cout << nPoints << " points "; cout << nHits << " Hits "<<endl; // Hit loop for (Int_t j =0; j<nHits; j++) { Hit = (FairTutorialDet4Hit*) TutorialDetHits->At(j); Int_t l = Hit->GetRefIndex(); Point = (FairTutorialDet4Point*) TutorialDetPoints->At(l); // Point info x_poi = Point -> GetX(); y_poi = Point -> GetY(); z_poi = Point -> GetZ(); // Hit info x_hit = Hit->GetX(); y_hit = Hit->GetY(); z_hit = Hit->GetZ(); dy_hit = Hit->GetDy(); // Int_t flg_hit = Hit->GetFlag(); Float_t delta_x = x_poi - x_hit; Float_t delta_y = y_poi - y_hit; Float_t delta_z = z_poi - z_hit; dxx ->Fill(x_poi,delta_x); dyy ->Fill(y_poi,delta_y); pullx ->Fill(delta_x); pully ->Fill(delta_y); pullz ->Fill(delta_z); pointx ->Fill(x_hit); pointy ->Fill(y_hit); } // Hit loop end } // event loop end // save histos to file // TFile *fHist = TFile::Open("data/auaumbias.hst.root","RECREATE"); cout << "Processing done, outflag =" <<iout << endl; if (iout==1){ fHist->Write(); if(0){ // explicit writing TIter next(gDirectory->GetList()); TH1 *h; TObject* obj; while(obj= (TObject*)next()){ if(obj->InheritsFrom(TH1::Class())){ h = (TH1*)obj; cout << "Write histo " << h->GetTitle() << endl; h->Write(); } } } fHist->ls(); fHist->Close(); } // ----- Finish ------------------------------------------------------- cout << endl << endl; // Extract the maximal used memory an add is as Dart measurement // This line is filtered by CTest and the value send to CDash FairSystemInfo sysInfo; Float_t maxMemory=sysInfo.GetMaxMemory(); cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">"; cout << maxMemory; cout << "</DartMeasurement>" << endl; timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); Float_t cpuUsage=ctime/rtime; cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">"; cout << cpuUsage; cout << "</DartMeasurement>" << endl; cout << endl << endl; cout << "Output file is " << outFile << endl; cout << "Parameter file is " << parFile << endl; cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl; cout << "Macro finished successfully." << endl; // ------------------------------------------------------------------------ }
void comparisonJetMCData(string plot,int rebin){ string tmp; string dir="/gpfs/cms/data/2011/Observables/"; //string dir=plotpath; if (isAngularAnalysis){ mcfile=dir+"MC_zjets"+version; back_w=dir+"MC_wjets"+version; back_ttbar=dir+"MC_ttbar"+version; WW=dir+"MC_diW"+version; ZZ=dir+"MC_siZ"+version; WZ=dir+"MC_diWZ"+version; datafile=dir+"DATA"+version; } // List of files TFile *dataf = TFile::Open(datafile.c_str()); //data file TFile *mcf = TFile::Open(mcfile.c_str()); //MC file TFile *ttbarf = TFile::Open(back_ttbar.c_str()); //MC background file TFile *wf = TFile::Open(back_w.c_str()); TFile *qcd23emf = TFile::Open(qcd23em.c_str()); TFile *qcd38emf = TFile::Open(qcd38em.c_str()); TFile *qcd817emf = TFile::Open(qcd817em.c_str()); TFile *qcd23bcf = TFile::Open(qcd23bc.c_str()); TFile *qcd38bcf = TFile::Open(qcd38bc.c_str()); TFile *qcd817bcf = TFile::Open(qcd817bc.c_str()); TFile *WZf = TFile::Open(WZ.c_str()); TFile *ZZf = TFile::Open(ZZ.c_str()); TFile *WWf = TFile::Open(WW.c_str()); // Canvas if (CanvPlot) delete CanvPlot; CanvPlot = new TCanvas("CanvPlot","CanvPlot",0,0,800,600); // Getting, defining ... dataf->cd("validationJEC"); TObject * obj; gDirectory->GetObject(plot.c_str(),obj); TH1 *data; TH2F *data2; TH1D *data3; THStack *hs = new THStack("hs","Total MC"); int flag=-1; if ((data = dynamic_cast<TH1F *>(obj)) ){ flag=1; gROOT->Reset(); gROOT->ForceStyle(); gStyle->SetPadRightMargin(0.03); gPad->SetLogy(1); gPad->Modified(); gPad->Update(); } if ((data2 = dynamic_cast<TH2F *>(obj)) ){ flag=2; gStyle->SetPalette(1); gStyle->SetPadRightMargin(0.15); gPad->Modified(); } //=================== // Dirty jobs :) if (flag==1){ CanvPlot->cd(); TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1); pad1->Draw(); pad1->cd(); pad1->SetLogy(1); TString str=data->GetTitle(); if (str.Contains("jet") && !str.Contains("zMass") && !str.Contains("Num") && !str.Contains("Eta") && !str.Contains("Phi") && !str.Contains("eld") && !str.Contains("meanPtZVsNjet")) { if (!isAngularAnalysis) rebin=5; } //====================== // DATA Double_t dataint = data->Integral(); data->SetLineColor(kBlack); data->Rebin(rebin); if(str.Contains("nJetVtx")) data->GetXaxis()->SetRangeUser(0,10); if(str.Contains("zMass")) data->GetXaxis()->SetRangeUser(70,110); data->SetMinimum(1.); data->Sumw2(); data->Draw("E1"); TLegend* legend = new TLegend(0.825,0.57,0.95,0.72); legend->SetFillColor(0); legend->SetFillStyle(0); legend->SetBorderSize(0); legend->AddEntry(data,"data","p"); // hack to calculate some yields in restricted regions... int num1=0, num2=0, num3=0, num4=0, num5=0; if(str.Contains("invMass") && !str.Contains("PF")){ for(int j=1;j<=data->GetNbinsX();j++){ num1 += data->GetBinContent(j); //conto quante Z ci sono tra 60 e 120 GeV if(j>10&&j<=50) num2 += data->GetBinContent(j); // ... tra 70 e 110 if(j>15&&j<=45) num3 += data->GetBinContent(j); // ... tra 75 e 105 } cout << "\n"; cout << data->GetNbinsX() <<" Number of bins of the invmass histo\n"; printf("Number of Z in 60-120 %i --- 70-110 %i --- 75-105 %i \n",num1,num2,num3); cout << "\n"; } if(str.Contains("zYieldVsjets") && !str.Contains("Vtx")){ for(int j=1;j<=data->GetNbinsX();j++){ num1 += data->GetBinContent(j); //conto quante Z if(j>1) num2 += data->GetBinContent(j); // ... +1,2,3,4... jets if(j>2) num3 += data->GetBinContent(j); // ... +2,3,4... jets if(j>3) num4 += data->GetBinContent(j); // .. if(str=="jet_pT"){ if(j>4) num5 += data->GetBinContent(j); // ... +4... jets } cout << "\n"; cout << data->GetNbinsX() <<" Number of bins of the zYieldVsjets histo\n"; printf("Number of Z+n jet %i --- >1 %i --- >2 %i --- >3 %i --- >4 %i \n",num1,num2,num3,num4,num5); cout << "\n"; } //====================== // Z + jets signal mcf->cd("validationJEC"); TH1F* mc; gDirectory->GetObject(plot.c_str(),mc); TH1F * hsum; if(mc){ hsum = (TH1F*) mc->Clone(); hsum->SetTitle("hsum"); hsum->SetName("hsum"); hsum->Reset(); Double_t mcint = mc->Integral(); mc->SetFillColor(kRed); mc->Sumw2(); if(lumiweights==0) mc->Scale(dataint/mcint); // Blocco da propagare negli altri MC if(zNumEvents>0.){ if(lumiweights==1) { if (WholeStat){ if (lumiPixel) mc->Scale( dataLumi2011pix / (zNumEvents / zjetsXsect)); else mc->Scale( dataLumi2011 / (zNumEvents / zjetsXsect)); } else{ if (RunA){ if (lumiPixel) mc->Scale( dataLumi2011Apix / (zNumEvents / zjetsXsect)); else mc->Scale( dataLumi2011A / (zNumEvents / zjetsXsect)); } if (!RunA){ if (lumiPixel) mc->Scale( dataLumi2011Bpix / (zNumEvents / zjetsXsect)); else mc->Scale( dataLumi2011B / (zNumEvents / zjetsXsect)); } } } } else { if(lumiweights==1) mc->Scale(zjetsScale); } // fin qui if(lumiweights==1) mc->Scale(1./zwemean); // perche' i Weights non fanno 1... mc->Rebin(rebin); if(lumiweights==0) mc->Draw("HISTO SAMES"); hsum->Rebin(rebin); hsum->Add(mc); legend->AddEntry(mc,"Z+jets","f"); } //====================== // ttbar ttbarf->cd("validationJEC"); TH1F* ttbar; gDirectory->GetObject(plot.c_str(),ttbar); if(ttbar){ ttbar->SetFillColor(kBlue); ttbar->Sumw2(); if(ttNumEvents>0.){ if(lumiweights==1) { if (WholeStat){ if (lumiPixel) ttbar->Scale( dataLumi2011pix / (ttNumEvents / ttbarXsect)); else ttbar->Scale( dataLumi2011 / (ttNumEvents / ttbarXsect)); } else{ if (RunA){ if (lumiPixel) ttbar->Scale( dataLumi2011Apix / (ttNumEvents / ttbarXsect)); else ttbar->Scale( dataLumi2011A / (ttNumEvents / ttbarXsect)); } if (!RunA){ if (lumiPixel) ttbar->Scale( dataLumi2011Bpix / (ttNumEvents / ttbarXsect)); else ttbar->Scale( dataLumi2011B / (ttNumEvents / ttbarXsect)); } } } } else { if(lumiweights==1) ttbar->Scale(ttwemean); } // fin qui if(lumiweights==1) ttbar->Scale(1./ttwemean); // perche' i Weights non fanno 1... ttbar->Rebin(rebin); if(lumiweights==0) ttbar->Draw("HISTO SAMES"); hsum->Rebin(rebin); hsum->Add(ttbar); if(lumiweights==1)legend->AddEntry(ttbar,"ttbar","f"); ////////// //Storing the bckgrounds! ////////// if(str=="jet_pT") evaluateAndFillBackgrounds(ttbar,"jet_pT"); if(str=="jet_pT2") evaluateAndFillBackgrounds(ttbar,"jet_pT2"); if(str=="jet_pT3") evaluateAndFillBackgrounds(ttbar,"jet_pT3"); if(str=="jet_pT4") evaluateAndFillBackgrounds(ttbar,"jet_pT4"); if(str=="Jet_multi") evaluateAndFillBackgrounds(ttbar,"jet_Multiplicity"); } //====================== // w+jets wf->cd("validationJEC"); TH1F* w; gDirectory->GetObject(plot.c_str(),w); if(w){ w->SetFillColor(kViolet+2); w->Sumw2(); if(wNumEvents>0.){ if(lumiweights==1) { if (WholeStat){ if (lumiPixel) w->Scale( dataLumi2011pix / (wNumEvents / wjetsXsect)); else w->Scale( dataLumi2011 / (wNumEvents / wjetsXsect)); } else{ if (RunA){ if (lumiPixel) w->Scale( dataLumi2011Apix / (wNumEvents / wjetsXsect)); else w->Scale( dataLumi2011A / (wNumEvents / wjetsXsect)); } if (!RunA){ if (lumiPixel) w->Scale( dataLumi2011Bpix / (wNumEvents / wjetsXsect)); else w->Scale( dataLumi2011B / (wNumEvents / wjetsXsect)); } } } } else { if(lumiweights==1) w->Scale(wwemean); } // fin qui if(lumiweights==1) w->Scale(1./wwemean); // perche' i Weights non fanno 1... w->Rebin(rebin); if(lumiweights==0) w->Draw("HISTO SAMES"); hsum->Rebin(rebin); hsum->Add(w); if(lumiweights==1)legend->AddEntry(w,"W+jets","f"); } //====================== // wz+jets WZf->cd("validationJEC"); TH1F* wz; gDirectory->GetObject(plot.c_str(),wz); if(wz){ wz->SetFillColor(kYellow+2); wz->Sumw2(); if(wzEvents>0.){ if(lumiweights==1) { if (WholeStat){ if (lumiPixel) wz->Scale( dataLumi2011pix / (wzEvents / WZXsect)); else wz->Scale( dataLumi2011 / (wzEvents / WZXsect)); } else{ if (RunA){ if (lumiPixel) wz->Scale( dataLumi2011Apix / (wzEvents / WZXsect)); else wz->Scale( dataLumi2011A / (wzEvents / WZXsect)); } if (!RunA){ if (lumiPixel) wz->Scale( dataLumi2011Bpix / (wzEvents / WZXsect)); else wz->Scale( dataLumi2011B / (wzEvents / WZXsect)); } } } } else { if(lumiweights==1) wz->Scale(wzjetsScale); } // fin qui if(lumiweights==1) wz->Scale(1./wzwemean); // perche' i Weights non fanno 1... wz->Rebin(rebin); if(lumiweights==0) wz->Draw("HISTO SAMES"); hsum->Rebin(rebin); hsum->Add(wz); legend->AddEntry(wz,"WZ+jets","f"); ////////// //Storing the bckgrounds! ////////// if(str=="jet_pT") evaluateAndFillBackgrounds(wz,"jet_pT"); if(str=="jet_pT2") evaluateAndFillBackgrounds(wz,"jet_pT2"); if(str=="jet_pT3") evaluateAndFillBackgrounds(wz,"jet_pT3"); if(str=="jet_pT4") evaluateAndFillBackgrounds(wz,"jet_pT4"); if(str=="Jet_multi") evaluateAndFillBackgrounds(wz,"jet_Multiplicity"); } //====================== // zz+jets ZZf->cd("validationJEC"); TH1F* zz; gDirectory->GetObject(plot.c_str(),zz); if(zz){ zz->SetFillColor(kOrange+2); zz->Sumw2(); if(zzEvents>0.){ if(lumiweights==1) { if (WholeStat){ if (lumiPixel) zz->Scale( dataLumi2011pix / (zzEvents / ZZXsect)); else zz->Scale( dataLumi2011 / (zzEvents / ZZXsect)); } else{ if (RunA){ if (lumiPixel) zz->Scale( dataLumi2011Apix / (zzEvents / ZZXsect)); else zz->Scale( dataLumi2011A / (zzEvents / ZZXsect)); } if (!RunA){ if (lumiPixel) zz->Scale( dataLumi2011Bpix / (zzEvents / ZZXsect)); else zz->Scale( dataLumi2011B / (zzEvents / ZZXsect)); } } } } else { if(lumiweights==1) zz->Scale(zzjetsScale); } // fin qui if(lumiweights==1) zz->Scale(1./zzwemean); // perche' i Weights non fanno 1... zz->Rebin(rebin); if(lumiweights==0) zz->Draw("HISTO SAMES"); hsum->Rebin(rebin); hsum->Add(zz); legend->AddEntry(zz,"ZZ+jets","f"); ////////// //Storing the bckgrounds! ////////// if(str=="jet_pT") evaluateAndFillBackgrounds(zz,"jet_pT"); if(str=="jet_pT2") evaluateAndFillBackgrounds(zz,"jet_pT2"); if(str=="jet_pT3") evaluateAndFillBackgrounds(zz,"jet_pT3"); if(str=="jet_pT4") evaluateAndFillBackgrounds(zz,"jet_pT4"); if(str=="Jet_multi") evaluateAndFillBackgrounds(zz,"jet_Multiplicity"); } //====================== // ww+jets WWf->cd("validationJEC"); TH1F* ww; gDirectory->GetObject(plot.c_str(),ww); if(ww){ ww->SetFillColor(kBlack); ww->Sumw2(); if(wwEvents>0.){ if(lumiweights==1) { if (WholeStat){ if (lumiPixel) ww->Scale( dataLumi2011pix / (wwEvents / WWXsect)); else ww->Scale( dataLumi2011 / (wwEvents / WWXsect)); } else{ if (RunA){ if (lumiPixel) ww->Scale( dataLumi2011Apix / (wwEvents / WWXsect)); else ww->Scale( dataLumi2011A / (wwEvents / WWXsect)); } if (!RunA){ if (lumiPixel) ww->Scale( dataLumi2011Bpix / (wwEvents / WWXsect)); else ww->Scale( dataLumi2011B / (wwEvents / WWXsect)); } } } } else { if(lumiweights==1) ww->Scale(wwjetsScale); } // fin qui if(lumiweights==1) ww->Scale(1./wwwemean); // perche' i Weights non fanno 1... ww->Rebin(rebin); if(lumiweights==0) ww->Draw("HISTO SAMES"); hsum->Rebin(rebin); hsum->Add(ww); legend->AddEntry(ww,"WW+jets","f"); ////////// //Storing the bckgrounds! ////////// if(str=="jet_pT") evaluateAndFillBackgrounds(ww,"jet_pT"); if(str=="jet_pT2") evaluateAndFillBackgrounds(ww,"jet_pT2"); if(str=="jet_pT3") evaluateAndFillBackgrounds(ww,"jet_pT3"); if(str=="jet_pT4") evaluateAndFillBackgrounds(ww,"jet_pT4"); if(str=="Jet_multi") evaluateAndFillBackgrounds(ww,"jet_Multiplicity"); } ///////// // Print the bkg contributions //////// for(int j=0;j<bckg_leadingJetPt.size();j++){ cout<<bckg_leadingJetPt[j]<<endl; } //====================== // QCD EM enriched qcd23emf->cd("validationJEC"); TH1F* qcd23emp; gDirectory->GetObject(plot.c_str(),qcd23emp); if(qcd23emp){ TH1D * qcdTotEM = (TH1D*) qcd23emp->Clone(); qcdTotEM->SetTitle("qcd em"); qcdTotEM->SetName("qcd em"); qcdTotEM->Reset(); qcdTotEM->Rebin(rebin); qcd38emf->cd("validationJEC"); TH1F* qcd38emp; gDirectory->GetObject(plot.c_str(),qcd38emp); qcd817emf->cd("validationJEC"); TH1F* qcd817emp; gDirectory->GetObject(plot.c_str(),qcd817emp); qcd23emp->Rebin(rebin); qcd23emp->Sumw2(); qcd23emp->Scale(qcd23emScale); qcd38emp->Rebin(rebin); qcd38emp->Sumw2(); qcd38emp->Scale(qcd38emScale); qcd817emp->Rebin(rebin); qcd817emp->Sumw2(); qcd817emp->Scale(qcd817emScale); qcdTotEM->SetFillColor(kOrange+1); qcdTotEM->Add(qcd23emp); qcdTotEM->Add(qcd38emp); qcdTotEM->Add(qcd817emp); hsum->Add(qcdTotEM); if(lumiweights==1)legend->AddEntry(qcdTotEM,"QCD em","f"); } //====================== // QCD bc qcd23bcf->cd("validationJEC"); TH1F* qcd23bcp; TH1D * qcdTotBC; bool qcdbcempty=true; gDirectory->GetObject(plot.c_str(),qcd23bcp); if(qcd23bcp){ qcdTotBC = (TH1D*) qcd23bcp->Clone(); qcdTotBC->SetTitle("qcd bc"); qcdTotBC->SetName("qcd bc"); qcdTotBC->Reset(); qcdTotBC->Rebin(rebin); qcd38bcf->cd("validationJEC"); TH1F* qcd38bcp; gDirectory->GetObject(plot.c_str(),qcd38bcp); qcd817bcf->cd("validationJEC"); TH1F* qcd817bcp; gDirectory->GetObject(plot.c_str(),qcd817bcp); qcd23bcp->Rebin(rebin); qcd23bcp->Sumw2(); qcd23bcp->Scale(qcd23bcScale); qcd38bcp->Rebin(rebin); qcd38bcp->Sumw2(); qcd38bcp->Scale(qcd38bcScale); qcd817bcp->Rebin(rebin); qcd817bcp->Sumw2(); qcd817bcp->Scale(qcd817bcScale); qcdTotBC->SetFillColor(kGreen+2); qcdTotBC->Add(qcd23bcp); qcdTotBC->Add(qcd38bcp); qcdTotBC->Add(qcd817bcp); hsum->Add(qcdTotBC); if (qcdTotBC->GetEntries()>0) qcdbcempty=false; if(lumiweights==1)legend->AddEntry(qcdTotBC,"QCD bc","f"); } //====================== // Add here other backgrounds //====================== // Stacked Histogram //if(qcd23em) hs->Add(qcdTotEM); if(!qcdbcempty) hs->Add(qcdTotBC); if (ww) hs->Add(ww); if (ttbar) hs->Add(ttbar); if(w) hs->Add(w); if (zz) hs->Add(zz); if (wz) hs->Add(wz); if(mc) hs->Add(mc); //Z+Jets // per avere le statistiche if(lumiweights==1) hsum->Draw("HISTO SAMES"); //====================== // Setting the stats pad1->Update(); // altrimenti non becchi la stat TPaveStats *r2; if(lumiweights==0) r2 = (TPaveStats*)mc->FindObject("stats"); if(lumiweights==1) r2 = (TPaveStats*)hsum->FindObject("stats"); r2->SetY1NDC(0.875); r2->SetY2NDC(0.75); r2->SetTextColor(kRed); if(lumiweights==1) hs->Draw("HISTO SAME"); gPad->RedrawAxis(); data->Draw("E1 SAMES"); r2->Draw(); legend->Draw(); TLegend* lumi = new TLegend(0.45,0.3,0.75,0.2); lumi->SetFillColor(0); lumi->SetFillStyle(0); lumi->SetBorderSize(0); lumi->AddEntry((TObject*)0,"#int L dt =4.9 1/fb",""); lumi->Draw(); //TLatex *latexLabel=CMSPrel(4.890,"",0.65,0.9); // make fancy label //latexLabel->Draw("same"); CanvPlot->Update(); //===============// // RATIO DATA MC // //===============// CanvPlot->cd(); TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3); pad2->Draw(); pad2->cd(); TH1D * ratio = (TH1D*) data->Clone(); ratio->SetTitle("ratio"); ratio->SetName("ratio"); ratio->Reset(); ratio->Sumw2(); //data->Sumw2(); hsum->Sumw2(); // FIXME controlla che sia corretto questo... ratio->SetMarkerSize(.5); ratio->SetLineColor(kBlack); ratio->SetMarkerColor(kBlack); gStyle->SetOptStat("m"); TH1F* sumMC; hs->Draw("nostack"); sumMC=(TH1F*) hs->GetHistogram(); ratio->Divide(data,hsum,1.,1.); ratio->GetYaxis()->SetRangeUser(0,2); pad2->SetTopMargin(1); ratio->Draw("E1"); TLine *OLine = new TLine(ratio->GetXaxis()->GetXmin(),1.,ratio->GetXaxis()->GetXmax(),1.); OLine->SetLineColor(kBlack); OLine->SetLineStyle(2); OLine->Draw(); TLegend* label = new TLegend(0.60,0.9,0.50,0.95); label->SetFillColor(0); label->SetFillStyle(0); label->SetBorderSize(0); //horrible mess double binContent = 0; double binSum = 0; double weightSum = 0; double binError = 1; double totalbins = ratio->GetSize() -2; for(unsigned int bin=1;bin<=totalbins;bin++){ binContent = ratio->GetBinContent(bin); binError = ratio->GetBinError(bin); if(binError!=0){ binSum += binContent/binError; weightSum += 1./binError; } } double ymean = binSum / weightSum; //double ymean = ratio->GetMean(2); stringstream sYmean; sYmean << ymean; string labeltext=sYmean.str()+" mean Y"; //label->AddEntry((TObject*)0,labeltext.c_str(),""); // mean on Y //label->Draw(); TPaveStats *r3 = (TPaveStats*)ratio->FindObject("stats"); r3->SetX1NDC(0.01); r3->SetX2NDC(0.10); r3->SetY1NDC(0.20); r3->SetY2NDC(0.50); gStyle->SetOptStat("mr"); r3->SetTextColor(kWhite); r3->SetLineColor(kWhite); r3->Draw(); CanvPlot->Update(); tmp=plotpath+plot+".png"; CanvPlot->Print(tmp.c_str()); OutputFile->cd(); string plotTmp; plotTmp = plot+"Ratio"; ratio->SetName(plotTmp.c_str()); ratio->Write(); plotTmp = plot+"Data"; data->SetName(plotTmp.c_str()); data->Write(); plotTmp = plot+"MC"; hsum->SetName(plotTmp.c_str()); hsum->Write(); } else if (flag==2){ //CanvPlot.Divide(2,1); //CanvPlot.cd(1); // data dataf->cd("validationJEC"); gDirectory->GetObject(plot.c_str(),data2); data2->Draw("COLZ"); gPad->Update(); // altrimenti non becchi la stat TPaveStats *r1 = (TPaveStats*)data2->FindObject("stats"); r1->SetX1NDC(0.70); r1->SetX2NDC(0.85); r1->Draw(); CanvPlot->Update(); tmp=plotpath+plot+"data.png"; CanvPlot->Print(tmp.c_str()); //CanvPlot.cd(2); // montecarlo mcf->cd("validationJEC"); gDirectory->GetObject(plot.c_str(),data2); data2->SetMinimum(1); data2->Draw("COLZ"); gPad->Update(); // altrimenti non becchi la stat TPaveStats *r2 = (TPaveStats*)data2->FindObject("stats"); r2->SetX1NDC(0.70); r2->SetX2NDC(0.85); r2->Draw(); CanvPlot->Update(); tmp=plotpath+plot+"mc.png"; CanvPlot->Print(tmp.c_str()); } // else { cout << "You're getting an exception! Most likely there's no histogram here... \n"; } delete data; delete data2; delete hs; //delete CanvPlot; dataf->Close(); mcf->Close(); ttbarf->Close(); wf->Close(); qcd23emf->Close(); qcd38emf->Close(); qcd817emf->Close(); qcd23bcf->Close(); qcd38bcf->Close(); qcd817bcf->Close(); WZf->Close(); ZZf->Close(); if (bckg_leadingJetPt.size()>0 && bckg_2leadingJetPt.size()>0 && bckg_3leadingJetPt.size()>0 && bckg_4leadingJetPt.size()>0 && bckg_JetMultiplicity.size()>0 && cold){ fzj->cd(); treeBKG_->Fill(); treeBKG_->Write(); TH1F *leadhisto=new TH1F("leadhisto","leading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size()); TH1F *leadhisto2=new TH1F("leadhisto2","subleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size()); TH1F *leadhisto3=new TH1F("leadhisto3","subsubleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size()); TH1F *leadhisto4=new TH1F("leadhisto4","subsubsubleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size()); TH1F *multiphisto=new TH1F("multiphisto","jet multiplicity background contribution",bckg_JetMultiplicity.size(),0,bckg_JetMultiplicity.size()); for (int i=0; i< bckg_leadingJetPt.size(); i++){ leadhisto->Fill(i,bckg_leadingJetPt[i]); leadhisto2->Fill(i,bckg_2leadingJetPt[i]); leadhisto3->Fill(i,bckg_3leadingJetPt[i]); leadhisto4->Fill(i,bckg_4leadingJetPt[i]); } leadhisto->Write(); leadhisto2->Write(); leadhisto3->Write(); leadhisto4->Write(); //fzj->Close(); for (int i=0; i< bckg_JetMultiplicity.size(); i++){ multiphisto->Fill(i,bckg_JetMultiplicity[i]); } multiphisto->Write(); cold=false; } return; }
void FakeLeptonPlotter::writeFakeRate(string extension) { for( unsigned int iVar = 0; iVar < nHistograms; ++iVar ) { if( configContainer.addOverflow ) { histogramContainers[iVar].addOverflow(); } if( configContainer.addUnderflow ) { histogramContainers[iVar].addUnderflow(); } HistogramContainer fakeHistCont("fake_rate_" + histogramContainers[iVar].containerName, 1); vector<TH1*> hMC; bool hasEwkCorrection = false; for( unsigned int iSample = 0; iSample < nSamples; ++iSample ) { if( histogramContainers[iVar].sampleType[iSample] == SampleType::DATA ) { fakeHistCont.add(histogramContainers[iVar], iSample); } else if( configContainer.sampleContainer.sampleType[iSample] == SampleType::MC ) { hMC.push_back(histogramContainers[iVar].histograms[iSample]); hasEwkCorrection = true; } } // Add QCD signal for( unsigned int iSample = 0; iSample < nSamples; ++iSample ) { if( histogramContainers[iVar].sampleType[iSample] == SampleType::SIGNAL ) { fakeHistCont.add(histogramContainers[iVar], iSample); } } // EKW MC correction if( hasEwkCorrection ) { // Add data without ewk correction fakeHistCont.add(fakeHistCont, 0); fakeHistCont.color.back() += 3; fakeHistCont.reducedNames.back() += "_before_ewk_correction"; fakeHistCont.histograms.back() = (TH1*) fakeHistCont.histograms[0]->Clone(); } for( TH1* h : hMC ) { fakeHistCont.histograms[0]->Add(h, -1.); } // Seperate Numerator and Denominator if( histogramContainers[iVar].containerName.find("lepton") != string::npos ) { if( histogramContainers[iVar].containerName.find("loose") != string::npos ) { hDenomVector.push_back(fakeHistCont.histograms); } else { fakeHistogramContainers.push_back(fakeHistCont); } } } for( unsigned int iFake = 0; iFake < fakeHistogramContainers.size(); ++iFake ) { for( unsigned int iHist = 0; iHist < fakeHistogramContainers[iFake].histograms.size(); ++iHist ) { // remove underflow in numerator, important for TGraphAsymmErrors to work! fakeHistogramContainers[iFake].histograms[iHist]->ClearUnderflowAndOverflow(); // fill empty/negative bins unsigned int nBins = fakeHistogramContainers[iFake].histograms[iHist]->GetNcells(); for( unsigned int i = 0; i < (nBins+2); ++i ) { if( hDenomVector[iFake][iHist]->GetBinContent(i) <= 0) { hDenomVector[iFake][iHist]->SetBinContent(i,1.); fakeHistogramContainers[iFake].histograms[iHist]->SetBinContent(i,0.); } if( fakeHistogramContainers[iFake].histograms[iHist]->GetBinContent(i) < 0.) { fakeHistogramContainers[iFake].histograms[iHist]->SetBinContent(i,0); } if( fakeHistogramContainers[iFake].histograms[iHist]->GetBinContent(i) > hDenomVector[iFake][iHist]->GetBinContent(i) ) { fakeHistogramContainers[iFake].histograms[iHist]->SetBinContent(i,hDenomVector[iFake][iHist]->GetBinContent(i)); } } } // Make plots BasePlotter::writeEfficiency(fakeHistogramContainers[iFake], hDenomVector[iFake], extension); } // Write histrograms system(("mkdir -p " + configContainer.outputDir).c_str()); TFile* f = new TFile((configContainer.outputDir + "Fakerate.root").c_str(), "RECREATE"); for( unsigned int iFake = 0; iFake < fakeHistogramContainers.size(); ++iFake ) { if( fakeHistogramContainers[iFake].histograms[0]->GetDimension() == 1 ) { // Write Data FR TGraphAsymmErrors* tgraph = new TGraphAsymmErrors(fakeHistogramContainers[iFake].histograms[0], hDenomVector[iFake][0], "cl=0.683 b(1,1) mode"); tgraph->Write(); // Write MC signal FR for( unsigned int iHist = 0; iHist < fakeHistogramContainers[iFake].histograms.size(); ++iHist ) { if( fakeHistogramContainers[iFake].sampleType[iHist] == SampleType::SIGNAL ) { TGraphAsymmErrors* tgraph = new TGraphAsymmErrors(fakeHistogramContainers[iFake].histograms[iHist], hDenomVector[iFake][iHist], "cl=0.683 b(1,1) mode"); tgraph->Write();; } } } else { // Write Data FR TH1* hTemp = (TH1*) fakeHistogramContainers[iFake].histograms[0]->Clone(); hTemp->Divide(hDenomVector[iFake][0]); hTemp->Write(); // Write MC signal FR for( unsigned int iHist = 0; iHist < fakeHistogramContainers[iFake].histograms.size(); ++iHist ) { if( fakeHistogramContainers[iFake].sampleType[iHist] == SampleType::SIGNAL ) { TH1* hTemp = (TH1*) fakeHistogramContainers[iFake].histograms[iHist]->Clone(); hTemp->Divide(hDenomVector[iFake][iHist]); hTemp->Write(); } } } } f->Close(); // verbose output for( unsigned int iVar = 0; iVar < fakeHistogramContainers.size(); ++iVar ) { if( iVar == 0 ) BasePlotter::writeHist("fake_lepton_intermediate.root", fakeHistogramContainers[iVar].histograms, "RECREATE"); else BasePlotter::writeHist("fake_lepton_intermediate.root", fakeHistogramContainers[iVar].histograms, "UPDATE"); BasePlotter::writeHist("fake_lepton_intermediate.root", hDenomVector[iVar], "UPDATE"); } }
void CalcAcceptanceSystematicsFromScale(){ char tempname[200]; TFile * infile = new TFile("LostLepton2_MuonEfficienciesFromAll_Elog408_.root","R"); TH1* hScaleAccPass, * hScaleAccAll, * hScaleAccPass_lowDphi, * hScaleAccAll_lowDphi; vector<TH1*> hScaleAccVec, hScaleAcc_lowDphiVec, hScaleAcc_DeviationFromNomVec, hScaleAcc_DeviationFromNom_lowDphiVec; int Scalesize = 9; // 101 pdf for(int iacc=0; iacc < Scalesize; iacc++){ // get the pass sprintf(tempname,"ScaleAcc/hScaleAccPass_%d",iacc); hScaleAccPass = (TH1*) infile->Get(tempname)->Clone(); // get the all sprintf(tempname,"ScaleAcc/hScaleAccAll_%d",iacc); hScaleAccAll = (TH1*) infile->Get(tempname)->Clone(); // divide the pass and all to get acc sprintf(tempname,"hScaleAccVec_%d",iacc); hScaleAccVec.push_back(static_cast<TH1*>(hScaleAccPass->Clone(tempname))); hScaleAccVec[iacc]->Divide(hScaleAccPass,hScaleAccAll,1,1,"B"); cout << " bin5=> acc: " << hScaleAccVec[iacc]->GetBinContent(5) << endl; // lowDphi sprintf(tempname,"ScaleAcc/hScaleAccPass_lowDphi_%d",iacc); hScaleAccPass_lowDphi = (TH1*) infile->Get(tempname)->Clone(); sprintf(tempname,"ScaleAcc/hScaleAccAll_lowDphi_%d",iacc); hScaleAccAll_lowDphi = (TH1*) infile->Get(tempname)->Clone(); sprintf(tempname,"hScaleAcc_lowDphiVec_%d",iacc); hScaleAcc_lowDphiVec.push_back(static_cast<TH1*>(hScaleAccPass_lowDphi->Clone(tempname))); hScaleAcc_lowDphiVec[iacc]->Divide(hScaleAccPass_lowDphi,hScaleAccAll_lowDphi,1,1,"B"); // calculate the deviation from nominal acceptance hScaleAcc_DeviationFromNomVec.push_back(static_cast<TH1*>(hScaleAccVec[iacc]->Clone("hScaleAcc_DeviationFromNomVec")));// copy hScaleAcc_DeviationFromNomVec[iacc]->Add(hScaleAccVec[0],-1.0); // subtract the nominal from each acceptance: Acc - Acc_nom // do the same for lowDphi hScaleAcc_DeviationFromNom_lowDphiVec.push_back(static_cast<TH1*>(hScaleAcc_lowDphiVec[iacc]->Clone("hScaleAcc_DeviationFromNom_lowDphiVec")));// copy hScaleAcc_DeviationFromNom_lowDphiVec[iacc]->Add(hScaleAcc_lowDphiVec[0],-1.0); // subtract the nominal from each acceptance: Acc - Acc_nom }// end of loop over pdf TH1 * hScaleAccSysMax = static_cast<TH1*>(hScaleAccAll->Clone("hScaleAccSysMax")); hScaleAccSysMax->Reset(); TH1 * hScaleAccSysMax_lowDphi = static_cast<TH1*>(hScaleAccAll_lowDphi->Clone("hScaleAccSysMax_lowDphi")); hScaleAccSysMax_lowDphi->Reset(); TH1 * hScaleAccSysMin = static_cast<TH1*>(hScaleAccAll->Clone("hScaleAccSysMin")); hScaleAccSysMin->Reset(); TH1 * hScaleAccSysMin_lowDphi = static_cast<TH1*>(hScaleAccAll_lowDphi->Clone("hScaleAccSysMin_lowDphi")); hScaleAccSysMin_lowDphi->Reset(); for(int ibin=0; ibin < hScaleAccSysMax->GetNbinsX()+2; ibin++){ //cout << "bincontent: " << hScaleAccSysMax->GetBinContent(ibin) << endl; for(int iacc=0; iacc < Scalesize; iacc++){ if(hScaleAccSysMax->GetBinContent(ibin)<hScaleAcc_DeviationFromNomVec[iacc]->GetBinContent(ibin)){ hScaleAccSysMax->SetBinContent(ibin,hScaleAcc_DeviationFromNomVec[iacc]->GetBinContent(ibin)); // get the max of all acc } if(hScaleAccSysMax_lowDphi->GetBinContent(ibin)<hScaleAcc_DeviationFromNom_lowDphiVec[iacc]->GetBinContent(ibin)){ hScaleAccSysMax_lowDphi->SetBinContent(ibin,hScaleAcc_DeviationFromNom_lowDphiVec[iacc]->GetBinContent(ibin)); } if(hScaleAccSysMin->GetBinContent(ibin)>hScaleAcc_DeviationFromNomVec[iacc]->GetBinContent(ibin)){ hScaleAccSysMin->SetBinContent(ibin,hScaleAcc_DeviationFromNomVec[iacc]->GetBinContent(ibin)); // get the max of all acc } if(hScaleAccSysMin_lowDphi->GetBinContent(ibin)>hScaleAcc_DeviationFromNom_lowDphiVec[iacc]->GetBinContent(ibin)){ hScaleAccSysMin_lowDphi->SetBinContent(ibin,hScaleAcc_DeviationFromNom_lowDphiVec[iacc]->GetBinContent(ibin)); } } } TFile * outFile = new TFile("AcceptanceSystematicsFromScale_AllSamples.root","RECREATE"); hScaleAccSysMax->Write(); hScaleAccSysMax_lowDphi->Write(); hScaleAccSysMin->Write(); hScaleAccSysMin_lowDphi->Write(); for(int iacc=0; iacc < Scalesize ; iacc++){ hScaleAccVec[iacc]->Write(); hScaleAcc_lowDphiVec[iacc]->Write(); } outFile->Close(); }
void CombinePreScale() { double jetptbin[] = {27, 33, 39, 47, 55, 64,74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 429, 692, 1000}; int nbins = sizeof(jetptbin)/sizeof(double)-1; TString kDir="/scratch/xuq7/RpA/TreeAna"; TString algo ="akPu3PF"; //"AkPu3PF" ; TString residual = "NoResidual"; //"NoResidual" ; TString coll = "PPbNoGplus" ; // or "PbP" ; TString class = "HFsumEta4Bin1" ; // "" for inclusive ; TString effTab = "TrkEffHIN12017v5TrkCorr2DCut" ; //"HistIterTrkCorrtestFilterCut"; // "Trk" ; "HistIterTrkCorrtest" ; const int Nfile = 5 ; TFile * f ; TString name[]={"jetptEta","jetptphi","jetEtaphi","jetptchMax","jetptchSum","jetptneuMax","jetptneuSum","jetptphoMax","jetptphoSum","jetptchMaxpt","jetptchSumpt","jetptneuMaxpt","jetptneuSumpt","jetptphoMaxpt","jetptphoSumpt","jetptSumSumpt","jetptSumSumrawpt","jetptneuMaxr","jetptchN","jetptneuN","jetptphoN"}; TString etaname[]={"jetpt","rawptJES","jetptchMaxpt","jetptneuMaxr","jetptSumSumpt"}; int nname=sizeof(name)/sizeof(TString); int netaname=sizeof(etaname)/sizeof(TString); f = TFile::Open(Form("%s/AllTrigLumiDATAPPb%sDiJetMass.root",kDir.Data(),algo.Data()),"readonly"); TString outname ; outname ="Datacombined.root"; TFile * outf = new TFile(Form("%s/%s", kDir.Data(), outname.Data()), "RECREATE"); // f = TFile::Open("AllTrigLumiDATAPPbakPu3PFDiJetMass.root", "readonly"); for(int m=0;m<nname;m++){ TH1 *hCombined; TH1 *hTrkPt[5]; hTrkPt[0] = (TH1*)f->Get(Form("Jet20%s_0-100%%",name[m].Data())); hTrkPt[1] = (TH1*)f->Get(Form("Jet40%s_0-100%%",name[m].Data())); hTrkPt[2] = (TH1*)f->Get(Form("Jet60%s_0-100%%",name[m].Data())); hTrkPt[3] = (TH1*)f->Get(Form("Jet80%s_0-100%%",name[m].Data())); hTrkPt[4] = (TH1*)f->Get(Form("Jet100%s_0-100%%",name[m].Data())); for( int i = 0; i<5; i++) { if(i==0){ hCombined = (TH1*)hTrkPt[i]->Clone(Form("%sCombinedSpectra",name[m].Data())); hCombined->SetTitle(""); } else hCombined->Add(hTrkPt[i]); } hCombined->Write(); } double etaMin[8] = {-1.,-2.2,-1.2,-0.7,-0.3,0.3,0.7,1.2}; double etaMax[8] = { 1.,-1.2,-0.7,-0.3, 0.3,0.7,1.2,2.2}; TH1* hTrk[8][5]; TH1* hCombinedEtaBin[8]; for(int m=0;m<netaname;m++){ for(int ieta=0; ieta<8; ieta++){ if(ieta==0){ hTrk[ieta][0] = (TH1*)f->Get(Form("Jet20%s_0-100%%",etaname[m].Data())); hTrk[ieta][1] = (TH1*)f->Get(Form("Jet40%s_0-100%%",etaname[m].Data())); hTrk[ieta][2] = (TH1*)f->Get(Form("Jet60%s_0-100%%",etaname[m].Data())); hTrk[ieta][3] = (TH1*)f->Get(Form("Jet80%s_0-100%%",etaname[m].Data())); hTrk[ieta][4] = (TH1*)f->Get(Form("Jet100%s_0-100%%",etaname[m].Data())); } else { hTrk[ieta][0] = (TH1*)f->Get(Form("Jet20%sEtaBin%.f_%.f_Cen0-100%%",etaname[m].Data(), etaMin[ieta]*10, etaMax[ieta]*10)); hTrk[ieta][1] = (TH1*)f->Get(Form("Jet40%sEtaBin%.f_%.f_Cen0-100%%",etaname[m].Data(), etaMin[ieta]*10, etaMax[ieta]*10)); hTrk[ieta][2] = (TH1*)f->Get(Form("Jet60%sEtaBin%.f_%.f_Cen0-100%%",etaname[m].Data(), etaMin[ieta]*10, etaMax[ieta]*10)); hTrk[ieta][3] = (TH1*)f->Get(Form("Jet80%sEtaBin%.f_%.f_Cen0-100%%",etaname[m].Data(), etaMin[ieta]*10, etaMax[ieta]*10)); hTrk[ieta][4] = (TH1*)f->Get(Form("Jet100%sEtaBin%.f_%.f_Cen0-100%%",etaname[m].Data(), etaMin[ieta]*10, etaMax[ieta]*10)); } for(int i = 0; i<5; i++) { if(i==0) { hCombinedEtaBin[ieta] = (TH1*)hTrk[ieta][i]->Clone(Form("%sCombinedSpectraInEtaBin%.f_%.f",etaname[m].Data(), etaMin[ieta]*10, etaMax[ieta]*10)); hCombinedEtaBin[ieta]->SetTitle(""); } else hCombinedEtaBin[ieta]->Add(hTrk[ieta][i]); } hCombinedEtaBin[ieta]->Write(); } } outf->Close();//write into a root file }
// === Main Function =================================================== void hadTau2(unsigned int id = 11, const TString &effName = "../data/LostLepton_MuonEfficienciesFromWJetMC.root", const TString &respTempl = "../data/HadTau_TauResponseTemplates.root", int nEvts = -1) { const bool isMC = ( id >= 10 ); // --- Declare the Output Histograms --------------------------------- const TString title = isMC ? "Hadronic-Tau Closure Test" : "Hadronic-Tau Prediction"; // Control plot: muon pt in the control sample TH1* hMuonPt = new TH1D("hMuonPt",title+";p_{T}(#mu^{gen}) [GeV];N(events)",50,0.,500.); hMuonPt->Sumw2(); // Predicted distributions TH1* hPredHt = new TH1D("hPredHt",title+";H_{T} [GeV];N(events)",25,500.,3000.); hPredHt->Sumw2(); TH1* hPredMht = new TH1D("hPredMht",title+";#slash{H}_{T} [GeV];N(events)",20,200.,1200.); hPredMht->Sumw2(); TH1* hPredNJets = new TH1D("hPredNJets",title+";N(jets);N(events)",9,3,12); hPredNJets->Sumw2(); // In case of MC: true distributions TH1* hTrueHt = static_cast<TH1*>(hPredHt->Clone("hTrueHt")); TH1* hTrueMht = static_cast<TH1*>(hPredMht->Clone("hTrueMht")); TH1* hTrueNJets = static_cast<TH1*>(hPredNJets->Clone("hTrueNJets")); // Event yields in the different RA2 search bins // First bin (around 0) is baseline selection TH1* hPredYields = new TH1D("hPredYields",title+";;N(events)",37,-0.5,36.5); hPredYields->Sumw2(); hPredYields->GetXaxis()->SetBinLabel(1,"baseline"); for(int bin = 2; bin <= hPredYields->GetNbinsX(); ++bin) { TString label = "Bin "; label += bin-1; hPredYields->GetXaxis()->SetBinLabel(bin,label); } TH1* hTrueYields = static_cast<TH1*>(hPredYields->Clone("hTrueYields")); // --- Tau Templates and Muon Efficiencies --------------------------- // Interface to the tau response templates TauResponse tauResp(respTempl); // Interfaces to the muon acceptance as well as reconstruction and // isolation efficiencies LeptonAcceptance muonAcc(effName,LeptonAcceptance::nameMuonAcc()); LeptonEfficiency muonRecoEff(effName,LeptonEfficiency::nameMuonRecoEff()); LeptonEfficiency muonIsoEff(effName,LeptonEfficiency::nameMuonIsoEff()); // --- Analyse the events -------------------------------------------- // Interface to the event content Event* evt = new Event(Sample::fileNameFullSample(id),nEvts); // Loop over the events (tree entries) while( evt->loadNext() ) { // Select the control sample: // - select events with exactly one well-reconstructed, isolated muon // Use the muon to predict the energy deposits of the // hadronically decaying tau: // - scale the muon pt by a random factor drawn from the // tau-reponse template to simulate the tau measurement // - use the simulated tau-pt to predict HT, MHT, and N(jets) if( evt->isoMuonsN() == 1 && evt->isoElectronsN() == 0 ) { // The kinematic properties of the well-reconstructed, isolated muon const float muPt = evt->isoMuonsPt()[0]; const float muEta = evt->isoMuonsEta()[0]; const float muPhi = evt->isoMuonsPhi()[0]; // Use only events where the muon is inside acceptance if( muPt < TauResponse::ptMin() ) continue; if( std::abs( muEta ) > TauResponse::etaMax() ) continue; // "Cross cleaning": find the jet that corresponds to // the muon. Associate the jet that is closest in // in eta-phi space to the lepton int muJetIdx = -1; const float deltaRMax = 0.2; if( !utils::findMatchedObject(muJetIdx,muEta,muPhi,evt->jetsEta(),evt->jetsPhi(),evt->jetsN(),deltaRMax) ) continue; // Calculate RA2 selection-variables from "cleaned" jets int selNJet = 0; float selHt = 0.; float selMhtX = 0.; float selMhtY = 0.; for(int jetIdx = 0; jetIdx < evt->jetsN(); ++jetIdx) { // Loop over reco jets // Skip this jet if it is the muon if( jetIdx == muJetIdx ) continue; // Calculate NJet and HT if( evt->jetsPt()[jetIdx] > Selection::htJetPtMin() && std::abs(evt->jetsEta()[jetIdx]) < Selection::htJetEtaMax() ) { selNJet++; selHt += evt->jetsPt()[jetIdx]; } // Calculate MHT if( evt->jetsPt()[jetIdx] > Selection::mhtJetPtMin() && std::abs(evt->jetsEta()[jetIdx]) < Selection::mhtJetEtaMax() ) { selMhtX -= evt->jetsPt()[jetIdx]*cos(evt->jetsPhi()[jetIdx]); selMhtY -= evt->jetsPt()[jetIdx]*sin(evt->jetsPhi()[jetIdx]); } } // End of loop over reco jets // Select only events with at least 2 HT jets if( selNJet < 2 ) continue; // Plot the muon pt as control plot hMuonPt->Fill(muPt); // Get random number from tau-response template // The template is chosen according to the muon pt const float scale = tauResp.getRandom(muPt); // Scale muon pt with tau response --> simulate tau jet pt const float simTauJetPt = scale * muPt; const float simTauJetEta = muEta; const float simTauJetPhi = muPhi; // Taking into account the simulated tau jet, recompute // HT, MHT, and N(jets) int simNJet = selNJet; float simHt = selHt; float simMhtX = selMhtX; float simMhtY = selMhtY; // If simulted tau-jet meets same criteria as as HT jets, // recompute NJets and HT if( simTauJetPt > Selection::htJetPtMin() && std::abs(muEta) < Selection::htJetEtaMax() ) { simNJet++; simHt += simTauJetPt; } // If simulated tau-jet meets same criteria as MHT jets, // recompute MHT if( simTauJetPt > Selection::mhtJetPtMin() && std::abs(muEta) < Selection::mhtJetEtaMax() ) { simMhtX -= simTauJetPt*cos(muPhi); simMhtY -= simTauJetPt*sin(muPhi); } const float simMht = sqrt( simMhtX*simMhtX + simMhtY*simMhtY ); const float simMhtPhi = std::atan2(simMhtY,simMhtX); // Apply baseline selection if( !Selection::nJets(simNJet) ) continue; if( !Selection::ht(simHt) ) continue; if( !Selection::mht(simMht) ) continue; if( !deltaPhi(simMhtPhi,evt->jetsN(),evt->jetsPt(),evt->jetsEta(),evt->jetsPhi(),muJetIdx,simTauJetPt,simTauJetEta,simTauJetPhi) ) continue; // Corrections to control sample const double corrBRWToTauHad = 0.65; // Correction for the BR of hadronic tau decays const double corrBRTauToMu = 1./1.15; // Correction for the fact that some muons could come from leptonic decays of taus from W decays const double acc = muonAcc(evt->mht(),evt->nJets()); const double recoEff = muonRecoEff(evt->ht(),evt->mht(),evt->nJets()); const double isoEff = muonIsoEff(evt->ht(),evt->mht(),evt->nJets()); if( !( acc > 0. && recoEff > 0. && isoEff > 0. ) ) continue; const double corrMuAcc = 1./acc; // Correction for muon acceptance const double corrMuRecoEff = 1./recoEff; // Correction for muon reconstruction efficiency const double corrMuIsoEff = 1./isoEff; // Correction for muon isolation efficiency // The overall correction factor const double corr = corrBRTauToMu * corrBRWToTauHad * corrMuAcc * corrMuRecoEff * corrMuIsoEff; // Fill the prediction hPredHt->Fill(simHt,corr); hPredMht->Fill(simMht,corr); hPredNJets->Fill(simNJet,corr); // Predicted event yields hPredYields->Fill(0.,corr); const unsigned int searchBin = Selection::searchBin(simHt,simMht,simNJet); if( searchBin > 0 ) { hPredYields->Fill(searchBin,corr); } } // End if exactly one muon if( isMC ) { // Fill the 'truth' for comparison with the prediction // Select only events where the W decayed into a hadronically // decaying tau if( !( evt->flgW() == 15 && evt->flgTau() == 1 ) ) continue; // Apply baseline selection if( !Selection::nJets(evt->nJets()) ) continue; if( !Selection::ht(evt->ht()) ) continue; if( !Selection::mht(evt->mht()) ) continue; if( !Selection::deltaPhi(evt->deltaPhi1(),evt->deltaPhi2(),evt->deltaPhi3()) ) continue; hTrueHt->Fill(evt->ht()); hTrueMht->Fill(evt->mht()); hTrueNJets->Fill(evt->nJets()); // True event yields hTrueYields->Fill(0.); const unsigned int searchBin = Selection::searchBin(evt->ht(),evt->mht(),evt->nJets()); if( searchBin > 0 ) { hTrueYields->Fill(searchBin); } } // End isMC } // End of loop over events // --- Save the Histograms to File ----------------------------------- const TString outFileName = isMC ? "HadTau_WJetMC_Closure.root" : "HadTau_Data_Prediction.root"; TFile outFile(outFileName,"RECREATE"); hMuonPt->Write(); hTrueHt->Write(); hTrueMht->Write(); hTrueNJets->Write(); hTrueYields->Write(); hPredHt->Write(); hPredMht->Write(); hPredNJets->Write(); hPredYields->Write(); outFile.Close(); }
void PerformanceSpectrumUncorr(const Char_t *fname = "HFEtask.root"){ gROOT->SetStyle("Plain"); gStyle->SetTitleFillColor(0); gStyle->SetTitleBorderSize(0); gStyle->SetTitleX(0.1); gStyle->SetTitleY(0.96); TFile *in = TFile::Open(fname); TList *res = (TList *)in->Get("HFE_Results"); TList *qa = (TList *)in->Get("HFE_QA"); gROOT->cd(); AliHFEcontainer *tcont = dynamic_cast<AliHFEcontainer *>(res->FindObject("trackContainer")); AliCFContainer *c = tcont->GetCFContainer("recTrackContReco"); AliCFContainer *cb = tcont->GetCFContainer("hadronicBackground"); TH1 *spec = c->Project(c->GetNStep() - 1, 0); spec->GetXaxis()->SetTitle("p_{T} / GeV/c"); spec->GetYaxis()->SetTitle("#frac{dN}{dp_{T}} / (GeV/c)^{-1}"); spec->GetXaxis()->SetRangeUser(ptmin, ptmax); spec->GetYaxis()->SetTitleOffset(1.1); spec->SetTitle(); spec->SetStats(kFALSE); spec->SetLineColor(kBlue); spec->SetLineWidth(1); spec->SetMarkerColor(kBlue); spec->SetMarkerStyle(22); // Produce background subtracted spectrum AliCFDataGrid tracks("tracks", "track grid", *c, c->GetNStep() - 1); AliCFDataGrid background("background", "background grid", *cb, 1); tracks.ApplyBGCorrection(background); TH1 *spec_subtracted = tracks.Project(0); spec_subtracted->GetXaxis()->SetTitle("p_{T} / GeV/c"); spec_subtracted->GetYaxis()->SetTitle("#frac{dN}{dp_{T}} / (GeV/c)^{-1}"); spec_subtracted->GetXaxis()->SetRangeUser(ptmin, ptmax); spec_subtracted->GetYaxis()->SetTitleOffset(1.1); spec_subtracted->SetTitle(); spec_subtracted->SetStats(kFALSE); spec_subtracted->SetLineColor(kRed); spec_subtracted->SetLineWidth(1); spec_subtracted->SetMarkerColor(kRed); spec_subtracted->SetMarkerStyle(22); TLegend *leg = new TLegend(0.2, 0.25, 0.4, 0.35); leg->SetBorderSize(0); leg->SetFillStyle(0); leg->AddEntry(spec, "Raw Spectrum", "p"); leg->AddEntry(spec_subtracted, "Spectrum after background subtraction", "p"); TCanvas *c1 = new TCanvas("cspec", "Single-inclusive electron spectrum", 1200, 750); c1->cd(); c1->SetLogy(); c1->SetGridx(kFALSE); c1->SetGridy(kFALSE); spec->Draw("ep"); spec_subtracted->Draw("epsame"); leg->Draw(); ALICEWorkInProgress(c1, "today"); // PID TList *pidqa = (TList *)qa->FindObject("HFEpidQA"); AliHFEtpcPIDqa *tpcqa = (AliHFEtpcPIDqa *)pidqa->FindObject("TPCQA"); AliHFEtofPIDqa *tofqa = (AliHFEtofPIDqa *)pidqa->FindObject("TOFQA"); // Make Plots for TPC // Create histograms by projecting the THnSparse TH2 *hTPCall = tpcqa->MakeSpectrumdEdx(AliHFEdetPIDqa::kBeforePID); TH2 *hTPCselected = tpcqa->MakeSpectrumdEdx(AliHFEdetPIDqa::kAfterPID); TH2 *hTPCsigmaAll = tpcqa->MakeSpectrumNSigma(AliHFEdetPIDqa::kBeforePID); TH2* hTPCsigmaSelected = tpcqa->MakeSpectrumNSigma(AliHFEdetPIDqa::kAfterPID); // Make Plots for TOF TH2 *hTOFsigmaAll = tofqa->MakeSpectrumNSigma(AliHFEdetPIDqa::kBeforePID); TH2 *hTOFsigmaSelected = tofqa->MakeSpectrumNSigma(AliHFEdetPIDqa::kAfterPID); hTPCsigmaAll->SetTitle("TPC n#sigma around the electron line"); hTPCsigmaSelected->SetTitle("TPC n#sigma around the electron line for selected tracks"); hTOFsigmaAll->SetTitle("TOF n#sigma around the electron line"); hTOFsigmaSelected->SetTitle("TOF n#sigma around the electron line for selected tracks"); DefineTPChisto(hTPCall, "TPC Signal / a.u"); DefineTPChisto(hTPCselected, "TPC Signal / a.u."); DefineTPChisto(hTPCsigmaAll, "TPC Sigma"); DefineTPChisto(hTPCsigmaSelected, "TPC Sigma"); // Also make nice histograms for TOF DefineTPChisto(hTOFsigmaAll, "TOF Sigma"); DefineTPChisto(hTOFsigmaSelected, "TOF Sigma"); // Plot them TCanvas *c2 = new TCanvas("cTPCall", "TPC Signal for all tracks", 640, 480); c2->cd(); c2->SetGridx(kFALSE); c2->SetGridy(kFALSE); c2->SetLogx(); c2->SetLogz(); hTPCall->GetYaxis()->SetRangeUser(40., 100.); hTPCall->Draw("colz"); ALICEWorkInProgress(c2, "today"); TCanvas *c3 = new TCanvas("cTPCsel", "TPC Signal for selected tracks", 640, 480); c3->cd(); c3->SetGridx(kFALSE); c3->SetGridy(kFALSE); c3->SetLogx(); c3->SetLogz(); hTPCselected->GetYaxis()->SetRangeUser(40., 100.); hTPCselected->Draw("colz"); ALICEWorkInProgress(c3, "today"); TCanvas *c4 = new TCanvas("cTPCsigAll", "TPC Sigma for all tracks", 640, 480); c4->cd(); c4->SetGridx(kFALSE); c4->SetGridy(kFALSE); c4->SetLogx(); c4->SetLogz(); //hTPCsigmaAll->GetYaxis()->SetRangeUser(-3.5, 5.); hTPCsigmaAll->Draw("colz"); ALICEWorkInProgress(c4, "today"); TCanvas *c5 = new TCanvas("cTPCsigSel", "TPC Sigma for selected tracks", 640, 480); c5->cd(); c5->SetGridx(kFALSE); c5->SetGridy(kFALSE); c5->SetLogx(); c5->SetLogz(); hTPCsigmaSelected->GetYaxis()->SetRangeUser(-3.5, 5.); hTPCsigmaSelected->Draw("colz"); ALICEWorkInProgress(c5, "today"); TCanvas *c6 = new TCanvas("cTOFsigAll", "TOF Sigma for all tracks", 640, 480); c6->cd(); c6->SetGridx(kFALSE); c6->SetGridy(kFALSE); c6->SetLogx(); c6->SetLogz(); hTOFsigmaAll->Draw("colz"); ALICEWorkInProgress(c6, "today"); TCanvas *c7 = new TCanvas("cTOFsigSel", "TOF Sigma for selected tracks", 640, 480); c7->cd(); c7->SetGridx(kFALSE); c7->SetGridy(kFALSE); c7->SetLogx(); c7->SetLogz(); //hTOFsigmaSelected->GetYaxis()->SetRangeUser(-3, 3); hTOFsigmaSelected->Draw("colz"); ALICEWorkInProgress(c7, "today"); TFile *output = new TFile("Performance.root", "RECREATE"); output->cd(); spec->Write(); hTPCall->Write(); hTPCselected->Write(); hTPCsigmaAll->Write(); hTPCsigmaSelected->Write(); c1->Write(); c2->Write(); c3->Write(); c4->Write(); c5->Write(); c6->Write(); c7->Write(); output->Close(); delete output; }
void MassPlotterSingleTop::singleTopAnalysis(TList* allCuts, Long64_t nevents ,TString myfileName ){ TopUtilities topUtils ; int lumi = 0; TIter nextcut(allCuts); TObject *objcut; std::vector<TString> alllabels; while( objcut = nextcut() ){ ExtendedCut* thecut = (ExtendedCut*)objcut ; alllabels.push_back( thecut->Name ); } //alllabels.push_back( "NoCut" ); alllabels.push_back( "Trigger" ); //alllabels.push_back( "MuonSelection" ); //alllabels.push_back( "MuonVeto1" ); //alllabels.push_back( "MuonVeto" ); alllabels.push_back( "== 1#mu" ); alllabels.push_back( "== 2-Jets" ); alllabels.push_back( "== 1-bJet" ); alllabels.push_back( "MT >50 GeV" ); //alllabels.push_back( "j'-bVeto" ); alllabels.push_back( "mtop" ); //cout << alllabels.size() << endl; ExtendedObjectProperty cutflowtable("" , "cutflowtable" , "1" , alllabels.size() , 0 , alllabels.size() , "2", {}, &alllabels ); ExtendedObjectProperty cutflowtablew1("" , "cutflowtablew1" , "1" , alllabels.size() , 0 , alllabels.size() , "2", {}, &alllabels ); TString fileName = fOutputDir; if(!fileName.EndsWith("/")) fileName += "/"; Util::MakeOutputDir(fileName); bool printEventIds = false; vector< ofstream* > EventIdFiles; if(printEventIds){ for( int i = 0 ; i < alllabels.size() ; i++ ){ ofstream* filetxt = new ofstream(fileName + "/IPM_" + myfileName + "_step" + boost::lexical_cast<string>(i) + ".txt" ); EventIdFiles.push_back( filetxt ); } } ExtendedObjectProperty nJetsBeforeCut("LeptonVeto" , "nJets" , "1" , 8 , 0 , 8 , "2", {}); ExtendedObjectProperty nJets20_47("OneBjet" , "nJets20_47" , "1" , 8 , 0 , 8 , "2", {}); ExtendedObjectProperty nJets20_24("OneBjet" , "nJets20_24" , "1" , 8 , 0 , 8 , "2", {}); ExtendedObjectProperty nbJets("Jets" , "nbJets" , "1" , 3 , 0 , 3 , "2", {}); ExtendedObjectProperty MTBeforeCut("OneBjetNoMT" , "MT" , "1" , 30 , 0 , 300 , "2", {}); ExtendedObjectProperty nPVBeforeCutsUnCorr("nPVBeforeCutsUnCorr" , "nPVBeforeCutsUnCorr" , "1" , 100 , 0 , 100 , "2", {}); ExtendedObjectProperty nPVBeforeCuts("nPVBeforeCuts" , "nPVBeforeCuts" , "1" , 100 , 0 , 100 , "2", {}); ExtendedObjectProperty nPVAfterCutsUnCorr("nPVAfterCutsUnCorr" , "nPVAfterCutsUnCorr" , "1" , 100 , 0 , 100 , "2", {}); ExtendedObjectProperty nPVAfterCuts("nPVAfterCuts" , "nPVAfterCuts" , "1" , 100 , 0 , 100 , "2", {}); ExtendedObjectProperty TopMass("OneBjet" , "TopMass" , "1" , 30 , 100 , 400 , "2", {}); ExtendedObjectProperty jprimeEta("OneBjet" , "jPrimeEta" , "1" , 10 , 0 , 5.0 , "2", {}); ExtendedObjectProperty jprimeEtaSB("SideBand" , "jPrimeEtaSB" , "1" , 10 , 0 , 5.0 , "2", {}); ExtendedObjectProperty jprimePt("OneBjet" , "jPrimePt" , "1" , 30 , 30 , 330 , "2", {}); ExtendedObjectProperty muPtOneB("OneBjet" , "muPt" , "1" , 20 , 20 , 120 , "2", {}); ExtendedObjectProperty muCharge("OneBjet" , "muCharge" , "1" , 40 , -2 , 2 , "2", {}); ExtendedObjectProperty muEtaOneB("OneBjet" , "muEta" , "1" , 10 , -2.5 , 2.5 , "2", {}); ExtendedObjectProperty METOneBSR("OneBjet" , "MET_SR" , "1" , 20 , 0 , 200 , "2", {}); ExtendedObjectProperty METOneBSB("OneBjet" , "MET_SB" , "1" , 20 , 0 , 200 , "2", {}); ExtendedObjectProperty METOneBAll("OneBjet" , "MET_ALL" , "1" , 20 , 0 , 200 , "2", {}); ExtendedObjectProperty bPtOneB("OneBjet" , "bPt" , "1" , 30 , 30 , 330 , "2", {}); ExtendedObjectProperty bEtaOneB("OneBjet" , "bEta" , "1" , 10 , 0 , 5.0 , "2", {}); ExtendedObjectProperty nonbCSV("OneBjet" , "jpCSV" , "1" , 20 , 0 , 1.0 , "2", {}); ExtendedObjectProperty nLbjets1EJ24("1EJ24" , "nLbJets_1EJ24" , "1" , 2 , 0 , 2 , "2", {}); ExtendedObjectProperty nTbjets1EJ24("1EJ24" , "nTbJets_1EJ24" , "1" , 2 , 0 , 2 , "2", {}); ExtendedObjectProperty nLbjets2EJ24("2EJ24" , "nLbJets_2EJ24" , "1" , 3 , 0 , 3 , "2", {}); ExtendedObjectProperty nTbjets2EJ24("2EJ24" , "nTbJets_2EJ24" , "1" , 3 , 0 , 3 , "2", {}); ExtendedObjectProperty nLbjets3EJ24("3EJ24" , "nLbJets_3EJ24" , "1" , 4 , 0 , 4 , "2", {}); ExtendedObjectProperty nTbjets3EJ24("3EJ24" , "nTbJets_3EJ24" , "1" , 4 , 0 , 4 , "2", {}); ExtendedObjectProperty nLbjets4EJ24("4EJ24" , "nLbJets_4EJ24" , "1" , 5 , 0 , 5 , "2", {}); ExtendedObjectProperty nTbjets4EJ24("4EJ24" , "nTbJets_4EJ24" , "1" , 5 , 0 , 5 , "2", {}); ExtendedObjectProperty nLbjets1EJ47("1EJ47" , "nLbJets_1EJ47" , "1" , 2 , 0 , 2 , "2", {}); ExtendedObjectProperty nTbjets1EJ47("1EJ47" , "nTbJets_1EJ47" , "1" , 2 , 0 , 2 , "2", {}); ExtendedObjectProperty nLbjets2EJ47("2EJ47" , "nLbJets_2EJ47" , "1" , 3 , 0 , 3 , "2", {}); ExtendedObjectProperty nTbjets2EJ47("2EJ47" , "nTbJets_2EJ47" , "1" , 3 , 0 , 3 , "2", {}); ExtendedObjectProperty nLbjets3EJ47("3EJ47" , "nLbJets_3EJ47" , "1" , 4 , 0 , 4 , "2", {}); ExtendedObjectProperty nTbjets3EJ47("3EJ47" , "nTbJets_3EJ47" , "1" , 4 , 0 , 4 , "2", {}); ExtendedObjectProperty nLbjets4EJ47("4EJ47" , "nLbJets_4EJ47" , "1" , 5 , 0 , 5 , "2", {}); ExtendedObjectProperty nTbjets4EJ47("4EJ47" , "nTbJets_4EJ47" , "1" , 5 , 0 , 5 , "2", {}); TH1* hTopMass = new TH1D("hTopMass" , "Top Mass" , 500 , 0 , 500 ); TH1* hTopMassEtaJ = new TH2D( "hTopMassEtaJ" , "Top Mass" , 500 , 0 , 500 , 20 , 0 , 5.0 ); TH1* hEtajPDFScales[102]; double ScalesPDF[102]; double CurrentPDFWeights[102]; for(int i=0 ; i < 102 ; i++){ TString s(to_string(i)); hEtajPDFScales[i] = new TH1D( TString("hEtaJp_PDF")+s , "" , 10 , 0 , 5.0 ); ScalesPDF[i] = 0 ; CurrentPDFWeights[i] = 0; } TH1* hEtajWScales[9]; double WScalesTotal[9]; double CurrentLHEWeights[9]; for(int i=0; i < 9; i++){ TString s(to_string(i)); hEtajWScales[i] = new TH1D( TString("hEtaJp_")+s , "" , 10 , 0 , 5.0 ); WScalesTotal[i] = 0 ; CurrentLHEWeights[i] = 0; } std::vector<ExtendedObjectProperty*> allProps = {&cutflowtable, &cutflowtablew1 , &nJetsBeforeCut , &nbJets , &MTBeforeCut, &TopMass , &jprimeEta , &jprimeEtaSB , &jprimePt , &muPtOneB, &muCharge, &muEtaOneB , &METOneBSR ,&METOneBSB , &METOneBAll , & bPtOneB , &bEtaOneB , &nonbCSV ,&nJets20_24, &nJets20_47,&nPVAfterCuts, &nPVBeforeCuts , &nPVAfterCutsUnCorr , &nPVBeforeCutsUnCorr}; std::vector<ExtendedObjectProperty*> JbJOptimizationProps = {&nLbjets1EJ24,&nTbjets1EJ24,&nLbjets2EJ24,&nTbjets2EJ24,&nLbjets3EJ24,&nTbjets3EJ24,&nLbjets4EJ24,&nTbjets4EJ24,&nLbjets1EJ47,&nTbjets1EJ47,&nLbjets2EJ47,&nTbjets2EJ47,&nLbjets3EJ47,&nTbjets3EJ47,&nLbjets4EJ47,&nTbjets4EJ47}; nextcut.Reset(); //codes for 2j0t selection TFile *theTreeFile = NULL; if(IsQCD==1) theTreeFile = new TFile( (fileName+ myfileName + "_Trees.root" ).Data(), "RECREATE"); double MT_QCD_Tree , TOPMASS_QCD_Tree , MuIso_QCD_Tree , Weight_QCD_Tree; TTree* theQCD_Tree = NULL; //end of 2j0t for(int ii = 0; ii < fSamples.size(); ii++){ int data = 0; sample Sample = fSamples[ii]; TEventList* list = 0; if(Sample.type == "data"){ data = 1; }else lumi = Sample.lumi; if( theTreeFile ){ TString treename = Sample.sname ; if( data ) treename = "Data"; if( theTreeFile->Get( treename ) ){ theQCD_Tree = (TTree*) (theTreeFile->Get( treename )) ; }else{ theTreeFile->cd(); theQCD_Tree = new TTree( treename , treename + " tree for QCD shape/normalization studies" ); theQCD_Tree->Branch( "MT/D" , &MT_QCD_Tree ); theQCD_Tree->Branch( "TOPMASS/D" , &TOPMASS_QCD_Tree ); theQCD_Tree->Branch( "MuIso/D" , &MuIso_QCD_Tree ); theQCD_Tree->Branch( "Weight/D" , &Weight_QCD_Tree ); } } double Weight = Sample.xsection * Sample.kfact * Sample.lumi / (Sample.nevents*Sample.PU_avg_weight); //Weight = 1.0; if(data == 1) Weight = 1.0; Sample.Print(Weight); SingleTopTree fTree( Sample.tree ); Sample.tree->SetBranchStatus("*", 1); string lastFileName = ""; Long64_t nentries = Sample.tree->GetEntries(); Long64_t maxloop = min(nentries, nevents); int counter = 0; double EventsIsPSeudoData ; int cutPassCounter = 0; for (Long64_t jentry=0; jentry<maxloop;jentry++, counter++) { Sample.tree->GetEntry(jentry); // //cout << fTree.Event_EventNumber << endl; // if( !(fTree.Event_EventNumber == 11112683 || fTree.Event_EventNumber == 11112881 ) ){ // //cout << " " ; // continue; // } // else{ // cutPassCounter ++ ; // cout << cutPassCounter << " : " << fTree.Event_EventNumber << " : " << endl; // } EventsIsPSeudoData = PSeudoDataRandom->Uniform(); if( lastFileName.compare( ((TChain*)Sample.tree)->GetFile()->GetName() ) != 0 ) { for(auto prop : allProps) prop->SetTree( Sample.tree , Sample.type, Sample.sname ); for(auto prop2 : JbJOptimizationProps ) prop2->SetTree( Sample.tree , Sample.type, Sample.sname ); nextcut.Reset(); while( objcut = nextcut() ){ ExtendedCut* thecut = (ExtendedCut*)objcut ; thecut->SetTree( Sample.tree , Sample.name , Sample.sname , Sample.type , Sample.xsection, Sample.nevents, Sample.kfact , Sample.PU_avg_weight); } lastFileName = ((TChain*)Sample.tree)->GetFile()->GetName() ; cout << "new file : " << lastFileName << endl; } if ( counter == 100000 ){ fprintf(stdout, "\rProcessed events: %6d of %6d ", jentry + 1, nentries); fflush(stdout); counter = 0; } nextcut.Reset(); double weight = Weight; if( !data ){ weight *= fTree.Event_puWeight ; } if( Sample.UseLHEWeight ){ //cout << "SIGNAL" << endl; weight *= fTree.Event_LHEWeightSign ; // if(fTree.Event_LHEWeightSign < 0.0) // cout << fTree.Event_LHEWeightSign << endl; } #ifdef SingleTopTreeLHEWeights_h for( int i = 0 ; i < 102 ; i++ ){ CurrentPDFWeights[i] = fTree.GetPDFWeight(i)/fabs(fTree.Event_LHEWeight) ; ScalesPDF[i] += CurrentPDFWeights[i] ; } if( Sample.name == "WJets" || Sample.name == "Signal" ){ if(fTree.GetLHEWeight(0) != fTree.Event_LHEWeight0) cout << "Wrong GetLHEWeight(0) Value" << endl; if(fTree.GetLHEWeight(1) != fTree.Event_LHEWeight1) cout << "Wrong GetLHEWeight(1) Value" << endl; if(fTree.GetLHEWeight(2) != fTree.Event_LHEWeight2) cout << "Wrong GetLHEWeight(2) Value" << endl; if(fTree.GetLHEWeight(3) != fTree.Event_LHEWeight3) cout << "Wrong GetLHEWeight(3) Value" << endl; if(fTree.GetLHEWeight(4) != fTree.Event_LHEWeight4) cout << "Wrong GetLHEWeight(4) Value" << endl; if(fTree.GetLHEWeight(5) != fTree.Event_LHEWeight5) cout << "Wrong GetLHEWeight(5) Value" << endl; if(fTree.GetLHEWeight(6) != fTree.Event_LHEWeight6) cout << "Wrong GetLHEWeight(6) Value" << endl; if(fTree.GetLHEWeight(7) != fTree.Event_LHEWeight7) cout << "Wrong GetLHEWeight(7) Value" << endl; if(fTree.GetLHEWeight(8) != fTree.Event_LHEWeight8) cout << "Wrong GetLHEWeight(8) Value" << endl; // CurrentLHEWeights[0] = fTree.Event_LHEWeight /fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[1] = fTree.Event_LHEWeight1/fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[2] = fTree.Event_LHEWeight2/fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[3] = fTree.Event_LHEWeight3/fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[4] = fTree.Event_LHEWeight4/fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[5] = fTree.Event_LHEWeight5/fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[6] = fTree.Event_LHEWeight6/fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[7] = fTree.Event_LHEWeight7/fabs(fTree.Event_LHEWeight) ; // CurrentLHEWeights[8] = fTree.Event_LHEWeight8/fabs(fTree.Event_LHEWeight) ; for(int i = 0 ; i<9 ;i++){ CurrentLHEWeights[i] = fTree.GetLHEWeight(i)/fabs(fTree.Event_LHEWeight) ; WScalesTotal[i] += CurrentLHEWeights[i]; } } #endif double cutindex = 0.5; bool pass=true; while( objcut = nextcut() ){ ExtendedCut* thecut = (ExtendedCut*)objcut ; pass &= thecut->Pass(jentry , weight); if(! pass ){ break; }else{ if( isfinite (weight) ){ cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); } else cout << "non-finite weight : " << weight << endl; } cutindex+=1.0; } if(! pass) continue; int cut = 0; //cout << alllabels[ int(cutindex) ] << endl; // cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); // cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); // cutindex ++ ; // if( data && !(fTree.Event_passesHLT_IsoMu20_eta2p1_v2 > 0.5) ) // continue; // if( !data && !(fTree.Event_passesHLT_IsoMu20_eta2p1_v1 > 0.5) ) // continue; nPVBeforeCutsUnCorr.Fill( fTree.Event_nPV , weight/fTree.Event_puWeight , false , true ); nPVBeforeCuts.Fill( fTree.Event_nPV , weight , false, true); // if( printEventIds ) // (*(EventIdFiles[cutindex])) << fTree.Event_EventNumber << endl; // cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); // cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); // cutindex ++ ; if( data && !(fTree.Event_passesHLT_IsoMu20_v2 > 0.5 || fTree.Event_passesHLT_IsoMu20_v1 > 0.5 || fTree.Event_passesHLT_IsoMu20_v3 > 0.5) ) continue; if(!data && !(fTree.Event_passesHLT_IsoMu20_v1 > 0.5) ) continue; if( printEventIds ) (*(EventIdFiles[cutindex])) << fTree.Event_EventNumber << endl; cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); cutindex ++ ; //cout << "nMuons : " << fTree.muons_size << endl; int tightMuIndex =-1; int nonTightMuIndex = -1; int nLooseMuos = 0; int nTightMuons = 0; int nTightNonIsoMuons = 0; for( int imu=0 ; imu < fTree.muons_size ; imu++ ){ // cout << imu << " : " << fTree.muons_Pt[imu] << "-" << fTree.muons_Eta[imu] << "-" // << fTree.muons_IsTightMuon[imu] << "-" << fTree.muons_Iso04[imu] << endl; bool isTight = false; if( fTree.muons_Pt[imu] > 22.0 && fabs(fTree.muons_Eta[imu]) < 2.1 && fTree.muons_IsTightMuon[imu] > 0.5 ){ if( fTree.muons_Iso04[imu] < 0.06 ){ isTight = true; nTightMuons ++; if( tightMuIndex == -1 ) tightMuIndex = imu; }else if( fTree.muons_Iso04[imu] < 0.15 ){ nTightNonIsoMuons ++; if( nonTightMuIndex == -1 ) nonTightMuIndex = imu; } } if( ! isTight ) if( fTree.muons_Pt[ imu ] > 10.0 && fTree.muons_IsLooseMuon[ imu ] > 0.5 && fabs(fTree.muons_Eta[imu]) < 2.5 && fTree.muons_Iso04[imu] < 0.20 ){ nLooseMuos++; } } if(IsQCD){ nLooseMuos = nTightMuons ; nTightMuons = nTightNonIsoMuons ; tightMuIndex = nonTightMuIndex ; } if( nTightMuons != 1 ) continue; bool isiso = true; if( nLooseMuos > 0 ) continue; #ifdef MUONCHARGEP if(fTree.muons_Charge[tightMuIndex] < 0) continue; #endif #ifdef MUONCHARGEN if(fTree.muons_Charge[tightMuIndex] > 0) continue; #endif // if( printEventIds ) // (*(EventIdFiles[cutindex])) << (fTree.Event_EventNumber) << endl ; // cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); // cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); // cutindex ++ ; int nLooseElectrons = 0; for( int iele = 0 ; iele < fTree.electrons_size;iele ++ ){ if( fTree.electrons_Pt[iele] > 20 && fabs(fTree.electrons_Eta[iele]) < 2.5 && ( fabs(fTree.electrons_Eta[iele]) < 1.4442 || fabs(fTree.electrons_Eta[iele]) > 1.566) && fTree.electrons_vidVeto[iele] > 0.5 ) nLooseElectrons++; } if( nLooseElectrons > 0 ) continue; if( printEventIds ) (*(EventIdFiles[cutindex])) << (fTree.Event_EventNumber) << endl ; cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); cutindex ++ ; int j1index = -1; int j2index = -1; int j3index = -1; int nJets = 0 ; int howManyBJets = 0; int bjIndex = -1; int bj2Index = -1; int jprimeIndex ; int nJetsPt20_47 = 0; int nJetsPt20_24 = 0; int nLbJetsPt20 = 0; int nTbJetsPt20 = 0; TLorentzVector muon; muon.SetPtEtaPhiE( fTree.muons_Pt[tightMuIndex] , fTree.muons_Eta[tightMuIndex] , fTree.muons_Phi[tightMuIndex] , fTree.muons_E[tightMuIndex] ); if( muon.Energy() == 0.0 ) cout << "ZERO???" <<endl; for( int jid = 0 ; jid < fTree.jetsAK4_size ; jid++ ){ float NHF = fTree.jetsAK4_JetID_neutralHadronEnergyFraction[jid] ; float NEMF = fTree.jetsAK4_JetID_neutralEmEnergyFraction[jid] ; float NumConst = fTree.jetsAK4_JetID_numberOfDaughters[jid] ; float eta = fTree.jetsAK4_Eta[jid] ; float CHF = fTree.jetsAK4_JetID_chargedHadronEnergyFraction[jid] ; float CHM = fTree.jetsAK4_JetID_chargedMultiplicity[jid] ; float CEMF = fTree.jetsAK4_JetID_chargedEmEnergyFraction[jid] ; float NumNeutralParticle = fTree.jetsAK4_JetID_neutralMultiplicity[jid] ; bool looseid ; if( abs(eta)<=3.0 ) { looseid = (NHF<0.99 && NEMF<0.99 && NumConst>1) && ((abs(eta)<=2.4 && CHF>0 && CHM>0 && CEMF<0.99) || abs(eta)>2.4) ; } else looseid = (NEMF<0.90 && NumNeutralParticle>10) ; if( fTree.jetsAK4_CorrPt[jid] > 20 && fabs( fTree.jetsAK4_Eta[jid] ) < 4.7 && looseid ){ TLorentzVector jet; jet.SetPtEtaPhiE( fTree.jetsAK4_CorrPt[jid] , fTree.jetsAK4_Eta[jid] , fTree.jetsAK4_Phi[jid] , fTree.jetsAK4_CorrE[jid] ); double DR = muon.DeltaR( jet ); if ( DR > 0.3 ){ if( fTree.jetsAK4_CorrPt[jid] <= 40 ){ nJetsPt20_47 ++ ; if( fabs( fTree.jetsAK4_Eta[jid] ) < 2.4 ){ nJetsPt20_24 ++; if( fTree.jetsAK4_CSV[jid] > 0.97 ) nTbJetsPt20++; else if( fTree.jetsAK4_CSV[jid] > 0.605 ) nLbJetsPt20++; } continue; } nJets++; if( nJets == 1 ) j1index = jid ; else if(nJets == 2 ) j2index = jid ; else if( nJets == 3 ) j3index = jid ; if( fTree.jetsAK4_IsCSVT[jid] == true && fabs( fTree.jetsAK4_Eta[jid] ) <= 2.4 ){ howManyBJets ++; if(howManyBJets==1) bjIndex = jid ; else if(howManyBJets==2) bj2Index = jid ; }else jprimeIndex = jid ; } } } nJetsBeforeCut.Fill( nJets , weight , EventsIsPSeudoData < fabs(weight) , isiso ); if (nJets != NUMBEROFJETS) continue; if( printEventIds ) (*(EventIdFiles[cutindex])) << (fTree.Event_EventNumber) << endl ; cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); cutindex ++ ; nbJets.Fill( howManyBJets , weight , EventsIsPSeudoData < fabs(weight) , isiso); if( howManyBJets != NUMBEROFBJETS ) continue; if( !data ){ if( NUMBEROFBJETS == 2 ) weight *= fTree.Event_bWeight2CSVT ; else if (NUMBEROFBJETS == 1 ) weight *= fTree.Event_bWeight1CSVT ; } //weight = 1.0; if( printEventIds ) (*(EventIdFiles[cutindex])) << (fTree.Event_EventNumber) << endl ; cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); cutindex ++ ; double MT = sqrt( 2*fTree.met_Pt* fTree.muons_Pt[tightMuIndex]*(1-TMath::Cos( Util::DeltaPhi(fTree.met_Phi , fTree.muons_Phi[tightMuIndex]) ) ) ) ; MTBeforeCut.Fill( MT , weight , EventsIsPSeudoData < fabs(weight) , isiso ); // if( fTree.met_Pt < 45 ) // continue; if( MT < 50 && (NUMBEROFBJETS == 1 && NUMBEROFJETS == 2) && !IsQCD ) continue; if( printEventIds ) (*(EventIdFiles[cutindex])) << (fTree.Event_EventNumber) << endl ; cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); cutindex ++ ; nonbCSV.Fill( fTree.jetsAK4_CSV[jprimeIndex] , weight , EventsIsPSeudoData < fabs(weight) , isiso); // if( fTree.jetsAK4_CSV[jprimeIndex] > 0.605 ) // continue; // if( printEventIds ) // (*(EventIdFiles[cutindex])) << (fTree.Event_EventNumber) << endl ; // cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); // cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); // cutindex ++ ; nJets20_47.Fill( nJetsPt20_47 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nJets20_24.Fill( nJetsPt20_24 , weight , EventsIsPSeudoData < fabs(weight) , isiso); if(nJetsPt20_24 < 2){ nLbjets1EJ24.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets1EJ24.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if(nJetsPt20_24 < 3){ nLbjets2EJ24.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets2EJ24.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if(nJetsPt20_24 < 4){ nLbjets3EJ24.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets3EJ24.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if(nJetsPt20_24 < 5){ nLbjets4EJ24.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets4EJ24.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if(nJetsPt20_47 < 2){ nLbjets1EJ47.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets1EJ47.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if(nJetsPt20_47 < 3){ nLbjets2EJ47.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets2EJ47.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if(nJetsPt20_47 < 4){ nLbjets3EJ47.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets3EJ47.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if(nJetsPt20_47 < 5){ nLbjets4EJ47.Fill( nLbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); nTbjets4EJ47.Fill( nTbJetsPt20 , weight , EventsIsPSeudoData < fabs(weight) , isiso); } if( NUMBEROFBJETS == 2 ) if( fTree.jetsAK4_CSV[bj2Index] > fTree.jetsAK4_CSV[bjIndex] ) std::swap( bj2Index , bjIndex ); //int jprimeIndex = (bjIndex == j1index) ? j2index : j1index ; TLorentzVector muLV; muLV.SetPtEtaPhiE( fTree.muons_Pt[tightMuIndex] , fTree.muons_Eta[tightMuIndex] , fTree.muons_Phi[ tightMuIndex ] , fTree.muons_E[tightMuIndex] ); TLorentzVector bjetLV; bjetLV.SetPtEtaPhiE( fTree.jetsAK4_CorrPt[ bjIndex ] , fTree.jetsAK4_Eta[ bjIndex ] , fTree.jetsAK4_Phi[ bjIndex ] , fTree.jetsAK4_CorrE[ bjIndex ] ) ; double topMass = topUtils.top4Momentum( muLV , bjetLV , fTree.met_Px , fTree.met_Py ).mass(); TopMass.Fill( topMass , weight , EventsIsPSeudoData < fabs(weight) , isiso ); //fTree.resolvedTopSemiLep_Mass[0] MT_QCD_Tree = MT; TOPMASS_QCD_Tree = topMass ; MuIso_QCD_Tree = fTree.muons_Iso04[tightMuIndex]; Weight_QCD_Tree = weight ; if( IsQCD ) theQCD_Tree->Fill(); if( (130. < topMass && topMass < 225.) || NUMBEROFBJETS == 2 ){ nPVAfterCutsUnCorr.Fill( fTree.Event_nPV , weight/fTree.Event_puWeight , EventsIsPSeudoData < fabs(weight) , isiso ); nPVAfterCuts.Fill( fTree.Event_nPV , weight , EventsIsPSeudoData < fabs(weight) , isiso ); #ifdef SingleTopTreeLHEWeights_h for(int i = 0 ; i< 102 ; i++){ hEtajPDFScales[i]->Fill( fabs( fTree.jetsAK4_Eta[jprimeIndex] ) , weight*fabs( CurrentPDFWeights[i] ) ); } if( Sample.name == "WJets" || Sample.name == "Signal"){ for(int i=0;i<9;i++) hEtajWScales[i]->Fill( fabs( fTree.jetsAK4_Eta[jprimeIndex] ) , weight*fabs( CurrentLHEWeights[i] ) ); } #endif jprimeEta.Fill( fabs( fTree.jetsAK4_Eta[jprimeIndex] ) , weight , EventsIsPSeudoData < fabs(weight) , isiso); jprimePt.Fill( fTree.jetsAK4_CorrPt[jprimeIndex] , weight , EventsIsPSeudoData < fabs(weight) , isiso); muPtOneB.Fill( fTree.muons_Pt[tightMuIndex] , weight , EventsIsPSeudoData < fabs(weight) , isiso); muCharge.Fill( fTree.muons_Charge[tightMuIndex] , weight , EventsIsPSeudoData < fabs(weight) , isiso); muEtaOneB.Fill( fabs(fTree.muons_Eta[tightMuIndex]) , weight , EventsIsPSeudoData < fabs(weight), isiso ); METOneBSR.Fill( fTree.met_Pt , weight , EventsIsPSeudoData < fabs(weight) , isiso); bPtOneB.Fill( fTree.jetsAK4_CorrPt[bjIndex] , weight , EventsIsPSeudoData < fabs(weight), isiso ); bEtaOneB.Fill(fabs( fTree.jetsAK4_Eta[bjIndex] ) , weight , EventsIsPSeudoData < fabs(weight), isiso ); if( printEventIds ) (*(EventIdFiles[cutindex])) << (fTree.Event_EventNumber) << endl ; cutflowtable.Fill( cutindex , weight , EventsIsPSeudoData < fabs(weight) ); cutflowtablew1.Fill( cutindex , weight/fabs(weight) , EventsIsPSeudoData < fabs(weight) ); cutindex++; }else{ jprimeEtaSB.Fill( fabs( fTree.jetsAK4_Eta[jprimeIndex] ) , weight , EventsIsPSeudoData < fabs(weight) , isiso ); METOneBSB.Fill( fTree.met_Pt , weight , EventsIsPSeudoData < fabs(weight) , isiso); } METOneBAll.Fill( fTree.met_Pt , weight , EventsIsPSeudoData < fabs(weight) , isiso); if(Sample.name == "Signal" ) hTopMass->Fill( topMass , weight ); if(Sample.name == "WJets") hTopMassEtaJ->Fill( topMass ,fabs( fTree.jetsAK4_Eta[jprimeIndex] ) ); } theQCD_Tree->Write(); } theTreeFile->Close(); // TString fileName = fOutputDir; // if(!fileName.EndsWith("/")) fileName += "/"; // Util::MakeOutputDir(fileName); fileName += myfileName + ".root" ; TFile *theFile = new TFile(fileName.Data(), "RECREATE"); nonbCSV.CalcSig( 0 , 0 , -1 , 0 ) ; nonbCSV.CalcSig( 0 , 4 , -1 , 0.1); nonbCSV.CalcSig( 0 , 2 , -1 , 0 ) ; nJets20_24.CalcSig( 0 , 0 , -1 , 0 ) ; nJets20_24.CalcSig( 0 , 4 , -1 , 0.1 ) ; nJets20_24.CalcSig( 0 , 2 , -1 , 0 ) ; nJets20_47.CalcSig( 0 , 0 , -1 , 0 ) ; nJets20_47.CalcSig( 0 , 4 , -1 , 0.1 ) ; nJets20_47.CalcSig( 0 , 2 , -1 , 0 ) ; muCharge.CalcSig( 0 , 0 , -1 , 0 ) ; muCharge.CalcSig( 0 , 4 , -1 , 0.1 ) ; muCharge.CalcSig( 0 , 2 , -1 , 0 ) ; muCharge.CalcSig( 1 , 0 , -1 , 0 ) ; muCharge.CalcSig( 1 , 4 , -1 , 0.1 ) ; muCharge.CalcSig( 1 , 2 , -1 , 0 ) ; for(auto prop : allProps) prop->Write( theFile , 1000 ); #ifdef SingleTopTreeLHEWeights_h TDirectory* dirWScales = theFile->mkdir("WJScales"); dirWScales->cd(); for(int i=0;i<9;i++){ cout << "WScalesTotal[i]" << WScalesTotal[i] << "," << WScalesTotal[0]/WScalesTotal[i] << endl; hEtajWScales[i]->Scale( WScalesTotal[0]/WScalesTotal[i] ); hEtajWScales[i]->Write(); } TDirectory* dirPDFScales = theFile->mkdir("PDFScales"); dirPDFScales->cd(); for(int i=0;i<102;i++){ cout << "PDFScales[i]" << ScalesPDF[i] << "," << WScalesTotal[0]/ScalesPDF[i] << endl; hEtajPDFScales[i]->Scale( WScalesTotal[0]/ScalesPDF[i] ); hEtajPDFScales[i]->Write(); } #endif TDirectory* dir2 = theFile->mkdir("JbJOptimizationProps"); dir2->cd(); for(auto prop2 : JbJOptimizationProps){ prop2->CalcSig( 0 , 0 , -1 , 0 ) ; prop2->CalcSig( 0 , 4 , -1 , 0.1 ) ; prop2->CalcSig( 0 , 2 , -1 , 0 ) ; prop2->Write( dir2 , 1000 ); } theFile->cd(); hTopMass->Write(); hTopMassEtaJ->Write(); //cutflowtable.Print("cutflowtable"); theFile->Close(); if( printEventIds ) for( auto a : EventIdFiles ){ a->close(); } }
/////////////////////// // Begin Main function: void mkROOTaqgcMuLT0_Para(){ ////////////////////////////////////// // Set MC normalization scale factors: const double intLUMI = 19297; const double WWA_scale = 2.1*0.01362 * intLUMI/198777; const double WWA2_scale = 2.1*0.01409 * intLUMI/199183; const double LT0_p8m5_scale = 2.1*0.0809985 * intLUMI/184603 ; const double LT0_p5m5_scale = 2.1*0.0443325 * intLUMI/149975; const double LT0_p3m5_scale = 2.1*0.029308 * intLUMI/97015; const double LT0_m3m5_scale = 2.1*0.0290669 * intLUMI/154634; const double LT0_m5m5_scale = 2.1*0.0440545 * intLUMI/199930; const double LT0_m8m5_scale = 2.1*0.0806445 * intLUMI/196613; /////////////////////////////////////////////////////////////////////////////////// // Specify what kinematical distribution to observe, as well as histogram settings: // plotVar_t pv = {"Photon_Et[iPhoton12]",30,450,10,3,"Photon ET (GeV)"}; if ( !strlen(pv.plotvar) ) break; std::cout << TString(pv.plotvar) << "\t"<<pv.MINRange<<"\t" << pv.MAXRange<<"\t" << pv.NBINS<<"\tTHE CUT " << endl; //////////////////////////////// // Specify event selection cuts: TCut the_cutKfac("effwt*puwt*(iPhoton12>-1&&Photon_Et[iPhoton12]>30.&&Photon_dRlep[iPhoton12]>0.5&&i12Jet2>-1&&i12Jet1>-1&&JetPFCor_dRpho12[i12Jet1]>0.5&&JetPFCor_dRpho12[i12Jet2]>0.5&&abs(W_muon_eta)<2.1&&abs(JetPFCor_dphiMET[i12Jet1])>0.4&& abs(JetPFCor_dphiMET[i12Jet2])>0.4&&JetPFCor_bDiscriminatorCSV[i12Jet1]<0.679&&JetPFCor_bDiscriminatorCSV[i12Jet2]<0.679&&abs(JetPFCor_Eta[i12Jet1]-JetPFCor_Eta[i12Jet2])<1.4&&abs(Photon_Eta[iPhoton12])<1.44421&&W_muon_pt>25&&event_met_pfmet>35.&&c2jMass12>70.&&c2jMass12<100.&&W_mt>30.&&abs(W_muon_dz000)<0.02&&abs(W_muon_dzPV)<0.5&&((i12Jet3>-1)? JetPFCor_dRpho12[i12Jet3]>0.5: 1 )&&((i12Jet4>-1)? JetPFCor_dRpho12[i12Jet4]>0.5: 1 ))"); //mva2jWWAmuA1>0.32 /////////////////////////// // Create output ROOT file: TFile f("para_mu_LT0_WWA_PhotonEt.root", "RECREATE"); ////////////////////////////////////////////////// // Create file pointers for each sample ROOT file: TFile *wwaShape_file,*wwa2Shape_file; TFile *LT0_m8m5_file,*LT0_m5m5_file,*LT0_m3m5_file,*LT0_p3m5_file,*LT0_p5m5_file,*LT0_p8m5_file; ////////////////////////////// // Open each sample ROOT file: wwaShape_file = new TFile("InData_New/RD_mu_qq_wpwma_wp_qq_wm_lvl.root"); wwa2Shape_file = new TFile("InData_New/RD_mu_qq_wpwma_wp_lvl_wm_qq.root"); LT0_m8m5_file = new TFile("InData_New/RD_mu_LT0_m8m11MG_CMSSW532.root"); LT0_m5m5_file = new TFile("InData_New/RD_mu_LT0_m5m11MG_CMSSW532.root"); LT0_m3m5_file = new TFile("InData_New/RD_mu_LT0_m3m11MG_CMSSW532.root"); LT0_p3m5_file = new TFile("InData_New/RD_mu_LT0_p3m11MG_CMSSW532.root"); LT0_p5m5_file = new TFile("InData_New/RD_mu_LT0_p5m11MG_CMSSW532.root"); LT0_p8m5_file = new TFile("InData_New/RD_mu_LT0_p8m11MG_CMSSW532.root"); /////////////////////////////////////////////////// // Retrieve ROOT tree with kinematic distributions: TTree* treewwa = (TTree*) wwaShape_file->Get("WJet"); TTree* treewwa2 = (TTree*) wwa2Shape_file->Get("WJet"); TTree* treeLT0_m8m5 = (TTree*) LT0_m8m5_file->Get("WJet"); TTree* treeLT0_m5m5 = (TTree*) LT0_m5m5_file->Get("WJet"); TTree* treeLT0_m3m5 = (TTree*) LT0_m3m5_file->Get("WJet"); TTree* treeLT0_p3m5 = (TTree*) LT0_p3m5_file->Get("WJet"); TTree* treeLT0_p5m5 = (TTree*) LT0_p5m5_file->Get("WJet"); TTree* treeLT0_p8m5 = (TTree*) LT0_p8m5_file->Get("WJet"); //////////////////////////////////////////////////////////// // Create kinematic-distribution histograms for each sample: TH1* th1wwa = new TH1D("th1wwa", "th1wwa", pv.NBINS, pv.MINRange, pv.MAXRange); TH1* th1wwa2 = new TH1D("th1wwa2", "th1wwa2", pv.NBINS, pv.MINRange, pv.MAXRange); TH1* signal_lt0_80 = new TH1D("signal_lt0_80","signal_lt0_80",pv.NBINS, pv.MINRange, pv.MAXRange); TH1* signal_lt0_50 = new TH1D("signal_lt0_50","signal_lt0_50",pv.NBINS, pv.MINRange, pv.MAXRange); TH1* signal_lt0_30 = new TH1D("signal_lt0_30","signal_lt0_30",pv.NBINS, pv.MINRange, pv.MAXRange); TH1* signal_lt0_m30 = new TH1D("signal_lt0_m30","signal_lt0_-30",pv.NBINS, pv.MINRange, pv.MAXRange); TH1* signal_lt0_m50 = new TH1D("signal_lt0_m50","signal_lt0_-50",pv.NBINS, pv.MINRange, pv.MAXRange); TH1* signal_lt0_m80 = new TH1D("signal_lt0_m80","signal_lt0_-80",pv.NBINS, pv.MINRange, pv.MAXRange); ///////////////////////////////////////////////////////////////////////// // Specify histograms to store Sum of Squares of Weights for each sample: th1wwa->Sumw2(); th1wwa2->Sumw2(); /////////////////////////////////////////////////////////////////////////////////// // Fill kinematical distribution for each sample according to event selection cuts: std::cout<<"Fill SM WWA Histogram..."<<std::endl; treewwa->Draw(TString(pv.plotvar)+TString(">>th1wwa"), the_cutKfac, "goff"); th1wwa->AddBinContent(pv.NBINS,th1wwa->GetBinContent(pv.NBINS+1));th1wwa->SetBinContent(pv.NBINS+1,0.); treewwa2->Draw(TString(pv.plotvar)+TString(">>th1wwa2"), the_cutKfac, "goff"); th1wwa2->AddBinContent(pv.NBINS,th1wwa2->GetBinContent(pv.NBINS+1));th1wwa2->SetBinContent(pv.NBINS+1,0.); std::cout<<"Fill aQGC_1 WWA Histogram..."<<std::endl; treeLT0_m8m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_m80"), the_cutKfac, "goff"); std::cout<<"Fill aQGC_2 WWA Histogram..."<<std::endl; treeLT0_m5m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_m50"), the_cutKfac, "goff"); std::cout<<"Fill aQGC_3 WWA Histogram..."<<std::endl; treeLT0_m3m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_m30"), the_cutKfac, "goff"); std::cout<<"Fill aQGC_4 WWA Histogram..."<<std::endl; treeLT0_p3m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_30"), the_cutKfac, "goff"); std::cout<<"Fill aQGC_5 WWA Histogram..."<<std::endl; treeLT0_p5m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_50"), the_cutKfac, "goff"); std::cout<<"Fill aQGC_6 WWA Histogram..."<<std::endl; treeLT0_p8m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_80"), the_cutKfac, "goff"); signal_lt0_80->AddBinContent(pv.NBINS,signal_lt0_80->GetBinContent(pv.NBINS+1));signal_lt0_80->SetBinContent(pv.NBINS+1,0.); signal_lt0_50->AddBinContent(pv.NBINS,signal_lt0_50->GetBinContent(pv.NBINS+1));signal_lt0_50->SetBinContent(pv.NBINS+1,0.); signal_lt0_30->AddBinContent(pv.NBINS,signal_lt0_30->GetBinContent(pv.NBINS+1));signal_lt0_30->SetBinContent(pv.NBINS+1,0.); signal_lt0_m30->AddBinContent(pv.NBINS,signal_lt0_m30->GetBinContent(pv.NBINS+1));signal_lt0_m30->SetBinContent(pv.NBINS+1,0.); signal_lt0_m50->AddBinContent(pv.NBINS,signal_lt0_m50->GetBinContent(pv.NBINS+1));signal_lt0_m50->SetBinContent(pv.NBINS+1,0.); signal_lt0_m80->AddBinContent(pv.NBINS,signal_lt0_m80->GetBinContent(pv.NBINS+1));signal_lt0_m80->SetBinContent(pv.NBINS+1,0.); ///////////////////////// // Normalize each sample: std::cout<<"\nScale Histograms..."<<std::endl; th1wwa->Scale(WWA_scale); th1wwa2->Scale(WWA2_scale); signal_lt0_m80->Scale(LT0_m8m5_scale); signal_lt0_m50->Scale(LT0_m5m5_scale); signal_lt0_m30->Scale(LT0_m3m5_scale); signal_lt0_30->Scale(LT0_p3m5_scale); signal_lt0_50->Scale(LT0_p5m5_scale); signal_lt0_80->Scale(LT0_p8m5_scale); /////////////////////////// // Combine certain samples: th1wwa->Add(th1wwa2,1); signal_lt0_80->Divide(th1wwa); signal_lt0_50->Divide(th1wwa); signal_lt0_30->Divide(th1wwa); signal_lt0_m30->Divide(th1wwa); signal_lt0_m50->Divide(th1wwa); signal_lt0_m80->Divide(th1wwa); /////////////////////////// //Fill Parabolic Histogram: TH1* bin_1 = new TH1D("bin_1","bin_1",17, -8.5E-11, 8.5E-11); TH1* bin_2 = new TH1D("bin_2","bin_2",17, -8.5E-11, 8.5E-11); TH1* bin_3 = new TH1D("bin_3","bin_3",17, -8.5E-11, 8.5E-11); TH1* bin_4 = new TH1D("bin_4","bin_4",17, -8.5E-11, 8.5E-11); TH1* bin_5 = new TH1D("bin_5","bin_5",17, -8.5E-11, 8.5E-11); TH1* bin_6 = new TH1D("bin_6","bin_6",17, -8.5E-11, 8.5E-11); TH1* bin_7 = new TH1D("bin_7","bin_7",17, -8.5E-11, 8.5E-11); TH1* bin_8 = new TH1D("bin_8","bin_8",17, -8.5E-11, 8.5E-11); TH1* bin_9 = new TH1D("bin_9","bin_9",17, -8.5E-11, 8.5E-11); TH1* bin_10 = new TH1D("bin_10","bin_10",17, -8.5E-11, 8.5E-11); bin_1->SetBinContent(1,signal_lt0_m80->GetBinContent(1)); bin_1->SetBinContent(4,signal_lt0_m50->GetBinContent(1)); bin_1->SetBinContent(6,signal_lt0_m30->GetBinContent(1)); bin_1->SetBinContent(9,1); bin_1->SetBinContent(12,signal_lt0_30->GetBinContent(1)); bin_1->SetBinContent(14,signal_lt0_50->GetBinContent(1)); bin_1->SetBinContent(17,signal_lt0_80->GetBinContent(1)); bin_2->SetBinContent(1,signal_lt0_m80->GetBinContent(2)); bin_2->SetBinContent(4,signal_lt0_m50->GetBinContent(2)); bin_2->SetBinContent(6,signal_lt0_m30->GetBinContent(2)); bin_2->SetBinContent(9,1); bin_2->SetBinContent(12,signal_lt0_30->GetBinContent(2)); bin_2->SetBinContent(14,signal_lt0_50->GetBinContent(2)); bin_2->SetBinContent(17,signal_lt0_80->GetBinContent(2)); bin_3->SetBinContent(1,signal_lt0_m80->GetBinContent(3)); bin_3->SetBinContent(4,signal_lt0_m50->GetBinContent(3)); bin_3->SetBinContent(6,signal_lt0_m30->GetBinContent(3)); bin_3->SetBinContent(9,1); bin_3->SetBinContent(12,signal_lt0_30->GetBinContent(3)); bin_3->SetBinContent(14,signal_lt0_50->GetBinContent(3)); bin_3->SetBinContent(17,signal_lt0_80->GetBinContent(3)); bin_4->SetBinContent(1,signal_lt0_m80->GetBinContent(4)); bin_4->SetBinContent(4,signal_lt0_m50->GetBinContent(4)); bin_4->SetBinContent(6,signal_lt0_m30->GetBinContent(4)); bin_4->SetBinContent(9,1); bin_4->SetBinContent(12,signal_lt0_30->GetBinContent(4)); bin_4->SetBinContent(14,signal_lt0_50->GetBinContent(4)); bin_4->SetBinContent(17,signal_lt0_80->GetBinContent(4)); bin_5->SetBinContent(1,signal_lt0_m80->GetBinContent(5)); bin_5->SetBinContent(4,signal_lt0_m50->GetBinContent(5)); bin_5->SetBinContent(6,signal_lt0_m30->GetBinContent(5)); bin_5->SetBinContent(9,1); bin_5->SetBinContent(12,signal_lt0_30->GetBinContent(5)); bin_5->SetBinContent(14,signal_lt0_50->GetBinContent(5)); bin_5->SetBinContent(17,signal_lt0_80->GetBinContent(5)); bin_6->SetBinContent(1,signal_lt0_m80->GetBinContent(6)); bin_6->SetBinContent(4,signal_lt0_m50->GetBinContent(6)); bin_6->SetBinContent(6,signal_lt0_m30->GetBinContent(6)); bin_6->SetBinContent(9,1); bin_6->SetBinContent(12,signal_lt0_30->GetBinContent(6)); bin_6->SetBinContent(14,signal_lt0_50->GetBinContent(6)); bin_6->SetBinContent(17,signal_lt0_80->GetBinContent(6)); bin_7->SetBinContent(1,signal_lt0_m80->GetBinContent(7)); bin_7->SetBinContent(4,signal_lt0_m50->GetBinContent(7)); bin_7->SetBinContent(6,signal_lt0_m30->GetBinContent(7)); bin_7->SetBinContent(9,1); bin_7->SetBinContent(12,signal_lt0_30->GetBinContent(7)); bin_7->SetBinContent(14,signal_lt0_50->GetBinContent(7)); bin_7->SetBinContent(17,signal_lt0_80->GetBinContent(7)); bin_8->SetBinContent(1,signal_lt0_m80->GetBinContent(8)); bin_8->SetBinContent(4,signal_lt0_m50->GetBinContent(8)); bin_8->SetBinContent(6,signal_lt0_m30->GetBinContent(8)); bin_8->SetBinContent(9,1); bin_8->SetBinContent(12,signal_lt0_30->GetBinContent(8)); bin_8->SetBinContent(14,signal_lt0_50->GetBinContent(8)); bin_8->SetBinContent(17,signal_lt0_80->GetBinContent(8)); bin_9->SetBinContent(1,signal_lt0_m80->GetBinContent(9)); bin_9->SetBinContent(4,signal_lt0_m50->GetBinContent(9)); bin_9->SetBinContent(6,signal_lt0_m30->GetBinContent(9)); bin_9->SetBinContent(9,1); bin_9->SetBinContent(12,signal_lt0_30->GetBinContent(9)); bin_9->SetBinContent(14,signal_lt0_50->GetBinContent(9)); bin_9->SetBinContent(17,signal_lt0_80->GetBinContent(9)); bin_10->SetBinContent(1,signal_lt0_m80->GetBinContent(10)); bin_10->SetBinContent(4,signal_lt0_m50->GetBinContent(10)); bin_10->SetBinContent(6,signal_lt0_m30->GetBinContent(10)); bin_10->SetBinContent(9,1); bin_10->SetBinContent(12,signal_lt0_30->GetBinContent(10)); bin_10->SetBinContent(14,signal_lt0_50->GetBinContent(10)); bin_10->SetBinContent(17,signal_lt0_80->GetBinContent(10)); //////////////// // Fit function: Char_t para_fit[] = "[0]+[1]*x+[2]*x^2"; Char_t fitopt[] = "QMR"; Double_t xmin = -8E-5; Double_t xmax = 8E-5; Double_t p[3][10]; TF1 *pfit = new TF1("pfit",para_fit,xmin,xmax); // pfit->SetParLimits(1,0.0,1E15); // pfit->FixParameter(0,0.0); ///////////////// // Fit histogram: bin_1->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][0] = pfit->GetParameter(0); p[1][0] = pfit->GetParameter(1); p[2][0] = pfit->GetParameter(2); bin_2->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][1] = pfit->GetParameter(0); p[1][1] = pfit->GetParameter(1); p[2][1] = pfit->GetParameter(2); bin_3->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][2] = pfit->GetParameter(0); p[1][2] = pfit->GetParameter(1); p[2][2] = pfit->GetParameter(2); bin_4->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][3] = pfit->GetParameter(0); p[1][3] = pfit->GetParameter(1); p[2][3] = pfit->GetParameter(2); bin_5->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][4] = pfit->GetParameter(0); p[1][4] = pfit->GetParameter(1); p[2][4] = pfit->GetParameter(2); bin_6->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][5] = pfit->GetParameter(0); p[1][5] = pfit->GetParameter(1); p[2][5] = pfit->GetParameter(2); bin_7->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][6] = pfit->GetParameter(0); p[1][6] = pfit->GetParameter(1); p[2][6] = pfit->GetParameter(2); bin_8->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][7] = pfit->GetParameter(0); p[1][7] = pfit->GetParameter(1); p[2][7] = pfit->GetParameter(2); bin_9->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][8] = pfit->GetParameter(0); p[1][8] = pfit->GetParameter(1); p[2][8] = pfit->GetParameter(2); bin_10->Fit(pfit,fitopt,"sames",xmin,xmax); p[0][9] = pfit->GetParameter(0); p[1][9] = pfit->GetParameter(1); p[2][9] = pfit->GetParameter(2); ///////////////////////////// // Fill parameter histograms: TH1* p0 = new TH1D("p0","Parameter 0",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* p1 = new TH1D("p1","Parameter 1",pv.NBINS,pv.MINRange,pv.MAXRange); for(Int_t i=1;i<=pv.NBINS;i++){ p0->SetBinContent(i,p[0][i-1]); p1->SetBinContent(i,p[1][i-1]); } /* /////////////////// // Fit pT-function: Char_t pt_fit[] = "[0]+[1]*x+[2]*x^2"; Char_t fitopt[] = "QMR"; Double_t xmin = 150;//45; Double_t xmax = 1050;//275; Double_t pt[2][3]; TF1 *ptfit = new TF1("ptfit",pt_fit,xmin,xmax); p0->Fit(ptfit,fitopt,"sames",xmin,xmax); pt[0][0] = ptfit->GetParameter(0); pt[0][1] = ptfit->GetParameter(1); pt[0][2] = ptfit->GetParameter(2); p1->Fit(ptfit,fitopt,"sames",xmin,xmax); pt[1][0] = ptfit->GetParameter(0); pt[1][1] = ptfit->GetParameter(1); pt[1][2] = ptfit->GetParameter(2); */ //////////////// // Closure test: // ratio = 1 + (pt[0][0]+pt[0][1]*pt+pt[0][2]*pt^2)*KOW + (pt[1][0]+pt[1][1]*pt+[1][2]*pt^2)*KOW^2 TH1* test = new TH1D("test","Test aQGC Photon ET",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* test2 = new TH1D("test2","Test aQGC Photon ET",pv.NBINS,pv.MINRange,pv.MAXRange); for(Int_t j=1;j<=pv.NBINS;j++){ Double_t value,bincent; TAxis* xaxis = test->GetXaxis(); bincent = xaxis->GetBinCenter(j); value = p[0][j-1]+p[1][j-1]*(8E-11)+p[2][j-1]*pow(8E-11,2); test->SetBinContent(j,value); test2->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-8E-11)+p[2][j-1]*pow(-8E-11,2)); } // test->SetBinContent(8,1+p[0][7]*(8E-11)+p[1][7]*pow(8E-11,2)); // test2->SetBinContent(8,1+p[0][7]*(-8E-11)+p[1][7]*pow(-8E-11,2)); TH1D* test_r = (TH1D*)test->Clone("test_r"); TH1D* test2_r = (TH1D*)test2->Clone("test2_r"); test_r->Divide(signal_lt0_80); test2_r->Divide(signal_lt0_m80); test->Multiply(th1wwa); test2->Multiply(th1wwa); test->Add(th1wwa,-1); test2->Add(th1wwa,-1); ///////////////////// // Simulate new aQGC: TH1* signal_lt0_18 = new TH1D("signal_lt0_18","signal_lt0_1p8",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_20 = new TH1D("signal_lt0_20","signal_lt0_2p0",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_22 = new TH1D("signal_lt0_22","signal_lt0_2p2",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_24 = new TH1D("signal_lt0_24","signal_lt0_2p4",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_26 = new TH1D("signal_lt0_26","signal_lt0_2p6",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_28 = new TH1D("signal_lt0_28","signal_lt0_2p8",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_32 = new TH1D("signal_lt0_32","signal_lt0_3p2",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_34 = new TH1D("signal_lt0_34","signal_lt0_3p4",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_36 = new TH1D("signal_lt0_36","signal_lt0_3p6",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_38 = new TH1D("signal_lt0_38","signal_lt0_3p8",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m18 = new TH1D("signal_lt0_m18","signal_lt0_-1p8",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m20 = new TH1D("signal_lt0_m20","signal_lt0_-2p0",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m22 = new TH1D("signal_lt0_m22","signal_lt0_-2p2",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m24 = new TH1D("signal_lt0_m24","signal_lt0_-2p4",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m26 = new TH1D("signal_lt0_m26","signal_lt0_-2p6",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m28 = new TH1D("signal_lt0_m28","signal_lt0_-2p8",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m32 = new TH1D("signal_lt0_m32","signal_lt0_-3p2",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m34 = new TH1D("signal_lt0_m34","signal_lt0_-3p4",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m36 = new TH1D("signal_lt0_m36","signal_lt0_-3p6",pv.NBINS,pv.MINRange,pv.MAXRange); TH1* signal_lt0_m38 = new TH1D("signal_lt0_m38","signal_lt0_-3p8",pv.NBINS,pv.MINRange,pv.MAXRange); signal_lt0_18->Sumw2(); signal_lt0_20->Sumw2(); signal_lt0_22->Sumw2(); signal_lt0_24->Sumw2(); signal_lt0_26->Sumw2(); signal_lt0_28->Sumw2(); signal_lt0_32->Sumw2(); signal_lt0_34->Sumw2(); signal_lt0_36->Sumw2(); signal_lt0_38->Sumw2(); signal_lt0_m18->Sumw2(); signal_lt0_m20->Sumw2(); signal_lt0_m22->Sumw2(); signal_lt0_m24->Sumw2(); signal_lt0_m26->Sumw2(); signal_lt0_m28->Sumw2(); signal_lt0_m32->Sumw2(); signal_lt0_m34->Sumw2(); signal_lt0_m36->Sumw2(); signal_lt0_m38->Sumw2(); for(Int_t j=1;j<=pv.NBINS;j++){ Double_t bincent; TAxis* xaxis = test->GetXaxis(); bincent = xaxis->GetBinCenter(j); signal_lt0_m50->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-5.E-11)+p[2][j-1]*pow(-5.E-11,2)); signal_lt0_m30->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.E-11)+p[2][j-1]*pow(-3.E-11,2)); signal_lt0_m80->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-8.E-11)+p[2][j-1]*pow(-8.E-11,2)); signal_lt0_m28->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.8E-11)+p[2][j-1]*pow(-2.8E-11,2)); signal_lt0_m26->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.6E-11)+p[2][j-1]*pow(-2.6E-11,2)); signal_lt0_m24->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.4E-11)+p[2][j-1]*pow(-2.4E-11,2)); signal_lt0_m22->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.2E-11)+p[2][j-1]*pow(-2.2E-11,2)); signal_lt0_m20->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.E-11)+p[2][j-1]*pow(-2.E-11,2)); signal_lt0_m18->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-1.8E-11)+p[2][j-1]*pow(-1.8E-11,2)); signal_lt0_m32->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.2E-11)+p[2][j-1]*pow(-3.2E-11,2)); signal_lt0_m34->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.4E-11)+p[2][j-1]*pow(-3.4E-11,2)); signal_lt0_m36->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.6E-11)+p[2][j-1]*pow(-3.6E-11,2)); signal_lt0_m38->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.8E-11)+p[2][j-1]*pow(-3.8E-11,2)); signal_lt0_50->SetBinContent(j,p[0][j-1]+p[1][j-1]*(5.E-11)+p[2][j-1]*pow(5.E-11,2)); signal_lt0_30->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.E-11)+p[2][j-1]*pow(3.E-11,2)); signal_lt0_80->SetBinContent(j,p[0][j-1]+p[1][j-1]*(8.E-11)+p[2][j-1]*pow(8.E-11,2)); signal_lt0_28->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.8E-11)+p[2][j-1]*pow(2.8E-11,2)); signal_lt0_26->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.6E-11)+p[2][j-1]*pow(2.6E-11,2)); signal_lt0_24->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.4E-11)+p[2][j-1]*pow(2.4E-11,2)); signal_lt0_22->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.2E-11)+p[2][j-1]*pow(2.2E-11,2)); signal_lt0_20->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.E-11)+p[2][j-1]*pow(2.E-11,2)); signal_lt0_18->SetBinContent(j,p[0][j-1]+p[1][j-1]*(1.8E-11)+p[2][j-1]*pow(1.8E-11,2)); signal_lt0_32->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.2E-11)+p[2][j-1]*pow(3.2E-11,2)); signal_lt0_34->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.4E-11)+p[2][j-1]*pow(3.4E-11,2)); signal_lt0_36->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.6E-11)+p[2][j-1]*pow(3.6E-11,2)); signal_lt0_38->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.8E-11)+p[2][j-1]*pow(3.8E-11,2)); } /* signal_lt0_m50->SetBinContent(8,1+p[0][7]*(-5.E-11)+p[1][7]*pow(-5.E-11,2)); signal_lt0_m30->SetBinContent(8,1+p[0][7]*(-3.E-11)+p[1][7]*pow(-3.E-11,2)); signal_lt0_m80->SetBinContent(8,1+p[0][7]*(-8.E-11)+p[1][7]*pow(-8.E-11,2)); signal_lt0_m28->SetBinContent(8,1+p[0][7]*(-2.8E-11)+p[1][7]*pow(-2.8E-11,2)); signal_lt0_m26->SetBinContent(8,1+p[0][7]*(-2.6E-11)+p[1][7]*pow(-2.6E-11,2)); signal_lt0_m24->SetBinContent(8,1+p[0][7]*(-2.4E-11)+p[1][7]*pow(-2.4E-11,2)); signal_lt0_m22->SetBinContent(8,1+p[0][7]*(-2.2E-11)+p[1][7]*pow(-2.2E-11,2)); signal_lt0_m20->SetBinContent(8,1+p[0][7]*(-2.E-11)+p[1][7]*pow(-2.E-11,2)); signal_lt0_m18->SetBinContent(8,1+p[0][7]*(-1.8E-11)+p[1][7]*pow(-1.8E-11,2)); signal_lt0_m32->SetBinContent(8,1+p[0][7]*(-3.2E-11)+p[1][7]*pow(-3.2E-11,2)); signal_lt0_m34->SetBinContent(8,1+p[0][7]*(-3.4E-11)+p[1][7]*pow(-3.4E-11,2)); signal_lt0_m36->SetBinContent(8,1+p[0][7]*(-3.6E-11)+p[1][7]*pow(-3.6E-11,2)); signal_lt0_m38->SetBinContent(8,1+p[0][7]*(-3.8E-11)+p[1][7]*pow(-3.8E-11,2)); signal_lt0_50->SetBinContent(8,1+p[0][7]*(5.E-11)+p[1][7]*pow(5.E-11,2)); signal_lt0_30->SetBinContent(8,1+p[0][7]*(3.E-11)+p[1][7]*pow(3.E-11,2)); signal_lt0_80->SetBinContent(8,1+p[0][7]*(8.E-11)+p[1][7]*pow(8.E-11,2)); signal_lt0_28->SetBinContent(8,1+p[0][7]*(2.8E-11)+p[1][7]*pow(2.8E-11,2)); signal_lt0_26->SetBinContent(8,1+p[0][7]*(2.6E-11)+p[1][7]*pow(2.6E-11,2)); signal_lt0_24->SetBinContent(8,1+p[0][7]*(2.4E-11)+p[1][7]*pow(2.4E-11,2)); signal_lt0_22->SetBinContent(8,1+p[0][7]*(2.2E-11)+p[1][7]*pow(2.2E-11,2)); signal_lt0_20->SetBinContent(8,1+p[0][7]*(2.E-11)+p[1][7]*pow(2.E-11,2)); signal_lt0_18->SetBinContent(8,1+p[0][7]*(1.8E-11)+p[1][7]*pow(1.8E-11,2)); signal_lt0_32->SetBinContent(8,1+p[0][7]*(3.2E-11)+p[1][7]*pow(3.2E-11,2)); signal_lt0_34->SetBinContent(8,1+p[0][7]*(3.4E-11)+p[1][7]*pow(3.4E-11,2)); signal_lt0_36->SetBinContent(8,1+p[0][7]*(3.6E-11)+p[1][7]*pow(3.6E-11,2)); signal_lt0_38->SetBinContent(8,1+p[0][7]*(3.8E-11)+p[1][7]*pow(3.8E-11,2)); */ signal_lt0_m50->Multiply(th1wwa); signal_lt0_m30->Multiply(th1wwa); signal_lt0_m80->Multiply(th1wwa); signal_lt0_m28->Multiply(th1wwa); signal_lt0_m26->Multiply(th1wwa); signal_lt0_m24->Multiply(th1wwa); signal_lt0_m22->Multiply(th1wwa); signal_lt0_m20->Multiply(th1wwa); signal_lt0_m18->Multiply(th1wwa); signal_lt0_m32->Multiply(th1wwa); signal_lt0_m34->Multiply(th1wwa); signal_lt0_m36->Multiply(th1wwa); signal_lt0_m38->Multiply(th1wwa); signal_lt0_50->Multiply(th1wwa); signal_lt0_30->Multiply(th1wwa); signal_lt0_80->Multiply(th1wwa); signal_lt0_28->Multiply(th1wwa); signal_lt0_26->Multiply(th1wwa); signal_lt0_24->Multiply(th1wwa); signal_lt0_22->Multiply(th1wwa); signal_lt0_20->Multiply(th1wwa); signal_lt0_18->Multiply(th1wwa); signal_lt0_32->Multiply(th1wwa); signal_lt0_34->Multiply(th1wwa); signal_lt0_36->Multiply(th1wwa); signal_lt0_38->Multiply(th1wwa); signal_lt0_m50->Add(th1wwa,-1); signal_lt0_m30->Add(th1wwa,-1); signal_lt0_m80->Add(th1wwa,-1); signal_lt0_m28->Add(th1wwa,-1); signal_lt0_m26->Add(th1wwa,-1); signal_lt0_m24->Add(th1wwa,-1); signal_lt0_m22->Add(th1wwa,-1); signal_lt0_m20->Add(th1wwa,-1); signal_lt0_m18->Add(th1wwa,-1); signal_lt0_m32->Add(th1wwa,-1); signal_lt0_m34->Add(th1wwa,-1); signal_lt0_m36->Add(th1wwa,-1); signal_lt0_m38->Add(th1wwa,-1); signal_lt0_50->Add(th1wwa,-1); signal_lt0_30->Add(th1wwa,-1); signal_lt0_80->Add(th1wwa,-1); signal_lt0_28->Add(th1wwa,-1); signal_lt0_26->Add(th1wwa,-1); signal_lt0_24->Add(th1wwa,-1); signal_lt0_22->Add(th1wwa,-1); signal_lt0_20->Add(th1wwa,-1); signal_lt0_18->Add(th1wwa,-1); signal_lt0_32->Add(th1wwa,-1); signal_lt0_34->Add(th1wwa,-1); signal_lt0_36->Add(th1wwa,-1); signal_lt0_38->Add(th1wwa,-1); signal_lt0_m50->Scale(1.185/2.1); signal_lt0_m30->Scale(1.185/2.1); signal_lt0_m80->Scale(1.185/2.1); signal_lt0_m28->Scale(1.185/2.1); signal_lt0_m26->Scale(1.185/2.1); signal_lt0_m24->Scale(1.185/2.1); signal_lt0_m22->Scale(1.185/2.1); signal_lt0_m20->Scale(1.185/2.1); signal_lt0_m18->Scale(1.185/2.1); signal_lt0_m32->Scale(1.185/2.1); signal_lt0_m34->Scale(1.185/2.1); signal_lt0_m36->Scale(1.185/2.1); signal_lt0_m38->Scale(1.185/2.1); signal_lt0_50->Scale(1.185/2.1); signal_lt0_30->Scale(1.185/2.1); signal_lt0_80->Scale(1.185/2.1); signal_lt0_28->Scale(1.185/2.1); signal_lt0_26->Scale(1.185/2.1); signal_lt0_24->Scale(1.185/2.1); signal_lt0_22->Scale(1.185/2.1); signal_lt0_20->Scale(1.185/2.1); signal_lt0_18->Scale(1.185/2.1); signal_lt0_32->Scale(1.185/2.1); signal_lt0_34->Scale(1.185/2.1); signal_lt0_36->Scale(1.185/2.1); signal_lt0_38->Scale(1.185/2.1); /* signal_lt0_18->Sumw2(); signal_lt0_20->Sumw2(); signal_lt0_22->Sumw2(); signal_lt0_24->Sumw2(); signal_lt0_26->Sumw2(); signal_lt0_28->Sumw2(); signal_lt0_30->Sumw2(); signal_lt0_32->Sumw2(); signal_lt0_34->Sumw2(); signal_lt0_36->Sumw2(); signal_lt0_38->Sumw2(); signal_lt0_50->Sumw2(); signal_lt0_80->Sumw2(); signal_lt0_m18->Sumw2(); signal_lt0_m20->Sumw2(); signal_lt0_m22->Sumw2(); signal_lt0_m24->Sumw2(); signal_lt0_m26->Sumw2(); signal_lt0_m28->Sumw2(); signal_lt0_m30->Sumw2(); signal_lt0_m32->Sumw2(); signal_lt0_m34->Sumw2(); signal_lt0_m36->Sumw2(); signal_lt0_m38->Sumw2(); signal_lt0_m50->Sumw2(); signal_lt0_m80->Sumw2(); */ /* // Adding 35% Signal K-factor Systematic uncertainty for(int hi=1;hi<=pv.NBINS;hi++){ fperr = pow(signal_lt0_m18->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m18->GetBinContent(hi),2); signal_lt0_m18->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m20->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m20->GetBinContent(hi),2); signal_lt0_m20->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m22->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m22->GetBinContent(hi),2); signal_lt0_m22->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m24->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m24->GetBinContent(hi),2); signal_lt0_m24->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m26->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m26->GetBinContent(hi),2); signal_lt0_m26->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m28->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m28->GetBinContent(hi),2); signal_lt0_m28->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m30->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m30->GetBinContent(hi),2); signal_lt0_m30->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m32->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m32->GetBinContent(hi),2); signal_lt0_m32->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m34->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m34->GetBinContent(hi),2); signal_lt0_m34->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m36->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m36->GetBinContent(hi),2); signal_lt0_m36->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m38->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m38->GetBinContent(hi),2); signal_lt0_m38->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m50->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m50->GetBinContent(hi),2); signal_lt0_m50->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_m80->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_m80->GetBinContent(hi),2); signal_lt0_m80->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_18->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_18->GetBinContent(hi),2); signal_lt0_18->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_20->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_20->GetBinContent(hi),2); signal_lt0_20->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_22->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_22->GetBinContent(hi),2); signal_lt0_22->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_24->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_24->GetBinContent(hi),2); signal_lt0_24->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_26->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_26->GetBinContent(hi),2); signal_lt0_26->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_28->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_28->GetBinContent(hi),2); signal_lt0_28->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_30->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_30->GetBinContent(hi),2); signal_lt0_30->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_32->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_32->GetBinContent(hi),2); signal_lt0_32->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_34->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_34->GetBinContent(hi),2); signal_lt0_34->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_36->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_36->GetBinContent(hi),2); signal_lt0_36->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_38->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_38->GetBinContent(hi),2); signal_lt0_38->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_50->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_50->GetBinContent(hi),2); signal_lt0_50->SetBinError(hi,sqrt(fperr)); fperr = pow(signal_lt0_80->GetBinError(hi),2); fperr += pow(0.28,2)*pow(signal_lt0_80->GetBinContent(hi),2); signal_lt0_80->SetBinError(hi,sqrt(fperr)); } */ //////////////////////// // Set histogram labels: const double BINWIDTH = ((pv.MAXRange-pv.MINRange)/pv.NBINS); char tmpc[100]; sprintf(tmpc,"Events / %.1f GeV",BINWIDTH); if (pv.slog==1) sprintf(tmpc,"Events / %.1f",BINWIDTH); if (pv.slog==2) sprintf(tmpc,"Events / %.2f",BINWIDTH); if (pv.slog==3) sprintf(tmpc,"Events / %.0f GeV",BINWIDTH); if (pv.slog==6) sprintf(tmpc,"Events / %.2f rad",BINWIDTH); signal_lt0_80->SetYTitle(tmpc); signal_lt0_80->GetXaxis()->SetTitle(pv.xlabel); signal_lt0_80->GetYaxis()->CenterTitle(true); signal_lt0_50->SetYTitle(tmpc); signal_lt0_50->GetXaxis()->SetTitle(pv.xlabel); signal_lt0_50->GetYaxis()->CenterTitle(true); signal_lt0_30->SetYTitle(tmpc); signal_lt0_30->GetXaxis()->SetTitle(pv.xlabel); signal_lt0_30->GetYaxis()->CenterTitle(true); signal_lt0_m30->SetYTitle(tmpc); signal_lt0_m30->GetXaxis()->SetTitle(pv.xlabel); signal_lt0_m30->GetYaxis()->CenterTitle(true); signal_lt0_m50->SetYTitle(tmpc); signal_lt0_m50->GetXaxis()->SetTitle(pv.xlabel); signal_lt0_m50->GetYaxis()->CenterTitle(true); signal_lt0_m80->SetYTitle(tmpc); signal_lt0_m80->GetXaxis()->SetTitle(pv.xlabel); signal_lt0_m80->GetYaxis()->CenterTitle(true); ////////////////////////////////////////////////////////// // Save Observed Data, Background (+ SM WWA), Background + // Uncertainty, Background - Uncertainty, Anomalous Signal // histograms to output ROOT file: std::cout<<"Save Histograms..."<<std::endl; f.cd(); signal_lt0_80->Write(); signal_lt0_50->Write(); signal_lt0_30->Write(); signal_lt0_m30->Write(); signal_lt0_m50->Write(); signal_lt0_m80->Write(); bin_1->Write(); bin_2->Write(); bin_3->Write(); bin_4->Write(); bin_5->Write(); bin_6->Write(); bin_7->Write(); bin_8->Write(); bin_9->Write(); bin_10->Write(); p0->Write(); p1->Write(); test->Write(); test2->Write(); test_r->Write(); test2_r->Write(); signal_lt0_m28->Write(); signal_lt0_m26->Write(); signal_lt0_m24->Write(); signal_lt0_m22->Write(); signal_lt0_m20->Write(); signal_lt0_m18->Write(); signal_lt0_m32->Write(); signal_lt0_m34->Write(); signal_lt0_m36->Write(); signal_lt0_m38->Write(); signal_lt0_28->Write(); signal_lt0_26->Write(); signal_lt0_24->Write(); signal_lt0_22->Write(); signal_lt0_20->Write(); signal_lt0_18->Write(); signal_lt0_32->Write(); signal_lt0_34->Write(); signal_lt0_36->Write(); signal_lt0_38->Write(); //For conveners // th1wwa->Write(); // }// End Main function