void annconvergencetest( TDirectory *lhdir ) { TCanvas* c = new TCanvas( "MLPConvergenceTest", "MLP Convergence Test", 150, 0, 600, 580*0.8 ); TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" ); TH1* estimatorHistTest = (TH1*)lhdir->Get( "estimatorHistTest" ); Double_t m1 = estimatorHistTrain->GetMaximum(); Double_t m2 = estimatorHistTest ->GetMaximum(); Double_t max = TMath::Max( m1, m2 ); m1 = estimatorHistTrain->GetMinimum(); m2 = estimatorHistTest ->GetMinimum(); Double_t min = TMath::Min( m1, m2 ); estimatorHistTrain->SetMaximum( max + 0.1*(max - min) ); estimatorHistTrain->SetMinimum( min - 0.1*(max - min) ); estimatorHistTrain->SetLineColor( 2 ); estimatorHistTrain->SetLineWidth( 2 ); estimatorHistTrain->SetTitle( TString("MLP Convergence Test") ); estimatorHistTest->SetLineColor( 4 ); estimatorHistTest->SetLineWidth( 2 ); estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" ); estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" ); estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 ); estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 ); estimatorHistTrain->Draw(); estimatorHistTest ->Draw("same"); // need a legend TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20, 1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 ); legend->AddEntry(estimatorHistTrain,"Training Sample","l"); legend->AddEntry(estimatorHistTest,"Test sample","l"); legend->Draw("same"); legend->SetMargin( 0.3 ); c->cd(); TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-( c->Update(); TString fname = "plots/annconvergencetest"; TMVAGlob::imgconv( c, fname ); }
void ratioPlots( TCanvas* c1, TH1* h_r, TH1* h_i, string xTitle, string yTitle, string savePath, double fitMin=-100000, double fitMax=100000, bool doubleColFit=0 ){ double xMaximum = h_r->GetXaxis()->GetBinUpEdge(h_r->GetXaxis()->GetLast()); double xMinimum = h_r->GetXaxis()->GetBinLowEdge(h_r->GetXaxis()->GetFirst()); double yMaximum; double yMinimum; h_i->Sumw2(); h_r->Sumw2(); TLine* line1 = new TLine(xMinimum,1,xMaximum,1); line1->SetLineColor(1); line1->SetLineWidth(2); line1->SetLineStyle(7); TF1* fpol1 = new TF1("fpol1", "pol1", fitMin, fitMax); fpol1->SetLineColor(2); fpol1->SetLineWidth(3); fpol1->SetLineStyle(7); TH1* hRatio = (TH1*)h_r->Clone("clone_record"); hRatio->Divide(h_i); yMaximum = hRatio->GetMaximum(); yMinimum = hRatio->GetMinimum(0); hRatio->GetYaxis()->SetRangeUser(yMinimum/2.5,yMaximum+yMaximum/5); hRatio->SetXTitle(xTitle.c_str()); hRatio->SetYTitle(yTitle.c_str()); hRatio->SetLineColor(9); hRatio->SetLineWidth(2); hRatio->SetMarkerStyle(8); hRatio->Draw("e"); hRatio->Fit("fpol1", "L"); line1->Draw("SAME"); if(doubleColFit){ double p0=fpol1->GetParameter(0); double p1=fpol1->GetParameter(1); double endPoint=double(fitMax*p1)+p0; double p1new=(endPoint-1)/(fitMax-fitMin); char fun[100], text[100]; sprintf(fun,"x*(%f)+1",p1new); sprintf(text,"Tangent: %f",p1new); TF1* fnew = new TF1("fnew", fun, fitMin, fitMax); fnew->SetLineColor(2); fnew->SetLineWidth(3); fnew->Draw("SAME"); TText* Title = new TText( fitMax/12, yMinimum, text); Title->SetTextColor(2); Title->SetTextSize(0.035); Title->Draw("SAME"); } c1->SaveAs(savePath.c_str()); c1->cd(); }
void makeplotThree(TH1& hist1, TH1& hist2, TH1& hist3, const char* plotname, int log) { hist1.SetLineColor(4); hist1.SetMarkerColor(4); hist3.SetLineColor(2); hist3.SetMarkerColor(2); gStyle->SetOptStat(0); TCanvas* can = new TCanvas( plotname, plotname, 500, 500); hist1.Draw( ); hist2.Draw( "same" ); hist3.Draw( "same" ); TLegend *leg = new TLegend(0.48,0.7,0.89,0.92); leg->AddEntry( &hist1,"CaloJet","LP"); leg->AddEntry( &hist3,"PF Jet","LP"); leg->AddEntry( &hist2,"GenJet","L"); leg->SetFillColor(0); leg->SetLineColor(0); leg->Draw(); can->SetLogy( log ); if(log==2) { can->SetLogy( 1 ); hist1.GetYaxis()->SetMoreLogLabels(); } std::string plot(cmEnergy); plot.append(plotname); can->SaveAs( (plot+".eps").c_str() ); can->SaveAs( (plot+".gif").c_str() ); can->SaveAs( (plot+".root").c_str() ); // delete can; cout << hist1.Integral() << endl; }
double Fit511Photopeak(TH1* h, double* error=0) { TSpectrum spec(1); spec.Search(h); h->GetXaxis()->SetTitle("Energy [photoelectrons]"); h->Draw("e"); TH1* bg = spec.Background(h); TH1* sig = (TH1*)(h->Clone()); sig->SetLineColor(kGreen); sig->Add(bg,-1); sig->Draw("same e"); sig->Fit("gaus","m","same e"); TF1* gaus = sig->GetFunction("gaus"); if(gaus) gaus->SetLineColor(kGreen); bg->SetLineColor(kRed); bg->Draw("same e"); TLine* line = new TLine(gaus->GetParameter(1),0, gaus->GetParameter(1),h->GetMaximum()); line->SetLineColor(kBlue); line->SetLineWidth(2); line->Draw(); double yield = spec.GetPositionX()[0]/epeak; double err = 0; cout<<"Results from TSpectrum: \n\t" <<"Peak = "<<spec.GetPositionX()[0]<<" p.e.; Light Yield = " <<yield<<" p.e./keV"<<endl; if(gaus){ yield = gaus->GetParameter(1)/epeak; err = gaus->GetParError(1)/epeak; cout<<"Results from BG Subtracted Gaus Fit: \n\t" <<"Peak = "<<gaus->GetParameter(1)<<" p.e.; Light Yield = " <<yield<<" +/- "<<err<<" p.e./keV"<<endl; err = max(err, TMath::Abs(yield-spec.GetPositionX()[0]/epeak)); } TLegend* leg = new TLegend(.6,.6,.9,.9); leg->AddEntry(h,"Raw Spectrum","lpe"); leg->AddEntry(bg,"Background","lpe"); leg->AddEntry(sig,"Signal","lpe"); char title[20]; sprintf(title,"Yield = %.2f pe/keV",yield); leg->AddEntry(line, title ,"l"); leg->Draw(); if(error) *error = err; return yield; }
void plotter::draw_output_stat(TH1* output_, TH1* stat_, TH1D* truth_, bool norm, TString file_name){ // std::vector<double> sys = get_sys_errors(); // TH1* output_sys = add_error_bar(output, sys); TH1* output = (TH1*) output_->Clone("output"); TH1* stat = (TH1*) stat_->Clone("stat"); TH1D* truth = (TH1D*) truth_->Clone("truth"); TCanvas *c = new TCanvas("c","",600,600); double ymax; gPad->SetLeftMargin(0.15); if(truth->GetMaximum() > output->GetMaximum()) ymax = 1.5 * truth->GetMaximum(); else ymax = 1.5 * output->GetMaximum(); TGaxis::SetMaxDigits(3); output->SetTitle(" "); output->GetYaxis()->SetRangeUser(0., ymax); output->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); if(norm) output->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]"); else output->GetYaxis()->SetTitle("events"); output->GetYaxis()->SetTitleOffset(1.1); output->GetXaxis()->SetTitleOffset(0.9); output->GetYaxis()->SetTitleSize(0.05); output->GetXaxis()->SetTitleSize(0.05); output->GetYaxis()->SetNdivisions(505); output->SetLineColor(kBlack); output->SetMarkerColor(kBlack); output->SetMarkerStyle(8); output->SetMarkerSize(1); output->Draw("E1"); stat->SetLineColor(kBlack); stat->SetMarkerColor(kBlack); stat->SetMarkerStyle(8); stat->SetMarkerSize(1); gStyle->SetEndErrorSize(5); truth->SetLineWidth(3); truth->SetLineColor(kRed); truth->SetLineStyle(2); truth->Draw("HIST SAME"); stat->Draw("E1 SAME"); output->Draw("E1 SAME"); TLegend *l=new TLegend(0.5,0.65,0.85,0.85); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(output,"data unfolded","pl"); l->AddEntry(truth,"MC particle level","pl"); l->SetTextSize(0.04); l->Draw(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void SetHistAttributes(TH1& h, int color=1, TString xtit="", TString ytit="") { h.SetLineColor(color); h.SetMarkerColor(color); h.SetLineWidth(2); SetTitles( h, xtit, ytit); }
void makeplotTwo(TH1& hist1, TH1& hist2, const char* plotname, int logy) { hist1.SetLineColor(4); hist1.SetMarkerColor(4); gStyle->SetOptStat(0); TCanvas* can = new TCanvas( plotname, plotname, 500, 500); hist1.Draw( ); hist2.Draw( "same" ); TLegend *leg = new TLegend(0.55,0.8,0.89,0.92); leg->AddEntry( &hist1,"Reconstructed","LP"); leg->AddEntry( &hist2,"Generated","L"); leg->SetFillColor(0); leg->SetLineColor(0); leg->Draw(); can->SetLogy( logy ); if(logy==2) hist1.GetYaxis()->SetMoreLogLabels(); std::string plot("ratio-"); plot.append(plotname); can->SaveAs( (plot+".eps").c_str() ); can->SaveAs( (plot+".gif").c_str() ); can->SaveAs( (plot+".root").c_str() ); // delete can; cout << hist1.Integral() << endl; }
/** SetColor/Style Histo */ void SetColorAndStyleHisto(TH1 & histo , EColor color){ histo.SetFillColor (color) ; histo.SetLineColor (color) ; histo.SetMarkerColor (color) ; histo.SetMarkerSize (1) ; histo.SetMarkerStyle (20) ; }
// Make 1D comparison plots void makeplots1D( TH1& eff, TH1& base, TH1& destination, TString name) { gROOT->ProcessLine(".L ~/tdrstyle.C"); setTDRStyle(); TGraphAsymmErrors *g1 = new TGraphAsymmErrors(); g1->BayesDivide(&destination, &base, ""); g1->GetYaxis()->SetRangeUser(0.5, 1.05); eff.SetLineColor(2); eff.SetMarkerStyle(22); eff.SetMarkerSize(1.4); eff.SetMarkerColor(2); // g1->GetYaxis()->SetTitle("Efficiency"); if(name.Contains("_Eta")) g1->GetXaxis()->SetTitle("#eta"); if(name.Contains("_Phi")) g1->GetXaxis()->SetTitle("#phi"); if(name.Contains("_Pt")) g1->GetXaxis()->SetTitle("p_{T} (GeV/c)"); TCanvas canvas("canvas",name,600,600); g1->Draw("APE"); eff.Draw("same"); canvas.SaveAs(name + TString(".eps")); canvas.SaveAs(name + TString(".gif")); canvas.Close(); delete g1; }
void plotter::draw_output_pseudo(TH1* output_, TH1D* pseudotruth_, TH1D* mctruth_, bool norm, TString file_name){ TH1* output = (TH1*) output_->Clone("output"); TH1D* pseudotruth = (TH1D*) pseudotruth_->Clone("pseudotruth"); TH1D* mctruth = (TH1D*) mctruth_->Clone("mctruth"); double ymax_temp = 0; if(pseudotruth->GetMaximum() > ymax_temp) ymax_temp = pseudotruth->GetMaximum(); if(mctruth->GetMaximum() > ymax_temp) ymax_temp = mctruth->GetMaximum(); if(output->GetMaximum() > ymax_temp) ymax_temp = output->GetMaximum(); double ymax = 1.5 * ymax_temp; pseudotruth->SetTitle(" "); pseudotruth->GetYaxis()->SetRangeUser(0., ymax); pseudotruth->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); if(norm) pseudotruth->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]"); else pseudotruth->GetYaxis()->SetTitle("events"); pseudotruth->GetYaxis()->SetTitleOffset(1.1); pseudotruth->GetXaxis()->SetTitleOffset(0.9); pseudotruth->GetYaxis()->SetTitleSize(0.05); pseudotruth->GetXaxis()->SetTitleSize(0.05); pseudotruth->GetYaxis()->SetNdivisions(505); pseudotruth->SetLineWidth(4); pseudotruth->SetLineColor(kRed); mctruth->SetLineWidth(3); mctruth->SetLineStyle(2); mctruth->SetLineColor(kBlue); output->SetLineColor(kBlack); output->SetMarkerColor(kBlack); output->SetMarkerStyle(8); output->SetMarkerSize(1); TCanvas *c= new TCanvas("Particle Level","",600,600); gPad->SetLeftMargin(0.15); TGaxis::SetMaxDigits(3); pseudotruth->Draw("HIST SAME"); mctruth->Draw("HIST SAME"); output->Draw("E1 SAME"); TLegend *l; if(mctruth->GetSize() > 20) l=new TLegend(0.2,0.6,0.4,0.85); else l=new TLegend(0.55,0.6,0.85,0.85); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(output,"pseudo data","pl"); l->AddEntry(pseudotruth,"pseudo data truth","pl"); l->AddEntry(mctruth,"MC truth","pl"); l->SetTextSize(0.04); l->Draw(); gPad->RedrawAxis(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void Legend() { TLegend* leg = new TLegend(.6, .6, .9, .85); leg->SetFillStyle(0); TH1* dummy = new TH1F("", "", 1, 0, 1); dummy->SetMarkerStyle(kFullCircle); leg->AddEntry(dummy->Clone(), "Fake Data", "lep"); dummy->SetLineColor(kTotalMCColor); leg->AddEntry(dummy->Clone(), "Total MC", "l"); dummy->SetLineColor(kNCBackgroundColor); leg->AddEntry(dummy->Clone(), "NC", "l"); dummy->SetLineColor(kNumuBackgroundColor); leg->AddEntry(dummy->Clone(), "#nu_{#mu} CC", "l"); dummy->SetLineColor(kBeamNueBackgroundColor); leg->AddEntry(dummy->Clone(), "Beam #nu_{e} CC", "l"); leg->Draw(); }
void showTauIsolation(TFile* inputFile, const TString& dqmDirectory, const TString& meName, const char* dqmSubDirectoryTauJet, const char* dqmSubDirectoryMuon, const char* dqmSubDirectoryElectron, TCanvas* canvas, TPostScript* ps, const char* outputFileLabel, bool useLogScale) { canvas->SetLogy(useLogScale); TLegend legend(0.74, 0.71, 0.89, 0.89, "", "brNDC"); legend.SetBorderSize(0); legend.SetFillColor(0); TH1* meTauJet = getMonitorElement(inputFile, dqmDirectory, dqmSubDirectoryTauJet, meName); meTauJet->SetMarkerStyle(20); meTauJet->SetMarkerColor(kRed); meTauJet->SetLineColor(kRed); meTauJet->Draw("e1p"); legend.AddEntry(meTauJet, "#tau-Jet", "p"); if ( dqmSubDirectoryMuon != "" ) { TH1* meMuon = getMonitorElement(inputFile, dqmDirectory, dqmSubDirectoryMuon, meName); meMuon->SetMarkerStyle(21); meMuon->SetMarkerColor(kBlue); meMuon->SetLineColor(kBlue); meMuon->Draw("e1psame"); legend.AddEntry(meMuon, "#mu", "p"); } if ( dqmSubDirectoryElectron != "" ) { TH1* meElectron = getMonitorElement(inputFile, dqmDirectory, dqmSubDirectoryElectron, meName); meElectron->SetMarkerStyle(23); meElectron->SetMarkerColor(kGreen); meElectron->SetLineColor(kGreen); meElectron->Draw("e1psame"); legend.AddEntry(meElectron, "e", "p"); } legend.Draw(); canvas->Update(); TString outputFileName = TString("plot").Append(meTauJet->GetName()).Append("_").Append(outputFileLabel).Append(".png"); canvas->Print(outputFileName.Data()); //ps->NewPage(); }
void format1Dhisto(TH1& h1, double Ymax, double Ymin, double& col){ //void format1Dhisto(TH1& h1, string& xTitle, double Ymax, double Ymin){ //h1.SetTitle(";XXXX;XXXX"); if(Ymax!=-1 && Ymin!=-1) h1.GetYaxis()->SetRangeUser(Ymax, Ymin); //if(Ymax==-1 && Ymin!=-1) h1.GetYaxis()->SetMinimum(Ymin); h1.SetMarkerColor(col); h1.SetLineColor(col); return; }
/** * Create ratios to other data * * @param ib Bin number * @param res Result * @param alice ALICE result if any * @param cms CMS result if any * @param all Stack to add ratio to */ void Ratio2Stack(Int_t ib, TH1* res, TGraph* alice, TGraph* cms, THStack* all) { if (!all || !res || !(alice || cms)) return; Int_t off = 5*ib; TGraph* gs[] = { (alice ? alice : cms), (alice ? cms : 0), 0 }; TGraph** pg = gs; while (*pg) { TGraph* g = *pg; const char* n = (g == alice ? "ALICE" : "CMS"); TH1* r = static_cast<TH1*>(res->Clone(Form("ratio%s", n))); TString tit(r->GetTitle()); tit.ReplaceAll("Corrected", Form("Ratio to %s", n)); r->SetTitle(tit); r->SetMarkerColor(g->GetMarkerColor()); r->SetLineColor(g->GetLineColor()); TObject* tst = r->FindObject("legend"); if (tst) r->GetListOfFunctions()->Remove(tst); for (Int_t i = 1; i <= r->GetNbinsX(); i++) { Double_t c = r->GetBinContent(i); Double_t e = r->GetBinError(i); Double_t o = g->Eval(r->GetBinCenter(i)); if (o < 1e-12) { r->SetBinContent(i, 0); r->SetBinError(i, 0); continue; } r->SetBinContent(i, (c - o) / o + off); r->SetBinError(i, e / o); } all->Add(r); pg++; } TLegend* leg = StackLegend(all); if (!leg) return; TString txt = res->GetTitle(); txt.ReplaceAll("Corrected P(#it{N}_{ch}) in ", ""); if (ib == 0) txt.Append(" "); // (#times1)"); // else if (ib == 1) txt.Append(" (#times10)"); else txt.Append(Form(" (+%d)", off)); TObject* dummy = 0; TLegendEntry* e = leg->AddEntry(dummy, txt, "p"); e->SetMarkerStyle(res->GetMarkerStyle()); e->SetMarkerSize(res->GetMarkerSize()); e->SetMarkerColor(kBlack); e->SetFillColor(0); e->SetFillStyle(0); e->SetLineColor(kBlack); }
// Do the loop here, so that we can use options like "errors" void Draw( const TString & xTitle = "", const TString & yTitle = "", const bool errors = false ) { // Create a new THStack so that it handle tha maximum // THStack stack(name_, title_); THStack * stack = new THStack(name_, title_); int colorIndex = 0; if( !(histoList_.empty()) ) { std::vector<TH1*>::iterator histoIter = histoList_.begin(); for( ; histoIter != histoList_.end(); ++histoIter, ++colorIndex ) { TH1 * histo = *histoIter; if(errors) histo->Sumw2(); // histo->SetNormFactor(1); if( colorIndex < 4 ) histo->SetLineColor(colors_[colorIndex]); else histo->SetLineColor(colorIndex); // Draw and get the maximum value TString normalizedHistoName(histo->GetName()); TH1 * normalizedHisto = (TH1*)histo->Clone(normalizedHistoName+"clone"); normalizedHisto->Scale(1/normalizedHisto->Integral()); stack->Add(normalizedHisto); } // Take the maximum of all the drawed histograms // First we need to draw the histogram, or getAxis() will return 0... (see root code...) canvas_->Draw(); canvas_->cd(); stack->Draw("nostack"); stack->GetYaxis()->SetTitleOffset(1.2); stack->GetYaxis()->SetTitle(yTitle); stack->GetXaxis()->SetTitle(xTitle); stack->GetXaxis()->SetTitleColor(kBlack); stack->Draw("nostack"); legend_->Draw("same"); canvas_->Update(); canvas_->Draw(); canvas_->ForceUpdate(); //canvas_->Print("test.pdf"); canvas_->Write(); } }
void DrawReport(const char* psname, TObjArray* harr) { gStyle->SetOptFit(1); if (!harr) harr = &histoArr; TCanvas* cnv = new TCanvas("cl","cl",900,600); // TString psnm1 = psname; if (psnm1.IsNull()) psnm1 = "clusters.ps"; TString psnm0 = psnm1.Data(); psnm0 += "["; TString psnm2 = psnm1.Data(); psnm2 += "]"; cnv->Print(psnm0.Data()); // TH1* clall = GetHistoClSize(0,kNPixAll,harr); clall->SetLineColor(kRed); clall->Draw(); TH1* clSpl = GetHistoClSize(0,kNPixSPL,harr); clSpl->SetLineColor(kBlue); clSpl->Draw("sames"); gPad->Modified(); gPad->Update(); SetStPadPos(clall,0.75,0.97,0.8,1.,-1,clall->GetLineColor()); SetStPadPos(clSpl,0.75,0.97,0.6,0.8,-1,clSpl->GetLineColor()); gPad->Modified(); gPad->Update(); gPad->SetLogy(1); // cnv->cd(); cnv->Print(psnm1.Data()); // // plot cluster sized from 1 to 10 for (int i=1;i<=10;i++) { if (clall->GetBinContent(clall->FindBin(i))<100) continue; DrawNP(i,harr,cnv); cnv->Print(psnm1.Data()); } cnv->Print(psnm2.Data()); }
void format1Dhisto(TH1& h1, double Ymax, double Ymin, double& col, const char* titx, const char* tity ){ //void format1Dhisto(TH1& h1, string& xTitle, double Ymax, double Ymin){ //h1.SetTitle(";XXXX;XXXX"); if(Ymax!=-1 && Ymin!=-1) h1.GetYaxis()->SetRangeUser(Ymax, Ymin); //if(Ymax==-1 && Ymin!=-1) h1.GetYaxis()->SetMinimum(Ymin); h1.SetMarkerColor(col); h1.SetLineColor(col); h1.GetXaxis()->SetTitle(titx); h1.GetYaxis()->SetTitle(tity); //cout<<"The title is : "<<tit<<endl; return; }
void SetStyle(TH1& h, double size, int color, int style, int fillstyle=0, int linestyle=1){ h.SetMarkerSize(size); h.SetMarkerColor(color); h.SetLineColor(color); h.SetMarkerStyle(style); h.SetFillStyle(fillstyle); h.SetLineStyle(linestyle); h.GetXaxis()->SetTitleFont(42); h.GetYaxis()->SetTitleFont(42); h.GetXaxis()->SetTitleSize(0.048); h.GetYaxis()->SetTitleSize(0.048); h.GetXaxis()->CenterTitle(); h.GetYaxis()->CenterTitle(); }
void DrawHijing2GeV() { TCanvas *c1 = new TCanvas(); TFile *fin = TFile::Open("Gamma_Neutron_Hijing_Energy_Graphs.root"); gROOT->cd(); TH1 *h1lim = new TH1F("h1lim","",1,0,0.1); TH1 *hjbkg = (TH1 *) fin->Get("hjbkg")->Clone(); TGraph *anti_neutron2GeV = (TGraph *) fin->Get("anti_neutron2GeV")->Clone(); TGraph *neutron2GeV = (TGraph *) fin->Get("neutron2GeV")->Clone(); h1lim->SetStats(0); h1lim->SetMaximum(0.3); h1lim->SetTitle("2 GeV Hadronic Showers with HIJING background"); h1lim->GetYaxis()->SetTitle("Deposited Energey [GeV]"); h1lim->GetYaxis()->SetTitleOffset(1.2); h1lim->GetXaxis()->SetTitle("cone size (#sqrt{#Delta#Phi^{2}+#Delta#Theta^{2}})"); h1lim->GetXaxis()->SetTitleOffset(1.2); h1lim->Draw(); hjbkg->SetStats(0); hjbkg->SetLineColor(6); hjbkg->SetMaximum(5.5); hjbkg->SetLineWidth(2); hjbkg->Draw("same"); anti_neutron2GeV->SetLineColor(4); anti_neutron2GeV->SetLineWidth(2); anti_neutron2GeV->Draw("same"); neutron2GeV->SetLineColor(2); neutron2GeV->SetLineWidth(2); neutron2GeV->Draw("same"); TLine *tl = new TLine(); tl->SetLineStyle(2); tl->DrawLine(0.024,0,0.024,0.3); TLegend *legrda = new TLegend(0.67,0.34,0.87,0.54,NULL,"brNDC"); legrda->SetLineColor(1); legrda->SetLineStyle(1); legrda->SetLineWidth(1); legrda->SetFillColor(10); legrda->SetFillStyle(1001); legrda->SetBorderSize(0); // legrda->SetTextSize(labelsize); legrda->AddEntry(hjbkg,"HIJING bkg"); legrda->AddEntry(anti_neutron2GeV,"2 GeV Anti Neutron","l"); legrda->AddEntry(neutron2GeV,"2 GeV Neutron", "l"); legrda->AddEntry(tl,"EMCal tower size","l"); legrda->Draw(); fin->Close(); c1->Print("Hijing2GeV.png"); }
void plotter::draw_delta(TH1* hist_, TString file_name){ TH1* hist = (TH1*) hist_->Clone("hist"); TCanvas *c= new TCanvas("Particle Level","",600,600); gPad->SetLeftMargin(0.15); hist->SetTitle(file_name); hist->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); hist->GetYaxis()->SetTitle("#Delta events"); hist->GetYaxis()->SetTitleOffset(1.5); hist->GetYaxis()->SetNdivisions(505); hist->SetFillColor(810); hist->SetLineColor(810); hist->Draw("HIST"); gPad->RedrawAxis(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void histogramStyle(TH1& hist, int color, int lineStyle, int markerStyle, float markersize, int filled) { hist.SetLineWidth(3); hist.SetStats(kFALSE); hist.SetLineColor (color); hist.SetMarkerColor(color); hist.SetMarkerStyle(markerStyle); hist.SetMarkerSize(markersize); hist.SetLineStyle(lineStyle); if(filled==1){ hist.SetFillStyle(1001); hist.SetFillColor(color); } else{ hist.SetFillStyle(0); } }
void boostcontrolplots( TDirectory *boostdir ) { const Int_t nPlots = 4; Int_t width = 900; Int_t height = 600; char cn[100]; const TString titName = boostdir->GetName(); sprintf( cn, "cv_%s", titName.Data() ); TCanvas *c = new TCanvas( cn, Form( "%s Control Plots", titName.Data() ), width, height ); c->Divide(2,2); const TString titName = boostdir->GetName(); TString hname[nPlots]={"Booster_BoostWeight","Booster_MethodWeight","Booster_ErrFraction","Booster_OrigErrFraction"}; for (Int_t i=0; i<nPlots; i++){ Int_t color = 4; TPad * cPad = (TPad*)c->cd(i+1); TH1 *h = (TH1*) boostdir->Get(hname[i]); TString plotname = h->GetName(); h->SetMaximum(h->GetMaximum()*1.3); h->SetMinimum( 0 ); h->SetMarkerColor(color); h->SetMarkerSize( 0.7 ); h->SetMarkerStyle( 24 ); h->SetLineWidth(1); h->SetLineColor(color); h->Draw(); c->Update(); } // write to file TString fname = Form( "plots/%s_ControlPlots", titName.Data() ); TMVAGlob::imgconv( c, fname ); }
TH1* compRatioHistogram(const std::string& ratioHistogramName, const TH1* numerator, const TH1* denominator) { TH1* histogramRatio = 0; if ( numerator->GetDimension() == denominator->GetDimension() && numerator->GetNbinsX() == denominator->GetNbinsX() ) { histogramRatio = (TH1*)numerator->Clone(ratioHistogramName.data()); histogramRatio->Divide(denominator); int nBins = histogramRatio->GetNbinsX(); for ( int iBin = 1; iBin <= nBins; ++iBin ){ double binContent = histogramRatio->GetBinContent(iBin); histogramRatio->SetBinContent(iBin, binContent - 1.); } histogramRatio->SetLineColor(numerator->GetLineColor()); histogramRatio->SetLineWidth(numerator->GetLineWidth()); histogramRatio->SetMarkerColor(numerator->GetMarkerColor()); histogramRatio->SetMarkerStyle(numerator->GetMarkerStyle()); histogramRatio->SetMarkerSize(numerator->GetMarkerSize()); } return histogramRatio; }
void patBJetTracks_efficiencies() { // define proper canvas style setNiceStyle(); gStyle->SetOptStat(0); // open file TFile* file = new TFile("analyzePatBJetTracks.root"); TLegend *legend[3] = { 0, 0, 0 }; // draw canvas with efficiencies TCanvas *canv; canv = new TCanvas("canv0", "hand-crafted track counting efficiencies", 800, 300); canv->Divide(3, 1); TH1 *total = (TH1*)file->Get(Form("%s/flavours", directory)); TH1 *effVsCutB = 0; unsigned int i = 0; for(const char **flavour = flavours; *flavour; flavour++, i++) { TH1 *h = (TH1*)file->Get(Form("%s/trackIPSig_%s", directory, *flavour)); TH1 *discrShape = (TH1*)h->Clone(Form("%s_discrShape", h->GetName())); discrShape->Scale(1.0 / discrShape->Integral()); discrShape->SetMaximum(discrShape->GetMaximum() * 5); TH1 *effVsCut = computeEffVsCut(h, total->GetBinContent(4 - i)); TH1 *effVsBEff = 0; if (flavour == flavours) // b-jets effVsCutB = effVsCut; else effVsBEff = computeEffVsBEff(effVsCut, effVsCutB); discrShape->SetTitle("discriminator shape"); effVsCut->SetTitle("efficiency versus discriminator cut"); if (effVsBEff) effVsBEff->SetTitle("mistag versus b efficiency"); setHistStyle(discrShape); setHistStyle(effVsCut); setHistStyle(effVsBEff); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape->SetLineColor(i + 1); discrShape->SetMarkerColor(i + 1); discrShape->Draw(i > 0 ? "same" : ""); if (!legend[0]) legend[0] = new TLegend(0.5, 0.7, 0.78, 0.88); legend[0]->AddEntry(discrShape, *flavour); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut->SetLineColor(i + 1); effVsCut->SetMarkerColor(i + 1); effVsCut->Draw(i > 0 ? "same" : ""); if (!legend[1]) legend[1] = new TLegend(0.12, 0.12, 0.40, 0.30); legend[1]->AddEntry(effVsCut, *flavour); if (!effVsBEff) continue; canv->cd(3); gPad->SetLogy(1); gPad->SetGridx(1); gPad->SetGridy(1); effVsBEff->SetLineColor(i + 1); effVsBEff->SetMarkerColor(i + 1); effVsBEff->Draw(i > 1 ? "same" : ""); if (!legend[2]) legend[2] = new TLegend(0.12, 0.7, 0.40, 0.88); legend[2]->AddEntry(effVsBEff, *flavour); } canv->cd(1); legend[0]->Draw(); canv->cd(2); legend[1]->Draw(); canv->cd(3); legend[2]->Draw(); //////////////////////////////////////////// // canvas to compare negative tagger with light flavour mistag TCanvas *canv; canv = new TCanvas("canv1", "comparing light flavour mistag with negative tagger", 530, 300); canv->Divide(2, 1); TH1 *h1 = (TH1*)file->Get(Form("%s/trackIPSig_udsg", directory)); TH1 *h2 = (TH1*)file->Get(Form("%s/negativeIPSig_all", directory)); h2 = invertHisto(h2); // invert x-axis TH1 *discrShape1 = (TH1*)h1->Clone("discrShape1"); TH1 *discrShape2 = (TH1*)h2->Clone("discrShape2"); discrShape1->Scale(1.0 / discrShape1->Integral()); discrShape1->SetMaximum(discrShape1->GetMaximum() * 5); discrShape2->Scale(1.0 / discrShape2->Integral()); TH1 *effVsCut1 = computeEffVsCut(h1, total->GetBinContent(2)); TH1 *effVsCut2 = computeEffVsCut(h2, total->GetBinContent(1)); discrShape1->SetTitle("discriminator shape"); effVsCut1->SetTitle("efficiency versus discriminator cut"); setHistStyle(discrShape1); setHistStyle(discrShape2); setHistStyle(effVsCut1); setHistStyle(effVsCut2); canv->cd(1); gPad->SetLogy(1); gPad->SetGridy(1); discrShape1->SetLineColor(1); discrShape1->SetMarkerColor(1); discrShape2->SetLineColor(2); discrShape2->SetMarkerColor(2); discrShape1->Draw(); discrShape2->Draw("same"); TLegend *l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(discrShape1, "udsg"); l->AddEntry(discrShape2, "inv. neg"); l->Draw(); canv->cd(2); gPad->SetLogy(1); gPad->SetGridy(1); effVsCut1->SetLineColor(1); effVsCut1->SetMarkerColor(1); effVsCut2->SetLineColor(2); effVsCut2->SetMarkerColor(2); effVsCut1->Draw(); effVsCut2->Draw("same"); l = new TLegend(0.5, 0.7, 0.78, 0.88); l->AddEntry(effVsCut1, "udsg"); l->AddEntry(effVsCut2, "inv. neg"); l->Draw(); }
TCanvas* plotting36GS( bool logScale=false ) { std::cout << "plotting mu + standalone " << std::endl; TGaxis::SetMaxDigits(3); // channels, ordered as in the legend vector<TString> channels; vector<TString> hnames; vector<TString> type; map<TString,int> fillColor_; map<TString,int> lineColor_; int lineWidth1(2); int lineWidth2(1); bool salamanderStyle=true; if( salamanderStyle ) { fillColor_["Signal"] = kOrange-2; lineColor_["Signal"] = kOrange+3; fillColor_["EWK"] = kOrange+7; lineColor_["EWK"] = kOrange+3; fillColor_["QCD"] = kViolet-5; lineColor_["QCD"] = kViolet+3; fillColor_["ttbar"] = kRed+2; lineColor_["ttbar"] = kRed+4; fillColor_["gamma+jet"] = kMagenta+4; lineColor_["gamma+jet"] = kViolet+3; } else { lineWidth1 = 2; lineWidth2 = 2; fillColor_["Signal"] = kPink+6; lineColor_["Signal"] = kMagenta+3; fillColor_["EWK"] = kAzure+8; lineColor_["EWK"] = kAzure+4; fillColor_["QCD"] = kYellow-7; lineColor_["QCD"] = kYellow+4; fillColor_["ttbar"] = kGreen; lineColor_["ttbar"] = kGreen+2; fillColor_["gamma+jet"] = kOrange; lineColor_["gamma+jet"] = kOrange+2; } // root file, where the data is TString fname("root/"); // histogram limits, in linear and logarithmic int nbin_(100); float xmin_(0.), xmax_(0.); float ymin_(0.), ymax_(0.); float yminl_(0.), ymaxl_(0.); // titles and axis, marker size TString xtitle; TString ytitle; int ndivx(510); int ndivy(510); float markerSize(0.); float titleOffset(1.); float r0_ = 1.; float dr_ = 0.3; if( use_chi ) { r0_ = 0.; dr_ = 7.5; //dr_ = 3.0; } // canvas name TString cname(""); TString ctitle; // legend position and scale; float xl_ = 0.; float yl_ = 0.; float scalel_ = 0.0; { if( logScale ) // fname += "Zmumu_40-200_36pb"; fname += "Zmusta_36pb"; else fname += "Zmusta_36pb"; if( logScale ) { lineWidth1 = 1; lineWidth2 = 1; } channels.push_back("Zmumu"); hnames.push_back(" Z #rightarrow #mu^{+}#mu^{-}"); type.push_back("Signal"); bool revert(false); if( logScale ) { if( revert ) { channels.push_back("EWK"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("tt"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCD"); hnames.push_back(" QCD"); type.push_back("QCD"); } else { channels.push_back("EWK"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("tt"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCD"); hnames.push_back(" QCD"); type.push_back("QCD"); } } if( !logScale ) { // lin scale xmin_ = 60; xmax_ = 120; ymin_ = 0.01; ymax_ = 2100; } else { // log scale xmin_ = 40; xmax_ = 200; yminl_ = 0.08; ymaxl_ = 3000; } xtitle = "M(#mu^{+}#mu^{-}) [GeV]"; ytitle = "number of events /"; ndivx = 504; if( logScale ) { ytitle += "5 GeV"; ndivy = 510; } else { ytitle += " GeV"; ndivy = 506; } if( logScale ) { markerSize = 0.48; } else { markerSize = 0.75; } cname += "Zmusta"; ctitle = "Z to mu sta analysis"; if( logScale ) { xl_ = 0.60; yl_ = 0.50; scalel_ = 0.065; } else { xl_ = 0.22; yl_ = 0.50; scalel_ = 0.072; } } if( logScale ) cname += "MuSta_log"; else cname += "MuStaNotInThePAPER_lin"; //Open the root file containing histograms and graphs fname += ".root"; TFile* f_ = TFile::Open(fname,"READ"); TCanvas* c_ = new TCanvas(cname,ctitle,300,300,479,510); c_->SetLeftMargin( 87./479 ); c_->SetRightMargin( 42./479 ); c_->SetTopMargin( 30./510 ); c_->SetBottomMargin( 80./510 ); c_->SetFillColor(0); c_->SetTickx(1); c_->SetTicky(1); c_->SetFrameFillStyle(0); c_->SetFrameLineWidth(2); c_->SetFrameBorderMode(0); Double_t scale = 4; Double_t wbin = 42*scale; Double_t left = 8*scale; Double_t right = 5*scale; Double_t h1 = 135*scale; Double_t h2 = 45*scale; Double_t top1 = 15*scale; Double_t bot1 = 3*scale; Double_t top2 = 3*scale; // Double_t bot1 = 0*scale; // Double_t top2 = 0*scale; Double_t bot2 = 80*scale; Double_t W = left + wbin + right; Double_t H = h1 + h2; Double_t s[2] = {1, h1/h2 }; TPad* pad[2]; pad[0] = new TPad( "top", "top", 0, h2/H, 1, 1, kWhite,0,0); pad[0]->SetLeftMargin( left/W ); pad[0]->SetRightMargin( right/W ); pad[0]->SetTopMargin( top1/H ); pad[0]->SetBottomMargin( bot1/H ); pad[1] = new TPad( "bottom", "bottom", 0, 0, 1, h2/H, kWhite,0,0); pad[1]->SetLeftMargin( left/W ); pad[1]->SetRightMargin( right/W ); pad[1]->SetTopMargin( top2/H ); pad[1]->SetBottomMargin( bot2/H ); pad[1]->SetGridy(); for( int ii=0; ii<2; ii++ ) { pad[ii]->SetFillColor(0); pad[ii]->SetTickx(1); pad[ii]->SetTicky(1); pad[ii]->SetFrameFillStyle(0); pad[ii]->SetFrameLineWidth(2); pad[ii]->SetFrameBorderMode(0); pad[ii]->SetFrameFillStyle(0); pad[ii]->SetFrameLineWidth(2); pad[ii]->SetFrameBorderMode(0); } // a dummy histogram with the correct x axis // Warning: setTDRstyle() must be called before TH1F* h_= new TH1F( "bidon", "bidon", nbin_, xmin_, xmax_ ); TAxis* ax_ = h_->GetXaxis(); TAxis* ay_ = h_->GetYaxis(); ax_->SetTitle(xtitle); ax_->CenterTitle(); ax_->SetTitleOffset(1.0); ax_->SetNdivisions(ndivx); ay_->SetTitle(ytitle); ay_->CenterTitle(); ay_->SetNdivisions(ndivy); ay_->SetTitleOffset(titleOffset); ay_->SetLabelOffset(0.015); // fetch histograms and dress them vector<TH1F*> histos; size_t nChan=channels.size(); for( size_t ii=0;ii<nChan;ii++) { TH1F* tmp = (TH1F*)f_->Get(channels[ii]); tmp->SetFillColor( fillColor_[type[ii]] ); tmp->SetLineColor( lineColor_[type[ii]] ); tmp->SetLineWidth( lineWidth2 ); histos.push_back(tmp); } // // stack histograms // TH1* h_stack = (TH1*) histos[nChan-1]->Clone(); h_stack -> Reset(); TString stackName_ = TString("Mll"); vector<TH1*> listOfStackedHists; for( size_t ii=0; ii<nChan; ii++ ) { TH1* hh_ = (TH1*) histos[nChan-ii-1]->Clone(); stackName_ += "_"; stackName_ += hh_->GetName(); TAxis* xaxis = h_stack->GetXaxis(); for( int iBin=1; iBin<=xaxis->GetNbins(); iBin++ ) { hh_ -> AddBinContent( iBin, h_stack->GetBinContent( iBin ) ); } hh_->SetName( stackName_ ); delete h_stack; h_stack = hh_; listOfStackedHists.push_back( (TH1*)hh_->Clone() ); } delete h_stack; TH1* totalHisto = listOfStackedHists[nChan-1]; // colors the stacked histogram totalHisto->SetLineColor( lineColor_["Signal"] ); totalHisto->SetLineWidth( lineWidth1 ); // The data points are presented as a TGraph // - error bars indicate the Poisson confidence interval at 68% // - bins with zero entry are removed TH1* hdata = (TH1*) f_->Get("hdata"); // hdata->Sumw2(); //hdata->Rebin(2); RooHist* roohist; TGraphAsymmErrors* dataGraph; roohist = new RooHist((*hdata)); int Nn0=0; vector<double> vY; vector<double> vX; vector<double > veY; vector<double > veX; vector<double> tmp(0,2); for(int ip=0;ip<roohist->GetN();ip++) { double Y,X; roohist->GetPoint(ip,X,Y); if(Y!=0) { Nn0++; vY.push_back(Y); vX.push_back(X); veX.push_back( roohist->GetErrorXlow(ip) ); veX.push_back( roohist->GetErrorXhigh(ip) ); veY.push_back( roohist->GetErrorYlow(ip) ); veY.push_back( roohist->GetErrorYhigh(ip) ); } } dataGraph=new TGraphAsymmErrors(Nn0); for(int ip=0;ip<Nn0;ip++) { dataGraph->SetPoint(ip,vX[ip],vY[ip]); dataGraph->SetPointError(ip,veX[ip*2],veX[ip*2+1],veY[ip*2],veY[ip*2+1]); } dataGraph->SetName("data"); dataGraph->SetMarkerStyle(kFullCircle); dataGraph->SetMarkerColor(kBlack); dataGraph->SetMarkerSize(markerSize); TGraph* dummyGraph = (TGraph*) dataGraph->Clone("dummyGraph"); dummyGraph->SetLineColor(0); dummyGraph->SetMarkerSize(1.5*markerSize); // Remove the horizontal bars (at Michael's request) double x_(0), y_(0); for( int ii=0; ii<dataGraph->GetN(); ii++ ) { dataGraph->SetPointEXlow(ii,0); dataGraph->SetPointEXhigh(ii,0); dataGraph->GetPoint(ii,x_,y_ ); if( y_==0 ) { dataGraph->RemovePoint( ii ); ii--; } } // get the ratio data/fit TGraphAsymmErrors* ratioGraph = (TGraphAsymmErrors*) dataGraph->Clone("ratio"); TH1* hfit = totalHisto; for( int ii=0; ii<dataGraph->GetN(); ii++ ) { dataGraph->GetPoint(ii,x_,y_ ); ratioGraph->SetPointEYlow(ii,0); ratioGraph->SetPointEYhigh(ii,0); ratioGraph->SetPoint(ii,x_,0 ); double eyl_ = dataGraph->GetErrorYlow(ii); double eyh_ = dataGraph->GetErrorYhigh(ii); int jj = hfit->FindBin(x_); float fit_ = hfit->GetBinContent( jj ); if( fit_>0 ) { if( use_chi ) { ratioGraph->SetPointEYlow(ii,eyl_/sqrt(fit_)); ratioGraph->SetPointEYhigh(ii,eyh_/sqrt(fit_)); ratioGraph->SetPoint(ii,x_,(y_-fit_)/sqrt(fit_) ); } else { ratioGraph->SetPointEYlow(ii,eyl_/fit_); ratioGraph->SetPointEYhigh(ii,eyh_/fit_); ratioGraph->SetPoint(ii,x_,y_/fit_ ); } } // cout << ii << " ratio=" << ratioGraph->GetY()[ii] // << "+" << ratioGraph->GetEYhigh()[ii] // << "-" << ratioGraph->GetEYlow()[ii] << endl; } TH1* hratio_ = (TH1*) h_->Clone("hratio"); ax_->SetLabelOffset(99); ax_->SetTitleOffset(99); // // now plotting // c_->Draw(); c_->cd(); TPad* p_ = pad[0]; p_->Draw(); p_->cd(); if( logScale ) { p_->SetLogy(true); } else { p_->SetLogy(false); } if( !logScale ) { h_->GetYaxis()->SetRangeUser(ymin_+0.001*(ymax_-ymin_),ymax_); } else { h_->GetYaxis()->SetRangeUser(yminl_,ymaxl_); } h_->Draw(); float dxl_ = scalel_*3.5; float dyl_ = scalel_*1.8; if( logScale ) { dxl_ = scalel_*4; dyl_ = scalel_*3.4; } TLegend* legend=new TLegend(xl_,yl_,xl_+dxl_,yl_+dyl_); legend->SetLineColor(0); legend->SetFillColor(0); legend->SetTextFont(42); legend->SetTextSize(0.048); legend->AddEntry(dummyGraph," data","pl"); if( logScale ) { legend->AddEntry(dummyGraph," ","0"); } for(size_t ii=0;ii<nChan;ii++) { legend->AddEntry(histos[ii],hnames[ii],"f"); } legend->Draw("same"); totalHisto->Draw("same"); for( size_t ii=0; ii<nChan; ii++ ) { // listOfStackedHists[nChan-ii-1]->Sumw2(); listOfStackedHists[nChan-ii-1]->Rebin(1.); listOfStackedHists[nChan-ii-1]->Scale(1.); listOfStackedHists[nChan-ii-1]->Draw("Same"); } // draw the data points dataGraph->Draw("PE"); // redraw axis p_->RedrawAxis(); //lumi pad, cms prelim pad etc.. { int txtFont = 42; // bold is 62 float txtSize1 = 0.055; float txtX1 = 0.91; float txtY1 = 0.935; float txtSize2 = 0.05; float txtX2 = 0.85; float txtY2 = 0.83; // TEST FOR THE NAME ZMT, ZMMNONISO, ZMS float txtSize3 = 0.055; float txtX3 = 0.3; float txtY3 = 0.935; TLatex latex; latex.SetNDC(); latex.SetTextFont(txtFont); latex.SetTextSize(txtSize1); latex.SetTextAlign(31); // align right latex.DrawLatex(txtX1,txtY1,"CMS"); latex.SetTextAlign(31); // align right latex.SetTextSize(txtSize2); latex.DrawLatex(txtX2,txtY2,"36 pb^{-1} at #sqrt{s} = 7 TeV"); latex.SetTextAlign(21); // align left??? latex.SetTextSize(txtSize3); latex.DrawLatex(txtX3,txtY3,"global plus standalone muon"); } c_->cd(); p_ = pad[1]; p_->Draw(); p_->cd(); TAxis* xratio_ = hratio_->GetXaxis(); TAxis* yratio_ = hratio_->GetYaxis(); yratio_->SetRangeUser(r0_-0.9999*dr_,r0_+0.9999*dr_); yratio_->SetLabelSize( s[1]*yratio_->GetLabelSize() ); yratio_->SetTitleSize( s[1]*yratio_->GetTitleSize() ); yratio_->SetLabelOffset( yratio_->GetLabelOffset() ); yratio_->SetTitleOffset( yratio_->GetTitleOffset()/s[1] ); if( use_chi ) { yratio_->SetTitle("#chi"); yratio_->SetNdivisions(4); } else { yratio_->SetTitle("data/fit"); yratio_->SetNdivisions(3); } xratio_->SetLabelSize( s[1]*xratio_->GetLabelSize() ); xratio_->SetTitleSize( s[1]*xratio_->GetTitleSize() ); xratio_->SetTitleOffset( 1.0 ); xratio_->CenterTitle(); xratio_->SetLabelOffset( xratio_->GetLabelOffset()*s[1] ); xratio_->SetTickLength( xratio_->GetTickLength()*s[1] ); hratio_->Draw(); ratioGraph->SetMarkerSize( ratioGraph->GetMarkerSize()*1. ); ratioGraph->SetLineColor( kBlack ); ratioGraph->SetMarkerColor( kGray+2 ); ratioGraph->SetMarkerStyle( kFullCircle ); ratioGraph->DrawClone("PE"); ratioGraph->SetMarkerColor( kBlack ); ratioGraph->SetMarkerStyle( kOpenCircle ); ratioGraph->DrawClone("PE"); p_->RedrawAxis(); c_->cd(); return c_; }
/** * Extract ALICE PbPb @ 5.02TeV over |eta|<2 * * @param filename Input file name * @param outname Output file name * @param reweigh Whether it is reweighed */ void Extract(const char* filename="dndneta.pbpb502.20151124.root", const char* outname="TRACKLETS_5023_PbPb.input", Bool_t reweigh=false) { if (filename == 0) return; TFile* file = TFile::Open(filename, "READ"); TObjArray* arr = static_cast<TObjArray*>(file->Get("TObjArray")); // Now count number of bins Int_t nBins = 0; TIter next(arr); TObject* obj = 0; while ((obj = next())) { if (TString(obj->GetName()).Contains("DataCorrSignal")) nBins++; } Info("ExtractdNdeta", "Defining %d centrality bins", nBins); TArrayD c(nBins+1); if (nBins == 5) { c[0] = 0; c[1] = 10; c[2] = 20; c[3] = 40; c[4] = 60; c[5] = 80; } else if (nBins >= 9) { c[0] = 0; c[1] = 5; c[2] = 10; c[3] = 20; c[4] = 30; c[5] = 40; c[6] = 50; c[7] = 60; c[8] = 70; c[9] = 80; if (nBins >= 10) c[10] = 90; if (nBins >= 11) c[11] = 100; } THStack* all = new THStack("all","all"); std::ofstream out(outname); std::ostream& o = out; // std::cout; // std::ostream& o = std::cout; o << "*author: SHAHOYAN : 2015\n" << "*title: Full centrality dependence of the charged " << "particle pseudo-rapidity density over the widest " << "possible pseudo-rapidity range in Pb-Pb collisions " << "at 5.02 TeV\n" << "*detector: TRACKLETS\n" << "*experiment: CERN-LHC-TRACKLETS\n" << "*comment: CERN-LHC: We present the charged particle pseudo-rapidity " << "density of charged particles in Pb-Pb collisions at sqrt(s)/nucleon " "= 5.02 over the widest possible pseudo-rapidity and centrality range " << "possible.\n" << std::endl; for (Int_t i = 0; i < nBins; i++) { TString hName = Form("bin%d_DataCorrSignal_PbPb",i); TH1* h = static_cast<TH1*>(arr->FindObject(hName)); if (!h) { hName.ReplaceAll("PbPb", "PBPB"); h = static_cast<TH1*>(arr->FindObject(hName)); if (!h) { Warning("", "Histogram (%s) missing for bin %d", hName.Data(), i); arr->Print(); continue; } } Color_t col = PbPbColor(c[i], c[i+1]); h->SetLineColor(col); h->SetMarkerColor(col); h->SetFillColor(col); all->Add(h); Info("","Making GSE for %0d%% to %3d%% (%d)", Int_t(c[i]), Int_t(c[i+1]), col); MakeGSE(o, h, c[i], c[i+1], reweigh); } // all->Draw("nostack"); o << "*E" << std::endl; out.close(); TCanvas* can = new TCanvas("c","C", 1600, 800); can->SetRightMargin(0.2); can->SetTopMargin(0.01); TLegend* cl = new TLegend(1-can->GetRightMargin(), can->GetBottomMargin(),.99, 1-can->GetTopMargin()); cl->SetFillStyle(0); cl->SetBorderSize(0); gROOT->LoadMacro("$HOME/GraphSysErr/GraphSysErr.C+"); TList* ll = GraphSysErr::Import(outname); // ll->ls(); TIter next(ll); TObject* obj = 0; Bool_t first = true; TH1* frame = 0; Double_t min=100000, max=0; Int_t i = 0; while ((obj = next())) { if (c[i+1] > 80) break; GraphSysErr* g = static_cast<GraphSysErr*>(obj); Color_t col = PbPbColor(c[i], c[i+1]); TLegendEntry* e = cl->AddEntry("", Form("%4.1f-%4.1f%%", c[i], c[i+1]), "F"); e->SetFillColor(col); e->SetFillStyle(1001); g->SetLineColor(col); g->SetMarkerColor(col); g->SetFillColor(col); // g->Print("qual"); g->SetDataOption(GraphSysErr::kNoTick); g->SetSumOption(GraphSysErr::kBox); g->SetSumLineColor(col); g->SetSumFillColor(col); g->SetCommonSumOption(GraphSysErr::kBox); g->SetCommonSumLineColor(col); g->SetCommonSumFillColor(col); g->SetName(Form("tracklets%03dd%02d_%03dd%02d", Int_t(c[i]), Int_t(c[i]*100) % 100, Int_t(c[i+1]), Int_t(c[i+1]*100) % 100)); g->SetTitle(Form("%4.1f - %4.1f%%", c[i], c[i+1])); if (first) g->Draw("combine stat quad axis xbase=2.5"); else g->Draw("combine stat quad xbase=2.5"); if (!frame) frame = g->GetMulti()->GetHistogram(); first = false; Double_t mn, mx; g->GetMinMax("combine stat quad", mn, mx); FindLeastLargest(g, c[i], c[i+1]); min = TMath::Min(min, mn); max = TMath::Max(max, mx); i++; } frame->SetMinimum(min*.9); frame->SetMaximum(max*1.1); cl->Draw(); TFile* outFile = TFile::Open(Form("PbPb5023midRapidity%s.root", reweigh ? "Reweighed" : "Normal"), "RECREATE"); ll->Write("container",TObject::kSingleKey); outFile->Write(); can->SaveAs(Form("PbPb5023midRapidity%s.png", reweigh ? "Reweighed" : "Normal")); }
void plot_MistagRate_allSamples(string sample="TTbar_", int wjets_hadtau_only=0){ // // icomp=0: only show own results // 1: show also Koushik's results // // /////////////////////////////////////////////////////////////////////////////////////////// ////Some cosmetic work for official documents. gStyle->SetOptStat(0); ///to avoid the stat. on the plots gROOT->LoadMacro("tdrstyle.C"); // setTDRStyle(); gROOT->LoadMacro("CMS_lumi_v2.C"); char tempname[200]; char tempname2[200]; int W = 800; int H = 600; int H_ref = 600; int W_ref = 800; float T = 0.08*H_ref; float B = 0.12*H_ref; float L = 0.12*W_ref; float R = 0.04*W_ref; TCanvas* c1 = new TCanvas("name","name",10,10,W,H); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetFrameFillStyle(0); c1->SetFrameBorderMode(0); c1->SetLeftMargin( L/W ); c1->SetRightMargin( R/W ); c1->SetTopMargin( T/H ); c1->SetBottomMargin( B/H ); c1->SetTickx(0); c1->SetTicky(0); Float_t legendX1 = .15; //.50; Float_t legendX2 = .50; //.70; Float_t legendY1 = .55; //.65; Float_t legendY2 = .88; TLegend* catLeg1 = new TLegend(legendX1,legendY1,legendX2,legendY2); catLeg1->SetTextSize(0.042); catLeg1->SetTextFont(42); catLeg1->SetFillColor(0); catLeg1->SetLineColor(0); catLeg1->SetBorderSize(0); TH1D * temp_tt_tauH, * temp_wj_tauH, *temp_tt_muH, * temp_wj_muH; // // From W+jets TFile file_WJet("Stack/TauBtaggedRate_WJet_stacked.root","R"); temp_wj_tauH = (TH1D*)file_WJet.Get("TauBtaggedRate")->Clone(); TH1D * wj_tauH = new TH1D("wj_tauH","WJet -- Tau mistag",temp_wj_tauH->GetNbinsX(),temp_wj_tauH->GetXaxis()->GetXmin(),temp_wj_tauH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<wj_tauH->GetNbinsX()+2;ibin++){ double con = (double)temp_wj_tauH->GetBinContent(ibin); double err = (double)temp_wj_tauH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; wj_tauH->SetBinContent(ibin,con); wj_tauH->SetBinError(ibin,err); } // // From ttbar TFile file_TTbar("Stack/TauBtaggedRate_TTbar_stacked.root","R"); temp_tt_tauH = (TH1D*)file_TTbar.Get("TauBtaggedRate")->Clone(); TH1D * tt_tauH = new TH1D("tt_tauH","WJet -- Tau mistag",temp_tt_tauH->GetNbinsX(),temp_tt_tauH->GetXaxis()->GetXmin(),temp_tt_tauH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<tt_tauH->GetNbinsX()+2;ibin++){ double con = (double)temp_tt_tauH->GetBinContent(ibin); double err = (double)temp_tt_tauH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; tt_tauH->SetBinContent(ibin,con); tt_tauH->SetBinError(ibin,err); } // // From W+jets - predictions TFile file_WJet_mu("../TauHad2/Stack/TauBtaggedRate_WJet_stacked.root","R"); temp_wj_muH = (TH1D*)file_WJet_mu.Get("TauBtaggedRate")->Clone(); TH1D * wj_muH = new TH1D("wj_muH","WJet -- Tau mistag",temp_wj_muH->GetNbinsX(),temp_wj_muH->GetXaxis()->GetXmin(),temp_wj_muH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<wj_muH->GetNbinsX()+2;ibin++){ double con = (double)temp_wj_muH->GetBinContent(ibin); double err = (double)temp_wj_muH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; wj_muH->SetBinContent(ibin,con); wj_muH->SetBinError(ibin,err); } // // From ttbar - predictions TFile file_TTbar_mu("../TauHad2/Stack/TauBtaggedRate_TTbar_stacked.root","R"); temp_tt_muH = (TH1D*)file_TTbar_mu.Get("TauBtaggedRate")->Clone(); TH1D * tt_muH = new TH1D("tt_muH","WJet -- Tau mistag",temp_tt_muH->GetNbinsX(),temp_tt_muH->GetXaxis()->GetXmin(),temp_tt_muH->GetXaxis()->GetXmax()); for(int ibin=0;ibin<tt_muH->GetNbinsX()+2;ibin++){ double con = (double)temp_tt_muH->GetBinContent(ibin); double err = (double)temp_tt_muH->GetBinError(ibin); cout << "con: " << con << " err: " << err << endl; tt_muH->SetBinContent(ibin,con); tt_muH->SetBinError(ibin,err); } // catLeg1->SetHeader("Prob. of #mu from #tau "); //...........................................................................// // TTbar ....................................................................// //...........................................................................// double XUp = 350. , maxVal=1.; wj_tauH->GetXaxis()->SetRangeUser(30.,XUp); wj_tauH->SetMaximum(maxVal); wj_tauH->SetTitle(""); wj_tauH->GetXaxis()->SetLabelFont(42); wj_tauH->GetXaxis()->SetLabelOffset(0.007); wj_tauH->GetXaxis()->SetLabelSize(0.04); wj_tauH->GetXaxis()->SetTitleSize(0.05); wj_tauH->GetXaxis()->SetTitleOffset(1.0); wj_tauH->GetXaxis()->SetTitleFont(42); wj_tauH->GetYaxis()->SetLabelFont(42); wj_tauH->GetYaxis()->SetLabelOffset(0.007); wj_tauH->GetYaxis()->SetLabelSize(0.04); wj_tauH->GetYaxis()->SetTitleSize(0.05); wj_tauH->GetYaxis()->SetTitleOffset(1.0); wj_tauH->GetYaxis()->SetTitleFont(42); wj_tauH->GetXaxis()->SetTitle("p_{T}(#tau jet)"); wj_tauH->GetYaxis()->SetTitle("b-tagging mistag rate"); wj_tauH->GetXaxis()->SetRangeUser(30.,XUp); wj_tauH->SetMaximum(maxVal); wj_tauH->SetLineColor(1); wj_tauH->Draw(); tt_tauH->SetLineColor(2); // thist.SetFillColor(0); // thist.SetLineWidth(3); if (!wjets_hadtau_only) tt_tauH->Draw("same"); wj_muH->SetLineColor(8); // wj_muH->SetMarkerStyle(20); if (!wjets_hadtau_only) { wj_muH->GetXaxis()->SetRangeUser(30.,500.); wj_muH->Draw("same"); } tt_muH->SetLineColor(4); if (!wjets_hadtau_only){ tt_muH->GetXaxis()->SetRangeUser(30.,500.); tt_muH->Draw("same"); } // sanity plot TH1 * sanityH = static_cast<TH1D*>(wj_tauH->Clone("sanity")); sanityH->Add(tt_muH); TH1 * tempH = static_cast<TH1D*>(wj_tauH->Clone("sanity")); tempH->Multiply(tt_muH); sanityH->Add(tempH,-1); sanityH->SetLineColor(34); if (!wjets_hadtau_only){ sanityH->GetXaxis()->SetRangeUser(30.,500.); sanityH->Draw("same"); } // // TLegend sprintf(tempname,"(a) #tau_{h}-jets in t#bar{t}"); if (!wjets_hadtau_only) catLeg1->AddEntry(tt_tauH,tempname,"l"); if (wjets_hadtau_only) sprintf(tempname,"#tau_{h}-jets in W+jets"); else sprintf(tempname,"(b) #tau_{h}-jets in W+jets"); catLeg1->AddEntry(wj_tauH,tempname,"l"); sprintf(tempname,"(c) #mu-jets in t#bar{t}"); if (!wjets_hadtau_only) catLeg1->AddEntry(tt_muH,tempname,"l"); sprintf(tempname,"(d) #mu-jets in W+jets"); if (!wjets_hadtau_only) catLeg1->AddEntry(wj_muH,tempname,"l"); //sprintf(tempname,"blue+(1 - blue)*red "); if (!wjets_hadtau_only){ sprintf(tempname,"(e) #mu-jets (t#bar{t}) + #tau_{h}-jets (W+jets)"); catLeg1->AddEntry(sanityH,tempname,"l"); TH1F *sanityHdummy = (TH1F*) sanityH->Clone(); sanityHdummy->SetLineColor(0); sprintf(tempname,"= (c) + [1-(c)]#times(b)"); catLeg1->AddEntry(sanityHdummy,tempname,"l"); } catLeg1->Draw(); if (wjets_hadtau_only) { sprintf(tempname,"TauBtaggedRate_allSamples_hadtau_Wjets.png"); c1->Print(tempname); sprintf(tempname,"TauBtaggedRate_allSamples_hadtau_Wjets.pdf"); c1->Print(tempname); } else { sprintf(tempname,"TauBtaggedRate_allSamples.png"); c1->Print(tempname); sprintf(tempname,"TauBtaggedRate_allSamples.pdf"); c1->Print(tempname); } }
// input: - Input file (result from TMVA) // - use of TMVA plotting TStyle void mvas( TString fin = "TMVA.root", HistType htype = MVAType, Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // switches const Bool_t Save_Images = kTRUE; // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); // define Canvas layout here! Int_t xPad = 1; // no of plots in x Int_t yPad = 1; // no of plots in y Int_t noPad = xPad * yPad ; const Int_t width = 600; // size of canvas // this defines how many canvases we need TCanvas *c = 0; // counter variables Int_t countCanvas = 0; // search for the right histograms in full list of keys TIter next(file->GetListOfKeys()); TKey *key(0); while ((key = (TKey*)next())) { if (!TString(key->GetName()).BeginsWith("Method_")) continue; if( ! gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory") ) continue; TString methodName; TMVAGlob::GetMethodName(methodName,key); TDirectory* mDir = (TDirectory*)key->ReadObj(); TIter keyIt(mDir->GetListOfKeys()); TKey *titkey; while ((titkey = (TKey*)keyIt())) { if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue; TDirectory *titDir = (TDirectory *)titkey->ReadObj(); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,titDir); cout << "--- Found directory for method: " << methodName << "::" << methodTitle << flush; TString hname = "MVA_" + methodTitle; if (htype == ProbaType ) hname += "_Proba"; else if (htype == RarityType ) hname += "_Rarity"; TH1* sig = dynamic_cast<TH1*>(titDir->Get( hname + "_S" )); TH1* bgd = dynamic_cast<TH1*>(titDir->Get( hname + "_B" )); if (sig==0 || bgd==0) { if (htype == MVAType) cout << "mva distribution not available (this is normal for Cut classifier)" << endl; else if(htype == ProbaType) cout << "probability distribution not available (this is normal for Cut classifier)" << endl; else if(htype == RarityType) cout << "rarity distribution not available (this is normal for Cut classifier)" << endl; else if(htype == CompareType) cout << "overtraining check not available (this is normal for Cut classifier)" << endl; else cout << endl; } else { cout << endl; // chop off useless stuff sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) ); if (htype == ProbaType) sig->SetTitle( Form("TMVA probability for classifier: %s", methodTitle.Data()) ); else if (htype == RarityType) sig->SetTitle( Form("TMVA Rarity for classifier: %s", methodTitle.Data()) ); else if (htype == CompareType) sig->SetTitle( Form("TMVA overtraining check for classifier: %s", methodTitle.Data()) ); // create new canvas TString ctitle = ((htype == MVAType) ? Form("TMVA response %s",methodTitle.Data()) : (htype == ProbaType) ? Form("TMVA probability %s",methodTitle.Data()) : (htype == CompareType) ? Form("TMVA comparison %s",methodTitle.Data()) : Form("TMVA Rarity %s",methodTitle.Data())); TString cname = ((htype == MVAType) ? Form("output_%s",methodTitle.Data()) : (htype == ProbaType) ? Form("probability_%s",methodTitle.Data()) : (htype == CompareType) ? Form("comparison_%s",methodTitle.Data()) : Form("rarity_%s",methodTitle.Data())); c = new TCanvas( Form("canvas%d", countCanvas+1), ctitle, countCanvas*50+200, countCanvas*20, width, (Int_t)width*0.78 ); // set the histogram style TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd ); // normalise both signal and background TMVAGlob::NormalizeHists( sig, bgd ); // frame limits (choose judicuous x range) Float_t nrms = 4; cout << "--- Mean and RMS (S): " << sig->GetMean() << ", " << sig->GetRMS() << endl; cout << "--- Mean and RMS (B): " << bgd->GetMean() << ", " << bgd->GetRMS() << endl; Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), bgd->GetMean() - nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmin() ); Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), bgd->GetMean() + nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmax() ); Float_t ymin = 0; Float_t maxMult = (htype == CompareType) ? 1.3 : 1.2; Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult; // build a frame Int_t nb = 500; TString hFrameName(TString("frame") + methodTitle); TObject *o = gROOT->FindObject(hFrameName); if(o) delete o; TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), nb, xmin, xmax, nb, ymin, ymax ); frame->GetXaxis()->SetTitle( methodTitle + ((htype == MVAType || htype == CompareType) ? " response" : "") ); if (htype == ProbaType ) frame->GetXaxis()->SetTitle( "Signal probability" ); else if (htype == RarityType ) frame->GetXaxis()->SetTitle( "Signal rarity" ); frame->GetYaxis()->SetTitle("Normalized"); TMVAGlob::SetFrameStyle( frame ); // eventually: draw the frame frame->Draw(); c->GetPad(0)->SetLeftMargin( 0.105 ); frame->GetYaxis()->SetTitleOffset( 1.2 ); // Draw legend TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, c->GetLeftMargin() + (htype == CompareType ? 0.40 : 0.3), 1 - c->GetTopMargin() ); legend->SetFillStyle( 1 ); legend->AddEntry(sig,TString("Signal") + ((htype == CompareType) ? " (test sample)" : ""), "F"); legend->AddEntry(bgd,TString("Background") + ((htype == CompareType) ? " (test sample)" : ""), "F"); legend->SetBorderSize(1); legend->SetMargin( (htype == CompareType ? 0.2 : 0.3) ); legend->Draw("same"); // overlay signal and background histograms sig->Draw("samehist"); bgd->Draw("samehist"); if (htype == CompareType) { // if overtraining check, load additional histograms TH1* sigOv = 0; TH1* bgdOv = 0; TString ovname = hname += "_Train"; sigOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_S" )); bgdOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_B" )); if (sigOv == 0 || bgdOv == 0) { cout << "+++ Problem in \"mvas.C\": overtraining check histograms do not exist" << endl; } else { cout << "--- Found comparison histograms for overtraining check" << endl; TLegend *legend2= new TLegend( 1 - c->GetRightMargin() - 0.42, 1 - c->GetTopMargin() - 0.12, 1 - c->GetRightMargin(), 1 - c->GetTopMargin() ); legend2->SetFillStyle( 1 ); legend2->SetBorderSize(1); legend2->AddEntry(sigOv,"Signal (training sample)","P"); legend2->AddEntry(bgdOv,"Background (training sample)","P"); legend2->SetMargin( 0.1 ); legend2->Draw("same"); } Int_t col = sig->GetLineColor(); sigOv->SetMarkerColor( col ); sigOv->SetMarkerSize( 0.7 ); sigOv->SetMarkerStyle( 20 ); sigOv->SetLineWidth( 1 ); sigOv->SetLineColor( col ); sigOv->Draw("e1same"); col = bgd->GetLineColor(); bgdOv->SetMarkerColor( col ); bgdOv->SetMarkerSize( 0.7 ); bgdOv->SetMarkerStyle( 20 ); bgdOv->SetLineWidth( 1 ); bgdOv->SetLineColor( col ); bgdOv->Draw("e1same"); ymax = TMath::Max( ymax, TMath::Max( sigOv->GetMaximum(), bgdOv->GetMaximum() )*maxMult ); frame->GetYaxis()->SetLimits( 0, ymax ); // for better visibility, plot thinner lines sig->SetLineWidth( 1 ); bgd->SetLineWidth( 1 ); // perform K-S test cout << "--- Perform Kolmogorov-Smirnov tests" << endl; Double_t kolS = sig->KolmogorovTest( sigOv ); Double_t kolB = bgd->KolmogorovTest( bgdOv ); cout << "--- Goodness of signal (background) consistency: " << kolS << " (" << kolB << ")" << endl; TString probatext = Form( "Kolmogorov-Smirnov test: signal (background) probability = %5.3g (%5.3g)", kolS, kolB ); TText* tt = new TText( 0.12, 0.74, probatext ); tt->SetNDC(); tt->SetTextSize( 0.032 ); tt->AppendPad(); } // redraw axes frame->Draw("sameaxis"); // text for overflows Int_t nbin = sig->GetNbinsX(); Double_t dxu = sig->GetBinWidth(0); Double_t dxo = sig->GetBinWidth(nbin+1); TString uoflow = Form( "U/O-flow (S,B): (%.1f, %.1f)%% / (%.1f, %.1f)%%", sig->GetBinContent(0)*dxu*100, bgd->GetBinContent(0)*dxu*100, sig->GetBinContent(nbin+1)*dxo*100, bgd->GetBinContent(nbin+1)*dxo*100 ); TText* t = new TText( 0.975, 0.115, uoflow ); t->SetNDC(); t->SetTextSize( 0.030 ); t->SetTextAngle( 90 ); t->AppendPad(); // update canvas c->Update(); // save canvas to file TMVAGlob::plot_logo(1.058); if (Save_Images) { if (htype == MVAType) TMVAGlob::imgconv( c, Form("plots/mva_%s", methodTitle.Data()) ); else if (htype == ProbaType) TMVAGlob::imgconv( c, Form("plots/proba_%s", methodTitle.Data()) ); else if (htype == CompareType) TMVAGlob::imgconv( c, Form("plots/overtrain_%s", methodTitle.Data()) ); else TMVAGlob::imgconv( c, Form("plots/rarity_%s", methodTitle.Data()) ); } countCanvas++; } } } }
void calculateTriggerRates( TString inFile0Name = "root://eoscms//eos/cms/store/caf/user/velicanu/PA2013_merged_HiForest/pPb_hiForest2_pilotRun_200kHz_v3.root", // TString inFile0Name = "/castor/cern.ch/user/m/miheejo/openHLT/cms442/r181530_reco_v1_2/HIExpressPhysics_hiexp-hirun2011-r181530-reco-v1_2.root", // "/castor/cern.ch/user/k/kimy/openHLT//openhlt_run181531.root", // "/castor/cern.ch/user/v/velicanu/HIHLT_Validation_Test_GRIF_v10.root", Int_t runNum = 202792, TString outdir = "output", char *projectTitle = "HIpARun2013", string source = "data" ) { char szBuf[256]; int scale = 23; // event selectoin //Form("&&Run==%d&&LumiBlock>%d",runNum,goodLumiStart) // trigger under investigation // const int ntrigs = 8; // const char* triggerPath[ntrigs] = {"","HLT_HIMinBiasHfOrBSC", // "L1_SingleMu3_BptxAND","HLT_HIL1SingleMu3","HLT_HIL2Mu3", // "L1_DoubleMuOpen_BptxAND","HLT_HIL1DoubleMuOpen","HLT_HIL2DoubleMu3"}; /* const int ntrigs = 9; const char* triggerPath[ntrigs] = { "", "HLT_PAL1SingleMuOpen_v1", "HLT_PAL1SingleMu3_v1", "HLT_PAL1SingleMu7_v1", "HLT_PAL1SingleMu12_v1", "HLT_PAL1DoubleMu0_v1", "HLT_PADimuon0_NoVertexing_v1", "HLT_PAMu5_v1", "HLT_PAMu8_v1" }; */ //trigger list for singleMu rate plot const int ntrigs = 4 ; const char* triggerPath[ntrigs] = { "", "HLT_PAMu3_v1", "HLT_PAMu7_v1", "HLT_PAMu12_v1" }; /* //trigger list for DoubleMu rate plot const int ntrigs = 4 ; const char* triggerPath[ntrigs] = { "", "HLT_PAL1DoubleMuOpen_v1", "HLT_PAL1DoubleMu0_HighQ_v1", "HLT_PAL2DoubleMu3_v1" }; //trigger list fo bJet+Mu rate plot const int ntrigs =5; const char* triggerPath[ntrigs] = { "", "HLT_PAMu3PFJet20_v1", "HLT_PAMu3PFJet40_v1", "HLT_PAMu7PFJet20_v1", "HLT_PABTagMu_Jet20_Mu4_v1" };*/ TString str; TH1D *ahTemp[ntrigs]; double ahTempRate[ntrigs]; //Rates (Integrated over lumisections) // Load input TChain * HltTree = new TChain("hltanalysis/HltTree","HI OpenHLT Tree"); HltTree->Add(inFile0Name); cout << inFile0Name << endl; cout << " # entries: " << HltTree->GetEntries() << endl; int nEvents = HltTree->GetEntries(); for(int it=1; it<ntrigs; it++) { TH1D *ph = new TH1D("ph",";Lumi Section; Counts ",1100,0,1100); HltTree->Draw("LumiBlock>>ph",str.Format("%s",triggerPath[it])); TLegend *lTemp= new TLegend(0.2,0.8,0.8,0.9); lTemp->SetHeader(str.Format("Run : %d",runNum)); lTemp->SetMargin(0.05); lTemp->SetFillStyle(0); lTemp->SetLineColor(0); lTemp->SetLineWidth(5.0); lTemp->SetTextSize(0.03); lTemp->AddEntry(ph,str.Format("%s",triggerPath[it],"l")); lTemp->Draw("same"); c1->SaveAs(str.Format("%d_%s.pdf",runNum,triggerPath[it])); TH1D *phLumi = (TH1D*)gDirectory->Get("ph"); phLumi->SetDirectory(0); phLumi->Scale(1./(phLumi->GetBinWidth(1)*23));// 1lumi unit=23 sec ahTempRate[it] = phLumi->Integral()/phLumi->GetNbinsX(); ahTemp[it] = phLumi; cout<< triggerPath[it]<<"\t"<<phLumi->GetEntries()<< "\t" << ahTempRate[it] << endl; } //---------------------------- // drawing part // axis // TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;dEvt/dLumiSec",1100,0,1100); TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;Rate [Hz]",1,0,1200); phLumiAxis->SetMinimum(0.01); phLumiAxis->SetMaximum(1e+3); gStyle->SetOptStat(kFALSE); // legend TLegend *l0= new TLegend(0.2,0.7,0.8,0.9); l0->SetHeader(str.Format("Run : %d",runNum)); l0->SetMargin(0.03); l0->SetFillStyle(0); l0->SetLineColor(0); l0->SetLineWidth(1.0); l0->SetTextSize(0.03); // canvas TCanvas *pcLumi = new TCanvas("pcLumi","pcLumi"); pcLumi->cd(); phLumiAxis->Draw(); pcLumi->SetLogy(); for(int it=1; it<ntrigs; it++) { TH1 *phLocal = (TH1 *)(ahTemp[it]->Clone("phLocal")); phLocal->SetDirectory(0); phLocal->SetLineColor(it); if (it >= 10) phLocal->SetLineColor(it+20); if(it==5) phLocal->SetLineColor(kOrange+2); phLocal->Draw("same"); l0->AddEntry(phLocal,str.Format("%s: %.2f Hz",triggerPath[it],ahTempRate[it]),"l"); pcLumi->Update(); } l0->Draw("same"); pcLumi->SaveAs(str.Format("%d_ratedMu.png",runNum)); }
void plot_efficiencies( TFile* file, Int_t type = 2, TDirectory* BinDir) { // input: - Input file (result from TMVA), // - type = 1 --> plot efficiency(B) versus eff(S) // = 2 --> plot rejection (B) versus efficiency (S) Bool_t __PLOT_LOGO__ = kTRUE; Bool_t __SAVE_IMAGE__ = kTRUE; // the coordinates Float_t x1 = 0; Float_t x2 = 1; Float_t y1 = 0; Float_t y2 = 0.8; // reverse order if "rejection" if (type == 2) { Float_t z = y1; y1 = 1 - y2; y2 = 1 - z; // cout << "--- type==2: plot background rejection versus signal efficiency" << endl; } else { // cout << "--- type==1: plot background efficiency versus signal efficiency" << endl; } // create canvas TCanvas* c = new TCanvas( "c", "the canvas", 200, 0, 650, 500 ); // global style settings c->SetGrid(); c->SetTicks(); // legend Float_t x0L = 0.107, y0H = 0.899; Float_t dxL = 0.457-x0L, dyH = 0.22; if (type == 2) { x0L = 0.15; y0H = 1 - y0H + dyH + 0.07; } TLegend *legend = new TLegend( x0L, y0H-dyH, x0L+dxL, y0H ); legend->SetTextSize( 0.05 ); legend->SetHeader( "MVA Method:" ); legend->SetMargin( 0.4 ); TString xtit = "Signal efficiency"; TString ytit = "Background efficiency"; if (type == 2) ytit = "Background rejection"; TString ftit = ytit + " versus " + xtit; if (TString(BinDir->GetName()).Contains("multicut")){ ftit += " Bin: "; ftit += (BinDir->GetTitle()); } // draw empty frame if(gROOT->FindObject("frame")!=0) gROOT->FindObject("frame")->Delete(); TH2F* frame = new TH2F( "frame", ftit, 500, x1, x2, 500, y1, y2 ); frame->GetXaxis()->SetTitle( xtit ); frame->GetYaxis()->SetTitle( ytit ); TMVAGlob::SetFrameStyle( frame, 1.0 ); frame->Draw(); Int_t color = 1; Int_t nmva = 0; TKey *key, *hkey; TString hNameRef = "effBvsS"; if (type == 2) hNameRef = "rejBvsS"; TList hists; TList methods; UInt_t nm = TMVAGlob::GetListOfMethods( methods ); // TIter next(file->GetListOfKeys()); TIter next(&methods); // loop over all methods while (key = (TKey*)next()) { TDirectory * mDir = (TDirectory*)key->ReadObj(); TList titles; UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles); TIter nextTitle(&titles); TKey *titkey; TDirectory *titDir; while ((titkey = TMVAGlob::NextKey(nextTitle,"TDirectory"))) { titDir = (TDirectory *)titkey->ReadObj(); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,titDir); TIter nextKey( titDir->GetListOfKeys() ); while ((hkey = TMVAGlob::NextKey(nextKey,"TH1"))) { TH1 *h = (TH1*)hkey->ReadObj(); TString hname = h->GetName(); if (hname.Contains( hNameRef ) && hname.BeginsWith( "MVA_" )) { h->SetLineWidth(3); h->SetLineColor(color); color++; if (color == 5 || color == 10 || color == 11) color++; h->Draw("csame"); hists.Add(h); nmva++; } } } } while (hists.GetSize()) { TListIter hIt(&hists); TH1* hist(0); Double_t largestInt=-1; TH1* histWithLargestInt(0); while ((hist = (TH1*)hIt())!=0) { Double_t integral = hist->Integral(1,hist->FindBin(0.9999)); if (integral>largestInt) { largestInt = integral; histWithLargestInt = hist; } } if (histWithLargestInt == 0) { cout << "ERROR - unknown hist \"histWithLargestInt\" --> serious problem in ROOT file" << endl; break; } legend->AddEntry(histWithLargestInt,TString(histWithLargestInt->GetTitle()).ReplaceAll("MVA_",""),"l"); hists.Remove(histWithLargestInt); } // rescale legend box size // current box size has been tuned for 3 MVAs + 1 title if (type == 1) { dyH *= (1.0 + Float_t(nmva - 3.0)/4.0); legend->SetY1( y0H - dyH ); } else { dyH *= (Float_t(nmva - 3.0)/4.0); legend->SetY2( y0H + dyH); } // redraw axes frame->Draw("sameaxis"); legend->Draw("same"); // ============================================================ if (__PLOT_LOGO__) TMVAGlob::plot_logo(); // ============================================================ c->Update(); TString fname = "plots/" + hNameRef; if (TString(BinDir->GetName()).Contains("multicut")){ TString fprepend(BinDir->GetName()); fprepend.ReplaceAll("multicutMVA_",""); fname = "plots/" + fprepend + "_" + hNameRef; } if (__SAVE_IMAGE__) TMVAGlob::imgconv( c, fname ); return; }