CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
16 
18 
19 public:
21  explicit PatMCMatching(const edm::ParameterSet&);
24 
25 private:
26 
27  virtual void beginJob() override ;
28  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
29  virtual void endJob() override ;
30 
31  // simple map to contain all histograms;
32  // histograms are booked in the beginJob()
33  // method
34  std::map<std::string,TH1F*> histContainer_;
35 
36  // input tags
38 };
39 
40 
41 
43  histContainer_(),
44  muonSrcToken_(consumes<edm::View<pat::Muon> >(iConfig.getUntrackedParameter<edm::InputTag>("muonSrc")))
45 {
46 }
47 
49 {
50 }
51 
52 void
54 {
55 
56  // get muon collection
58  iEvent.getByToken(muonSrcToken_,muons);
59 
60  for(edm::View<pat::Muon>::const_iterator muon=muons->begin(); muon!=muons->end(); ++muon){
61 
62  for(unsigned int i = 0 ; i < muon->genParticleRefs().size() ; ++i ){
63 
64  switch( muon->genParticle(i)->status() ){
65  case 1:
66  histContainer_["DR_status1Match"]->Fill( ROOT::Math::VectorUtil::DeltaR(muon->p4() , muon->genParticle(i)->p4() ) );
67  break;
68  case 3:
69  histContainer_["DR_status3Match"]->Fill( ROOT::Math::VectorUtil::DeltaR(muon->p4() , muon->genParticle(i)->p4() ) );
70  break;
71  default:
72  histContainer_["DR_defaultMatch"]->Fill( ROOT::Math::VectorUtil::DeltaR(muon->p4() , muon->genParticle(i)->p4() ) );
73  break;
74  }
75  }
76  }
77 
78 }
79 
80 void
82 {
83  // register to the TFileService
85 
86  // book histograms:
87  histContainer_["DR_defaultMatch" ]=fs->make<TH1F>("DR_defaultMatch", "DR_defaultMatch", 100, 0., 0.02);
88  histContainer_["DR_status1Match" ]=fs->make<TH1F>("DR_status1Match", "DR_status1Match", 100, 0., 0.02);
89  histContainer_["DR_status3Match" ]=fs->make<TH1F>("DR_status3Match", "DR_status3Match", 100, 0., 0.02);
90 
91 }
92 
93 void
95 {
96 }
97 
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
std::map< std::string, TH1F * > histContainer_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
PatMCMatching(const edm::ParameterSet &)
default constructor
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
virtual void endJob() override
int iEvent
Definition: GenABIO.cc:230
virtual void beginJob() override
~PatMCMatching()
default destructor
tuple muons
Definition: patZpeak.py:38
edm::EDGetTokenT< edm::View< pat::Muon > > muonSrcToken_