source: branches/AddingGoogleTestEnvironment/mcalib/MCalibrateRelTimes.cc@ 19779

Last change on this file since 19779 was 12630, checked in by tbretz, 13 years ago
Removed an obsolete fGeomCam; make sure that everything is initialized properly
File size: 5.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-2006
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MCalibrateRelTimes
28//
29// This task takes the extracted arrival times from MArrivalTimeCam for each
30// pixel and applies the offset calibrated in MCalibrationRelTimeCam
31// The calibrated arrival time and its error gets stored in MSignalCam.
32//
33// Input Containers:
34// MArrivalTimeCam
35// MCalibrationRelTimeCam
36//
37// Output Containers:
38// MSignalCam
39//
40//////////////////////////////////////////////////////////////////////////////
41#include "MCalibrateRelTimes.h"
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MParList.h"
47
48#include "MGeomCam.h"
49
50#include "MCalibrationRelTimeCam.h"
51#include "MCalibrationRelTimePix.h"
52
53#include "MArrivalTimeCam.h"
54#include "MArrivalTimePix.h"
55
56#include "MBadPixelsCam.h"
57#include "MBadPixelsPix.h"
58
59#include "MSignalCam.h"
60#include "MSignalPix.h"
61
62#include "MRawRunHeader.h"
63
64ClassImp(MCalibrateRelTimes);
65
66using namespace std;
67// --------------------------------------------------------------------------
68//
69// Default constructor.
70//
71MCalibrateRelTimes::MCalibrateRelTimes(const char *name, const char *title)
72 : fCalibrations(NULL), fBadPixels(NULL), fSignals(NULL), fArrivalTime(NULL)
73{
74 fName = name ? name : "MCalibrateRelTimes";
75 fTitle = title ? title : "Task to calculate the calibrated arrival times of photons in one event";
76}
77
78// --------------------------------------------------------------------------
79//
80// The PreProcess searches for the following input containers:
81// - MGeomCam
82// - MCalibrationRelTimesCam
83// - MArrivalTimeCam
84// - MBadPixelsCam
85//
86Int_t MCalibrateRelTimes::PreProcess(MParList *pList)
87{
88 fSignals = (MArrivalTimeCam*)pList->FindObject(AddSerialNumber("MArrivalTimeCam"));
89 if (!fSignals)
90 {
91 *fLog << err << AddSerialNumber("MArrivalTimeCam") << " not found ... aborting" << endl;
92 return kFALSE;
93 }
94
95 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
96 if (!fBadPixels)
97 *fLog << warn << AddSerialNumber("MBadPixelsCam") << " not found ... ignoring." << endl;
98
99 fCalibrations = (MCalibrationRelTimeCam*)pList->FindObject(AddSerialNumber("MCalibrationRelTimeCam"));
100 if (!fCalibrations)
101 {
102 *fLog << err << AddSerialNumber("MCalibrationRelTimeCam") << " not found ... aborting." << endl;
103 return kFALSE;
104 }
105
106 fArrivalTime = (MSignalCam*)pList->FindCreateObj(AddSerialNumber("MSignalCam"));
107 if (!fArrivalTime)
108 return kFALSE;
109
110 return kTRUE;
111}
112
113Bool_t MCalibrateRelTimes::ReInit(MParList *pList)
114{
115 MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
116 if (!runheader)
117 {
118 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found ... aborting." << endl;
119 return kFALSE;
120 }
121
122 fFreq = runheader->GetFreqSampling();
123
124 return kTRUE;
125}
126
127// --------------------------------------------------------------------------
128//
129// Apply the calibration factors to the extracted signal according to the
130// selected calibration method
131//
132Int_t MCalibrateRelTimes::Process()
133{
134 const UInt_t npix = fSignals->GetSize();
135
136 for (UInt_t idx=0; idx<npix; idx++)
137 {
138 if (fBadPixels && (*fBadPixels)[idx].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
139 continue;
140
141 const MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCalibrations)[idx];
142 const MArrivalTimePix &sig = (*fSignals)[idx];
143
144 const Float_t signal = sig.GetArrivalTime();
145 const Float_t offset = pix.GetTimeOffset();
146
147 // convert from slices to ns
148 const Float_t time = 1000*(signal-offset)/fFreq; // [ns]
149
150 (*fArrivalTime)[idx].SetArrivalTime(time);
151
152 // FIXME: Is this necessary or explicitly done by the signal-
153 // extractor (may depend on the fact whether independent
154 // extractor are or can be used for signal and arrival time)
155 if (fBadPixels && !sig.IsArrivalTimeValid())
156 (*fBadPixels)[idx].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
157 }
158
159 fArrivalTime->SetReadyToSave();
160
161 return kTRUE;
162}
Note: See TracBrowser for help on using the repository browser.