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 
16 class PatMCMatchingExtended : public edm::one::EDAnalyzer<edm::one::SharedResources> {
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  usesResource(TFileService::kSharedResource);
53 }
54 
56 
58  // get muon collection
60  iEvent.getByToken(muonSrcToken_, muons);
61 
62  for (edm::View<pat::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
63  if (muon->genParticleById(0, 1).isNonnull()) {
64  histContainer_["DR_status1Match"]->Fill(
65  ROOT::Math::VectorUtil::DeltaR(muon->p4(), (muon->genParticleById(0, 1))->p4()));
66  histContainer_["DPt_status1Match"]->Fill(muon->pt() - (muon->genParticleById(0, 1))->pt());
67  }
68  if (muon->genParticleById(0, 3).isNonnull()) {
69  histContainer_["DR_status3Match"]->Fill(
70  ROOT::Math::VectorUtil::DeltaR(muon->p4(), (muon->genParticleById(0, 3))->p4()));
71  histContainer_["DPt_status3Match"]->Fill(muon->pt() - (muon->genParticleById(0, 3))->pt());
72  }
73  if (muon->genParticleById(0, -1).isNonnull()) {
74  histContainer_["DR_defaultMatch"]->Fill(
75  ROOT::Math::VectorUtil::DeltaR(muon->p4(), (muon->genParticleById(0, -1))->p4()));
76  histContainer_["DPt_defaultMatch"]->Fill(muon->pt() - (muon->genParticleById(0, -1))->pt());
77  }
78  if (muon->genParticleById(0, 1).isNull() && muon->genParticleById(0, 3).isNull() &&
79  muon->genParticleById(0, -1).isNull())
80  noMatch++;
81  if (muon->genParticleById(0, 1).isNull() && muon->genParticleById(0, 3).isNull() &&
82  muon->genParticleById(0, -1).isNonnull())
83  decayInFlight++;
84 
85  if (muon->genParticleById(-13, 0, 1).isNonnull()) {
86  diffCharge++;
87  std::cout << " DIFF CHARGE!!! charge gen: " << muon->genParticleById(-13, 0, true)->charge()
88  << " charge reco: " << muon->charge() << std::endl;
89  }
90  numberMuons++;
91  }
92 }
93 
95  // register to the TFileService
97 
98  // book histograms:
99  //DR
100  histContainer_["DR_defaultMatch"] = fs->make<TH1F>("DR_defaultMatch", "DR_defaultMatch", 100, 0, 0.02);
101  histContainer_["DR_status1Match"] = fs->make<TH1F>("DR_status1Match", "DR_status1Match", 100, 0, 0.02);
102  histContainer_["DR_status3Match"] = fs->make<TH1F>("DR_status3Match", "DR_status3Match", 100, 0, 0.02);
103  //DPT
104  histContainer_["DPt_defaultMatch"] = fs->make<TH1F>("DPt_defaultMatch", "DPt_defaultMatch", 10, 0, 1.2);
105  histContainer_["DPt_status1Match"] = fs->make<TH1F>("DPt_status1Match", "DPt_status1Match", 10, 0, 1.2);
106  histContainer_["DPt_status3Match"] = fs->make<TH1F>("DPt_status3Match", "DPt_status3Match", 10, 0, 1.2);
107  //some counters
108  diffCharge = 0;
109  noMatch = 0;
110  decayInFlight = 0;
111  numberMuons = 0;
112 }
113 
115  std::cout << "diffcharge: " << diffCharge << std::endl;
116  std::cout << "noMatch: " << noMatch << std::endl;
117  std::cout << "decayInFlight: " << decayInFlight << std::endl;
118  std::cout << "numberMuons: " << numberMuons << std::endl;
119 }
120 
static const std::string kSharedResource
Definition: TFileService.h:76
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:41
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_