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

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