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 | ! Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MFCosmics
|
---|
29 | //
|
---|
30 | // Filter to reject cosmics by the criterion that at least
|
---|
31 | // fMaxEmptyPixels of the pixels have values of lower than 3 Pedestal RMS.
|
---|
32 | // fMaxEmptyPixels is set to 0.4 by default which is slightly higher
|
---|
33 | // than the number of outer pixels in MAGIC (for the case that
|
---|
34 | // the outer pixels have some defect).
|
---|
35 | //
|
---|
36 | // In the PostProcess we...
|
---|
37 | // a) check the ratio of events which were accepted against
|
---|
38 | // fMinAcceptedFraction.
|
---|
39 | // b) check the ratio of events which were rejected against
|
---|
40 | // fMaxAcceptedFraction.
|
---|
41 | //
|
---|
42 | // Input Containers:
|
---|
43 | // MRawEvtData
|
---|
44 | // MPedestalCam
|
---|
45 | // MBadPixelsCam
|
---|
46 | // MExtractedSignalCam
|
---|
47 | //
|
---|
48 | // Output Containers:
|
---|
49 | // -/-
|
---|
50 | //
|
---|
51 | //////////////////////////////////////////////////////////////////////////////
|
---|
52 | #include "MFCosmics.h"
|
---|
53 |
|
---|
54 | #include "MLog.h"
|
---|
55 | #include "MLogManip.h"
|
---|
56 |
|
---|
57 | #include "MParList.h"
|
---|
58 |
|
---|
59 | #include "MGeomCam.h"
|
---|
60 | #include "MRawEvtPixelIter.h"
|
---|
61 |
|
---|
62 | #include "MPedestalCam.h"
|
---|
63 | #include "MPedestalPix.h"
|
---|
64 |
|
---|
65 | #include "MBadPixelsCam.h"
|
---|
66 | #include "MBadPixelsPix.h"
|
---|
67 |
|
---|
68 | #include "MExtractedSignalCam.h"
|
---|
69 | #include "MExtractedSignalPix.h"
|
---|
70 |
|
---|
71 | ClassImp(MFCosmics);
|
---|
72 |
|
---|
73 | using namespace std;
|
---|
74 |
|
---|
75 | const TString MFCosmics::fgNamePedestalCam = "MPedestalCam";
|
---|
76 |
|
---|
77 | // --------------------------------------------------------------------------
|
---|
78 | //
|
---|
79 | // Default constructor.
|
---|
80 | //
|
---|
81 | MFCosmics::MFCosmics(const char *name, const char *title)
|
---|
82 | : fPedestals(NULL), fSignals(NULL), fBadPixels(NULL), fRawEvt(NULL),
|
---|
83 | fNamePedestalCam(fgNamePedestalCam), fMaxEmptyPixels(0.2),
|
---|
84 | fMinAcceptedFraction(0), fMaxAcceptedFraction(1)
|
---|
85 | {
|
---|
86 | fName = name ? name : "MFCosmics";
|
---|
87 | fTitle = title ? title : "Filter to reject cosmics";
|
---|
88 | }
|
---|
89 |
|
---|
90 | // --------------------------------------------------------------------------
|
---|
91 | //
|
---|
92 | // The PreProcess searches for the following input containers:
|
---|
93 | // - MRawEvtData
|
---|
94 | // - MPedestalCam
|
---|
95 | // - MExtractedSignalCam
|
---|
96 | //
|
---|
97 | Int_t MFCosmics::PreProcess(MParList *pList)
|
---|
98 | {
|
---|
99 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
100 | if (!fRawEvt)
|
---|
101 | {
|
---|
102 | *fLog << err << "MRawEvtData not found... aborting." << endl;
|
---|
103 | return kFALSE;
|
---|
104 | }
|
---|
105 |
|
---|
106 | fPedestals = (MPedestalCam*)pList->FindObject(fNamePedestalCam, "MPedestalCam");
|
---|
107 | if (!fPedestals)
|
---|
108 | {
|
---|
109 | *fLog << err << fNamePedestalCam << " [MPedestalCam] not found... aborting." << endl;
|
---|
110 | return kFALSE;
|
---|
111 | }
|
---|
112 |
|
---|
113 | fBadPixels = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
|
---|
114 | if (!fBadPixels)
|
---|
115 | {
|
---|
116 | *fLog << err << "MBadPixelsCam not found... aborting." << endl;
|
---|
117 | return kFALSE;
|
---|
118 | }
|
---|
119 |
|
---|
120 | fSignals = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
|
---|
121 | if (!fSignals)
|
---|
122 | {
|
---|
123 | *fLog << err << "MExtractedSignalCam not found... aborting." << endl;
|
---|
124 | return kFALSE;
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | memset(fCut, 0, sizeof(fCut));
|
---|
129 |
|
---|
130 | return kTRUE;
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | // --------------------------------------------------------------------------
|
---|
135 | //
|
---|
136 | // Initialize number of used FADC slices
|
---|
137 | //
|
---|
138 | Bool_t MFCosmics::ReInit(MParList *pList)
|
---|
139 | {
|
---|
140 | fSqrtHiGainSamples = TMath::Sqrt((Float_t) fSignals->GetNumUsedHiGainFADCSlices());
|
---|
141 |
|
---|
142 | return kTRUE;
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | // --------------------------------------------------------------------------
|
---|
147 | //
|
---|
148 | // Retrieve the integral of the FADC time slices and compare them to the
|
---|
149 | // pedestal values.
|
---|
150 | //
|
---|
151 | Int_t MFCosmics::Process()
|
---|
152 | {
|
---|
153 | fResult = CosmicsRejection();
|
---|
154 | fCut[fResult ? 0 : 1]++;
|
---|
155 |
|
---|
156 | return kTRUE;
|
---|
157 | }
|
---|
158 |
|
---|
159 | // ---------------------------------------------------------
|
---|
160 | //
|
---|
161 | // Cosmics rejection:
|
---|
162 | //
|
---|
163 | // Requiring less than fMaxEmptyPixels pixels to have values
|
---|
164 | // lower than 3 Pedestal RMS.
|
---|
165 | //
|
---|
166 | // fMaxEmptyPixels is set to 230 by default which is slightly higher
|
---|
167 | // than the number of outer pixels in MAGIC (for the case that
|
---|
168 | // the outer pixels have some defect).
|
---|
169 | //
|
---|
170 | Bool_t MFCosmics::CosmicsRejection() const
|
---|
171 | {
|
---|
172 | MRawEvtPixelIter pixel(fRawEvt);
|
---|
173 |
|
---|
174 | Int_t cosmicpix = 0;
|
---|
175 | Int_t allpix = 0;
|
---|
176 |
|
---|
177 | //
|
---|
178 | // Create a first loop to sort out the cosmics ...
|
---|
179 | //
|
---|
180 | while (pixel.Next())
|
---|
181 | {
|
---|
182 | const UInt_t idx = pixel.GetPixelId();
|
---|
183 |
|
---|
184 | if ((*fBadPixels)[idx].IsUnsuitable())
|
---|
185 | continue;
|
---|
186 |
|
---|
187 | const MExtractedSignalPix &sig = (*fSignals)[idx];
|
---|
188 |
|
---|
189 | allpix++;
|
---|
190 |
|
---|
191 | //
|
---|
192 | // Check whether the pixel has a saturating hi-gain. In
|
---|
193 | // this case the extracted hi-gain might be empty.
|
---|
194 | //
|
---|
195 | if (sig.GetNumHiGainSaturated()>0)
|
---|
196 | continue;
|
---|
197 |
|
---|
198 | const MPedestalPix &ped = (*fPedestals)[idx];
|
---|
199 |
|
---|
200 | const Float_t pedrms = ped.GetPedestalRms()*fSqrtHiGainSamples;
|
---|
201 | const Float_t sumhi = sig.GetExtractedSignalHiGain();
|
---|
202 |
|
---|
203 | //
|
---|
204 | // We consider a pixel as presumably due to cosmics
|
---|
205 | // if its sum of FADC slices is lower than 3 pedestal RMS
|
---|
206 | //
|
---|
207 | if (sumhi < 3.*pedrms )
|
---|
208 | cosmicpix++;
|
---|
209 | }
|
---|
210 |
|
---|
211 | //
|
---|
212 | // If the camera contains more than fMaxEmptyPixels
|
---|
213 | // presumed pixels due to cosmics, then the event is discarted.
|
---|
214 | //
|
---|
215 | return cosmicpix > fMaxEmptyPixels*allpix;
|
---|
216 | }
|
---|
217 |
|
---|
218 | // ---------------------------------------------------------
|
---|
219 | //
|
---|
220 | // In the PostProcess we...
|
---|
221 | // a) check the ratio of events which were accepted against
|
---|
222 | // fMinAcceptedFraction.
|
---|
223 | // b) check the ratio of events which were rejected against
|
---|
224 | // fMaxAcceptedFraction.
|
---|
225 | //
|
---|
226 | // return failure (kFALSE) if condition is not fullfilled.
|
---|
227 | //
|
---|
228 | Int_t MFCosmics::PostProcess()
|
---|
229 | {
|
---|
230 | const UInt_t n = GetNumExecutions();
|
---|
231 | if (n==0)
|
---|
232 | return kTRUE;
|
---|
233 |
|
---|
234 | *fLog << inf << endl;
|
---|
235 | *fLog << GetDescriptor() << " execution statistics:" << endl;
|
---|
236 | *fLog << dec << setfill(' ');
|
---|
237 |
|
---|
238 | *fLog << " " << setw(7) << fCut[0] << " (" << setw(3) ;
|
---|
239 | *fLog << (int)(fCut[0]*100/n);
|
---|
240 | *fLog << "%) Detected cosmics " ;
|
---|
241 | *fLog << " (with fMaxEmptyPixels = " << fMaxEmptyPixels*100 << "%)" << endl;
|
---|
242 |
|
---|
243 | *fLog << " " << setw(7) << fCut[1] << " (" << setw(3) ;
|
---|
244 | *fLog << (int)(fCut[1]*100/n);
|
---|
245 | *fLog << "%) No cosmics!" << endl;
|
---|
246 | *fLog << endl;
|
---|
247 |
|
---|
248 | if (fCut[0]<fMinAcceptedFraction*n)
|
---|
249 | {
|
---|
250 | *fLog << err << "ERROR - Fraction of accepted events " << Form("%.1f", fCut[0]*100./n);
|
---|
251 | *fLog << "% underrun " << fMinAcceptedFraction*100 << "%... abort." << endl;
|
---|
252 | return kFALSE;
|
---|
253 | }
|
---|
254 | if (fCut[0]>fMaxAcceptedFraction*n)
|
---|
255 | {
|
---|
256 | *fLog << err << "ERROR - Fraction of accepted events " << Form("%.1f", fCut[0]*100./n);
|
---|
257 | *fLog << "% exceeded " << fMaxAcceptedFraction*100 << "%... abort." << endl;
|
---|
258 | return kFALSE;
|
---|
259 | }
|
---|
260 |
|
---|
261 | return kTRUE;
|
---|
262 | }
|
---|
263 |
|
---|
264 | // --------------------------------------------------------------------------
|
---|
265 | //
|
---|
266 | // Read the setup from a TEnv, eg:
|
---|
267 | // MFCosmics.MaxEmptyPixels: 0.2
|
---|
268 | // MFCosmics.MaxAcceptedFraction: 1
|
---|
269 | // MFCosmics.MinAcceptedFraction: 0
|
---|
270 | //
|
---|
271 | Int_t MFCosmics::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
272 | {
|
---|
273 | Bool_t rc = kFALSE;
|
---|
274 | if (IsEnvDefined(env, prefix, "MaxEmptyPixels", print))
|
---|
275 | {
|
---|
276 | rc = kTRUE;
|
---|
277 | SetMaxEmptyPixels(GetEnvValue(env, prefix, "MaxEmptyPixels", fMaxEmptyPixels));
|
---|
278 | }
|
---|
279 | if (IsEnvDefined(env, prefix, "MaxAcceptedFraction", print))
|
---|
280 | {
|
---|
281 | rc = kTRUE;
|
---|
282 | SetMaxAcceptedFraction(GetEnvValue(env, prefix, "MaxAcceptedFraction", fMaxAcceptedFraction));
|
---|
283 | }
|
---|
284 | if (IsEnvDefined(env, prefix, "MinAcceptedFraction", print))
|
---|
285 | {
|
---|
286 | rc = kTRUE;
|
---|
287 | fMinAcceptedFraction = GetEnvValue(env, prefix, "MinAcceptedFraction", fMinAcceptedFraction);
|
---|
288 | }
|
---|
289 | return rc;
|
---|
290 | }
|
---|