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

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