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

Last change on this file since 4532 was 4532, checked in by gaug, 20 years ago
*** empty log message ***
File size: 13.0 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(2,4);
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 badtreat.SetSloppyTreatment();
264
265 MHCamEvent evt("ExtSignal");
266 evt.SetType(0);
267 MFillH fill(&evt, "MExtractedSignalCam");
268
269 MFillH fillcam("MHCalibrationTestCam", "MCerPhotEvt");
270 fillcam.SetNameTab("Test");
271
272 MFCosmics cosmics;
273 MContinue cont(&cosmics);
274
275 tlist.AddToList(&read);
276 tlist.AddToList(&apply);
277
278 if (fExtractor)
279 tlist.AddToList(fExtractor);
280 else
281 {
282 *fLog << warn << GetDescriptor()
283 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
284 tlist.AddToList(&extract2);
285 }
286
287
288 if (fUseCosmicsFilter)
289 tlist.AddToList(&cont);
290
291 tlist.AddToList(&fill);
292 tlist.AddToList(&photcalc);
293 tlist.AddToList(&pedphotcalc);
294 tlist.AddToList(&badtreat);
295 tlist.AddToList(&fillcam);
296
297 // Create and setup the eventloop
298 MEvtLoop evtloop(fName);
299 evtloop.SetParList(&plist);
300 evtloop.SetDisplay(fDisplay);
301 evtloop.SetLogStream(fLog);
302
303 // Execute first analysis
304 if (!evtloop.Eventloop())
305 {
306 *fLog << err << GetDescriptor() << ": Failed." << endl;
307 return kFALSE;
308 }
309
310 tlist.PrintStatistics();
311
312 DisplayResult(plist);
313
314 if (!WriteResultD())
315 return kFALSE;
316
317 *fLog << inf << GetDescriptor() << ": Done." << endl;
318
319 return kTRUE;
320}
321
322Bool_t MJExtractCalibTest::ProcessT(MPedestalCam &pedcam, MCalibrationRelTimeCam &relcam)
323{
324
325// const TString fname = GetOutputFile();
326
327// if (gSystem->AccessPathName(fname, kFileExists))
328 return ProcessFileT(pedcam,relcam);
329
330// return kTRUE;
331}
332
333Bool_t MJExtractCalibTest::ProcessFileT(MPedestalCam &pedcam, MCalibrationRelTimeCam &relcam)
334{
335
336 if (!fRuns)
337 {
338 *fLog << err << "No Runs choosen... abort." << endl;
339 return kFALSE;
340 }
341 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
342 {
343 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
344 return kFALSE;
345 }
346
347 *fLog << inf;
348 fLog->Separator(GetDescriptor());
349 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
350 *fLog << endl;
351
352 MArrivalTime arrtime;
353
354 // Setup Lists
355 MParList plist;
356 plist.AddToList(&pedcam);
357 plist.AddToList(&relcam);
358 plist.AddToList(&arrtime);
359 plist.AddToList(&fTestTimeCam);
360 plist.AddToList(&fBadPixels);
361
362 MTaskList tlist;
363 plist.AddToList(&tlist);
364
365 // Setup Task-lists
366 MReadMarsFile read("Events");
367 read.DisableAutoScheme();
368 static_cast<MRead&>(read).AddFiles(*fRuns);
369
370 MGeomApply apply; // Only necessary to craete geometry
371 MExtractTimeFastSpline extract;
372 MExtractSlidingWindow extcharge; // Only for the cosmics filter
373 MCalibrateRelTimes timecalc;
374 MFCosmics cosmics;
375 MContinue cont(&cosmics);
376
377 MHCamEvent evt("ExtTimes");
378 evt.SetType(0);
379 MFillH fill(&evt, "MArrivalTimeCam");
380
381 MFillH fillcam("MHCalibrationTestTimeCam", "MArrivalTime");
382 fillcam.SetNameTab("TestTime");
383
384 tlist.AddToList(&read);
385 tlist.AddToList(&apply);
386
387 if (fTimeExtractor)
388 tlist.AddToList(fTimeExtractor);
389 else
390 {
391 *fLog << warn << GetDescriptor()
392 << ": No extractor has been chosen, take default MExtractTimeFastSpline " << endl;
393 tlist.AddToList(&extract);
394 }
395
396 tlist.AddToList(&extcharge);
397 tlist.AddToList(&cont);
398 tlist.AddToList(&fill);
399 tlist.AddToList(&timecalc);
400 tlist.AddToList(&fillcam);
401
402 // Create and setup the eventloop
403 MEvtLoop evtloop(fName);
404 evtloop.SetParList(&plist);
405 evtloop.SetDisplay(fDisplay);
406 evtloop.SetLogStream(fLog);
407
408 // Execute first analysis
409 if (!evtloop.Eventloop())
410 {
411 *fLog << err << GetDescriptor() << ": Failed." << endl;
412 return kFALSE;
413 }
414
415 tlist.PrintStatistics();
416
417 DisplayResultT(plist);
418
419 if (!WriteResultT())
420 return kFALSE;
421
422 *fLog << inf << GetDescriptor() << ": Done." << endl;
423
424 return kTRUE;
425}
426
427
428Bool_t MJExtractCalibTest::ReadPedPhotCam()
429{
430
431 const TString fname = GetOutputFile();
432
433 if (gSystem->AccessPathName(fname, kFileExists))
434 {
435 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
436 return kFALSE;
437 }
438
439 *fLog << inf << "Reading from file: " << fname << endl;
440
441 TFile file(fname, "READ");
442 if (fPedPhotCam.Read()<=0)
443 {
444 *fLog << "Unable to read MPedPhotCam from " << fname << endl;
445 return kFALSE;
446 }
447
448 if (file.FindKey("MBadPixelsCam"))
449 {
450 MBadPixelsCam bad;
451 if (bad.Read()<=0)
452 {
453 *fLog << "Unable to read MBadPixelsCam from " << fname << endl;
454 return kFALSE;
455 }
456 fBadPixels.Merge(bad);
457 }
458
459 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
460 fDisplay->Read();
461
462 return kTRUE;
463}
464
465Bool_t MJExtractCalibTest::WriteResultD()
466{
467
468 if (fOutputPath.IsNull())
469 return kTRUE;
470
471 const TString oname(GetOutputFile());
472
473 *fLog << inf << "Writing to file: " << oname << endl;
474
475 TFile file(oname, "UPDATE");
476
477 if (fDisplay && fDisplay->Write()<=0)
478 {
479 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
480 return kFALSE;
481 }
482
483 if (fPedPhotCam.Write()<=0)
484 {
485 *fLog << err << "Unable to write MPedPhotCam to " << oname << endl;
486 return kFALSE;
487 }
488
489 if (fTestCam.Write()<=0)
490 {
491 *fLog << err << "Unable to write MHCalibrationTestCam to " << oname << endl;
492 return kFALSE;
493 }
494
495 return kTRUE;
496
497}
498
499Bool_t MJExtractCalibTest::WriteResultT()
500{
501
502 if (fOutputPath.IsNull())
503 return kTRUE;
504
505 const TString oname(GetOutputFile());
506
507 *fLog << inf << "Writing to file: " << oname << endl;
508
509 TFile file(oname, "UPDATE");
510
511 if (fDisplay && fDisplay->Write()<=0)
512 {
513 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
514 return kFALSE;
515 }
516
517 if (fTestTimeCam.Write()<=0)
518 {
519 *fLog << err << "Unable to write MHCalibrationTestTimeCam to " << oname << endl;
520 return kFALSE;
521 }
522
523 return kTRUE;
524
525}
526
527
Note: See TracBrowser for help on using the repository browser.