ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/UfCode/UserArea/FlatRandomDrop/src/FlatRandomDrop.cc
Revision: 1.1
Committed: Mon Oct 25 15:29:00 2010 UTC (14 years, 6 months ago) by digiovan
Content type: text/plain
Branch: MAIN
CVS Tags: V2012-H-02, V2012-01-00, V2011-01-01, V2011-01-00, AnnaDimuon, V01-00-01, V01-00-00, HEAD
Log Message:
package for Z'/boostedZ analysis

File Contents

# User Rev Content
1 digiovan 1.1 // -*- C++ -*-
2     //
3     // Package: FlatRandomDrop
4     // Class: FlatRandomDrop
5     //
6     /**\class FlatRandomDrop FlatRandomDrop.cc UserArea/FlatRandomDrop/src/FlatRandomDrop.cc
7    
8     Description: [one line class summary]
9    
10     Implementation:
11     [Notes on implementation]
12     */
13     //
14     // Original Author: Theodore Nicholas Kypreos,8 R-031,+41227675208,
15     // Created: Mon Jun 14 19:03:27 CEST 2010
16     // $Id$
17     //
18     //
19    
20    
21     // system include files
22     #include <memory>
23    
24     // user include files
25     #include "FWCore/Framework/interface/Frameworkfwd.h"
26     #include "FWCore/Framework/interface/EDFilter.h"
27    
28     #include "FWCore/Framework/interface/Event.h"
29     #include "FWCore/Framework/interface/MakerMacros.h"
30    
31     #include "FWCore/ParameterSet/interface/ParameterSet.h"
32    
33     #include "TRandom3.h"
34    
35     //
36     // class declaration
37     //
38    
39     class FlatRandomDrop : public edm::EDFilter {
40     public:
41     explicit FlatRandomDrop(const edm::ParameterSet&);
42     ~FlatRandomDrop();
43    
44     private:
45     virtual void beginJob() ;
46     virtual bool filter(edm::Event&, const edm::EventSetup&);
47     virtual void endJob() ;
48    
49     TRandom3* _rand3;
50    
51     int _numSeen;
52     int _numDropped;
53     double _pval;
54    
55    
56     // ----------member data ---------------------------
57     };
58    
59     //
60     // constants, enums and typedefs
61     //
62    
63     //
64     // static data member definitions
65     //
66    
67     //
68     // constructors and destructor
69     //
70     FlatRandomDrop::FlatRandomDrop(const edm::ParameterSet& iConfig):_numSeen(0),_numDropped(0)
71     {
72     //now do what ever initialization is needed
73     _rand3 = new TRandom3(0);
74     _pval = iConfig.getParameter<double>("probKeep");
75     std::cout<<"---FlatRandomDrop: initializing to keep "<<_pval*100.<<"% of events"<<std::endl;
76     std::cout <<"If you are pre-scaling the data, you don't deserve to breathe and"<<std::endl
77     <<"Cromm will rise up from the Earth to swallow your bones."<<std::endl;
78    
79    
80    
81     }
82    
83    
84     FlatRandomDrop::~FlatRandomDrop()
85     {
86     _rand3->Delete();
87     // do anything here that needs to be done at desctruction time
88     // (e.g. close files, deallocate resources etc.)
89    
90     }
91    
92    
93     //
94     // member functions
95     //
96    
97     // ------------ method called on each new Event ------------
98     bool
99     FlatRandomDrop::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
100     {
101     if (_pval >= 1) return true;
102    
103     double prob = _rand3->Rndm();
104     ++_numSeen;
105    
106     if (prob < _pval) return true;
107     else {
108     ++_numDropped;
109     return false;
110     }
111     /* {
112     ++_numDropped;
113     return true;
114     }else return false;
115     */
116     /*
117     using namespace edm;
118     #ifdef THIS_IS_AN_EVENT_EXAMPLE
119     Handle<ExampleData> pIn;
120     iEvent.getByLabel("example",pIn);
121     #endif
122    
123     #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
124     ESHandle<SetupData> pSetup;
125     iSetup.get<SetupRecord>().get(pSetup);
126     #endif
127     return true;
128     */
129     }
130    
131     // ------------ method called once each job just before starting event loop ------------
132     void
133     FlatRandomDrop::beginJob()
134     {
135     }
136    
137     // ------------ method called once each job just after ending the event loop ------------
138     void
139     FlatRandomDrop::endJob() {
140     std::cout<<"-----FlatRandomDrop..."<<std::endl;
141     if (_pval <1){
142     std::cout<<"-------number of events seen: "<<_numSeen<<std::endl;
143     std::cout<<"-------number of events rejected: "<<_numDropped<<std::endl;
144     std::cout<<"-------rate of drop: "<<1.0*_numDropped/_numSeen<<std::endl;
145     std::cout<<"-------number of events accepted: "<<_numSeen-_numDropped<<std::endl;
146     std::cout<<"-------rate of accept: "<<(1.-1.0*_numDropped/_numSeen)<<std::endl;
147     } else {
148     std::cout<<"-----no flat-random filtering applied..."<<std::endl;
149    
150     }
151     }
152    
153     //define this as a plug-in
154     DEFINE_FWK_MODULE(FlatRandomDrop);