source: trunk/MagicSoft/Mars/mtemp/mmpi/macros/SuperCutsONOFFMacro.C@ 4998

Last change on this file since 4998 was 4412, checked in by paneque, 20 years ago
*** empty log message ***
File size: 12.9 KB
Line 
1// Silly macro to run the classes that optimize supercuts
2// using ON and OFF data.
3
4// The user only needs to fill/change the variables that control
5// the optimization procedure.
6
7
8gROOT -> Reset();
9
10void SuperCutsONOFFMacro()
11{
12 gLog.SetNoColors();
13
14 // File containing the data (ON/OFF DATA and path for files (root/ps))
15
16 // From magicserv01
17 TString ONDataFilename("/.magic/data16a/mazin/data/Mrk421/2004_04_22/4slices/Hillas_20040422_4sl_time_clean/Mrk421_*_HillasON.root");
18
19 TString OFFDataFilename("/.magic/data16a/mazin/data/Mrk421/2004_04_22/4slices/Hillas_20040422_4sl_time_clean/Mrk421_*_HillasOFF.root");
20
21
22 TString PathForFiles ("/mnt/magicserv01/scratch/David/SillyTestForCommiting_July20_2004/");
23
24
25 // **********************************************
26 // Boolean variables defining the job of the
27 // macro
28 // **********************************************
29
30
31
32 // Boolean variable that decides wether data is read from files specified above
33 // (ON/OFF) or read from already existing Matrices (which are obviously stored
34 // in a root file). The names of the files storing those matrices are produced
35 // automatically using information provided by some of the next variables whose
36 // values must be specified by user.
37
38 // kTRUE reads alredy existing matrices, and kFALSE read data and produce matrices.
39
40 Bool_t ReadMatrixFromRootFiles = kTRUE;
41
42
43 // Boolean variable that controls wether to use the
44 // TRAIN sample or not.
45
46
47 Bool_t TrainParams = kTRUE;
48
49
50
51 // Variable that allows the user to skip the optimization on the
52 // train sample. If optimization is skipped (value kTRUE), the
53 // previously optimized supercuts (stored in root file
54 // which is called OptSCParametersONOFFThetaRangeXXXXXmRad.root, and located
55 // in the directory specified by variable PathForFiles) are used
56 // on the train and/or the test sample.
57
58 // If value kFALSE, the cuts are optimized.
59 // The optimized cuts will be written in root file
60 // located in directory specified before. Name of
61 // the root files is created automatically.
62
63 Bool_t SkipOptimization = kTRUE;
64
65
66
67
68
69 // Boolean variable that allows the user to write the initial parameters
70 // into the root file that will be used to store the optimum cuts.
71 // If ApplyInitialParams = kTRUE , the initial
72 // parameters are written into this root file, and they
73 // will be applied to the data (TRAIN/TEST )
74 // IF NO OPTIMIZATION PROCEDURE IS PERFORMED.
75
76 // If cuts are optimized (ie, variable SkipOptimization = kFALSE),
77 // the cuts applied to the data are the optimized cuts.
78
79 // NOTE: be aware that, if ApplyInitialSCParams = kTRUE and
80 // there was a root file with the optimized cuts
81 // (previously computed), it will be overwritten with the initial
82 // SC parameters.
83
84 Bool_t ApplyInitialSCParams = kTRUE;
85
86
87
88 // Boolean variable that controls wether to use the
89 // TEST sample or not.
90
91
92 Bool_t TestParams = kFALSE;
93
94
95 // Boolean variable that controls wether to combine, OR not, the
96 // alpha distributions computed (after cuts) for the several theta bins
97 // in which the TRAIN sample was divided.
98
99 Bool_t CombineCosThetaBinsForTrainSample = kFALSE;
100
101 // Boolean variable that controls wether to combine, OR not, the
102 // alpha distribution computed (after cuts) for the several theta bins
103 // in which the TEST sample was divided.
104
105 Bool_t CombineCosThetaBinsForTestSample = kFALSE;
106
107
108 // Fraction of ON events used for the training/testing
109 Double_t whichfractiontrain = 0.999;
110 Double_t whichfractiontest = 0.001;
111
112 // Fraction of OFF events used for the training/testing
113 Double_t whichfractiontrainOFF = 0.999;
114 Double_t whichfractiontestOFF = 0.001;
115
116
117 // Efficiency for gammas when using this set of dynamical cuts
118 // (i.e., fraction of initial gammas that remain after cuts)
119
120 // Current value is the first estimation of the efficiency of cuts
121 // on Mkn421 at a SIZE > 2000 photons
122
123 Double_t gammaeff = 0.6;
124
125
126 // Alpha value (degrees) below which signal is expected
127
128 Double_t alphasig = 12;
129
130 // Definition of alpha bkg region (where no signal is expected)
131
132 Double_t alphabkgmin = 30;
133 Double_t alphabkgmax = 90;
134
135 // Definition of the Size range
136
137 Double_t SizeLow = 800;
138 Double_t SizeUp = 1200;
139// Double_t SizeUp = 1000000;
140
141
142 // Definition of binning of alpha plots
143 Int_t NAlphaBins = 35;
144 Double_t AlphaBinLow = -9;
145 Double_t AlphaBinUp = 96;
146
147
148 // Boolean variable used to determine wether the normalization factor is
149 // computed from method 1) or 2)
150 // 1) Using total number of ON and OFF events before cuts, and tuning the factor
151 // correcting for "contamination" of gamma events in ON sample
152 // 2) Using number of ON and OFF events after cuts in the background
153 // region determined by variables fAlphaBkgMin-fAlphaBkgMax
154
155 Bool_t NormFactorFromAlphaBkg = kTRUE; // if kTRUE, method 2) is used
156
157
158 // Boolean variable used to disable the usage ("serious" usage) of the
159 // quantities computed from fits. This will be useful in those cases
160 // where there is too few events to perform a decent fit to the
161 // alpha histograms.
162
163 Bool_t UseFittedQuantities = kTRUE;
164
165
166 // Boolean variable used to control wether to use theta information
167 // in the computation of teh dynamical cuts that take place within
168 // class MCT1SupercutsCalc
169 Bool_t NotUseTheta = kTRUE; // kTRUE renoves theta from the parameterization of cuts
170
171 // Boolean variable used to decide wether to use dynamical cuts or static cuts
172 // kTRUE means that static cuts are used.
173 Bool_t UseStaticCuts = kFALSE;
174
175
176
177
178
179 // Name of the Postscript document where all plots
180 // will be saved.
181 // STORAGE OF PSFILE IS NOT WORKING PROPERLY
182 // For the time being, several ps files are produced
183 // and saved in the directory specified by PathForFiles
184
185 /*
186 TString PsFileName = ("PsTest23.ps");
187 TString CompletePsFileName = (PathForFiles);
188 CompletePsFileName += PsFileName;
189 TPostScript* PsFile = new TPostScript(CompletePsFileName, 111);
190 */
191
192 // Boolean variable used to decide wether initial parameters are
193 // read from ascii file or not. If kTRUE, parameters are retrieved
194 // from ascii file. Otherwise, default parameters from MSupercuts
195 // class are used.
196
197 Bool_t ReadInitParamsFromAsciiFile = kTRUE;
198
199 // Number of SC parameters. The aim of this variable is to cross check
200 // that the number of parameters read from an ascii file
201 // is teh one the user wants.
202
203 Int_t NInitSCPar = 104;
204
205 // Name of the ascii file containing the 2 columns, the first one
206 // for initial parameters and the second one for the steps
207 // Name must contain also the path.
208
209 const char* InitSCParamAsciiFile =
210 // {"../InitialSCParametersSteps/InitSCParamsAndStepsDanielModified1.txt"};
211 // {"../InitialSCParametersSteps/FixedStaticCutsInLengthWidthDist.txt"};
212 // {"../InitialSCParametersSteps/FixedStaticCutsInLengthWidthDist11.txt"};
213 // {"../InitialSCParametersSteps/InitSCParamsAndStepsDanielModified1.txt"};
214 // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421.txt"};
215 // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynStaticCutsFixedPol2SizeCut3000.txt"};
216 // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynWithDistParametersFixed.txt"};
217 // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynStaticCutsVariablePol2.txt"};
218 // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynStaticCutsVariablePol2WidthCutLowFixed.txt"};
219 // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynCutsOnSize.txt"};
220 // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynCutsOnSizeAndDist.txt"};
221 {"mtemp/mmpi/asciifiles/OptimizedMkn421DynCutsGridWithSelected22pointsMay19.txt"};
222
223
224 // Name of the root file where alpha distributions, TTree objects
225 // with info about the events and cuts applied and info support histograms
226 // will be stored.
227 // Write only the name of the file. The Path
228 // is the one defined previously
229
230 TString RootFilename = ("RootFileDynCuts.root");
231
232
233
234
235
236
237 // Vector containing the theta bins in which data (ON/OFF train/test)
238 // will be divided. Actually this vector contains the cosinus of
239 // these theta bins. The dimension of the vector is N+1, where
240 // N is the number of theta bins intended. The first component of the
241 // vector is the low bin edge of the first bin, and the last
242 // vector component the upper bin edge of the last bin.
243
244
245 TArrayD CosThetaRangeVector(2);
246 CosThetaRangeVector[0] = 0.0;
247 //CosThetaRangeVector[1] = 0.825;
248 //CosThetaRangeVector[2] = 0.921;
249 //CosThetaRangeVector[3] = 0.961;
250 CosThetaRangeVector[1] = 1.0;
251
252
253 /*
254 TArrayD CosThetaRangeVector(2);
255 CosThetaRangeVector[0] = 0.622;
256 // CosThetaRangeVector[1] = 0.825;
257 //CosThetaRangeVector[2] = 0.921;
258 //CosThetaRangeVector[0] = 0.961;
259 CosThetaRangeVector[1] = 0.984;
260
261 */
262 // Object of MCT1FindSupercutsONOFFThetaLoop created, data that was specified
263 // above is introduced and ... and the party starts.
264
265 MFindSupercutsONOFFThetaLoop FindSupercuts("MFindSupercutsONOFFThetaLoop",
266 "Optimizer for the supercuts");
267
268
269 FindSupercuts.SetPathForFiles(PathForFiles);
270
271 FindSupercuts.SetDataONOFFRootFilenames(ONDataFilename, OFFDataFilename);
272
273 FindSupercuts.SetFractionTrainTestOnOffEvents(whichfractiontrain,
274 whichfractiontest,
275 whichfractiontrainOFF,
276 whichfractiontestOFF);
277
278
279 FindSupercuts.SetGammaEfficiency(gammaeff);
280
281
282 FindSupercuts.SetAlphaSig(alphasig);
283
284 // Bkg alpha region is set
285 FindSupercuts.SetAlphaBkgMin(alphabkgmin);
286 FindSupercuts.SetAlphaBkgMax(alphabkgmax);
287
288 // alpha bkg and signal region set in object FindSupercuts
289 // are re-checked in order to be sure that make sense
290
291 FindSupercuts.CheckAlphaSigBkg();
292
293
294 // binning for alpha plots is defined
295
296 FindSupercuts.SetAlphaPlotBinining(NAlphaBins, AlphaBinLow,
297 AlphaBinUp);
298
299
300
301
302 // Size range is defined
303
304 FindSupercuts.SetSizeRange(SizeLow, SizeUp);
305
306
307
308 FindSupercuts.SetNormFactorFromAlphaBkg(NormFactorFromAlphaBkg);
309
310 FindSupercuts.SetUseFittedQuantities(UseFittedQuantities);
311
312 FindSupercuts.SetVariableUseStaticCuts(UseStaticCuts);
313
314 FindSupercuts.SetVariableNotUseTheta(NotUseTheta);
315
316 FindSupercuts.SetReadMatricesFromFile(ReadMatrixFromRootFiles);
317
318 FindSupercuts.SetTrainParameters(TrainParams);
319 FindSupercuts.SetSkipOptimization(SkipOptimization);
320 FindSupercuts.SetUseInitialSCParams(ApplyInitialSCParams);
321
322 FindSupercuts.SetTestParameters(TestParams);
323
324
325
326 FindSupercuts.SetHadronnessName("MHadSC");
327 FindSupercuts.SetHadronnessNameOFF("MHadOFFSC");
328
329 FindSupercuts.SetAlphaDistributionsRootFilename (RootFilename);
330
331 // FindSupercuts.SetPostScriptFile (PsFile);
332
333 FindSupercuts.SetCosThetaRangeVector (CosThetaRangeVector);
334
335
336 // Names for all root files (matrices, alpha distributions...)
337 // are created
338 FindSupercuts.SetALLNames();
339
340 if(ReadInitParamsFromAsciiFile)
341 {
342 // Initial SC Parameters and steps are retrieved from
343 // Ascii file
344 if(!FindSupercuts.ReadSCParamsFromAsciiFile(InitSCParamAsciiFile,
345 NInitSCPar))
346 {
347 cout << "Initial SC Parameters could not be read from Ascii file "
348 << InitSCParamAsciiFile << endl
349 << "Aborting execution of macro... " << endl;
350 return;
351
352 }
353 }
354
355
356
357
358 // Finally loop over all theta bins defined is executed
359
360 if (!FindSupercuts.LoopOverThetaRanges())
361 {
362 cout << "Function MFindSupercutsONOFFThetaLoop::LoopOverThetaRanges()" << endl
363 << "could not be performed" << endl;
364
365 }
366
367
368
369 // Nex and Significance are computed vs alphasig
370
371 if (!FindSupercuts.ComputeNexSignificanceVSAlphaSig())
372 {
373 cout << "Function MFindSupercutsONOFFThetaLoop::ComputeNexSignificanceVSAlphaSig()" << endl
374 << "could not be performed" << endl;
375
376
377 }
378
379
380
381
382 // Option to store ps files in a single ps document is still not working
383 /*
384 PsFile -> Close();
385 PsFile = NULL;
386 */
387
388 // Several theta bins are combined to produced a single alpha plot (for train and test)
389 // with single Nex and significances
390
391 if (CombineCosThetaBinsForTrainSample || CombineCosThetaBinsForTestSample)
392 {
393 if(!FindSupercuts.ComputeOverallSignificance(CombineCosThetaBinsForTrainSample,
394 CombineCosThetaBinsForTestSample))
395 {
396 cout << "Function MFindSupercutsONOFFThetaLoop::ComputeOverallSignificance" << endl
397 << "could not be performed" << endl;
398 }
399
400
401 }
402
403
404
405}
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
Note: See TracBrowser for help on using the repository browser.