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