CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PatMCMatching.cc
Go to the documentation of this file.
1 #include <map>
2 #include <string>
3 
4 #include "TH1.h"
5 
12 #include "Math/VectorUtil.h"
13 
15 
17 public:
19  explicit PatMCMatching(const edm::ParameterSet&);
21  ~PatMCMatching() override;
22 
23 private:
24  void beginJob() override;
25  void analyze(const edm::Event&, const edm::EventSetup&) override;
26  void endJob() override;
27 
28  // simple map to contain all histograms;
29  // histograms are booked in the beginJob()
30  // method
31  std::map<std::string, TH1F*> histContainer_;
32 
33  // input tags
35 };
36 
38  : histContainer_(),
39  muonSrcToken_(consumes<edm::View<pat::Muon> >(iConfig.getUntrackedParameter<edm::InputTag>("muonSrc"))) {}
40 
42 
44  // get muon collection
46  iEvent.getByToken(muonSrcToken_, muons);
47 
48  for (edm::View<pat::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
49  for (unsigned int i = 0; i < muon->genParticleRefs().size(); ++i) {
50  switch (muon->genParticle(i)->status()) {
51  case 1:
52  histContainer_["DR_status1Match"]->Fill(
53  ROOT::Math::VectorUtil::DeltaR(muon->p4(), muon->genParticle(i)->p4()));
54  break;
55  case 3:
56  histContainer_["DR_status3Match"]->Fill(
57  ROOT::Math::VectorUtil::DeltaR(muon->p4(), muon->genParticle(i)->p4()));
58  break;
59  default:
60  histContainer_["DR_defaultMatch"]->Fill(
61  ROOT::Math::VectorUtil::DeltaR(muon->p4(), muon->genParticle(i)->p4()));
62  break;
63  }
64  }
65  }
66 }
67 
69  // register to the TFileService
71 
72  // book histograms:
73  histContainer_["DR_defaultMatch"] = fs->make<TH1F>("DR_defaultMatch", "DR_defaultMatch", 100, 0., 0.02);
74  histContainer_["DR_status1Match"] = fs->make<TH1F>("DR_status1Match", "DR_status1Match", 100, 0., 0.02);
75  histContainer_["DR_status3Match"] = fs->make<TH1F>("DR_status3Match", "DR_status3Match", 100, 0., 0.02);
76 }
77 
79 
~PatMCMatching() override
default destructor
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PatMCMatching(const edm::ParameterSet &)
default constructor
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void analyze(const edm::Event &, const edm::EventSetup &) override
void endJob() override
int iEvent
Definition: GenABIO.cc:224
void beginJob() override
tuple muons
Definition: patZpeak.py:39
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::map< std::string, TH1F * > histContainer_
edm::EDGetTokenT< edm::View< pat::Muon > > muonSrcToken_