source: trunk/MagicSoft/Mars/mtemp/mmpi/SupercutsONOFFClasses/MHFindSignificanceONOFF.h@ 4788

Last change on this file since 4788 was 4411, checked in by paneque, 20 years ago
*** empty log message ***
File size: 12.9 KB
Line 
1#ifndef MARS_MHFindSignificanceONOFF
2#define MARS_MHFindSignificanceONOFF
3
4#ifndef MARS_MH
5#include "MH.h"
6#endif
7
8#ifndef ROOT_TArrayD
9#include <TArrayD.h>
10#endif
11
12#ifndef ROOT_TPostScript
13#include <TPostScript.h>
14#endif
15
16
17class TF1;
18class TH1;
19class TCanvas;
20
21class MHFindSignificanceONOFF : public MH
22{
23private:
24
25 TH1 *fHistOrig; // original plot of |alpha| (0.0 to 90.0 degrees)
26 TH1 *fHist; // copy of fHistOrig or rebinned histogram
27
28
29
30 TH1 *fHistOrigOFF; // original plot of |alpha| (0.0 to 90.0 degrees)
31 TH1 *fHistOFF; // copy of fHistOrig or rebinned histogram
32 TH1 *fHistOFFNormalized; // fHistOFF normalized (contents and errors) with
33 // with fNormFactor; useful when plotting OFF
34 // Data together with ON data
35
36
37 // Postscript file where, for each theta bin,
38 // alpha ON and OFF distributions
39 // after cuts (and hence, Nex and SigmaLiMa computations) will be stored
40 // This TPostScript object has to be initialized and closed finally
41 // outside this class.
42
43 // NOT WORKING WELL !!!
44
45 TPostScript* fPsFilename;
46
47
48 TString fPsFilenameString; // Name of the file where plots will be stored while the
49 // TPostScript option is not working
50
51
52
53 Double_t fAlphamin; // requested lower limit of fit range
54 Double_t fAlphammm; // center of fit range
55 Double_t fAlphamax; // requested lower limit of fit range
56
57 Double_t fAlphaminOFF; // requested lower limit of fit range for OFF data
58 Double_t fAlphamaxOFF; // requested lower limit of fit range for OFF data
59
60
61 Double_t fAlphami; // actual lower limit of fit range
62 Double_t fAlphamm; // actual center of fit range
63 Double_t fAlphama; // actual upper limit of fit range
64
65 Double_t fAlphasig; // requested signal range
66 Double_t fAlphasi; // actual signal range
67 Double_t fAlphasiOFF; // actual signal range for OFF data
68
69
70 Double_t fAlphalow; // requested lower edge of signal range
71 Double_t fAlphalo; // actual lower edge of signal range
72
73 Double_t fAlphahig; // requested upper edge of background range
74 Double_t fAlphahi; // actual upper edge of background range
75
76 // number of events in signal region
77 Double_t fNon; // total number of events in signal region
78 Double_t fNbg; // number of background events in signal region
79 Double_t fNex; // number of excess events in signal region
80
81 Double_t fdNon;
82 Double_t fdNbg;
83 Double_t fdNex;
84
85 // number of events in background region
86 Double_t fNbgtot; // total number of events in background region
87 Double_t fNbgtotFitted; // fitted total no. of events in background region
88 Double_t fdNbgtotFitted; // fitted error of this number
89
90 // Variables related to OFF data.
91 // Many variables are defined for similarity with
92 // existing program. Many of them might be removed in future...
93
94
95 Double_t fNexONOFF; // number of excess events (ON-OFF)
96 // in signal region
97 Double_t fNexONOFFFitted; // number of excess events (ON-OFF fitted)
98 // in signal region
99
100 Double_t fdNexONOFF; // error in number of excess events (ON-OFF)
101 // in signal region
102 Double_t fdNexONOFFFitted; // error in number of excess events (ON-OFF fitted)
103 // in signal region
104
105
106
107 Double_t fNoffTot; // Total number of OFF events
108 Double_t fNoffSig; // Number of OFF events in "signal" region
109 Double_t fNoffBg; // Number of OFF events in "background" region
110
111 // errors for previous quantities
112
113 Double_t fdNoffTot;
114 Double_t fdNoffSig;
115 Double_t fdNoffBg;
116
117 // Fitted quantities for OFF alpha distribution
118
119 Double_t fNoffTotFitted; // Total number of OFF events
120 Double_t fNoffSigFitted; // Number of OFF events in "signal" region
121 Double_t fNoffBgFitted; // Number of OFF events in "background" region
122
123 // errors for previous quantities
124
125 Double_t fdNoffTotFitted;
126 Double_t fdNoffSigFitted;
127 Double_t fdNoffBgFitted;
128
129
130 // Boolean variable used to disable the usage ("serious" usage) of the
131 // quantities computed from fits. This will be useful in those cases
132 // where there is too few events to perform a decent fit to the
133 // alpha histograms.
134
135 Bool_t fUseFittedQuantities;
136
137
138
139 // Bool variable used to decide wether to print or not the results
140 // of the fit, significance, Nex... onto the final alpha plot.
141 // for the time being, this variable is set in the constructor.
142 // At some point, I might make it such it can be set externally...
143
144 Bool_t fPrintResultsOntoAlphaPlot;
145
146
147 // effective number of background events
148 Double_t fNoff; // fNoff = fNoffSig * fNormFactor
149 Double_t fGamma; //
150 Double_t fNormFactor; // = TotalNon/TotalNoff)
151
152 Double_t fSigLiMa; // significance of gamma signal according to Li & Ma
153 // Computed using quantities fGama and Noff
154 // and formula (17)
155
156
157 Double_t fSigLiMa2; // significance of gamma signal according to Li & Ma
158 // Computed using quantities fNormFactor and fNoffSig
159 // and formula (17)
160
161 Double_t fSigLiMa3; // significance of gamma signal according to Li & Ma
162 // Computed using quantities fNormFactor and fNoffSig
163 // and formula (5)
164
165
166
167
168 const static Double_t fEps = 1.e-4; // tolerance for floating point comparisons
169
170 Bool_t fDraw; // if true : draw plots
171 Bool_t fSavePlots; // if true : Save plots in Psfile
172 Bool_t fFitGauss; // if true : do the (polynomial+Gauss fit)
173 Bool_t fRebin; // if true : allow rebinning of the alpha plot
174 Bool_t fReduceDegree; // if true : allow reducing of the order of the polynomial
175
176 Bool_t fConstantBackg; // if set true if background fit is not possible
177 // due to low statistics
178
179 TCanvas *fCanvas;
180
181 Double_t fNexGauss; // total number of excess events
182 // (from fitted Gauss function)
183 Double_t fdNexGauss; // error of the total number of excess events
184
185 Double_t fSigmaGauss; // sigma of fitted Gauss function
186 Double_t fdSigmaGauss; // error of this sigma
187
188 //--------------------
189 TF1 *fPoly; // polynomial function
190 Int_t fFitBad; // if != 0 fit failed
191 Int_t fDegree; // degree of polynomial to be fitted to the background
192 Int_t fNdf; // number of degrees of freedom of polynomial fit
193 Double_t fChisq; // chi squared of polynomial fit
194 Double_t fProb; // chi squared probability ofg polynomial fit
195
196 TArrayD fValues;
197 TArrayD fErrors;
198
199 const static Int_t fNdim = 6;
200 Double_t fEmat[fNdim][fNdim];
201 Double_t fEma [fNdim][fNdim];
202 Double_t fCorr[fNdim][fNdim];
203
204 Int_t fMbins; // number of bins in the fit range
205 Int_t fMlow; // number of bins in the fit range with too few entries
206 Int_t fNzero; // number of bins in the fit range with zero entry
207 Int_t fIstat;
208
209 //--------------------
210
211 // Fit to OFF data
212
213
214 TF1 *fPolyOFF; // polynomial function for OFF data
215
216 TF1 *fPolyOFFNormalized; // polynomial function for OFF data normalized with fNormFactor*(BinWidthON/BinWidthOFF)
217
218 Int_t fFitBadOFF; // if != 0 fit failed
219 Int_t fDegreeOFF; // degree of polynomial to be fitted to the background
220 Int_t fNdfOFF; // number of degrees of freedom of polynomial fit
221 Double_t fChisqOFF; // chi squared of polynomial fit
222 Double_t fProbOFF; // chi squared probability ofg polynomial fit
223
224 TArrayD fValuesOFF;
225 TArrayD fErrorsOFF;
226 TArrayD fValuesOFFNormalized;
227 TArrayD fErrorsOFFNormalized;
228
229 const static Int_t fNdimOFF = 6;
230 Double_t fEmatOFF[fNdim][fNdim];
231 Double_t fEmaOFF [fNdim][fNdim];
232 Double_t fCorrOFF[fNdim][fNdim];
233
234 Int_t fMbinsOFF; // number of bins in the fit range
235 Int_t fMlowOFF; // number of bins in the fit range with too few entries
236 Int_t fNzeroOFF; // number of bins in the fit range with zero entry
237 Int_t fIstatOFF;
238
239
240 //--------------------
241 TF1 *fGPoly; // (Gauss+polynomial) function
242 TF1 *fGBackg; // polynomial part of (Gauss+polynomial) function
243 Int_t fGFitBad; // if != 0 fit failed
244 Int_t fGDegree; // degree of polynomial to be fitted to the background
245 Int_t fGNdf; // number of degrees of freedom of polynomial fit
246 Double_t fGChisq; // chi squared of polynomial fit
247 Double_t fGProb; // chi squared probability ofg polynomial fit
248
249 TArrayD fGValues;
250 TArrayD fGErrors;
251
252 const static Int_t fGNdim = 9;
253 Double_t fGEmat[fGNdim][fGNdim];
254 Double_t fGEma[fGNdim][fGNdim];
255 Double_t fGCorr[fGNdim][fGNdim];
256
257 Int_t fGMbins; // number of bins in the fit range
258 Int_t fGNzero; // numnber of bins in the fit range with zero entry
259 Int_t fGIstat;
260
261 //--------------------
262
263 static const TString gsDefName; //! Default Name
264 static const TString gsDefTitle; //! Default Title
265
266 Bool_t DetExcess();
267 Bool_t DetExcessONOFF();
268 Bool_t FitPolynomial();
269 Bool_t FitPolynomialOFF();
270 Bool_t FitGaussPoly();
271 //Bool_t FitGaussPolyONOFF();
272 Bool_t RebinHistogram(Double_t x0, Int_t nrebin);
273 Bool_t RebinHistogramOFF(Double_t x0, Int_t nrebin);
274
275 public:
276 MHFindSignificanceONOFF(const char *name=NULL, const char *title=NULL);
277 ~MHFindSignificanceONOFF();
278
279
280 // fhistOFF is the alpha distribution of OFF data (after cuts),
281 // BUT NOT normalized. Normalization factor is also one of the
282 // arguments. Off alpha distribution will be normalized
283 // at the beginning of the function FindSigmaONOFF.
284
285 Bool_t FindSigmaONOFF(TH1 *fhistON, TH1 *fhistOFF,
286 Double_t NormFactor,
287 Double_t alphamin, Double_t alphamax,
288 Int_t degreeON, Int_t degreeOFF,
289 Double_t alphasig,
290 Bool_t drawpoly,
291 Bool_t fitgauss,
292 Bool_t print, Bool_t saveplots,
293 //TPostScript* PsFile
294 const TString psfilename);
295
296 // Set limits for the polynomial fit of the OFF data
297 // It will give the user the possibility of using,
298 // for the OFF data substraction, a fit in the region
299 // of interest. Might be useful in case of "pathological"
300 // alpha distribution for the OFF data.
301
302 void SetLimitsForOFFDataFit(Double_t Low, Double_t Up)
303 { fAlphaminOFF = Low; fAlphamaxOFF = Up; }
304
305 void SetAlphaSig (Double_t alphasig)
306 { fAlphasig = alphasig; }
307
308
309 void SetUseFittedQuantities (Bool_t b)
310 {fUseFittedQuantities = b;}
311
312
313 Bool_t SigmaLiMa(Double_t non, Double_t noff, Double_t gamma,
314 Double_t *siglima);
315
316 Bool_t SigmaLiMaForm5(Double_t non, Double_t noff, Double_t gamma,
317 Double_t *siglima);
318
319
320 Bool_t SigmaVsAlphaONOFF(TH1 *fhistON, TH1 *fhistOFF,
321 Double_t alphamin, Double_t alphamax,
322 Int_t degree, Bool_t print);
323
324
325
326 // Function that returns one of the 3 LiMa sigmas.
327 // The returned value is the one used in the optimization
328 // and final alpha plots.
329
330
331 Double_t GetSignificance();// { return fSigLiMa; }
332
333 Bool_t GetUseFittedQuantities() {return fUseFittedQuantities;}
334
335
336
337 // Following function computes a clone of fHistOFF and normalizes
338 // contents, errors and fPolyOFF (if exists) with the fNormFactor.
339 // This normalized OFF hist will be used when plotting OFF data
340 // together with ON data.
341
342 Bool_t ComputeHistOFFNormalized();
343
344
345 Bool_t DrawFit(Option_t *opt=NULL);
346
347 Bool_t DrawHistOFF();
348 Bool_t DrawHistOFFNormalized();
349
350 Float_t GetDegree() const { return fDegree; }
351 Float_t GetProb() const { return fProb; }
352 Float_t GetNdf() const { return fNdf; }
353 Float_t GetGamma() const { return fGamma; }
354 Float_t GetNon() const { return fNon; }
355 Float_t GetNex() const { return fNex; }
356 Float_t GetNbg() const { return fNbg; }
357 Float_t GetSigLiMa1() const { return fSigLiMa; }
358 Float_t GetSigLiMa2() const { return fSigLiMa2; }
359 Float_t GetSigLiMa3() const { return fSigLiMa3; }
360
361 Float_t GetMbins() const { return fMbins; }
362 Float_t GetAlphasi() const { return fAlphasi; }
363 Float_t GetNexONOFF() const {return fNexONOFF;}
364 Float_t GetNexONOFFFitted() const {return fNexONOFFFitted;}
365
366
367
368 void SetRebin(Bool_t b=kTRUE);
369 void SetReduceDegree(Bool_t b=kTRUE);
370
371 void SetPsFilename (TPostScript* PsFile) {fPsFilename = PsFile;}
372
373 void PrintPoly(Option_t *opt=NULL);
374 void PrintPolyOFF(Option_t *opt=NULL);
375 void PrintPolyGauss(Option_t *opt=NULL);
376
377 ClassDef(MHFindSignificanceONOFF, 1) // Determine significance from alpha plot
378};
379
380#endif
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
Note: See TracBrowser for help on using the repository browser.