CMS 3D CMS Logo

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