void drawFrequency(const char* ifname="output/HUMAN.pair.output", int type=2) { gROOT->SetStyle("Plain"); TFile outfile(TString(TString(ifname)+".root"),"RECREATE"); int nbins = 400; if(type == 1)nbins = 20; TH1F* freq = new TH1F("freq","",nbins,-0.5,float(nbins)-0.5); int bin = 1; ifstream infile(ifname); while(1){ TString name; float freq1,freq2; infile >> name >> freq1; if(type == 2) infile >> freq2; if(!infile.good()) break; freq->SetBinContent(bin,freq1); bin++; } infile.close(); TCanvas* c = new TCanvas("c","",800,600); gStyle->SetOptStat(0); freq->SetYTitle("Frequency"); freq->SetXTitle("Amino acid pair"); if(type == 1)freq->SetXTitle("Amino acid"); freq->SetLineWidth(2); freq->SetLineColor(kBlue); freq->Draw(); c->SaveAs(TString(TString(ifname)+".pdf")); outfile.Close(); }
void read21m() { TFile *f = new TFile("read21.root"); //root file name TTree *ntuple = (TTree*)f->Get("ntuple"); Float_t hm,zm; //Values ntuple->SetBranchAddress("hm",&hm); //Values ntuple->SetBranchAddress("zm",&zm); //create histogram TH1F *higg = new TH1F("hm","Higgs invariant mass distribution",100,0,300.); TH1F *zboson = new TH1F("zm","Z0 invariant mass distribution",100,0,300.); //read all entries and fill the histograms Long64_t nentries = ntuple->GetEntries(); for (Long64_t q=0;q<nentries;q++) { ntuple->GetEntry(q); higg->Fill(hm); //Histogram value zboson->Fill(zm); } { higg->SetXTitle("m[GeV]"); higg->SetYTitle("Event"); zboson->SetXTitle("m[GeV]"); zboson->SetYTitle("Event"); } if (gROOT->IsBatch()) return; f->Write(); new TBrowser(); ntuple->StartViewer(); }
TH1F * DrawOverflow(TH1F *h) { // This function paint the histogram h with an extra bin for overflows UInt_t nx = h->GetNbinsX()+1; Double_t *xbins= new Double_t[nx+1]; for (UInt_t i=0;i<nx;i++) xbins[i]=h->GetBinLowEdge(i+1); xbins[nx]=xbins[nx-1]+h->GetBinWidth(nx); char *tempName= new char[strlen(h->GetName())+10]; sprintf(tempName,"%swtOverFlow",h->GetName()); // Book a temporary histogram having ab extra bin for overflows TH1F *htmp = new TH1F(tempName, h->GetTitle(), nx, xbins); // Reset the axis labels htmp->SetXTitle(h->GetXaxis()->GetTitle()); htmp->SetYTitle(h->GetYaxis()->GetTitle()); // Fill the new hitogram including the extra bin for overflows for (UInt_t i=1; i<=nx; i++) htmp->Fill(htmp->GetBinCenter(i), h->GetBinContent(i)); // Fill the underflows htmp->Fill(h->GetBinLowEdge(1)-1, h->GetBinContent(0)); // Restore the number of entries htmp->SetEntries(h->GetEntries()); // FillStyle and color htmp->SetFillStyle(h->GetFillStyle()); htmp->SetFillColor(h->GetFillColor()); return htmp; }
void DrawJMS_vs_Eta(Str jetAlgo) { double massEbins[] = {50, 100, 250, 500, 750, 1500}; double massNbins = sizeof(massEbins)/sizeof(double); myJES = new JetCalibrationTool(jetAlgo,_jesFile); TH1F *h = new TH1F("","",100,-4.8,4.8); h->SetXTitle("Jet #eta_{det}"); h->SetYTitle("Jet mass response"); h->SetMaximum(1.4); h->SetMinimum(0.6); h->Draw(); TLine *l = new TLine(); l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(4); l->DrawLine(-4.65,1,4.65,1); for (int i=0;i<massNbins;++i) { Graph *g = GetJMSGraph(massEbins[i]); FormatGraph(g,i); g->Draw("PL"); double x=0.52, y=0.3-0.05*i; if (i>2) { x=0.74; y=0.3-0.05*(i-3); } DrawLabel(Form("E = %.0f GeV",massEbins[i]),x,y,i); } tex->SetNDC(); tex->SetTextAlign(12); tex->DrawLatex(0.18,0.975,myJES->AbsoluteJES_Description()); tex->DrawLatex(0.18,0.9,jetAlgo); }
void DrawInsituCorr_vs_Pt(Str jetAlgo) { myJES = new JetCalibrationTool(jetAlgo,_jesFile); TH1F *h = new TH1F("","",100,15,2500); h->SetXTitle("Jet p_{T}"); h->SetYTitle("Residual correction for data only"); h->SetMaximum(1.1); h->SetMinimum(0.85); h->Draw(); TLine *l = new TLine(); l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(4); l->DrawLine(16,1,2400,1); for (int i=0;i<6;++i) { double eta=4.0*i/5; Graph *g = GetInsituGraphVsPt(eta); FormatGraph(g,i); g->Draw("PL"); double x=0.52, y=0.3-0.05*i; if (i>2) { x=0.74; y=0.3-0.05*(i-3); } DrawLabel(Form("#eta = %.1f",eta),x,y,i); } l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(1); tex->SetNDC(); tex->SetTextAlign(12); //tex->DrawLatex(0.18,0.975,myJES->AbsoluteJES_Description()); tex->DrawLatex(0.18,0.9,GetJetDesc(jetAlgo)); }
void gerrors2() { TCanvas *c1 = new TCanvas("c1","gerrors2",200,10,700,500); c1->SetGrid(); // draw a frame to define the range TH1F *hr = c1->DrawFrame(-0.4,0,1.2,12); hr->SetXTitle("X title"); hr->SetYTitle("Y title"); c1->GetFrame()->SetBorderSize(12); // create first graph const Int_t n1 = 10; Double_t xval1[] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95}; Double_t yval1[] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1}; Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05}; Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8}; TGraphErrors *gr1 = new TGraphErrors(n1,xval1,yval1,ex1,ey1); gr1->SetMarkerColor(kBlue); gr1->SetMarkerStyle(21); gr1->Draw("LP"); // create second graph const Int_t n2 = 10; Float_t xval2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01}; Float_t yval2[] = {0.82,3.86,7,9,10,10.55,9.64,7.26,5.42,2}; Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04}; Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7}; TGraphErrors *gr2 = new TGraphErrors(n2,xval2,yval2,ex2,ey2); gr2->SetMarkerColor(kRed); gr2->SetMarkerStyle(20); gr2->Draw("LP"); }
void binomialEfficiency2D(TH2F * numerator,TH2F * denominator,bool text2D){ if(!numerator) cout<<"numerator not found"<<endl; if(!denominator) cout<<"denominator not found"<<endl; TH1F * efficiency = numerator->Clone("efficiency"); efficiency->SetXTitle(numerator->GetXaxis()->GetTitle()); efficiency->SetYTitle(numerator->GetYaxis()->GetTitle()); float eff,err; for(int i=0;i<=numerator->GetXaxis()->GetNbins();i++) for(int j=0;j<=numerator->GetYaxis()->GetNbins();j++){ if(denominator->GetBinContent(i,j)!=0){ eff = numerator->GetBinContent(i,j)/denominator->GetBinContent(i,j); err = sqrt(eff*(1-eff)/denominator->GetBinContent(i,j)); efficiency->SetBinContent(i,j,eff); efficiency->SetBinError(i,j,err); cout<<i<<" "<<j<<" "<<eff<<"+/-"<<err<<endl; } } if(text2D==true){ efficiency->Draw("colztextE"); //efficiency->Draw("colz"); }else{ efficiency->Draw("colz"); } }
void DrawInsituCorr_vs_Eta(Str jetAlgo) { Nbins=sizeof(Ebins)/sizeof(double); myJES = new JetCalibrationTool(jetAlgo,_jesFile); TH1F *h = new TH1F("","",100,-4.8,4.8); h->SetXTitle("Jet #eta_{det}"); h->SetYTitle("Residual correction for data only"); h->SetMaximum(1.1); h->SetMinimum(0.85); h->Draw(); TLine *l = new TLine(); l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(4); l->DrawLine(-4.65,1,4.65,1); for (int i=0;i<Nbins;++i) { Graph *g = GetInsituGraph(Ebins[i]); FormatGraph(g,i); g->Draw("PL"); double x=0.52, y=0.3-0.05*i; if (i>2) { x=0.74; y=0.3-0.05*(i-3); } DrawLabel(Form("p_{T} = %.0f GeV",Ebins[i]),x,y,i); } l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(1); tex->SetNDC(); tex->SetTextAlign(12); //tex->DrawLatex(0.18,0.975,myJES->AbsoluteJES_Description()); tex->DrawLatex(0.18,0.9,GetJetDesc(jetAlgo)); }
void read25cm() { TFile *f = new TFile("read25c.root"); //root file name TTree *ntuple = (TTree*)f->Get("ntuple"); Float_t dRm,dRmbar,dRb,dRbbar; //Values ntuple->SetBranchAddress("dRm",&dRm); //Values ntuple->SetBranchAddress("dRmbar",&dRmbar); ntuple->SetBranchAddress("dRb",&dRb); ntuple->SetBranchAddress("dRbbar",&dRbbar); //create histogram TH1F *mudR = new TH1F("dRm","dR distribution of mu and jet",100,0.,2 * M_PI); TH1F *mubardR = new TH1F("dRmbar","dR distribution of mubar and jet",100,0.,2 * M_PI); TH1F *bdR = new TH1F("dRb","dR distribution of b and jet",100,0.,2 * M_PI); TH1F *bbardR = new TH1F("dRbbar","dR distribution of bbar and jet",100,0.,2 * M_PI); //read all entries and fill the histograms Long64_t nentries = ntuple->GetEntries(); for (Long64_t q=0;q<nentries;q++) { ntuple->GetEntry(q); mudR->Fill(dRm); //Histogram value mubardR->Fill(dRmbar); bdR->Fill(dRb); bbardR->Fill(dRbbar); } { mudR->SetXTitle("dR"); mudR->SetYTitle("Event"); mubardR->SetXTitle("dR"); mubardR->SetYTitle("Event"); bdR->SetXTitle("dR"); bdR->SetYTitle("Event"); bbardR->SetXTitle("dR"); bbardR->SetYTitle("Event"); } if (gROOT->IsBatch()) return; f->Write(); new TBrowser(); ntuple->StartViewer(); }
void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt) { vC1->cd(pad); TH1F *vFrame = gPad->DrawFrame(0,-130,60,70); vFrame->SetTitle(title); vFrame->SetTitleSize(0.2); vFrame->SetXTitle(xt); vFrame->SetYTitle(yt); grin->Draw("P"); grout->DrawClone("LPX"); }
TCanvas * plot (TH1F* histoDataIn, TString legendData, TH1F* histoSimulationIn, TString legendSimulation, TString & canvasName, Float_t maximum = 0.15, TString xAxisTitle = "#eta", TString yAxisTitle = "Number of Clusters", TString error = "", bool useLegend = true, TString text = "", Float_t textX = 0.7, Float_t textY = 0.4, Float_t rebin = 0 ) { TH1F * histoData = (TH1F*)histoDataIn->Clone(); TH1F * histoSimulation = (TH1F*)histoSimulationIn->Clone(); // histoData->Sumw2(); histoData->Scale(1/(histoData->Integral())); histoSimulation->Scale(1/(histoSimulation->Integral())); // Create also the legend and add the histograms TLegend * legend = new TLegend( 0.55, 0.65, 0.76, 0.82 ); legend->AddEntry( histoData, xAxisTitle ); legend->AddEntry( histoSimulation, yAxisTitle, "F" ); cout << "histoData = " << histoData << endl; cout << "histoSimulation = " << histoSimulation << endl; TCanvas * c = new TCanvas( canvasName, canvasName, 1000, 800 ); c->Draw(); histoSimulation->SetMaximum(maximum); histoSimulation->SetFillColor(kRed); // histoSimulation->SetLineWidth(0); histoSimulation->SetLineColor(kRed); histoSimulation->SetXTitle(xAxisTitle); histoSimulation->SetYTitle(yAxisTitle); histoSimulation->SetTitleOffset(1.6,"Y"); histoSimulation->SetTitle(); histoData->SetLineStyle(1); histoData->SetLineWidth(2.5); histoSimulation->Draw(); histoData->Draw("same"); legend->SetFillColor(kWhite); if (useLegend) legend->Draw("same"); if ( text != "" ) { TPaveText * pt = new TPaveText(textX, textY, textX+0.2, textY+0.17, "NDC" ); // "NDC" option sets coords relative to pad dimensions pt->SetFillColor(0); // text is black on white pt->SetTextSize(0.08); pt->SetBorderSize(0); pt->SetTextAlign(12); pt->AddText(text); pt->Draw("same"); //to draw your text object } return c; };
void binomialEfficiency1D(TH1F * numerator,TH1F * denominator){ TH1F * efficiency = numerator->Clone("efficiency"); efficiency->SetXTitle(numerator->GetXaxis()->GetTitle()); efficiency->SetYTitle("#epsilon"); for(int j=0;j<=numerator->GetXaxis()->GetNbins() ;j++){ if(denominator->GetBinContent(j)!=0){ float eff = numerator->GetBinContent(j)/denominator->GetBinContent(j); float err = sqrt(eff*(1-eff)/denominator->GetBinContent(j)); efficiency->SetBinContent(j,eff); efficiency->SetBinError(j,err); cout<<"1Deff "<<j<<" "<<eff<<" +/- "<<err<<endl; } } efficiency->Draw("E"); efficiency->SetMarkerColor(kRed); efficiency->SetMarkerStyle(23); efficiency->SetMarkerSize(2); }
void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt) { vC1->cd(pad); TH1F *vFrame = gPad->DrawFrame(0,0,15,150); vFrame->SetTitle(title); vFrame->SetTitleSize(0.2); vFrame->SetXTitle(xt); vFrame->SetYTitle(yt); grxy->SetMarkerColor(kBlue); grxy->SetMarkerStyle(21); grxy->SetMarkerSize(0.5); grxy->Draw("P"); grin->SetMarkerColor(kRed); grin->SetMarkerStyle(5); grin->SetMarkerSize(0.7); grin->Draw("P"); grout->DrawClone("LP"); }
TList * aPath(TString tag, TString label,vector<module> modules){ TList * result=new TList(); bool canProceed=false; int Ndiv=0; for (int i=0;i!=(int)modules.size();++i){if(get(modules[i].name)) {canProceed=true;Ndiv++;}} if (!canProceed) return result; TCanvas * c = new TCanvas("c_"+tag,"timing for "+label+"path",modules.size()*bsize,bsize); c->Divide(modules.size(),1); // c->Divide(Ndiv,1); TCanvas * d = new TCanvas("d_"+tag,"truncated mean for "+label+"path",modules.size()*bsize,bsize); d->Divide(modules.size(),1); // d->Divide(Ndiv,1); result->Add(c); result->Add(d); for (int i=0;i!=(int)modules.size();++i){ TH1F * h = get(modules[i].name); if (!h) { // i--; continue;} c->cd(i+1)->SetGrid(); if (modules[i].log) c->cd(i+1)->SetLogy(); if (modules[i].max!=-1){ //resize the axis SetX(h,modules[i].max);} h->SetXTitle("time [ms]"); h->Draw(); //plot the means pave(h,modules[i].min)->Draw(); d->cd(i+1)->SetGrid(); TGraph * tr=truncatedMean(h,modules[i].max); tr->Draw("apl"); tr->GetXaxis()->SetTitle("min time [ms]"); tr->GetYaxis()->SetTitle("mean time starting from min [ms]"); tr->GetXaxis()->SetRange(0,tr->GetXaxis()->FindBin(modules[i].max)); } return result;}
void bichdX() { if (gClassTable->GetID("StBichsel") < 0) { // gSystem->Load("libStar"); // gSystem->Load("St_base"); // gSystem->Load("StarClassLibrary"); gSystem->Load("StBichsel"); } if (!m_Bichsel) m_Bichsel = Bichsel::Instance(); TCanvas *c1 = new TCanvas("c1"); c1->SetLogx(); c1->SetLogy(); // TH1F *hr = c1->DrawFrame(2.e-2,1,1.e3,1.e2); // TH1F *hr = c1->DrawFrame(1.e-2,1,1.e3,1.e2); TH1F *hr = c1->DrawFrame(1.e-1,1,1.e4,2.e2); // hr->SetXTitle("Momentum (GeV/c)"); hr->SetTitle("dE/dx Bichsel predictions for different dX"); hr->SetXTitle("#beta#gamma "); hr->SetYTitle("dE/dx (keV/cm)"); // Mass Type Length log2(dx) Double_t params[4] = { 1.0, 0., 60., 1.}; TLegend *leg = new TLegend(0.72,0.7,0.9,0.9,"");//TLegend(0.79,0.91,0.89,0.89,""); Int_t h = 0; // for (Int_t f = 0; f< NF; f++) { for (Int_t f = 5; f <= 5; f++) { Int_t icol = 2; for (Int_t dx = 0; dx < Nlog10dx; dx++) { params[3] = log10dx[dx]; Char_t *FunName = Form("%s%s%i",FNames[f],Names[h],dx); TF1 *func = func = new TF1(FunName,Rbichsel70,1.e-1,1.e4,4); if (! func) continue; func->SetLineColor(icol); // func->SetLineStyle(f+1); icol++; if (icol == 5) icol++; func->SetParameters(params); func->Draw("same"); leg->AddEntry(func,Form("%s dX = %4.1f (cm)",FNames[f],TMath::Power(2.,params[3])),"L"); } } leg->Draw(); }
void sigHist(TChain & EventsVBF, TChain & EventsGF, string variable, string title, int nBins, float min, float max, float GF, float VBF ){ TCanvas c(""); TH1F *hVBF = new TH1F("hVBF","hVBF", nBins, min, max); TH1F *hGF = new TH1F("hGF","hGF", nBins, min, max); EventsVBF.Project("hVBF",variable.c_str() ); EventsGF.Project("hGF",variable.c_str() ); //hVBF->Draw(); EventsVBF.Draw("h.mass()"); TH1F * h = new TH1F(title.c_str(),title.c_str(), nBins, min,max); h->Add(hVBF,hGF,VBF,GF); h->SetLineColor(kBlue+1); h->SetFillColor(kAzure+7); //h->SetLineColor(kMagenta+3); //h->SetFillColor(kMagenta-3); // h->SetLineColor(kTeal+3); // h->SetFillColor(kTeal+2); // h->SetLineColor(kOrange+7); // h->SetFillColor(kYellow-9); h->SetMarkerStyle(0); h->SetTitle( ("H350, "+title).c_str() ); h->SetXTitle("m_{H} (GeV/c^{2})"); //h->hGF->GetXaxis()->SeXmin(); //h->Scale(1/h->GetEntries()); h->Draw("HIST"); h->Write(); //c.SaveAs( (title+".eps").c_str() ); delete hVBF; delete hGF; delete h; }
mkplots(){ gStyle->SetOptStat(1); TFile * f = new TFile("plots.root"); f->ls(); TH1F * hpn = (TH1F *) f->Get("hpn"); TH1F * hpt = (TH1F *) f->Get("hpt"); TH1F * hpp = (TH1F *) f->Get("hpp"); TH1F * hde = (TH1F *) f->Get("hde"); TH1F * hdp = (TH1F *) f->Get("hdp"); TH1F * hdt = (TH1F *) f->Get("hdt"); TCanvas * c1 = new TCanvas; hpn->SetXTitle("pull shower log(N)"); hpn->Draw("ep"); c1->SaveAs("plots/pn.png"); TCanvas * c2 = new TCanvas; hpt->SetXTitle("pull shower eta)"); hpt->Draw("ep"); c2->SaveAs("plots/pt.png"); TCanvas * c3 = new TCanvas; hpp->SetXTitle("pull shower phi"); hpp->Draw("ep"); c3->SaveAs("plots/pp.png"); TCanvas * c4 = new TCanvas; hde->SetXTitle("shower E fractional difference"); hde->Draw("ep"); c4->SaveAs("plots/dn.png"); TCanvas * c5 = new TCanvas; hdt->SetXTitle("shower theta fractional difference"); hdt->Draw("ep"); c5->SaveAs("plots/dt.png"); TCanvas * c6 = new TCanvas; hdp->SetXTitle("shower phi fractional difference"); hdp->Draw("ep"); c6->SaveAs("plots/dp.png"); }
//=============================== void DrawFit(Double_t nSigma, Int_t iRapBin, Int_t iPTBin){ gStyle->SetFillColor(0); Char_t name[100]; gStyle->SetFrameBorderMode(0); //prepare the drawing of the individual components: fBG->SetFillColor(colour[BG]); fBG->SetLineColor(colour[BG]); fBG->SetFillStyle(1001); fBG->SetNpx(1000); TH1 *hBG = fBG->GetHistogram(); fUps1S->SetNpx(1000); fUps1S->SetFillColor(colour[UPS1S]); fUps1S->SetLineColor(colour[UPS1S]); fUps1S->SetFillStyle(1001); fUps2S->SetNpx(1000); fUps2S->SetFillColor(colour[UPS2S]); fUps2S->SetLineColor(colour[UPS2S]); fUps2S->SetFillStyle(1001); fUps3S->SetNpx(1000); fUps3S->SetFillColor(colour[UPS3S]); fUps3S->SetLineColor(colour[UPS3S]); fUps3S->SetFillStyle(1001); TH1 *hUps1S = fUps1S->GetHistogram(); TH1 *hUps2S = fUps2S->GetHistogram(); TH1 *hUps3S = fUps3S->GetHistogram(); THStack *hStack = new THStack("hMass_Stack", ""); hStack->Add(hBG); hStack->Add(hUps3S); hStack->Add(hUps2S); hStack->Add(hUps1S); if(!PlotSimplistic) hStack->Draw("same"); hMass->Draw("same"); if(!PlotSimplistic) fRECO->Draw("same"); TLine *line[3]; Double_t max[3] = {1., 0.5, 0.3}; for(int iL = 0; iL < 3; iL++){ line[iL]= new TLine(massMin[iL], 0.1, massMin[iL], max[iL]*hUps1S->GetMaximum()); line[iL]->SetLineStyle(2); line[iL]->SetLineColor(colour[iL]); line[iL]->SetLineWidth(2); if(!PlotSimplistic) line[iL]->Draw(); if(!PlotSimplistic) line[iL]->DrawLine(massMax[iL], 0.1, massMax[iL], max[iL]*hUps1S->GetMaximum()); } /* double MassScan[13]={8.6,8.95,9.3,9.45,9.6,9.85,10.0125,10.175,10.3425,10.51,10.8,11.1,11.4}; TLine *line[13]; for(int iL = 0; iL < 13; iL++){ line[iL]= new TLine(MassScan[iL], 0.1, MassScan[iL], 1.1*hUps1S->GetMaximum()); line[iL]->SetLineStyle(2); line[iL]->SetLineColor(kWhite); line[iL]->SetLineWidth(2); line[iL]->Draw(); } TLatex *texMassScan[13]; char MassScanName[200]; for(int iL = 0; iL < 13; iL++){ sprintf(MassScanName,"%d",iL+1); texMassScan[iL] = new TLatex((MassScan[iL]+MassScan[iL+1])/2., 0.015*hStack->GetMaximum(), MassScanName); texMassScan[iL]->SetTextSize(0.03); texMassScan[iL]->SetTextColor(kWhite); texMassScan[iL]->Draw(); } */ if(iRapBin == 0) sprintf(name, "|y| < %1.1f", onia::rapYPS); else if(iRapBin == 1) sprintf(name, "|y| < %1.1f", onia::rapForPTRange[iRapBin]); else if(iRapBin > 1) sprintf(name, "%1.1f < |y| < %1.1f", onia::rapForPTRange[iRapBin-1], onia::rapForPTRange[iRapBin]); double xText=10.25; TLatex *tex = new TLatex(xText, hStack->GetMaximum(), name); tex->SetTextSize(0.04); if(!PlotSimplistic) tex->Draw(); if(iPTBin == 0) sprintf(name, "all p_{T}"); // else if(iPTBin == 1) sprintf(name, "p_{T} < %1.1f GeV", onia::pTRange[iRapBin][iPTBin]); else sprintf(name, "%1.1f < p_{T} < %1.1f", onia::pTRange[iRapBin][iPTBin-1], onia::pTRange[iRapBin][iPTBin]); if(!PlotSimplistic) tex->DrawLatex(xText, 0.94*hStack->GetMaximum(), name); sprintf(name, "frac(BG) in #pm %1.1f#sigma:", nSigma); if(!PlotSimplistic) tex->DrawLatex(xText, 0.86*hStack->GetMaximum(), name); sprintf(name, "%1.2f, %1.2f, %1.2f", fracBG[0], fracBG[1], fracBG[2]); if(!PlotSimplistic) tex->DrawLatex(xText, 0.80*hStack->GetMaximum(), name); sprintf(name, "Figures/massFit_rap%d_pT%d.pdf", iRapBin, iPTBin); // gPad->SetLogy(kTRUE); gPad->Print(name); if(iPTBin>-1&&iRapBin>-10){ /// produce pedagogical plot cout<<"Plot pedagogical"<<endl; double mean1S_draw = fUps1S->GetParameter(1); double sigma1S_draw = fUps1S->GetParameter(2); double nSigmaMin=0; double nSigmaMax=2.5; int nIntegrals=100; double nSigmaCenter[nIntegrals]; double lSig[nIntegrals]; double lBkg[nIntegrals]; double lSig_[nIntegrals]; double lBkg_[nIntegrals]; double lSigOVERBkg[nIntegrals]; double maxSig=2.5; int whichBinIsAtOne=1/(nSigmaMax-nSigmaMin)*nIntegrals; cout<<"whichBinIsAtOne "<<whichBinIsAtOne<<endl; for(int nIter=0;nIter<nIntegrals;nIter++){ nSigmaCenter[nIter]= (nSigmaMax-nSigmaMin)/double(nIntegrals)*double(nIter+1); lSig_[nIter]= fUps1S->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw); lBkg_[nIter]= fBG->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw); } for(int nIter=0;nIter<nIntegrals;nIter++){ nSigmaCenter[nIter]= (nSigmaMax-nSigmaMin)/double(nIntegrals)*double(nIter+1); lSig[nIter]= fUps1S->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw)/lSig_[whichBinIsAtOne-1]; lBkg[nIter]= fBG->Integral(mean1S_draw-nSigmaCenter[nIter]*sigma1S_draw, mean1S_draw+nSigmaCenter[nIter]*sigma1S_draw)/lBkg_[whichBinIsAtOne-1]; } for(int nIter=0;nIter<nIntegrals;nIter++){ lSigOVERBkg[nIter]= lSig[nIter]/lBkg[nIter]; cout<<"lSigOVERBkg[nIter] "<<lSigOVERBkg[nIter]<<endl; } TGraphErrors *nSigma_Sig = new TGraphErrors(nIntegrals,nSigmaCenter,lSig,0,0); TGraphErrors *nSigma_Bkg = new TGraphErrors(nIntegrals,nSigmaCenter,lBkg,0,0); TGraphErrors *nSigma_SigOVERBkg = new TGraphErrors(nIntegrals,nSigmaCenter,lSigOVERBkg,0,0); TCanvas *SystCanvas = new TCanvas("SystCanvas","SystCanvas",1000,800); // gStyle->SetPalette(1); // gPad->SetFillColor(kWhite); // gPad->SetLeftMargin(0.15); SystCanvas->SetFillColor(kWhite); SystCanvas->SetGrid(); SystCanvas->GetFrame()->SetFillColor(kWhite); SystCanvas->GetFrame()->SetBorderSize(0); SystCanvas->SetRightMargin(0.05) ; TLegend* plotLegend=new TLegend(0.1,0.7,0.45,0.9); plotLegend->SetFillColor(kWhite); plotLegend->SetTextFont(72); plotLegend->SetTextSize(0.03); plotLegend->SetBorderSize(1); char legendentry[200]; double lineWidth=3; char drawGraphStyle[200]; sprintf(drawGraphStyle,"LX"); TH1F *SystHisto = new TH1F; SystHisto = SystCanvas->DrawFrame(nSigmaMin,0,nSigmaMax,maxSig); SystHisto->SetXTitle("n_{#sigma}"); SystHisto->GetYaxis()->SetTitleOffset(1.5); nSigma_Sig->SetLineColor(kGreen-2); nSigma_Sig->SetLineWidth(lineWidth); nSigma_Sig->Draw(drawGraphStyle); sprintf(legendentry,"Signal yield"); plotLegend->AddEntry(nSigma_Sig,legendentry,"l"); nSigma_Bkg->SetLineColor(kBlue); nSigma_Bkg->SetLineWidth(lineWidth); nSigma_Bkg->Draw(drawGraphStyle); sprintf(legendentry,"Background yield"); plotLegend->AddEntry(nSigma_Bkg,legendentry,"l"); nSigma_SigOVERBkg->SetLineColor(kRed); nSigma_SigOVERBkg->SetLineWidth(lineWidth); nSigma_SigOVERBkg->Draw(drawGraphStyle); sprintf(legendentry,"S/B ratio"); plotLegend->AddEntry(nSigma_SigOVERBkg,legendentry,"l"); plotLegend->Draw(); sprintf(name,"Figures/pedagogical_rap%d_pT%d.pdf",iRapBin,iPTBin); SystCanvas->SaveAs(name); } }
void plot_golfcourse_Asymptotic(bool unblind){ bool useNewStyle=true; if(useNewStyle) setFPStyle(); TFile *fFREQ=new TFile("higgsCombineEXOZZ.Asymptotic.TOTAL.root","READ"); TTree *t=(TTree*)fFREQ->Get("limit"); double mh,limit; float quant; t->SetBranchAddress("mh",&mh); t->SetBranchAddress("limit",&limit); t->SetBranchAddress("quantileExpected",&quant); //1st loop on tree for preparing mH ordered list vector<double> v_mhTMP; for(int i=0;i<t->GetEntries();i++){ t->GetEntry(i); if(quant>-1.01&&quant<-0.99){ v_mhTMP.push_back(mh); } } std::sort(v_mhTMP.begin(),v_mhTMP.end()); int nMH=v_mhTMP.size(); int iMH=0; vector<double> v_mh, v_median,v_68l,v_68h,v_95l,v_95h, v_obs; while(iMH<nMH){ double mhTMP=v_mhTMP.at(iMH); for(int i=0;i<t->GetEntries();i++){ // int i=j; // if(j==t->GetEntries())i=0; t->GetEntry(i); //cout<<"i "<<i<<flush<<" m = "<<mh<<endl; // if(mh==600)cout<<"$$$$$$$$$ TREE 600 $$$$$$$$$$$$$$"<<endl; if(mh!=mhTMP)continue;//follow exactly the order of v_mhTMP if(quant>-1.01&&quant<-0.99){ v_obs.push_back(limit); v_mh.push_back(mh); } else if(quant>0.02&&quant<0.03)v_95l.push_back(limit); else if(quant>0.15&&quant<0.17)v_68l.push_back(limit); else if(quant>0.49&&quant<0.51)v_median.push_back(limit); else if(quant>0.83&&quant<0.85)v_68h.push_back(limit); else if(quant>0.965&&quant<0.98){ // cout<<"95% -> at M="<<mh<<" I found "<<limit<<endl; v_95h.push_back(limit); } else {cout<<"Error! Quantile = "<<quant<<endl;} } iMH++; }//end while loop cout<<"Out of the loop !"<<endl; //////////////////////////////////////// /// //read in theoretical values from text files // bool applyExtraTherUnc=true; string xsect_file_th="../../../data/xsect_BulkG_ZZ_c0p5_xsect_in_pb.txt"; if(!isZZChannel)xsect_file_th="../../../data/xsect_BulkG_WW_c0p5_xsect_in_pb.txt"; // make_interpolated_xsect(xsect_file_th, xsect_file_interpol); // string xsect_file_interpol="./RSGravXSectTimesBRToZZ_AgasheHapola_c10_EXPOINTERP.txt"; ifstream xsect_file(xsect_file_th.c_str(),ios::in); if (! xsect_file.is_open()){ cout<<"Failed to open file with xsections"<<endl;} float mH, CS; vector<float> v_mhxs, v_xs, v_brzz2l2q,v_toterrh,v_toterrl; while(xsect_file.good()){ xsect_file >> mH>> CS; if(mH==1200)cout<<"~~~~~ 1200 theor ~~~~~~~~~~~~~"<<endl; if(mH<600.0)continue; v_mhxs.push_back(mH); v_xs.push_back(CS);//*BRZZ2l2q (multyply by BRZZ2l2q only if exp rates in cards are for process X->ZZ->2l2q !) //unavailable theor errors for graviton float tot_err_p=0.0; float tot_err_m=0.0; v_toterrh.push_back(1.0+(tot_err_p)); v_toterrl.push_back(1.0-(tot_err_m)); } cout<<"Size of theor "<<v_mhxs.size()<<endl; xsect_file.close(); string xsect_file_interpol2="../../../data/xsect_BulkG_ZZ_c0p2_xsect_in_pb.txt"; if(!isZZChannel)xsect_file_interpol2="../../../data/xsect_BulkG_WW_c0p2_xsect_in_pb.txt"; ifstream xsect_file2(xsect_file_interpol2.c_str(),ios::in); if (! xsect_file2.is_open()){ cout<<"Failed to open file with xsections (c=0.10)"<<endl;} float mH2,CS10; vector<float> v_xs10; while(xsect_file2.good()){ xsect_file2 >> mH2>> CS10; if(mH2==975)cout<<"~~~~~ 975 theor ~~~~~~~~~~~~~"<<endl; if(mH2<600.0)continue; v_xs10.push_back(CS10);//*BRZZ2l2q //unavailable theor errors for graviton float tot_err_p=0.0; float tot_err_m=0.0; // v_toterrh.push_back(1.0+(tot_err_p)); // v_toterrl.push_back(1.0-(tot_err_m)); } cout<<"Size of theor "<<v_xs10.size()<<endl; xsect_file2.close(); // //END THEOR INPUT PART /////////////// const int nMass= v_mh.size(); double mass[nMass],mass1[nMass],obs_lim_cls[nMass]; double medianD[nMass]; double up68err[nMass],down68err[nMass],up95err[nMass],down95err[nMass]; double xs[nMass], xs_uperr[nMass], xs_downerr[nMass]; double xs10[nMass], xs10_uperr[nMass], xs10_downerr[nMass]; int nMassEff=0,nMassEff1=0; int nM95=0; double mass95[nMass],median95[nMass]; int nexcluded=0; bool excl; for(int im=0;im<nMass;im++){ if( mass[nMassEff-1]>1600.) cout<<"Array "<<im<<flush<<" m = "<<v_mh.at(im)<<endl;; //protection against messed up jobs excl=false; if(v_68h.at(im)>=v_95h.at(im) || v_68l.at(im)<=v_95l.at(im) ){ cout<<"Point at M = "<<v_mh.at(im) <<" excluded: "<<v_95l.at(im)<<" "<<v_68l.at(im)<<" "<<v_median.at(im)<<" "<<v_68h.at(im)<<" "<<v_95h.at(im)<< endl; nexcluded++; // continue; excl=true; } // if(im%2==1)excl=true;//sample only one half of the points //search for right index in theor vectors bool found=false; int indtmp=0,ind=-1; while(!found){ if(v_mhxs.at(indtmp)==v_mh.at(im)){found=true;ind=indtmp;} indtmp++; if(indtmp==v_mhxs.size()){ cout<<"!!! m="<<flush<<v_mh.at(im)<<" NOT found in theor matrix."<<endl; break; } }//end while if(!found){ cout<<"(2) m="<<v_mh.at(im)<<" NOT found in theor matrix."<<endl; continue; } double fl_xs=double(v_xs.at(ind));//*1000.0 double fl_xs10=double(v_xs10.at(ind));//*1000.0 if(fl_xs<fl_xs10)cout<<"WARNING ABOUT XSECT! XS="<<fl_xs<<" XS10="<<fl_xs10<<endl; mass[nMassEff]=v_mh.at(im); //if( mass[nMassEff]==600.0)cout<<"=============> 600 !!!"<<endl; obs_lim_cls[nMassEff]=v_obs.at(im)*fl_xs; nMassEff++; if(!excl){ mass1[nMassEff1]=v_mh.at(im); medianD[nMassEff1]=v_median.at(im)*fl_xs; up68err[nMassEff1]=(v_68h.at(im)-v_median.at(im))*fl_xs; down68err[nMassEff1]=(v_median.at(im)-v_68l.at(im))*fl_xs; cout<<"M="<<mass1[nMassEff1]<<" Median="<<medianD[nMassEff1]<<endl; //scale factor 100 for making the xsect visible xs[nMassEff1]=fl_xs;//*100.0; xs_uperr[nMassEff1]=double( v_toterrh.at(ind))*xs[nMassEff1]- xs[nMassEff1]; xs_downerr[nMassEff1]= xs[nMassEff1]- double( v_toterrl.at(ind))* xs[nMassEff1]; xs10[nMassEff1]=fl_xs10;//*100.0; xs10_uperr[nMassEff1]=double( v_toterrh.at(ind))*xs10[nMassEff1]- xs10[nMassEff1]; xs10_downerr[nMassEff1]= xs10[nMassEff1]- double( v_toterrl.at(ind))* xs10[nMassEff1]; //cout<<"Theor err on 4g for M="<<mass[nMassEff]<<" "<< ggxs4g_downerr[nMassEff] << " "<<ggxs4g_uperr[nMassEff]<<endl; nMassEff1++; bool skip95= false;// // skip95=v_mh.at(im)==204||v_mh.at(im)==208||v_mh.at(im)==212||v_mh.at(im)==214|| v_mh.at(im)==232 || v_mh.at(im)==240 || v_mh.at(im)==240 || v_mh.at(im)==244 || v_mh.at(im)==252 || v_mh.at(im)==264 || v_mh.at(im)==272 || v_mh.at(im)==288 ; // skip95=false; if(skip95 )continue; mass95[nM95]=v_mh.at(im); median95[nM95]=v_median.at(im)*fl_xs; up95err[nM95]=(v_95h.at(im)-v_median.at(im))*fl_xs; down95err[nM95]=(v_median.at(im)-v_95l.at(im))*fl_xs; // cout<<"M95: "<< mass95[nM95]<<" "<<median95[nM95]<<" +"<<up95err[nM95]<<" -"<< down95err[nM95]<< // " ("<<v_95h.at(im) <<" - "<<v_median.at(im) <<")"<<endl; nM95++; }//end if not excluded mass point }//end loop over im (mass points) cout<<"Excluded "<<nexcluded<<" sick mass points."<<endl; // cout<<"Working on TGraph"<<endl; TGraphAsymmErrors *grobslim_cls=new TGraphAsymmErrors(nMassEff,mass,obs_lim_cls); grobslim_cls->SetName("LimitObservedCLs"); TGraphAsymmErrors *grmedian_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD); grmedian_cls->SetName("LimitExpectedCLs"); TGraphAsymmErrors *gr68_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD,0,0,down68err,up68err); gr68_cls->SetName("Limit68CLs"); TGraphAsymmErrors *gr95_cls=new TGraphAsymmErrors(nM95,mass95,median95,0,0,down95err,up95err); gr95_cls->SetName("Limit95CLs"); // TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff1,mass1,xs,0,0,0,0);//xs_downerr,xs_uperr); TGraph *grthSM=new TGraph(nMassEff1,mass1,xs);//xs_downerr,xs_uperr); grthSM->SetName("SMXSection"); // TGraphAsymmErrors *grthSM10=new TGraphAsymmErrors(nMassEff1,mass1,xs10,0,0,0,0); TGraph *grthSM10=new TGraph(nMassEff1,mass1,xs10); grthSM10->SetName("SMXSection_2nd"); // cout<<"Plotting"<<endl; double fr_left=590.0, fr_down=0.0005,fr_right=2020.0,fr_up=1.0; if(!isZZChannel){fr_left=1000.0, fr_down=0.0000005,fr_right=2500.0,fr_up=10.0;} TCanvas *cMCMC=new TCanvas("c_lim_Asymp","canvas with limits for Asymptotic CLs",630,600); cMCMC->cd(); cMCMC->SetGridx(1); cMCMC->SetGridy(1); // draw a frame to define the range TH1F *hr = cMCMC->DrawFrame(fr_left,fr_down,fr_right,fr_up,""); TString VV = "ZZ"; if(!isZZChannel)VV="WW"; hr->SetXTitle("M_{1} [GeV]"); hr->SetYTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q // cMCMC->GetFrame()->SetFillColor(21); //cMCMC->GetFrame()->SetBorderSize(12); gr95_cls->SetFillColor(kYellow); gr95_cls->SetFillStyle(1001);//solid gr95_cls->SetLineStyle(kDashed); gr95_cls->SetLineWidth(3); gr95_cls->GetXaxis()->SetTitle("M_{1} [GeV]"); gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q gr95_cls->GetXaxis()->SetRangeUser(fr_left,fr_right); gr95_cls->Draw("3"); gr68_cls->SetFillColor(kGreen); gr68_cls->SetFillStyle(1001);//solid gr68_cls->SetLineStyle(kDashed); gr68_cls->SetLineWidth(3); gr68_cls->Draw("3same"); grmedian_cls->GetXaxis()->SetTitle("M_{1} [GeV]"); grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q grmedian_cls->SetMarkerStyle(24);//25=hollow squre grmedian_cls->SetMarkerColor(kBlack); grmedian_cls->SetLineStyle(2); grmedian_cls->SetLineWidth(3); grmedian_cls->SetMinimum(0.0); grmedian_cls->SetMaximum(8.0); grobslim_cls->SetMarkerColor(kBlack); grobslim_cls->SetMarkerStyle(20);//24=hollow circle // 20 = solid circle grobslim_cls->SetMarkerSize(0.7); grobslim_cls->SetLineStyle(1); grobslim_cls->SetLineWidth(1); grthSM->SetLineColor(kRed); grthSM->SetLineWidth(2); grthSM->SetLineStyle(kSolid); grthSM->SetFillColor(kRed); grthSM->SetFillStyle(3344); grthSM10->SetLineColor(kRed); grthSM10->SetLineWidth(2); grthSM10->SetLineStyle(1); grthSM10->SetLineStyle(kDashed); grthSM10->SetFillColor(kRed); grthSM10->SetFillStyle(3344); grthSM->Draw("L3"); grthSM10->Draw("L3"); grmedian_cls->Draw("L"); if(unblind)grobslim_cls->Draw("LP"); /* TFile *fUnMPlus=new TFile("AsymptoticCLs_UnmatchedPlus_TGraph.root","READ"); TGraph *grobs_ump=(TGraph*)fUnMPlus->Get("LimitObservedCLs"); TGraph *grmedian_ump=(TGraph*)fUnMPlus->Get("LimitExpectedCLs"); grobs_ump->SetName("LimitObs_UnmatchedPlus"); grmedian_ump->SetName("LimitExp_UnmatchedPlus"); grobs_ump->SetMarkerColor(kBlue); grobs_ump->SetLineColor(kBlue); grobs_ump->SetMarkerStyle(25); grmedian_ump->SetMarkerColor(kBlue); grmedian_ump->SetLineColor(kBlue); grmedian_ump->SetMarkerStyle(25); grobs_ump->Draw("P"); grmedian_ump->Draw("L"); */ //draw grid on top of limits gStyle->SetOptStat(0); TH1D* postGrid = new TH1D("postGrid","",1,fr_left,fr_right); postGrid->GetYaxis()->SetRangeUser(fr_down,fr_up); postGrid->Draw("AXIGSAME"); TLine *l1=new TLine(); l1->SetLineStyle(1); l1->SetLineWidth(2.0); l1->SetLineColor(kRed); // l1->DrawLine(200.0,1.0,600.0,1.0); // cMCMC->Update(); cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); //more graphics TLegend *leg = new TLegend(.46,.75,.94,.92); // TLegend *leg = new TLegend(.35,.71,.90,.90); leg->SetFillColor(0); leg->SetShadowColor(0); leg->SetTextFont(42); leg->SetTextSize(0.025); // leg->SetBorderMode(0); if(unblind)leg->AddEntry(grobslim_cls, "Asympt. CL_{S} Observed", "LP"); leg->AddEntry(gr68_cls, "Asympt. CL_{S} Expected #pm 1#sigma", "LF"); leg->AddEntry(gr95_cls, "Asympt. CL_{S} Expected #pm 2#sigma", "LF"); leg->AddEntry(grthSM, "#sigma_{TH} x BR(G #rightarrow "+VV+"), #tilde{k}=0.50", "L" );// #rightarrow 2l2q leg->AddEntry(grthSM10, "#sigma_{TH} x BR(G #rightarrow "+VV+"), #tilde{k}=0.20", "L");// #rightarrow 2l2q leg->Draw(); if(useNewStyle){ TPaveText* cmslabel = new TPaveText( 0.145, 0.953, 0.6, 0.975, "brNDC"); cmslabel->SetFillColor(kWhite); cmslabel->SetTextSize(0.038); cmslabel->SetTextAlign(11); cmslabel->SetTextFont(62); cmslabel->SetBorderSize(0); // std::string leftText = "CMS Preliminary 2011"; std::string leftText = "CMS"; std::string units = "fb ^{-1}"; char lumiText[300]; sprintf( lumiText, "%.1f %s", intLumi, units.c_str()); cmslabel->AddText(Form("%s, #sqrt{s} = 8 TeV, %s", leftText.c_str(), lumiText)); //cmslabel->Draw(); TPaveText* label_sqrt = new TPaveText(0.4,0.953,0.96,0.975, "brNDC"); label_sqrt->SetFillColor(kWhite); label_sqrt->SetBorderSize(0); label_sqrt->SetTextSize(0.038); label_sqrt->SetTextFont(62); label_sqrt->SetTextAlign(31); // align right // label_sqrt->AddText("#sqrt{s} = 7 TeV"); label_sqrt->AddText(Form("%s, L = %s at #sqrt{s} = 8 TeV", leftText.c_str(), lumiText)); label_sqrt->Draw(); } else{ TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.04); latex->SetTextAlign(31); latex->SetTextAlign(11); // align left latex->DrawLatex(0.18, 0.96, "CMS preliminary 2012"); latex->DrawLatex(0.60,0.96,Form("%.1f fb^{-1} at #sqrt{s} = 8 TeV",intLumi)); } TLine *l1b=new TLine(); l1b->SetLineStyle(1); l1b->SetLineWidth(2.0); l1b->SetLineColor(kRed); //l1b->DrawLine(200.0,1.0,600.0,1.0); cMCMC->Update(); // cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.root"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.eps"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.png"); gPad->SetLogy(); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.eps"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.png"); cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.root"); // cMCMC->SaveAs("ClsLimit_1fb.png"); TFile *outfile=new TFile("AsymptoticCLs_TGraph.root","RECREATE"); outfile->cd(); if(unblind)grobslim_cls->Write(); grmedian_cls->Write(); outfile->Close(); }//end main
//___________________________________________________________________________ Double_t* Ifit(int shift, Double_t& dataResult, Double_t& dataErr, std::string dataFile, TH1D* hsig, TH1D* hbkg, TH1D* hEGdata, Double_t* FitPar, int ptbin=30, char EBEE[10]="EB", int fit_data=2) { printf(" *** calling Ifit for %s , ptbin %d *** \n\n", EBEE,ptbin); cout << "The number of bins are: " << endl; cout << "hdata nbins = " << hEGdata->GetNbinsX() << endl; cout << "hsig nbins = " << hsig->GetNbinsX() << endl; cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl; TCanvas *c1 = new TCanvas("HF1", "Histos1", 0, 0, 600, 600); gStyle->SetOptFit(0); if(fit_data != 3) dataColl.clear(); sigColl.clear(); bkgColl.clear(); totalColl.clear(); ctauColl.clear(); Para.clear(); Para_err.clear(); info.clear(); info_err.clear(); float ptmax=0.; if(ptbin== 21) ptmax= 23; if(ptbin== 23) ptmax= 26; if(ptbin== 26) ptmax= 30; if(ptbin== 30) ptmax= 35; if(ptbin== 35) ptmax= 40; if(ptbin== 40) ptmax= 45; if(ptbin== 45) ptmax= 50; if(ptbin== 50) ptmax= 60; if(ptbin== 60) ptmax= 85; if(ptbin== 85) ptmax= 120; if(ptbin== 120) ptmax= 300; if(ptbin== 300) ptmax= 500; Double_t* fitted = new Double_t[6]; fitted[0] = 0.; fitted[1] = 0.; fitted[2] = 0.; fitted[3] = 0.; fitted[4] = 0.; fitted[5] = 0.; char hname[30]; hsig->SetLineColor(1); hbkg->SetLineColor(1); hsig->SetNdivisions(505,"XY"); hbkg->SetNdivisions(505,"XY"); hsig->SetTitle(""); hbkg->SetTitle(""); hsig->SetXTitle("combined ISO (GeV)"); hbkg->SetXTitle("combined ISO (GeV)"); TH1F *hsum = (TH1F*)hsig->Clone(); hsum->Add(hbkg,1); float ntemplate = 1.; if (hsum->Integral()>1.) ntemplate = hsum->Integral(); float sigfrac = hsig->Integral()/ntemplate*0.8; TH1F *hsum_norm = (TH1F*)hsum->Clone(); hsum_norm->Scale(1./hsum->Integral()); TH1F *hdata = new TH1F(); int ndata=0; if ( fit_data==1 ) { hdata = (TH1F*)hEGdata->Clone(); ndata = (int)hdata->Integral(); for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){ for(int ipoint=0; ipoint<hdata->GetBinContent(ibin); ipoint++) { dataColl.push_back(hdata->GetBinCenter(ibin)); } } ndata = dataColl.size(); }else if (fit_data==2 ){ hdata = (TH1F*)hEGdata->Clone(); hdata -> Reset(); dataColl.clear(); FILE *infile = fopen(dataFile.data(),"r"); float xdata, xdata1, xdata2; // combined isolation, pt, eta int flag = 1; while (flag!=-1){ flag =fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2); if( xdata1 >= ptbin && xdata1 < ptmax && xdata<20.) { if((strcmp(EBEE,"EB")==0 && TMath::Abs(xdata2)<1.45) || (strcmp(EBEE,"EE")==0 && TMath::Abs(xdata2)<2.5 && TMath::Abs(xdata2)>1.7) ) { dataColl.push_back(xdata); hdata->Fill(xdata); } } }// keep reading files as long as text exists ndata = dataColl.size(); printf("test print data 2 %2.3f \n", dataColl[2]); // cout << "ndata in dataColl = " << ndata << endl; if ( ndata == 0 ) { printf(" no data to fit \n"); return fitted; } } if(ndata==0) { printf(" --- no events in the fit \n"); return fitted; } //test fit the template and get PDFs TCanvas *c10 = new TCanvas("c10","c10",1000,500); c10->Divide(2,1); c10->cd(1); double par[20] = {hsig->GetMaximum(), 1., 0.6, 0.3, hbkg->GetMaximum(), -.45, -0.05, 0.03, 1., 1., 1., 1.}; if(strcmp(EBEE,"EE")==0) { par[2]=-0.1, par[3]=0.2; par[6]=-0.15; par[7]=0.02; }; int fit_status; TF1 *f1 = new TF1("f1", exp_conv, -1., 20., 11); TF1 *fmcsigfit = new TF1("fmcsigfit", exp_conv, -1., 20., 11); fmcsigfit->SetLineColor(4); fmcsigfit->SetLineWidth(2); f1->SetNpx(10000); f1->SetParameters(par); f1->SetLineWidth(2); c10->cd(1); fit_status = hsig->Fit(f1,"","",-1., 5.); hsig->Draw(); f1->Draw("same"); if ( fit_status > 0 ) { printf("fit signal template failed. QUIT \n"); return fitted; } if(para_index>0 && para_index<4){ double tmppar = f1->GetParameter(para_index); f1->SetParameter(para_index, tmppar+para_sigma*f1->GetParError(para_index)); } TF1 *fmcsig = (TF1*)f1->Clone(); TF1 *fmcsigcorr = (TF1*)f1->Clone(); fmcsig->SetNpx(10000); fmcsigcorr->SetNpx(10000); fmcsigfit->SetNpx(10000); TCanvas *c101 = new TCanvas("c101","c101",1000,500); c101->Divide(2,1); c101->cd(1); fmcsig->SetLineColor(1); // fmcsig->Draw(); // f1->Draw("same"); TH1F *htmp1 = (TH1F*)fmcsig->GetHistogram(); // TH1F *htmp2 = (TH1F*)fmcsigcorr->GetHistogram(); TH2F *htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25); htmp2->SetNdivisions(505,"XY"); htmp2->SetXTitle("Iso"); htmp2->SetYTitle("A.U."); htmp2->SetLineColor(1); // htmp2->Draw(); // htmp1->Draw("same"); // htmp2->Add(htmp1,-1); // htmp2->Divide(htmp1); htmp2->GetXaxis()->SetRangeUser(-1., 10.); htmp2->SetMinimum(-1.); //htmp2->SetMaximum(1.5); htmp2->Draw(); fmcsig->Draw("same"); // fmcsigcorr->Draw("same"); TLegend *tleg1 = new TLegend(0.5, 0.7, 0.93, 0.92); tleg1->SetHeader(""); tleg1->SetFillColor(0); tleg1->SetShadowColor(0); tleg1->SetBorderSize(0); tleg1->AddEntry(fmcsig,"Zee data","l"); //tleg1->AddEntry(fmcsigcorr,"corrected shape","l"); tleg1->AddEntry(fmcsigfit,"shape from data","l"); tleg1->Draw(); //return fitted; SigPDFnorm = f1->Integral(-1.,20.); printf("status %d, sig area %3.3f \n", fit_status,f1->Integral(-1., 20.)); f1->SetParameter(2,f1->GetParameter(2)+0.2); f1->SetParameter(3,f1->GetParameter(3)+0.1); Para.push_back(f1->GetParameter(0)); Para.push_back(f1->GetParameter(1)); Para.push_back(f1->GetParameter(2)); Para.push_back(f1->GetParameter(3)); Para_err.push_back(f1->GetParError(0)); Para_err.push_back(f1->GetParError(1)); Para_err.push_back(f1->GetParError(2)); Para_err.push_back(f1->GetParError(3)); c10->cd(2); TF1 *fbkgfit = new TF1("fbkgfit", expinv_power, -1., 20., 11); TF1 *f3 = new TF1("f3", expinv_power, -1., 20., 11); fbkgfit->SetNpx(10000); fbkgfit->SetLineColor(4); fbkgfit->SetLineWidth(2); f3->SetNpx(10000); f3->SetLineWidth(2); f3->SetParameters(f1->GetParameters()); f3->SetParLimits(5,-5.,0.); f3->SetParLimits(6,-0.5,0.); f3->SetParLimits(7,0.001,0.2); f3->SetParLimits(8,0.5,5.); if ( strcmp(EBEE,"EB")==0 ){ // f3->FixParameter(8,1.); // f3->FixParameter(6,-0.1); f3->SetParLimits(8,1.,1.5); } float bkg_bend_power = 1.; if ( ptbin==21 ) bkg_bend_power = 4.5; if ( ptbin==23 ) bkg_bend_power = 4.; if ( ptbin==26 ) bkg_bend_power = 3.5; if ( ptbin==30 ) bkg_bend_power = 2.6; if ( ptbin==35 ) bkg_bend_power = 2.2; if ( ptbin==40 ) bkg_bend_power = 2.; if ( ptbin==45 ) bkg_bend_power = 2.; if ( ptbin==50 ) bkg_bend_power = 1.8; if ( ptbin==60 ) bkg_bend_power = 1.5; if ( ptbin==85 ) bkg_bend_power = 1.; if ( ptbin==120 ) bkg_bend_power = 1.; if ( strcmp(EBEE,"EE")==0 ){ f3->SetParameter(8,bkg_bend_power); f3->SetParLimits(8,bkg_bend_power-1., bkg_bend_power+1.); } f3->FixParameter(0,f3->GetParameter(0)); f3->FixParameter(1,f3->GetParameter(1)); f3->FixParameter(2,f3->GetParameter(2)); f3->FixParameter(3,f3->GetParameter(3)); hbkg->SetMaximum(hbkg->GetMaximum()*3.); fit_status = hbkg->Fit(f3,"b","",-1., 20.); hbkg->Draw(); if ( fit_status > 0 ) { printf("fit background template failed. QUIT \n"); return fitted; }else { f3->Draw("same"); } TF1 *fmcbkg = (TF1*)f3->Clone(); fmcbkg->SetLineColor(1); c101->cd(2); htmp1 = (TH1F*)fmcbkg->GetHistogram(); htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25); htmp2->SetNdivisions(505,"XY"); htmp2->SetXTitle("Iso"); htmp2->SetYTitle("A.U."); htmp2->SetLineColor(1); htmp2->GetXaxis()->SetRangeUser(-1., 20.); htmp2->SetMinimum(-1.); htmp2->SetMaximum(1.5); htmp2->Draw(); fmcbkg->Draw("same"); TLegend *tleg2 = new TLegend(0.25, 0.2, 0.6, 0.42); tleg2->SetHeader(""); tleg2->SetFillColor(0); tleg2->SetShadowColor(0); tleg2->SetBorderSize(0); if ( strcmp(EBEE,"EB")==0 ){ tleg2->AddEntry(fmcbkg,"MC shape","l"); }else { tleg2->AddEntry(fmcbkg,"Data SB shape","l"); } tleg2->AddEntry(fbkgfit,"shape from data","l"); tleg2->Draw(); if(para_index>4){ double tmppar = f3->GetParameter(para_index); f3->SetParameter(para_index, tmppar+para_sigma*f3->GetParError(para_index)); } // f3->SetParameter(5,-0.5); // f3->SetParameter(6,-0.05); // f3->SetParameter(7,0.02); // f3->SetParameter(8,1.); Para.push_back(f3->GetParameter(4)); Para.push_back(f3->GetParameter(5)); Para.push_back(f3->GetParameter(6)); Para.push_back(f3->GetParameter(7)); Para.push_back(f3->GetParameter(8)); Para_err.push_back(f3->GetParError(4)); Para_err.push_back(f3->GetParError(5)); Para_err.push_back(f3->GetParError(6)); Para_err.push_back(f3->GetParError(7)); Para_err.push_back(f3->GetParError(8)); BkgPDFnorm = f3->Integral(-1., 20.); printf("status %d, bkg area %3.3f \n", fit_status,f3->Integral(-1., 20.)/hdata->GetBinWidth(2)); //test PDFs TCanvas *c11 = new TCanvas("c11","c11",1000,500); c11->Divide(2,1); c11->cd(1); TF1 *f11 = new TF1("f11",exp_conv_norm, -1., 20., 11); f11->SetNpx(10000); f11->SetParameters(f3->GetParameters()); f11->Draw(); printf(" SIG PDF area %2.3f \n", f11->Integral(-1., 20.)); c11->cd(2); TF1 *f12 = new TF1("f12",expinv_power_norm, -1., 20., 11); f12->SetNpx(10000); f12->SetParameters(f3->GetParameters()); f12->Draw(); printf(" BKG PDF area %2.3f \n", f12->Integral(-1., 20.)); //c1->cd(); printf(" --------- before the fit ------------- \n"); printf("Nsig %2.3f, Nbg %2.3f, Ntemplate %3.3f \n", hsig->Integral(), hbkg->Integral(), ntemplate); printf("Purity %2.3f, init size %4.3f, fit sample size %4d\n", hsig->Integral()/hsum->Integral(), hsum->Integral(), ndata); printf(" -------------------------------------- \n"); printf( " ----- Got %d, %d, %d events for fit ----- \n ", dataColl.size(), sigColl.size(), bkgColl.size() ); //-------------------------------------------------- //init parameters for fit Double_t vstart[11] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.}; vstart[0] = sigfrac*ndata; vstart[1] = (1-sigfrac)*ndata; for (int ii=0; ii<9; ii++) { vstart[ii+2] = Para[ii]; //8 shape parameters } TMinuit *gMinuit = new TMinuit(NPAR); gMinuit->Command("SET STR 1"); gMinuit->SetFCN(fcn); Double_t arglist[11]; Int_t ierflg = 0; arglist[0] = 1; gMinuit->mnexcm("SET ERR", arglist ,1,ierflg); arglist[0] = 1; gMinuit->mnexcm("SET PRINT", arglist ,1,ierflg); Double_t step[] = { 1.,1.,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,}; for ( int ii=0; ii<9; ii++){ printf(" para %d, %.5f, err %.5f \n", ii, Para[ii], Para_err[ii]); } float sigma = 3.; gMinuit->mnparm(0, "Signal yield" , vstart[0], step[0], 0., ndata*2. , ierflg); gMinuit->mnparm(1, "background yield" , vstart[1], step[1], 0., ndata*2. , ierflg); // gMinuit->mnparm(2, "constant" , Para[0], 0.00, Para[0], Para[0] , ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], 0.01, Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], 0.01, Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], 0.01, Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg); // gMinuit->mnparm(6, "constant" , Para[4], 0.00, Para[4] , Para[4] , ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], 0.01, Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], 0.01, Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], 0.01, 0.001 , 0.1 , ierflg); // // gMinuit->mnparm(10, "bg bend power", Para[8], 0.01, Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], 0.01, 0.5 , 5. , ierflg); // gMinuit->mnparm(2, "constant" , Para[0], TMath::Abs(Para[0]*0.0) , Para[0], Para[0], ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.01) , Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.1) , 0.8 , 1.3 , ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], TMath::Abs(Para[2]*0.1) , 0.5 , 1.0 , ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], TMath::Abs(Para[3]*0.1) , 0.25 , 0.5 , ierflg); // gMinuit->mnparm(6, "constant" , Para[4], TMath::Abs(Para[4]*0.0) , Para[4], Para[4], ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.1) , -0.7 , -0.3 , ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], TMath::Abs(Para[6]*0.0) , -0.15 , -0.05 , ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) , 0.01 , 0.05 , ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) , 0.5 , 1.5 , ierflg); gMinuit->mnparm(2, "constant" , Para[0], 0.00, Para[0], Para[0] , ierflg); gMinuit->mnparm(3, "exp tail" , Para[1], 0.00, Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); gMinuit->mnparm(4, "exg mean" , Para[2], 0.00, Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg); gMinuit->mnparm(5, "exg width" , Para[3], 0.00, Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg); gMinuit->mnparm(6, "constant" , Para[4], 0.00, Para[4] , Para[4] , ierflg); gMinuit->mnparm(7, "bg exp turnon", Para[5], 0.00, Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg); gMinuit->mnparm(8, "bg x offset ", Para[6], 0.00, Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg); gMinuit->mnparm(9, "bg bend slope", Para[7], 0.00, 0.001 , 0.1 , ierflg); gMinuit->mnparm(10, "bg bend power", Para[8], 0.00, Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg); printf(" --------------------------------------------------------- \n"); printf(" Now ready for minimization step \n --------------------------------------------------------- \n"); arglist[0] = 500; // number of iteration gMinuit->mnexcm("MIGRAD", arglist,1,ierflg); //can do scan // arglist[0] = 0; // gMinuit->mnexcm("SCAN", arglist,1,ierflg); printf (" -------------------------------------------- \n"); printf("Finished. ierr = %d \n", ierflg); double para[NPAR+1],errpara[NPAR+1]; double tmp_errpara[NPAR+1]; for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j]=0.1; } for(int j=2; j<=NPAR-1;j++) { if(Para_err[j-2]!=0.) tmp_errpara[j]=TMath::Abs(Para_err[j-2]); } int ni=6; if ( strcmp(EBEE,"EE")==0 ) { ni=6; }//if(ptbin==21) ni=0;} if ( ierflg == 0 ) { for(int i=0; i<ni; i++) { float istep[10] = {0.,0.,0.,0.,0.,0.,0.}; if (i<(ni-1)) { istep[i] = 0.001; }else { for (int j=0; j<ni-1; j++) {istep[j] = 0.001;} } for(int j=0; j<=NPAR-1;j++) { gMinuit->GetParameter(j, para[j], errpara[j]); if (errpara[j] != 0. ) { tmp_errpara[j] = TMath::Abs(errpara[j]); } } if ( strcmp(EBEE,"EB")==0 ) { sigma = 10.; if ( i==(ni-1) ) { sigma=5.;istep[1]=istep[4]=0.; } if ( ptbin==21 && i==1 ){ sigma=3.; } if ( ptbin==21 && i==(ni-1) ){ sigma=20.; } if ( ptbin==23 && i==0 ){ para[7]=-0.5; } if ( ptbin==23 && i==1 ){ istep[1]=0.; istep[3]=0.01; } if ( ptbin==23 && i==3 ){ istep[1]=0.01; istep[3]=0.0; } if ( ptbin==23 && i==(ni-1) ){ sigma=20.; } if ( ptbin==26 && i==1 ){ sigma=5.; } if ( ptbin==26 && i==(ni-1) ){ sigma=20.; } if ( ptbin==30 && i==(ni-1) ){ sigma=3.; } if ( ptbin==35 && i==(ni-1) ) { sigma=10.; } if ( ptbin==40 && i==(ni-1) ) { sigma=5.; istep[4]=0.01; } if ( ptbin==45 && i==(ni-1) ) { sigma=10.; } if ( ptbin==60 && i==0 ) { para[3]=1.; para[4]=0.6; para[5]=0.32; para[7]=-0.45; para[9]=0.025; para[10] = 1.;} if ( ptbin==60 && i==(ni-1) ) { sigma=5.; istep[4]=0.01;} if ( ptbin>=85 && i==(ni-1) ){ sigma=3.; } if ( ptbin==300 ) { istep[2]=istep[3]=istep[4]=0.; }// para[7] = -5.11907e-02; istep[1]=0.; } float tmp8=0.; // if( i!= (ni-1) ) { gMinuit->mnparm(0, "Signal yield" , para[0], 1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg); gMinuit->mnparm(1, "background yield", para[1], 1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg); gMinuit->mnparm(2, "constant" , para[2], 0., para[2]-100.*tmp_errpara[2], para[2]+100.*tmp_errpara[2], ierflg); gMinuit->mnparm(6, "constant" , para[6], 0., para[6]-100.*tmp_errpara[6], para[6]+100.*tmp_errpara[6], ierflg); gMinuit->mnparm(3, "exp tail" , para[3], istep[4], para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg); gMinuit->mnparm(4, "exg mean" , para[4], istep[3], para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg); gMinuit->mnparm(5, "exg width" , para[5], istep[2], para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg); gMinuit->mnparm(7, "bg exp turnon", para[7], istep[1], para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); gMinuit->mnparm(8, "bg x offset ", para[8], tmp8 , para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg); gMinuit->mnparm(9, "bg bend slope", para[9], istep[0], para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg); float sigma10=5.; if ( para[10]-sigma10*tmp_errpara[10] < 1. )// && i!=(ni-1)) gMinuit->mnparm(10, "bg bend power", para[10], istep[0], 1., para[10]+sigma10*tmp_errpara[10], ierflg); else gMinuit->mnparm(10, "bg bend power", para[10], istep[0], para[10]-sigma10*tmp_errpara[10], para[10]+sigma10*tmp_errpara[10], ierflg); // }else { // gMinuit->mnparm(2, "constant" , Para[0], TMath::Abs(Para[0]*0.0) , Para[0], Para[0], ierflg); // //gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.01) , Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); // gMinuit->mnparm(3, "exp tail" , Para[1], TMath::Abs(Para[1]*0.0) , 0.8 , 1.3 , ierflg); // gMinuit->mnparm(4, "exg mean" , Para[2], TMath::Abs(Para[2]*0.1) , 0.5 , 1.0 , ierflg); // gMinuit->mnparm(5, "exg width" , Para[3], TMath::Abs(Para[3]*0.1) , 0.25 , 0.5 , ierflg); // gMinuit->mnparm(6, "constant" , Para[4], TMath::Abs(Para[4]*0.0) , Para[4], Para[4], ierflg); // gMinuit->mnparm(7, "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.0) , -0.7 , -0.3 , ierflg); // gMinuit->mnparm(8, "bg x offset ", Para[6], TMath::Abs(Para[6]*0.0) , -0.15 , -0.05 , ierflg); // gMinuit->mnparm(9, "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) , 0.01 , 0.05 , ierflg); // gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) , 0.5 , 1.5 , ierflg); // } if( ptbin >=300 ) { gMinuit->mnparm(3, "exp tail" , 1.257281, 0.0, para[1]-3.*tmp_errpara[1], para[1]+3.*tmp_errpara[1], ierflg); gMinuit->mnparm(4, "exg mean" , 0.856906, 0.0, para[2]-3.*tmp_errpara[2], para[2]+3.*tmp_errpara[2], ierflg); gMinuit->mnparm(5, "exg width" , 0.320847, 0.0, para[3]-3.*tmp_errpara[3], para[3]+3.*tmp_errpara[3], ierflg); } }else{ sigma=10.; if ( i==0 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 0.3; } if ( i==(ni-1) ) { sigma=3.;istep[1]=istep[4]=0.; } //test of not changing signal template if ( i==(ni-1) ) { istep[4]=0.;} if ( ptbin==21 && i==(ni-1) ) { sigma=20.;} if ( ptbin==23 && i==0 ) { sigma=5.;} if ( ptbin==23 && i==(ni-1) ) { sigma=10.;} if ( ptbin<30 && ptbin>21 && i==1 ){ istep[1]=0.; istep[3]=0.01; } if ( ptbin<30 && ptbin>21 && i==3 ){ istep[1]=0.01; istep[3]=0.0; } if ( ptbin==26 && i==1 ) { para[7] = -0.8; } if ( ptbin==26 && i==(ni-1) ) { sigma=10.; } if ( ptbin==30 && i==(ni-1) ) { sigma=10.; } if ( ptbin==35) {para[7] = -0.75;} if ( ptbin==40 && i==0) {para[7] = -0.65; para[10] = 2.;} if ( ptbin==45 && i==(ni-1) ) {sigma=5.;} if ( ptbin==85 && i==(ni-1) ) {sigma=10.; istep[4]=0.01;} if (ptbin >= 85 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 1.; } if ( ptbin==120 ) { para[7] = -0.615255; istep[1]=0.;} // if ( ptbin==120 && i==0 ) { // para[3] = 1.446454; para[4]=-0.016373; para[5]=0.163238; // istep[2]=istep[3]=istep[4]=0.; sigma=5.; tmp_errpara[10]=0.2; // } // if ( ptbin==120 && i==(ni-1) ) { istep[2]=istep[3]=istep[4]=0.; sigma=5.;} gMinuit->mnparm(0, "Signal yield" , para[0], 1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg); gMinuit->mnparm(1, "background yield", para[1], 1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg); gMinuit->mnparm(2, "constant" , para[2], 0., para[2], para[2] , ierflg); gMinuit->mnparm(6, "constant" , para[6], 0., para[6], para[6], ierflg); gMinuit->mnparm(3, "exp tail" , para[3], istep[4], para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg); gMinuit->mnparm(4, "exg mean" , para[4], istep[3], para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg); gMinuit->mnparm(5, "exg width" , para[5], istep[2], para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg); gMinuit->mnparm(7, "bg exp turnon", para[7], istep[1], para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); gMinuit->mnparm(8, "bg x offset ", para[8], 0.00, para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg); gMinuit->mnparm(9, "bg bend slope", para[9], istep[0], para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg); float minerr=1.; //if ( tmp_errpara[10] > 0.5) tmp_errpara[10] = 0.5; float sigma10=5.; if ( para[10]-sigma10*tmp_errpara[10] < 1. ) gMinuit->mnparm(10, "bg bend power", para[10], istep[0], minerr, para[10]+sigma10*tmp_errpara[10], ierflg); else gMinuit->mnparm(10, "bg bend power", para[10], istep[0], para[10]-sigma10*tmp_errpara[10], para[10]+sigma10*tmp_errpara[10], ierflg); } printf(" ************ \n"); printf(" do %d th fit \n", i); if(i==5 && dataFile.find("toy") != std::string::npos) { cout << "dataResult = " << dataResult << "\t dataErr = " << dataErr << endl; // fixed turn on at +- 1 sigma gMinuit->mnparm(7, "bg exp turnon", dataResult-(float)shift*dataErr, 0.00, para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg); } else if(dataFile.find("toy") == std::string::npos) { dataResult = para[7]; dataErr = tmp_errpara[7]; } arglist[0] = 500; // number of iteration gMinuit->mnexcm("MIGRAD", arglist ,1,ierflg); if ( ierflg != 0 ) { printf("fit failed at %d iteration \n", i); c1->cd(); c1->Draw(); hdata->Draw("phe"); return fitted; } } } Double_t amin,edm,errdef; if ( ierflg == 0 ) { for(int j=0; j<=NPAR-1;j++) { gMinuit->GetParameter(j, para[j],errpara[j]); info.push_back(para[j]); info_err.push_back(errpara[j]); printf("Parameter %d = %f +- %f\n",j,para[j],errpara[j]); } para[NPAR] = dataColl.size(); printf(" fitted yield %2.3f \n", (para[0]+para[1])/ndata ); info.push_back(sigColl.size()); for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j] = errpara[j]; if( tmp_errpara[j] == 0. ) tmp_errpara[j] = par[j]*.1; } //do minos if fit sucessed. } if (ierflg != 0 ) { printf(" *********** Fit failed! ************\n"); gMinuit->GetParameter(0, para[0],errpara[0]); gMinuit->GetParameter(1, para[1],errpara[1]); para[0]=0.; errpara[0]=0.; c1->cd(); c1->Draw(); //gPad->SetLogy(); hdata->SetNdivisions(505,"XY"); hdata->SetXTitle("comb. ISO (GeV)"); hdata->SetYTitle("Entries"); hdata->SetTitle(""); hdata->SetMarkerStyle(8); hdata->SetMinimum(0.); if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.); else hdata->SetMaximum(hdata->GetMaximum()*1.25); if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.25); hdata->Draw("phe"); return fitted; } // Print results // Double_t amin,edm,errdef; Int_t nvpar,nparx,icstat; gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat); gMinuit->mnprin(1,amin); gMinuit->mnmatu(1); printf(" ========= happy ending !? =========================== \n"); printf("FCN = %3.3f \n", amin); //use new PDF form double tmppar[12]; for(int ii=0; ii<9; ii++){ tmppar[ii] = para[ii+2]; fmcsigfit->SetParameter(ii,tmppar[ii]); fbkgfit->SetParameter(ii,tmppar[ii]); } c101->cd(1); //fmcsigfit->SetParameters(tmppar); //fmcsigfit->SetParameter(2,0.1); //fmcsigfit->SetLineStyle(2); fmcsigfit->Draw("same"); c101->cd(2); fbkgfit->SetParameter(4,fbkgfit->GetParameter(4)*fmcbkg->Integral(-1., 20.)/fbkgfit->Integral(-1., 20.)); fbkgfit->Draw("same"); char fname[100]; sprintf(fname,"plots/template_Ifit%s_%d.pdf",EBEE,ptbin); c101->SaveAs(fname); f11->SetParameters(tmppar); SigPDFnorm = f11->Integral(-1., 20.); f12->SetParameters(tmppar); BkgPDFnorm = f12->Integral(-1., 20.); // plot c1->cd(); c1->Draw(); //gPad->SetLogy(); hdata->SetNdivisions(505,"XY"); hdata->SetXTitle("comb. ISO (GeV)"); hdata->SetYTitle("Entries"); hdata->SetTitle(""); hdata->SetMarkerStyle(8); hdata->SetMinimum(0.); if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.); else hdata->SetMaximum(hdata->GetMaximum()*1.5); if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.2); hdata->Draw("p e "); f11->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2)); // f11->SetFillColor(5); f11->SetLineColor(4); //f11->SetFillColor(603); f11->SetLineWidth(2); // f11->SetFillStyle(3001); f11->Draw("same"); f12->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2)); // f12->SetFillColor(8); f12->SetLineColor(2); //f12->SetFillColor(603); f12->SetLineWidth(2); // f12->SetFillStyle(3013); f12->Draw("same"); TF1 *f13 = new TF1("f13",sum_norm, -1., 20 ,11); f13->SetNpx(10000); f13->SetParameters(f12->GetParameters()); f13->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2)); f13->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2)); f13->SetLineWidth(2); f13->SetLineColor(1); f13->Draw("same"); f11->Draw("same"); hdata->Draw("pe same"); // cout << "The number of bins are: " << endl; // cout << "hdata nbins = " << hdata->GetNbinsX() << endl; // cout << "hsig nbins = " << hsig->GetNbinsX() << endl; // cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl; // get chi2/NDF double chi2ForThisBin=0; int nbinForThisBin=0; chi2Nbins(f13, hdata, chi2ForThisBin, nbinForThisBin); for(int epar=0; epar < 11; epar++) { // cout << "f11 parameter " << epar << " = " << // f11->GetParameter(epar) << endl; FitPar[epar] = f11->GetParameter(epar); } for(int epar=0; epar < 11; epar++) { // cout << "f12 parameter " << epar << " = " << // f12->GetParameter(epar) << endl; FitPar[epar+11] = f12->GetParameter(epar); } for(int epar=0; epar < 11; epar++) { // cout << "f13 parameter " << epar << " = " << // f13->GetParameter(epar) << endl; FitPar[epar+22] = f13->GetParameter(epar); } // cout << "hdata integral = " << hdata->Integral() << endl; // cout << endl; // printf("fit area %3.2f; sig area %3.2f; bg area %3.2f\n", f13->Integral(-1., 20.)/hdata->GetBinWidth(2), f11->Integral(-1., 20.)/hdata->GetBinWidth(2),f12->Integral(-1., 20.)/hdata->GetBinWidth(2)); // for(int i=0; i<12; i++){ // printf(" fit para %d = %4.3f \n", i, f13->GetParameter(i)); // } TLegend *tleg = new TLegend(0.5, 0.7, 0.93, 0.92); char text[50]; sprintf(text,"%s Pt %d ~ %.0f GeV",EBEE, ptbin, ptmax); tleg->SetHeader(text); tleg->SetFillColor(0); tleg->SetShadowColor(0); tleg->SetBorderSize(0); sprintf(text,"#chi^{2}/NDF = %.1f/%d",chi2ForThisBin,nbinForThisBin); tleg->AddEntry(hdata,text,""); sprintf(text,"Data %.1f events",hdata->Integral()); tleg->AddEntry(hdata,text,"pl"); sprintf(text,"Fitted %.1f events",para[0]+para[1]);//f13->Integral(-1., 20.)/hdata->GetBinWidth(2)); tleg->AddEntry(f13,text,"l"); sprintf(text,"SIG %.1f #pm %.1f events",para[0], errpara[0]); tleg->AddEntry(f11,text,"f"); sprintf(text,"BKG %.1f #pm %.1f events",para[1], errpara[1]); tleg->AddEntry(f12,text,"f"); tleg->Draw(); gPad->RedrawAxis(); printf("%s, ptbin %d, Data %.1f events \n",EBEE, ptbin, hdata->Integral()); printf("Fitted %.1f (in 5GeV) %.1f events \n",para[0]+para[1],f13->Integral(-1.,5.)); printf("SIG %.1f #pm %.1f events \n",para[0], errpara[0]); printf("SIG (in 5GeV) %.1f #pm %.1f events \n",f11->Integral(-1.,5.)/hdata->GetBinWidth(2), f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2)); printf("BKG %.1f #pm %.1f events \n",para[1], errpara[1]); printf("BKG (in 5GeV) %.1f #pm %.1f events \n",f12->Integral(-1.,5.)/hdata->GetBinWidth(2), f12->Integral(-1.,5.)*errpara[1]/para[1]/hdata->GetBinWidth(2)); float purity = f11->Integral(-1.,5.)/hdata->GetBinWidth(2)/(f11->Integral(-1.,5.)/hdata->GetBinWidth(2)+f12->Integral(-1.,5.)/hdata->GetBinWidth(2)); float purity_err = purity*errpara[0]/para[0]; printf("Purity (in 5GeV) %.3f #pm %.3f \n", purity, purity_err); // hsig->Scale(para[0]/hsig->Integral()); // hbkg->Scale(para[1]/hbkg->Integral()); // hbkg->Add(hsig); // hsig->SetLineColor(1); // hsig->SetFillColor(5); // hsig->SetFillStyle(3001); // hbkg->SetLineWidth(2); // hsig->Draw("same"); // hbkg->Draw("same"); sprintf(fname,"plots/unbinned_free_Ifit%s_%d.pdf",EBEE,ptbin); if (para_index>0) sprintf(fname,"plots/unbinned_Ifit%s_%d_para%d_sigma%1.0f.pdf",EBEE,ptbin,para_index,para_sigma); if(Opt_SavePDF == 1) { c1->SaveAs(fname); } else { c1->Close(); c10->Close(); c101->Close(); c11->Close(); } printf("----- fit results with signal projection ----------- \n"); fitted[0] = para[0]; fitted[1] = errpara[0]; fitted[2] = para[1]; fitted[3] = errpara[1]; fitted[4] = f11->Integral(-1.,5.)/hdata->GetBinWidth(2); fitted[5] = f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2); return fitted; }
void merge_pbpb_pp_HLT(){ TH1::SetDefaultSumw2(); //TFile *fpbpb1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet80_v2.root"); //TFile *fpbpb2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet65_v2.root"); //TFile *fpbpb3 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PbPb/2011/data/ntuple_2011_pbpbJet55_v2.root"); //TFile *fpp1 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet80.root"); //TFile *fpp2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_ppJet40.root"); TFile *fpp1_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet80_v2.root"); TFile *fpp2_v2 = TFile::Open("/mnt/hadoop/cms/store/user/rkunnawa/rootfiles/PP/2013/data/ntuple_2013_JEC_applied_ppJet40_v2.root"); /* TTree *jetpbpb1_v2 = (TTree*)fpbpb1->Get("jetR3"); TTree *jetpbpb2_v2 = (TTree*)fpbpb2->Get("jetR3"); TTree *jetpbpb3_v2 = (TTree*)fpbpb3->Get("jetR3"); TTree *evtpbpb1_v2 = (TTree*)fpbpb1->Get("evt"); TTree *evtpbpb2_v2 = (TTree*)fpbpb2->Get("evt"); TTree *evtpbpb3_v2 = (TTree*)fpbpb3->Get("evt"); jetpbpb1_v2->AddFriend(evtpbpb1_v2); jetpbpb2_v2->AddFriend(evtpbpb2_v2); jetpbpb3_v2->AddFriend(evtpbpb3_v2); */ //TTree *jetpp1 = (TTree*)fpp1->Get("ntjet"); // TTree *jetpp2 = (TTree*)fpp2->Get("ntjet"); TTree *jetpp1_v2 = (TTree*)fpp1_v2->Get("jetR3"); TTree *jetpp2_v2 = (TTree*)fpp2_v2->Get("jetR3"); TTree *evtpp1_v2 = (TTree*)fpp1_v2->Get("evt"); TTree *evtpp2_v2 = (TTree*)fpp2_v2->Get("evt"); jetpp1_v2->AddFriend(evtpp1_v2); jetpp2_v2->AddFriend(evtpp2_v2); //TCut pbpb3 = "abs(eta)<2&&jet55&&!jet65&&!jet80&&chMax/pt>0.01"; TCut pp3 = "abs(eta)<2&&jet40&&!jet60&&!jet80&&chMax/pt>0.01"; //TH1F *hpbpb1 = new TH1F("hpbpb1","",30,0,300); //TH1F *hpbpb2 = new TH1F("hpbpb2","",30,0,300); //TH1F *hpbpb3 = new TH1F("hpbpb3","",30,0,300); //TH1F *hpbpbComb = new TH1F("hpbpbComb","",30,0,300); TH1F *hpp1 = new TH1F("hpp1","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp2 = new TH1F("hpp2","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hpp3 = new TH1F("hpp3","",nbins_jetPtBin,boundaries_jetPtBin); TH1F *hppComb = new TH1F("hppComb","",nbins_jetPtBin,boundaries_jetPtBin); //get the prescl factor information. //Float_t presclpbpb3 = (Float_t)jetpbpb1_v2->GetEntries("jet80")/jetpbpb1_v2->GetEntries("jet55&&jet80"); //cout<<"pbpb prescl3 = "<<presclpbpb3<<endl;//1.99871 Float_t presclpp3 = (Float_t)jetpp1_v2->GetEntries("jet80")/jetpp1_v2->GetEntries("jet40&&jet80"); cout<<"pp prescl3 = "<<presclpp3<<endl; //9.24968 /* jetpbpb1_v2->Project("hpbpb1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpbpb1->Print("base"); divideBinWidth(hpbpb1); jetpbpb2_v2->Project("hpbpb2","pt","abs(eta)<2&&jet65&&!jet80&&chMax/pt>0.01"); hpbpb2->Print("base"); divideBinWidth(hpbpb2); jetpbpb3_v2->Project("hpbpb3","pt","1.9987"*pbpb3); hpbpb3->Print("base"); divideBinWidth(hpbpb3); */ jetpp1_v2->Project("hpp1","pt","abs(eta)<2&&jet80&&chMax/pt>0.01"); hpp1->Print("base"); //divideBinWidth(hpp1); //hpp1->Scale(1./3.083e11); //hpp1->Scale(1./4); jetpp2_v2->Project("hpp2","pt","abs(eta)<2&&jet60&&!jet80&&chMax/pt>0.01"); hpp2->Print("base"); //divideBinWidth(hpp2); //hpp2->Scale(1./3.083e11); //hpp2->Scale(1./4); jetpp2_v2->Project("hpp3","pt","9.25038"*pp3); //9.25038 - ak5 //9.24955 - ak4 //9.24968 - ak3 hpp3->Print("base"); //divideBinWidth(hpp3); //hpp3->Scale(1./3.083e11); //hpp3->Scale(1./4); //scale the PbPb histograms before adding them //we have to scale them according to the lumi of the Jet80 file. // HLT file | Lumi // HLT_80 | 150 mub-1 // HLT_65 | 12.1 mub-1 // HLT_55 | 0.38 mub-1 // // therefore scale for HLT_55 = 150/0.38 = 394.73684 // scale for HLT_65 = 150/12.1 = 12.3967 //hpbpb2->Scale(12.3867); //hpbpb3->Scale(394.7368); //add the histograms /* hpbpbComb->Add(hpbpb1,1); hpbpbComb->Add(hpbpb2,1); hpbpbComb->Add(hpbpb3,1); hpbpbComb->Print("base"); */ hppComb->Add(hpp1,1); hppComb->Add(hpp2,1); hppComb->Add(hpp3,1); hppComb->Print("base"); /* TCanvas *c1 = new TCanvas("c1","",800,600); c1->SetLogy(); hpbpbComb->SetMarkerStyle(29); //hpbpbComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hpbpbComb->SetYTitle("counts"); hpbpbComb->SetXTitle("Jet p_{T} GeV/c"); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]*pow(x+[1],[2])"); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Fit("fPowerLaw","","",30,300); hpbpbComb->Draw(); hpbpb3->SetMarkerStyle(24); hpbpb3->SetMarkerColor(kRed); hpbpb3->Draw("same"); hpbpb2->SetMarkerStyle(25); hpbpb2->SetMarkerColor(kBlue); hpbpb2->Draw("same"); hpbpb1->SetMarkerStyle(26); hpbpb1->SetMarkerColor(kGreen); hpbpb1->Draw("same"); TLegend *title = myLegend(0.54,0.65,0.85,0.9); title->AddEntry(hpbpbComb,"PbPb Merged","pl"); title->AddEntry(hpbpb3,"w_{3} * (HLT_55 && !HLT_65 && !HLT_80)","pl"); title->AddEntry(hpbpb2,"HLT_65 && !HLT_80","pl"); title->AddEntry(hpbpb1,"HLT_80","pl"); title->SetTextSize(0.03); title->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c1->SaveAs("pbpb_2013_pt_combined.gif","RECREATE"); */ //plot the statistical uncertainty here //statistical error/meanvalue as a function of pt for the combined spectra. /* TCanvas *c2 = new TCanvas("c2","",800,600); //TH1F* hPbPb_Uncert = (TH1F*)hpbpbComb->Clone("hPbPb_Uncert"); TH1F* hPbPb_Uncert = new TH1F("hPbPb_Uncert","",30,0,300); for(int i = 1;i<=hpbpbComb->GetNbinsX();i++){ double val = hpbpbComb->GetBinContent(i); double valErr = hpbpbComb->GetBinError(i); double uncert = (double)valErr/val; cout<<"uncert = "<<uncert<<endl; hPbPb_Uncert->SetBinContent(i,uncert); hPbPb_Uncert->SetBinError(i,0); } hPbPb_Uncert->SetYTitle("uncertainty"); hPbPb_Uncert->SetXTitle("p_{T} GeV/c"); hPbPb_Uncert->Draw(); drawText("PbPb 2011, 55,65 scaled",0.3,0.65,20); drawText("Anti-k_{T} PU PF Jets R = 0.3, |#eta|<2, |vz|<15",0.3,0.56,20); c2->SaveAs("pbpb_2013_hlt_merge_scaled_uncert.gif","RECREATE"); */ TCanvas *c2 = new TCanvas("c2","",800,600); c2->SetLogy(); TH1F* hPPComb = (TH1F*)hppComb->Clone("hPPComb"); //TH1F* hPPComb_bins = rebin_yaxian(hppComb,"hPPComb_bins"); hPPComb->Scale(1./3.083e11); hPPComb->Print("base"); hPPComb->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}"); hPPComb->SetXTitle("Jet p_{T} GeV/c"); //hPPComb_bins->Scale(1./3.083e11); //hPPComb_bins->Print("base"); //hPPComb_bins->Scale(1./4); //divideBinWidth(hPPComb_bins); hPPComb->Scale(1./4); divideBinWidth(hPPComb); TF1 *fPowerLaw = new TF1("fPowerLaw","[0]/pow(x,[1])"); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->Fit("fPowerLaw","","",25,500); hPPComb->SetMarkerColor(kBlue); hPPComb->SetMarkerStyle(26); hPPComb->SetTitle("PP2013 ak3PF"); hPPComb->Draw(); //hPPComb_bins->SetMarkerColor(kRed); //hPPComb_bins->SetMarkerStyle(23); //hPPComb_bins->Draw("same"); c2->SaveAs("pp_2013_ak3_pt_evt_frac_merged.gif","RECREATE"); TCanvas *c5 = new TCanvas("c5","",800,600); TH1F* hppFunc = (TH1F*)functionHist(fPowerLaw,hppComb,"Fit Function p_{T} spectra PP 2013 merged"); TH1F* hPPRatio = (TH1F*)hppComb->Clone("hPPRatio"); hPPRatio->Divide(hppFunc); hPPRatio->SetTitle("Spectra to Fit Ratio"); hPPRatio->SetXTitle("Jet p_{T} GeV/c"); hPPRatio->SetYTitle("Measured data/Fit"); hPPRatio->SetMarkerStyle(8); hPPRatio->SetMarkerColor(4); hPPRatio->Draw(); c5->SaveAs("pp_2013_merged_spectra_fit_comp.gif","RECREATE"); TFile *fpbpbunfo = TFile::Open("result-2013-akPu3PF-cent-6-isFineBin-0/pbpb_pp_merged_chmx_pt_Unfo_2013_akPu3PF_cent_6_isFineBin_0.root"); TH1F* hppUnfo = (TH1F*)fpbpbunfo->Get("Unfolded_cent6"); TH1F* hPPGen = (TH1F*)fpbpbunfo->Get("hGen_cent6"); hppUnfo->Print("base"); hPPGen->Print("base"); hPPGen->Scale(1./4); divideBinWidth(hPPGen); hppUnfo->Scale(1./3.083e11); hppUnfo->Scale(1./4); divideBinWidth(hppUnfo); hppUnfo->Divide(hPPGen); TCanvas *c6 = new TCanvas("c6","",800,600); hppUnfo->SetMarkerStyle(21); hppUnfo->SetMarkerColor(kRed); hPPGen->SetMarkerStyle(21); hPPGen->SetMarkerColor(kBlue); hppUnfo->Draw(); // hPPGen->Draw("same"); c6->SaveAs("pp_2760GeV_unfold_vs_mc.gif","RECREATE"); /* TCanvas *c7 = new TCanvas("c7","",800,600); c7->SetLogy(); hPPComb->Draw(); hPPComb->SetYTitle(""); hPPComb->SetXTitle("p_{T} GeV/c"); //hppComb->SetTitle("PP 2013 2.76 TeV ak4PF measured vs unfolded"); hPPComb->SetMarkerStyle(23); hPPComb->SetMarkerColor(kBlue); //hppUnfo->SetAxisRange(10,500,"X"); //hppUnfo->SetMarkerStyle(24); //hppUnfo->SetMarkerColor(kRed); //hppUnfo->Draw("same"); TLegend *title5 = myLegend(0.54,0.65,0.85,0.9); title5->AddEntry(hppComb,"Measured","pl"); title5->AddEntry(hppUnfo,"Bayesian iter = 4","pl"); title5->SetTextSize(0.06); title5->Draw(); gStyle->SetOptStat(0); c7->SaveAs("PP2013_measured_vs_unfolded.gif","RECREATE"); //TCanvas */ //Create output file and save them. TFile f("merge_pp_ak3_HLT_V2.root","RECREATE"); //hpbpb1->Write(); //hpbpb2->Write(); //hpbpb3->Write(); //hPPComb_bins->Write(); hpp1->Write(); hpp2->Write(); hpp3->Write(); //hpbpbComb->Write(); hppComb->Write(); //hPPComb->Write(); //hPbPb_Uncert->Write(); hPPComb->Write(); hPPGen->Write(); f.Close(); }
void plot_figure(TString fn,TPad *thePad,bool saxis=false,float ymin=-2.0,float ymax=1.0,bool with_d=false) { //cout<<"wit"<<with_d<<endl; gStyle->SetOptFit(); gStyle->SetPadTickY(1); gStyle->SetLineStyleString(11,"40 20"); float xmin=0,xmax=2; thePad->cd(); //thePad->SetGrid(); /***************************************************** Colors *****************************************************/ int HRMcol=kRed+2; int RNAcol=kMagenta; int QGScol=kGreen+1; float kb2b=1000; Double_t x,y; /***************************************************** Format the pad *****************************************************/ thePad->SetTopMargin(0.15); TH1F *hr = thePad->DrawFrame(xmin,ymin,xmax,ymax); hr->SetXTitle("Q (GeV)"); hr->SetYTitle("t_{20}"); /*hr->GetYaxis()->SetTitleOffset(1.5); hr->GetYaxis()->SetTitleSize(.06); hr->GetYaxis()->SetTitleFont(42); hr->GetYaxis()->CenterTitle(); hr->GetXaxis()->SetTitleSize(.06); hr->GetXaxis()->SetTitleFont(42); *//***************************************************** Draw legend *****************************************************/ TLegend *dummylegend=new TLegend(); TLegend *legend=new TLegend(0.59,0.17,0.94,0.55); legend->SetMargin(0.2); legend->SetTextFont(72); legend->SetTextSize(0.035); legend->SetFillStyle(0); legend->SetBorderSize(0); legend->Draw(); TLegend *thlegend=new TLegend(0.23,0.64,0.57,0.84); thlegend->SetMargin(0.2); thlegend->SetTextFont(72); thlegend->SetTextSize(0.035); thlegend->SetFillStyle(0); thlegend->SetBorderSize(0); thlegend->Draw(); thePad->SetLeftMargin(0.19); /***************************************************** Draw top axis *****************************************************/ float titlex1=0.47, titley1=0.85,titlex2=0.56,titley2=0.95; if (saxis) { titley1=0.72;titley2=0.82; TGaxis *axispp = new TGaxis(thePad->GetUxmin(),thePad->GetUymax()*1, thePad->GetUxmax(), thePad->GetUymax()*1, xmin*0.1973, xmax*0.1973,510,"-R"); axispp->SetTitle("Q (GeV)"); axispp->SetLabelFont(42); axispp->SetLabelSize(0.04); axispp->SetTitleFont(42); axispp->SetTitleSize(.055); axispp->Draw(); } /***************************************************** Make Title *****************************************************/ //TPaveLabel *label = new TPaveLabel(titlex1,titley1,titlex2,titley2,"^{3}He(#gamma,pp)n","NDC"); //label->SetTextSize(0.7); //label->SetFillStyle(0); //label->SetTextFont(42); //label->SetBorderSize(0); //label->Draw(); //TPaveLabel *label = new TPaveLabel(titlex1,titley1-0.06,titlex2,titley2-0.06,"90#circc.m.","NDC"); //label->SetTextSize(0.5); //label->SetFillStyle(0); //label->SetTextFont(42); //label->SetBorderSize(0); //label->Draw(); /*-------------------------------------------------------------------------------------- Constants? ---------------------------------------------------------------------------------------*/ Double_t xmd = 1.875613; Double_t xmdsq = xmd*xmd; Double_t q0sq = 1.15; Double_t degr = 0.01745329252; Double_t xhbarc = 0.1973; /*-------------------------------------------------------------------------------------- Plot IMII modelfor t20 ---------------------------------------------------------------------------------------*/ const Int_t npt = 94; //Double_t x, y; Double_t qfm[npt]; Double_t qsqpt[npt] = {0.0003893797, 0.003893797, 0.03893797, 0.05840695, 0.07787593, 0.09734491, 0.1168139, 0.1362829, 0.1557519, 0.1752208, 0.1946898, 0.2530968, 0.3115037, 0.3893797, 0.4672556, 0.5451315, 0.6230075, 0.7008834, 0.7787593, 0.8566352, 0.9345112, 1.012387, 1.090263, 1.168139, 1.246015, 1.323891, 1.401767, 1.479643, 1.557519, 1.596457, 1.635395, 1.674333, 1.71327, 1.752208, 1.810615, 1.830084, 1.869022, 1.90796, 1.946898, 1.985836, 2.024774, 2.063712, 2.10265, 2.141588, 2.180526, 2.219464, 2.258402, 2.29734, 2.336278, 2.375216, 2.414154, 2.453092, 2.49203, 2.530968, 2.569906, 2.608844, 2.647782, 2.68672, 2.725658, 2.803534, 2.881409, 2.959285, 3.037161, 3.115037, 3.309727, 3.504417, 3.699107, 3.893797, 4.088486, 4.283176, 4.477866, 4.672556, 4.867246, 5.061936, 5.256625, 5.451315, 5.646005, 5.840695, 6.035385, 6.230075, 6.424764, 6.619454, 6.716799, 6.814144, 6.911489, 7.008834, 7.106179, 7.203524, 7.300869, 7.398214, 7.495558, 7.592903, 7.690248, 7.787593}; Double_t t20theory[npt] = {-0.001309568, -0.0131055, -0.1318868, -0.1984704, -0.2654408, -0.3327329, -0.4002368, -0.4677915, -0.5351828, -0.6021447, -0.668362, -0.8587877, -1.027779, -1.198694, -1.286326, -1.282388, -1.197382, -1.054978, -0.8820486, -0.7009335, -0.5265257, -0.3668914, -0.2252485, -0.1019077, 0.004321276, 0.09524616, 0.1728195, 0.238883, 0.2950801, 0.3199333, 0.3428342, 0.3639258, 0.3833423, 0.4012027, 0.4253075, 0.432676, 0.4464807, 0.4591073, 0.4706305, 0.4811208, 0.4906344, 0.4992296, 0.506956, 0.5138575, 0.5199757, 0.5253475, 0.5300049, 0.5339787, 0.5372949, 0.539977, 0.5420477, 0.5435232, 0.5444235, 0.5447623, 0.5445543, 0.5438103, 0.5425456, 0.540766, 0.5384844, 0.5324458, 0.5245013, 0.514713, 0.5031468, 0.4898722, 0.4497016, 0.4006593, 0.3444063, 0.2827923, 0.2178549, 0.1514989, 0.08547981, 0.02124835, -0.04018853, -0.09806195, -0.1520174, -0.2019219, -0.2477681, -0.2898, -0.3282607, -0.3633281, -0.3951718, -0.4241511, -0.4375907, -0.4502916, -0.4622216, -0.473322, -0.4835232, -0.4927239, -0.500801, -0.5076282, -0.513053, -0.516797, -0.5184837, -0.5176145}; //FILE *fp = fopen("im2.dat","r"); for (Int_t i=0;i<npt;i++) { // Int_t ncols = fscanf(fp,"%f, %f",&x, &y); // qsqpt[i] = x; // t20theory[i] = y; qfm[i] = qsqpt[i]**(0.5)/xhbarc; // printf(" line %d read: %f %f \n",i,qsqpt[i],t20theory[i]); } //fclose(fp); //TGraph* gQGS=new TGraph("log170_89.dat","%lg %lg"); gQGS = new TGraph(npt,qsqpt,t20theory); gQGS->SetLineColor(kMagenta); gQGS->SetMarkerStyle(20); gQGS->SetMarkerSize(1.3); gQGS->SetLineStyle(11); gQGS->SetLineWidth(2); gQGS->Draw("l"); thlegend->AddEntry(gQGS,"IMII","L"); /*-------------------------------------------------------------------------------------- Plot IMII+ME modelfor t20 ---------------------------------------------------------------------------------------*/ Double_t t20theoryme[npt] = {-0.001325945, -0.01328168, -0.1349228, -0.2041014, -0.2743705, -0.3456319, -0.4177289, -0.4904376, -0.5634585, -0.6364107, -0.7088243, -0.9168859, -1.095754, -1.251422, -1.277469, -1.170903, -0.9677308, -0.7200701, -0.4713423, -0.2466468, -0.05555869, 0.101535, 0.2283672, 0.3298602, 0.4107891, 0.4752683, 0.5266488, 0.567598, 0.6002075, 0.6139116, 0.6261154, 0.6369641, 0.6465931, 0.6551208, 0.6660647, 0.6692667, 0.6750632, 0.6801088, 0.6844693, 0.6882072, 0.6913724, 0.694014, 0.6961743, 0.6978924, 0.6992062, 0.7001432, 0.7007343, 0.701005, 0.7009771, 0.7006715, 0.7001097, 0.6993112, 0.6982906, 0.6970643, 0.6956426, 0.6940377, 0.6922587, 0.6903158, 0.6882191, 0.6836015, 0.6784688, 0.6728624, 0.6668122, 0.6603509, 0.6425963, 0.622676, 0.6008623, 0.5773537, 0.5521636, 0.5259722, 0.4991099, 0.4706432, 0.4410795, 0.4127616, 0.3872456, 0.3640124, 0.3422358, 0.3246932, 0.3143134, 0.3116054, 0.3142227, 0.3184956, 0.3200235, 0.3212056, 0.3227668, 0.3250734, 0.3281051, 0.3321319, 0.3372873, 0.3437867, 0.351448, 0.3600231, 0.3689893, 0.3779735}; TGraph* gRNA=new TGraph(npt,qsqpt,t20theoryme); gRNA->SetLineColor(kRed); gRNA->SetMarkerStyle(1); gRNA->SetMarkerSize(1.3); gRNA->SetLineStyle(11); gRNA->SetLineWidth(3); gRNA->Draw("l"); thlegend->AddEntry(gRNA,"IM+E II","L"); /*-------------------------------------------------------------------------------------- Dan Phillips no rpg(f/g=0) ---------------------------------------------------------------------------------------*/ const Int_t nph = 66; Double_t qph[nph] = { 0.01, 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 47.5, 50.0, 52.5, 55.0, 57.5, 60.0, 62.5, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0}; for (Int_t i=0;i<nph;i++) {qph[i] = qph[i]*xhbarc**2;} Double_t tphrpg0[nph] = {-0.00139028, -0.0347797, -0.0705278, -0.106823, -0.143214, -0.215941, -0.28903, -0.36176, -0.437352, -0.594782, -0.753442, -0.905365, -1.04209, -1.14824, -1.2301, -1.27076, -1.26585, -1.21681, -1.13043, -1.01648, -0.885684, -0.7701, -0.630809, -0.495011, -0.366781, -0.248492, -0.141153, -0.0449377, 0.0407569, 0.116675, 0.183835, 0.230211, 0.284553, 0.332797, 0.375647, 0.41358, 0.447136, 0.476061, 0.502346, 0.525668, 0.546396, 0.561598, 0.57851, 0.593626, 0.607141, 0.619222, 0.630017, 0.638943, 0.647659, 0.655433, 0.662379, 0.675447, 0.686163, 0.693653, 0.698255, 0.70103, 0.701985, 0.701414, 0.699577, 0.696913, 0.68897, 0.68092, 0.673572, 0.668027, 0.665207, 0.664439}; TGraph* gph=new TGraph(nph,qph,tphrpg0); gph->SetLineColor(9); gph->SetMarkerStyle(1); gph->SetMarkerSize(1.3); gph->SetLineStyle(1); gph->SetLineWidth(3); gph->Draw("l"); thlegend->AddEntry(gph,"#rho#pi#gamma f/g=0","L"); Double_t tphrpg3[nph] = {-0.00139212, -0.0348353, -0.0706589, -0.10705, -0.143559, -0.216597, -0.290087, -0.363321, -0.439532, -0.598654, -0.759312, -0.913351, -1.0519, -1.15918, -1.24066, -1.27901, -1.2698, -1.21493, -1.12197, -1.00156, -0.865071, -0.744981, -0.60214, -0.464095, -0.334789, -0.216384, -0.109662, -0.0145868, 0.069612, 0.143819, 0.20915, 0.254731, 0.307099, 0.353368, 0.394259, 0.43028, 0.461982, 0.489554, 0.51413, 0.535803, 0.554941, 0.568991, 0.584356, 0.59797, 0.610026, 0.620686, 0.630093, 0.63772, 0.645084, 0.651525, 0.657156, 0.666024, 0.673624, 0.678127, 0.679481, 0.67949, 0.677837, 0.674823, 0.670722, 0.662356, 0.650039, 0.638996, 0.628928, 0.620671, 0.614933, 0.610454}; //TGraph* gph3=new TGraph(nph,qph,tphrpg3); //gph3->SetLineColor(39); //gph3->SetMarkerStyle(1); //gph3->SetMarkerSize(1.3); //gph3->SetLineStyle(2); //gph3->SetLineWidth(2); //TPaveLabel * Label = new TPaveLabel(0.20,0.66,0.48,0.71,"Propagator f/g=3","NDC"); //Label->SetTextSize(0.6); //Label->SetLineColor(kWhite); //Label->SetFillColor(kWhite); //Label->SetTextColor(39); //Label->SetBorderSize(0); //Label->Draw(); //gph3->Draw("l"); Double_t tphrpg6[nph] = {-0.00139403, -0.0348929, -0.0707944, -0.107286, -0.143917, -0.217276, -0.29118, -0.364936, -0.441787, -0.602659, -0.765378, -0.921581, -1.06195, -1.17027, -1.25116, -1.28686, -1.27292, -1.21183, -1.11202, -0.985056, -0.84299, -0.718589, -0.572616, -0.432822, -0.302967, -0.184961, -0.0793357, 0.0141671, 0.0964853, 0.168642, 0.231842, 0.276257, 0.326398, 0.370465, 0.409197, 0.443123, 0.472809, 0.498773, 0.52149, 0.541377, 0.558796, 0.571442, 0.58515, 0.597161, 0.607665, 0.616818, 0.624764, 0.630973, 0.636932, 0.642002, 0.646291, 0.650319, 0.654857, 0.656509, 0.654827, 0.652371, 0.648479, 0.643459, 0.637587, 0.622962, 0.607813, 0.595048, 0.583592, 0.574033, 0.566854, 0.560502}; TGraph* gph6=new TGraph(nph,qph,tphrpg6); gph6->SetLineColor(49); gph6->SetMarkerStyle(1); gph6->SetMarkerSize(1.3); gph6->SetLineStyle(1); gph6->SetLineWidth(2); gph6->Draw("l"); thlegend->AddEntry(gph6,"#rho#pi#gamma f/g=6.1","L"); /*-------------------------------------------------------------------------------------- put line at -root(2) ---------------------------------------------------------------------------------------*/ Int_t n = 2; float xfm[2] = {0., 9.}; float yt20[2] = {0., 0.}; TGraph* g0=new TGraph(n,xfm,yt20); g0->SetLineColor(1); g0->SetMarkerStyle(1); g0->SetMarkerSize(1.3); g0->SetLineStyle(1); g0->SetLineWidth(1); g0->Draw("l"); yt20[0] = -1.*2**(0.5); yt20[1] = yt20[0]; xfm[1] = 1.; TGraph* g1=new TGraph(n,xfm,yt20); g1->SetLineColor(1); g1->SetMarkerStyle(1); g1->SetMarkerSize(1.3); g1->SetLineStyle(3); g1->SetLineWidth(1); g1->Draw("l"); /* sanity checks plots11dsdtSet(100,0.040,0.020,0.05,0.000,0.140,kBlack,legend,"E03-101 140 MeV Bins Pn< 100 Mev/c 80 mr X 40 mr"); */ /* PRL */ //plotSet(kBlue,legend,"T_{20}"); //plotSet(kBlue,legend,""); plotSet(kBlue,legend,""); //plots11dsdtSet(kBlue,legend,""); /***************************************************** Add the rest of the legend enteries *****************************************************/ //if(!with_d){ //legend->AddEntry(gQGS,"QGS","l"); //legend->AddEntry(gRNA,"RNA","l"); //legend->AddEntry(gHRM,"HRM","F"); //}; gStyle->SetPaperSize(20,26); //default //TPaveLabel *label = new TPaveLabel(0.5,0.4,0.85,0.5,"Preliminary","NDC"); //label->SetTextColor(kBlue); //label->Draw(); //cout<<with_d<<endl; c->SaveAs(fn+".pdf"); c->SaveAs(fn+".eps"); c->SaveAs(fn+".png"); }
//void plot_Asymptotic(string outputname) //void plot_Asymptotic() TGraphAsymmErrors * plot_Asymptotic(TString dir_path ,TGraphAsymmErrors *grmedian_cls ) //void plot_Asymptotic( TGraphAsymmErrors *grmedian_cls ) { string outputname = "counting"; bool useNewStyle = true; if (useNewStyle) setFPStyle(); // gROOT->LoadMacro("CMS_lumi.C"); TFile *fFREQ[nXm]; TTree *t[nXm]; // int Xmass[nXm]={800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000}; int Xmass[nXm]={800,1000,1200,1400,1600,1800,2000,2500,3000,3500,4000}; //int Xmass[nXm]={800,900,1100,1400,1700,1900}; vector<double> v_mh, v_median, v_68l, v_68h, v_95l, v_95h, v_obs; for(int n=0;n<nXm;n++) { char limitfile[200]; // if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]); if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]); // const string dirLimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/"; TString LimitFile = limitfile; LimitFile = dir_path + LimitFile; // LimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/" + LimitFile; // limitfile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/" + limitfile; // limitfile = dirLimitFile + limitfile; // fFREQ[n] = new TFile(limitfile, "READ"); fFREQ[n] = new TFile( LimitFile , "READ"); cout<<" Read limit file: "<<limitfile<<endl; t[n] = (TTree*)fFREQ[n]->Get("limit"); double mh, limit; float quant; t[n]->SetBranchAddress("mh", &mh); t[n]->SetBranchAddress("limit", &limit); t[n]->SetBranchAddress("quantileExpected", &quant); //int iMH = 0; //while (iMH < n) { for (int i = 0; i < t[n]->GetEntries(); i++) { t[n]->GetEntry(i); cout<<" quant : "<<quant<<" limit : " <<limit<<endl; /// Map: mh --> observed, 95low, 68low, expected, 68hi, 95hi, xsec if (quant > -1.01 && quant < -0.99) { v_obs.push_back(limit); } else if (quant > 0.02 && quant < 0.03) { v_95l.push_back(limit); } else if (quant > 0.15 && quant < 0.17) { v_68l.push_back(limit); } else if (quant > 0.49 && quant < 0.51) { v_median.push_back(limit); v_mh.push_back(mh); } else if (quant > 0.83 && quant < 0.85) { v_68h.push_back(limit); } else if (quant > 0.965 && quant < 0.98) { v_95h.push_back(limit); } else { cout << "Error! Quantile = " << quant << endl; } } // iMH++; // }//end while loop }//file loop // string xsect_file_th = dirXSect + "13TeV_xsec_Zhllbb.txt"; string xsect_file_th = dirXSect + "13TeV_xsec_Zh.txt"; ifstream xsect_file(xsect_file_th.c_str(), ios::in); if (! xsect_file.is_open()) { cout << "Failed to open file with xsections: " << xsect_file_th << endl; } float mH, CS; vector<float> v_mhxs, v_xs, v_toterrh, v_toterrl; while (xsect_file.good()) { xsect_file >> mH >> CS; v_mhxs.push_back(mH); v_xs.push_back(CS);//*BRZZ2l2q (multyply by BRZZ2l2q only if exp rates in cards are for process X->ZZ->2l2q !) //unavailable theory errors for graviton float tot_err_p = 0.0; float tot_err_m = 0.0; v_toterrh.push_back(1.0 + (tot_err_p)); v_toterrl.push_back(1.0 - (tot_err_m)); } cout << "Size of theory xsects vector" << v_mhxs.size() << endl; xsect_file.close(); /////////////////////////// // END THEORY INPUT PART // /////////////////////////// /// Here we multiply the limits in terms of signal strength by the cross-section. /// There are also some hooks to exclude sick mass points. double mass[nXm], obs_lim_cls[nXm]; double medianD[nXm]; double up68err[nXm], down68err[nXm], up95err[nXm], down95err[nXm]; double xs[nXm], xs_uperr[nXm], xs_downerr[nXm]; double xs10[nXm], xs10_uperr[nXm], xs10_downerr[nXm]; int nMassEff = 0; for (int im = 0; im < nXm; im++) { double fl_xs = double(v_xs.at(im)); //*1000.0 double fl_xs10 = 0;//double(v_xs10.at(ind)); //*1000.0 fl_xs = (fl_xs); fl_xs10 = (fl_xs10); mass[nMassEff] = Xmass[im]; /// This is the part where we multiply the limits in terms of signal strength /// by the cross-section, in order to have limits in picobarns. //std::cerr << mass[nMassEff] << ":" << v_obs.at(im) << std::endl; obs_lim_cls[nMassEff] = v_obs.at(im) * fl_xs; medianD[nMassEff] = v_median.at(im) * fl_xs; up68err[nMassEff] = (v_68h.at(im) - v_median.at(im)) * fl_xs; down68err[nMassEff] = (v_median.at(im) - v_68l.at(im)) * fl_xs; //scale factor 100 for making the xsect visible xs[nMassEff] = fl_xs; //*100.0; xs_uperr[nMassEff] = double(v_toterrh.at(im)) * xs[nMassEff] - xs[nMassEff]; xs_downerr[nMassEff] = xs[nMassEff] - double(v_toterrl.at(im)) * xs[nMassEff]; xs10[nMassEff] = fl_xs10; //*100.0; xs10_uperr[nMassEff] = double(v_toterrh.at(im)) * xs10[nMassEff] - xs10[nMassEff]; xs10_downerr[nMassEff] = xs10[nMassEff] - double(v_toterrl.at(im)) * xs10[nMassEff]; up95err[nMassEff] = (v_95h.at(im) - v_median.at(im)) * fl_xs; down95err[nMassEff] = (v_median.at(im) - v_95l.at(im)) * fl_xs; cout<<"fl_xs:"<<fl_xs<<" v_obs"<<v_obs.at(im)<<" obs_lim_cls: "<<obs_lim_cls[nMassEff] <<medianD[nMassEff] <<" mass: "<<mass[nMassEff]<<endl; nMassEff++; }//end loop over im (mass points) /// The TGraphs themselves. //cout<<"Working on TGraph"<<endl; TGraphAsymmErrors *grobslim_cls = new TGraphAsymmErrors(nMassEff, mass, obs_lim_cls); grobslim_cls->SetName("LimitObservedCLs"); // TGraphAsymmErrors *grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD); grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD); grmedian_cls->SetName("LimitExpectedCLs"); TGraphAsymmErrors *gr68_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down68err, up68err); gr68_cls->SetName("Limit68CLs"); TGraphAsymmErrors *gr95_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down95err, up95err); gr95_cls->SetName("Limit95CLs"); // TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff1,mass1,xs,0,0,0,0);//xs_downerr,xs_uperr); TGraph *grthSM=new TGraph(nMassEff,mass,xs);//xs_downerr,xs_uperr); /// For the time being we have to do it like this, given that /// the cards and the limits were made with the old, wrong xsects. // TGraph *grthSM10 = new TGraph(35); // grthSM10->SetPoint(0, 600, 7.1185E-03); // grthSM10->SetPoint(1, 650, 4.1893E-03); // grthSM10->SetPoint(2, 700, 2.5592E-03); // grthSM10->SetPoint(3, 750, 1.6182E-03); // grthSM10->SetPoint(4, 800, 1.0564E-03); // grthSM10->SetPoint(5, 850, 7.0295E-04); // grthSM10->SetPoint(6, 900, 4.7877E-04); // grthSM10->SetPoint(7, 950, 3.3017E-04); // grthSM10->SetPoint(8, 1000, 2.3212E-04); // grthSM10->SetPoint(9, 1050, 1.6574E-04); // grthSM10->SetPoint(10, 1100, 1.1917E-04); // grthSM10->SetPoint(11, 1150, 8.6629E-05); // grthSM10->SetPoint(12, 1200, 6.3987E-05); // grthSM10->SetPoint(13, 1250, 4.7353E-05); // grthSM10->SetPoint(14, 1300, 3.5511E-05); // grthSM10->SetPoint(15, 1350, 2.6631E-05); // grthSM10->SetPoint(16, 1400, 2.0199E-05); // grthSM10->SetPoint(17, 1450, 1.5333E-05); // grthSM10->SetPoint(18, 1500, 1.1758E-05); // grthSM10->SetPoint(19, 1550, 9.0363E-06); // grthSM10->SetPoint(20, 1600, 6.9870E-06); // grthSM10->SetPoint(21, 1650, 5.4316E-06); // grthSM10->SetPoint(22, 1700, 4.2252E-06); // grthSM10->SetPoint(23, 1750, 3.3172E-06); // grthSM10->SetPoint(24, 1800, 2.6083E-06); // grthSM10->SetPoint(25, 1850, 2.0499E-06); // grthSM10->SetPoint(26, 1900, 1.6186E-06); // grthSM10->SetPoint(27, 1950, 1.2799E-06); // grthSM10->SetPoint(28, 2000, 1.0205E-06); // grthSM10->SetPoint(29, 2050, 8.0867E-07); // grthSM10->SetPoint(30, 2100, 6.4555E-07); // grthSM10->SetPoint(31, 2150, 5.1755E-07); // grthSM10->SetPoint(32, 2200, 4.1408E-07); // grthSM10->SetPoint(33, 2250, 3.3170E-07); // grthSM10->SetPoint(34, 2300, 2.6637E-07); // grthSM10->SetPoint(35, 2350, 2.1366E-07); // grthSM10->SetPoint(36, 2400, 1.7285E-07); // grthSM10->SetPoint(37, 2450, 1.3896E-07); // grthSM10->SetPoint(38, 2500, 1.1238E-07); // if (!isZZChannel) { // grthSM10->SetPoint(0, 800, 2.0523E-03); // grthSM10->SetPoint(1, 850, 1.3726E-03); // grthSM10->SetPoint(2, 900, 9.3786E-04); // grthSM10->SetPoint(3, 950, 6.4928E-04); // grthSM10->SetPoint(4, 1000, 4.5618E-04); // grthSM10->SetPoint(5, 1050, 3.2571E-04); // grthSM10->SetPoint(6, 1100, 2.3543E-04); // grthSM10->SetPoint(7, 1150, 1.7157E-04); // grthSM10->SetPoint(8, 1200, 1.2611E-04); // grthSM10->SetPoint(9, 1250, 9.3461E-05); // grthSM10->SetPoint(10, 1300, 6.9899E-05); // grthSM10->SetPoint(11, 1350, 5.2749E-05); // grthSM10->SetPoint(12, 1400, 4.0048E-05); // grthSM10->SetPoint(13, 1450, 3.0363E-05); // grthSM10->SetPoint(14, 1500, 2.3324E-05); // grthSM10->SetPoint(15, 1550, 1.8008E-05); // grthSM10->SetPoint(16, 1600, 1.3876E-05); // grthSM10->SetPoint(17, 1650, 1.0812E-05); // grthSM10->SetPoint(18, 1700, 8.4385E-06); // grthSM10->SetPoint(19, 1750, 6.5972E-06); // grthSM10->SetPoint(20, 1800, 5.1608E-06); // grthSM10->SetPoint(21, 1850, 4.0824E-06); // grthSM10->SetPoint(22, 1900, 3.2292E-06); // grthSM10->SetPoint(23, 1950, 2.5502E-06); // grthSM10->SetPoint(24, 2000, 2.0281E-06); // grthSM10->SetPoint(25, 2050, 1.6179E-06); // grthSM10->SetPoint(26, 2100, 1.2893E-06); // grthSM10->SetPoint(27, 2150, 1.0313E-06); // grthSM10->SetPoint(28, 2200, 8.2293E-07); // grthSM10->SetPoint(29, 2250, 6.6187E-07); // grthSM10->SetPoint(30, 2300, 5.3108E-07); // grthSM10->SetPoint(31, 2350, 4.2755E-07); // grthSM10->SetPoint(32, 2400, 3.4315E-07); // grthSM10->SetPoint(33, 2450, 2.7803E-07); // grthSM10->SetPoint(34, 2500, 2.2432E-07); // } grthSM->SetName("SMXSection"); // TGraphAsymmErrors *grthSM10=new TGraphAsymmErrors(nMassEff1,mass1,xs10,0,0,0,0); TGraph *grthSM10=new TGraph(nMassEff,mass,xs10); // TGraph *grthSM = new TGraph(35); // grthSM->SetPoint(0, 600, 4.4387E-02); // grthSM->SetPoint(1, 650, 2.6088E-02); // grthSM->SetPoint(2, 700, 1.5907E-02); // grthSM->SetPoint(3, 750, 1.0045E-02); // grthSM->SetPoint(4, 800, 6.5582E-03); // grthSM->SetPoint(5, 850, 4.3560E-03); // grthSM->SetPoint(6, 900, 2.9701E-03); // grthSM->SetPoint(7, 950, 2.0553E-03); // grthSM->SetPoint(8, 1000, 1.4410E-03); // grthSM->SetPoint(9, 1050, 1.0283E-03); // grthSM->SetPoint(10, 1100, 7.3979E-04); // grthSM->SetPoint(11, 1150, 5.4086E-04); // grthSM->SetPoint(12, 1200, 3.9717E-04); // grthSM->SetPoint(13, 1250, 2.9347E-04); // grthSM->SetPoint(14, 1300, 2.1957E-04); // grthSM->SetPoint(15, 1350, 1.6507E-04); // grthSM->SetPoint(16, 1400, 1.2514E-04); // grthSM->SetPoint(17, 1450, 9.5937E-05); // grthSM->SetPoint(18, 1500, 7.3300E-05); // grthSM->SetPoint(19, 1550, 5.6376E-05); // grthSM->SetPoint(20, 1600, 4.3715E-05); // grthSM->SetPoint(21, 1650, 3.3834E-05); // grthSM->SetPoint(22, 1700, 2.6389E-05); // grthSM->SetPoint(23, 1750, 2.0691E-05); // grthSM->SetPoint(24, 1800, 1.6259E-05); // grthSM->SetPoint(25, 1850, 1.2809E-05); // grthSM->SetPoint(26, 1900, 1.0131E-05); // grthSM->SetPoint(27, 1950, 8.0235E-06); // grthSM->SetPoint(28, 2000, 6.3711E-06); // grthSM->SetPoint(29, 2050, 5.0725E-06); // grthSM->SetPoint(30, 2100, 4.0513E-06); // grthSM->SetPoint(31, 2150, 3.2469E-06); // grthSM->SetPoint(32, 2200, 2.6006E-06); // grthSM->SetPoint(33, 2250, 2.0899E-06); // grthSM->SetPoint(34, 2300, 1.6810E-06); // grthSM->SetPoint(35, 2350, 1.3586E-06); // grthSM->SetPoint(36, 2400, 1.0964E-06); // grthSM->SetPoint(37, 2450, 8.8416E-07); // grthSM->SetPoint(38, 2500, 7.1662E-07); // if (!isZZChannel) { // grthSM->SetPoint(0, 800, 1.2713E-02); // grthSM->SetPoint(1, 850, 8.5015E-03); // grthSM->SetPoint(2, 900, 5.8030E-03); // grthSM->SetPoint(3, 950, 4.0261E-03); // grthSM->SetPoint(4, 1000, 2.8289E-03); // grthSM->SetPoint(5, 1050, 2.0214E-03); // grthSM->SetPoint(6, 1100, 1.4580E-03); // grthSM->SetPoint(7, 1150, 1.0625E-03); // grthSM->SetPoint(8, 1200, 7.8079E-04); // grthSM->SetPoint(9, 1250, 5.7987E-04); // grthSM->SetPoint(10, 1300, 4.3448E-04); // grthSM->SetPoint(11, 1350, 3.2719E-04); // grthSM->SetPoint(12, 1400, 2.4778E-04); // grthSM->SetPoint(13, 1450, 1.8896E-04); // grthSM->SetPoint(14, 1500, 1.4543E-04); // grthSM->SetPoint(15, 1550, 1.1200E-04); // grthSM->SetPoint(16, 1600, 8.6492E-05); // grthSM->SetPoint(17, 1650, 6.7405E-05); // grthSM->SetPoint(18, 1700, 5.2283E-05); // grthSM->SetPoint(19, 1750, 4.1121E-05); // grthSM->SetPoint(20, 1800, 3.2378E-05); // grthSM->SetPoint(21, 1850, 2.5507E-05); // grthSM->SetPoint(22, 1900, 2.0215E-05); // grthSM->SetPoint(23, 1950, 1.6020E-05); // grthSM->SetPoint(24, 2000, 1.2714E-05); // grthSM->SetPoint(25, 2050, 1.0133E-05); // grthSM->SetPoint(26, 2100, 8.0785E-06); // grthSM->SetPoint(27, 2150, 6.4583E-06); // grthSM->SetPoint(28, 2200, 5.1774E-06); // grthSM->SetPoint(29, 2250, 4.1620E-06); // grthSM->SetPoint(30, 2300, 3.3440E-06); // grthSM->SetPoint(31, 2350, 2.7018E-06); // grthSM->SetPoint(32, 2400, 2.1753E-06); // grthSM->SetPoint(33, 2450, 1.7626E-06); // grthSM->SetPoint(34, 2500, 1.4225E-06); // } grthSM10->SetName("SMXSection_2nd"); // double fr_left = 590.0, fr_down = 1E-5, fr_right = 2000.0, fr_up = 0.5; // double fr_left = 590.0, fr_down = 5E-5, fr_right = 2000.0, fr_up = 5; double fr_left = 500.0, fr_down = 5E-7, fr_right = 4500.0, fr_up = 5E-1; TCanvas *cMCMC = new TCanvas("c_lim_Asymptotic", "canvas with limits for Asymptotic CLs", 630, 600); cMCMC->cd(); cMCMC->SetGridx(1); cMCMC->SetGridy(1); // draw a frame to define the range TH1F *hr = cMCMC->DrawFrame(fr_left, fr_down, fr_right, fr_up, ""); TString VV = "ZH"; hr->SetXTitle("M_{X} [GeV]"); hr->SetYTitle("#sigma_{95%} [pb]"); // #rightarrow 2l2q gr95_cls->SetFillColor(kYellow); gr95_cls->SetFillStyle(1001);//solid gr95_cls->SetLineStyle(kDashed); gr95_cls->SetLineWidth(3); gr95_cls->GetXaxis()->SetTitle("M_{V'} [GeV]"); gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q gr95_cls->GetXaxis()->SetRangeUser(fr_left, fr_right); // gr95_cls->Draw("3"); gr68_cls->SetFillColor(kGreen); gr68_cls->SetFillStyle(1001);//solid gr68_cls->SetLineStyle(kDashed); gr68_cls->SetLineWidth(3); // gr68_cls->Draw("3same"); grmedian_cls->GetXaxis()->SetTitle("M_{V'} [GeV]"); grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q grmedian_cls->SetMarkerStyle(24);//25=hollow squre grmedian_cls->SetMarkerColor(kBlack); grmedian_cls->SetLineStyle(2); grmedian_cls->SetLineWidth(3); grmedian_cls->SetMinimum(0.0); grmedian_cls->SetMaximum(8.0); grobslim_cls->SetMarkerColor(kBlack); grobslim_cls->SetMarkerStyle(21);//24=hollow circle grobslim_cls->SetMarkerSize(1.0); grobslim_cls->SetLineStyle(1); grobslim_cls->SetLineWidth(3); grthSM->SetLineColor(kRed); grthSM->SetLineWidth(2); grthSM->SetLineStyle(kSolid); grthSM->SetFillColor(kRed); grthSM->SetFillStyle(3344); grthSM10->SetLineColor(kRed); grthSM10->SetLineWidth(2); grthSM10->SetLineStyle(1); grthSM10->SetLineStyle(kDashed); grthSM10->SetFillColor(kRed); grthSM10->SetFillStyle(3344); // grthSM->Draw("L3"); grmedian_cls->Draw("L"); // grobslim_cls->Draw("LP"); /* TFile *fUnMPlus=new TFile("AsymptoticCLs_UnmatchedPlus_TGraph.root","READ"); TGraph *grobs_ump=(TGraph*)fUnMPlus->Get("LimitObservedCLs"); TGraph *grmedian_ump=(TGraph*)fUnMPlus->Get("LimitExpectedCLs"); grobs_ump->SetName("LimitObs_UnmatchedPlus"); grmedian_ump->SetName("LimitExp_UnmatchedPlus"); grobs_ump->SetMarkerColor(kBlue); grobs_ump->SetLineColor(kBlue); grobs_ump->SetMarkerStyle(25); grmedian_ump->SetMarkerColor(kBlue); grmedian_ump->SetLineColor(kBlue); grmedian_ump->SetMarkerStyle(25); grobs_ump->Draw("P"); grmedian_ump->Draw("L"); */ //draw grid on top of limits gStyle->SetOptStat(0); TH1D* postGrid = new TH1D("postGrid", "", 1, fr_left, fr_right); postGrid->GetYaxis()->SetRangeUser(fr_down, fr_up); postGrid->Draw("AXIGSAME"); //more graphics TLegend *leg = new TLegend(.20, .2, .75, .35); // TLegend *leg = new TLegend(.35,.71,.90,.90); leg->SetFillColor(0); leg->SetShadowColor(0); leg->SetTextFont(42); leg->SetTextSize(0.03); // leg->SetBorderMode(0); leg->AddEntry(grmedian_cls, "CL_{S} Expected limit central value", "L"); // leg->AddEntry(grobslim_cls, "Frequentist CL_{S} Observed", "LP"); // leg->AddEntry(gr68_cls, "Frequentist CL_{S} Expected #pm 1#sigma", "LF"); // leg->AddEntry(gr95_cls, "Frequentist CL_{S} Expected #pm 2#sigma", "LF"); // leg->AddEntry(grthSM, "#sigma_{TH}", "L"); // leg->AddEntry(grthSM, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.50", "L"); // #rightarrow 2l2q // leg->AddEntry(grthSM10, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.20", "L"); // #rightarrow 2l2q leg->Draw(); TLatex * latex = new TLatex(); latex->SetNDC(); latex->SetTextSize(0.04); latex->SetTextAlign(31); latex->SetTextAlign(11); // align left // latex->DrawLatex(0.18, 0.96, "CMS preliminary 2012"); // latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 8 TeV", intLumi)); latex->DrawLatex(0.18, 0.96, "CMS preliminary 2015"); latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 13 TeV", intLumi)); // cMCMC->RedrawAxis(""); gPad->RedrawAxis(""); // hr->GetYaxis()->DrawClone(); cMCMC->Update(); char fnam[50]; //string outputname="shape2d"; //string outputname="shape1d"; //string outputname="counting"; sprintf(fnam, "XZHllbb_%s_Asymptotic.root",outputname.data() ); // cMCMC->SaveAs(fnam); //sprintf(fnam, "XZHllbb_%s_Asymptotic.eps", outputname.data()); //cMCMC->SaveAs(fnam); sprintf(fnam, "XZHllbb_%s_Asymptotic.png", outputname.data()); // cMCMC->SaveAs(fnam); //sprintf(fnam, "XZHllbb_%s_Asymptotic.pdf", outputname.data()); //cMCMC->SaveAs(fnam); gPad->SetLogy(); //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.eps", outputname.data()); //cMCMC->SaveAs(fnam); sprintf(fnam, "XZHllbb_%s_Asymptotic_log.png", outputname.data()); // cMCMC->SaveAs(fnam); //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.pdf", outputname.data()); //cMCMC->SaveAs(fnam); cMCMC->Draw(); return grmedian_cls; }//end main
void bichseldX() { if (gClassTable->GetID("StBichsel") < 0) { gSystem->Load("libTable"); gSystem->Load("St_base"); gSystem->Load("StarClassLibrary"); gSystem->Load("StBichsel"); } if (!m_Bichsel) m_Bichsel = Bichsel::Instance(); TCanvas *c1 = new TCanvas("c1"); c1->SetLogx(); c1->SetLogy(); c1->SetGrid(); // TH1F *hr = c1->DrawFrame(2.e-2,1,1.e3,1.e2); // TH1F *hr = c1->DrawFrame(1.e-2,1,1.e3,1.e2); TH1F *hr = c1->DrawFrame(1.e-1,1,1.e2,2.e2); // hr->SetXTitle("Momentum (GeV/c)"); hr->SetTitle("dE/dx predictions"); hr->SetXTitle("#beta #gamma"); hr->SetYTitle("dE/dx (keV/cm)"); hr->Draw(); // Mass Type Length log2(dx) Double_t params[5] = { 1.0, 0., 60., 1., 1e-3}; TLegend *leg = new TLegend(0.4,0.7,0.9,0.9,"");//TLegend(0.79,0.91,0.89,0.89,""); // for (Int_t h = 0; h < 4; h++) { // Masses for (Int_t h = 2; h < 3; h++) { // Masses params[0] = 1.; // Masses[h]; params[1] = h; // for (Int_t f = 0; f < NF; f++) { // Functions Int_t f = 3; for (Int_t dx = 0; dx < Nlog2dx; dx++) { params[3] = log2dx[dx]; Char_t *FunName = Form("%s%s%i",FNames[f],Names[h],(int)log2dx[dx]); // cout << "Make " << FunName << endl; TF1 *func = 0; if (TString(FNames[f]) == "Sirrf") { func = new TF1(FunName,sifunc,1.e-2,1.e3,5); func->SetLineColor(2); } if (TString(FNames[f]) == "Girrf") { func = new TF1(FunName,gfunc,1.e-2,1.e3,5); params[4] = 1.e-3; if (dx == 1) params[4] = 1.e-2; if (dx == 2) params[4] = 1.e-3; if (dx == 3) params[4] = 1.e-4; func->SetLineColor(3); } else {if (TString(FNames[f]) == "Bz") { func = new TF1(FunName,bichselZ,1.e-2,1.e3,5); func->SetLineColor(4); } else {if (TString(FNames[f]) == "B70") { func = new TF1(FunName,bichsel70,1.e-2,1.e3,5); func->SetLineColor(6); } else {if (TString(FNames[f]) == "B60") { func = new TF1(FunName,bichsel60,1.e-2,1.e3,5); func->SetLineColor(7); }}}} if (! func) continue; func->SetParameters(params); func->SetLineColor(dx+1); func->Draw("same"); if ( h == 2) { TString name(FNames[f]); name += ": Bichsel, 30% truncation"; name += Form(" dx = %3.1f cm",TMath::Power(2.,log2dx[dx])); cout << name << endl; leg->AddEntry(func,name.Data(),"L"); } } } leg->Draw(); }
void produceHisto(std::string outputName="", std::string var="0.692-9.240*ecalIso/pt-11.117*hcalIso/pt",double genIsoCut=5.0,bool normalize=false ) { if(outputName=="")outputName = var; vector<string> mixFile; vector<double> mixWeight; vector<TTree*> mixTree; vector<int> mixPtHatLo; vector<int> mixPtHatHi; vector<string> phoFile; vector<double> phoWeight; vector<TTree*> phoTree; vector<int> phoPtHatLo; vector<int> phoPtHatHi; vector<string> jetFile; vector<double> jetWeight; vector<TTree*> jetTree; vector<int> jetPtHatLo; vector<int> jetPtHatHi; double lumi = 1.0; FILE *fTable = fopen("inputFile.txt","r"); int flag=1; int nfile=0; while (flag!=-1){ // first reading input file char filename[100]; flag=fscanf(fTable,"%s",filename); std::string tempFile = filename; bool isPhotonJet = false; if(tempFile.find("PhotonJet") != std::string::npos)isPhotonJet=true; char tmp[1000]; // read in x-section flag=fscanf(fTable,"%s",tmp); double cross=atof(tmp); // read in number of events flag=fscanf(fTable,"%s",tmp); double nevt=atof(tmp); double scale =lumi*cross/nevt; flag=fscanf(fTable,"%s",tmp); int ptHatLo=atof(tmp); flag=fscanf(fTable,"%s",tmp); int ptHatHi=atof(tmp); if (flag!=-1) { cout <<filename<<" "<<cross<<" "<<nevt<< " " << ptHatLo << " " << ptHatHi << endl; if(isPhotonJet) { cout << "filling photon jet" << endl; phoFile.push_back(tempFile); phoWeight.push_back(scale); phoPtHatLo.push_back(ptHatLo); phoPtHatHi.push_back(ptHatHi); } else { cout << "filling dijet" << endl; jetFile.push_back(tempFile); jetWeight.push_back(scale); jetPtHatLo.push_back(ptHatLo); jetPtHatHi.push_back(ptHatHi); } cout << "filling mixture" << endl; mixFile.push_back(tempFile); mixWeight.push_back(scale); mixPtHatLo.push_back(ptHatLo); mixPtHatHi.push_back(ptHatHi); nfile++; } } std::string treeName = "Analysis"; // first photon trees fillTrees(phoFile,phoTree,treeName); const unsigned int nSize_pho = phoFile.size(); if(phoTree.size()!= nSize_pho){cout << "error 1"<< endl; return;} if(phoWeight.size()!= nSize_pho){cout << "error 2"<< endl; return;} if(phoPtHatLo.size()!= nSize_pho){cout << "error 3"<< endl; return;} if(phoPtHatHi.size()!= nSize_pho){cout << "error 4"<< endl; return;} // second fill background trees fillTrees(jetFile,jetTree,treeName); const unsigned int nSize_jet = jetFile.size(); if(jetTree.size()!= nSize_jet){cout << "error 1"<< endl; return;} if(jetWeight.size()!= nSize_jet){cout << "error 2"<< endl; return;} if(jetPtHatLo.size()!= nSize_jet){cout << "error 3"<< endl; return;} if(jetPtHatHi.size()!= nSize_jet){cout << "error 4"<< endl; return;} // last fill mix trees fillTrees(mixFile,mixTree,treeName); const unsigned int nSize_mix = mixFile.size(); if(mixTree.size()!= nSize_mix){cout << "error 1"<< endl; return;} if(mixWeight.size()!= nSize_mix){cout << "error 2"<< endl; return;} if(mixPtHatLo.size()!= nSize_mix){cout << "error 3"<< endl; return;} if(mixPtHatHi.size()!= nSize_mix){cout << "error 4"<< endl; return;} TH1F *hTemplate = new TH1F("hTemplate","",70,-5,2); TH1F* hEcalIsoPho = (TH1F*)hTemplate->Clone(); std::string histoName = outputName + "Pho"; hEcalIsoPho->SetName(histoName.data()); TH1F* hEcalIsoJet = (TH1F*)hTemplate->Clone(); histoName = outputName + "Jet"; hEcalIsoJet->SetName(histoName.data()); TH1F* hEcalIsoMixSig = (TH1F*)hTemplate->Clone(); histoName = outputName + "MixSig"; hEcalIsoMixSig->SetName(histoName.data()); TH1F* hEcalIsoMixBkg = (TH1F*)hTemplate->Clone(); histoName = outputName + "MixBkg"; hEcalIsoMixBkg->SetName(histoName.data()); TH1F* hEcalIsoMixData = (TH1F*)hTemplate->Clone(); histoName = outputName + "MixData"; hEcalIsoMixData->SetName(histoName.data()); cout << "making histograms from photon+jet MC samples" << endl; TCut allCut = basicCut + sigCut; // makePlot(phoTree,phoWeight,Form("%s",var.data()),hardScatterCut,hEcalIsoPho,normalize); makePlot(phoTree,phoWeight,phoPtHatLo,phoPtHatHi,Form("%s",var.data()),allCut,hEcalIsoPho,normalize); cout << "making histograms from dijet MC samples" << endl; allCut = basicCut + decayCut; makePlot(jetTree,jetWeight,jetPtHatLo,jetPtHatHi,Form("%s",var.data()),allCut,hEcalIsoJet,normalize); cout << "making histograms from mixed MC signal samples" << endl; allCut = basicCut + sigCut; makePlot(mixTree,mixWeight,mixPtHatLo,mixPtHatHi,Form("%s",var.data()),allCut,hEcalIsoMixSig,normalize); cout << "making histograms from mixed MC background samples" << endl; allCut = basicCut + bkgCut; makePlot(mixTree,mixWeight,mixPtHatLo,mixPtHatHi,Form("%s",var.data()),allCut,hEcalIsoMixBkg,normalize); hEcalIsoPho->SetMarkerColor(2); hEcalIsoPho->SetLineColor(2); hEcalIsoJet->SetMarkerColor(1); hEcalIsoJet->SetLineColor(1); hEcalIsoMixSig->SetMarkerColor(5); hEcalIsoMixSig->SetLineColor(5); hEcalIsoMixBkg->SetMarkerColor(4); hEcalIsoMixBkg->SetLineColor(4); cout << "hEcalIsoPho->Integral() = " << hEcalIsoPho->Integral() << endl; cout << "hEcalIsoJet->Integral() = " << hEcalIsoJet->Integral() << endl; cout << "hEcalIsoMixSig->Integral() = " << hEcalIsoMixSig->Integral() << endl; cout << "hEcalIsoMixBkg->Integral() = " << hEcalIsoMixBkg->Integral() << endl; hEcalIsoMixData->Reset(); hEcalIsoMixData->Sumw2(); hEcalIsoMixData->Add(hEcalIsoMixSig,hEcalIsoMixBkg,1.0,1.0); cout << "hEcalIsoMixData->Integral() = " << hEcalIsoMixData->Integral() << endl; hEcalIsoPho->SetXTitle(var.data()); hEcalIsoPho->Draw("hist"); hEcalIsoJet->Draw("histesame"); hEcalIsoMixSig->Draw("histesame"); hEcalIsoMixBkg->Draw("histesame"); TLegend* leg = new TLegend(0.5,0.6,0.7,0.9); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetTextSize(0.03); leg->SetBorderSize(0); leg->AddEntry(hEcalIsoPho,"#gamma+jet MC"); leg->AddEntry(hEcalIsoJet,"Dijet MC"); leg->AddEntry(hEcalIsoMixSig,"Mixed MC: signal"); leg->AddEntry(hEcalIsoMixBkg,"Mixed MC: background"); leg->Draw("same"); // dump histogram to a root file std::string histoFile = outputName + "_histo.root"; TFile* outFile = new TFile(histoFile.data(),"recreate"); hEcalIsoPho->Write(); hEcalIsoJet->Write(); hEcalIsoMixSig->Write(); hEcalIsoMixBkg->Write(); hEcalIsoMixData->Write(); outFile->Close(); }
void unfoldPt(int mode=0) { // Matched Tracklets TFile *inf = new TFile("match-10TeV-12.root"); TNtuple *nt = (TNtuple*)inf->FindObjectAny("nt"); // Test sample TFile *infTest = new TFile("./TrackletTree-Run123596.root"); TNtuple *ntTest = (TNtuple*)infTest->FindObjectAny("TrackletTree12"); TFile *pdfFile; if (mode==0) pdfFile = new TFile("pdf.root","recreate"); else pdfFile = new TFile("pdf.root"); double nPtBin=15; double minPt=log(0.05); double maxPt=log(10); double nDphiBin=600; double maxDphi=0.4; char* mycut = Form("abs(eta)<2&&log(pt)>%f&&log(pt)<%f",minPt,maxPt); char* mycut1=Form("abs(eta)<2&&log(pt)>%f&&log(pt)<%f&&abs(eta-eta1)<0.01&&abs(deta)<0.01",minPt,maxPt); TH2F *h; TH1F *hdphi = new TH1F("hdphi","",nDphiBin,0,maxDphi); TH1F *hdphi2; TH1F *hpt; TH1F *hptH = new TH1F("hptH","",nPtBin,minPt,maxPt); TH1F *hptUnfold = new TH1F("hptUnfold","",nPtBin,minPt,maxPt); TH1F *hptMC = new TH1F("hptMC","",nPtBin,minPt,maxPt); TH1F *hptTemp = new TH1F("hptTemp","",nPtBin,minPt,maxPt); // Delta phi as a function of matched genparticle transverse momentum TCanvas *c = new TCanvas("c","",600,600); if (mode == 0) { h = new TH2F("h","",nPtBin,minPt,maxPt,nDphiBin,0,maxDphi); hdphi2 = new TH1F("hdphiMC","",nDphiBin,0,maxDphi); hpt = new TH1F("hpt","",nPtBin,minPt,maxPt); h->SetXTitle("ln(P_{T}) GeV/c"); h->SetYTitle("|#Delta#phi|"); nt->Draw("abs(dphi):log(pt)>>h",mycut1,"col"); // used to generate pdf nt->Draw("abs(dphi)>>hdphiMC",mycut,""); nt->Draw("log(pt)>>hpt",mycut,""); h->Write(); hpt->Write(); hdphi2->Write(); } else { h = (TH2F*) pdfFile->FindObjectAny("h"); hdphi2 = (TH1F*) pdfFile->FindObjectAny("hdphiMC"); hpt = (TH1F*) pdfFile->FindObjectAny("hpt"); } // Delta phi fit TCanvas *c2 = new TCanvas("c2","",600,600); c2->SetLogy(); c2->SetLogx(); // dphi for unfolding and MC truth: ntTest->Draw("abs(dphi)>>hdphi","abs(eta1)<2&&abs(deta)<0.1","",200000); ntTest->Draw("log(pt)>>hptH",mycut,"",200000); histFunction2D *myfun = new histFunction2D(h); TF1 *test = new TF1("histFun",myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); TF1 *test2 = new TF1("histFunMC",myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); for (int i=0;i<nPtBin+1;i++) { test->SetParameter(i,1); } hdphi2->SetXTitle("|#Delta#phi|"); hdphi2->SetYTitle("Arbitrary Normalization"); hdphi2->Fit("histFunMC","M"); hdphi->SetXTitle("|#Delta#phi|"); hdphi->SetYTitle("Arbitrary Normalization"); hdphi->Fit("histFun","M"); hdphi->SetStats(0); hdphi->Draw(); for (int i=0;i<nPtBin+1;i++) { TF1 *testPlot = new TF1(Form("histFun%d",i),myfun,&histFunction2D::evaluate,0,maxDphi,nPtBin+1); testPlot->SetParameter(i,test->GetParameter(i)); testPlot->SetLineColor(i+2); testPlot->Draw("same"); } int total=0,totalMC=0; for (int i=0;i<nPtBin;i++){ if (test->GetParameter(i)==0) continue; hptUnfold->SetBinContent(i+1,fabs(test->GetParameter(i))); hptUnfold->SetBinError(i+1,test->GetParError(i)); hptMC->SetBinContent(i+1,fabs(test2->GetParameter(i))); hptMC->SetBinError(i+1,test2->GetParError(i)); total+=fabs(test->GetParameter(i)); totalMC+=fabs(test2->GetParameter(i)); } hptUnfold->SetEntries(total); hptMC->SetEntries(totalMC); TCanvas *c3 = new TCanvas("c3","",600,600); hpt->Sumw2(); hptH->Sumw2(); //hptMC->Sumw2(); double normMC=0; double norm=0; double normTruth=0; hptUnfold->SetMarkerColor(2); hptUnfold->SetMarkerStyle(4); // hptUnfold->Scale(1./hptUnfold->GetEntries()); TH1F *hptCorrected = (TH1F*)hptUnfold->Clone(); hptCorrected->SetName("hptCorrected"); hptMC->Divide(hpt); hptCorrected->Divide(hptMC); for (int i=0;i<nPtBin;i++){ if (hptMC->GetBinContent(i)<=0.001)hptCorrected->SetBinContent(i,0); } hptCorrected->Scale(1./(hptCorrected->GetSum())); hptCorrected->SetMarkerStyle(20); hpt->Scale(1./hpt->GetEntries()); if (hptH->GetEntries())hptH->Scale(1./hptH->GetEntries()); hptTemp->SetXTitle("ln(P_{T}) GeV/c"); hptTemp->SetYTitle("Arbitrary Normalization"); hptTemp->Draw(); hptH->SetXTitle("ln(P_{T}) GeV/c"); hptH->SetYTitle("Arbitrary Normalization"); hptH->Draw("hist"); hptH->SetLineColor(4); hpt->Draw("hist same "); hptCorrected->Draw("same"); TH1F *hptUnfoldRatio = (TH1F*)hptUnfold->Clone(); hptUnfoldRatio->SetName("hptUnfoldRatio"); hptUnfoldRatio->Scale(1./hptUnfoldRatio->GetSum()); //hptUnfoldRatio->Divide(hptH); TH1F *hptCorrectedRatio = (TH1F*)hptCorrected->Clone(); hptCorrectedRatio->SetName("hptCorrectedRatio"); hptCorrectedRatio->SetMarkerColor(2); //hptCorrectedRatio->Divide(hptH); TCanvas *c4 = new TCanvas("c4","",600,600); TLine *l = new TLine(-2.5,1,2.5,1); hptUnfoldRatio->Draw(); hptMC->Draw("same"); hptCorrectedRatio->Draw("same"); l->Draw("same"); }
void pythia8(Int_t nev = 100, Int_t ndeb = 1) { const char *p8dataenv = gSystem->Getenv("PYTHIA8DATA"); if (!p8dataenv) { const char *p8env = gSystem->Getenv("PYTHIA8"); if (!p8env) { Error("pythia8.C", "Environment variable PYTHIA8 must contain path to pythia directory!"); return; } TString p8d = p8env; p8d += "/xmldoc"; gSystem->Setenv("PYTHIA8DATA", p8d); } const char* path = gSystem->ExpandPathName("$PYTHIA8DATA"); if (gSystem->AccessPathName(path)) { Error("pythia8.C", "Environment variable PYTHIA8DATA must contain path to $PYTHIA8/xmldoc directory !"); return; } // Load libraries #ifndef G__WIN32 // Pythia8 is a static library on Windows if (gSystem->Getenv("PYTHIA8")) { gSystem->Load("$PYTHIA8/lib/libpythia8"); } else { gSystem->Load("libpythia8"); } #endif gSystem->Load("libEG"); gSystem->Load("libEGPythia8"); // Histograms TH1F* etaH = new TH1F("etaH", "Pseudorapidity", 120, -12., 12.); TH1F* ptH = new TH1F("ptH", "pt", 50, 0., 10.); // Array of particles TClonesArray* particles = new TClonesArray("TParticle", 1000); // Create pythia8 object TPythia8* pythia8 = new TPythia8(); // Configure pythia8->ReadString("HardQCD:all = on"); // Initialize pythia8->Initialize(2212 /* p */, 2212 /* p */, 14000. /* TeV */); // Event loop for (Int_t iev = 0; iev < nev; iev++) { pythia8->GenerateEvent(); if (iev < ndeb) pythia8->EventListing(); pythia8->ImportParticles(particles,"All"); Int_t np = particles->GetEntriesFast(); // Particle loop for (Int_t ip = 0; ip < np; ip++) { TParticle* part = (TParticle*) particles->At(ip); Int_t ist = part->GetStatusCode(); // Positive codes are final particles. if (ist <= 0) continue; Int_t pdg = part->GetPdgCode(); Float_t charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge(); if (charge == 0.) continue; Float_t eta = part->Eta(); Float_t pt = part->Pt(); etaH->Fill(eta); if (pt > 0.) ptH->Fill(pt, 1./(2. * pt)); } } pythia8->PrintStatistics(); TCanvas* c1 = new TCanvas("c1","Pythia8 test example",800,800); c1->Divide(1, 2); c1->cd(1); etaH->Scale(5./Float_t(nev)); etaH->Draw(); etaH->SetXTitle("#eta"); etaH->SetYTitle("dN/d#eta"); c1->cd(2); gPad->SetLogy(); ptH->Scale(5./Float_t(nev)); ptH->Draw(); ptH->SetXTitle("p_{t} [GeV/c]"); ptH->SetYTitle("dN/dp_{t}^{2} [GeV/c]^{-2}"); }
void plotHitEnergy(string inputDir, int hittype=1, float radius=0.4) { setNCUStyle(true); string decversion; if(inputDir.find("rfull009")!=std::string::npos)decversion="rfull009"; else if(inputDir.find("rfull012")!=std::string::npos)decversion="rfull012"; TH1F* hecal; TH1F* hhcal; std::string ecalhitname = hittype==1? "EM_BARREL":"EcalBarrelHits"; std::string hcalhitname = hittype==1? "HAD_BARREL":"HcalBarrelHits"; TString energy=gSystem->GetFromPipe(Form("file=%s; test=${file##*/}; test2=${test%%mumu*}; echo \"${test2##*tev}\"",inputDir.data())); cout << "energy = " << energy.Data() << endl; string inputFile = inputDir + "/radius" + Form("%0.1f",radius)+ (hittype==1? "_rawhit.root": "_rawhit_new.root"); cout << "opening " << inputFile.data() << endl; TFile *f = TFile::Open(inputFile.data()); hecal = (TH1F*)f->FindObjectAny("hecalhit_energy"); hecal->SetLineWidth(3); hecal->SetFillStyle(1001); hecal->SetFillColor(4); hecal->SetLineColor(4); hecal->SetXTitle(Form("%s hit energy [GeV]",ecalhitname.data())); hecal->SetYTitle(Form("Number of hits per %.1f GeV",hecal->GetBinWidth(1))); hecal->SetTitleOffset(1.2,"X"); hecal->SetTitleOffset(1.4,"Y"); hhcal = (TH1F*)f->FindObjectAny("hhcalhit_energy"); hhcal->SetLineWidth(3); hhcal->SetFillStyle(1001); hhcal->SetFillColor(2); hhcal->SetLineColor(2); hhcal->SetXTitle(Form("%s hit energy [GeV]",hcalhitname.data())); hhcal->SetYTitle(Form("Number of hits per %.1f GeV",hhcal->GetBinWidth(1))); hhcal->SetTitleOffset(1.2,"X"); hhcal->SetTitleOffset(1.4,"Y"); TLegend* leg = new TLegend(0.444,0.690,0.990,0.903); leg->SetFillColor(0); leg->SetFillStyle(0); TCanvas* c1 = new TCanvas("c1","",500,500); int lastbin=hecal->FindLastBinAbove(0)+20; float xmax=hecal->GetBinLowEdge(lastbin); hecal->GetXaxis()->SetRangeUser(0,xmax); hecal->Draw("hist"); c1->SetLogy(1); leg->SetHeader(decversion.data()); leg->AddEntry(hecal,Form("%s-TeV Z'#rightarrow qq",energy.Data()),"f"); leg->Draw("same"); std::string outputname = decversion + "/" + decversion + "_" + ecalhitname + "hit_energy_" + Form("%s",energy.Data()) + "TeVZp"; c1->Print(Form("%s.pdf",outputname.data())); c1->Print(Form("%s.eps",outputname.data())); leg->Clear(); lastbin=hhcal->FindLastBinAbove(0)+20; xmax=hhcal->GetBinLowEdge(lastbin); hhcal->GetXaxis()->SetRangeUser(0,xmax); hhcal->Draw("hist"); c1->SetLogy(1); leg->SetHeader(decversion.data()); leg->AddEntry(hhcal,Form("%s-TeV Z'#rightarrow qq",energy.Data()),"f"); leg->Draw("same"); outputname = decversion + "/" + decversion + "_" + hcalhitname + "hit_energy_" + Form("%s",energy.Data()) + "TeVZp"; c1->Print(Form("%s.pdf",outputname.data())); c1->Print(Form("%s.eps",outputname.data())); }
/*#include <TSystem.h> // interface to OS #include <TStyle.h> // class to handle ROOT plotting styles#include <TFile.h> // file handle class #include <TTree.h> // class to access ntuples #include <TBenchmark.h> // class to track macro running statistics #include <TH1D.h> // histogram class #include <vector> // STL vector class #include <iostream> // standard I/O #include <iomanip> // functions to format standard I/O #include <fstream> // functions for file I/O #include <string> // C++ string class #include <sstream> // class for parsing strings #include <TRandom3.h> #include <TGaxis.h> #include "Math/LorentzVector.h" // 4-vector class #include "../Utils/MyTools.hh" // various helper functions #include "../Utils/CPlot.hh" // helper class for plots #include "../Utils/MitStyleRemix.hh" // style settings for drawing #include "../Utils/WModels.hh" // definitions of PDFs for fitting #include "../Utils/RecoilCorrector.hh" // class to handle recoil corrections for MET */ void W_MET_Ratio() { TCanvas *c = new TCanvas("c","c",800,800); c->Divide(1,2,0,0); c->cd(1)->SetPad(0,0.3,1.0,1.0); c->cd(1)->SetTopMargin(0.1); c->cd(1)->SetBottomMargin(0.01); c->cd(1)->SetLeftMargin(0.15); c->cd(1)->SetRightMargin(0.07); c->cd(1)->SetTickx(1); c->cd(1)->SetTicky(1); c->cd(2)->SetPad(0,0,1.0,0.3); c->cd(2)->SetTopMargin(0.05); c->cd(2)->SetBottomMargin(0.45); c->cd(2)->SetLeftMargin(0.15); c->cd(2)->SetRightMargin(0.07); c->cd(2)->SetTickx(1); c->cd(2)->SetTicky(1); c->cd(2)->SetGridy(); TLegend * lgc = new TLegend(0.59, 0.67, 0.89, 0.89); lgc->SetTextSize(0.03); lgc->SetBorderSize(0); lgc->SetFillColor(0); // TFile *file = new TFile("../ElectronHighPU/Ele_RD_HighPU_A_Analysis.root"); TFile *file = new TFile("./ElectronHighPU_N/Ele_WToENu_S10_Analysis.root"); ///////////////Original Plot//////////////////////// c->cd(1); lgc->AddEntry(h1_W_Neut_pt1,"UnCorrected"); h1_W_Neut_pt1->SetYTitle("Events"); h1_W_Neut_pt1->SetFillColor(kWhite); h1_W_Neut_pt1->SetMarkerColor(kBlack); h1_W_Neut_pt1->SetMarkerStyle(1); h1_W_Neut_pt1->SetLineWidth(2); h1_W_Neut_pt1->Draw(); lgc->AddEntry(h1_W_Neut_pt_Corr,"Corrected"); h1_W_Neut_pt_Corr->SetLineColor(kRed); h1_W_Neut_pt_Corr->SetFillColor(kWhite); h1_W_Neut_pt_Corr->SetMarkerColor(kRed); h1_W_Neut_pt_Corr->SetMarkerStyle(1); h1_W_Neut_pt_Corr->SetLineWidth(2); h1_W_Neut_pt_Corr->Draw("same"); lgc->Draw(); /////////////////////////////////////////////////////// c->cd(2); TH1F * h1_Ori = (TH1F*)file->Get("h1_W_Neut_pt1"); TH1F * h1_Corr = (TH1F*)file->Get("h1_W_Neut_pt_Corr"); int Nbins = h1_Ori->GetNbinsX(); TH1F * ratio = new TH1F("ratio","", Nbins, h1_Ori->GetXaxis()->GetXmin(), h1_Ori->GetXaxis()->GetXmax()); ratio->Divide(h1_Ori, h1_Corr); ratio->SetXTitle("N_vtx"); ratio->SetMaximum(2); ratio->SetMinimum(0); ratio->SetNdivisions(10,"X"); ratio->SetNdivisions(4,"Y"); ratio->SetLabelSize(0.09,"XY"); ratio->SetTitleSize(0.12,"X"); ratio->SetMarkerStyle(20); ratio->SetMarkerSize(0.7); ratio->SetMarkerColor(kBlue); ratio->Draw("P"); // c->SaveAs("W_MET_Ratio_RD.png"); c->SaveAs("W_MET_Ratio_MC.png"); }
void drawHFPosition(char file[100]="hf.out", int save=0) { setTDRStyle(); std::ifstream theFile(file); static const int NPMAX=20000; int etaIndex[NPMAX], phiIndex[NPMAX], depths[NPMAX], np=0; float radiusT[NPMAX], radiusH[NPMAX], phiH[NPMAX]; double deg=3.1415926/180.; while (theFile) { int ieta, iphi, idep; float etaR, rr, phideg; theFile >> ieta >> iphi >> idep >> etaR >> rr >> phideg; if (np < NPMAX) { etaIndex[np] = ieta; phiIndex[np] = iphi; depths[np] = idep; radiusT[np] = etaR; radiusH[np] = rr; if (phideg < 0) phideg += 360; int iphi = (int)(phideg/20); float phi = (phideg - iphi*20.0); if (phi > 10) phi -= 20; phiH[np] = phi*deg; np++; } } std::cout << np << " points found\n"; // for (int i=0; i<np; i++) std::cout << std::setw(4) << i << " " << std::setw(3) << etaIndex[i] << " " << std::setw(3) << phiIndex[i] << " " << depths[i] << " " << std::setw(6) << radiusT[i] << " " << std::setw(6) << radiusH[i] << " " << std::setw(6) << phiH[i] << "\n"; int symbol[14] = {20,21,22,23,24,25,26,27,28,29,30,3,5,2}; int colr[3] = {2,4,1}; TGraph *gr[3][14]; float x1[NPMAX], y1[NPMAX], x2[NPMAX], y2[NPMAX], x3[NPMAX], y3[NPMAX]; int np1, np2, np3; for (int i=0; i<13; i++) { np1 = np2 = np3 = 0; for (int j=0; j<np; j++) { if (etaIndex[j] == (i+29)) { int k = 2; if (depths[j] == 3) k = 0; else if (depths[j] == 4) k = 1; if (k == 0) { x1[np1] = radiusH[j]*cos(phiH[j]); y1[np1] = radiusH[j]*sin(phiH[j]); np1++; // if (np1 == 1) std::cout << i << " 0 " <<x1[0] << " " <<y1[0] << "\n"; } else if (k==1) { x2[np2] = radiusH[j]*cos(phiH[j]); y2[np2] = radiusH[j]*sin(phiH[j]); np2++; // if (np2 == 1) std::cout << i << " 1 " <<x2[0] << " " <<y2[0] << "\n"; } else { x3[np3] = radiusH[j]*cos(phiH[j]); y3[np3] = radiusH[j]*sin(phiH[j]); np3++; } } } // std::cout << "i " << i << " " <<np1 << " " <<np2 << " " <<np3 <<"\n"; if (np1 > 0) { gr[0][i] = new TGraph(np1,x1,y1); gr[0][i]->SetTitle(""); gr[0][i]->SetMarkerStyle(symbol[i]); gr[0][i]->SetMarkerColor(colr[0]); } else gr[0][i] = 0; if (np2 > 0) { gr[1][i] = new TGraph(np2,x2,y2); gr[1][i]->SetTitle(""); gr[1][i]->SetMarkerStyle(symbol[i]); gr[1][i]->SetMarkerColor(colr[1]); } else gr[1][i] = 0; if (np3 > 0) { gr[2][i] = new TGraph(np3,x3,y3); gr[2][i]->SetTitle(""); gr[2][i]->SetMarkerStyle(symbol[i]); gr[2][i]->SetMarkerColor(colr[2]); } else gr[2][i] = 0; } np1 = np2 = np3 = 0; for (int j=0; j<np; j++) { if (etaIndex[j] < 29 || etaIndex[j] > 41) { int k = 2; if (depths[j] == 3) k = 0; else if (depths[j] == 4) k = 1; if (k == 0) { x1[np1] = radiusH[j]*cos(phiH[j]); y1[np1] = radiusH[j]*sin(phiH[j]); np1++; if (np1 == 1) std::cout << i << " 0 " <<x1[0] << " " <<y1[0] << "\n"; } else if (k==1) { x2[np2] = radiusH[j]*cos(phiH[j]); y2[np2] = radiusH[j]*sin(phiH[j]); np2++; if (np2 == 1) std::cout << i << " 1 " <<x2[0] << " " <<y2[0] << "\n"; } else { x3[np3] = radiusH[j]*cos(phiH[j]); y3[np3] = radiusH[j]*sin(phiH[j]); np3++; } } } // std::cout << "i " << i << " " <<np1 << " " <<np2 << " " <<np3 <<"\n"; if (np1 > 0) { gr[0][13] = new TGraph(np1,x1,y1); gr[0][13]->SetTitle(""); gr[0][13]->SetMarkerStyle(symbol[13]); gr[0][13]->SetMarkerColor(colr[0]); } else gr[0][13] = 0; if (np2 > 0) { gr[1][13] = new TGraph(np2,x2,y2); gr[1][13]->SetTitle(""); gr[1][13]->SetMarkerStyle(symbol[13]); gr[1][13]->SetMarkerColor(colr[1]); } else gr[1][13] = 0; if (np3 > 0) { gr[2][13] = new TGraph(np3,x3,y3); gr[2][13]->SetTitle(""); gr[2][13]->SetMarkerStyle(symbol[13]); gr[2][13]->SetMarkerColor(colr[2]); } else gr[2][13] = 0; TCanvas *c0 = new TCanvas("c0","PMT Hits",800,600); TH1F *vFrame = c0->DrawFrame(1000.0,-250.0,1500.0,250.0); vFrame->SetXTitle("x (mm)"); vFrame->SetYTitle("y (mm)"); for (int i=0; i<=13; i++) { for (int j=0; j<3; j++) { if (gr[j][i] != 0) { gr[j][i]->Draw("p"); gr[j][i]->SetLineColor(colr[j]); gr[j][i]->SetLineWidth(2); // std::cout << "Next " << i << " " << j << "\n"; } } } TLegend *leg1 = new TLegend(0.75,0.55,0.90,0.90); char list[40]; for (i=0; i<= 13; i++) { if (i < 13) sprintf (list, "#eta = %d", i+29); else sprintf (list, "Unknown #eta"); if (gr[0][i] != 0) leg1->AddEntry(gr[0][i], list, "P"); else if (gr[1][i] != 0) leg1->AddEntry(gr[1][i], list, "P"); } for (i=0; i<2; i++) { if (i == 0) sprintf (list, "Long Fibre"); else sprintf (list, "Short Fibre"); if (gr[i][0] != 0) leg1->AddEntry(gr[i][0], list, "L"); else if (gr[i][1] != 0) leg1->AddEntry(gr[i][1], list, "L"); else if (gr[i][2] != 0) leg1->AddEntry(gr[i][2], list, "L"); } leg1->SetFillColor(0); leg1->SetTextSize(0.03); leg1->SetBorderSize(1); leg1->Draw(); if (save != 0) { if (save > 0) c0->SaveAs("PMTHits.eps"); else c0->SaveAs("PMTHits.gif"); } }