source: trunk/MagicSoft/Mars/mcalib/MExtractPINDiode.cc@ 3173

Last change on this file since 3173 was 3171, checked in by gaug, 22 years ago
*** empty log message ***
File size: 5.9 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, 02/2004 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MExtractPINDiode
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MExtractPINDiode.h"
31
32#include <fstream>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38
39#include "MRawEvtData.h"
40#include "MRawEvtPixelIter.h"
41
42#include "MPedestalCam.h"
43#include "MPedestalPix.h"
44
45#include "MExtractedSignalPINDiode.h"
46
47ClassImp(MExtractPINDiode);
48
49using namespace std;
50
51const UInt_t MExtractPINDiode::fgPINDiodeId = 254;
52const Byte_t MExtractPINDiode::fgSaturationLimit = 254;
53const Byte_t MExtractPINDiode::fgFirst = 1;
54const Byte_t MExtractPINDiode::fgLast = 30;
55
56// --------------------------------------------------------------------------
57//
58// Default constructor.
59//
60MExtractPINDiode::MExtractPINDiode(const char *name, const char *title)
61 : fSaturationLimit(fgSaturationLimit)
62{
63
64 fName = name ? name : "MExtractPINDiode";
65 fTitle = title ? title : "Task to extract the signal from the FADC slices";
66
67 AddToBranchList("MRawEvtData.*");
68
69 SetRange();
70}
71
72void MExtractPINDiode::SetRange(Byte_t first, Byte_t last)
73{
74
75 fNumSamples = last-first+1;
76 fFirst = first;
77 fLast = last;
78
79 fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples);
80}
81
82// --------------------------------------------------------------------------
83//
84// The PreProcess searches for the following input containers:
85// - MRawEvtData
86// - MPedestalCam
87//
88// The following output containers are also searched and created if
89// they were not found:
90//
91// - MExtractedPINDiode
92//
93Int_t MExtractPINDiode::PreProcess(MParList *pList)
94{
95 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData"));
96 if (!fRawEvt)
97 {
98 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl;
99 return kFALSE;
100 }
101
102
103 fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode"));
104 if (!fPINDiode)
105 return kFALSE;
106
107 fPINDiode->SetUsedFADCSlices(fFirst, fFirst+fNumSamples-1);
108
109 fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber("MPedestalCam"));
110
111 if (!fPedestals)
112 {
113 *fLog << err << AddSerialNumber("MPedestalCam") << " not found... aborting" << endl;
114 return kFALSE;
115 }
116
117 return kTRUE;
118}
119
120void MExtractPINDiode::FindSignal(Byte_t *ptr, Int_t size, UInt_t &sum, UInt_t &sum2, UInt_t &sat, UInt_t &max) const
121{
122
123 Byte_t *end = ptr + size;
124
125 while (ptr<end)
126 {
127 sum += *ptr;
128 sum2 += *ptr * *ptr;
129 if (*ptr > max)
130 max = *ptr;
131
132 if (*ptr++ >= fSaturationLimit)
133 sat++;
134 }
135}
136
137// --------------------------------------------------------------------------
138//
139// Calculate the integral of the FADC time slices and store them as a new
140// pixel in the MExtractedPINDiode container.
141//
142Int_t MExtractPINDiode::Process()
143{
144
145 MRawEvtPixelIter pixel(fRawEvt);
146
147 fPINDiode->Clear();
148
149 pixel.Jump(fgPINDiodeId);
150
151 UInt_t sum = 0;
152 UInt_t sum2 = 0;
153 UInt_t sat = 0;
154 UInt_t max = 0;
155
156 FindSignal(pixel.GetHiGainSamples()+fFirst-1,
157 fRawEvt->GetNumHiGainSamples(),
158 sum, sum2, sat, max);
159 FindSignal(pixel.GetLoGainSamples(),
160 fLast-fRawEvt->GetNumLoGainSamples(),
161 sum, sum2, sat, max);
162
163 const MPedestalPix &ped = (*fPedestals)[fgPINDiodeId];
164
165 const Float_t pedes = ped.GetPedestal();
166 const Float_t pedrms = ped.GetPedestalRms();
167
168 const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1);
169 const Float_t rms = TMath::Sqrt(var);
170
171 //
172 // FIXME: The following formulae have to be revised!!
173 //
174 fPINDiode->SetExtractedSignal(sum - pedes*fNumSamples, pedrms*fSqrtSamples);
175 fPINDiode->SetExtractedRms (rms, rms/2./fSqrtSamples);
176 fPINDiode->SetExtractedTime (max, rms/fSqrtSamples);
177 fPINDiode->SetSaturation(sat);
178
179 if (sat)
180 *fLog << warn << "WARNING - saturation occurred in the PIN Diode " << endl;
181
182 fPINDiode->SetReadyToSave();
183
184 return kTRUE;
185}
186
187// --------------------------------------------------------------------------
188//
189// Implementation of SavePrimitive. Used to write the call to a constructor
190// to a macro. In the original root implementation it is used to write
191// gui elements to a macro-file.
192//
193void MExtractPINDiode::StreamPrimitive(ofstream &out) const
194{
195 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
196 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
197
198 if (fSaturationLimit!=fgSaturationLimit)
199 {
200 out << " " << GetUniqueName() << ".SetSaturationLimit(";
201 out << (int)fSaturationLimit << ");" << endl;
202 }
203
204 const Bool_t arg2 = fNumSamples+fFirst-1 != fgLast;
205 const Bool_t arg1 = arg2 || fFirst != fgFirst;
206
207 if (!arg1)
208 return;
209
210 out << " " << GetUniqueName() << ".SetRange(";
211 out << (int)fFirst;
212 if (arg2)
213 out << ", " << (int)(fNumSamples+fFirst-1);
214 out << ");" << endl;
215}
Note: See TracBrowser for help on using the repository browser.