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