void trigger_waveform10(void) { //=========Macro generated from canvas: c1/c1 //========= (Wed Dec 17 14:50:15 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(kFALSE); gStyle->SetOptFit(kTRUE); gStyle->SetOptFit(1111); gStyle->SetPadRightMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadBottomMargin(0.15); gStyle->SetFillColor(0); // Int_t j; char string[256]; 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 *hist10 = new TH1F("hist10","Ch=40,04,14",100,0,100); TH1F *h_adc = new TH1F("h_adc","ADC",100,0,100); TH1F *h_trig = new TH1F("h_trig","Trig",100,0,100); hist10->SetBinContent(1,2); hist10->SetBinContent(3,1); hist10->SetBinContent(5,3); hist10->SetBinContent(6,3); hist10->SetBinContent(7,1); hist10->SetBinContent(8,3); hist10->SetBinContent(9,2); hist10->SetBinContent(10,2); hist10->SetBinContent(12,1); hist10->SetBinContent(13,2); hist10->SetBinContent(14,2); hist10->SetBinContent(15,3); hist10->SetBinContent(16,3); hist10->SetBinContent(17,4); hist10->SetBinContent(19,2); hist10->SetBinContent(20,2); hist10->SetBinContent(21,3); hist10->SetBinContent(22,1); hist10->SetBinContent(23,3); hist10->SetBinContent(25,1); hist10->SetBinContent(26,3); hist10->SetBinContent(27,2); hist10->SetBinContent(28,2); hist10->SetBinContent(29,1); hist10->SetBinContent(30,3); hist10->SetBinContent(31,4); hist10->SetBinContent(32,1); hist10->SetBinContent(33,2); hist10->SetBinContent(34,1); hist10->SetBinContent(35,2); hist10->SetBinContent(36,18); hist10->SetBinContent(37,50); hist10->SetBinContent(38,71); hist10->SetBinContent(39,74); hist10->SetBinContent(40,72); hist10->SetBinContent(41,66); hist10->SetBinContent(42,61); hist10->SetBinContent(43,55); hist10->SetBinContent(44,49); hist10->SetBinContent(45,44); hist10->SetBinContent(46,43); hist10->SetBinContent(47,39); hist10->SetBinContent(48,36); hist10->SetBinContent(49,33); hist10->SetBinContent(50,31); hist10->SetBinContent(51,29); hist10->SetBinContent(52,26); hist10->SetBinContent(53,23); hist10->SetBinContent(54,24); hist10->SetBinContent(55,22); hist10->SetBinContent(56,19); hist10->SetBinContent(57,18); hist10->SetBinContent(58,15); hist10->SetBinContent(59,18); hist10->SetBinContent(60,16); hist10->SetBinContent(61,15); hist10->SetBinContent(62,15); hist10->SetBinContent(63,16); hist10->SetBinContent(64,14); hist10->SetBinContent(65,14); hist10->SetBinContent(66,12); hist10->SetBinContent(67,12); hist10->SetBinContent(68,13); hist10->SetBinContent(69,12); hist10->SetBinContent(70,10); hist10->SetBinContent(71,8); hist10->SetBinContent(72,9); hist10->SetBinContent(73,9); hist10->SetBinContent(74,8); hist10->SetBinContent(75,7); hist10->SetBinContent(76,8); hist10->SetBinContent(77,6); hist10->SetBinContent(78,4); hist10->SetBinContent(79,5); hist10->SetBinContent(80,3); hist10->SetBinContent(81,5); hist10->SetBinContent(82,5); hist10->SetBinContent(83,3); hist10->SetBinContent(84,4); hist10->SetBinContent(85,4); hist10->SetBinContent(86,4); hist10->SetBinContent(87,4); hist10->SetBinContent(88,5); hist10->SetBinContent(89,4); hist10->SetBinContent(90,5); hist10->SetBinContent(91,7); hist10->SetBinContent(92,4); hist10->SetBinContent(93,3); hist10->SetBinContent(94,7); hist10->SetBinContent(95,6); hist10->SetBinContent(96,6); hist10->SetBinContent(97,4); hist10->SetBinContent(98,4); hist10->SetBinContent(99,5); hist10->SetBinContent(100,3); hist10->SetMaximum(84); hist10->SetEntries(1100); // hist10->SetStats(0); hist10->SetTitle(""); hist10->SetLineColor(1); hist10->GetXaxis()->SetTitle("sample (4 ns)"); hist10->GetXaxis()->SetNdivisions(505); hist10->GetXaxis()->SetLabelFont(42); hist10->GetXaxis()->SetLabelSize(0.07); hist10->GetXaxis()->SetTitleSize(0.07); hist10->GetXaxis()->SetTitleFont(42); hist10->GetYaxis()->SetTitle("ADC value"); hist10->GetYaxis()->SetNdivisions(505); hist10->GetYaxis()->SetLabelFont(42); hist10->GetYaxis()->SetLabelSize(0.07); hist10->GetYaxis()->SetTitleSize(0.07); hist10->GetYaxis()->SetTitleOffset(1.2); hist10->GetYaxis()->SetTitleFont(42); hist10->GetZaxis()->SetLabelFont(42); hist10->GetZaxis()->SetLabelSize(0.07); hist10->GetZaxis()->SetTitleSize(0.07); hist10->GetZaxis()->SetTitleFont(42); hist10->Draw(""); TPaveText *pt = new TPaveText(0,0.9018323,0.416129,0.995,"blNDC"); pt->SetName("title"); pt->SetBorderSize(0); pt->SetFillColor(0); pt->SetFillStyle(0); pt->SetTextFont(42); TText *text = pt->AddText("Ch=40,04,14"); 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"); // hist10->Fit(pulse); Int_t ndim = hist10->GetNbinsX(); Double_t xlo = hist10->GetBinLowEdge(1); Double_t width = hist10->GetBinWidth(1); // printf ("\ntrigger_waveform: ndim=%d, xlo=%f, width=%f\n\n",ndim,xlo,width); Double_t xbin, content; Int_t daq_thresh=5; Int_t NSA_daq = 55; Int_t NSB_daq = 5; Int_t trig_thresh=20; Int_t NSA_trig = 15; Int_t NSB_trig = 3; Int_t jdaq_thresh=0; Int_t jtrig_thresh=0; bool daq_over = false; bool trig_over = false; Int_t jdaq_min=0; Int_t jdaq_max=0; Int_t jtrig_min=0; Int_t jtrig_max=0; for(j=0;jGetBinCenter(j+1); content = hist10->GetBinContent(j+1) - pedestal; // subtract pedestal, assume no baseline shifts. // printf ("j=%d, xbin=%f, content=%f\n",j,xbin,content); if (content > daq_thresh && !daq_over) { jdaq_thresh = j; jdaq_min = j - NSB_daq; jdaq_max = j + NSA_daq - 1; daq_over = true; } if (content > trig_thresh && !trig_over) { jtrig_thresh = j; jtrig_min = j - NSB_trig; jtrig_max = j + NSA_trig -1; trig_over = true; } } // print out portion of processed pulsed by daq and trig Double_t sum_tot=0; Double_t sum_adc=0; Double_t sum_trig=0; for(j=0;jGetBinCenter(j+1); content = hist10->GetBinContent(j+1) - pedestal; // subtract pedestal, assume no baseline shifts. sum_tot += content; if (j >= jdaq_min && j<=jdaq_max) { h_adc->SetBinContent(j+1,content); sum_adc += content; // printf ("jdaq_min=%d, jdaq_max=%d, j=%d, xbin=%f, content=%f\n",jdaq_min, jdaq_max,j,xbin,content); } if (j >= jtrig_min && j<=jtrig_max) { h_trig->SetBinContent(j+1,content); sum_trig += content; // printf ("jtrig_min=%d, jtrig_max=%d, j=%d, xbin=%f, content=%f\n",jtrig_min, jtrig_max,j,xbin,content); } } Double_t ratio_trig_adc=0; Double_t ratio_adc_tot=0; if (sum_adc > 0) { ratio_trig_adc=sum_trig/sum_adc; } if (sum_tot > 0) { ratio_adc_tot=sum_adc/sum_tot; } cout << endl << "sum_adc=" << sum_adc << " sum_trig=" << sum_trig << " ratio=" << ratio_trig_adc << endl << endl; // draw histograms sprintf (string,"ADC N_{SB}= %d, N_{SA}=%d, Th=%d\n",NSB_daq,NSA_daq,daq_thresh); printf("string=%s",string); t1 = new TLatex(0.2,0.86,string); t1->SetNDC(); t1->SetTextSize(0.035); t1->Draw(); sprintf (string,"Trig N_{SB}= %d, N_{SA}=%d, Th=%d\n",NSB_trig,NSA_trig,trig_thresh); printf("string=%s",string); t1 = new TLatex(0.2,0.82,string); t1->SetNDC(); t1->SetTextSize(0.035); t1->Draw(); sprintf (string,"Sum tot = %.1f\n",sum_tot); printf("string=%s",string); t1 = new TLatex(0.2,0.76,string); t1->SetNDC(); t1->SetTextSize(0.035); t1->Draw(); sprintf (string,"Sum ADC = %.1f\n",sum_adc); printf("string=%s",string); t1 = new TLatex(0.2,0.72,string); t1->SetNDC(); t1->SetTextSize(0.035); t1->Draw(); sprintf (string,"Sum Trig = %.1f\n",sum_trig); printf("string=%s",string); t1 = new TLatex(0.2,0.68,string); t1->SetNDC(); t1->SetTextSize(0.035); t1->Draw(); sprintf (string,"ADC/tot = %.2f\n",ratio_adc_tot); printf("string=%s",string); t1 = new TLatex(0.2,0.64,string); t1->SetNDC(); t1->SetTextSize(0.035); t1->Draw(); sprintf (string,"Trig/ADC= %.2f\n",ratio_trig_adc); printf("string=%s",string); t1 = new TLatex(0.2,0.60,string); t1->SetNDC(); t1->SetTextSize(0.035); t1->Draw(); TLegend *leg = new TLegend(0.65,0.7,0.95,0.9); leg->AddEntry(hist10,"Full Pulse","l"); leg->AddEntry(h_adc,"ADC Pulse-Ped","l"); leg->AddEntry(h_trig,"Trig Pulse-Ped","l"); h_adc->SetLineColor(2); h_adc->Draw("Same"); h_trig->SetLineColor(4); h_trig->Draw("Same"); leg->Draw(); // c1->SaveAs("trigger_waveform10.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; }