pxar
 All Classes Namespaces Functions Variables Typedefs Friends
fitScurve.C
1 double PIF_errOld(double *x, double *par) {
2  return par[0]*TMath::Erf(par[2]*(x[0]-par[1]))+par[3];
3 }
4 
5 // ----------------------------------------------------------------------
6 TF1* errScurveOld(TH1 *h) {
7 
8  // -- determine step function and start of function range (to exclude spurious low-threshold readouts)
9  int STARTBIN(2);
10  int ibin(-1), jbin(-1);
11  double hmax(h->GetMaximum());
12  for (int i = STARTBIN; i <= h->GetNbinsX(); ++i) {
13  if (h->GetBinContent(i) > 0) {
14  ibin = i;
15  break;
16  }
17  }
18 
19  // require 2 consecutive bins on plateau
20  for (int i = STARTBIN; i < h->GetNbinsX(); ++i) {
21  if (h->GetBinContent(i) > 0.9*hmax && h->GetBinContent(i+1) > 0.9*hmax) {
22  jbin = i;
23  break;
24  }
25  }
26 
27  double lo = h->GetBinLowEdge(1);
28  // require 3 consecutive bins at zero
29  for (int i = 3; i < h->GetNbinsX(); ++i) {
30  if (h->GetBinContent(i-2) < 1 && h->GetBinContent(i-1) < 1 && h->GetBinContent(i) < 1) {
31  lo = h->GetBinLowEdge(i-2);
32  break;
33  }
34  }
35 
36  double hi = h->FindLastBinAbove(0.9*h->GetMaximum());
37 
38 
39  // -- setup function
40  TF1* f = (TF1*)gROOT->FindObject("PIF_err_old");
41  if (0 == f) {
42  f = new TF1("PIF_err_old", PIF_errOld, h->GetBinLowEdge(1), h->GetBinLowEdge(h->GetNbinsX()+1), 4);
43  f->SetParNames("p0", "p1", "p2", "p3");
44  f->SetNpx(1000);
45  }
46 
47  f->SetRange(lo, hi);
48 
49  cout << "initializing to " << 0.5*h1->GetMaximum() << endl;
50  f->SetParameter(0, 0.5*h1->GetMaximum());
51  f->SetParameter(1, 30.);
52  f->SetParameter(2, .2);
53  f->SetParameter(3, 0.5*h1->GetMaximum());
54 
55  return f;
56 }
57 
58 
59 // ----------------------------------------------------------------------
60 void fitScurve(int idx = 0, double p0 = -1., double p1 = -1., double p2 = -1., double p3 = -1) {
61  TFile *file = TFile::Open("roc/pxar.root");
62 
63  TH1D *h(0), *h0(0), *h1(0);
64  int row(0), col(0);
65 
66  PixInitFunc *fPIF = new PixInitFunc();
67  TF1 *f(0), *f1(0);
68 
69  col = idx/80;
70  row = idx%80;
71  h = (TH1D*)file->Get(Form("Scurves/scurveVcal_Vcal_c%d_r%d_C0_V0", col, row));
72 
73  h0 = (TH1D*)h->Clone("h0");
74  h1 = (TH1D*)h->Clone("h1");
75 
76  zone(1,2);
77 
78  if (1) {
79  f = fPIF->errScurve(h0);
80  if (p0 > 0.) f->SetParameter(0, p0);
81  if (p1 > 0.) f->SetParameter(1, p1);
82  if (p2 > 0.) f->SetParameter(2, p2);
83  if (p3 > 0.) f->SetParameter(3, p3);
84 
85 
86  f->SetLineColor(kRed);
87 
88  h0->Fit(f);
89 
90  double fSigma = 1./(TMath::Sqrt(2.)/f->GetParameter(1));
91  cout << "==> " << fSigma << endl;
92  }
93 
94  c0.cd(2);
95  f1 = errScurveOld(h1);
96  if (p0 > 0.) f1->SetParameter(0, p0);
97  if (p1 > 0.) f1->SetParameter(1, p1);
98  if (p2 > 0.) f1->SetParameter(2, p2);
99  if (p3 > 0.) f1->SetParameter(3, p3);
100 
101 
102  f1->SetLineColor(kBlue);
103 
104  // f1->FixParameter(0, 0.5*h1->GetMaximum());
105  f1->FixParameter(3, 0.5*h1->GetMaximum());
106 
107  h1->Fit(f1, "r");
108  double sig = 1./(TMath::Sqrt(2.)*f1->GetParameter(2));
109  cout << "==> " << sig << endl;
110 }
111 
112 
113 // ----------------------------------------------------------------------
114 void overlay() {
115 
116  TFile *f0 = TFile::Open("roc/pxar-v20.root");
117  TH1D *h0 = (TH1D*)f0->Get("Scurves/dist_sig_scurveVcal_Vcal_C0_V0");
118 
119  TFile *f1 = TFile::Open("roc/pxar-v10.root");
120  TH1D *h1 = (TH1D*)f1->Get("Scurves/dist_sig_scurveVcal_Vcal_C0_V0");
121 
122  TFile *f2 = TFile::Open("roc/pxar-v30.root");
123  TH1D *h2 = (TH1D*)f2->Get("Scurves/dist_sig_scurveVcal_Vcal_C0_V0");
124 
125  TFile *f3 = TFile::Open("roc/pxar-v40.root");
126  TH1D *h3 = (TH1D*)f3->Get("Scurves/dist_sig_scurveVcal_Vcal_C0_V0");
127 
128  TFile *f4 = TFile::Open("roc/pxar-v50.root");
129  TH1D *h4 = (TH1D*)f4->Get("Scurves/dist_sig_scurveVcal_Vcal_C0_V0");
130 
131  h4->SetLineColor(kOrange);
132  h4->Draw();
133 
134  h0->SetLineColor(kRed);
135  h0->Draw("samehist");
136  tl.SetTextColor(kRed);
137  tl.DrawLatex(0.20, 0.75, "ntrig = 5");
138 
139  h1->SetLineColor(kCyan);
140  h1->Draw("samehist");
141  tl.SetTextColor(kCyan);
142  tl.DrawLatex(0.20, 0.70, "ntrig = 10");
143 
144  h2->SetLineColor(kBlue);
145  h2->Draw("samehist");
146  tl.SetTextColor(kBlue);
147  tl.DrawLatex(0.20, 0.65, "ntrig = 20");
148 
149  h3->SetLineColor(kBlack);
150  h3->Draw("samehist");
151  tl.SetTextColor(kBlack);
152  tl.DrawLatex(0.20, 0.60, "ntrig = 50");
153 
154  tl.SetTextColor(kOrange);
155  tl.DrawLatex(0.20, 0.55, "ntrig = 100");
156 
157  gStyle->SetOptStat(0);
158  gStyle->SetOptTitle(0);
159 
160 }
161 
162 
163 // ----------------------------------------------------------------------
164 void compare(string f1name = "roc/pxar-v0.root", string f2name = "roc/pxar-v1.root") {
165 
166  TFile *f1 = TFile::Open(f1name.c_str());
167  TH2D *h1 = (TH2D*)f1->Get("Scurves/sig_scurveVcal_Vcal_C0_V0");
168  h1->SetMinimum(0.);
169  TFile *f2 = TFile::Open(f2name.c_str());
170  TH2D *h2 = (TH2D*)f2->Get("Scurves/sig_scurveVcal_Vcal_C0_V0");
171  h2->SetMinimum(0.);
172 
173  TH2D *h3 = (TH2D*)h1->Clone("h3"); h3->Reset();
174  h3->SetMinimum(-1.);
175  TH1D *h4 = new TH1D("h4", "", 100, -1., 1.);
176 
177  double v1, v2;
178  for (int ix = 0; ix < h1->GetNbinsX(); ++ix) {
179  for (int iy = 0; iy < h1->GetNbinsY(); ++iy) {
180  v1 = h1->GetBinContent(ix+1, iy+1);
181  v2 = h2->GetBinContent(ix+1, iy+1);
182  h3->SetBinContent(ix+1, iy+1, v1-v2);
183  h4->Fill(v1-v2);
184  }
185  }
186 
187  zone(2,2);
188 
189  c0.cd(1);
190  h1->Draw("colz");
191 
192  c0.cd(2);
193  h2->Draw("colz");
194 
195  c0.cd(3);
196  h3->Draw("colz");
197 
198  c0.cd(4);
199  h4->Draw();
200 
201 }