source: trunk/MagicSoft/Mars/mjobs/MJExtractCalibTest.cc@ 4067

Last change on this file since 4067 was 4066, checked in by gaug, 21 years ago
*** empty log message ***
File size: 12.5 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): Markus Gaug, 04/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJExtractCalibTest
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MJExtractCalibTest.h"
31
32#include <TFile.h>
33#include <TStyle.h>
34#include <TCanvas.h>
35#include <TSystem.h>
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MRunIter.h"
41#include "MParList.h"
42#include "MTaskList.h"
43#include "MEvtLoop.h"
44
45#include "MHCamera.h"
46
47#include "MPedestalCam.h"
48#include "MBadPixelsCam.h"
49#include "MCerPhotEvt.h"
50#include "MArrivalTime.h"
51#include "MCalibrationChargeCam.h"
52#include "MCalibrationRelTimeCam.h"
53#include "MCalibrationQECam.h"
54#include "MHCamEvent.h"
55
56#include "MReadMarsFile.h"
57#include "MGeomApply.h"
58#include "MExtractSlidingWindow.h"
59#include "MExtractor.h"
60#include "MExtractTime.h"
61#include "MExtractTimeFastSpline.h"
62#include "MFillH.h"
63#include "MCalibrate.h"
64#include "MCalibrateRelTimes.h"
65#include "MPedPhotCalc.h"
66
67#include "MStatusDisplay.h"
68
69ClassImp(MJExtractCalibTest);
70
71using namespace std;
72// --------------------------------------------------------------------------
73//
74// Default constructor.
75//
76// Sets fRuns to 0, fExtractor to NULL, fTimeExtractor to NULL
77//
78MJExtractCalibTest::MJExtractCalibTest(const char *name, const char *title)
79 : fRuns(NULL), fExtractor(NULL), fTimeExtractor(NULL)
80{
81 fName = name ? name : "MJExtractCalibTest";
82 fTitle = title ? title : "Tool to extract, calibrate and test signals from a file";
83}
84
85
86void MJExtractCalibTest::DisplayResult(MParList &plist)
87{
88 if (!fDisplay)
89 return;
90
91 //
92 // Update display
93 //
94 TString title = fDisplay->GetTitle();
95 title += "-- Extraction-Calibration-Test ";
96 title += fRuns->GetRunsAsString();
97 title += " --";
98 fDisplay->SetTitle(title);
99
100 //
101 // Get container from list
102 //
103 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
104
105 // Create histograms to display
106 MHCamera disp1 (geomcam, "Test;Photons", "Mean of calibrated Photons");
107 MHCamera disp2 (geomcam, "Test;SigmaPhotons", "Sigma of calibrated photons");
108 MHCamera disp3 (geomcam, "Test;PhotonsPerArea", "Equiv. Cherenkov Photons per Area");
109 MHCamera disp4 (geomcam, "Test;SigmaPhotPerArea", "Sigma equiv. Cher. Photons per Area");
110
111 // Fitted charge means and sigmas
112 disp1.SetCamContent(fTestCam, 0);
113 disp1.SetCamError( fTestCam, 1);
114 disp2.SetCamContent(fTestCam, 2);
115 disp2.SetCamError( fTestCam, 3);
116 disp3.SetCamContent(fTestCam, 7);
117 disp3.SetCamError( fTestCam, 8);
118 disp4.SetCamContent(fTestCam, 9);
119 disp4.SetCamError( fTestCam, 10);
120
121 disp1.SetYTitle("Photons");
122 disp2.SetYTitle("\\sigma_{phot}");
123 disp3.SetYTitle("Photons per Area [mm^{-2}]");
124 disp4.SetYTitle("\\sigma_{phot} per Area [mm^{-2}]");
125
126 gStyle->SetOptStat(1111);
127 gStyle->SetOptFit();
128
129 TCanvas &c = fDisplay->AddTab("TestCharges");
130 c.Divide(4,4);
131
132 CamDraw(c, 1, 4, disp1, 2, 1);
133 CamDraw(c, 2, 4, disp2, 2, 1);
134 CamDraw(c, 3, 4, disp3, 1, 1);
135 CamDraw(c, 4, 4, disp4, 2, 1);
136
137 return;
138
139}
140
141
142void MJExtractCalibTest::DisplayResultT(MParList &plist)
143{
144 if (!fDisplay)
145 return;
146
147 //
148 // Update display
149 //
150 TString title = fDisplay->GetTitle();
151 title += "-- Extraction-Calibration-Test-Time";
152 title += fRuns->GetRunsAsString();
153 title += " --";
154 fDisplay->SetTitle(title);
155
156 //
157 // Get container from list
158 //
159 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
160
161 // Create histograms to display
162 MHCamera disp1 (geomcam, "Test;Arr.Times", "Mean of calibrated Arr.Times");
163 MHCamera disp2 (geomcam, "Test;SigmaArr.Times", "Sigma of calibrated Arr.Times");
164
165 // Fitted charge means and sigmas
166 disp1.SetCamContent(fTestTimeCam, 0);
167 disp1.SetCamError( fTestTimeCam, 1);
168 disp2.SetCamContent(fTestTimeCam, 2);
169 disp2.SetCamError( fTestTimeCam, 3);
170
171 disp1.SetYTitle("Mean Arr.Times [FADC units]");
172 disp2.SetYTitle("\\sigma_{t} [FADC units]");
173
174 gStyle->SetOptStat(1111);
175 gStyle->SetOptFit();
176
177 TCanvas &c = fDisplay->AddTab("TestTimes");
178 c.Divide(4,2);
179
180 CamDraw(c, 1, 2, disp1, 5, 1);
181 CamDraw(c, 2, 2, disp2, 5, 1);
182
183 return;
184
185}
186
187
188void MJExtractCalibTest::SetOutputPath(const char *path)
189{
190 fOutputPath = path;
191 if (fOutputPath.EndsWith("/"))
192 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
193}
194
195TString MJExtractCalibTest::GetOutputFile() const
196{
197 if (!fRuns)
198 return "";
199
200 return Form("%s/%s-Test.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
201}
202
203
204Bool_t MJExtractCalibTest::ProcessD(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
205{
206 // const TString fname = GetOutputFile();
207
208// if (gSystem->AccessPathName(fname, kFileExists))
209 return ProcessFileD(pedcam,calcam,qecam);
210
211 // return kTRUE;
212}
213
214Bool_t MJExtractCalibTest::ProcessFileD(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
215{
216 if (!fRuns)
217 {
218 *fLog << err << "No Runs choosen... abort." << endl;
219 return kFALSE;
220 }
221 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
222 {
223 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
224 return kFALSE;
225 }
226
227 *fLog << inf;
228 fLog->Separator(GetDescriptor());
229 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
230 *fLog << endl;
231
232 MCerPhotEvt cerphot;
233 MPedPhotCam pedphot;
234 // Setup Lists
235 MParList plist;
236 plist.AddToList(&pedcam);
237 plist.AddToList(&calcam);
238 plist.AddToList(&qecam);
239 plist.AddToList(&cerphot);
240 plist.AddToList(&pedphot);
241 plist.AddToList(&fTestCam);
242 plist.AddToList(&fBadPixels);
243
244 MTaskList tlist;
245 plist.AddToList(&tlist);
246
247 // Setup Task-lists
248 MReadMarsFile read("Events");
249 read.DisableAutoScheme();
250 static_cast<MRead&>(read).AddFiles(*fRuns);
251
252 MGeomApply apply; // Only necessary to craete geometry
253 MExtractSlidingWindow extract2;
254 MCalibrate photcalc;
255 photcalc.SetCalibrationMode(MCalibrate::kFfactor);
256 MPedPhotCalc pedphotcalc;
257
258 MHCamEvent evt("ExtSignal");
259 evt.SetType(0);
260 MFillH fill(&evt, "MExtractedSignalCam");
261
262 MFillH fillcam("MHCalibrationTestCam", "MCerPhotEvt");
263 fillcam.SetNameTab("Test");
264
265
266 tlist.AddToList(&read);
267 tlist.AddToList(&apply);
268
269 if (fExtractor)
270 tlist.AddToList(fExtractor);
271 else
272 {
273 *fLog << warn << GetDescriptor()
274 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
275 tlist.AddToList(&extract2);
276 }
277
278 // if (TestBit(kEnableGraphicalOutput))
279 tlist.AddToList(&fill);
280 tlist.AddToList(&photcalc);
281 tlist.AddToList(&pedphotcalc);
282 tlist.AddToList(&fillcam);
283
284 // Create and setup the eventloop
285 MEvtLoop evtloop(fName);
286 evtloop.SetParList(&plist);
287 evtloop.SetDisplay(fDisplay);
288 evtloop.SetLogStream(fLog);
289
290 // Execute first analysis
291 if (!evtloop.Eventloop())
292 {
293 *fLog << err << GetDescriptor() << ": Failed." << endl;
294 return kFALSE;
295 }
296
297 tlist.PrintStatistics();
298
299 DisplayResult(plist);
300
301 if (!WriteResultD())
302 return kFALSE;
303
304 *fLog << inf << GetDescriptor() << ": Done." << endl;
305
306 return kTRUE;
307}
308
309Bool_t MJExtractCalibTest::ProcessT(MPedestalCam &pedcam, MCalibrationRelTimeCam &relcam)
310{
311
312// const TString fname = GetOutputFile();
313
314// if (gSystem->AccessPathName(fname, kFileExists))
315 return ProcessFileT(pedcam,relcam);
316
317// return kTRUE;
318}
319
320Bool_t MJExtractCalibTest::ProcessFileT(MPedestalCam &pedcam, MCalibrationRelTimeCam &relcam)
321{
322
323 if (!fRuns)
324 {
325 *fLog << err << "No Runs choosen... abort." << endl;
326 return kFALSE;
327 }
328 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
329 {
330 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
331 return kFALSE;
332 }
333
334 *fLog << inf;
335 fLog->Separator(GetDescriptor());
336 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
337 *fLog << endl;
338
339 MArrivalTime arrtime;
340
341 // Setup Lists
342 MParList plist;
343 plist.AddToList(&pedcam);
344 plist.AddToList(&relcam);
345 plist.AddToList(&arrtime);
346 plist.AddToList(&fTestTimeCam);
347 plist.AddToList(&fBadPixels);
348
349 MTaskList tlist;
350 plist.AddToList(&tlist);
351
352 // Setup Task-lists
353 MReadMarsFile read("Events");
354 read.DisableAutoScheme();
355 static_cast<MRead&>(read).AddFiles(*fRuns);
356
357 MGeomApply apply; // Only necessary to craete geometry
358 MExtractTimeFastSpline extract;
359 MCalibrateRelTimes timecalc;
360
361 MHCamEvent evt("ExtTimes");
362 evt.SetType(0);
363 MFillH fill(&evt, "MArrivalTimeCam");
364
365 MFillH fillcam("MHCalibrationTestTimeCam", "MArrivalTime");
366 fillcam.SetNameTab("TestTime");
367
368 tlist.AddToList(&read);
369 tlist.AddToList(&apply);
370
371 if (fTimeExtractor)
372 tlist.AddToList(fTimeExtractor);
373 else
374 {
375 *fLog << warn << GetDescriptor()
376 << ": No extractor has been chosen, take default MExtractTimeFastSpline " << endl;
377 tlist.AddToList(&extract);
378 }
379
380 // if (TestBit(kEnableGraphicalOutput))
381 tlist.AddToList(&fill);
382 tlist.AddToList(&timecalc);
383 tlist.AddToList(&fillcam);
384
385 // Create and setup the eventloop
386 MEvtLoop evtloop(fName);
387 evtloop.SetParList(&plist);
388 evtloop.SetDisplay(fDisplay);
389 evtloop.SetLogStream(fLog);
390
391 // Execute first analysis
392 if (!evtloop.Eventloop())
393 {
394 *fLog << err << GetDescriptor() << ": Failed." << endl;
395 return kFALSE;
396 }
397
398 tlist.PrintStatistics();
399
400 DisplayResultT(plist);
401
402 if (!WriteResultT())
403 return kFALSE;
404
405 *fLog << inf << GetDescriptor() << ": Done." << endl;
406
407 return kTRUE;
408}
409
410
411Bool_t MJExtractCalibTest::ReadPedPhotCam()
412{
413 const TString fname = GetOutputFile();
414
415 if (gSystem->AccessPathName(fname, kFileExists))
416 {
417 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
418 return kFALSE;
419 }
420
421 *fLog << inf << "Reading from file: " << fname << endl;
422
423 TFile file(fname, "READ");
424 if (fPedPhotCam.Read()<=0)
425 {
426 *fLog << "Unable to read MPedPhotCam from " << fname << endl;
427 return kFALSE;
428 }
429
430 if (file.FindKey("MBadPixelsCam"))
431 {
432 MBadPixelsCam bad;
433 if (bad.Read()<=0)
434 {
435 *fLog << "Unable to read MBadPixelsCam from " << fname << endl;
436 return kFALSE;
437 }
438 fBadPixels.Merge(bad);
439 }
440
441 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
442 fDisplay->Read();
443
444 return kTRUE;
445}
446
447Bool_t MJExtractCalibTest::WriteResultD()
448{
449
450 if (fOutputPath.IsNull())
451 return kTRUE;
452
453 const TString oname(GetOutputFile());
454
455 *fLog << inf << "Writing to file: " << oname << endl;
456
457 TFile file(oname, "UPDATE");
458
459 if (fDisplay && fDisplay->Write()<=0)
460 {
461 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
462 return kFALSE;
463 }
464
465 if (fPedPhotCam.Write()<=0)
466 {
467 *fLog << err << "Unable to write MPedPhotCam to " << oname << endl;
468 return kFALSE;
469 }
470
471 if (fTestCam.Write()<=0)
472 {
473 *fLog << err << "Unable to write MHCalibrationTestCam to " << oname << endl;
474 return kFALSE;
475 }
476
477 return kTRUE;
478
479}
480
481Bool_t MJExtractCalibTest::WriteResultT()
482{
483
484 if (fOutputPath.IsNull())
485 return kTRUE;
486
487 const TString oname(GetOutputFile());
488
489 *fLog << inf << "Writing to file: " << oname << endl;
490
491 TFile file(oname, "UPDATE");
492
493 if (fDisplay && fDisplay->Write()<=0)
494 {
495 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
496 return kFALSE;
497 }
498
499 if (fTestTimeCam.Write()<=0)
500 {
501 *fLog << err << "Unable to write MHCalibrationTestTimeCam to " << oname << endl;
502 return kFALSE;
503 }
504
505 return kTRUE;
506
507}
508
509
Note: See TracBrowser for help on using the repository browser.