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 |
|
---|
88 | plist.AddToList(&src);
|
---|
89 |
|
---|
90 | //
|
---|
91 | // Now setup the tasks and tasklist:
|
---|
92 | // ---------------------------------
|
---|
93 | //
|
---|
94 | MReadMarsFile read("Events");
|
---|
95 |
|
---|
96 | if (CalibrationFilename)
|
---|
97 | read.AddFile(CalibrationFilename->Data());
|
---|
98 |
|
---|
99 | read.DisableAutoScheme();
|
---|
100 |
|
---|
101 | MGeomApply geom; // Reads in geometry from MC file and sets the right sizes for
|
---|
102 | // several parameter containers.
|
---|
103 |
|
---|
104 | MMcPedestalCopy pcopy;
|
---|
105 | // Copies pedestal data from the MC file run fadc header to the MPedestalCam container.
|
---|
106 |
|
---|
107 | MExtractSignal sigextract;
|
---|
108 | // Define ADC slices to be integrated in high and low gain:
|
---|
109 | sigextract.SetRange(BinsHigh[0], BinsHigh[1], BinsLow[0], BinsLow[1]);
|
---|
110 |
|
---|
111 | MMcCalibrationUpdate mccalibupdate;
|
---|
112 |
|
---|
113 | MCalibrate calib; // Transforms signals from ADC counts into photons.
|
---|
114 |
|
---|
115 | // MBlindPixelCalc blind;
|
---|
116 | // blind.SetUseInterpolation();
|
---|
117 |
|
---|
118 | MImgCleanStd clean(CleanLev[0], CleanLev[1]); // Applies tail cuts to image.
|
---|
119 |
|
---|
120 | MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
|
---|
121 | MHillasSrcCalc scalc; // Calculates source-dependent Hillas parameters
|
---|
122 |
|
---|
123 | MMcCalibrationCalc mccalibcalc;
|
---|
124 |
|
---|
125 | tlist.AddToList(&read);
|
---|
126 | tlist.AddToList(&geom);
|
---|
127 | tlist.AddToList(&pcopy);
|
---|
128 |
|
---|
129 | tlist.AddToList(&sigextract);
|
---|
130 | tlist.AddToList(&mccalibupdate);
|
---|
131 | tlist.AddToList(&calib);
|
---|
132 | tlist.AddToList(&clean);
|
---|
133 | // tlist.AddToList(&blind);
|
---|
134 | tlist.AddToList(&hcalc);
|
---|
135 |
|
---|
136 | tlist.AddToList(&mccalibcalc);
|
---|
137 |
|
---|
138 | //
|
---|
139 | // Open output files:
|
---|
140 | //
|
---|
141 |
|
---|
142 | MWriteRootFile write1(OutFilename1.Data()); // Writes output1
|
---|
143 | write1.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
144 | write1.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
145 | write1.AddContainer("MSrcPosCam", "RunHeaders");
|
---|
146 | write1.AddContainer("MMcEvt", "Events");
|
---|
147 | write1.AddContainer("MHillas", "Events");
|
---|
148 | write1.AddContainer("MHillasExt", "Events");
|
---|
149 | write1.AddContainer("MHillasSrc", "Events");
|
---|
150 | write1.AddContainer("MNewImagePar", "Events");
|
---|
151 |
|
---|
152 | if (OutFilename2)
|
---|
153 | {
|
---|
154 | MWriteRootFile write2(OutFilename2.Data()); // Writes output2
|
---|
155 | write2.AddContainer("MRawRunHeader", "RunHeaders");
|
---|
156 | write2.AddContainer("MMcRunHeader", "RunHeaders");
|
---|
157 | write2.AddContainer("MSrcPosCam", "RunHeaders");
|
---|
158 | write2.AddContainer("MMcEvt", "Events");
|
---|
159 | write2.AddContainer("MHillas", "Events");
|
---|
160 | write2.AddContainer("MHillasExt", "Events");
|
---|
161 | write2.AddContainer("MHillasSrc", "Events");
|
---|
162 | write2.AddContainer("MNewImagePar", "Events");
|
---|
163 |
|
---|
164 | //
|
---|
165 | // Divide output in train and test samples, using the event number
|
---|
166 | // (odd/even) to achieve otherwise unbiased event samples:
|
---|
167 | //
|
---|
168 |
|
---|
169 | MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
|
---|
170 | MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
|
---|
171 |
|
---|
172 | write1.SetFilter(&filter1);
|
---|
173 | write2.SetFilter(&filter2);
|
---|
174 | }
|
---|
175 |
|
---|
176 | //
|
---|
177 | // First loop: Calibration loop
|
---|
178 | //
|
---|
179 |
|
---|
180 | MProgressBar bar;
|
---|
181 | bar.SetWindowName("Calibrating...");
|
---|
182 |
|
---|
183 | MEvtLoop evtloop;
|
---|
184 | evtloop.SetProgressBar(&bar);
|
---|
185 | evtloop.SetParList(&plist);
|
---|
186 |
|
---|
187 | if (CalibrationFilename)
|
---|
188 | {
|
---|
189 | if (!evtloop.Eventloop())
|
---|
190 | return;
|
---|
191 | mccalibcalc->GetHist()->Write();
|
---|
192 | }
|
---|
193 |
|
---|
194 | //
|
---|
195 | // Second loop: analysis loop
|
---|
196 | //
|
---|
197 |
|
---|
198 | //
|
---|
199 | // Change the read task by another one which reads the file we want to analyze:
|
---|
200 | //
|
---|
201 |
|
---|
202 | MReadMarsFile read2("Events");
|
---|
203 | read2.AddFile(AnalysisFilename);
|
---|
204 | read2.DisableAutoScheme();
|
---|
205 | tlist.AddToListBefore(&read2, &read, "All");
|
---|
206 | tlist.RemoveFromList(&read);
|
---|
207 |
|
---|
208 | bar.SetWindowName("Analyzing...");
|
---|
209 |
|
---|
210 | tlist.RemoveFromList(&mccalibcalc); // Removes calibration task from list.
|
---|
211 |
|
---|
212 | tlist.AddToList(&scalc); // Calculates Source-dependent Hillas parameters
|
---|
213 |
|
---|
214 |
|
---|
215 | // Add tasks to write output:
|
---|
216 |
|
---|
217 | if (OutFilename2)
|
---|
218 | {
|
---|
219 | tlist.AddToList(&filter1);
|
---|
220 | tlist.AddToList(&filter2);
|
---|
221 | tlist.AddToList(&write2);
|
---|
222 | }
|
---|
223 |
|
---|
224 | tlist.AddToList(&write1);
|
---|
225 |
|
---|
226 | if (!evtloop.Eventloop())
|
---|
227 | return;
|
---|
228 |
|
---|
229 |
|
---|
230 | tlist.PrintStatistics();
|
---|
231 | }
|
---|