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

Last change on this file since 6157 was 6027, checked in by moralejo, 20 years ago
*** empty log message ***
File size: 6.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// 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("/data1/magic/mc_data/root/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 = "/data1/magic/mc_data/root/Period021_0.73_mirror/gammas_wobble/used/Gamma_*.root"; // File to be analyzed
50
51 Char_t* OutFilename = "calibrated_gamma.root"; // Output file name
52
53
54 // MExtractSignal sigextract;
55 // (other extraction methods can be used)
56 // sigextract.SetSaturationLimit(240);
57 // Defines when to switch to low gain
58 // Define FADC slices to be integrated in high and low gain:
59 // sigextract.SetRange(5, 10, 5, 10);
60
61 MExtractFixedWindowPeakSearch sigextract;
62 sigextract.SetWindows(6, 6, 4);
63
64
65
66 // ---------------------------------------------------------------------
67 //
68 // Create a empty Parameter List and an empty Task List
69 // The tasklist is identified in the eventloop by its name
70 //
71 MParList plist;
72
73 MTaskList tlist;
74
75 plist.AddToList(&tlist);
76
77 MBadPixelsCam badpix;
78 plist.AddToList(&badpix); // Not used for now.
79
80 //
81 // Now setup the tasks and tasklist:
82 // ---------------------------------
83 //
84 MReadMarsFile read("Events");
85
86 if (CalibrationFilename)
87 read.AddFile(CalibrationFilename->Data());
88
89 read.DisableAutoScheme();
90
91 MGeomApply geom;
92 // Reads in geometry from MC file and sets the right sizes for
93 // several parameter containers.
94
95 MMcPedestalCopy pcopy;
96 // Copies pedestal data from the MC file run fadc header to the
97 // MPedestalCam container.
98
99 MPointingPosCalc pointcalc;
100 // Creates MPointingPos object and fill it with the telescope orientation
101 // information taken from MMcEvt.
102
103 MMcCalibrationUpdate mccalibupdate;
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
114 MImgCleanStd clean;
115 //
116 // Applies tail cuts to image. Since the calibration is performed on
117 // noiseless camera files, the precise values of the cleaning levels
118 // are unimportant (in any case, only pixels without any C-photon will
119 // be rejected).
120 //
121
122 MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
123 hcalc.Disable(MHillasCalc::kCalcHillasSrc);
124
125 MMcCalibrationCalc mccalibcalc;
126 // Calculates calibration constants to convert from ADC counts to photons.
127
128
129 tlist.AddToList(&read);
130 tlist.AddToList(&geom);
131 tlist.AddToList(&pcopy);
132 tlist.AddToList(&pointcalc);
133 tlist.AddToList(&sigextract);
134 tlist.AddToList(&mccalibupdate);
135 tlist.AddToList(&calib);
136 tlist.AddToList(&clean);
137 tlist.AddToList(&hcalc);
138
139 tlist.AddToList(&mccalibcalc);
140
141 //
142 // Open output file:
143 //
144 MWriteRootFile write(OutFilename); // Writes output
145 write.AddContainer("MGeomCam", "RunHeaders");
146 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
147 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
148 write.AddContainer("MMcFadcHeader", "RunHeaders");
149 write.AddContainer("MMcRunHeader", "RunHeaders");
150 write.AddContainer("MMcTrigHeader", "RunHeaders");
151 write.AddContainer("MRawRunHeader", "RunHeaders");
152
153
154 write.AddContainer("MMcEvt", "Events");
155 write.AddContainer("MMcTrig", "Events");
156 write.AddContainer("MPointingPos", "Events");
157 write.AddContainer("MRawEvtHeader", "Events");
158 write.AddContainer("MCerPhotEvt", "Events");
159 write.AddContainer("MPedPhotCam", "Events");
160
161 //
162 // First loop: Calibration loop
163 //
164
165 MProgressBar bar;
166 bar.SetWindowName("Calibrating...");
167
168 MEvtLoop evtloop;
169 evtloop.SetProgressBar(&bar);
170 evtloop.SetParList(&plist);
171
172 if (CalibrationFilename)
173 {
174 if (!evtloop.Eventloop())
175 return;
176 mccalibcalc->GetHistADC2PhotEl()->Write();
177 mccalibcalc->GetHistPhot2PhotEl()->Write();
178 // Writes out the histograms used for calibration.
179 }
180
181 //
182 // Second loop: apply calibration factors to MC events in the
183 // file to be anlyzed:
184 //
185
186 //
187 // Change the read task by another one which reads the file we want to analyze:
188 //
189
190 MReadMarsFile read2("Events");
191 read2.AddFile(AnalysisFilename);
192 read2.DisableAutoScheme();
193 tlist.AddToListBefore(&read2, &read, "All");
194 tlist.RemoveFromList(&read);
195
196 bar.SetWindowName("Writing...");
197
198 tlist.RemoveFromList(&clean);
199 tlist.RemoveFromList(&hcalc);
200 tlist.RemoveFromList(&mccalibcalc);
201
202 tlist.AddToList(&write); // Add task to write output.
203
204 if (!evtloop.Eventloop())
205 return;
206
207
208 tlist.PrintStatistics();
209}
Note: See TracBrowser for help on using the repository browser.