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

Last change on this file since 4007 was 3982, checked in by gaug, 21 years ago
*** empty log message ***
File size: 17.6 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#include "MWriteRootFile.h"
67
68#include "MStatusDisplay.h"
69
70ClassImp(MJExtractCalibTest);
71
72using namespace std;
73// --------------------------------------------------------------------------
74//
75// Default constructor.
76//
77// Sets fRuns to 0, fExtractor to NULL, fTimeExtractor to NULL
78//
79MJExtractCalibTest::MJExtractCalibTest(const char *name, const char *title)
80 : fRuns(NULL), fExtractor(NULL), fTimeExtractor(NULL)
81{
82 fName = name ? name : "MJExtractCalibTest";
83 fTitle = title ? title : "Tool to extract, calibrate and test signals from a file";
84}
85
86
87void MJExtractCalibTest::DisplayResult(MParList &plist)
88{
89 if (!fDisplay)
90 return;
91
92 //
93 // Update display
94 //
95 TString title = fDisplay->GetTitle();
96 title += "-- Extraction-Calibration-Test ";
97 title += fRuns->GetRunsAsString();
98 title += " --";
99 fDisplay->SetTitle(title);
100
101 //
102 // Get container from list
103 //
104 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
105
106 // Create histograms to display
107 MHCamera disp1 (geomcam, "Test;Photons", "Mean of calibrated Photons");
108 MHCamera disp2 (geomcam, "Test;SigmaPhotons", "Sigma of calibrated photons");
109 MHCamera disp3 (geomcam, "Test;PhotonsPerArea", "Equiv. Cherenkov Photons per Area");
110 MHCamera disp4 (geomcam, "Test;SigmaPhotPerArea", "Sigma equiv. Cher. Photons per Area");
111
112 // Fitted charge means and sigmas
113 disp1.SetCamContent(fTestCam, 0);
114 disp1.SetCamError( fTestCam, 1);
115 disp2.SetCamContent(fTestCam, 2);
116 disp2.SetCamError( fTestCam, 3);
117 disp3.SetCamContent(fTestCam, 7);
118 disp3.SetCamError( fTestCam, 8);
119 disp4.SetCamContent(fTestCam, 9);
120 disp4.SetCamError( fTestCam, 10);
121
122 disp1.SetYTitle("Photons");
123 disp2.SetYTitle("\\sigma_{phot}");
124 disp3.SetYTitle("Photons per Area [mm^{-2}]");
125 disp4.SetYTitle("\\sigma_{phot} per Area [mm^{-2}]");
126
127 gStyle->SetOptStat(1111);
128 gStyle->SetOptFit();
129
130 TCanvas &c = fDisplay->AddTab("TestCharges");
131 c.Divide(4,4);
132
133 CamDraw(c, 1, 4, disp1, 2, 1);
134 CamDraw(c, 2, 4, disp2, 2, 1);
135 CamDraw(c, 3, 4, disp3, 1, 1);
136 CamDraw(c, 4, 4, disp4, 2, 1);
137
138 return;
139
140}
141
142
143void MJExtractCalibTest::SetOutputPath(const char *path)
144{
145 fOutputPath = path;
146 if (fOutputPath.EndsWith("/"))
147 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
148}
149
150TString MJExtractCalibTest::GetOutputFileD() const
151{
152 if (!fRuns)
153 return "";
154
155 return Form("%s/%s-F3.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
156}
157
158TString MJExtractCalibTest::GetOutputFileT() const
159{
160 if (!fRuns)
161 return "";
162
163 return Form("%s/%s-F4.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
164}
165
166TString MJExtractCalibTest::GetOutputFileP() const
167{
168 if (!fRuns)
169 return "";
170
171 return Form("%s/%s-F2.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
172}
173
174Bool_t MJExtractCalibTest::ProcessD(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
175{
176 const TString fname = GetOutputFileD();
177
178 if (gSystem->AccessPathName(fname, kFileExists))
179 return ProcessFileD(pedcam,calcam,qecam);
180
181 return kTRUE;
182}
183
184Bool_t MJExtractCalibTest::ProcessFileD(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
185{
186 if (!fRuns)
187 {
188 *fLog << err << "No Runs choosen... abort." << endl;
189 return kFALSE;
190 }
191 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
192 {
193 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
194 return kFALSE;
195 }
196
197 *fLog << inf;
198 fLog->Separator(GetDescriptor());
199 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
200 *fLog << endl;
201
202 MCerPhotEvt cerphot;
203
204 // Setup Lists
205 MParList plist;
206 plist.AddToList(&pedcam);
207 plist.AddToList(&calcam);
208 plist.AddToList(&qecam);
209 plist.AddToList(&cerphot);
210 plist.AddToList(&fTestCam);
211 plist.AddToList(&fBadPixels);
212
213 MTaskList tlist;
214 plist.AddToList(&tlist);
215
216 // Setup Task-lists
217 MReadMarsFile read("Events");
218 read.DisableAutoScheme();
219 static_cast<MRead&>(read).AddFiles(*fRuns);
220
221 MGeomApply apply; // Only necessary to craete geometry
222 MExtractSlidingWindow extract2;
223 MCalibrate photcalc;
224 photcalc.SetCalibrationMode(MCalibrate::kFfactor);
225
226 MHCamEvent evt("ExtSignal");
227 evt.SetType(0);
228 MFillH fill(&evt, "MExtractedSignalCam");
229
230 MFillH fillcam("MHCalibrationTestCam", "MCerPhotEvt");
231 fillcam.SetNameTab("Test");
232
233 /*
234 MWriteRootFile write(GetOutputFileD(), "RECREATE", fRuns->GetRunsAsString(), 2);
235 write.AddContainer("MExtractedSignalCam", "Events");
236 write.AddContainer("MTime", "Events");
237 write.AddContainer("MRawEvtHeader", "Events");
238 write.AddContainer("MPedestalCam", "RunHeaders");
239 write.AddContainer("MRawRunHeader", "RunHeaders");
240 write.AddContainer("MBadPixelsCam", "RunHeaders");
241 */
242
243 tlist.AddToList(&read);
244 tlist.AddToList(&apply);
245
246 if (fExtractor)
247 tlist.AddToList(fExtractor);
248 else
249 {
250 *fLog << warn << GetDescriptor()
251 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
252 tlist.AddToList(&extract2);
253 }
254
255 // if (TestBit(kEnableGraphicalOutput))
256 tlist.AddToList(&fill);
257 tlist.AddToList(&photcalc);
258 tlist.AddToList(&fillcam);
259
260 // Create and setup the eventloop
261 MEvtLoop evtloop(fName);
262 evtloop.SetParList(&plist);
263 evtloop.SetDisplay(fDisplay);
264 evtloop.SetLogStream(fLog);
265
266 // Execute first analysis
267 if (!evtloop.Eventloop())
268 {
269 *fLog << err << GetDescriptor() << ": Failed." << endl;
270 return kFALSE;
271 }
272
273 tlist.PrintStatistics();
274
275 DisplayResult(plist);
276
277 *fLog << inf << GetDescriptor() << ": Done." << endl;
278
279 return kTRUE;
280}
281
282Bool_t MJExtractCalibTest::ProcessT(MPedestalCam &pedcam, MCalibrationRelTimeCam &relcam)
283{
284 const TString fname = GetOutputFileT();
285
286 if (gSystem->AccessPathName(fname, kFileExists))
287 return ProcessFileT(pedcam,relcam);
288
289 return kTRUE;
290}
291
292Bool_t MJExtractCalibTest::ProcessFileT(MPedestalCam &pedcam, MCalibrationRelTimeCam &relcam)
293{
294
295 if (!fRuns)
296 {
297 *fLog << err << "No Runs choosen... abort." << endl;
298 return kFALSE;
299 }
300 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
301 {
302 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
303 return kFALSE;
304 }
305
306 *fLog << inf;
307 fLog->Separator(GetDescriptor());
308 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
309 *fLog << endl;
310
311 MArrivalTime arrtime;
312
313 // Setup Lists
314 MParList plist;
315 plist.AddToList(&pedcam);
316 plist.AddToList(&relcam);
317 plist.AddToList(&arrtime);
318 plist.AddToList(&fTestCam);
319 plist.AddToList(&fBadPixels);
320
321 MTaskList tlist;
322 plist.AddToList(&tlist);
323
324 // Setup Task-lists
325 MReadMarsFile read("Events");
326 read.DisableAutoScheme();
327 static_cast<MRead&>(read).AddFiles(*fRuns);
328
329 MGeomApply apply; // Only necessary to craete geometry
330 MExtractTimeFastSpline extract;
331 MCalibrateRelTimes timecalc;
332
333 MHCamEvent evt("ExtTimes");
334 evt.SetType(0);
335 MFillH fill(&evt, "MArrivalTimeCam");
336
337 MFillH fillcam("MHCalibrationTestTimeCam", "MArrivalTime");
338 fillcam.SetNameTab("TestTime");
339
340 /*
341 MWriteRootFile write(GetOutputFileD(), "RECREATE", fRuns->GetRunsAsString(), 2);
342 write.AddContainer("MExtractedSignalCam", "Events");
343 write.AddContainer("MTime", "Events");
344 write.AddContainer("MRawEvtHeader", "Events");
345 write.AddContainer("MPedestalCam", "RunHeaders");
346 write.AddContainer("MRawRunHeader", "RunHeaders");
347 write.AddContainer("MBadPixelsCam", "RunHeaders");
348 */
349
350 tlist.AddToList(&read);
351 tlist.AddToList(&apply);
352
353 if (fTimeExtractor)
354 tlist.AddToList(fTimeExtractor);
355 else
356 {
357 *fLog << warn << GetDescriptor()
358 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
359 tlist.AddToList(&extract);
360 }
361
362 // if (TestBit(kEnableGraphicalOutput))
363 tlist.AddToList(&fill);
364 tlist.AddToList(&timecalc);
365 tlist.AddToList(&fillcam);
366
367 // Create and setup the eventloop
368 MEvtLoop evtloop(fName);
369 evtloop.SetParList(&plist);
370 evtloop.SetDisplay(fDisplay);
371 evtloop.SetLogStream(fLog);
372
373 // Execute first analysis
374 if (!evtloop.Eventloop())
375 {
376 *fLog << err << GetDescriptor() << ": Failed." << endl;
377 return kFALSE;
378 }
379
380 tlist.PrintStatistics();
381
382 DisplayResult(plist);
383
384 *fLog << inf << GetDescriptor() << ": Done." << endl;
385
386 return kTRUE;
387}
388
389
390Bool_t MJExtractCalibTest::ReadPedPhotCam()
391{
392 const TString fname = GetOutputFileP();
393
394 if (gSystem->AccessPathName(fname, kFileExists))
395 {
396 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
397 return kFALSE;
398 }
399
400 *fLog << inf << "Reading from file: " << fname << endl;
401
402 TFile file(fname, "READ");
403 if (fPedPhotCam.Read()<=0)
404 {
405 *fLog << "Unable to read MPedPhotCam from " << fname << endl;
406 return kFALSE;
407 }
408
409 if (file.FindKey("MBadPixelsCam"))
410 {
411 MBadPixelsCam bad;
412 if (bad.Read()<=0)
413 {
414 *fLog << "Unable to read MBadPixelsCam from " << fname << endl;
415 return kFALSE;
416 }
417 fBadPixels.Merge(bad);
418 }
419
420 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
421 fDisplay->Read();
422
423 return kTRUE;
424}
425
426Bool_t MJExtractCalibTest::ProcessP(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
427{
428 if (!ReadPedPhotCam())
429 return ProcessFileP(pedcam, calcam, qecam);
430
431 return kTRUE;
432}
433
434Bool_t MJExtractCalibTest::ProcessFileP(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
435{
436 if (!fRuns)
437 {
438 *fLog << err << "No Runs choosen... abort." << endl;
439 return kFALSE;
440 }
441 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
442 {
443 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
444 return kFALSE;
445 }
446
447 *fLog << inf;
448 fLog->Separator(GetDescriptor());
449 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
450 *fLog << endl;
451
452 MReadMarsFile read("Events");
453 read.DisableAutoScheme();
454 static_cast<MRead&>(read).AddFiles(*fRuns);
455
456 // Setup Tasklist
457 MParList plist;
458 plist.AddToList(&pedcam);
459 plist.AddToList(&calcam);
460 plist.AddToList(&fPedPhotCam);
461 plist.AddToList(&fBadPixels);
462
463 MTaskList tlist;
464 plist.AddToList(&tlist);
465
466 MGeomApply apply; // Only necessary to craete geometry
467 MExtractSlidingWindow extract2;
468 MCalibrate calib;
469 MPedPhotCalc calc;
470
471 MHCamEvent evt1("ExtOffset");
472 MHCamEvent evt2("CalOffset");
473 evt1.SetType(0);
474 evt2.SetType(0);
475 MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtractedSignal");
476 MFillH fill2(&evt2, "MCerPhotEvt", "FillCerPhotEvt");
477
478 tlist.AddToList(&read);
479 tlist.AddToList(&apply);
480
481 if (fExtractor)
482 tlist.AddToList(fExtractor);
483 else
484 {
485 *fLog << warn << GetDescriptor()
486 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
487 tlist.AddToList(&extract2);
488 }
489
490 if (TestBit(kEnableGraphicalOutput))
491 tlist.AddToList(&fill1);
492 tlist.AddToList(&calib);
493 tlist.AddToList(&calc);
494 if (TestBit(kEnableGraphicalOutput))
495 tlist.AddToList(&fill2);
496
497 // Create and setup the eventloop
498 MEvtLoop evtloop(fName);
499 evtloop.SetParList(&plist);
500 evtloop.SetDisplay(fDisplay);
501 evtloop.SetLogStream(fLog);
502
503 // Execute first analysis
504 if (!evtloop.Eventloop())
505 {
506 *fLog << err << GetDescriptor() << ": Failed." << endl;
507 return kFALSE;
508 }
509
510 tlist.PrintStatistics();
511
512 DisplayResult(plist);
513
514 *fLog << inf << GetDescriptor() << ": Done." << endl;
515
516 return kTRUE;
517}
518
519/*
520Bool_t MJExtractCalibTest::ProcessFile(MPedestalCam *pedcam, MCalibrationChargeCam *calcam)
521{
522 if (!fRuns)
523 {
524 *fLog << err << "No Runs choosen... abort." << endl;
525 return kFALSE;
526 }
527 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
528 {
529 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
530 return kFALSE;
531 }
532
533 Int_t type = 0;
534 if (pedcam && calcam) type = 2;
535 if (pedcam && !calcam) type = 3;
536
537 *fLog << inf;
538 fLog->Separator(GetDescriptor());
539 *fLog << "Calculating from Runs " << fRuns->GetRunsAsString() << endl;
540 *fLog << endl;
541
542 MReadMarsFile read("Events");
543 read.DisableAutoScheme();
544 static_cast<MRead&>(read).AddFiles(*fRuns);
545
546 // Setup Tasklist
547 MParList plist;
548 switch (type)
549 {
550 case 2:
551 plist.AddToList(calcam);
552 plist.AddToList(&fPedPhotCam);
553 case 3:
554 plist.AddToList(pedcam);
555 }
556
557 MTaskList tlist;
558 plist.AddToList(&tlist);
559
560 MGeomApply apply; // Only necessary to craete geometry
561 MExtractSignal extract;
562 MCalibrate calib;
563 MPedPhotCalc calc;
564
565
566 MHCamEvent evt1("ExtOffset");
567 MHCamEvent evt2("CalOffset");
568 evt1.SetType(0);
569 evt2.SetType(0);
570 MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtractedSignal");
571 MFillH fill2(&evt2, "MCerPhotEvt", "FillCerPhotEvt");
572
573 tlist.AddToList(&read);
574 tlist.AddToList(&apply);
575 tlist.AddToList(&extract);
576 if (TestBit(kEnableGraphicalOutput))
577 tlist.AddToList(&fill1);
578 tlist.AddToList(&calib);
579 tlist.AddToList(&calc);
580 if (TestBit(kEnableGraphicalOutput))
581 tlist.AddToList(&fill2);
582
583
584 MHCamEvent evt("ExtSignal");
585 evt.SetType(0);
586 MFillH fill(&evt, "MExtractedSignalCam");
587
588 MWriteRootFile write(GetOutputFileD(), "RECREATE", fRuns->GetRunsAsString(), 2);
589 write.AddContainer("MExtractedSignalCam", "Events");
590 write.AddContainer("MTime", "Events");
591 write.AddContainer("MRawRunHeader", "RunHeaders");
592 write.AddContainer("MPedestalCam", "RunHeaders");
593
594 tlist.AddToList(&read);
595 tlist.AddToList(&apply);
596 tlist.AddToList(&extract);
597 if (TestBit(kEnableGraphicalOutput))
598 tlist.AddToList(&fill);
599 tlist.AddToList(&write);
600
601 // Create and setup the eventloop
602 MEvtLoop evtloop(fName);
603 evtloop.SetParList(&plist);
604 evtloop.SetDisplay(fDisplay);
605 evtloop.SetLogStream(fLog);
606
607 // Execute first analysis
608 if (!evtloop.Eventloop())
609 {
610 *fLog << err << GetDescriptor() << ": Failed." << endl;
611 return kFALSE;
612 }
613
614 tlist.PrintStatistics();
615
616 //DisplayResult(plist);
617
618 //if (!WriteResult())
619 // return kFALSE;
620
621 *fLog << inf << GetDescriptor() << ": Done." << endl;
622
623 return kTRUE;
624
625
626 // ------------------------------------------------------
627
628 MGeomApply apply; // Only necessary to craete geometry
629 MExtractSignal extract;
630 MCalibrate calib;
631 MPedPhotCalc calc;
632
633 MHCamEvent evt1("ExtOffset");
634 MHCamEvent evt2("CalOffset");
635 evt1.SetType(0);
636 evt2.SetType(0);
637 MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtractedSignal");
638 MFillH fill2(&evt2, "MCerPhotEvt", "FillCerPhotEvt");
639
640 tlist.AddToList(&read);
641 tlist.AddToList(&apply);
642 tlist.AddToList(&extract);
643 if (TestBit(kEnableGraphicalOutput))
644 tlist.AddToList(&fill1);
645 tlist.AddToList(&calib);
646 tlist.AddToList(&calc);
647 if (TestBit(kEnableGraphicalOutput))
648 tlist.AddToList(&fill2);
649
650 // Create and setup the eventloop
651 MEvtLoop evtloop(fName);
652 evtloop.SetParList(&plist);
653 evtloop.SetDisplay(fDisplay);
654 evtloop.SetLogStream(fLog);
655
656 // Execute first analysis
657 if (!evtloop.Eventloop())
658 {
659 *fLog << err << GetDescriptor() << ": Failed." << endl;
660 return kFALSE;
661 }
662
663 tlist.PrintStatistics();
664
665 //DisplayResult(plist);
666
667 if (!WriteResult())
668 return kFALSE;
669
670 *fLog << inf << GetDescriptor() << ": Done." << endl;
671
672 return kTRUE;
673 }
674 */
Note: See TracBrowser for help on using the repository browser.