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 Run(const char* newName, const char* oldName, const char* newTitle="New", const char* oldTitle="Old") { TFile* newFile = TFile::Open(newName,"READ"); TFile* oldFile = TFile::Open(oldName,"READ"); if (!newFile || !oldFile) return; TH1* newCent = GetH1(newFile, "realCent"); TH1* oldCent = GetH1(oldFile, "realCent"); if (!newCent || !oldCent) return; TString t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle); TCanvas* c = new TCanvas("c", t, 1200, 800); c->SetTopMargin(0.01); c->SetRightMargin(0.20); fLegend = new TLegend(1-c->GetRightMargin(), c->GetBottomMargin(), 1, 1-c->GetTopMargin(), t); fLegend->SetFillStyle(0); fLegend->SetBorderSize(0); THStack* stack = new THStack("ratios",""); fMin = +1e6; fMax = -1e6; TH1* one = 0; for (Int_t i = newCent->GetNbinsX(); i--;) { Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1); Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1); Info("", "c1=%f c2=%f", c1, c2); TH1* r = One(newFile, oldFile, c1, c2); if (!r) continue; if (!one) { one = static_cast<TH1*>(r->Clone("one")); one->SetDirectory(0); one->Reset(); for (Int_t j = 1; j <= one->GetNbinsX(); j++) { one->SetBinContent(j,1); one->SetBinError (j,0); } } // r->Add(one, i-1); // r->Scale(TMath::Power(10,i)); stack->Add(r); } stack->Draw("nostack"); stack->SetMinimum(0.95*fMin); stack->SetMaximum(1.05*fMax); stack->GetHistogram()->SetXTitle("#eta"); stack->GetHistogram()->SetYTitle("#it{R}"); fLegend->Draw(); c->Modified(); c->Update(); c->cd(); c->SaveAs(Form("%sover%s.png", newTitle, oldTitle)); }
TCanvas* makeNiceCanvasByPixMargins(Int_t pixelPerBinX, Int_t pixelPerBinY, Int_t nbinx, Int_t nbiny, Int_t top, Int_t bottom, Int_t left, Int_t right) { Int_t rubaX = 4; //determinato sperimentalmente Int_t rubaY = 28; //determinato sperimentalmente TString name = generateRandomName(); Int_t plotBaseDimX = pixelPerBinX*nbinx; Int_t plotBaseDimY = pixelPerBinY*nbiny; Int_t XX = (Int_t)(plotBaseDimX+left+right); Int_t YY = (Int_t)(plotBaseDimY+top+bottom); TCanvas* can = new TCanvas(name,name,XX+rubaX,YY+rubaY); can->SetTopMargin((1.*top)/(1.*YY)); can->SetBottomMargin((1.*bottom)/(1.*YY)); can->SetRightMargin(right/(1.*XX)); can->SetLeftMargin(left/(1.*XX)); can->SetBorderMode(0); std::cout << "Nice canvas " << XX << " * " << YY << " Margin: t " << can->GetTopMargin() << " b " << can->GetBottomMargin() << " l " << can->GetLeftMargin() << " r " << can->GetRightMargin() << std::endl; return can; }
/** * 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")); }
// 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++; } } } }
//------------------------------------------------------------------------------ // DrawIt //------------------------------------------------------------------------------ void DrawIt(TString filename, TString hname, TString cname, TString title) { TFile* inputfile = TFile::Open("../AuxiliaryFilesWZXS8TeV/" + filename + ".root"); TH2F* h = (TH2F*)inputfile->Get(hname)->Clone(cname); h->SetDirectory(0); inputfile->Close(); TString name = h->GetName(); TCanvas* canvas = new TCanvas(name, name, 600, 600); if (name.Contains("PR")) canvas->SetLogx(); if (name.Contains("SF")) canvas->SetLogx(); canvas->SetLeftMargin (0.9 * canvas->GetLeftMargin()); canvas->SetRightMargin(3.5 * canvas->GetRightMargin()); canvas->SetTopMargin (1.2 * canvas->GetTopMargin()); TH2FAxisFonts(h, "x", "p_{T} [GeV]"); TH2FAxisFonts(h, "y", "#eta"); h->Draw("colz"); h->SetTitle(""); DrawTLatex(42, 0.940, 0.976, _bigLabelSize, 33, title); if (!title.Contains("trigger")) { Double_t hmin = h->GetMinimum(); Double_t hmax = h->GetMaximum(); for (Int_t i=1; i<=h->GetNbinsX(); i++) { for (Int_t j=1; j<=h->GetNbinsY(); j++) { Double_t value = h->GetBinContent(i,j); Double_t ypos = h->GetYaxis()->GetBinCenter(j); Double_t xpos = h->GetXaxis()->GetBinCenter(i); if (gPad->GetLogx()) xpos = h->GetXaxis()->GetBinCenterLog(i); TLatex* latex = new TLatex(xpos, ypos, Form("%.2f", value)); latex->SetTextAlign( 22); latex->SetTextFont ( 42); latex->SetTextSize (0.027); if (value < hmin + 0.3*(hmax - hmin)) latex->SetTextColor(kWhite); latex->Draw(); } } } // Set the palette font //---------------------------------------------------------------------------- canvas->Update(); TPaletteAxis* palette = (TPaletteAxis*)h->GetListOfFunctions()->FindObject("palette"); palette->SetLabelFont(42); // Save the plot //---------------------------------------------------------------------------- canvas->Update(); canvas->Modified(); canvas->GetFrame()->DrawClone(); canvas->SaveAs("pdf/scale_factors/" + name + ".pdf"); canvas->SaveAs("png/scale_factors/" + name + ".png"); }
// input: - Input file (result from TMVA) // - use of TMVA plotting TStyle void probas( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // switches const Bool_t Draw_CFANN_Logy = kFALSE; 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; // list of existing MVAs const Int_t nveto = 1; TString suffixSig = "_tr_S"; TString suffixBgd = "_tr_B"; // search for the right histograms in full list of keys TList methods; UInt_t nmethods = TMVAGlob::GetListOfMethods( methods ); if (nmethods==0) { cout << "--- Probas.C: no methods found!" << endl; return; } TIter next(&methods); TKey *key, *hkey; char fname[200]; TH1* sig(0); TH1* bgd(0); while ((key = (TKey*)next())) { TDirectory * mDir = (TDirectory*)key->ReadObj(); TList titles; UInt_t ni = TMVAGlob::GetListOfTitles( mDir, titles ); TString methodName; TMVAGlob::GetMethodName(methodName,key); if (ni==0) { cout << "+++ No titles found for classifier: " << methodName << endl; return; } TIter nextTitle(&titles); TKey *instkey; TDirectory *instDir; while ((instkey = (TKey *)nextTitle())) { instDir = (TDirectory *)instkey->ReadObj(); TString instName = instkey->GetName(); TList h1hists; UInt_t nhists = TMVAGlob::GetListOfKeys( h1hists, "TH1", instDir ); if (nhists==0) cout << "*** No histograms found!" << endl; TIter nextInDir(&h1hists); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,instDir); while (hkey = (TKey*)nextInDir()) { TH1 *th1 = (TH1*)hkey->ReadObj(); TString hname= th1->GetName(); if (hname.Contains( suffixSig ) && !hname.Contains( "Cut") && !hname.Contains("original") && !hname.Contains("smoothed")) { // retrieve corresponding signal and background histograms TString hnameS = hname; TString hnameB = hname; hnameB.ReplaceAll("_S","_B"); sig = (TH1*)instDir->Get( hnameS ); bgd = (TH1*)instDir->Get( hnameB ); if (sig == 0 || bgd == 0) { cout << "*** probas.C: big troubles in probas.... histogram: " << hname << " not found" << endl; return; } TH1* sigF(0); TH1* bkgF(0); for (int i=0; i<= 5; i++) { TString hspline = hnameS + Form("_smoothed_hist_from_spline%i",i); sigF = (TH1*)instDir->Get( hspline ); if (sigF) { bkgF = (TH1*)instDir->Get( hspline.ReplaceAll("_tr_S","_tr_B") ); break; } } if ((sigF == NULL || bkgF == NULL) &&!hname.Contains("hist") ) { cout << "*** probas.C: big troubles - did not found histogram " << hspline.Data() << " " << sigF << " " << bkgF << endl; return; } else { // remove the signal suffix // check that exist if (NULL != sigF && NULL != bkgF && NULL!=sig && NULL!=bgd) { TString hname = sig->GetName(); // chop off useless stuff sig->SetTitle( TString("TMVA output for classifier: ") + methodTitle ); // create new canvas cout << "--- Book canvas no: " << countCanvas << endl; char cn[20]; sprintf( cn, "canvas%d", countCanvas+1 ); c = new TCanvas( cn, Form("TMVA Output Fit Variables %s",methodTitle.Data()), countCanvas*50+200, countCanvas*20, width, width*0.78 ); // set the histogram style TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd ); TMVAGlob::SetSignalAndBackgroundStyle( sigF, bkgF ); // frame limits (choose judicuous x range) Float_t nrms = 4; 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 ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*1.5; if (Draw_CFANN_Logy && mvaName[imva] == "CFANN") ymin = 0.01; // build a frame Int_t nb = 500; TH2F* frame = new TH2F( TString("frame") + sig->GetName() + "_proba", sig->GetTitle(), nb, xmin, xmax, nb, ymin, ymax ); frame->GetXaxis()->SetTitle(methodTitle); frame->GetYaxis()->SetTitle("Normalized"); TMVAGlob::SetFrameStyle( frame ); // eventually: draw the frame frame->Draw(); if (Draw_CFANN_Logy && mvaName[imva] == "CFANN") c->SetLogy(); // overlay signal and background histograms sig->SetMarkerColor( TMVAGlob::c_SignalLine ); sig->SetMarkerSize( 0.7 ); sig->SetMarkerStyle( 20 ); sig->SetLineWidth(1); bgd->SetMarkerColor( TMVAGlob::c_BackgroundLine ); bgd->SetMarkerSize( 0.7 ); bgd->SetMarkerStyle( 24 ); bgd->SetLineWidth(1); sig->Draw("samee"); bgd->Draw("samee"); sigF->SetFillStyle( 0 ); bkgF->SetFillStyle( 0 ); sigF->Draw("samehist"); bkgF->Draw("samehist"); // redraw axes frame->Draw("sameaxis"); // Draw legend TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.2, c->GetLeftMargin() + 0.4, 1 - c->GetTopMargin() ); legend->AddEntry(sig,"Signal data","P"); legend->AddEntry(sigF,"Signal PDF","L"); legend->AddEntry(bgd,"Background data","P"); legend->AddEntry(bkgF,"Background PDF","L"); legend->Draw("same"); legend->SetBorderSize(1); legend->SetMargin( 0.3 ); // save canvas to file c->Update(); TMVAGlob::plot_logo(); sprintf( fname, "plots/mva_pdf_%s_c%i", methodTitle.Data(), countCanvas+1 ); if (Save_Images) TMVAGlob::imgconv( c, fname ); countCanvas++; } } } } } } }
TCanvas* DrawKs(const char* filename) { TFile* file = TFile::Open(filename, "READ"); if (!file) { Warning("DrawKs", "File %s couldn't be opened", filename); return 0; } TH1* cent = static_cast<TH1*>(file->Get("cent")); if (!cent) { Warning("DrawKs", "Failed to find cent in %s", file->GetName()); return 0; } TString t(filename); t.ReplaceAll("results/", ""); t.ReplaceAll("combine_",""); t.ReplaceAll("_0x3.root", ""); TString nm(filename); nm.ReplaceAll(".root", ""); nm.ReplaceAll("results/", "plots/"); nm.ReplaceAll("combine", "ks"); if (t.Contains("none")) t.ReplaceAll("none", "No weights"); else t.Append(" weights"); Int_t cW = 1200; Int_t cH = 800; TCanvas* c = new TCanvas(nm,t,cW, cH); c->SetTopMargin(0.07); c->SetRightMargin(0.20); c->SetTicks(); TLegend* l = new TLegend(1-c->GetRightMargin(), c->GetBottomMargin(), .99, 1-c->GetTopMargin()); l->SetFillStyle(0); l->SetBorderSize(0); THStack* s = new THStack("ks", ""); Int_t nCent = cent->GetXaxis()->GetNbins(); for (Int_t i = 1; i <= nCent; i++) { Double_t c1 = cent->GetXaxis()->GetBinLowEdge(i); Double_t c2 = cent->GetXaxis()->GetBinUpEdge(i); TH1* h = GetCentK(file, c1, c2, nCent-i+1-2, l); if (!h) continue; s->Add(h); } s->Draw("nostack"); TH1* f = s->GetHistogram(); if (f) { f->SetXTitle("#eta"); f->SetYTitle("#it{k}(#eta)"); } TLatex* tit = new TLatex(0.55, 0.99, t); tit->SetTextFont(42); tit->SetTextAlign(23); tit->SetTextSize(0.03); tit->SetNDC(); tit->Draw(); l->SetBorderSize(0); l->Draw(); c->Modified(); c->Update(); c->cd(); return c; }
void plotLimit(int signal = 0){ //signal: 0 = ZPN, 1 = ZPW, 2 = ZPXW, 3 = RSG setTDRStyle(); //gROOT->SetStyle("Plain"); gStyle->SetOptStat(0000000000); //this clears all the boxes and crap gStyle->SetLegendBorderSize(1); TGraph * limit_obs = new TGraph(3); TGraph * limit_exp = new TGraph(3); TGraphAsymmErrors * band_exp1 = new TGraphAsymmErrors(); TGraphAsymmErrors * band_exp2 = new TGraphAsymmErrors(); TGraph * limit_obs_2 = new TGraph(3); TGraph * limit_exp_2 = new TGraph(3); TGraphAsymmErrors * band_exp1_2 = new TGraphAsymmErrors(); TGraphAsymmErrors * band_exp2_2 = new TGraphAsymmErrors(); TGraph * limit_obs_3 = new TGraph(3); TGraph * limit_exp_3 = new TGraph(3); TGraphAsymmErrors * band_exp1_3 = new TGraphAsymmErrors(); TGraphAsymmErrors * band_exp2_3 = new TGraphAsymmErrors(); TGraph * limit_obs_4 = new TGraph(3); TGraph * limit_exp_4 = new TGraph(3); TGraphAsymmErrors * band_exp1_4 = new TGraphAsymmErrors(); TGraphAsymmErrors * band_exp2_4 = new TGraphAsymmErrors(); TGraph *theory = new TGraph(3); TGraph *theory2 = new TGraph(3); TGraph *theory3 = new TGraph(3); TGraph *theory4 = new TGraph(3); theory->SetPoint(0, 0.01, 4.24671); theory->SetPoint(1, 0.1, 42.24246); theory->SetPoint(2, 0.3, 122.17487); theory2->SetPoint(0, 0.01, 0.17980); theory2->SetPoint(1, 0.1, 2.00723); theory2->SetPoint(2, 0.3, 6.99950); theory3->SetPoint(0, 0.01, 0.01659*0.1); theory3->SetPoint(1, 0.1, 0.23030*0.1); theory3->SetPoint(2, 0.3, 1.03387*0.1); theory4->SetPoint(0, 0.01, 0.00203*0.01); theory4->SetPoint(1, 0.1, 0.04254*0.01); theory4->SetPoint(2, 0.3, 0.25352*0.01); string filename = "Limits/comb_width_1TeV.txt"; if (signal == 1) filename= "Limits/comb_width_2TeV.txt"; if (signal == 2) filename= "Limits/comb_width_3TeV.txt"; if (signal == 3) filename= "Limits/comb_width_4TeV.txt"; ifstream infile(filename); double mass, exp, obs, up1, up2, dn1, dn2; int point = 0; while (!infile.eof()){ //infile >> mass >> exp >> dn2 >> up2 >> dn1 >> up1; //obs = exp; infile >> mass >> obs >> exp >> dn2 >> up2 >> dn1 >> up1; double sf = 1.0; cout.precision(3); //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl; cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf << " \\\\" << endl; //if (mass == 2500) sf = 0.01; //if (mass == 3000) sf = 0.001; //if (mass == 3500) sf = 0.0001; //if (mass == 4000) sf = 0.0001; limit_obs->SetPoint(point, mass, obs*sf); limit_exp->SetPoint(point, mass, exp*sf); band_exp1->SetPoint(point, mass, exp*sf); band_exp2->SetPoint(point, mass, exp*sf); band_exp1->SetPointEYhigh(point, up1*sf - exp*sf); band_exp1->SetPointEYlow(point, exp*sf - dn1*sf); band_exp2->SetPointEYhigh(point, up2*sf - exp*sf); band_exp2->SetPointEYlow(point, exp*sf - dn2*sf); point++; } ifstream infile2 ("Limits/comb_width_2TeV.txt"); point = 0; while (!infile2.eof()){ //infile >> mass >> exp >> dn2 >> up2 >> dn1 >> up1; //obs = exp; infile2 >> mass >> obs >> exp >> dn2 >> up2 >> dn1 >> up1; double sf = 1.0; cout.precision(3); //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl; cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf << " \\\\" << endl; //if (mass == 2500) sf = 0.01; //if (mass == 3000) sf = 0.001; //if (mass == 3500) sf = 0.0001; //if (mass == 4000) sf = 0.0001; limit_obs_2->SetPoint(point, mass, obs*sf); limit_exp_2->SetPoint(point, mass, exp*sf); band_exp1_2->SetPoint(point, mass, exp*sf); band_exp2_2->SetPoint(point, mass, exp*sf); band_exp1_2->SetPointEYhigh(point, up1*sf - exp*sf); band_exp1_2->SetPointEYlow(point, exp*sf - dn1*sf); band_exp2_2->SetPointEYhigh(point, up2*sf - exp*sf); band_exp2_2->SetPointEYlow(point, exp*sf - dn2*sf); point++; } ifstream infile3 ("Limits/comb_width_3TeV.txt"); point = 0; while (!infile3.eof()){ //infile >> mass >> exp >> dn2 >> up2 >> dn1 >> up1; //obs = exp; infile3 >> mass >> obs >> exp >> dn2 >> up2 >> dn1 >> up1; double sf = 0.1; cout.precision(3); //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl; cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf << " \\\\" << endl; //if (mass == 2500) sf = 0.01; //if (mass == 3000) sf = 0.001; //if (mass == 3500) sf = 0.0001; //if (mass == 4000) sf = 0.0001; limit_obs_3->SetPoint(point, mass, obs*sf); limit_exp_3->SetPoint(point, mass, exp*sf); band_exp1_3->SetPoint(point, mass, exp*sf); band_exp2_3->SetPoint(point, mass, exp*sf); band_exp1_3->SetPointEYhigh(point, up1*sf - exp*sf); band_exp1_3->SetPointEYlow(point, exp*sf - dn1*sf); band_exp2_3->SetPointEYhigh(point, up2*sf - exp*sf); band_exp2_3->SetPointEYlow(point, exp*sf - dn2*sf); point++; } ifstream infile4 ("Limits/comb_width_4TeV.txt"); point = 0; while (!infile4.eof()){ //infile >> mass >> exp >> dn2 >> up2 >> dn1 >> up1; //obs = exp; infile4 >> mass >> obs >> exp >> dn2 >> up2 >> dn1 >> up1; double sf = 0.01; cout.precision(3); //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl; cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf << " \\\\" << endl; //if (mass == 2500) sf = 0.01; //if (mass == 3000) sf = 0.001; //if (mass == 3500) sf = 0.0001; //if (mass == 4000) sf = 0.0001; limit_obs_4->SetPoint(point, mass, obs*sf); limit_exp_4->SetPoint(point, mass, exp*sf); band_exp1_4->SetPoint(point, mass, exp*sf); band_exp2_4->SetPoint(point, mass, exp*sf); band_exp1_4->SetPointEYhigh(point, up1*sf - exp*sf); band_exp1_4->SetPointEYlow(point, exp*sf - dn1*sf); band_exp2_4->SetPointEYhigh(point, up2*sf - exp*sf); band_exp2_4->SetPointEYlow(point, exp*sf - dn2*sf); point++; } double max = 200000.0; //band_exp2->GetHistogram()->GetMaximum()*50; TCanvas *canvas = new TCanvas("limit set ZPN","limit set ZPN", 500,500); limit_exp->SetMinimum(0.00001); limit_exp->GetXaxis()->SetLabelSize(0.05); limit_exp->GetYaxis()->SetLabelSize(0.05); limit_exp->Draw("AL"); if (signal == 0){ limit_exp->GetXaxis()->SetTitle("#Gamma_{Z'} / M_{Z'}"); limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]"); } else if (signal == 1){ limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]"); limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]"); } else if (signal == 2){ limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]"); limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]"); } else if (signal == 3){ limit_exp->GetXaxis()->SetTitle("M_{g_{KK}} [GeV]"); limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{g_{KK}} #times B(g_{KK}#rightarrowt#bar{t}) [pb]"); } //limit_exp->GetYaxis()->SetTitleOffset(1.2); limit_exp->GetYaxis()->SetRangeUser(0.00001,2000); band_exp2->SetFillColor(5); band_exp2->SetLineColor(0); //band_exp2->SetFillStyle(4000); band_exp2->Draw("3same"); band_exp1->SetFillColor(3); band_exp1->SetLineColor(0); //band_exp1->SetFillStyle(4000); band_exp1->Draw("3same"); limit_obs->Draw("Lsame"); limit_obs->SetLineWidth(2); limit_obs->SetMarkerSize(1.0); limit_obs->SetMarkerStyle(20); limit_exp->Draw("Lsame"); limit_exp->SetLineStyle(2); limit_exp->SetLineWidth(2); limit_exp->SetMarkerSize(1.0); limit_exp->SetMaximum(max); limit_exp->SetMinimum(0.000001); limit_exp->SetMarkerStyle(20); band_exp2_2->SetFillColor(5); band_exp2_2->SetLineColor(0); band_exp1_2->SetFillColor(3); band_exp1_2->SetLineColor(0); band_exp2_3->SetFillColor(5); band_exp2_3->SetLineColor(0); band_exp1_3->SetFillColor(3); band_exp1_3->SetLineColor(0); band_exp2_4->SetFillColor(5); band_exp2_4->SetLineColor(0); band_exp1_4->SetFillColor(3); band_exp1_4->SetLineColor(0); band_exp2_2->Draw("3same"); band_exp1_2->Draw("3same"); limit_obs_2->Draw("Lsame"); limit_obs_2->SetLineWidth(2); limit_obs_2->SetMarkerSize(1.0); limit_obs_2->SetMarkerStyle(20); band_exp2_3->Draw("3same"); band_exp1_3->Draw("3same"); limit_obs_3->Draw("Lsame"); limit_obs_3->SetLineWidth(2); limit_obs_3->SetMarkerSize(1.0); limit_obs_3->SetMarkerStyle(20); band_exp2_4->Draw("3same"); band_exp1_4->Draw("3same"); limit_obs_4->Draw("Lsame"); limit_obs_4->SetLineWidth(2); limit_obs_4->SetMarkerSize(1.0); limit_obs_4->SetMarkerStyle(20); limit_exp_2->Draw("L same"); limit_exp_2->SetLineStyle(2); limit_exp_2->SetLineWidth(2); limit_exp_2->SetMarkerSize(1.0); limit_exp_3->Draw("L same"); limit_exp_3->SetLineStyle(2); limit_exp_3->SetLineWidth(2); limit_exp_3->SetMarkerSize(1.0); limit_exp_4->Draw("L same"); limit_exp_4->SetLineStyle(2); limit_exp_4->SetLineWidth(2); limit_exp_4->SetMarkerSize(1.0); canvas->RedrawAxis(); double x1 = 595; double y1 = 1.0; double x2 = 905; double y2 = 1.0; TLine * line = new TLine(x1, y1, x2, y2); theory->SetLineColor(2); theory->SetLineWidth(2); theory->Draw("same"); theory2->SetLineColor(kBlue); theory2->SetLineWidth(2); theory2->Draw("same"); theory3->SetLineColor(kMagenta); theory3->SetLineWidth(2); theory3->Draw("same"); theory4->SetLineColor(kCyan); theory4->SetLineWidth(2); theory4->Draw("same"); CMS_lumi(canvas, 4, 10); float t = canvas->GetTopMargin(); float r = canvas->GetRightMargin(); //Legend TLegend *l = new TLegend(0.51,0.63,0.99-r,0.99-t); l->AddEntry(limit_obs,"Observed", "L"); l->AddEntry(limit_exp,"Expected", "L"); l->AddEntry(band_exp1,"#pm1 #sigma Exp.", "F"); l->AddEntry(band_exp2,"#pm2 #sigma Exp.", "F"); l->AddEntry(theory, "Z' 1 TeV (NLO)", "L"); l->AddEntry(theory2, "Z' 2 TeV (NLO)", "L"); l->AddEntry(theory3, "Z' 3 TeV (NLO x 0.1)", "L"); l->AddEntry(theory4, "Z' 4 TeV (NLO x 0.01)", "L"); l->SetFillColor(0); l->SetLineColor(0); l->SetTextSize(0.04); l->SetTextFont(42); l->Draw(); //TLatex * label = new TLatex(); //label->SetNDC(); //label->DrawLatex(0.2,0.86,"CMS Preliminary, 19.7 fb^{-1}"); //label->DrawLatex(0.2,0.80,"#sqrt{s} = 8 TeV"); //label->DrawLatex(0.6,0.80, Form("BR(b'#rightarrow %s) = 1", channel.Data())); //label->DrawLatex(0.55,0.80, "BR(b'#rightarrow tW) = 0.5"); //label->DrawLatex(0.55,0.74, "BR(b'#rightarrow bH) = 0.25"); //label->DrawLatex(0.55,0.68, "BR(b'#rightarrow bZ) = 0.25"); //label->DrawLatex(0.2,0.74, lepton.Data()); canvas->SetLogy(1); canvas->SetLogx(1); canvas->SetTickx(1); canvas->SetTicky(1); if (signal == 0){ canvas->Print("Limits/comb_ZPN_limit.pdf"); canvas->Print("Limits/comb_ZPN_limit.root"); } else if (signal == 1){ canvas->Print("Limits/comb_ZPW_limit.pdf"); canvas->Print("Limits/comb_ZPW_limit.root"); } else if (signal == 2){ canvas->Print("Limits/comb_ZPXW_limit.pdf"); canvas->Print("Limits/comb_ZPXW_limit.root"); } else if (signal == 3){ canvas->Print("Limits/comb_RSG_limit.pdf"); canvas->Print("Limits/comb_RSG_limit.root"); } }
void vs_PlotQCDcomp() { Bool_t saveC = false; Bool_t diJets = true; Bool_t isMC = false; TString vsSave; vsSave = "_T07w"; TString jSave; if(diJets) jSave = "2j"; else jSave = "3j"; TString sample; if(diJets) sample = "select_1ph_2jets"; else sample = "select_1ph_3jets"; TString FOtag; if(isMC) FOtag = "_FO_CorrMC"; // else FOtag = "_FO_Corr"; else FOtag = "_FO"; TString sysu = "SYSTUP_"; TString sysd = "SYSTDOWN_"; TString outDir; outDir = "Plots_PhotonSusyAnalysis/QCDweights/"; // string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_QCD_PhotonJet_T07w_PAT/mergedHistos.root"; // string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_Data_V05w_PAT/mergedHistos.root"; string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/PhotonHadReReco_22Jan2013_V05_PAT/mergedHistos.root"; setMyTDRStyle(); gROOT->SetStyle("mytdrStyle"); // gStyle->SetHistMinimumZero(); // gStyle->SetPaintTextFormat("4.2f"); gStyle->SetHistLineWidth(2); gStyle->UseCurrentStyle(); // gStyle->SetPadTopMargin(1.0); // gStyle->SetPadLeftMargin(3.2); // gStyle->SetPadRightMargin(4.5); // gStyle->SetPadBottomMargin(3.2); gROOT->ForceStyle(1); static const Int_t nHt = 7; static const Int_t nPt = 13; static const Int_t nMet = 16; static const Int_t nJet = 15; Double_t binPt[nPt+1] = {0.,75.,90.,120.,160.,210.,260.,320.,400.,500.,650.,800.,1000.,1500.}; Double_t binHt[nHt+1] = {0.,400.,450.,550.,700.,900.,1200.,1500.}; Double_t binMet[nMet+1] = {0.,10.,20.,30.,40.,50.,60.,70.,80.,90.,100.,120.,160.,200.,270.,350.,500.}; Double_t binJet[nJet+1] = {0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15}; TLatex *as = new TLatex(); as->SetNDC(true); as->SetTextColor(12); as->SetTextFont(43); as->SetTextSize(19); TLegend *legend = new TLegend(0.60, 0.70, 0.75, 0.85, ""); legend->SetFillColor(10); legend->SetFillStyle(1001); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->SetShadowColor(0); std::string outLumi = "CMS Work in Progress - QCD MC #sqrt{s} = 8 TeV - #geq 1 #gamma, #geq 2 j"; TFile* f1 = TFile::Open( inputFile1.c_str() ); //photon Pt TCanvas * cPt = new TCanvas("cPt","cPt"); TH1F* hpt = (TH1F*) f1->Get( sample+"/PreselCut_photonPt" ); TH1F* hptFO = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_photonPt" ); TH1F *hptR = (TH1F*) hpt->Rebin(nPt,hpt->GetTitle(),binPt); if (hptR->GetSumw2N() == 0) hptR->Sumw2(); TH1F *hptFOR = (TH1F*) hptFO->Rebin(nPt,hptFO->GetTitle(),binPt); if (hptFOR->GetSumw2N() == 0) hptFOR->Sumw2(); TH1F* hptSU = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysu+"photonPt" ); TH1F* hptSD = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysd+"photonPt" ); TH1F *hptSUR = (TH1F*) hptSU->Rebin(nPt,hptSU->GetTitle(),binPt); if (hptSUR->GetSumw2N() == 0) hptSUR->Sumw2(); TH1F *hptSDR = (TH1F*) hptSD->Rebin(nPt,hptSD->GetTitle(),binPt); if (hptSDR->GetSumw2N() == 0) hptSDR->Sumw2(); if ( hptFOR != 0 ) { for (int b = 0; b < hptFOR->GetNbinsX(); b++) { Double_t mainHistoContent = hptFOR->GetBinContent(b); Double_t systUpHistoContent = hptSUR->GetBinContent(b); Double_t systDnHistoContent = hptSDR->GetBinContent(b); Double_t systDiffUp = fabs( (double) systUpHistoContent - mainHistoContent ); Double_t systDiffDn = fabs( (double) mainHistoContent - systDnHistoContent ); // use average error for histogram Double_t systDiff = ( systDiffUp + systDiffDn ) / 2.; Double_t statErr = hptFOR->GetBinError(b); Double_t combError = sqrt( systDiff * systDiff + statErr * statErr ); hptFOR->SetBinError(b, combError); } //for }//if cPt->SetLogy(1); gPad->Update(); cPt->Update(); // hptR->Scale(1,"width"); // hptR->SetMinimum(0.02); // hptR->SetMaximum(1000); hptR->GetXaxis()->SetTitle("1^{st} photon p_{T} [GeV]"); hptR->GetYaxis()->SetTitle("Number of Events / GeV"); if(isMC) hptR->SetMarkerSize(0); if(isMC) hptR->Draw("histE"); else hptR->Draw("E X0"); hptFOR->SetMarkerSize(0); hptFOR->SetLineColor(2); hptFOR->SetFillColor(2); hptFOR->SetFillStyle(3004); hptFOR->Draw("same hist ][ E2"); legend->Clear(); if(isMC) legend->SetHeader("#gamma/QCD (Sim)"); else legend->SetHeader("#gamma/QCD (Data)"); if(isMC) legend->AddEntry(hptR, "#gamma", "l"); else legend->AddEntry(hptR, "#gamma", "p"); legend->AddEntry(hptFOR, "Pred (from #gamma_{jet})", "f"); legend->Draw(); as->DrawLatex(0.17, 0.93, outLumi.c_str() ); cPt->Update(); cPt->SetBottomMargin(0.2 + 0.8 * cPt->GetBottomMargin() - 0.2 * cPt->GetTopMargin()); TPad *ratioPt = new TPad("BottomPad", "", 0, 0, 1, 1); ratioPt->SetTopMargin(0.8 - 0.8 * ratioPt->GetBottomMargin() + 0.2 * ratioPt->GetTopMargin()); ratioPt->SetFillStyle(0); ratioPt->SetFrameFillColor(10); ratioPt->SetFrameBorderMode(0); ratioPt->Draw(); ratioPt->cd(); ratioPt->SetLogy(0); TH1F *hptRat = (TH1F*) divideHistosForRatio(hptR,hptFOR); hptRat->SetMinimum(0.); hptRat->SetMaximum(10.); hptRat->GetXaxis()->SetNdivisions(505); if(isMC) hptRat->GetYaxis()->SetTitle("Sim/Pred"); else hptRat->GetYaxis()->SetTitle("Data/Pred"); hptRat->GetYaxis()->SetTitleSize(0.04); hptRat->GetYaxis()->SetLabelSize(0.03); hptRat->GetYaxis()->SetTitleOffset(1.3); hptRat->GetYaxis()->SetNdivisions(505); hptRat->SetMarkerStyle(20); hptRat->SetMarkerSize(1); hptRat->SetMarkerColor(1); hptRat->SetLineColor(1); hptRat->Draw("E X0"); TH1F *hptFRat = (TH1F*) getSystErrForRatio(hptFOR); hptFRat->SetLineColor(2); hptFRat->SetFillColor(2); hptFRat->SetFillStyle(3004); hptFRat->Draw("same hist ][ E2"); TLine * line = new TLine( hptRat->GetXaxis()->GetXmin(), 1., hptRat->GetXaxis()->GetXmax(), 1. ); line->SetLineColor(1); line->SetLineWidth(0.5); line->SetLineStyle(1); line->Draw("same"); hptR->GetXaxis()->SetLabelSize(0); hptR->GetXaxis()->SetTitle(""); cPt->RedrawAxis(); gPad->Update(); cPt->Update(); return; }
void DrawMLPoutputMovie( TFile* file, const TString& methodType, const TString& methodTitle ) { gROOT->SetBatch( 1 ); // define Canvas layout here! const Int_t width = 600; // size of canvas // this defines how many canvases we need TCanvas* c = 0; Float_t nrms = 4; Float_t xmin = -1.2; Float_t xmax = 1.2; Float_t ymin = 0; Float_t ymax = 0; Float_t maxMult = 6.0; Int_t countCanvas = 0; Bool_t first = kTRUE; TString dirname = methodType + "/" + methodTitle + "/" + "EpochMonitoring"; TDirectory *epochDir = (TDirectory*)file->Get( dirname ); if (!epochDir) { cout << "Big troubles: could not find directory \"" << dirname << "\"" << endl; exit(1); } // now read all evolution histograms TIter keyItTit(epochDir->GetListOfKeys()); TKey *titkeyTit; while ((titkeyTit = (TKey*)keyItTit())) { if (!gROOT->GetClass(titkeyTit->GetClassName())->InheritsFrom("TH1F")) continue; TString name = titkeyTit->GetName(); if (!name.BeginsWith("convergencetest___")) continue; if (!name.Contains("_train_")) continue; // only for training so far if (name.EndsWith( "_B")) continue; // must be signal histogram if (!name.EndsWith( "_S")) { cout << "Big troubles with histogram: " << name << " -> should end with _S" << endl; exit(1); } // create canvas countCanvas++; TString ctitle = Form("TMVA response %s",methodTitle.Data()); c = new TCanvas( Form("canvas%d", countCanvas), ctitle, 0, 0, width, (Int_t)width*0.78 ); TH1F* sig = (TH1F*)titkeyTit->ReadObj(); sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) ); TString dataType = (name.Contains("_train_") ? "(training sample)" : "(test sample)"); // find background TString nbn = sig->GetName(); nbn[nbn.Length()-1] = 'B'; TH1F* bgd = dynamic_cast<TH1F*>(epochDir->Get( nbn )); if (bgd == 0) { cout << "Big troubles with histogram: " << bgd << " -> cannot find!" << endl; exit(1); } cout << "sig = " << sig->GetName() << endl; cout << "bgd = " << bgd->GetName() << endl; // set the histogram style TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd ); // normalise both signal and background TMVAGlob::NormalizeHists( sig, bgd ); // set only first time, then same for all plots if (first) { if (xmin == 0 && xmax == 0) { xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), bgd->GetMean() - nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmin() ); xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), bgd->GetMean() + nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmax() ); } ymin = 0; ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult; first = kFALSE; } // build a frame Int_t nb = 100; 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 + " response" ); frame->GetYaxis()->SetTitle("(1/N) dN^{ }/^{ }dx"); TMVAGlob::SetFrameStyle( frame ); // find epoch number (4th token) TObjArray* tokens = name.Tokenize("_"); TString es = ((TObjString*)tokens->At(4))->GetString(); if (!es.IsFloat()) { cout << "Big troubles in epoch parsing: \"" << es << "\" is not float" << endl; exit(1); } Int_t epoch = es.Atoi(); // 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() + 0.5, 1 - c->GetTopMargin() ); legend->SetFillStyle( 1 ); legend->AddEntry(sig,TString("Signal ") + dataType, "F"); legend->AddEntry(bgd,TString("Background ") + dataType, "F"); legend->SetBorderSize(1); legend->SetMargin( 0.15 ); legend->Draw("same"); TText* t = new TText(); t->SetTextSize( 0.04 ); t->SetTextColor( 1 ); t->SetTextAlign( 31 ); t->DrawTextNDC( 1 - c->GetRightMargin(), 1 - c->GetTopMargin() + 0.015, Form( "Epoch: %i", epoch) ); // overlay signal and background histograms sig->Draw("samehist"); bgd->Draw("samehist"); // save to file TString dirname = "movieplots"; TString foutname = dirname + "/" + name; foutname.Resize( foutname.Length()-2 ); foutname.ReplaceAll("convergencetest___",""); foutname += ".gif"; cout << "storing file: " << foutname << endl; c->Update(); c->Print(foutname); } }