CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/ElectroWeakAnalysis/ZMuMu/plugins/ZMuMu_vtxAnalyzer.cc

Go to the documentation of this file.
00001 /* \class ZMuMu_vtxAnalyzer
00002  * 
00003  * author: Davide Piccolo
00004  *
00005  * ZMuMu Vtx analyzer:
00006  * check muon vtx distributions, 
00007  *
00008  */
00009 
00010 #include "DataFormats/Common/interface/AssociationVector.h"
00011 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00012 #include "DataFormats/Candidate/interface/CandMatchMap.h" 
00013 #include "FWCore/Framework/interface/EDAnalyzer.h"
00014 #include "DataFormats/Candidate/interface/Particle.h"
00015 #include "DataFormats/Candidate/interface/Candidate.h"
00016 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00017 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00018 #include "DataFormats/MuonReco/interface/Muon.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/EventSetup.h"
00022 #include "FWCore/Utilities/interface/InputTag.h"
00023 #include "DataFormats/Candidate/interface/OverlapChecker.h"
00024 #include "DataFormats/Math/interface/deltaR.h"
00025 #include "DataFormats/PatCandidates/interface/Muon.h" 
00026 #include "DataFormats/PatCandidates/interface/GenericParticle.h"
00027 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
00028 #include "DataFormats/Common/interface/AssociationVector.h"
00029 #include "DataFormats/PatCandidates/interface/PATObject.h"
00030 
00031 #include "TH1.h"
00032 #include "TH2.h"
00033 #include "TH3.h"
00034 #include <vector>
00035 using namespace edm;
00036 using namespace std;
00037 using namespace reco;
00038 
00039 class ZMuMu_vtxAnalyzer : public edm::EDAnalyzer {
00040 public:
00041   ZMuMu_vtxAnalyzer(const edm::ParameterSet& pset);
00042 private:
00043   virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
00044   bool check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00045   float getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00046   float getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00047   float getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00048   Particle::LorentzVector getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00049   virtual void endJob();
00050 
00051   edm::InputTag zMuMu_, zMuMuMatchMap_; 
00052   edm::InputTag zMuStandAlone_, zMuStandAloneMatchMap_;
00053   edm::InputTag zMuTrack_, zMuTrackMatchMap_; 
00054   edm::InputTag muons_, muonMatchMap_, muonIso_;
00055   edm::InputTag tracks_, trackIso_;
00056   edm::InputTag genParticles_, primaryVertices_;
00057 
00058   bool bothMuons_;
00059 
00060   double etamax_, ptmin_, massMin_, massMax_, isoMax_;
00061 
00062   reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
00063   OverlapChecker overlap_;
00064 
00065   // general histograms
00066 
00067   // vertex studies
00068   // ... zmumu No cuts
00069   TH1D *h_muon_vz, *h_dimuon_vz, *h_muon_d0signed;
00070   TH1D *h_muon_vz_respectToPV, *h_muon_d0signed_respectToPV;
00071   // ... cynematic cuts zmumu
00072   TH1D *h_zmumuSele_muon_vz, *h_zmumuSele_dimuon_vz, *h_zmumuSele_muon_d0signed;
00073   TH1D *h_zmumuSele_muon_vz_respectToPV, *h_zmumuSele_muon_d0signed_respectToPV;
00074   // ... cynematic cuts zmumuNotIso
00075   TH1D *h_zmumuNotIsoSele_dimuon_vz;
00076   TH1D *h_zmumuNotIsoSele_muonIso_vz, *h_zmumuNotIsoSele_muonIso_d0signed;
00077   TH1D *h_zmumuNotIsoSele_muonIso_vz_respectToPV, *h_zmumuNotIsoSele_muonIso_d0signed_respectToPV;
00078   TH1D *h_zmumuNotIsoSele_muonNotIso_vz, *h_zmumuNotIsoSele_muonNotIso_d0signed;
00079   TH1D *h_zmumuNotIsoSele_muonNotIso_vz_respectToPV, *h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV;
00080   // ... cynematic cuts zmutrack
00081   TH1D *h_zmutrackSele_muon_vz, *h_zmutrackSele_muon_d0signed;
00082   TH1D *h_zmutrackSele_muon_vz_respectToPV, *h_zmutrackSele_muon_d0signed_respectToPV;
00083   TH1D *h_zmutrackSele_track_vz, *h_zmutrackSele_track_d0signed;
00084   TH1D *h_zmutrackSele_track_vz_respectToPV, *h_zmutrackSele_track_d0signed_respectToPV;
00085   // ... cynematic cuts zmusta
00086   TH1D *h_zmustaSele_muon_vz, *h_zmustaSele_muon_d0signed;
00087   TH1D *h_zmustaSele_muon_vz_respectToPV, *h_zmustaSele_muon_d0signed_respectToPV;
00088   TH1D *h_zmustaSele_sta_vz, *h_zmustaSele_sta_d0signed;
00089   TH1D *h_zmustaSele_sta_vz_respectToPV, *h_zmustaSele_sta_d0signed_respectToPV;
00090 
00091 
00092   // global counters
00093 };
00094 
00095 #include "FWCore/ServiceRegistry/interface/Service.h"
00096 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00097 #include "DataFormats/Common/interface/Handle.h"
00098 #include "DataFormats/Candidate/interface/Particle.h"
00099 #include "DataFormats/Candidate/interface/Candidate.h"
00100 #include "DataFormats/Common/interface/ValueMap.h"
00101 #include "DataFormats/Candidate/interface/CandAssociation.h"
00102 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00103 #include "DataFormats/Math/interface/LorentzVector.h"
00104 #include "DataFormats/TrackReco/interface/Track.h"
00105 #include <iostream>
00106 #include <iterator>
00107 #include <cmath>
00108 using namespace std;
00109 using namespace reco;
00110 using namespace edm;
00111 
00112 typedef edm::ValueMap<float> IsolationCollection;
00113 
00114 ZMuMu_vtxAnalyzer::ZMuMu_vtxAnalyzer(const ParameterSet& pset) : 
00115   zMuMu_(pset.getParameter<InputTag>("zMuMu")), 
00116   zMuMuMatchMap_(pset.getParameter<InputTag>("zMuMuMatchMap")), 
00117   zMuStandAlone_(pset.getParameter<InputTag>("zMuStandAlone")), 
00118   zMuStandAloneMatchMap_(pset.getParameter<InputTag>("zMuStandAloneMatchMap")), 
00119   zMuTrack_(pset.getParameter<InputTag>("zMuTrack")), 
00120   zMuTrackMatchMap_(pset.getParameter<InputTag>("zMuTrackMatchMap")), 
00121   muons_(pset.getParameter<InputTag>("muons")), 
00122   tracks_(pset.getParameter<InputTag>("tracks")), 
00123   genParticles_(pset.getParameter<InputTag>( "genParticles" ) ),
00124   primaryVertices_(pset.getParameter<InputTag>( "primaryVertices" ) ),
00125 
00126   bothMuons_(pset.getParameter<bool>("bothMuons")), 
00127 
00128   etamax_(pset.getUntrackedParameter<double>("etamax")),  
00129   ptmin_(pset.getUntrackedParameter<double>("ptmin")), 
00130   massMin_(pset.getUntrackedParameter<double>("zMassMin")), 
00131   massMax_(pset.getUntrackedParameter<double>("zMassMax")), 
00132   isoMax_(pset.getUntrackedParameter<double>("isomax")) { 
00133   Service<TFileService> fs;
00134 
00135   // general histograms
00136 
00137   // vertex histograms
00138   // ... zmumu no Cuts
00139   h_muon_vz = fs->make<TH1D>("muonVz","z vertex of muons",50,-20.,20.);
00140   h_muon_d0signed = fs->make<TH1D>("muonD0signed","d0 vertex of muons",50,-.1,.1);
00141   h_dimuon_vz = fs->make<TH1D>("dimuonVz","z vertex of dimuon",50,-20.,20.);
00142   h_muon_vz_respectToPV = fs->make<TH1D>("muonVz_respectToPV","z vertex of muons respect to PrimaryVertex",50,-.05,.05);
00143   h_muon_d0signed_respectToPV = fs->make<TH1D>("muonD0signed_respectToPV","d0 vertex of muons respect to PrimaryVertex",50,-.05,.05);
00144   // ... zmumu cynematic Cuts
00145   h_zmumuSele_muon_vz = fs->make<TH1D>("zmumuSele_muonVz","z vertex of muons (zmumu sele)",50,-20.,20.);
00146   h_zmumuSele_muon_d0signed = fs->make<TH1D>("zmumuSele_muonD0signed","d0 vertex of muons (zmumu sele)",50,-.1,.1);
00147   h_zmumuSele_dimuon_vz = fs->make<TH1D>("zmumuSele_dimuonVz","z vertex of dimuon (zmumu sele)",50,-20.,20.);
00148   h_zmumuSele_muon_vz_respectToPV = fs->make<TH1D>("zmumuSele_muonVz_respectToPV","z vertex of muons respect to PrimaryVertex (zmumu sele)",50,-.05,.05);
00149   h_zmumuSele_muon_d0signed_respectToPV = fs->make<TH1D>("zmumuSele_muonD0signed_respectToPV","d0 vertex of muons respect to PrimaryVertex (zmumu sele)",50,-.05,.05);
00150   // ... zmumuNotIso cynematic Cuts
00151   h_zmumuNotIsoSele_dimuon_vz = fs->make<TH1D>("zmumuNotIsoSele_dimuonVz","z vertex of dimuon (zmumuNotIso sele)",50,-20.,20.);
00152   h_zmumuNotIsoSele_muonIso_vz = fs->make<TH1D>("zmumuNotIsoSele_muonIsoVz","z vertex of muons (zmumuNotIso sele muon Iso)",50,-20.,20.);
00153   h_zmumuNotIsoSele_muonIso_d0signed = fs->make<TH1D>("zmumuNotIsoSele_muonIsoD0signed","d0 vertex of muons (zmumuNotIso sele muon Iso)",50,-.1,.1);
00154   h_zmumuNotIsoSele_muonIso_vz_respectToPV = fs->make<TH1D>("zmumuNotIsoSele_muonIsoVz_respectToPV","z vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Iso)",50,-.05,.05);
00155   h_zmumuNotIsoSele_muonIso_d0signed_respectToPV = fs->make<TH1D>("zmumuNotIsoSele_muonIsoD0signed_respectToPV","d0 vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Iso)",50,-.05,.05);
00156   h_zmumuNotIsoSele_muonNotIso_vz = fs->make<TH1D>("zmumuNotIsoSele_muonNotIsoVz","z vertex of muons (zmumuNotIso sele muon Not Iso)",50,-20.,20.);
00157   h_zmumuNotIsoSele_muonNotIso_d0signed = fs->make<TH1D>("zmumuNotIsoSele_muonNotIsoD0signed","d0 vertex of muons (zmumuNotIso sele muon Not Iso)",50,-.1,.1);
00158   h_zmumuNotIsoSele_muonNotIso_vz_respectToPV = fs->make<TH1D>("zmumuNotIsoSele_muonNotIsoVz_respectToPV","z vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Not Iso)",50,-.05,.05);
00159   h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV = fs->make<TH1D>("zmumuNotIsoSele_muonNotIsoD0signed_respectToPV","d0 vertex of muons respect to PrimaryVertex (zmumuNotIso sele muon Not Iso)",50,-.05,.05);
00160   // ... zmutrack cynematic Cuts
00161   h_zmutrackSele_muon_vz = fs->make<TH1D>("zmutrackSele_muonVz","z vertex of muon (zmutrack sele)",50,-20.,20.);
00162   h_zmutrackSele_muon_d0signed = fs->make<TH1D>("zmutrackSele_muonD0signed","d0 vertex of muon (zmutrack sele)",50,-.1,.1);
00163   h_zmutrackSele_muon_vz_respectToPV = fs->make<TH1D>("zmutrackSele_muonVz_respectToPV","z vertex of muon respect to PV (zmutrack sele)",50,-.05,.05);
00164   h_zmutrackSele_muon_d0signed_respectToPV = fs->make<TH1D>("zmutrackSele_muonD0signed_respectToPV","d0 vertex of muon respect to PV (zmutrack sele)",50,-.1,.1);
00165   h_zmutrackSele_track_vz = fs->make<TH1D>("zmutrackSele_trackVz","z vertex of track (zmutrack sele)",50,-20.,20.);
00166   h_zmutrackSele_track_d0signed = fs->make<TH1D>("zmutrackSele_trackD0signed","d0 vertex of track (zmutrack sele)",50,-.1,.1);
00167   h_zmutrackSele_track_vz_respectToPV = fs->make<TH1D>("zmutrackSele_trackVz_respectToPV","z vertex of track respect to PV (zmutrack sele)",50,-.05,.05);
00168   h_zmutrackSele_track_d0signed_respectToPV = fs->make<TH1D>("zmutrackSele_trackD0signed_respectToPV","d0 vertex of track respect to PV (zmutrack sele)",50,-.1,.1);
00169   // ... zmusta cynematic Cuts
00170   h_zmustaSele_muon_vz = fs->make<TH1D>("zmustaSele_muonVz","z vertex of muon (zmusta sele)",50,-20.,20.);
00171   h_zmustaSele_muon_d0signed = fs->make<TH1D>("zmustaSele_muonD0signed","d0 vertex of muon (zmusta sele)",50,-.1,.1);
00172   h_zmustaSele_muon_vz_respectToPV = fs->make<TH1D>("zmustaSele_muonVz_respectToPV","z vertex of muon respect to PV (zmusta sele)",50,-.05,.05);
00173   h_zmustaSele_muon_d0signed_respectToPV = fs->make<TH1D>("zmustaSele_muonD0signed_respectToPV","d0 vertex of muon respect to PV (zmusta sele)",50,-.1,.1);
00174   h_zmustaSele_sta_vz = fs->make<TH1D>("zmustaSele_staVz","z vertex of sta (zmusta sele)",50,-20.,20.);
00175   h_zmustaSele_sta_d0signed = fs->make<TH1D>("zmustaSele_staD0signed","d0 vertex of sta (zmusta sele)",50,-.1,.1);
00176   h_zmustaSele_sta_vz_respectToPV = fs->make<TH1D>("zmustaSele_staVz_respectToPV","z vertex of sta respect to PV (zmusta sele)",50,-.05,.05);
00177   h_zmustaSele_sta_d0signed_respectToPV = fs->make<TH1D>("zmustaSele_staD0signed_respectToPV","d0 vertex of sta respect to PV (zmusta sele)",50,-.1,.1);
00178 
00179 }
00180 
00181 void ZMuMu_vtxAnalyzer::analyze(const Event& event, const EventSetup& setup) {
00182   Handle<CandidateView> zMuMu;  
00183   Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global 
00184   Handle<CandidateView> zMuStandAlone;  
00185   Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
00186   Handle<CandidateView> zMuTrack;  
00187   Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
00188   Handle<CandidateView> muons; //Collection of Muons
00189   Handle<CandidateView> tracks; //Collection of Tracks
00190 
00191   Handle<GenParticleCollection> genParticles;  // Collection of Generatd Particles
00192   Handle<reco::VertexCollection> primaryVertices;  // Collection of primary Vertices
00193   
00194   event.getByLabel(zMuMu_, zMuMu); 
00195   event.getByLabel(zMuStandAlone_, zMuStandAlone); 
00196   event.getByLabel(zMuTrack_, zMuTrack); 
00197   event.getByLabel(genParticles_, genParticles);
00198   event.getByLabel(primaryVertices_, primaryVertices);
00199   event.getByLabel(muons_, muons); 
00200   event.getByLabel(tracks_, tracks); 
00201 
00202   /*  
00203   cout << "*********  zMuMu         size : " << zMuMu->size() << endl;
00204   cout << "*********  zMuStandAlone size : " << zMuStandAlone->size() << endl;
00205   cout << "*********  zMuTrack      size : " << zMuTrack->size() << endl;
00206   cout << "*********  muons         size : " << muons->size() << endl;      
00207   cout << "*********  tracks        size : " << tracks->size() << endl;
00208   cout << "*********  vertices      size : " << primaryVertices->size() << endl;
00209   */
00210 
00211   //      std::cout<<"Run-> "<<event.id().run()<<std::endl;
00212   //      std::cout<<"Event-> "<<event.id().event()<<std::endl; 
00213 
00214   bool zMuMu_found = false;
00215 
00216   // loop on ZMuMu
00217   if (zMuMu->size() > 0 ) {
00218     event.getByLabel(zMuMuMatchMap_, zMuMuMatchMap); 
00219     for(unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
00220       const Candidate & zMuMuCand = (*zMuMu)[i]; //the candidate
00221       CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
00222 
00223       const Candidate * lep0 = zMuMuCand.daughter( 0 );
00224       const Candidate * lep1 = zMuMuCand.daughter( 1 );
00225       const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
00226       double trkiso0 = muonDau0.trackIso();
00227       const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
00228       double trkiso1 = muonDau1.trackIso();
00229 
00230       // vertex
00231       h_muon_vz->Fill(muonDau0.vz());
00232       h_muon_vz->Fill(muonDau1.vz());
00233       h_dimuon_vz->Fill((muonDau0.vz()+muonDau1.vz())/2.);
00234  
00235       TrackRef mu0TrkRef = muonDau0.track();
00236       float d0signed_mu0 = (*mu0TrkRef).dxy();
00237       float d0signed_mu0_respectToPV= (*mu0TrkRef).dxy( primaryVertices->begin()->position() );
00238       float vz_mu0_respectToPV= (*mu0TrkRef).dz( primaryVertices->begin()->position() );
00239       
00240       TrackRef mu1TrkRef = muonDau1.track();
00241       float d0signed_mu1 = (*mu1TrkRef).dxy();
00242       float d0signed_mu1_respectToPV= (*mu1TrkRef).dxy( primaryVertices->begin()->position() );
00243       float vz_mu1_respectToPV= (*mu1TrkRef).dz( primaryVertices->begin()->position() );
00244       h_muon_d0signed->Fill(d0signed_mu0);
00245       h_muon_d0signed->Fill(d0signed_mu1);
00246       h_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
00247       h_muon_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
00248       h_muon_vz_respectToPV->Fill(vz_mu0_respectToPV);
00249       h_muon_vz_respectToPV->Fill(vz_mu1_respectToPV);
00250 
00251       // eta , pt distributions
00252       double pt0 = zMuMuCand.daughter(0)->pt();
00253       double pt1 = zMuMuCand.daughter(1)->pt();
00254       double eta0 = zMuMuCand.daughter(0)->eta();
00255       double eta1 = zMuMuCand.daughter(1)->eta();
00256       double mass = zMuMuCand.mass();
00257 
00258       // HLT match
00259       const pat::TriggerObjectStandAloneCollection mu0HLTMatches = 
00260         muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
00261       const pat::TriggerObjectStandAloneCollection mu1HLTMatches = 
00262         muonDau1.triggerObjectMatchesByPath( "HLT_Mu9" );
00263 
00264       bool trig0found = false;
00265       bool trig1found = false;
00266       if( mu0HLTMatches.size()>0 )
00267         trig0found = true;
00268       if( mu1HLTMatches.size()>0 )
00269         trig1found = true;
00270 
00271       // cynematical selection
00272       if ((trig0found || trig1found) && pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass > massMin_) {
00273         if (trkiso0<isoMax_ && trkiso1<isoMax_) {  // zmumu both isolated
00274           h_zmumuSele_muon_vz->Fill(muonDau0.vz());
00275           h_zmumuSele_muon_vz->Fill(muonDau1.vz());
00276           h_zmumuSele_dimuon_vz->Fill((muonDau0.vz()+muonDau1.vz())/2.);
00277           h_zmumuSele_muon_d0signed->Fill(d0signed_mu0);
00278           h_zmumuSele_muon_d0signed->Fill(d0signed_mu1);
00279           h_zmumuSele_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
00280           h_zmumuSele_muon_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
00281           h_zmumuSele_muon_vz_respectToPV->Fill(vz_mu0_respectToPV);
00282           h_zmumuSele_muon_vz_respectToPV->Fill(vz_mu1_respectToPV);
00283         }
00284         if (trkiso0>=isoMax_ && trkiso1<isoMax_) {  // zmumu just muon1 isolated
00285           h_zmumuNotIsoSele_muonNotIso_vz->Fill(muonDau0.vz());
00286           h_zmumuNotIsoSele_muonIso_vz->Fill(muonDau1.vz());
00287           h_zmumuNotIsoSele_dimuon_vz->Fill((muonDau0.vz()+muonDau1.vz())/2.);
00288           h_zmumuNotIsoSele_muonNotIso_d0signed->Fill(d0signed_mu0);
00289           h_zmumuNotIsoSele_muonIso_d0signed->Fill(d0signed_mu1);
00290           h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
00291           h_zmumuNotIsoSele_muonIso_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
00292           h_zmumuNotIsoSele_muonNotIso_vz_respectToPV->Fill(vz_mu0_respectToPV);
00293           h_zmumuNotIsoSele_muonIso_vz_respectToPV->Fill(vz_mu1_respectToPV);     
00294         }
00295         if (trkiso0<isoMax_ && trkiso1>=isoMax_) {  // zmumu just muon0 isolated
00296           h_zmumuNotIsoSele_muonNotIso_vz->Fill(muonDau1.vz());
00297           h_zmumuNotIsoSele_muonIso_vz->Fill(muonDau0.vz());
00298           h_zmumuNotIsoSele_dimuon_vz->Fill((muonDau1.vz()+muonDau1.vz())/2.);
00299           h_zmumuNotIsoSele_muonNotIso_d0signed->Fill(d0signed_mu1);
00300           h_zmumuNotIsoSele_muonIso_d0signed->Fill(d0signed_mu0);
00301           h_zmumuNotIsoSele_muonNotIso_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV);
00302           h_zmumuNotIsoSele_muonIso_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV);
00303           h_zmumuNotIsoSele_muonNotIso_vz_respectToPV->Fill(vz_mu1_respectToPV);
00304           h_zmumuNotIsoSele_muonIso_vz_respectToPV->Fill(vz_mu0_respectToPV);     
00305         }
00306       }
00307     }  // end loop on ZMuMu cand
00308   }    // end if ZMuMu size > 0
00309 
00310   // loop on ZMuSta
00311   bool zMuSta_found = false;
00312   if (!zMuMu_found && zMuStandAlone->size() > 0 ) {
00313     event.getByLabel(zMuStandAloneMatchMap_, zMuStandAloneMatchMap); 
00314     for(unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
00315       const Candidate & zMuStandAloneCand = (*zMuStandAlone)[i]; //the candidate
00316       CandidateBaseRef zMuStandAloneCandRef = zMuStandAlone->refAt(i);
00317       GenParticleRef zMuStandAloneMatch = (*zMuStandAloneMatchMap)[zMuStandAloneCandRef];
00318 
00319       const Candidate * lep0 = zMuStandAloneCand.daughter( 0 );
00320       const Candidate * lep1 = zMuStandAloneCand.daughter( 1 );
00321       const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
00322       double trkiso0 = muonDau0.trackIso();
00323       const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
00324       double trkiso1 = muonDau1.trackIso();
00325 
00326       // vertex
00327  
00328       TrackRef mu0TrkRef = muonDau0.track();
00329       float d0signed_mu0 = (*mu0TrkRef).dxy();
00330       float d0signed_mu0_respectToPV= (*mu0TrkRef).dxy( primaryVertices->begin()->position() );
00331       float vz_mu0_respectToPV= (*mu0TrkRef).dz( primaryVertices->begin()->position() );
00332       
00333       TrackRef mu1TrkRef = muonDau1.track();
00334       float d0signed_mu1 = (*mu1TrkRef).dxy();
00335       float d0signed_mu1_respectToPV= (*mu1TrkRef).dxy( primaryVertices->begin()->position() );
00336       float vz_mu1_respectToPV= (*mu1TrkRef).dz( primaryVertices->begin()->position() );
00337 
00338       double pt0 = zMuStandAloneCand.daughter(0)->pt();
00339       double pt1 = zMuStandAloneCand.daughter(1)->pt();
00340       double eta0 = zMuStandAloneCand.daughter(0)->eta();
00341       double eta1 = zMuStandAloneCand.daughter(1)->eta();
00342       double mass = zMuStandAloneCand.mass();
00343 
00344       // HLT match 
00345       const pat::TriggerObjectStandAloneCollection mu0HLTMatches = 
00346         muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
00347       const pat::TriggerObjectStandAloneCollection mu1HLTMatches = 
00348         muonDau1.triggerObjectMatchesByPath( "HLT_Mu9" );
00349 
00350       bool trig0found = false;
00351       bool trig1found = false;
00352       if( mu0HLTMatches.size()>0 )
00353         trig0found = true;
00354       if( mu1HLTMatches.size()>0 )
00355         trig1found = true;
00356 
00357       // check the global muon ... trigger is required just on global muon
00358       bool trigfound = false;
00359       if (muonDau0.isGlobalMuon()) trigfound = trig0found;
00360       if (muonDau1.isGlobalMuon()) trigfound = trig1found;
00361 
00362       // cynematical selection
00363       if (trigfound && pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && trkiso0<isoMax_ && trkiso1<isoMax_) {
00364         zMuSta_found = true;
00365         h_zmustaSele_muon_vz->Fill(muonDau0.vz(),1.);     // muon vz
00366         h_zmustaSele_sta_vz->Fill(muonDau1.vz(),1.);    // sta vz
00367         h_zmustaSele_muon_d0signed->Fill(d0signed_mu0,1.);   // muon d0
00368         h_zmustaSele_sta_d0signed->Fill(d0signed_mu1,1.);  // sta d0
00369         h_zmustaSele_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV,1.); // muon d0 respect PV
00370         h_zmustaSele_sta_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV,1.); // sta d0 respect PV
00371         h_zmustaSele_muon_vz_respectToPV->Fill(vz_mu0_respectToPV,1.);             // muon vz respect PV
00372         h_zmustaSele_sta_vz_respectToPV->Fill(vz_mu1_respectToPV,1.);             // sta vz respect PV
00373       }
00374       
00375     }  // end loop on ZMuStandAlone cand
00376   }    // end if ZMuStandAlone size > 0
00377 
00378 
00379   // loop on ZMuTrack
00380   if (!zMuMu_found && !zMuSta_found && zMuTrack->size() > 0 ) {
00381     event.getByLabel(zMuTrackMatchMap_, zMuTrackMatchMap); 
00382     for(unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
00383       const Candidate & zMuTrackCand = (*zMuTrack)[i]; //the candidate
00384       CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(i);
00385       const Candidate * lep0 = zMuTrackCand.daughter( 0 );
00386       const Candidate * lep1 = zMuTrackCand.daughter( 1 );
00387       const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
00388       double trkiso0 = muonDau0.trackIso();
00389       const pat::GenericParticle & trackDau1 = dynamic_cast<const pat::GenericParticle &>(*lep1->masterClone());
00390       double trkiso1 = trackDau1.trackIso();
00391 
00392       // vertex
00393  
00394       TrackRef mu0TrkRef = muonDau0.track();
00395       float d0signed_mu0 = (*mu0TrkRef).dxy();
00396       float d0signed_mu0_respectToPV= (*mu0TrkRef).dxy( primaryVertices->begin()->position() );
00397       float vz_mu0_respectToPV= (*mu0TrkRef).dz( primaryVertices->begin()->position() );
00398       
00399       TrackRef mu1TrkRef = trackDau1.track();
00400       float d0signed_mu1 = (*mu1TrkRef).dxy();
00401       float d0signed_mu1_respectToPV= (*mu1TrkRef).dxy( primaryVertices->begin()->position() );
00402       float vz_mu1_respectToPV= (*mu1TrkRef).dz( primaryVertices->begin()->position() );
00403 
00404       // cynematical parameters 
00405 
00406       double pt0 = zMuTrackCand.daughter(0)->pt();
00407       double pt1 = zMuTrackCand.daughter(1)->pt();
00408       double eta0 = zMuTrackCand.daughter(0)->eta();
00409       double eta1 = zMuTrackCand.daughter(1)->eta();
00410       double mass = zMuTrackCand.mass();
00411 
00412       // HLT match (check just dau0 the global)
00413        const pat::TriggerObjectStandAloneCollection mu0HLTMatches = 
00414         muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
00415 
00416       bool trig0found = false;
00417       if( mu0HLTMatches.size()>0 )
00418         trig0found = true;
00419 
00420       // cynematical selection
00421       if (trig0found && pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && trkiso0<isoMax_ && trkiso1<isoMax_) {
00422         h_zmutrackSele_muon_vz->Fill(muonDau0.vz(),1.);     // muon vz
00423         h_zmutrackSele_track_vz->Fill(trackDau1.vz(),1.);    // track vz
00424         h_zmutrackSele_muon_d0signed->Fill(d0signed_mu0,1.);   // muon d0
00425         h_zmutrackSele_track_d0signed->Fill(d0signed_mu1,1.);  // track d0
00426         h_zmutrackSele_muon_d0signed_respectToPV->Fill(d0signed_mu0_respectToPV,1.); // muon d0 respect PV
00427         h_zmutrackSele_track_d0signed_respectToPV->Fill(d0signed_mu1_respectToPV,1.); // track d0 respect PV
00428         h_zmutrackSele_muon_vz_respectToPV->Fill(vz_mu0_respectToPV,1.);             // muon vz respect PV
00429         h_zmutrackSele_track_vz_respectToPV->Fill(vz_mu1_respectToPV,1.);                 // track vz respect PV
00430       }
00431       
00432     }  // end loop on ZMuTrack cand
00433   }    // end if ZMuTrack size > 0
00434 
00435 }       // end analyze
00436 
00437 bool ZMuMu_vtxAnalyzer::check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00438 {
00439   int partId0 = dauGen0->pdgId();
00440   int partId1 = dauGen1->pdgId();
00441   int partId2 = dauGen2->pdgId();
00442   bool muplusFound=false;
00443   bool muminusFound=false;
00444   bool ZFound=false;
00445   if (partId0==13 || partId1==13 || partId2==13) muminusFound=true;
00446   if (partId0==-13 || partId1==-13 || partId2==-13) muplusFound=true;
00447   if (partId0==23 || partId1==23 || partId2==23) ZFound=true;
00448   return muplusFound*muminusFound*ZFound;   
00449 }
00450  
00451 float ZMuMu_vtxAnalyzer::getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00452 {
00453   int partId0 = dauGen0->pdgId();
00454   int partId1 = dauGen1->pdgId();
00455   int partId2 = dauGen2->pdgId();
00456   float ptpart=0.;
00457   if (partId0 == ipart) {
00458     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00459       const Candidate * dauMuGen = dauGen0->daughter(k);
00460       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00461         ptpart = dauMuGen->pt();
00462       }
00463     }
00464   }
00465   if (partId1 == ipart) {
00466     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00467       const Candidate * dauMuGen = dauGen1->daughter(k);
00468       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00469         ptpart = dauMuGen->pt();
00470       }
00471     }
00472   }
00473   if (partId2 == ipart) {
00474     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00475       const Candidate * dauMuGen = dauGen2->daughter(k);
00476       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00477         ptpart = dauMuGen->pt();
00478       }
00479     }
00480   }
00481   return ptpart;
00482 }
00483  
00484 float ZMuMu_vtxAnalyzer::getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00485 {
00486   int partId0 = dauGen0->pdgId();
00487   int partId1 = dauGen1->pdgId();
00488   int partId2 = dauGen2->pdgId();
00489   float etapart=0.;
00490   if (partId0 == ipart) {
00491     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00492       const Candidate * dauMuGen = dauGen0->daughter(k);
00493       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00494         etapart = dauMuGen->eta();
00495       }
00496     }
00497   }
00498   if (partId1 == ipart) {
00499     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00500       const Candidate * dauMuGen = dauGen1->daughter(k);
00501       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00502         etapart = dauMuGen->eta();
00503       }
00504     }
00505   }
00506   if (partId2 == ipart) {
00507     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00508       const Candidate * dauMuGen = dauGen2->daughter(k);
00509       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00510         etapart = dauMuGen->eta();
00511       }
00512     }
00513   }
00514   return etapart;
00515 }
00516 
00517 float ZMuMu_vtxAnalyzer::getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00518 {
00519   int partId0 = dauGen0->pdgId();
00520   int partId1 = dauGen1->pdgId();
00521   int partId2 = dauGen2->pdgId();
00522   float phipart=0.;
00523   if (partId0 == ipart) {
00524     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00525       const Candidate * dauMuGen = dauGen0->daughter(k);
00526       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00527         phipart = dauMuGen->phi();
00528       }
00529     }
00530   }
00531   if (partId1 == ipart) {
00532     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00533       const Candidate * dauMuGen = dauGen1->daughter(k);
00534       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00535         phipart = dauMuGen->phi();
00536       }
00537     }
00538   }
00539   if (partId2 == ipart) {
00540     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00541       const Candidate * dauMuGen = dauGen2->daughter(k);
00542       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00543         phipart = dauMuGen->phi();
00544       }
00545     }
00546   }
00547   return phipart;
00548 }
00549 
00550 Particle::LorentzVector ZMuMu_vtxAnalyzer::getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00551 {
00552   int partId0 = dauGen0->pdgId();
00553   int partId1 = dauGen1->pdgId();
00554   int partId2 = dauGen2->pdgId();
00555   Particle::LorentzVector p4part(0.,0.,0.,0.);
00556   if (partId0 == ipart) {
00557     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00558       const Candidate * dauMuGen = dauGen0->daughter(k);
00559       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00560         p4part = dauMuGen->p4();
00561       }
00562     }
00563   }
00564   if (partId1 == ipart) {
00565     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00566       const Candidate * dauMuGen = dauGen1->daughter(k);
00567       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00568         p4part = dauMuGen->p4();
00569       }
00570     }
00571   }
00572   if (partId2 == ipart) {
00573     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00574       const Candidate * dauMuGen = dauGen2->daughter(k);
00575       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00576         p4part = dauMuGen->p4();
00577       }
00578     }
00579   }
00580   return p4part;
00581 }
00582  
00583 
00584 
00585 void ZMuMu_vtxAnalyzer::endJob() {
00586   
00587 }
00588   
00589 #include "FWCore/Framework/interface/MakerMacros.h"
00590 
00591 DEFINE_FWK_MODULE(ZMuMu_vtxAnalyzer);
00592