source: branches/Mars_MC/mfilter/MFCosmics.cc@ 17859

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