source: trunk/MagicSoft/Mars/macros/starmc.C@ 6718

Last change on this file since 6718 was 6403, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 9.0 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// STARMC - STandard Analysis and Reconstruction (MC example)
29//
30// This macro is a version of the standard converter to convert raw data
31// into image parameters, made to show how to run analysis on MC files.
32//
33/////////////////////////////////////////////////////////////////////////////
34
35#include "MImgCleanStd.h"
36
37void starmc()
38{
39 //
40 // This is a demonstration program which calculates the image
41 // parameters from Magic Monte Carlo files (output of camera).
42
43 TString* CalibrationFilename;
44 TString* OutFilename1;
45 TString* OutFilename2;
46
47 // ------------- user change -----------------
48 //
49 // Comment line starting "CalibrationFileName" to disable calibration. In that
50 // case the units of the MHillas.fSize parameter will be ADC counts (rather,
51 // equivalent ADC counts in inner pixels, since we correct for the possible
52 // differences in gain of outer pixels)
53 //
54 CalibrationFilename = new TString("/users/emc/moralejo/mcdata/Period021_0.73_mirror/gammas_nonoise/Gamma_zbin0_*.root");
55 // File to be used in the calibration (must be a camera file without added noise)
56
57
58 Char_t* AnalysisFilename = "Gamma_*w0.root"; // File to be analyzed
59
60
61
62 // ------------- user change -----------------
63 //
64 // Change output file names as desired. If you want only one output, comment
65 // the initialization of OutFilename2.
66
67 OutFilename1 = new TString("star_train.root"); // Output file name 1 (test)
68 OutFilename2 = new TString("star_test.root"); // Output file name 2 (train)
69 //
70 // Fraction of events (taken at random) which one wants to process from the
71 // file to be analyzed (useful to make smaller files if starting sample is
72 // too large).
73 //
74 Float_t accepted_fraction = 1.;
75
76 Float_t CleanLev[2] = {5., 4.};
77 // User change: tail cuts for image analysis
78
79 MImgCleanStd clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
80
81
82 // User change: signal extraction
83 //
84 // MExtractFixedWindowPeakSearch sigextract;
85 // sigextract.SetWindows(6, 6, 4);
86
87 MExtractTimeAndChargeDigitalFilter sigextract;
88 sigextract.SetNameWeightsFile("/users/emc/moralejo/Mars/msignal/MC_weights.dat");
89 sigextract.SetRange(1, 14, 3, 14);
90
91 ////////// Calibration //////////
92
93 MMcCalibrationUpdate mccalibupdate;
94 ///// User change: calibrate in photons or phe- :
95 mccalibupdate.SetSignalType(MCalibrateData::kPhe);
96 // mccalibupdate.SetSignalType(MCalibrateData::kPhot);
97
98
99 MSrcPosCam src;
100 //
101 // ONLY FOR WOBBLE MODE!!
102 // src.SetX(120.); // units: mm
103
104 src.SetReadyToSave();
105
106 // -------------------------------------------
107
108 //
109 // Create a empty Parameter List and an empty Task List
110 // The tasklist is identified in the eventloop by its name
111 //
112 MParList plist;
113
114 MTaskList tlist;
115
116 plist.AddToList(&tlist);
117
118 src.SetReadyToSave();
119 plist.AddToList(&src);
120
121 MBadPixelsCam badpix;
122 plist.AddToList(&badpix);
123
124
125 //
126 // Now setup the tasks and tasklist:
127 // ---------------------------------
128 //
129 MReadMarsFile read("Events");
130
131 if (CalibrationFilename)
132 read.AddFile(CalibrationFilename->Data());
133
134 read.DisableAutoScheme();
135
136 MGeomApply geom; // Reads in geometry from MC file and sets the right sizes for
137 // several parameter containers.
138
139 MMcPedestalCopy pcopy;
140 // Copies pedestal data from the MC file run fadc header to the MPedestalCam container.
141
142 MPointingPosCalc pointcalc;
143 // Creates MPointingPos object and fill it with the telescope orientation
144 // information taken from MMcEvt.
145
146 MCalibrateData calib; // Applies calibration to the data
147 calib.SetCalibrationMode(MCalibrateData::kFfactor);
148 // Do not change the CalibrationMode above for MC...!
149 calib.SetSignalType(mccalibupdate.GetSignalType());
150
151 // MBlindPixelCalc blind;
152 // blind.SetUseInterpolation();
153
154 MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
155 hcalc.Disable(MHillasCalc::kCalcHillasSrc);
156
157 MMcCalibrationCalc mccalibcalc;
158
159 tlist.AddToList(&read);
160 tlist.AddToList(&geom);
161 tlist.AddToList(&pcopy);
162 tlist.AddToList(&pointcalc);
163
164 tlist.AddToList(&sigextract);
165 tlist.AddToList(&mccalibupdate);
166 tlist.AddToList(&calib);
167 tlist.AddToList(&clean);
168 // tlist.AddToList(&blind);
169 tlist.AddToList(&hcalc);
170
171 tlist.AddToList(&mccalibcalc);
172
173 //
174 // Open output files:
175 //
176
177 MWriteRootFile write1(OutFilename1->Data()); // Writes output1
178 write1.AddContainer("MRawRunHeader", "RunHeaders");
179 write1.AddContainer("MMcRunHeader", "RunHeaders");
180 write1.AddContainer("MSrcPosCam", "RunHeaders");
181 write1.AddContainer("MGeomCam", "RunHeaders");
182 write1.AddContainer("MMcConfigRunHeader", "RunHeaders");
183 write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
184 write1.AddContainer("MMcFadcHeader", "RunHeaders");
185 write1.AddContainer("MMcTrigHeader", "RunHeaders");
186
187
188 write1.AddContainer("MMcEvt", "Events");
189 write1.AddContainer("MHillas", "Events");
190 write1.AddContainer("MHillasExt", "Events");
191 write1.AddContainer("MHillasSrc", "Events");
192 write1.AddContainer("MImagePar", "Events");
193 write1.AddContainer("MNewImagePar", "Events");
194 write1.AddContainer("MConcentration","Events");
195 write1.AddContainer("MPointingPos", "Events");
196
197 if (OutFilename2)
198 {
199 MWriteRootFile write2(OutFilename2->Data()); // Writes output2
200 write2.AddContainer("MRawRunHeader", "RunHeaders");
201 write2.AddContainer("MMcRunHeader", "RunHeaders");
202 write2.AddContainer("MSrcPosCam", "RunHeaders");
203 write2.AddContainer("MGeomCam", "RunHeaders");
204 write2.AddContainer("MMcConfigRunHeader", "RunHeaders");
205 write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
206 write2.AddContainer("MMcFadcHeader", "RunHeaders");
207 write2.AddContainer("MMcTrigHeader", "RunHeaders");
208
209
210 write2.AddContainer("MMcEvt", "Events");
211 write2.AddContainer("MHillas", "Events");
212 write2.AddContainer("MHillasExt", "Events");
213 write2.AddContainer("MHillasSrc", "Events");
214 write2.AddContainer("MImagePar", "Events");
215 write2.AddContainer("MNewImagePar", "Events");
216 write2.AddContainer("MConcentration","Events");
217 write2.AddContainer("MPointingPos", "Events");
218
219 //
220 // Divide output in train and test samples, using the event number
221 // (odd/even) to achieve otherwise unbiased event samples:
222 //
223
224 MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
225 MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
226
227 write1.SetFilter(&filter1);
228 write2.SetFilter(&filter2);
229 }
230
231 //
232 // First loop: Calibration loop
233 //
234
235 // MProgressBar bar;
236 // bar.SetWindowName("Calibrating...");
237
238 MEvtLoop evtloop;
239 // evtloop.SetProgressBar(&bar);
240 evtloop.SetParList(&plist);
241
242 if (CalibrationFilename)
243 {
244 if (!evtloop.Eventloop())
245 return;
246 mccalibcalc->GetHistADC2PhotEl()->Write();
247 mccalibcalc->GetHistPhot2PhotEl()->Write();
248 }
249
250 //
251 // Second loop: analysis loop
252 //
253
254 //
255 // Change the read task by another one which reads the file we want to analyze:
256 //
257
258 MReadMarsFile read2("Events");
259 read2.AddFile(AnalysisFilename);
260 read2.DisableAutoScheme();
261 tlist.AddToListBefore(&read2, &read);
262 tlist.RemoveFromList(&read);
263
264 //
265 // Analyzed only the desired fraction of events, skip the rest:
266 //
267 MFEventSelector eventselector;
268 Float_t rejected_fraction = 1. - accepted_fraction;
269 eventselector.SetSelectionRatio(rejected_fraction);
270 MContinue skip(&eventselector);
271 tlist.AddToListBefore(&skip, &sigextract);
272
273 // bar.SetWindowName("Analyzing...");
274
275 tlist.RemoveFromList(&mccalibcalc); // Removes calibration task from list.
276
277 hcalc.Enable(MHillasCalc::kCalcHillasSrc);
278
279 // Add tasks to write output:
280
281 if (OutFilename2)
282 {
283 tlist.AddToList(&filter1);
284 tlist.AddToList(&filter2);
285 tlist.AddToList(&write2);
286 }
287
288 tlist.AddToList(&write1);
289
290 if (!evtloop.Eventloop())
291 return;
292
293
294 tlist.PrintStatistics();
295}
Note: See TracBrowser for help on using the repository browser.