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

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