source: trunk/MagicSoft/Mars/macros/mccalibrate.C@ 6388

Last change on this file since 6388 was 6357, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 6.6 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// MMCALIBRATE - Calibration of MC data
29//
30// This macro converts raw MC data into calibrated data (photons per pixel)
31//
32/////////////////////////////////////////////////////////////////////////////
33
34#include "MImgCleanStd.h"
35
36void mccalibrate()
37{
38 //
39 // This is a demonstration program which reads in MC camera files
40 // and produces and output with calibrated events (signal in photons
41 // for all pixels, in MCerPhotEvt containers).
42 //
43
44 // ------------- user change -----------------
45 TString* CalibrationFilename;
46
47 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)
48
49 Char_t* AnalysisFilename = "Gamma_*.root"; // File to be analyzed
50
51 Char_t* OutFilename = "calibrated_gamma.root"; // Output file name
52
53
54 // (other extraction methods can be used)
55 // MExtractFixedWindowPeakSearch sigextract;
56 // sigextract.SetWindows(6, 6, 4);
57
58 MExtractTimeAndChargeDigitalFilter sigextract;
59 sigextract.SetNameWeightsFile("/users/emc/moralejo/Mars/msignal/MC_weights.dat");
60 sigextract.SetRange(1, 14, 3, 14);
61
62
63 MMcCalibrationUpdate mccalibupdate;
64 ///// User change: calibrate in photons or phe- :
65 mccalibupdate.SetSignalType(MCalibrateData::kPhe);
66 // mccalibupdate.SetSignalType(MCalibrateData::kPhot);
67
68 // ---------------------------------------------------------------------
69 //
70 // Create a empty Parameter List and an empty Task List
71 // The tasklist is identified in the eventloop by its name
72 //
73 MParList plist;
74
75 MTaskList tlist;
76
77 plist.AddToList(&tlist);
78
79 MBadPixelsCam badpix;
80 plist.AddToList(&badpix); // Not used for now.
81
82 //
83 // Now setup the tasks and tasklist:
84 // ---------------------------------
85 //
86 MReadMarsFile read("Events");
87
88 if (CalibrationFilename)
89 read.AddFile(CalibrationFilename->Data());
90
91 read.DisableAutoScheme();
92
93 MGeomApply geom;
94 // Reads in geometry from MC file and sets the right sizes for
95 // several parameter containers.
96
97 MMcPedestalCopy pcopy;
98 // Copies pedestal data from the MC file run fadc header to the
99 // MPedestalCam container.
100
101 MPointingPosCalc pointcalc;
102 // Creates MPointingPos object and fill it with the telescope orientation
103 // information taken from MMcEvt.
104
105 MCalibrateData calib;
106 // MCalibrateData transforms signals from ADC counts into photons. In the first
107 // loop it applies a "dummy" calibration supplied by MMcCalibrationUpdate, just
108 // to equalize inner and outer pixels. At the end of the first loop, in the
109 // PostProcess of MMcCalibrationCalc (see below) the true calibration constants
110 // are calculated.
111
112 calib.SetCalibrationMode(MCalibrateData::kFfactor);
113 // Do not change the CalibrationMode above for MC...!
114
115 // Now set also whether to calibrate in photons or phe-:
116 calib.SetSignalType(mccalibupdate.GetSignalType());
117
118 MImgCleanStd clean;
119 //
120 // Applies tail cuts to image. Since the calibration is performed on
121 // noiseless camera files, the precise values of the cleaning levels
122 // are unimportant (in any case, only pixels without any C-photon will
123 // be rejected).
124 //
125
126 MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
127 hcalc.Disable(MHillasCalc::kCalcHillasSrc);
128
129 MMcCalibrationCalc mccalibcalc;
130 // Calculates calibration constants to convert from ADC counts to photons.
131
132
133 tlist.AddToList(&read);
134 tlist.AddToList(&geom);
135 tlist.AddToList(&pcopy);
136 tlist.AddToList(&pointcalc);
137 tlist.AddToList(&sigextract);
138 tlist.AddToList(&mccalibupdate);
139 tlist.AddToList(&calib);
140 tlist.AddToList(&clean);
141 tlist.AddToList(&hcalc);
142
143 tlist.AddToList(&mccalibcalc);
144
145 //
146 // Open output file:
147 //
148 MWriteRootFile write(OutFilename); // Writes output
149 write.AddContainer("MGeomCam", "RunHeaders");
150 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
151 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
152 write.AddContainer("MMcFadcHeader", "RunHeaders");
153 write.AddContainer("MMcRunHeader", "RunHeaders");
154 write.AddContainer("MMcTrigHeader", "RunHeaders");
155 write.AddContainer("MRawRunHeader", "RunHeaders");
156
157
158 write.AddContainer("MMcEvt", "Events");
159 write.AddContainer("MMcTrig", "Events");
160 write.AddContainer("MPointingPos", "Events");
161 write.AddContainer("MRawEvtHeader", "Events");
162 write.AddContainer("MCerPhotEvt", "Events");
163 write.AddContainer("MPedPhotCam", "Events");
164
165 //
166 // First loop: Calibration loop
167 //
168
169 MProgressBar bar;
170 bar.SetWindowName("Calibrating...");
171
172 MEvtLoop evtloop;
173 evtloop.SetProgressBar(&bar);
174 evtloop.SetParList(&plist);
175
176 if (CalibrationFilename)
177 {
178 if (!evtloop.Eventloop())
179 return;
180 mccalibcalc->GetHistADC2PhotEl()->Write();
181 mccalibcalc->GetHistPhot2PhotEl()->Write();
182 // Writes out the histograms used for calibration.
183 }
184
185 //
186 // Second loop: apply calibration factors to MC events in the
187 // file to be anlyzed:
188 //
189
190 //
191 // Change the read task by another one which reads the file we want to analyze:
192 //
193
194 MReadMarsFile read2("Events");
195 read2.AddFile(AnalysisFilename);
196 read2.DisableAutoScheme();
197 tlist.AddToListBefore(&read2, &read, "All");
198 tlist.RemoveFromList(&read);
199
200 bar.SetWindowName("Writing...");
201
202 tlist.RemoveFromList(&clean);
203 tlist.RemoveFromList(&hcalc);
204 tlist.RemoveFromList(&mccalibcalc);
205
206 tlist.AddToList(&write); // Add task to write output.
207
208 if (!evtloop.Eventloop())
209 return;
210
211
212 tlist.PrintStatistics();
213}
Note: See TracBrowser for help on using the repository browser.