source: trunk/MagicSoft/Mars/mtemp/mmpi/SupercutsONOFFClasses/MFindSupercutsONOFFThetaLoop.h@ 6724

Last change on this file since 6724 was 6355, checked in by mazin, 20 years ago
*** empty log message ***
File size: 14.8 KB
Line 
1#ifndef MARS_MFindSupercutsONOFFThetaLoop
2#define MARS_MFindSupercutsONOFFThetaLoop
3
4#ifndef MARS_MParContainer
5#include "MParContainer.h"
6#endif
7
8#ifndef ROOT_TArrayD
9#include <TArrayD.h>
10#endif
11#ifndef ROOT_TArrayI
12#include <TArrayI.h>
13#endif
14
15#ifndef ROOT_TH1F
16#include <TH1F.h>
17#endif
18
19#ifndef ROOT_TPostScript
20#include <TPostScript.h>
21#endif
22
23
24class MFilter;
25class MEvtLoop;
26class MH3;
27class MSupercutsCalcONOFF;
28class MFindSupercutsONOFF;
29class MGeomCam;
30class MHMatrix;
31
32
33class MFindSupercutsONOFFThetaLoop : public MParContainer
34{
35private:
36
37 TString fDataONRootFilename;
38 TString fDataOFFRootFilename;
39
40
41 TString fPathForFiles; // Path to directory where files (PsFiles, rootfiles) will be stored
42
43
44 TString* fOptSCParamFilenameVector; // Pointer to vector of TStrings containing name of the root files where optimized supercuts will be stored. To be created and filled once Vector of Costheta ranges is defined
45
46
47
48
49 // Vectors containing the names of the root files where matrices
50 // will be stored for Train/Test ON/OFF samples.
51 // To be defined and filled once vector fCosThetaRangeVector is
52 // defined
53
54 TString* fTrainMatrixONFilenameVector;
55 TString* fTestMatrixONFilenameVector;
56 TString* fTrainMatrixOFFFilenameVector;
57 TString* fTestMatrixOFFFilenameVector;
58
59
60 Double_t fAlphaSig; // Max alpha value were signal is expected
61
62
63 // Background range (in alpha) is defined by the member variables
64 // fAlphaBkgMin and fAlphaBkgMax
65 Double_t fAlphaBkgMin;
66 Double_t fAlphaBkgMax;
67
68
69 // Degree used in the polyinomial fits for ON and OFF data
70
71 Int_t fDegreeON;
72 Int_t fDegreeOFF;
73
74
75
76
77
78 // Size range of events used to fill the data matrices
79 // is defined by the following variables
80
81 Double_t fSizeCutLow;
82 Double_t fSizeCutUp;
83
84 Double_t fLeakMax;
85 Double_t fDistMax;
86 Double_t fDistMin;
87
88 // Variables for binning of alpha plots
89
90 Int_t fNAlphaBins;
91 Double_t fAlphaBinLow;
92 Double_t fAlphaBinUp;
93
94
95
96 // Boolean variable used to disable the usage ("serious" usage) of the
97 // quantities computed from fits. This will be useful in those cases
98 // where there is too few events to perform a decent fit to the
99 // alpha histograms. In general this variable will be always kTRUE
100
101 Bool_t fUseFittedQuantities;
102
103
104 Double_t fPolyGaussFitAlphaSigma;
105
106
107 Double_t fWhichFractionTrain; // number <= 1; specifying fraction of ON Train events
108 Double_t fWhichFractionTest; // number <= 1; specifying fraction of ON Test events
109
110 Double_t fWhichFractionTrainOFF; // number <= 1; specifying fraction of OFF Train events
111 Double_t fWhichFractionTestOFF; // number <= 1; specifying fraction of OFF Test events
112
113 Double_t fThetaMin; // Cuts in ThetaOrig.fVal (in rad!!!)
114 Double_t fThetaMax; // Cuts in ThetaOrig.fVal (in rad !!!)
115 TArrayD fCosThetaRangeVector; // vector containing the
116 // theta ranges that will be used in the
117 // optimization
118
119 TString* fThetaRangeStringVector; // Pointer to vector of TStrings that contain Cos theta ranges specified in fCosThetaRangeVector. It will be used to identify alpha distributions stored in fAlphaDistributionsRootFilename
120
121 TArrayD fCosThetaBinCenterVector; // vector containing the
122 // theta bin centers of the theta ranges/bins contained in
123 // fCosThetaRangeVector
124
125 Double_t fActualCosThetaBinCenter; // Theta value used to fill
126 // the histograms fNormFactorTrainHist, fNormFactorTestHist,
127 // fSigmaLiMaTrainHist ...
128
129
130
131 Double_t fOverallNexTrain;
132 Double_t fOverallNexTest;
133
134 Double_t fOverallSigmaLiMaTrain;
135 Double_t fOverallSigmaLiMaTest;
136
137
138 TH1F* fSuccessfulThetaBinsHist; // Hist containing theta bins were optimization was successful
139
140 TH1F* fNormFactorTrainHist; // Hist containing norm factors train for all Cos theta ranges
141 TH1F* fNormFactorTestHist; // Hist containing norm factors test for all Cos theta ranges
142 TH1F* fSigmaLiMaTrainHist; // Hist containing SigmaLiMa for Train samples for all Cos theta ranges
143 TH1F* fSigmaLiMaTestHist; // Hist containing SigmaLiMa for Test samples for all Cos theta ranges
144 TH1F* fNexTrainHist; // Hist containing Number os excess events for Train sample for all Cos thetas
145 TH1F* fNexTestHist; // Hist containing Number os excess events for Test sample for all Cos theta
146
147 TH1F* fNEvtsInTrainMatrixONHist; // Hist containing total number of events in Train Matrices of ON data for all Cos theta ranges
148 TH1F* fNEvtsInTestMatrixONHist; // Hist containing total number of events in Test Matrices of ON data for all Cos theta ranges
149 TH1F* fNEvtsInTrainMatrixOFFHist; // Hist containing total number of events in Train Matrices of OFF data for all Cos theta ranges
150 TH1F* fNEvtsInTestMatrixOFFHist; // Hist containing total number of events in Test Matrices of OFF data for all Cos theta ranges
151
152
153
154
155 // Boolean variable that controls wether the optimization of the
156 // parameters (MMinuitInterface::CallMinuit(..) in function FindParams(..))
157 // takes place or not. kTRUE will skip such optimization.
158 // This variable is useful to test the optmized parameters (previously found
159 // and stored in root file) on the TRAIN sample.
160
161 Bool_t fSkipOptimization;
162
163
164
165
166 // Boolean variable that allows the user to write the initial parameters
167 // into the root file that will be used to store the optimum cuts.
168 // If fUseInitialSCParams = kTRUE , parameters are written.
169 // In this way, the initial SC parameters can be applied on the data (train/test)
170
171 // The initial parameters are ONLY written to the root file if
172 // there is NO SC params optimization, i.e., if variable
173 // fSkipOptimization = kTRUE;
174
175 // The default value is obviously kFALSE.
176
177 Bool_t fUseInitialSCParams;
178
179
180 Double_t fGammaEfficiency; // Fraction of gammas that remain after cuts
181 // Quantity that will have to be determined with MC
182
183 Bool_t fTuneNormFactor; // If true, normalization factors are corrected
184 // using the estimated number of gammas and the gamma efficiency
185 // fNormFactor = fNormFactor - Ngammas/EventsInMatrixOFF
186
187
188 // Boolean variable used to determine wether the normalization factor is
189 // computed from method 1) or 2)
190 // 1) Using total number of ON and OFF events before cuts, and tuning the factor
191 // correcting for "contamination" of gamma events in ON sample
192 // 2) Using number of ON and OFF events after cuts in the background
193 // region determined by variables fAlphaBkgMin-fAlphaBkgMax
194
195 Bool_t fNormFactorFromAlphaBkg; // if kTRUE, method 2) is used
196
197
198 // Boolean variable used to control decide wether to use theta information
199 // in the computation of teh dynamical cuts.
200 Bool_t fNotUseTheta;
201
202 // Boolean variable used to decide wether to use dynamical cuts or static cuts
203 // kTRUE means that static cuts are used.
204 Bool_t fUseStaticCuts;
205
206
207 // Names for the Hadronness containers for ON and OFF data
208
209 TString fHadronnessName;
210 TString fHadronnessNameOFF;
211
212 // Vectors where initial SC parameters and steps are stored.
213 // If these vectors are empty, initial SC parameters and steps
214 // are taken from Supercuts container.
215 // They will be intialized to empty vectors in constructor
216
217 TArrayD fInitSCPar;
218 TArrayD fInitSCParSteps;
219
220
221
222 // Name of Postscript file where, for each theta bin, alpha ON and OFF distributions
223 // after cuts (and hence, Nex and SigmaLiMa computations) will be stored
224 // If fAlphaDistributionsPostScriptFilename is not defined, postscript file is not
225 // produced. It is an optional variable...
226
227 // Still not working...
228
229 TPostScript* fPsFilename;
230
231
232 // ********************************************************
233 // Due to the failure of the use of object TPostScript
234 // to make a Ps document with all plots, I decided to use the
235 // standard way (SaveAs(filename.ps)) to store plots related
236 // to alpha distributions
237 // for ON and OFF and BEFORE and AFTER cuts (VERY IMPORTANT
238 // TO COMPUTE EFFICIENCIES IN CUTS)
239
240 // Psfilename is set inside function LoopOverThetaRanges()
241 // and given to the object MFindSupercutsONOFF created
242 // within this loop.
243
244 // This will have to be removed as soon as the TPostScript
245 // solutions works...
246 // ********************************************************
247
248
249 TString fAlphaDistributionsRootFilename;
250 // Root file where histograms containing the ON alpha distribution and the
251 // OFF alpha distribution (non normalized) , AFTER CUTS, are stored.
252 // Histograms containing the normalization factors, Nex and SigmaLiMa for
253 // each theta bin will be also stored there.
254 // This name MUST be defined, since the histograms
255 // stored there will be used by
256 // function XXX to compute an overall Nex and sigmaLiMa
257 // combining all those histograms
258
259 // Boolean variables seting flags for loop over theta ranges
260
261 Bool_t fReadMatricesFromFile;
262 Bool_t fOptimizeParameters;
263 Bool_t fTestParameters;
264
265 //--------------------------------------------
266
267
268public:
269 MFindSupercutsONOFFThetaLoop(const char *name=NULL,
270 const char *title=NULL);
271 ~MFindSupercutsONOFFThetaLoop();
272
273 void SetHadronnessName(const TString &name)
274 {fHadronnessName = name;}
275 void SetHadronnessNameOFF(const TString &name)
276 {fHadronnessNameOFF = name;}
277
278 void SetPathForFiles(const TString &path)
279 {fPathForFiles = path;}
280
281 void SetDataONOFFRootFilenames(const TString &name1, const TString &name2 )
282 {fDataONRootFilename = name1; fDataOFFRootFilename = name2; }
283
284
285
286 // Names of root files containing matrices and optimizedparameters
287 Bool_t SetALLNames();
288
289 // Function to set names manually... in case matrices are
290 // already defined...
291
292 Bool_t SetNamesManually(TString* OptSCParamFilenameVector,
293 TString* ThetaRangeStringVector,
294 TString* TrainMatrixONFilenameVector,
295 TString* TestMatrixONFilenameVector,
296 TString* TrainMatrixOFFFilenameVector,
297 TString* TestMatrixOFFFilenameVector)
298
299 {
300 fOptSCParamFilenameVector = OptSCParamFilenameVector;
301 fThetaRangeStringVector = ThetaRangeStringVector;
302 fTrainMatrixONFilenameVector = TrainMatrixONFilenameVector;
303 fTestMatrixONFilenameVector = TestMatrixONFilenameVector;
304 fTrainMatrixOFFFilenameVector = TrainMatrixOFFFilenameVector;
305 fTestMatrixOFFFilenameVector = TestMatrixOFFFilenameVector;
306
307 return kTRUE;
308 }
309
310 Bool_t SetAlphaDistributionsRootFilename(const TString &name);
311
312
313 Bool_t SetAlphaSig (Double_t alphasig);
314
315 Bool_t SetAlphaBkgMin (Double_t alphabkgmin);
316 Bool_t SetAlphaBkgMax (Double_t alphabkgmax);
317
318
319 void SetDegreeON (Int_t d) {fDegreeON = d;}
320 void SetDegreeOFF (Int_t d) {fDegreeOFF = d;}
321
322 Bool_t CheckAlphaSigBkg();
323
324 void SetPostScriptFile(TPostScript* PsFile);
325
326
327 Bool_t SetCosThetaRangeVector (const TArrayD &d);
328
329 Bool_t SetThetaRange (Int_t thetabin);
330
331
332 void SetAlphaPlotBinining(Int_t nbins, Double_t binlow, Double_t binup)
333 { fNAlphaBins = nbins; fAlphaBinLow = binlow; fAlphaBinUp = binup;}
334
335 Bool_t SetNormFactorTrainHist();
336 Bool_t SetNormFactorTestHist();
337 Bool_t SetSigmaLiMaTrainHist();
338 Bool_t SetSigmaLiMaTestHist();
339 Bool_t SetNexTrainHist();
340 Bool_t SetNexTestHist();
341 Bool_t SetNexSigmaLiMaNormFactorNEvtsTrainTestHist();
342 Bool_t SetSuccessfulThetaBinsHist();
343 void WriteNexSigmaLiMaNormFactorNEvtsTrainTestHistToFile();
344
345 void WriteSuccessfulThetaBinsHistToFile();
346
347
348 Bool_t SetInitSCPar (TArrayD &d);
349 Bool_t SetInitSCParSteps (TArrayD &d);
350
351
352
353 Bool_t ReadSCParamsFromAsciiFile(const char* filename, Int_t Nparams);
354
355
356 void SetFractionTrainTestOnOffEvents(Double_t fontrain,
357 Double_t fontest,
358 Double_t fofftrain,
359 Double_t fofftest);
360
361 void SetTuneNormFactor(Bool_t b) {fTuneNormFactor = b;}
362 Bool_t SetGammaEfficiency (Double_t gammaeff);
363
364
365
366 void SetNormFactorFromAlphaBkg (Bool_t b) {fNormFactorFromAlphaBkg = b;}
367
368 void SetUseFittedQuantities (Bool_t b)
369 {fUseFittedQuantities = b;}
370
371 void SetReadMatricesFromFile(Bool_t b);
372 void SetTrainParameters(Bool_t b) {fOptimizeParameters = b;}
373 void SetTestParameters(Bool_t b) {fTestParameters = b;}
374
375
376 void SetSkipOptimization(Bool_t b) {fSkipOptimization = b;}
377
378 void SetUseInitialSCParams(Bool_t b) {fUseInitialSCParams = b;}
379
380
381 void SetVariableNotUseTheta(Bool_t b) {fNotUseTheta = b;}
382 Bool_t GetVariableNotUseTheta() { return fNotUseTheta;}
383
384
385 void SetVariableUseStaticCuts(Bool_t b) {fUseStaticCuts = b;}
386 Bool_t GetVariableUseStaticCuts() { return fUseStaticCuts;}
387
388
389 void SetSizeRange(Double_t SizeMin, Double_t SizeMax)
390 {fSizeCutLow = SizeMin; fSizeCutUp = SizeMax; }
391
392//DM:
393 void SetFilters(Double_t LeakageMax, Double_t DistMax, Double_t DistMin)
394 {fLeakMax = LeakageMax; fDistMax = DistMax; fDistMin = DistMin; }
395
396 // Function that loops over the theta ranges defined by
397 // fCosThetaRangeVector optimizing parameter and/or testing
398 // parameters
399
400 Bool_t LoopOverThetaRanges();
401
402
403 // Function that loops over the alpha distributions (ON-OFF)
404 // stored in root file defined by fAlphaDistributionsRootFilename
405 // and computes the significance and Nex (using MHFindSignificanceONOFF::FindSigma)
406 // for several cuts in alpha (0-fAlphaSig; in bins defined for alpha distributions
407 // by user).
408
409 // It creates the histograms, fills them and store them
410 // in root file defined by fAlphaDistributionsRootFilename. A single histogram
411 // for each theta bin.
412
413 // The function returns kFALSE if it could not accomplish its duty
414
415 Bool_t ComputeNexSignificanceVSAlphaSig();
416
417
418
419
420 // Function that gets the histograms with the alpha distributions
421 // (for all the theta bins specified by fCosThetaRangeVector)
422 // stored in fAlphaDistributionsRootFilename, and combine them
423 // (correcting OFF histograms with the normalization factors stored
424 // in NormFactorTrain or NormFactorTest) to get one single
425 // Alpha distribution for ON and another one for OFF.
426 // Then these histograms are given as arguments to
427 // the function MHFindSignificanceONOFF::FindSigmaONOFF,
428 // (Object of this class is created) to compute the
429 // Overall Excess events and significance, that will be
430 // stored in variables fOverallNexTrain and fOverallSigmaLiMaTrain
431 // and Test.
432
433
434
435 Bool_t ComputeOverallSignificance(Bool_t CombineTrainData,
436 Bool_t CombineTestData);
437
438
439 Double_t GetOverallNexTrain() {return fOverallNexTrain;}
440 Double_t GetOverallNexTest() {return fOverallNexTest;}
441
442 Double_t GetOverallSigmaLiMaTrain() {return fOverallSigmaLiMaTrain;}
443 Double_t GetOverallSigmaLiMaTest() {return fOverallSigmaLiMaTest;}
444
445 Double_t GetGammaEfficiency() {return fGammaEfficiency;}
446
447 Double_t GetAlphaSig() {return fAlphaSig;}
448 Double_t GetAlphaBkgMin () {return fAlphaBkgMin;}
449 Double_t GetAlphaBkgMax () {return fAlphaBkgMax;}
450
451 Int_t GetDegreeON () {return fDegreeON;}
452 Int_t GetDegreeOFF () {return fDegreeOFF;}
453
454
455 Bool_t GetSkipOptimization() {return fSkipOptimization;}
456
457 Bool_t GetUseFittedQuantities() {return fUseFittedQuantities;}
458
459 ClassDef(MFindSupercutsONOFFThetaLoop, 1)
460 // Class for optimization of the Supercuts
461};
462
463#endif
464
465
466
467
Note: See TracBrowser for help on using the repository browser.