#include void peak_study2(Double_t pedestal=100) { // loop over generated pulses with variable heights and starting points relative to sampling and compute mean and sigmas for // various estimates of the peak gROOT->Reset(); //TTree *Bfield = (TTree *) gROOT->FindObject("Bfield"); gStyle->SetPalette(1,0); gStyle->SetOptStat(kTRUE); gStyle->SetOptFit(kTRUE); gStyle->SetOptFit(1111); gStyle->SetPadRightMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadBottomMargin(0.15); gStyle->SetLabelSize(0.05,"XYZ"); gStyle->SetTitleSize(0.05,"XYZ"); gStyle->SetTitleOffset(1.5,"Y"); gStyle->SetNdivisions(505,"XYZ"); // gStyle->SetFillColor(0); // char string[256]; // define histograms of peak estimates Int_t nbins=100; Double_t ypmin=20; Double_t ypmax=30; TH1D* hptrue = new TH1D("hptrue","Generated peak",nbins, ypmin,ypmax); TH1D* hpsample = new TH1D("hpsample","Single sample max",nbins, ypmin,ypmax); TH1D* hp3sample = new TH1D("hp3sample","Average 3 max samples",nbins, ypmin,ypmax); TH1D* hpeak = new TH1D("hpeak","Parabolic peak estimate, all double",nbins, ypmin,ypmax); TH1D* hipeak = new TH1D("hipeak","Parabolic ipeak, double ratio",nbins, ypmin,ypmax); Double_t pedestal=2; Double_t ped_sigma=1.2; Double_t xpmin=0; Double_t xpmax=100; Double_t mu=0.0787; // unis of 1/x Double_t sigma=0.865; // units of x Double_t gain0=350; Double_t t0=39.5; TF1 *pulse = new TF1("pulse_func",pulse_func,xpmin,xpmax,5); pulse->SetParNames("mu","sigma","gain","t0","pedestal"); Double_t gain_min=gain0*1.00; Double_t gain_max=gain0*1.04; Int_t ngain = 10; Int_t nsample = 10; for (Int_t j=0;jDivide(1,2); c1->SetGridx(); c1->SetGridy(); // c1->SetLogx(); // ouput legend TLegend *leg = new TLegend(0.55,0.7,0.85,0.9); pulse->Draw(); pulse->SetLineColor(1); points->SetMarkerStyle(20); points->SetMarkerColor(4); points->SetMarkerSize(0.7); points->Draw("psame"); peak->SetMarkerStyle(21); peak->SetMarkerColor(2); peak->SetMarkerSize(1.2); peak->Draw("psame"); leg->AddEntry(pulse,"Generated pulse","l"); leg->AddEntry(points,"Samples","p"); leg->AddEntry(peak,"Parabolic peak estimate","p"); leg->Draw(); TCanvas *c2 = new TCanvas("c2", "c2",200,10,1000,700); // c2->Divide(1,2); c2->SetGridx(); c2->SetGridy(); c2->Divide(3,2); c2->cd(1); hptrue->Draw(); c2->cd(2); hpsample->Draw(); c2->cd(3); hp3sample->Draw(); c2->cd(4); hpeak->Draw(); c2->cd(5); hipeak->Draw(); c2->cd(6); sprintf (string,"For parabolic peak estimate:\n"); printf("string=%s",string); t1 = new TLatex(0.2,0.9,string); t1->SetNDC(); t1->SetTextSize(0.04); t1->Draw(); sprintf (string,"(x_{2},y_{2}) = max sample\n"); printf("string=%s",string); t1 = new TLatex(0.2,0.8,string); t1->SetNDC(); t1->SetTextSize(0.04); t1->Draw(); sprintf (string,"y_{p} = y_{2} - #frac{1}{8} (y_{3}-y_{1})^{2}/(y_{1}-2y_{2}+y_{3}) \n"); printf("string=%s",string); t1 = new TLatex(0.2,0.7,string); t1->SetNDC(); t1->SetTextSize(0.04); t1->Draw(); sprintf (string,"x_{p} = x_{2} - #frac{1}{2} (y_{3}-y_{1})/(y_{1}-2y_{2}+y_{3}) \n"); printf("string=%s",string); t1 = new TLatex(0.2,0.6,string); t1->SetNDC(); t1->SetTextSize(0.04); t1->Draw(); sprintf (string,"peak_study2.pdf("); c1->SaveAs(string); sprintf (string,"peak_study2.pdf)"); c2->SaveAs(string); } Double_t pulse_func (Double_t *x, Double_t *par) { Double_t mu=par[0]; Double_t sigma=par[1]; Double_t gain=par[2]; Double_t t0=par[3]; Double_t pedestal=par[4]; Double_t x1=x[0]-t0; char string[256]; Double_t func; Double_t amplitude; if (x1 < -20) { func = pedestal; } else if { Double_t arg = (mu*sigma*sigma-x1)/(sqrt(2)*sigma); Double_t arg2 = -mu*x1 +(mu*sigma)*(mu*sigma)/2; amplitude = (mu/2)* exp(arg2) * TMath::Erfc(arg); func = gain * amplitude + pedestal; } /*sprintf (string,"x1=%f amplitude=%f mu=%f sigma=%f t0=%f pedestal=%f, func=%f\n",x1,amplitude,mu,sigma,pedestal,func); printf ("string=%s",string);*/ return func; }