CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PatMCMatchingExtended.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:
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  //counts how often a genParticle with different charge gives a match
40  unsigned int diffCharge;
41 
42  //how many muons have no match
43  unsigned int noMatch;
44 
45  //how many muons have no status 1 or 3 match, but decay in flight
46  unsigned int decayInFlight;
47 
48  //count the number of muons in all events
49  unsigned int numberMuons;
50 
51 };
52 
53 
54 
56  histContainer_(),
57  muonSrcToken_(consumes<edm::View<pat::Muon> >(iConfig.getUntrackedParameter<edm::InputTag>("muonSrc")))
58 {
59 }
60 
62 {
63 }
64 
65 void
67 {
68 
69  // get muon collection
71  iEvent.getByToken(muonSrcToken_,muons);
72 
73  for(edm::View<pat::Muon>::const_iterator muon=muons->begin(); muon!=muons->end(); ++muon){
74  if(muon->genParticleById(0,1).isNonnull() ){
75  histContainer_["DR_status1Match"]->Fill( ROOT::Math::VectorUtil::DeltaR(muon->p4() , (muon->genParticleById(0,1) )->p4() ) );
76  histContainer_["DPt_status1Match"]->Fill(muon->pt() - (muon->genParticleById(0,1) )->pt() );
77  }
78  if(muon->genParticleById(0,3).isNonnull() ){
79  histContainer_["DR_status3Match"]->Fill( ROOT::Math::VectorUtil::DeltaR(muon->p4() , (muon->genParticleById(0,3) )->p4() ) );
80  histContainer_["DPt_status3Match"]->Fill(muon->pt() - (muon->genParticleById(0,3) )->pt() );
81  }
82  if(muon->genParticleById(0,-1).isNonnull() ){
83  histContainer_["DR_defaultMatch"]->Fill( ROOT::Math::VectorUtil::DeltaR(muon->p4() , (muon->genParticleById(0,-1) )->p4() ) );
84  histContainer_["DPt_defaultMatch"]->Fill(muon->pt() - (muon->genParticleById(0,-1) )->pt() );
85  }
86  if(muon->genParticleById(0,1).isNull() && muon->genParticleById(0,3).isNull() && muon->genParticleById(0,-1).isNull()) noMatch++;
87  if(muon->genParticleById(0,1).isNull() && muon->genParticleById(0,3).isNull() && muon->genParticleById(0,-1).isNonnull())decayInFlight++;
88 
89 
90 
91  if( muon->genParticleById(-13,0, 1).isNonnull() ){
92  diffCharge++;
93  std::cout<<" DIFF CHARGE!!! charge gen: "<< muon->genParticleById(-13,0, true)->charge()<< " charge reco: "<< muon->charge()<<std::endl;
94  }
95  numberMuons++;
96  }
97 
98 }
99 
100 void
102 {
103  // register to the TFileService
105 
106  // book histograms:
107  //DR
108  histContainer_["DR_defaultMatch" ]=fs->make<TH1F>("DR_defaultMatch", "DR_defaultMatch", 100, 0, 0.02);
109  histContainer_["DR_status1Match" ]=fs->make<TH1F>("DR_status1Match", "DR_status1Match", 100, 0, 0.02);
110  histContainer_["DR_status3Match" ]=fs->make<TH1F>("DR_status3Match", "DR_status3Match", 100, 0, 0.02);
111  //DPT
112  histContainer_["DPt_defaultMatch" ]=fs->make<TH1F>("DPt_defaultMatch", "DPt_defaultMatch", 10, 0, 1.2);
113  histContainer_["DPt_status1Match" ]=fs->make<TH1F>("DPt_status1Match", "DPt_status1Match", 10, 0, 1.2);
114  histContainer_["DPt_status3Match" ]=fs->make<TH1F>("DPt_status3Match", "DPt_status3Match", 10, 0, 1.2);
115  //some counters
116  diffCharge=0;
117  noMatch=0;
118  decayInFlight=0;
119  numberMuons=0;
120 
121 }
122 
123 void
125 {
126  std::cout<<"diffcharge: "<< diffCharge <<std::endl;
127  std::cout<<"noMatch: "<< noMatch <<std::endl;
128  std::cout<<"decayInFlight: "<< decayInFlight <<std::endl;
129  std::cout<<"numberMuons: "<< numberMuons <<std::endl;
130 }
131 
134 
135 
virtual void endJob() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
~PatMCMatchingExtended()
default destructor
virtual void beginJob() override
int iEvent
Definition: GenABIO.cc:230
double p4[4]
Definition: TauolaWrapper.h:92
std::map< std::string, TH1F * > histContainer_
tuple muons
Definition: patZpeak.py:38
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:85
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
PatMCMatchingExtended(const edm::ParameterSet &)
default constructor
tuple cout
Definition: gather_cfg.py:121
edm::EDGetTokenT< edm::View< pat::Muon > > muonSrcToken_