source: trunk/Mars/mdrs/MCalibrateDrsTimes.cc@ 17559

Last change on this file since 17559 was 14922, checked in by tbretz, 12 years ago
New classes for DRS calibration.
File size: 5.6 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 2013 <mailto:thomas.bretz@epfl.ch>
19!
20! Copyright: MAGIC Software Development, 2000-2013
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MCalibrateDrsTimes
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MCalibrateDrsTimes.h"
31
32#include "MParList.h"
33
34#include "MArrivalTimeCam.h"
35#include "MArrivalTimePix.h"
36
37#include "MBadPixelsCam.h"
38#include "MBadPixelsPix.h"
39
40#include "MSignalCam.h"
41
42#include "MRawRunHeader.h"
43#include "MRawEvtData.h"
44
45#include "MDrsCalibrationTime.h"
46
47ClassImp(MCalibrateDrsTimes);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Default constructor.
54//
55MCalibrateDrsTimes::MCalibrateDrsTimes(const char *name, const char *title)
56 : fRunHeader(NULL), fCalib(NULL), fBadPixels(NULL), fSignals(NULL),
57 fArrivalTime(NULL), fArrivalTimeU(NULL), fNameArrivalTime("MArrivalTimeCam"),
58 fNameCalibrated("MSignalCam"), fNameUncalibrated(""), fIsTimeMarker(kFALSE)
59{
60 fName = name ? name : "MCalibrateDrsTimes";
61 fTitle = title ? title : "Task to calculate the calibrated arrival times of photons in one event";
62}
63
64// --------------------------------------------------------------------------
65//
66// The PreProcess searches for the following input containers:
67// - MGeomCam
68// - MCalibrationRelTimesCam
69// - MArrivalTimeCam
70// - MBadPixelsCam
71//
72Int_t MCalibrateDrsTimes::PreProcess(MParList *pList)
73{
74 fSignals = (MArrivalTimeCam*)pList->FindObject(AddSerialNumber(fNameArrivalTime), "MArrivalTimeCam");
75 if (!fSignals)
76 {
77 *fLog << err << AddSerialNumber("MArrivalTimeCam") << " not found ... aborting" << endl;
78 return kFALSE;
79 }
80
81 fRaw = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
82 if (!fRaw)
83 {
84 *fLog << err << AddSerialNumber("MRawEvtData") << " not found ... aborting" << endl;
85 return kFALSE;
86 }
87
88 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
89 if (!fBadPixels)
90 *fLog << warn << AddSerialNumber("MBadPixelsCam") << " not found ... ignoring." << endl;
91
92 fCalib = (MDrsCalibrationTime*)pList->FindObject("MDrsCalibrationTime");
93 if (!fCalib)
94 *fLog << warn << "MDrsCalibrationTime not found... no calibratuon will be applied." << endl;
95
96 fArrivalTime = (MSignalCam*)pList->FindCreateObj(AddSerialNumber("MSignalCam"), fNameCalibrated);
97 if (!fArrivalTime)
98 return kFALSE;
99
100 if (!fNameUncalibrated.IsNull())
101 {
102 fArrivalTimeU = (MSignalCam*)pList->FindCreateObj("MSignalCam", fNameUncalibrated);
103 if (!fArrivalTimeU)
104 return kFALSE;
105 }
106
107 return kTRUE;
108}
109
110Bool_t MCalibrateDrsTimes::ReInit(MParList *pList)
111{
112 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
113 if (!fRunHeader)
114 {
115 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found ... aborting." << endl;
116 return kFALSE;
117 }
118
119 fFreq = fRunHeader->GetFreqSampling();
120
121 return kTRUE;
122}
123
124// --------------------------------------------------------------------------
125//
126// Apply the calibration factors to the extracted signal according to the
127// selected calibration method
128//
129Int_t MCalibrateDrsTimes::Process()
130{
131 const UInt_t npix = fSignals->GetSize();
132
133 const UShort_t *idx = fRaw->GetPixelIds();
134 const int16_t *start = reinterpret_cast<int16_t*>(fRaw->GetStartCells());
135
136 for (UInt_t hw=(fIsTimeMarker?8:0); hw<npix; hw+=(fIsTimeMarker?9:1))
137 //for (UInt_t hw=8; hw<npix; hw+=9)
138 {
139 const UInt_t sw = idx[hw];
140
141 if (start[hw]<0)
142 {
143 if (fBadPixels)
144 (*fBadPixels)[sw].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
145 continue;
146 }
147
148 if (fBadPixels && !fIsTimeMarker && (*fBadPixels)[sw].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
149 continue;
150
151 const Float_t signal = (*fSignals)[sw].GetArrivalTime();
152 const Float_t offset = fCalib ? fCalib->GetOffset(hw, start[hw], signal) : 0;
153 const Float_t delay = fCalib ? fCalib->GetDelay(sw) : 0;
154
155 //if (fIsTimeMarker)
156 // offset = fCalib ? fCalib->GetDelay(hw, start[hw], signal) : 0;
157
158 // convert from slices to ns
159 const Float_t utime = 1000*(signal )/fFreq-delay; // [ns]
160 const Float_t time = 1000*(signal-offset)/fFreq-delay; // [ns]
161
162 /*
163 (*fArrivalTime)[sw].SetArrivalTime(time);
164 if (fArrivalTimeU)
165 (*fArrivalTimeU)[sw].SetArrivalTime(utime);
166 */
167
168 for (UInt_t j=hw-(fIsTimeMarker?8:0); j<=hw; j++)
169 {
170 (*fArrivalTime)[idx[j]].SetArrivalTime(time);
171 if (fArrivalTimeU)
172 (*fArrivalTimeU)[idx[j]].SetArrivalTime(utime);
173 }
174 }
175
176 fArrivalTime->SetReadyToSave();
177
178 return kTRUE;
179}
Note: See TracBrowser for help on using the repository browser.