source: trunk/MagicSoft/Mars/macros/starmcstereo.C@ 3254

Last change on this file since 3254 was 2908, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 7.9 KB
Line 
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
35void starmcstereo(Int_t ct1 = 2, Int_t ct2 = 3)
36{
37 Int_t CT[2] = {ct1, ct2};
38
39 Int_t NCTs = sizeof(CT)/sizeof(CT[0]);
40
41
42 // ------------- user change -----------------
43
44 Char_t* AnalysisFilename = "G_XX_*_w0.root"; // File to be analyzed
45 Char_t* OutFileTag = "gammas"; // Output file tag
46
47 Float_t CleanLev[2] = {4., 3.}; // Tail cuts for image analysis
48
49 Int_t BinsHigh[2] = {0, 5}; // First and last FADC bin of the range to be integrated,
50 Int_t BinsLow[2] = {0, 5}; // for high and low gain respectively.
51
52 // -------------------------------------------
53
54 //
55 // This is a demonstration program which calculates the image
56 // parameters from a Magic Monte Carlo root file. Units of Size are
57 // for the moment, FADC counts.
58 //
59 //
60 // Create a empty Parameter List and an empty Task List
61 // The tasklist is identified in the eventloop by its name
62 //
63 MParList plist;
64
65 MTaskList tlist;
66
67 plist.AddToList(&tlist);
68
69 TString s = " MSrcPosCam;";
70 s += CT[0];
71 MSrcPosCam src1(s);
72 src1.SetReadyToSave();
73 plist.AddToList(&src1);
74
75 if (NCTs==2)
76 {
77 s = " MSrcPosCam;";
78 s += CT[1];
79 MSrcPosCam src2(s);
80 src2.SetReadyToSave();
81 plist.AddToList(&src2);
82 }
83 //
84 // Now setup the tasks and tasklist:
85 // ---------------------------------
86 //
87 MReadMarsFile read("Events");
88 read.DisableAutoScheme();
89
90 read.AddFile(AnalysisFilename);
91
92 MGeomApply* apply = new MGeomApply[NCTs];
93
94 MMcPedestalCopy* pcopy = new MMcPedestalCopy[NCTs];
95
96 MExtractSignal* sigextract = new MExtractSignal[NCTs];
97
98 MMcCalibrationUpdate* mccalibupdate = new MMcCalibrationUpdate[NCTs];
99 MCalibrate* calib = new MCalibrate[NCTs];
100
101 MImgCleanStd** clean = new MImgCleanStd*[NCTs];
102
103 MHillasCalc* hcalc = new MHillasCalc[NCTs];
104 MHillasSrcCalc* scalc = new MHillasSrcCalc[NCTs];
105
106 TString outfile = "star_";
107 outfile += CT[0];
108 if (NCTs==2)
109 {
110 outfile += "_";
111 outfile += CT[1];
112 }
113
114 //
115 // We have two output files (will be later train and test sampls for random forest)
116 //
117 outfile += "_";
118 outfile += OutFileTag;
119 outfile += "_train.root";
120 MWriteRootFile write1(outfile);
121
122 outfile = "star_";
123 outfile += CT[0];
124 if (NCTs==2)
125 {
126 outfile += "_";
127 outfile += CT[1];
128 }
129
130 outfile += "_";
131 outfile += OutFileTag;
132 outfile += "_test.root";
133
134 MWriteRootFile write2(outfile);
135
136 for (Int_t i = 0; i < NCTs; i++)
137 {
138 apply[i]->SetSerialNumber(CT[i]);
139
140 pcopy[i]->SetSerialNumber(CT[i]);
141
142 sigextract[i]->SetSerialNumber(CT[i]);
143 sigextract[i].SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);
144
145 mccalibupdate[i]->SetSerialNumber(CT[i]);
146 calib[i]->SetSerialNumber(CT[i]);
147
148 clean[i] = new MImgCleanStd(CleanLev[0], CleanLev[1]);
149 clean[i]->SetSerialNumber(CT[i]);
150
151 hcalc[i]->SetSerialNumber(CT[i]);
152 scalc[i]->SetSerialNumber(CT[i]);
153
154 write1.SetSerialNumber(CT[i]);
155 write2.SetSerialNumber(CT[i]);
156
157 write1.AddContainer(write1.AddSerialNumber("MMcEvt"), "Events");
158 write1.AddContainer(write1.AddSerialNumber("MHillas"), "Events");
159 write1.AddContainer(write1.AddSerialNumber("MHillasExt"), "Events");
160 write1.AddContainer(write1.AddSerialNumber("MHillasSrc"), "Events");
161 write1.AddContainer(write1.AddSerialNumber("MNewImagePar"), "Events");
162 write1.AddContainer(write1.AddSerialNumber("MSrcPosCam"), "RunHeaders");
163 write2.AddContainer(write2.AddSerialNumber("MMcEvt"), "Events");
164 write2.AddContainer(write2.AddSerialNumber("MHillas"), "Events");
165 write2.AddContainer(write2.AddSerialNumber("MHillasExt"), "Events");
166 write2.AddContainer(write2.AddSerialNumber("MHillasSrc"), "Events");
167 write2.AddContainer(write2.AddSerialNumber("MNewImagePar"), "Events");
168 write2.AddContainer(write2.AddSerialNumber("MSrcPosCam"), "RunHeaders");
169 }
170
171 if (NCTs==2)
172 {
173 write1.AddContainer("MStereoPar", "Events");
174 write2.AddContainer("MStereoPar", "Events");
175 }
176
177 write1.AddContainer("MRawRunHeader", "RunHeaders");
178 write1.AddContainer("MMcRunHeader", "RunHeaders");
179
180 write2.AddContainer("MRawRunHeader", "RunHeaders");
181 write2.AddContainer("MMcRunHeader", "RunHeaders");
182
183 tlist.AddToList(&read);
184
185 for (i = 0; i < NCTs; i++)
186 {
187 tlist.AddToList(&(apply[i]));
188 tlist.AddToList(&(pcopy[i]));
189 tlist.AddToList(&(sigextract[i]));
190 tlist.AddToList(&(mccalibupdate[i]));
191 tlist.AddToList(&(calib[i]));
192 tlist.AddToList(clean[i]);
193 tlist.AddToList(&(hcalc[i]));
194 tlist.AddToList(&(scalc[i]));
195 }
196
197 MStereoCalc stereocalc;
198 stereocalc.SetCTids(CT[0],CT[1]);
199
200 //
201 // FIXME: telescope coordinates must be introduced by the user, since
202 // they are not available nor in the camera file, neither in the reflector
203 // output.
204 //
205
206 if (CT[0] == 1)
207 stereocalc.SetCT1coor(0.,0.);
208 else if (CT[0] == 2)
209 stereocalc.SetCT1coor(0.,0.);
210 else if (CT[0] == 3)
211 stereocalc.SetCT1coor(60.,60.); // in meters
212 else if (CT[0] == 4)
213 stereocalc.SetCT1coor(60.,-60.);
214 else if (CT[0] == 5)
215 stereocalc.SetCT1coor(-60.,60.);
216 else if (CT[0] == 6)
217 stereocalc.SetCT1coor(-60.,-60.);
218 else
219 {
220 cout << "Unknown CT id!" << endl;
221 exit;
222 }
223
224 if (NCTs==2)
225 {
226 if (CT[1] == 1)
227 stereocalc.SetCT2coor(0.,0.);
228 else if (CT[1] == 2)
229 stereocalc.SetCT2coor(0.,0.);
230 else if (CT[1] == 3)
231 stereocalc.SetCT2coor(60.,60.); // in meters
232 else if (CT[1] == 4)
233 stereocalc.SetCT2coor(60.,-60.);
234 else if (CT[1] == 5)
235 stereocalc.SetCT2coor(-60.,60.);
236 else if (CT[1] == 6)
237 stereocalc.SetCT2coor(-60.,-60.);
238 else
239 {
240 cout << "Unknown CT id!" << endl;
241 exit;
242 }
243
244 tlist.AddToList(&stereocalc);
245 }
246
247 MF filter1("MMcEvt;1.fEvtNumber<2501");
248 MF filter2("MMcEvt;1.fEvtNumber>2500");
249 //
250 // ^^^^ Filters to divide output in two: test and train samples.
251 // FIXME: It is better to separate the events in odd and even
252 // event numbers (it is independent of the number of events in
253 // the file), but it is not yet possible because we cannot use
254 // the modulus operator(%) in the filter yet.
255 //
256
257 write1.SetFilter (&filter1);
258 write2.SetFilter (&filter2);
259
260 tlist.AddToList(&filter1);
261 tlist.AddToList(&write1);
262 tlist.AddToList(&filter2);
263 tlist.AddToList(&write2);
264
265 //
266 // Create and set up the eventloop
267 //
268 MProgressBar bar;
269
270 MEvtLoop evtloop;
271 evtloop.SetProgressBar(&bar);
272 evtloop.SetParList(&plist);
273
274 //
275 // Execute your analysis
276 //
277 if (!evtloop.Eventloop())
278 return;
279
280 for (Int_t i= 0; i < NCTs; i++ )
281 delete clean[i];
282
283 tlist.PrintStatistics();
284}
Note: See TracBrowser for help on using the repository browser.