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("nonoise/Gamma_zbin0_90_7_507*.root");
|
---|
55 | // File to be used in the calibration (must be a camera file without added noise)
|
---|
56 |
|
---|
57 | Char_t* AnalysisFilename = "Gamma_zbin0*.root"; // File to be analyzed
|
---|
58 |
|
---|
59 | // ------------- user change -----------------
|
---|
60 | //
|
---|
61 | // Change output file names as desired. If you want only one output, comment
|
---|
62 | // the initialization of OutFilename2.
|
---|
63 |
|
---|
64 | OutFilename1 = new TString("star_train.root"); // Output file name 1 (test)
|
---|
65 | // OutFilename2 = new TString("star_test.root"); // Output file name 2 (train)
|
---|
66 |
|
---|
67 |
|
---|
68 | Float_t CleanLev[2] = {4., 3.}; // Tail cuts for image analysis
|
---|
69 |
|
---|
70 | Int_t BinsHigh[2] = {5, 9}; // First and last FADC bin of the range to be integrated,
|
---|
71 | Int_t BinsLow[2] = {5, 9}; // for high and low gain respectively.
|
---|
72 |
|
---|
73 | // -------------------------------------------
|
---|
74 |
|
---|
75 | //
|
---|
76 | // Create a empty Parameter List and an empty Task List
|
---|
77 | // The tasklist is identified in the eventloop by its name
|
---|
78 | //
|
---|
79 | MParList plist;
|
---|
80 |
|
---|
81 | MTaskList tlist;
|
---|
82 |
|
---|
83 | plist.AddToList(&tlist);
|
---|
84 |
|
---|
85 | MSrcPosCam src;
|
---|
86 | src.SetReadyToSave();
|
---|
87 | plist.AddToList(&src);
|
---|
88 |
|
---|
89 | MBadPixelsCam badpix;
|
---|
90 | plist.AddToList(&badpix);
|
---|
91 |
|
---|
92 |
|
---|
93 | //
|
---|
94 | // Now setup the tasks and tasklist:
|
---|
95 | // ---------------------------------
|
---|
96 | //
|
---|
97 | MReadMarsFile read("Events");
|
---|
98 |
|
---|
99 | if (CalibrationFilename)
|
---|
100 | read.AddFile(CalibrationFilename->Data());
|
---|
101 |
|
---|
102 | read.DisableAutoScheme();
|
---|
103 |
|
---|
104 | MGeomApply geom; // Reads in geometry from MC file and sets the right sizes for
|
---|
105 | // several parameter containers.
|
---|
106 |
|
---|
107 | MMcPedestalCopy pcopy;
|
---|
108 | // Copies pedestal data from the MC file run fadc header to the MPedestalCam container.
|
---|
109 |
|
---|
110 | MExtractSignal sigextract;
|
---|
111 | // Define ADC slices to be integrated in high and low gain:
|
---|
112 | sigextract.SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);
|
---|
113 |
|
---|
114 | MMcCalibrationUpdate mccalibupdate;
|
---|
115 |
|
---|
116 | MCalibrate calib; // Transforms signals from ADC counts into photons.
|
---|
117 |
|
---|
118 | // MBlindPixelCalc blind;
|
---|
119 | // blind.SetUseInterpolation();
|
---|
120 |
|
---|
121 | MImgCleanStd clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
|
---|
122 |
|
---|
123 | MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
|
---|
124 | MHillasSrcCalc scalc; // Calculates source-dependent Hillas parameters
|
---|
125 |
|
---|
126 | MMcCalibrationCalc mccalibcalc;
|
---|
127 |
|
---|
128 | tlist.AddToList(&read);
|
---|
129 | tlist.AddToList(&geom);
|
---|
130 | tlist.AddToList(&pcopy);
|
---|
131 |
|
---|
132 | tlist.AddToList(&sigextract);
|
---|
133 | tlist.AddToList(&mccalibupdate);
|
---|
134 | tlist.AddToList(&calib);
|
---|
135 | tlist.AddToList(&clean);
|
---|
136 | // tlist.AddToList(&blind);
|
---|
137 | tlist.AddToList(&hcalc);
|
---|
138 |
|
---|
139 | tlist.AddToList(&mccalibcalc);
|
---|
140 |
|
---|
141 | //
|
---|
142 | // Open output files:
|
---|
143 | //
|
---|
144 |
|
---|
145 | MWriteRootFile write1(OutFilename1.Data()); // Writes output1
|
---|
146 | write1.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
147 | write1.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
148 | write1.AddContainer("MSrcPosCam", "RunHeaders");
|
---|
149 | write1.AddContainer("MMcEvt", "Events");
|
---|
150 | write1.AddContainer("MHillas", "Events");
|
---|
151 | write1.AddContainer("MHillasExt", "Events");
|
---|
152 | write1.AddContainer("MHillasSrc", "Events");
|
---|
153 | write1.AddContainer("MNewImagePar", "Events");
|
---|
154 |
|
---|
155 | if (OutFilename2)
|
---|
156 | {
|
---|
157 | MWriteRootFile write2(OutFilename2.Data()); // Writes output2
|
---|
158 | write2.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
159 | write2.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
160 | write2.AddContainer("MSrcPosCam", "RunHeaders");
|
---|
161 | write2.AddContainer("MMcEvt", "Events");
|
---|
162 | write2.AddContainer("MHillas", "Events");
|
---|
163 | write2.AddContainer("MHillasExt", "Events");
|
---|
164 | write2.AddContainer("MHillasSrc", "Events");
|
---|
165 | write2.AddContainer("MNewImagePar", "Events");
|
---|
166 |
|
---|
167 | //
|
---|
168 | // Divide output in train and test samples, using the event number
|
---|
169 | // (odd/even) to achieve otherwise unbiased event samples:
|
---|
170 | //
|
---|
171 |
|
---|
172 | MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
|
---|
173 | MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
|
---|
174 |
|
---|
175 | write1.SetFilter(&filter1);
|
---|
176 | write2.SetFilter(&filter2);
|
---|
177 | }
|
---|
178 |
|
---|
179 | //
|
---|
180 | // First loop: Calibration loop
|
---|
181 | //
|
---|
182 |
|
---|
183 | MProgressBar bar;
|
---|
184 | bar.SetWindowName("Calibrating...");
|
---|
185 |
|
---|
186 | MEvtLoop evtloop;
|
---|
187 | evtloop.SetProgressBar(&bar);
|
---|
188 | evtloop.SetParList(&plist);
|
---|
189 |
|
---|
190 | if (CalibrationFilename)
|
---|
191 | {
|
---|
192 | if (!evtloop.Eventloop())
|
---|
193 | return;
|
---|
194 | mccalibcalc->GetHist()->Write();
|
---|
195 | }
|
---|
196 |
|
---|
197 | //
|
---|
198 | // Second loop: analysis loop
|
---|
199 | //
|
---|
200 |
|
---|
201 | //
|
---|
202 | // Change the read task by another one which reads the file we want to analyze:
|
---|
203 | //
|
---|
204 |
|
---|
205 | MReadMarsFile read2("Events");
|
---|
206 | read2.AddFile(AnalysisFilename);
|
---|
207 | read2.DisableAutoScheme();
|
---|
208 | tlist.AddToListBefore(&read2, &read, "All");
|
---|
209 | tlist.RemoveFromList(&read);
|
---|
210 |
|
---|
211 | bar.SetWindowName("Analyzing...");
|
---|
212 |
|
---|
213 | tlist.RemoveFromList(&mccalibcalc); // Removes calibration task from list.
|
---|
214 |
|
---|
215 | tlist.AddToList(&scalc); // Calculates Source-dependent Hillas parameters
|
---|
216 |
|
---|
217 |
|
---|
218 | // Add tasks to write output:
|
---|
219 |
|
---|
220 | if (OutFilename2)
|
---|
221 | {
|
---|
222 | tlist.AddToList(&filter1);
|
---|
223 | tlist.AddToList(&filter2);
|
---|
224 | tlist.AddToList(&write2);
|
---|
225 | }
|
---|
226 |
|
---|
227 | tlist.AddToList(&write1);
|
---|
228 |
|
---|
229 | if (!evtloop.Eventloop())
|
---|
230 | return;
|
---|
231 |
|
---|
232 |
|
---|
233 | tlist.PrintStatistics();
|
---|
234 | }
|
---|