source: trunk/Mars/mfilter/MFCosmics.cc@ 9969

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