source: trunk/Mars/mcalib/MCalibrateDrsTimes.cc@ 14909

Last change on this file since 14909 was 14895, checked in by tbretz, 12 years ago
Added calibration class for DRS timing
File size: 6.1 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// MCalibrateDrsTimes
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 "MCalibrateDrsTimes.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#include "MRawEvtData.h"
64#include "MHDrsCalib.h"
65
66ClassImp(MCalibrateDrsTimes);
67
68using namespace std;
69// --------------------------------------------------------------------------
70//
71// Default constructor.
72//
73MCalibrateDrsTimes::MCalibrateDrsTimes(const char *name, const char *title)
74 : fRunHeader(NULL), fCalib(NULL), fBadPixels(NULL), fSignals(NULL),
75 fArrivalTime(NULL), fArrivalTimeU(NULL), fNameArrivalTime("MArrivalTimeCam"),
76 fNameCalibrated("MSignalCam"), fNameUncalibrated(""), fIsTimeMarker(kFALSE)
77{
78 fName = name ? name : "MCalibrateDrsTimes";
79 fTitle = title ? title : "Task to calculate the calibrated arrival times of photons in one event";
80}
81
82// --------------------------------------------------------------------------
83//
84// The PreProcess searches for the following input containers:
85// - MGeomCam
86// - MCalibrationRelTimesCam
87// - MArrivalTimeCam
88// - MBadPixelsCam
89//
90Int_t MCalibrateDrsTimes::PreProcess(MParList *pList)
91{
92 fSignals = (MArrivalTimeCam*)pList->FindObject(AddSerialNumber(fNameArrivalTime), "MArrivalTimeCam");
93 if (!fSignals)
94 {
95 *fLog << err << AddSerialNumber("MArrivalTimeCam") << " not found ... aborting" << endl;
96 return kFALSE;
97 }
98
99 fRaw = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
100 if (!fRaw)
101 {
102 *fLog << err << AddSerialNumber("MRawEvtData") << " not found ... aborting" << endl;
103 return kFALSE;
104 }
105
106 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
107 if (!fBadPixels)
108 *fLog << warn << AddSerialNumber("MBadPixelsCam") << " not found ... ignoring." << endl;
109
110 fCalib = (MDrsCalibrationTime*)pList->FindObject("MDrsCalibrationTime");
111 if (!fCalib)
112 *fLog << warn << "MDrsCalibrationTime not found... no calibratuon will be applied." << endl;
113
114 fArrivalTime = (MSignalCam*)pList->FindCreateObj(AddSerialNumber("MSignalCam"), fNameCalibrated);
115 if (!fArrivalTime)
116 return kFALSE;
117
118 if (!fNameUncalibrated.IsNull())
119 {
120 fArrivalTimeU = (MSignalCam*)pList->FindCreateObj("MSignalCam", fNameUncalibrated);
121 if (!fArrivalTimeU)
122 return kFALSE;
123 }
124
125 return kTRUE;
126}
127
128Bool_t MCalibrateDrsTimes::ReInit(MParList *pList)
129{
130 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
131 if (!fRunHeader)
132 {
133 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found ... aborting." << endl;
134 return kFALSE;
135 }
136
137 fFreq = fRunHeader->GetFreqSampling();
138
139 return kTRUE;
140}
141
142// --------------------------------------------------------------------------
143//
144// Apply the calibration factors to the extracted signal according to the
145// selected calibration method
146//
147Int_t MCalibrateDrsTimes::Process()
148{
149 const UInt_t npix = fSignals->GetSize();
150
151 const UShort_t *idx = fRaw->GetPixelIds();
152 const int16_t *start = reinterpret_cast<int16_t*>(fRaw->GetStartCells());
153
154 for (UInt_t hw=(fIsTimeMarker?8:0); hw<npix; hw+=(fIsTimeMarker?9:1))
155 //for (UInt_t hw=8; hw<npix; hw+=9)
156 {
157 const UInt_t sw = idx[hw];
158
159 if (start[hw]<0)
160 {
161 if (fBadPixels)
162 (*fBadPixels)[sw].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
163 continue;
164 }
165
166 if (fBadPixels && !fIsTimeMarker && (*fBadPixels)[sw].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
167 continue;
168
169 const Float_t signal = (*fSignals)[sw].GetArrivalTime();
170 const Float_t offset = fCalib ? fCalib->GetOffset(hw, start[hw], signal) : 0;
171 const Float_t delay = fCalib ? fCalib->GetDelay(sw) : 0;
172
173 //if (fIsTimeMarker)
174 // offset = fCalib ? fCalib->GetDelay(hw, start[hw], signal) : 0;
175
176 // convert from slices to ns
177 const Float_t utime = 1000*(signal )/fFreq-delay; // [ns]
178 const Float_t time = 1000*(signal-offset)/fFreq-delay; // [ns]
179
180 /*
181 (*fArrivalTime)[sw].SetArrivalTime(time);
182 if (fArrivalTimeU)
183 (*fArrivalTimeU)[sw].SetArrivalTime(utime);
184 */
185
186 for (UInt_t j=hw-(fIsTimeMarker?8:0); j<=hw; j++)
187 {
188 (*fArrivalTime)[idx[j]].SetArrivalTime(time);
189 if (fArrivalTimeU)
190 (*fArrivalTimeU)[idx[j]].SetArrivalTime(utime);
191 }
192 }
193
194 fArrivalTime->SetReadyToSave();
195
196 return kTRUE;
197}
Note: See TracBrowser for help on using the repository browser.