CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/ElectroWeakAnalysis/ZMuMu/plugins/GlbMuQualityCutsAnalysis.cc

Go to the documentation of this file.
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   //  virtual void endJob();
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 /*void GlbMuQualityCutsAnalysis::endJob() {
00057   cout << src_.encode() << endl ;
00058 
00059 }
00060 */
00061 void GlbMuQualityCutsAnalysis::analyze(const edm::Event& evt, const edm::EventSetup&) {
00062   Handle<CandidateView> src;
00063   evt.getByLabel(src_, src);
00064   int j=0;
00065   cout << ">> entries in " << src_ << ": " << src->size() << endl;
00066   for(CandidateView::const_iterator i = src->begin(); i != src->end(); ++i) {
00067     j++;
00068     const Candidate * dau1 = i->daughter(0);
00069     const Candidate * dau2 = i->daughter(1);
00070     if(dau1 == 0|| dau2 == 0) 
00071       throw Exception(errors::InvalidReference) <<
00072         "one of the two daughter does not exist\n";
00073     const Candidate * c1 = dau1->masterClone().get();
00074     GenParticleRef mc1;
00075     const pat::Muon * mu1 = dynamic_cast<const pat::Muon*>(c1);
00076   std::cout << " dimuon mass  " << i->mass() << std::endl;
00077      std::cout << "dau1.pt() " << dau1->pt() << std::endl;
00078     std::cout << "dau2.pt() " << dau2->pt() << std::endl;
00079     std::cout << "dau1.isGlobalMuon() " << dau1->isGlobalMuon() << std::endl;
00080     std::cout << "dau2.isGlobalMuon() " << dau2->isGlobalMuon()<< std::endl;
00081     std::cout << "dau1.isTrackerMuon() " << dau1->isTrackerMuon() << std::endl;
00082     std::cout << "dau2.isTrackerlMuon() " << dau2->isTrackerMuon()<< std::endl;
00083     std::cout << "dau1.isStandAloneMuon() " << dau1->isStandAloneMuon() << std::endl;
00084     std::cout << "dau2.isStandAloneMuon() " << dau2->isStandAloneMuon()<< std::endl;
00085     std::cout << "dau1.charge() " << dau1->charge() << std::endl;
00086     std::cout << "dau2.charge() " << dau2->charge()<< std::endl; 
00087   if(mu1 != 0) {
00088  
00089       //     if (mc1.isNonnull()) cout << "GlbMuQualityCutsAnalysis> genParticleRef1 " << mc1->pdgId() << endl;
00090       // double trackIso1=mu1->trackIso();
00091       // std::cout << " mu1 iso" << trackIso1 << std::endl;
00092     } else {
00093       const pat::GenericParticle * gp1 = dynamic_cast<const pat::GenericParticle*>(c1);
00094       if(gp1 == 0) 
00095         throw Exception(errors::InvalidReference) <<
00096           "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
00097  
00098     }
00099     const Candidate * c2 = dau2->masterClone().get();
00100  
00101     const pat::Muon * mu2 = dynamic_cast<const pat::Muon*>(c2);
00102     if(mu2 != 0) {
00103  
00104       // double trackIso2=mu2->trackIso();
00105      //std::cout << " mu2 iso" << trackIso2 << std::endl;
00106     } else {
00107       const pat::GenericParticle * gp2 = dynamic_cast<const pat::GenericParticle*>(c2);
00108       if(gp2 == 0) 
00109         throw Exception(errors::InvalidReference) <<
00110           "first of two daughter is neither a pat::Muon not pat::GenericParticle\n";
00111  
00112     }
00113 
00114     int nOfHit_1=0, nOfHit_tk_1=0, nOfHit_2=0, nOfHit_tk_2=0;
00115     if (mu1->isGlobalMuon() )   nOfHit_1= mu1->numberOfValidHits();
00116     std::cout << "n of hit of GlbMu1: " << nOfHit_1 << std::endl;
00117     if (mu1->isTrackerMuon() ) nOfHit_tk_1= mu1->innerTrack()->numberOfValidHits();
00118     std::cout << "n of hit of TrkMu1: " << nOfHit_tk_1 << std::endl;
00119     if (mu2->isGlobalMuon() ) nOfHit_2= mu2->numberOfValidHits();
00120     std::cout << "n of hit of GlbMu2: " << nOfHit_2 << std::endl;    
00121     if (mu2->isTrackerMuon() ) nOfHit_tk_2= mu2->innerTrack()->numberOfValidHits();
00122     std::cout << "n of hit of TrkMu2: " << nOfHit_tk_2 << std::endl;
00123     h_GlbMuNofHitsGlbMu_->Fill(nOfHit_1);
00124     h_GlbMuNofHitsGlbMu_->Fill(nOfHit_2);
00125     h_TrkMuNofHitsGlbMu_->Fill(nOfHit_tk_1);
00126     h_TrkMuNofHitsGlbMu_->Fill(nOfHit_tk_2);
00127     double nChi2_1=0, nChi2_2=0; 
00128     if (mu1->isGlobalMuon() ) nChi2_1= mu1->normChi2();
00129     std::cout << "chi2 of GlbMu1: " << nChi2_1 << std::endl;
00130     if (mu2->isGlobalMuon() )  nChi2_2= mu2->normChi2();
00131     std::cout << "chi2 of GlbMu2: " << nChi2_2 << std::endl;
00132     h_GlbMuChi2_->Fill(nChi2_1);
00133     h_GlbMuChi2_->Fill(nChi2_2);
00134     double dxy_1= mu1->dB(); 
00135     double dxy_2= mu2->dB(); 
00136  
00137     h_GlbMuDxy_->Fill(dxy_1); 
00138     h_GlbMuDxy_->Fill(dxy_2); 
00139     if (mu1->isGlobalMuon() && ( nOfHit_tk_1<nHitCut_)) { 
00140       std::cout<<"found a GlbMuon with nOfHit " << nOfHit_tk_1 << ", it has eta: " << mu1->eta()<< std::endl;
00141   }
00142     if ( mu2->isGlobalMuon() && ( nOfHit_tk_2<nHitCut_)) { 
00143       std::cout<<"found a GlbMuon with nOfHit " << nOfHit_tk_2 << ", it has eta: " << mu2->eta()<< std::endl;
00144   }
00145     if (mu1->isGlobalMuon() && ( nChi2_1 >chi2Cut_)) {
00146       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;
00147     }
00148     if (mu2->isGlobalMuon() && ( nChi2_2 >chi2Cut_)) {
00149       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;
00150     }
00151 
00152   }
00153 }
00154 
00155 
00156 
00157 #include "FWCore/Framework/interface/MakerMacros.h"
00158 
00159 DEFINE_FWK_MODULE(GlbMuQualityCutsAnalysis);