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

Last change on this file since 4090 was 3852, checked in by moralejo, 21 years ago
*** empty log message ***
File size: 6.3 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 = "Proton_zbin0_0*.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 MCalibrate calib;
106 // MCalibrate 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(MCalibrate::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
124 MMcCalibrationCalc mccalibcalc;
125 // Calculates calibration constants to convert from ADC counts to photons.
126
127
128 tlist.AddToList(&read);
129 tlist.AddToList(&geom);
130 tlist.AddToList(&pcopy);
131 tlist.AddToList(&pointcalc);
132 tlist.AddToList(&sigextract);
133 tlist.AddToList(&mccalibupdate);
134 tlist.AddToList(&calib);
135 tlist.AddToList(&clean);
136 tlist.AddToList(&hcalc);
137
138 tlist.AddToList(&mccalibcalc);
139
140 //
141 // Open output file:
142 //
143 MWriteRootFile write(OutFilename); // Writes output
144 write.AddContainer("MGeomCam", "RunHeaders");
145 write.AddContainer("MMcConfigRunHeader", "RunHeaders");
146 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
147 write.AddContainer("MMcFadcHeader", "RunHeaders");
148 write.AddContainer("MMcRunHeader", "RunHeaders");
149 write.AddContainer("MMcTrigHeader", "RunHeaders");
150 write.AddContainer("MRawRunHeader", "RunHeaders");
151 write.AddContainer("MSrcPosCam", "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.