source: trunk/MagicSoft/Mars/mtemp/mmpi/macros/SuperCutsONOFFMacroNew.C@ 6723

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