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

Last change on this file since 8132 was 8132, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 8.6 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MFCosmics.cc,v 1.15 2006-10-19 14:01:03 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-2006
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 "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
192 allpix++;
193
194 //
195 // Check whether the pixel has a saturating hi-gain. In
196 // this case the extracted hi-gain might be empty.
197 //
198 if (sig.IsHiGainSaturated())
199 continue;
200
201 const MPedestalPix &ped = (*fPedestals)[idx];
202
203 const Float_t pedrms = ped.GetPedestalRms()*fSqrtHiGainSamples;
204 const Float_t sumhi = sig.GetExtractedSignalHiGain();
205
206 //
207 // We consider a pixel as presumably due to cosmics
208 // if its sum of FADC slices is lower than 3 pedestal RMS
209 //
210 if (sumhi < 3.*pedrms )
211 cosmicpix++;
212 }
213
214 //
215 // If the camera contains more than fMaxEmptyPixels
216 // presumed pixels due to cosmics, then the event is discarted.
217 //
218 return cosmicpix > fMaxEmptyPixels*allpix;
219}
220
221// ---------------------------------------------------------
222//
223// In the PostProcess we...
224// a) check the ratio of events which were accepted against
225// fMinAcceptedFraction.
226// b) check the ratio of events which were rejected against
227// fMaxAcceptedFraction.
228//
229// return failure (kFALSE) if condition is not fullfilled.
230//
231Int_t MFCosmics::PostProcess()
232{
233 const UInt_t n = GetNumExecutions();
234 if (n==0)
235 return kTRUE;
236
237 *fLog << inf << endl;
238 *fLog << GetDescriptor() << " execution statistics:" << endl;
239 *fLog << dec << setfill(' ');
240
241 *fLog << " " << setw(7) << fCut[0] << " (" << setw(3) ;
242 *fLog << (int)(fCut[0]*100/n);
243 *fLog << "%) Detected cosmics " ;
244 *fLog << " (with fMaxEmptyPixels = " << fMaxEmptyPixels*100 << "%)" << endl;
245
246 *fLog << " " << setw(7) << fCut[1] << " (" << setw(3) ;
247 *fLog << (int)(fCut[1]*100/n);
248 *fLog << "%) No cosmics!" << endl;
249 *fLog << endl;
250
251 if (fCut[0]<fMinAcceptedFraction*n)
252 {
253 *fLog << err << "ERROR - Fraction of accepted events " << Form("%.1f", fCut[0]*100./n);
254 *fLog << "% underrun " << fMinAcceptedFraction*100 << "%... abort." << endl;
255 return kFALSE;
256 }
257 if (fCut[0]>fMaxAcceptedFraction*n)
258 {
259 *fLog << err << "ERROR - Fraction of accepted events " << Form("%.1f", fCut[0]*100./n);
260 *fLog << "% exceeded " << fMaxAcceptedFraction*100 << "%... abort." << endl;
261 return kFALSE;
262 }
263
264 return kTRUE;
265}
266
267// --------------------------------------------------------------------------
268//
269// Read the setup from a TEnv, eg:
270// MFCosmics.MaxEmptyPixels: 0.2
271// MFCosmics.MaxAcceptedFraction: 1
272// MFCosmics.MinAcceptedFraction: 0
273//
274Int_t MFCosmics::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
275{
276 Bool_t rc = kFALSE;
277 if (IsEnvDefined(env, prefix, "MaxEmptyPixels", print))
278 {
279 rc = kTRUE;
280 SetMaxEmptyPixels(GetEnvValue(env, prefix, "MaxEmptyPixels", fMaxEmptyPixels));
281 }
282 if (IsEnvDefined(env, prefix, "MaxAcceptedFraction", print))
283 {
284 rc = kTRUE;
285 SetMaxAcceptedFraction(GetEnvValue(env, prefix, "MaxAcceptedFraction", fMaxAcceptedFraction));
286 }
287 if (IsEnvDefined(env, prefix, "MinAcceptedFraction", print))
288 {
289 rc = kTRUE;
290 fMinAcceptedFraction = GetEnvValue(env, prefix, "MinAcceptedFraction", fMinAcceptedFraction);
291 }
292 return rc;
293}
Note: See TracBrowser for help on using the repository browser.