source: trunk/MagicSoft/Mars/mjobs/MJExtractSignal.cc@ 6232

Last change on this file since 6232 was 4773, checked in by gaug, 20 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): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJExtractSignal
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MJExtractSignal.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#include "MPrint.h"
45
46#include "MHCamera.h"
47
48#include "MPedestalCam.h"
49#include "MCalibrationChargeCam.h"
50#include "MCalibrationQECam.h"
51#include "MHCamEvent.h"
52
53#include "MReadMarsFile.h"
54#include "MGeomApply.h"
55#include "MBadPixelsMerge.h"
56#include "MExtractSignal.h"
57#include "MFillH.h"
58#include "MCalibrateData.h"
59#include "MPedPhotCalc.h"
60#include "MWriteRootFile.h"
61
62#include "MExtractSlidingWindow.h"
63#include "MExtractor.h"
64#include "MExtractTime.h"
65#include "MExtractTimeFastSpline.h"
66
67#include "MJExtractSignal.h"
68#include "MStatusDisplay.h"
69
70
71ClassImp(MJExtractSignal);
72
73using namespace std;
74
75MJExtractSignal::MJExtractSignal(const char *name, const char *title)
76 : fRuns(0), fExtractor(NULL), fTimeExtractor(NULL)
77{
78 fName = name ? name : "MJExtractSignal";
79 fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
80}
81
82Bool_t MJExtractSignal::WriteResult()
83{
84 if (fOutputPath.IsNull())
85 return kTRUE;
86
87 const TString oname = GetOutputFileP();
88
89 *fLog << inf << "Writing to file: " << oname << endl;
90
91 TFile file(oname, "RECREATE");
92
93 if (fDisplay && fDisplay->Write()<=0)
94 {
95 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
96 return kFALSE;
97 }
98
99 if (fPedPhotCam.Write()<=0)
100 {
101 *fLog << err << "Unable to write MPedPhotCam to " << oname << endl;
102 return kFALSE;
103 }
104
105 if (fBadPixels.Write()<=0)
106 {
107 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
108 return kFALSE;
109 }
110
111 return kTRUE;
112
113}
114
115void MJExtractSignal::SetOutputPath(const char *path)
116{
117 fOutputPath = path;
118 if (fOutputPath.EndsWith("/"))
119 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
120}
121
122TString MJExtractSignal::GetOutputFileD() const
123{
124 if (!fRuns)
125 return "";
126
127 return Form("%s/%s-F3.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
128}
129TString MJExtractSignal::GetOutputFileP() const
130{
131 if (!fRuns)
132 return "";
133
134 return Form("%s/%s-F2.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
135}
136
137Bool_t MJExtractSignal::ProcessD(MPedestalCam &pedcam)
138{
139 const TString fname = GetOutputFileD();
140
141 if (gSystem->AccessPathName(fname, kFileExists))
142 return ProcessFileD(pedcam);
143
144 return kTRUE;
145}
146
147Bool_t MJExtractSignal::ProcessFileD(MPedestalCam &pedcam)
148{
149
150 if (!fRuns)
151 {
152 *fLog << err << "No Runs choosen... abort." << endl;
153 return kFALSE;
154 }
155 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
156 {
157 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
158 return kFALSE;
159 }
160
161 *fLog << inf;
162 fLog->Separator(GetDescriptor());
163 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
164 *fLog << endl;
165
166 // Setup Lists
167 MParList plist;
168 plist.AddToList(&pedcam);
169
170 MTaskList tlist;
171 plist.AddToList(&tlist);
172
173 // Setup Parameters
174
175 // Make sure, that at least an empty MBadPixelsCam is available
176 // This is necessary for input which don't contain a MBadPixelsCam
177 MBadPixelsCam badcam;
178 plist.AddToList(&badcam);
179
180 // Setup Task-lists
181 MReadMarsFile read("Events");
182 read.DisableAutoScheme();
183 static_cast<MRead&>(read).AddFiles(*fRuns);
184
185 MGeomApply apply; // Only necessary to craete geometry
186 MBadPixelsMerge merge(&fBadPixels);
187 MExtractTimeFastSpline exttime;
188 MExtractSlidingWindow extcharge; // Only for the cosmics filter
189
190 MHCamEvent evt("ExtSignal");
191 evt.SetType(0);
192 MFillH fill(&evt, "MExtractedSignalCam");
193
194 MWriteRootFile write(GetOutputFileD(), "RECREATE", fRuns->GetRunsAsString(), 2);
195 write.AddContainer("MExtractedSignalCam", "Events");
196 write.AddContainer("MArrivalTimeCam", "Events");
197 write.AddContainer("MTime", "Events");
198 write.AddContainer("MRawEvtHeader", "Events");
199 write.AddContainer("MPedestalCam", "RunHeaders");
200 write.AddContainer("MRawRunHeader", "RunHeaders");
201 write.AddContainer("MBadPixelsCam", "RunHeaders");
202
203 tlist.AddToList(&read);
204 tlist.AddToList(&apply);
205 tlist.AddToList(&merge);
206
207 if (fTimeExtractor)
208 tlist.AddToList(fTimeExtractor);
209 else
210 {
211 *fLog << warn << GetDescriptor()
212 << ": No extractor has been chosen, take default MExtractTimeFastSpline " << endl;
213 tlist.AddToList(&exttime);
214 }
215
216 if (fExtractor)
217 tlist.AddToList(fExtractor);
218 else
219 {
220 *fLog << warn << GetDescriptor()
221 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
222 tlist.AddToList(&extcharge);
223 }
224
225// MPrint print("MExtractedSignalCam");
226// tlist.AddToList(&print);
227
228 if (TestBit(kEnableGraphicalOutput))
229 tlist.AddToList(&fill);
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 //if (!WriteResult())
250 // return kFALSE;
251
252 *fLog << inf << GetDescriptor() << ": Done." << endl;
253
254 return kTRUE;
255}
256
257Bool_t MJExtractSignal::ReadPedPhotCam()
258{
259 const TString fname = GetOutputFileP();
260
261 if (gSystem->AccessPathName(fname, kFileExists))
262 {
263 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
264 return kFALSE;
265 }
266
267 *fLog << inf << "Reading from file: " << fname << endl;
268
269 TFile file(fname, "READ");
270 if (fPedPhotCam.Read()<=0)
271 {
272 *fLog << "Unable to read MPedPhotCam from " << fname << endl;
273 return kFALSE;
274 }
275
276 if (file.FindKey("MBadPixelsCam"))
277 {
278 MBadPixelsCam bad;
279 if (bad.Read()<=0)
280 {
281 *fLog << "Unable to read MBadPixelsCam from " << fname << endl;
282 return kFALSE;
283 }
284 fBadPixels.Merge(bad);
285 }
286
287 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
288 fDisplay->Read();
289
290 return kTRUE;
291}
292
293Bool_t MJExtractSignal::ProcessP(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
294{
295 if (!ReadPedPhotCam())
296 return ProcessFileP(pedcam, calcam, qecam);
297
298 return kTRUE;
299}
300
301Bool_t MJExtractSignal::ProcessFileP(MPedestalCam &pedcam, MCalibrationChargeCam &calcam, MCalibrationQECam &qecam)
302{
303 if (!fRuns)
304 {
305 *fLog << err << "No Runs choosen... abort." << endl;
306 return kFALSE;
307 }
308 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
309 {
310 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
311 return kFALSE;
312 }
313
314 *fLog << inf;
315 fLog->Separator(GetDescriptor());
316 *fLog << "Calculate MExtractedSignalCam from Runs " << fRuns->GetRunsAsString() << endl;
317 *fLog << endl;
318
319 MReadMarsFile read("Events");
320 read.DisableAutoScheme();
321 static_cast<MRead&>(read).AddFiles(*fRuns);
322
323 // Setup Tasklist
324 MParList plist;
325 plist.AddToList(&pedcam);
326 plist.AddToList(&calcam);
327 plist.AddToList(&qecam);
328 plist.AddToList(&fPedPhotCam);
329 plist.AddToList(&fBadPixels);
330
331 MTaskList tlist;
332 plist.AddToList(&tlist);
333
334 MGeomApply apply; // Only necessary to craete geometry
335 MBadPixelsMerge merge(&fBadPixels);
336 MExtractSignal extract;
337 MCalibrateData calib;
338 MPedPhotCalc calc;
339
340 MHCamEvent evt1("ExtOffset");
341 MHCamEvent evt2("CalOffset");
342 evt1.SetType(0);
343 evt2.SetType(0);
344 MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtractedSignal");
345 MFillH fill2(&evt2, "MCerPhotEvt", "FillCerPhotEvt");
346
347 tlist.AddToList(&read);
348 tlist.AddToList(&apply);
349 tlist.AddToList(&merge);
350 tlist.AddToList(&extract);
351 if (TestBit(kEnableGraphicalOutput))
352 tlist.AddToList(&fill1);
353 tlist.AddToList(&calib);
354 tlist.AddToList(&calc);
355 if (TestBit(kEnableGraphicalOutput))
356 tlist.AddToList(&fill2);
357
358 // Create and setup the eventloop
359 MEvtLoop evtloop(fName);
360 evtloop.SetParList(&plist);
361 evtloop.SetDisplay(fDisplay);
362 evtloop.SetLogStream(fLog);
363
364 // Execute first analysis
365 if (!evtloop.Eventloop())
366 {
367 *fLog << err << GetDescriptor() << ": Failed." << endl;
368 return kFALSE;
369 }
370
371 tlist.PrintStatistics();
372
373 //DisplayResult(plist);
374
375 if (!WriteResult())
376 return kFALSE;
377
378 *fLog << inf << GetDescriptor() << ": Done." << endl;
379
380 return kTRUE;
381}
382
383/*
384Bool_t MJExtractSignal::ProcessFile(MPedestalCam *pedcam, MCalibrationChargeCam *calcam)
385{
386 if (!fRuns)
387 {
388 *fLog << err << "No Runs choosen... abort." << endl;
389 return kFALSE;
390 }
391 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
392 {
393 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
394 return kFALSE;
395 }
396
397 Int_t type = 0;
398 if (pedcam && calcam) type = 2;
399 if (pedcam && !calcam) type = 3;
400
401 *fLog << inf;
402 fLog->Separator(GetDescriptor());
403 *fLog << "Calculating from Runs " << fRuns->GetRunsAsString() << endl;
404 *fLog << endl;
405
406 MReadMarsFile read("Events");
407 read.DisableAutoScheme();
408 static_cast<MRead&>(read).AddFiles(*fRuns);
409
410 // Setup Tasklist
411 MParList plist;
412 switch (type)
413 {
414 case 2:
415 plist.AddToList(calcam);
416 plist.AddToList(&fPedPhotCam);
417 case 3:
418 plist.AddToList(pedcam);
419 }
420
421 MTaskList tlist;
422 plist.AddToList(&tlist);
423
424 MGeomApply apply; // Only necessary to craete geometry
425 MExtractSignal extract;
426 MCalibrateData calib;
427 MPedPhotCalc calc;
428
429
430 MHCamEvent evt1("ExtOffset");
431 MHCamEvent evt2("CalOffset");
432 evt1.SetType(0);
433 evt2.SetType(0);
434 MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtractedSignal");
435 MFillH fill2(&evt2, "MCerPhotEvt", "FillCerPhotEvt");
436
437 tlist.AddToList(&read);
438 tlist.AddToList(&apply);
439 tlist.AddToList(&extract);
440 if (TestBit(kEnableGraphicalOutput))
441 tlist.AddToList(&fill1);
442 tlist.AddToList(&calib);
443 tlist.AddToList(&calc);
444 if (TestBit(kEnableGraphicalOutput))
445 tlist.AddToList(&fill2);
446
447
448 MHCamEvent evt("ExtSignal");
449 evt.SetType(0);
450 MFillH fill(&evt, "MExtractedSignalCam");
451
452 MWriteRootFile write(GetOutputFileD(), "RECREATE", fRuns->GetRunsAsString(), 2);
453 write.AddContainer("MExtractedSignalCam", "Events");
454 write.AddContainer("MTime", "Events");
455 write.AddContainer("MRawRunHeader", "RunHeaders");
456 write.AddContainer("MPedestalCam", "RunHeaders");
457
458 tlist.AddToList(&read);
459 tlist.AddToList(&apply);
460 tlist.AddToList(&extract);
461 if (TestBit(kEnableGraphicalOutput))
462 tlist.AddToList(&fill);
463 tlist.AddToList(&write);
464
465 // Create and setup the eventloop
466 MEvtLoop evtloop(fName);
467 evtloop.SetParList(&plist);
468 evtloop.SetDisplay(fDisplay);
469 evtloop.SetLogStream(fLog);
470
471 // Execute first analysis
472 if (!evtloop.Eventloop())
473 {
474 *fLog << err << GetDescriptor() << ": Failed." << endl;
475 return kFALSE;
476 }
477
478 tlist.PrintStatistics();
479
480 //DisplayResult(plist);
481
482 //if (!WriteResult())
483 // return kFALSE;
484
485 *fLog << inf << GetDescriptor() << ": Done." << endl;
486
487 return kTRUE;
488
489
490 // ------------------------------------------------------
491
492 MGeomApply apply; // Only necessary to craete geometry
493 MExtractSignal extract;
494 MCalibrateData calib;
495 MPedPhotCalc calc;
496
497 MHCamEvent evt1("ExtOffset");
498 MHCamEvent evt2("CalOffset");
499 evt1.SetType(0);
500 evt2.SetType(0);
501 MFillH fill1(&evt1, "MExtractedSignalCam", "FillExtractedSignal");
502 MFillH fill2(&evt2, "MCerPhotEvt", "FillCerPhotEvt");
503
504 tlist.AddToList(&read);
505 tlist.AddToList(&apply);
506 tlist.AddToList(&extract);
507 if (TestBit(kEnableGraphicalOutput))
508 tlist.AddToList(&fill1);
509 tlist.AddToList(&calib);
510 tlist.AddToList(&calc);
511 if (TestBit(kEnableGraphicalOutput))
512 tlist.AddToList(&fill2);
513
514 // Create and setup the eventloop
515 MEvtLoop evtloop(fName);
516 evtloop.SetParList(&plist);
517 evtloop.SetDisplay(fDisplay);
518 evtloop.SetLogStream(fLog);
519
520 // Execute first analysis
521 if (!evtloop.Eventloop())
522 {
523 *fLog << err << GetDescriptor() << ": Failed." << endl;
524 return kFALSE;
525 }
526
527 tlist.PrintStatistics();
528
529 //DisplayResult(plist);
530
531 if (!WriteResult())
532 return kFALSE;
533
534 *fLog << inf << GetDescriptor() << ": Done." << endl;
535
536 return kTRUE;
537 }
538 */
Note: See TracBrowser for help on using the repository browser.