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

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