/*============================================================================*/ void gaus1peakfit(Char_t *s, Float_t x1, Float_t x2, Float_t x3, Float_t x4) { Double_t par[5],epar[5],x[4],y[4]; TH1 *hist; hist = (TH1 *) gROOT->FindObject(s); setcanvas(1); TCanvas *c1=(TCanvas*) gROOT->FindObject("c1"); if(c1==NULL)setcanvas(1); c1->Clear(); hist->SetAxisRange(x1-30,x4+30); hist->Draw(); //--**-- Linear background estimation --**--// x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4; Int_t bin1 = hist->FindBin(x1); y[0] = hist->GetBinContent(bin1); Int_t bin2 = hist->FindBin(x2); y[1] = hist->GetBinContent(bin2); Int_t bin3 = hist->FindBin(x3); y[2] = hist->GetBinContent(bin3); Int_t bin4 = hist->FindBin(x4); y[3] = hist->GetBinContent(bin4); TGraph *g = new TGraph(4,x,y); TF1 *fpol1 = new TF1("POL1","pol1",x1,x4); g->Fit(fpol1,"RQN"); par[3]=fpol1->GetParameter(0); par[4]=fpol1->GetParameter(1); //--**-- Gaussian Peak estimation without background --**--// TF1 *fgaus = new TF1("GAUS","gaus",x2,x3); hist->Fit(fgaus,"RQN"); fgaus->GetParameters(&par[0]); //--**-- Final Peak Fit with Background --**--// TF1 *func = new TF1("FGAUS","gaus(0)+pol1(3)",x1,x4); func->SetParameters(par); hist->Fit(func,"R+QN"); func->GetParameters(par); epar[0]=func->GetParError(0); epar[1]=func->GetParError(1); epar[2]=func->GetParError(2); Double_t fwhm = par[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t efwhm = epar[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t N0 = par[0]*(TMath::Sqrt(TMath::TwoPi())*par[2]); Double_t r0 = epar[0]/par[0]; Double_t r2 = epar[2]/par[2]; Double_t eN0= N0*TMath::Sqrt(r0*r0+r2*r2); printf("Peak = %f +- %f; FFHM = %f +- %f; Area = %f +- %f\n", par[1],epar[1],fwhm,efwhm,N0,eN0); //printf("%11.4f %11.4f %11.0f %11.0f\n", // par[1],epar[1],N0,eN0); func->SetLineWidth(0.5); func->SetLineStyle(1); func->SetLineColor(4); func->SetFillColor(4); func->Draw("same"); }
void QAcentrality(const Char_t *fdata) { style(); TFile *fin = TFile::Open(fdata); TList *lin = (TList *)fin->Get("clist"); lin->ls(); TH1 *hin = (TH1 *)lin->FindObject("EvCentrDist"); Float_t sum = 1.2 * hin->Integral(hin->FindBin(0.1), hin->FindBin(79.9)); hin->Scale(1. / sum); SetHistoStyle(hin, 20, kRed+1); TCanvas *c = new TCanvas("cQAcentrality", "cQAcentrality", 800, 800); TH1 * hfr = c->DrawFrame(0., 0.005, 100., 0.015); hfr->SetTitle(";centrality percentile;events"); hin->Draw("same"); c->SaveAs(canvasPrefix+"centrality.pdf"); TH2 *hinv0 = (TH2 *)lin->FindObject("V0"); TCanvas *cv0 = new TCanvas("cQAcentralityV0", "cQAcentralityV0", 800, 800); cv0->SetLogx(); cv0->SetLogz(); // TH1 * hfrv0 = cv0->DrawFrame(100., -0.5, 50000., 10.5); // DrawBinLabelsY(hfrv0, kTRUE); // hfrv0->SetTitle(";V0 signal;"); //hinv0->Draw("same,col"); hinv0->Draw("col"); cv0->SaveAs(canvasPrefix+"centralityV0.pdf"); }
void fill_data(double e_min, double e_max, int mask) { const char name_pattern[] = "danss_report_v4n-sect%d-calc.root"; const char pos[3][20] = {"hUp_%d", "hMid_%d", "hDown_%d"}; char fname[1024]; char cpos[32]; int i, j; TFile *f; TH1* h; double val, err; for (i=0; i<3; i++) { sprintf(fname, name_pattern, 3-i); f = new TFile(fname); if (!f->IsOpen()) return; for (j=0; j<3; j++) { sprintf(cpos, pos[j], mask); h = (TH1*) f->Get(cpos); if (!h) { printf("Something is wrong: %d %d %s.\n", i, j, cpos); return; } val = h->IntegralAndError(h->FindBin(e_min), h->FindBin(e_max), err); DataArray.cnt[3*i+j] = val; DataArray.ecnt[3*i+j] = err; printf("%d %d %f +- %f\n", i, j, val, err); } f->Close(); } }
Double_t fitlang( char* hs, double klow = 18, double khigh = 40 ) { TH1 *h = (TH1*)gDirectory->Get(hs); if( h == NULL ){ cout << hs << " does not exist\n"; return 0; } double aa = h->GetEntries();//normalization // find peak: int ipk = h->GetMaximumBin(); double xpk = h->GetBinCenter(ipk); double sm = xpk / 9; // sigma double ns = sm; // noise // fit range: int ib0 = h->FindBin(klow); int ib9 = h->FindBin(khigh); double x0 = h->GetBinLowEdge(ib0); double x9 = h->GetBinLowEdge(ib9) + h->GetBinWidth(ib9); // create a TF1 with the range from x0 to x9 and 4 parameters TF1 *fitFcn = new TF1( "fitFcn", fitLandauGauss, x0, x9, 4 ); fitFcn->SetParName( 0, "peak" ); fitFcn->SetParName( 1, "sigma" ); fitFcn->SetParName( 2, "area" ); fitFcn->SetParName( 3, "smear" ); fitFcn->SetNpx(500); fitFcn->SetLineWidth(4); fitFcn->SetLineColor(kMagenta); // set start values: fitFcn->SetParameter( 0, xpk ); // peak position, defined above fitFcn->SetParameter( 1, sm ); // width fitFcn->SetParameter( 2, aa ); // area fitFcn->SetParameter( 3, ns ); // noise h->Fit("fitFcn", "NQR", "ep" );// R = range from fitFcn return fitFcn->GetParameter(0); }
TH1 *computeEffVsBEff(TH1 *effVsCut, TH1 *effVsCutB) { TH1 *h = new TH1F(Form("%s_effVsBEff", effVsCut->GetName()), "effVsBEff", 100, 0, 1); h->SetMaximum(1.5); h->SetMinimum(1e-3); unsigned int n = effVsCut->GetNbinsX(); for(unsigned int bin = 1; bin <= n; bin++) { double eff = effVsCut->GetBinContent(bin); double error = effVsCut->GetBinError(bin); double effB = effVsCutB->GetBinContent(bin); h->SetBinContent(h->FindBin(effB), eff); h->SetBinError(h->FindBin(effB), error); // FIXME: The error in effB is not propagated } return h; }
TEST_F(EvalHistMethods, CreateHistogram1D) { evaluator->SetNormalizationBuffer(norm); evaluator->SetParameterBuffer(params); TH1* hist = evaluator->CreateHistogram(); EXPECT_EQ(2, hist->GetNbinsX()); ASSERT_FLOAT_EQ(1.0, hist->Integral("width")); ASSERT_FLOAT_EQ(1.6, hist->GetBinContent(hist->FindBin(0.25))); ASSERT_FLOAT_EQ(0.4, hist->GetBinContent(hist->FindBin(0.75))); delete hist; }
void DrawReport(const char* psname, TObjArray* harr) { gStyle->SetOptFit(1); if (!harr) harr = &histoArr; TCanvas* cnv = new TCanvas("cl","cl",900,600); // TString psnm1 = psname; if (psnm1.IsNull()) psnm1 = "clusters.ps"; TString psnm0 = psnm1.Data(); psnm0 += "["; TString psnm2 = psnm1.Data(); psnm2 += "]"; cnv->Print(psnm0.Data()); // TH1* clall = GetHistoClSize(0,kNPixAll,harr); clall->SetLineColor(kRed); clall->Draw(); TH1* clSpl = GetHistoClSize(0,kNPixSPL,harr); clSpl->SetLineColor(kBlue); clSpl->Draw("sames"); gPad->Modified(); gPad->Update(); SetStPadPos(clall,0.75,0.97,0.8,1.,-1,clall->GetLineColor()); SetStPadPos(clSpl,0.75,0.97,0.6,0.8,-1,clSpl->GetLineColor()); gPad->Modified(); gPad->Update(); gPad->SetLogy(1); // cnv->cd(); cnv->Print(psnm1.Data()); // // plot cluster sized from 1 to 10 for (int i=1;i<=10;i++) { if (clall->GetBinContent(clall->FindBin(i))<100) continue; DrawNP(i,harr,cnv); cnv->Print(psnm1.Data()); } cnv->Print(psnm2.Data()); }
TCanvas* plotting36GS( bool logScale=false ) { std::cout << "plotting mu + standalone " << std::endl; TGaxis::SetMaxDigits(3); // channels, ordered as in the legend vector<TString> channels; vector<TString> hnames; vector<TString> type; map<TString,int> fillColor_; map<TString,int> lineColor_; int lineWidth1(2); int lineWidth2(1); bool salamanderStyle=true; if( salamanderStyle ) { fillColor_["Signal"] = kOrange-2; lineColor_["Signal"] = kOrange+3; fillColor_["EWK"] = kOrange+7; lineColor_["EWK"] = kOrange+3; fillColor_["QCD"] = kViolet-5; lineColor_["QCD"] = kViolet+3; fillColor_["ttbar"] = kRed+2; lineColor_["ttbar"] = kRed+4; fillColor_["gamma+jet"] = kMagenta+4; lineColor_["gamma+jet"] = kViolet+3; } else { lineWidth1 = 2; lineWidth2 = 2; fillColor_["Signal"] = kPink+6; lineColor_["Signal"] = kMagenta+3; fillColor_["EWK"] = kAzure+8; lineColor_["EWK"] = kAzure+4; fillColor_["QCD"] = kYellow-7; lineColor_["QCD"] = kYellow+4; fillColor_["ttbar"] = kGreen; lineColor_["ttbar"] = kGreen+2; fillColor_["gamma+jet"] = kOrange; lineColor_["gamma+jet"] = kOrange+2; } // root file, where the data is TString fname("root/"); // histogram limits, in linear and logarithmic int nbin_(100); float xmin_(0.), xmax_(0.); float ymin_(0.), ymax_(0.); float yminl_(0.), ymaxl_(0.); // titles and axis, marker size TString xtitle; TString ytitle; int ndivx(510); int ndivy(510); float markerSize(0.); float titleOffset(1.); float r0_ = 1.; float dr_ = 0.3; if( use_chi ) { r0_ = 0.; dr_ = 7.5; //dr_ = 3.0; } // canvas name TString cname(""); TString ctitle; // legend position and scale; float xl_ = 0.; float yl_ = 0.; float scalel_ = 0.0; { if( logScale ) // fname += "Zmumu_40-200_36pb"; fname += "Zmusta_36pb"; else fname += "Zmusta_36pb"; if( logScale ) { lineWidth1 = 1; lineWidth2 = 1; } channels.push_back("Zmumu"); hnames.push_back(" Z #rightarrow #mu^{+}#mu^{-}"); type.push_back("Signal"); bool revert(false); if( logScale ) { if( revert ) { channels.push_back("EWK"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("tt"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCD"); hnames.push_back(" QCD"); type.push_back("QCD"); } else { channels.push_back("EWK"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("tt"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCD"); hnames.push_back(" QCD"); type.push_back("QCD"); } } if( !logScale ) { // lin scale xmin_ = 60; xmax_ = 120; ymin_ = 0.01; ymax_ = 2100; } else { // log scale xmin_ = 40; xmax_ = 200; yminl_ = 0.08; ymaxl_ = 3000; } xtitle = "M(#mu^{+}#mu^{-}) [GeV]"; ytitle = "number of events /"; ndivx = 504; if( logScale ) { ytitle += "5 GeV"; ndivy = 510; } else { ytitle += " GeV"; ndivy = 506; } if( logScale ) { markerSize = 0.48; } else { markerSize = 0.75; } cname += "Zmusta"; ctitle = "Z to mu sta analysis"; if( logScale ) { xl_ = 0.60; yl_ = 0.50; scalel_ = 0.065; } else { xl_ = 0.22; yl_ = 0.50; scalel_ = 0.072; } } if( logScale ) cname += "MuSta_log"; else cname += "MuStaNotInThePAPER_lin"; //Open the root file containing histograms and graphs fname += ".root"; TFile* f_ = TFile::Open(fname,"READ"); TCanvas* c_ = new TCanvas(cname,ctitle,300,300,479,510); c_->SetLeftMargin( 87./479 ); c_->SetRightMargin( 42./479 ); c_->SetTopMargin( 30./510 ); c_->SetBottomMargin( 80./510 ); c_->SetFillColor(0); c_->SetTickx(1); c_->SetTicky(1); c_->SetFrameFillStyle(0); c_->SetFrameLineWidth(2); c_->SetFrameBorderMode(0); Double_t scale = 4; Double_t wbin = 42*scale; Double_t left = 8*scale; Double_t right = 5*scale; Double_t h1 = 135*scale; Double_t h2 = 45*scale; Double_t top1 = 15*scale; Double_t bot1 = 3*scale; Double_t top2 = 3*scale; // Double_t bot1 = 0*scale; // Double_t top2 = 0*scale; Double_t bot2 = 80*scale; Double_t W = left + wbin + right; Double_t H = h1 + h2; Double_t s[2] = {1, h1/h2 }; TPad* pad[2]; pad[0] = new TPad( "top", "top", 0, h2/H, 1, 1, kWhite,0,0); pad[0]->SetLeftMargin( left/W ); pad[0]->SetRightMargin( right/W ); pad[0]->SetTopMargin( top1/H ); pad[0]->SetBottomMargin( bot1/H ); pad[1] = new TPad( "bottom", "bottom", 0, 0, 1, h2/H, kWhite,0,0); pad[1]->SetLeftMargin( left/W ); pad[1]->SetRightMargin( right/W ); pad[1]->SetTopMargin( top2/H ); pad[1]->SetBottomMargin( bot2/H ); pad[1]->SetGridy(); for( int ii=0; ii<2; ii++ ) { pad[ii]->SetFillColor(0); pad[ii]->SetTickx(1); pad[ii]->SetTicky(1); pad[ii]->SetFrameFillStyle(0); pad[ii]->SetFrameLineWidth(2); pad[ii]->SetFrameBorderMode(0); pad[ii]->SetFrameFillStyle(0); pad[ii]->SetFrameLineWidth(2); pad[ii]->SetFrameBorderMode(0); } // a dummy histogram with the correct x axis // Warning: setTDRstyle() must be called before TH1F* h_= new TH1F( "bidon", "bidon", nbin_, xmin_, xmax_ ); TAxis* ax_ = h_->GetXaxis(); TAxis* ay_ = h_->GetYaxis(); ax_->SetTitle(xtitle); ax_->CenterTitle(); ax_->SetTitleOffset(1.0); ax_->SetNdivisions(ndivx); ay_->SetTitle(ytitle); ay_->CenterTitle(); ay_->SetNdivisions(ndivy); ay_->SetTitleOffset(titleOffset); ay_->SetLabelOffset(0.015); // fetch histograms and dress them vector<TH1F*> histos; size_t nChan=channels.size(); for( size_t ii=0;ii<nChan;ii++) { TH1F* tmp = (TH1F*)f_->Get(channels[ii]); tmp->SetFillColor( fillColor_[type[ii]] ); tmp->SetLineColor( lineColor_[type[ii]] ); tmp->SetLineWidth( lineWidth2 ); histos.push_back(tmp); } // // stack histograms // TH1* h_stack = (TH1*) histos[nChan-1]->Clone(); h_stack -> Reset(); TString stackName_ = TString("Mll"); vector<TH1*> listOfStackedHists; for( size_t ii=0; ii<nChan; ii++ ) { TH1* hh_ = (TH1*) histos[nChan-ii-1]->Clone(); stackName_ += "_"; stackName_ += hh_->GetName(); TAxis* xaxis = h_stack->GetXaxis(); for( int iBin=1; iBin<=xaxis->GetNbins(); iBin++ ) { hh_ -> AddBinContent( iBin, h_stack->GetBinContent( iBin ) ); } hh_->SetName( stackName_ ); delete h_stack; h_stack = hh_; listOfStackedHists.push_back( (TH1*)hh_->Clone() ); } delete h_stack; TH1* totalHisto = listOfStackedHists[nChan-1]; // colors the stacked histogram totalHisto->SetLineColor( lineColor_["Signal"] ); totalHisto->SetLineWidth( lineWidth1 ); // The data points are presented as a TGraph // - error bars indicate the Poisson confidence interval at 68% // - bins with zero entry are removed TH1* hdata = (TH1*) f_->Get("hdata"); // hdata->Sumw2(); //hdata->Rebin(2); RooHist* roohist; TGraphAsymmErrors* dataGraph; roohist = new RooHist((*hdata)); int Nn0=0; vector<double> vY; vector<double> vX; vector<double > veY; vector<double > veX; vector<double> tmp(0,2); for(int ip=0;ip<roohist->GetN();ip++) { double Y,X; roohist->GetPoint(ip,X,Y); if(Y!=0) { Nn0++; vY.push_back(Y); vX.push_back(X); veX.push_back( roohist->GetErrorXlow(ip) ); veX.push_back( roohist->GetErrorXhigh(ip) ); veY.push_back( roohist->GetErrorYlow(ip) ); veY.push_back( roohist->GetErrorYhigh(ip) ); } } dataGraph=new TGraphAsymmErrors(Nn0); for(int ip=0;ip<Nn0;ip++) { dataGraph->SetPoint(ip,vX[ip],vY[ip]); dataGraph->SetPointError(ip,veX[ip*2],veX[ip*2+1],veY[ip*2],veY[ip*2+1]); } dataGraph->SetName("data"); dataGraph->SetMarkerStyle(kFullCircle); dataGraph->SetMarkerColor(kBlack); dataGraph->SetMarkerSize(markerSize); TGraph* dummyGraph = (TGraph*) dataGraph->Clone("dummyGraph"); dummyGraph->SetLineColor(0); dummyGraph->SetMarkerSize(1.5*markerSize); // Remove the horizontal bars (at Michael's request) double x_(0), y_(0); for( int ii=0; ii<dataGraph->GetN(); ii++ ) { dataGraph->SetPointEXlow(ii,0); dataGraph->SetPointEXhigh(ii,0); dataGraph->GetPoint(ii,x_,y_ ); if( y_==0 ) { dataGraph->RemovePoint( ii ); ii--; } } // get the ratio data/fit TGraphAsymmErrors* ratioGraph = (TGraphAsymmErrors*) dataGraph->Clone("ratio"); TH1* hfit = totalHisto; for( int ii=0; ii<dataGraph->GetN(); ii++ ) { dataGraph->GetPoint(ii,x_,y_ ); ratioGraph->SetPointEYlow(ii,0); ratioGraph->SetPointEYhigh(ii,0); ratioGraph->SetPoint(ii,x_,0 ); double eyl_ = dataGraph->GetErrorYlow(ii); double eyh_ = dataGraph->GetErrorYhigh(ii); int jj = hfit->FindBin(x_); float fit_ = hfit->GetBinContent( jj ); if( fit_>0 ) { if( use_chi ) { ratioGraph->SetPointEYlow(ii,eyl_/sqrt(fit_)); ratioGraph->SetPointEYhigh(ii,eyh_/sqrt(fit_)); ratioGraph->SetPoint(ii,x_,(y_-fit_)/sqrt(fit_) ); } else { ratioGraph->SetPointEYlow(ii,eyl_/fit_); ratioGraph->SetPointEYhigh(ii,eyh_/fit_); ratioGraph->SetPoint(ii,x_,y_/fit_ ); } } // cout << ii << " ratio=" << ratioGraph->GetY()[ii] // << "+" << ratioGraph->GetEYhigh()[ii] // << "-" << ratioGraph->GetEYlow()[ii] << endl; } TH1* hratio_ = (TH1*) h_->Clone("hratio"); ax_->SetLabelOffset(99); ax_->SetTitleOffset(99); // // now plotting // c_->Draw(); c_->cd(); TPad* p_ = pad[0]; p_->Draw(); p_->cd(); if( logScale ) { p_->SetLogy(true); } else { p_->SetLogy(false); } if( !logScale ) { h_->GetYaxis()->SetRangeUser(ymin_+0.001*(ymax_-ymin_),ymax_); } else { h_->GetYaxis()->SetRangeUser(yminl_,ymaxl_); } h_->Draw(); float dxl_ = scalel_*3.5; float dyl_ = scalel_*1.8; if( logScale ) { dxl_ = scalel_*4; dyl_ = scalel_*3.4; } TLegend* legend=new TLegend(xl_,yl_,xl_+dxl_,yl_+dyl_); legend->SetLineColor(0); legend->SetFillColor(0); legend->SetTextFont(42); legend->SetTextSize(0.048); legend->AddEntry(dummyGraph," data","pl"); if( logScale ) { legend->AddEntry(dummyGraph," ","0"); } for(size_t ii=0;ii<nChan;ii++) { legend->AddEntry(histos[ii],hnames[ii],"f"); } legend->Draw("same"); totalHisto->Draw("same"); for( size_t ii=0; ii<nChan; ii++ ) { // listOfStackedHists[nChan-ii-1]->Sumw2(); listOfStackedHists[nChan-ii-1]->Rebin(1.); listOfStackedHists[nChan-ii-1]->Scale(1.); listOfStackedHists[nChan-ii-1]->Draw("Same"); } // draw the data points dataGraph->Draw("PE"); // redraw axis p_->RedrawAxis(); //lumi pad, cms prelim pad etc.. { int txtFont = 42; // bold is 62 float txtSize1 = 0.055; float txtX1 = 0.91; float txtY1 = 0.935; float txtSize2 = 0.05; float txtX2 = 0.85; float txtY2 = 0.83; // TEST FOR THE NAME ZMT, ZMMNONISO, ZMS float txtSize3 = 0.055; float txtX3 = 0.3; float txtY3 = 0.935; TLatex latex; latex.SetNDC(); latex.SetTextFont(txtFont); latex.SetTextSize(txtSize1); latex.SetTextAlign(31); // align right latex.DrawLatex(txtX1,txtY1,"CMS"); latex.SetTextAlign(31); // align right latex.SetTextSize(txtSize2); latex.DrawLatex(txtX2,txtY2,"36 pb^{-1} at #sqrt{s} = 7 TeV"); latex.SetTextAlign(21); // align left??? latex.SetTextSize(txtSize3); latex.DrawLatex(txtX3,txtY3,"global plus standalone muon"); } c_->cd(); p_ = pad[1]; p_->Draw(); p_->cd(); TAxis* xratio_ = hratio_->GetXaxis(); TAxis* yratio_ = hratio_->GetYaxis(); yratio_->SetRangeUser(r0_-0.9999*dr_,r0_+0.9999*dr_); yratio_->SetLabelSize( s[1]*yratio_->GetLabelSize() ); yratio_->SetTitleSize( s[1]*yratio_->GetTitleSize() ); yratio_->SetLabelOffset( yratio_->GetLabelOffset() ); yratio_->SetTitleOffset( yratio_->GetTitleOffset()/s[1] ); if( use_chi ) { yratio_->SetTitle("#chi"); yratio_->SetNdivisions(4); } else { yratio_->SetTitle("data/fit"); yratio_->SetNdivisions(3); } xratio_->SetLabelSize( s[1]*xratio_->GetLabelSize() ); xratio_->SetTitleSize( s[1]*xratio_->GetTitleSize() ); xratio_->SetTitleOffset( 1.0 ); xratio_->CenterTitle(); xratio_->SetLabelOffset( xratio_->GetLabelOffset()*s[1] ); xratio_->SetTickLength( xratio_->GetTickLength()*s[1] ); hratio_->Draw(); ratioGraph->SetMarkerSize( ratioGraph->GetMarkerSize()*1. ); ratioGraph->SetLineColor( kBlack ); ratioGraph->SetMarkerColor( kGray+2 ); ratioGraph->SetMarkerStyle( kFullCircle ); ratioGraph->DrawClone("PE"); ratioGraph->SetMarkerColor( kBlack ); ratioGraph->SetMarkerStyle( kOpenCircle ); ratioGraph->DrawClone("PE"); p_->RedrawAxis(); c_->cd(); return c_; }
bool TauAnalysisSelector::process(Long64_t entry) { double weight = 1.0; if(!fPuWeightName.empty()) { weight *= fPuWeight->value(); } fEventCounter.setWeight(weight); cAll.increment(); if(fIsEmbedded) { weight *= fGeneratorWeight->value(); fEventCounter.setWeight(weight); } cGeneratorWeight.increment(); /* std::cout << "FOO Event " << fEventInfo.event() << ":" << fEventInfo.lumi() << ":" << fEventInfo.run() << " electronVeto passed? " << fElectronVetoPassed->value() << std::endl; if( (fEventInfo.event() == 10069461 && fEventInfo.lumi() == 33572) || (fEventInfo.event() == 10086951 && fEventInfo.lumi() == 33630) || (fEventInfo.event() == 101065527 && fEventInfo.lumi() == 336953) || (fEventInfo.event() == 101450418 && fEventInfo.lumi() == 338236) || (fEventInfo.event() == 101460111 && fEventInfo.lumi() == 338268) ) { std::cout << "BAR Event " << fEventInfo.event() << ":" << fEventInfo.lumi() << ":" << fEventInfo.run() << " electronVeto passed? " << fElectronVetoPassed->value() << " Nelectrons " << fElectrons.size() << std::endl; for(size_t i=0; i<fElectrons.size(); ++i) { ElectronCollection::Electron electron = fElectrons.get(i); std::cout << " Electron " << i << " pt " << electron.p4().Pt() << " eta " << electron.p4().Eta() << " hasGsfTrack " << electron.hasGsfTrack() << " hasSuperCluster " << electron.hasSuperCluster() << " supercluster eta " << electron.superClusterEta() << " passIdVeto " << electron.cutBasedIdVeto() << std::endl; } } if(!fElectronVetoPassed->value()) return false; cElectronVeto.increment(); */ // Tau BR if(fIsEmbedded && fEmbeddingNormalizationMode == kIDTriggerEfficiencyTauBR) { weight *= (1-0.357); // from my thesis, which took the numbers from PDG fEventCounter.setWeight(weight); } cTauBRWeight.increment(); // MC status std::vector<GenParticleCollection::GenParticle> genTaus; GenParticleCollection::GenParticle theGenTau; if(isMC()) { bool canContinue = true; if(fIsEmbedded) { canContinue = findGenTaus(fGenTausEmbedded, 2212, &genTaus); canContinue = canContinue && genTaus.size() != 0; } else canContinue = findGenTaus(fGenTaus, 6, &genTaus); if(!canContinue) return false; } cGenTauFound.increment(); if(isMC() && fMCTauMultiplicity != kMCTauNone) { size_t ntaus = genTaus.size(); if(fIsEmbedded) { std::vector<GenParticleCollection::GenParticle> genTausOrig; findGenTaus(fGenTaus, 6, &genTausOrig); ntaus = genTausOrig.size(); } if(fIsEmbedded) { // For embedded the embedded tau is counted as one if(fMCTauMultiplicity == kMCTauZeroTaus) return true; if(fMCTauMultiplicity == kMCTauOneTau && ntaus != 0) return true; if(fMCTauMultiplicity == kMCTauTwoTaus && ntaus != 1) return true; if(fMCTauMultiplicity == kMCTauMoreThanTwoTaus && ntaus < 2) return true; } else { if(fMCTauMultiplicity == kMCTauZeroTaus && ntaus != 0) return true; if(fMCTauMultiplicity == kMCTauOneTau && ntaus != 1) return true; if(fMCTauMultiplicity == kMCTauTwoTaus && ntaus != 2) return true; if(fMCTauMultiplicity == kMCTauMoreThanTwoTaus && ntaus < 3) return true; } if(genTaus.size() > 0) theGenTau = genTaus[0]; } cTauMCSelection.increment(); bool originalMuonIsWMu = false; EmbeddingMuonCollection::Muon embeddingMuon; if(fIsEmbedded) { if(fMuons.size() != 1) throw std::runtime_error("Embedding muon collection size is not 1"); embeddingMuon = fMuons.get(0); if(embeddingMuon.p4().Pt() < 41) return true; //std::cout << "Muon pt " << muon.p4().Pt() << std::endl; originalMuonIsWMu = std::abs(embeddingMuon.pdgId()) == 13 && std::abs(embeddingMuon.motherPdgId()) == 24 && std::abs(embeddingMuon.grandMotherPdgId()) == 6; if(!originalMuonIsWMu) return true; } cOnlyWMu.increment(); // Per-event correction for W->tau->mu if(fIsEmbedded && fEmbeddingWTauMuWeights) { embeddingMuon.ensureValidity(); int bin = fEmbeddingWTauMuWeights->FindBin(embeddingMuon.p4().Pt()); //std::cout << embeddingMuon.p4().Pt() << " " << bin << std::endl; weight *= fEmbeddingWTauMuWeights->GetBinContent(bin); fEventCounter.setWeight(weight); } cWTauMuWeight.increment(); // Muon trigger efficiency weighting if(fIsEmbedded && (fEmbeddingNormalizationMode == kIDTriggerEfficiency || fEmbeddingNormalizationMode == kIDTriggerEfficiencyTauBR)) { weight *= 1/embeddingMuon.triggerEfficiency(); fEventCounter.setWeight(weight); } cTriggerEffWeight.increment(); // Muon ID efficiency weighting if(fIsEmbedded) { weight *= 1/embeddingMuon.idEfficiency(); fEventCounter.setWeight(weight); } cIdEffWeight.increment(); // Weighting by arbitrary histogram, given in constructor argument if(fIsEmbedded && fEmbeddingMuonWeights) { embeddingMuon.ensureValidity(); int bin = fEmbeddingMuonWeights->FindFixBin(embeddingMuon.p4().Pt()); weight *= fEmbeddingMuonWeights->GetBinContent(bin); fEventCounter.setWeight(weight); } cMuonWeight.increment(); // Jet selection /* size_t njets = fJets.size(); size_t nselectedjets = 0; for(size_t i=0; i<njets; ++i) { JetCollection::Jet jet = fJets.get(i); // Clean selected muon from jet collection bool matches = false; double DR = ROOT::Math::VectorUtil::DeltaR(fMuons.get(0).p4(), jet.p4()); if(DR < 0.1) { matches = true; } if(matches) continue; // Count jets ++nselectedjets; } if(nselectedjets < 3) return true; */ cJetSelection.increment(); if(fSelectedVertexCount->value() <= 0) return true; cPrimaryVertex.increment(); std::vector<TauCollection::Tau> selectedTaus; std::vector<TauCollection::Tau> tmp; if(fTaus.size() < 1) return true; cAllTauCandidates.increment(); // Pre pT cut (for some reason in the region pT < 10 there is significantly more normal than embedded) for(size_t i=0; i<fTaus.size(); ++i) { TauCollection::Tau tau = fTaus.get(i); if(tau.p4().Pt() < 10) continue; if(!TauID::isolation(tau)) continue; //if(isMC() && !fIsEmbedded && tau.genMatchP4().Pt() <= 41) continue; // temporary hack selectedTaus.push_back(tau); if(!fIsEmbedded) break; // select only the first gen tau } if(selectedTaus.empty()) return true; cPrePtCut.increment(); // Decay mode finding bool atLeastOneIsolated = false; for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::decayModeFinding(tau)) continue; if(TauID::isolation(tau)) { atLeastOneIsolated = true; hTau_AfterDecayModeFindingIsolation.fill(tau.p4(), weight); } tmp.push_back(tau); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cDecayModeFinding.increment(); if(atLeastOneIsolated) { if(theGenTau.isValid()) hGenTau_AfterDecayModeFindingIsolation.fill(theGenTau.p4(), weight); hVertexCount_AfterDecayModeFindingIsolation->Fill(fVertexCount->value(), weight); } // Eta cut atLeastOneIsolated = false; for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::eta(tau)) continue; if(TauID::isolation(tau)) { atLeastOneIsolated = true; hTau_AfterEtaCutIsolation.fill(tau.p4(), weight); } tmp.push_back(tau); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cEtaCut.increment(); if(atLeastOneIsolated) { hGenTau_AfterEtaCutIsolation.fill(theGenTau.p4(), weight); hVertexCount_AfterEtaCutIsolation->Fill(fVertexCount->value(), weight); } // Pt cut atLeastOneIsolated = false; for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::pt(tau)) continue; if(TauID::isolation(tau)) { atLeastOneIsolated = true; hTau_AfterPtCutIsolation.fill(tau.p4(), weight); hTauLeadingTrackPt_AfterPtCutIsolation->Fill(tau.leadPFChargedHadrCandP4().Pt(), weight); } tmp.push_back(tau); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cPtCut.increment(); if(atLeastOneIsolated) { hGenTau_AfterPtCutIsolation.fill(theGenTau.p4(), weight); hVertexCount_AfterPtCutIsolation->Fill(fVertexCount->value(), weight); } // Leading track pt atLeastOneIsolated = false; for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::leadingChargedHadrCandPt(tau)) continue; tmp.push_back(tau); if(TauID::isolation(tau)) { atLeastOneIsolated = true; hTau_AfterLeadingTrackPtCutIsolation.fill(tau.p4(), weight); } } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cLeadingTrackPtCut.increment(); if(atLeastOneIsolated) { hGenTau_AfterLeadingTrackPtCutIsolation.fill(theGenTau.p4(), weight); } // ECAL fiducial cuts for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::ecalCracks(tau)) continue; tmp.push_back(tau); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cEcalCracks.increment(); for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::ecalGap(tau)) continue; tmp.push_back(tau); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cEcalGap.increment(); // Against electron atLeastOneIsolated = false; for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::againstElectron(tau)) continue; tmp.push_back(tau); if(TauID::isolation(tau)) { atLeastOneIsolated = true; hTau_AfterAgainstElectronIsolation.fill(tau.p4(), weight); } } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cAgainstElectron.increment(); if(atLeastOneIsolated) { hGenTau_AfterAgainstElectronIsolation.fill(theGenTau.p4(), weight); } // Against muon atLeastOneIsolated = false; for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::againstMuon(tau)) continue; tmp.push_back(tau); if(TauID::isolation(tau)) { atLeastOneIsolated = true; hTau_AfterAgainstMuonIsolation.fill(tau.p4(), weight); } } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cAgainstMuon.increment(); if(atLeastOneIsolated) { hGenTau_AfterAgainstMuonIsolation.fill(theGenTau.p4(), weight); } // Tau candidate selection finished // Isolation for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::isolation(tau)) continue; int decayMode = tau.decayMode(); int fill = -1; if (decayMode <= 2) fill = decayMode; // 0 = pi+, 1 = pi+pi0, 2 = pi+pi0pi0 else if(decayMode == 10) fill = 3; // pi+pi-pi+ else fill = 4; // Other hTau_AfterIsolation.fill(tau.p4(), weight); hTauDecayModeAll_AfterIsolation->Fill(decayMode, weight); hTauDecayMode_AfterIsolation->Fill(fill, weight); tmp.push_back(tau); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cIsolation.increment(); hVertexCount_AfterIsolation->Fill(fVertexCount->value(), weight); if(theGenTau.isValid()) hGenTau_AfterIsolation.fill(theGenTau.p4(), weight); // One prong for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::oneProng(tau)) continue; tmp.push_back(tau); hTau_AfterOneProng.fill(tau.p4(), weight); hTauP_AfterOneProng->Fill(tau.p4().P(), weight); hTauLeadingTrackPt_AfterOneProng->Fill(tau.leadPFChargedHadrCandP4().Pt(), weight); hTauLeadingTrackP_AfterOneProng->Fill(tau.leadPFChargedHadrCandP4().P(), weight); hTauRtau_AfterOneProng->Fill(tau.rtau(), weight); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cOneProng.increment(); hGenTau_AfterOneProng.fill(theGenTau.p4(), weight); hVertexCount_AfterOneProng->Fill(fVertexCount->value(), weight); // Rtau for(size_t i=0; i<selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; if(!TauID::rtau(tau)) continue; hTau_AfterRtau.fill(tau.p4(), weight); tmp.push_back(tau); } selectedTaus.swap(tmp); tmp.clear(); if(selectedTaus.empty()) return true; cRtau.increment(); hVertexCount_AfterRtau->Fill(fVertexCount->value(), weight); if(theGenTau.isValid()) hGenTau_AfterRtau.fill(theGenTau.p4(), weight); // Tau ID finished // Trigger /* if(fIsEmbedded) { if(!fMuTriggerPassed->value()) return true; } */ cMuTrigger.increment(); if(false) { std::cout << "Event " << fEventInfo.event() << ":" << fEventInfo.lumi() << ":" << fEventInfo.run() << std::endl; for(size_t i=0; i< selectedTaus.size(); ++i) { TauCollection::Tau& tau = selectedTaus[i]; std::cout << " selected tau pt " << tau.p4().Pt() << " eta " << tau.p4().Eta() << " phi " << tau.p4().Phi() << std::endl; if(fIsEmbedded) { embeddingMuon.ensureValidity(); double DR = ROOT::Math::VectorUtil::DeltaR(tau.p4(), embeddingMuon.p4()); if(DR < 0.5) { std::cout << " matched to embedding muon, DR " << DR << std::endl; } } for(size_t j=0; j<fGenTaus.size(); ++j) { GenParticleCollection::GenParticle gen = fGenTaus.get(j); double DR = ROOT::Math::VectorUtil::DeltaR(tau.p4(), gen.p4()); if(DR < 0.5) { std::cout << " matched to generator tau, DR " << DR << " mother " << gen.motherPdgId() << " grandmother " << gen.grandMotherPdgId() << std::endl; } } } } return true; }
void GetEccenNpart_new(char* xname = "ile") { gStyle->SetOptStat(0); gStyle->SetTitle(0); char name[100]; TChain* ch = new TChain("t"); int n; //you need a file list of root ntuple: fxxxx.lis // sprintf(name,"f%s.lis",xname); cout << "open the filelist : " << name << endl; ifstream fin(name); string filename; while(!fin.eof()){ fin >> filename; if(filename.empty()) continue; cout << filename << endl; ch->AddFile(filename.c_str()); } fin.close(); double b; int ncoll; int npart; int nHitBbc_n, nHitBbc_s; double qBBC_n, qBBC_s; double vertex, ecc_std, ecc_rp, ecc_part,e4; double r_oll,r_geo,r_arith; ch->SetBranchAddress("b", &b ); ch->SetBranchAddress("vertex", &vertex ); ch->SetBranchAddress("ncoll", &ncoll ); ch->SetBranchAddress("npart", &npart ); ch->SetBranchAddress("ecc_std", &ecc_std ); ch->SetBranchAddress("ecc_rp", &ecc_rp ); ch->SetBranchAddress("ecc_part", &ecc_part ); ch->SetBranchAddress("r_ollitra", &r_oll ); ch->SetBranchAddress("r_geo", &r_geo ); ch->SetBranchAddress("r_arith", &r_arith ); ch->SetBranchAddress("e4", &e4 ); ch->SetBranchAddress("qBBC_n", &qBBC_n ); ch->SetBranchAddress("qBBC_s", &qBBC_s ); ch->SetBranchAddress("nHitBbc_n", &nHitBbc_n); ch->SetBranchAddress("nHitBbc_s", &nHitBbc_s); char fname[100]; sprintf(fname,"rootfile/g%s_cent.root",xname); TFile* fout = new TFile(fname,"recreate");//rootfile to save distributions TH1* hbbcq = new TH1D("hbbcq","hbbcq",12000,-0.5,2999.5); hbbcq->Sumw2(); TH1* hbbcqall = new TH1D("hbbcqall","hbbcqall",12000,-0.5,2999.5);hbbcqall->Sumw2(); TH1* hbbcqeff = new TH1D("hbbcqeff","hbbcqeff",12000,-0.5,2999.5);hbbcqeff->Sumw2(); n = ch->GetEntries(); cout << "events: "<< n << endl; //First loop determines the BBC trigger efficiency //as function of bbcq; for(int i=0; i<n; i++){ ch->GetEntry(i); if(nHitBbc_n>=2&&nHitBbc_s>=2){ hbbcq->Fill( (qBBC_n+qBBC_s)/100. );//divide by 100 to fit in 0-3000 range } hbbcqall->Fill( (qBBC_n+qBBC_s)/100. ); } hbbcqeff->Divide(hbbcq,hbbcqall); efficiency = hbbcq->Integral()/hbbcqall->Integral(); cout << "efficiency : " << efficiency << endl; //hbin contains the integrated fraction starting from 0 bbc charge, including the BBC trigger efficiency TH1* hbin = new TH1D("hbin","hbin",hbbcq->GetNbinsX(),-0.5,2999.5); TH1* hbbcqscale = (TH1*)hbbcq->Clone("hbbcqscale"); hbbcqscale->Scale(1.0/hbbcq->Integral()); for(int i=1; i<=hbbcqscale->GetNbinsX(); i++){ hbin->SetBinContent(i,hbbcqscale->Integral(1,i)); } //Following two lines defines the array of cuts and average bbc charge //for centrality percentitle in 5%, 10% and 20% steps double bbcq5[21],bbcq10[11],bbcq20[6]; double abbcq5[20],abbcq10[10],abbcq20[5]; //calculate the various variables for 5% step GetCentrality(hbin,20,bbcq5,hbbcq,abbcq5); cout << endl << endl; //calculate the various variables for 10% step GetCentrality(hbin,10,bbcq10,hbbcq,abbcq10); cout << endl << endl; //calculate the various variables for 20% step GetCentrality(hbin,5,bbcq20,hbbcq,abbcq20); cout << endl << endl; cout << " Find cuts for all the centralities " << endl << endl; const int nval=9;//number of variables to fill char* centname[3] = {"5pStep","10pStep","20pStep"}; char* varname[nval] = {"npart","ncoll","b","standard_ecc","reactionplane_ecc","participant_ecc","R_Ollitraut","R_Geo", "R_arith"}; double vup[nval] = {499.5,2999.5,19.995,1,1,1,4,4,4}; double vlo[nval] = {-0.5,-0.5,-0.005,-1,-1,-1,0,0,0}; int vNb[nval] = {500,3000,2000,200,200,200,400,400,400}; //initialize the histograms which are used to fill the distribution of variables for each centrality TH1* hvar[3][nval][20]; for(int i=0; i<3; i++){ int NC = 0; if(i==0) NC = 20; else if(i==1) NC = 10; else if(i==2) NC = 5; for(int ivar=0; ivar<nval; ivar++){ for(int icen=0; icen<NC; icen++){ sprintf(name,"hvar_%s_%s_cent%d",centname[i],varname[ivar],icen); hvar[i][ivar][icen] = new TH1D(name,name,vNb[ivar],vlo[ivar],vup[ivar]); } } } double qbbcsum; for(int i=0; i<n; i++){ if(i%1000000==0) cout << i << endl; ch->GetEntry(i); if(!(nHitBbc_n>=2&&nHitBbc_s>=2)) continue;//BBC trigger condition qbbcsum = (qBBC_n+qBBC_s)/100.; int centbin5 = FindBin(20,bbcq5,qbbcsum); int centbin10 = FindBin(10,bbcq10,qbbcsum); int centbin20 = FindBin(5,bbcq20,qbbcsum); if(centbin5==-1) continue; if(centbin10==-1) continue; if(centbin20==-1) continue; //find the weight according to the corresponding average efficiency. double weight = hbbcqeff->GetBinContent(hbbcqeff->FindBin(qbbcsum)); //5 percent step // hvar[0][0][centbin5]->Fill(npart,weight); hvar[0][1][centbin5]->Fill(ncoll,weight); hvar[0][2][centbin5]->Fill(b,weight); hvar[0][3][centbin5]->Fill(ecc_std,weight); hvar[0][4][centbin5]->Fill(ecc_rp,weight); hvar[0][5][centbin5]->Fill(ecc_part,weight); hvar[0][6][centbin5]->Fill(r_oll,weight); hvar[0][7][centbin5]->Fill(r_geo,weight); hvar[0][8][centbin5]->Fill(r_arith,weight); //10 percent step // hvar[1][0][centbin10]->Fill(npart,weight); hvar[1][1][centbin10]->Fill(ncoll,weight); hvar[1][2][centbin10]->Fill(b,weight); hvar[1][3][centbin10]->Fill(ecc_std,weight); hvar[1][4][centbin10]->Fill(ecc_rp,weight); hvar[1][5][centbin10]->Fill(ecc_part,weight); hvar[1][6][centbin10]->Fill(r_oll,weight); hvar[1][7][centbin10]->Fill(r_geo,weight); hvar[1][8][centbin10]->Fill(r_arith,weight); //20 percent step // hvar[2][0][centbin20]->Fill(npart,weight); hvar[2][1][centbin20]->Fill(ncoll,weight); hvar[2][2][centbin20]->Fill(b,weight); hvar[2][3][centbin20]->Fill(ecc_std,weight); hvar[2][4][centbin20]->Fill(ecc_rp,weight); hvar[2][5][centbin20]->Fill(ecc_part,weight); hvar[2][6][centbin20]->Fill(r_oll,weight); hvar[2][7][centbin20]->Fill(r_geo,weight); hvar[2][8][centbin20]->Fill(r_arith,weight); } //get mean and RMS values for the variables float var[3][nval+1][20]; float rms[3][nval+1][20]; for(int i=0; i<3; i++){ int NC = 0; if(i==0) NC = 20; else if(i==1) NC = 10; else if(i==2) NC = 5; for(int icen=0; icen<NC; icen++){ for(int ivar=0; ivar<nval; ivar++){ var[i][ivar][icen] = hvar[i][ivar][icen]->GetMean(); rms[i][ivar][icen] = hvar[i][ivar][icen]->GetRMS(); } var[i][nval][icen] = var[i][1][icen]/sigmann; rms[i][nval][icen] = rms[i][1][icen]/sigmann; } } //save to file for(int ivar=0; ivar<4; ivar++){ for(int icen=0; icen<16; icen++){ cout<<var[0][ivar][icen]<<","; } cout<<var[2][ivar][4]<<","; cout<<endl; } cout.precision(4); sprintf(name,"5pstepresults/t%s.txt",xname); ofstream f5(name); cout << " Bin % & npart & ncoll & b & ecc_std & ecc_rp & ecc_part & r_ollitrau & T_{AB}\\\\\\hline" << endl; for(int icen=0; icen<19; icen++){ for(int ivar=0; ivar<7; ivar++){ f5 << var[0][ivar][icen] << " "; } f5 << var[0][nval][icen] << " "; f5 <<endl<< " ("; /* for(int ivar=0; ivar<7; ivar++){ f5 << rms[0][ivar][icen] << " "; } f5 << rms[0][nval][icen] << " "; f5 << ")"<< endl; */ cout << icen*5 << "-" << icen*5+5; for(int ivar=0; ivar<7; ivar++){ cout <<" & " <<var[0][ivar][icen] ; } cout <<" & " <<var[0][nval][icen] ; cout <<"\\\\"<<endl; for(int ivar=0; ivar<7; ivar++){ if(ivar==0)cout <<" & ("<<rms[0][ivar][icen]; else cout <<" & "<<rms[0][ivar][icen]; } cout <<" & "<<rms[0][nval][icen]; cout << ")\\\\\\hline" << endl; // printf(" & %3.1f & %4.1f & %2.2f & %1.3f & %1.3f & %1.3f & %1.3f \\\\\n", // var[0][0][icen],var[0][1][icen],var[0][2][icen],var[0][3][icen],var[0][4][icen],var[0][5][icen],var[0][6][icen]); //printf(" (& %3.1f & %4.1f & %2.2f & %1.3f & %1.3f & %1.3f & %1.3f) \\\\\\hline\n", // rms[0][0][icen],rms[0][1][icen],rms[0][2][icen],rms[0][3][icen],rms[0][4][icen],rms[0][5][icen],rms[0][6][icen]); } f5.close(); cout << endl << endl; sprintf(name,"10pstepresults/t%s.txt",xname); ofstream f10(name); cout <<endl<< " Bin % & npart & ncoll & b & ecc_std & ecc_rp & ecc_part & r_ollitrau & T_{AB}\\\\\\hline" << endl; for(int icen=0; icen<10; icen++){ for(int ivar=0; ivar<7; ivar++){ f10 << var[1][ivar][icen] << " "; } f10 << var[1][nval][icen] << " "; f10 <<endl<<" ("; /*for(int ivar=0; ivar<7; ivar++){ f10 << rms[1][ivar][icen] << " "; } f10 << rms[1][nval][icen] << " "; f10 << ")" << endl; */ cout << icen*10 << "-" << icen*10+10; for(int ivar=0; ivar<7; ivar++){ cout <<" & " <<var[1][ivar][icen] ; } cout <<" & " <<var[1][nval][icen] ; cout <<"\\\\"<<endl; for(int ivar=0; ivar<7; ivar++){ if(ivar==0)cout <<" & ("<<rms[1][ivar][icen]; else cout <<" & "<<rms[1][ivar][icen]; } cout <<" & "<<rms[1][nval][icen]; cout << ")\\\\\\hline" << endl; //printf(" & %3.1f & %4.1f & %2.2f & %1.3f & %1.3f & %1.3f & %1.3f \\\\\n", // var[1][0][icen],var[1][1][icen],var[1][2][icen],var[1][3][icen],var[1][4][icen],var[1][5][icen],var[1][6][icen]); //printf(" (& %3.1f & %4.1f & %2.2f & %1.3f & %1.3f & %1.3f & %1.3f) \\\\\\hline\n", // rms[1][0][icen],rms[1][1][icen],rms[1][2][icen],rms[1][3][icen],rms[1][4][icen],rms[1][5][icen],rms[1][6][icen]); } f10.close(); cout << endl << endl; sprintf(name,"20pstepresults/t%s.txt",xname); ofstream f20(name); cout <<endl<< " Bin % & npart & ncoll & b & ecc_std & ecc_rp & ecc_part & r_ollitrau & T_{AB}\\\\\\hline" << endl; for(int icen=0; icen<5; icen++){ for(int ivar=0; ivar<7; ivar++){ f20 << var[2][ivar][icen] << " "; } f20 << var[2][nval][icen] << " "; f20 << endl<< " ("; /*for(int ivar=0; ivar<7; ivar++){ f20 << rms[2][ivar][icen] << " "; } f20 << rms[2][nval][icen] << " "; f20 << ")"<< endl; */ cout << icen*20 << "-" << icen*20+20; for(int ivar=0; ivar<7; ivar++){ cout <<" & " <<var[2][ivar][icen] ; } cout <<" & " <<var[2][nval][icen] ; cout <<"\\\\"<<endl; for(int ivar=0; ivar<7; ivar++){ if(ivar==0)cout <<" & ("<<rms[2][ivar][icen]; else cout <<" & "<<rms[2][ivar][icen]; } cout <<" & "<<rms[2][nval][icen]; cout << ")\\\\\\hline" << endl; //printf(" & %3.1f & %4.1f & %2.2f & %1.3f & %1.3f & %1.3f & %1.3f \\\\\n", // var[2][0][icen],var[2][1][icen],var[2][2][icen],var[2][3][icen],var[2][4][icen],var[2][5][icen],var[2][6][icen]); //printf(" (& %3.1f & %4.1f & %2.2f & %1.3f & %1.3f & %1.3f & %1.3f) \\\\\\hline\n", // rms[2][0][icen],rms[2][1][icen],rms[2][2][icen],rms[2][3][icen],rms[2][4][icen],rms[2][5][icen],rms[2][6][icen]); } f20.close(); fout->Write(); fout->Close(); return; }
/*============================================================================*/ void gaus2peakfit(Char_t *s, Float_t x1, Float_t x2, Float_t x3, Float_t x4) { Double_t par[8],epar[8],x[2],y[2]; TH1 *hist; hist = (TH1 *) gROOT->FindObject(s); TCanvas *c1=(TCanvas*) gROOT->FindObject("c1"); if(c1==NULL)setcanvas(1); c1->Clear(); hist->SetAxisRange(x1-30,x4+30); hist->Draw(); //--**-- Linear background estimation --**--// x[0] = x1; x[1] = x4; Int_t bin1 = hist->FindBin(x1); y[0] = hist->GetBinContent(bin1); Int_t bin2 = hist->FindBin(x4); y[1] = hist->GetBinContent(bin2); TGraph *g = new TGraph(2,x,y); TF1 *fpol1 = new TF1("POL1","pol1",x1,x4); g->Fit(fpol1,"RQN"); par[6]=fpol1->GetParameter(0); par[7]=fpol1->GetParameter(1); //--**-- Two Gaussian Peak estimation without background --**--// fgaus1 = new TF1("m1","gaus",x1,x2); fgaus2 = new TF1("m2","gaus",x3,x4); hist->Fit(fgaus1,"R+QN"); hist->Fit(fgaus2,"R+QN"); fgaus1->GetParameters(&par[0]); fgaus2->GetParameters(&par[3]); //--**-- Final Peak Fit with Background --**--// func = new TF1("m","gaus(0)+gaus(3)+pol1(6)",x1,x4); func->SetParameters(par); hist->Fit(func,"R+QN"); func->SetLineWidth(0.5); func->SetLineStyle(1); func->SetLineColor(4); func->SetFillColor(4); func->Draw("same"); func->GetParameters(par); epar[0]=func->GetParError(0); epar[1]=func->GetParError(1); epar[2]=func->GetParError(2); epar[3]=func->GetParError(3); epar[4]=func->GetParError(4); epar[5]=func->GetParError(5); Double_t fwhm1 = par[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t efwhm1 = epar[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t N10 = par[0]*(TMath::Sqrt(TMath::TwoPi())*par[2]); Double_t r10 = epar[0]/par[0]; Double_t r12 = epar[2]/par[2]; Double_t eN10= N10*TMath::Sqrt(r10*r10+r12*r12); Double_t fwhm2 = par[5]*TMath::Sqrt(8*TMath::Log(2)); Double_t efwhm2 = epar[5]*TMath::Sqrt(8*TMath::Log(2)); Double_t N20 = par[3]*(TMath::Sqrt(TMath::TwoPi())*par[5]); Double_t r20 = epar[3]/par[3]; Double_t r22 = epar[5]/par[5]; Double_t eN20= N20*TMath::Sqrt(r20*r20+r22*r22); //printf("Peak = %f +- %f; FFHM = %f +- %f; Area = %f +- %f\n", // par[1],epar[1],fwhm1,efwhm1,N10,eN10); //printf("Peak = %f +- %f; FFHM = %f +- %f; Area = %f +- %f\n", // par[4],epar[4],fwhm2,efwhm2,N20,eN20); printf("%11.4f %11.4f %11.0f %11.0f\n", par[1],epar[1],N10,eN10); printf("%11.4f %11.4f %11.0f %11.0f\n", par[4],epar[4],N20,eN20); }
TCanvas* WmunuOthers( int iV=0 ) { gStyle->SetOptStat(0); gStyle->SetOptTitle(0); TGaxis::SetMaxDigits(3); double intLumi(36); // channels, ordered as in the legend vector<TString> channels; vector<TString> hnames; vector<TString> type; map<TString,int> fillColor_; map<TString,int> lineColor_; int lineWidth1(2); int lineWidth2(1); bool salamanderStyle=true; if( salamanderStyle ) { lineWidth1 = 2; lineWidth2 = 1; fillColor_["Signal"] = kOrange-2; lineColor_["Signal"] = kOrange+3; fillColor_["EWK"] = kOrange+7; lineColor_["EWK"] = kOrange+3; fillColor_["QCD"] = kViolet-5; lineColor_["QCD"] = kViolet+3; fillColor_["ttbar"] = kRed+2; lineColor_["ttbar"] = kRed+4; fillColor_["gamma+jet"] = kMagenta+4; lineColor_["gamma+jet"] = kViolet+3; } else { lineWidth1 = 2; lineWidth2 = 2; fillColor_["Signal"] = kPink+6; lineColor_["Signal"] = kMagenta+3; fillColor_["EWK"] = kAzure+8; lineColor_["EWK"] = kAzure+4; fillColor_["QCD"] = kYellow-7; lineColor_["QCD"] = kYellow+4; fillColor_["ttbar"] = kGreen; lineColor_["ttbar"] = kGreen+2; fillColor_["gamma+jet"] = kOrange; lineColor_["gamma+jet"] = kOrange+2; } // log scale? bool logScaleY=false; bool logScaleX=false; // rebin? int rb = 1; // histogram limits, in linear and logarithmic int nbin_(0); float xmin_(0.), xmax_(0.); float ymin_(0.), ymax_(0.); float yminl_(0.), ymaxl_(0.); // titles and axis, marker size TString xtitle; TString ytitle; int ndivx(510); int ndivy(510); float markerSize(1.); float titleOffset(1.00); float r0_ = 1.; float dr_ = 0.3; if( use_chi ) { r0_ = 0.; dr_ = 7.5; } // canvas name TString cname; TString ctitle; // legend position and scale; float xl_ = 0.; float yl_ = 0.; float scalel_ = 0.075; // root file, where the data is // TString fname("../Results/"); TString fname = "./Wmunu_Fit_pfMet"; TString dataHistName("data"); double factor; // *** // Only the following is specific if( iV==6 || iV==7 || iV==20 || iV ==22 || iV==21 || iV==23) { if( iV==6 || iV==20 || iV==22) { // MET plots in linear scale (inclusive) if(iV==20) fname = "./Wmunu_PLUS_pfMet"; else if(iV==22) fname = "./Wmunu_MINUS_pfMet"; logScaleY = false; ctitle = "W to mu-nu analysis - MET linear scale"; dataHistName = "DataMET"; channels.push_back("WTemplateMET"); if(iV==6) {cname="Wmn_MET";hnames.push_back(" W #rightarrow #mu#nu"); factor=1;} else if(iV==20) {cname="Wmn_MET_plus";hnames.push_back(" W^{+} #rightarrow #mu^{+}#nu"); factor=3./5.;} else {cname="Wmn_MET_minus";hnames.push_back(" W^{-} #rightarrow #mu^{-}#nu");factor=2./5.;} type.push_back("Signal"); channels.push_back("NonQCDMET"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDMET"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 100; xmin_ = 0.; xmax_ = 100.; xtitle = "#slash{E}_{T} [GeV]"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; xl_ = 0.6; yl_ = 0.53; //ymax_ = 500.*intLumi*factor; if(iV==6) ymax_ = 14e3; else ymax_ = 8e3; } else if( iV==7 || iV==21 || iV==23) { // MET plots in log scale (inclusive) logScaleY = true; if(iV==21) fname = "./Wmunu_PLUS_pfMet"; else if(iV==23) fname = "./Wmunu_MINUS_pfMet"; ctitle = "W to mu-nu analysis - MET log scale"; dataHistName = "DataMET"; channels.push_back("WTemplateMET"); if(iV==7) {cname="Wmn_MET";hnames.push_back(" W #rightarrow #mu#nu");} else if(iV==21) {cname="Wmn_MET_plus";hnames.push_back(" W^{+} #rightarrow #mu^{+}#nu");} else {cname="Wmn_MET_minus";hnames.push_back(" W^{-} #rightarrow #mu^{-}#nu");} type.push_back("Signal"); channels.push_back("EWKMET"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("TTbar_MCMET"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCDMET"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 200; xmin_ = 0.; xmax_ = 200.; xtitle = "#slash{E}_{T} [GeV]"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 0.9; yminl_ = 0.05; ymaxl_ = 800.*intLumi; xl_ = 0.6; yl_ = 0.43; } } else if( iV==8 || iV==9 ) { if( iV==8 ) {cname="pt"; // pT plots in linear scale (inclusive) logScaleY = false; ctitle = "W to mu-nu analysis - pT linear scale"; dataHistName = "DataPT"; channels.push_back("WTemplatePT"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("NonQCDPT"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDPT"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 60; xmin_ = 20.; xmax_ = 80.; xtitle = "p_{T}(#mu) [GeV]"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; ymax_ = 500.*intLumi; xl_ = 0.6; yl_ = 0.53; } else if( iV==9 ) {cname="pt"; // pT plots in log scale (inclusive) logScaleY = true; ctitle = "W to mu-nu analysis - pT log scale"; dataHistName = "DataPT"; channels.push_back("WTemplatePT"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("EWKPT"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("TTbar_MCPT"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCDPT"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 80; xmin_ = 20.; xmax_ = 100.; xtitle = "p_{T}(#mu) [GeV]"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 0.9; yminl_ = 0.1; ymaxl_ = 30000.*intLumi; xl_ = 0.6; yl_ = 0.45; } } else if( iV==13 || iV==14 ) { if( iV==13 ) {cname="ptw"; // pT plots in linear scale (inclusive) logScaleY = false; ctitle = "W to mu-nu analysis - W pT linear scale"; dataHistName = "DataPTW"; channels.push_back("WTemplatePTW"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("NonQCDPTW"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDPTW"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 100; xmin_ = 0.; xmax_ = 100.; xtitle = "p_{T}(W) [GeV]"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; ymax_ = 500.*intLumi; xl_ = 0.6; yl_ = 0.53; } else if( iV==14 ) {cname="ptw"; // pT plots in log scale (inclusive) logScaleY = true; ctitle = "W to mu-nu analysis - pT log scale"; dataHistName = "DataPTW"; channels.push_back("WTemplatePTW"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("EWKPTW"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("TTbar_MCPTW"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCDPTW"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 100; xmin_ = 0.; xmax_ = 100.; xtitle = "p_{T}(W) [GeV]"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 0.9; yminl_ = 0.1; ymaxl_ = 45000.*intLumi; xl_ = 0.6; yl_ = 0.48; } } else if( iV==10 || iV==11 || iV==12 ) { if( iV==10 ) {cname="iso"; // isolation plot in linear scale logScaleY = false; ctitle = "W to mu-nu analysis - isolation, linear scale"; dataHistName = "DataISO"; channels.push_back("WTemplateISO"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("NonQCDISO"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDISO"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 25; xmin_ = 0.; xmax_ = 0.5; xtitle = "I^{rel}_{comb}"; ytitle = "number of events"; //ytitle = "CMS preliminary"; ndivx = 506; ndivy = 506; markerSize = 1.1; titleOffset = 1.25; ymin_ = 0.; ymax_ = 5000.*intLumi; xl_ = 0.6; yl_ = 0.53; } else if( iV==11 ) {cname="iso"; // isolation plot in log scale logScaleY = true; ctitle = "W to mu-nu analysis - isolation, log scale"; dataHistName = "DataISO"; channels.push_back("WTemplateISO"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("EWKISO"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("TTbar_MCISO"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCDISO"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 25; xmin_ = 0.; xmax_ = 0.5; xtitle = "I^{rel}_{comb}"; ytitle = "number of events"; //ytitle = "CMS preliminary"; ndivx = 506; ndivy = 506; markerSize = 0.9; yminl_ = 50; ymaxl_ = 30000.*intLumi; xl_ = 0.6; yl_ = 0.45; } else if( iV==12 ) {cname="iso2"; // isolation plot in log scale logScaleX = true; logScaleY = true; ctitle = "W to mu-nu analysis - isolation, log scale"; dataHistName = "DataISO"; channels.push_back("WTemplateISO"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("EWKISO"); hnames.push_back(" EWK"); type.push_back("EWK"); channels.push_back("TTbar_MCISO"); hnames.push_back(" t#bar{t}"); type.push_back("ttbar"); channels.push_back("QCDISO"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 200; xmin_ = 0.; xmax_ = 0.5; xtitle = "I^{rel}_{comb}"; ytitle = "number of events"; ndivx = 506; ndivy = 506; markerSize = 0.9; yminl_ = 1; ymaxl_ = 4000000.*intLumi; xl_ = 0.6; yl_ = 0.45; } } else if( iV==15 ) {cname="acop"; // pT plots in linear scale (inclusive) logScaleY = false; ctitle = "W to mu-nu analysis - acop linear scale"; dataHistName = "DataACOP"; channels.push_back("WTemplateACOP"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("NonQCDACOP"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDACOP"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 60; xmin_ = 0; xmax_ = 3.14; xtitle = "acop"; ytitle = "number of events"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; ymax_ = 400.*intLumi; xl_ = 0.6; yl_ = 0.53; } else if( iV==16 ) {cname="eta"; // pT plots in linear scale (inclusive) logScaleY = false; ctitle = "W to mu-nu analysis - eta linear scale"; dataHistName = "DataETA"; channels.push_back("WTemplateETA"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("NonQCDETA"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDETA"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 60; xmin_ = -3; xmax_ = 3; xtitle = "eta"; ytitle = "number of events"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; ymax_ = 120.*intLumi; xl_ = 0.25; yl_ = 0.63; } else if( iV==17 ) {cname="ptw_minus"; fname = "./Wmunu_MINUS_pfMet"; // pT plots in linear scale (inclusive) logScaleY = false; ctitle = "W to mu-nu analysis - eta linear scale"; dataHistName = "DataPTW"; channels.push_back("WTemplatePTW"); hnames.push_back(" W^{-} #rightarrow #mu^{-}#nu"); type.push_back("Signal"); channels.push_back("NonQCDPTW"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDPTW"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 100; xmin_ = 0; xmax_ = 100; xtitle = "W pt (GeV)"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; ymax_ = 200.*intLumi; xl_ = 0.6; yl_ = 0.53; } else if( iV==18 ) {cname="ptw_plus"; fname = "./Wmunu_PLUS_pfMet"; // pT plots in linear scale (inclusive) logScaleY = false; ctitle = "W to mu-nu analysis - eta linear scale"; dataHistName = "DataPTW"; channels.push_back("WTemplatePTW"); hnames.push_back(" W^{+} #rightarrow #mu^{+}#nu"); type.push_back("Signal"); channels.push_back("NonQCDPTW"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDPTW"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 100; xmin_ = 0; xmax_ = 100; xtitle = "W pt (GeV)"; ytitle = "number of events / 2 GeV"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; ymax_ = 300.*intLumi; xl_ = 0.6; yl_ = 0.53; } else if( iV==19 ) {cname="phi"; //fname = "../Results/Wmunu__pfMet.root"; // pT plots in linear scale (inclusive) logScaleY = false; ctitle = "W to mu-nu analysis - phi linear scale"; dataHistName = "DataPHI"; channels.push_back("WTemplatePHI"); hnames.push_back(" W #rightarrow #mu#nu"); type.push_back("Signal"); channels.push_back("NonQCDPHI"); hnames.push_back(" EWK+t#bar{t}"); type.push_back("EWK"); channels.push_back("QCDPHI"); hnames.push_back(" QCD"); type.push_back("QCD"); nbin_ = 60; xmin_ = -3.5; xmax_ = 3.5; xtitle = "Phi"; ytitle = "number of events"; ndivx = 506; ndivy = 506; markerSize = 1.1; ymin_ = 0.; ymax_ = 100.*intLumi; xl_ = 0.25; yl_ = 0.63; } int nChan=channels.size(); // open the root file containing histograms and graphs fname += ".root"; TFile* f_ = TFile::Open(fname,"READ"); // the canvas if( logScaleY ) cname += "_log"; //else cname += "_lin"; TCanvas* c_=new TCanvas(cname,ctitle,300,300,479,510); c_->SetLeftMargin( 87./479 ); c_->SetRightMargin( 42./479 ); c_->SetTopMargin( 30./510 ); c_->SetBottomMargin( 80./510 ); c_->SetFillColor(0); c_->SetTickx(1); c_->SetTicky(1); c_->SetFrameFillStyle(0); c_->SetFrameLineWidth(2); c_->SetFrameBorderMode(0); Double_t scale = 4; Double_t wbin = 42*scale; Double_t left = 8*scale; Double_t right = 5*scale; Double_t h1 = 135*scale; Double_t h2 = 45*scale; Double_t top1 = 15*scale; Double_t bot1 = 3*scale; Double_t top2 = 3*scale; // Double_t bot1 = 0*scale; // Double_t top2 = 0*scale; Double_t bot2 = 80*scale; Double_t W = left + wbin + right; Double_t H = h1 + h2; Double_t s[2] = {1, h1/h2 }; TPad* pad[2]; pad[0] = new TPad( "top", "top", 0, h2/H, 1, 1, kWhite,0,0); pad[0]->SetLeftMargin( left/W ); pad[0]->SetRightMargin( right/W ); pad[0]->SetTopMargin( top1/H ); pad[0]->SetBottomMargin( bot1/H ); pad[1] = new TPad( "bottom", "bottom", 0, 0, 1, h2/H, kWhite,0,0); pad[1]->SetLeftMargin( left/W ); pad[1]->SetRightMargin( right/W ); pad[1]->SetTopMargin( top2/H ); pad[1]->SetBottomMargin( bot2/H ); pad[1]->SetGridy(); for( int ii=0; ii<2; ii++ ) { pad[ii]->SetFillColor(0); pad[ii]->SetTickx(1); pad[ii]->SetTicky(1); pad[ii]->SetFrameFillStyle(0); pad[ii]->SetFrameLineWidth(2); pad[ii]->SetFrameBorderMode(0); pad[ii]->SetFrameFillStyle(0); pad[ii]->SetFrameLineWidth(2); pad[ii]->SetFrameBorderMode(0); } // a dummy histogram with the correct x axis // Warning: setTDRstyle() must be called before cout << nbin_<<endl; TH1F* h_= new TH1F( "bidon", "bidon", nbin_, xmin_, xmax_ ); TAxis* ax_ = h_->GetXaxis(); TAxis* ay_ = h_->GetYaxis(); ax_->SetTitle(xtitle); ax_->CenterTitle(); ax_->SetNdivisions(ndivx); ax_->SetTitleOffset(1.0); ax_->SetTitleSize( 1.4*ax_->GetTitleSize() ); ax_->SetLabelSize( 1.2*ax_->GetLabelSize() ); ay_->SetTitle(ytitle); ay_->CenterTitle(); ay_->SetNdivisions(ndivy); /*if(logScaleY) */ titleOffset *=1.1; ay_->SetTitleOffset(titleOffset); ay_->SetLabelOffset(0.015); ay_->SetLabelSize( 1.2*ay_->GetLabelSize() ); ay_->SetTitleSize( 1.4*ay_->GetTitleSize() ); // fetch histograms and dress them vector<TH1F*> histos; for( int ii=0; ii<nChan; ii++ ) { TH1F* tmp = (TH1F*)f_->Get(channels[ii]); tmp->Rebin(rb); tmp->SetStats(kFALSE); // tmp->UseCurrentStyle(); tmp->SetFillStyle( 1001 ); tmp->SetFillColor( fillColor_[type[ii]] ); tmp->SetLineColor( lineColor_[type[ii]] ); tmp->SetLineWidth( lineWidth2 ); histos.push_back(tmp); } TH1* h_sig = (TH1*) histos[0]->Clone(); h_sig->SetFillStyle(0); h_sig->SetLineColor(lineColor_["Signal"]); h_sig->SetLineWidth( 2 ); h_sig->SetLineStyle( kDashed ); TH1* h_tot = (TH1*) histos[0]->Clone(); h_tot->SetFillStyle(0); // // stack histogram // THStack* stackedHisto=new THStack("stackedHisto","XXX"); TH1F* totalHisto(0); for(int ii=0;ii<nChan;ii++) { stackedHisto->Add(histos[nChan-ii-1],"ah"); if(ii==0) { totalHisto = (TH1F*)histos[ii]->Clone(); } else { totalHisto->Add(histos[ii]); } } // colors the stacked histogram totalHisto->SetLineColor( lineColor_["Signal"] ); totalHisto->SetFillColor( 0 ); totalHisto->SetLineWidth( lineWidth1 ); // The data points are presented as a TGraph // possibly a TGraph with asymmetric errors where // - error bars indicate the Poisson confidence interval at 68% // - bins with zero entry are removed // TGraphAsymmErrors* dataGraph = (TGraphAsymmErrors*)f_->Get("data"); // The data points are presented as a TGraph // possibly a TGraph with asymmetric errors where // - error bars indicate the Poisson confidence interval at 68% // - bins with zero entry are removed TH1* hdata = (TH1*) f_->Get( dataHistName ); assert( hdata ); hdata->Rebin(rb); RooHist* roohist; TGraphAsymmErrors* dataGraph; roohist = new RooHist((*hdata)); int Nn0=0; vector<double> vY; vector<double> vX; vector<double > veY; vector<double > veX; vector<double> tmp(0,2); for(int ip=0;ip<roohist->GetN();ip++) { double Y,X; // double eY[2],eX[2]; roohist->GetPoint(ip,X,Y); if(Y!=0) { Nn0++; vY.push_back(Y); vX.push_back(X); veX.push_back( roohist->GetErrorXlow(ip) ); veX.push_back( roohist->GetErrorXhigh(ip) ); veY.push_back( roohist->GetErrorYlow(ip) ); veY.push_back( roohist->GetErrorYhigh(ip) ); } } dataGraph=new TGraphAsymmErrors(Nn0); for(int ip=0;ip<Nn0;ip++) { dataGraph->SetPoint(ip,vX[ip],vY[ip]); dataGraph->SetPointError(ip,veX[ip*2],veX[ip*2+1],veY[ip*2],veY[ip*2+1]); } dataGraph->SetName("data"); dataGraph->SetMarkerStyle(kFullCircle); dataGraph->SetMarkerColor(kBlack); if(logScaleY) markerSize *= 0.45; else markerSize *= 0.7; dataGraph->SetMarkerSize(markerSize); TGraph* dummyGraph = (TGraph*) dataGraph->Clone("dummyGraph"); dummyGraph->SetLineColor(0); dummyGraph->SetMarkerSize(1.5*markerSize); // Remove the null bins double x_(0), y_(0); for( int ii=0; ii<dataGraph->GetN(); ii++ ) { dataGraph->SetPointEXlow(ii,0); dataGraph->SetPointEXhigh(ii,0); dataGraph->GetPoint(ii,x_,y_ ); if( y_==0 ) { dataGraph->RemovePoint( ii ); ii--; } } // get the ratio data/fit TGraphAsymmErrors* ratioGraph = (TGraphAsymmErrors*) dataGraph->Clone("ratio"); TH1* hfit = totalHisto; for( int ii=0; ii<dataGraph->GetN(); ii++ ) { dataGraph->GetPoint(ii,x_,y_ ); ratioGraph->SetPointEYlow(ii,0); ratioGraph->SetPointEYhigh(ii,0); ratioGraph->SetPoint(ii,x_,0 ); double eyl_ = dataGraph->GetErrorYlow(ii); double eyh_ = dataGraph->GetErrorYhigh(ii); int jj = hfit->FindBin(x_); float fit_ = hfit->GetBinContent( jj ); if( fit_>0 ) { if( use_chi ) { ratioGraph->SetPointEYlow(ii,eyl_/sqrt(fit_)); ratioGraph->SetPointEYhigh(ii,eyh_/sqrt(fit_)); ratioGraph->SetPoint(ii,x_,(y_-fit_)/sqrt(fit_) ); } else { ratioGraph->SetPointEYlow(ii,eyl_/fit_); ratioGraph->SetPointEYhigh(ii,eyh_/fit_); ratioGraph->SetPoint(ii,x_,y_/fit_ ); } } // cout << ii << " ratio=" << ratioGraph->GetY()[ii] // << "+" << ratioGraph->GetEYhigh()[ii] // << "-" << ratioGraph->GetEYlow()[ii] << endl; } TH1* hratio_ = (TH1*) h_->Clone("hratio"); ax_->SetLabelOffset(99); ax_->SetTitleOffset(99); // // now plotting // c_->Draw(); c_->cd(); TPad* p_ = pad[0]; p_->Draw(); p_->cd(); if( logScaleY ) { p_->SetLogy(true); } else { p_->SetLogy(false); } if( !logScaleY ) { h_->GetYaxis()->SetRangeUser(ymin_+0.001*(ymax_-ymin_),rb*ymax_); } else { h_->GetYaxis()->SetRangeUser(yminl_,rb*ymaxl_); } h_->Draw("hist"); float dxl_ = scalel_*3.5; float dyl_ = scalel_*(nChan+0.5); TLegend* legend=new TLegend(xl_,yl_,xl_+dxl_,yl_+dyl_); legend->SetTextFont(42); legend->SetTextSize(0.045); legend->SetLineColor(0); legend->SetFillColor(0); legend->AddEntry(dummyGraph," data","pl"); legend->AddEntry(dummyGraph," ","0"); // skip a line for( int ii=0; ii<nChan; ii++ ) { legend->AddEntry(histos[ii],hnames[ii],"f"); } legend->Draw("same"); stackedHisto->Draw("samehist"); h_sig->Draw("samehist"); totalHisto->Draw("samehist"); // draw the data points dataGraph->Draw("PE"); // redraw axis p_->RedrawAxis(); //lumi pad, cms prelim pad etc.. { int txtFont = 42; float txtSize1 = 0.055; float txtX1 = 0.91; float txtY1 = 0.935; float txtSize2 = 0.05; float txtX2 = 0.85; float txtY2 = 0.83; TLatex latex; latex.SetNDC(); latex.SetTextFont(txtFont); latex.SetTextSize(txtSize1); latex.SetTextAlign(31); // align right // latex.DrawLatex(txtX1,txtY1,"CMS preliminary"); latex.DrawLatex(txtX1,txtY1,"CMS"); latex.SetTextAlign(31); // align right latex.SetTextSize(txtSize2); latex.DrawLatex(txtX2,txtY2,"36 pb^{-1} at #sqrt{s} = 7 TeV"); } c_->cd(); p_ = pad[1]; p_->Draw(); p_->cd(); TAxis* xratio_ = hratio_->GetXaxis(); TAxis* yratio_ = hratio_->GetYaxis(); yratio_->SetRangeUser(r0_-0.9999*dr_,r0_+0.9999*dr_); yratio_->SetLabelSize( s[1]*yratio_->GetLabelSize() ); yratio_->SetTitleSize( s[1]*yratio_->GetTitleSize() ); yratio_->SetLabelOffset( yratio_->GetLabelOffset() ); yratio_->SetTitleOffset( yratio_->GetTitleOffset()/s[1] ); if( use_chi ) { yratio_->SetTitle("#chi"); yratio_->SetNdivisions(4); } else { yratio_->SetTitle("data/fit"); yratio_->SetNdivisions(3); } xratio_->SetLabelSize( s[1]*xratio_->GetLabelSize() ); xratio_->SetTitleSize( s[1]*xratio_->GetTitleSize() ); xratio_->SetTitleOffset( 1.0 ); xratio_->CenterTitle(); xratio_->SetLabelOffset( xratio_->GetLabelOffset()*s[1] ); xratio_->SetTickLength( xratio_->GetTickLength()*s[1] ); hratio_->Draw(); ratioGraph->SetMarkerSize( ratioGraph->GetMarkerSize()*1. ); ratioGraph->SetLineColor( kBlack ); ratioGraph->SetMarkerColor( kGray+2 ); ratioGraph->SetMarkerStyle( kFullCircle ); ratioGraph->DrawClone("PE"); ratioGraph->SetMarkerColor( kBlack ); ratioGraph->SetMarkerStyle( kOpenCircle ); ratioGraph->DrawClone("PE"); p_->RedrawAxis(); c_->cd(); c_->SaveAs("plot.pdf"); return c_; }
void AnalysisSparse(Bool_t save_output = kFALSE) { gStyle->SetGridColor(kGray); // TString tmpstr(fname); // if (tmpstr.Contains("data")) { // Printf("!!! Real Data !!!"); // mc = kFALSE; // } TString gtitle = Form("Monte Carlo, %s", graph_name.Data()); grapht = graph_name.Data(); Double_t grx[999], gry[999], gry2[999], gry3[999], gry4[999], gry_eff[999], gry_fix[999], grxE[999]; Double_t gry22[999], gry22E[999], grx22E[999]; Double_t gry_true[999], gry_true_eff[999], gry_true_effE[999]; TH1::AddDirectory(kFALSE); TFile::SetCacheFileDir(gSystem->HomeDirectory()); TFile *f = TFile::Open(fname.Data(), "CACHEREAD"); if (!f) return; TList *l; f->GetObject(lname.Data(), l); if (!l) return; Int_t bf[999], bl[999]; Int_t nn = FindExactRange(((THnSparse *)(l->FindObject(s1name.Data())))-> Projection(1), del_step, bf, bl); // Int_t nn = FindRange5(bf, bl); Bool_t binhaluska = kFALSE; if (binAnders) { nn = 8; bf[0] = 6;bf[1] = 9;bf[2] = 11;bf[3] = 16;bf[4] = 21;bf[5] = 26; bl[0] = 8;bl[1] = 10;bl[2] = 15;bl[3] = 20;bl[4] = 25;bl[5] = 30; bf[6] = 31;bf[7] = 41; bl[6] = 40;bl[7] = 50; } Printf("number of intervals = %d =>", nn); Int_t count = 0; Double_t ptmean = 0, value = 0; Int_t fitStatus = -1; gStyle->SetOptStat(0); TCanvas *c = new TCanvas("c", "Signal & Background"); c->Divide(5, 5); c->Modified(); c->Draw(); TCanvas *c2 = (TCanvas *)c->DrawClone("c2"); c2->SetTitle("Phi mesons (raw)"); c2->Modified(); c2->Draw(); TCanvas *c3, *c4; if (mc) { c3 = (TCanvas *)c->DrawClone("c3"); c3->SetTitle("Phi mesons (gen)"); c3->Modified(); c3->Draw(); c4 = (TCanvas *)c->DrawClone("c4"); c4->SetTitle("Phi mesons (true)"); c4->Modified(); c4->Draw(); } for (Int_t i = 0; i < nn; i++) { c->cd(count + 1)->SetGrid(); h1 = (TH1D *)PullHisto(l, s1name.Data(), bf[i], bl[i], ptmean); h1->SetLineColor(kRed); h1->GetXaxis()->SetTitle("inv. mass, GeV/c^2"); h1->Draw("hist"); h3_p = (TH1D *)PullHisto(l, s3name_p.Data(), bf[i], bl[i], ptmean); h3_m = (TH1D *)PullHisto(l, s3name_m.Data(), bf[i], bl[i], ptmean); // !!!!!!!!!!!!!!!!!!!!!!!! if (count==0) h3_p = h1; // !!!!!!!!!!!!!!!!!!!!!!!! else { h3_p->Add(h3_m); // h3_p->Add((TH1D *)PullHisto(l, smix.Data(), bf[i], bl[i], ptmean)); // h3_p->Add((TH1D *)PullHisto(l, smixpp.Data(), bf[i], bl[i], ptmean)); // h3_p->Add((TH1D *)PullHisto(l, smixmm.Data(), bf[i], bl[i], ptmean)); Norm(h1, h3_p, norm[0], norm[1]); } h3_p->SetLineColor(kBlue); h3_p->Draw("hist, same"); if (mc) { c3->cd(count + 1)->SetGrid(); Printf("%s", s1namegen.Data()); hg = (TH1D *)PullHisto(l, s1namegen.Data(), bf[i], bl[i], ptmean); hg->SetLineColor(kMagenta); hg->GetXaxis()->SetTitle("inv. mass, GeV/c^2"); hg->Draw("hist"); c4->cd(count + 1)->SetGrid(); ht = (TH1D *)PullHisto(l, s1nametrue.Data(), bf[i], bl[i], ptmean); ht->SetLineColor(kMagenta-5); ht->GetXaxis()->SetTitle("inv. mass, GeV/c^2"); ht->Draw("hist"); } c2->cd(count + 1)->SetGrid(); TH1 *hh = (TH1 *)h1->Clone("hh"); hh->SetLineColor(kRed+1); hh->Add(h3_p, -1); /// !!!!!!!!!!!!!!!!!!!!!! ////////// if ((ilist == 3) && (count < 2)) hh->Reset(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! hh->Draw("hist"); // !!!!!!!!!!!!!!!!!! ff->SetParameters(0.1, 1.02, 0.004, -25000., 0., 0., 0.); ff->SetLineColor(hh->GetLineColor()); ff->SetLineWidth(1); // ff->SetLineStyle(kDashed); // where fit Double_t fmin = 1.02-2*0.004; Double_t fmax = 1.02+2*0.004; // Double_t fmin = 0.995; // Double_t fmax = 1.185; // !!!!!!!!!!!!!!!!!! Bool_t hisfun = kFALSE; // kFALSE = integral from function Double_t hisfun_k = 1.0/hh->GetBinWidth(10); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (binhaluska) if (i > 9) hisfun_k = 0.5/hh->GetBinWidth(10); Printf("======= %f", hisfun_k); // !!!!!!!!!!!!!!!!!! // wehere integral (his or fun) Double_t fmini = 1.02-2*0.004; Double_t fmaxi = 1.02+2*0.004; hh->Fit(ff, "Q", "", fmin, fmax); hh->Fit(ff, "Q", "", fmin, fmax); fitStatus = hh->Fit(ff, "Q", "", fmin, fmax); TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax); pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4), ff->GetParameter(5), ff->GetParameter(6)); pp3->SetLineWidth(1); pp3->SetLineColor(h3_p->GetLineColor()); pp3->Draw("same"); // ff->SetRange(fmin, fmax); // ff->DrawCopy("same"); value = hh->Integral(hh->FindBin(fmini), hh->FindBin(fmaxi)); if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k - pp3->Integral(fmini, fmaxi)*hisfun_k; if (value < 0) value = 0; if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) { printf(" SKIP Data"); value = 0; } grx[count] = ptmean; if (binhaluska) { if (count < 10) grxE[count] = 0.25; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! else grxE[count] = 0.50; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! } else // grxE[count] = (1.30-1.10)/2.0; // !!!!!!!!!!!!!!!!!!!!!!!!!! grxE[count] = 0.05; gry[count] = value; Double_t tmp1 = h1->Integral(h1->FindBin(fmini), h1->FindBin(fmaxi)); Double_t tmp2 = h3_p->Integral(h3_p->FindBin(fmini), h3_p->FindBin(fmaxi)); Double_t tmp_sg = tmp1 - tmp2; Double_t tmp_bg = tmp2; // if ((tmp_sg <= -tmp_bg) || (tmp_bg < 33.0)) { // gry3[count] = 0.0; // gry4[count] = 0.0; // } // else { gry3[count] = tmp_sg/tmp_bg; gry4[count] = tmp_sg/TMath::Sqrt(tmp_sg + tmp_bg); // } // Printf("%4.2f, %10f, %10f, %10f", ptmean, tmp1, tmp2, gry3[count]); if (mc) { c3->cd(count + 1); // !!!!!!!!!!!!!!!! ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.); hg->Fit(ff, "Q", "", fmin, fmax); hg->Fit(ff, "Q", "", fmin, fmax); fitStatus = hg->Fit(ff, "Q", "", fmin, fmax); /* TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax); pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4), ff->GetParameter(5), ff->GetParameter(6)); pp3->SetLineWidth(1); pp3->SetLineColor(h3_p->GetLineColor()); pp3->Draw("same"); */ value = hg->Integral(hg->FindBin(fmini), hg->FindBin(fmaxi)); if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k; //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k; if (value <= 0) value = -1; if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) { printf(" SKIP MC"); value = -1; } gry2[count] = value; Double_t superfactor = CalculateFactor(l, 0.1); if (useCF) { gry22E[i] = TMath::Sqrt(gry2[i])*superfactor; // gry22E[i] = 0.0001; gry22[i] = gry2[i]*superfactor; grx22E[i] = 0.05; } gry_eff[count] = gry[count]/gry2[count]; c4->cd(count + 1); // !!!!!!!!!!!!!!!! ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.); ht->Fit(ff, "Q", "", fmin, fmax); ht->Fit(ff, "Q", "", fmin, fmax); fitStatus = ht->Fit(ff, "Q", "", fmin, fmax); /* TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax); pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4), ff->GetParameter(5), ff->GetParameter(6)); pp3->SetLineWidth(1); pp3->SetLineColor(h3_p->GetLineColor()); pp3->Draw("same"); */ value = ht->Integral(ht->FindBin(fmini), ht->FindBin(fmaxi)); if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k; //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k; if (value <= 0) value = -1; if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) { printf(" SKIP true"); value = -1; } gry_true[count] = value; gry_true_eff[count] = gry_true[count]/gry2[count]; // Propagation of uncertainty (A/B) Double_t AAA = gry_true[count]; Double_t AAAE = TMath::Sqrt(AAA); Double_t BBB = gry2[count]; Double_t BBBE = TMath::Sqrt(BBB); Double_t EEE = TMath::Sqrt((AAAE/AAA)*(AAAE/AAA)+(BBBE/BBB)*(BBBE/BBB)); EEE = EEE*gry_true_eff[count]; gry_true_effE[count] = EEE; } Printf("=> %6.4f", ptmean); count++; } new TCanvas(); TGraph *gr = new TGraph(count, grx, gry); gr->SetMarkerStyle(8); gr->SetMarkerColor(hh->GetLineColor()); gr->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr->SetTitle(Form("raw phi, %s", gtitle.Data())); gr->Draw("AP"); cc3 = new TCanvas(); TGraph *gr3 = new TGraph(count, grx, gry3); gr3->SetMarkerStyle(22); gr3->SetMarkerColor(kBlue+1); gr3->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr3->SetTitle(Form("SIG / BKG, %s", gtitle.Data())); gr3->SetMinimum(0); gr3->Draw("AP"); cc4 = new TCanvas(); TGraph *gr4 = new TGraph(count, grx, gry4); gr4->SetMarkerStyle(23); gr4->SetMarkerColor(kBlue-1); gr4->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr4->SetTitle(Form("Significance, %s", gtitle.Data())); gr4->SetMinimum(0); gr4->Draw("AP"); ccc = new TCanvas("ccc","ccc",0,0,900,300); ccc->Divide(2, 1, 0.001, 0.001); ccc->cd(1); gr3->Draw("AP"); ccc->cd(2); gr4->Draw("AP"); TString blabla = "mc"; if (!mc) blabla = "data"; // gr3->SaveAs(Form("SB_%s_%s.C", blabla.Data(), grapht.Data())); // gr4->SaveAs(Form("Sig_%s_%s.C", blabla.Data(), grapht.Data())); // ccc->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data())); // c->SaveAs(Form("%s_%s_0.eps", blabla.Data(), grapht.Data())); // c2->SaveAs(Form("%s_%s_1.eps", blabla.Data(), grapht.Data())); // cc3->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data())); // gr3->SaveAs(Form("sig_bck_%s_%s.C", blabla.Data(), grapht.Data())); if (mc) { new TCanvas(); TGraph *gr2 = new TGraph(count, grx, gry2); gr2->SetMarkerStyle(8); gr2->SetMarkerColor(hg->GetLineColor()); gr2->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr2->SetTitle(Form("gen phi, %s", gtitle.Data())); gr2->Draw("AP"); new TCanvas(); TGraphErrors *gr22 = new TGraphErrors(count, grx, gry22, grx22E, gry22E); gr22->SetMarkerStyle(8); gr22->SetMarkerColor(kCyan); gr22->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr22->SetTitle(Form("gen phi, %s", gtitle.Data())); gr22->Draw("AP"); c = new TCanvas(); c->SetGrid(); TGraph *gr_e = new TGraph(count, grx, gry_eff); gr_e->SetMarkerStyle(22); gr_e->SetMarkerColor(kBlack); gr_e->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_e->SetTitle(Form("efficiency (raw), %s", grapht.Data())); gr_e->Draw("AP"); Printf("Save as '\033[1meffi_raw_%s\033[0m' file", grapht.Data()); for (Int_t i = 0; i < gr_e->GetN(); i++) Printf("%f %f", gr_e->GetX()[i], gr_e->GetY()[i]); cvb = new TCanvas(); cvb->cd(); TGraph *gr_true = new TGraph(count, grx, gry_true); gr_true->SetMarkerStyle(8); gr_true->SetMarkerColor(ht->GetLineColor()); gr_true->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_true->SetTitle(Form("true phi, %s", gtitle.Data())); gr_true->Draw("AP"); c = new TCanvas(); c->cd(); c->SetGrid(); TGraphErrors *gr_true_eff = new TGraphErrors(count, grx, gry_true_eff, grxE, gry_true_effE); gr_true_eff->SetMarkerStyle(20); // gr_true_eff->SetMarkerSize(0.75); gr_true_eff->SetMarkerColor(kBlack); gr_true_eff->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_true_eff->SetTitle(Form("efficiency (true), %s", grapht.Data())); gr_true_eff->Draw("AEP"); m_gr->Add(gr_true_eff); Printf("Save as '\033[1meffi_true_%s\033[0m' file", grapht.Data()); TString tout; Double_t oux, ouy, ouxe, ouye; for (Int_t i = 0; i < gr_true_eff->GetN(); i++) { oux = gr_true_eff->GetX()[i]; ouy = gr_true_eff->GetY()[i]; ouy = MinusCheck(ouy); ouxe = gr_true_eff->GetErrorX(i); ouye = gr_true_eff->GetErrorY(i); ouye = NanCheck(ouye); Printf("%f %f %f %f", gr_true_eff->GetX()[i], gr_true_eff->GetY()[i], gr_true_eff->GetErrorX(i), gr_true_eff->GetErrorY(i)); if (!save_output) continue; gSystem->mkdir(dir_prefix.Data()); tout = Form("%f %f %f %f", oux, ouy, ouxe, ouye); if (i == 0) tout = Form("Printf(\"%s\"); > %s/effi_%s", tout.Data(), dir_prefix.Data(), grapht.Data()); else tout = Form("Printf(\"%s\"); >> %s/effi_%s", tout.Data(), dir_prefix.Data(), grapht.Data()); // Printf(":::::: %s", tout.Data()); gROOT->ProcessLine(tout.Data()); } // ------------------ c = new TCanvas("cfinal", "mc_effi", 1200, 450); c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw(); c->cd(1); gr_true->SetMinimum(0); gr_true->SetTitle(Form("phi (true & raw), %s", gtitle.Data())); gr_true->SetMarkerColor(kGreen+1); gr_true->Draw("AP"); gr->SetMarkerColor(kRed+1); gr->Draw("P"); c->cd(2)->SetGrid(); gr_true_eff->SetMinimum(0); gr_true_eff->SetTitle(Form("efficiency, %s", grapht.Data())); gr_true_eff->SetMarkerColor(kGreen+1); gr_true_eff->Draw("AP"); gr_e->SetMarkerColor(kRed+1); gr_e->Draw("P"); // c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data())); return; } // TGraph *geff = new TGraph(Form("effi_raw_%s", grapht.Data())); // TGraph *geff = new TGraph(Form("effi_true_%s", grapht.Data())); // TGraph *geff = new TGraph("effi_true_Phi2010_qualityonly"); TGraph *geff = new TGraph("effi_true_PhiNsigma_qualityonly"); if (geff->IsZombie()) return; geff->SetMarkerStyle(22); geff->SetMarkerColor(kBlack); geff->GetXaxis()->SetTitle("p_{t}, GeV/c"); geff->SetTitle(Form("efficiency, %s", grapht.Data())); c = new TCanvas(); c->SetGrid(); geff->Draw("AP"); Double_t tpcsigma = 9999.9; if (ilist == 1) tpcsigma = 1.0; if (ilist == 2) tpcsigma = 1.5; if (ilist == 3) tpcsigma = 2.0; if (ilist == 4) tpcsigma = 2.5; if (ilist == 5) tpcsigma = 3.0; Double_t sss = TMath::Erf(tpcsigma/TMath::Sqrt(2.0)); if (noSigma) sss = 1.0; Printf("sigma = %10f", sss); // for (Int_t i = 0; i < count; i++) // geff->GetY()[i] = (sss*sss)/(geff->GetY()[i]); // geff->SetMaximum(1.0); // geff->Draw("AP"); for (Int_t i = 0; i < count; i++) { Double_t deno = geff->Eval(grx[i])*sss*sss; if (deno < 0.00001) deno = 1; gry_fix[i] = gry[i]/deno; } new TCanvas; TGraph *gr_fix = new TGraph(count, grx, gry_fix); gr_fix->SetMarkerStyle(21); gr_fix->SetMarkerColor(hh->GetLineColor()); gr_fix->GetXaxis()->SetTitle("p_{t}, GeV/c"); gr_fix->SetTitle(Form("corrected phi * #sigma^{2}, %s", gtitle.Data())); if (noSigma) gr_fix->SetTitle(Form("corrected phi (no #sigma), %s", gtitle.Data())); gr_fix->Draw("AP"); //--------------------- c = new TCanvas("cfinald", "data_correct", 1200, 450); c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw(); c->cd(1); gr->SetMinimum(0); gr->SetMarkerColor(kBlack); gr->Draw("AP"); c->cd(2); gr_fix->SetMinimum(0); gr_fix->SetMarkerColor(kGreen+3); gr_fix->Draw("AP"); TString bla9 = Form("qualityonly_PID2_%s", grapht.Data()); if (noSigma) bla9 = Form("%s_noSig.C", bla9.Data()); else bla9 = Form("%s.C", bla9.Data()); // gr_fix->SaveAs(bla9.Data()); // TPad *cp = new TPad("cpf", "", 0.45,0.45,0.99,0.92); TPad *cp = new TPad("cpf", "", 0.60,0.55,0.99,0.93); cp->SetLogy(); cp->Draw(); cp->cd(); TGraph *cloneg = ((TGraph *)gr_fix->Clone()); cloneg->SetTitle(); cloneg->SetMarkerSize(0.8); cloneg->Draw("AP"); // c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data())); f->Close(); }
void Fit::nll(int& ndim, double* gout, double& result, double* par, int flags) { size_t n = Fit::signals.size(); result = 0; // make summed fit histogram TH1* hfit = (TH1*) signals[0].histogram->Clone("hfit"); hfit->Reset(); for (size_t i=0; i<n; i++) { TH1* h = Fit::signals.at(i).histogram; h->Scale(1.0/h->Integral()); hfit->Add(h, Fit::norms[i] * par[i]); } // loop over bins if (hfit->IsA() == TH2F::Class()) { TH2F* h2 = dynamic_cast<TH2F*>(hfit); for (int i=1; i<h2->GetNbinsX(); i++) { if (i < h2->GetXaxis()->FindBin(Fit::r_range.min) || i > h2->GetXaxis()->FindBin(Fit::r_range.max)) { continue; } for (int j=1; j<h2->GetNbinsY(); j++) { if (j < h2->GetYaxis()->FindBin(Fit::e_range.min) || j > h2->GetYaxis()->FindBin(Fit::e_range.max)) { continue; } double nexp = h2->GetBinContent(i, j); double nobs = dynamic_cast<TH2F*>(Fit::data)->GetBinContent(i, j); result += (nexp - nobs * TMath::Log(TMath::Max(1e-12, nexp))); //std::cout << "- " << nexp << " " << nobs << " " << TMath::Log(nexp) << " // " << result << std::endl; } } } else { for (int i=1; i<hfit->GetNbinsX(); i++) { if (i < hfit->FindBin(Fit::e_range.min) || i > hfit->FindBin(Fit::e_range.max)) { continue; } double nexp = hfit->GetBinContent(i); double nobs = Fit::data->GetBinContent(i); result += (nexp - nobs * TMath::Log(TMath::Max(1e-12, nexp))); //std::cout << "- " << nexp << " " << nobs << " " << TMath::Log(nexp) << " // " << result << std::endl; } } // constraints for (size_t i=0; i<n; i++) { if (Fit::signals.at(i).constraint > 0) { result += 0.5 * TMath::Power((par[i]-1.0) / Fit::signals.at(i).constraint, 2); } } delete hfit; #ifdef DEBUG // print parameters at each iteration std::cout << "+ "; for (size_t i=0; i<n; i++) { std::cout << par[i] * Fit::signals.at(i).rate << " (" << par[i] << ") \t"; } std::cout << result << std::endl; #endif }
// The probability to find a value of the test statistic equal or // worse than the one obtained with the observed yields void ToyExperiments::printGlobalPValueOfObservation(unsigned int nExperiments) const { std::cout << "Performing " << nExperiments << " toy experiments to compute global p-value of observation ... " << std::flush; // The test statistic TH1* hTestStat = new TH1D("hTestStat","",10000*Parameters::nBins(),0,1000); std::vector<unsigned int> obs(Parameters::nBins(),0); // Minimal value (in standard deviations) allowed for //correlated fluctuation const double minCorr = findMinValidRandomNumberForCorrelatedUncertainties(); // Throw mean values for(unsigned int p = 0; p < nExperiments; ++p) { // Throw one (normalized) random number for correlated // uncertainties that is valid in all bins double rCorr = rand_->Gaus(0.,1.); while( rCorr <= minCorr ) { rCorr = rand_->Gaus(0.,1.); } // Loop over all bins and get individual predictions for(unsigned int bin = 0; bin < Parameters::nBins(); ++bin) { double prediction = -1.; bool negativePrediction = true; while( negativePrediction ) { // Throw one (normalized) random number for uncorrelated // uncertainties that is valid in this bin only double rUncorr = rand_->Gaus(0.,1.); // Scale the normalized random numbers by the uncertainties' size // to obtain variation of yield double uncorrVar = rUncorr * uncorrelatedUncerts_.at(bin); double corrVar = rCorr * correlatedUncerts_.at(bin); // Add variations to yield prediction = meanPredictions_.at(bin) + uncorrVar + corrVar; // Check if prediction is positive if( prediction >= 0. ) { negativePrediction = false; } } // Throw predicted yields from Poisson with // this mean obs.at(bin) = rand_->Poisson(prediction); } // End of loop over bins hTestStat->Fill(testStatistic(obs)); } std::cout << "ok" << std::endl; std::cout << "\n\n----- Global p-value of observation -----" << std::endl; double tSObs = testStatistic(observedYields_); int binTSObs = hTestStat->FindBin(tSObs); int binTSTot = hTestStat->GetNbinsX()+1; // Include overflows double gpVal = hTestStat->Integral(binTSObs,binTSTot)/hTestStat->Integral(1,binTSTot); if( binTSObs == binTSTot ) { std::cerr << " ERROR: observed value of test statistic out of histogram range" << std::endl; } else if( hTestStat->GetBinContent(binTSTot) > 0 ) { std::cerr << " WARNING: distribution of test statistic has overflows (N = " << hTestStat->GetBinContent(binTSTot) << ")" << std::endl; } std::cout << " observed value of test statistic : " << tSObs << std::endl; std::cout << " global p-value (including correlations) : " << gpVal << " (" << TMath::NormQuantile(1.-gpVal) << "sig)" << std::endl; hTestStat->Draw(); gPad->SetLogy(); gPad->SaveAs("TestStatistic.pdf"); delete hTestStat; }