1 using namespace RooFit;
3 stringstream ss_c; ss_c <<
counter;
4 TH2I *
h2 = (TH2I*)f->Get(
"TAGH_timewalk/Timewalk/TAGHRF_tdcTimeDiffVsPulseHeight_"+TString(ss_c.str()));
5 stringstream ss_ph; ss_ph << ph_bin;
7 if (counter == 0 && ph_bin == 0) {
9 h = h2->ProjectionY(TString(h2->GetName())+
"_"+TString(ss_ph.str()),1,N+1);
10 h->SetTitle(
"TAGH TDC timing - relative to RF, all counters");
13 h = h2->ProjectionY(TString(h2->GetName())+
"_"+TString(ss_ph.str()),ph_bin,ph_bin);
14 h->SetTitle(
"TAGH counter "+TString(ss_c.str())+
", Pulse-height bin "+TString(ss_ph.str()));
16 h->GetXaxis()->SetTitle(
"time(TDC) - time(RF) [ns]");
20 if (h->GetEntries() == 0.0)
return 999.0;
21 int max_bin = h->GetMaximumBin();
22 double max = h->GetBinContent(max_bin);
23 if (max < 7.0)
return 999.0;
24 return h->GetBinCenter(max_bin);
29 if (h->GetEntries() < 100.0 || mode == 999.0) {
30 if (counter > 0) fout << counter << sep << ph_bin << sep << h->GetEntries() << sep << 0.0 << sep << 0.0 << sep << 0.0 << endl;
33 double xlow = mode - 1.0;
34 double xhigh = mode + 1.0;
35 RooRealVar
x(
"TDC time difference",
"TDC time difference [ns]",xlow,xhigh);
36 RooDataHist data(
"data",
"data",RooArgList(x),h);
38 RooRealVar mean(
"mean",
"mean",mode,xlow,xhigh);
39 RooRealVar sigma1(
"sigma1",
"sigma1",0.2,0.01,0.4);
40 RooGaussian gauss1(
"gauss1",
"gauss1",x,mean,sigma1);
41 RooRealVar sigma2(
"sigma2",
"sigma2",0.7,0.3,3.0);
42 RooGaussian gauss2(
"gauss2",
"gauss2",x,mean,sigma2);
44 RooRealVar
f1(
"f1",
"f1",0.75,0.01,1.);
45 RooAddPdf doubleGauss(
"doubleGauss",
"doubleGauss",RooArgList(gauss1,gauss2),RooArgList(f1));
46 doubleGauss.fitTo(data,PrintLevel(-1));
48 TCanvas *canvas =
new TCanvas(
"c",
"c",800,500);
49 canvas->SetBatch(kTRUE);
50 RooPlot *plot = x.frame();
51 plot->SetTitle(h->GetTitle());
52 plot->SetXTitle(h->GetXaxis()->GetTitle());
53 plot->SetYTitle(
"TAGH hits");
54 plot->SetTitleOffset(1.1,
"Y");
56 doubleGauss.plotOn(plot,LineColor(kRed));
58 doubleGauss.plotOn(plot,Components(
"gauss1"),LineColor(kBlue),LineStyle(kDashed));
59 doubleGauss.plotOn(plot,Components(
"gauss2"),LineColor(kGreen),LineStyle(kDashed));
61 doubleGauss.paramOn(plot,Layout(0.56,0.9,0.9),Format(
"NEU",AutoPrecision(1)));
63 doubleGauss.paramOn(plot,Layout(0.15,0.45,0.9),Format(
"NEU",AutoPrecision(1)));
66 canvas->Print(
"overall_gaussian_fit.gif");
70 system(TString(
"mkdir -p fits_gaussian/counter_"+ss.str()).Data());
71 canvas->Print(
"fits_gaussian/counter_"+TString(ss.str())+
"/"+TString(h->GetName())+
".gif");
73 delete canvas;
delete plot;
74 if (counter > 0) fout << counter << sep << ph_bin << sep << h->GetEntries() << sep << mean.getVal() << sep << mean.getError() << sep << sigma1.getVal() << endl;
77 TFile *
f =
new TFile(rootFile,
"read");
79 system(
"mkdir -p gaussian-fits-csv");
80 for (
int i = 1; i <= 274; i++) {
81 stringstream ss; ss << i;
82 ofstream fout; fout.open(
"gaussian-fits-csv/counter_"+TString(ss.str())+
".txt");
83 for (
int j = 1; j <= 41; j++) {
void WriteGaussianFitResults(ofstream &fout, TH1 *h, int counter, int ph_bin)
int gaussian_fits(TString rootFile, bool doAllFits)
TH1 * GetHistogram(TFile *f, TString hname, TString htype, int counter)