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

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