source: trunk/MagicSoft/Mars/mfilter/MFRandomSplit.cc@ 2765

Last change on this file since 2765 was 2585, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.1 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): Wolfgang Wittek, 11/2003 <mailto:wittek@mppmu.mpg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MFRandomSplit
28//
29// A filter which gives fResult = kTRUE with the probability fProb
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MFRandomSplit.h"
33
34#include <fstream>
35#include <TRandom.h>
36
37#include "MParList.h"
38
39#include "MLog.h"
40#include "MLogManip.h"
41
42ClassImp(MFRandomSplit);
43
44using namespace std;
45
46// --------------------------------------------------------------------------
47//
48// Constructor
49//
50MFRandomSplit::MFRandomSplit(Double_t f, const char *name, const char *title)
51 : fProb(f)
52{
53 fName = name ? name : "MFRandomSplit";
54 fTitle = title ? title : "Filter for random splitting";
55
56 if (fProb < 0)
57 {
58 *fLog << warn << "WARNING - MFRandomSplit::MFRandomSplit: Probability less than 0... set to 0." << endl;
59 fProb = 0;
60 }
61
62 if (fProb > 1)
63 {
64 *fLog << warn << "WARNING - MFRandomSplit::MFRandomSplit: Probability greater than 1... set to 1." << endl;
65 fProb = 1;
66 }
67}
68
69// --------------------------------------------------------------------------
70//
71// PreProcess. Set fNumSelectedEvts=0
72//
73Int_t MFRandomSplit::PreProcess(MParList *pList)
74{
75 fNumSelectedEvts = 0;
76 return kTRUE;
77}
78
79// --------------------------------------------------------------------------
80//
81// Select events randomly according to the probability fProb. Count all
82// selected events
83//
84Int_t MFRandomSplit::Process()
85{
86 fResult = gRandom->Uniform() < fProb;
87
88 if (fResult)
89 fNumSelectedEvts++;
90
91 return kTRUE;
92}
93
94
95// --------------------------------------------------------------------------
96//
97// PostProcess. Prints execution statistics
98//
99Int_t MFRandomSplit::PostProcess()
100{
101 if (GetNumExecutions()==0)
102 return kTRUE;
103
104 *fLog << inf << endl;
105 *fLog << GetDescriptor() << " execution statistics:" << endl;
106 *fLog << dec << setfill(' ');
107 *fLog << " " << setw(7) << fNumSelectedEvts << " (";
108 *fLog << setw(3) << (int)(100.*fNumSelectedEvts/GetNumExecutions());
109 *fLog << "%) selected - out of " << GetNumExecutions() << endl;
110 *fLog << endl;
111
112 return kTRUE;
113}
Note: See TracBrowser for help on using the repository browser.