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

Last change on this file since 18679 was 18273, checked in by Daniela Dorner, 9 years ago
fixed bug in arrival time (introduced with time slope parameter)
File size: 6.2 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 "MLog.h"
33#include "MLogManip.h"
34
35#include "MParList.h"
36
37#include "MArrivalTimeCam.h"
38#include "MArrivalTimePix.h"
39
40#include "MBadPixelsCam.h"
41#include "MBadPixelsPix.h"
42
43#include "MSignalCam.h"
44
45#include "MRawRunHeader.h"
46#include "MRawEvtData.h"
47
48#include "MDrsCalibrationTime.h"
49
50ClassImp(MCalibrateDrsTimes);
51
52using namespace std;
53
54// --------------------------------------------------------------------------
55//
56// Default constructor.
57//
58MCalibrateDrsTimes::MCalibrateDrsTimes(const char *name, const char *title)
59 : fRunHeader(NULL), fCalib(NULL), fBadPixels(NULL), fSignals(NULL),
60 fArrivalTime(NULL), fArrivalTimeU(NULL), fNameArrivalTime("MArrivalTimeCam"),
61 fNameCalibrated("MSignalCam"), fNameUncalibrated(""), fIsTimeMarker(kFALSE)
62{
63 fName = name ? name : "MCalibrateDrsTimes";
64 fTitle = title ? title : "Task to calculate the calibrated arrival times of photons in one event";
65}
66
67// --------------------------------------------------------------------------
68//
69// The PreProcess searches for the following input containers:
70// - MGeomCam
71// - MCalibrationRelTimesCam
72// - MArrivalTimeCam
73// - MBadPixelsCam
74//
75Int_t MCalibrateDrsTimes::PreProcess(MParList *pList)
76{
77 fSignals = (MArrivalTimeCam*)pList->FindObject(AddSerialNumber(fNameArrivalTime), "MArrivalTimeCam");
78 if (!fSignals)
79 {
80 *fLog << err << AddSerialNumber("MArrivalTimeCam") << " not found ... aborting" << endl;
81 return kFALSE;
82 }
83
84 fRaw = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
85 if (!fRaw)
86 {
87 *fLog << err << AddSerialNumber("MRawEvtData") << " not found ... aborting" << endl;
88 return kFALSE;
89 }
90
91 fBadPixels = (MBadPixelsCam*)pList->FindObject(AddSerialNumber("MBadPixelsCam"));
92 if (!fBadPixels)
93 *fLog << warn << AddSerialNumber("MBadPixelsCam") << " not found ... ignoring." << endl;
94
95 fCalib = (MDrsCalibrationTime*)pList->FindObject("MDrsCalibrationTime");
96 if (!fCalib)
97 *fLog << warn << "MDrsCalibrationTime not found... no calibratuon will be applied." << endl;
98
99 fArrivalTime = (MSignalCam*)pList->FindCreateObj(AddSerialNumber("MSignalCam"), fNameCalibrated);
100 if (!fArrivalTime)
101 return kFALSE;
102
103 if (!fNameUncalibrated.IsNull())
104 {
105 fArrivalTimeU = (MSignalCam*)pList->FindCreateObj("MSignalCam", fNameUncalibrated);
106 if (!fArrivalTimeU)
107 return kFALSE;
108 }
109
110 return kTRUE;
111}
112
113Bool_t MCalibrateDrsTimes::ReInit(MParList *pList)
114{
115 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
116 if (!fRunHeader)
117 {
118 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found ... aborting." << endl;
119 return kFALSE;
120 }
121
122 fFreq = fRunHeader->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 MCalibrateDrsTimes::Process()
133{
134 const UInt_t npix = fSignals->GetSize();
135
136 const UShort_t *idx = fRaw->GetPixelIds();
137 const int16_t *start = reinterpret_cast<int16_t*>(fRaw->GetStartCells());
138
139 for (UInt_t hw=(fIsTimeMarker?8:0); hw<npix; hw+=(fIsTimeMarker?9:1))
140 //for (UInt_t hw=8; hw<npix; hw+=9)
141 {
142 const UInt_t sw = idx[hw];
143
144 if (start[hw]<0)
145 {
146 if (fBadPixels)
147 (*fBadPixels)[sw].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
148 continue;
149 }
150
151 if (fBadPixels && !fIsTimeMarker && (*fBadPixels)[sw].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
152 continue;
153
154 const Float_t signal = (*fSignals)[sw].GetArrivalTimeHiGain();
155 const Float_t slope = (*fSignals)[sw].GetArrivalTimeHiGainError();
156 const Float_t offset = fCalib ? fCalib->GetOffset(hw, start[hw], signal) : 0;
157 const Float_t offset2 = (fCalib && (signal-slope)>=0) ? fCalib->GetOffset(hw, start[hw], signal-slope) : 0;
158 const Float_t delay = fCalib ? fCalib->GetDelay(hw) : 0;
159
160 //if (fIsTimeMarker)
161 // offset = fCalib ? fCalib->GetDelay(hw, start[hw], signal) : 0;
162
163 // convert from slices to ns
164 const Float_t utime = 1000*(signal )/fFreq-delay; // [ns]
165 const Float_t time = 1000*(signal-offset)/fFreq-delay; // [ns]
166 const Float_t slopecal = (slope-offset+offset2)<0 ? -1 : 1000*(slope-offset+offset2)/fFreq; // [ns]
167 const Float_t uslope = slope<0 ? -1 : 1000*(slope)/fFreq; // [ns]
168
169 /*
170 (*fArrivalTime)[sw].SetArrivalTime(time);
171 if (fArrivalTimeU)
172 (*fArrivalTimeU)[sw].SetArrivalTime(utime);
173 */
174
175 for (UInt_t j=hw-(fIsTimeMarker?8:0); j<=hw; j++)
176 {
177 (*fArrivalTime)[idx[j]].SetArrivalTime(time);
178 (*fArrivalTime)[idx[j]].SetTimeSlope(slopecal);
179 if (fArrivalTimeU)
180 {
181 (*fArrivalTimeU)[idx[j]].SetArrivalTime(utime);
182 (*fArrivalTimeU)[idx[j]].SetTimeSlope(uslope);
183 }
184 }
185 }
186
187 fArrivalTime->SetReadyToSave();
188
189 return kTRUE;
190}
Note: See TracBrowser for help on using the repository browser.