source: trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.cc@ 5691

Last change on this file since 5691 was 5683, checked in by gaug, 20 years ago
*** empty log message ***
File size: 11.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): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJCalibrateSignalFromOutside
28//
29// This class is reading the output written by callisto. It calibrates
30// signal and time.
31//
32// The signal and time extractors are read from the callisto-output. In
33// pricipal you could overwrite these default using the resource file,
34// but this is NOT recommended!
35//
36/////////////////////////////////////////////////////////////////////////////
37#include "MJCalibrateSignalFromOutside.h"
38
39#include <TEnv.h>
40#include <TFile.h>
41
42#include "MLog.h"
43#include "MLogManip.h"
44
45#include "MDirIter.h"
46#include "MRunIter.h"
47#include "MParList.h"
48#include "MTaskList.h"
49#include "MEvtLoop.h"
50
51#include "MStatusDisplay.h"
52
53#include "MGeomCam.h"
54#include "MHCamEvent.h"
55#include "MPedestalCam.h"
56#include "MBadPixelsCam.h"
57
58#include "MCalibrationQECam.h"
59#include "MCalibrationBlindCam.h"
60#include "MCalibrationChargeCam.h"
61#include "MCalibrationRelTimeCam.h"
62#include "MCalibrationChargePINDiode.h"
63
64#include "MReadReports.h"
65#include "MReadMarsFile.h"
66#include "MRawFileRead.h"
67#include "MGeomApply.h"
68#include "MMcPedestalCopy.h"
69#include "MPointingPosCalc.h"
70#include "MPedCalcFromLoGain.h"
71#include "MExtractor.h"
72#include "MTaskEnv.h"
73#include "MCalibrateData.h"
74#include "MCalibrateRelTimes.h"
75#include "MBadPixelsMerge.h"
76#include "MBadPixelsCalc.h"
77#include "MBadPixelsTreat.h"
78#include "MFillH.h"
79#include "MWriteRootFile.h"
80
81ClassImp(MJCalibrateSignalFromOutside);
82
83using namespace std;
84
85// --------------------------------------------------------------------------
86//
87// Default constructor.
88//
89// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
90//
91MJCalibrateSignalFromOutside::MJCalibrateSignalFromOutside(const char *name, const char *title)
92 : fIsDataCheck(kFALSE), fGeometry("MGeomCamMagic")
93{
94 fName = name ? name : "MJCalibrateSignalFromOutside";
95 fTitle = title ? title : "Tool to calibrate data";
96}
97
98Bool_t MJCalibrateSignalFromOutside::WriteResult()
99{
100 if (fPathOut.IsNull())
101 {
102 *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
103 return kTRUE;
104 }
105
106 const TString oname = Form("%s/signal%06d.root", (const char*)fPathOut, fSequence.GetSequence());
107
108 *fLog << inf << "Writing to file: " << oname << endl;
109
110 TFile file(oname, "RECREATE");
111
112 *fLog << inf << " - MStatusDisplay..." << flush;
113 if (fDisplay && fDisplay->Write()<=0)
114 {
115 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
116 return kFALSE;
117 }
118 *fLog << inf << "ok." << endl;
119
120 return kTRUE;
121}
122
123Bool_t MJCalibrateSignalFromOutside::ProcessFile(MPedestalCam &pedcamab, MPedestalCam &pedcamrms, MCalibrationChargeCam &chargecam, MCalibrationQECam &qecam, MCalibrationRelTimeCam &relcam, Byte_t filetype)
124{
125 // --------------------------------------------------------------------------------
126
127 *fLog << inf;
128 fLog->Separator(GetDescriptor());
129
130 *fLog << "Calibrate data from ";
131 *fLog << "Runs " << fRuns->GetRunsAsString() << endl;
132 *fLog << endl;
133
134 MDirIter iter;
135
136 *fLog << all;
137 if (fExtractor)
138 {
139 *fLog << underline << "Signal Extractor found in calibration file" << endl;
140 fExtractor->Print();
141 *fLog << endl;
142 }
143 else
144 {
145 *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
146 return kFALSE;
147 }
148
149 fExtractor->SetPedestals(&pedcamab);
150
151 // Setup Parlist
152 MParList plist;
153 plist.AddToList(this); // take care of fDisplay!
154 plist.AddToList(&fBadPixels);
155 plist.AddToList(&pedcamrms);
156 plist.AddToList(&chargecam);
157 plist.AddToList(&qecam);
158 plist.AddToList(&relcam);
159
160 // Setup Tasklist
161 MTaskList tlist;
162 plist.AddToList(&tlist);
163
164 MReadReports readreal;
165 readreal.AddTree("Events", "MTime.", kTRUE);
166 readreal.AddTree("Trigger");
167 readreal.AddTree("Camera");
168 readreal.AddTree("Drive");
169 readreal.AddTree("CC");
170 readreal.AddTree("Currents");
171
172 // MReadMarsFile read("Events");
173 // read.DisableAutoScheme();
174 MRawFileRead rawread(NULL);
175 if (IsDataCheck())
176 rawread.AddFiles(*fRuns);
177 else
178 {
179 // read.AddFiles(*fRuns);
180 readreal.AddFiles(*fRuns);
181 }
182
183 MGeomApply apply; // Only necessary to create geometry
184 apply.SetGeometry(fGeometry);
185 MBadPixelsMerge merge(&fBadPixels);
186
187 MPedCalcFromLoGain pedlo1("MPedCalcMeanFromLoGain");
188 pedlo1.SetPedestalUpdate(kTRUE);
189 pedlo1.SetPedestalsOut(&pedcamab);
190
191 MPedCalcFromLoGain pedlo2("MPedCalcRmsFromLoGain");
192 pedlo2.SetPedestalUpdate(kTRUE);
193 pedlo2.SetPedestalsIn(&pedcamab);
194 pedlo2.SetPedestalsOut(&pedcamrms);
195
196 if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
197 pedlo2.SetExtractor((MExtractTimeAndCharge*)fExtractor);
198
199 MMcPedestalCopy pcopy;
200 MTaskEnv taskenv1("ExtractSignal");
201 taskenv1.SetDefault(fExtractor);
202 MCalibrateData calib;
203 if (filetype==3) // MC file
204 {
205 calib.SetCalibrationMode(MCalibrateData::kFfactor);
206 calib.SetPedestalFlag(MCalibrateData::kRun);
207 }
208 else
209 {
210 calib.SetPedestalCamMean(&pedcamab);
211 calib.SetPedestalCamRms(&pedcamrms);
212 calib.SetPedestalFlag(MCalibrateData::kEvent);
213 }
214
215 MCalibrateRelTimes caltm;
216 MBadPixelsCalc bpcal;
217 MBadPixelsTreat treat;
218
219 MHCamEvent evt0(0, "PedFLG", "Pedestal from Lo Gain;;P [fadc/sl]");
220 MHCamEvent evt1(2, "PedRmsFLG", "Pedestal RMS from Lo Gain;;\\sigma_{p} [fadc/sl]");
221 MHCamEvent evt2(0, "Extra'd", "Extracted Signal;;S [fadc/sl]");
222 MHCamEvent evt3(0, "PedPhot", "Calibrated Pedestal;;P [\\gamma]");
223 MHCamEvent evt4(1, "PedRMS", "Calibrated Pedestal RMS;;\\sigma_{p} [\\gamma]");
224 MHCamEvent evt5(0, "Interp'd", "Interpolated Signal;;S [\\gamma]");
225 MHCamEvent evt6(2, "Unsuitable", "Unsuitable event ratio;;%");
226 MHCamEvent evt7(0, "Times", "Arrival Time;;T [slice]");
227 evt0.EnableVariance();
228 evt1.EnableVariance();
229 evt2.EnableVariance();
230 evt3.EnableVariance();
231 evt4.EnableVariance();
232 evt5.EnableVariance();
233 evt7.EnableVariance();
234
235 MFillH fill0(&evt0, &pedcamab, "FillPedFLG");
236 MFillH fill1(&evt1, "MPedestalCam", "FillPedRmsFLG");
237 MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
238 MFillH fill3(&evt3, "MPedPhotCam", "FillPedPhot");
239 MFillH fill4(&evt4, "MPedPhotCam", "FillPedRMS");
240 MFillH fill5(&evt5, "MCerPhotEvt", "FillInterpolated");
241 MFillH fill6(&evt6, "MBadPixelsCam", "FillUnsuitable");
242 MFillH fill7(&evt7, "MArrivalTime", "FillTimes");
243
244 MWriteRootFile write(2, Form("%s{s/_D_/_Y_}", fPathOut.Data()), fOverwrite);
245 // Run Header
246 write.AddContainer("MRawRunHeader", "RunHeaders");
247 write.AddContainer("MBadPixelsCam", "RunHeaders");
248 write.AddContainer("MGeomCam", "RunHeaders");
249 // Monte Carlo Headers
250 write.AddContainer("MMcTrigHeader", "RunHeaders", kFALSE);
251 write.AddContainer("MMcConfigRunHeader", "RunHeaders", kFALSE);
252 write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
253 // Monte Carlo
254 write.AddContainer("MMcEvt", "Events", kFALSE);
255 write.AddContainer("MMcTrig", "Events", kFALSE);
256 // Data
257 write.AddContainer("MCerPhotEvt", "Events");
258 write.AddContainer("MPedPhotCam", "Events");
259 write.AddContainer("MTime", "Events", kFALSE);
260 write.AddContainer("MRawEvtHeader", "Events");
261 write.AddContainer("MArrivalTime", "Events");
262 // Slow-Control: Current
263 write.AddContainer("MTimeCurrents", "Currents", kFALSE);
264 write.AddContainer("MCameraDC", "Currents", kFALSE);
265 write.AddContainer("MReportCurrents", "Currents", kFALSE);
266 // Slow-Control: Camera
267 write.AddContainer("MReportCamera", "Camera", kFALSE);
268 write.AddContainer("MTimeCamera", "Camera", kFALSE);
269 write.AddContainer("MCameraAUX", "Camera", kFALSE);
270 write.AddContainer("MCameraCalibration", "Camera", kFALSE);
271 write.AddContainer("MCameraCooling", "Camera", kFALSE);
272 write.AddContainer("MCameraHV", "Camera", kFALSE);
273 write.AddContainer("MCameraLV", "Camera", kFALSE);
274 write.AddContainer("MCameraLids", "Camera", kFALSE);
275 // Slow-Control: Trigger
276 write.AddContainer("MReportTrigger", "Trigger", kFALSE);
277 write.AddContainer("MTimeTrigger", "Trigger", kFALSE);
278 // Slow-Control: Drive
279 write.AddContainer("MPointingPos", "Drive", kFALSE);
280 write.AddContainer("MReportDrive", "Drive", kFALSE);
281 write.AddContainer("MTimeDrive", "Drive", kFALSE);
282 // Slow-Control: Central Control
283 write.AddContainer("MReportCC", "CC", kFALSE);
284 write.AddContainer("MTimeCC", "CC", kFALSE);
285
286 // Now setup tasklist for events
287 MTaskList tlist2;
288 tlist2.AddToList(&apply);
289 tlist2.AddToList(&merge);
290 if (filetype==3)
291 tlist2.AddToList(&pcopy);
292 else
293 {
294 tlist2.AddToList(&pedlo1);
295 tlist2.AddToList(&pedlo2);
296 }
297 tlist2.AddToList(&fill0);
298 tlist2.AddToList(&fill1);
299 tlist2.AddToList(&taskenv1);
300 tlist2.AddToList(&fill2);
301 tlist2.AddToList(&calib);
302 if (&relcam)
303 tlist2.AddToList(&caltm);
304 tlist2.AddToList(&fill3);
305 tlist2.AddToList(&bpcal);
306 tlist2.AddToList(&treat);
307 tlist2.AddToList(&fill4);
308 tlist2.AddToList(&fill5);
309 tlist2.AddToList(&fill6);
310 tlist2.AddToList(&fill7);
311
312 // Setup List for Drive-tree
313 MPointingPosCalc pcalc;
314
315 // Now setup main tasklist
316 tlist.AddToList(IsDataCheck() ? (MTask*)&rawread : (MTask*)&readreal);
317 tlist.AddToList(&tlist2, IsDataCheck()?"All":"Events");
318 if (!IsDataCheck())
319 tlist.AddToList(&pcalc, "Drive");
320 tlist.AddToList(&write);
321
322 // Create and setup the eventloop
323 MEvtLoop evtloop(fName);
324 evtloop.SetParList(&plist);
325 evtloop.SetDisplay(fDisplay);
326 evtloop.SetLogStream(fLog);
327 if (!SetupEnv(evtloop))
328 return kFALSE;
329
330 // Execute first analysis
331 if (!evtloop.Eventloop(fMaxEvents))
332 {
333 *fLog << err << GetDescriptor() << ": Failed." << endl;
334 return kFALSE;
335 }
336
337 tlist.PrintStatistics();
338
339 if (!WriteResult())
340 return kFALSE;
341
342 *fLog << all << GetDescriptor() << ": Done." << endl;
343 *fLog << endl << endl;
344
345 return kTRUE;
346}
Note: See TracBrowser for help on using the repository browser.