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

Last change on this file since 20112 was 19315, checked in by tbretz, 6 years ago
Comparison between signed an unsigned.
File size: 6.3 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 calibration 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 Int_t sw = idx[hw];
143 if (sw>=fSignals->GetSize())
144 continue;
145
146 if (start[hw]<0)
147 {
148 if (fBadPixels)
149 (*fBadPixels)[sw].SetUnsuitable(MBadPixelsPix::kUnsuitableEvt);
150 continue;
151 }
152
153 if (fBadPixels && !fIsTimeMarker && (*fBadPixels)[sw].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
154 continue;
155
156 const Float_t signal = (*fSignals)[sw].GetArrivalTimeHiGain();
157 const Float_t slope = (*fSignals)[sw].GetArrivalTimeHiGainError();
158 const Float_t offset = fCalib ? fCalib->GetOffset(hw, start[hw], signal) : 0;
159 const Float_t offset2 = (fCalib && (signal-slope)>=0) ? fCalib->GetOffset(hw, start[hw], signal-slope) : 0;
160 const Float_t delay = fCalib ? fCalib->GetDelay(hw) : 0;
161
162 //if (fIsTimeMarker)
163 // offset = fCalib ? fCalib->GetDelay(hw, start[hw], signal) : 0;
164
165 // convert from slices to ns
166 const Float_t utime = 1000*(signal )/fFreq-delay; // [ns]
167 const Float_t time = 1000*(signal-offset)/fFreq-delay; // [ns]
168 const Float_t slopecal = (slope-offset+offset2)<0 ? -1 : 1000*(slope-offset+offset2)/fFreq; // [ns]
169 const Float_t uslope = slope<0 ? -1 : 1000*(slope)/fFreq; // [ns]
170
171 /*
172 (*fArrivalTime)[sw].SetArrivalTime(time);
173 if (fArrivalTimeU)
174 (*fArrivalTimeU)[sw].SetArrivalTime(utime);
175 */
176
177 for (UInt_t j=hw-(fIsTimeMarker?8:0); j<=hw; j++)
178 {
179 (*fArrivalTime)[idx[j]].SetArrivalTime(time);
180 (*fArrivalTime)[idx[j]].SetTimeSlope(slopecal);
181 if (fArrivalTimeU)
182 {
183 (*fArrivalTimeU)[idx[j]].SetArrivalTime(utime);
184 (*fArrivalTimeU)[idx[j]].SetTimeSlope(uslope);
185 }
186 }
187 }
188
189 fArrivalTime->SetReadyToSave();
190
191 return kTRUE;
192}
Note: See TracBrowser for help on using the repository browser.