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

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