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 
14 
16 
17 public:
22 
23 private:
24 
25  virtual void beginJob() ;
26  virtual void analyze(const edm::Event&, const edm::EventSetup&);
27  virtual void endJob() ;
28 
29  // simple map to contain all histograms;
30  // histograms are booked in the beginJob()
31  // method
32  std::map<std::string,TH1F*> histContainer_;
33 
34  // input tags
36 
37  //counts how often a genParticle with different charge gives a match
38  unsigned int diffCharge;
39 
40  //how many muons have no match
41  unsigned int noMatch;
42 
43  //how many muons have no status 1 or 3 match, but decay in flight
44  unsigned int decayInFlight;
45 
46  //count the number of muons in all events
47  unsigned int numberMuons;
48 
49 };
50 
51 
53 
54 
56  histContainer_(),
57  muonSrc_(iConfig.getUntrackedParameter<edm::InputTag>("muonSrc"))
58 {
59 }
60 
62 {
63 }
64 
65 void
67 {
68 
69  // get muon collection
71  iEvent.getByLabel(muonSrc_,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 
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
~PatMCMatchingExtended()
default destructor
int iEvent
Definition: GenABIO.cc:243
double p4[4]
Definition: TauolaWrapper.h:92
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
std::map< std::string, TH1F * > histContainer_
PatMCMatchingExtended(const edm::ParameterSet &)
default constructor
T * make() const
make new ROOT object
tuple cout
Definition: gather_cfg.py:41
virtual void analyze(const edm::Event &, const edm::EventSetup &)