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

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