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

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