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

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