1 | /*############################################################################
|
---|
2 | #
|
---|
3 | # How to use:
|
---|
4 | #
|
---|
5 | # - 1. From a hillas file select a training subsample, for a given size
|
---|
6 | # range, with will be write into a MHMatrix. The the matrix will be read
|
---|
7 | # and the optimization will start.
|
---|
8 | # Once you've created the matrix you can set to false GenerateTrainMatrix
|
---|
9 | # and start directly the optimization from reading the matrix.
|
---|
10 | #
|
---|
11 | # - 2. It is recomended to start optimazing the static cuts and then, the
|
---|
12 | # dinanical cuts, this can be done:
|
---|
13 | # -seting in 'TString initParams' the name of the previous optimization
|
---|
14 | # results.
|
---|
15 | # -and using the the funtion MMyFindSuperCuts.SetOptimizationMode(Mode)
|
---|
16 | #
|
---|
17 | # The supercuts function used is:
|
---|
18 | #
|
---|
19 | # Length_low = par[0]*S1 + par[1]*S2 +par[2]*ZA +par[3]*dist*dist
|
---|
20 | # Length_up = par[4]*S1 + par[5]*S2 +par[6]*ZA +par[7]*dist*dist
|
---|
21 | # ....
|
---|
22 | # and simiar with: Width, Dist,Asym, Conc, Leakage
|
---|
23 | #
|
---|
24 | # where S1 = log(size)-log(LowerSizeCut)
|
---|
25 | # S2 = S1*S1
|
---|
26 | # ZA = cos(theta/kRad2Deg) - 1;
|
---|
27 | #
|
---|
28 | # NOTE: Currently with neglect ZA depence, so we put ZA = 0;
|
---|
29 | # -----
|
---|
30 | #
|
---|
31 | # The optimization modes are:
|
---|
32 | #
|
---|
33 | # Mode 0 = optimize only supercuts params,i.e.
|
---|
34 | # only optimaze par0, par4, par8,..
|
---|
35 | # 1 = optimize only dynamical params, i.e.
|
---|
36 | # all but par0, par4, par8
|
---|
37 | # other = optimize all the params at the same time.
|
---|
38 | #
|
---|
39 | #
|
---|
40 | # Warning: Some times Minuit fails to converge, or its take too long. Then,
|
---|
41 | # it's better to try again with diferent nuumber of parameter,
|
---|
42 | # initial values or stepsizes.
|
---|
43 | #
|
---|
44 | # author: Marcos Lopez
|
---|
45 | # email: marcos@gae.ucm.es
|
---|
46 | ###########################################################################*/
|
---|
47 |
|
---|
48 |
|
---|
49 | Bool_t GenerateTrainMatrix = kTRUE;
|
---|
50 |
|
---|
51 | void OptimizeSuperCuts()
|
---|
52 | {
|
---|
53 |
|
---|
54 | // --- Input -----------------------------------------
|
---|
55 |
|
---|
56 | Int_t Mode = 0;
|
---|
57 | Double_t SizeCutLow = 2000;
|
---|
58 | Double_t SizeCutUp = 1e7;
|
---|
59 |
|
---|
60 | // Hillas file
|
---|
61 | TString datafile = "~/MAGIC/data/Period022/2004_10_10/CrabNebula_20041010_6_30-25.hillas.root";
|
---|
62 |
|
---|
63 | // Intermediate file to speed up otpimization (from the original hillas
|
---|
64 | //file, a given number of events in a given size cut range will be stored
|
---|
65 | //in a MHatrix)
|
---|
66 | TString matrixfile = "SC_matrix.150k.root"; // matrix with the
|
---|
67 |
|
---|
68 | // Output file where the supercuts parameters wiil be saved
|
---|
69 | TString outfile = "SC.150k.Above2000.root";
|
---|
70 |
|
---|
71 |
|
---|
72 | // File with the starting supercuts parameters (if any)
|
---|
73 | //
|
---|
74 | //TString initParams="~/MAGIC/results/SuperCutsParams/AllDynCutsParams_Above2000ph.150k.CrabNebula_20041010_6_30-25.root";
|
---|
75 | TString initParams="";
|
---|
76 |
|
---|
77 | // Number of train events to use from hillas file
|
---|
78 | Int_t howmany = 150000;
|
---|
79 |
|
---|
80 | MH3 h3("");
|
---|
81 |
|
---|
82 |
|
---|
83 | //
|
---|
84 | // fStepsizes
|
---|
85 | // if == 0.0 the parameter will be fixed in the minimization
|
---|
86 | // != 0.0 initial step sizes for the parameters
|
---|
87 | //
|
---|
88 | TArrayD fStepsizes(48);
|
---|
89 |
|
---|
90 | // LengthUp
|
---|
91 | fStepsizes[0] = 0.1;
|
---|
92 | fStepsizes[1] = 0.1;
|
---|
93 | fStepsizes[2] = 0.1;
|
---|
94 | fStepsizes[3] = 0.1;
|
---|
95 | // LengthLo
|
---|
96 | fStepsizes[4] = 0.1;
|
---|
97 | fStepsizes[5] = 0.1;
|
---|
98 | fStepsizes[6] = 0.1;
|
---|
99 | fStepsizes[7] = 0.1;
|
---|
100 | // WidthUp
|
---|
101 | fStepsizes[8] = 0.1;
|
---|
102 | fStepsizes[9] = 0.1;
|
---|
103 | fStepsizes[10] = 0.1;
|
---|
104 | fStepsizes[11] = 0.1;
|
---|
105 | // WidthLo
|
---|
106 | fStepsizes[12] = 0.1;
|
---|
107 | fStepsizes[13] = 0.1;
|
---|
108 | fStepsizes[14] = 0.1;
|
---|
109 | fStepsizes[15] = 0.1;
|
---|
110 | // DistUp
|
---|
111 | fStepsizes[16] = 0.1;
|
---|
112 | fStepsizes[17] = 0.1;
|
---|
113 | fStepsizes[18] = 0.1;
|
---|
114 | fStepsizes[19] = 0.;
|
---|
115 | // DistLo
|
---|
116 | fStepsizes[20] = 0.1;
|
---|
117 | fStepsizes[21] = 0.1;
|
---|
118 | fStepsizes[22] = 0.1;
|
---|
119 | fStepsizes[23] = 0.;
|
---|
120 |
|
---|
121 | for(int i=24;i<48;i++)
|
---|
122 | fStepsizes[i] = .0;
|
---|
123 |
|
---|
124 | //------------------------------------------------------
|
---|
125 |
|
---|
126 |
|
---|
127 | MMyFindSuperCuts a;
|
---|
128 | a.SetHadronnessName("MHadronness");
|
---|
129 | a.SetFilenameParam(outfile);
|
---|
130 | a.SetSizeCuts(SizeCutLow, SizeCutUp);
|
---|
131 |
|
---|
132 | if(GenerateTrainMatrix)
|
---|
133 | a.DefineTrainMatrix(datafile, h3 ,howmany, matrixfile);
|
---|
134 |
|
---|
135 |
|
---|
136 | a.ReadMatrix(matrixfile,"");
|
---|
137 | a.SetOptimizationMode(Mode);
|
---|
138 |
|
---|
139 |
|
---|
140 | //
|
---|
141 | // Start optimization
|
---|
142 | //
|
---|
143 | a.FindParams(initParams,0,fStepsizes);
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|