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

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