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(); }
double AutoSetYRange(TCanvas& canv, double maxScale) { TList* list = canv.GetListOfPrimitives(); double maximum = 0; int firstHist = -1; // int isCanvasLogY = canv.GetLogy(); for (int iPrims = 0; iPrims <= list->LastIndex(); ++iPrims) { TH1* hist = dynamic_cast<TH1*>(list->At(iPrims)); if (hist) { //Remember histo to set maximum of, which is the first one drawn if (firstHist == -1) { firstHist = iPrims; } if (hist->GetMaximum() > maximum) { maximum = hist->GetMaximum(); } } } if (firstHist != -1) { dynamic_cast<TH1*>(list->At(firstHist))->SetMaximum(maximum * maxScale); return maximum * maxScale; } else { std::cout << __func__ << " No Histograms found" << std::endl; return -1; } }
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 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 Test(TH1* h, TH1* s, const char* test) { // Check that hist and sparse are equal, print the test result cout << test << ": "; // What exactly is "equal"? // Define it as the max of 1/1000 of the "amplitude" of the // original hist, or 1E-4, whatever is larger. Double_t epsilon = 1E-4; Double_t diffH = h->GetMaximum() - h->GetMinimum(); if (diffH < 0.) diffH = -diffH; if (diffH / 1000. > epsilon) epsilon = diffH / 1000.; TH1* diff = (TH1*)s->Clone("diff"); diff->Add(h, -1); Double_t max = diff->GetMaximum(); Double_t min = diff->GetMinimum(); if (max < -min) max = -min; if (max < epsilon) cout << "SUCCESS"; else { cout << "FAIL: delta=" << max; TCanvas* c = new TCanvas(test, test); c->Divide(1,3); c->cd(1); h->Draw(); c->cd(2); s->Draw(); c->cd(3); diff->Draw(); TFile f("runsparse.root", "UPDATE"); c->Write(); delete c; } cout <<endl; delete diff; }
// Draw pT balance plots void PlotOnCanvas(TH1& genHist, TH1& recoHist, TString plotname) { TLine* line1 = new TLine(1.0, genHist.GetMinimum(), 1.0, genHist.GetMaximum()); line1->SetLineColor(4); line1->SetLineWidth(2); TCanvas canvas("canvas", "", 880, 600); gStyle->SetOptStat(0); genHist.Draw("hist"); line1->Draw(); recoHist.Draw("same"); recoHist.Draw("HIST same"); leg_hist = new TLegend(0.6,0.65,0.85,0.85); leg_hist->AddEntry(&genHist,"Generator level","l"); leg_hist->AddEntry(&recoHist,"Calorimeter level","l"); leg_hist->SetFillColor(0); leg_hist->Draw(); canvas.SaveAs(plotname+TString(".eps")); canvas.SaveAs(plotname+TString(".gif")); canvas.SaveAs(plotname+TString(".root")); delete line1; delete leg_hist; }
TCanvas* DrawNP(int np, TObjArray* harr, TCanvas* cnv) { if (!harr) harr = &histoArr; if (!cnv) cnv = new TCanvas(Form("cnv%d",np),Form("cnv%d",np),900,700); cnv->Clear(); cnv->Divide(2,1); cnv->cd(1); // TH1* dxodd = (TH1*)harr->At(np*10+kDTXodd); TH1* dxevn = (TH1*)harr->At(np*10+kDTXeven); TH1* dxoddS =(TH1*)harr->At(np*10+kDTXoddSPL); TH1* dxevnS =(TH1*)harr->At(np*10+kDTXevenSPL); double max = TMath::Max(dxodd->GetMaximum(),dxevn->GetMaximum()); dxodd->SetMaximum(1.1*max); dxodd->GetXaxis()->SetTitle("#DeltaX, #mum"); dxodd->SetTitle(Form("#DeltaX for clSize=%d",np)); dxodd->Fit("gaus","",""); dxevn->Fit("gaus","","sames"); // dxoddS->Draw("sames"); dxevnS->Draw("sames"); // gPad->Modified(); gPad->Update(); SetStPadPos(dxodd,0.75,0.97,0.8,1., -1,dxodd->GetLineColor()); SetStPadPos(dxevn,0.75,0.97,0.6,0.8, -1,dxevn->GetLineColor()); SetStPadPos(dxoddS,0.75,0.97,0.4,0.6, -1,dxoddS->GetLineColor()); SetStPadPos(dxevnS,0.75,0.97,0.2,0.4, -1,dxevnS->GetLineColor()); // cnv->cd(2); TH1* dz = (TH1*)harr->At(np*10+kDTZ); dz->SetTitle(Form("#DeltaZ for clSize=%d",np)); dz->GetXaxis()->SetTitle("#DeltaZ, #mum"); dz->Fit("gaus"); TH1* dzS = (TH1*)harr->At(np*10+kDTZSPL); dz->Draw("sames"); gPad->Modified(); gPad->Update(); SetStPadPos(dz,0.75,0.97,0.8,1., -1, dz->GetLineColor()); SetStPadPos(dzS,0.75,0.97,0.5,0.7, -1, dzS->GetLineColor()); gPad->Modified(); gPad->Update(); // cnv->cd(); return cnv; }
TH1F *stabilityHist(TGraphErrors *g_data, double& y_err_mean){ //------------------------------ Double_t *Y=g_data->GetY(); Double_t *EY = g_data->GetEY(); TH1 *obj = (TH1*) g_data->GetYaxis()->GetParent(); TH1F *hist_corr = new TH1F("hist_"+TString(g_data->GetName()),"", g_data->GetN(), obj->GetMinimum(), obj->GetMaximum()); hist_corr->GetXaxis()->SetLabelSize(0); hist_corr->GetYaxis()->SetLabelSize(0); for(int i =0; i < g_data->GetN(); i++){ hist_corr -> Fill(Y[i]); y_err_mean+=EY[i]; } y_err_mean/=g_data->GetN(); return hist_corr; }
//____________________________________________________________________ TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2) { TString name; name.Form("cent%03dd%02d_%03dd%02d", Int_t(c1), Int_t(c1*100)%100, Int_t(c2), Int_t(c2*100)%100); TDirectory* newSubDir = GetD(newDir, name); TDirectory* oldSubDir = GetD(oldDir, name); if (!newSubDir || !oldSubDir) return 0; Int_t newDim = 0; if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3; else if (TString(newDir->GetName()).Contains("eta")) newDim = 2; else if (TString(newDir->GetName()).Contains("const")) newDim = 1; Int_t oldDim = 0; if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3; else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2; else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1; TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim)); TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim)); if (!newSubSubDir || !oldSubSubDir) return 0; TH1* newRes = GetH1(newSubSubDir, "result"); TH1* oldRes = GetH1(oldSubSubDir, "result"); if (!newRes || !oldRes) return 0; TH1* ratio = static_cast<TH1*>(newRes->Clone(name)); ratio->SetDirectory(0); ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2)); ratio->SetYTitle("New / Old"); ratio->Divide(oldRes); fMin = TMath::Min(fMin, ratio->GetMinimum()); fMax = TMath::Max(fMax, ratio->GetMaximum()); Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName()); if (!fLegend) return ratio; TLegendEntry* e = fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f"); e->SetFillStyle(1001); e->SetFillColor(ratio->GetMarkerColor()); return ratio; }
void RenderHisto( TObject * obj, TCanvas * canvas ) { assert(obj->InheritsFrom("TH1")) ; TH1 * histo = dynamic_cast<TH1*>(obj) ; assert(histo) ; TString histo_option = ((TH1 *)obj)->GetOption() ; if ((histo_option.Contains("ELE_LOGY")==kTRUE)&&(histo->GetMaximum()>0)) { canvas->SetLogy(1) ; } int histo_name_flag = 1 ; // use 0 to switch off if ( obj->InheritsFrom("TH2") ) { gStyle->SetPalette(1) ; gStyle->SetOptStat(110+histo_name_flag) ; } else if ( obj->InheritsFrom("TProfile") ) { gStyle->SetOptStat(110+histo_name_flag) ; } else // TH1 { gStyle->SetOptStat(111110+histo_name_flag) ; } }
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 ); }
void drawPlots(canvasSet_t& cs,bool savePlots2file) { wCanvas_t *wc0 = cs.canvases[0]; unsigned npads = wc0->npadsx*wc0->npadsy; unsigned npadsall = cs.ncanvases*npads; if (!npads) { if (gl_verbose) cout << "Nothing to draw, guess I'm done." << endl; return; // no pads to draw on. } else if (!wc0->pads.size()) { /******************************************************** * CHECK MULTIPAD OPTION, ASSIGN HISTOS TO PADS/CANVASES ********************************************************/ if (wc0->multipads.size()) { npadsall = assignHistos2Multipad(cs); } else { cerr << "npads>0, but no pad specs supplied, exiting." << endl; return; // no pads to draw on. } } else if (cs.ncanvases>1) { npadsall = assignPads2Canvases(cs); } else { npadsall = std::min(npadsall,(unsigned)wc0->pads.size()); } wc0->c1->cd(); if (gl_verbose) cout << "Drawing on " << npadsall << " pad(s)" << endl; wLegend_t *wleg = NULL; /*************************************************** * LOOP OVER PADS... ***************************************************/ //vector<vector<string> >::const_iterator it; for (unsigned ipad = 0; ipad< npadsall; ipad++) { if (gl_verbose) cout << "Drawing pad# " << ipad+1 << endl; unsigned ipadc = ipad % npads; unsigned cnum = (ipad / npads) + 1; wCanvas_t *wc = cs.canvases[cnum-1]; if (!ipadc) { if (cnum-1) { // first canvas already created wc->c1 = new TCanvas(wc->title.c_str(),wc->title.c_str(), wc->padxdim*wc->npadsx, wc->padydim*wc->npadsy); float left = wc->leftmargin; float bot = wc->bottommargin; float rhgt = 1-wc->rightmargin; float top = 1-wc->topmargin; wc->motherpad = new TPad("mother","",left,bot,rhgt,top); wc->c1->SetFillColor(wc->fillcolor); wc->motherpad->SetFillColor(wc->fillcolor); wc->motherpad->Draw(); wc->motherpad->cd(); wc->motherpad->Divide(wc->npadsx,wc->npadsy); // , wc->padxmargin,wc->padymargin); } /*************************************************** * CHECK FOR LATEX OBJECTS ON THE CANVAS ***************************************************/ wc->c1->cd(); for (unsigned j=0; j<wc->latex_ids.size(); j++) { string& lid = wc->latex_ids[j]; map<string,TLatex *>::const_iterator it = glmap_id2latex.find(lid); if (it == glmap_id2latex.end()) { cerr << "ERROR: latex id " << lid << " never defined in layout" << endl; exit (-1); } TLatex *ltx = it->second; ltx->Draw(); wc->c1->Update(); } } wPad_t *& wp = wc->pads[ipadc]; wp->vp = wc->motherpad->cd(ipadc+1); if (!wp->histo_ids.size() && !wp->stack_ids.size() && !wp->graph_ids.size() && !wp->macro_ids.size()) { cerr << "ERROR: pad #" << ipadc+1 << " has no ids defined for it"; cerr << ", continuing to the next" << endl; continue; } #if 0 /*************************************************** * Draw the frame first: * (Fix up frame since it can't be auto-scaled:) ***************************************************/ string& hid0 = wp->histo_ids[0]; map<string,wTH1 *>::const_iterator it = glmap_id2histo.find(hid0); if (it == glmap_id2histo.end()) { cerr << "ERROR: id0 " << hid0 << " never defined in layout" << endl; return; } wTH1 *myHisto = it->second; TH1 *h = myHisto->histo(); if (wp->hframe->histo()->GetXaxis()->GetXmin() <= wp->hframe->histo()->GetXaxis()->GetXmax()) wp->hframe->histo()->GetXaxis()->SetRangeUser(h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax()); if (wp->hframe->histo()->GetYaxis()->GetXmin() <= wp->hframe->histo()->GetYaxis()->GetXmax()) wp->hframe->histo()->GetYaxis()->SetRangeUser(h->GetYaxis()->GetXmin(), h->GetYaxis()->GetXmax()); wp->hframe->SetStats(0); //wp->hframe->Draw("AXIS"); #endif /*************************************************** * Check for external macros to run on the pad ***************************************************/ for (size_t i=0; i<wp->macro_ids.size(); i++) { map<string,string>::const_iterator it = glmap_objpath2id.find(wp->macro_ids[i]); if (it != glmap_objpath2id.end()) { string path = it->second; int error; gROOT->Macro(path.c_str(), &error, kTRUE); // update current pad if (error) { static const char *errorstr[] = { "kNoError","kRecoverable","kDangerous","kFatal","kProcessing" }; cerr << "ERROR: error returned from macro: " << errorstr[error] << endl; } } else { cerr << "ERROR: macro id " << wp->macro_ids[i]; cerr << " never defined in layout" << endl; } } /*************************************************** * Check for existence of a legend, create it ***************************************************/ bool drawlegend = false; if (wp->legid.size()) { map<string,wLegend_t *>::const_iterator it=glmap_id2legend.find(wp->legid); if (it != glmap_id2legend.end()) { drawlegend = true; wleg = it->second; } else { cerr << "ERROR: legend id " << wp->legid; cerr << " never defined in layout" << endl; } } else { // Maybe gPad already *has* a legend from macros... TPave *testing = (TPave *)gPad->GetPrimitive("TPave"); if (testing && !strcmp(testing->IsA()->GetName(),"TLegend")) { TLegend *pullTheOtherOne = (TLegend *)testing; if (gl_verbose) cout << "Found legend from macro" << endl; wleg = new wLegend_t(); wleg->leg = pullTheOtherOne; drawlegend = true; } } /*************************************************** * LOOP OVER STACKS DEFINED FOR PAD... ***************************************************/ if (wp->stack_ids.size()) { wStack_t *ws=NULL; for (unsigned j = 0; j < wp->stack_ids.size(); j++) { string& sid = wp->stack_ids[j]; map<string,wStack_t *>::const_iterator it = glmap_id2stack.find(sid); if (it == glmap_id2stack.end()) { cerr << "ERROR: stack id " << sid << " never defined in layout" << endl; exit (-1); } bool firstInPad = !j; ws = it->second; if (!ws) { cerr<< "find returned NULL stack pointer for " << sid << endl; continue; } // Add the histos in the stack to any legend that exists // if (drawlegend) { for (size_t i=0; i<ws->v_histos.size(); i++) { wTH1 *wh = ws->v_histos[i]; wh->ApplySavedStyle(); if(wh->GetLegendEntry().size()) wh->Add2Legend(wleg->leg); } } string drawopt(""); if (ws->sum->GetDrawOption().size()) { drawopt = ws->sum->GetDrawOption(); cout << "drawopt stored with histo = " << drawopt << endl; } drawInPad(wp, ws, firstInPad, drawopt); wp->vp->Update(); } } // stack loop /*************************************************** * LOOP OVER HISTOS DEFINED FOR PAD... ***************************************************/ for (unsigned j = 0; j < wp->histo_ids.size(); j++) { string& hid = wp->histo_ids[j]; map<string,wTH1 *>::const_iterator it = glmap_id2histo.find(hid); if (it == glmap_id2histo.end()) { cerr << "ERROR: histo id " << hid << " never defined in layout" << endl; exit (-1); } wTH1 *myHisto = it->second; if (myHisto) { bool firstInPad = !j && !wp->stack_ids.size(); if (gl_verbose) { cout << "Drawing " << hid << " => "; cout << myHisto->histo()->GetName() << endl; cout << "firstInPad = " << firstInPad << endl; } drawInPad(wp,*myHisto,firstInPad); myHisto->DrawFits("same"); if (drawlegend && myHisto->GetLegendEntry().size()) { if (wleg->drawoption.size()) myHisto->SetDrawOption(wleg->drawoption); myHisto->Add2Legend(wleg->leg); } if (myHisto->statsAreOn()) { myHisto->DrawStats(); wp->vp->Update(); } myHisto->ApplySavedStyle(); wp->vp->Update(); } } // histos loop /*************************************************** * LOOP OVER HISTOS DEFINED FOR ALTERNATE Y-AXIS ***************************************************/ Float_t rightmax=0.0,rightmin=0.0; Float_t scale=0.0; for (unsigned j = 0; j < wp->altyh_ids.size(); j++) { string& hid = wp->altyh_ids[j]; map<string,wTH1 *>::const_iterator it = glmap_id2histo.find(hid); if (it == glmap_id2histo.end()) { cerr << "ERROR: histo id " << hid << " never defined in layout" << endl; exit (-1); } wTH1 *myHisto = it->second; TH1 *h = myHisto->histo(); if (!j) { //scale second set of histos to the pad coordinates rightmin = h->GetMinimum(); rightmax = 1.1*h->GetMaximum(); scale = gPad->GetUymax()/rightmax; } TH1 *scaled=(TH1 *)h->Clone(Form("%s_%d",h->GetName(),ipad)); scaled->Scale(scale); scaled->Draw("same"); //draw an axis on the right side TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(), gPad->GetUxmax(), gPad->GetUymax(), rightmin,rightmax,505,"+L"); axis->Draw(); gPad->Update(); if (drawlegend && myHisto->GetLegendEntry().size()) { if (wleg->drawoption.size()) myHisto->SetDrawOption(wleg->drawoption); myHisto->Add2Legend(wleg->leg); } } /*************************************************** * LOOP OVER GRAPHS DEFINED FOR PAD... ***************************************************/ #if 0 TMultiGraph *mg; if (graph_ids.size()) mg = new TMultiGraph(); #endif for( unsigned j = 0; j < wp->graph_ids.size(); j++ ) { string& gid = wp->graph_ids[j]; wGraph_t *wg = findGraph(gid); bool firstInPad = !j && !wp->histo_ids.size() && !wp->macro_ids.size(); if( firstInPad && wg->gr && wg->gr->IsA()==TGraph::Class() ) wg->drawopt += string("A"); // no histos drawn, need to draw the frame ourselves. if( wg && wg->gr ) { // "pre-draw" in order to define the plot elements wg->gr->Draw(wg->drawopt.c_str()); if (firstInPad) { // Now we can set the axis attributes and range: wg->gr->GetXaxis()->ImportAttributes(wg->xax); wg->gr->GetYaxis()->ImportAttributes(wg->yax); cout << wg->xax->GetXmin() << " " << wg->xax->GetXmax() << endl; if( wg->xax->GetXmax()>wg->xax->GetXmin() ) wg->gr->GetXaxis()->SetLimits(wg->xax->GetXmin(),wg->xax->GetXmax()); if( wg->yax->GetXmax()>wg->yax->GetXmin() ) wg->gr->GetYaxis()->SetRangeUser(wg->yax->GetXmin(),wg->yax->GetXmax()); } // draw for good drawInPad<TGraph>(wp,wg->gr,wg->drawopt.c_str(),firstInPad); wp->vp->Update(); if( wg->fitfn ) wg->gr->Fit(wg->fitfn); if( drawlegend && wg->leglabel.size() ) wleg->leg->AddEntry(wg->gr,wg->leglabel.c_str(),wg->legdrawopt.c_str()); } if( wg && wg->gr2d ) { drawInPad<TGraph2D>(wp,wg->gr2d,wg->drawopt.c_str(),firstInPad); if (firstInPad) { // Now we can set the axis attributes and range: wg->gr2d->GetXaxis()->ImportAttributes(wg->xax); wg->gr2d->GetYaxis()->ImportAttributes(wg->yax); cout << wg->xax->GetXmin() << " " << wg->xax->GetXmax() << endl; if( wg->xax->GetXmax()>wg->xax->GetXmin() ) wg->gr2d->GetXaxis()->SetLimits(wg->xax->GetXmin(),wg->xax->GetXmax()); if( wg->yax->GetXmax()>wg->yax->GetXmin() ) wg->gr2d->GetYaxis()->SetRangeUser(wg->yax->GetXmin(),wg->yax->GetXmax()); } if (wg->contours) { //cout << "setting contours "; wg->contours->Print(); wg->gr2d->GetHistogram()->SetContour(wg->contours->GetNoElements(), wg->contours->GetMatrixArray()); wg->gr2d->SetLineStyle (wg->lstyle); wg->gr2d->SetLineColor (wg->lcolor); wg->gr2d->SetLineWidth (wg->lwidth); } wp->vp->Modified(); wp->vp->Update(); if( drawlegend && wg->leglabel.size() ) wleg->leg->AddEntry(wg->gr2d,wg->leglabel.c_str(),wg->legdrawopt.c_str()); } } // graph loop /*************************************************** * LOOP OVER LINES DEFINED FOR PAD... ***************************************************/ for( unsigned j = 0; j < wp->line_ids.size(); j++ ) { string drawopt("L"); string& lid = wp->line_ids[j]; map<string,TLine *>::const_iterator it2 = glmap_id2line.find(lid); if (it2 == glmap_id2line.end()) { cerr << "ERROR: line id " << lid << " never defined in layout" << endl; exit (-1); } TLine *line = it2->second; if (!j && !wp->histo_ids.size() && !wp->macro_ids.size()) drawopt += string("A"); // no histos drawn, need to draw the frame ourselves. if (line) { drawInPad<TLine>(wp,line,drawopt.c_str()); //if (drawlegend) //wleg->leg->AddEntry(line,lid.c_str(),"L"); } } /*************************************************** * LOOP OVER BOXES DEFINED FOR PAD... ***************************************************/ for (unsigned j = 0; j < wp->box_ids.size(); j++) { string drawopt("L"); string& bid = wp->box_ids[j]; map<string,TBox *>::const_iterator it2 = glmap_id2box.find(bid); if (it2 == glmap_id2box.end()) { cerr << "ERROR: box id " << bid << " never defined in layout" << endl; exit (-1); } TBox *box = it2->second; if (box) { drawInPad<TBox>(wp,box,drawopt.c_str()); } } /*************************************************** * Draw the legend ***************************************************/ if (drawlegend) { wleg->leg->Draw("same"); wp->vp->Update(); } /*************************************************** * Draw each latex/label object ***************************************************/ for (unsigned j=0; j<wp->latex_ids.size(); j++) { string& lid = wp->latex_ids[j]; map<string,TLatex *>::const_iterator it2 = glmap_id2latex.find(lid); if (it2 == glmap_id2latex.end()) { cerr << "ERROR: latex id " << lid << " never defined in layout" << endl; exit (-1); } if (gl_verbose) cout << "Drawing latex object " << lid << endl; TLatex *ltx = it2->second; ltx->Draw(); wp->vp->Update(); } for (unsigned j = 0; j < wp->label_ids.size(); j++) { string& lid = wp->label_ids[j]; map<string,wLabel_t *>::const_iterator it2 = glmap_id2label.find(lid); if (it2 == glmap_id2label.end()) { cerr << "ERROR: label id " << lid << " never defined in layout" << endl; exit (-1); } if (gl_verbose) cout << "Drawing label object " << lid << endl; wLabel_t *wlab = it2->second; drawStandardText(wlab->text, wlab->x1ndc, wlab->y1ndc,-1,-1,wlab->textsize); wp->vp->Update(); } wc->c1->Update(); } // pad loop //prdFixOverlay(); if (savePlots2file) { wc0 = cs.canvases[0]; if (!wc0->savenamefmts.size()) // define a default wc0->savenamefmts.push_back("%F_%C.png"); for (size_t i=0; i<cs.canvases.size(); i++) { wCanvas_t *wc = cs.canvases[i]; wc->c1->cd(); for (size_t j=0; j<wc0->savenamefmts.size(); j++) saveCanvas2File(wc,wc0->savenamefmts[j]); } } } // drawPlots
//______________________________________________________________________________ void PIDEnergy() { // Main method. Char_t tmp[256]; // load CaLib gSystem->Load("libCaLib.so"); // general configuration const Char_t* data = "Data.PID.E0"; const Char_t* hName = "CaLib_PID_Energy_Proton_PID_Energy"; // configuration (December 2007) //const Char_t calibration[] = "LD2_Dec_07"; //const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Dec_07/AR/out/ARHistograms_CB_RUN.root"; //const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/Dec_07/MC/calibration/all.root"; // configuration (February 2009) //const Char_t calibration[] = "LD2_Feb_09"; //const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/Feb_09/AR/out/ARHistograms_CB_RUN.root"; //const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/Feb_09/MC/calibration/all.root"; // configuration (May 2009) const Char_t calibration[] = "LD2_May_09"; const Char_t filePat[] = "/usr/puma_scratch0/werthm/A2/May_09/AR/out/ARHistograms_CB_RUN.root"; const Char_t mcFile[] = "/usr/panther_scratch0/werthm/A2/May_09/MC/calibration/all.root"; // get number of sets Int_t nSets = TCMySQLManager::GetManager()->GetNsets(data, calibration); // create canvas Int_t n = TMath::Sqrt(nSets); TCanvas* cOverview = new TCanvas("c", "c", 1200, 900); cOverview->Divide(n, nSets / n + 1); // create arrays Double_t* pos = new Double_t[nSets+1]; Double_t* fwhm = new Double_t[nSets+1]; // total sum histogram TH1* hTot = 0; // load MC histo TFile* fMC = new TFile(mcFile); TH2* hMC2 = (TH2*) fMC->Get(hName); TH1* hMC = hMC2->ProjectionX("mc"); hMC->SetLineColor(kBlue); // loop over sets for (Int_t i = 0; i < nSets; i++) { // create file manager TCFileManager m(data, calibration, 1, &i, filePat); // get histo TH2* h2 = (TH2*) m.GetHistogram(hName); // skip empty histo if (!h2) continue; // project histo sprintf(tmp, "Proj_%d", i); TH1* h = (TH1*) h2->ProjectionX(tmp); //TH1* h = (TH1*) h2->ProjectionX(tmp, 9, 9); //h->Rebin(4); // add to total histogram if (!hTot) hTot = (TH1*) h->Clone(); else hTot->Add(h); // fit histo cOverview->cd(i+1); h->SetLineColor(kBlack); h->Draw(); hMC->Scale(h->GetMaximum()/hMC->GetMaximum()); hMC->DrawCopy("same"); } }
void recurseOverKeys(TDirectory *target, TString imageType) { // TString path( (char*)strstr( target->GetPath(), ":" ) ); // path.Remove( 0, 2 ); // cout << path << endl; // sourceFile->cd( path ); target->cd(); TDirectory *current_sourcedir = gDirectory; TKey *key; TIter nextkey(current_sourcedir->GetListOfKeys()); TCanvas *canvasDefault = new TCanvas(); while ( (key = (TKey*)nextkey() ) ) { TObject* obj = key->ReadObj(); if (obj->IsA()->InheritsFrom("TH1") ) { // ************************** // Plot & Save this Histogram TH1* h = (TH1*)obj; h->SetStats(displayStatsBox); TString histName = h->GetName(); // Now to label the X-axis! // if (autoLabelXaxis) { // if ( histName.Contains("Phi") ) { // h->GetXaxis()->SetTitle("#phi"); // } else if ( histName.Contains("Eta") ) { // h->GetXaxis()->SetTitle("#eta"); // } else if ( histName.Contains("Pt") ) { // h->GetXaxis()->SetTitle("p_{T} (GeV)"); // } else if ( histName.Contains("Et") ) { // h->GetXaxis()->SetTitle("E_{T} (GeV)"); // } // } // h->SetLineColor(lineColor); // h->SetLineWidth(lineWidth); // ******************************** // A trick to decide whether to have log or no-log y axis // get hist max y value if (autoLogYaxis) { Double_t testYvalue = h->GetMaximum(); //cout << testYvalue << endl; if (testYvalue > 1.0) { Double_t maxy = log10(testYvalue); // get hist min y value Double_t miny = log10(h->GetMinimum(1.0)); // log scale if more than 3 powers of 10 between low and high bins if ( (maxy-miny) > 3.0 ) { canvasDefault->SetLogy(1); } } } // End of log or no-log y axis decision // ******************************** h->Draw(drawOptions1D); canvasDefault->Modified(); canvasDefault->Update(); // gPad->Print(outputFolder+path+"/"+histName+outputType); TString outputFolder = "images/"; gPad->Print(outputFolder+histName+"."+imageType); // To store the root file name in image file name: //canvasDefault->Print(outputFolder+histFileName+histName+outputType); // if (printOutput) cout << outputFolder+path+"/"+histName+outputType << endl; canvasDefault->SetLogy(0); // reset to no-log - prevents errors // ************************** } else if ( obj->IsA()->InheritsFrom( "TDirectory" ) ) { // it's a subdirectory cout << "Found subdirectory " << obj->GetName() << endl; // gSystem->MakeDirectory(outputFolder+path+"/"+obj->GetName()); // obj is now the starting point of another round of merging // obj still knows its depth within the target file via // GetPath(), so we can still figure out where we are in the recursion recurseOverKeys((TDirectory*)obj, imageType); } // end of IF a TDriectory } // end of LOOP over keys }
void plotter::draw_output_mass(TH1* output_, TH1* stat_, std::vector<TH1D*> mtop_templates_, std::vector<bool> show, bool norm, TString file_name){ TH1* output = (TH1*) output_->Clone("output"); TH1* stat = (TH1*) stat_->Clone("stat"); std::vector<TH1D*> mtop_templates; for(unsigned int i = 0; i < mtop_templates_.size(); i++){ mtop_templates.push_back((TH1D*) mtop_templates_[i]->Clone("")); } TCanvas *c = new TCanvas("c","",600,600); gPad->SetLeftMargin(0.15); double max = output->GetMaximum(); for(unsigned int i = 0; i < mtop_templates.size(); i++){ if(show[i]){ double max_temp = mtop_templates[i]->GetMaximum(); if(max_temp > max) max = max_temp; } } double ymax = 1.5 * max; 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 SAME"); stat->SetLineColor(kBlack); stat->SetMarkerColor(kBlack); stat->SetMarkerStyle(8); stat->SetMarkerSize(1); gStyle->SetEndErrorSize(5); mtop_templates[0]->SetLineColor(kRed); mtop_templates[1]->SetLineColor(kRed); mtop_templates[2]->SetLineColor(kRed); mtop_templates[3]->SetLineColor(13); mtop_templates[4]->SetLineColor(kAzure+7); mtop_templates[5]->SetLineColor(kAzure+7); mtop_templates[6]->SetLineColor(kAzure+7); for(unsigned int i = 0; i < mtop_templates.size(); i++){ mtop_templates[i]->SetLineWidth(3); if(show[i]) mtop_templates[i]->Draw("HIST SAME"); } stat->Draw("E1 SAME"); output->Draw("E1 SAME"); // draw again to set markers in front TLegend *l=new TLegend(0.56,0.65,0.78,0.85); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(output,"data unfolded","pl"); if(show[0]) l->AddEntry(mtop_templates[0],"m_{top}^{MC} = 166.5 GeV","pl"); if(show[1]) l->AddEntry(mtop_templates[1],"m_{top}^{MC} = 169.5 GeV","pl"); if(show[2]) l->AddEntry(mtop_templates[2],"m_{top}^{MC} = 171.5 GeV","pl"); if(show[3]) l->AddEntry(mtop_templates[3],"m_{top}^{MC} = 172.5 GeV","pl"); if(show[4]) l->AddEntry(mtop_templates[4],"m_{top}^{MC} = 173.5 GeV","pl"); if(show[5]) l->AddEntry(mtop_templates[5],"m_{top}^{MC} = 175.5 GeV","pl"); if(show[6]) l->AddEntry(mtop_templates[6],"m_{top}^{MC} = 178.5 GeV","pl"); l->SetTextSize(0.04); l->Draw(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void eregtesting_13TeV_Pi0(bool dobarrel=true, bool doele=false,int gammaID=0) { //output dir TString EEorEB = "EE"; if(dobarrel) { EEorEB = "EB"; } TString gammaDir = "bothGammas"; if(gammaID==1) { gammaDir = "gamma1"; } else if(gammaID==2) { gammaDir = "gamma2"; } TString dirname = TString::Format("ereg_test_plots/%s_%s",gammaDir.Data(),EEorEB.Data()); gSystem->mkdir(dirname,true); gSystem->cd(dirname); //read workspace from training TString fname; if (doele && dobarrel) fname = "wereg_ele_eb.root"; else if (doele && !dobarrel) fname = "wereg_ele_ee.root"; else if (!doele && dobarrel) fname = "wereg_ph_eb.root"; else if (!doele && !dobarrel) fname = "wereg_ph_ee.root"; TString infile = TString::Format("../../ereg_ws/%s/%s",gammaDir.Data(),fname.Data()); TFile *fws = TFile::Open(infile); RooWorkspace *ws = (RooWorkspace*)fws->Get("wereg"); //read variables from workspace RooGBRTargetFlex *meantgt = static_cast<RooGBRTargetFlex*>(ws->arg("sigmeant")); RooRealVar *tgtvar = ws->var("tgtvar"); RooArgList vars; vars.add(meantgt->FuncVars()); vars.add(*tgtvar); //read testing dataset from TTree RooRealVar weightvar("weightvar","",1.); TTree *dtree; if (doele) { //TFile *fdin = TFile::Open("root://eoscms.cern.ch//eos/cms/store/cmst3/user/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TFile *fdin = TFile::Open("/data/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterSingleInvert"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } else { if(dobarrel) { TFile *fdin = TFile::Open("/afs/cern.ch/work/z/zhicaiz/public/ECALpro_MC_TreeForRegression/Gun_Pi0_Pt1To15_FlatPU0to50RAW_withHLT_80X_mcRun2_GEN-SIM-RAW_ALL_EcalNtp_ALL_EB_combine_test.root");//("root://eoscms.cern.ch///eos/cms/store/cmst3/user/bendavid/idTreesAug1/hgg-2013Final8TeV_ID_s12-h124gg-gf-v7n_noskim.root"); // TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); if(gammaID==0) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma"); } else if(gammaID==1) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma1"); } else if(gammaID==2) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma2"); } } else { TFile *fdin = TFile::Open("/afs/cern.ch/work/z/zhicaiz/public/ECALpro_MC_TreeForRegression/Gun_Pi0_Pt1To15_FlatPU0to50RAW_withHLT_80X_mcRun2_GEN-SIM-RAW_ALL_EcalNtp_ALL_EE_combine_test.root");//("root://eoscms.cern.ch///eos/cms/store/cmst3/user/bendavid/idTreesAug1/hgg-2013Final8TeV_ID_s12-h124gg-gf-v7n_noskim.root"); // TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterPreselNoSmear"); if(gammaID==0) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma"); } else if(gammaID==1) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma1"); } else if(gammaID==2) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma2"); } } } //selection cuts for testing //TCut selcut = "(STr2_enG1_true/cosh(STr2_Eta_1)>1.0) && (STr2_S4S9_1>0.75)"; TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)>60)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_nocor/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03)"; /* TCut selcut; if (dobarrel) selcut = "ph.genpt>25. && ph.isbarrel && ph.ispromptgen"; else selcut = "ph.genpt>25. && !ph.isbarrel && ph.ispromptgen"; */ TCut selweight = "xsecweight(procidx)*puweight(numPU,procidx)"; TCut prescale10 = "(Entry$%10==0)"; TCut prescale10alt = "(Entry$%10==1)"; TCut prescale25 = "(Entry$%25==0)"; TCut prescale100 = "(Entry$%100==0)"; TCut prescale1000 = "(Entry$%1000==0)"; TCut evenevents = "(Entry$%2==0)"; TCut oddevents = "(Entry$%2==1)"; TCut prescale100alt = "(Entry$%100==1)"; TCut prescale1000alt = "(Entry$%1000==1)"; TCut prescale50alt = "(Entry$%50==1)"; TCut Events3_4 = "(Entry$%4==3)"; TCut Events1_4 = "(Entry$%4==1)"; TCut Events2_4 = "(Entry$%4==2)"; TCut Events0_4 = "(Entry$%4==0)"; TCut Events01_4 = "(Entry$%4<2)"; TCut Events23_4 = "(Entry$%4>1)"; if (doele) weightvar.SetTitle(prescale100alt*selcut); else weightvar.SetTitle(selcut); //make testing dataset RooDataSet *hdata = RooTreeConvert::CreateDataSet("hdata",dtree,vars,weightvar); if (doele) weightvar.SetTitle(prescale1000alt*selcut); else weightvar.SetTitle(prescale10alt*selcut); //make reduced testing dataset for integration over conditional variables RooDataSet *hdatasmall = RooTreeConvert::CreateDataSet("hdatasmall",dtree,vars,weightvar); //retrieve full pdf from workspace RooAbsPdf *sigpdf = ws->pdf("sigpdf"); //input variable corresponding to sceta RooRealVar *scetavar = ws->var("var_1"); RooRealVar *scphivar = ws->var("var_2"); //regressed output functions RooAbsReal *sigmeanlim = ws->function("sigmeanlim"); RooAbsReal *sigwidthlim = ws->function("sigwidthlim"); RooAbsReal *signlim = ws->function("signlim"); RooAbsReal *sign2lim = ws->function("sign2lim"); RooAbsReal *sigalphalim = ws->function("sigalphalim"); RooAbsReal *sigalpha2lim = ws->function("sigalpha2lim"); //formula for corrected energy/true energy ( 1.0/(etrue/eraw) * regression mean) RooFormulaVar ecor("ecor","","1./(@0)*@1",RooArgList(*tgtvar,*sigmeanlim)); RooRealVar *ecorvar = (RooRealVar*)hdata->addColumn(ecor); ecorvar->setRange(0.,2.); ecorvar->setBins(800); //formula for raw energy/true energy (1.0/(etrue/eraw)) RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); RooRealVar *rawvar = (RooRealVar*)hdata->addColumn(raw); rawvar->setRange(0.,2.); rawvar->setBins(800); //clone data and add regression outputs for plotting RooDataSet *hdataclone = new RooDataSet(*hdata,"hdataclone"); RooRealVar *meanvar = (RooRealVar*)hdataclone->addColumn(*sigmeanlim); RooRealVar *widthvar = (RooRealVar*)hdataclone->addColumn(*sigwidthlim); RooRealVar *nvar = (RooRealVar*)hdataclone->addColumn(*signlim); RooRealVar *n2var = (RooRealVar*)hdataclone->addColumn(*sign2lim); RooRealVar *alphavar = (RooRealVar*)hdataclone->addColumn(*sigalphalim); RooRealVar *alpha2var = (RooRealVar*)hdataclone->addColumn(*sigalpha2lim); //plot target variable and weighted regression prediction (using numerical integration over reduced testing dataset) TCanvas *craw = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot = tgtvar->frame(0.6,2.0,100); hdata->plotOn(plot); sigpdf->plotOn(plot,ProjWData(*hdatasmall)); plot->Draw(); craw->SaveAs("RawE.pdf"); craw->SaveAs("RawE.png"); craw->SetLogy(); plot->SetMinimum(0.1); craw->SaveAs("RawElog.pdf"); craw->SaveAs("RawElog.png"); //plot distribution of regressed functions over testing dataset TCanvas *cmean = new TCanvas; RooPlot *plotmean = meanvar->frame(0.8,2.0,100); hdataclone->plotOn(plotmean); plotmean->Draw(); cmean->SaveAs("mean.pdf"); cmean->SaveAs("mean.png"); TCanvas *cwidth = new TCanvas; RooPlot *plotwidth = widthvar->frame(0.,0.05,100); hdataclone->plotOn(plotwidth); plotwidth->Draw(); cwidth->SaveAs("width.pdf"); cwidth->SaveAs("width.png"); TCanvas *cn = new TCanvas; RooPlot *plotn = nvar->frame(0.,111.,200); hdataclone->plotOn(plotn); plotn->Draw(); cn->SaveAs("n.pdf"); cn->SaveAs("n.png"); TCanvas *cn2 = new TCanvas; RooPlot *plotn2 = n2var->frame(0.,111.,100); hdataclone->plotOn(plotn2); plotn2->Draw(); cn2->SaveAs("n2.pdf"); cn2->SaveAs("n2.png"); TCanvas *calpha = new TCanvas; RooPlot *plotalpha = alphavar->frame(0.,5.,200); hdataclone->plotOn(plotalpha); plotalpha->Draw(); calpha->SaveAs("alpha.pdf"); calpha->SaveAs("alpha.png"); TCanvas *calpha2 = new TCanvas; RooPlot *plotalpha2 = alpha2var->frame(0.,5.,200); hdataclone->plotOn(plotalpha2); plotalpha2->Draw(); calpha2->SaveAs("alpha2.pdf"); calpha2->SaveAs("alpha2.png"); TCanvas *ceta = new TCanvas; RooPlot *ploteta = scetavar->frame(-2.6,2.6,200); hdataclone->plotOn(ploteta); ploteta->Draw(); ceta->SaveAs("eta.pdf"); ceta->SaveAs("eta.png"); //create histograms for eraw/etrue and ecor/etrue to quantify regression performance TH1 *heraw;// = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.)); TH1 *hecor;// = hdata->createHistogram("hecor",*ecorvar); if (EEorEB == "EB") { heraw = hdata->createHistogram("hraw",*rawvar,Binning(800,0.8,1.1)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(800,0.8,1.1)); } else { heraw = hdata->createHistogram("hraw",*rawvar,Binning(200,0.,2.)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(200,0.,2.)); } //heold->SetLineColor(kRed); hecor->SetLineColor(kBlue); heraw->SetLineColor(kMagenta); hecor->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); heraw->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); hecor->GetXaxis()->SetRangeUser(0.0,1.5); heraw->GetXaxis()->SetRangeUser(0.0,1.5); /*if(EEorEB == "EE") { heraw->GetYaxis()->SetRangeUser(10.0,200.0); hecor->GetYaxis()->SetRangeUser(10.0,200.0); } */ //heold->GetXaxis()->SetRangeUser(0.6,1.2); double effsigma_cor, effsigma_raw, fwhm_cor, fwhm_raw; if(EEorEB == "EB") { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(200,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(200,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } else { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(200,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(200,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } TCanvas *cresponse = new TCanvas; gStyle->SetOptStat(0); gStyle->SetPalette(107); hecor->SetTitle(""); heraw->SetTitle(""); hecor->Draw("HIST"); //heold->Draw("HISTSAME"); heraw->Draw("HISTSAME"); //show errSigma in the plot TLegend *leg = new TLegend(0.1, 0.75, 0.7, 0.9); leg->AddEntry(hecor,Form("E_{cor}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_cor, fwhm_cor),"l"); leg->AddEntry(heraw,Form("E_{raw}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_raw, fwhm_raw),"l"); leg->SetFillStyle(0); leg->SetBorderSize(0); // leg->SetTextColor(kRed); leg->Draw(); cresponse->SaveAs("response.pdf"); cresponse->SaveAs("response.png"); cresponse->SetLogy(); cresponse->SaveAs("responselog.pdf"); cresponse->SaveAs("responselog.png"); // draw CCs vs eta and phi TCanvas *c_eta = new TCanvas; TH1 *h_eta = hdata->createHistogram("h_eta",*scetavar,Binning(100,-3.2,3.2)); h_eta->Draw("HIST"); c_eta->SaveAs("heta.pdf"); c_eta->SaveAs("heta.png"); TCanvas *c_phi = new TCanvas; TH1 *h_phi = hdata->createHistogram("h_phi",*scphivar,Binning(100,-3.2,3.2)); h_phi->Draw("HIST"); c_phi->SaveAs("hphi.pdf"); c_phi->SaveAs("hphi.png"); RooRealVar *scetaiXvar = ws->var("var_6"); RooRealVar *scphiiYvar = ws->var("var_7"); if(EEorEB=="EB") { scetaiXvar->setRange(-90,90); scetaiXvar->setBins(180); scphiiYvar->setRange(0,360); scphiiYvar->setBins(360); } else { scetaiXvar->setRange(0,50); scetaiXvar->setBins(50); scphiiYvar->setRange(0,50); scphiiYvar->setBins(50); } ecorvar->setRange(0.5,1.5); ecorvar->setBins(800); rawvar->setRange(0.5,1.5); rawvar->setBins(800); TCanvas *c_cor_eta = new TCanvas; TH2F *h_CC_eta = hdata->createHistogram(*scetaiXvar, *ecorvar, "","cor_vs_eta"); if(EEorEB=="EB") { h_CC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetXaxis()->SetTitle("iX"); } h_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_eta->Draw("COLZ"); c_cor_eta->SaveAs("cor_vs_eta.pdf"); c_cor_eta->SaveAs("cor_vs_eta.png"); TCanvas *c_cor_phi = new TCanvas; TH2F *h_CC_phi = hdata->createHistogram(*scphiiYvar, *ecorvar, "","cor_vs_phi"); if(EEorEB=="EB") { h_CC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetXaxis()->SetTitle("iY"); } h_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_phi->Draw("COLZ"); c_cor_phi->SaveAs("cor_vs_phi.pdf"); c_cor_phi->SaveAs("cor_vs_phi.png"); TCanvas *c_raw_eta = new TCanvas; TH2F *h_RC_eta = hdata->createHistogram(*scetaiXvar, *rawvar, "","raw_vs_eta"); if(EEorEB=="EB") { h_RC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_RC_eta->GetXaxis()->SetTitle("iX"); } h_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_eta->Draw("COLZ"); c_raw_eta->SaveAs("raw_vs_eta.pdf"); c_raw_eta->SaveAs("raw_vs_eta.png"); TCanvas *c_raw_phi = new TCanvas; TH2F *h_RC_phi = hdata->createHistogram(*scphiiYvar, *rawvar, "","raw_vs_phi"); if(EEorEB=="EB") { h_RC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_RC_phi->GetXaxis()->SetTitle("iY"); } h_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_phi->Draw("COLZ"); c_raw_phi->SaveAs("raw_vs_phi.pdf"); c_raw_phi->SaveAs("raw_vs_phi.png"); //on2,5,20, etc if(EEorEB == "EB") { TCanvas *myC_iCrystal_mod = new TCanvas; RooRealVar *iEtaOn5var = ws->var("var_8"); iEtaOn5var->setRange(0,5); iEtaOn5var->setBins(5); TH2F *h_CC_iEtaOn5 = hdata->createHistogram(*iEtaOn5var, *ecorvar, "","cor_vs_iEtaOn5"); h_CC_iEtaOn5->GetXaxis()->SetTitle("iEtaOn5"); h_CC_iEtaOn5->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iEtaOn5->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn5.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn5.png"); TH2F *h_RC_iEtaOn5 = hdata->createHistogram(*iEtaOn5var, *rawvar, "","raw_vs_iEtaOn5"); h_RC_iEtaOn5->GetXaxis()->SetTitle("iEtaOn5"); h_RC_iEtaOn5->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iEtaOn5->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn5.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn5.png"); RooRealVar *iPhiOn2var = ws->var("var_9"); iPhiOn2var->setRange(0,2); iPhiOn2var->setBins(2); TH2F *h_CC_iPhiOn2 = hdata->createHistogram(*iPhiOn2var, *ecorvar, "","cor_vs_iPhiOn2"); h_CC_iPhiOn2->GetXaxis()->SetTitle("iPhiOn2"); h_CC_iPhiOn2->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iPhiOn2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn2.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn2.png"); TH2F *h_RC_iPhiOn2 = hdata->createHistogram(*iPhiOn2var, *rawvar, "","raw_vs_iPhiOn2"); h_RC_iPhiOn2->GetXaxis()->SetTitle("iPhiOn2"); h_RC_iPhiOn2->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iPhiOn2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn2.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn2.png"); RooRealVar *iPhiOn20var = ws->var("var_10"); iPhiOn20var->setRange(0,20); iPhiOn20var->setBins(20); TH2F *h_CC_iPhiOn20 = hdata->createHistogram(*iPhiOn20var, *ecorvar, "","cor_vs_iPhiOn20"); h_CC_iPhiOn20->GetXaxis()->SetTitle("iPhiOn20"); h_CC_iPhiOn20->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iPhiOn20->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn20.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iPhiOn20.png"); TH2F *h_RC_iPhiOn20 = hdata->createHistogram(*iPhiOn20var, *rawvar, "","raw_vs_iPhiOn20"); h_RC_iPhiOn20->GetXaxis()->SetTitle("iPhiOn20"); h_RC_iPhiOn20->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iPhiOn20->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn20.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iPhiOn20.png"); RooRealVar *iEtaOn2520var = ws->var("var_11"); iEtaOn2520var->setRange(-25,25); iEtaOn2520var->setBins(50); TH2F *h_CC_iEtaOn2520 = hdata->createHistogram(*iEtaOn2520var, *ecorvar, "","cor_vs_iEtaOn2520"); h_CC_iEtaOn2520->GetXaxis()->SetTitle("iEtaOn2520"); h_CC_iEtaOn2520->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_iEtaOn2520->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn2520.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_iEtaOn2520.png"); TH2F *h_RC_iEtaOn2520 = hdata->createHistogram(*iEtaOn2520var, *rawvar, "","raw_vs_iEtaOn2520"); h_RC_iEtaOn2520->GetXaxis()->SetTitle("iEtaOn2520"); h_RC_iEtaOn2520->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_iEtaOn2520->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn2520.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_iEtaOn2520.png"); } // other variables TCanvas *myC_variables = new TCanvas; RooRealVar *Nxtalvar = ws->var("var_3"); Nxtalvar->setRange(0,10); Nxtalvar->setBins(10); TH2F *h_CC_Nxtal = hdata->createHistogram(*Nxtalvar, *ecorvar, "","cor_vs_Nxtal"); h_CC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_CC_Nxtal->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Nxtal.pdf"); myC_variables->SaveAs("cor_vs_Nxtal.png"); TH2F *h_RC_Nxtal = hdata->createHistogram(*Nxtalvar, *rawvar, "","raw_vs_Nxtal"); h_RC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_RC_Nxtal->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Nxtal.pdf"); myC_variables->SaveAs("raw_vs_Nxtal.png"); RooRealVar *S4S9var = ws->var("var_4"); int Nbins_S4S9 = 100; double Low_S4S9 = 0.6; double High_S4S9 = 1.0; S4S9var->setRange(Low_S4S9,High_S4S9); S4S9var->setBins(Nbins_S4S9); TH2F *h_CC_S4S9 = hdata->createHistogram(*S4S9var, *ecorvar, "","cor_vs_S4S9"); h_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h_CC_S4S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S4S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S4S9.pdf"); myC_variables->SaveAs("cor_vs_S4S9.png"); TH2F *h_RC_S4S9 = hdata->createHistogram(*S4S9var, *rawvar, "","raw_vs_S4S9"); h_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h_RC_S4S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S4S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S4S9.pdf"); myC_variables->SaveAs("raw_vs_S4S9.png"); /* RooRealVar *S1S9var = ws->var("var_5"); S1S9var->setRange(0.3,1.0); S1S9var->setBins(100); TH2F *h_CC_S1S9 = hdata->createHistogram(*S1S9var, *ecorvar, "","cor_vs_S1S9"); h_CC_S1S9->GetXaxis()->SetTitle("S1S9"); h_CC_S1S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S1S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S1S9.pdf"); TH2F *h_RC_S1S9 = hdata->createHistogram(*S1S9var, *rawvar, "","raw_vs_S1S9"); h_RC_S1S9->GetXaxis()->SetTitle("S1S9"); h_RC_S1S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S1S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S1S9.pdf"); */ RooRealVar *S2S9var = ws->var("var_5"); int Nbins_S2S9 = 100; double Low_S2S9 = 0.5; double High_S2S9 = 1.0; S2S9var->setRange(Low_S2S9,High_S2S9); S2S9var->setBins(Nbins_S2S9); TH2F *h_CC_S2S9 = hdata->createHistogram(*S2S9var, *ecorvar, "","cor_vs_S2S9"); h_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h_CC_S2S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S2S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S2S9.pdf"); myC_variables->SaveAs("cor_vs_S2S9.png"); TH2F *h_RC_S2S9 = hdata->createHistogram(*S2S9var, *rawvar, "","raw_vs_S2S9"); h_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h_RC_S2S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S2S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S2S9.pdf"); myC_variables->SaveAs("raw_vs_S2S9.png"); TH2F *h_S2S9_eta = hdata->createHistogram(*scetaiXvar, *S2S9var, "","S2S9_vs_eta"); h_S2S9_eta->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S2S9_eta->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_eta.pdf"); myC_variables->SaveAs("S2S9_vs_eta.png"); TH2F *h_S4S9_eta = hdata->createHistogram(*scetaiXvar, *S4S9var, "","S4S9_vs_eta"); h_S4S9_eta->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S4S9_eta->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_eta.pdf"); myC_variables->SaveAs("S4S9_vs_eta.png"); TH2F *h_S2S9_phi = hdata->createHistogram(*scphiiYvar, *S2S9var, "","S2S9_vs_phi"); h_S2S9_phi->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S2S9_phi->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_phi.pdf"); myC_variables->SaveAs("S2S9_vs_phi.png"); TH2F *h_S4S9_phi = hdata->createHistogram(*scphiiYvar, *S4S9var, "","S4S9_vs_phi"); h_S4S9_phi->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S4S9_phi->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_phi.pdf"); myC_variables->SaveAs("S4S9_vs_phi.png"); /* RooRealVar *DeltaRvar = ws->var("var_6"); DeltaRvar->setRange(0.0,0.1); DeltaRvar->setBins(100); TH2F *h_CC_DeltaR = hdata->createHistogram(*DeltaRvar, *ecorvar, "","cor_vs_DeltaR"); h_CC_DeltaR->GetXaxis()->SetTitle("#Delta R"); h_CC_DeltaR->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_DeltaR->Draw("COLZ"); myC_variables->SaveAs("cor_vs_DeltaR.pdf"); myC_variables->SaveAs("cor_vs_DeltaR.png"); TH2F *h_RC_DeltaR = hdata->createHistogram(*DeltaRvar, *rawvar, "","raw_vs_DeltaR"); h_RC_DeltaR->GetXaxis()->SetTitle("#Delta R"); h_RC_DeltaR->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_DeltaR->Draw("COLZ"); myC_variables->SaveAs("raw_vs_DeltaR.pdf"); myC_variables->SaveAs("raw_vs_DeltaR.png"); */ if(EEorEB=="EE") { /* RooRealVar *Es_e1var = ws->var("var_9"); Es_e1var->setRange(0.0,200.0); Es_e1var->setBins(1000); TH2F *h_CC_Es_e1 = hdata->createHistogram(*Es_e1var, *ecorvar, "","cor_vs_Es_e1"); h_CC_Es_e1->GetXaxis()->SetTitle("Es_e1"); h_CC_Es_e1->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Es_e1->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Es_e1.pdf"); myC_variables->SaveAs("cor_vs_Es_e1.png"); TH2F *h_RC_Es_e1 = hdata->createHistogram(*Es_e1var, *rawvar, "","raw_vs_Es_e1"); h_RC_Es_e1->GetXaxis()->SetTitle("Es_e1"); h_RC_Es_e1->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Es_e1->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Es_e1.pdf"); myC_variables->SaveAs("raw_vs_Es_e1.png"); RooRealVar *Es_e2var = ws->var("var_10"); Es_e2var->setRange(0.0,200.0); Es_e2var->setBins(1000); TH2F *h_CC_Es_e2 = hdata->createHistogram(*Es_e2var, *ecorvar, "","cor_vs_Es_e2"); h_CC_Es_e2->GetXaxis()->SetTitle("Es_e2"); h_CC_Es_e2->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Es_e2->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Es_e2.pdf"); myC_variables->SaveAs("cor_vs_Es_e2.png"); TH2F *h_RC_Es_e2 = hdata->createHistogram(*Es_e2var, *rawvar, "","raw_vs_Es_e2"); h_RC_Es_e2->GetXaxis()->SetTitle("Es_e2"); h_RC_Es_e2->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Es_e2->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Es_e2.pdf"); myC_variables->SaveAs("raw_vs_Es_e2.png"); */ } TProfile *p_CC_eta = h_CC_eta->ProfileX("p_CC_eta",1,-1,"s"); p_CC_eta->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB == "EB") { // p_CC_eta->GetYaxis()->SetRangeUser(0.85,1.0); // p_CC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_eta->SetTitle(""); p_CC_eta->Draw(); myC_variables->SaveAs("profile_cor_vs_eta.pdf"); myC_variables->SaveAs("profile_cor_vs_eta.png"); TProfile *p_RC_eta = h_RC_eta->ProfileX("p_RC_eta",1,-1,"s"); p_RC_eta->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB=="EB") { // p_RC_eta->GetYaxis()->SetRangeUser(0.80,0.95); // p_RC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_eta->SetTitle(""); p_RC_eta->Draw(); myC_variables->SaveAs("profile_raw_vs_eta.pdf"); myC_variables->SaveAs("profile_raw_vs_eta.png"); int Nbins_iEta = EEorEB=="EB" ? 180 : 50; int nLow_iEta = EEorEB=="EB" ? -90 : 0; int nHigh_iEta = EEorEB=="EB" ? 90 : 50; TH1F *h1_RC_eta = new TH1F("h1_RC_eta","h1_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_RC_eta->SetBinContent(i,p_RC_eta->GetBinError(i)); } h1_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_RC_eta->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_eta->SetTitle(""); h1_RC_eta->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.png"); TH1F *h1_CC_eta = new TH1F("h1_CC_eta","h1_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_CC_eta->SetBinContent(i,p_CC_eta->GetBinError(i)); } h1_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_CC_eta->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_eta->SetTitle(""); h1_CC_eta->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.png"); TProfile *p_CC_phi = h_CC_phi->ProfileX("p_CC_phi",1,-1,"s"); p_CC_phi->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB == "EB") { // p_CC_phi->GetYaxis()->SetRangeUser(0.94,1.00); } p_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_phi->SetTitle(""); p_CC_phi->Draw(); myC_variables->SaveAs("profile_cor_vs_phi.pdf"); myC_variables->SaveAs("profile_cor_vs_phi.png"); TProfile *p_RC_phi = h_RC_phi->ProfileX("p_RC_phi",1,-1,"s"); p_RC_phi->GetYaxis()->SetRangeUser(0.7,1.2); if(EEorEB=="EB") { // p_RC_phi->GetYaxis()->SetRangeUser(0.89,0.95); } p_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_phi->SetTitle(""); p_RC_phi->Draw(); myC_variables->SaveAs("profile_raw_vs_phi.pdf"); myC_variables->SaveAs("profile_raw_vs_phi.png"); int Nbins_iPhi = EEorEB=="EB" ? 360 : 50; int nLow_iPhi = EEorEB=="EB" ? 0 : 0; int nHigh_iPhi = EEorEB=="EB" ? 360 : 50; TH1F *h1_RC_phi = new TH1F("h1_RC_phi","h1_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_RC_phi->SetBinContent(i,p_RC_phi->GetBinError(i)); } h1_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_RC_phi->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_phi->SetTitle(""); h1_RC_phi->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.png"); TH1F *h1_CC_phi = new TH1F("h1_CC_phi","h1_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_CC_phi->SetBinContent(i,p_CC_phi->GetBinError(i)); } h1_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_CC_phi->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_phi->SetTitle(""); h1_CC_phi->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.png"); // FWHM over sigma_eff vs. eta/phi TH1F *h1_FoverS_RC_phi = new TH1F("h1_FoverS_RC_phi","h1_FoverS_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_CC_phi = new TH1F("h1_FoverS_CC_phi","h1_FoverS_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_RC_eta = new TH1F("h1_FoverS_RC_eta","h1_FoverS_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_eta = new TH1F("h1_FoverS_CC_eta","h1_FoverS_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_S2S9 = new TH1F("h1_FoverS_CC_S2S9","h1_FoverS_CC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_RC_S2S9 = new TH1F("h1_FoverS_RC_S2S9","h1_FoverS_RC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_CC_S4S9 = new TH1F("h1_FoverS_CC_S4S9","h1_FoverS_CC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); TH1F *h1_FoverS_RC_S4S9 = new TH1F("h1_FoverS_RC_S4S9","h1_FoverS_RC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); float FWHMoverSigmaEff = 0.0; TH1F *h_tmp_rawvar = new TH1F("tmp_rawvar","tmp_rawvar",800,0.5,1.5); TH1F *h_tmp_corvar = new TH1F("tmp_corvar","tmp_corvar",800,0.5,1.5); for(int i=1;i<=Nbins_iPhi;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_phi->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_phi->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_phi->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_phi->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_CC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_phi->SetTitle(""); h1_FoverS_CC_phi->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.png"); h1_FoverS_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_RC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_phi->SetTitle(""); h1_FoverS_RC_phi->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.png"); for(int i=1;i<=Nbins_iEta;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_eta->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_eta->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_eta->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_eta->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_CC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_eta->SetTitle(""); h1_FoverS_CC_eta->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.png"); h1_FoverS_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_RC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_eta->SetTitle(""); h1_FoverS_RC_eta->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.png"); for(int i=1;i<=Nbins_S2S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S2S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S2S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S2S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S2S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_CC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S2S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S2S9->SetTitle(""); h1_FoverS_CC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.png"); h1_FoverS_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_RC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S2S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S2S9->SetTitle(""); h1_FoverS_RC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.png"); for(int i=1;i<=Nbins_S4S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S4S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S4S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S4S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S4S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_CC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S4S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S4S9->SetTitle(""); h1_FoverS_CC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.png"); h1_FoverS_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_RC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S4S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S4S9->SetTitle(""); h1_FoverS_RC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.png"); printf("calc effsigma\n"); std::cout<<"_"<<EEorEB<<std::endl; printf("corrected curve effSigma= %5f, FWHM=%5f \n",effsigma_cor, fwhm_cor); printf("raw curve effSigma= %5f FWHM=%5f \n",effsigma_raw, fwhm_raw); /* new TCanvas; RooPlot *ploteold = testvar.frame(0.6,1.2,100); hdatasigtest->plotOn(ploteold); ploteold->Draw(); new TCanvas; RooPlot *plotecor = ecorvar->frame(0.6,1.2,100); hdatasig->plotOn(plotecor); plotecor->Draw(); */ }
void plotter::draw_output_data(TH1* output_, TH1* stat_, std::vector<TH1D*> truth_, std::vector<TString> legnames, bool norm, TString file_name){ TH1* output = (TH1*) output_->Clone("output"); TH1* stat = (TH1*) stat_->Clone("stat"); std::vector<TH1D*> truth; for(auto t: truth_){ truth.push_back( (TH1D*) t->Clone() ); } double max = output->GetMaximum(); for(auto t: truth){ if(t->GetMaximum() > max) max = t->GetMaximum(); } double ymax = 1.5 * max; TCanvas *c = new TCanvas("c","",600,600); gPad->SetLeftMargin(0.15); 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("#frac{d#sigma}{dm_{jet}} [#frac{fb}{GeV}]"); 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); Color_t color[] = {kRed-4, kAzure+7, kGreen, 798}; Int_t style[] = {1, 2, 9, 7}; for(unsigned int i=0; i<truth.size(); i++){ truth[i]->SetLineWidth(3); truth[i]->SetLineColor(color[i]); truth[i]->SetLineStyle(style[i]); truth[i]->Draw("HIST SAME"); } stat->Draw("E1 SAME"); output->Draw("E1 SAME"); TLegend *l=new TLegend(0.55,0.67,0.85,0.87); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(output,"data unfolded","pl"); for(unsigned int i=0; i<truth.size(); i++){ l->AddEntry(truth[i],legnames[i],"l"); } l->SetTextSize(0.03); l->Draw(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void plotEfficiencyCuts(TString outputFileName = "plotOutput.root") { // general root setting gROOT->Reset(); // gROOT->SetBatch(kTRUE); gStyle->SetOptStat(0); gStyle->SetTitleSize(0.1); gStyle->SetLabelSize(0.04,"X"); gStyle->SetLabelSize(0.04,"Y"); gStyle->SetPadBorderMode(0); gStyle->SetPadColor(0); gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(0); // ************************************************************ std::vector<TString> FileSuffix; FileSuffix.push_back("VBFH160ZZ"); FileSuffix.push_back("VBFH200ZZ"); FileSuffix.push_back("VBFH400ZZ"); FileSuffix.push_back("VBFH800ZZ"); FileSuffix.push_back("ZZ0Jets"); FileSuffix.push_back("ZZ1Jets"); FileSuffix.push_back("ZZ2Jets"); FileSuffix.push_back("Zbb0Jets"); FileSuffix.push_back("Zbb1Jets"); FileSuffix.push_back("Zbb2Jets"); // ************************************************************ // List of Files TList * FileList = new TList(); std::vector<TString>::const_iterator FileSuffix_itr = FileSuffix.begin(); for ( ; FileSuffix_itr != FileSuffix.end(); ++FileSuffix_itr ) { FileList->Add( TFile::Open(*FileSuffix_itr+"output.root" ) ); } // ************************************************************ // List of xSec (in pb) // stored in // "HiggsAnalysis/VBFHiggsToZZto2l2bs/interface/xSecLO.h" // "HiggsAnalysis/VBFHiggsToZZto2l2bs/interface/xSecNLO.h" // "HiggsAnalysis/VBFHiggsToZZto2l2bs/interface/BR.h" std::vector<double> crossSections; crossSections.push_back(1000*xSec_VBFH160_*BR_H160ZZ_); crossSections.push_back(1000*xSec_VBFH200_*BR_H200ZZ_); crossSections.push_back(1000*xSec_VBFH400_*BR_H400ZZ_); crossSections.push_back(1000*xSec_VBFH800_*BR_H800ZZ_); crossSections.push_back(1000*xSec_ZZ0Jets_*BR_Zll_); crossSections.push_back(1000*xSec_ZZ1Jets_*BR_Zll_); crossSections.push_back(1000*xSec_ZZ2Jets_*BR_Zll_); crossSections.push_back(1000*xSec_Zbb0Jets_*BR_Zll_); crossSections.push_back(1000*xSec_Zbb1Jets_*BR_Zll_); crossSections.push_back(1000*xSec_Zbb2Jets_*BR_Zll_); // ************************************************************ std::vector<TString> varNameVector; varNameVector.push_back("ZbeforeDeltaRcutNumber"); varNameVector.push_back("ZafterDeltaRcutNumber"); varNameVector.push_back("ZbeforeLeptonShiftedEtaCutNumber"); varNameVector.push_back("ZafterLeptonShiftedEtaCutNumber"); // ************************************************************ std::vector<TH1*> TH1vector; std::vector<TH1*> eventsNumberTH1vector; findObj( eventsNumberTH1vector, FileList, "eventsNumber", &FileSuffix ); std::vector<double>::const_iterator crossSections_itr = crossSections.begin(); std::vector<TH1*>::const_iterator eventsNumberTH1vector_itr = eventsNumberTH1vector.begin(); int index = 0; for ( ; eventsNumberTH1vector_itr != eventsNumberTH1vector.end(); ++eventsNumberTH1vector_itr, ++crossSections_itr, index++) { TH1 * histo = (TH1*)(*eventsNumberTH1vector_itr)->Clone(); crossSections[index] = *crossSections_itr/double(histo->GetMaximum()); } TFile * outputFile = TFile::Open( outputFileName, "RECREATE" ); std::vector<TString>::const_iterator varNameVector_itr = varNameVector.begin(); for ( ; varNameVector_itr != varNameVector.end(); ++varNameVector_itr ) { findObj( TH1vector, FileList, *varNameVector_itr, &FileSuffix, "TH1", &crossSections ); TH1D * efficiencyHZZ = new TH1D("efficiencyHZZ","efficiency",100,0.,1000.); efficiencyHZZ->SetBinContent(16,0.40); efficiencyHZZ->SetBinContent(20,0.44); efficiencyHZZ->SetBinContent(40,0.60); efficiencyHZZ->SetBinContent(80,0.80); efficiencyHZZ->SetBinError(16,0.03); efficiencyHZZ->SetBinError(20,0.03); efficiencyHZZ->SetBinError(40,0.04); efficiencyHZZ->SetBinError(80,0.04); efficiencyHZZ->GetXaxis()->SetTitle("m_{H} (GeV/c^{2})"); efficiencyHZZ->GetXaxis()->SetLabelSize(0.05); efficiencyHZZ->GetXaxis()->SetBinLabel(16,"160"); efficiencyHZZ->GetXaxis()->SetBinLabel(20,"200"); efficiencyHZZ->GetXaxis()->SetBinLabel(40,"400"); efficiencyHZZ->GetXaxis()->SetBinLabel(80,"800"); TLine * efficiencyZbb = new TLine(0.,0.7,1000.,0.7); TLine * efficiencyZZ = new TLine(0.,0.65,1000.,0.65); TLegend * legend = new TLegend(0.65,0.3,0.85,0.6); legend->AddEntry(efficiencyHZZ,"HZZ","lpe"); legend->AddEntry(efficiencyZbb,"Zbb+n jets","l"); legend->AddEntry(efficiencyZZ, "ZZ+n jets","l"); efficiencyHZZ->Draw(); efficiencyZbb->Draw("same"); efficiencyZZ->Draw("same"); legend->Draw(); // // HZZ efficiency histogram // THStackLegend<TH1> * StackLegend_ = new THStackLegend<TH1>( *varNameVector_itr ); // // outputFile->cd(); // TDirectory * directory = outputFile->mkdir( *varNameVector_itr, *varNameVector_itr ); // directory->cd(); // std::vector<TH1*>::const_iterator TH1vector_itr = TH1vector.begin(); // std::vector<TString>::const_iterator FileSuffix_itr = FileSuffix.begin(); // for ( ; TH1vector_itr != TH1vector.end(); ++TH1vector_itr, // ++FileSuffix_itr) { // TH1 * histo = (TH1*)(*TH1vector_itr)->Clone(); // FashionAttributedHisto<TH1D> * dressedHisto; // bool dressed = false; // if ( *FileSuffix_itr == "VBFH160ZZ" ) { dressedHisto = new H160<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "VBFH200ZZ" ) { dressedHisto = new H200<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "VBFH400ZZ" ) { dressedHisto = new H400<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "VBFH800ZZ" ) { dressedHisto = new H800<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "ZZ0Jets" ) { dressedHisto = new ZZ0jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "ZZ1Jets" ) { dressedHisto = new ZZ1jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "ZZ2Jets" ) { dressedHisto = new ZZ2jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "Zbb0Jets" ) { dressedHisto = new Zbb0jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "Zbb1Jets" ) { dressedHisto = new Zbb1jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "Zbb2Jets" ) { dressedHisto = new Zbb2jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "WZ0Jets" ) { dressedHisto = new WZ0jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "WZ1Jets" ) { dressedHisto = new WZ1jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "WZ2Jets" ) { dressedHisto = new WZ2jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "tt0Jets" ) { dressedHisto = new tt0jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "tt1Jets" ) { dressedHisto = new tt1jets<TH1D>((TH1D*)histo); dressed = true; } // else if ( *FileSuffix_itr == "tt2Jets" ) { dressedHisto = new tt2jets<TH1D>((TH1D*)histo); dressed = true; } // else dressedHisto = new FashionAttributedHisto<TH1D>((TH1D*)histo); // StackLegend_->Add(dressedHisto,*FileSuffix_itr,true,"l",false,dressed); // // dressedHisto->Write(); // } // StackLegend_->Write("nostack"); // StackLegend_->Draw("nostack"); // // StackLegend_->SavePrimitive(Stack+*varNameVector_itr+".C","nostack"); // // TH1vector.clear(); // } }
// input: - Input file (result from TMVA), // - normal/decorrelated/PCA // - use of TMVA plotting TStyle void variables( TString fin = "TMVA.root", TString dirName = "InputVariables_Id", TString title = "TMVA Input Variables", Bool_t isRegression = kFALSE, Bool_t useTMVAStyle = kTRUE ) { TString outfname = dirName; outfname.ToLower(); outfname.ReplaceAll( "input", "" ); // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // obtain shorter histogram title TString htitle = title; htitle.ReplaceAll("variables ","variable"); htitle.ReplaceAll("and target(s)",""); htitle.ReplaceAll("(training sample)",""); // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); TDirectory* dir = (TDirectory*)file->Get( dirName ); if (dir==0) { cout << "No information about " << title << " available in directory " << dirName << " of file " << fin << endl; return; } dir->cd(); // how many plots are in the directory? Int_t noPlots = TMVAGlob::GetNumberOfInputVariables( dir ) + TMVAGlob::GetNumberOfTargets( dir ); // define Canvas layout here! // default setting Int_t xPad; // no of plots in x Int_t yPad; // no of plots in y Int_t width; // size of canvas Int_t height; switch (noPlots) { case 1: xPad = 1; yPad = 1; width = 550; height = 0.90*width; break; case 2: xPad = 2; yPad = 1; width = 600; height = 0.50*width; break; case 3: xPad = 3; yPad = 1; width = 900; height = 0.4*width; break; case 4: xPad = 2; yPad = 2; width = 600; height = width; break; default: // xPad = 3; yPad = 2; width = 800; height = 0.55*width; break; xPad = 1; yPad = 1; width = 550; height = 0.90*width; break; } Int_t noPadPerCanv = xPad * yPad ; // counter variables Int_t countCanvas = 0; Int_t countPad = 0; // loop over all objects in directory TCanvas* canv = 0; TKey* key = 0; Bool_t createNewFig = kFALSE; TIter next(dir->GetListOfKeys()); while ((key = (TKey*)next())) { if (key->GetCycle() != 1) continue; if (!TString(key->GetName()).Contains("__Signal") && !(isRegression && TString(key->GetName()).Contains("__Regression"))) continue; // make sure, that we only look at histograms TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TH1")) continue; TH1 *sig = (TH1*)key->ReadObj(); TString hname(sig->GetName()); //normalize to 1 NormalizeHist(sig); // create new canvas if (countPad%noPadPerCanv==0) { ++countCanvas; canv = new TCanvas( Form("canvas%d", countCanvas), title, countCanvas*50+50, countCanvas*20, width, height ); canv->Divide(xPad,yPad); canv->SetFillColor(kWhite); canv->Draw(); } TPad* cPad = (TPad*)canv->cd(countPad++%noPadPerCanv+1); cPad->SetFillColor(kWhite); // find the corredponding backgrouns histo TString bgname = hname; bgname.ReplaceAll("__Signal","__Background"); TH1 *bgd = (TH1*)dir->Get(bgname); if (bgd == NULL) { cout << "ERROR!!! couldn't find background histo for" << hname << endl; exit; } //normalize to 1 NormalizeHist(bgd); // this is set but not stored during plot creation in MVA_Factory TMVAGlob::SetSignalAndBackgroundStyle( sig, (isRegression ? 0 : bgd) ); sig->SetTitle( TString( htitle ) + ": " + sig->GetTitle() ); TMVAGlob::SetFrameStyle( sig, 1.2 ); // normalise both signal and background // if (!isRegression) TMVAGlob::NormalizeHists( sig, bgd ); // else { // // change histogram title for target // TString nme = sig->GetName(); // if (nme.Contains( "_target" )) { // TString tit = sig->GetTitle(); // sig->SetTitle( tit.ReplaceAll("Input variable", "Regression target" ) ); // } // } sig->SetTitle( "" ); // finally plot and overlay Float_t sc = 1.1; if (countPad == 1) sc = 1.3; sig->SetMaximum( TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*sc ); sig->Draw( "hist" ); cPad->SetLeftMargin( 0.17 ); sig->GetYaxis()->SetTitleOffset( 1.50 ); if (!isRegression) { bgd->Draw("histsame"); TString ytit = TString("(1/N) ") + sig->GetYaxis()->GetTitle(); ytit = TString("Fraction of Events"); sig->GetYaxis()->SetTitle( ytit ); // histograms are normalised } if (countPad == 1) sig->GetXaxis()->SetTitle("Leading Lepton p_{T} [GeV/c]"); if (countPad == 2) sig->GetXaxis()->SetTitle("Trailing Lepton p_{T} [GeV/c]"); if (countPad == 3) sig->GetXaxis()->SetTitle("#Delta#phi(l,l)"); if (countPad == 4) sig->GetXaxis()->SetTitle("#Delta R(l,l)"); if (countPad == 5) sig->GetXaxis()->SetTitle("Dilepton Mass [GeV/c^{2}]"); if (countPad == 6) sig->GetXaxis()->SetTitle("Dilepton Flavor Final State"); if (countPad == 7) sig->GetXaxis()->SetTitle("M_{T} (Higgs) [GeV/c^{2}]"); if (countPad == 8) sig->GetXaxis()->SetTitle("#Delta#phi(Dilepton System, MET)"); if (countPad == 9) sig->GetXaxis()->SetTitle("#Delta#phi(Dilepton System, Jet)"); // Draw legend // if (countPad == 1 && !isRegression) { TLegend *legend= new TLegend( cPad->GetLeftMargin(), 1-cPad->GetTopMargin()-.15, cPad->GetLeftMargin()+.4, 1-cPad->GetTopMargin() ); if(countPad == 1 || countPad == 2 ||countPad == 3 ||countPad == 4 ||countPad == 5 ||countPad == 7 ) { legend= new TLegend( 0.50, 1-cPad->GetTopMargin()-.15, 0.90, 1-cPad->GetTopMargin() ); } legend->SetFillStyle(0); legend->AddEntry(sig,"Signal","F"); legend->AddEntry(bgd,"Background","F"); legend->SetBorderSize(0); legend->SetMargin( 0.3 ); legend->SetTextSize( 0.03 ); legend->Draw("same"); // } // redraw axes sig->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 = ""; if (isRegression) { uoflow = Form( "U/O-flow: %.1f%% / %.1f%%", sig->GetBinContent(0)*dxu*100, sig->GetBinContent(nbin+1)*dxo*100 ); } else { 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.98, 0.14, uoflow ); t->SetNDC(); t->SetTextSize( 0.040 ); t->SetTextAngle( 90 ); // t->AppendPad(); // save canvas to file if (countPad%noPadPerCanv==0) { TString fname = Form( "plots/%s_c%i", outfname.Data(), countCanvas ); TMVAGlob::plot_logo(); TMVAGlob::imgconv( canv, fname ); createNewFig = kFALSE; } else { createNewFig = kTRUE; } } if (createNewFig) { TString fname = Form( "plots/%s_c%i", outfname.Data(), countCanvas ); TMVAGlob::plot_logo(); TMVAGlob::imgconv( canv, fname ); createNewFig = kFALSE; } return; }
void eregtesting_13TeV_Eta(bool dobarrel=true, bool doele=false,int gammaID=0) { //output dir TString EEorEB = "EE"; if(dobarrel) { EEorEB = "EB"; } TString gammaDir = "bothGammas"; if(gammaID==1) { gammaDir = "gamma1"; } else if(gammaID==2) { gammaDir = "gamma2"; } TString dirname = TString::Format("ereg_test_plots_Eta/%s_%s",gammaDir.Data(),EEorEB.Data()); gSystem->mkdir(dirname,true); gSystem->cd(dirname); //read workspace from training TString fname; if (doele && dobarrel) fname = "wereg_ele_eb.root"; else if (doele && !dobarrel) fname = "wereg_ele_ee.root"; else if (!doele && dobarrel) fname = "wereg_ph_eb.root"; else if (!doele && !dobarrel) fname = "wereg_ph_ee.root"; TString infile = TString::Format("../../ereg_ws_Eta/%s/%s",gammaDir.Data(),fname.Data()); TFile *fws = TFile::Open(infile); RooWorkspace *ws = (RooWorkspace*)fws->Get("wereg"); //read variables from workspace RooGBRTargetFlex *meantgt = static_cast<RooGBRTargetFlex*>(ws->arg("sigmeant")); RooRealVar *tgtvar = ws->var("tgtvar"); RooArgList vars; vars.add(meantgt->FuncVars()); vars.add(*tgtvar); //read testing dataset from TTree RooRealVar weightvar("weightvar","",1.); TTree *dtree; if (doele) { //TFile *fdin = TFile::Open("root://eoscms.cern.ch//eos/cms/store/cmst3/user/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TFile *fdin = TFile::Open("/data/bendavid/regTreesAug1/hgg-2013Final8TeV_reg_s12-zllm50-v7n_noskim.root"); TDirectory *ddir = (TDirectory*)fdin->FindObjectAny("PhotonTreeWriterSingleInvert"); dtree = (TTree*)ddir->Get("hPhotonTreeSingle"); } else { //TFile *fdin = TFile::Open("/eos/cms/store/group/dpg_ecal/alca_ecalcalib/piZero2017/zhicaiz/Gun_MultiPion_FlatPt-1To15/Gun_FlatPt1to15_MultiPion_withPhotonPtFilter_pythia8/photons_0_half2.root"); //TFile *fdin = TFile::Open("/eos/cms/store/group/dpg_ecal/alca_ecalcalib/piZero2017/zhicaiz/Gun_MultiEta_FlatPt-1To15/Gun_FlatPt1to15_MultiEta_withPhotonPtFilter_pythia8/photons_22Aug2017_V3_half2.root"); TFile *fdin = TFile::Open("/eos/cms/store/group/dpg_ecal/alca_ecalcalib/piZero2017/zhicaiz/Gun_MultiEta_FlatPt-1To15/Gun_FlatPt1to15_MultiEtaToGG_withPhotonPtFilter_pythia8/photons_20171008_half2.root"); if(gammaID==0) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma"); } else if(gammaID==1) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma1"); } else if(gammaID==2) { dtree = (TTree*)fdin->Get("Tree_Optim_gamma2"); } } //selection cuts for testing //TCut selcut = "(STr2_enG1_true/cosh(STr2_Eta_1)>1.0) && (STr2_S4S9_1>0.75)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (STr2_enG_true/STr2_enG_rec)<3.0 && STr2_EOverEOther < 10.0 && STr2_EOverEOther > 0.1"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (STr2_mPi0_nocor>0.1)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.1) && (STr2_mPi0_nocor < 0.2)"; TCut selcut = ""; if(dobarrel) selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.2) && (STr2_mPi0_nocor < 1.0) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)<1.479 && (!STr2_fromPi0)"; //if(dobarrel) selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.1) && (STr2_mPi0_nocor < 0.2) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)<1.479"; else selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.2) && (STr2_mPi0_nocor < 1.0) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)>1.479 && (!STr2_fromPi0)"; //else selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_Nxtal > 6) && (STr2_mPi0_nocor>0.1) && (STr2_mPi0_nocor < 0.2) && (STr2_ptPi0_nocor > 2.0) && abs(STr2_Eta)>1.479"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (STr2_iEta_on2520==0 || STr2_iPhi_on20==0) "; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.75) && (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)>60)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03) && (abs(STr2_iEtaiX)<60)"; //TCut selcut = "(STr2_enG_rec/cosh(STr2_Eta)>1.0) && (STr2_S4S9 > 0.9) && (STr2_S2S9>0.85)&& (STr2_isMerging < 2) && (STr2_DeltaR < 0.03)"; /* TCut selcut; if (dobarrel) selcut = "ph.genpt>25. && ph.isbarrel && ph.ispromptgen"; else selcut = "ph.genpt>25. && !ph.isbarrel && ph.ispromptgen"; */ TCut selweight = "xsecweight(procidx)*puweight(numPU,procidx)"; TCut prescale10 = "(Entry$%10==0)"; TCut prescale10alt = "(Entry$%10==1)"; TCut prescale25 = "(Entry$%25==0)"; TCut prescale100 = "(Entry$%100==0)"; TCut prescale1000 = "(Entry$%1000==0)"; TCut evenevents = "(Entry$%2==0)"; TCut oddevents = "(Entry$%2==1)"; TCut prescale100alt = "(Entry$%100==1)"; TCut prescale1000alt = "(Entry$%1000==1)"; TCut prescale50alt = "(Entry$%50==1)"; TCut Events3_4 = "(Entry$%4==3)"; TCut Events1_4 = "(Entry$%4==1)"; TCut Events2_4 = "(Entry$%4==2)"; TCut Events0_4 = "(Entry$%4==0)"; TCut Events01_4 = "(Entry$%4<2)"; TCut Events23_4 = "(Entry$%4>1)"; TCut EventsTest = "(Entry$%2==1)"; //weightvar.SetTitle(EventsTest*selcut); weightvar.SetTitle(selcut); /* if (doele) weightvar.SetTitle(prescale100alt*selcut); else weightvar.SetTitle(selcut); */ //make testing dataset RooDataSet *hdata = RooTreeConvert::CreateDataSet("hdata",dtree,vars,weightvar); if (doele) weightvar.SetTitle(prescale1000alt*selcut); else weightvar.SetTitle(prescale10alt*selcut); //make reduced testing dataset for integration over conditional variables RooDataSet *hdatasmall = RooTreeConvert::CreateDataSet("hdatasmall",dtree,vars,weightvar); //retrieve full pdf from workspace RooAbsPdf *sigpdf = ws->pdf("sigpdf"); //input variable corresponding to sceta RooRealVar *scEraw = ws->var("var_0"); scEraw->setRange(1.,2.); scEraw->setBins(100); // RooRealVar *scetavar = ws->var("var_1"); // RooRealVar *scphivar = ws->var("var_2"); //regressed output functions RooAbsReal *sigmeanlim = ws->function("sigmeanlim"); RooAbsReal *sigwidthlim = ws->function("sigwidthlim"); RooAbsReal *signlim = ws->function("signlim"); RooAbsReal *sign2lim = ws->function("sign2lim"); // RooAbsReal *sigalphalim = ws->function("sigalphalim"); //RooAbsReal *sigalpha2lim = ws->function("sigalpha2lim"); //formula for corrected energy/true energy ( 1.0/(etrue/eraw) * regression mean) RooFormulaVar ecor("ecor","","1./(@0)*@1",RooArgList(*tgtvar,*sigmeanlim)); RooRealVar *ecorvar = (RooRealVar*)hdata->addColumn(ecor); ecorvar->setRange(0.,2.); ecorvar->setBins(800); //formula for raw energy/true energy (1.0/(etrue/eraw)) RooFormulaVar raw("raw","","1./@0",RooArgList(*tgtvar)); RooRealVar *rawvar = (RooRealVar*)hdata->addColumn(raw); rawvar->setRange(0.,2.); rawvar->setBins(800); //clone data and add regression outputs for plotting RooDataSet *hdataclone = new RooDataSet(*hdata,"hdataclone"); RooRealVar *meanvar = (RooRealVar*)hdataclone->addColumn(*sigmeanlim); RooRealVar *widthvar = (RooRealVar*)hdataclone->addColumn(*sigwidthlim); RooRealVar *nvar = (RooRealVar*)hdataclone->addColumn(*signlim); RooRealVar *n2var = (RooRealVar*)hdataclone->addColumn(*sign2lim); // RooRealVar *alphavar = (RooRealVar*)hdataclone->addColumn(*sigalphalim); // RooRealVar *alpha2var = (RooRealVar*)hdataclone->addColumn(*sigalpha2lim); //plot target variable and weighted regression prediction (using numerical integration over reduced testing dataset) TCanvas *craw = new TCanvas; //RooPlot *plot = tgtvar->frame(0.6,1.2,100); RooPlot *plot = tgtvar->frame(0.6,2.0,100); hdata->plotOn(plot); sigpdf->plotOn(plot,ProjWData(*hdatasmall)); plot->Draw(); craw->SaveAs("RawE.pdf"); craw->SaveAs("RawE.png"); craw->SetLogy(); plot->SetMinimum(0.1); craw->SaveAs("RawElog.pdf"); craw->SaveAs("RawElog.png"); //plot distribution of regressed functions over testing dataset TCanvas *cmean = new TCanvas; RooPlot *plotmean = meanvar->frame(0.8,2.0,100); hdataclone->plotOn(plotmean); plotmean->Draw(); cmean->SaveAs("mean.pdf"); cmean->SaveAs("mean.png"); TCanvas *cwidth = new TCanvas; RooPlot *plotwidth = widthvar->frame(0.,0.05,100); hdataclone->plotOn(plotwidth); plotwidth->Draw(); cwidth->SaveAs("width.pdf"); cwidth->SaveAs("width.png"); TCanvas *cn = new TCanvas; RooPlot *plotn = nvar->frame(0.,111.,200); hdataclone->plotOn(plotn); plotn->Draw(); cn->SaveAs("n.pdf"); cn->SaveAs("n.png"); TCanvas *cn2 = new TCanvas; RooPlot *plotn2 = n2var->frame(0.,111.,100); hdataclone->plotOn(plotn2); plotn2->Draw(); cn2->SaveAs("n2.pdf"); cn2->SaveAs("n2.png"); /* TCanvas *calpha = new TCanvas; RooPlot *plotalpha = alphavar->frame(0.,5.,200); hdataclone->plotOn(plotalpha); plotalpha->Draw(); calpha->SaveAs("alpha.pdf"); calpha->SaveAs("alpha.png"); TCanvas *calpha2 = new TCanvas; RooPlot *plotalpha2 = alpha2var->frame(0.,5.,200); hdataclone->plotOn(plotalpha2); plotalpha2->Draw(); calpha2->SaveAs("alpha2.pdf"); calpha2->SaveAs("alpha2.png"); */ /* TCanvas *ceta = new TCanvas; RooPlot *ploteta = scetavar->frame(-2.6,2.6,200); hdataclone->plotOn(ploteta); ploteta->Draw(); ceta->SaveAs("eta.pdf"); ceta->SaveAs("eta.png"); */ //create histograms for eraw/etrue and ecor/etrue to quantify regression performance TH1 *heraw;// = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.)); TH1 *hecor;// = hdata->createHistogram("hecor",*ecorvar); if (EEorEB == "EB") { heraw = hdata->createHistogram("hraw",*rawvar,Binning(800,0.,2.0)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(800,0.,2.0)); } else { heraw = hdata->createHistogram("hraw",*rawvar,Binning(200,0.,2.)); hecor = hdata->createHistogram("hecor",*ecorvar, Binning(200,0.,2.)); } //heold->SetLineColor(kRed); hecor->SetLineColor(kBlue); heraw->SetLineColor(kMagenta); hecor->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); heraw->GetYaxis()->SetRangeUser(1.0,1.3*hecor->GetMaximum()); hecor->GetXaxis()->SetRangeUser(0.0,1.5); heraw->GetXaxis()->SetRangeUser(0.0,1.5); /*if(EEorEB == "EE") { heraw->GetYaxis()->SetRangeUser(10.0,200.0); hecor->GetYaxis()->SetRangeUser(10.0,200.0); } */ //heold->GetXaxis()->SetRangeUser(0.6,1.2); double effsigma_cor, effsigma_raw, fwhm_cor, fwhm_raw; if(EEorEB == "EB") { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(800,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(800,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } else { TH1 *hecorfine = hdata->createHistogram("hecorfine",*ecorvar,Binning(200,0.,2.)); effsigma_cor = effSigma(hecorfine); fwhm_cor = FWHM(hecorfine); TH1 *herawfine = hdata->createHistogram("herawfine",*rawvar,Binning(200,0.,2.)); effsigma_raw = effSigma(herawfine); fwhm_raw = FWHM(herawfine); } TCanvas *cresponse = new TCanvas; gStyle->SetOptStat(0); gStyle->SetPalette(107); hecor->SetTitle(""); heraw->SetTitle(""); hecor->Draw("HIST"); //heold->Draw("HISTSAME"); heraw->Draw("HISTSAME"); //show errSigma in the plot TLegend *leg = new TLegend(0.1, 0.75, 0.7, 0.9); leg->AddEntry(hecor,Form("E_{cor}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_cor, fwhm_cor),"l"); leg->AddEntry(heraw,Form("E_{raw}/E_{true}, #sigma_{eff}=%4.3f, FWHM=%4.3f", effsigma_raw, fwhm_raw),"l"); leg->SetFillStyle(0); leg->SetBorderSize(0); // leg->SetTextColor(kRed); leg->Draw(); cresponse->SaveAs("response.pdf"); cresponse->SaveAs("response.png"); cresponse->SetLogy(); cresponse->SaveAs("responselog.pdf"); cresponse->SaveAs("responselog.png"); // draw CCs vs eta and phi /* TCanvas *c_eta = new TCanvas; TH1 *h_eta = hdata->createHistogram("h_eta",*scetavar,Binning(100,-3.2,3.2)); h_eta->Draw("HIST"); c_eta->SaveAs("heta.pdf"); c_eta->SaveAs("heta.png"); TCanvas *c_phi = new TCanvas; TH1 *h_phi = hdata->createHistogram("h_phi",*scphivar,Binning(100,-3.2,3.2)); h_phi->Draw("HIST"); c_phi->SaveAs("hphi.pdf"); c_phi->SaveAs("hphi.png"); */ RooRealVar *scetaiXvar = ws->var("var_4"); RooRealVar *scphiiYvar = ws->var("var_5"); if(EEorEB=="EB") { scetaiXvar->setRange(-90,90); scetaiXvar->setBins(180); scphiiYvar->setRange(0,360); scphiiYvar->setBins(360); } else { scetaiXvar->setRange(0,50); scetaiXvar->setBins(50); scphiiYvar->setRange(0,50); scphiiYvar->setBins(50); } ecorvar->setRange(0.5,1.5); ecorvar->setBins(800); rawvar->setRange(0.5,1.5); rawvar->setBins(800); TCanvas *c_cor_eta = new TCanvas; TH3F *h3_CC_eta_phi = (TH3F*) hdata->createHistogram("var_5,var_4,ecor",(EEorEB=="EB") ? 170 : 100, (EEorEB=="EB") ? 360 : 100,25); TProfile2D *h_CC_eta_phi = h3_CC_eta_phi->Project3DProfile(); h_CC_eta_phi->SetTitle("E_{cor}/E_{true}"); if(EEorEB=="EB") { h_CC_eta_phi->GetXaxis()->SetTitle("i#eta"); h_CC_eta_phi->GetYaxis()->SetTitle("i#phi"); h_CC_eta_phi->GetXaxis()->SetRangeUser(-85,85); h_CC_eta_phi->GetYaxis()->SetRangeUser(0,360); } else { h_CC_eta_phi->GetXaxis()->SetTitle("iX"); h_CC_eta_phi->GetYaxis()->SetTitle("iY"); } h_CC_eta_phi->SetMinimum(0.5); h_CC_eta_phi->SetMaximum(1.5); h_CC_eta_phi->Draw("COLZ"); c_cor_eta->SaveAs("cor_vs_eta_phi.pdf"); c_cor_eta->SaveAs("cor_vs_eta_phi.png"); TH2F *h_CC_eta = hdata->createHistogram(*scetaiXvar, *ecorvar, "","cor_vs_eta"); if(EEorEB=="EB") { h_CC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetXaxis()->SetTitle("iX"); } h_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_eta->Draw("COLZ"); c_cor_eta->SaveAs("cor_vs_eta.pdf"); c_cor_eta->SaveAs("cor_vs_eta.png"); TCanvas *c_cor_scEraw = new TCanvas; TH2F *h_CC_scEraw = hdata->createHistogram(*scEraw, *ecorvar, "","cor_vs_scEraw"); h_CC_scEraw->GetXaxis()->SetTitle("E_{raw}"); h_CC_scEraw->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_scEraw->Draw("COLZ"); c_cor_scEraw->SaveAs("cor_vs_scEraw.pdf"); c_cor_scEraw->SaveAs("cor_vs_scEraw.png"); TCanvas *c_raw_scEraw = new TCanvas; TH2F *h_RC_scEraw = hdata->createHistogram(*scEraw, *rawvar, "","raw_vs_scEraw"); h_RC_scEraw->GetXaxis()->SetTitle("E_{raw}"); h_RC_scEraw->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_scEraw->Draw("COLZ"); c_raw_scEraw->SaveAs("raw_vs_scEraw.pdf"); c_raw_scEraw->SaveAs("raw_vs_scEraw.png"); TCanvas *c_cor_phi = new TCanvas; TH2F *h_CC_phi = hdata->createHistogram(*scphiiYvar, *ecorvar, "","cor_vs_phi"); if(EEorEB=="EB") { h_CC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetXaxis()->SetTitle("iY"); } h_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_phi->Draw("COLZ"); c_cor_phi->SaveAs("cor_vs_phi.pdf"); c_cor_phi->SaveAs("cor_vs_phi.png"); TCanvas *c_raw_eta = new TCanvas; TH3F *h3_RC_eta_phi = (TH3F*) hdata->createHistogram("var_5,var_4,raw",(EEorEB=="EB") ? 170 : 100, (EEorEB=="EB") ? 360 : 100,25); TProfile2D *h_RC_eta_phi = h3_RC_eta_phi->Project3DProfile(); h_RC_eta_phi->SetTitle("E_{raw}/E_{true}"); if(EEorEB=="EB") { h_RC_eta_phi->GetXaxis()->SetTitle("i#eta"); h_RC_eta_phi->GetYaxis()->SetTitle("i#phi"); h_RC_eta_phi->GetXaxis()->SetRangeUser(-85,85); h_RC_eta_phi->GetYaxis()->SetRangeUser(0,360); } else { h_RC_eta_phi->GetXaxis()->SetTitle("iX"); h_RC_eta_phi->GetYaxis()->SetTitle("iY"); } h_RC_eta_phi->SetMinimum(0.5); h_RC_eta_phi->SetMaximum(1.5); h_RC_eta_phi->Draw("COLZ"); c_raw_eta->SaveAs("raw_vs_eta_phi.pdf"); c_raw_eta->SaveAs("raw_vs_eta_phi.png"); TH2F *h_RC_eta = hdata->createHistogram(*scetaiXvar, *rawvar, "","raw_vs_eta"); if(EEorEB=="EB") { h_RC_eta->GetXaxis()->SetTitle("i#eta"); } else { h_RC_eta->GetXaxis()->SetTitle("iX"); } h_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_eta->Draw("COLZ"); c_raw_eta->SaveAs("raw_vs_eta.pdf"); c_raw_eta->SaveAs("raw_vs_eta.png"); TCanvas *c_raw_phi = new TCanvas; TH2F *h_RC_phi = hdata->createHistogram(*scphiiYvar, *rawvar, "","raw_vs_phi"); if(EEorEB=="EB") { h_RC_phi->GetXaxis()->SetTitle("i#phi"); } else { h_RC_phi->GetXaxis()->SetTitle("iY"); } h_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_phi->Draw("COLZ"); c_raw_phi->SaveAs("raw_vs_phi.pdf"); c_raw_phi->SaveAs("raw_vs_phi.png"); //on2,5,20, etc if(EEorEB == "EB") { TCanvas *myC_iCrystal_mod = new TCanvas; RooRealVar *SM_distvar = ws->var("var_6"); SM_distvar->setRange(0,10); SM_distvar->setBins(10); TH2F *h_CC_SM_dist = hdata->createHistogram(*SM_distvar, *ecorvar, "","cor_vs_SM_dist"); h_CC_SM_dist->GetXaxis()->SetTitle("SM_dist"); h_CC_SM_dist->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_SM_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_SM_dist.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_SM_dist.png"); TH2F *h_RC_SM_dist = hdata->createHistogram(*SM_distvar, *rawvar, "","raw_vs_SM_dist"); h_RC_SM_dist->GetXaxis()->SetTitle("distance to SM gap"); h_RC_SM_dist->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_SM_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_SM_dist.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_SM_dist.png"); RooRealVar *M_distvar = ws->var("var_7"); M_distvar->setRange(0,13); M_distvar->setBins(10); TH2F *h_CC_M_dist = hdata->createHistogram(*M_distvar, *ecorvar, "","cor_vs_M_dist"); h_CC_M_dist->GetXaxis()->SetTitle("M_dist"); h_CC_M_dist->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_M_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_M_dist.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_M_dist.png"); TH2F *h_RC_M_dist = hdata->createHistogram(*M_distvar, *rawvar, "","raw_vs_M_dist"); h_RC_M_dist->GetXaxis()->SetTitle("distance to module gap"); h_RC_M_dist->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_M_dist->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_M_dist.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_M_dist.png"); /* RooRealVar *DeltaRG1G2var = ws->var("var_8"); DeltaRG1G2var->setRange(0,0.2); DeltaRG1G2var->setBins(100); TH2F *h_CC_DeltaRG1G2 = hdata->createHistogram(*DeltaRG1G2var, *ecorvar, "","cor_vs_DeltaRG1G2"); h_CC_DeltaRG1G2->GetXaxis()->SetTitle("DeltaRG1G2"); h_CC_DeltaRG1G2->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_DeltaRG1G2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("cor_vs_DeltaRG1G2.pdf"); myC_iCrystal_mod->SaveAs("cor_vs_DeltaRG1G2.png"); TH2F *h_RC_DeltaRG1G2 = hdata->createHistogram(*DeltaRG1G2var, *rawvar, "","raw_vs_DeltaRG1G2"); h_RC_DeltaRG1G2->GetXaxis()->SetTitle("distance to module gap"); h_RC_DeltaRG1G2->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_DeltaRG1G2->Draw("COLZ"); myC_iCrystal_mod->SaveAs("raw_vs_DeltaRG1G2.pdf"); myC_iCrystal_mod->SaveAs("raw_vs_DeltaRG1G2.png"); */ } // other variables TCanvas *myC_variables = new TCanvas; RooRealVar *Nxtalvar = ws->var("var_1"); Nxtalvar->setRange(0,10); Nxtalvar->setBins(10); TH2F *h_CC_Nxtal = hdata->createHistogram(*Nxtalvar, *ecorvar, "","cor_vs_Nxtal"); h_CC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_CC_Nxtal->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("cor_vs_Nxtal.pdf"); myC_variables->SaveAs("cor_vs_Nxtal.png"); TH2F *h_RC_Nxtal = hdata->createHistogram(*Nxtalvar, *rawvar, "","raw_vs_Nxtal"); h_RC_Nxtal->GetXaxis()->SetTitle("Nxtal"); h_RC_Nxtal->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_Nxtal->Draw("COLZ"); myC_variables->SaveAs("raw_vs_Nxtal.pdf"); myC_variables->SaveAs("raw_vs_Nxtal.png"); RooRealVar *S4S9var = ws->var("var_2"); int Nbins_S4S9 = 100; double Low_S4S9 = 0.6; double High_S4S9 = 1.0; S4S9var->setRange(Low_S4S9,High_S4S9); S4S9var->setBins(Nbins_S4S9); TH2F *h_CC_S4S9 = hdata->createHistogram(*S4S9var, *ecorvar, "","cor_vs_S4S9"); h_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h_CC_S4S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S4S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S4S9.pdf"); myC_variables->SaveAs("cor_vs_S4S9.png"); TH2F *h_RC_S4S9 = hdata->createHistogram(*S4S9var, *rawvar, "","raw_vs_S4S9"); h_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h_RC_S4S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S4S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S4S9.pdf"); myC_variables->SaveAs("raw_vs_S4S9.png"); RooRealVar *S2S9var = ws->var("var_3"); int Nbins_S2S9 = 100; double Low_S2S9 = 0.5; double High_S2S9 = 1.0; S2S9var->setRange(Low_S2S9,High_S2S9); S2S9var->setBins(Nbins_S2S9); TH2F *h_CC_S2S9 = hdata->createHistogram(*S2S9var, *ecorvar, "","cor_vs_S2S9"); h_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h_CC_S2S9->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h_CC_S2S9->Draw("COLZ"); myC_variables->SaveAs("cor_vs_S2S9.pdf"); myC_variables->SaveAs("cor_vs_S2S9.png"); TH2F *h_RC_S2S9 = hdata->createHistogram(*S2S9var, *rawvar, "","raw_vs_S2S9"); h_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h_RC_S2S9->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h_RC_S2S9->Draw("COLZ"); myC_variables->SaveAs("raw_vs_S2S9.pdf"); myC_variables->SaveAs("raw_vs_S2S9.png"); TH2F *h_S2S9_eta = hdata->createHistogram(*scetaiXvar, *S2S9var, "","S2S9_vs_eta"); h_S2S9_eta->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S2S9_eta->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_eta.pdf"); myC_variables->SaveAs("S2S9_vs_eta.png"); TH2F *h_S4S9_eta = hdata->createHistogram(*scetaiXvar, *S4S9var, "","S4S9_vs_eta"); h_S4S9_eta->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_eta->GetYaxis()->SetTitle("i#eta"); } else { h_CC_eta->GetYaxis()->SetTitle("iX"); } h_S4S9_eta->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_eta.pdf"); myC_variables->SaveAs("S4S9_vs_eta.png"); TH2F *h_S2S9_phi = hdata->createHistogram(*scphiiYvar, *S2S9var, "","S2S9_vs_phi"); h_S2S9_phi->GetYaxis()->SetTitle("S2S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S2S9_phi->Draw("COLZ"); myC_variables->SaveAs("S2S9_vs_phi.pdf"); myC_variables->SaveAs("S2S9_vs_phi.png"); TH2F *h_S4S9_phi = hdata->createHistogram(*scphiiYvar, *S4S9var, "","S4S9_vs_phi"); h_S4S9_phi->GetYaxis()->SetTitle("S4S9"); if(EEorEB=="EB") { h_CC_phi->GetYaxis()->SetTitle("i#phi"); } else { h_CC_phi->GetYaxis()->SetTitle("iY"); } h_S4S9_phi->Draw("COLZ"); myC_variables->SaveAs("S4S9_vs_phi.pdf"); myC_variables->SaveAs("S4S9_vs_phi.png"); if(EEorEB=="EE") { } TProfile *p_CC_eta = h_CC_eta->ProfileX("p_CC_eta");//,1,-1,"s"); p_CC_eta->GetYaxis()->SetRangeUser(0.8,1.05); if(EEorEB == "EB") { // p_CC_eta->GetYaxis()->SetRangeUser(0.85,1.0); // p_CC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_eta->SetTitle(""); p_CC_eta->Draw(); myC_variables->SaveAs("profile_cor_vs_eta.pdf"); myC_variables->SaveAs("profile_cor_vs_eta.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_CC_eta = new TH1F("h1_fit_CC_eta","h1_fit_CC_eta",(EEorEB=="EB") ? 180 : 50,(EEorEB=="EB") ? -90 : 0, (EEorEB=="EB") ? 90 : 50); for(int ix = 1;ix <= h_CC_eta->GetNbinsX(); ix++) { stringstream os_iEta; os_iEta << ((EEorEB=="EB") ? (-90 + ix -1) : (0 + ix -1)); string ss_iEta = os_iEta.str(); TH1D * h_temp = h_CC_eta->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.95,1.07); h_temp->Fit("f_temp","R"); h1_fit_CC_eta->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_CC_eta->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{cor}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/CC_iEta_"+ss_iEta+".pdf").c_str()); myC_variables->SaveAs(("fits/CC_iEta_"+ss_iEta+".png").c_str()); myC_variables->SaveAs(("fits/CC_iEta_"+ss_iEta+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_CC_eta->GetYaxis()->SetRangeUser(0.95,1.05); h1_fit_CC_eta->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h1_fit_CC_eta->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#eta" : "iX"); h1_fit_CC_eta->SetTitle(""); h1_fit_CC_eta->Draw(); myC_variables->SaveAs("profile_fit_cor_vs_eta.pdf"); myC_variables->SaveAs("profile_fit_cor_vs_eta.png"); myC_variables->SaveAs("profile_fit_cor_vs_eta.C"); TProfile *p_RC_eta = h_RC_eta->ProfileX("p_RC_eta");//,1,-1,"s"); p_RC_eta->GetYaxis()->SetRangeUser(0.8,1.05); if(EEorEB=="EB") { // p_RC_eta->GetYaxis()->SetRangeUser(0.80,0.95); // p_RC_eta->GetXaxis()->SetRangeUser(-1.5,1.5); } p_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_eta->SetTitle(""); p_RC_eta->Draw(); myC_variables->SaveAs("profile_raw_vs_eta.pdf"); myC_variables->SaveAs("profile_raw_vs_eta.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_RC_eta = new TH1F("h1_fit_RC_eta","h1_fit_RC_eta",(EEorEB=="EB") ? 180 : 50,(EEorEB=="EB") ? -90 : 0, (EEorEB=="EB") ? 90 : 50); for(int ix = 1;ix <= h_RC_eta->GetNbinsX(); ix++) { stringstream os_iEta; os_iEta << ((EEorEB=="EB") ? (-90 + ix -1) : (0 + ix -1)); string ss_iEta = os_iEta.str(); TH1D * h_temp = h_RC_eta->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.87,1.05); h_temp->Fit("f_temp","R"); h1_fit_RC_eta->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_RC_eta->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{raw}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/RC_iEta_"+ss_iEta+".pdf").c_str()); myC_variables->SaveAs(("fits/RC_iEta_"+ss_iEta+".png").c_str()); myC_variables->SaveAs(("fits/RC_iEta_"+ss_iEta+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_RC_eta->GetYaxis()->SetRangeUser(0.9,1.0); h1_fit_RC_eta->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h1_fit_RC_eta->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#eta" : "iX"); h1_fit_RC_eta->SetTitle(""); h1_fit_RC_eta->Draw(); myC_variables->SaveAs("profile_fit_raw_vs_eta.pdf"); myC_variables->SaveAs("profile_fit_raw_vs_eta.png"); myC_variables->SaveAs("profile_fit_raw_vs_eta.C"); int Nbins_iEta = EEorEB=="EB" ? 180 : 50; int nLow_iEta = EEorEB=="EB" ? -90 : 0; int nHigh_iEta = EEorEB=="EB" ? 90 : 50; TH1F *h1_RC_eta = new TH1F("h1_RC_eta","h1_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_RC_eta->SetBinContent(i,p_RC_eta->GetBinError(i)); } h1_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_RC_eta->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_eta->SetTitle(""); h1_RC_eta->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_eta.png"); TH1F *h1_CC_eta = new TH1F("h1_CC_eta","h1_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); for(int i=1;i<=Nbins_iEta;i++) { h1_CC_eta->SetBinContent(i,p_CC_eta->GetBinError(i)); } h1_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_CC_eta->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_eta->SetTitle(""); h1_CC_eta->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_eta.png"); TProfile *p_CC_phi = h_CC_phi->ProfileX("p_CC_phi");//,1,-1,"s"); p_CC_phi->GetYaxis()->SetRangeUser(0.9,1.0); if(EEorEB == "EB") { // p_CC_phi->GetYaxis()->SetRangeUser(0.94,1.00); } p_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); p_CC_phi->SetTitle(""); p_CC_phi->Draw(); myC_variables->SaveAs("profile_cor_vs_phi.pdf"); myC_variables->SaveAs("profile_cor_vs_phi.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_CC_phi = new TH1F("h1_fit_CC_phi","h1_fit_CC_phi",(EEorEB=="EB") ? 360 : 50,(EEorEB=="EB") ? 0 : 0, (EEorEB=="EB") ? 360 : 50); for(int ix = 1;ix <= h_CC_phi->GetNbinsX(); ix++) { stringstream os_iPhi; os_iPhi << ((EEorEB=="EB") ? (0 + ix -1) : (0 + ix -1)); string ss_iPhi = os_iPhi.str(); TH1D * h_temp = h_CC_phi->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.95,1.07); h_temp->Fit("f_temp","R"); h1_fit_CC_phi->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_CC_phi->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{cor}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/CC_iPhi_"+ss_iPhi+".pdf").c_str()); myC_variables->SaveAs(("fits/CC_iPhi_"+ss_iPhi+".png").c_str()); myC_variables->SaveAs(("fits/CC_iPhi_"+ss_iPhi+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_CC_phi->GetYaxis()->SetRangeUser(0.95,1.05); h1_fit_CC_phi->GetYaxis()->SetTitle("E_{cor}/E_{true}"); h1_fit_CC_phi->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#phi" : "iX"); h1_fit_CC_phi->SetTitle(""); h1_fit_CC_phi->Draw(); myC_variables->SaveAs("profile_fit_cor_vs_phi.pdf"); myC_variables->SaveAs("profile_fit_cor_vs_phi.png"); myC_variables->SaveAs("profile_fit_cor_vs_phi.C"); TProfile *p_RC_phi = h_RC_phi->ProfileX("p_RC_phi");//,1,-1,"s"); p_RC_phi->GetYaxis()->SetRangeUser(0.8,0.9); if(EEorEB=="EB") { // p_RC_phi->GetYaxis()->SetRangeUser(0.89,0.95); } p_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); p_RC_phi->SetTitle(""); p_RC_phi->Draw(); myC_variables->SaveAs("profile_raw_vs_phi.pdf"); myC_variables->SaveAs("profile_raw_vs_phi.png"); gStyle->SetOptStat(111); gStyle->SetOptFit(1); TH1F *h1_fit_RC_phi = new TH1F("h1_fit_RC_phi","h1_fit_RC_phi",(EEorEB=="EB") ? 360 : 50,(EEorEB=="EB") ? 0 : 0, (EEorEB=="EB") ? 360 : 50); for(int ix = 1;ix <= h_RC_phi->GetNbinsX(); ix++) { stringstream os_iPhi; os_iPhi << ((EEorEB=="EB") ? (0 + ix -1) : (0 + ix -1)); string ss_iPhi = os_iPhi.str(); TH1D * h_temp = h_RC_phi->ProjectionY("h_temp",ix,ix); h_temp->Rebin(4); TF1 *f_temp = new TF1("f_temp","gaus(0)",0.87,1.05); h_temp->Fit("f_temp","R"); h1_fit_RC_phi->SetBinContent(ix, f_temp->GetParameter(1)); h1_fit_RC_phi->SetBinError(ix, f_temp->GetParError(1)); h_temp->GetXaxis()->SetTitle("E_{raw}/E_{true}"); h_temp->SetTitle(""); h_temp->Draw(); myC_variables->SaveAs(("fits/RC_iPhi_"+ss_iPhi+".pdf").c_str()); myC_variables->SaveAs(("fits/RC_iPhi_"+ss_iPhi+".png").c_str()); myC_variables->SaveAs(("fits/RC_iPhi_"+ss_iPhi+".C").c_str()); } gStyle->SetOptStat(0); gStyle->SetOptFit(0); h1_fit_RC_phi->GetYaxis()->SetRangeUser(0.9,1.0); h1_fit_RC_phi->GetYaxis()->SetTitle("E_{raw}/E_{true}"); h1_fit_RC_phi->GetXaxis()->SetTitle((EEorEB=="EB") ? "i#phi" : "iX"); h1_fit_RC_phi->SetTitle(""); h1_fit_RC_phi->Draw(); myC_variables->SaveAs("profile_fit_raw_vs_phi.pdf"); myC_variables->SaveAs("profile_fit_raw_vs_phi.png"); myC_variables->SaveAs("profile_fit_raw_vs_phi.C"); int Nbins_iPhi = EEorEB=="EB" ? 360 : 50; int nLow_iPhi = EEorEB=="EB" ? 0 : 0; int nHigh_iPhi = EEorEB=="EB" ? 360 : 50; TH1F *h1_RC_phi = new TH1F("h1_RC_phi","h1_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_RC_phi->SetBinContent(i,p_RC_phi->GetBinError(i)); } h1_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_RC_phi->GetYaxis()->SetTitle("#sigma_{E_{raw}/E_{true}}"); h1_RC_phi->SetTitle(""); h1_RC_phi->Draw(); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Eraw_Etrue_vs_phi.png"); TH1F *h1_CC_phi = new TH1F("h1_CC_phi","h1_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); for(int i=1;i<=Nbins_iPhi;i++) { h1_CC_phi->SetBinContent(i,p_CC_phi->GetBinError(i)); } h1_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_CC_phi->GetYaxis()->SetTitle("#sigma_{E_{cor}/E_{true}}"); h1_CC_phi->SetTitle(""); h1_CC_phi->Draw(); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("sigma_Ecor_Etrue_vs_phi.png"); // FWHM over sigma_eff vs. eta/phi TH1F *h1_FoverS_RC_phi = new TH1F("h1_FoverS_RC_phi","h1_FoverS_RC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_CC_phi = new TH1F("h1_FoverS_CC_phi","h1_FoverS_CC_phi",Nbins_iPhi,nLow_iPhi,nHigh_iPhi); TH1F *h1_FoverS_RC_eta = new TH1F("h1_FoverS_RC_eta","h1_FoverS_RC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_eta = new TH1F("h1_FoverS_CC_eta","h1_FoverS_CC_eta",Nbins_iEta,nLow_iEta,nHigh_iEta); TH1F *h1_FoverS_CC_S2S9 = new TH1F("h1_FoverS_CC_S2S9","h1_FoverS_CC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_RC_S2S9 = new TH1F("h1_FoverS_RC_S2S9","h1_FoverS_RC_S2S9",Nbins_S2S9,Low_S2S9,High_S2S9); TH1F *h1_FoverS_CC_S4S9 = new TH1F("h1_FoverS_CC_S4S9","h1_FoverS_CC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); TH1F *h1_FoverS_RC_S4S9 = new TH1F("h1_FoverS_RC_S4S9","h1_FoverS_RC_S4S9",Nbins_S4S9,Low_S4S9,High_S4S9); float FWHMoverSigmaEff = 0.0; TH1F *h_tmp_rawvar = new TH1F("tmp_rawvar","tmp_rawvar",800,0.5,1.5); TH1F *h_tmp_corvar = new TH1F("tmp_corvar","tmp_corvar",800,0.5,1.5); for(int i=1;i<=Nbins_iPhi;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_phi->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_phi->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_phi->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_phi->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_CC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_phi->SetTitle(""); h1_FoverS_CC_phi->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_phi.png"); h1_FoverS_RC_phi->GetXaxis()->SetTitle("i#phi"); h1_FoverS_RC_phi->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_phi->SetTitle(""); h1_FoverS_RC_phi->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_phi.png"); for(int i=1;i<=Nbins_iEta;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_eta->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_eta->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_eta->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_eta->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_CC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_eta->SetTitle(""); h1_FoverS_CC_eta->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_eta.png"); h1_FoverS_RC_eta->GetXaxis()->SetTitle("i#eta"); h1_FoverS_RC_eta->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_eta->SetTitle(""); h1_FoverS_RC_eta->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_eta.png"); for(int i=1;i<=Nbins_S2S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S2S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S2S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S2S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S2S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_CC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S2S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S2S9->SetTitle(""); h1_FoverS_CC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S2S9.png"); h1_FoverS_RC_S2S9->GetXaxis()->SetTitle("S2S9"); h1_FoverS_RC_S2S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S2S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S2S9->SetTitle(""); h1_FoverS_RC_S2S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S2S9.png"); for(int i=1;i<=Nbins_S4S9;i++) { float FWHM_tmp = 0.0; float effSigma_tmp = 0.0; for(int j=1;j<=800;j++) { h_tmp_rawvar->SetBinContent(j,h_RC_S4S9->GetBinContent(i,j)); h_tmp_corvar->SetBinContent(j,h_CC_S4S9->GetBinContent(i,j)); } FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_rawvar); effSigma_tmp = effSigma(h_tmp_rawvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_RC_S4S9->SetBinContent(i, FWHMoverSigmaEff); FWHMoverSigmaEff = 0.0; FWHM_tmp= FWHM(h_tmp_corvar); effSigma_tmp = effSigma(h_tmp_corvar); if(effSigma_tmp>0.000001) FWHMoverSigmaEff = FWHM_tmp/effSigma_tmp; h1_FoverS_CC_S4S9->SetBinContent(i, FWHMoverSigmaEff); } h1_FoverS_CC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_CC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{cor}/E_{true}"); h1_FoverS_CC_S4S9->GetYaxis()->SetRangeUser(0.0,1.0); h1_FoverS_CC_S4S9->SetTitle(""); h1_FoverS_CC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Ecor_Etrue_vs_S4S9.png"); h1_FoverS_RC_S4S9->GetXaxis()->SetTitle("S4S9"); h1_FoverS_RC_S4S9->GetYaxis()->SetTitle("FWHM/#sigma_{eff} of E_{raw}/E_{true}"); h1_FoverS_RC_S4S9->GetYaxis()->SetRangeUser(0.0,2.0); h1_FoverS_RC_S4S9->SetTitle(""); h1_FoverS_RC_S4S9->Draw(); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.pdf"); myC_variables->SaveAs("FoverS_Eraw_Etrue_vs_S4S9.png"); printf("calc effsigma\n"); std::cout<<"_"<<EEorEB<<std::endl; printf("corrected curve effSigma= %5f, FWHM=%5f \n",effsigma_cor, fwhm_cor); printf("raw curve effSigma= %5f FWHM=%5f \n",effsigma_raw, fwhm_raw); /* new TCanvas; RooPlot *ploteold = testvar.frame(0.6,1.2,100); hdatasigtest->plotOn(ploteold); ploteold->Draw(); new TCanvas; RooPlot *plotecor = ecorvar->frame(0.6,1.2,100); hdatasig->plotOn(plotecor); plotecor->Draw(); */ }
void plot_efficiencies( TFile* file, Int_t type = 2, TDirectory* BinDir=0) { // input: - Input file (result from TMVA), // - type = 1 --> plot efficiency(B) versus eff(S) // = 2 --> plot rejection (B) versus efficiency (S) // = 3 --> plot 1/eff(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 if (type == 3) { y1 = 0; y2 = -1; // will be set to the max found in the histograms } 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"; if (type == 3) ytit = "1/(Background eff.)"; TString ftit = ytit + " versus " + xtit; TString hNameRef = "effBvsS"; if (type == 2) hNameRef = "rejBvsS"; if (type == 3) hNameRef = "invBeffvsSeff"; if (TString(BinDir->GetName()).Contains("multicut")){ ftit += " Bin: "; ftit += (BinDir->GetTitle()); } TList xhists; TList xmethods; UInt_t xnm = TMVAGlob::GetListOfMethods( xmethods ); TIter xnext(&xmethods); // loop over all methods TKey *xkey; while ((xkey = (TKey*)xnext())) { TDirectory * mDir = (TDirectory*)xkey->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() ); TKey *hkey2; while ((hkey2 = TMVAGlob::NextKey(nextKey,"TH1"))) { TH1 *h = (TH1*)hkey2->ReadObj(); TString hname = h->GetName(); if (hname.Contains( hNameRef ) && hname.BeginsWith( "MVA_" )) { if (type==3 && h->GetMaximum() > y2) y2 = h->GetMaximum(); } } } } // 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; 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() ); TKey *hkey2; while ((hkey2 = TMVAGlob::NextKey(nextKey,"TH1"))) { TH1 *h = (TH1*)hkey2->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(TMath::Min(10,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; }
// 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 plotVariable(string variable = "Elec_Fbrem", const TString& category = "TauNoGammas", const TString& xAxisTitle = "Fbrem", const TString& yAxisTitle = "a.u.", float xMin = -0.2, float xMax = 1, int nBins = 100, int numPVMin = 0, int numPVMax = 50, float PtMin = 10, float PtMax = 60, const TString& Region = "Endcap" ) { string discriminator = ""; // string discriminator = "-AntiEMed"; float AbsEtaMin = 0; float AbsEtaMax = 3.0; if(Region == "Barrel"){ AbsEtaMin = 0; AbsEtaMax = 1.479; } if(Region == "Endcap"){ AbsEtaMin = 1.479; AbsEtaMax = 3.0; } TCanvas *c1 = new TCanvas("c1","",5,30,650,600); c1->SetGrid(0,0); c1->SetFillStyle(4000); c1->SetFillColor(10); c1->SetTicky(); c1->SetObjectStat(0); gStyle->SetOptStat(0); gStyle->SetTitleFillColor(0); gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(0); gStyle->SetPadBorderMode(0); gStyle->SetPadColor(0); gStyle->SetTitleFillColor(0); gStyle->SetTitleBorderSize(0); gStyle->SetTitleH(0.07); gStyle->SetTitleFontSize(0.1); gStyle->SetTitleStyle(0); gStyle->SetTitleOffset(1.3,"y"); TLegend* leg = new TLegend(0.6,0.75,0.8,0.88,NULL,"brNDC"); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetFillColor(10); leg->SetTextSize(0.03); //leg->SetHeader("#splitline{CMS Preliminary}{ #sqrt{s}=7 TeV}"); // std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/AntiEMVA_Fall11DYJetsToLL-iter4.root"; // std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/Trees_ForV4/AntiEMVA_AntiEMVATrees-DYJetsToLL-madgraph-PUS6.root"; std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/Trees_ForV4/AntiEMVA_V4.root"; TFile* inputFile = new TFile (inputFileName.data(),"READ"); if(inputFile->IsZombie()){ cout << "No such file!" << endl; return; } TTree* inputTree = (TTree*)inputFile->Get("AntiEMVAAnalyzer2/tree"); // TTree* inputTree = (TTree*)inputFile->Get("AntiEMVAAnalyzer/tree"); std::vector<TH1*> histograms; std::vector<std::string> matchings ; matchings.push_back("GenHadMatch"); matchings.push_back("GenEleMatch"); for ( std::vector<std::string>::const_iterator matching = matchings.begin(); matching != matchings.end(); ++matching ) { TCut PUSelection(Form("NumPV>%i && NumPV<%i",numPVMin,numPVMax)); TCut ElecPtSelection (Form("Elec_Pt>%0f && Elec_Pt<%0f",PtMin,PtMax)); TCut TauPtSelection (Form("Tau_Pt>%0f && Tau_Pt<%0f",PtMin,PtMax)); TCut ElecAbsEtaSelection (Form("Elec_AbsEta>%0f && Elec_AbsEta<%0f",AbsEtaMin,AbsEtaMax)); TCut TauAbsEtaSelection = ""; if(Region == "Barrel"){ TauAbsEtaSelection = "Tau_Eta>-1.479 && Tau_Eta<1.479"; } if(Region == "Endcap"){ TauAbsEtaSelection = "(Tau_Eta>1.479 && Tau_Eta<3.0) || (Tau_Eta>-3.0 && Tau_Eta<-1.479)"; } // TCut TauAbsEtaSelection (Form("Tau_AbsEta>%0f && Tau_AbsEta<%0f",AbsEtaMin,AbsEtaMax)); TCut ElecMatchSelection (Form("Elec_%s == 1",matching->data())); // TCut ElecMatchSelection (Form("Elec_PFTauMatch && Elec_%s",matching->data())); TCut TauMatchSelection (Form("Tau_%s",matching->data())); TCut CategorySelection = ""; if(discriminator == ""){ if (category == "NoEleMatch") CategorySelection = "Tau_GsfEleMatch<0.5"; if (category == "woG") CategorySelection = "Tau_NumGammaCands<0.5"; if (category == "wGwoGSF") CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf<0.5"; if (category == "wGwGSFwoPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput<-0.1"; if (category == "wGwGSFwPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput>-0.1"; } if(discriminator == "-AntiEMed"){ if (category == "NoEleMatch") CategorySelection = "Tau_GsfEleMatch<0.5"; if (category == "woG") CategorySelection = "Tau_NumGammaCands<0.5"; if (category == "wGwoGSF") CategorySelection = "Tau_NumGammaCands>0.5 && (Tau_HasGsf<0.5 || (Tau_HasGsf>0.5 && Elec_PFMvaOutput>-0.1))"; if (category == "wGwGSFwoPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput<-0.1"; } TCut ElecSelection = CategorySelection && PUSelection && ElecPtSelection && ElecAbsEtaSelection && ElecMatchSelection ; TCut TauSelection = CategorySelection && PUSelection && TauPtSelection && TauAbsEtaSelection && TauMatchSelection ; TCut Selection; if (variable.find("Elec")!=std::string::npos)Selection = ElecSelection; if (variable.find("Tau")!=std::string::npos)Selection = TauSelection; TH1F* hVariable = new TH1F( "hVariable" ,"" , nBins ,xMin, xMax); hVariable->SetXTitle(Form("%s",variable.data())); if (matching->find("EleMatch")!=std::string::npos){ // hVariable->SetFillColor(kRed); // hVariable->SetFillStyle(3345); hVariable->SetLineColor(kRed); hVariable->SetLineWidth(2); } if (matching->find("HadMatch")!=std::string::npos){ // hVariable->SetFillColor(kBlue); // hVariable->SetFillStyle(3354); hVariable->SetLineColor(kBlue); hVariable->SetLineWidth(2); } inputTree->Draw(Form("%s>>hVariable",variable.data())); cout<<"Variable plotted : "<<variable<<endl; cout<<"Matching applied : "<<matching->data()<<endl; cout<<" Total number of Candidates : "<<hVariable->GetEntries()<<endl; inputTree->Draw(Form("%s>>hVariable",variable.data()),Selection); cout<<" Number of Cantidates after selection: "<<hVariable->GetEntries()<<endl; hVariable->Scale(1./hVariable->Integral()); leg->AddEntry(hVariable,Form("%s",matching->data())); histograms.push_back(hVariable); c1->Clear(); } // double yMin = +1.e+6; // double yMax = -1.e+6; TH1* refHistogram = histograms.front(); refHistogram->SetStats(false); refHistogram->SetTitle(""); // refHistogram->SetMinimum(yMin); // refHistogram->SetMaximum(yMax); if (xAxisTitle == "HoHplusE" ) { refHistogram->SetMaximum(1.0); refHistogram->SetMinimum(0.01); c1->SetLogy(); } if(xAxisTitle == "E_{#gamma}/(P_{in}-P_{out})" ){ refHistogram->SetMaximum(0.03); refHistogram->SetMinimum(0.0); } if(xAxisTitle == "HadrMva(#tau)" ){ refHistogram->SetMaximum(0.25); refHistogram->SetMinimum(0.0); } TAxis* xAxis = refHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.Data()); xAxis->SetTitleOffset(1.15); //if(variable.find("AbsEta")!=std::string::npos)xAxis->SetLimits(AbsEtaMin, AbsEtaMax); TAxis* yAxis = refHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.Data()); yAxis->SetTitleOffset(1.30); int numHistograms = histograms.size(); float YMax = 0; for ( int iHistogram = 0; iHistogram < numHistograms; ++iHistogram ) { TH1* histogram = histograms[iHistogram]; if(histogram->GetMaximum()>YMax) YMax = histogram->GetMaximum(); } for ( int iHistogram = 0; iHistogram < numHistograms; ++iHistogram ) { TH1* histogram = histograms[iHistogram]; yAxis->SetRangeUser(0.,YMax+0.10*YMax); std::string drawOption = "hist"; if ( iHistogram > 0 ) drawOption.append("same"); histogram->Draw(drawOption.data()); leg->Draw(); }//loop matchings string outputName = Form("plots/plotVariablesAntiEMVA/%s/plotVariablesAntiEMVA_v4_%s_%s_%s",category.Data(),category.Data(),variable.data(),Region.Data()); c1->Print(std::string(outputName).append(".png").data()); c1->Print(std::string(outputName).append(".pdf").data()); }
void patBJetVertex_efficiencies() { // define proper canvas style setNiceStyle(); gStyle->SetOptStat(0); // open file TFile* file = new TFile("analyzePatBJetVertex.root"); unsigned int j = 0; for(const char **algo = algos; *algo; algo++, j++) { TLegend *legend[3] = { 0, 0, 0 }; // draw canvas with efficiencies TCanvas *canv; canv = new TCanvas(*algo, Form("%s efficiencies", algoNames[j]), 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/%s_%s", directory, *algo, *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.3, 0.4, 0.58, 0.58); 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(); } }
void likelihoodrefs( TDirectory *lhdir ) { Bool_t newCanvas = kTRUE; const UInt_t maxCanvas = 200; TCanvas** c = new TCanvas*[maxCanvas]; Int_t width = 670; Int_t height = 380; // avoid duplicated printing std::vector<std::string> hasBeenUsed; const TString titName = lhdir->GetName(); UInt_t ic = -1; TIter next(lhdir->GetListOfKeys()); TKey *key; while ((key = TMVAGlob::NextKey(next,"TH1"))) { // loop over all TH1 TH1 *h = (TH1*)key->ReadObj(); TH1F *b( 0 ); TString hname( h->GetName() ); // avoid duplicated plotting Bool_t found = kFALSE; for (UInt_t j = 0; j < hasBeenUsed.size(); j++) { if (hasBeenUsed[j] == hname.Data()) found = kTRUE; } if (!found) { // draw original plots if (hname.EndsWith("_sig_nice")) { if (newCanvas) { char cn[20]; sprintf( cn, "cv%d_%s", ic+1, titName.Data() ); ++ic; TString n = hname; c[ic] = new TCanvas( cn, Form( "%s reference for variable: %s", titName.Data(),(n.ReplaceAll("_sig","")).Data() ), ic*50+50, ic*20, width, height ); c[ic]->Divide(2,1); newCanvas = kFALSE; } // signal Int_t color = 4; TPad * cPad = (TPad*)c[ic]->cd(1); TString plotname = hname; 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); color++; h->Draw("e1"); Double_t hSscale = 1.0/(h->GetSumOfWeights()*h->GetBinWidth(1)); TLegend *legS= new TLegend( cPad->GetLeftMargin(), 1-cPad->GetTopMargin()-.14, cPad->GetLeftMargin()+.77, 1-cPad->GetTopMargin() ); legS->SetBorderSize(1); legS->AddEntry(h,"Input data (signal)","p"); // background TString bname( hname ); b = (TH1F*)lhdir->Get( bname.ReplaceAll("_sig","_bgd") ); cPad = (TPad*)c[ic]->cd(2); color = 2; b->SetMaximum(b->GetMaximum()*1.3); b->SetMinimum( 0 ); b->SetLineWidth(1); b->SetLineColor(color); b->SetMarkerColor(color); b->SetMarkerSize( 0.7 ); b->SetMarkerStyle( 24 ); b->Draw("e1"); Double_t hBscale = 1.0/(b->GetSumOfWeights()*b->GetBinWidth(1)); TLegend *legB= new TLegend( cPad->GetLeftMargin(), 1-cPad->GetTopMargin()-.14, cPad->GetLeftMargin()+.77, 1-cPad->GetTopMargin() ); legB->SetBorderSize(1); legB->AddEntry(b,"Input data (backgr.)","p"); // register hasBeenUsed.push_back( bname.Data() ); // the PDFs -------------- // check for splines h = 0; b = 0; TString pname = hname; pname.ReplaceAll("_nice",""); for (int i=0; i<= 5; i++) { TString hspline = pname + Form( "_smoothed_hist_from_spline%i", i ); h = (TH1F*)lhdir->Get( hspline ); if (h) { b = (TH1F*)lhdir->Get( hspline.ReplaceAll("_sig","_bgd") ); break; } } // check for KDE if (h == 0 && b == 0) { TString hspline = pname +"_smoothed_hist_from_KDE"; h = (TH1F*)lhdir->Get( hspline ); if (h) { b = (TH1F*)lhdir->Get( hspline.ReplaceAll("_sig","_bgd") ); } } // found something ? if (h == 0 || b == 0) { cout << "--- likelihoodrefs.C: did not find spline for histogram: " << pname.Data() << endl; } else { Double_t pSscale = 1.0/(h->GetSumOfWeights()*h->GetBinWidth(1)); h->Scale( pSscale/hSscale ); color = 4; c[ic]->cd(1); h->SetLineWidth(2); h->SetLineColor(color); legS->AddEntry(h,"Estimated PDF (norm. signal)","l"); h->Draw("histsame"); legS->Draw(); Double_t pBscale = 1.0/(b->GetSumOfWeights()*b->GetBinWidth(1)); b->Scale( pBscale/hBscale ); color = 2; c[ic]->cd(2); b->SetLineColor(color); b->SetLineWidth(2); legB->AddEntry(b,"Estimated PDF (norm. backgr.)","l"); b->Draw("histsame"); // draw the legends legB->Draw(); hasBeenUsed.push_back( pname.Data() ); } c[ic]->Update(); // write to file TString fname = Form( "root_mva/plots/%s_refs_c%i", titName.Data(), ic+1 ); TMVAGlob::imgconv( c[ic], fname ); // c[ic]->Update(); newCanvas = kTRUE; hasBeenUsed.push_back( hname.Data() ); } } } }
void pidHistogramMaker::distributionReport( string pType ){ uint nBinsPt = ptBins.size() - 1; string rName = speciesName( pType, 0 ); taskProgress tp( pType + " distribution report", nBinsPt ); book->cd( "tof" ); for ( uint i = 0; i < nBinsPt; i ++ ){ tp.showProgress( i ); // momentum value used for finding nice range double p = ptBins[ i ]; double p2 = ptBins[ i + 1 ]; double avgP = 0.2; avgP = (ptBins[ i ] + ptBins[ i + 1])/2.0; string name = speciesName( pType, 0, i, 0 ); book->cd( "dedx_tof" ); TH2 * pTof = book->get2D( name ); book->cd( "scratch" ); TH2 * pDedx = (TH2*)pTof->Clone( "pDedx__" ); // start a new page on the report file pReport[ rName ]->newPage( 2, 2 ); // get information on plot ranges double tofLow, tofHigh, dedxLow, dedxHigh; autoViewport( pType, p, &tofLow, &tofHigh, &dedxLow, &dedxHigh, tofPadding, dedxPadding, tofScalePadding, dedxScalePadding ); if ( true ) { // show the tof proj string title = "#beta^{-1} : " + ts(ptBins[ i ], 4) + " < pT < " + ts(ptBins[i+1], 4); vector<string> others = otherSpecies( pType ); vector< double > tofMean = enhanceTof( pType, others, avgP ); vector< double > dedxMean = enhanceDedx( pType, others, avgP ); pReport[ rName ]->cd( 1, 1 ); //hdt->GetXaxis()->SetRangeUser( -.06, .06 ); // Make the all tof tracks histogram string hName = sTofName( pType, 0, i ); book->cd( "scratch" ); TH1* hTof = (TH1D*)pTof->ProjectionY( "_py" ); book->cd( "tof" ); book->add( hName, (TH1*)hTof->Clone( hName.c_str() ) ); book->style( hName )->set( "style.tof" ) ->set( "title", title )->draw(); TLine * l1 = new TLine( tofMean[ 0 ], hTof->GetMinimum(), tofMean[ 0 ], hTof->GetMaximum() ); l1->Draw(); TLine * l2 = new TLine( tofMean[ 1 ], hTof->GetMinimum(), tofMean[ 1 ], hTof->GetMaximum() ); l2->Draw(); pReport[ rName ]->cd( 2, 1 ); pTof->GetXaxis()->SetRangeUser( -.06, .06 ); // Make the all tof tracks histogram hName = sTofName( pType, 0, i, 0, pType ); book->cd( "scratch" ); hTof = (TH1D*)pTof->ProjectionY( "_py" ); book->cd( "tof" ); book->add( hName, (TH1*)hTof->Clone( hName.c_str() ) ); book->style( hName )->set( "style.tof" ) ->set( "title", title + " " + pType + " enhanced" )->draw(); for ( int j = 0; j < dedxMean.size(); j++ ){ pReport[ rName ]->cd( j+1, 2 ); pTof->GetXaxis()->SetRangeUser( dedxMean[j]-0.06, dedxMean[j]+0.06 ); // Make the all tof tracks histogram hName = sTofName( pType, 0, i, 0, others[ j ] ); book->cd( "scratch" ); hTof = (TH1D*)pTof->ProjectionY( "_py" ); book->cd( "tof" ); book->add( hName, (TH1*)hTof->Clone( hName.c_str() ) ); book->style( hName )->set( "style.tof" ) ->set( "title", title + " " + others[ j ] + " enhanced" )->draw(); } } pReport[ rName ]->savePage(); pReport[ rName ]->newPage( 2, 2 ); if ( true ) { // show the dedx proj string title = "dEdx : " + ts(ptBins[ i ], 4) + " < pT < " + ts(ptBins[i+1], 4); pTof->GetXaxis()->SetRange( 1, pTof->GetXaxis()->GetNbins() ); pTof->GetYaxis()->SetRange( 1, pTof->GetYaxis()->GetNbins() ); vector<string> others = otherSpecies( pType ); vector< double > tofMean = enhanceTof( pType, others, avgP ); vector< double > dedxMean = enhanceDedx( pType, others, avgP ); pReport[ rName ]->cd( 1, 1 ); // Make the all dedx tracks histogram string hName = sDedxName( pType, 0, i ); book->cd( "scratch" ); TH1* hDedx = (TH1D*)pTof->ProjectionX( "_px" ); book->cd( "dedx" ); book->add( hName, (TH1*)hDedx->Clone( hName.c_str() ) ); book->style( hName )->set( "style.dedx" ) ->set( "title", title )->draw(); TLine * l1 = new TLine( dedxMean[ 0 ], hDedx->GetMinimum(), dedxMean[ 0 ], hDedx->GetMaximum() ); l1->Draw(); TLine * l2 = new TLine( dedxMean[ 1 ], hDedx->GetMinimum(), dedxMean[ 1 ], hDedx->GetMaximum() ); l2->Draw(); pReport[ rName ]->cd( 2, 1 ); pTof->GetYaxis()->SetRangeUser( -.012, .012 ); // Make the all tof tracks histogram hName = sDedxName( pType, 0, i, 0, pType ); book->cd( "scratch" ); hDedx = (TH1D*)pTof->ProjectionX( "_px" ); book->cd( "dedx" ); book->add( hName, (TH1*)hDedx->Clone( hName.c_str() ) ); book->style( hName )->set( "style.dedx" ) ->set( "title", title + " " + pType + " enhanced" )->draw(); for ( int j = 0; j < dedxMean.size(); j++ ){ pReport[ rName ]->cd( j+1, 2 ); pTof->GetYaxis()->SetRangeUser( tofMean[j]-0.012, tofMean[j]+0.012 ); // Make the all tof tracks histogram hName = sDedxName( pType, 0, i, 0, others[ j ] ); book->cd( "scratch" ); hDedx = (TH1D*)pTof->ProjectionX( "_px" ); book->cd( "dedx" ); book->add( hName, (TH1*)hDedx->Clone( hName.c_str() ) ); book->style( hName )->set( "style.dedx" ) ->set( "title", title + " " + others[ j ] + " enhanced" )->draw(); } } pReport[ rName ]->savePage(); } }
int ratio5() { // Constants and arrays Int_t multi = 2; const Int_t n_at = 3; Int_t at[n_at] = { 500, 510, 550 }; //for ( int ii = 0; ii < n_at; ++ii ) { at[ii] = 500 + ii * 10; } TString eq = "Gt"; const Int_t n = 4; float pt[n] = { 50., 40., 30., 20. }; Int_t colour[n] = { 1, 2, 3, 4 }; const Int_t m = 2; Int_t style[m] = { kOpenSquare, kFullSquare }; const Int_t ngr = 1000; double x3[ngr]; double r[ngr]; int count = 0; // General style gStyle->SetOptStat(0); // // Canvas for RECO curves // TCanvas* reco_canvas = new TCanvas("Reco"); // reco_canvas->SetFillColor(0); // reco_canvas->SetLineColor(0); // reco_canvas->SetLogy(); // TLegend* reco_legend = new TLegend( 0.5, 0.7, 0.88, 0.88, NULL, "brNDC" ); // reco_legend->SetFillColor(0); // reco_legend->SetLineColor(0); // bool empty = true; // double reco_max = 1.e-15.; // double reco_min = 1.e15; // Loop through pt bins for ( Int_t i = 0; i < 1; ++i ) { std::stringstream pt_can; pt_can << "PtBin" << pt[i]; // Canvas for Pt bin TCanvas* pt_canvas = new TCanvas(TString(pt_can.str()),""); pt_canvas->SetFillColor(0); pt_canvas->SetLineColor(0); pt_canvas->SetLogy(); TLegend* pt_legend = new TLegend( 0.82, 0.5, 0.98, 0.9, NULL, "brNDC" ); pt_legend->SetFillColor(0); pt_legend->SetLineColor(0); bool empty = true; double pt_max = 1.e-15.; double pt_min = 1.e15; std::vector<TH1*> pt_ratio; pt_canvas->SetRightMargin(0.2); // Open files std::stringstream ss; ss << "results/4/Reco" << pt[i] << "_QCDPythia6.root"; TString name(ss.str()); TFile* file = new TFile(name); if ( file->IsZombie() || !(file->IsOpen()) ) { continue; } file->cd(); // Loop through AlphaT thresolds for ( Int_t iat = 0; iat < n_at; ++iat ) { // Loop through RECO and GEN for ( Int_t j = 0; j < m; ++j ) { // Define names of histos to open std::stringstream pre; std::stringstream post; if ( j == 0 ) { pre << "Ratio" << at[iat] << "/GenHt" << eq << "PreAlphaT" << at[iat] << "_" << multi; post << "Ratio" << at[iat] << "/GenHt" << eq << "PostAlphaT" << at[iat] << "_" << multi; std::cout << pre.str() << std::endl; std::cout << post.str() << std::endl; } else if ( j == 1 ) { pre << "Ratio" << at[iat] << "/Ht" << eq << "PreAlphaT" << at[iat] << "_" << multi; post << "Ratio" << at[iat] << "/Ht" << eq << "PostAlphaT" << at[iat] << "_" << multi; std::cout << pre.str() << std::endl; std::cout << post.str() << std::endl; } // Create ratio histo TH1* denominator = his( (TH1*)file->Get(TString(pre.str())), 45, 200., 650. ); TH1* numerator = his( (TH1*)file->Get(TString(post.str())), 45, 200., 650. ); int rebin = 5; numerator->Rebin(rebin); denominator->Rebin(rebin); TH1* ratio = (TH1*)numerator->Clone(); ratio->Divide(denominator); //ratio->Divide(numerator,denominator,1.,1.,"b"); //@@ poisson errors ratio->SetMarkerStyle(style[j]); ratio->SetMarkerSize(1.2); ratio->SetMarkerColor(iat+1);//colour[iat]); ratio->SetBarOffset(0.1*i); //ratio->GetXaxis()->SetRangeUser(100.,550.); ratio->GetYaxis()->SetRangeUser(1.e-7,1.e-1); ratio->GetXaxis()->SetTitle("HT_{reco} [GeV]"); ratio->GetYaxis()->SetTitle("R(#alpha_{T})"); if ( ratio->GetMaximum() > 0. && ratio->GetMaximum() > pt_max ) { pt_max = ratio->GetMaximum(); } if ( ratio->GetMinimum() > 0. && ratio->GetMinimum() < pt_min ) { pt_min = ratio->GetMinimum(); } pt_ratio.push_back(ratio); if ( empty ) { ratio->Draw(""); empty = false; } else { ratio->Draw("same"); } //ratio->GetYaxis()->SetRangeUser(pt_min/1.1,pt_max*1.1); // Text for legend std::stringstream pt_leg; if ( j == 0 ) { pt_leg << "#alpha_{T} = " << at[iat]/1000. << ", GEN"; } else if ( j == 1 ) { pt_leg << "#alpha_{T} = " << at[iat]/1000. << ", RECO"; } pt_legend->AddEntry( ratio, TString(pt_leg.str()), "lep" ); // // Draw histos on canvas for RECO only // if ( j == 1 ) { // reco_canvas->cd(); // if ( i == 0 ) ratio->Draw(""); // else ratio->Draw("same"); // std::stringstream reco_leg; // reco_leg << "p_{T}^{min} = " << pt[i]; // reco_legend->AddEntry( ratio, TString(reco_leg.str()), "lep" ); // } } } // if (0) { // int nbins = ratio->GetNbinsX(); // int bin_width = ratio->GetBinWidth(1); // double lower = 0.; // double upper = 1400.; // int bin_lower = int( ( lower - ratio->GetBinLowEdge(1) ) / bin_width ); // for ( Int_t ii = bin_lower; ii < ratio->GetNbinsX()-1; ++ii ) { // if ( ratio->GetBinContent(ii) > 0. ) { // lower = ratio->GetBinCenter(ii); // break; // } // } // int bin_upper = int( ( upper - ratio->GetBinLowEdge(1) ) / bin_width ); // for ( Int_t ii = bin_upper; ii > 0; --ii ) { // if ( ratio->GetBinContent(ii) > 0. ) { // upper = ratio->GetBinCenter(ii); // break; // } // } // if (0) { // std::cout << " bin_width: " << bin_width // << " bin_lower: " << bin_lower // << " bin_upper: " << bin_upper // << " lower: " << lower // << " upper: " << upper // << std::endl; // } // TF1* fit = new TF1(sample[i],"expo",lower,upper); // fit->SetLineColor(colour[i]); // fit->SetLineWidth(1); // ratio->Fit(sample[i],"QR","same"); // } pt_canvas->cd(); // for ( Int_t iii = 0; iii < pt_ratio.size(); ++iii ) { // TH1* ratio = pt_ratio[iii]; // if ( !ratio ) { continue; } // if ( ii == 0 ) { ratio->Draw(""); } // else { ratio->Draw("same"); } // ratio->GetYaxis()->SetRangeUser(pt_min/1.1,pt_max*1.1); // } pt_legend->Draw("same"); pt_canvas->Update(); pt_canvas->SaveAs(TString(pt_can.str()+".png")); // pt_canvas->SaveAs(TString(pt_can.str()+".C")); } // reco_canvas->cd(); // reco_legend->Draw("same"); // reco_canvas->Update(); // reco_canvas->SaveAs(TString("Reco.png")); // reco_canvas->SaveAs(TString("Reco.C")); // TCanvas* c2 = new TCanvas("C2"); // c2->SetLogy(); // c2->SetFillColor(0); // gStyle->SetOptStat(0); // if ( count > 0 ) { // TGraph* graph = new TGraph(count,x3,r); // graph->Draw("a*"); // } }
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(); }
// --------------------------------------------------------------------------------------------- // returns scaling (change in normalization, in log 10) or -666 if failed // optional parameter accepts the desired unit prefix (in log 10) int adjustUnits( TH1& h1, int forceNewPrefix = -666) { if( h1.GetDimension() != 1) {cerr<<"ERROR! 'adjustUnits' works only for 1D histograms!"<<endl; return -666;} bool forced = forceNewPrefix != -666; TString ss( h1.GetYaxis()->GetTitle() ); ss.ReplaceAll ("_{T}", "_%@#"); // otherwise it messes up the reg. exp. // all backslashes are doubled, to get by the compiler string parsing, leaving \[ for TRegexp --> literal [s & ]s int iOpenBracket = ss.Index (TRegexp ("\\[[^\\]]*\\][^\\[\\]]*$"));// That is, the start of the last square brackets int iCloseBracket = ss.Last(']'); // no need for quotes with char if( iOpenBracket < 0 || iCloseBracket <= iOpenBracket ) { // can't find units return -666; } Double_t oldMax = h1.GetMaximum(); h1.SetMaximum(); // unsets Double_t max = h1.GetMaximum(); Double_t max10 = TMath::Log10( max ); if( -3 < max10 && max10 < 3 && ! forced ) return 0; // no rescaling needed // parse input units TString inputUnits = ss( 1+iOpenBracket, -1 + iCloseBracket - iOpenBracket); int curPrefix = 0, prefixLength = 0; if( inputUnits.BeginsWith( "m" ) ) {curPrefix = -3; prefixLength = 1;} if( inputUnits.BeginsWith( "#mu" ) ) {curPrefix = -6; prefixLength = 3;} if( inputUnits.BeginsWith( "n" ) ) {curPrefix = -9; prefixLength = 1;} if( inputUnits.BeginsWith( "p" ) ) {curPrefix = -12; prefixLength = 1;} if( inputUnits.BeginsWith( "f" ) ) {curPrefix = -15; prefixLength = 1;} if( inputUnits.BeginsWith( "k" ) ) {curPrefix = 3; prefixLength = 1;} // add more as needed.... TString baseUnit( inputUnits( prefixLength, inputUnits.Length() - prefixLength ) ); // find target units int iNewPrefix = 3 * TMath::Floor( 0.5 + (curPrefix + max10)/3. ); if( forced ) iNewPrefix = forceNewPrefix; // prepare new units and scaling TString sNewPrefix; int scale10 = 1; if( iNewPrefix > 3 ) {cerr<<"adjustUnits - NYI for >kilo"<<endl;} if( iNewPrefix >= 3 ) {sNewPrefix = "k"; scale10 = curPrefix - 3;} if( -15 < iNewPrefix && iNewPrefix < 3 ) scale10 = curPrefix- iNewPrefix; if( iNewPrefix == 0 ) sNewPrefix = ""; if( iNewPrefix == -3 ) sNewPrefix = "m"; if( iNewPrefix == -6 ) sNewPrefix = "#mu"; if( iNewPrefix == -9 ) sNewPrefix = "n"; if( iNewPrefix == -12 ) sNewPrefix = "p"; if( iNewPrefix < -15 ) {cerr<<"adjustUnits - NYI for <femto"<<endl;} if( iNewPrefix <= -15 ) {sNewPrefix = "f"; scale10 = curPrefix + 15;} // sanity checks if( forced && forceNewPrefix != 0 && sNewPrefix == "" ) { cerr<<"adjustUnits - illegal new prefix forced!"<<endl; return -666; } if( scale10 == 0 && ! forced ) {cerr<<"Bug in adjustUnits? scale10 == 0 .... "<<endl; return -666;} // good to go - changing the histogram Double_t scale = TMath::Power( 10, scale10 ); h1.Scale( scale ); h1.SetMaximum( oldMax * scale ); h1.GetYaxis()->SetTitle( ss( 0, iOpenBracket + 1 ) + sNewPrefix + baseUnit + ss( iCloseBracket, ss.Length() - iCloseBracket ) ); return scale10; }