CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GlbMuQualityCutsAnalysis.cc
Go to the documentation of this file.
5 #include <iostream>
6 #include "TH1.h"
7 
9 public:
11  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
12  // virtual void endJob();
13 private:
16  std::vector<unsigned int> matched_, unMatched_;
18  int nHitCut_;
20 
21 };
22 
30 using namespace std;
31 using namespace reco;
32 using namespace edm;
35 
36 
37 
39  src_(cfg.getParameter<InputTag>("src")),
40  srcToken_(consumes<CandidateView>(src_)),
41  ptMin_(cfg.getUntrackedParameter<double>("ptMin")),
42  massMin_(cfg.getUntrackedParameter<double>("massMin")),
43  massMax_(cfg.getUntrackedParameter<double>("massMax")),
44  etaMin_(cfg.getUntrackedParameter<double>("etaMin")),
45  etaMax_(cfg.getUntrackedParameter<double>("etaMax")),
46  trkIso_(cfg.getUntrackedParameter<double>("trkIso")),
47  chi2Cut_(cfg.getUntrackedParameter<double>("chi2Cut")),
48  nHitCut_(cfg.getUntrackedParameter<int>("nHitCut"))
49 {
51  TFileDirectory trackEffDir = fs->mkdir("QualityOfGlbMu");
52  h_GlbMuNofHitsGlbMu_= trackEffDir.make<TH1D>("# of Hits of GlobalMuon", "# of Hits of GlobalMuon", 100, 0, 100);
53  h_TrkMuNofHitsGlbMu_= trackEffDir.make<TH1D>("# of Hits of TrackerMuon", "# of Hits of TrackerMuon", 100, 0, 100);
54  h_GlbMuChi2_= trackEffDir.make<TH1D>("chi2 of GlobalMuon", "chi2 of GlobalMuon", 100,0,10);
55  h_GlbMuDxy_= trackEffDir.make<TH1D>("Dxy of GlobalMuon", "Dxy of GlobalMuon", 1000,-5.,5.);
56 }
57 
58 /*void GlbMuQualityCutsAnalysis::endJob() {
59  cout << src_.encode() << endl ;
60 
61 }
62 */
65  evt.getByToken(srcToken_, src);
66  int j=0;
67  cout << ">> entries in " << src_ << ": " << src->size() << endl;
68  for(CandidateView::const_iterator i = src->begin(); i != src->end(); ++i) {
69  j++;
70  const Candidate * dau1 = i->daughter(0);
71  const Candidate * dau2 = i->daughter(1);
72  if(dau1 == 0|| dau2 == 0)
74  "one of the two daughter does not exist\n";
75  const Candidate * c1 = dau1->masterClone().get();
76  GenParticleRef mc1;
77  const pat::Muon * mu1 = dynamic_cast<const pat::Muon*>(c1);
78  std::cout << " dimuon mass " << i->mass() << std::endl;
79  std::cout << "dau1.pt() " << dau1->pt() << std::endl;
80  std::cout << "dau2.pt() " << dau2->pt() << std::endl;
81  std::cout << "dau1.isGlobalMuon() " << dau1->isGlobalMuon() << std::endl;
82  std::cout << "dau2.isGlobalMuon() " << dau2->isGlobalMuon()<< std::endl;
83  std::cout << "dau1.isTrackerMuon() " << dau1->isTrackerMuon() << std::endl;
84  std::cout << "dau2.isTrackerlMuon() " << dau2->isTrackerMuon()<< std::endl;
85  std::cout << "dau1.isStandAloneMuon() " << dau1->isStandAloneMuon() << std::endl;
86  std::cout << "dau2.isStandAloneMuon() " << dau2->isStandAloneMuon()<< std::endl;
87  std::cout << "dau1.charge() " << dau1->charge() << std::endl;
88  std::cout << "dau2.charge() " << dau2->charge()<< std::endl;
89  if(mu1 != 0) {
90 
91  // if (mc1.isNonnull()) cout << "GlbMuQualityCutsAnalysis> genParticleRef1 " << mc1->pdgId() << endl;
92  // double trackIso1=mu1->trackIso();
93  // std::cout << " mu1 iso" << trackIso1 << std::endl;
94  } else {
95  const pat::GenericParticle * gp1 = dynamic_cast<const pat::GenericParticle*>(c1);
96  if(gp1 == 0)
98  "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
99 
100  }
101  const Candidate * c2 = dau2->masterClone().get();
102 
103  const pat::Muon * mu2 = dynamic_cast<const pat::Muon*>(c2);
104  if(mu2 != 0) {
105 
106  // double trackIso2=mu2->trackIso();
107  //std::cout << " mu2 iso" << trackIso2 << std::endl;
108  } else {
109  const pat::GenericParticle * gp2 = dynamic_cast<const pat::GenericParticle*>(c2);
110  if(gp2 == 0)
112  "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
113 
114  }
115 
116  int nOfHit_1=0, nOfHit_tk_1=0, nOfHit_2=0, nOfHit_tk_2=0;
117  if (mu1->isGlobalMuon() ) nOfHit_1= mu1->numberOfValidHits();
118  std::cout << "n of hit of GlbMu1: " << nOfHit_1 << std::endl;
119  if (mu1->isTrackerMuon() ) nOfHit_tk_1= mu1->innerTrack()->numberOfValidHits();
120  std::cout << "n of hit of TrkMu1: " << nOfHit_tk_1 << std::endl;
121  if (mu2->isGlobalMuon() ) nOfHit_2= mu2->numberOfValidHits();
122  std::cout << "n of hit of GlbMu2: " << nOfHit_2 << std::endl;
123  if (mu2->isTrackerMuon() ) nOfHit_tk_2= mu2->innerTrack()->numberOfValidHits();
124  std::cout << "n of hit of TrkMu2: " << nOfHit_tk_2 << std::endl;
125  h_GlbMuNofHitsGlbMu_->Fill(nOfHit_1);
126  h_GlbMuNofHitsGlbMu_->Fill(nOfHit_2);
127  h_TrkMuNofHitsGlbMu_->Fill(nOfHit_tk_1);
128  h_TrkMuNofHitsGlbMu_->Fill(nOfHit_tk_2);
129  double nChi2_1=0, nChi2_2=0;
130  if (mu1->isGlobalMuon() ) nChi2_1= mu1->normChi2();
131  std::cout << "chi2 of GlbMu1: " << nChi2_1 << std::endl;
132  if (mu2->isGlobalMuon() ) nChi2_2= mu2->normChi2();
133  std::cout << "chi2 of GlbMu2: " << nChi2_2 << std::endl;
134  h_GlbMuChi2_->Fill(nChi2_1);
135  h_GlbMuChi2_->Fill(nChi2_2);
136  double dxy_1= mu1->dB();
137  double dxy_2= mu2->dB();
138 
139  h_GlbMuDxy_->Fill(dxy_1);
140  h_GlbMuDxy_->Fill(dxy_2);
141  if (mu1->isGlobalMuon() && ( nOfHit_tk_1<nHitCut_)) {
142  std::cout<<"found a GlbMuon with nOfHit " << nOfHit_tk_1 << ", it has eta: " << mu1->eta()<< std::endl;
143  }
144  if ( mu2->isGlobalMuon() && ( nOfHit_tk_2<nHitCut_)) {
145  std::cout<<"found a GlbMuon with nOfHit " << nOfHit_tk_2 << ", it has eta: " << mu2->eta()<< std::endl;
146  }
147  if (mu1->isGlobalMuon() && ( nChi2_1 >chi2Cut_)) {
148  std::cout<<"found a GlbMuon with chi2 " << nChi2_1 << ", it has chi2 of track: " << mu1->innerTrack()->normalizedChi2()<< ", and chi2 of Sta: "<< mu1->outerTrack()->normalizedChi2() << ", eta: "<< mu1->eta()<< ",pt: "<< mu1->pt()<< std::endl;
149  }
150  if (mu2->isGlobalMuon() && ( nChi2_2 >chi2Cut_)) {
151  std::cout<<"found a GlbMuon with chi2 " << nChi2_2 << ", it has chi2 of track: " << mu2->innerTrack()->normalizedChi2()<< ", and chi2 of Sta: "<< mu2->outerTrack()->normalizedChi2() << ", eta: "<<mu2->eta()<< ",pt: "<< mu2->pt()<< std::endl;
152  }
153 
154  }
155 }
156 
157 
158 
160 
value_type const * get() const
Definition: RefToBase.h:212
int i
Definition: DBlmapReader.cc:9
reco::TrackRef innerTrack() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
edm::EDGetTokenT< reco::CandidateView > srcToken_
tuple cfg
Definition: looper.py:259
std::vector< unsigned int > matched_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isTrackerMuon() const
Definition: Muon.h:219
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
bool isGlobalMuon() const
Definition: Muon.h:218
GlbMuQualityCutsAnalysis(const edm::ParameterSet &cfg)
double dB(IpType type) const
reco::TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
Definition: Muon.h:76
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
tuple c2
Definition: counter.py:145
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
virtual bool isStandAloneMuon() const =0
std::vector< unsigned int > unMatched_
int j
Definition: DBlmapReader.cc:9
virtual int charge() const =0
electric charge
T * make(const Args &...args) const
make new ROOT object
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
tuple cout
Definition: gather_cfg.py:121
unsigned int numberOfValidHits() const
numberOfValidHits returns the number of valid hits on the global track.
virtual bool isTrackerMuon() const =0
double normChi2() const
Norm chi2 gives the normalized chi2 of the global track.
Analysis-level muon class.
Definition: Muon.h:49
virtual bool isGlobalMuon() const =0
virtual const CandidateBaseRef & masterClone() const =0