1 using namespace RooFit;
5 if (htype ==
"TDCADC") {
6 TH2I *
h2 = (TH2I*)f->Get(
"TAGH_timewalk/Offsets/"+hname);
7 h = h2->ProjectionY(TString(h2->GetName())+
"_"+TString(ss.str()),counter,counter);
8 TString title =
"TAGH counter "+TString(ss.str());
10 h->GetXaxis()->SetTitle(h2->GetYaxis()->GetTitle());
12 if (htype ==
"TAGH") {
13 TH2I *
h2 = (TH2I*)f->Get(
"TAGH_timewalk/Timewalk/TAGHRF_tdcTimeDiffVsPulseHeight_"+TString(ss.str()));
15 h = h2->ProjectionY(TString(h2->GetName()),1,N+1);
16 h->SetTitle(
"TAGH counter "+TString(ss.str()));
17 h->GetXaxis()->SetTitle(
"time(TDC) - time(RF) [ns]");
22 if (h->GetEntries() == 0.0)
return 999.0;
23 int max_bin = h->GetMaximumBin();
24 double max = h->GetBinContent(max_bin);
25 if (max < 7.0)
return 999.0;
26 return h->GetBinCenter(max_bin);
30 double max = h->GetBinContent(h->GetMaximumBin());
32 if (h->GetEntries() < 100.0 || mode == 999.0) {
33 fout << counter << sep << max << sep << 0.0 << sep << 0.0 << sep << 0.0 << endl;
36 double xlow = h->GetBinCenter(h->FindFirstBinAbove(0.5*max)) - 1.0;
37 double xhigh = h->GetBinCenter(h->FindLastBinAbove(0.5*max)) + 1.0;
38 RooRealVar
x(
"TDC time difference",
"TDC time difference [ns]",xlow,xhigh);
39 RooDataHist data(
"data",
"data",RooArgList(x),h);
41 RooRealVar mean(
"mean",
"mean",mode,xlow,xhigh);
42 RooRealVar
sigma(
"sigma",
"sigma",0.2,0.01,0.6);
43 RooGaussian gauss(
"gauss",
"gauss",x,mean,sigma);
44 gauss.fitTo(data,PrintLevel(-1));
46 TCanvas *canvas =
new TCanvas(
"c",
"c",800,500);
47 RooPlot *plot = x.frame();
48 plot->SetTitle(h->GetTitle());
49 plot->SetXTitle(h->GetXaxis()->GetTitle());
50 plot->SetYTitle(
"TAGH hits");
51 plot->SetTitleSize(0.0474,
"XY");
53 gauss.plotOn(plot,LineColor(kRed));
55 gauss.paramOn(plot,Layout(0.58,0.9,0.9),Format(
"NEU",AutoPrecision(1)));
58 system(TString(
"mkdir -p fits_"+htype).Data());
59 canvas->Print(
"fits_"+htype+
"/counter_"+TString(ss.str())+
".gif");
60 delete canvas;
delete plot;
61 fout << counter << sep << max << sep << mean.getVal() << sep << mean.getError() << sep << sigma.getVal() << endl;
65 double max = h->GetBinContent(h->GetMaximumBin());
67 if (h->GetEntries() < 100.0 || mode == 999.0) {
68 if (counter > 0) fout << counter << sep << max << sep << 0.0 << sep << 0.0 << sep << 0.0 << endl;
71 double xlow = mode - 1.0;
72 double xhigh = mode + 1.0;
73 RooRealVar
x(
"TDC time difference",
"TDC time difference [ns]",xlow,xhigh);
74 RooDataHist data(
"data",
"data",RooArgList(x),h);
76 RooRealVar mean(
"mean",
"mean",mode,xlow,xhigh);
77 RooRealVar sigma1(
"sigma1",
"sigma1",0.2,0.01,0.4);
78 RooGaussian gauss1(
"gauss1",
"gauss1",x,mean,sigma1);
79 RooRealVar sigma2(
"sigma2",
"sigma2",0.7,0.3,3.0);
80 RooGaussian gauss2(
"gauss2",
"gauss2",x,mean,sigma2);
82 RooRealVar
f1(
"f1",
"f1",0.75,0.01,1.);
83 RooAddPdf doubleGauss(
"doubleGauss",
"doubleGauss",RooArgList(gauss1,gauss2),RooArgList(f1));
84 doubleGauss.fitTo(data,PrintLevel(-1));
86 TCanvas *canvas =
new TCanvas(
"c",
"c",800,500);
87 RooPlot *plot = x.frame();
88 plot->SetTitle(h->GetTitle());
89 plot->SetXTitle(h->GetXaxis()->GetTitle());
90 plot->SetYTitle(
"TAGH hits");
91 plot->SetTitleSize(0.0474,
"XY");
93 doubleGauss.plotOn(plot,LineColor(kRed));
95 doubleGauss.plotOn(plot,Components(
"gauss1"),LineColor(kBlue),LineStyle(kDashed));
96 doubleGauss.plotOn(plot,Components(
"gauss2"),LineColor(kGreen),LineStyle(kDashed));
97 doubleGauss.paramOn(plot,Layout(0.15,0.45,0.9),Format(
"NEU",AutoPrecision(1)));
100 system(TString(
"mkdir -p fits_"+htype).Data());
101 canvas->Print(
"fits_"+htype+
"/counter_"+TString(ss.str())+
".gif");
102 delete canvas;
delete plot;
103 if (counter > 0) fout << counter << sep << max << sep << mean.getVal() << sep << mean.getError() << sep << sigma1.getVal() << endl;
105 int fits(TString rootFile,
bool doAllFits) {
106 TFile *
f =
new TFile(rootFile,
"read");
107 TString hnames[] = {
"TAGH_tdcadcTimeDiffVsSlotID",
"TAGHRF_tdcTimeDiffVsSlotID"};
108 TString htypes[] = {
"TDCADC",
"TAGH"};
110 if (doAllFits) N_htypes = 2;
111 for (
int htype = 0; htype < N_htypes; htype++) {
112 system(
"mkdir -p fits-csv");
113 ofstream fout; fout.open(
"fits-csv/results_"+htypes[htype]+
".txt");
115 for (
int i = 1; i <= N; i++) {
int fits(TString rootFile, bool doAllFits)
void WriteFitResults2(ofstream &fout, TH1 *h, TString htype, int counter)
Double_t sigma[NCHANNELS]
TH1 * GetHistogram(TFile *f, TString hname, TString htype, int counter)
void WriteFitResults(ofstream &fout, TH1 *h, TString htype, int counter)