CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EmptyEventsFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EmptyEventsFilter
4 // Class: EmptyEventsFilter
5 //
13 //
14 // Original Author: Manuel Zeise
15 // Created: Wed Oct 17 10:06:52 CEST 2007
16 // $Id: EmptyEventsFilter.cc,v 1.8 2011/04/27 15:54:05 fruboes Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
32 
34 #include <vector>
37 
38 //#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
39 
40 //
41 // class declaration
42 //
43 
45  public:
46  explicit EmptyEventsFilter(const edm::ParameterSet&);
48 
49  private:
50  virtual void beginJob() ;
51  virtual bool filter(edm::Event&, const edm::EventSetup&);
52  virtual void endJob() ;
53 
55  int target_;
56 
57  int evTotal_;
59  // ----------member data ---------------------------
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 //
67 // static data member definitions
68 //
69 
70 //
71 // constructors and destructor
72 //
74 {
75  //now do what ever initialization is needed
76  src_ = iConfig.getUntrackedParameter<edm::InputTag>("src",edm::InputTag("generator"));
77  target_ = iConfig.getUntrackedParameter<int>("target",0);
78  evTotal_ = 0;
79  evSelected_ = 0;
80 }
81 
82 
84 {
85 
86  // do anything here that needs to be done at desctruction time
87  // (e.g. close files, deallocate resources etc.)
88 
89 }
90 
91 
92 //
93 // member functions
94 //
95 
96 // ------------ method called on each new Event ------------
97 bool
99 {
100  ++evTotal_;
101  using namespace edm;
102  using namespace std;
103 // using namespace HepMC;
104 
105  bool found = false;
106  switch (target_)
107  {
108  case 1:
109  {
110  Handle<edm::HepMCProduct> dataHandle ;
111  iEvent.getByLabel(src_, dataHandle ) ;
112  if (dataHandle.isValid())
113  found = true;
114  break;
115  }
116  case 0:
117  default:
118  {
119  Handle<std::vector<reco::Muon> > dataHandle;
120  iEvent.getByLabel(src_, dataHandle ) ;
121  if (dataHandle.isValid())
122  found = true;
123  }
124  }
125 
126 // Handle<edm::HepMCProduct> HepMCHandle;
127 // iEvent.getByLabel("newSource",HepMCHandle);
128 //
129 // HepMC::GenEvent * evt = new HepMC::GenEvent(*(HepMCHandle->GetEvent()));
130 // evt->print(std::cout);
131 
132  if (!found) {
133  return false;
134  }
135  else {
136  ++evSelected_;
137  return true;
138  }
139 
140 }
141 
142 // ------------ method called once each job just before starting event loop ------------
143 void
145 {
146 }
147 
148 // ------------ method called once each job just after ending the event loop ------------
149 void
151  std::cout << "EmptyEventsFilter:: "
152  << double(evSelected_)/evTotal_
153  << " " << evSelected_
154  << " " << evTotal_
155  << std::endl;
156 
157 }
158 
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual bool filter(edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:243
virtual void endJob()
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
EmptyEventsFilter(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:121
virtual void beginJob()