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 | // MMCALIBRATE - Calibration of MC data
|
---|
29 | //
|
---|
30 | // This macro converts raw MC data into calibrated data (photons per pixel)
|
---|
31 | // It optionally divides the output into a train and a test sample
|
---|
32 | //
|
---|
33 | /////////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | #include "MImgCleanStd.h"
|
---|
36 |
|
---|
37 | void mccalibrate()
|
---|
38 | {
|
---|
39 | //
|
---|
40 | // This macro reads in MC camera files and produces and output with
|
---|
41 | // calibrated events (signal in photons for all pixels, in MCerPhotEvt
|
---|
42 | // containers).
|
---|
43 | //
|
---|
44 |
|
---|
45 | // ------------- user change -----------------
|
---|
46 | TString* CalibrationFilename;
|
---|
47 |
|
---|
48 | CalibrationFilename = new TString("/users/emc/moralejo/mcdata/Period021_0.73_mirror/gammas_nonoise/Gamma_*root"); // File to be used for the calibration (must be a camera file without added noise)
|
---|
49 |
|
---|
50 | Char_t* AnalysisFilename = "Gamma_zbin*w0.root"; // File to be analyzed
|
---|
51 |
|
---|
52 |
|
---|
53 | TString* OutFilename1;
|
---|
54 | TString* OutFilename2;
|
---|
55 |
|
---|
56 | // Output file names
|
---|
57 | OutFilename1 = new TString("calibrated_gamma_train.root");
|
---|
58 | OutFilename2 = new TString("calibrated_gamma_test.root");
|
---|
59 |
|
---|
60 | // To get only one output file, just comment out the second
|
---|
61 | // one of the above lines
|
---|
62 |
|
---|
63 |
|
---|
64 | //
|
---|
65 | // Set signal extractor
|
---|
66 | //
|
---|
67 | // MExtractFixedWindowPeakSearch sigextract;
|
---|
68 | // sigextract.SetWindows(6, 6, 4);
|
---|
69 | //
|
---|
70 | MExtractTimeAndChargeDigitalFilter sigextract;
|
---|
71 | sigextract.SetNameWeightsFile("/users/emc/moralejo/Mars/msignal/MC_weights.dat");
|
---|
72 | sigextract.SetRange(1, 14, 3, 14);
|
---|
73 |
|
---|
74 |
|
---|
75 | MMcCalibrationUpdate mccalibupdate;
|
---|
76 | ///// User change: calibrate in photons or phe- :
|
---|
77 | mccalibupdate.SetSignalType(MCalibrateData::kPhe);
|
---|
78 | // mccalibupdate.SetSignalType(MCalibrateData::kPhot);
|
---|
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 | MBadPixelsCam badpix;
|
---|
92 | plist.AddToList(&badpix); // Not used for now.
|
---|
93 |
|
---|
94 | //
|
---|
95 | // Now setup the tasks and tasklist:
|
---|
96 | // ---------------------------------
|
---|
97 | //
|
---|
98 | MReadMarsFile read("Events");
|
---|
99 |
|
---|
100 | if (CalibrationFilename)
|
---|
101 | read.AddFile(CalibrationFilename->Data());
|
---|
102 |
|
---|
103 | read.DisableAutoScheme();
|
---|
104 |
|
---|
105 | MGeomApply geom;
|
---|
106 | // Reads in geometry from MC file and sets the right sizes for
|
---|
107 | // several parameter containers.
|
---|
108 |
|
---|
109 | MMcPedestalCopy pcopy;
|
---|
110 | // Copies pedestal data from the MC file run fadc header to the
|
---|
111 | // MPedestalCam container.
|
---|
112 |
|
---|
113 | MPointingPosCalc pointcalc;
|
---|
114 | // Creates MPointingPos object and fills it with the telescope
|
---|
115 | // orientation information taken from MMcEvt.
|
---|
116 |
|
---|
117 | MCalibrateData calib;
|
---|
118 | //
|
---|
119 | // MCalibrateData transforms signals from ADC counts into photons or phe-
|
---|
120 | // (this can be selected anove). In the first loop it applies a "dummy"
|
---|
121 | // calibration supplied by MMcCalibrationUpdate, just to equalize inner
|
---|
122 | // and outer pixels, and calculates SIZE in "equivalent number of inner
|
---|
123 | // ADC counts". At the end of the first loop, in the PostProcess of
|
---|
124 | // MMcCalibrationCalc (see below) the true calibration constants
|
---|
125 | // are calculated.
|
---|
126 | //
|
---|
127 | calib.SetCalibrationMode(MCalibrateData::kFfactor);
|
---|
128 | // Do not change the CalibrationMode above for MC...!
|
---|
129 |
|
---|
130 | // Now set also whether to calibrate in photons or phe-:
|
---|
131 | calib.SetSignalType(mccalibupdate.GetSignalType());
|
---|
132 |
|
---|
133 | MImgCleanStd clean;
|
---|
134 | //
|
---|
135 | // Applies tail cuts to image. Since the calibration is performed on
|
---|
136 | // noiseless camera files, the precise values of the cleaning levels
|
---|
137 | // are unimportant (in any case, only pixels without any C-photon will
|
---|
138 | // be rejected).
|
---|
139 | //
|
---|
140 |
|
---|
141 | MHillasCalc hcalc;
|
---|
142 | hcalc.Disable(MHillasCalc::kCalcHillasSrc);
|
---|
143 | // Calculates Hillas parameters not dependent on source position.
|
---|
144 |
|
---|
145 | MMcCalibrationCalc mccalibcalc;
|
---|
146 | // Calculates calibration constants to convert from ADC counts to photons.
|
---|
147 |
|
---|
148 | tlist.AddToList(&read);
|
---|
149 | tlist.AddToList(&geom);
|
---|
150 |
|
---|
151 | MF notrigger("MMcTrig.fNumFirstLevel<1");
|
---|
152 | MContinue skipnotrig(¬rigger);
|
---|
153 | tlist.AddToList(&skipnotrig);
|
---|
154 |
|
---|
155 | tlist.AddToList(&pcopy);
|
---|
156 | tlist.AddToList(&pointcalc);
|
---|
157 | tlist.AddToList(&sigextract);
|
---|
158 | tlist.AddToList(&mccalibupdate);
|
---|
159 | tlist.AddToList(&calib);
|
---|
160 | tlist.AddToList(&clean);
|
---|
161 | tlist.AddToList(&hcalc);
|
---|
162 |
|
---|
163 | tlist.AddToList(&mccalibcalc);
|
---|
164 |
|
---|
165 | //
|
---|
166 | // Open output files:
|
---|
167 | //
|
---|
168 | MWriteRootFile write1(OutFilename1->Data()); // Writes output
|
---|
169 |
|
---|
170 | MWriteRootFile write1_b(OutFilename1->Data());
|
---|
171 | write1_b.AddContainer("MMcEvtBasic", "OriginalMC", kFALSE);
|
---|
172 | // Add the MMcEvtBasic container only in case it exists in
|
---|
173 | // the input camera files
|
---|
174 |
|
---|
175 | write1.AddContainer("MGeomCam", "RunHeaders");
|
---|
176 | write1.AddContainer("MMcConfigRunHeader", "RunHeaders");
|
---|
177 | write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
|
---|
178 | write1.AddContainer("MMcFadcHeader", "RunHeaders");
|
---|
179 | write1.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
180 | write1.AddContainer("MMcTrigHeader", "RunHeaders");
|
---|
181 | write1.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
182 |
|
---|
183 | write1.AddContainer("MMcEvt", "Events");
|
---|
184 | write1.AddContainer("MMcTrig", "Events");
|
---|
185 | write1.AddContainer("MPointingPos", "Events");
|
---|
186 | write1.AddContainer("MRawEvtHeader", "Events");
|
---|
187 | write1.AddContainer("MCerPhotEvt", "Events");
|
---|
188 | write1.AddContainer("MPedPhotCam", "Events");
|
---|
189 |
|
---|
190 | if (OutFilename2)
|
---|
191 | {
|
---|
192 | MWriteRootFile write2(OutFilename2->Data()); // Writes output
|
---|
193 |
|
---|
194 | MWriteRootFile write2_b(OutFilename2->Data());
|
---|
195 | write2_b.AddContainer("MMcEvtBasic", "OriginalMC", kFALSE);
|
---|
196 | // Add the MMcEvtBasic container only in case it exists in
|
---|
197 | // the input camera files
|
---|
198 |
|
---|
199 | write2.AddContainer("MGeomCam", "RunHeaders");
|
---|
200 | write2.AddContainer("MMcConfigRunHeader", "RunHeaders");
|
---|
201 | write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
|
---|
202 | write2.AddContainer("MMcFadcHeader", "RunHeaders");
|
---|
203 | write2.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
204 | write2.AddContainer("MMcTrigHeader", "RunHeaders");
|
---|
205 | write2.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
206 |
|
---|
207 | write2.AddContainer("MMcEvt", "Events");
|
---|
208 | write2.AddContainer("MMcTrig", "Events");
|
---|
209 | write2.AddContainer("MPointingPos", "Events");
|
---|
210 | write2.AddContainer("MRawEvtHeader", "Events");
|
---|
211 | write2.AddContainer("MCerPhotEvt", "Events");
|
---|
212 | write2.AddContainer("MPedPhotCam", "Events");
|
---|
213 |
|
---|
214 | //
|
---|
215 | // Divide output in train and test samples, using the event number
|
---|
216 | // (odd/even) to achieve otherwise unbiased event samples:
|
---|
217 | //
|
---|
218 | MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
|
---|
219 | MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
|
---|
220 |
|
---|
221 | write1.SetFilter(&filter1);
|
---|
222 | write2.SetFilter(&filter2);
|
---|
223 |
|
---|
224 | write1_b.SetFilter(&filter1);
|
---|
225 | write2_b.SetFilter(&filter2);
|
---|
226 | }
|
---|
227 |
|
---|
228 | //
|
---|
229 | // First loop: Calibration loop
|
---|
230 | //
|
---|
231 |
|
---|
232 | MProgressBar bar;
|
---|
233 | bar.SetWindowName("Calibrating...");
|
---|
234 |
|
---|
235 | MEvtLoop evtloop;
|
---|
236 | evtloop.SetProgressBar(&bar);
|
---|
237 | evtloop.SetParList(&plist);
|
---|
238 |
|
---|
239 | if (CalibrationFilename)
|
---|
240 | {
|
---|
241 | if (!evtloop.Eventloop())
|
---|
242 | return;
|
---|
243 | mccalibcalc->GetHistADC2PhotEl()->Write();
|
---|
244 | mccalibcalc->GetHistPhot2PhotEl()->Write();
|
---|
245 | // Writes out the histograms used for calibration. In case of
|
---|
246 | // aslit output in train and test file, this is written only
|
---|
247 | // in the test file for now.
|
---|
248 | }
|
---|
249 |
|
---|
250 | //
|
---|
251 | // Second loop: apply calibration factors to MC events in the
|
---|
252 | // file to be anlyzed:
|
---|
253 | //
|
---|
254 |
|
---|
255 | //
|
---|
256 | // Change the read task by another one which reads the file we want to analyze:
|
---|
257 | //
|
---|
258 |
|
---|
259 | MReadMarsFile read2("Events");
|
---|
260 | read2.AddFile(AnalysisFilename);
|
---|
261 | read2.DisableAutoScheme();
|
---|
262 | tlist.AddToListBefore(&read2, &read, "All");
|
---|
263 | tlist.RemoveFromList(&read);
|
---|
264 |
|
---|
265 | // Now add tasks to write MMcEvtBasic to the OriginalMC tree:
|
---|
266 | tlist.AddToListBefore(&write1_b, &skipnotrig, "All");
|
---|
267 | if (OutFilename2)
|
---|
268 | tlist.AddToListBefore(&write2_b, &skipnotrig, "All");
|
---|
269 |
|
---|
270 |
|
---|
271 | if (OutFilename2) // Add filters to split output in train and test
|
---|
272 | {
|
---|
273 | tlist.AddToListBefore(&filter1, &write1_b, "All");
|
---|
274 | tlist.AddToListBefore(&filter2, &write1_b, "All");
|
---|
275 | }
|
---|
276 |
|
---|
277 | bar.SetWindowName("Writing...");
|
---|
278 |
|
---|
279 | tlist.RemoveFromList(&clean);
|
---|
280 | tlist.RemoveFromList(&hcalc);
|
---|
281 | tlist.RemoveFromList(&mccalibcalc);
|
---|
282 |
|
---|
283 | tlist.AddToList(&write1);
|
---|
284 | tlist.AddToList(&write2);
|
---|
285 | // Add tasks to write the Events and RunHeaders trees to output.
|
---|
286 |
|
---|
287 | if (!evtloop.Eventloop())
|
---|
288 | return;
|
---|
289 |
|
---|
290 |
|
---|
291 | tlist.PrintStatistics();
|
---|
292 | }
|
---|