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

Last change on this file since 5560 was 5123, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 8.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("/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 MMcCalibrationUpdate mccalibupdate;
122
123 MCalibrateData calib; // Transforms signals from ADC counts into photons.
124 calib.SetCalibrationMode(MCalibrateData::kFfactor);
125
126 // MBlindPixelCalc blind;
127 // blind.SetUseInterpolation();
128
129 MImgCleanStd clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
130
131 MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
132 hcalc.Disable(MHillasCalc::kCalcHillasSrc);
133
134 MMcCalibrationCalc mccalibcalc;
135
136 tlist.AddToList(&read);
137 tlist.AddToList(&geom);
138 tlist.AddToList(&pcopy);
139
140 tlist.AddToList(&sigextract);
141 tlist.AddToList(&mccalibupdate);
142 tlist.AddToList(&calib);
143 tlist.AddToList(&clean);
144 // tlist.AddToList(&blind);
145 tlist.AddToList(&hcalc);
146
147 tlist.AddToList(&mccalibcalc);
148
149 //
150 // Open output files:
151 //
152
153 MWriteRootFile write1(OutFilename1.Data()); // Writes output1
154 write1.AddContainer("MRawRunHeader", "RunHeaders");
155 write1.AddContainer("MMcRunHeader", "RunHeaders");
156 write1.AddContainer("MSrcPosCam", "RunHeaders");
157 write1.AddContainer("MGeomCam", "RunHeaders");
158 write1.AddContainer("MMcConfigRunHeader", "RunHeaders");
159 write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
160 write1.AddContainer("MMcFadcHeader", "RunHeaders");
161 write1.AddContainer("MMcTrigHeader", "RunHeaders");
162
163
164 write1.AddContainer("MMcEvt", "Events");
165 write1.AddContainer("MHillas", "Events");
166 write1.AddContainer("MHillasExt", "Events");
167 write1.AddContainer("MHillasSrc", "Events");
168 write1.AddContainer("MImagePar", "Events");
169 write1.AddContainer("MNewImagePar", "Events");
170
171 if (OutFilename2)
172 {
173 MWriteRootFile write2(OutFilename2.Data()); // Writes output2
174 write2.AddContainer("MRawRunHeader", "RunHeaders");
175 write2.AddContainer("MMcRunHeader", "RunHeaders");
176 write2.AddContainer("MSrcPosCam", "RunHeaders");
177 write2.AddContainer("MGeomCam", "RunHeaders");
178 write2.AddContainer("MMcConfigRunHeader", "RunHeaders");
179 write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
180 write2.AddContainer("MMcFadcHeader", "RunHeaders");
181 write2.AddContainer("MMcTrigHeader", "RunHeaders");
182
183
184 write2.AddContainer("MMcEvt", "Events");
185 write2.AddContainer("MHillas", "Events");
186 write2.AddContainer("MHillasExt", "Events");
187 write2.AddContainer("MHillasSrc", "Events");
188 write2.AddContainer("MImagePar", "Events");
189 write2.AddContainer("MNewImagePar", "Events");
190
191 //
192 // Divide output in train and test samples, using the event number
193 // (odd/even) to achieve otherwise unbiased event samples:
194 //
195
196 MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
197 MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
198
199 write1.SetFilter(&filter1);
200 write2.SetFilter(&filter2);
201 }
202
203 //
204 // First loop: Calibration loop
205 //
206
207 MProgressBar bar;
208 bar.SetWindowName("Calibrating...");
209
210 MEvtLoop evtloop;
211 evtloop.SetProgressBar(&bar);
212 evtloop.SetParList(&plist);
213
214 if (CalibrationFilename)
215 {
216 if (!evtloop.Eventloop())
217 return;
218 mccalibcalc->GetHistADC2PhotEl()->Write();
219 mccalibcalc->GetHistPhot2PhotEl()->Write();
220 }
221
222 //
223 // Second loop: analysis loop
224 //
225
226 //
227 // Change the read task by another one which reads the file we want to analyze:
228 //
229
230 MReadMarsFile read2("Events");
231 read2.AddFile(AnalysisFilename);
232 read2.DisableAutoScheme();
233 tlist.AddToListBefore(&read2, &read);
234 tlist.RemoveFromList(&read);
235
236 //
237 // Analyzed only the desired fraction of events, skip the rest:
238 //
239 MFEventSelector eventselector;
240 Float_t rejected_fraction = 1. - accepted_fraction;
241 eventselector.SetSelectionRatio(rejected_fraction);
242 MContinue skip(&eventselector);
243 tlist.AddToListBefore(&skip, &sigextract);
244
245 bar.SetWindowName("Analyzing...");
246
247 tlist.RemoveFromList(&mccalibcalc); // Removes calibration task from list.
248
249 hcalc.Enable(MHillasCalc::kCalcHillasSrc);
250
251 // Add tasks to write output:
252
253 if (OutFilename2)
254 {
255 tlist.AddToList(&filter1);
256 tlist.AddToList(&filter2);
257 tlist.AddToList(&write2);
258 }
259
260 tlist.AddToList(&write1);
261
262 if (!evtloop.Eventloop())
263 return;
264
265
266 tlist.PrintStatistics();
267}
Note: See TracBrowser for help on using the repository browser.