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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MCerPhotAnal2 //
|
---|
28 | // //
|
---|
29 | // This is a task which calculates the number of photons from the FADC //
|
---|
30 | // time slices. At the moment it integrates simply the FADC values. //
|
---|
31 | // //
|
---|
32 | // Input Containers: //
|
---|
33 | // MRawEvtData, MPedesdtalCam //
|
---|
34 | // //
|
---|
35 | // Output Containers: //
|
---|
36 | // MCerPhotEvt //
|
---|
37 | // //
|
---|
38 | //////////////////////////////////////////////////////////////////////////////
|
---|
39 |
|
---|
40 | #include "MCerPhotAnal2.h"
|
---|
41 |
|
---|
42 | #include "MParList.h"
|
---|
43 |
|
---|
44 | #include "MLog.h"
|
---|
45 | #include "MLogManip.h"
|
---|
46 |
|
---|
47 | #include "MRawRunHeader.h"
|
---|
48 | #include "MRawEvtData.h" // MRawEvtData::GetNumPixels
|
---|
49 | #include "MCerPhotEvt.h"
|
---|
50 | #include "MPedestalPix.h"
|
---|
51 | #include "MPedestalCam.h"
|
---|
52 | #include "MRawEvtPixelIter.h"
|
---|
53 |
|
---|
54 | ClassImp(MCerPhotAnal2);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // Default constructor. b is the number of slices before the maximum slice,
|
---|
61 | // a the number of slices behind the maximum slice which is taken as signal.
|
---|
62 | //
|
---|
63 | MCerPhotAnal2::MCerPhotAnal2(Byte_t b, Byte_t a, const char *name, const char *title)
|
---|
64 | : fBefore(b), fAfter(a)
|
---|
65 | {
|
---|
66 | fName = name ? name : "MCerPhotAnal2";
|
---|
67 | fTitle = title ? title : "Task to calculate Cerenkov photons from raw data";
|
---|
68 |
|
---|
69 | AddToBranchList("MRawEvtData.fHiGainPixId");
|
---|
70 | AddToBranchList("MRawEvtData.fLoGainPixId");
|
---|
71 | AddToBranchList("MRawEvtData.fHiGainFadcSamples");
|
---|
72 | AddToBranchList("MRawEvtData.fLoGainFadcSamples");
|
---|
73 | }
|
---|
74 |
|
---|
75 | // --------------------------------------------------------------------------
|
---|
76 | //
|
---|
77 | // The PreProcess searches for the following input containers:
|
---|
78 | // - MRawRunHeader
|
---|
79 | // - MRawEvtData
|
---|
80 | // - MPedestalCam
|
---|
81 | //
|
---|
82 | // The following output containers are also searched and created if
|
---|
83 | // they were not found:
|
---|
84 | // - MCerPhotEvt
|
---|
85 | //
|
---|
86 | Int_t MCerPhotAnal2::PreProcess(MParList *pList)
|
---|
87 | {
|
---|
88 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
89 | if (!fRunHeader)
|
---|
90 | {
|
---|
91 | *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
|
---|
92 | return kFALSE;
|
---|
93 | }
|
---|
94 |
|
---|
95 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
96 | if (!fRawEvt)
|
---|
97 | {
|
---|
98 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
---|
99 | return kFALSE;
|
---|
100 | }
|
---|
101 |
|
---|
102 | fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
|
---|
103 | if (!fCerPhotEvt)
|
---|
104 | return kFALSE;
|
---|
105 |
|
---|
106 | const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
107 | if (!runheader)
|
---|
108 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
109 | else
|
---|
110 | if (runheader->GetRunType() == kRTMonteCarlo)
|
---|
111 | {
|
---|
112 | fPedestals=NULL;
|
---|
113 | return kTRUE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
---|
117 | if (runheader && !fPedestals)
|
---|
118 | return kFALSE;
|
---|
119 |
|
---|
120 | return kTRUE;
|
---|
121 | }
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------
|
---|
124 | //
|
---|
125 | // Calculate the integral of the FADC time slices and store them as a new
|
---|
126 | // pixel in the MCerPhotEvt container.
|
---|
127 | //
|
---|
128 | Int_t MCerPhotAnal2::Process()
|
---|
129 | {
|
---|
130 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
131 |
|
---|
132 | while (pixel.Next())
|
---|
133 | {
|
---|
134 | Byte_t max = pixel.GetNumMaxHiGainSample();
|
---|
135 | Byte_t num = fRawEvt->GetNumHiGainSamples();
|
---|
136 |
|
---|
137 | Byte_t *ptr = pixel.GetHiGainSamples();
|
---|
138 |
|
---|
139 | ULong_t sumb = 0; // sum background
|
---|
140 | ULong_t sqb = 0; // sum sqares background
|
---|
141 | ULong_t sumsb = 0; // sum signal+background
|
---|
142 | ULong_t sqsb = 0; // sum sqares signal+background
|
---|
143 |
|
---|
144 | Int_t sat = 0; // saturates?
|
---|
145 | Int_t nb = 0;
|
---|
146 | Int_t nsb = 0;
|
---|
147 | for (int i=0; i<num; i++)
|
---|
148 | {
|
---|
149 | if (ptr[i]>250)
|
---|
150 | sat++;
|
---|
151 | if (sat>1)
|
---|
152 | continue;
|
---|
153 |
|
---|
154 | if (i<max-fBefore || i>max+fAfter)
|
---|
155 | {
|
---|
156 | sumb += ptr[i];
|
---|
157 | sqb += ptr[i]*ptr[i];
|
---|
158 | nb++;
|
---|
159 | }
|
---|
160 | else
|
---|
161 | {
|
---|
162 | sumsb += ptr[i];
|
---|
163 | sqsb += ptr[i]*ptr[i];
|
---|
164 | nsb++;
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | if (sat>1)
|
---|
169 | {
|
---|
170 | // Area: x9
|
---|
171 | max = pixel.GetNumMaxLoGainSample();
|
---|
172 | num = fRawEvt->GetNumLoGainSamples();
|
---|
173 |
|
---|
174 | ptr = pixel.GetLoGainSamples();
|
---|
175 |
|
---|
176 | sumsb = 0; // sum signal+background
|
---|
177 | sqsb = 0; // sum sqares signal+background
|
---|
178 | sumb = 0; // sum background
|
---|
179 | sqb = 0; // sum sqares background
|
---|
180 |
|
---|
181 | nb = 0;
|
---|
182 | nsb = 0;
|
---|
183 | for (int i=0; i<num; i++)
|
---|
184 | {
|
---|
185 | if (ptr[i]>250)
|
---|
186 | return kCONTINUE;
|
---|
187 | if (i<max-fBefore || i>max+fAfter)
|
---|
188 | {
|
---|
189 | sumb += ptr[i];
|
---|
190 | sqb += ptr[i]*ptr[i];
|
---|
191 | nb++;
|
---|
192 | }
|
---|
193 | else
|
---|
194 | {
|
---|
195 | sumsb += ptr[i];
|
---|
196 | sqsb += ptr[i]*ptr[i];
|
---|
197 | nsb++;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | Float_t b = (float)sumb/nb; // background
|
---|
203 | Float_t sb = (float)sumsb/nsb; // signal+background
|
---|
204 |
|
---|
205 | Float_t msb = (float)sqb/nb; // mean square background
|
---|
206 | //Float_t mssb = (float)sqsb/nsb; // mean square signal+background
|
---|
207 |
|
---|
208 | Float_t sigb = sqrt(msb-b*b); // sigma background
|
---|
209 | //Float_t sigsb = sqrt(mssb-sb*sb); // sigma signal+background
|
---|
210 |
|
---|
211 | Float_t s = sb-b; // signal
|
---|
212 | Float_t sqs = sqsb-nsb*b; // sum sqaures signal
|
---|
213 |
|
---|
214 | Float_t mss = (float)sqs/nsb; // mean quare signal
|
---|
215 | Float_t sigs = sqrt(mss-s*s); // sigma signal
|
---|
216 |
|
---|
217 | if (sat>1)
|
---|
218 | s*=9;
|
---|
219 |
|
---|
220 | Int_t idx = pixel.GetPixelId();
|
---|
221 | fCerPhotEvt->AddPixel(idx, s, sigs);
|
---|
222 |
|
---|
223 | // Preliminary: Do not overwrite pedestals calculated by
|
---|
224 | // MMcPedestalCopy and MMcPedestalNSBAdd
|
---|
225 | if (fPedestals)
|
---|
226 | (*fPedestals)[idx].Set(b, sigb);
|
---|
227 | }
|
---|
228 |
|
---|
229 | fCerPhotEvt->FixSize();
|
---|
230 | fCerPhotEvt->SetReadyToSave();
|
---|
231 |
|
---|
232 | if (fPedestals)
|
---|
233 | fPedestals->SetReadyToSave();
|
---|
234 |
|
---|
235 | return kTRUE;
|
---|
236 | }
|
---|
237 |
|
---|