CMS 3D CMS Logo

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 
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PatMCMatchingExtended::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PatMCMatchingExtended.cc:55
sistrip::View
View
Definition: ConstantsForView.h:26
PatMCMatchingExtended::noMatch
unsigned int noMatch
Definition: PatMCMatchingExtended.cc:40
muon
Definition: MuonCocktails.h:17
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
EDAnalyzer.h
edm::Handle
Definition: AssociativeIterator.h:50
PatMCMatchingExtended::muonSrcToken_
edm::EDGetTokenT< edm::View< pat::Muon > > muonSrcToken_
Definition: PatMCMatchingExtended.cc:34
Muon
Definition: Muon.py:1
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PatMCMatchingExtended::endJob
void endJob() override
Definition: PatMCMatchingExtended.cc:112
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11710
Service.h
PatMCMatchingExtended::PatMCMatchingExtended
PatMCMatchingExtended(const edm::ParameterSet &)
default constructor
Definition: PatMCMatchingExtended.cc:49
TFileService.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PatMCMatchingExtended::numberMuons
unsigned int numberMuons
Definition: PatMCMatchingExtended.cc:46
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
p4
double p4[4]
Definition: TauolaWrapper.h:92
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
electronAnalyzer_cfi.DeltaR
DeltaR
Definition: electronAnalyzer_cfi.py:33
PatMCMatchingExtended::~PatMCMatchingExtended
~PatMCMatchingExtended() override
default destructor
Definition: PatMCMatchingExtended.cc:53
PatMCMatchingExtended::decayInFlight
unsigned int decayInFlight
Definition: PatMCMatchingExtended.cc:43
InputTag.h
PatMCMatchingExtended
Definition: PatMCMatchingExtended.cc:16
PatMCMatchingExtended::beginJob
void beginJob() override
Definition: PatMCMatchingExtended.cc:92
PatMCMatchingExtended::histContainer_
std::map< std::string, TH1F * > histContainer_
Definition: PatMCMatchingExtended.cc:31
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
ParameterSet.h
edm::Event
Definition: Event.h:73
PatMCMatchingExtended::diffCharge
unsigned int diffCharge
Definition: PatMCMatchingExtended.cc:37
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64