CMS 3D CMS Logo

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 class PatMCMatching : public edm::one::EDAnalyzer<edm::one::SharedResources> {
17 public:
19  explicit PatMCMatching(const edm::ParameterSet&);
21  ~PatMCMatching() 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 
38  : histContainer_(),
39  muonSrcToken_(consumes<edm::View<pat::Muon> >(iConfig.getUntrackedParameter<edm::InputTag>("muonSrc"))) {
40  usesResource(TFileService::kSharedResource);
41 }
42 
44 
46  // get muon collection
48  iEvent.getByToken(muonSrcToken_, muons);
49 
50  for (edm::View<pat::Muon>::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
51  for (unsigned int i = 0; i < muon->genParticleRefs().size(); ++i) {
52  switch (muon->genParticle(i)->status()) {
53  case 1:
54  histContainer_["DR_status1Match"]->Fill(
55  ROOT::Math::VectorUtil::DeltaR(muon->p4(), muon->genParticle(i)->p4()));
56  break;
57  case 3:
58  histContainer_["DR_status3Match"]->Fill(
59  ROOT::Math::VectorUtil::DeltaR(muon->p4(), muon->genParticle(i)->p4()));
60  break;
61  default:
62  histContainer_["DR_defaultMatch"]->Fill(
63  ROOT::Math::VectorUtil::DeltaR(muon->p4(), muon->genParticle(i)->p4()));
64  break;
65  }
66  }
67  }
68 }
69 
71  // register to the TFileService
73 
74  // book histograms:
75  histContainer_["DR_defaultMatch"] = fs->make<TH1F>("DR_defaultMatch", "DR_defaultMatch", 100, 0., 0.02);
76  histContainer_["DR_status1Match"] = fs->make<TH1F>("DR_status1Match", "DR_status1Match", 100, 0., 0.02);
77  histContainer_["DR_status3Match"] = fs->make<TH1F>("DR_status3Match", "DR_status3Match", 100, 0., 0.02);
78 }
79 
81 
static const std::string kSharedResource
Definition: TFileService.h:76
~PatMCMatching() override
default destructor
PatMCMatching(const edm::ParameterSet &)
default constructor
void analyze(const edm::Event &, const edm::EventSetup &) override
void endJob() override
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
Definition: Muon.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginJob() override
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
std::map< std::string, TH1F * > histContainer_
edm::EDGetTokenT< edm::View< pat::Muon > > muonSrcToken_