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

Last change on this file since 4908 was 4773, checked in by gaug, 20 years ago
*** empty log message ***
File size: 7.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("../../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 MHillasSrcCalc scalc; // Calculates source-dependent Hillas parameters
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("MMcEvt", "Events");
158 write1.AddContainer("MHillas", "Events");
159 write1.AddContainer("MHillasExt", "Events");
160 write1.AddContainer("MHillasSrc", "Events");
161 write1.AddContainer("MNewImagePar", "Events");
162
163 if (OutFilename2)
164 {
165 MWriteRootFile write2(OutFilename2.Data()); // Writes output2
166 write2.AddContainer("MRawRunHeader", "RunHeaders");
167 write2.AddContainer("MMcRunHeader", "RunHeaders");
168 write2.AddContainer("MSrcPosCam", "RunHeaders");
169 write2.AddContainer("MMcEvt", "Events");
170 write2.AddContainer("MHillas", "Events");
171 write2.AddContainer("MHillasExt", "Events");
172 write2.AddContainer("MHillasSrc", "Events");
173 write2.AddContainer("MNewImagePar", "Events");
174
175 //
176 // Divide output in train and test samples, using the event number
177 // (odd/even) to achieve otherwise unbiased event samples:
178 //
179
180 MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
181 MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
182
183 write1.SetFilter(&filter1);
184 write2.SetFilter(&filter2);
185 }
186
187 //
188 // First loop: Calibration loop
189 //
190
191 MProgressBar bar;
192 bar.SetWindowName("Calibrating...");
193
194 MEvtLoop evtloop;
195 evtloop.SetProgressBar(&bar);
196 evtloop.SetParList(&plist);
197
198 if (CalibrationFilename)
199 {
200 if (!evtloop.Eventloop())
201 return;
202 mccalibcalc->GetHistADC2PhotEl()->Write();
203 mccalibcalc->GetHistPhot2PhotEl()->Write();
204 }
205
206 //
207 // Second loop: analysis loop
208 //
209
210 //
211 // Change the read task by another one which reads the file we want to analyze:
212 //
213
214 MReadMarsFile read2("Events");
215 read2.AddFile(AnalysisFilename);
216 read2.DisableAutoScheme();
217 tlist.AddToListBefore(&read2, &read);
218 tlist.RemoveFromList(&read);
219
220 //
221 // Analyzed only the desired fraction of events, skip the rest:
222 //
223 MFEventSelector eventselector;
224 Float_t rejected_fraction = 1. - accepted_fraction;
225 eventselector.SetSelectionRatio(rejected_fraction);
226 MContinue skip(&eventselector);
227 tlist.AddToListBefore(&skip, &sigextract);
228
229 bar.SetWindowName("Analyzing...");
230
231 tlist.RemoveFromList(&mccalibcalc); // Removes calibration task from list.
232
233 tlist.AddToList(&scalc); // Calculates Source-dependent Hillas parameters
234
235
236 // Add tasks to write output:
237
238 if (OutFilename2)
239 {
240 tlist.AddToList(&filter1);
241 tlist.AddToList(&filter2);
242 tlist.AddToList(&write2);
243 }
244
245 tlist.AddToList(&write1);
246
247 if (!evtloop.Eventloop())
248 return;
249
250
251 tlist.PrintStatistics();
252}
Note: See TracBrowser for help on using the repository browser.