//================================================ void DeltaZVsPt(const Int_t save = 0) { THnSparseF *hn = (THnSparseF*)f->Get(Form("mhTrkDzDy_%s",trigName[kTrigType])); TH2F *hTrkDzVsPt = (TH2F*)hn->Projection(1,0); c = draw2D(hTrkDzVsPt,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType])); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_vs_pt_%s.pdf",run_type,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_vs_pt_%s.png",run_type,trigName[kTrigType])); } Double_t pt_cut = 1; hTrkDzVsPt->GetXaxis()->SetRangeUser(pt_cut+0.1,100); TH1F *hMthDz = (TH1F*)hTrkDzVsPt->ProjectionY(Form("hTrkDzVsPt_%s_proj",trigName[kTrigType])); hMthDz->SetTitle(Form("%s: #Deltaz of matched track-hit pairs (p_{T}>%1.1f GeV/c);#Deltaz (cm)",trigName[kTrigType],pt_cut)); TH1F *hClone = (TH1F*)hMthDz->Clone(Form("%s_clone",hMthDz->GetName())); c = draw1D(hClone,"",kFALSE,kFALSE); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_%s.pdf",run_type,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/DeltaZ_%s.png",run_type,trigName[kTrigType])); } Double_t range = 50; TF1 *func = new TF1("func","gaus(0)+gaus(3)",-1*range,range); func->SetParameters(10000,0,10,1000,0,40); c = FitDeltaZ(hMthDz,func,range,20.); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%s.pdf",run_type,pt_cut,trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%s.png",run_type,pt_cut,trigName[kTrigType])); } // pt dependence Double_t pt_cuts[5] = {1,2,3,5,20}; for(Int_t i=0; i<4; i++) { hTrkDzVsPt->GetXaxis()->SetRangeUser(pt_cuts[i]+0.1,pt_cuts[i+1]-0.1); TH1F *htmp = (TH1F*)hTrkDzVsPt->ProjectionY(Form("hTrkDz_pt%1.0f-%1.0f_%s",pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); htmp->SetTitle(Form("%s: #Deltaz of matched track-hit pairs (%1.0f < p_{T} < %1.0f GeV/c);#Deltaz (cm)",trigName[kTrigType],pt_cuts[i],pt_cuts[i+1])); TF1 *func = new TF1(Form("func_pt%1.0f-%1.0f",pt_cuts[i],pt_cuts[i+1]),"gaus(0)+gaus(3)",-1*range,range); if(i==0) func->SetParameters(100,0,100,1000,0,10); if(i==1) func->SetParameters(1000,0,15,1000,0,60); if(i==2) func->SetParameters(1000,0,15,1000,0,60); if(i==3) func->SetParameters(1000,0,60,1000,0,15); c = FitDeltaZ(htmp,func,range,20.); if(save) { c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%1.0f_%s.pdf",run_type,pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/FitDz_Pt%1.0f_%1.0f_%s.png",run_type,pt_cuts[i],pt_cuts[i+1],trigName[kTrigType])); } } }
void ZVXT1HF0() { NCanvas(1,1,"data"); NCanvas(1,1,"ratio"); TH1F * HDatHF0; TH1F * HDat; TFile *fzee = new TFile("ZDiffOutputfile_DataOnly_2010_2011.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NVTX1_InstLumiPerBx_DATA10"); HDatHF0 = (TH1F*)fzee->Get("HF0NVTX1_InstLumiPerBx_DATA10"); data->cd(1); HDat->Draw(); NSetTitle(HDat,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Entries"); HDat->SetTitle("Number of Z produced in events without PU"); HDatHF0->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->AddEntry(HDat,"All Z","p"); legend->AddEntry(HDatHF0,"Z with minE_HF=0","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDatHF0->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); Hra->Divide(HDat); NLogAxis(0,1); ratio->cd(1); Hra->Draw(); Hra->SetTitle("Fraction of Z with (PU=0 && E_HF=0)"); Hra->Fit("expo","","",0.,1.2); NSetTitle(Hra,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Fraction"); NLogAxis(0,1); NText(.05,0.1, "0.62"); NText(0.3,0.1, "2.47"); NText(0.7,0.1, "4.93"); NText(1.1,0.1, "7.4"); NText(1.4,0.1, "<Number of Int.>"); }
void EflowCASTOR() { NCanvas(1,2,"data"); TH1F * HDat; TH1F * HZ2; // TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root"); TFile *fzee = new TFile("ZDiffOutputfile.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_DATA"); HZ2 = (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_Z2PY6"); data->cd(1); NHSetMarker(HDat,2,20,0.8); HDat->SetMinimum(10); HDat->Draw(); NStat(HDat,0); NSetTitle(HDat,"CASTOR Modules", "Entries"); HDat->SetTitle("CASTOR Module Energy 2010"); HZ2->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.06); legend->SetBorderSize(0); legend->AddEntry(HDat,"Data2010","p"); legend->AddEntry(HZ2,"Z2","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDat->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); NHSetMarker(Hra,4,20,0.8); Hra->SetMinimum(1); Hra->Divide(HZ2); NLogAxis(0,0); data->cd(2); Hra->Draw(); Hra->SetTitle("Ratio DATA/MC"); Hra->Fit("pol0"); NSetTitle(Hra,"CASTOR Modules", "Ratio"); NLogAxis(0,1); }
TH1F* normalizeYield(TH1F* hYW) { TH1F* hYWnorm = (TH1F*)hYW->Clone("hYWnorm"); hYWnorm->SetTitle( TString::Format("Q2W = %s",_q2w_bng.Data()) ); hYWnorm->SetYTitle(XSECTITLE.Data()); for (int ibin = 0; ibin < hYW->GetNbinsX(); ibin++) { float wmin = hYW->GetBinLowEdge(ibin+1); float dw = hYW->GetBinWidth(ibin+1); float vgflux = getvgflux(wmin,_q2min); float factor = 1000000000; float norm = LUM*vgflux*_dq2*dw*factor; /*printf("[wmin,q2min] = %f:%f\n",wmin,_q2min); printf("lum:vgflux:dw:dq2:factor = %f:%f:%f:%f:%.0E\n", LUM,vgflux,dw,_dq2,factor); printf("norm = %f\n",norm);*/ float yield = hYW->GetBinContent(ibin+1); float normYield = yield/norm; hYWnorm->SetBinContent(ibin+1,normYield); hYWnorm->SetBinError(ibin+1,0); //tmp till errors are correctly propagated } return hYWnorm; }
TH1F* CreateEffHisto(TH1F* hGen, TH1F* hRec) { // create an efficiency histogram Int_t nBins = hGen->GetNbinsX(); TH1F* hEff = (TH1F*) hGen->Clone("hEff"); hEff->SetTitle(""); hEff->SetStats(kFALSE); hEff->SetMinimum(0.); hEff->SetMaximum(110.); hEff->GetYaxis()->SetTitle("#epsilon [%]"); for (Int_t iBin = 0; iBin <= nBins; iBin++) { Double_t nGen = hGen->GetBinContent(iBin); Double_t nRec = hRec->GetBinContent(iBin); if (nGen > 0) { Double_t eff = nRec/nGen; hEff->SetBinContent(iBin, 100. * eff); Double_t error = sqrt(eff*(1.-eff) / nGen); if (error == 0) error = 0.0001; hEff->SetBinError(iBin, 100. * error); } else { hEff->SetBinContent(iBin, -100.); hEff->SetBinError(iBin, 0); } } return hEff; }
void PlotScurveGroup( Char_t *fname, UInt_t pBeId = 0, UInt_t pFeId = 0, UInt_t pCbc = 0, UInt_t pGroup = 0, UInt_t color = 4 ){ TFile *fin = new TFile( fname ); UInt_t cCh1(0); for( int i=0; i < 16; i++ ){ cCh1 = i * 16 + pGroup*2; for( int j = cCh1; j < cCh1 + 2; j++ ){ if( j < 254 ){ TString hname = Form( "h_%02d_%02d_%02d_%03d", pBeId, pFeId, pCbc, j ); TH1F *h = (TH1F *) fin->Get( hname ); h->GetXaxis()->SetRangeUser( 50, 170 ); h->SetLineColor(1); h->SetMarkerColor(1); h->SetTitle( Form( "FE(00),CBC(%02d); VCth; Rate", pCbc ) ); TF1 *func = h->GetFunction( Form("f_%s", hname.Data() ) ); if( i == 0 ) h->Draw(); else h->Draw("same"); } } } TString cPadName( fname ); cPadName.ReplaceAll( ".root", Form( "G%d.png", pGroup ) ); gPad->Print( cPadName ); }
void Deconvolution_wide_boost() { Int_t i; const Int_t nbins = 256; Double_t xmin = 0; Double_t xmax = nbins; Double_t source[nbins]; Double_t response[nbins]; gROOT->ForceStyle(); TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax); TH1F *d = new TH1F("d","",nbins,xmin,xmax); TString dir = gROOT->GetTutorialDir(); TString file = dir+"/spectrum/TSpectrum.root"; TFile *f = new TFile(file.Data()); h = (TH1F*) f->Get("decon3"); h->SetTitle("Deconvolution of closely positioned overlapping peaks using boosted Gold deconvolution method"); d = (TH1F*) f->Get("decon_response_wide"); for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1); for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1); h->SetMaximum(200000); h->Draw("L"); TSpectrum *s = new TSpectrum(); s->Deconvolution(source,response,256,200,50,1.2); for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]); d->SetLineColor(kRed); d->Draw("SAME L"); }
void pv_dist(const string& fFile, const string& fTitle, const string& fNameExt) { TH1F *h; TFile file(fFile.c_str()); TDirectoryFile *dir = (TDirectoryFile*)file.Get("offsetAnalysis"); TDirectoryFile *subDir = (TDirectoryFile*)dir->Get("PrimaryVertices"); h = (TH1F*)subDir->Get("h_NofPVs"); string name = h->GetName(); string fileName = name + "__" + fNameExt + ".png"; h->SetTitle(fTitle.c_str()); TCanvas *c = new TCanvas("c","",1120,800); c->cd(); h->SetLineWidth(2); h->Draw(); c->SetLogy(); c->SaveAs(fileName.c_str()); delete c; }
void make_histos_syst_rawyield(TString file_syst, TString file_default, TString out_tag){ TFile *f1 = new TFile(file_syst.Data(),"read"); TFile *f2 = new TFile(file_default.Data(),"read"); TDirectoryFile *dir1 = (TDirectoryFile*)(f1->Get("effunf")); TDirectoryFile *dir2 = (TDirectoryFile*)(f2->Get("effunf")); TList *list = dir1->GetListOfKeys(); TFile *f = new TFile(Form("plots/ratiosyst_%s.root",out_tag.Data()),"recreate"); for (int i=0; i<list->GetSize(); i++){ TString name = dir1->GetListOfKeys()->At(i)->GetName(); if (!(name.Contains("hreco_"))) continue; TObject *obj1 = dir1->Get(name.Data()); assert(obj1); TObject *obj2 = dir2->Get(name.Data()); assert(obj2); TString newname = name; newname.Append("_ratiosyst"); if (name.EndsWith("_0")) newname.ReplaceAll("_0_","_EBEB_"); if (name.EndsWith("_1")) newname.ReplaceAll("_1_","_EBEE_"); if (name.EndsWith("_2")) newname.ReplaceAll("_2_","_EEEE_"); TH1F *h = (TH1F*)(((TH1F*)obj1)->Clone(newname.Data())); h->SetTitle(h->GetName()); h->Divide((TH1F*)obj2); for (int j=0; j<h->GetNbinsX(); j++) h->SetBinError(j+1,0); for (int j=0; j<h->GetNbinsX(); j++) h->SetBinContent(j+1,1+fabs(1-h->GetBinContent(j+1))); f->cd(); h->Write(); } }
void compnclusts(Int_t run) { TFile* f = new TFile(Form("hodtest_%d.root",run)); cout << "hcana root file " << Form("hodtest_%d.root",run) << endl; TH1F* h = nclust; TFile* f1 = new TFile(Form("%d_hbk.root",run)); cout << "Engine root file " << Form("%d_hbk.root",run) << endl; TH1F* h1; switch (run) { case 50017 : // h1 = h212; //A+ break; default : h1 = h412; //hnclusters } TCanvas *c1 = new TCanvas("c1", "Shower Cluster Map", 1000, 667); gPad->SetLogy(); h1->SetFillColor(kGreen); h1->SetLineColor(kGreen); h1->SetFillStyle(1111); h1->Draw(); h->SetFillColor(kBlue); h->SetLineWidth(2); h->SetFillStyle(0); h->Draw("same"); TLatex l; l.SetTextSize(0.04); Float_t maxy = h1->GetBinContent(h1->GetMaximumBin()); Float_t xmin = h1->GetXaxis()->GetXmin(); Float_t xmax = h1->GetXaxis()->GetXmax(); Float_t xt = xmin + 0.67*(xmax-xmin); l.SetTextColor(kGreen); l.DrawLatex(xt,0.095*maxy,"Engine"); l.SetTextColor(kBlue); l.DrawLatex(xt,0.045*maxy,"hcana"); // Difference between the histograms. TCanvas *c2 = new TCanvas("c2", "Cluster differences", 1000, 667); TH1F* dif = h->Clone(); dif->Add(h,h1,1.,-1.); dif->SetTitle("Difference"); dif->SetFillColor(kRed); dif->SetLineColor(kRed); dif->SetLineWidth(1); dif->SetFillStyle(1111); dif->Draw(); }
void plotBkgModel(TList* HistList, std::string name){ gROOT->SetBatch(); system("mkdir -p plots/ada/bkgMod"); system("mkdir -p plots/grad/bkgMod"); std::string bdt; TString str = HistList->At(0)->GetName(); if (str.Contains("ada")) bdt="ada"; else if (str.Contains("grad")) bdt="grad"; else std::cout << "Error find BDT type" << std::endl; assert (str.Contains("ada") || str.Contains("grad")); gStyle->SetOptStat(0); gROOT->SetStyle("Plain"); gROOT->ForceStyle(); int color[6] = {kGreen+4,kGreen-1,kGreen,kRed,kRed-2,kRed+4}; TCanvas *canv = new TCanvas(); TLegend *leg = new TLegend(0.45,0.6,0.85,0.85); leg->SetLineColor(0); leg->SetFillColor(0); TPaveText *txt = new TPaveText(0.2,0.1,0.4,0.35,"NDC"); txt->SetFillColor(0); txt->SetLineColor(0); txt->AddText("#int L = 4.76 fb^{-1}"); for (int i=1; i<HistList->GetEntries(); i++){ //if (((TH1F*)HistList->At(i))->GetNbinsX()!=((TH1F*)HistList->At(0))->GetNbinsX()) std::cout << "Plot problem: calling plot for histograms with different number of bins" << std::endl; //assert (((TH1F*)HistList->At(i))->GetNbinsX()==((TH1F*)HistList->At(0))->GetNbinsX()); TH1F *temp = linearBin((TH1F*)HistList->At(i)); temp->Scale(((TH1F*)HistList->At(0))->Integral()/temp->Integral()); temp->SetLineColor(color[i-1]); temp->SetMarkerStyle(20); temp->SetMarkerColor(color[i-1]); temp->SetTitle(Form("Data in sidebands %s %s",bdt.c_str(),name.c_str())); temp->GetXaxis()->SetTitle(""); temp->GetYaxis()->SetRangeUser(1.0,2.*(((TH1F*)HistList->At(0))->GetMaximum())); if (i==1) temp->Draw("p"); else temp->Draw("same p"); if (i==1) leg->AddEntry(temp,"Low 3 sideband","lep"); if (i==2) leg->AddEntry(temp,"Low 2 sideband","lep"); if (i==3) leg->AddEntry(temp,"Low 1 sideband","lep"); if (i==4) leg->AddEntry(temp,"High 1 sideband","lep"); if (i==5) leg->AddEntry(temp,"High 2 sideband","lep"); if (i==6) leg->AddEntry(temp,"High 3 sideband","lep"); } leg->Draw("same"); txt->Draw("same"); canv->SetLogy(); canv->Print(("plots/"+bdt+"/bkgMod/"+name+".png").c_str(),"png"); delete canv; delete txt; delete leg; bkgCalls++; }
void ZVXT1NVTX() { NCanvas(1,1,"data"); NCanvas(1,1,"ratio"); TH1F * HDatHF0; TH1F * HDat; TFile *fzee = new TFile("ZDiffOutputfile_DataOnly_2010_2011.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NoCuts_InstLumiPerBx_DATA10"); HDatNVTX1 = (TH1F*)fzee->Get("NVTX1_InstLumiPerBx_DATA10"); data->cd(1); HDat->Draw(); NStat(HDat,0); NSetTitle(HDat,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Entries"); HDat->SetTitle("Z production luminosity"); HDatNVTX1->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->AddEntry(HDat,"All Z","p"); legend->AddEntry(HDatNVTX1,"Z with PU=0","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDatNVTX1->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); Hra->Divide(HDat); NLogAxis(0,1); ratio->cd(1); Hra->Draw(); Hra->SetTitle("Fraction of Z with PU=0"); // Hra->Fit("expo","","",0.1,1.2); NSetTitle(Hra,"Luminosity [10^{-30} cm^{-2} s^{-1}]", "Fraction"); NLogAxis(0,1); }
TH1F* createHistogram(char* name, int nbins=12) { TH1F* hist = new TH1F(name,name, 20, 0, 20); hist->SetTitle(""); char temp[100]; sprintf(temp, "Events", 20); hist->GetXaxis()->SetTitle("nPV"); hist->GetYaxis()->SetTitle(temp); return hist; }
TH1F* eff_bg(TH1F* h1, TH1F* h2, TH1F* h3, TH1F* h4, const char* name="eff"){ // first, verify that all histograms have same binning // nx is the number of visible bins // nxtot = nx+2 includes underflow and overflow Int_t nx = h1->GetNbinsX(); Int_t nxtot = nx + 2; if (h2->GetNbinsX() != nx) { // cout << "Histograms must have same number of bins" << endl; return 0; } if (h3->GetNbinsX() != nx) { // cout << "Histograms must have same number of bins" << endl; return 0; } if (h3->GetNbinsX() != nx) { // cout << "Histograms must have same number of bins" << endl; return 0; } // get the new histogram TH1F* temp = (TH1F*) h1->Clone(name); temp->SetTitle(name); temp->Reset(); temp->Sumw2(); // Loop over bins, calculate efficiency and error, put it in histogram for (Int_t i=0; i<nxtot; i++) { Double_t x1 = h1->GetBinContent(i); Double_t x2 = h2->GetBinContent(i); Double_t x3 = h3->GetBinContent(i); Double_t x4 = h4->GetBinContent(i); Double_t denom = x1 - x3; Double_t eff; if (denom == 0.) { eff = 0; } else { eff = (x2-x4)/denom; } Double_t failSig = x1 - x2; Double_t failBg = x3 - x4; Double_t blah = (1-eff)*(1-eff)*(x2+x4) + eff*eff*(failSig+failBg); if (blah <= 0.) blah=0.0; Double_t err; if (denom == 0) { err = 0.; } else { err = sqrt(blah)/denom; } temp->SetBinContent(i,eff); temp->SetBinError(i,err); } // Done return temp; }
void Background_order() { Int_t i; const Int_t nbins = 4096; Double_t xmin = 0; Double_t xmax = 4096; Double_t source[nbins]; gROOT->ForceStyle(); TH1F *d1 = new TH1F("d1","",nbins,xmin,xmax); TH1F *d2 = new TH1F("d2","",nbins,xmin,xmax); TH1F *d3 = new TH1F("d3","",nbins,xmin,xmax); TH1F *d4 = new TH1F("d4","",nbins,xmin,xmax); TString dir = gROOT->GetTutorialsDir(); TString file = dir+"/spectrum/TSpectrum.root"; TFile *f = new TFile(file.Data()); TH1F *back = (TH1F*) f->Get("back2"); back->SetTitle("Influence of clipping filter difference order on the estimated background"); back->SetAxisRange(1220,1460); back->SetMaximum(3000); back->Draw("L"); TSpectrum *s = new TSpectrum(); for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1); s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder2,kFALSE, TSpectrum::kBackSmoothing3,kFALSE); for (i = 0; i < nbins; i++) d1->SetBinContent(i + 1,source[i]); d1->SetLineColor(kRed); d1->Draw("SAME L"); for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1); s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder4,kFALSE, TSpectrum::kBackSmoothing3,kFALSE); for (i = 0; i < nbins; i++) d2->SetBinContent(i + 1,source[i]); d2->SetLineColor(kBlue); d2->Draw("SAME L"); for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1); s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder6,kFALSE, TSpectrum::kBackSmoothing3,kFALSE); for (i = 0; i < nbins; i++) d3->SetBinContent(i + 1,source[i]); d3->SetLineColor(kGreen); d3->Draw("SAME L"); for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1); s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder8,kFALSE, TSpectrum::kBackSmoothing3,kFALSE); for (i = 0; i < nbins; i++) d4->SetBinContent(i + 1,source[i]); d4->SetLineColor(kMagenta); d4->Draw("SAME L"); }
void CheckEHF() { TH1F * HDat; TH1F * HDatnoPUAft; TH1F * HDatnoPUBef; // TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root"); TFile *fzee = new TFile("ZDiffOutputfile_Data2011_noPU.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NVTX1_minEHFZoom_DATA10"); HDatnoPUAft = (TH1F*)fzee->Get("NVTX1noPUAft_minEHFZoom_DATA10"); HDatnoPUBef = (TH1F*)fzee->Get("NVTX1noPUBef_minEHFZoom_DATA10"); HDat->Scale(1./HDat->GetEntries()); HDatnoPUAft->Add(HDatnoPUBef); HDatnoPUAft->Scale(1./HDatnoPUAft->GetEntries()); HDatnoPUBef->Scale(1./HDatnoPUBef->GetEntries()); HDatnoPUAft->SetMinimum(0.); NHSetMarker(HDatnoPUAft,2,20,0.8); NHSetLine(HDatnoPUAft,2,1,1.); HDatnoPUAft->Draw("E1"); HDatnoPUAft->SetTitle("2011 Z->ee Data, minHF Energy"); NSetTitle(HDatnoPUAft,"HF Energy [GeV]", "Fraction"); NHSetMarker(HDatnoPUBef,6,20,0.8); NHSetLine(HDatnoPUBef,6,1,1.); // HDatnoPUBef->Draw("SAMEP"); NHSetMarker(HDat,4,20,0.8); NHSetLine(HDat,1,1,1.); HDat->Draw("SAMEP"); TLegend *legend = new TLegend(0.6,0.1,0.75,0.4); legend->SetTextFont(72); legend->SetTextSize(0.04); legend->SetBorderSize(0); legend->AddEntry(HDatnoPUBef,"No PU before or after","p"); // legend->AddEntry(HDatnoPUBef,"No PU before","p"); // legend->AddEntry(HDatnoPUAft,"No PU after","p"); legend->AddEntry(HDat,"PU before && after","p"); legend->Draw(); // NHSetLine(HDatnoPUBef,3,2,1.); // HDatnoPUBef->Draw("SAME HIST"); }
void EtaCharged() { NCanvas(1,2,"data"); TH1F * HDatHF0; TH1F * HDat; TFile *fzee = new TFile("ZDiffOutputfile.root"); // TFile *fzee = new TFile("ZDiffOutputfile.root"); HDat = (TH1F*)fzee->Get("NoCuts_max_eta_charged_PF_DATA"); HDatZ2 = (TH1F*)fzee->Get("NoCuts_max_eta_charged_PF_Z2PY6"); data->cd(1); HDat->Draw(); NSetTitle(HDat,"Eta", "Entries"); HDat->SetTitle("EtaMax Charged PrimaryVertex"); HDatZ2->Draw("SAME HIST"); NHSetMarker(HDat,2,20,0.4); TLegend *legend = new TLegend(0.6,0.7,0.9,0.8); legend->SetTextFont(72); legend->SetTextSize(0.06); legend->SetBorderSize(0); legend->AddEntry(HDat,"Data","p"); legend->AddEntry(HDatZ2,"PYTHIA Z2","l"); legend->Draw(); TH1F * Hra = (TH1F * ) HDatZ2->Clone(); // Hra->GetXaxis->SetRange(0,12); NStat(Hra,0); Hra->Divide(HDat); NLogAxis(0,1); data->cd(2); Hra->Draw(); Hra->SetTitle(""); NSetTitle(Hra,"Eta", "Ratio"); NLogAxis(0,0); }
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 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"); }
void doPlot1d(TTree *t, std::string hname, std::string todraw, std::string cut, int nBins, double min, double max, std::string title, std::string titleX, std::string unitX) { const std::string plotstring = todraw + ">>" + hname + "(" + toString(nBins) + "," + toString(min) + "," + toString(max) + ")"; t->Draw(plotstring.c_str(), cut.c_str()); TH1F *h = (TH1F*)gDirectory->GetList()->FindObject(hname.c_str()); h->SetTitle(title.c_str()); h->GetXaxis()->SetTitle(unitX.size()>0 ? (titleX+" / "+unitX).c_str() : titleX.c_str()); const double binsize = (max-min)/nBins; h->GetYaxis()->SetTitle(("entries per "+toString(binsize)+" "+unitX).c_str()); return; }
void plotPulls(TTree *t, string hname, string valtitle, string toPlot, double trueVal, int nBins, double lo, double hi) { string plotstring = makePlotsString("("+toPlot+"-"+toString(trueVal)+")/"+toPlot+"_err", hname, nBins, lo, hi); cout << plotstring << endl; t->Draw(plotstring.c_str()); cout << "Thisplot: " << hname << endl; TH1F *h = (TH1F*)gDirectory->GetList()->FindObject(hname.c_str()); h->SetTitle(("Pull distribution of " + valtitle).c_str()); h->GetXaxis()->SetTitle(("pull "+valtitle).c_str()); h->Fit("gaus"); gStyle->SetOptFit(1); gPad->SaveAs((fileprefix+"_"+hname+".pdf").c_str()); }
//************************************************************************************************* //Normalize Hist //************************************************************************************************* TH1F* NormalizeHist(TH1F *originalHist) { TH1F* hist = (TH1F*)originalHist->Clone((string(originalHist->GetName())+"_normalized").c_str()); Double_t norm = 0; hist->SetTitle(""); for (UInt_t b=0; int(b)<hist->GetXaxis()->GetNbins()+2; ++b) { norm += hist->GetBinContent(b); } for (UInt_t b=0; int(b)<hist->GetXaxis()->GetNbins()+2; ++b) { hist->SetBinContent(b,hist->GetBinContent(b) / norm); hist->SetBinError(b,hist->GetBinError(b) / norm); } return hist; }
TH1F* FillCum(TH1F* h){ int size = h->GetXaxis()->GetNbins(); TH1F* cumhist = (TH1F*)h->Clone(); float sum = h->GetBinContent(size+1);//Overflow string title = h->GetTitle(); title += "(Cumlative)"; cumhist->SetTitle(title.c_str()); for(int i=size; i>0; --i){ sum += h->GetBinContent(i); cumhist->SetBinContent(i,sum); } return cumhist; }
void plotHisto(TTree *t, string hname, string valtitle, string valunit, string toPlot, int nBins, double lo, double hi) { string plotstring = makePlotsString(toPlot, hname, nBins, lo, hi); cout << "Thisplot: " << hname << endl; cout << plotstring << endl; t->Draw(plotstring.c_str()); TH1F *h = (TH1F*)gDirectory->GetList()->FindObject(hname.c_str()); h->SetTitle(("Distribution of " + valtitle).c_str()); h->GetXaxis()->SetTitle(valueWithUnit(valtitle,valunit).c_str()); h->Fit("gaus"); gStyle->SetOptFit(1); gPad->SaveAs((fileprefix+"_"+hname+".pdf").c_str()); }
void t(){ gStyle->SetOptStat(0); gStyle->SetPadLeftMargin(0.13); gStyle->SetPadBottomMargin(0.13); TFile *f_bef = TFile::Open("hists/sig_nofilt_noeff.root"); TH2F *tb = (TH2F*) f_bef->Get("inv_p_t_pbar_pi0_lab_the_pi0"); tb->SetTitle("#theta_{#pi^{0}} vs t;t[(GeV)^{2}];#theta_{#pi^{0}}[#circ]"); set_style(tb->GetXaxis()); set_style(tb->GetYaxis()); TFile* f_aft = TFile::Open("hists/sig_noeff.root"); TH1F *ta = (TH1F*) f_aft->Get("inv_p_t_pbar_pi0"); // tb->SetTitle(Form("#theta_{J/#psi} in #bar{p}p#rightarrow%s", rxn.c_str())); ta->SetTitle("t;t[(GeV)^{2}]"); ta->GetXaxis()->SetRangeUser(-0.8,0.8); set_style(ta->GetXaxis()); set_style(ta->GetYaxis()); TCanvas *tc0 = new TCanvas("tc0","tc0",1100,500); tc0->Divide(2,1); tc0->cd(1); tb->Draw("colz"); TLatex *tt = new TLatex(); tt->SetTextSize(0.06); tt->SetNDC(); tt->DrawLatex(0.5,0.5,"s=12.25 GeV^{2}"); tc0->cd(2); ta->Draw(); tt->DrawLatex(0.19,0.7,"s=12.25 GeV^{2}"); tt->DrawLatex(0.19,0.6,"After MC rejection"); tc0->Print("figs/t_vs_the_pi0.pdf"); TCanvas *tc1 = new TCanvas("tc1","tc1",1400,1000); tc1->cd(); ta->Draw(); tt->DrawLatex(0.19,0.7,"s=12.25 GeV^{2}"); tt->DrawLatex(0.19,0.6,"Forward Hemesphere in CM"); //tt->DrawLatex(0.19,0.5,"After MC rejection"); }
void addPlot(TObject* obj, TString title, int color, THStack* hStack, bool doFillColor) { TH1F* h = (TH1F*)obj; h->SetTitle(title); if ( doFillColor ) { h->SetFillColor(color); //h->SetLineWidth(2); } else { h->SetLineColor(color); h->SetLineWidth(2); } hStack->Add(h); }
TH1F* MakeRelative(TH1F *hist, TH1F *reference) { TH1F *relative = (TH1F*)hist->Clone((string(hist->GetName())+"_relative").c_str()); relative->SetTitle(""); assert(hist->GetXaxis()->GetNbins() == reference->GetXaxis()->GetNbins()); for (UInt_t b=0; b<hist->GetXaxis()->GetNbins()+2; ++b) { if (reference->GetBinContent(b) > 0) { relative->SetBinContent(b,100 * ( hist->GetBinContent(b) - reference->GetBinContent(b) )/reference->GetBinContent(b)); // relative->SetBinContent(b,( hist->GetBinContent(b) - reference->GetBinContent(b) )/reference->GetBinError(b)); } else { relative->SetBinContent(b,0); } } return relative; }
TH1F* makehist( string id, int ndf ) { int hits_count = ndf + 2; TString hist_name, cut, title; hist_name += id; hist_name += "_chisq_"; hist_name += hits_count; hist_name += "hits"; cut += id; cut += "_hits_count == "; cut += hits_count; float min_x = 0; float max_x = (ndf == 2) ? 2.0 : 0.5; TH1F *hist = new TH1F(hist_name.Data(), cut, 1000, min_x, max_x); events->Draw(Form("%s_chisq >> %s", id.c_str(), hist_name.Data()), cut); if (hits_count > 3) { TF1 *func = new TF1("func", "[0]*exp([1]*x)+[2]"); TFitResultPtr fit = hist->Fit(func, "SQ", "", 0.0, 0.5); // S - return fit result, Q - quiet std::cout << hist_name << "\tslope: " << fit->Parameter(1) << "\tadd const: " << fit->Parameter(2) << std::endl; } if (id[1] == '3') { title += "Left "; } else { title += "Right "; } title += id[2]; title += " ("; title += cut; title += ")"; hist->SetTitle(title); hist->SetLabelSize(0.04, "X"); hist->SetLabelSize(0.04, "Y"); hist->SetTitleSize(0.05, "X"); hist->SetTitleSize(0.05, "Y"); hist->SetTitleOffset(0.9, "X"); hist->SetTitleOffset(1.1, "Y"); hist->GetXaxis()->SetTitle("#chi^2, [mm]"); hist->GetYaxis()->SetTitle("N"); return hist; }
void plotMttResolution() { setTDRStyle(); TCanvas *c = new TCanvas("c", "c", 800, 800); TH1F *mtt = (TH1F*) _file0->Get("mtt_resolution_mva"); mtt->SetTitle(""); mtt->SetName("m_{t#bar{t}}"); mtt->GetXaxis()->SetTitle("m_{t#bar{t}} - m_{t#bar{t}}^{gen} (GeV)"); mtt->SetLineColor(TColor::GetColor("#542437")); mtt->SetLineColor(TColor::GetColor("#8A9B0F")); mtt->SetLineColor(TColor::GetColor("#C02942")); mtt->SetFillColor(mtt->GetLineColor()); mtt->SetFillStyle(3004); mtt->GetXaxis()->SetTitleOffset(1.2); TF1 *voigt = new TF1("voigt", "gaus", -100, 100); voigt->SetParName(0, "amp"); voigt->SetParName(2, "mean"); voigt->SetParName(1, "sigma"); voigt->SetParameter(0, mtt->GetMaximum()); voigt->SetParameter(2, 0); voigt->SetParameter(1, 100); mtt->Fit(voigt, "RVN"); voigt->SetLineColor(TColor::GetColor("#8A9B0F")); voigt->SetLineWidth(2); mtt->Draw(); voigt->Draw("same"); TLatex* latex = new TLatex(); latex->SetTextFont(42); latex->SetTextSize(0.033); latex->DrawLatexNDC(0.25, 0.84, TString::Format("mean = %.2f", voigt->GetParameter(1))); latex->DrawLatexNDC(0.25, 0.8, TString::Format("#sigma = %.2f", voigt->GetParameter(2))); gPad->Modified(); gPad->Update(); c->Print("mtt_resolution.pdf"); }
void comphh(Int_t run, TH1F* h1, TH1F* h2) { TFile* f = new TFile(Form("hodtest_%d.root",run)); cout << "hcana root file " << Form("hodtest_%d.root",run) << endl; TCanvas *c1 = new TCanvas("c1", "h1 vs h2", 1000, 667); // gPad->SetLogy(); h1->SetFillColor(kGreen); h1->SetLineColor(kGreen); h1->Draw(); h2->SetLineColor(kBlue); h2->SetFillStyle(0); h2->SetLineWidth(2); h2->Draw("same"); TLatex l; l.SetTextSize(0.04); Float_t maxy = h1->GetBinContent(h1->GetMaximumBin()); Float_t xmin = h1->GetXaxis()->GetXmin(); Float_t xmax = h1->GetXaxis()->GetXmax(); Float_t xt = xmin + 0.75*(xmax-xmin); l.SetTextColor(kGreen); l.DrawLatex(xt,0.65*maxy,"h1"); l.SetTextColor(kBlue); l.DrawLatex(xt,0.75*maxy,"h2"); // Difference between the histograms. TCanvas *c2 = new TCanvas("c2", "Epr differences", 1000, 667); TH1F* dif = h2->Clone(); dif->Add(h2,h1,1.,-1.); dif->SetTitle("Difference"); dif->SetFillColor(kRed); dif->SetLineColor(kRed); dif->SetLineWidth(1); dif->SetFillStyle(1111); dif->Draw(); }