CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/ElectroWeakAnalysis/ZMuMu/plugins/ZMuMu_efficiencyAnalyzer.cc

Go to the documentation of this file.
00001 /* \class ZMuMu_efficieyAnalyzer
00002  * 
00003  * author: Davide Piccolo
00004  *
00005  * ZMuMu efficiency analyzer:
00006  * check muon reco efficiencies from MC truth, 
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_efficiencyAnalyzer : public edm::EDAnalyzer {
00040 public:
00041   ZMuMu_efficiencyAnalyzer(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   // binning of entries array (at moment defined by hand and not in cfg file)
00063   unsigned int etaBins;
00064   unsigned int ptBins;
00065   double  etaRange[7];
00066   double  ptRange[5];
00067 
00068   reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
00069   OverlapChecker overlap_;
00070 
00071   // general histograms
00072   TH1D *h_zmm_mass, *h_zmm2HLT_mass; 
00073   TH1D *h_zmm1HLTplus_mass, *h_zmmNotIsoplus_mass, *h_zmsplus_mass, *h_zmtplus_mass;
00074   TH1D *h_zmm1HLTminus_mass, *h_zmmNotIsominus_mass, *h_zmsminus_mass, *h_zmtminus_mass;
00075 
00076   // global counters
00077   int nGlobalMuonsMatched_passed;    // total number of global muons MC matched and passing cuts (and triggered)
00078 
00079   vector<TH1D *>  hmumu2HLTplus_eta, hmumu1HLTplus_eta, hmustaplus_eta, hmutrackplus_eta, hmumuNotIsoplus_eta;
00080   vector<TH1D *>  hmumu2HLTplus_pt, hmumu1HLTplus_pt, hmustaplus_pt, hmutrackplus_pt, hmumuNotIsoplus_pt;
00081   vector<TH1D *>  hmumu2HLTminus_eta, hmumu1HLTminus_eta, hmustaminus_eta, hmutrackminus_eta, hmumuNotIsominus_eta;
00082   vector<TH1D *>  hmumu2HLTminus_pt, hmumu1HLTminus_pt, hmustaminus_pt, hmutrackminus_pt, hmumuNotIsominus_pt;
00083 };
00084 
00085 #include "FWCore/ServiceRegistry/interface/Service.h"
00086 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00087 #include "DataFormats/Common/interface/Handle.h"
00088 #include "DataFormats/Candidate/interface/Particle.h"
00089 #include "DataFormats/Candidate/interface/Candidate.h"
00090 #include "DataFormats/Common/interface/ValueMap.h"
00091 #include "DataFormats/Candidate/interface/CandAssociation.h"
00092 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00093 #include "DataFormats/Math/interface/LorentzVector.h"
00094 #include "DataFormats/TrackReco/interface/Track.h"
00095 #include <iostream>
00096 #include <iterator>
00097 #include <cmath>
00098 using namespace std;
00099 using namespace reco;
00100 using namespace edm;
00101 
00102 
00103 typedef edm::ValueMap<float> IsolationCollection;
00104 
00105 ZMuMu_efficiencyAnalyzer::ZMuMu_efficiencyAnalyzer(const ParameterSet& pset) : 
00106   zMuMu_(pset.getParameter<InputTag>("zMuMu")), 
00107   zMuMuMatchMap_(pset.getParameter<InputTag>("zMuMuMatchMap")), 
00108   zMuStandAlone_(pset.getParameter<InputTag>("zMuStandAlone")), 
00109   zMuStandAloneMatchMap_(pset.getParameter<InputTag>("zMuStandAloneMatchMap")), 
00110   zMuTrack_(pset.getParameter<InputTag>("zMuTrack")), 
00111   zMuTrackMatchMap_(pset.getParameter<InputTag>("zMuTrackMatchMap")), 
00112   muons_(pset.getParameter<InputTag>("muons")), 
00113   tracks_(pset.getParameter<InputTag>("tracks")), 
00114   genParticles_(pset.getParameter<InputTag>( "genParticles" ) ),
00115   primaryVertices_(pset.getParameter<InputTag>( "primaryVertices" ) ),
00116 
00117   bothMuons_(pset.getParameter<bool>("bothMuons")), 
00118 
00119   etamax_(pset.getUntrackedParameter<double>("etamax")),  
00120   ptmin_(pset.getUntrackedParameter<double>("ptmin")), 
00121   massMin_(pset.getUntrackedParameter<double>("zMassMin")), 
00122   massMax_(pset.getUntrackedParameter<double>("zMassMax")), 
00123   isoMax_(pset.getUntrackedParameter<double>("isomax")) { 
00124   Service<TFileService> fs;
00125 
00126   // general histograms
00127   h_zmm_mass  = fs->make<TH1D>("zmm_mass","zmumu mass",100,0.,200.);
00128   h_zmm2HLT_mass  = fs->make<TH1D>("zmm2HLT_mass","zmumu 2HLT mass",100,0.,200.);
00129   h_zmm1HLTplus_mass  = fs->make<TH1D>("zmm1HLTplus_mass","zmumu 1HLT plus mass",100,0.,200.);
00130   h_zmmNotIsoplus_mass  = fs->make<TH1D>("zmmNotIsoplus_mass","zmumu a least One Not Iso plus mass",100,0.,200.);
00131   h_zmsplus_mass  = fs->make<TH1D>("zmsplus_mass","zmusta plus mass",100,0.,200.);
00132   h_zmtplus_mass  = fs->make<TH1D>("zmtplus_mass","zmutrack plus mass",100,0.,200.);
00133   h_zmm1HLTminus_mass  = fs->make<TH1D>("zmm1HLTminus_mass","zmumu 1HLT minus mass",100,0.,200.);
00134   h_zmmNotIsominus_mass  = fs->make<TH1D>("zmmNotIsominus_mass","zmumu a least One Not Iso minus mass",100,0.,200.);
00135   h_zmsminus_mass  = fs->make<TH1D>("zmsminus_mass","zmusta minus mass",100,0.,200.);
00136   h_zmtminus_mass  = fs->make<TH1D>("zmtminus_mass","zmutrack minus mass",100,0.,200.);
00137 
00138   cout << "primo" << endl;
00139   // creating histograms for each Pt, eta interval
00140 
00141   TFileDirectory etaDirectory = fs->mkdir("etaIntervals");   // in this directory will be saved all the histos of different eta intervals
00142   TFileDirectory ptDirectory = fs->mkdir("ptIntervals");   // in this directory will be saved all the histos of different pt intervals
00143 
00144   // binning of entries array (at moment defined by hand and not in cfg file)
00145   etaBins = 6;
00146   ptBins = 4;
00147   double  etaRangeTmp[7] = {-2.,-1.2,-0.8,0.,0.8,1.2,2.};
00148   double  ptRangeTmp[5] = {20.,40.,60.,80.,100.};
00149   for (unsigned int i=0;i<=etaBins;i++) etaRange[i] = etaRangeTmp[i];
00150   for (unsigned int i=0;i<=ptBins;i++) ptRange[i] = ptRangeTmp[i];
00151 
00152   // eta histograms creation
00153   cout << "eta istograms creation " << endl;
00154 
00155   for (unsigned int i=0;i<etaBins;i++) {
00156     cout << " bin eta plus  " << i << endl;
00157     // muon plus
00158     double range0 = etaRange[i];
00159     double range1= etaRange[i+1];
00160     char ap[30], bp[50];
00161     sprintf(ap,"zmumu2HLTplus_etaRange%d",i);
00162     sprintf(bp,"zmumu2HLT plus mass eta Range %f to %f",range0,range1);
00163     cout << ap << "   " << bp << endl;
00164     hmumu2HLTplus_eta.push_back(etaDirectory.make<TH1D>(ap,bp,200,0.,200.));
00165     sprintf(ap,"zmumu1HLTplus_etaRange%d",i);
00166     sprintf(bp,"zmumu1HLT plus mass eta Range %f to %f",range0,range1);
00167     cout << ap << "   " << bp << endl;
00168     hmumu1HLTplus_eta.push_back(etaDirectory.make<TH1D>(ap,bp,200,0.,200.));
00169     sprintf(ap,"zmustaplus_etaRange%d",i);
00170     sprintf(bp,"zmusta plus mass eta Range %f to %f",range0,range1);
00171     cout << ap << "   " << bp << endl;
00172     hmustaplus_eta.push_back(etaDirectory.make<TH1D>(ap,bp,50,0.,200.));
00173     sprintf(ap,"zmutrackplus_etaRange%d",i);
00174     sprintf(bp,"zmutrack plus mass eta Range %f to %f",range0,range1);
00175     cout << ap << "   " << bp << endl;
00176     hmutrackplus_eta.push_back(etaDirectory.make<TH1D>(ap,bp,100,0.,200.));
00177     sprintf(ap,"zmumuNotIsoplus_etaRange%d",i);
00178     sprintf(bp,"zmumuNotIso plus mass eta Range %f to %f",range0,range1);
00179     cout << ap << "   " << bp << endl;
00180     hmumuNotIsoplus_eta.push_back(etaDirectory.make<TH1D>(ap,bp,100,0.,200.));
00181     // muon minus 
00182     cout << " bin eta minus  " << i << endl;
00183     char am[30], bm[50];
00184     sprintf(am,"zmumu2HLTminus_etaRange%d",i);
00185     sprintf(bm,"zmumu2HLT minus mass eta Range %f to %f",range0,range1);
00186     cout << am << "   " << bm << endl;
00187     hmumu2HLTminus_eta.push_back(etaDirectory.make<TH1D>(am,bm,200,0.,200.));
00188     sprintf(am,"zmumu1HLTminus_etaRange%d",i);
00189     sprintf(bm,"zmumu1HLT minus mass eta Range %f to %f",range0,range1);
00190     cout << am << "   " << bm << endl;
00191     hmumu1HLTminus_eta.push_back(etaDirectory.make<TH1D>(am,bm,200,0.,200.));
00192     sprintf(am,"zmustaminus_etaRange%d",i);
00193     sprintf(bm,"zmusta minus mass eta Range %f to %f",range0,range1);
00194     cout << am << "   " << bm << endl;
00195     hmustaminus_eta.push_back(etaDirectory.make<TH1D>(am,bm,50,0.,200.));
00196     sprintf(am,"zmutrackminus_etaRange%d",i);
00197     sprintf(bm,"zmutrack minus mass eta Range %f to %f",range0,range1);
00198     cout << am << "   " << bm << endl;
00199     hmutrackminus_eta.push_back(etaDirectory.make<TH1D>(am,bm,100,0.,200.));
00200     sprintf(am,"zmumuNotIsominus_etaRange%d",i);
00201     sprintf(bm,"zmumuNotIso minus mass eta Range %f to %f",range0,range1);
00202     cout << am << "   " << bm << endl;
00203     hmumuNotIsominus_eta.push_back(etaDirectory.make<TH1D>(am,bm,100,0.,200.));
00204   } 
00205 
00206   // pt histograms creation
00207   cout << "pt istograms creation " << endl;
00208 
00209   for (unsigned int i=0;i<ptBins;i++) {
00210     double range0 = ptRange[i];
00211     double range1= ptRange[i+1];
00212     // muon plus
00213     cout << " bin pt plus  " << i << endl;
00214     char ap1[30], bp1[50];
00215     sprintf(ap1,"zmumu2HLTplus_ptRange%d",i);
00216     sprintf(bp1,"zmumu2HLT plus mass pt Range %f to %f",range0,range1);
00217     cout << ap1 << "   " << bp1 << endl;
00218     hmumu2HLTplus_pt.push_back(ptDirectory.make<TH1D>(ap1,bp1,200,0.,200.));
00219     sprintf(ap1,"zmumu1HLTplus_ptRange%d",i);
00220     sprintf(bp1,"zmumu1HLT plus mass pt Range %f to %f",range0,range1);
00221     cout << ap1 << "   " << bp1 << endl;
00222     hmumu1HLTplus_pt.push_back(ptDirectory.make<TH1D>(ap1,bp1,200,0.,200.));
00223     sprintf(ap1,"zmustaplus_ptRange%d",i);
00224     sprintf(bp1,"zmusta plus mass pt Range %f to %f",range0,range1);
00225     cout << ap1 << "   " << bp1 << endl;
00226     hmustaplus_pt.push_back(ptDirectory.make<TH1D>(ap1,bp1,50,0.,200.));
00227     sprintf(ap1,"zmutrackplus_ptRange%d",i);
00228     sprintf(bp1,"zmutrack plus mass pt Range %f to %f",range0,range1);
00229     cout << ap1 << "   " << bp1 << endl;
00230     hmutrackplus_pt.push_back(ptDirectory.make<TH1D>(ap1,bp1,100,0.,200.));
00231     sprintf(ap1,"zmumuNotIsoplus_ptRange%d",i);
00232     sprintf(bp1,"zmumuNotIso plus mass pt Range %f to %f",range0,range1);
00233     cout << ap1 << "   " << bp1 << endl;
00234     hmumuNotIsoplus_pt.push_back(ptDirectory.make<TH1D>(ap1,bp1,100,0.,200.));
00235     // muon minus 
00236     cout << " bin pt minus  " << i << endl;
00237     char am1[30], bm1[50];
00238     sprintf(am1,"zmumu2HLTminus_ptRange%d",i);
00239     sprintf(bm1,"zmumu2HLT minus mass pt Range %f to %f",range0,range1);
00240     cout << am1 << "   " << bm1 << endl;
00241     hmumu2HLTminus_pt.push_back(ptDirectory.make<TH1D>(am1,bm1,200,0.,200.));
00242     sprintf(am1,"zmumu1HLTminus_ptRange%d",i);
00243     sprintf(bm1,"zmumu1HLT minus mass pt Range %f to %f",range0,range1);
00244     cout << am1 << "   " << bm1 << endl;
00245     hmumu1HLTminus_pt.push_back(ptDirectory.make<TH1D>(am1,bm1,200,0.,200.));
00246     sprintf(am1,"zmustaminus_ptRange%d",i);
00247     sprintf(bm1,"zmusta minus mass pt Range %f to %f",range0,range1);
00248     cout << am1 << "   " << bm1 << endl;
00249     hmustaminus_pt.push_back(ptDirectory.make<TH1D>(am1,bm1,50,0.,200.));
00250     sprintf(am1,"zmutrackminus_ptRange%d",i);
00251     sprintf(bm1,"zmutrack minus mass pt Range %f to %f",range0,range1);
00252     cout << am1 << "   " << bm1 << endl;
00253     hmutrackminus_pt.push_back(ptDirectory.make<TH1D>(am1,bm1,100,0.,200.));
00254     sprintf(am1,"zmumuNotIsominus_ptRange%d",i);
00255     sprintf(bm1,"zmumuNotIso minus mass pt Range %f to %f",range0,range1);
00256     cout << am1 << "   " << bm1 << endl;
00257     hmumuNotIsominus_pt.push_back(ptDirectory.make<TH1D>(am1,bm1,100,0.,200.));
00258   } 
00259 
00260   // clear global counters
00261   nGlobalMuonsMatched_passed = 0;
00262 }
00263 
00264 void ZMuMu_efficiencyAnalyzer::analyze(const Event& event, const EventSetup& setup) {
00265   Handle<CandidateView> zMuMu;  
00266   Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global 
00267   Handle<CandidateView> zMuStandAlone;  
00268   Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
00269   Handle<CandidateView> zMuTrack;  
00270   Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
00271   Handle<CandidateView> muons; //Collection of Muons
00272   Handle<CandidateView> tracks; //Collection of Tracks
00273 
00274   Handle<GenParticleCollection> genParticles;  // Collection of Generatd Particles
00275   Handle<reco::VertexCollection> primaryVertices;  // Collection of primary Vertices
00276   
00277   event.getByLabel(zMuMu_, zMuMu); 
00278   event.getByLabel(zMuStandAlone_, zMuStandAlone); 
00279   event.getByLabel(zMuTrack_, zMuTrack); 
00280   event.getByLabel(genParticles_, genParticles);
00281   event.getByLabel(primaryVertices_, primaryVertices);
00282   event.getByLabel(muons_, muons); 
00283   event.getByLabel(tracks_, tracks); 
00284 
00285   /*
00286   cout << "*********  zMuMu         size : " << zMuMu->size() << endl;
00287   cout << "*********  zMuStandAlone size : " << zMuStandAlone->size() << endl;
00288   cout << "*********  zMuTrack      size : " << zMuTrack->size() << endl;
00289   cout << "*********  muons         size : " << muons->size() << endl;      
00290   cout << "*********  tracks        size : " << tracks->size() << endl;
00291   cout << "*********  vertices      size : " << primaryVertices->size() << endl;
00292   */
00293 
00294   //      std::cout<<"Run-> "<<event.id().run()<<std::endl;
00295   //      std::cout<<"Event-> "<<event.id().event()<<std::endl; 
00296 
00297 
00298 
00299   bool zMuMu_found = false;
00300   // loop on ZMuMu
00301   if (zMuMu->size() > 0 ) {
00302     for(unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
00303       const Candidate & zMuMuCand = (*zMuMu)[i]; //the candidate
00304       CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
00305 
00306       const Candidate * lep0 = zMuMuCand.daughter( 0 );
00307       const Candidate * lep1 = zMuMuCand.daughter( 1 );
00308       const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
00309       double trkiso0 = muonDau0.trackIso();
00310       const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
00311       double trkiso1 = muonDau1.trackIso();
00312 
00313       // kinemtic variables
00314       double pt0 = zMuMuCand.daughter(0)->pt();
00315       double pt1 = zMuMuCand.daughter(1)->pt();
00316       double eta0 = zMuMuCand.daughter(0)->eta();
00317       double eta1 = zMuMuCand.daughter(1)->eta();
00318       double charge0 = zMuMuCand.daughter(0)->charge();
00319       double charge1 = zMuMuCand.daughter(1)->charge();
00320       double mass = zMuMuCand.mass();
00321 
00322       // HLT match
00323       const pat::TriggerObjectStandAloneCollection mu0HLTMatches = 
00324         muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
00325       const pat::TriggerObjectStandAloneCollection mu1HLTMatches = 
00326         muonDau1.triggerObjectMatchesByPath( "HLT_Mu9" );
00327 
00328       bool trig0found = false;
00329       bool trig1found = false;
00330       if( mu0HLTMatches.size()>0 )
00331         trig0found = true;
00332       if( mu1HLTMatches.size()>0 )
00333         trig1found = true;
00334       
00335       // kinematic selection
00336 
00337       bool checkOppositeCharge = false;
00338       if (charge0 != charge1) checkOppositeCharge = true;
00339       if (pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && mass<massMax_ && checkOppositeCharge) {
00340         if (trig0found || trig1found) { // at least one muon match HLT 
00341           zMuMu_found = true;           // Z found as global-global (so don't check Zms and Zmt)
00342           if (trkiso0 < isoMax_ && trkiso1 < isoMax_) { // both muons are isolated
00343             if (trig0found && trig1found) {  
00344               
00345               // ******************** category zmm 2 HLT ****************
00346               
00347               h_zmm2HLT_mass->Fill(mass);  
00348               h_zmm_mass->Fill(mass);  
00349               
00350               // check the cynematics to fill correct histograms
00351               
00352               for (unsigned int j=0;j<etaBins;j++) {  // eta Bins loop
00353                 double range0 = etaRange[j];
00354                 double range1= etaRange[j+1];
00355 
00356                 // eta histograms
00357                 
00358                 if (eta0>=range0 && eta0<range1)
00359                   {
00360                     if (charge0<0) hmumu2HLTminus_eta[j]->Fill(mass);  // mu- in bin eta
00361                     if (charge0>0) hmumu2HLTplus_eta[j]->Fill(mass);  // mu+ in bin eta
00362                   }
00363                 if (eta1>=range0 && eta1<range1)
00364                   {
00365                     if (charge1<0) hmumu2HLTminus_eta[j]->Fill(mass);  // mu- in bin eta
00366                     if (charge1>0) hmumu2HLTplus_eta[j]->Fill(mass);  // mu+ in bin eta
00367                   }
00368               } // end loop etaBins
00369               
00370               for (unsigned int j=0;j<ptBins;j++) {  // pt Bins loop
00371                 double range0pt = ptRange[j];
00372                 double range1pt = ptRange[j+1];
00373                 // pt histograms
00374                 if (pt0>=range0pt && pt0<range1pt)
00375                   {
00376                     if (charge0<0) hmumu2HLTminus_pt[j]->Fill(mass);  // mu- in bin eta
00377                     if (charge0>0) hmumu2HLTplus_pt[j]->Fill(mass);  // mu+ in bin eta
00378                   }
00379                 if (pt1>=range0pt && pt1<range1pt)
00380                   {
00381                     if (charge1<0) hmumu2HLTminus_pt[j]->Fill(mass);  // mu- in bin eta
00382                     if (charge1>0) hmumu2HLTplus_pt[j]->Fill(mass);  // mu+ in bin eta
00383                   }
00384               } // end loop  ptBins
00385               
00386             }  // ******************* end category zmm 2 HLT ****************
00387             
00388             if (!trig0found || !trig1found) { 
00389               // ****************** category zmm 1 HLT ****************** 
00390               h_zmm_mass->Fill(mass);  
00391               double eta = 9999;
00392               double pt = 9999;
00393               double charge = 0;
00394               if (trig0found) {
00395                 eta = eta1;       // check  muon not HLT matched
00396                 pt = pt1;
00397                 charge = charge1;
00398               } else {
00399                 eta = eta0;       
00400                 pt =pt0;
00401                 charge = charge0;
00402               }
00403               if (charge<0) h_zmm1HLTminus_mass->Fill(mass);  
00404               if (charge>0) h_zmm1HLTplus_mass->Fill(mass);  
00405 
00406               for (unsigned int j=0;j<etaBins;j++) {  // eta Bins loop
00407                 double range0 = etaRange[j];
00408                 double range1= etaRange[j+1];
00409                 // eta histograms fill the bin of the muon not HLT matched
00410                 if (eta>=range0 && eta<range1) 
00411                   {
00412                     if (charge<0) hmumu1HLTminus_eta[j]->Fill(mass);
00413                     if (charge>0) hmumu1HLTplus_eta[j]->Fill(mass);
00414                   }
00415               } // end loop etaBins
00416               for (unsigned int j=0;j<ptBins;j++) {  // pt Bins loop
00417                 double range0 = ptRange[j];
00418                 double range1= ptRange[j+1];
00419                 // pt histograms
00420                 if (pt>=range0 && pt<range1)
00421                   {
00422                     if (charge<0) hmumu1HLTminus_pt[j]->Fill(mass);
00423                     if (charge>0) hmumu1HLTplus_pt[j]->Fill(mass);
00424                   }
00425               } // end loop ptBins
00426 
00427             } // ****************** end category zmm 1 HLT ***************
00428 
00429           } else {  // one or both muons are not isolated
00430             // *****************  category zmumuNotIso **************** (per ora non studio iso vs eta e pt da capire meglio)
00431 
00432           } // end if both muons isolated
00433           
00434         } // end if at least 1 HLT trigger found
00435       }  // end if kinematic selection 
00436 
00437 
00438     }  // end loop on ZMuMu cand
00439   }    // end if ZMuMu size > 0
00440 
00441   // loop on ZMuSta
00442   bool zMuSta_found = false;
00443   if (!zMuMu_found && zMuStandAlone->size() > 0 ) {
00444     event.getByLabel(zMuStandAloneMatchMap_, zMuStandAloneMatchMap); 
00445     for(unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
00446       const Candidate & zMuStandAloneCand = (*zMuStandAlone)[i]; //the candidate
00447       CandidateBaseRef zMuStandAloneCandRef = zMuStandAlone->refAt(i);
00448       GenParticleRef zMuStandAloneMatch = (*zMuStandAloneMatchMap)[zMuStandAloneCandRef];
00449 
00450       const Candidate * lep0 = zMuStandAloneCand.daughter( 0 );
00451       const Candidate * lep1 = zMuStandAloneCand.daughter( 1 );
00452       const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
00453       double trkiso0 = muonDau0.trackIso();
00454       const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
00455       double trkiso1 = muonDau1.trackIso();
00456       double pt0 = zMuStandAloneCand.daughter(0)->pt();
00457       double pt1 = zMuStandAloneCand.daughter(1)->pt();
00458       double eta0 = zMuStandAloneCand.daughter(0)->eta();
00459       double eta1 = zMuStandAloneCand.daughter(1)->eta();
00460       double charge0 = zMuStandAloneCand.daughter(0)->charge();
00461       double charge1 = zMuStandAloneCand.daughter(1)->charge();
00462       double mass = zMuStandAloneCand.mass();
00463 
00464       // HLT match
00465       const pat::TriggerObjectStandAloneCollection mu0HLTMatches = 
00466         muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
00467       const pat::TriggerObjectStandAloneCollection mu1HLTMatches = 
00468         muonDau1.triggerObjectMatchesByPath( "HLT_Mu9" );
00469 
00470       bool trig0found = false;
00471       bool trig1found = false;
00472       if( mu0HLTMatches.size()>0 )
00473         trig0found = true;
00474       if( mu1HLTMatches.size()>0 )
00475         trig1found = true;
00476 
00477       // check HLT match of Global muon and save eta, pt of second muon (standAlone)
00478       bool trigGlbfound = false;
00479       double pt =999.;
00480       double eta = 999.;
00481       double charge = 0;
00482       if (muonDau0.isGlobalMuon()) {
00483         trigGlbfound = trig0found;
00484         pt = pt1;
00485         eta = eta1;
00486         charge = charge1;
00487       }
00488       if (muonDau1.isGlobalMuon()) {
00489         trigGlbfound = trig1found;
00490         pt = pt0;
00491         eta = eta0;
00492         charge = charge0;
00493       }
00494 
00495       bool checkOppositeCharge = false;
00496       if (charge0 != charge1) checkOppositeCharge = true;
00497 
00498       if (checkOppositeCharge && trigGlbfound && pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && mass<massMax_ && trkiso0<isoMax_ && trkiso1<isoMax_ ) {  // global mu match HLT + kinematic cuts + opposite charge
00499 
00500         if (charge<0) h_zmsminus_mass->Fill(mass);
00501         if (charge>0) h_zmsplus_mass->Fill(mass);
00502 
00503         for (unsigned int j=0;j<etaBins;j++) {  // eta Bins loop
00504           double range0 = etaRange[j];
00505           double range1= etaRange[j+1];
00506           // eta histograms
00507           if (eta>=range0 && eta<range1) {
00508             if (charge<0)  hmustaminus_eta[j]->Fill(mass);
00509             if (charge>0)  hmustaplus_eta[j]->Fill(mass);
00510           }
00511         } // end loop etaBins
00512         for (unsigned int j=0;j<ptBins;j++) {  // pt Bins loop
00513           double range0 = ptRange[j];
00514           double range1= ptRange[j+1];
00515           // pt histograms
00516           if (pt>=range0 && pt<range1) {
00517             if (charge<0)  hmustaminus_pt[j]->Fill(mass);
00518             if (charge>0)  hmustaplus_pt[j]->Fill(mass);
00519           }
00520         } // end loop ptBins
00521         
00522       } // end if trigGlbfound + kinecuts + OppostieCharge
00523     }  // end loop on ZMuStandAlone cand
00524   }    // end if ZMuStandAlone size > 0
00525 
00526 
00527   // loop on ZMuTrack
00528   //  bool zMuTrack_found = false;
00529   if (!zMuMu_found && !zMuSta_found && zMuTrack->size() > 0 ) {
00530     event.getByLabel(zMuTrackMatchMap_, zMuTrackMatchMap); 
00531     for(unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
00532       const Candidate & zMuTrackCand = (*zMuTrack)[i]; //the candidate
00533       CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(i);
00534       const Candidate * lep0 = zMuTrackCand.daughter( 0 );
00535       const Candidate * lep1 = zMuTrackCand.daughter( 1 );
00536       const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
00537       double trkiso0 = muonDau0.trackIso();
00538       const pat::GenericParticle & trackDau1 = dynamic_cast<const pat::GenericParticle &>(*lep1->masterClone());
00539       double trkiso1 = trackDau1.trackIso();
00540       double pt0 = zMuTrackCand.daughter(0)->pt();
00541       double pt1 = zMuTrackCand.daughter(1)->pt();
00542       double eta0 = zMuTrackCand.daughter(0)->eta();
00543       double eta1 = zMuTrackCand.daughter(1)->eta();
00544       double charge0 = zMuTrackCand.daughter(0)->charge();
00545       double charge1 = zMuTrackCand.daughter(1)->charge();
00546       double mass = zMuTrackCand.mass();
00547 
00548       // HLT match (check just dau0 the global)
00549       const pat::TriggerObjectStandAloneCollection mu0HLTMatches = 
00550         muonDau0.triggerObjectMatchesByPath( "HLT_Mu9" );
00551 
00552       bool trig0found = false;
00553       if( mu0HLTMatches.size()>0 )
00554         trig0found = true;
00555 
00556       bool checkOppositeCharge = false;
00557       if (charge0 != charge1) checkOppositeCharge = true;
00558 
00559       if (checkOppositeCharge && trig0found && pt0>ptmin_ && pt1>ptmin_ && abs(eta0)<etamax_ && abs(eta1)<etamax_ && mass>massMin_ && mass<massMax_ && trkiso0<isoMax_ && trkiso1<isoMax_ ) {  // global mu match HLT + kinematic cuts + opposite charge
00560 
00561         if (charge1<0) h_zmtminus_mass->Fill(mass);
00562         if (charge1>0) h_zmtplus_mass->Fill(mass);
00563 
00564         for (unsigned int j=0;j<etaBins;j++) {  // eta Bins loop
00565           double range0 = etaRange[j];
00566           double range1= etaRange[j+1];
00567           // eta histograms
00568           if (eta1>=range0 && eta1<range1) {
00569             if (charge1<0)  hmutrackminus_eta[j]->Fill(mass);  // just check muon1 (mu0 is global by definition)
00570             if (charge1>0)  hmutrackplus_eta[j]->Fill(mass);  // just check muon1 (mu0 is global by definition)
00571           }
00572         } // end loop etaBins
00573         for (unsigned int j=0;j<ptBins;j++) {  // pt Bins loop
00574           double range0 = ptRange[j];
00575           double range1= ptRange[j+1];
00576           // pt histograms
00577           if (pt1>=range0 && pt1<range1) {
00578             if (charge1<0)  hmutrackminus_pt[j]->Fill(mass);  // just check muon1 (mu0 is global by definition)
00579             if (charge1>0)  hmutrackplus_pt[j]->Fill(mass);  // just check muon1 (mu0 is global by definition)
00580           }
00581         } // end loop ptBins
00582         
00583       } // end if trig0found
00584 
00585       
00586     }  // end loop on ZMuTrack cand
00587   }    // end if ZMuTrack size > 0
00588 
00589 }       // end analyze
00590 
00591 bool ZMuMu_efficiencyAnalyzer::check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00592 {
00593   int partId0 = dauGen0->pdgId();
00594   int partId1 = dauGen1->pdgId();
00595   int partId2 = dauGen2->pdgId();
00596   bool muplusFound=false;
00597   bool muminusFound=false;
00598   bool ZFound=false;
00599   if (partId0==13 || partId1==13 || partId2==13) muminusFound=true;
00600   if (partId0==-13 || partId1==-13 || partId2==-13) muplusFound=true;
00601   if (partId0==23 || partId1==23 || partId2==23) ZFound=true;
00602   return muplusFound*muminusFound*ZFound;   
00603 }
00604  
00605 float ZMuMu_efficiencyAnalyzer::getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00606 {
00607   int partId0 = dauGen0->pdgId();
00608   int partId1 = dauGen1->pdgId();
00609   int partId2 = dauGen2->pdgId();
00610   float ptpart=0.;
00611   if (partId0 == ipart) {
00612     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00613       const Candidate * dauMuGen = dauGen0->daughter(k);
00614       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00615         ptpart = dauMuGen->pt();
00616       }
00617     }
00618   }
00619   if (partId1 == ipart) {
00620     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00621       const Candidate * dauMuGen = dauGen1->daughter(k);
00622       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00623         ptpart = dauMuGen->pt();
00624       }
00625     }
00626   }
00627   if (partId2 == ipart) {
00628     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00629       const Candidate * dauMuGen = dauGen2->daughter(k);
00630       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00631         ptpart = dauMuGen->pt();
00632       }
00633     }
00634   }
00635   return ptpart;
00636 }
00637  
00638 float ZMuMu_efficiencyAnalyzer::getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00639 {
00640   int partId0 = dauGen0->pdgId();
00641   int partId1 = dauGen1->pdgId();
00642   int partId2 = dauGen2->pdgId();
00643   float etapart=0.;
00644   if (partId0 == ipart) {
00645     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00646       const Candidate * dauMuGen = dauGen0->daughter(k);
00647       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00648         etapart = dauMuGen->eta();
00649       }
00650     }
00651   }
00652   if (partId1 == ipart) {
00653     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00654       const Candidate * dauMuGen = dauGen1->daughter(k);
00655       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00656         etapart = dauMuGen->eta();
00657       }
00658     }
00659   }
00660   if (partId2 == ipart) {
00661     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00662       const Candidate * dauMuGen = dauGen2->daughter(k);
00663       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00664         etapart = dauMuGen->eta();
00665       }
00666     }
00667   }
00668   return etapart;
00669 }
00670 
00671 float ZMuMu_efficiencyAnalyzer::getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00672 {
00673   int partId0 = dauGen0->pdgId();
00674   int partId1 = dauGen1->pdgId();
00675   int partId2 = dauGen2->pdgId();
00676   float phipart=0.;
00677   if (partId0 == ipart) {
00678     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00679       const Candidate * dauMuGen = dauGen0->daughter(k);
00680       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00681         phipart = dauMuGen->phi();
00682       }
00683     }
00684   }
00685   if (partId1 == ipart) {
00686     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00687       const Candidate * dauMuGen = dauGen1->daughter(k);
00688       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00689         phipart = dauMuGen->phi();
00690       }
00691     }
00692   }
00693   if (partId2 == ipart) {
00694     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00695       const Candidate * dauMuGen = dauGen2->daughter(k);
00696       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00697         phipart = dauMuGen->phi();
00698       }
00699     }
00700   }
00701   return phipart;
00702 }
00703 
00704 Particle::LorentzVector ZMuMu_efficiencyAnalyzer::getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
00705 {
00706   int partId0 = dauGen0->pdgId();
00707   int partId1 = dauGen1->pdgId();
00708   int partId2 = dauGen2->pdgId();
00709   Particle::LorentzVector p4part(0.,0.,0.,0.);
00710   if (partId0 == ipart) {
00711     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
00712       const Candidate * dauMuGen = dauGen0->daughter(k);
00713       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00714         p4part = dauMuGen->p4();
00715       }
00716     }
00717   }
00718   if (partId1 == ipart) {
00719     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
00720       const Candidate * dauMuGen = dauGen1->daughter(k);
00721       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
00722         p4part = dauMuGen->p4();
00723       }
00724     }
00725   }
00726   if (partId2 == ipart) {
00727     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
00728       const Candidate * dauMuGen = dauGen2->daughter(k);
00729       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
00730         p4part = dauMuGen->p4();
00731       }
00732     }
00733   }
00734   return p4part;
00735 }
00736  
00737 
00738 
00739 void ZMuMu_efficiencyAnalyzer::endJob() {
00740   
00741   
00742  
00743 }
00744   
00745 #include "FWCore/Framework/interface/MakerMacros.h"
00746 
00747 DEFINE_FWK_MODULE(ZMuMu_efficiencyAnalyzer);
00748