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

Last change on this file since 7068 was 7005, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.4 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("/data1/magic/mc_data/root/Period025/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_zbin1_0_*.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 // USER CHANGE: tail cuts for image analysis
77
78 Float_t CleanLev[2] = {7., 5.};
79 MImgCleanStd clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
80 clean.SetMethod(MImgCleanStd::kAbsolute); // In absolute units (phot or phe- as chosen below)
81
82
83 // USER CHANGE: signal extraction
84 //
85 // MExtractFixedWindowPeakSearch sigextract;
86 // sigextract.SetWindows(6, 6, 4);
87
88 // MExtractTimeAndChargeDigitalFilter sigextract;
89 // sigextract.SetNameWeightsFile("/users/emc/moralejo/Mars/msignal/MC_weights.dat");
90 // sigextract.SetRange(1, 14, 3, 14);
91
92 MExtractTimeAndChargeSpline sigextract;
93 sigextract.SetRiseTimeHiGain(0.5);
94 sigextract.SetFallTimeHiGain(0.5);
95
96 // USER CHANGE: high to low gain ratio. DEPENDS on EXTRACTOR!!
97 // One should calculate somewhere else what this factor is for each extractor!
98 Float_t hi2low = 12.; // tentative value for spline with risetime 0.5, fall time 0.5
99
100
101 ////////// Calibration //////////
102 MMcCalibrationUpdate mccalibupdate;
103 mccalibupdate.SetUserLow2HiGainFactor(hi2low);
104
105 ///// USER CHANGE: calibrate in photons or phe- :
106 mccalibupdate.SetSignalType(MCalibrateData::kPhe);
107 // mccalibupdate.SetSignalType(MCalibrateData::kPhot);
108
109
110 MSrcPosCam src;
111 //
112 // ONLY FOR WOBBLE MODE!!
113 // src.SetX(120.); // units: mm
114
115 src.SetReadyToSave();
116
117 // -------------------------------------------
118
119 //
120 // Create a empty Parameter List and an empty Task List
121 // The tasklist is identified in the eventloop by its name
122 //
123 MParList plist;
124
125 MTaskList tlist;
126
127 plist.AddToList(&tlist);
128
129 src.SetReadyToSave();
130 plist.AddToList(&src);
131
132 MBadPixelsCam badpix;
133 plist.AddToList(&badpix);
134
135
136 //
137 // Now setup the tasks and tasklist:
138 // ---------------------------------
139 //
140 MReadMarsFile read("Events");
141
142 if (CalibrationFilename)
143 read.AddFile(CalibrationFilename->Data());
144
145 read.DisableAutoScheme();
146
147 MGeomApply geom; // Reads in geometry from MC file and sets the right sizes for
148 // several parameter containers.
149
150 MMcPedestalCopy pcopy;
151 // Copies pedestal data from the MC file run fadc header to the MPedestalCam container.
152
153 MPointingPosCalc pointcalc;
154 // Creates MPointingPos object and fill it with the telescope orientation
155 // information taken from MMcEvt.
156
157 MCalibrateData calib; // Applies calibration to the data
158 calib.SetCalibrationMode(MCalibrateData::kFfactor);
159 // Do not change the CalibrationMode above for MC...!
160 calib.SetSignalType(mccalibupdate.GetSignalType());
161
162 // MBlindPixelCalc blind;
163 // blind.SetUseInterpolation();
164
165 MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
166 hcalc.Disable(MHillasCalc::kCalcHillasSrc);
167
168 MMcCalibrationCalc mccalibcalc;
169
170 tlist.AddToList(&read);
171 tlist.AddToList(&geom);
172 tlist.AddToList(&pcopy);
173 tlist.AddToList(&pointcalc);
174
175 tlist.AddToList(&sigextract);
176 tlist.AddToList(&mccalibupdate);
177 tlist.AddToList(&calib);
178 tlist.AddToList(&clean);
179 // tlist.AddToList(&blind);
180 tlist.AddToList(&hcalc);
181
182 tlist.AddToList(&mccalibcalc);
183
184 //
185 // Open output files:
186 //
187
188 MWriteRootFile write1(OutFilename1->Data()); // Writes output1
189 write1.AddContainer("MRawRunHeader", "RunHeaders");
190 write1.AddContainer("MMcRunHeader", "RunHeaders");
191 write1.AddContainer("MSrcPosCam", "RunHeaders");
192 write1.AddContainer("MGeomCam", "RunHeaders");
193 write1.AddContainer("MMcConfigRunHeader", "RunHeaders");
194 write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
195 write1.AddContainer("MMcFadcHeader", "RunHeaders");
196 write1.AddContainer("MMcTrigHeader", "RunHeaders");
197
198
199 write1.AddContainer("MMcEvt", "Events");
200 write1.AddContainer("MHillas", "Events");
201 write1.AddContainer("MHillasExt", "Events");
202 write1.AddContainer("MHillasSrc", "Events");
203 write1.AddContainer("MImagePar", "Events");
204 write1.AddContainer("MNewImagePar", "Events");
205 write1.AddContainer("MConcentration","Events");
206 write1.AddContainer("MPointingPos", "Events");
207
208 if (OutFilename2)
209 {
210 MWriteRootFile write2(OutFilename2->Data()); // Writes output2
211 write2.AddContainer("MRawRunHeader", "RunHeaders");
212 write2.AddContainer("MMcRunHeader", "RunHeaders");
213 write2.AddContainer("MSrcPosCam", "RunHeaders");
214 write2.AddContainer("MGeomCam", "RunHeaders");
215 write2.AddContainer("MMcConfigRunHeader", "RunHeaders");
216 write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
217 write2.AddContainer("MMcFadcHeader", "RunHeaders");
218 write2.AddContainer("MMcTrigHeader", "RunHeaders");
219
220
221 write2.AddContainer("MMcEvt", "Events");
222 write2.AddContainer("MHillas", "Events");
223 write2.AddContainer("MHillasExt", "Events");
224 write2.AddContainer("MHillasSrc", "Events");
225 write2.AddContainer("MImagePar", "Events");
226 write2.AddContainer("MNewImagePar", "Events");
227 write2.AddContainer("MConcentration","Events");
228 write2.AddContainer("MPointingPos", "Events");
229
230 //
231 // Divide output in train and test samples, using the event number
232 // (odd/even) to achieve otherwise unbiased event samples:
233 //
234
235 MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
236 MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
237
238 write1.SetFilter(&filter1);
239 write2.SetFilter(&filter2);
240 }
241
242 //
243 // First loop: Calibration loop
244 //
245
246 MProgressBar bar;
247 bar.SetWindowName("Calibrating...");
248
249 MEvtLoop evtloop;
250 evtloop.SetProgressBar(&bar);
251 evtloop.SetParList(&plist);
252
253 if (CalibrationFilename)
254 {
255 if (!evtloop.Eventloop())
256 return;
257 mccalibcalc->GetHistADC2PhotEl()->Write();
258 mccalibcalc->GetHistPhot2PhotEl()->Write();
259 }
260
261 //
262 // Second loop: analysis loop
263 //
264
265 //
266 // Change the read task by another one which reads the file we want to analyze:
267 //
268
269 MReadMarsFile read2("Events");
270 read2.AddFile(AnalysisFilename);
271 read2.DisableAutoScheme();
272 tlist.AddToListBefore(&read2, &read);
273 tlist.RemoveFromList(&read);
274
275 //
276 // Analyzed only the desired fraction of events, skip the rest:
277 //
278 MFEventSelector eventselector;
279 Float_t rejected_fraction = 1. - accepted_fraction;
280 eventselector.SetSelectionRatio(rejected_fraction);
281 MContinue skip(&eventselector);
282 tlist.AddToListBefore(&skip, &sigextract);
283
284 bar.SetWindowName("Analyzing...");
285
286 tlist.RemoveFromList(&mccalibcalc); // Removes calibration task from list.
287
288 hcalc.Enable(MHillasCalc::kCalcHillasSrc);
289
290 // Add tasks to write output:
291
292 if (OutFilename2)
293 {
294 tlist.AddToList(&filter1);
295 tlist.AddToList(&filter2);
296 tlist.AddToList(&write2);
297 }
298
299 tlist.AddToList(&write1);
300
301 if (!evtloop.Eventloop())
302 return;
303
304
305 tlist.PrintStatistics();
306}
Note: See TracBrowser for help on using the repository browser.