00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "FWCore/Utilities/interface/InputTag.h"
00003 #include <iostream>
00004 #include "TH1.h"
00005
00006 class GlbMuQualityCutsAnalysis : public edm::EDAnalyzer {
00007 public:
00008 GlbMuQualityCutsAnalysis(const edm::ParameterSet & cfg);
00009 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00010
00011 private:
00012 edm::InputTag src_;
00013 std::vector<unsigned int> matched_, unMatched_;
00014 double ptMin_, massMin_,massMax_, etaMin_, etaMax_, trkIso_, chi2Cut_;
00015 int nHitCut_;
00016 TH1D *h_GlbMuNofHitsGlbMu_, *h_GlbMuChi2_, *h_TrkMuNofHitsGlbMu_, *h_GlbMuDxy_;
00017
00018 };
00019
00020 #include "DataFormats/Candidate/interface/Candidate.h"
00021 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00022 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00023 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
00024 #include "FWCore/Framework/interface/Event.h"
00025 #include "DataFormats/Common/interface/Handle.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include "DataFormats/PatCandidates/interface/Muon.h"
00028 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
00029 using namespace std;
00030 using namespace reco;
00031 using namespace edm;
00032 #include "FWCore/ServiceRegistry/interface/Service.h"
00033 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00034
00035
00036
00037 GlbMuQualityCutsAnalysis::GlbMuQualityCutsAnalysis(const edm::ParameterSet & cfg) :
00038 src_(cfg.getParameter<InputTag>("src")),
00039 ptMin_(cfg.getUntrackedParameter<double>("ptMin")),
00040 massMin_(cfg.getUntrackedParameter<double>("massMin")),
00041 massMax_(cfg.getUntrackedParameter<double>("massMax")),
00042 etaMin_(cfg.getUntrackedParameter<double>("etaMin")),
00043 etaMax_(cfg.getUntrackedParameter<double>("etaMax")),
00044 trkIso_(cfg.getUntrackedParameter<double>("trkIso")),
00045 chi2Cut_(cfg.getUntrackedParameter<double>("chi2Cut")),
00046 nHitCut_(cfg.getUntrackedParameter<int>("nHitCut"))
00047 {
00048 Service<TFileService> fs;
00049 TFileDirectory trackEffDir = fs->mkdir("QualityOfGlbMu");
00050 h_GlbMuNofHitsGlbMu_= trackEffDir.make<TH1D>("# of Hits of GlobalMuon", "# of Hits of GlobalMuon", 100, 0, 100);
00051 h_TrkMuNofHitsGlbMu_= trackEffDir.make<TH1D>("# of Hits of TrackerMuon", "# of Hits of TrackerMuon", 100, 0, 100);
00052 h_GlbMuChi2_= trackEffDir.make<TH1D>("chi2 of GlobalMuon", "chi2 of GlobalMuon", 100,0,10);
00053 h_GlbMuDxy_= trackEffDir.make<TH1D>("Dxy of GlobalMuon", "Dxy of GlobalMuon", 1000,-5.,5.);
00054 }
00055
00056
00057
00058
00059
00060
00061 void GlbMuQualityCutsAnalysis::analyze(const edm::Event& evt, const edm::EventSetup&) {
00062 Handle<CandidateView> src;
00063 evt.getByLabel(src_, src);
00064 double trackIso1=-1;
00065 double trackIso2=-1;
00066 int j=0;
00067 cout << ">> entries in " << src_ << ": " << src->size() << endl;
00068 for(CandidateView::const_iterator i = src->begin(); i != src->end(); ++i) {
00069 j++;
00070 const Candidate * dau1 = i->daughter(0);
00071 const Candidate * dau2 = i->daughter(1);
00072 if(dau1 == 0|| dau2 == 0)
00073 throw Exception(errors::InvalidReference) <<
00074 "one of the two daughter does not exist\n";
00075 const Candidate * c1 = dau1->masterClone().get();
00076 GenParticleRef mc1;
00077 const pat::Muon * mu1 = dynamic_cast<const pat::Muon*>(c1);
00078 std::cout << " dimuon mass " << i->mass() << std::endl;
00079 std::cout << "dau1.pt() " << dau1->pt() << std::endl;
00080 std::cout << "dau2.pt() " << dau2->pt() << std::endl;
00081 std::cout << "dau1.isGlobalMuon() " << dau1->isGlobalMuon() << std::endl;
00082 std::cout << "dau2.isGlobalMuon() " << dau2->isGlobalMuon()<< std::endl;
00083 std::cout << "dau1.isTrackerMuon() " << dau1->isTrackerMuon() << std::endl;
00084 std::cout << "dau2.isTrackerlMuon() " << dau2->isTrackerMuon()<< std::endl;
00085 std::cout << "dau1.isStandAloneMuon() " << dau1->isStandAloneMuon() << std::endl;
00086 std::cout << "dau2.isStandAloneMuon() " << dau2->isStandAloneMuon()<< std::endl;
00087 std::cout << "dau1.charge() " << dau1->charge() << std::endl;
00088 std::cout << "dau2.charge() " << dau2->charge()<< std::endl;
00089 if(mu1 != 0) {
00090
00091
00092 trackIso1=mu1->trackIso();
00093
00094 } else {
00095 const pat::GenericParticle * gp1 = dynamic_cast<const pat::GenericParticle*>(c1);
00096 if(gp1 == 0)
00097 throw Exception(errors::InvalidReference) <<
00098 "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
00099
00100 }
00101 const Candidate * c2 = dau2->masterClone().get();
00102
00103 const pat::Muon * mu2 = dynamic_cast<const pat::Muon*>(c2);
00104 if(mu2 != 0) {
00105
00106 trackIso2=mu2->trackIso();
00107
00108 } else {
00109 const pat::GenericParticle * gp2 = dynamic_cast<const pat::GenericParticle*>(c2);
00110 if(gp2 == 0)
00111 throw Exception(errors::InvalidReference) <<
00112 "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
00113
00114 }
00115
00116 int nOfHit_1=0, nOfHit_tk_1=0, nOfHit_2=0, nOfHit_tk_2=0;
00117 if (mu1->isGlobalMuon() ) nOfHit_1= mu1->numberOfValidHits();
00118 std::cout << "n of hit of GlbMu1: " << nOfHit_1 << std::endl;
00119 if (mu1->isTrackerMuon() ) nOfHit_tk_1= mu1->innerTrack()->numberOfValidHits();
00120 std::cout << "n of hit of TrkMu1: " << nOfHit_tk_1 << std::endl;
00121 if (mu2->isGlobalMuon() ) nOfHit_2= mu2->numberOfValidHits();
00122 std::cout << "n of hit of GlbMu2: " << nOfHit_2 << std::endl;
00123 if (mu2->isTrackerMuon() ) nOfHit_tk_2= mu2->innerTrack()->numberOfValidHits();
00124 std::cout << "n of hit of TrkMu2: " << nOfHit_tk_2 << std::endl;
00125 h_GlbMuNofHitsGlbMu_->Fill(nOfHit_1);
00126 h_GlbMuNofHitsGlbMu_->Fill(nOfHit_2);
00127 h_TrkMuNofHitsGlbMu_->Fill(nOfHit_tk_1);
00128 h_TrkMuNofHitsGlbMu_->Fill(nOfHit_tk_2);
00129 double nChi2_1=0, nChi2_2=0;
00130 if (mu1->isGlobalMuon() ) nChi2_1= mu1->normChi2();
00131 std::cout << "chi2 of GlbMu1: " << nChi2_1 << std::endl;
00132 if (mu2->isGlobalMuon() ) nChi2_2= mu2->normChi2();
00133 std::cout << "chi2 of GlbMu2: " << nChi2_2 << std::endl;
00134 h_GlbMuChi2_->Fill(nChi2_1);
00135 h_GlbMuChi2_->Fill(nChi2_2);
00136 double dxy_1= mu1->dB();
00137 double dxy_2= mu2->dB();
00138
00139 h_GlbMuDxy_->Fill(dxy_1);
00140 h_GlbMuDxy_->Fill(dxy_2);
00141 if (mu1->isGlobalMuon() && ( nOfHit_tk_1<nHitCut_)) {
00142 std::cout<<"found a GlbMuon with nOfHit " << nOfHit_tk_1 << ", it has eta: " << mu1->eta()<< std::endl;
00143 }
00144 if ( mu2->isGlobalMuon() && ( nOfHit_tk_2<nHitCut_)) {
00145 std::cout<<"found a GlbMuon with nOfHit " << nOfHit_tk_2 << ", it has eta: " << mu2->eta()<< std::endl;
00146 }
00147 if (mu1->isGlobalMuon() && ( nChi2_1 >chi2Cut_)) {
00148 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;
00149 }
00150 if (mu2->isGlobalMuon() && ( nChi2_2 >chi2Cut_)) {
00151 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;
00152 }
00153
00154 }
00155 }
00156
00157
00158
00159 #include "FWCore/Framework/interface/MakerMacros.h"
00160
00161 DEFINE_FWK_MODULE(GlbMuQualityCutsAnalysis);