source: branches/Corsika7405Compatibility/mjobs/MJExtractSignal.cc@ 19690

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