void fit_waveform02(void) { //=========Macro generated from canvas: c1/c1 //========= (Wed Dec 17 14:48:18 2014) by ROOT version5.34/19 TCanvas *c1 = new TCanvas("c1", "c1",1505,246,779,672); 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->SetFillColor(0); // c1->Range(-21.79487,-16.8,106.4103,95.2); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetBorderSize(2); c1->SetLeftMargin(0.17); c1->SetRightMargin(0.05); c1->SetBottomMargin(0.15); c1->SetFrameBorderMode(0); c1->SetFrameBorderMode(0); TH1F *hist02 = new TH1F("hist02","Ch=38,10,12",100,0,100); hist02->SetBinContent(1,3); hist02->SetBinContent(2,3); hist02->SetBinContent(3,3); hist02->SetBinContent(4,3); hist02->SetBinContent(5,3); hist02->SetBinContent(6,3); hist02->SetBinContent(7,3); hist02->SetBinContent(8,4); hist02->SetBinContent(9,3); hist02->SetBinContent(10,2); hist02->SetBinContent(11,3); hist02->SetBinContent(13,5); hist02->SetBinContent(14,4); hist02->SetBinContent(15,4); hist02->SetBinContent(16,3); hist02->SetBinContent(17,4); hist02->SetBinContent(18,4); hist02->SetBinContent(19,4); hist02->SetBinContent(20,4); hist02->SetBinContent(21,4); hist02->SetBinContent(22,3); hist02->SetBinContent(23,6); hist02->SetBinContent(24,1); hist02->SetBinContent(25,2); hist02->SetBinContent(26,4); hist02->SetBinContent(27,2); hist02->SetBinContent(28,3); hist02->SetBinContent(29,4); hist02->SetBinContent(30,5); hist02->SetBinContent(31,4); hist02->SetBinContent(32,6); hist02->SetBinContent(33,4); hist02->SetBinContent(34,4); hist02->SetBinContent(35,4); hist02->SetBinContent(36,13); hist02->SetBinContent(37,28); hist02->SetBinContent(38,34); hist02->SetBinContent(39,33); hist02->SetBinContent(40,31); hist02->SetBinContent(41,31); hist02->SetBinContent(42,28); hist02->SetBinContent(43,28); hist02->SetBinContent(44,22); hist02->SetBinContent(45,24); hist02->SetBinContent(46,22); hist02->SetBinContent(47,20); hist02->SetBinContent(48,21); hist02->SetBinContent(49,15); hist02->SetBinContent(50,17); hist02->SetBinContent(51,17); hist02->SetBinContent(52,16); hist02->SetBinContent(53,14); hist02->SetBinContent(54,14); hist02->SetBinContent(55,13); hist02->SetBinContent(56,11); hist02->SetBinContent(57,11); hist02->SetBinContent(58,10); hist02->SetBinContent(59,13); hist02->SetBinContent(60,10); hist02->SetBinContent(61,8); hist02->SetBinContent(62,9); hist02->SetBinContent(63,10); hist02->SetBinContent(64,9); hist02->SetBinContent(65,8); hist02->SetBinContent(66,10); hist02->SetBinContent(67,7); hist02->SetBinContent(68,8); hist02->SetBinContent(69,7); hist02->SetBinContent(70,8); hist02->SetBinContent(71,8); hist02->SetBinContent(72,8); hist02->SetBinContent(73,4); hist02->SetBinContent(74,4); hist02->SetBinContent(75,3); hist02->SetBinContent(76,6); hist02->SetBinContent(77,7); hist02->SetBinContent(78,4); hist02->SetBinContent(79,4); hist02->SetBinContent(80,4); hist02->SetBinContent(81,5); hist02->SetBinContent(82,4); hist02->SetBinContent(83,3); hist02->SetBinContent(84,5); hist02->SetBinContent(85,4); hist02->SetBinContent(86,4); hist02->SetBinContent(87,4); hist02->SetBinContent(88,2); hist02->SetBinContent(89,3); hist02->SetBinContent(90,4); hist02->SetBinContent(91,5); hist02->SetBinContent(92,7); hist02->SetBinContent(93,5); hist02->SetBinContent(94,4); hist02->SetBinContent(95,5); hist02->SetBinContent(96,7); hist02->SetBinContent(97,4); hist02->SetBinContent(98,5); hist02->SetBinContent(99,5); hist02->SetBinContent(100,6); hist02->SetMaximum(84); hist02->SetEntries(1100); // hist02->SetStats(0); hist02->SetLineColor(2); hist02->GetXaxis()->SetTitle("sample (4 ns)"); hist02->GetXaxis()->SetNdivisions(505); hist02->GetXaxis()->SetLabelFont(42); hist02->GetXaxis()->SetLabelSize(0.07); hist02->GetXaxis()->SetTitleSize(0.07); hist02->GetXaxis()->SetTitleFont(42); hist02->GetYaxis()->SetTitle("ADC value"); hist02->GetYaxis()->SetNdivisions(505); hist02->GetYaxis()->SetLabelFont(42); hist02->GetYaxis()->SetLabelSize(0.07); hist02->GetYaxis()->SetTitleSize(0.07); hist02->GetYaxis()->SetTitleOffset(1.2); hist02->GetYaxis()->SetTitleFont(42); hist02->GetZaxis()->SetLabelFont(42); hist02->GetZaxis()->SetLabelSize(0.07); hist02->GetZaxis()->SetTitleSize(0.07); hist02->GetZaxis()->SetTitleFont(42); hist02->Draw(""); TPaveText *pt = new TPaveText(0,0.9018323,0.4148387,0.995,"blNDC"); pt->SetName("title"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetFillStyle(0); pt->SetTextFont(42); TText *text = pt->AddText("Ch=38,10,12"); pt->Draw(); c1->Modified(); c1->cd(); c1->SetSelected(c1); // define pulse function Double_t xmin=0; Double_t xmax=100; TF1 *pulse = new TF1("pulse_func",pulse_func,xmin,xmax,5); Double_t mu=1/8.; // unis of 1/x Double_t sigma=5; // units of x Double_t gain=500; Double_t t0=40; Double_t pedestal=2; pulse->SetParameters(mu,sigma,gain,t0,pedestal); pulse->SetParNames("mu","sigma","gain","t0","pedestal"); hist02->Fit(pulse); c1->SaveAs("fit_waveform02.pdf"); } 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; }