source: trunk/MagicSoft/Mars/mcalib/MCalibrateRelTimes.cc@ 5653

Last change on this file since 5653 was 5307, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 5.7 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-2004
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 MCerPhotEvt.
32//
33// Input Containers:
34// MArrivalTimeCam
35// MCalibrationRelTimeCam
36//
37// Output Containers:
38// MArrivalTime
39//
40//////////////////////////////////////////////////////////////////////////////
41#include "MCalibrateRelTimes.h"
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MParList.h"
47#include "MH.h"
48
49#include "MGeomCam.h"
50
51#include "MCalibrationRelTimeCam.h"
52#include "MCalibrationRelTimePix.h"
53
54#include "MArrivalTimeCam.h"
55#include "MArrivalTimePix.h"
56
57#include "MBadPixelsCam.h"
58#include "MBadPixelsPix.h"
59
60#include "MArrivalTime.h"
61
62ClassImp(MCalibrateRelTimes);
63
64using namespace std;
65// --------------------------------------------------------------------------
66//
67// Default constructor.
68//
69MCalibrateRelTimes::MCalibrateRelTimes(const char *name, const char *title)
70 : fGeomCam(NULL), fCalibrations(NULL), fBadPixels(NULL), fSignals(NULL),
71 fArrivalTime(NULL)
72{
73 fName = name ? name : "MCalibrateRelTimes";
74 fTitle = title ? title : "Task to calculate the calibrated arrival times of photons in one event";
75}
76
77// --------------------------------------------------------------------------
78//
79// The PreProcess searches for the following input containers:
80// - MGeomCam
81// - MCalibrationRelTimesCam
82// - MArrivalTimeCam
83// - MBadPixelsCam
84//
85// The following output containers are also searched and created if
86// they were not found:
87//
88// - MArrivalTime
89//
90Int_t MCalibrateRelTimes::PreProcess(MParList *pList)
91{
92
93 fSignals = (MArrivalTimeCam*)pList->FindObject(AddSerialNumber("MArrivalTimeCam"));
94
95 if (!fSignals)
96 {
97 *fLog << err << AddSerialNumber("MArrivalTimeCam") << " not found ... aborting" << endl;
98 return kFALSE;
99 }
100
101 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
102 if (!fBadPixels)
103 *fLog << warn << AddSerialNumber("MBadPixelsCam") << " not found ... no action" << endl;
104
105
106 fCalibrations = (MCalibrationRelTimeCam*)pList->FindObject(AddSerialNumber("MCalibrationRelTimeCam"));
107 if (!fCalibrations)
108 {
109 *fLog << err << AddSerialNumber("MCalibrationRelTimeCam") << " not found ... aborting." << endl;
110 return kFALSE;
111 }
112
113
114 fArrivalTime = (MArrivalTime*)pList->FindCreateObj(AddSerialNumber("MArrivalTime"));
115 if (!fArrivalTime)
116 {
117 *fLog << err << AddSerialNumber("MArrivalTime") << ": Cannot create ... aborting." << endl;
118 return kFALSE;
119 }
120
121 return kTRUE;
122}
123
124// --------------------------------------------------------------------------
125//
126// Check for validity of the selected calibration method, switch to a
127// different one in case of need
128//
129Bool_t MCalibrateRelTimes::ReInit(MParList *pList)
130{
131 return kTRUE;
132}
133// --------------------------------------------------------------------------
134//
135// Apply the calibration factors to the extracted signal according to the
136// selected calibration method
137//
138Int_t MCalibrateRelTimes::Process()
139{
140 /*
141 if (fCalibrations->GetNumPixels() != (UInt_t)fSignals->GetSize())
142 {
143 // FIXME: MArrivalTime must be of variable size -
144 // like MCerPhotEvt - because we must be able
145 // to reduce size by zero supression
146 // For the moment this check could be done in ReInit...
147 *fLog << err << "MArrivalTime and MCalibrationCam have different sizes... abort." << endl;
148 return kFALSE;
149 }
150 */
151
152 const UInt_t npix = fSignals->GetSize();
153
154 for (UInt_t pixidx=0; pixidx<npix; pixidx++)
155 {
156 MCalibrationRelTimePix &pix = (MCalibrationRelTimePix&)(*fCalibrations)[pixidx];
157
158 if (fBadPixels && (*fBadPixels)[pixidx].IsUnsuitable())
159 continue;
160
161 const Float_t offset = pix.GetTimeOffset();
162 const Float_t precision = pix.GetTimePrecision();
163
164 MArrivalTimePix &sig = (*fSignals)[pixidx];
165
166 Float_t signal;
167 Float_t sigerr;
168
169 if (sig.IsLoGainUsed())
170 {
171 signal = sig.GetArrivalTimeLoGain();
172 sigerr = sig.GetArrivalTimeLoGainError();
173 }
174 else
175 {
176 signal = sig.GetArrivalTimeHiGain();
177 sigerr = sig.GetArrivalTimeHiGainError();
178 }
179
180 const Float_t time = signal - offset;
181 const Float_t err = sigerr*sigerr + precision*precision;
182
183 fArrivalTime->SetTime(pixidx, time);
184 fArrivalTime->SetTimeErr(pixidx, err>0 ? TMath::Sqrt(err) : 0);
185
186 } /* for (UInt_t pixidx=0; pixidx<npix; pixidx++) */
187
188 fArrivalTime->SetReadyToSave();
189
190 return kTRUE;
191}
Note: See TracBrowser for help on using the repository browser.