1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Abelardo Moralejo 1/2004 <mailto:moralejo@pd.infn.it>
|
---|
19 | ! Thomas Bretz, 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // STARMCSTEREO - STandard Analysis and Reconstruction (for MC stereo files)
|
---|
29 | //
|
---|
30 | // This macro is the standard converter to convert raw data from stereo
|
---|
31 | // camera simulation into image parameters
|
---|
32 | //
|
---|
33 | /////////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | //
|
---|
36 | // User change.
|
---|
37 | //
|
---|
38 |
|
---|
39 | Float_t ctx[7] = {0., 0., 0., 0., 0., 0., 0.};
|
---|
40 | Float_t cty[7] = {-70., -40., -30., 30., 50., 60., 70.}; // in meters
|
---|
41 | //
|
---|
42 | // FIXME: unfortunately present version of reflector was not prepared for
|
---|
43 | // stereo configurations and keeps no track of CT position. So the positions
|
---|
44 | // must be set above by the user, making sure that they correspond to the
|
---|
45 | // files one is analysing.
|
---|
46 | //
|
---|
47 |
|
---|
48 | void starmcstereo(Int_t ct1 = 1, Int_t ct2 = 2)
|
---|
49 | {
|
---|
50 | if (ct1 > sizeof(ctx)/sizeof(ctx[0]) ||
|
---|
51 | ct2 > sizeof(ctx)/sizeof(ctx[0]) )
|
---|
52 | {
|
---|
53 | cout << endl << "Wrong CT id number!" << endl;
|
---|
54 | return;
|
---|
55 | }
|
---|
56 |
|
---|
57 | Int_t CT[2] = {ct1, ct2}; // Only 2-telescope analysis for the moment
|
---|
58 | Int_t NCTs = sizeof(CT)/sizeof(CT[0]);
|
---|
59 |
|
---|
60 |
|
---|
61 | // ------------- user change -----------------
|
---|
62 |
|
---|
63 | Char_t* AnalysisFilename = "G_XX_*_w0.root"; // File to be analyzed
|
---|
64 | Char_t* OutFileTag = "gammas"; // Output file tag
|
---|
65 |
|
---|
66 | Float_t CleanLev[2] = {4., 3.}; // Tail cuts for image analysis
|
---|
67 |
|
---|
68 | Int_t BinsHigh[2] = {5, 9}; // First and last FADC bin of the range to be integrated,
|
---|
69 | Int_t BinsLow[2] = {5, 9}; // for high and low gain respectively.
|
---|
70 |
|
---|
71 | // -------------------------------------------
|
---|
72 |
|
---|
73 | //
|
---|
74 | // This is a demonstration program which calculates the image
|
---|
75 | // parameters from a Magic Monte Carlo root file. Units of Size are
|
---|
76 | // for the moment, FADC counts.
|
---|
77 | //
|
---|
78 | //
|
---|
79 | // Create a empty Parameter List and an empty Task List
|
---|
80 | // The tasklist is identified in the eventloop by its name
|
---|
81 | //
|
---|
82 | MParList plist;
|
---|
83 |
|
---|
84 | MTaskList tlist;
|
---|
85 |
|
---|
86 | plist.AddToList(&tlist);
|
---|
87 |
|
---|
88 | TString s = " MSrcPosCam;";
|
---|
89 | s += CT[0];
|
---|
90 | MSrcPosCam src1(s);
|
---|
91 | src1.SetReadyToSave();
|
---|
92 | plist.AddToList(&src1);
|
---|
93 |
|
---|
94 | if (NCTs==2)
|
---|
95 | {
|
---|
96 | s = " MSrcPosCam;";
|
---|
97 | s += CT[1];
|
---|
98 | MSrcPosCam src2(s);
|
---|
99 | src2.SetReadyToSave();
|
---|
100 | plist.AddToList(&src2);
|
---|
101 | }
|
---|
102 | //
|
---|
103 | // Now setup the tasks and tasklist:
|
---|
104 | // ---------------------------------
|
---|
105 | //
|
---|
106 | MReadMarsFile read("Events");
|
---|
107 | read.DisableAutoScheme();
|
---|
108 |
|
---|
109 | read.AddFile(AnalysisFilename);
|
---|
110 |
|
---|
111 | MGeomApply* apply = new MGeomApply[NCTs];
|
---|
112 |
|
---|
113 | MMcPedestalCopy* pcopy = new MMcPedestalCopy[NCTs];
|
---|
114 |
|
---|
115 | MExtractSignal* sigextract = new MExtractSignal[NCTs];
|
---|
116 |
|
---|
117 | MMcCalibrationUpdate* mccalibupdate = new MMcCalibrationUpdate[NCTs];
|
---|
118 | MCalibrate* calib = new MCalibrate[NCTs];
|
---|
119 |
|
---|
120 | MImgCleanStd** clean = new MImgCleanStd*[NCTs];
|
---|
121 |
|
---|
122 | MHillasCalc* hcalc = new MHillasCalc[NCTs];
|
---|
123 | MHillasSrcCalc* scalc = new MHillasSrcCalc[NCTs];
|
---|
124 |
|
---|
125 | TString outfile = "star_";
|
---|
126 | outfile += CT[0];
|
---|
127 | if (NCTs==2)
|
---|
128 | {
|
---|
129 | outfile += "_";
|
---|
130 | outfile += CT[1];
|
---|
131 | }
|
---|
132 |
|
---|
133 | //
|
---|
134 | // We have two output files (will be later train and test sampls for random forest)
|
---|
135 | //
|
---|
136 | outfile += "_";
|
---|
137 | outfile += OutFileTag;
|
---|
138 | outfile += "_train.root";
|
---|
139 | MWriteRootFile write1(outfile);
|
---|
140 |
|
---|
141 | outfile = "star_";
|
---|
142 | outfile += CT[0];
|
---|
143 | if (NCTs==2)
|
---|
144 | {
|
---|
145 | outfile += "_";
|
---|
146 | outfile += CT[1];
|
---|
147 | }
|
---|
148 |
|
---|
149 | outfile += "_";
|
---|
150 | outfile += OutFileTag;
|
---|
151 | outfile += "_test.root";
|
---|
152 |
|
---|
153 | MWriteRootFile write2(outfile);
|
---|
154 |
|
---|
155 | for (Int_t i = 0; i < NCTs; i++)
|
---|
156 | {
|
---|
157 | apply[i]->SetSerialNumber(CT[i]);
|
---|
158 |
|
---|
159 | pcopy[i]->SetSerialNumber(CT[i]);
|
---|
160 |
|
---|
161 | sigextract[i]->SetSerialNumber(CT[i]);
|
---|
162 | sigextract[i].SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);
|
---|
163 |
|
---|
164 | mccalibupdate[i]->SetSerialNumber(CT[i]);
|
---|
165 | calib[i]->SetSerialNumber(CT[i]);
|
---|
166 |
|
---|
167 | clean[i] = new MImgCleanStd(CleanLev[0], CleanLev[1]);
|
---|
168 | clean[i]->SetSerialNumber(CT[i]);
|
---|
169 |
|
---|
170 | hcalc[i]->SetSerialNumber(CT[i]);
|
---|
171 | scalc[i]->SetSerialNumber(CT[i]);
|
---|
172 |
|
---|
173 | write1.SetSerialNumber(CT[i]);
|
---|
174 | write2.SetSerialNumber(CT[i]);
|
---|
175 |
|
---|
176 | write1.AddContainer(write1.AddSerialNumber("MMcEvt"), "Events");
|
---|
177 | write1.AddContainer(write1.AddSerialNumber("MHillas"), "Events");
|
---|
178 | write1.AddContainer(write1.AddSerialNumber("MHillasExt"), "Events");
|
---|
179 | write1.AddContainer(write1.AddSerialNumber("MHillasSrc"), "Events");
|
---|
180 | write1.AddContainer(write1.AddSerialNumber("MNewImagePar"), "Events");
|
---|
181 | write1.AddContainer(write1.AddSerialNumber("MSrcPosCam"), "RunHeaders");
|
---|
182 | write2.AddContainer(write2.AddSerialNumber("MMcEvt"), "Events");
|
---|
183 | write2.AddContainer(write2.AddSerialNumber("MHillas"), "Events");
|
---|
184 | write2.AddContainer(write2.AddSerialNumber("MHillasExt"), "Events");
|
---|
185 | write2.AddContainer(write2.AddSerialNumber("MHillasSrc"), "Events");
|
---|
186 | write2.AddContainer(write2.AddSerialNumber("MNewImagePar"), "Events");
|
---|
187 | write2.AddContainer(write2.AddSerialNumber("MSrcPosCam"), "RunHeaders");
|
---|
188 | }
|
---|
189 |
|
---|
190 | if (NCTs==2)
|
---|
191 | {
|
---|
192 | write1.AddContainer("MStereoPar", "Events");
|
---|
193 | write2.AddContainer("MStereoPar", "Events");
|
---|
194 | }
|
---|
195 |
|
---|
196 | write1.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
197 | write1.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
198 |
|
---|
199 | write2.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
200 | write2.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
201 |
|
---|
202 | tlist.AddToList(&read);
|
---|
203 |
|
---|
204 | for (i = 0; i < NCTs; i++)
|
---|
205 | {
|
---|
206 | tlist.AddToList(&(apply[i]));
|
---|
207 | tlist.AddToList(&(pcopy[i]));
|
---|
208 | tlist.AddToList(&(sigextract[i]));
|
---|
209 | tlist.AddToList(&(mccalibupdate[i]));
|
---|
210 | tlist.AddToList(&(calib[i]));
|
---|
211 | tlist.AddToList(clean[i]);
|
---|
212 | tlist.AddToList(&(hcalc[i]));
|
---|
213 | tlist.AddToList(&(scalc[i]));
|
---|
214 | }
|
---|
215 |
|
---|
216 | MStereoCalc stereocalc;
|
---|
217 | stereocalc.SetCTids(CT[0],CT[1]);
|
---|
218 |
|
---|
219 | //
|
---|
220 | // FIXME: telescope coordinates must be introduced by the user, since
|
---|
221 | // they are not available nor in the camera file, neither in the reflector
|
---|
222 | // output.
|
---|
223 | //
|
---|
224 |
|
---|
225 | stereocalc.SetCT1coor(ctx[CT[0]-1],cty[CT[0]-1]);
|
---|
226 | stereocalc.SetCT2coor(ctx[CT[1]-1],cty[CT[1]-1]);
|
---|
227 |
|
---|
228 | tlist.AddToList(&stereocalc);
|
---|
229 |
|
---|
230 |
|
---|
231 | MF filter1("{MMcEvt;1.fEvtNumber%2}<0.5");
|
---|
232 | MF filter2("{MMcEvt;1.fEvtNumber%2}>0.5");
|
---|
233 | //
|
---|
234 | // ^^^^ Filters to divide output in two: test and train samples.
|
---|
235 | //
|
---|
236 |
|
---|
237 | write1.SetFilter (&filter1);
|
---|
238 | write2.SetFilter (&filter2);
|
---|
239 |
|
---|
240 | tlist.AddToList(&filter1);
|
---|
241 | tlist.AddToList(&write1);
|
---|
242 | tlist.AddToList(&filter2);
|
---|
243 | tlist.AddToList(&write2);
|
---|
244 |
|
---|
245 | //
|
---|
246 | // Create and set up the eventloop
|
---|
247 | //
|
---|
248 | MProgressBar bar;
|
---|
249 |
|
---|
250 | MEvtLoop evtloop;
|
---|
251 | evtloop.SetProgressBar(&bar);
|
---|
252 | evtloop.SetParList(&plist);
|
---|
253 |
|
---|
254 | //
|
---|
255 | // Execute your analysis
|
---|
256 | //
|
---|
257 | if (!evtloop.Eventloop())
|
---|
258 | return;
|
---|
259 |
|
---|
260 | for (Int_t i= 0; i < NCTs; i++ )
|
---|
261 | delete clean[i];
|
---|
262 |
|
---|
263 | tlist.PrintStatistics();
|
---|
264 | }
|
---|