CMS 3D CMS Logo

MuScleFitGenFilter.cc
Go to the documentation of this file.
1 //#define DEBUG
2 // System include files
3 // --------------------
4 #include <memory>
5 #include <vector>
6 #include <string>
7 
8 // User include files
9 // ------------------
16 
17 
18 // Collaborating Class Header
25 
26 #include "MuScleFitUtils.h"
27 
28 #include <CLHEP/Vector/LorentzVector.h>
29 
30 // Class declaration
31 // -----------------
32 
34  public:
35  explicit MuScleFitGenFilter(const edm::ParameterSet&);
36  ~MuScleFitGenFilter() override;
37 
38  private:
39  bool filter(edm::Event&, const edm::EventSetup&) override;
40  void endJob() override {};
41 
45  unsigned int totalEvents_;
47 };
48 
49 // Constructor
50 // -----------
52  genParticlesName_( iConfig.getUntrackedParameter<std::string>("GenParticlesName", "genParticles") ),
55  totalEvents_(0),
57 {
58  MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind");
59 }
60 
61 // Destructor
62 // ----------
64 {
65  std::cout << "Total number of events = " << totalEvents_ << std::endl;
66  std::cout << "Events passing the filter = " << eventsPassingTheFilter_ << std::endl;
67 }
68 
69 // Method called for each event
70 // ----------------------------
72 {
73  ++totalEvents_;
74 
76 
77  std::pair<lorentzVector,lorentzVector> genPair;
78 
79  event.getByToken( evtMCToken_, evtMC );
80  if( evtMC.isValid() ) {
81 
82  genPair = MuScleFitUtils::findGenMuFromRes(evtMC.product());
83  }
84  else {
86  event.getByToken( genParticlesToken_, genParticles );
87  if( genParticles.isValid() ) {
88 
89  genPair = MuScleFitUtils::findGenMuFromRes(genParticles.product());
90  }
91  else {
92  std::cout << "ERROR: no generator info found" << std::endl;
93  return false;
94  }
95  }
96  lorentzVector emptyVec(0.,0.,0.,0.);
97  if( (genPair.first == emptyVec) || (genPair.second == emptyVec) ) {
98  return false;
99  }
100 
102 
103  return true;
104 }
105 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
static std::pair< lorentzVector, lorentzVector > findGenMuFromRes(const reco::GenParticleCollection *genParticles)
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::HepMCProduct > evtMCToken_
bool isValid() const
Definition: HandleBase.h:74
bool filter(edm::Event &, const edm::EventSetup &) override
~MuScleFitGenFilter() override
unsigned int eventsPassingTheFilter_
T const * product() const
Definition: Handle.h:74
std::string genParticlesName_
fixed size matrix
HLT enums.
static std::vector< int > resfind
void endJob() override
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
Definition: event.py:1
MuScleFitGenFilter(const edm::ParameterSet &)