source: trunk/MagicSoft/Mars/mfilter/MFCosmics.cc@ 7876

Last change on this file since 7876 was 7876, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 8.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): 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
71ClassImp(MFCosmics);
72
73using namespace std;
74
75const TString MFCosmics::fgNamePedestalCam = "MPedestalCam";
76
77// --------------------------------------------------------------------------
78//
79// Default constructor.
80//
81MFCosmics::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//
97Int_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 memset(fCut, 0, sizeof(fCut));
128
129 return kTRUE;
130}
131
132
133// --------------------------------------------------------------------------
134//
135// Initialize number of used FADC slices
136//
137Bool_t MFCosmics::ReInit(MParList *pList)
138{
139 fSqrtHiGainSamples = TMath::Sqrt((Float_t) fSignals->GetNumUsedHiGainFADCSlices());
140
141 return kTRUE;
142}
143
144
145// --------------------------------------------------------------------------
146//
147// Retrieve the integral of the FADC time slices and compare them to the
148// pedestal values.
149//
150Int_t MFCosmics::Process()
151{
152 fResult = CosmicsRejection();
153 fCut[fResult ? 0 : 1]++;
154
155 return kTRUE;
156}
157
158// ---------------------------------------------------------
159//
160// Cosmics rejection:
161//
162// Requiring less than fMaxEmptyPixels pixels to have values
163// lower than 3 Pedestal RMS.
164//
165// fMaxEmptyPixels is set to 230 by default which is slightly higher
166// than the number of outer pixels in MAGIC (for the case that
167// the outer pixels have some defect).
168//
169Bool_t MFCosmics::CosmicsRejection() const
170{
171 MRawEvtPixelIter pixel(fRawEvt);
172
173 Int_t cosmicpix = 0;
174 Int_t allpix = 0;
175
176 //
177 // Create a first loop to sort out the cosmics ...
178 //
179 while (pixel.Next())
180 {
181 const UInt_t idx = pixel.GetPixelId();
182
183 if ((*fBadPixels)[idx].IsUnsuitable())
184 continue;
185
186 const MExtractedSignalPix &sig = (*fSignals)[idx];
187
188 allpix++;
189
190 //
191 // Check whether the pixel has a saturating hi-gain. In
192 // this case the extracted hi-gain might be empty.
193 //
194 if (sig.IsHiGainSaturated())
195 continue;
196
197 const MPedestalPix &ped = (*fPedestals)[idx];
198
199 const Float_t pedrms = ped.GetPedestalRms()*fSqrtHiGainSamples;
200 const Float_t sumhi = sig.GetExtractedSignalHiGain();
201
202 //
203 // We consider a pixel as presumably due to cosmics
204 // if its sum of FADC slices is lower than 3 pedestal RMS
205 //
206 if (sumhi < 3.*pedrms )
207 cosmicpix++;
208 }
209
210 //
211 // If the camera contains more than fMaxEmptyPixels
212 // presumed pixels due to cosmics, then the event is discarted.
213 //
214 return cosmicpix > fMaxEmptyPixels*allpix;
215}
216
217// ---------------------------------------------------------
218//
219// In the PostProcess we...
220// a) check the ratio of events which were accepted against
221// fMinAcceptedFraction.
222// b) check the ratio of events which were rejected against
223// fMaxAcceptedFraction.
224//
225// return failure (kFALSE) if condition is not fullfilled.
226//
227Int_t MFCosmics::PostProcess()
228{
229 const UInt_t n = GetNumExecutions();
230 if (n==0)
231 return kTRUE;
232
233 *fLog << inf << endl;
234 *fLog << GetDescriptor() << " execution statistics:" << endl;
235 *fLog << dec << setfill(' ');
236
237 *fLog << " " << setw(7) << fCut[0] << " (" << setw(3) ;
238 *fLog << (int)(fCut[0]*100/n);
239 *fLog << "%) Detected cosmics " ;
240 *fLog << " (with fMaxEmptyPixels = " << fMaxEmptyPixels*100 << "%)" << endl;
241
242 *fLog << " " << setw(7) << fCut[1] << " (" << setw(3) ;
243 *fLog << (int)(fCut[1]*100/n);
244 *fLog << "%) No cosmics!" << endl;
245 *fLog << endl;
246
247 if (fCut[0]<fMinAcceptedFraction*n)
248 {
249 *fLog << err << "ERROR - Fraction of accepted events " << Form("%.1f", fCut[0]*100./n);
250 *fLog << "% underrun " << fMinAcceptedFraction*100 << "%... abort." << endl;
251 return kFALSE;
252 }
253 if (fCut[0]>fMaxAcceptedFraction*n)
254 {
255 *fLog << err << "ERROR - Fraction of accepted events " << Form("%.1f", fCut[0]*100./n);
256 *fLog << "% exceeded " << fMaxAcceptedFraction*100 << "%... abort." << endl;
257 return kFALSE;
258 }
259
260 return kTRUE;
261}
262
263// --------------------------------------------------------------------------
264//
265// Read the setup from a TEnv, eg:
266// MFCosmics.MaxEmptyPixels: 0.2
267// MFCosmics.MaxAcceptedFraction: 1
268// MFCosmics.MinAcceptedFraction: 0
269//
270Int_t MFCosmics::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
271{
272 Bool_t rc = kFALSE;
273 if (IsEnvDefined(env, prefix, "MaxEmptyPixels", print))
274 {
275 rc = kTRUE;
276 SetMaxEmptyPixels(GetEnvValue(env, prefix, "MaxEmptyPixels", fMaxEmptyPixels));
277 }
278 if (IsEnvDefined(env, prefix, "MaxAcceptedFraction", print))
279 {
280 rc = kTRUE;
281 SetMaxAcceptedFraction(GetEnvValue(env, prefix, "MaxAcceptedFraction", fMaxAcceptedFraction));
282 }
283 if (IsEnvDefined(env, prefix, "MinAcceptedFraction", print))
284 {
285 rc = kTRUE;
286 fMinAcceptedFraction = GetEnvValue(env, prefix, "MinAcceptedFraction", fMinAcceptedFraction);
287 }
288 return rc;
289}
Note: See TracBrowser for help on using the repository browser.