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

Last change on this file since 4692 was 3439, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 7.7 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
35//
36// User change.
37//
38
39Float_t ctx[7] = {0., 0., 0., 0., 0., 0., 0.};
40Float_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
48void starmcstereo(Int_t ct1 = 2, Int_t ct2 = 5)
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 = "gam-yXX-00001.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 MSrcPosCam src[NCTs];
89 MBadPixelsCam badpix[NCTs];
90
91 for (Int_t ict = 0; ict < NCTs; ict++)
92 {
93 TString s = "MSrcPosCam;";
94 s += CT[ict];
95 src[ict].SetName(s);
96 src[ict].SetReadyToSave();
97 plist.AddToList(&(src[ict]));
98
99 TString b = "MBadPixelsCam;";
100 b += CT[ict];
101 badpix[ict].SetName(b);
102 badpix[ict].SetReadyToSave();
103 plist.AddToList(&(badpix[ict]));
104 }
105 //
106 // Now setup the tasks and tasklist:
107 // ---------------------------------
108 //
109 MReadMarsFile read("Events");
110 read.DisableAutoScheme();
111
112 read.AddFile(AnalysisFilename);
113
114 MGeomApply* apply = new MGeomApply[NCTs];
115
116 MMcPedestalCopy* pcopy = new MMcPedestalCopy[NCTs];
117
118 MExtractSignal* sigextract = new MExtractSignal[NCTs];
119
120 MMcCalibrationUpdate* mccalibupdate = new MMcCalibrationUpdate[NCTs];
121 MCalibrate* calib = new MCalibrate[NCTs];
122
123 MImgCleanStd** clean = new MImgCleanStd*[NCTs];
124
125 MHillasCalc* hcalc = new MHillasCalc[NCTs];
126 MHillasSrcCalc* scalc = new MHillasSrcCalc[NCTs];
127
128 TString outfile = "star_";
129 outfile += CT[0];
130 if (NCTs==2)
131 {
132 outfile += "_";
133 outfile += CT[1];
134 }
135
136 //
137 // We have two output files (will be later train and test sampls for random forest)
138 //
139 outfile += "_";
140 outfile += OutFileTag;
141 outfile += "_train.root";
142 MWriteRootFile write1(outfile);
143
144 outfile = "star_";
145 outfile += CT[0];
146 if (NCTs==2)
147 {
148 outfile += "_";
149 outfile += CT[1];
150 }
151
152 outfile += "_";
153 outfile += OutFileTag;
154 outfile += "_test.root";
155
156 MWriteRootFile write2(outfile);
157
158 for (Int_t i = 0; i < NCTs; i++)
159 {
160 apply[i]->SetSerialNumber(CT[i]);
161
162 pcopy[i]->SetSerialNumber(CT[i]);
163
164 sigextract[i]->SetSerialNumber(CT[i]);
165 sigextract[i].SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);
166
167 mccalibupdate[i]->SetSerialNumber(CT[i]);
168 calib[i]->SetSerialNumber(CT[i]);
169
170 clean[i] = new MImgCleanStd(CleanLev[0], CleanLev[1]);
171 clean[i]->SetSerialNumber(CT[i]);
172
173 hcalc[i]->SetSerialNumber(CT[i]);
174 scalc[i]->SetSerialNumber(CT[i]);
175
176 write1.SetSerialNumber(CT[i]);
177 write2.SetSerialNumber(CT[i]);
178
179 write1.AddContainer(write1.AddSerialNumber("MMcEvt"), "Events");
180 write1.AddContainer(write1.AddSerialNumber("MHillas"), "Events");
181 write1.AddContainer(write1.AddSerialNumber("MHillasExt"), "Events");
182 write1.AddContainer(write1.AddSerialNumber("MHillasSrc"), "Events");
183 write1.AddContainer(write1.AddSerialNumber("MNewImagePar"), "Events");
184 write1.AddContainer(write1.AddSerialNumber("MSrcPosCam"), "RunHeaders");
185 write2.AddContainer(write2.AddSerialNumber("MMcEvt"), "Events");
186 write2.AddContainer(write2.AddSerialNumber("MHillas"), "Events");
187 write2.AddContainer(write2.AddSerialNumber("MHillasExt"), "Events");
188 write2.AddContainer(write2.AddSerialNumber("MHillasSrc"), "Events");
189 write2.AddContainer(write2.AddSerialNumber("MNewImagePar"), "Events");
190 write2.AddContainer(write2.AddSerialNumber("MSrcPosCam"), "RunHeaders");
191 }
192
193 if (NCTs==2)
194 {
195 write1.AddContainer("MStereoPar", "Events");
196 write2.AddContainer("MStereoPar", "Events");
197 }
198
199 write1.AddContainer("MRawRunHeader", "RunHeaders");
200 write1.AddContainer("MMcRunHeader", "RunHeaders");
201
202 write2.AddContainer("MRawRunHeader", "RunHeaders");
203 write2.AddContainer("MMcRunHeader", "RunHeaders");
204
205 tlist.AddToList(&read);
206
207 for (i = 0; i < NCTs; i++)
208 {
209 tlist.AddToList(&(apply[i]));
210 tlist.AddToList(&(pcopy[i]));
211 tlist.AddToList(&(sigextract[i]));
212 tlist.AddToList(&(mccalibupdate[i]));
213 tlist.AddToList(&(calib[i]));
214 tlist.AddToList(clean[i]);
215 tlist.AddToList(&(hcalc[i]));
216 tlist.AddToList(&(scalc[i]));
217 }
218
219 MStereoCalc stereocalc;
220 stereocalc.SetCTids(CT[0],CT[1]);
221
222 //
223 // FIXME: telescope coordinates must be introduced by the user, since
224 // they are not available nor in the camera file, neither in the reflector
225 // output.
226 //
227
228 stereocalc.SetCT1coor(ctx[CT[0]-1],cty[CT[0]-1]);
229 stereocalc.SetCT2coor(ctx[CT[1]-1],cty[CT[1]-1]);
230
231 tlist.AddToList(&stereocalc);
232
233
234 MF filter1("{MMcEvt;1.fEvtNumber%2}<0.5");
235 MF filter2("{MMcEvt;1.fEvtNumber%2}>0.5");
236 //
237 // ^^^^ Filters to divide output in two: test and train samples.
238 //
239
240 write1.SetFilter (&filter1);
241 write2.SetFilter (&filter2);
242
243 tlist.AddToList(&filter1);
244 tlist.AddToList(&write1);
245 tlist.AddToList(&filter2);
246 tlist.AddToList(&write2);
247
248 //
249 // Create and set up the eventloop
250 //
251 MProgressBar bar;
252
253 MEvtLoop evtloop;
254 evtloop.SetProgressBar(&bar);
255 evtloop.SetParList(&plist);
256
257 //
258 // Execute your analysis
259 //
260 if (!evtloop.Eventloop())
261 return;
262
263 for (Int_t i= 0; i < NCTs; i++ )
264 delete clean[i];
265
266 tlist.PrintStatistics();
267}
Note: See TracBrowser for help on using the repository browser.