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

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