void ratioPlots( TCanvas* c1, TH1* h_r, TH1* h_i, string xTitle, string yTitle, string savePath, double fitMin=-100000, double fitMax=100000, bool doubleColFit=0 ){ double xMaximum = h_r->GetXaxis()->GetBinUpEdge(h_r->GetXaxis()->GetLast()); double xMinimum = h_r->GetXaxis()->GetBinLowEdge(h_r->GetXaxis()->GetFirst()); double yMaximum; double yMinimum; h_i->Sumw2(); h_r->Sumw2(); TLine* line1 = new TLine(xMinimum,1,xMaximum,1); line1->SetLineColor(1); line1->SetLineWidth(2); line1->SetLineStyle(7); TF1* fpol1 = new TF1("fpol1", "pol1", fitMin, fitMax); fpol1->SetLineColor(2); fpol1->SetLineWidth(3); fpol1->SetLineStyle(7); TH1* hRatio = (TH1*)h_r->Clone("clone_record"); hRatio->Divide(h_i); yMaximum = hRatio->GetMaximum(); yMinimum = hRatio->GetMinimum(0); hRatio->GetYaxis()->SetRangeUser(yMinimum/2.5,yMaximum+yMaximum/5); hRatio->SetXTitle(xTitle.c_str()); hRatio->SetYTitle(yTitle.c_str()); hRatio->SetLineColor(9); hRatio->SetLineWidth(2); hRatio->SetMarkerStyle(8); hRatio->Draw("e"); hRatio->Fit("fpol1", "L"); line1->Draw("SAME"); if(doubleColFit){ double p0=fpol1->GetParameter(0); double p1=fpol1->GetParameter(1); double endPoint=double(fitMax*p1)+p0; double p1new=(endPoint-1)/(fitMax-fitMin); char fun[100], text[100]; sprintf(fun,"x*(%f)+1",p1new); sprintf(text,"Tangent: %f",p1new); TF1* fnew = new TF1("fnew", fun, fitMin, fitMax); fnew->SetLineColor(2); fnew->SetLineWidth(3); fnew->Draw("SAME"); TText* Title = new TText( fitMax/12, yMinimum, text); Title->SetTextColor(2); Title->SetTextSize(0.035); Title->Draw("SAME"); } c1->SaveAs(savePath.c_str()); c1->cd(); }
void plotComparison(TFile **input, const string &title, const bool &reverse_order = false) { TH1 *qcd = merge("htlep", input, 0, QCD_CHANNELS); TH1 *ttjets = get("htlep", input[TTJETS], TTJETS); TH1 *zjets = get("htlep", input[ZJETS], ZJETS); TH1 *wjets = get("htlep", input[WJETS], WJETS); TH1 *data = merge("htlep", input, RERECO, RERECO + DATA_CHANNELS); data->SetFillColor(0); THStack *stack = new THStack(); stack->Add(qcd); stack->Add(ttjets); stack->Add(zjets); stack->Add(wjets); if (reverse_order) { stack->Draw("h"); data->Draw("h same"); } else { data->Draw("h"); stack->Draw("h same"); } TLegend *legend = createLegend(title.c_str()); legend->Draw(); }
void dominik() { TH1* matHistogramRoman = static_cast<TH1*>(extractObjectFromFile("lyRoman.root", "lightYieldProjectionY")->At(0)); TList* objects = extractObjectFromFile("c.root", "chargeBins"); TH1* matHistogramDominik = new TH1D("matHistogramDominik", ";channel;light yield / pixels", 512, -0.5, 512-0.5); int sipmIt = 0; for (int i = 0; i < objects->GetSize(); ++i) { TH1* h = static_cast<TH1*>(objects->At(i)); if (h->GetLineColor() == 8) { for (int bin = 1; bin <= 128; ++bin) { matHistogramDominik->SetBinContent(512 - (sipmIt * 128 + bin - 1), h->GetBinContent(bin)); if (h->GetBinError(bin) > 0) matHistogramDominik->SetBinError(512 - (sipmIt * 128 + bin - 1), h->GetBinError(bin)); } ++sipmIt; } } TCanvas* c = new TCanvas; c->Divide(1, 2); c->cd(1); matHistogramDominik->Draw(); matHistogramRoman->Draw("SAME"); c->cd(2); TH1* h = static_cast<TH1*>(matHistogramDominik->Clone()); h->Add(matHistogramRoman, -1); h->Draw(); }
// Draw pT balance plots void PlotOnCanvas(TH1& genHist, TH1& recoHist, TString plotname) { TLine* line1 = new TLine(1.0, genHist.GetMinimum(), 1.0, genHist.GetMaximum()); line1->SetLineColor(4); line1->SetLineWidth(2); TCanvas canvas("canvas", "", 880, 600); gStyle->SetOptStat(0); genHist.Draw("hist"); line1->Draw(); recoHist.Draw("same"); recoHist.Draw("HIST same"); leg_hist = new TLegend(0.6,0.65,0.85,0.85); leg_hist->AddEntry(&genHist,"Generator level","l"); leg_hist->AddEntry(&recoHist,"Calorimeter level","l"); leg_hist->SetFillColor(0); leg_hist->Draw(); canvas.SaveAs(plotname+TString(".eps")); canvas.SaveAs(plotname+TString(".gif")); canvas.SaveAs(plotname+TString(".root")); delete line1; delete leg_hist; }
void makeplotTwo(TH1& hist1, TH1& hist2, const char* plotname, int logy) { hist1.SetLineColor(4); hist1.SetMarkerColor(4); gStyle->SetOptStat(0); TCanvas* can = new TCanvas( plotname, plotname, 500, 500); hist1.Draw( ); hist2.Draw( "same" ); TLegend *leg = new TLegend(0.55,0.8,0.89,0.92); leg->AddEntry( &hist1,"Reconstructed","LP"); leg->AddEntry( &hist2,"Generated","L"); leg->SetFillColor(0); leg->SetLineColor(0); leg->Draw(); can->SetLogy( logy ); if(logy==2) hist1.GetYaxis()->SetMoreLogLabels(); std::string plot(cmEnergy); plot.append(plotname); can->SaveAs( (plot+".eps").c_str() ); can->SaveAs( (plot+".gif").c_str() ); can->SaveAs( (plot+".root").c_str() ); // delete can; cout << hist1.Integral() << endl; }
void makeplotThree(TH1& hist1, TH1& hist2, TH1& hist3, const char* plotname, int log) { hist1.SetLineColor(4); hist1.SetMarkerColor(4); hist3.SetLineColor(2); hist3.SetMarkerColor(2); gStyle->SetOptStat(0); TCanvas* can = new TCanvas( plotname, plotname, 500, 500); hist1.Draw( ); hist2.Draw( "same" ); hist3.Draw( "same" ); TLegend *leg = new TLegend(0.48,0.7,0.89,0.92); leg->AddEntry( &hist1,"CaloJet","LP"); leg->AddEntry( &hist3,"PF Jet","LP"); leg->AddEntry( &hist2,"GenJet","L"); leg->SetFillColor(0); leg->SetLineColor(0); leg->Draw(); can->SetLogy( log ); if(log==2) { can->SetLogy( 1 ); hist1.GetYaxis()->SetMoreLogLabels(); } std::string plot("ratio-"); plot.append(plotname); can->SaveAs( (plot+".eps").c_str() ); can->SaveAs( (plot+".gif").c_str() ); can->SaveAs( (plot+".root").c_str() ); // delete can; cout << hist1.Integral() << endl; }
// Draw pT balance plots void PlotOnCanvas(TH1& genHist, TH1& recoHist, TString plotname) { gROOT->ProcessLine(".L mystyle.C"); setTDRStyle(); tdrStyle->SetErrorX(0.5); tdrStyle->SetPadLeftMargin(0.14); tdrStyle->SetPadRightMargin(0.10); tdrStyle->SetLegendBorderSize(0); tdrStyle->SetTitleYOffset(1.5); TCanvas canvas("canvas", "", 500, 500); gStyle->SetOptStat(0); genHist.SetMinimum(0); genHist.Draw(); genHist.Draw("hist same"); recoHist.Draw("same"); recoHist.Draw("HIST same"); leg_hist = new TLegend(0.6,0.7,0.89,0.89); leg_hist->AddEntry(&genHist,"Generator level","l"); leg_hist->AddEntry(&recoHist,"Calorimeter level","l"); leg_hist->SetFillColor(0); leg_hist->Draw(); canvas.SaveAs(plotname+TString(".eps")); canvas.SaveAs(plotname+TString(".gif")); canvas.SaveAs(plotname+TString(".root")); canvas.Close(); // delete leg_hist; }
void MakeNsignalEff_pt15(){ setTDRStyle(); gStyle->SetPalette(1); TH1* medium = makehist("PreSelection_medium_pt15"); TH1* tight = makehist("PreSelection_tight_pt15"); TH1* tight_dxy10= makehist("PreSelection_iso_10_10_pt15"); TH1* tight_anal = makehist("PreSelection_pt15"); TLegend* legendH = new TLegend(0.6, 0.7, 0.9, 0.9); legendH->SetFillColor(kWhite); legendH->SetTextSize(0.03); medium->GetXaxis()->SetTitle("m_{N} GeV"); medium->GetYaxis()->SetTitle("ID efficiency"); medium->SetMarkerColor(kRed); tight->SetMarkerColor(kRed); tight_dxy10->SetMarkerColor(kRed); tight_anal->SetMarkerColor(kRed); medium->SetMarkerStyle(20.); tight->SetMarkerStyle(21.); tight_dxy10->SetMarkerStyle(22.); tight_anal->SetMarkerStyle(23.); legendH->AddEntry(medium, "medium ID", "p"); legendH->AddEntry(tight, "tight ID", "p"); legendH->AddEntry(tight_dxy10, "tight+ dxy ", "p"); legendH->AddEntry(tight_anal, "tight+ dxy+ iso ", "p"); medium->Draw("p"); tight->Draw("psame"); tight_dxy10->Draw("psame"); tight_anal->Draw("psame"); legendH->Draw(); TGraphAsymmErrors * g = new TGraphAsymmErrors(heff); g->SetLineWidth(2.0); g->SetMarkerSize(2.); // g->Draw( "9pXsame" ); CMS_lumi( c1, 2, 11 ); c1->Update(); c1->RedrawAxis(); c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/SignalPlots/SignalEff_presel_med_tight_pt15.pdf" )); }
void QAvertex(const Char_t *fdata, const Char_t *fmc) { style(); TFile *fdtin = TFile::Open(fdata); TList *ldtin = (TList *)fdtin->Get("clist"); TH2 *hdtin = (TH2 *)ldtin->FindObject("zv"); TH1 *hdt = (TH1 *)ldtin->FindObject("zvNoSel"); SetHistoStyle(hdt, 20, kRed+1); hdt->Scale(1. / hdt->Integral()); TH1 *hdt0010 = hdtin->ProjectionX("hdt0010", 1, 4); SetHistoStyle(hdt0010, 20, kRed+1); hdt0010->Scale(1. / hdt0010->Integral()); TH1 *hdt7080 = hdtin->ProjectionX("hdt7080", 11, 11); SetHistoStyle(hdt7080, 25, kAzure-3); hdt7080->Scale(1. / hdt7080->Integral()); TFile *fmcin = TFile::Open(fmc); TList *lmcin = (TList *)fmcin->Get("clist"); TH1 *hmc = (TH1 *)lmcin->FindObject("zvNoSel"); SetHistoStyle(hmc, 25, kAzure-3); hmc->Scale(1. / hmc->Integral()); TCanvas *c = new TCanvas("cVertex", "cVertex", 800, 800); TH1 * hfr = c->DrawFrame(-20., 0., 20., 0.1); hfr->SetTitle(";#it{z}_{vtx};"); hdt0010->Draw("same"); hdt7080->Draw("same"); TLegend *legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(hdt0010, "0-10%", "p"); legend->AddEntry(hdt7080, "70-80%", "p"); legend->Draw("same"); c->SaveAs(canvasPrefix+"vertex.pdf"); TCanvas *c1 = new TCanvas("cVertexDataMC", "cVertexDataMC", 800, 800); hfr = c1->DrawFrame(-20., 0., 20., 0.1); hfr->SetTitle(";#it{z}_{vtx};"); hdt->Draw("same"); hmc->Draw("same"); legend = new TLegend(0.20, 0.18+0.60, 0.50, 0.30+0.60); legend->SetFillColor(0); legend->SetBorderSize(0); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->AddEntry(hdt, "data", "p"); legend->AddEntry(hmc, "Monte Carlo", "p"); legend->Draw("same"); c1->SaveAs(canvasPrefix+"vertexDataMC.pdf"); //return 0; }
double Fit511Photopeak(TH1* h, double* error=0) { TSpectrum spec(1); spec.Search(h); h->GetXaxis()->SetTitle("Energy [photoelectrons]"); h->Draw("e"); TH1* bg = spec.Background(h); TH1* sig = (TH1*)(h->Clone()); sig->SetLineColor(kGreen); sig->Add(bg,-1); sig->Draw("same e"); sig->Fit("gaus","m","same e"); TF1* gaus = sig->GetFunction("gaus"); if(gaus) gaus->SetLineColor(kGreen); bg->SetLineColor(kRed); bg->Draw("same e"); TLine* line = new TLine(gaus->GetParameter(1),0, gaus->GetParameter(1),h->GetMaximum()); line->SetLineColor(kBlue); line->SetLineWidth(2); line->Draw(); double yield = spec.GetPositionX()[0]/epeak; double err = 0; cout<<"Results from TSpectrum: \n\t" <<"Peak = "<<spec.GetPositionX()[0]<<" p.e.; Light Yield = " <<yield<<" p.e./keV"<<endl; if(gaus){ yield = gaus->GetParameter(1)/epeak; err = gaus->GetParError(1)/epeak; cout<<"Results from BG Subtracted Gaus Fit: \n\t" <<"Peak = "<<gaus->GetParameter(1)<<" p.e.; Light Yield = " <<yield<<" +/- "<<err<<" p.e./keV"<<endl; err = max(err, TMath::Abs(yield-spec.GetPositionX()[0]/epeak)); } TLegend* leg = new TLegend(.6,.6,.9,.9); leg->AddEntry(h,"Raw Spectrum","lpe"); leg->AddEntry(bg,"Background","lpe"); leg->AddEntry(sig,"Signal","lpe"); char title[20]; sprintf(title,"Yield = %.2f pe/keV",yield); leg->AddEntry(line, title ,"l"); leg->Draw(); if(error) *error = err; return yield; }
void plotter::draw_output_stat(TH1* output_, TH1* stat_, TH1D* truth_, bool norm, TString file_name){ // std::vector<double> sys = get_sys_errors(); // TH1* output_sys = add_error_bar(output, sys); TH1* output = (TH1*) output_->Clone("output"); TH1* stat = (TH1*) stat_->Clone("stat"); TH1D* truth = (TH1D*) truth_->Clone("truth"); TCanvas *c = new TCanvas("c","",600,600); double ymax; gPad->SetLeftMargin(0.15); if(truth->GetMaximum() > output->GetMaximum()) ymax = 1.5 * truth->GetMaximum(); else ymax = 1.5 * output->GetMaximum(); TGaxis::SetMaxDigits(3); output->SetTitle(" "); output->GetYaxis()->SetRangeUser(0., ymax); output->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); if(norm) output->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]"); else output->GetYaxis()->SetTitle("events"); output->GetYaxis()->SetTitleOffset(1.1); output->GetXaxis()->SetTitleOffset(0.9); output->GetYaxis()->SetTitleSize(0.05); output->GetXaxis()->SetTitleSize(0.05); output->GetYaxis()->SetNdivisions(505); output->SetLineColor(kBlack); output->SetMarkerColor(kBlack); output->SetMarkerStyle(8); output->SetMarkerSize(1); output->Draw("E1"); stat->SetLineColor(kBlack); stat->SetMarkerColor(kBlack); stat->SetMarkerStyle(8); stat->SetMarkerSize(1); gStyle->SetEndErrorSize(5); truth->SetLineWidth(3); truth->SetLineColor(kRed); truth->SetLineStyle(2); truth->Draw("HIST SAME"); stat->Draw("E1 SAME"); output->Draw("E1 SAME"); TLegend *l=new TLegend(0.5,0.65,0.85,0.85); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(output,"data unfolded","pl"); l->AddEntry(truth,"MC particle level","pl"); l->SetTextSize(0.04); l->Draw(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
void plotCut2DSignal() { string canvas_title = "Cut 2D Signal"; TCanvas *canvas = new TCanvas(canvas_title.c_str(), canvas_title.c_str()); canvas->SetWindowSize(1200, 640); canvas->Divide(3, 2); canvas_title = "DeltaR Signal"; TCanvas *canvas_dr = new TCanvas(canvas_title.c_str(), canvas_title.c_str()); canvas_dr->SetWindowSize(1200, 640); canvas_dr->Divide(3, 2); canvas_title = "pTrel Signal"; TCanvas *canvas_ptrel = new TCanvas(canvas_title.c_str(), canvas_title.c_str()); canvas_ptrel->SetWindowSize(1200, 640); canvas_ptrel->Divide(3, 2); for(int i = 0; SIGNAL_CHANNELS > i; ++i) { int id = BACKGROUND_CHANNELS + i; TH1 *hist = get("dr_vs_ptrel", input_s1[id], id); if (!hist) continue; canvas->cd(i + 1); style(hist, id); hist->SetMarkerSize(0.1); hist->Draw("scat"); TLegend *legend = createLegend(toString(id)); legend->Draw(); canvas_ptrel->cd(i + 1); TH2 *hist2d = dynamic_cast<TH2 *>(hist); TH1 *ptrel = dynamic_cast<TH1 *>(hist2d->ProjectionX()->Clone()); style(ptrel, id); ptrel->Draw(); legend->Draw(); canvas_dr->cd(i + 1); TH2 *hist2d = dynamic_cast<TH2 *>(hist); TH1 *dr = dynamic_cast<TH1 *>(hist2d->ProjectionY()->Clone()); style(dr, id); dr->Draw(); legend->Draw(); } }
// show the histogram in first slot, try a Gaussian fit with given parameters void PRadHistCanvas::UpdateHist(int index, TObject *tob, int range_min, int range_max) { --index; if(index < 0 || index >= canvases.size()) return; canvases[index]->cd(); canvases[index]->SetGrid(); gPad->SetLogy(); TH1 *hist = (TH1*)tob; hist->GetXaxis()->SetRangeUser(hist->FindFirstBinAbove(0,1) - 10, hist->FindLastBinAbove(0,1) + 10); hist->GetXaxis()->SetLabelSize(HIST_LABEL_SIZE); hist->GetYaxis()->SetLabelSize(HIST_LABEL_SIZE); // try to fit gaussian in certain range if(range_max > range_min && hist->Integral(range_min, range_max + 1) > 0) { TF1 *fit = new TF1("", "gaus", range_min, range_max); fit->SetLineColor(kRed); fit->SetLineWidth(2); hist->Fit(fit,"qlR"); } hist->SetFillColor(fillColors[index]); hist->Draw(); canvases[index]->Refresh(); }
void QAcentrality(const Char_t *fdata) { style(); TFile *fin = TFile::Open(fdata); TList *lin = (TList *)fin->Get("clist"); lin->ls(); TH1 *hin = (TH1 *)lin->FindObject("EvCentrDist"); Float_t sum = 1.2 * hin->Integral(hin->FindBin(0.1), hin->FindBin(79.9)); hin->Scale(1. / sum); SetHistoStyle(hin, 20, kRed+1); TCanvas *c = new TCanvas("cQAcentrality", "cQAcentrality", 800, 800); TH1 * hfr = c->DrawFrame(0., 0.005, 100., 0.015); hfr->SetTitle(";centrality percentile;events"); hin->Draw("same"); c->SaveAs(canvasPrefix+"centrality.pdf"); TH2 *hinv0 = (TH2 *)lin->FindObject("V0"); TCanvas *cv0 = new TCanvas("cQAcentralityV0", "cQAcentralityV0", 800, 800); cv0->SetLogx(); cv0->SetLogz(); // TH1 * hfrv0 = cv0->DrawFrame(100., -0.5, 50000., 10.5); // DrawBinLabelsY(hfrv0, kTRUE); // hfrv0->SetTitle(";V0 signal;"); //hinv0->Draw("same,col"); hinv0->Draw("col"); cv0->SaveAs(canvasPrefix+"centralityV0.pdf"); }
void printJERs() { vector<double> ptBins; vector<double> etaBins; ptBins.push_back(0); ptBins.push_back(20); ptBins.push_back(30); ptBins.push_back(50); ptBins.push_back(80); ptBins.push_back(120); ptBins.push_back(170); ptBins.push_back(230); ptBins.push_back(300); ptBins.push_back(380); ptBins.push_back(470); ptBins.push_back(570); ptBins.push_back(680); ptBins.push_back(800); ptBins.push_back(1000); ptBins.push_back(1300); ptBins.push_back(1700); ptBins.push_back(2200); ptBins.push_back(2800); ptBins.push_back(3500); etaBins.push_back(0); etaBins.push_back(0.3); etaBins.push_back(0.5); etaBins.push_back(0.8); etaBins.push_back(1.1); etaBins.push_back(1.4); etaBins.push_back(1.7); etaBins.push_back(2.0); etaBins.push_back(2.3); etaBins.push_back(2.8); etaBins.push_back(3.2); etaBins.push_back(4.1); etaBins.push_back(5.0); TFile f("qcd_all.root"); TCanvas *c1 = new TCanvas("c1"); gStyle->SetOptStat(11111); gPad->Print("JERs.eps["); for (unsigned ptbin=0; ptbin < ptBins.size() -1; ++ptbin) { for (unsigned etabin=0; etabin < etaBins.size() -1; ++etabin) { stringstream name; name << "Hist/JERS/jer_pt"<< ptBins.at(ptbin) << "to" << ptBins.at(ptbin+1) << "_eta" << etaBins.at(etabin) << "to" << etaBins.at(etabin+1); TH1* hist = (TH1*) f.Get(name.str().c_str()); hist->Draw(); gPad->Print("JERs.eps"); } } gPad->Print("JERs.eps]"); }
// Make 1D comparison plots void makeplots1D( TH1& eff, TH1& base, TH1& destination, TString name) { gROOT->ProcessLine(".L ~/tdrstyle.C"); setTDRStyle(); TGraphAsymmErrors *g1 = new TGraphAsymmErrors(); g1->BayesDivide(&destination, &base, ""); g1->GetYaxis()->SetRangeUser(0.5, 1.05); eff.SetLineColor(2); eff.SetMarkerStyle(22); eff.SetMarkerSize(1.4); eff.SetMarkerColor(2); // g1->GetYaxis()->SetTitle("Efficiency"); if(name.Contains("_Eta")) g1->GetXaxis()->SetTitle("#eta"); if(name.Contains("_Phi")) g1->GetXaxis()->SetTitle("#phi"); if(name.Contains("_Pt")) g1->GetXaxis()->SetTitle("p_{T} (GeV/c)"); TCanvas canvas("canvas",name,600,600); g1->Draw("APE"); eff.Draw("same"); canvas.SaveAs(name + TString(".eps")); canvas.SaveAs(name + TString(".gif")); canvas.Close(); delete g1; }
// Test the global style settings for a generic histogram. void styles::testGlobalStyle(bool fixY, float scale) { readGroupStyle(); setGlobalStyle(); setDefaultStyle(); TH1* h = new TH1F("h", "h", 50, 0, 50); TH1* hc[6]; for (int i=1; i<=50; i++) { double value = scale*exp(-0.5*pow(((i-25.)/5.),2)); // Gaussian shape h->SetBinContent(i, value); } TCanvas c; if(nPads == 2) c.Divide(2); if(nPads == 3) c.Divide(3); if(nPads == 4) c.Divide(2,2); if(nPads == 6) c.Divide(3,2); c.cd(1); h->Draw(); if(fixY) moveYAxisLabel(h,100); setTitles(h, "D^{(*)0/+} channels", "xlabel^{2}_{miss} (GeV^{2})", "Events/(10 MeV^{2})"); float scales[] = {0.1, 10, 0.01}; for(int pads = 2; pads<=4; pads++){ if(nPads>=pads){ c.cd(pads); hc[pads-2] = static_cast<TH1F*>(h->Clone()); hc[pads-2]->Scale(scales[pads-2]); if(fixY) moveYAxisLabel(hc[pads-2],hc[pads-2]->GetMaximum()); hc[pads-2]->Draw(); setTitles(hc[pads-2], "D^{(*)0/+} channels", "xlabel^{2}_{miss} (GeV^{2})", "Events/(1000 MeV^{2})"); } } TString epsName = "babar_code/styles/Plot_"; epsName += nPads; epsName += "Pads.eps"; c.Print(epsName); }
void fadc_fit_heights(std::string fadc_id,std::string hist_type) { /*****************************************************************/ // Prepare the canvas gStyle->SetOptFit(1111); TCanvas *AlCapCanvas = (TCanvas *) gROOT->GetListOfCanvases()->At(0); AlCapCanvas->Clear(); AlCapCanvas->Divide(4,2); // gROOT->ProcessLine(".L common/get_histogram.C"); // get_histogram() is called here /*****************************************************************/ const int n_channels = 8; std::string bank_names[n_channels] = {"Na", "Nb", "Nc", "Nd", "Ne", "Nf", "Ng", "Nh"}; std::string name; double mean = 0; double rms = 0; for (int iChn = 0; iChn < n_channels; iChn++) { name=bank_names[iChn]+fadc_id; TH1* hist = get_histogram(name, hist_type); mean = hist->GetMean(); rms = hist->GetRMS(); AlCapCanvas->cd(iChn+1); if (hist->Integral()!=0) { TF1* gaus = new TF1("gaus","gaus",mean-rms,mean+rms); hist->Fit("gaus","Q"); hist->GetXaxis()->SetRange(mean-2*rms,mean+2*rms); hist->Draw(); } } }
// draw the next waveform that we find associated with an event void DrawNext(void) { static Int_t evno=0; if (tree == nullptr) { tree = (TTree*)gROOT->FindObject("FragmentTree"); } tree->SetBranchAddress("TFragment", &frag); do { tree->GetEntry(evno++); } while (frag->wavebuffer.empty()); cout<<"Event number "<<evno<<endl; frag->Print(); //printf("wavebuffer.size() = %i\n",wavebuffer.size()); TH1 *his = makeHisto(frag->wavebuffer); TChannel *chan = TChannel::GetChannel(frag->ChannelAddress); // if(chan && (strncmp(chan->GetChannelName(),"DSC",3)==0)) // TH1 *his = makeDescantHisto(frag->wavebuffer); if(chan) his->SetTitle(chan->GetChannelName()); his->Draw(); }
int main (int argc, char *argv[]) { LineStream ls; char *line; char *pos; Stringa buffer; if (argc != 2) { usage ("%s <file.intraOffsets>"); } TH1 *his = new TH1D ("","Intra-read distribution",1000,0,1000); TCanvas *canv = new TCanvas("","canvas",1200,400); ls = ls_createFromFile (argv[1]); while (line = ls_nextLine (ls)) { his->Fill (atoi (line)); } ls_destroy (ls); his->Draw(); his->GetXaxis()->SetLabelSize (0.04); his->GetYaxis()->SetLabelSize (0.04); buffer = stringCreate (100); pos = strchr (argv[1],'.'); if (pos == NULL) { die ("Expected <file.intraOffsets>: %s",argv[1]); } *pos = '\0'; stringPrintf (buffer,"%s_intraDistribution.jpg",argv[1]); canv->Print (string (buffer),"jpg"); stringDestroy (buffer); return 0; }
void Test(TH1* h, TH1* s, const char* test) { // Check that hist and sparse are equal, print the test result cout << test << ": "; // What exactly is "equal"? // Define it as the max of 1/1000 of the "amplitude" of the // original hist, or 1E-4, whatever is larger. Double_t epsilon = 1E-4; Double_t diffH = h->GetMaximum() - h->GetMinimum(); if (diffH < 0.) diffH = -diffH; if (diffH / 1000. > epsilon) epsilon = diffH / 1000.; TH1* diff = (TH1*)s->Clone("diff"); diff->Add(h, -1); Double_t max = diff->GetMaximum(); Double_t min = diff->GetMinimum(); if (max < -min) max = -min; if (max < epsilon) cout << "SUCCESS"; else { cout << "FAIL: delta=" << max; TCanvas* c = new TCanvas(test, test); c->Divide(1,3); c->cd(1); h->Draw(); c->cd(2); s->Draw(); c->cd(3); diff->Draw(); TFile f("runsparse.root", "UPDATE"); c->Write(); delete c; } cout <<endl; delete diff; }
void Combine(const char* inputFile){ TFile* f = TFile::Open(inputFile,"READ"); TH1 *myhist = (TH1F*)f->Get("MET_1tag"); TVectorF CutFlow = (TVectorF)f->Get("CutFlow"); CutFlow.Print(); myhist->Draw(); }
/*============================================================================*/ void gaus1peakfit(Char_t *s, Float_t x1, Float_t x2, Float_t x3, Float_t x4) { Double_t par[5],epar[5],x[4],y[4]; TH1 *hist; hist = (TH1 *) gROOT->FindObject(s); setcanvas(1); TCanvas *c1=(TCanvas*) gROOT->FindObject("c1"); if(c1==NULL)setcanvas(1); c1->Clear(); hist->SetAxisRange(x1-30,x4+30); hist->Draw(); //--**-- Linear background estimation --**--// x[0] = x1; x[1] = x2; x[2] = x3; x[3] = x4; Int_t bin1 = hist->FindBin(x1); y[0] = hist->GetBinContent(bin1); Int_t bin2 = hist->FindBin(x2); y[1] = hist->GetBinContent(bin2); Int_t bin3 = hist->FindBin(x3); y[2] = hist->GetBinContent(bin3); Int_t bin4 = hist->FindBin(x4); y[3] = hist->GetBinContent(bin4); TGraph *g = new TGraph(4,x,y); TF1 *fpol1 = new TF1("POL1","pol1",x1,x4); g->Fit(fpol1,"RQN"); par[3]=fpol1->GetParameter(0); par[4]=fpol1->GetParameter(1); //--**-- Gaussian Peak estimation without background --**--// TF1 *fgaus = new TF1("GAUS","gaus",x2,x3); hist->Fit(fgaus,"RQN"); fgaus->GetParameters(&par[0]); //--**-- Final Peak Fit with Background --**--// TF1 *func = new TF1("FGAUS","gaus(0)+pol1(3)",x1,x4); func->SetParameters(par); hist->Fit(func,"R+QN"); func->GetParameters(par); epar[0]=func->GetParError(0); epar[1]=func->GetParError(1); epar[2]=func->GetParError(2); Double_t fwhm = par[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t efwhm = epar[2]*TMath::Sqrt(8*TMath::Log(2)); Double_t N0 = par[0]*(TMath::Sqrt(TMath::TwoPi())*par[2]); Double_t r0 = epar[0]/par[0]; Double_t r2 = epar[2]/par[2]; Double_t eN0= N0*TMath::Sqrt(r0*r0+r2*r2); printf("Peak = %f +- %f; FFHM = %f +- %f; Area = %f +- %f\n", par[1],epar[1],fwhm,efwhm,N0,eN0); //printf("%11.4f %11.4f %11.0f %11.0f\n", // par[1],epar[1],N0,eN0); func->SetLineWidth(0.5); func->SetLineStyle(1); func->SetLineColor(4); func->SetFillColor(4); func->Draw("same"); }
TCanvas* DrawNP(int np, TObjArray* harr, TCanvas* cnv) { if (!harr) harr = &histoArr; if (!cnv) cnv = new TCanvas(Form("cnv%d",np),Form("cnv%d",np),900,700); cnv->Clear(); cnv->Divide(2,1); cnv->cd(1); // TH1* dxodd = (TH1*)harr->At(np*10+kDTXodd); TH1* dxevn = (TH1*)harr->At(np*10+kDTXeven); TH1* dxoddS =(TH1*)harr->At(np*10+kDTXoddSPL); TH1* dxevnS =(TH1*)harr->At(np*10+kDTXevenSPL); double max = TMath::Max(dxodd->GetMaximum(),dxevn->GetMaximum()); dxodd->SetMaximum(1.1*max); dxodd->GetXaxis()->SetTitle("#DeltaX, #mum"); dxodd->SetTitle(Form("#DeltaX for clSize=%d",np)); dxodd->Fit("gaus","",""); dxevn->Fit("gaus","","sames"); // dxoddS->Draw("sames"); dxevnS->Draw("sames"); // gPad->Modified(); gPad->Update(); SetStPadPos(dxodd,0.75,0.97,0.8,1., -1,dxodd->GetLineColor()); SetStPadPos(dxevn,0.75,0.97,0.6,0.8, -1,dxevn->GetLineColor()); SetStPadPos(dxoddS,0.75,0.97,0.4,0.6, -1,dxoddS->GetLineColor()); SetStPadPos(dxevnS,0.75,0.97,0.2,0.4, -1,dxevnS->GetLineColor()); // cnv->cd(2); TH1* dz = (TH1*)harr->At(np*10+kDTZ); dz->SetTitle(Form("#DeltaZ for clSize=%d",np)); dz->GetXaxis()->SetTitle("#DeltaZ, #mum"); dz->Fit("gaus"); TH1* dzS = (TH1*)harr->At(np*10+kDTZSPL); dz->Draw("sames"); gPad->Modified(); gPad->Update(); SetStPadPos(dz,0.75,0.97,0.8,1., -1, dz->GetLineColor()); SetStPadPos(dzS,0.75,0.97,0.5,0.7, -1, dzS->GetLineColor()); gPad->Modified(); gPad->Update(); // cnv->cd(); return cnv; }
void evtime() { vector<int> runs; vector<int> marks; vector<int> mcols; runs.push_back(13893); marks.push_back(2); mcols.push_back(2); runs.push_back(14009); marks.push_back(24); mcols.push_back(4); runs.push_back(14085); marks.push_back(25); mcols.push_back(3); runs.push_back(14234); marks.push_back(5); mcols.push_back(3); runs.push_back(14434); marks.push_back(28); mcols.push_back(3); string pre = "run"; string suf = "evt.root"; double tmax = 160; double emax = 180; new TCanvas; TH1* ph = new TH2F("hevtime", "Event vs. time; Time [sec]; Event", tmax, 0, tmax, emax, 0, emax); ph->SetStats(0); ph->Draw("axis"); TLegend* pleg = new TLegend(0.65,0.15,0.85,0.37); pleg->SetBorderSize(0); for ( unsigned int isam=0; isam<runs.size(); ++isam ) { int run = runs[isam]; int icol = dsindex(run); int col = colormap(icol); ostringstream ssrun; ssrun << run; string srun = ssrun.str(); ostringstream sst0; sst0 << t0map(run); string fname = pre + srun + suf; TFile* pfile = TFile::Open(fname.c_str(), "READ"); TTree* ptree = dynamic_cast<TTree*>(pfile->Get("DXDisplay/EventTree")); ptree->SetMarkerStyle(marks[isam]); ptree->SetMarkerColor(col); cout << run << " " << col << " " << sst0.str() << endl; if ( ptree == 0 ) { cout << "Tree not found" << endl; pfile->ls(); return; } string sarg = "event:tlo-"; sarg += sst0.str(); sarg += ">>hevtime"; ptree->Draw(sarg.c_str(), "", "same"); pleg->AddEntry(ptree, srun.c_str(), "p"); } pleg->Draw(); }
void showGraph(double canvasSizeX, double canvasSizeY, TGraph* graph, bool useLogScaleX, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset, bool useLogScaleY, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset, const std::string& outputFileName) { TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY); canvas->SetFillColor(10); canvas->SetBorderSize(2); canvas->SetTopMargin(0.05); canvas->SetLeftMargin(0.19); canvas->SetBottomMargin(0.19); canvas->SetRightMargin(0.05); canvas->SetLogx(useLogScaleX); canvas->SetLogy(useLogScaleY); TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 10, xMin, xMax); dummyHistogram->SetTitle(""); dummyHistogram->SetStats(false); dummyHistogram->SetMinimum(yMin); dummyHistogram->SetMaximum(yMax); dummyHistogram->Draw("axis"); TAxis* xAxis = dummyHistogram->GetXaxis(); xAxis->SetTitle(xAxisTitle.data()); xAxis->SetTitleOffset(xAxisOffset); xAxis->SetTitleSize(0.065); xAxis->SetLabelSize(0.055); xAxis->SetLabelOffset(0.01); xAxis->SetTickLength(0.055); xAxis->SetNdivisions(505); TAxis* yAxis = dummyHistogram->GetYaxis(); yAxis->SetTitle(yAxisTitle.data()); yAxis->SetTitleOffset(yAxisOffset); yAxis->SetTitleSize(0.070); yAxis->SetLabelSize(0.055); yAxis->SetLabelOffset(0.01); yAxis->SetTickLength(0.055); yAxis->SetNdivisions(505); graph->SetMarkerColor(1); graph->SetLineColor(1); graph->Draw("p"); canvas->Update(); size_t idx = outputFileName.find_last_of('.'); std::string outputFileName_plot = std::string(outputFileName, 0, idx); if ( useLogScaleY ) outputFileName_plot.append("_log"); else outputFileName_plot.append("_linear"); if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data()); canvas->Print(std::string(outputFileName_plot).append(".png").data()); //canvas->Print(std::string(outputFileName_plot).append(".pdf").data()); //canvas->Print(std::string(outputFileName_plot).append(".root").data()); delete dummyHistogram; delete canvas; }
void drawEnergyDeposit(const char *filename) { gROOT->SetStyle("Plain"); gStyle->SetPadRightMargin(0.01); gStyle->SetPadTopMargin(0.01); gStyle->SetPadLeftMargin(0.07); gStyle->SetPadBottomMargin(0.07); gStyle->SetOptStat(0); TGaxis::SetMaxDigits(3); TFile *file = new TFile(filename, "READ"); if (file->IsZombie()) return; TCanvas *c = new TCanvas(); c->Divide(5, 4, 0.001, 0.001); for(int i=0; i<5; i++) { TH1 *hist = (TH1*)file->Get(Form("probPos%d", i)); c->cd(i+1); gPad->SetLogy(); hist->Draw(); } for(int i=0; i<5; i++) { TH1 *hist = (TH1*)file->Get(Form("ptSigPos%d", i)); c->cd(i+6); gPad->SetLogx(); hist->Draw("col"); } for(int i=0; i<5; i++) { TH1 *hist = (TH1*)file->Get(Form("probNeg%d", i)); c->cd(i+11); gPad->SetLogy(); hist->Draw(); } for(int i=0; i<5; i++) { TH1 *hist = (TH1*)file->Get(Form("ptSigNeg%d", i)); c->cd(i+16); gPad->SetLogx(); hist->Draw("col"); } }
void Kin2Txt() { AliRunLoader* rl = AliRunLoader::Open("galice.root"); rl->LoadKinematics(); rl->LoadHeader(); TH1* hM = new TH1D("hM", "TreeK;M#(){#pi^{+}#pi^{-}} #(){GeV/#it{c}^{2}}", 100, 0., 2.); TH1* hPt = new TH1D("hPt", "TreeK;P_{T}#(){#pi^{+}#pi^{-}} #(){GeV/#it{c}}", 100, 0., 1.); TH1* hY = new TH1D("hY", "TreeK;Y#(){#pi^{+}#pi^{-}}", 160,-8., 8.); std::ofstream ofs("rho0.txt"); AliStack *stack = NULL; TParticle *part = NULL; TLorentzVector v[2], vSum; for (Int_t i=0, n(rl->GetNumberOfEvents()); i<n; ++i) { rl->GetEvent(i); stack = rl->Stack(); Int_t nPrimary(0); for (Int_t j(0), m(stack->GetNtrack()); j<m; ++j) { part = stack->Particle(j); if (part->IsPrimary()) part->Momentum(v[nPrimary++]); } if (nPrimary != 2) { Printf("Error: nPrimary=%d != 2", nPrimary); continue; } vSum = v[0] + v[1]; hM->Fill(vSum.M()); hPt->Fill(vSum.Perp()); hY->Fill(vSum.Rapidity()); ofs << std::fixed << std::setprecision(4) << vSum.M() << " " << vSum.Perp() << " " << vSum.Rapidity() << " " << v[0].Eta() << " " << v[0].Px() << " " << v[0].Py() << " " << v[0].Pz() << " " << v[1].Eta() << " " << v[1].Px() << " " << v[1].Py() << " " << v[1].Pz() << std::endl; } hM->Draw(); c1->SaveAs("TreeK.pdf("); hPt->Draw(); c1->SaveAs("TreeK.pdf"); hY->Draw(); c1->SaveAs("TreeK.pdf)"); }
void plotter::draw_output_pseudo(TH1* output_, TH1D* pseudotruth_, TH1D* mctruth_, bool norm, TString file_name){ TH1* output = (TH1*) output_->Clone("output"); TH1D* pseudotruth = (TH1D*) pseudotruth_->Clone("pseudotruth"); TH1D* mctruth = (TH1D*) mctruth_->Clone("mctruth"); double ymax_temp = 0; if(pseudotruth->GetMaximum() > ymax_temp) ymax_temp = pseudotruth->GetMaximum(); if(mctruth->GetMaximum() > ymax_temp) ymax_temp = mctruth->GetMaximum(); if(output->GetMaximum() > ymax_temp) ymax_temp = output->GetMaximum(); double ymax = 1.5 * ymax_temp; pseudotruth->SetTitle(" "); pseudotruth->GetYaxis()->SetRangeUser(0., ymax); pseudotruth->GetXaxis()->SetTitle("Leading-jet mass [GeV]"); if(norm) pseudotruth->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]"); else pseudotruth->GetYaxis()->SetTitle("events"); pseudotruth->GetYaxis()->SetTitleOffset(1.1); pseudotruth->GetXaxis()->SetTitleOffset(0.9); pseudotruth->GetYaxis()->SetTitleSize(0.05); pseudotruth->GetXaxis()->SetTitleSize(0.05); pseudotruth->GetYaxis()->SetNdivisions(505); pseudotruth->SetLineWidth(4); pseudotruth->SetLineColor(kRed); mctruth->SetLineWidth(3); mctruth->SetLineStyle(2); mctruth->SetLineColor(kBlue); output->SetLineColor(kBlack); output->SetMarkerColor(kBlack); output->SetMarkerStyle(8); output->SetMarkerSize(1); TCanvas *c= new TCanvas("Particle Level","",600,600); gPad->SetLeftMargin(0.15); TGaxis::SetMaxDigits(3); pseudotruth->Draw("HIST SAME"); mctruth->Draw("HIST SAME"); output->Draw("E1 SAME"); TLegend *l; if(mctruth->GetSize() > 20) l=new TLegend(0.2,0.6,0.4,0.85); else l=new TLegend(0.55,0.6,0.85,0.85); l->SetBorderSize(0); l->SetFillStyle(0); l->AddEntry(output,"pseudo data","pl"); l->AddEntry(pseudotruth,"pseudo data truth","pl"); l->AddEntry(mctruth,"MC truth","pl"); l->SetTextSize(0.04); l->Draw(); gPad->RedrawAxis(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
histoBook* histoBook::draw(string name, Option_t* opt ){ // no parameters if ( name == ""){ TH1* h = get( styling ); if ( h ){ // use the draw option set in its styling h->Draw( drawOption.c_str() ); drawOption = ""; } } else { TH1* h = get( name ); if ( h ){ h->Draw( opt ); } } return this; }