//------------------------------------------------------------------------------ // SetAxis //------------------------------------------------------------------------------ void SetAxis(TH1* hist, TString xtitle, TString ytitle, Float_t size, Float_t offset) { TAxis* xaxis = (TAxis*)hist->GetXaxis(); TAxis* yaxis = (TAxis*)hist->GetYaxis(); xaxis->SetLabelFont(42); yaxis->SetLabelFont(42); xaxis->SetTitleFont(42); yaxis->SetTitleFont(42); xaxis->SetLabelOffset(0.025); yaxis->SetLabelOffset(0.025); xaxis->SetTitleOffset(1.4); yaxis->SetTitleOffset(offset); xaxis->SetLabelSize(size); yaxis->SetLabelSize(size); xaxis->SetTitleSize(size); yaxis->SetTitleSize(size); xaxis->SetTitle(xtitle); yaxis->SetTitle(ytitle); xaxis->SetNdivisions(505); yaxis->SetNdivisions(505); yaxis->CenterTitle(); gPad->GetFrame()->DrawClone(); gPad->RedrawAxis(); }
TH2* RootWriter::CreateTH2(Histogram2D* h) { const Axis& xax = h->GetAxisX(), yax = h->GetAxisY(); const int xchannels = xax.GetBinCount(); const int ychannels = yax.GetBinCount(); TH2* mat = new TH2F( h->GetName().c_str(), h->GetTitle().c_str(), xchannels, xax.GetLeft(), xax.GetRight(), ychannels, yax.GetLeft(), yax.GetRight() ); mat->SetOption( "colz" ); mat->SetContour( 64 ); TAxis* rxax = mat->GetXaxis(); rxax->SetTitle(xax.GetTitle().c_str()); rxax->SetTitleSize(0.03); rxax->SetLabelSize(0.03); TAxis* ryax = mat->GetYaxis(); ryax->SetTitle(yax.GetTitle().c_str()); ryax->SetTitleSize(0.03); ryax->SetLabelSize(0.03); ryax->SetTitleOffset(1.3); TAxis* zax = mat->GetZaxis(); zax->SetLabelSize(0.025); for(int iy=0; iy<ychannels+2; ++iy) for(int ix=0; ix<xchannels+2; ++ix) mat->SetBinContent(ix, iy, h->GetBinContent(ix, iy)); mat->SetEntries( h->GetEntries() ); return mat; }
bool TMRCScanner::PlotRatevsDAC(int xmin,int xmax,int ymax) { int channel = 0; // Read channel range from configuration ffile = new TFile(foutfile); if (ffile->IsOpen()){ ftree = (TTree*) ffile->Get("T"); //ftree->SetMarkerStyle(23); //ftree->SetLineColor(kRed); ftree->Draw("(HITEntries[0]/Duration):DAC>>hDAC(1024,0,1023,2001,0,2000)","HITEntries!=0","L"); TH2F *h = (TH2F*)gPad->GetPrimitive("hDAC"); TAxis *xaxis = h->GetXaxis(); xaxis->SetTitle("Threshold [DAC unit]"); xaxis->SetRange(xmin,xmax); TAxis *yaxis = h->GetYaxis(); yaxis->SetTitle("Rate [Hz]"); yaxis->SetRange(0,ymax); h->SetTitle("Pulse Amplitude Integral Distribution"); for (int i = 2048; i<(2048+128); i++) { ftree->Draw(Form("(HITEntries[%d]/Duration):DAC",channel+i),"HITEntries!=0","SAME,L"); printf("%d\n",i); } ftree->SetLineColor(kRed); ftree->Draw("Rate:DAC","","SAME,L"); }else { printf("File %s not opened \n",foutfile); return false; } delete ffile; return true; }
void showGraph(double canvasSizeX, double canvasSizeY, TGraph* graph, bool useLogScaleX, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, bool useLogScaleY, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetTopMargin(0.05); canvas->SetLeftMargin(0.19); canvas->SetBottomMargin(0.19); canvas->SetRightMargin(0.05); canvas->SetLogx(useLogScaleX); canvas->SetLogy(useLogScaleY); TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 10, xMin, xMax); dummyHistogram->SetTitle(""); dummyHistogram->SetStats(false); dummyHistogram->SetMinimum(yMin); dummyHistogram->SetMaximum(yMax); dummyHistogram->Draw("axis"); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(xAxisOffset); xAxis->SetTitleSize(0.065); xAxis->SetLabelSize(0.055); xAxis->SetLabelOffset(0.01); xAxis->SetTickLength(0.055); xAxis->SetNdivisions(505); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(yAxisOffset); yAxis->SetTitleSize(0.070); yAxis->SetLabelSize(0.055); yAxis->SetLabelOffset(0.01); yAxis->SetTickLength(0.055); yAxis->SetNdivisions(505); graph->SetMarkerColor(1); graph->SetLineColor(1); graph->Draw("p"); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( useLogScaleY ) outputFileName_plot.append("_log"); else outputFileName_plot.append("_linear"); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); //canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); //canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete dummyHistogram; delete canvas; }
void showHistograms(double canvasSizeX, double canvasSizeY, TH1* histogram, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.15); canvas->SetBottomMargin(0.15); canvas->SetLogy(useLogScale); histogram->SetTitle(""); histogram->SetStats(true); histogram->SetMinimum(yMin); histogram->SetMaximum(yMax); histogram->SetLineColor(1); histogram->SetLineWidth(2); histogram->SetMarkerColor(1); histogram->SetMarkerStyle(20); histogram->SetMarkerSize(1.5); histogram->Draw("hist"); TAxis* xAxis = histogram->GetXaxis(); xAxis->SetRangeUser(xMin, xMax); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleSize(0.060); xAxis->SetTitleOffset(xAxisOffset); xAxis->SetLabelSize(0.050); xAxis->SetNdivisions(505); TAxis* yAxis = histogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleSize(0.060); yAxis->SetTitleOffset(yAxisOffset); yAxis->SetLabelSize(0.050); yAxis->SetNdivisions(505); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( useLogScale ) outputFileName_plot.append("_log"); else outputFileName_plot.append("_linear"); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); //canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); //canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete canvas; }
void setup_TGraph(TGraph* graph, std::string xtitle, std::string ytitle, int lcolor){ graph->SetLineColor(lcolor); graph->SetLineWidth(LINE_WIDTH); // graph->Draw(); TAxis *xaxis = graph->GetXaxis(); TAxis *yaxis = graph->GetYaxis(); xaxis->SetTitle(xtitle.c_str()); yaxis->SetTitle(ytitle.c_str()); xaxis->SetTitleOffset(1.1); yaxis->SetTitleOffset(1.1); }
// Create, Draw and fit a TGraph2DErrors void macro4(){ gStyle->SetPalette(57); const double e = 0.3; const int nd = 500; TRandom3 my_random_generator; TF2 f2("f2", "1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200", -6,6,-6,6); f2.SetParameters(1,1); TGraph2DErrors dte(nd); // Fill the 2D graph double rnd, x, y, z, ex, ey, ez; for (Int_t i=0; i<nd; i++) { f2.GetRandom2(x,y); // A random number in [-e,e] rnd = my_random_generator.Uniform(-e,e); z = f2.Eval(x,y)*(1+rnd); dte.SetPoint(i,x,y,z); ex = 0.05*my_random_generator.Uniform(); ey = 0.05*my_random_generator.Uniform(); ez = fabs(z*rnd); dte.SetPointError(i,ex,ey,ez); } // Fit function to generated data f2.SetParameters(0.7,1.5); // set initial values for fit f2.SetTitle("Fitted 2D function"); dte.Fit(&f2); // Plot the result auto c1 = new TCanvas(); f2.SetLineWidth(1); f2.SetLineColor(kBlue-5); TF2 *f2c = (TF2*)f2.DrawClone("Surf1"); TAxis *Xaxis = f2c->GetXaxis(); TAxis *Yaxis = f2c->GetYaxis(); TAxis *Zaxis = f2c->GetZaxis(); Xaxis->SetTitle("X Title"); Xaxis->SetTitleOffset(1.5); Yaxis->SetTitle("Y Title"); Yaxis->SetTitleOffset(1.5); Zaxis->SetTitle("Z Title"); Zaxis->SetTitleOffset(1.5); dte.DrawClone("P0 Same"); // Make the x and y projections auto c_p= new TCanvas("ProjCan", "The Projections",1000,400); c_p->Divide(2,1); c_p->cd(1); dte.Project("x")->Draw(); c_p->cd(2); dte.Project("y")->Draw(); }
void showHistogram1d(TH1* histogram, const std::string& xAxisTitle, Float_t* genX, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetTopMargin(0.10); canvas->SetLeftMargin(0.16); canvas->SetRightMargin(0.14); canvas->SetBottomMargin(0.12); TAxis* xAxis = histogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(1.15); TAxis* yAxis = histogram->GetYaxis(); yAxis->SetTitle("Sampling Points"); yAxis->SetTitleOffset(1.60); histogram->SetLineColor(1); histogram->SetLineWidth(2); histogram->SetMarkerColor(1); histogram->SetMarkerStyle(20); histogram->Draw("e1p"); TMarker* genMarker = 0; if ( genX ) { genMarker = new TMarker(*genX, 0.10, 34); genMarker->SetMarkerColor(1); genMarker->SetMarkerSize(2); genMarker->Draw(); } canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete genMarker; delete canvas; }
/* double residual_error( double error_data, double pdf ) { double chi2 = 0.; if ( pdf > 0 ) chi2 += 2. * ( pdf - error_data ); if ( error_data > 0 && pdf > 0 ) chi2=(error_data/pdf); //chi2 += 2. * error_data * log( error_data / error_pdf ); // return ( ( error_data >= pdf ) ? sqrt( chi2 ) : -sqrt( chi2 ) ); // return ( ( error_data >= pdf ) ? chi2 : chi2 ); return ( chi2 ); } */ TH1D* residualHist( const RooHist* rhist, const RooCurve* curve ) { double r = 0.2; double sr = 1. / r; // Grab info from the histogram. int n = rhist->GetN(); double* x = rhist->GetX(); double* y = rhist->GetY(); //rhist->Sumw2(); // double e; // Create residual histogram. double xMin = x[ 0 ]; double xMax = x[ n - 1 ]; TH1D* residuals_temp = new TH1D( "r", "", n, xMin, xMax ); double datum = 0.; double pdf = 0.; double error_data = 0.; // Fill the histogram. if ( curve ) for ( int bin = 0; bin < n; bin++ ) { datum = y[ bin ]; pdf = curve->Eval( x[ bin ] ); error_data = rhist->GetErrorY(bin); // error_pdf = curve->Eval( x[ bin ] ); residuals_temp->SetBinContent( bin + 1, residual( datum, pdf ) ); // residuals_temp->SetBinError ( bin + 1, residual_error( error_data, pdf ) ); residuals_temp->SetBinError ( bin + 1, error_data / pdf ); } residuals_temp->SetMinimum ( -2. ); residuals_temp->SetMaximum ( 2. ); residuals_temp->SetStats ( false ); residuals_temp->SetMarkerStyle( 8 ); residuals_temp->SetMarkerSize ( .8 ); TAxis* xAxis = residuals_temp->GetXaxis(); xAxis->SetTickLength ( sr * xAxis->GetTickLength() ); xAxis->SetLabelSize ( sr * xAxis->GetLabelSize() ); xAxis->SetTitleSize ( sr * xAxis->GetTitleSize() ); xAxis->SetLabelOffset( sr * xAxis->GetLabelOffset() ); TAxis* yAxis = residuals_temp->GetYaxis(); //yAxis->SetNdivisions ( 500 ); //yAxis->SetLabelSize ( 10*sr * yAxis->GetLabelSize() ); yAxis->SetLabelSize ( 2.5 * yAxis->GetLabelSize() ); yAxis->SetTitle(" (DATA - FIT) / FIT"); yAxis->SetTitleSize ( 0.09 ); yAxis->SetTitleOffset( 0.35 ); return residuals_temp; }
TGraphErrors* PlotLightYieldGraph() { string filename; vector<double> x,y,ex,ey; while(1){ cout<<"\n\nEnter next file to process; <enter> to finish."<<endl; getline(cin, filename); if(filename=="") break; //load the tree TTree* Events = GetEventsTree(filename.c_str()); if(!Events) continue; gROOT->ProcessLine(".x analysis/Aliases.C"); double start = Events->GetMinimum("timestamp"); double end = Events->GetMaximum("timestamp"); double error = 0; TString title = TString("Na22 Spectrum, ") + TString(filename)(TRegexp("Run......")); TH1F* hist = new TH1F("Na22Spec",title,200,1000,2500); Events->Draw("sumspec >> Na22Spec","min > 0","e"); double yield = Fit511Photopeak(hist,&error); x.push_back((start+end)/2.); ex.push_back((end-start)/2.); y.push_back(yield); ey.push_back(error); } if(x.size() == 0){ cerr<<"No valid points found!"<<endl; return 0; } TGraphErrors* graph = new TGraphErrors(x.size(),&x[0],&y[0],&ex[0],&ey[0]); graph->Draw("ape"); TAxis* xax = graph->GetXaxis(); xax->SetTitle("Run Time"); xax->SetTimeDisplay(1); xax->SetTimeFormat("%Y/%m/%d"); xax->SetTimeOffset(1,"gmt"); TAxis* yax = graph->GetYaxis(); yax->SetTitle("511 keV Light Yield [pe/keV]"); graph->Draw("ape"); return graph; }
void drawEmptyHisto ( float Xmin, float Xmax, TString xTitle, float Ymin, float Ymax, TString yTitle, TString name ) { printf ( "Setting empty histo: X: %.2f-%.2f\tY: %.2f-%.2f\n",Xmin,Xmax,Ymin,Ymax ); printf("Total luminosity to be plotted: %.3f\n",Xmax); printf("Luminosity scale used: %.2f\n",lumiScale); Xmax*=1.02; // Increasing max lumi to have free space gStyle->SetOptStat ( 0 ); // TGaxis::SetMaxDigits ( 4 ); TH1F *histo = new TH1F ( name, xTitle, 1, Xmin, Xmax ); TAxis *xAx = histo->GetXaxis(); TAxis *yAx = histo->GetYaxis(); xAx->SetTitle ( xTitle ); // xAx->SetTitleOffset ( 1.1 ); // xAx->SetNdivisions ( 510 ); yAx->SetTitle ( yTitle ); // yAx->SetTitleOffset ( 1.15 ); // yAx->SetNdivisions ( 510 ); histo->SetMinimum ( Ymin ); histo->SetMaximum ( Ymax ); histo->Draw ( "AXIS" ); }
void SetAxisLabels(TH1& hist, char* xtitle, char* ytitle="", double xoffset=1.1, double yoffset=1.4) { TAxis* x = hist.GetXaxis(); TAxis* y = hist.GetYaxis(); x->SetTitle(xtitle); x->SetTitleSize(0.06); x->SetLabelSize(0.05); x->SetTitleOffset(xoffset); x->SetNdivisions(505); y->SetTitle(ytitle); y->SetTitleSize(0.06); y->SetLabelSize(0.05); y->SetTitleOffset(yoffset); y->SetNoExponent(); hist.SetLineWidth(2); hist.SetMarkerStyle(20); std::stringstream str; str << "Events / " << (int) lumi << " pb^{-1} "; std::string defYtitle = str.str(); if(ytitle=="") y->SetTitle( defYtitle.c_str() ); }
//------------------------------------------------------------------------------ // SetAxis //------------------------------------------------------------------------------ void SetAxis(TH1* hist, TString xtitle, TString ytitle, Float_t xoffset, Float_t yoffset) { gPad->cd(); gPad->Update(); // See https://root.cern.ch/doc/master/classTAttText.html#T4 Float_t padw = gPad->XtoPixel(gPad->GetX2()); Float_t padh = gPad->YtoPixel(gPad->GetY1()); Float_t size = (padw < padh) ? padw : padh; size = 20. / size; // Like this label size is always 20 pixels TAxis* xaxis = (TAxis*)hist->GetXaxis(); TAxis* yaxis = (TAxis*)hist->GetYaxis(); xaxis->SetTitleOffset(xoffset); yaxis->SetTitleOffset(yoffset); xaxis->SetLabelSize(size); yaxis->SetLabelSize(size); xaxis->SetTitleSize(size); yaxis->SetTitleSize(size); xaxis->SetTitle(xtitle); yaxis->SetTitle(ytitle); yaxis->CenterTitle(); gPad->GetFrame()->DrawClone(); gPad->RedrawAxis(); }
TH1p RootWriter::CreateTH1(Histogram1D* h) { const Axis& xax = h->GetAxisX(); const int channels = xax.GetBinCount(); TH1* r = new TH1I( h->GetName().c_str(), h->GetTitle().c_str(), channels, xax.GetLeft(), xax.GetRight() ); TAxis* rxax = r->GetXaxis(); rxax->SetTitle(xax.GetTitle().c_str()); rxax->SetTitleSize(0.03); rxax->SetLabelSize(0.03); TAxis* ryax = r->GetYaxis(); ryax->SetLabelSize(0.03); for(int i=0; i<channels+2; ++i) r->SetBinContent(i, h->GetBinContent(i)); r->SetEntries( h->GetEntries() ); return r; }
void drawBeamSpotPdfs (TDirectory* directory, const char* coord, const char* fname) { TH3* obsHisto = directory->Get("PVobs"); TH3* estHisto = directory->Get("PVest"); if ( obsHisto==0 || estHisto==0 ) return; std::string fullName("PV"); fullName += coord; if ( fname ) fullName += fname; else fullName += directory->GetName(); TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str()); c->SetLogy(true); TH1* obsHisto1D = obsHisto->Project3D(coord); TH1* estHisto1D = estHisto->Project3D(coord); TAxis* xaxis = obsHisto1D->GetXaxis(); string atitle("Primary vertex "); atitle += coord; atitle += " [cm]"; xaxis->SetTitle(atitle.c_str()); if ( c->GetLogy() ) obsHisto1D->SetMinimum(0.5); obsHisto1D->SetMarkerStyle(21); // obsHisto1D->SetLineColor(2); // obsHisto1D->SetMarkerColor(2); obsHisto1D->Draw("E0"); estHisto1D->SetLineColor(2); estHisto1D->SetLineWidth(2); estHisto1D->Draw("hist same c"); if ( strcmp(coord,"x") || strcmp(coord,"y") ) xaxis->SetNdivisions(508); string epsName = fullName + ".eps"; c->SaveAs(epsName.c_str()); string pngName = fullName + ".png"; c->SaveAs(pngName.c_str()); }
void LEPStyle::setHist() { _hist = new TH1F( "bidon", "bidon", 100, _xmin, _xmax ); _ax = _hist->GetXaxis(); _ay = _hist->GetYaxis(); _ax->SetTitle(_title); _ax->SetNdivisions(_ndivx); if( _logX ) { _ax->SetMoreLogLabels(); } _ax->SetLabelSize(_scale*0.060); // _ax->SetLabelOffset(_scale*0.007); _ax->SetTitleSize(_scale*0.070); _ax->SetTitleOffset(0.9); _ax->CenterTitle( _centerTitle ); _ay->SetNdivisions(0); }
void plot3(TString infile = "fp-d", TString pltmd = "cos") { // CHECK FOR RIGHT INPUT //////////////////////////////////////////////// string strpltmd = pltmd, filename = infile, strfile = infile; if( (strpltmd.compare("cos") != 0 ) && (strpltmd.compare("sin") != 0 ) && (strpltmd.compare("tan") != 0 ) && (strpltmd.compare("mmp") != 0 ) ) {error(4);}; // GLOBAL VARIABLES //////////////////////////////////////////////////// Int_t file, point, color, style; Float_t fits2b, fittph, tphold, fitsph, fitcph, fitx, fitxmin, fitxmax = -1.0; Float_t xVal, yVal; Float_t xMin = 100000, xMax = -1.0, yMin = 100000, yMax = -1.0; Float_t MZ, MW, Mmin = 100000; Float_t Cz1, Cz2, Cz3, Cw1, Cw2, Cw3, Cw4, C1, C2; Float_t phiMin, phiMax, cphmin, cphmax, sphmin, sphmax; // CUSTOMIZE PLOT /////////////////////////////////////////////////////// gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetTitleBorderSize(0); gStyle->SetPalette(1); TCanvas *MyC = new TCanvas("MyC","Plot of the GAPP fit results",200,10,700,500); Float_t mmlegxmin, mmlegxmax, mmlegymin, mmlegymax; Float_t s2blegxmin, s2blegymin, s2blegxmax, s2blegymax; Float_t lblxmin, lblxmax, lblymin, lblymax; string plottitle = "Model: " + infile + " | Plot: "; string xtitle, ytitle, NPleg, SMleg, display; NPleg = "#font[52]{M_{H}^{(NP)}, #bar{m}_{t}^{(NP)}}"; SMleg = "#font[52]{M_{H}^{(SM)}, #bar{m}_{t}^{(SM)}}"; if (strpltmd.compare("tan") == 0) { plottitle += "#font[42]{tan^{2}(#tilde{#phi}) over }#font[52]{#tilde{x}}#font[42]{.}"; xtitle = "#font[52]{#tilde{x}}"; ytitle = "#font[42]{tan^{2}(#tilde{#phi})}"; display = "C"; mmlegxmin = 0.15; mmlegxmax = 0.30; mmlegymin = 0.75; mmlegymax = 0.85; s2blegxmin = 0.15; s2blegxmax = 0.40; s2blegymin = 0.30; s2blegymax = 0.50; lblxmin = 0.88; lblxmax = 0.88; lblymin = 0.60; lblymax = 0.65; } else if (strpltmd.compare("cos") == 0) { plottitle += "#font[42]{cos(#tilde{#phi}) over }#font[52]{#tilde{x}}#font[42]{.}"; xtitle = "#font[52]{#tilde{x}}"; ytitle = "#font[42]{cos(#tilde{#phi})}"; display = "C"; mmlegxmin = 0.70; mmlegxmax = 0.85; mmlegymin = 0.75; mmlegymax = 0.85; s2blegxmin = 0.15; s2blegxmax = 0.40; s2blegymin = 0.30; s2blegymax = 0.50; lblxmin = 0.65; lblxmax = 0.80; lblymin = 0.60; lblymax = 0.65; } else if (strpltmd.compare("sin") == 0) { plottitle += "#font[42]{sin(#tilde{#phi}) over }#font[52]{#tilde{x}}#font[42]{.}"; xtitle = "#font[52]{#tilde{x}}"; ytitle = "#font[42]{sin(#tilde{#phi})}"; display = "C"; mmlegxmin = 0.15; mmlegxmax = 0.30; mmlegymin = 0.75; mmlegymax = 0.85; s2blegxmin = 0.60; s2blegxmax = 0.85; s2blegymin = 0.30; s2blegymax = 0.50; lblxmin = 0.65; lblxmax = 0.80; lblymin = 0.60; lblymax = 0.65; } else if (strpltmd.compare("mmp") == 0) { plottitle += "#font[42]{Masses of the new heavy gauge bosons.}"; xtitle = "#font[52]{M_{Z'}}#font[42]{ (TeV)}"; ytitle = "#font[52]{M_{W'}}#font[42]{ (TeV)}"; display = "C"; mmlegxmin = 0.15; mmlegxmax = 0.30; mmlegymin = 0.75; mmlegymax = 0.85; s2blegxmin = 0.60; s2blegxmax = 0.85; s2blegymin = 0.45; s2blegymax = 0.65; lblxmin = 0.35; lblxmax = 0.50; lblymin = 0.45; lblymax = 0.50; }; // PREPARE BOSON MASSES AND PHI BOUNDS ////////////////////////////////// string mdl(filename,0,2); if ( (mdl.compare("lr") == 0) || (mdl.compare("lp") == 0) || (mdl.compare("hp") == 0) || (mdl.compare("fp") == 0) ) { phiMin = 5.600; phiMax = 84.400; string Higgs(filename,3,1); if (Higgs.compare("d") == 0) { Cz1 = 11.95349795785275; Cz2 = 30.63269990028513; Cz3 = 42.58619785813789; Cw1 = 21.29309892906894; Cw2 = 9.339600971216193; Cw3 = 30.63269990028513; Cw4 = 42.58619785813789; } else if (Higgs.compare("t") == 0) { Cz1 = 5.976748978926375; Cz2 = 30.63269990028513; Cz3 = 85.17239571627579; Cw1 = 15.05649464522066; Cw2 = 3.302047590161717; Cw3 = 21.66058982554409; Cw4 = 60.22597858088265; } } else if ( (mdl.compare("uu") == 0) || (mdl.compare("nu") == 0) ) { phiMin = 10.179, phiMax = 79.821; C1 = 94.0397928463607; C2 = 77.1253849720165; } else {error(6);} cphmin = cos(TMath::Pi()*phiMin/180.0)*cos(TMath::Pi()*phiMin/180.0); cphmax = cos(TMath::Pi()*phiMax/180.0)*cos(TMath::Pi()*phiMax/180.0); sphmin = sin(TMath::Pi()*phiMin/180.0)*sin(TMath::Pi()*phiMin/180.0); sphmax = sin(TMath::Pi()*phiMax/180.0)*sin(TMath::Pi()*phiMax/180.0); // LOOP OVER ROOT FILES //////////////////////////////////////////////// for(file=0; file<=1; file++) { if(file==0) string epsfile = filename + "_" + strpltmd + ".eps"; if(file==1) string filename = filename + "_sm"; string rootname = filename + ".root"; TFile *rootfile = TFile::Open(rootname.c_str()); if(rootfile == NULL) error(1); TTree *tree = (TTree*)rootfile->Get(filename.c_str()); if(tree == NULL) error(2); TBranch *fits2bbranch = (TBranch*)tree->GetBranch("fits2b"); TBranch *fittphbranch = (TBranch*)tree->GetBranch("fittph"); TBranch *fitxbranch = (TBranch*)tree->GetBranch("fitx"); if( (fits2bbranch == NULL) || (fittphbranch == NULL) || (fitxbranch == NULL) ) error(3); tree->SetBranchAddress("fits2b",&fits2b); tree->SetBranchAddress("fittph",&fittph); tree->SetBranchAddress("fitx", &fitx); // GET ARRAYS /////////////////////////////////////////////////////////// Int_t Npoints = (Int_t)tree->GetEntries(); Int_t tphStep = 0; Float_t tphMax = -1.0; for(point=0; point<Npoints; point++) { tree->GetEntry(point); if( fittph > tphMax ) {tphStep++; tphMax = fittph;} }; const int tphSteps = tphStep; Float_t xArray[tphSteps], yArray[tphSteps], zArray[tphSteps]; tphStep = -1, tphold = -1.0, fitxmin = 100000; for(point=0; point<Npoints; point++) { tree->GetEntry(point); if(fittph > tphold) {tphStep++; fitxmin = 100000;} fitsph = fittph / (1.0 + fittph); fitcph = 1.0 - fitsph; if (strpltmd.compare("tan") == 0) { xVal = fitx; yVal = fittph; } else if (strpltmd.compare("cos") == 0) { xVal = fitx; yVal = sqrt(fitcph); } else if (strpltmd.compare("sin") == 0) { xVal = fitx; yVal = sqrt(fitsph); } else if (strpltmd.compare("mmp") == 0) { if (fitsph != 0.0) { if ( (mdl.compare("lr") == 0) || (mdl.compare("lp") == 0) || (mdl.compare("hp") == 0) || (mdl.compare("fp") == 0) ) { MMI(Cz1,Cz2,Cz3,Cw1,Cw2,Cw3,Cw4,fitx,fitsph,fitcph,fits2b,xVal,yVal); } else if ( (mdl.compare("uu") == 0) || (mdl.compare("nu") == 0) ) { MMII(C1,C2,fitx,fitsph,fitcph,xVal,yVal); } } } if( (strpltmd.compare("mmp") == 0) && (tphStep==1) ) { xArray[0] = xArray[1]; yArray[0] = yArray[1]; zArray[0] = zArray[1]; } if(fitx>fitxmax) fitxmax = fitx; if(fitx<fitxmin) { xArray[tphStep] = xVal; yArray[tphStep] = yVal; zArray[tphStep] = fits2b; fitxmin = fitx; } tphold = fittph; } if(file==0) TGraph *NPplot = new TGraph(tphSteps,xArray,yArray); if(file==1) TGraph *SMplot = new TGraph(tphSteps,xArray,yArray); TMarker *NPmrk[tphSteps], *SMmrk[tphSteps]; for(tphStep=0; tphStep<tphSteps; tphStep++){ marker(zArray[tphStep],color,style); if(file==0) { NPmrk[tphStep] = new TMarker(xArray[tphStep],yArray[tphStep],style); NPmrk[tphStep]->SetMarkerSize(0.8); NPmrk[tphStep]->SetMarkerColor(color);} if(file==1) { SMmrk[tphStep] = new TMarker(xArray[tphStep],yArray[tphStep],style); SMmrk[tphStep]->SetMarkerSize(0.8); SMmrk[tphStep]->SetMarkerColor(color);} if( (strpltmd.compare("mmp") != 0) || (tphStep !=0 )) { if (xArray[tphStep] < xMin) xMin = xArray[tphStep]; if (xArray[tphStep] > xMax) xMax = xArray[tphStep]; if (yArray[tphStep] < yMin) yMin = yArray[tphStep]; if (yArray[tphStep] > yMax) yMax = yArray[tphStep]; } if( ((strfile.compare("uu-d") == 0) || (strfile.compare("nu-d") == 0)) && (strpltmd.compare("sin") == 0) ) { fitx = xArray[tphStep]; fitsph = yArray[tphStep]*yArray[tphStep]; fitcph = 1.0 - fitsph; if( (sphmin < fitsph) && (fitsph<sphmax) ) { MMII(C1,C2,fitx,fitsph,fitcph,MZ,MW); if(MZ < Mmin) { Mmin = MZ; cout << MZ << "\t" << sqrt(fitsph) << endl;} } } } } // CREATE PLOTS ///////////////////////////////////////////////////////// NPplot->SetLineStyle(2); NPplot->SetMarkerStyle(20); NPplot->SetMarkerSize(0.4); SMplot->SetMarkerStyle(20); SMplot->SetMarkerSize(0.4); if(strpltmd.compare("cos") == 0) {yMin = 0.0; yMax = 1.0;} if(strpltmd.compare("sin") == 0) {yMin = 0.0; yMax = 1.0;} if(strpltmd.compare("mmp") == 0) {xMin = 0.0; xMax = 5.0; yMin = 0.0; yMax = 5;} TH1F* frame = MyC->DrawFrame(0.9*xMin,0.9*yMin,1.1*xMax,1.0*yMax); frame->SetTitle(plottitle.c_str()); TAxis *xaxis = frame->GetXaxis(); TAxis *yaxis = frame->GetYaxis(); xaxis->SetTitle(xtitle.c_str()); xaxis->CenterTitle(); xaxis->SetTitleOffset(1.); xaxis->SetDecimals(); xaxis->SetLabelSize(0.03); xaxis->SetLabelOffset(0.01); yaxis->SetTitle(ytitle.c_str()); yaxis->CenterTitle(); yaxis->SetTitleOffset(1.2); yaxis->SetDecimals(); yaxis->SetLabelSize(0.03); yaxis->SetLabelOffset(0.01); TLegend *mmleg = new TLegend(mmlegxmin,mmlegymin,mmlegxmax,mmlegymax); mmleg->AddEntry(NPplot,NPleg.c_str(),"l"); mmleg->AddEntry(SMplot,SMleg.c_str(),"l"); mmleg->SetTextSize(0.025); mmleg->SetFillStyle(0); if( (strfile.compare("uu-d") != 0) && (strfile.compare("nu-d") != 0) ) { for(tphStep=0; tphStep<tphSteps; tphStep++){NPmrk[tphStep]->Draw(); SMmrk[tphStep]->Draw();} } Float_t xdummy[1] = {0.0}, ydummy[1] = {0.0}; TGraph *circle = new TGraph(1,xdummy,ydummy); circle->SetMarkerStyle(24); circle->SetMarkerColor(kGreen+1); circle->SetMarkerSize(0.8); TGraph *square = new TGraph(1,xdummy,ydummy); square->SetMarkerStyle(25); square->SetMarkerColor(kCyan+1); square->SetMarkerSize(0.8); TGraph *triangle = new TGraph(1,xdummy,ydummy); triangle->SetMarkerStyle(26); triangle->SetMarkerColor(kBlue+1); triangle->SetMarkerSize(0.8); TGraph *diamond = new TGraph(1,xdummy,ydummy); diamond->SetMarkerStyle(27); diamond->SetMarkerColor(kMagenta+1); diamond->SetMarkerSize(0.8); TLegend *s2bleg = new TLegend(s2blegxmin,s2blegymin,s2blegxmax,s2blegymax); s2bleg->AddEntry(circle,"#font[42]{0.00 < sin^{2}(2#tilde{#beta}) #leq 0.25}","p"); s2bleg->AddEntry(square,"#font[42]{0.25 < sin^{2}(2#tilde{#beta}) #leq 0.50}","p"); s2bleg->AddEntry(triangle,"#font[42]{0.50 < sin^{2}(2#tilde{#beta}) #leq 0.75}","p"); s2bleg->AddEntry(diamond,"#font[42]{0.75 < sin^{2}(2#tilde{#beta}) #leq 1.00}","p"); s2bleg->SetTextSize(0.025); s2bleg->SetFillStyle(0); NPplot->Draw(display.c_str()); SMplot->Draw(display.c_str()); mmleg->Draw(); if( (strfile.compare("uu-d") != 0) && (strfile.compare("nu-d") != 0) ) s2bleg->Draw(); // BOUNDS ON PHI ////////////////////////////////////////////////////// Int_t i; const int iSteps = 100; fitxmin = 1.0, fitxmax *= 1.5; Float_t deltax = (fitxmax-fitxmin)/iSteps; Float_t phixmin0[iSteps], phixmax0[iSteps], phixmin1[iSteps], phixmax1[iSteps]; Float_t phiymin0[iSteps], phiymax0[iSteps], phiymin1[iSteps], phiymax1[iSteps]; if ( (strpltmd.compare("tan") == 0) || (strpltmd.compare("cos") == 0) || (strpltmd.compare("sin") == 0) ) { for(i=0; i<100; i++) { fitx = fitxmin + i*deltax; phixmin0[i] = fitx; if (strpltmd.compare("tan") == 0) { phiymin0[i] = sphmin / cphmin; phiymax0[i] = sphmax / cphmax; } if (strpltmd.compare("cos") == 0) { phiymin0[i] = sqrt(cphmin); phiymax0[i] = sqrt(cphmax); } if (strpltmd.compare("sin") == 0) { phiymin0[i] = sqrt(sphmin); phiymax0[i] = sqrt(sphmax); } } TGraph *phiMin0 = new TGraph(iSteps,phixmin0,phiymin0); TGraph *phiMax0 = new TGraph(iSteps,phixmin0,phiymax0); } else if (strpltmd.compare("mmp") == 0) { if ( (mdl.compare("lr") == 0) || (mdl.compare("lp") == 0) || (mdl.compare("hp") == 0) || (mdl.compare("fp") == 0) ) { for(i=0; i<100; i++) { fitx = fitxmin + i*deltax; MMI(Cz1,Cz2,Cz3,Cw1,Cw2,Cw3,Cw4,fitx,sphmin,cphmin,0.0,phixmin0[i],phiymin0[i]); MMI(Cz1,Cz2,Cz3,Cw1,Cw2,Cw3,Cw4,fitx,sphmin,cphmin,1.0,phixmin1[i],phiymin1[i]); MMI(Cz1,Cz2,Cz3,Cw1,Cw2,Cw3,Cw4,fitx,sphmax,cphmax,0.0,phixmax0[i],phiymax0[i]); MMI(Cz1,Cz2,Cz3,Cw1,Cw2,Cw3,Cw4,fitx,sphmax,cphmax,1.0,phixmax1[i],phiymax1[i]); } TGraph *phiMin0 = new TGraph(iSteps,phixmin0,phiymin0); TGraph *phiMin1 = new TGraph(iSteps,phixmin1,phiymin1); TGraph *phiMax0 = new TGraph(iSteps,phixmax0,phiymax0); TGraph *phiMax1 = new TGraph(iSteps,phixmax1,phiymax1); phiMin1->SetLineStyle(7); phiMin1->SetMarkerStyle(22); phiMin1->SetMarkerSize(1.0); phiMax1->SetLineStyle(7); phiMax1->SetMarkerStyle(22); phiMax1->SetMarkerSize(1.0); phiMin1->Draw("C"); phiMax1->Draw("C"); } else if ( (mdl.compare("uu") == 0) || (mdl.compare("nu") == 0) ) { for(i=0; i<100; i++) { fitx = fitxmin + i*deltax; MMII(C1,C2,fitx,sphmin,cphmin,phixmin0[i],phiymin0[i]); MMII(C1,C2,fitx,sphmax,cphmax,phixmax0[i],phiymax0[i]); } TGraph *phiMin0 = new TGraph(iSteps,phixmin0,phiymin0); TGraph *phiMax0 = new TGraph(iSteps,phixmax0,phiymax0); } } phiMin0->SetLineStyle(3); phiMin0->SetMarkerStyle(20); phiMin0->SetMarkerSize(0.4); phiMax0->SetLineStyle(3); phiMax0->SetMarkerStyle(20); phiMax0->SetMarkerSize(0.4); phiMin0->Draw("C"); phiMax0->Draw("C"); // LABEL ALLOWED REGION /////////////////////////////////////////////// TPaveText *allowed = new TPaveText(lblxmin,lblymin,lblxmax,lblymax,"NDC"); TText *text = allowed->AddText("#font[42]{allowed (95% CL)}"); allowed->SetTextSize(0.04); if (strpltmd.compare("tan") == 0) text->SetTextAngle(270); allowed->SetFillStyle(0); allowed->SetLineColor(0); allowed->SetBorderSize(1); allowed->Draw(); // SAVE GRAPHIC /////////////////////////////////////////////////////// MyC->Print(epsfile.c_str()); }
void SampleDiagnostics::write() const { if (passedRate == 0) { std::cerr << "WARNING : No accumulated rate for " << name << ". Maybe you just didn't run over it/them?" << std::endl; return; } //.. Histogram output ....................................................... const Int_t numDatasets = static_cast<Int_t>(size()); const UInt_t numBins = numDatasets + 3; TH2* hCorrelation = new TH2F("h_correlation_" + name, name, numBins, 0, numBins, numBins, 0, numBins); TH2* hSharedRate = new TH2F("h_shared_rate_" + name, name, numBins, 0, numBins, numBins, 0, numBins); //........................................................................... Double_t overhead = 0; Double_t overheadErr = 0; for (Int_t iSet = 0, xBin = 1; iSet < numDatasets; ++iSet, ++xBin) { const Dataset& dataset = at(iSet); if (!dataset.isNewTrigger) { overhead += dataset.rate; overheadErr += dataset.rateUncertainty2; // I think this is over-estimating it because the values are NOT uncorrelated, but oh well } if (iSet == firstNewTrigger) ++xBin; if (dataset.rate == 0) continue; for (Int_t jSet = 0, yBin = 1; jSet <= numDatasets; ++jSet, ++yBin) { if (jSet == firstNewTrigger) ++yBin; if (jSet == numDatasets) ++yBin; hCorrelation->SetBinContent (xBin, yBin, commonRates[iSet][jSet] / dataset.rate); hCorrelation->SetBinError (xBin, yBin, ratioError(commonRates[iSet][jSet], commonRateUncertainties2[iSet][jSet], dataset.rate, dataset.rateUncertainty2)); hSharedRate ->SetBinContent (xBin, yBin, commonRates[iSet][jSet]); hSharedRate ->SetBinError (xBin, yBin, TMath::Sqrt(commonRateUncertainties2[iSet][jSet])); } // end loop over other datasets // Rightmost column is the fraction of rate out of the total hCorrelation->SetBinContent (numBins, xBin, dataset.rate / passedRate); hCorrelation->SetBinError (numBins, xBin, ratioError(dataset.rate, dataset.rateUncertainty2, passedRate, passedRateUncertainty2)); hSharedRate ->SetBinContent (numBins, xBin, dataset.rate); hSharedRate ->SetBinError (numBins, xBin, TMath::Sqrt(dataset.rateUncertainty2)); } // end loop over datasets // Top-right cell is the total overhead for the _current_ datasets (not including new triggers) hSharedRate ->SetBinContent (numBins, numBins, overhead); hSharedRate ->SetBinError (numBins, numBins, TMath::Sqrt(overheadErr)); overheadErr = ratioError (overhead, overheadErr, passedRate, passedRateUncertainty2); overhead /= passedRate; // Can only do this after error is computed overhead -= 1; hCorrelation->SetBinContent (numBins, numBins, overhead); hCorrelation->SetBinError (numBins, numBins, overheadErr); //........................................................................... // Histogram format hCorrelation->SetTitle (TString::Format("%s (overhead = %.3g%% #pm %.3g%%)" , hCorrelation->GetTitle(), 100*overhead, 100*overheadErr)); hSharedRate ->SetTitle (TString::Format("%s (total rate = %.3g #pm %.3g Hz)", hSharedRate ->GetTitle(), passedRate, TMath::Sqrt(passedRateUncertainty2))); hCorrelation->SetZTitle ("(X #cap Y) / X"); hSharedRate->SetZTitle ("X #cap Y"); hCorrelation->SetOption ("colz"); hSharedRate->SetOption ("colz"); hCorrelation->SetStats (kFALSE); hSharedRate->SetStats (kFALSE); hCorrelation->SetMinimum(0); hSharedRate->SetMinimum(0); hCorrelation->SetMaximum(1); std::vector<TAxis*> axes; axes.push_back(hCorrelation->GetXaxis()); axes.push_back(hCorrelation->GetYaxis()); axes.push_back(hSharedRate ->GetXaxis()); axes.push_back(hSharedRate ->GetYaxis()); const UInt_t numAxes = axes.size(); for (UInt_t iAxis = 0; iAxis < numAxes; ++iAxis) { TAxis* axis = axes[iAxis]; for (Int_t iSet = 0, bin = 1; iSet < numDatasets; ++iSet, ++bin) { if (iSet == firstNewTrigger) ++bin; axis->SetBinLabel(bin, at(iSet).name); } // end loop over datasets axis->SetLabelSize (0.04f); axis->LabelsOption ("v"); axis->SetTitle (iAxis % 2 == 0 ? "X" : "Y"); } // end loop over axes to format hCorrelation->GetXaxis()->SetBinLabel(numBins, "rate / total"); hCorrelation->GetYaxis()->SetBinLabel(numBins, "overlap / rate"); hSharedRate ->GetXaxis()->SetBinLabel(numBins, "rate"); hSharedRate ->GetYaxis()->SetBinLabel(numBins, "overlap"); if (gDirectory->GetDirectory("unnormalized") == 0) gDirectory->mkdir("unnormalized"); gDirectory->cd("unnormalized"); hSharedRate ->Write(); gDirectory->cd("/"); hCorrelation->Write(); //........................................................................... }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // drawFigure7 // // parameter = "dg0" // parameter = "lam0" // parameter = "dk0" // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void drawFigure7(TString parameter = "dk0") { gInterpreter->ExecuteMacro("WZPaperStyle.C"); gSystem->mkdir("pdf", kTRUE); gSystem->mkdir("png", kTRUE); // Individual settings //---------------------------------------------------------------------------- if (parameter.Contains("dg0")) { xtitle = "#Delta#kappa^{Z}"; ytitle = "#lambda"; xmin = -0.5; xmax = 0.5; ymin = -0.039; ymax = 0.053; } else if (parameter.Contains("lam0")) { xtitle = "#Delta#kappa^{Z}"; ytitle = "#Deltag^{Z}_{1}"; xmin = -0.53; xmax = 0.53; ymin = -0.05; ymax = 0.09; } else if (parameter.Contains("dk0")) { xtitle = "#Deltag^{Z}_{1}"; ytitle = "#lambda"; xmin = -0.059; xmax = 0.059; ymin = -0.037; ymax = 0.052; } // Read the input file //---------------------------------------------------------------------------- TFile* file = new TFile("rootfiles/contours_" + parameter + "_2Dpol2.root", "read"); TGraph* cont_exp_68 = (TGraph*)file->Get("cont_exp_68"); TGraph* cont_exp_95 = (TGraph*)file->Get("cont_exp_95"); TGraph* cont_exp_99 = (TGraph*)file->Get("cont_exp_99"); TGraph* cont_obs_95 = (TGraph*)file->Get("cont_obs_95"); TGraph* bestFit = (TGraph*)file->Get("bestFit"); bestFit->SetMarkerSize(1.5); bestFit->SetMarkerStyle(34); TGraph* g_large = new TGraph(2); g_large->SetPoint(0, -1.0, 1.0); g_large->SetPoint(1, 1.0, 1.0); // Draw //---------------------------------------------------------------------------- TCanvas* canvas = new TCanvas("canvas", "canvas"); TMultiGraph* mg = new TMultiGraph(); mg->Add(cont_exp_68); mg->Add(cont_exp_95); mg->Add(cont_exp_99); mg->Add(cont_obs_95); mg->Add(bestFit, "p"); mg->Add(g_large); mg->Draw("ac"); mg->SetMinimum(ymin); mg->SetMaximum(ymax); // Axis labels //---------------------------------------------------------------------------- TAxis* xaxis = mg->GetXaxis(); TAxis* yaxis = mg->GetYaxis(); xaxis->SetLabelFont ( 42); xaxis->SetLabelOffset( 0.01); xaxis->SetLabelSize ( 0.05); xaxis->SetNdivisions ( 505); xaxis->SetTitle (xtitle); xaxis->SetTitleFont ( 42); xaxis->SetTitleOffset( 1.2); xaxis->SetTitleSize ( 0.05); xaxis->SetLimits(xmin, xmax); yaxis->SetLabelFont ( 42); yaxis->SetLabelOffset( 0.01); yaxis->SetLabelSize ( 0.05); yaxis->SetNdivisions ( 505); yaxis->SetTitle (ytitle); yaxis->SetTitleFont ( 42); yaxis->SetTitleOffset( 1.6); yaxis->SetTitleSize ( 0.05); canvas->Modified(); // Legend //---------------------------------------------------------------------------- Double_t x0 = 0.580; Double_t y0 = 0.755; DrawTLegend(x0 - 0.36, y0 + 2.*(_yoffset+0.001), (TH1F*)cont_exp_68, " Expected 68% CL", "l"); DrawTLegend(x0 - 0.36, y0 + 1.*(_yoffset+0.001), (TH1F*)cont_exp_95, " Expected 95% CL", "l"); DrawTLegend(x0, y0 + 2.*(_yoffset+0.001), (TH1F*)cont_exp_99, " Expected 99% CL", "l"); DrawTLegend(x0, y0 + 1.*(_yoffset+0.001), (TH1F*)cont_obs_95, " Observed 95% CL", "l"); DrawTLegend(x0, y0, (TH1F*)bestFit, " Best fit", "p"); // Finish it //---------------------------------------------------------------------------- DrawTLatex(_cmsTextFont, 0.190, 0.94, 0.055, 11, "CMS"); // DrawTLatex(_extraTextFont, 0.315, 0.94, 0.030, 11, "Preliminary"); DrawTLatex(_lumiTextFont, 0.940, 0.94, 0.040, 31, "19.6 fb^{-1} (8 TeV)"); canvas->SaveAs("pdf/lZ_dkg_2dlimit_" + parameter + "_2Dpol2_deltaNLL.pdf"); canvas->SaveAs("png/lZ_dkg_2dlimit_" + parameter + "_2Dpol2_deltaNLL.png"); }
void makeTable( int num ) { // TString rootfilename; // if(num<9) rootfilename = Form("root_electroneff_%d_eta_et.root", num); // else if(num<17) rootfilename = Form("root_electroneff_10%d_eta_et.root", num-8); // else if(num<25) rootfilename = Form("root_electroneff_20%d_eta_et.root", num-16); // else if(num<33) rootfilename = Form("root_electroneff_30%d_eta_et.root", num-24); // else rootfilename = Form("root_electroneff_40%d_eta_et.root", num-32); TString rootfilename; if(num==0) rootfilename = "root_electroneff_WenuOff_eta_et.root"; if(num==1) rootfilename = "root_electroneff_WenuOn_eta_et.root"; if(num==2) rootfilename = "root_electroneff_ZeeOff_eta_et.root"; if(num==3) rootfilename = "root_electroneff_ZeeOn_eta_et.root"; TString pname = ""; if(num==0) pname = "WenuOff-"; if(num==1) pname = "WenuOn-"; if(num==2) pname = "ZeeOff-"; if(num==3) pname = "ZeeOn-"; // if(num==1) pname = "WenuSelection-A1"; // if(num==2) pname = "WenuSelection-A2"; // if(num==3) pname = "WenuSelection-A3"; // if(num==4) pname = "WenuSelection-B1"; // if(num==5) pname = "WenuSelection-B2"; // if(num==6) pname = "WenuSelection-B3"; // if(num==7) pname = "ZeeSelection-A"; // if(num==8) pname = "ZeeSelection-B"; // if(num==9) pname = "WenuSelection-A1-noId-"; // if(num==10) pname = "WenuSelection-A2-noId-"; // if(num==11) pname = "WenuSelection-A3-noId-"; // if(num==12) pname = "WenuSelection-B1-noId-"; // if(num==13) pname = "WenuSelection-B2-noId-"; // if(num==14) pname = "WenuSelection-B3-noId-"; // if(num==15) pname = "ZeeSelection-A-noId-"; // if(num==16) pname = "ZeeSelection-B-noId-"; // if(num==17) pname = "WenuSelection-A1-noTrackIso-"; // if(num==18) pname = "WenuSelection-A2-noTrackIso-"; // if(num==19) pname = "WenuSelection-A3-noTrackIso-"; // if(num==20) pname = "WenuSelection-B1-noTrackIso-"; // if(num==21) pname = "WenuSelection-B2-noTrackIso-"; // if(num==22) pname = "WenuSelection-B3-noTrackIso-"; // if(num==23) pname = "ZeeSelection-A-noTrackIso-"; // if(num==24) pname = "ZeeSelection-B-noTrackIso-"; // if(num==25) pname = "WenuSelection-A1-noIso-"; // if(num==26) pname = "WenuSelection-A2-noIso-"; // if(num==27) pname = "WenuSelection-A3-noIso-"; // if(num==28) pname = "WenuSelection-B1-noIso-"; // if(num==29) pname = "WenuSelection-B2-noIso-"; // if(num==30) pname = "WenuSelection-B3-noIso-"; // if(num==31) pname = "ZeeSelection-A-noIso-"; // if(num==32) pname = "ZeeSelection-B-noIso-"; // if(num==33) pname = "WenuSelection-A1-noSigmaEtaEta-"; // if(num==34) pname = "WenuSelection-A2-noSigmaEtaEta-"; // if(num==35) pname = "WenuSelection-A3-noSigmaEtaEta-"; // if(num==36) pname = "WenuSelection-B1-noSigmaEtaEta-"; // if(num==37) pname = "WenuSelection-B2-noSigmaEtaEta-"; // if(num==38) pname = "WenuSelection-B3-noSigmaEtaEta-"; // if(num==39) pname = "ZeeSelection-A-noSigmaEtaEta-"; // if(num==40) pname = "ZeeSelection-B-noSigmaEtaEta-"; TString label = TString("electroneff-") + pname; gROOT->ProcessLine(".L tdrstyleNew.C"); setTDRStyle(); tdrStyle->SetPadLeftMargin(0.16); tdrStyle->SetPadRightMargin(0.1); tdrStyle->SetPadTopMargin(0.08); tdrStyle->SetLegendBorderSize(0); TFile* myhistos = new TFile(rootfilename); TH1F* h0 = (TH1F*) myhistos->Get("sbs_eff_EtDet"); TH1F* h1 = (TH1F*) myhistos->Get("sbs_eff_EtaDet"); TH2F* h2 = (TH2F*) myhistos->Get("sbs_eff_EtDet_EtaDet"); // TH1F *base = (TH1F*)f.Get("base"); // TH1F *destination = (TH1F*)f.Get("destination"); // TGraphAsymmErrors *g1 = new TGraphAsymmErrors(); // g1->BayesDivide(destination, base, ""); // g1->GetYaxis()->SetRangeUser(0.5, 1.05); h0->SetMarkerStyle(20); h1->SetMarkerStyle(20); ScaleTo10pb( *h0 ); ScaleTo10pb( *h1 ); // TH1F* h01 = (TH1F*) myhistos->Get("fit_eff_Et"); // TH1F* h11 = (TH1F*) myhistos->Get("fit_eff_Eta"); // h01->SetMarkerColor(4); // h01->SetLineColor(4); // h11->SetMarkerColor(4); // h11->SetLineColor(4); // ScaleTo10pb( *h01 ); // ScaleTo10pb( *h11 ); TH1F* h02 = (TH1F*) myhistos->Get("truth_eff_EtDet"); TH1F* h12 = (TH1F*) myhistos->Get("truth_eff_EtaDet"); h02->SetMarkerColor(2); h02->SetLineColor(2); h02->SetMarkerStyle(24); h12->SetMarkerColor(2); h12->SetLineColor(2); h12->SetMarkerStyle(24); ScaleTo10pb( *h02 ); ScaleTo10pb( *h12 ); TAxis* xaxis = h0->GetXaxis(); TAxis* yaxis = h0->GetYaxis(); xaxis->SetTitle("E_{T} (GeV)"); xaxis->SetTitleSize(0.04); xaxis->SetTitleOffset(1.3); xaxis->SetNdivisions(505); yaxis->SetTitle("Efficiency "); yaxis->SetTitleSize(0.04); yaxis->SetTitleOffset(1.6); h0->SetMinimum(0.5); h0->SetMaximum(1.1); TAxis* xaxis = h1->GetXaxis(); TAxis* yaxis = h1->GetYaxis(); xaxis->SetTitle("#eta"); xaxis->SetTitleSize(0.04); xaxis->SetTitleOffset(1.3); xaxis->SetNdivisions(505); yaxis->SetTitle("Efficiency "); yaxis->SetTitleSize(0.04); yaxis->SetTitleOffset(1.6); h1->SetMinimum(0.5); h1->SetMaximum(1.1); TAxis* xaxis = h2->GetXaxis(); TAxis* yaxis = h2->GetYaxis(); xaxis->SetTitle("E_{T} (GeV)"); xaxis->SetTitleSize(0.04); xaxis->SetTitleOffset(1.3); xaxis->SetNdivisions(505); yaxis->SetTitle("#eta "); yaxis->SetTitleSize(0.04); yaxis->SetTitleOffset(1.7); double l1 = 0.2, l2 =0.3; double p1 = 0.5; if(num==0) p1 = 0.82; if(num==2) p1 = 0.4; TCanvas* can0 = new TCanvas("can0", "", 500, 500); gStyle->SetOptStat(0); h0->Draw("e"); // h01->Draw("esame"); h02->Draw("esame"); leg_hist = new TLegend(0.3, l1, 0.8, l2); leg_hist->AddEntry( h0,"Sideband subtracted","P"); // leg_hist->AddEntry( h01,"fit","le"); leg_hist->AddEntry( h02,"Monte Carlo truth","P"); leg_hist->SetFillColor(0); leg_hist->SetMargin(0.15); leg_hist->Draw(); TLatex* CMS = new TLatex(); CMS->SetTextAlign(12); CMS->SetTextSize(0.04); CMS->SetNDC(); CMS->DrawLatex(0.25, p1, "CMS Preliminary, #intLdt = 10 pb^{-1}"); can0->Update(); can0->SaveAs( label+TString("et.eps") ); can0->SaveAs( label+TString("et.gif") ); can0->SaveAs( label+TString("et.root") ); can0->SaveAs( label+TString("et.pdf") ); p1 = 0.5; if(num==0 || num==2) p1 = 0.82; TCanvas* can1 = new TCanvas("can1", "", 500, 500); gStyle->SetOptStat(0); h1->Draw("e"); // h11->Draw("esame"); h12->Draw("esame"); leg_hist = new TLegend(0.3,l1,0.8,l2); leg_hist->AddEntry( h1,"Sideband subtracted","P"); // leg_hist->AddEntry( h11,"fit","le"); leg_hist->AddEntry( h12,"Monte Carlo truth","P"); leg_hist->SetFillColor(0); leg_hist->SetMargin(0.15); leg_hist->Draw(); TLatex* CMS2 = new TLatex(); CMS2->SetTextAlign(12); CMS2->SetTextSize(0.04); CMS2->SetNDC(); CMS2->DrawLatex(0.25,p1,"CMS Preliminary, #intLdt = 10 pb^{-1}"); can1->Update(); can1->SaveAs( label+TString("eta.eps") ); can1->SaveAs( label+TString("eta.gif") ); can1->SaveAs( label+TString("eta.root") ); can1->SaveAs( label+TString("eta.pdf") ); tdrStyle->SetPadRightMargin(0.2); TCanvas* can2 = new TCanvas("can2", "", 500, 500); gStyle->SetOptStat(0); h2->Draw("colz"); can2->SaveAs( label+TString("et_eta.eps") ); can2->SaveAs( label+TString("et_eta.gif") ); can2->SaveAs( label+TString("et_eta.root") ); can2->SaveAs( label+TString("et_eta.pdf") ); delete can0; delete can1; delete can2; delete myhistos; }
void showGraphs(const TString& title, double canvasSizeX, double canvasSizeY, TGraph* graph1, const std::string& legendEntry1, TGraph* graph2, const std::string& legendEntry2, TGraph* graph3, const std::string& legendEntry3, TGraph* graph4, const std::string& legendEntry4, TGraph* graph5, const std::string& legendEntry5, TGraph* graph6, const std::string& legendEntry6, double xMin, double xMax, unsigned numBinsX, const std::string& xAxisTitle, double xAxisOffset, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, double legendX0, double legendY0, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.12); canvas->SetBottomMargin(0.12); int colors[6] = { 1, 2, 3, 4, 6, 7 }; int markerStyles[6] = { 22, 32, 20, 24, 21, 25 }; TLegend* legend = new TLegend(legendX0, legendY0, legendX0 + 0.44, legendY0 + 0.20, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", numBinsX, xMin, xMax); dummyHistogram->SetTitle(""); dummyHistogram->SetStats(false); dummyHistogram->SetMinimum(yMin); dummyHistogram->SetMaximum(yMax); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(xAxisOffset); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(yAxisOffset); dummyHistogram->Draw("axis"); graph1->SetLineColor(colors[0]); graph1->SetLineWidth(2); graph1->Draw("L"); legend->AddEntry(graph1, legendEntry1.data(), "l"); if ( graph2 ) { graph2->SetLineColor(colors[1]); graph2->SetLineWidth(2); graph2->Draw("L"); legend->AddEntry(graph2, legendEntry2.data(), "l"); } if ( graph3 ) { graph3->SetLineColor(colors[2]); graph3->SetLineWidth(2); graph3->Draw("L"); legend->AddEntry(graph3, legendEntry3.data(), "l"); } if ( graph4 ) { graph4->SetLineColor(colors[3]); graph4->SetLineWidth(2); graph4->Draw("L"); legend->AddEntry(graph4, legendEntry4.data(), "l"); } if ( graph5 ) { graph5->SetLineColor(colors[4]); graph5->SetLineWidth(2); graph5->Draw("L"); legend->AddEntry(graph5, legendEntry5.data(), "l"); } if ( graph6 ) { graph6->SetLineColor(colors[5]); graph6->SetLineWidth(2); graph6->Draw("L"); legend->AddEntry(graph6, legendEntry6.data(), "l"); } legend->Draw(); TPaveText* label = 0; if ( title.Length() > 0 ) { label = new TPaveText(0.175, 0.925, 0.48, 0.98, "NDC"); label->AddText(title.Data()); label->SetTextAlign(13); label->SetTextSize(0.045); label->SetFillStyle(0); label->SetBorderSize(0); label->Draw(); } canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete legend; delete label; delete dummyHistogram; delete canvas; }
//------------------------------------------------------------------------------- void showDistribution(const TString& title, double canvasSizeX, double canvasSizeY, TH1* histogram1, const std::string& legendEntry1, TH1* histogram2, const std::string& legendEntry2, TH1* histogram3, const std::string& legendEntry3, TH1* histogram4, const std::string& legendEntry4, const std::string& xAxisTitle, double xAxisOffset, bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, double legendX0, double legendY0, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.12); canvas->SetBottomMargin(0.12); canvas->SetLogy(useLogScale); int colors[6] = { 1, 2, 3, 4, 6, 7 }; int markerStyles[6] = { 22, 32, 20, 24, 21, 25 }; int numHistograms = 1; if ( histogram2 ) ++numHistograms; if ( histogram3 ) ++numHistograms; if ( histogram4 ) ++numHistograms; TLegend* legend = new TLegend(legendX0, legendY0, legendX0 + 0.44, legendY0 + 0.05*numHistograms, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); histogram1->SetTitle(""); histogram1->SetStats(false); histogram1->SetMinimum(yMin); histogram1->SetMaximum(yMax); histogram1->SetLineColor(colors[0]); histogram1->SetLineWidth(2); histogram1->SetMarkerColor(colors[0]); histogram1->SetMarkerStyle(markerStyles[0]); histogram1->Draw("e1p"); legend->AddEntry(histogram1, legendEntry1.data(), "p"); TAxis* xAxis = histogram1->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(xAxisOffset); TAxis* yAxis = histogram1->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(yAxisOffset); if ( histogram2 ) { histogram2->SetLineColor(colors[1]); histogram2->SetLineWidth(2); histogram2->SetMarkerColor(colors[1]); histogram2->SetMarkerStyle(markerStyles[1]); histogram2->Draw("e1psame"); legend->AddEntry(histogram2, legendEntry2.data(), "p"); } if ( histogram3 ) { histogram3->SetLineColor(colors[2]); histogram3->SetLineWidth(2); histogram3->SetMarkerColor(colors[2]); histogram3->SetMarkerStyle(markerStyles[2]); histogram3->Draw("e1psame"); legend->AddEntry(histogram3, legendEntry3.data(), "p"); } if ( histogram4 ) { histogram4->SetLineColor(colors[3]); histogram4->SetLineWidth(2); histogram4->SetMarkerColor(colors[3]); histogram4->SetMarkerStyle(markerStyles[3]); histogram4->Draw("e1psame"); legend->AddEntry(histogram4, legendEntry4.data(), "p"); } legend->Draw(); TPaveText* label = 0; if ( title.Length() > 0 ) { label = new TPaveText(0.175, 0.925, 0.48, 0.98, "NDC"); label->AddText(title.Data()); label->SetTextAlign(13); label->SetTextSize(0.045); label->SetFillStyle(0); label->SetBorderSize(0); label->Draw(); } canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete legend; delete label; delete canvas; }
void showEfficiency(const TString& title, double canvasSizeX, double canvasSizeY, const TH1* histogram1_numerator, const TH1* histogram1_denominator, const std::string& legendEntry1, const TH1* histogram2_numerator, const TH1* histogram2_denominator, const std::string& legendEntry2, const TH1* histogram3_numerator, const TH1* histogram3_denominator, const std::string& legendEntry3, const TH1* histogram4_numerator, const TH1* histogram4_denominator, const std::string& legendEntry4, const TH1* histogram5_numerator, const TH1* histogram5_denominator, const std::string& legendEntry5, const TH1* histogram6_numerator, const TH1* histogram6_denominator, const std::string& legendEntry6, const std::string& xAxisTitle, double xAxisOffset, bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, double legendX0, double legendY0, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.12); canvas->SetBottomMargin(0.12); canvas->SetLogy(useLogScale); canvas->SetGridx(); canvas->SetGridy(); TH1* dummyHistogram = new TH1D("dummyHistogram_top", "dummyHistogram_top", 10, histogram1_numerator->GetXaxis()->GetXmin(), histogram1_numerator->GetXaxis()->GetXmax()); dummyHistogram->SetTitle(""); dummyHistogram->SetStats(false); dummyHistogram->SetMaximum(yMax); dummyHistogram->SetMinimum(yMin); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(xAxisOffset); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(yAxisOffset); dummyHistogram->Draw(); int colors[6] = { 1, 2, 3, 4, 6, 7 }; int markerStyles[6] = { 22, 32, 20, 24, 21, 25 }; int numGraphs = 1; if ( histogram2_numerator && histogram2_denominator ) ++numGraphs; if ( histogram3_numerator && histogram3_denominator ) ++numGraphs; if ( histogram4_numerator && histogram4_denominator ) ++numGraphs; if ( histogram5_numerator && histogram5_denominator ) ++numGraphs; if ( histogram6_numerator && histogram6_denominator ) ++numGraphs; TLegend* legend = new TLegend(legendX0, legendY0, legendX0 + 0.18, legendY0 + 0.05*numGraphs, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); TGraphAsymmErrors* graph1 = getEfficiency(histogram1_numerator, histogram1_denominator); graph1->SetLineColor(colors[0]); graph1->SetMarkerColor(colors[0]); graph1->SetMarkerStyle(markerStyles[0]); graph1->Draw("p"); legend->AddEntry(graph1, legendEntry1.data(), "p"); TGraphAsymmErrors* graph2 = 0; if ( histogram2_numerator && histogram2_denominator ) { graph2 = getEfficiency(histogram2_numerator, histogram2_denominator); graph2->SetLineColor(colors[1]); graph2->SetMarkerColor(colors[1]); graph2->SetMarkerStyle(markerStyles[1]); graph2->Draw("p"); legend->AddEntry(graph2, legendEntry2.data(), "p"); } TGraphAsymmErrors* graph3 = 0; if ( histogram3_numerator && histogram3_denominator ) { graph3 = getEfficiency(histogram3_numerator, histogram3_denominator); graph3->SetLineColor(colors[2]); graph3->SetMarkerColor(colors[2]); graph3->SetMarkerStyle(markerStyles[2]); graph3->Draw("p"); legend->AddEntry(graph3, legendEntry3.data(), "p"); } TGraphAsymmErrors* graph4 = 0; if ( histogram4_numerator && histogram4_denominator ) { graph4 = getEfficiency(histogram4_numerator, histogram4_denominator); graph4->SetLineColor(colors[3]); graph4->SetMarkerColor(colors[3]); graph4->SetMarkerStyle(markerStyles[3]); graph4->Draw("p"); legend->AddEntry(graph4, legendEntry4.data(), "p"); } TGraphAsymmErrors* graph5 = 0; if ( histogram5_numerator && histogram5_denominator ) { graph5 = getEfficiency(histogram5_numerator, histogram5_denominator); graph5->SetLineColor(colors[4]); graph5->SetMarkerColor(colors[4]); graph5->SetMarkerStyle(markerStyles[4]); graph5->Draw("p"); legend->AddEntry(graph5, legendEntry5.data(), "p"); } TGraphAsymmErrors* graph6 = 0; if ( histogram6_numerator && histogram6_denominator ) { graph6 = getEfficiency(histogram6_numerator, histogram6_denominator); graph6->SetLineColor(colors[5]); graph6->SetMarkerColor(colors[5]); graph6->SetMarkerStyle(markerStyles[5]); graph6->Draw("p"); legend->AddEntry(graph6, legendEntry6.data(), "p"); } legend->Draw(); TPaveText* label = 0; if ( title.Length() > 0 ) { label = new TPaveText(0.175, 0.925, 0.48, 0.98, "NDC"); label->AddText(title.Data()); label->SetTextAlign(13); label->SetTextSize(0.045); label->SetFillStyle(0); label->SetBorderSize(0); label->Draw(); } canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete legend; delete label; delete dummyHistogram; delete canvas; }
void makePlot(const std::string& inputFilePath, const std::string& canvasName, const std::string& sample, int massPoint, const std::string& channel, double k, const std::string& inputFileName, const std::string& outputFilePath, const std::string& outputFileName) { std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileName.data()); TFile* inputFile = new TFile(inputFileName_full.data()); if ( !inputFile ) { std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl; assert(0); } inputFile->ls(); TCanvas* canvas = dynamic_cast<TCanvas*>(inputFile->Get(canvasName.data())); if ( !canvas ) { std::cerr << "Failed to load canvas = " << canvasName << " !!" << std::endl; assert(0); } int idxPad = -1; if ( massPoint == 90 ) idxPad = 1; if ( massPoint == 125 ) idxPad = 2; if ( massPoint == 200 ) idxPad = 3; if ( massPoint == 300 ) idxPad = 4; if ( massPoint == 500 ) idxPad = 5; if ( massPoint == 800 ) idxPad = 6; if ( !(idxPad >= 1 && idxPad <= 6) ) { std::cerr << "Invalid sample = " << sample << " !!" << std::endl; assert(0); } TVirtualPad* pad = canvas->GetPad(idxPad); std::cout << "pad = " << pad << ": ClassName = " << pad->ClassName() << std::endl; TCanvas* canvas_new = new TCanvas("canvas_new", "canvas_new", 900, 800); canvas_new->SetFillColor(10); canvas_new->SetBorderSize(2); canvas_new->SetTopMargin(0.065); canvas_new->SetLeftMargin(0.17); canvas_new->SetBottomMargin(0.165); canvas_new->SetRightMargin(0.015); canvas_new->SetLogx(true); canvas_new->SetLogy(true); canvas_new->Draw(); canvas_new->cd(); //TList* pad_primitives = canvas->GetListOfPrimitives(); TList* pad_primitives = pad->GetListOfPrimitives(); TH1* histogramCA = 0; TH1* histogramSVfit = 0; TH1* histogramSVfitMEMkEq0 = 0; TH1* histogramSVfitMEMkNeq0 = 0; TIter pad_nextObj(pad_primitives); while ( TObject* obj = pad_nextObj() ) { std::string objName = ""; if ( dynamic_cast<TNamed*>(obj) ) objName = (dynamic_cast<TNamed*>(obj))->GetName(); std::cout << "obj = " << obj << ": name = " << objName << ", type = " << obj->ClassName() << std::endl; TH1* tmpHistogram = dynamic_cast<TH1*>(obj); if ( tmpHistogram ) { std::cout << "tmpHistogram:" << " fillColor = " << tmpHistogram->GetFillColor() << ", fillStyle = " << tmpHistogram->GetFillStyle() << "," << " lineColor = " << tmpHistogram->GetLineColor() << ", lineStyle = " << tmpHistogram->GetLineStyle() << ", lineWidth = " << tmpHistogram->GetLineWidth() << "," << " markerColor = " << tmpHistogram->GetMarkerColor() << ", markerStyle = " << tmpHistogram->GetMarkerStyle() << ", markerSize = " << tmpHistogram->GetMarkerSize() << "," << " integral = " << tmpHistogram->Integral() << std::endl; std::cout << "(mean = " << tmpHistogram->GetMean() << ", rms = " << tmpHistogram->GetRMS() << ": rms/mean = " << (tmpHistogram->GetRMS()/tmpHistogram->GetMean()) << ")" << std::endl; if ( tmpHistogram->GetLineColor() == 416 ) histogramCA = tmpHistogram; if ( tmpHistogram->GetLineColor() == 600 ) histogramSVfit = tmpHistogram; if ( tmpHistogram->GetLineColor() == 616 ) histogramSVfitMEMkEq0 = tmpHistogram; if ( tmpHistogram->GetLineColor() == 632 ) histogramSVfitMEMkNeq0 = tmpHistogram; } } if ( !(histogramCA && histogramSVfit && histogramSVfitMEMkEq0 && histogramSVfitMEMkNeq0) ) { std::cerr << "Failed to load histograms !!" << std::endl; assert(0); } //gStyle->SetLineStyleString(2,"40 10 10 10 10 10 10 10"); //gStyle->SetLineStyleString(3,"25 15"); //gStyle->SetLineStyleString(4,"60 25"); //int colors[4] = { kBlack, kGreen - 6, kBlue - 7, kMagenta - 7 }; int colors[4] = { 28, kGreen - 6, kBlue - 7, kBlack }; //int lineStyles[4] = { 2, 3, 4, 1 }; int lineStyles[4] = { 7, 1, 1, 1 }; //int lineWidths[4] = { 3, 3, 4, 3 }; int lineWidths[4] = { 3, 3, 1, 1 }; int markerStyles[4] = { 20, 25, 21, 24 }; int markerSizes[4] = { 2, 2, 2, 2 }; histogramCA->SetFillColor(0); histogramCA->SetFillStyle(0); histogramCA->SetLineColor(colors[0]); histogramCA->SetLineStyle(lineStyles[0]); histogramCA->SetLineWidth(lineWidths[0]); histogramCA->SetMarkerColor(colors[0]); histogramCA->SetMarkerStyle(markerStyles[0]); histogramCA->SetMarkerSize(markerSizes[0]); histogramSVfit->SetFillColor(0); histogramSVfit->SetFillStyle(0); histogramSVfit->SetLineColor(colors[1]); histogramSVfit->SetLineStyle(lineStyles[1]); histogramSVfit->SetLineWidth(lineWidths[1]); histogramSVfit->SetMarkerColor(colors[1]); histogramSVfit->SetMarkerStyle(markerStyles[1]); histogramSVfit->SetMarkerSize(markerSizes[1]); histogramSVfitMEMkEq0->SetFillColor(0); histogramSVfitMEMkEq0->SetFillStyle(0); histogramSVfitMEMkEq0->SetLineColor(colors[2]); histogramSVfitMEMkEq0->SetLineStyle(lineStyles[2]); histogramSVfitMEMkEq0->SetLineWidth(lineWidths[2]); histogramSVfitMEMkEq0->SetMarkerColor(colors[2]); histogramSVfitMEMkEq0->SetMarkerStyle(markerStyles[2]); histogramSVfitMEMkEq0->SetMarkerSize(markerSizes[2]); // CV: fix pathological bins at high mass for which dN/dm increases int numBins = histogramSVfitMEMkEq0->GetNbinsX(); for ( int idxBin = 1; idxBin <= numBins; ++idxBin ) { double binCenter = histogramSVfitMEMkEq0->GetBinCenter(idxBin); if ( (channel == "#tau_{h}#tau_{h}" && massPoint == 500 && binCenter > 1500.) || (channel == "#tau_{h}#tau_{h}" && massPoint == 800 && binCenter > 2000.) || (channel == "#mu#tau_{h}" && massPoint == 500 && binCenter > 1500.) || (channel == "#mu#tau_{h}" && massPoint == 800 && binCenter > 2500.) ) { histogramSVfitMEMkEq0->SetBinContent(idxBin, 0.); } } histogramSVfitMEMkNeq0->SetFillColor(0); histogramSVfitMEMkNeq0->SetFillStyle(0); histogramSVfitMEMkNeq0->SetLineColor(colors[3]); histogramSVfitMEMkNeq0->SetLineStyle(lineStyles[3]); histogramSVfitMEMkNeq0->SetLineWidth(lineWidths[3]); histogramSVfitMEMkNeq0->SetMarkerColor(colors[3]); histogramSVfitMEMkNeq0->SetMarkerStyle(markerStyles[3]); histogramSVfitMEMkNeq0->SetMarkerSize(markerSizes[3]); TAxis* xAxis = histogramCA->GetXaxis(); xAxis->SetTitle("m_{#tau#tau} [GeV]"); xAxis->SetTitleOffset(1.15); xAxis->SetTitleSize(0.070); xAxis->SetTitleFont(42); xAxis->SetLabelOffset(0.010); xAxis->SetLabelSize(0.055); xAxis->SetLabelFont(42); xAxis->SetTickLength(0.040); xAxis->SetNdivisions(510); //double xMin = 20.; //double xMax = xAxis->GetXmax(); //xAxis->SetRangeUser(xMin, xMax); TAxis* yAxis = histogramCA->GetYaxis(); yAxis->SetTitle("dN/dm_{#tau#tau} [1/GeV]"); yAxis->SetTitleOffset(1.20); yAxis->SetTitleSize(0.070); yAxis->SetTitleFont(42); yAxis->SetLabelOffset(0.010); yAxis->SetLabelSize(0.055); yAxis->SetLabelFont(42); yAxis->SetTickLength(0.040); yAxis->SetNdivisions(505); double massPoint_double = 0.; if ( massPoint == 90 ) massPoint_double = 91.2; else massPoint_double = massPoint; double dLog = (TMath::Log(5.*massPoint_double) - TMath::Log(50.))/25.; // xMin = 50, xMax = 5*massPoint, numBins = 25 double binWidth = TMath::Exp(TMath::Log(massPoint_double) + 0.5*dLog) - TMath::Exp(TMath::Log(massPoint_double) - 0.5*dLog); double sf_binWidth = 1./binWidth; std::cout << "massPoint = " << massPoint << ": sf_binWidth = " << sf_binWidth << std::endl; histogramCA->SetTitle(""); histogramCA->SetStats(false); histogramCA->SetMaximum(sf_binWidth*0.79); histogramCA->SetMinimum(sf_binWidth*1.1e-4); histogramCA->Draw("hist"); histogramSVfit->Draw("histsame"); //histogramSVfitMEMkEq0->Draw("histsame"); histogramSVfitMEMkEq0->Draw("epsame"); //histogramSVfitMEMkNeq0->Draw("histsame"); histogramSVfitMEMkNeq0->Draw("epsame"); histogramCA->Draw("axissame"); //TPaveText* label_sample = new TPaveText(0.21, 0.86, 0.46, 0.94, "NDC"); TPaveText* label_sample = new TPaveText(0.1700, 0.9475, 0.4600, 1.0375, "NDC"); label_sample->SetFillStyle(0); label_sample->SetBorderSize(0); label_sample->AddText(sample.data()); label_sample->SetTextFont(42); label_sample->SetTextSize(0.055); label_sample->SetTextColor(1); label_sample->SetTextAlign(13); label_sample->Draw(); //TLegend* legend_new = new TLegend(0.225, 0.52, 0.41, 0.82, NULL, "brNDC"); TLegend* legend_new = new TLegend(0.30, 0.30, 0.80, 0.80, NULL, "brNDC"); legend_new->SetFillColor(10); legend_new->SetFillStyle(0); legend_new->SetBorderSize(0); legend_new->SetTextFont(42); legend_new->SetTextSize(0.055); legend_new->SetTextColor(1); legend_new->SetMargin(0.20); legend_new->AddEntry(histogramCA, "CA", "l"); legend_new->AddEntry(histogramSVfit, "SVfit", "l"); //legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "l"); legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "p"); //legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM(k=%1.0f)", k), "l"); legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM (k=%1.0f)", k), "p"); //legend_new->Draw(); double label_channel_y0; if ( channel == "e#mu" ) label_channel_y0 = 0.9275; else if ( channel == "#mu#tau_{h}" ) label_channel_y0 = 0.9400; else if ( channel == "#tau_{h}#tau_{h}" ) label_channel_y0 = 0.9350; else { std::cerr << "Invalid channel = " << channel << " !!" << std::endl; assert(0); } TPaveText* label_channel = new TPaveText(0.895, label_channel_y0, 0.975, label_channel_y0 + 0.055, "NDC"); label_channel->SetFillStyle(0); label_channel->SetBorderSize(0); label_channel->AddText(channel.data()); label_channel->SetTextFont(62); label_channel->SetTextSize(0.055); label_channel->SetTextColor(1); label_channel->SetTextAlign(31); label_channel->Draw(); canvas_new->Update(); std::string outputFileName_full = Form("%s%s", outputFilePath.data(), outputFileName.data()); size_t idx = outputFileName_full.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName_full, 0, idx); canvas_new->Print(std::string(outputFileName_plot).append(".pdf").data()); canvas_new->Print(std::string(outputFileName_plot).append(".root").data()); std::string channel_string; if ( channel == "e#mu" ) channel_string = "emu"; else if ( channel == "#mu#tau_{h}" ) channel_string = "muhad"; else if ( channel == "#tau_{h}#tau_{h}" ) channel_string = "hadhad"; else { std::cerr << "Invalid channel = " << channel << " !!" << std::endl; assert(0); } std::string outputFileName_legend = Form("makeSVfitMEM_PerformancePlots_legend_%s.pdf", channel_string.data()); makePlot_legend(legend_new, outputFilePath, outputFileName_legend); delete label_sample; delete legend_new; delete label_channel; delete canvas_new; delete inputFile; }
void plot_ZJetBalance(int JetAlgo) { Float_t pt[NGenPtBins]; TString ptBin[NGenPtBins]; for(int i=0; i<NGenPtBins; i++) { pt[i] = 0.5*( GenPt[i] + GenPt[i+1] ); ptBin[i] = Form("%d_%d", (int) GenPt[i], (int) GenPt[i+1] ); } Float_t errpt[NGenPtBins]; Float_t genMean[NGenPtBins]; Float_t genSigma[NGenPtBins]; Float_t recoMean[NGenPtBins]; Float_t recoSigma[NGenPtBins]; TString algoSt; if(JetAlgo==0) algoSt = "_ic5"; if(JetAlgo==1) algoSt = "_ic7"; if(JetAlgo==2) algoSt = "_mp5"; if(JetAlgo==3) algoSt = "_mp7"; if(JetAlgo==4) algoSt = "_kt6"; TString textFilename = "ZjetPtBalance" + algoSt + TString(".txt"); TString JetResponseFilename = "Histograms_ZjetResponse" + algoSt + TString(".root"); FILE *file = fopen(textFilename,"w+"); fprintf( file ,"%s %s %s %s %s \n", "pT bin", "genMean", "genSigma", "recoMean", "recoSigma"); TH1F* responseHistGen; TH1F* responseHistReco; TH1F* genJetpt; TH1F* caloJetpt; TH1F* Zpt; if(storeResponsHistogramsInRootFile == true) { TFile respHistFile(JetResponseFilename,"RECREATE"); } for(int i=0; i<NGenPtBins; i++) { responseHistGen = new TH1F("responseHistGen_"+ptBin[i],"", 40, 0.0, 2.0); responseHistGen->Sumw2(); TAxis* responseHistGenx = responseHistGen->GetXaxis(); TAxis* responseHistGeny = responseHistGen->GetYaxis(); responseHistGenx->SetTitle("p_{T,Jet} / p_{T,Z} "); responseHistGeny->SetTitle("Events / 0.05 "); responseHistGeny->SetTitleOffset(1.2); responseHistReco = new TH1F("responseHistReco_"+ptBin[i],"", 40, 0.0, 2.0); responseHistReco->Sumw2(); responseHistReco->SetLineColor(2); responseHistReco->SetMarkerColor(2); genJetpt = new TH1F("genJetpt_"+ptBin[i],"", NGenPtBins-1, GenPt); genJetpt->Sumw2(); caloJetpt = new TH1F("caloJetpt_"+ptBin[i],"", NGenPtBins-1, GenPt); caloJetpt->Sumw2(); recoZpt = new TH1F("recoZpt_"+ptBin[i],"", NGenPtBins-1, GenPt); recoZpt->Sumw2(); errpt[i] = 0.0; genMean[i] = 0.0; genSigma[i] = 0.0; recoMean[i] = 0.0; recoSigma[i] = 0.0; plot_ZJetBalance( JetAlgo, i, *responseHistGen, *responseHistReco, *genJetpt, *caloJetpt, *recoZpt); genMean[i] = (Float_t) responseHistGen->GetMean(1); genSigma[i] = (Float_t) responseHistGen->GetMean(11); recoMean[i] = (Float_t) responseHistReco->GetMean(1); recoSigma[i] = (Float_t) responseHistReco->GetMean(11); if(storeResponseInTextFile == true) { fprintf( file ,"%5.1f %5.4f %5.4f %5.4f %5.4f \n", pt[i], genMean[i], genSigma[i], recoMean[i], recoSigma[i] ); } if(storeResponsHistogramsInRootFile == true) { respHistFile.cd(); responseHistGen->Write(); responseHistReco->Write(); genJetpt->Write(); caloJetpt->Write(); recoZpt->Write(); } delete responseHistGen; delete responseHistReco; delete genJetpt; delete caloJetpt; delete recoZpt; } fclose(file); respHistFile.Close(); if(makeplot_Response == true) { // plot full spectrum TGraphErrors *ptbalanceGen = new TGraphErrors(NGenPtBins, pt, genMean, errpt, genSigma); TGraphErrors *ptbalanceReco = new TGraphErrors(NGenPtBins, pt, recoMean, errpt, recoSigma); // plot Zmumu values Float_t ptmm[9] = { 40.0, 60.0, 100.0, 140.0, 200.0, 250.0, 330.0, 400.0, 520.0 }; Float_t balancemm[9] = { 0.496, 0.568, 0.66, 0.71, 0.75, 0.765, 0.775, 0.79, 0.81 }; TGraph *ptbalancemm = new TGraph( 9, ptmm, balancemm); ptbalanceGen->GetXaxis()->SetTitle("p_{T}^{Z} [GeV/c] "); ptbalanceGen->GetYaxis()->SetTitle("p_{T}^{Jet} / p_{T}^{Z} "); ptbalanceGen->SetMarkerStyle(22); ptbalanceGen->SetMarkerSize(1.2); ptbalanceGen->SetTitle(""); ptbalanceGen->SetMinimum(0.2); ptbalanceReco->SetMarkerColor(2); ptbalanceReco->SetLineColor(2); ptbalanceReco->SetMarkerStyle(22); ptbalanceReco->SetMarkerSize(1.2); ptbalanceReco->SetMinimum(0.2); ptbalancemm->SetMarkerStyle(24); ptbalancemm->SetMarkerSize(1.2); ptbalancemm->SetMinimum(0.2); ptbalancemm->SetMarkerColor(4); ptbalancemm->SetLineColor(4); TCanvas c1("c1","",800,600); c1.SetGrid(); ptbalanceGen->Draw("APL"); ptbalanceReco->Draw("PL"); ptbalancemm->Draw("PL"); leg_hist = new TLegend(0.6,0.35,0.85,0.55); leg_hist->AddEntry( ptbalanceGen, "Generator level", "l"); leg_hist->AddEntry( ptbalanceReco,"Calorimeter level","l"); leg_hist->AddEntry( ptbalancemm,"Z#rightarrow#mu#mu","l"); leg_hist->SetFillColor(0); leg_hist->Draw(); c1.SaveAs("PtBalanceVsPt.eps"); c1.SaveAs("PtBalanceVsPt.gif"); c1.SaveAs("PtBalanceVsPt.root"); c1.Close(); delete leg_hist; delete ptbalanceGen; delete ptbalanceReco; delete ptbalancemm; } }
void showHistogram2d(TH2* histogram, const std::string& xAxisTitle, const std::string& yAxisTitle, int zAxisNormOption, double zMin, double zMax, Float_t* genX, Float_t* genY, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", 900, 800); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetTopMargin(0.10); canvas->SetLeftMargin(0.12); canvas->SetRightMargin(0.14); canvas->SetBottomMargin(0.12); histogram->SetTitle(""); histogram->SetStats(false); int numBinsX = histogram->GetNbinsX(); int numBinsY = histogram->GetNbinsY(); if ( zAxisNormOption == kNormByQuantiles ) { std::vector<double> binContents; for ( int iBinX = 1; iBinX <= numBinsX; ++iBinX ) { for ( int iBinY = 1; iBinY <= numBinsY; ++iBinY ) { binContents.push_back(histogram->GetBinContent(iBinX, iBinY)); } } std::sort(binContents.begin(), binContents.end()); histogram->SetMinimum(binContents[TMath::Nint(0.05*binContents.size())]); histogram->SetMaximum(binContents[TMath::Nint(0.95*binContents.size())]); } else if ( zAxisNormOption == kNormByNegLogMax ) { double maxBinContent = 0.; for ( int iBinX = 1; iBinX <= numBinsX; ++iBinX ) { for ( int iBinY = 1; iBinY <= numBinsY; ++iBinY ) { double binContent = histogram->GetBinContent(iBinX, iBinY); if ( binContent > maxBinContent ) { std::cout << "binX = " << iBinX << " (x = " << histogram->GetXaxis()->GetBinCenter(iBinX) << ")," << " binY = " << iBinY << " (y = " << histogram->GetYaxis()->GetBinCenter(iBinY) << "): maxBinContent = " << maxBinContent << std::endl; maxBinContent = binContent; } } } double logMaxBinContent = TMath::Log(maxBinContent); for ( int iBinX = 1; iBinX <= numBinsX; ++iBinX ) { for ( int iBinY = 1; iBinY <= numBinsY; ++iBinY ) { double binContent = histogram->GetBinContent(iBinX, iBinY); if ( binContent > 0. ) { histogram->SetBinContent(iBinX, iBinY, -TMath::Log(binContent) + logMaxBinContent); } else { histogram->SetBinContent(iBinX, iBinY, -1.); } } } histogram->SetMinimum(0.); histogram->SetMaximum(zMax); } else if ( zAxisNormOption == kNormByValue ) { histogram->SetMinimum(zMin); histogram->SetMaximum(zMax); } else assert(0); TAxis* xAxis = histogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(1.15); TAxis* yAxis = histogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(1.30); gStyle->SetPalette(1,0); histogram->Draw("COLZ"); TMarker* genMarker = 0; if ( genX && genY ) { genMarker = new TMarker(*genX, *genY, 34); genMarker->SetMarkerColor(1); genMarker->SetMarkerSize(2); genMarker->Draw(); } canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete genMarker; delete canvas; }
void Plot::FitSignal(int mode, int fitMode) { const int nPar = 6; TRandom ran; if(mode==0) { gStyle->SetOptLogy(1); } else { gStyle->SetOptLogy(0); } gStyle->SetOptStat(0); gStyle->SetOptTitle(0); const float limitBinSize = 2.0; // **** bin size here TCanvas* c = NewCanvas(); c->Divide(1,2); gROOT->cd(); TH1F* cc = new TH1F("CCSignal","CC Signal",500,0.0,1000.0); TH1F* ccBg = new TH1F("CCBgFit","CC Bg Fit",500,0.0,1000.0); TH1F* ccBgErr = new TH1F("CCBgErr","CC Bg Err",500,0.0,1000.0); TH1F* ccBgP = new TH1F("CCBgPlus","CC Bg Plus",500,0.0,1000.0); TH1F* ccBgM = new TH1F("CCBgMinus","CC Bg Minus",500,0.0,1000.0); TH1F* cp = new TH1F("CPSignal","CP Signal",500,0.0,1000.0); TH1F* cpBg = new TH1F("CPBgFit","CP Bg Fit",500,0.0,1000.0); TH1F* cpBgErr = new TH1F("CPBgErr","CP Bg Err",500,0.0,1000.0); TH1F* cpBgP = new TH1F("CPBgPlus","CP Bg Plus",500,0.0,1000.0); TH1F* cpBgM = new TH1F("CPBgMinus","CP Bg Minus",500,0.0,1000.0); TMatrixD matrix(nPar,nPar); fd->cd(); TH1F* hInt,*hBgInt; char fitname[100]; for(int ind=0; ind<2; ind++) { if(debug) printf("starting ind %i\n",ind); c->cd(ind+1); gStyle->SetOptLogy(1); printf("Starting %i ######################################\n",ind); TH1F* h; //char cind[20]; //char handle[100]; //sprintf(handle,"side_1exp_%02i_%02i_%02i",ind,mode,fitMode); TF1* fits[4]; //TF1* dpx[4]; if(debug) printf("looking for h %i\n",int(fd)); if(ind==0) { h = (TH1F*)fd->FindObjectAny("pair_mass_2GeV1"); } else if(ind==1) { h = (TH1F*)fd->FindObjectAny("pair_mass_2GeV3"); } if(debug) printf("new h %i\n",int(h)); if(debug) printf("new fit\n"); sprintf(fitname,"hfit_%1i",ind); fits[ind] = new TF1(fitname,"([0]*pow((x-30.0),[1])+[3]*pow((x-30.0),0.2))*([2]*exp(-[2]*(x-30.0))+[4]*[5]*exp(-[5]*(x-30.0)))",30.0,500.0); //fits[ind] = new TF1(fitname,"([0]*((1-[3])*pow((x-30.0),[1])+[3]*pow((x-30.0),0.2)))*(exp(-[2]*(x-30.0))+[4]*exp(-[5]*(x-30.0)))",30.0,500.0); fits[ind]->SetParameter(0,0.0004); fits[ind]->SetParameter(1,2); fits[ind]->SetParameter(2,0.02); fits[ind]->SetParameter(3,0.005); //fits[ind]->SetParameter(3,0.5); fits[ind]->SetParameter(4,1.005); fits[ind]->SetParameter(5,0.05); float llim = 30.0; h->Fit(fits[ind],"LN","",llim,1000.0); double par[20],parMin[20],fval,fvalMin; for(int i=0; i<nPar; i++) parMin[i] = fits[ind]->GetParameter(i); gMinuit->Eval(nPar,0,fvalMin,parMin,0); //printf("got back %10.5f\n",fvalMin); // save the fit results in a histogram, for limit program for(int ibin=16; ibin<250; ibin++) { float xx = h->GetBinCenter(ibin); float yy = fits[ind]->Eval(xx); if(ind==0) { cc->SetBinContent(ibin,h->GetBinContent(ibin)); ccBg->SetBinContent(ibin,yy); ccBgErr->SetBinContent(ibin,0.0); ccBgP->SetBinContent(ibin,0.0); ccBgM->SetBinContent(ibin,99999.0); } else { cp->SetBinContent(ibin,h->GetBinContent(ibin)); cpBg->SetBinContent(ibin,yy); cpBgErr->SetBinContent(ibin,0.0); cpBgP->SetBinContent(ibin,0.0); cpBgM->SetBinContent(ibin,99999.0); } } //vary the parameters to find an error envelope double par2[20],fval2=1e10; int pslim = (ind==0?25000:150000); for(int ips=0; ips<pslim; ips++) { if(ips%10000==0) printf("Processing %d\n",ips); for(int i=0; i<nPar; i++) { par[i] = parMin[i]; } for(int i=0; i<nPar; i++) { //int i = (ips%2==0?0:3); par[i] = parMin[i]+(2.0*(ran.Uniform()-0.5))*fits[ind]->GetParError(i); } fval = 0.0; gMinuit->Eval(nPar,0,fval,par,0); if((fval-fvalMin)<1.0) { printf("Found nearby min %10.5f\n",fval-fvalMin); float eOld,eNew; for(int ibin=16; ibin<250; ibin++) { float xx = h->GetBinCenter(ibin); for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,par[i]); float yy = fits[ind]->Eval(xx); for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,parMin[i]); float yyMin = fits[ind]->Eval(xx); TH1F *hBgErr,*hBgP,*hBgM; if(ind==0) { hBgErr = ccBgErr; hBgP = ccBgP; hBgM = ccBgM; } else { hBgErr = cpBgErr; hBgP = cpBgP; hBgM = cpBgM; } eOld = hBgErr->GetBinContent(ibin); eNew = yy - yyMin; if(eOld>fabs(eNew)) hBgErr->SetBinContent(ibin,fabs(eNew)); eOld = hBgP->GetBinContent(ibin); if(yy>eOld) hBgP->SetBinContent(ibin,yy); eOld = hBgM->GetBinContent(ibin); if(yy<eOld) hBgM->SetBinContent(ibin,yy); } } // end if near maximum /* if(fval<fval2) { for(int i=0; i<nPar; i++) par2[i] = par[i]; fval2 = fval; } */ } /* printf("forcing new fit..\n"); for(int i=0; i<nPar; i++) { printf("old,new = %10.5f %10.5f\n",parMin[i],par2[i]); fits[ind]->SetParameter(i,par2[i]); } */ // restore original fit fval = 0.0; gMinuit->Eval(nPar,0,fval,parMin,0); for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,parMin[i]); //extract fit error matrix gMinuit->mnemat(matrix.GetMatrixArray(),nPar); matrix.Print(); for(int i=0; i<nPar; i++) { for(int j=0; j<nPar; j++) { printf("%10.5f",matrix(i,j)/sqrt(matrix(i,i)*matrix(j,j))); } printf("\n"); } //matrix.Draw("text"); float hm = h->GetMaximum(); if(mode==0) { //TAxis* ax = h->GetXaxis(); //ax->SetRangeUser(24.1,199.9); h->SetMaximum(1.2*hm); //h->SetMinimum(0.0); } else if(mode==1) { TAxis* ax = h->GetXaxis(); ax->SetRangeUser(20.0,500.0); h->SetMaximum(1.15*hm); h->SetMinimum(0.0); } h->Draw(); fits[ind]->SetLineColor(1); fits[ind]->SetLineWidth(2.0); fits[ind]->Draw("SAME"); // find chi2's and KS's //AnaChiKs(h,fits[ind]); TAxis* ax,*ay; ax = h->GetXaxis(); ay = h->GetYaxis(); ax->SetTitle("m(#gamma#gamma) (GeV/c^{2})"); ay->SetTitle("Entries/2 GeV/c^{2}"); ax->CenterTitle(); ay->CenterTitle(); ax->SetTitleOffset(0.9); ay->SetTitleOffset(1.0); ax->SetTitleSize(0.08); ay->SetTitleSize(0.07); ax->SetLabelSize(0.07); ay->SetLabelSize(0.07); gPad->SetLeftMargin(0.16); gPad->SetBottomMargin(0.16); TText* text; text = new TLatex(0.5,0.8,"Diphoton Data"); text->SetNDC(true); text->SetTextSize(0.06); text->Draw(); if(ind==0) text = new TLatex(0.5,0.72,"Central-Central"); else if(ind==1) text = new TLatex(0.5,0.72,"Central-Plug"); text->SetNDC(true); text->SetTextSize(0.06); text->Draw(); if(ind==0) { text = new TLatex(0.15,0.92,"W/Z H#rightarrow X(#gamma#gamma)"); text->SetNDC(true); text->SetTextSize(0.08); text->Draw(); text = new TLatex(0.5,0.92,"CDF Run II Preliminary, 2.0 fb^{-1}"); text->SetNDC(true); text->SetTextSize(0.06); text->Draw(); } /* if(debug) printf("start loop\n"); int ibin; for(ibin=16; ibin<=250; ibin++) { if(debug) printf("start bin %i\n",ibin); float xx = (ibin-0.5)*2.0; // *** bin width here if(debug) printf("-1 test ibin %i\n",ibin); float yy = fits[ind]->Eval(xx); //printf("%f yy= %f \n",xx,yy); // the derivative of this yield wrt parameters if(debug) printf("0 test ibin %i\n",ibin); double y0 = yy; if(debug) printf("1 test ibin %i\n",ibin); TMatrixD vv(nPar,1); float dirSize = 0.5; for(int i=0; i<nPar; i++){ int ipar = i; double par = fits[ind]->GetParameter(ipar); double spar = fits[ind]->GetParError(ipar); double parp = par + dirSize*spar; fits[ind]->SetParameter(ipar,parp); double yp = fits[ind]->Eval(xx); vv(i,0) = limitBinSize*(yp-y0)/(dirSize*spar); fits[ind]->SetParameter(ipar,par); //printf("%f %f %f\n",yp,y0,spar); } //vv.Print(); if(debug) printf("start matrix %i\n",ibin); TMatrixD tempM(matrix, TMatrixDBase::kMult, vv); //matrix.Print(); TMatrixD tempN(vv, TMatrixDBase::kTransposeMult, tempM); //tempN.Print(); float bgSig = 0.0; if(tempN(0,0)>0.0) bgSig = sqrt(tempN(0,0)); // ****** hack temp ********** bgSig = 0.3*y0; // file hists to be saved if(debug) printf("start fill %i\n",ibin); if(ind==0) { //printf("filling cc %i %f\n",ibin,h->GetBinContent(ibin)); cc->SetBinContent(ibin,h->GetBinContent(ibin)); //printf("getting cc %i %f\n",ibin,cc->GetBinContent(ibin)); ccBg->SetBinContent(ibin,yy); ccBgErr->SetBinContent(ibin,bgSig); ccBgP->SetBinContent(ibin,yy+bgSig); ccBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0))); //if(ibin==27) { //printf("bg %f %f \n",yy,bgSig); //} } else { cp->SetBinContent(ibin,h->GetBinContent(ibin)); cpBg->SetBinContent(ibin,yy); cpBgErr->SetBinContent(ibin,bgSig); cpBgP->SetBinContent(ibin,yy+bgSig); cpBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0))); } if(debug) printf("end fill %i\n",ibin); } */ } printf("cc plus BG=%f\n",ccBgP->GetSum()); printf("cc minus BG=%f\n",ccBgM->GetSum()); printf("cp plus BG=%f\n",cpBgP->GetSum()); printf("cp minus BG=%f\n",cpBgM->GetSum()); char fn[100]; if(mode==0) { sprintf(fn,"FitSignal_%d",fitMode); savePlot(c,fn); } else if(mode==1) { sprintf(fn,"FitSignalLin_%d",fitMode); savePlot(c,fn); } //if(mode!=0) return; // plot of fit results gStyle->SetOptLogy(0); c = NewCanvas(); c->Divide(1,2); c->cd(1); cc->Draw(); ccBg->Draw("SAME"); c->cd(2); ccBgErr->SetMinimum(0.0); ccBgErr->SetMaximum(4.0); ccBgErr->Draw(); ccBgP->SetLineStyle(2); ccBgP->Draw("SAME"); ccBgM->SetLineStyle(2); ccBgM->Draw("SAME"); savePlot(c,"FitSignalResultsCC"); c = NewCanvas(); c->Divide(1,2); c->cd(1); cp->Draw(); cpBg->Draw("SAME"); c->cd(2); cpBgErr->SetMinimum(0.0); cpBgErr->SetMaximum(4.0); cpBgErr->Draw(); cpBgP->SetLineStyle(2); cpBgP->Draw("SAME"); cpBgM->SetLineStyle(2); cpBgM->Draw("SAME"); savePlot(c,"FitSignalResultsCP"); char title[100]; if(name) { sprintf(title,"TPeaksHiggs_FitSignalHist_%s.root",name); TFile* ff = new TFile(title,"RECREATE"); gROOT->GetList()->Write(); ff->Close(); } }
void showHistograms(double canvasSizeX, double canvasSizeY, TH1* histogram1, const std::string& legendEntry1, TH1* histogram2, const std::string& legendEntry2, TH1* histogram3, const std::string& legendEntry3, TH1* histogram4, const std::string& legendEntry4, double legendTextSize, double legendPosX, double legendPosY, double legendSizeX, double legendSizeY, std::vector<std::string>& labelTextLines, double labelTextSize, double labelPosX, double labelPosY, double labelSizeX, double labelSizeY, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { const unsigned numBinsMin_rebinned = 20; TH1* histogram1_rebinned = rebinHistogram(histogram1, numBinsMin_rebinned, xMin, xMax); TH1* histogram2_rebinned = rebinHistogram(histogram2, numBinsMin_rebinned, xMin, xMax); TH1* histogram3_rebinned = rebinHistogram(histogram3, numBinsMin_rebinned, xMin, xMax); TH1* histogram4_rebinned = rebinHistogram(histogram4, numBinsMin_rebinned, xMin, xMax); TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.14); canvas->SetBottomMargin(0.12); canvas->SetLogy(useLogScale); histogram1_rebinned->SetTitle(""); histogram1_rebinned->SetStats(false); histogram1_rebinned->SetMinimum(yMin); histogram1_rebinned->SetMaximum(yMax); TAxis* xAxis = histogram1_rebinned->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleSize(0.045); xAxis->SetTitleOffset(xAxisOffset); if ( xMax > xMin ) { std::cout << "limiting x-axis range to " << xMin << ".." << xMax << std::endl; xAxis->SetRangeUser(xMin, xMax); } TAxis* yAxis = histogram1_rebinned->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleSize(0.045); yAxis->SetTitleOffset(yAxisOffset); int colors[4] = { 1, 2, 3, 4 }; int lineStyles[4] = { 1, 7, 4, 3 }; histogram1_rebinned->SetLineColor(colors[0]); histogram1_rebinned->SetLineWidth(2); histogram1_rebinned->SetLineStyle(lineStyles[0]); histogram1_rebinned->Draw("hist"); if ( histogram2_rebinned ) { histogram2_rebinned->SetLineColor(colors[1]); histogram2_rebinned->SetLineWidth(2); histogram2_rebinned->SetLineStyle(lineStyles[1]); histogram2_rebinned->Draw("histsame"); } if ( histogram3_rebinned ) { histogram3_rebinned->SetLineColor(colors[2]); histogram3_rebinned->SetLineWidth(2); histogram3_rebinned->SetLineStyle(lineStyles[2]); histogram3_rebinned->Draw("histsame"); } if ( histogram4_rebinned ) { histogram4_rebinned->SetLineColor(colors[3]); histogram4_rebinned->SetLineWidth(2); histogram4_rebinned->SetLineStyle(lineStyles[3]); histogram4_rebinned->Draw("histsame"); } TLegend* legend = new TLegend(legendPosX, legendPosY, legendPosX + legendSizeX, legendPosY + legendSizeY, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetTextSize(legendTextSize); legend->AddEntry(histogram1_rebinned, legendEntry1.data(), "l"); if ( histogram2_rebinned ) legend->AddEntry(histogram2_rebinned, legendEntry2.data(), "l"); if ( histogram3_rebinned ) legend->AddEntry(histogram3_rebinned, legendEntry3.data(), "l"); if ( histogram4_rebinned ) legend->AddEntry(histogram4_rebinned, legendEntry4.data(), "l"); legend->Draw(); TPaveText* label = 0; if ( labelTextLines.size() > 0 ) { label = new TPaveText(labelPosX, labelPosY, labelPosX + labelSizeX, labelPosY + labelSizeY, "brNDC"); for ( std::vector<std::string>::const_iterator labelTextLine = labelTextLines.begin(); labelTextLine != labelTextLines.end(); ++labelTextLine ) { label->AddText(labelTextLine->data()); } label->SetFillColor(10); label->SetBorderSize(0); label->SetTextColor(1); label->SetTextAlign(12); label->SetTextSize(labelTextSize); label->Draw(); } canvas->Update(); std::string outputFileName_plot = "plots/"; size_t idx = outputFileName.find_last_of('.'); outputFileName_plot.append(std::string(outputFileName, 0, idx)); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete label; delete legend; delete canvas; delete histogram1_rebinned; delete histogram2_rebinned; delete histogram3_rebinned; delete histogram4_rebinned; }
void DeltaPlot::viewGMstar (Char_t const* title) { FFactor GMS(12); GMS.LoadParameters(parametersFile); GMS.CheckParameters(); //GMS.PrintParameters(); const int nPoints = 2500; double qMin; double qMax; double qStep; double qA; double DX[nPoints], DY[nPoints], RY[nPoints]; qMin = 0.004; qMax = 3.0; qStep = (qMax-qMin)/nPoints; qA = qMin; for (int i = 0; i < nPoints; i++) { qA = qMin + i*qStep; double qA2 = qA*qA; double gen = GMS.AbsGEN(-qA2); double gmn = GMS.AbsGMN(-qA2); double msq = massDi*massDi - massNucl*massNucl - qA2; double abq = sqrt((qA2 + msq*msq)/(4.*massDi*massDi)); double jsc = (massDi+massNucl)/2./massNucl*(1.-qA2/4./massDi/massDi)*(1.-qA2/4./massNucl/massNucl); DX[i] = qA2; double mDip = 1. + qA2/0.71; double gD = 1./mDip/mDip; double gDmn = gD*(-muN); DY[i] = sqrt(2.)*2./3.*gDmn*jsc; double masst = qA2/(4.*massNucl*massNucl); double gmo = (GMS.ScalarOne(-qA2)-GMS.VectorOne(-qA2))/qA2+(GMS.ScalarTwo(-qA2)-GMS.VectorTwo(-qA2))/massN/massN/4.; RY[i] = sqrt(2.)*2./3.*gmn*jsc; } c[k] = new TCanvas (uName("c",k), uName("Graph_",k), x0+k*s, y0+k*s, w, h); //c[k]->SetLogy(); // logarithmic scale TGraphErrors *g[5]; TMultiGraph *mg = new TMultiGraph(); Double_t EX0[100] = {0}; // 1999-PRL-82-45_Frolov Double_t X1[] = {2.8, 4.0}; Double_t Y1[] = {0.0859, 0.0402}; Double_t U1[] = {0.0035, 0.0019}; Double_t D1[] = {0.0035, 0.0019}; g[1] = new TGraphErrors (2, X1, Y1, EX0, D1); g[1]->SetTitle("JLab/Hall C"); g[1]->SetMarkerColor(2); g[1]->SetMarkerStyle(21); mg->Add(g[1]); // 2006-PRL-97-112003_Ungaro Double_t X2[] = {3.0, 3.5, 4.2, 5.0, 6.0}; Double_t Y2[] = {0.0697, 0.0524, 0.0346, 0.0242, 0.0134}; Double_t U2[] = {0.0010, 0.0011, 0.0012, 0.0014, 0.0014}; Double_t D2[] = {0.0010, 0.0011, 0.0012, 0.0014, 0.0014}; g[2] = new TGraphErrors (5, X2, Y2, EX0, D2); g[2]->SetTitle("JLaB/CLAS"); g[2]->SetMarkerColor(4); g[2]->SetMarkerStyle(21); mg->Add(g[2]); // 1968-PL-28-148B_Bartel Double_t X3[] = {0.20, 0.30, 0.40, 0.47, 0.48, 0.50, 0.60, 0.63, 0.63, 0.77, 0.78, 0.79, 0.97, 0.98, 1.15, 1.34, 1.57, 2.34}; Double_t Y3[] = {1.7700, 1.3800, 1.1700, 0.9780, 0.9610, 0.9640, 0.7660, 0.7350, 0.7190, 0.5700, 0.5720, 0.5530, 0.4460, 0.4460, 0.3260, 0.2690, 0.2090, 0.1020}; Double_t U3[] = {0.0620, 0.0483, 0.0351, 0.0293, 0.0336, 0.0289, 0.0268, 0.0221, 0.0252, 0.0200, 0.0172, 0.0194, 0.0156, 0.0156, 0.0147, 0.0121, 0.0115, 0.0082}; Double_t D3[] = {0.0620, 0.0483, 0.0351, 0.0293, 0.0336, 0.0289, 0.0268, 0.0221, 0.0252, 0.0200, 0.0172, 0.0194, 0.0156, 0.0156, 0.0147, 0.0121, 0.0115, 0.0082}; g[3] = new TGraphErrors (18, X3, Y3, EX0, D3); g[3]->SetTitle("DESY"); g[3]->SetMarkerColor(6); g[3]->SetMarkerStyle(22); mg->Add(g[3]); // 1975-PR-D12-1884_Stein Double_t X4[] = {0.09, 0.22, 0.46, 0.78, 1.17, 1.48, 1.82}; Double_t Y4[] = {2.2448, 1.5824, 0.9147, 0.5007, 0.2708, 0.1728, 0.1122}; Double_t U4[] = {0.0709, 0.0332, 0.0243, 0.0136, 0.0116, 0.0095, 0.0064}; Double_t D4[] = {0.0709, 0.0332, 0.0243, 0.0136, 0.0116, 0.0095, 0.0064}; g[4] = new TGraphErrors (7, X4, Y4, EX0, D4); g[4]->SetTitle("SLAC"); g[4]->SetMarkerColor(4); g[4]->SetMarkerStyle(23); mg->Add(g[4]); for (int i=0; i<4; ++i) { g[i+1]->SetFillColor(0); //g[i+1]->SetLineColor(4); g[i+1]->SetMarkerSize(1.2); } // Formula D TGraph *gD = new TGraph (nPoints, DX, DY); gD->SetTitle("Dipole formulae"); gD->SetFillColor(0); gD->SetLineWidth(3); gD->SetMarkerSize(0.3); gD->SetMarkerStyle(21); gD->SetMarkerColor(4); gD->SetLineColor(4); mg->Add(gD); // Formula A TGraph *gA = new TGraph (nPoints, DX, RY); gA->SetTitle("Our result"); gA->SetFillColor(0); gA->SetLineWidth(3); gA->SetMarkerSize(0.3); gA->SetMarkerStyle(21); //gA->SetLineColor(3); mg->Add(gA); mg->Draw("AP"); //TF1 *fg = new TF1 ("fg", "[1]*x + [0]"); //mg->Fit("poly5","Fit"); // fg TAxis *aX = mg->GetXaxis(); aX->SetTitle("Q^{2} [GeV^{2}]"); //aX->SetLimits(0.,10.); aX->SetRangeUser(-0.01,7.0); aX->SetTitleOffset(1.2); aX->CenterTitle(); TAxis *aY = mg->GetYaxis(); aY->SetTitle("G_{M}^{*}"); //aY->SetRangeUser(0.6,1.8); aY->SetTitleOffset(1.2); aY->CenterTitle(); gPad->SetFillColor(kWhite); TLegend *leg = c[k]->BuildLegend(); leg->SetFillStyle(0); c[k]->Modified(); c[k]->SaveAs("imgGMstar.pdf"); ++k; }
void showGraphs(double canvasSizeX, double canvasSizeY, TGraph* graph1, const std::string& legendEntry1, TGraph* graph2, const std::string& legendEntry2, TGraph* graph3, const std::string& legendEntry3, TGraph* graph4, const std::string& legendEntry4, TGraph* graph5, const std::string& legendEntry5, TGraph* graph6, const std::string& legendEntry6, int colors[], int markerStyles[], double legendTextSize, double legendPosX, double legendPosY, double legendSizeX, double legendSizeY, std::vector<std::string>& labelTextLines, double labelTextSize, double labelPosX, double labelPosY, double labelSizeX, double labelSizeY, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetLeftMargin(0.14); canvas->SetBottomMargin(0.12); TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 100, xMin, xMax); dummyHistogram->SetTitle(""); dummyHistogram->SetStats(false); dummyHistogram->SetMinimum(yMin); dummyHistogram->SetMaximum(yMax); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleSize(0.045); xAxis->SetTitleOffset(xAxisOffset); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleSize(0.045); yAxis->SetTitleOffset(yAxisOffset); dummyHistogram->Draw("axis"); graph1->SetLineColor(colors[0]); graph1->SetLineWidth(2); graph1->SetMarkerColor(colors[0]); graph1->SetMarkerStyle(markerStyles[0]); graph1->SetMarkerSize(2); graph1->Draw("p"); if ( graph2 ) { graph2->SetLineColor(colors[1]); graph2->SetLineWidth(2); graph2->SetMarkerColor(colors[1]); graph2->SetMarkerStyle(markerStyles[1]); graph2->SetMarkerSize(2); graph2->Draw("p"); } if ( graph3 ) { graph3->SetLineColor(colors[2]); graph3->SetLineWidth(2); graph3->SetMarkerColor(colors[2]); graph3->SetMarkerStyle(markerStyles[2]); graph3->SetMarkerSize(2); graph3->Draw("p"); } if ( graph4 ) { graph4->SetLineColor(colors[3]); graph4->SetLineWidth(2); graph4->SetMarkerColor(colors[3]); graph4->SetMarkerStyle(markerStyles[3]); graph4->SetMarkerSize(2); graph4->Draw("p"); } if ( graph5 ) { graph5->SetLineColor(colors[4]); graph5->SetLineWidth(2); graph5->SetMarkerColor(colors[4]); graph5->SetMarkerStyle(markerStyles[4]); graph5->SetMarkerSize(2); graph5->Draw("p"); } if ( graph6 ) { graph6->SetLineColor(colors[5]); graph6->SetLineWidth(2); graph6->SetMarkerColor(colors[5]); graph6->SetMarkerStyle(markerStyles[5]); graph6->SetMarkerSize(2); graph6->Draw("p"); } TLegend* legend = new TLegend(legendPosX, legendPosY, legendPosX + legendSizeX, legendPosY + legendSizeY, "", "brNDC"); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetTextSize(legendTextSize); legend->AddEntry(graph1, legendEntry1.data(), "p"); if ( graph2 ) legend->AddEntry(graph2, legendEntry2.data(), "p"); if ( graph3 ) legend->AddEntry(graph3, legendEntry3.data(), "p"); if ( graph4 ) legend->AddEntry(graph4, legendEntry4.data(), "p"); if ( graph5 ) legend->AddEntry(graph5, legendEntry5.data(), "p"); if ( graph6 ) legend->AddEntry(graph6, legendEntry6.data(), "p"); legend->Draw(); TPaveText* label = 0; if ( labelTextLines.size() > 0 ) { label = new TPaveText(labelPosX, labelPosY, labelPosX + labelSizeX, labelPosY + labelSizeY, "brNDC"); for ( std::vector<std::string>::const_iterator labelTextLine = labelTextLines.begin(); labelTextLine != labelTextLines.end(); ++labelTextLine ) { label->AddText(labelTextLine->data()); } label->SetFillColor(10); label->SetBorderSize(0); label->SetTextColor(1); label->SetTextAlign(12); label->SetTextSize(labelTextSize); label->Draw(); } canvas->Update(); std::string outputFileName_plot = "plots/"; size_t idx = outputFileName.find_last_of('.'); outputFileName_plot.append(std::string(outputFileName, 0, idx)); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); delete dummyHistogram; delete label; delete legend; delete canvas; }