1 | #include "TString.h"
|
---|
2 | #include "TChain.h"
|
---|
3 | #include "TCanvas.h"
|
---|
4 | #include "TH1F.h"
|
---|
5 | #include "TF1.h"
|
---|
6 | #include "TLegend.h"
|
---|
7 | #include "TArrayF.h"
|
---|
8 | #include "TGraphErrors.h"
|
---|
9 | #include "MRawRunHeader.h"
|
---|
10 | #include "TPad.h"
|
---|
11 | #include "TPaveText.h"
|
---|
12 | #include "iostream.h"
|
---|
13 | #include "TObjArray.h"
|
---|
14 | #include "TFile.h"
|
---|
15 |
|
---|
16 | //--------------------------------------------------------------------------------------
|
---|
17 | // MAIN INPUT/OUTPUT
|
---|
18 |
|
---|
19 | #include "IOMkn421.h"
|
---|
20 | //--------------------------------------------------------------------------------------
|
---|
21 |
|
---|
22 | Double_t signal(Double_t *x, Double_t *par)
|
---|
23 | {
|
---|
24 | return par[0]/(TMath::Sqrt(2.*TMath::Pi())*par[1])*TMath::Exp(-(x[0]-par[2])*(x[0]-par[2])/2./par[1]/par[1]);
|
---|
25 | }
|
---|
26 |
|
---|
27 | Double_t background(Double_t *x, Double_t *par)
|
---|
28 | {
|
---|
29 | return par[0]+par[1]*x[0]+par[2]*x[0]*x[0]+par[3]*x[0]*x[0]*x[0];
|
---|
30 | }
|
---|
31 |
|
---|
32 | Double_t fitFunction(Double_t *x, Double_t *par)
|
---|
33 | {
|
---|
34 | return signal(x,par) + background(x,&par[3]);
|
---|
35 | }
|
---|
36 |
|
---|
37 | void AlphaPlot()
|
---|
38 | {
|
---|
39 | DistLo*=deg2mm;
|
---|
40 | DistUp*=deg2mm;
|
---|
41 |
|
---|
42 | Double_t acut = 10; // alpha region of excess
|
---|
43 | Int_t nbins = 36;
|
---|
44 | Int_t nbin_flat= nbins/3;
|
---|
45 |
|
---|
46 | // input file chain
|
---|
47 | TChain *fEvents=new TChain("Events");
|
---|
48 | fEvents->Add(fileOn1.Data());
|
---|
49 | fEvents->Add(fileOn2.Data());
|
---|
50 |
|
---|
51 | TChain *fEventsOff=new TChain("Events");
|
---|
52 | fEventsOff->Add(fileOff1.Data());
|
---|
53 | fEventsOff->Add(fileOff2.Data());
|
---|
54 |
|
---|
55 |
|
---|
56 | cout<<"Non="<<fEvents->GetEntries()<<" Noff="<<fEventsOff->GetEntries()<<endl;
|
---|
57 | //************************************************************************
|
---|
58 | // alpha plot + fit
|
---|
59 |
|
---|
60 | // make alpha plot (after cuts)
|
---|
61 | TCanvas *c1 = new TCanvas("c1","Alpha distribution after g/h separation",200,10,800,500);
|
---|
62 | c1->SetFillColor(0);
|
---|
63 | c1->SetBorderMode(0);
|
---|
64 | c1->cd();
|
---|
65 |
|
---|
66 | TH1F *halpha=new TH1F("halpha","",nbins,0.,90.);
|
---|
67 | halpha->GetXaxis()->SetTitle("Alpha [deg]");
|
---|
68 | halpha->GetYaxis()->SetTitle("Counts");
|
---|
69 |
|
---|
70 | TH1F *halphaOff=new TH1F("halphaOff","",nbins,0.,90.);
|
---|
71 | halpha->SetStats(kFALSE);
|
---|
72 | halphaOff->SetStats(kFALSE);
|
---|
73 |
|
---|
74 | TString strcut=Form("MHillas.fSize>%f",SizeLo);
|
---|
75 |
|
---|
76 | strcut+=Form("&& MHillasSrc.fDist>%f",DistLo);
|
---|
77 | strcut+=Form("&& MHillasSrc.fDist<%f",DistUp);
|
---|
78 |
|
---|
79 | strcut+=Form("&& MHillas.fWidth>%f",WidthLo);
|
---|
80 | strcut+=Form("&& MHillas.fWidth<%f",WidthUp);
|
---|
81 |
|
---|
82 | strcut+=Form("&& MHillas.fLength>%f",LengthLo);
|
---|
83 | strcut+=Form("&& MHillas.fLength<%f",LengthUp);
|
---|
84 |
|
---|
85 | // fill histograms
|
---|
86 | fEvents->Project("halpha","TMath::Abs(MHillasSrc.fAlpha)",strcut.Data());
|
---|
87 | halpha->SetLineWidth(2);
|
---|
88 | halpha->DrawCopy("e");
|
---|
89 |
|
---|
90 | fEventsOff->Project("halphaOff","TMath::Abs(MHillasSrc.fAlpha)",strcut.Data());
|
---|
91 | halphaOff->SetLineColor(2);
|
---|
92 | halphaOff->SetLineWidth(2);
|
---|
93 |
|
---|
94 |
|
---|
95 | // scale Off histogram to On data using bins nbin_flat(first bin after peak) - nbins
|
---|
96 | Double_t nsample_on=0;
|
---|
97 | Double_t nsample_off=0;
|
---|
98 | for(Int_t i=nbin_flat;i<nbins;i++)
|
---|
99 | nsample_on+=halpha->GetBinContent(i);
|
---|
100 | for(Int_t i=nbin_flat;i<nbins;i++)
|
---|
101 | nsample_off+=halphaOff->GetBinContent(i);
|
---|
102 |
|
---|
103 | Double_t scal=nsample_on/nsample_off;
|
---|
104 | halphaOff->Sumw2();
|
---|
105 | halphaOff->Scale(scal);
|
---|
106 | halphaOff->Draw("e same");
|
---|
107 |
|
---|
108 | gPad->SetGridx();
|
---|
109 | gPad->SetGridy();
|
---|
110 |
|
---|
111 | //--------------------------------------------------------------------------
|
---|
112 | // fit alpha hist
|
---|
113 | TF1 *backFcn = new TF1("backFcn",background,20.,89.5,4);
|
---|
114 | backFcn->SetLineWidth(2);
|
---|
115 | backFcn->SetLineColor(kRed);
|
---|
116 |
|
---|
117 | TF1 *signalFcn = new TF1("signalFcn",signal,0.,89.5,3);
|
---|
118 | signalFcn->SetLineWidth(2);
|
---|
119 | signalFcn->SetLineColor(kBlue);
|
---|
120 | signalFcn->SetNpx(500);
|
---|
121 |
|
---|
122 | TF1 *fitFcn = new TF1("fitFcn",fitFunction,0.,89.5,7);
|
---|
123 | fitFcn->SetNpx(500);
|
---|
124 | fitFcn->SetLineWidth(2);
|
---|
125 | fitFcn->SetLineColor(kMagenta);
|
---|
126 |
|
---|
127 | // start-parameters
|
---|
128 | Double_t p3start=halpha->GetBinContent(halpha->GetNbinsX()-1);
|
---|
129 | Double_t p4start=0.;
|
---|
130 | Double_t p5start=0.;
|
---|
131 | Double_t p6start=0.;
|
---|
132 |
|
---|
133 | Double_t p0start=(halpha->GetEntries()-p3start*nbins)*halpha->GetBinWidth(1);
|
---|
134 | Double_t p1start=5.;
|
---|
135 | Double_t p2start=0.;
|
---|
136 |
|
---|
137 | cout<<"Start values for fit:"<<endl;
|
---|
138 |
|
---|
139 | cout<<" Gaussian:"<<endl;
|
---|
140 | cout<<" p0 = "<<p0start<<endl;
|
---|
141 | cout<<" p1 = "<<p1start<<endl;
|
---|
142 | cout<<" p2 = "<<p2start<<endl;
|
---|
143 |
|
---|
144 | cout<<" Pol3:"<<endl;
|
---|
145 | cout<<" p0 = "<<p3start<<endl;
|
---|
146 | cout<<" p1 = "<<p4start<<endl;
|
---|
147 | cout<<" p2 = "<<p5start<<endl;
|
---|
148 | cout<<" p3 = "<<p6start<<endl<<endl<<endl;
|
---|
149 |
|
---|
150 | // background fit
|
---|
151 | Double_t parb[4];
|
---|
152 | backFcn->SetParameters(p3start,p4start,p5start,p6start);
|
---|
153 | backFcn->FixParameter(1,0); // deriv. at zero equal zero
|
---|
154 | //backFcn->FixParameter(2,0); // no 2nd order term
|
---|
155 | backFcn->FixParameter(3,0); // no 3rd order term
|
---|
156 | halpha->Fit ("backFcn","RN");
|
---|
157 | backFcn->GetParameters(parb);
|
---|
158 |
|
---|
159 | // total fit
|
---|
160 | Double_t par[7];
|
---|
161 | fitFcn->SetParameters(p0start,p1start,p2start,
|
---|
162 | parb[0],parb[1],parb[2],parb[3]);
|
---|
163 |
|
---|
164 | fitFcn->FixParameter(2,0.);
|
---|
165 | fitFcn->FixParameter(3,parb[0]);
|
---|
166 | fitFcn->FixParameter(4,parb[1]);
|
---|
167 | fitFcn->FixParameter(5,parb[2]);
|
---|
168 | fitFcn->FixParameter(6,parb[3]);
|
---|
169 | halpha->Fit ("fitFcn","RN");
|
---|
170 |
|
---|
171 | // draw fit results + legend
|
---|
172 | TLegend *legend=new TLegend(0.4,0.5,0.93,0.65);
|
---|
173 | legend->SetTextFont(40);
|
---|
174 | legend->SetTextSize(0.04);
|
---|
175 | legend->SetFillColor(19);
|
---|
176 | legend->AddEntry(halpha,"Data","lp");
|
---|
177 | TString strpol("");
|
---|
178 | strpol=Form("Polynom");
|
---|
179 | legend->AddEntry(backFcn,strpol.Data(),"l");
|
---|
180 | legend->AddEntry(fitFcn,"Global Fit","l");
|
---|
181 | //legend->Draw();
|
---|
182 |
|
---|
183 | fitFcn->GetParameters(par);
|
---|
184 | fitFcn->SetRange(-90.,90.);
|
---|
185 | fitFcn->SetLineWidth(2);
|
---|
186 | fitFcn->Draw("same");
|
---|
187 |
|
---|
188 | signalFcn->SetParameters(par);
|
---|
189 | //signalFcn->SetLineWidth(2);
|
---|
190 | //signalFcn->Draw("same");
|
---|
191 |
|
---|
192 | backFcn->SetParameters(&par[3]);
|
---|
193 | backFcn->SetRange(-90,90);
|
---|
194 | backFcn->SetLineWidth(2);
|
---|
195 | backFcn->Draw("same");
|
---|
196 |
|
---|
197 | //-----------------------------------------------------------------------
|
---|
198 | // calculate significance
|
---|
199 |
|
---|
200 | // analytical method
|
---|
201 | Double_t nSig=signalFcn->Integral(0.,acut)/halpha->GetBinWidth(1);
|
---|
202 | Double_t nOffScaled=backFcn->Integral(0.,acut)/halpha->GetBinWidth(1);
|
---|
203 |
|
---|
204 | Double_t nOn=nSig+nOffScaled;
|
---|
205 |
|
---|
206 | // significance after Li/Ma
|
---|
207 | Double_t theta=1.; // should be = Ton/Toff ???
|
---|
208 | Double_t nOff=nOffScaled/theta;
|
---|
209 | Double_t siglima = sqrt(2*(nOn*TMath::Log((1+theta)*nOn/(theta*(nOn+nOff)))
|
---|
210 | +nOff*TMath::Log((1+theta)*(nOff/(nOn+nOff)))));
|
---|
211 |
|
---|
212 | // "standard" significance
|
---|
213 | Double_t sigstd = nSig/sqrt(nOn+nOffScaled);
|
---|
214 |
|
---|
215 | TPaveText *pt = new TPaveText(0.25,0.75,0.56,0.98,"brNDC");
|
---|
216 | pt->SetTextFont(60);
|
---|
217 | pt->SetTextSize(0.03);
|
---|
218 | pt->SetTextAlign(12);
|
---|
219 |
|
---|
220 | TString strcut1(Form("cuts:"));
|
---|
221 | TString strcut3(Form(" |alpha| < %4.2f ",acut));
|
---|
222 | pt->AddText(strcut3.Data());
|
---|
223 | TString str("");
|
---|
224 | pt->AddText(str);
|
---|
225 |
|
---|
226 | TString strsig(Form("NExcess = %d",Int_t(nSig)));
|
---|
227 | pt->AddText(strsig.Data());
|
---|
228 | TString strbak(Form("NOff = %d",Int_t(nOffScaled)));
|
---|
229 | pt->AddText(strbak.Data());
|
---|
230 | pt->AddText(str);
|
---|
231 |
|
---|
232 | TString strsg(Form("Significance (Li/Ma) = %4.2f",siglima));
|
---|
233 | pt->AddText(strsg.Data());
|
---|
234 | strsg=Form("Significance (std) = %4.2f",sigstd);
|
---|
235 | pt->AddText(strsg.Data());
|
---|
236 | pt->Draw();
|
---|
237 |
|
---|
238 | cout<<endl<<"Results for events with |alpha| < "<<acut<<" degrees :"<<endl;
|
---|
239 | cout<<" noff ="<<nOffScaled<<endl;
|
---|
240 | cout<<" nexcess ="<<nSig<<endl;
|
---|
241 | cout<<" sig. (Li/Ma) ="<<siglima<<endl;
|
---|
242 | cout<<" sig.-std ="<<sigstd<<endl<<endl<<endl;
|
---|
243 |
|
---|
244 | gPad->SetGridx();
|
---|
245 | gPad->SetGridy();
|
---|
246 |
|
---|
247 | c1->Update();
|
---|
248 |
|
---|
249 | return;
|
---|
250 | }
|
---|