#include #include "TFile.h" #include "TTree.h" #include "TLeaf.h" #include "TString.h" #include "TH1F.h" #include "TCanvas.h" #include "TROOT.h" #include "TEventList.h" #include "TDirectory.h" #include #include #include "TLine.h" #include "TLatex.h" #include "TStyle.h" #include "TObjArray.h" #include "TPRegexp.h" #include "TRegexp.h" #include "TSystemDirectory.h" #include "TSystemFile.h" #include #include #include typedef std::map CountMap; std::map cuts, files; std::map effs, effb; std::vector modes; CountMap gevtcnt, evtcnt, evcntrec[10]; Int_t ev, run, mode, rec, nbranch; // --------------------------------------------------------------- void init(TTree *t) { t->SetBranchAddress("ev",&ev); t->SetBranchAddress("run",&run); t->SetBranchAddress("mode",&mode); t->SetBranchAddress("recmode",&rec); } // --------------------------------------------------------------- int uid(int lev, int lrun, int lmode) { return lev+10000*lrun+(((lmode/100)%10)*20+lmode%10)*100000; } // --------------------------------------------------------------- int countEvents(TTree *t, TEventList &el) { t->SetBranchStatus("*",0); t->SetBranchStatus("ev",1); t->SetBranchStatus("run",1); t->SetBranchStatus("mode",1); t->SetBranchStatus("recmode",1); evtcnt.clear(); for (int j=0;j<10;++j) evcntrec[j].clear(); for (int i=0;iGetEntry(el.GetEntry(i)); evtcnt[uid(ev,run,mode)] += 1; gevtcnt[uid(ev,run,mode)] += 1; if (rec<10) evcntrec[rec][uid(ev,run,mode)]+=1; } t->SetBranchStatus("*",1); return evtcnt.size(); } // --------------------------------------------------------------- int readmodes(TString fname) { ifstream f(fname.Data()); if (!f.is_open()) { cout <<"Cannot read file "<GetEntries(); TRegexp reg("^M[0-9]+_n[0-9]+.+root"); for (int i=0; iAt(i))->GetName(); TString mpat = fname(reg); if (mpat) { int lmode = TString(mpat(1,3)+mpat(6,3)).Atoi(); files[lmode] = fname; } } } // --------------------------------------------------------------- int simubg(TString cfgfile) { int nmodes = readmodes(cfgfile); readdir(); if (nmodes==0) return; TRegexp rtname("n[0-9][0-9][0-9]"); double sumeffb=0., geffb=0.; TCanvas *c1=new TCanvas("c1","c1",5,5,1800,800); c1->Divide(10,6); gevtcnt.clear(); for( int i=0; iDraw(">>el",cut); //cout <<"el:"<Draw(">>el",cuts[lmode]); t->SetEventList(&el); c1->cd(i%60+1); t->SetLineColor(1); t->Draw("xm"); t->SetLineColor(2); t->Draw("xm","xmct","same"); t->SetLineColor(4); t->Draw("xm","mode%1000==900","same"); c1->Update(); TLatex lat; lat.SetTextSize(0.09); lat.DrawLatex(gPad->GetUxmin()+(gPad->GetUxmax()-gPad->GetUxmin())*0.05,gPad->GetUymax()*0.85,TString::Format("(%02d) %d",i+1,lmode%1000)); lat.DrawLatex(gPad->GetUxmin()+(gPad->GetUxmax()-gPad->GetUxmin())*0.05,gPad->GetUymax()*0.73,TString::Format("S:%4.2f%%",effs[lmode])); lat.DrawLatex(gPad->GetUxmin()+(gPad->GetUxmax()-gPad->GetUxmin())*0.05,gPad->GetUymax()*0.61,TString::Format("B:%4.3f%%",effb[lmode])); c1->Update(); } printf("(%2d) %d (%4.1f, %6.3f; %6.3f; %6.3f) %s : %s\n",i+1, lmode, effs[lmode], effb[lmode], sumeffb, geffb, files[lmode].Data(), cuts[lmode].Data()); } printf("\nSUM(effb) = %6.3f%% SIMU(effb) = %6.3f%%\n",sumeffb, geffb); return 0; }