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

Last change on this file since 5496 was 5021, 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 CalibrationFilename = new TString("../gammas_nonoise/Gamma_zbin0_0*.root"); // File to be used for the calibration (must be a camera file without added noise)
47
48 Char_t* AnalysisFilename = "Gamma_zbin9_90_7_1740to1749_w0.root"; // File to be analyzed
49
50 Char_t* OutFilename = "calibrated_data.root"; // Output file name
51
52
53 MExtractSignal sigextract;
54 // (other extraction methods can be used)
55
56 sigextract.SetSaturationLimit(240);
57 // Defines when to switch to low gain
58
59 // Define FADC slices to be integrated in high and low gain:
60 sigextract.SetRange(5, 10, 5, 10);
61
62 // ---------------------------------------------------------------------
63 //
64 // Create a empty Parameter List and an empty Task List
65 // The tasklist is identified in the eventloop by its name
66 //
67 MParList plist;
68
69 MTaskList tlist;
70
71 plist.AddToList(&tlist);
72
73 MSrcPosCam src;
74 src.SetReadyToSave();
75 plist.AddToList(&src);
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 write.AddContainer("MSrcPosCam", "RunHeaders");
153
154
155 write.AddContainer("MMcEvt", "Events");
156 write.AddContainer("MMcTrig", "Events");
157 write.AddContainer("MPointingPos", "Events");
158 write.AddContainer("MRawEvtHeader", "Events");
159 write.AddContainer("MCerPhotEvt", "Events");
160 write.AddContainer("MPedPhotCam", "Events");
161
162 //
163 // First loop: Calibration loop
164 //
165
166 MProgressBar bar;
167 bar.SetWindowName("Calibrating...");
168
169 MEvtLoop evtloop;
170 evtloop.SetProgressBar(&bar);
171 evtloop.SetParList(&plist);
172
173 if (CalibrationFilename)
174 {
175 if (!evtloop.Eventloop())
176 return;
177 mccalibcalc->GetHistADC2PhotEl()->Write();
178 mccalibcalc->GetHistPhot2PhotEl()->Write();
179 // Writes out the histograms used for calibration.
180 }
181
182 //
183 // Second loop: apply calibration factors to MC events in the
184 // file to be anlyzed:
185 //
186
187 //
188 // Change the read task by another one which reads the file we want to analyze:
189 //
190
191 MReadMarsFile read2("Events");
192 read2.AddFile(AnalysisFilename);
193 read2.DisableAutoScheme();
194 tlist.AddToListBefore(&read2, &read, "All");
195 tlist.RemoveFromList(&read);
196
197 bar.SetWindowName("Writing...");
198
199 tlist.RemoveFromList(&clean);
200 tlist.RemoveFromList(&hcalc);
201 tlist.RemoveFromList(&mccalibcalc);
202
203 tlist.AddToList(&write); // Add task to write output.
204
205 if (!evtloop.Eventloop())
206 return;
207
208
209 tlist.PrintStatistics();
210}
Note: See TracBrowser for help on using the repository browser.