CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 /* \class ZMuMuPerformances
00002  * 
00003  * author: Davide Piccolo
00004  *
00005  * ZMuMu Performances:
00006  * check charge mis-id for standAlone and global muons,
00007  * check standAlne resolution vs track resolution 
00008  *
00009  */
00010 
00011 #include "DataFormats/Common/interface/AssociationVector.h"
00012 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00013 #include "DataFormats/Candidate/interface/CandMatchMap.h" 
00014 #include "FWCore/Framework/interface/EDAnalyzer.h"
00015 #include "DataFormats/Candidate/interface/Particle.h"
00016 #include "DataFormats/Candidate/interface/Candidate.h"
00017 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00018 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00019 #include "DataFormats/MuonReco/interface/Muon.h"
00020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00021 #include "FWCore/Framework/interface/Event.h"
00022 #include "FWCore/Framework/interface/EventSetup.h"
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 #include "DataFormats/Candidate/interface/OverlapChecker.h"
00025 #include "DataFormats/Math/interface/deltaR.h"
00026 #include "TH1.h"
00027 #include "TH2.h"
00028 #include "TH3.h"
00029 #include <vector>
00030 using namespace edm;
00031 using namespace std;
00032 using namespace reco;
00033 
00034 class ZMuMuPerformances : public edm::EDAnalyzer {
00035 public:
00036   ZMuMuPerformances(const edm::ParameterSet& pset);
00037 private:
00038   virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
00039   bool check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00040   float getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00041   float getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00042   float getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00043   Particle::LorentzVector getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2); 
00044   virtual void endJob();
00045 
00046   edm::InputTag zMuMu_, zMuMuMatchMap_; 
00047   edm::InputTag zMuTrack_, zMuTrackMatchMap_; 
00048   edm::InputTag zMuStandAlone_, zMuStandAloneMatchMap_;
00049   edm::InputTag muons_, muonMatchMap_, muonIso_;
00050   edm::InputTag tracks_, trackIso_;
00051   edm::InputTag genParticles_;
00052 
00053   bool noCut_;
00054   double zMassMin_, zMassMax_;
00055   double ptminPlus_, ptmaxPlus_, etaminPlus_, etamaxPlus_;
00056   double ptminMinus_, ptmaxMinus_, etaminMinus_, etamaxMinus_, isomax_;
00057 
00058   double etamax_, ptmin_, massMin_, massMax_, isoMax_;
00059 
00060   reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
00061   OverlapChecker overlap_;
00062 
00063   // general histograms
00064   TH1D *h_n_globalMuon_perEvent, *h_n_staOnlyMuon_perEvent, *h_n_trackerOnlyMuon_perEvent, *h_n_trackerStaOnlyMuon_perEvent;
00065   TH1D *h_n_globalMuon_perEvent_MCmatch, *h_n_staOnlyMuon_perEvent_MCmatch, *h_n_trackerOnlyMuon_perEvent_MCmatch;
00066   TH1D *h_n_trackerStaOnlyMuon_perEvent_MCmatch, *h_n_tracks_perEvent;
00067   TH1D *h_n_zMuMu_perEvent, *h_n_zMuSta_perEvent, *h_n_zMuTrack_perEvent;
00068 
00069   // zMuMu inv mass 
00070   TH1D *h_zMuMuMassSameSign, *h_zMuMuMassSameSign_MCmatch,*h_zMuMuMassOppositeSign; 
00071   // histograms with MC truth
00072   // charge truth
00073   TH1D *h_GlobalMuonChargeTimeGenCharge,*h_TrackerMuonChargeTimeGenCharge; 
00074   // resolution respect to gen particles
00075   TH1D *h_GlobalMuonEtaMinusGenEta,*h_TrackerMuonEtaMinusGenEta,*h_GlobalMuonPtMinusGenPt,*h_TrackerMuonPtMinusGenPt; 
00076   TH1D *h_GlobalMuonStaComponentEtaMinusGenEta, *h_GlobalMuonStaComponentPtMinusGenPt;
00077   TH2D *h_DEtaGlobalGenvsEtaGen, *h_DPtGlobalGenvsPtGen, *h_DEtaGlobalStaComponentGenvsEtaGen,*h_DPtGlobalStaComponentGenvsPtGen; 
00078   TH2D *h_DPtGlobalGenvsEtaGen, *h_DPtGlobalStaComponentGenvsEtaGen; 
00079   // resolution respect to gen particles for ZMuMuTagged events
00080   TH1D *h_GlobalMuonEtaMinusGenEta_ZMuMuTagged;
00081   TH1D *h_GlobalMuonPtMinusGenPt_ZMuMuTagged; 
00082   TH1D *h_GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged, *h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged;
00083   TH2D *h_DEtaGlobalGenvsEtaGen_ZMuMuTagged, *h_DPtGlobalGenvsPtGen_ZMuMuTagged;
00084   TH2D *h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged,*h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged; 
00085   TH2D *h_DPtGlobalGenvsEtaGen_ZMuMuTagged, *h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged; 
00086   TH2D *h_DPtTrackGenvsPtGen_ZMuMuTagged, *h_DPtTrackGenvsEtaGen_ZMuMuTagged;
00087 
00088   // histograms for cynematic of ZMuMutagged muons for STA performances studies
00089   TH1D *h_zMuTrackMass_ZMuMuTagged, *h_etaTrack_ZMuMuTagged, *h_phiTrack_ZMuMuTagged, *h_ptTrack_ZMuMuTagged, *h_DRTrack_ZMuMuTagged;
00090   // histograms for cynematic of ZMuMutagged muons when StandAlone has wrong charge
00091   TH1D *h_zMuTrackMass_wrongStaCharge_ZMuMuTagged, *h_etaTrack_wrongStaCharge_ZMuMuTagged;
00092   TH1D *h_phiTrack_wrongStaCharge_ZMuMuTagged, *h_ptTrack_wrongStaCharge_ZMuMuTagged, *h_DRTrack_wrongStaCharge_ZMuMuTagged;
00093 
00094   // hisograms for performances of Standlone when Sta has correct charge
00095   TH1D *h_zMuStaMass_correctStaCharge_ZMuMuTagged, *h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged;
00096   TH2D *h_ptStaMinusptTrack_vsEtaTracker_correctStaCharge_ZMuMuTagged;
00097   TH2D *h_ptStaMinusptTrack_vsPtTracker_correctStaCharge_ZMuMuTagged;
00098 
00099   // histograms for cynematic of ZMuMutagged muons for TRK performances studies
00100   TH1D *h_zMuStaMass_ZMuMuTagged, *h_etaSta_ZMuMuTagged, *h_phiSta_ZMuMuTagged, *h_ptSta_ZMuMuTagged, *h_DRSta_ZMuMuTagged;
00101   // histograms for cynematic of ZMuMutagged muons when TRK has wrong charge
00102   TH1D *h_zMuStaMass_wrongTrkCharge_ZMuMuTagged, *h_etaSta_wrongTrkCharge_ZMuMuTagged;
00103   TH1D *h_phiSta_wrongTrkCharge_ZMuMuTagged, *h_ptSta_wrongTrkCharge_ZMuMuTagged, *h_DRSta_wrongTrkCharge_ZMuMuTagged;
00104 
00105   // histograms for cynematic of ZMuTracktagged muons with unMatchd StandAlone for STA performances studies
00106   TH1D *h_zMuTrackMass_ZMuTrackTagged, *h_etaTrack_ZMuTrackTagged, *h_phiTrack_ZMuTrackTagged, *h_ptTrack_ZMuTrackTagged, *h_DRTrack_ZMuTrackTagged;
00107   // histograms for cynematic of ZMuTracktagged muons when unMatched StandAlone has wrong charge
00108   TH1D *h_zMuTrackMass_wrongStaCharge_ZMuTrackTagged, *h_etaTrack_wrongStaCharge_ZMuTrackTagged;
00109   TH1D *h_phiTrack_wrongStaCharge_ZMuTrackTagged, *h_ptTrack_wrongStaCharge_ZMuTrackTagged, *h_DRTrack_wrongStaCharge_ZMuTrackTagged;
00110 
00111   // histograms for cynematic of ZMuStatagged muons with unMatchd Track for Track performances studies
00112   TH1D *h_zMuStaMass_ZMuStaTagged, *h_etaSta_ZMuStaTagged, *h_phiSta_ZMuStaTagged, *h_ptSta_ZMuStaTagged;
00113   // histograms for cynematic of ZMuStatagged muons when unMatched Track has wrong charge
00114   TH1D *h_zMuStaMass_wrongTrkCharge_ZMuStaTagged, *h_etaSta_wrongTrkCharge_ZMuStaTagged;
00115   TH1D *h_phiSta_wrongTrkCharge_ZMuStaTagged, *h_ptSta_wrongTrkCharge_ZMuStaTagged;
00116 
00117 
00118   // global counters
00119   int totalNumberOfZfound;          // total number of events with Z found 
00120   int totalNumberOfZpassed;         // total number of Z that pass cynematical cuts at generator level
00121 
00122   int nZMuMuSameSign;               // number of ZMuMu SameSIgn (no Cuts)
00123   int nZMuMuSameSign_mcMatched;     // number of ZMuMu Same Sign (no cuts) MCmatch
00124 
00125   int n_goodTrack_ZMuMutagged;      // total number of tracks selected and tagged to study Sta charge
00126   int n_correctStaCharge_ZMuMutagged;  // total number of tracks selected and tagged with correct charge of Sta
00127   int n_wrongStaCharge_ZMuMutagged;  // total number of tracks selected and tagged with wrong charge of Sta
00128 
00129   int n_goodSta_ZMuMutagged;          // total number of standAlone selected and tagged to study Trk charge
00130   int n_correctTrkCharge_ZMuMutagged;  // total number of standAlone selected and tagged with correct charge of Trk
00131   int n_wrongTrkCharge_ZMuMutagged;  // total number of standAlone selected and tagged with wrong charge of Trk
00132 
00133   int n_goodTrack_ZMuTracktagged;   // number of traks selected and tagged to study Sta charge (for ZMuTrack colllection no ZMuMu found)
00134   int n_correctStaCharge_ZMuTracktagged;  // total number of tracks selected and tagged with correct charge of unMatched Sta
00135   int n_wrongStaCharge_ZMuTracktagged;  // total number of tracks selected and tagged with wrong charge of unMatched Sta
00136   int n_StaNotFound_ZMuTracktagged;  // total number of tracks selected and tagged with no STA found
00137 
00138   int n_goodSta_ZMuStatagged;   // number of sta selected and tagged to study Trk charge (for ZMuSta collection no ZMuMu found)
00139   int n_correctTrkCharge_ZMuStatagged;  // total number of sta selected and tagged with correct charge of unMatched track
00140   int n_wrongTrkCharge_ZMuStatagged;  // total number of sta selected and tagged with wrong charge of unMatched track
00141   int n_TrkNotFound_ZMuStatagged;  // total number of selected selected and tagged with no Trk found
00142 
00143   int n_OneGoodZMuTrack;            // total number with just 1 good ZMuTrack found
00144   int n_MultipleGoodZMuTrack;       // total number with more than 1 good ZMuTrack found
00145   int numberOfMatchedZMuSta_;
00146   int n_ZMuStaTaggedMatched;
00147 };
00148 
00149 #include "FWCore/ServiceRegistry/interface/Service.h"
00150 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00151 #include "DataFormats/Common/interface/Handle.h"
00152 #include "DataFormats/Candidate/interface/Particle.h"
00153 #include "DataFormats/Candidate/interface/Candidate.h"
00154 #include "DataFormats/Common/interface/ValueMap.h"
00155 #include "DataFormats/Candidate/interface/CandAssociation.h"
00156 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00157 #include "DataFormats/Math/interface/LorentzVector.h"
00158 #include "DataFormats/TrackReco/interface/Track.h"
00159 #include <iostream>
00160 #include <iterator>
00161 #include <cmath>
00162 using namespace std;
00163 using namespace reco;
00164 using namespace edm;
00165 
00166 
00167 typedef edm::ValueMap<float> IsolationCollection;
00168 
00169 ZMuMuPerformances::ZMuMuPerformances(const ParameterSet& pset) : 
00170   zMuMu_(pset.getParameter<InputTag>("zMuMu")), 
00171   zMuMuMatchMap_(pset.getParameter<InputTag>("zMuMuMatchMap")), 
00172   zMuTrack_(pset.getParameter<InputTag>("zMuTrack")), 
00173   zMuTrackMatchMap_(pset.getParameter<InputTag>("zMuTrackMatchMap")), 
00174   zMuStandAlone_(pset.getParameter<InputTag>("zMuStandAlone")), 
00175   zMuStandAloneMatchMap_(pset.getParameter<InputTag>("zMuStandAloneMatchMap")), 
00176   muons_(pset.getParameter<InputTag>("muons")), 
00177   muonMatchMap_(pset.getParameter<InputTag>("muonMatchMap")), 
00178   muonIso_(pset.getParameter<InputTag>("muonIso")), 
00179   tracks_(pset.getParameter<InputTag>("tracks")), 
00180   trackIso_(pset.getParameter<InputTag>("trackIso")), 
00181   genParticles_(pset.getParameter<InputTag>( "genParticles" ) ),
00182 
00183   noCut_(pset.getParameter<bool>("noCut")), 
00184 
00185   zMassMin_(pset.getUntrackedParameter<double>("zMassMin")), 
00186   zMassMax_(pset.getUntrackedParameter<double>("zMassMax")), 
00187   ptminPlus_(pset.getUntrackedParameter<double>("ptminPlus")), 
00188   ptmaxPlus_(pset.getUntrackedParameter<double>("ptmaxPlus")), 
00189   etaminPlus_(pset.getUntrackedParameter<double>("etaminPlus")),  
00190   etamaxPlus_(pset.getUntrackedParameter<double>("etamaxPlus")),  
00191   ptminMinus_(pset.getUntrackedParameter<double>("ptminMinus")), 
00192   ptmaxMinus_(pset.getUntrackedParameter<double>("ptmaxMinus")), 
00193   etaminMinus_(pset.getUntrackedParameter<double>("etaminMinus")),  
00194   etamaxMinus_(pset.getUntrackedParameter<double>("etamaxMinus")),  
00195   isomax_(pset.getUntrackedParameter<double>("isomax")) { 
00196   Service<TFileService> fs;
00197 
00198   // cut setting
00199   etamax_ = etamaxPlus_;
00200   ptmin_ = ptminPlus_;
00201   massMin_ = zMassMin_;
00202   massMax_ = zMassMax_;
00203   isoMax_ = isomax_;
00204 
00205   // general histograms
00206   h_n_globalMuon_perEvent = fs->make<TH1D>("n_globalMuon_perEvent","n.of globalMuons per Event",6,-.5,5.5);
00207   h_n_staOnlyMuon_perEvent = fs->make<TH1D>("n_staOnlyMuon_perEvent","n.of standAlone Only Muons per Event",6,-.5,5.5);
00208   h_n_trackerOnlyMuon_perEvent = fs->make<TH1D>("n_trackerOnlyMuon_perEvent","n.of tracker Only Muons per Event",6,-.5,5.5);
00209   h_n_trackerStaOnlyMuon_perEvent = fs->make<TH1D>("n_trackerStaOnlyMuon_perEvent","n.of tracker & StandAlone Only Muons per Event",6,-.5,5.5);
00210   h_n_globalMuon_perEvent_MCmatch = fs->make<TH1D>("n_globalMuon_perEvent_MCmatch","n.of globalMuons per Event (MCmatch)",6,-.5,5.5);
00211   h_n_staOnlyMuon_perEvent_MCmatch = fs->make<TH1D>("n_staOnlyMuon_perEvent_MCmatch","n.of standAlone Only Muons per Event (MCmatch)",6,-.5,5.5);
00212   h_n_trackerOnlyMuon_perEvent_MCmatch = fs->make<TH1D>("n_trackerOnlyMuon_perEvent_MCmatch","n.of tracker Only Muons per Event (MCmatch)",6,-.5,5.5);
00213   h_n_trackerStaOnlyMuon_perEvent_MCmatch = fs->make<TH1D>("n_trackerStaOnlyMuon_perEvent_MCmatch","n.of tracker & StandAlone Only Muons per Event (MCmatch)",6,-.5,5.5);
00214   h_n_tracks_perEvent = fs->make<TH1D>("n_tracks_perEvent","n.of tracks per Event",100,-.5,99.5);
00215   h_n_zMuMu_perEvent = fs->make<TH1D>("n_zMuMu_perEvent","n.of global-global muons per Event",6,-.5,5.5);
00216   h_n_zMuSta_perEvent = fs->make<TH1D>("n_zMuSta_perEvent","n.of global-sta muons per Event",6,-.5,5.5);
00217   h_n_zMuTrack_perEvent = fs->make<TH1D>("n_zMuTrack_perEvent","n.of global-track muons per Event",100,-.5,99.5);
00218 
00219   // zMuMu inv mass 
00220   h_zMuMuMassSameSign = fs->make<TH1D>("zMuMuMassSameSign","inv Mass ZMuMu cand SameSign",100, 0., 200.);
00221   h_zMuMuMassOppositeSign = fs->make<TH1D>("zMuMuMassOppositeSign","inv Mass ZMuMu cand OppositeSign",100, 0., 200.);
00222   h_zMuMuMassSameSign_MCmatch = fs->make<TH1D>("zMuMuMassSameSign_MCmatch","inv Mass ZMuMu cand SameSign (MC match)",100, 0., 200.);
00223 
00224   // histograms for MC truth
00225   // charge truth
00226   h_GlobalMuonChargeTimeGenCharge = fs->make<TH1D>("GlobalMuonChargeTimeGenCharge","charge global mu times charge generated mu",3, -1.5, 1.5);
00227   h_TrackerMuonChargeTimeGenCharge = fs->make<TH1D>("TrackerMuonChargeTimeGenCharge","charge Tracker mu times charge generated mu",3, -1.5, 1.5);
00228   // resolution respect to gen particles
00229   h_GlobalMuonEtaMinusGenEta = fs->make<TH1D>("GlobalMuonEtaMinusGenEta","global mu Eta minus generated mu Eta",100, -.005, .005);
00230   h_GlobalMuonPtMinusGenPt = fs->make<TH1D>("GlobalMuonPtMinusGenPtoverPt","global mu Pt minus generated mu Pt over Pt",100, -.5, .5);
00231   h_GlobalMuonStaComponentEtaMinusGenEta = fs->make<TH1D>("GlobalMuonStaComponentEtaMinusGenEta","global mu Sta cmponent Eta minus generated mu Eta",100, -.5, .5);
00232   h_GlobalMuonStaComponentPtMinusGenPt = fs->make<TH1D>("GlobalMuonStaComponentPtMinusGenPtoerPt","global mu Sta component Pt minus generated mu Pt over Pt",100, -1., 1.);
00233   h_TrackerMuonEtaMinusGenEta = fs->make<TH1D>("TrackerMuonEtaMinusGenEta","Tracker mu Eta minus Eta generated mu",100, -.005, .005);
00234   h_TrackerMuonPtMinusGenPt = fs->make<TH1D>("TrackerMuonPtMinusenPtoverPt","Tracker mu Pt minus Pt generated mu over Pt",100, -.5, .5);
00235 
00236   h_DEtaGlobalGenvsEtaGen = fs->make<TH2D>("h_DEtaGlobalGenvsEtaGen","Eta global - Eta Gen vs Eta gen",50,-2.5,2.5,100,-.005,.005);
00237   h_DEtaGlobalStaComponentGenvsEtaGen = fs->make<TH2D>("h_DEtaGlobalStaComponentGenvsEtaGen","Eta Sta component of a Global - Eta Gen vs Eta gen",50,-2.5,2.5,100,-.5,.5);
00238   h_DPtGlobalGenvsPtGen = fs->make<TH2D>("h_DPtGlobalGenovePtvsPtGen","Pt global - Pt Gen over Pt vs Pt gen",50,0.,100.,100,-.5,.5);
00239   h_DPtGlobalStaComponentGenvsPtGen = fs->make<TH2D>("h_DPtGlobalStaComponentGenoverPtvsPtGen","Pt Sta component of a Global - Pt Gen over Pt vs Pt gen",50,0.,100.,100,-1.,1.);
00240 
00241   // resolution respect to gen particles for ZMuMuTagged events
00242   h_GlobalMuonEtaMinusGenEta_ZMuMuTagged = fs->make<TH1D>("GlobalMuonEtaMinusGenEta_ZMuMuTagged","global mu Eta minus generated mu Eta",100, -.005, .005);
00243   h_GlobalMuonPtMinusGenPt_ZMuMuTagged = fs->make<TH1D>("GlobalMuonPtMinusGenPtoverPt_ZMuMuTagged","global mu Pt minus generated mu Pt over Pt",100, -.5, .5);
00244   h_GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged = fs->make<TH1D>("GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged","global mu Sta cmponent Eta minus generated mu Eta",100, -.5, .5);
00245   h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged = fs->make<TH1D>("GlobalMuonStaComponentPtMinusGenPtoverPt_ZMuMuTagged","global mu Sta component Pt minus generated mu Pt over Pt",100, -1., 1.);
00246   h_DEtaGlobalGenvsEtaGen_ZMuMuTagged = fs->make<TH2D>("h_DEtaGlobalGenvsEtaGen_ZMuMuTagged","Eta global - Eta Gen vs Eta gen",50,-2.5,2.5,100,-.005,.005);
00247   h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged = fs->make<TH2D>("h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged","Eta Sta component of a Global - Eta Gen vs Eta gen",50,-2.5,2.5,100,-.5,.5);
00248   h_DPtGlobalGenvsPtGen_ZMuMuTagged = fs->make<TH2D>("h_DPtGlobalGenOverPtvsPtGen_ZMuMuTagged","Pt global - Pt Gen vs Pt gen over Pt",50,0.,100.,100,-.5,.5);
00249   h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged = fs->make<TH2D>("h_DPtGlobalStaComponentGenoverPtvsPtGen_ZMuMuTagged","Pt Sta component of a Global - Pt Gen over Pt vs Pt gen",50,0.,100.,100,-1.,1.);
00250   h_DPtGlobalGenvsEtaGen_ZMuMuTagged = fs->make<TH2D>("h_DPtGlobalGenOverPtvsEtaGen_ZMuMuTagged","Pt global - Pt Gen over Pt vs Eta gen",50,-2.5,2.5,100,-.5,.5);
00251   h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged = fs->make<TH2D>("h_DPtGlobalStaComponentGenoverPtvsEtaGen_ZMuMuTagged","Pt Sta component of a Global - Pt Gen over Pt vs Eta gen",50,-2.5,2.5,100,-1.,1.);
00252   h_DPtTrackGenvsPtGen_ZMuMuTagged = fs->make<TH2D>("h_DPtTrackGenOverPtvsPtGen_ZMuMuTagged","Pt track - Pt Gen vs Pt gen over Pt",50,0.,100.,100,-.5,.5);
00253   h_DPtTrackGenvsEtaGen_ZMuMuTagged = fs->make<TH2D>("h_DPtTrackGenOverPtvsEtaGen_ZMuMuTagged","Pt track - Pt Gen over Pt vs Eta gen",50,-2.5,2.5,100,-.5,.5);
00254 
00255   // histograms for cynematic of ZMuMutagged muons for Sta performances studies
00256   h_zMuTrackMass_ZMuMuTagged = fs->make<TH1D>("zMuTrackMass_ZMuMuTagged","inv Mass ZMuTrack cand (global-global)",100, 0., 200.);
00257   h_etaTrack_ZMuMuTagged = fs->make<TH1D>("etaTrack_ZMuMuTagged","eta of Track (global-global)",50, -2.5, 2.5);
00258   h_phiTrack_ZMuMuTagged = fs->make<TH1D>("phiTrack_ZMuMuTagged","phi of Track (global-global)",50, -3.1415, 3.1415);
00259   h_ptTrack_ZMuMuTagged = fs->make<TH1D>("ptTrack_ZMuMuTagged","pt of Track (global-global)",100, 0., 100.);
00260   h_DRTrack_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_ZMuMuTagged","DR track-sta (global-global)",100, 0., 5.);
00261 
00262   // histograms for cynematic of ZMuMutagged muons when StandAlone has wrong charge
00263   h_zMuTrackMass_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("zMuTrackMass_wrongStaCharge_ZMuMuTagged","inv Mass ZMuTrack cand (global-global wrongStaCharge)",100, 0., 200.);
00264   h_etaTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("etaTrack_wrongStaCharge_ZMuMuTagged","eta of Track (global-global wrongStaCharge)",50, -2.5, 2.5);
00265   h_phiTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("phiTrack_wrongStaCharge_ZMuMuTagged","phi of Track (global-global wrongStaCharge)",50, -3.1415, 3.1415);
00266   h_ptTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("ptTrack_wrongStaCharge_ZMuMuTagged","pt of Track (global-global wrongStaCharge)",100, 0., 100.);
00267   h_DRTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_wrongStaCharge_ZMuMuTagged","DR track-sta (global-global wrongStaCharge)",100, 0., 5.);
00268 
00269   // hisograms for performances of StandAlone when StandAlone has correct charge
00270   h_zMuStaMass_correctStaCharge_ZMuMuTagged = fs->make<TH1D>("zMuStaMass_correctStaCharge_ZMuMuTagged","inv Mass ZMuSta cand (global-global correctStaCharge)",100, 0., 200.);
00271   h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged = fs->make<TH1D>("ptStaMinusptTrackoverPT_correctStaCharge_ZMuMuTagged","ptSta - ptTrack over Pt (global-global correctStaCharge)",100, -1., 1.);
00272   h_ptStaMinusptTrack_vsPtTracker_correctStaCharge_ZMuMuTagged = fs->make<TH2D>("ptStaMinusptTrackoverPt_vsPtTracker_correctStaCharge_ZMuMuTagged","ptSta - ptTrack over Pt vs ptTrack (global-global correctStaCharge)",100,0.,100.,100, -1., 1.);
00273   h_ptStaMinusptTrack_vsEtaTracker_correctStaCharge_ZMuMuTagged = fs->make<TH2D>("ptStaMinusptTrackoverPt_vsEtaTracker_correctStaCharge_ZMuMuTagged","ptSta - ptTrack over Pt vs etaTrack (global-global correctStaCharge)",100,-2.5, 2.5, 100, -1., 1.);
00274 
00275   // histograms for cynematic of ZMuMutagged muons for TRK performances studies
00276   h_zMuStaMass_ZMuMuTagged = fs->make<TH1D>("zMuStaMass_ZMuMuTagged","inv Mass ZMuSta cand (global-global)",100, 0., 200.);
00277   h_etaSta_ZMuMuTagged = fs->make<TH1D>("etaSta_ZMuMuTagged","eta of Sta (global-global)",50, -2.5, 2.5);
00278   h_phiSta_ZMuMuTagged = fs->make<TH1D>("phiSta_ZMuMuTagged","phi of Sta (global-global)",50, -3.1415, 3.1415);
00279   h_ptSta_ZMuMuTagged = fs->make<TH1D>("ptSta_ZMuMuTagged","pt of Sta (global-global)",100, 0., 100.);
00280   h_DRSta_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_ZMuMuTagged_staSelected","DR track-sta sta selected (global-global)",100, 0., 5.);
00281 
00282   // histograms for cynematic of ZMuMutagged muons when Track has wrong charge
00283   h_zMuStaMass_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("zMuStaMass_wrongTrkCharge_ZMuMuTagged","inv Mass ZMuSta cand (global-global wrongTrkCharge)",100, 0., 200.);
00284   h_etaSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("etaSta_wrongTrkCharge_ZMuMuTagged","eta of Sta (global-global wrongTrkCharge)",50, -2.5, 2.5);
00285   h_phiSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("phiSta_wrongTrkCharge_ZMuMuTagged","phi of Sta (global-global wrongTrkCharge)",50, -3.1415, 3.1415);
00286   h_ptSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("ptSta_wrongTrkCharge_ZMuMuTagged","pt of Sta (global-global wrongTrkCharge)",100, 0., 100.);
00287   h_DRSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_wrongTrkCharge_ZMuMuTagged","DR track-sta (global-global wrongTrkCharge)",100, 0., 5.);
00288 
00289   //
00290   // ****************************************************************************************************
00291   // histograms for cynematic of ZMuTracktagged muons with unMatched StandAlone 
00292   h_zMuTrackMass_ZMuTrackTagged = fs->make<TH1D>("zMuTrackMass_ZMuTrackTagged","inv Mass ZMuTrack cand (global-track)",100, 0., 200.);
00293   h_etaTrack_ZMuTrackTagged = fs->make<TH1D>("etaTrack_ZMuTrackTagged","eta of Track (global-track)",50, -2.5, 2.5);
00294   h_phiTrack_ZMuTrackTagged = fs->make<TH1D>("phiTrack_ZMuTrackTagged","phi of Track (global-track)",50, -3.1415, 3.1415);
00295   h_ptTrack_ZMuTrackTagged = fs->make<TH1D>("ptTrack_ZMuTrackTagged","pt of Track (global-track)",100, 0., 100.);
00296   h_DRTrack_ZMuTrackTagged = fs->make<TH1D>("DRTrackSta_ZMuTrackTagged","DR track-sta (global-track)",100, 0., 5.);
00297 
00298   // histograms for cynematic of ZMuTracktagged muons when unMatched StandAlone has wrong charge
00299   h_zMuTrackMass_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("zMuTrackMass_wrongStaCharge_ZMuTrackTagged","inv Mass ZMuTrack cand (global-track wrongUnMatcehdStaCharge)",100, 0., 200.);
00300   h_etaTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("etaTrack_wrongStaCharge_ZMuTrackTagged","eta of Track (global-track wrongUnMatchedStaCharge)",50, -2.5, 2.5);
00301   h_phiTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("phiTrack_wrongStaCharge_ZMuTrackTagged","phi of Track (global-track wrongUnMatchedStaCharge)",50, -3.1415, 3.1415);
00302   h_ptTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("ptTrack_wrongStaCharge_ZMuTrackTagged","pt of Track (global-track wrongUnMatchedStaCharge)",100, 0., 100.);
00303   h_DRTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("DRTrackSta_wrongStaCharge_ZMuTrackTagged","DR track-sta (global-track wrongUnMatchedStaCharge)",100, 0., 5.);
00304 
00305   // histograms for cynematic of ZMuStatagged muons with unMatched Track 
00306   h_zMuStaMass_ZMuStaTagged = fs->make<TH1D>("zMuStaMass_ZMuStaTagged","inv Mass ZMuSta cand (global-sta)",100, 0., 200.);
00307   h_etaSta_ZMuStaTagged = fs->make<TH1D>("etaSta_ZMuStaTagged","eta of Sta (global-sta)",50, -2.5, 2.5);
00308   h_phiSta_ZMuStaTagged = fs->make<TH1D>("phiSta_ZMuStaTagged","phi of Sta (global-sta)",50, -3.1415, 3.1415);
00309   h_ptSta_ZMuStaTagged = fs->make<TH1D>("ptSta_ZMuStaTagged","pt of Sta (global-sta)",100, 0., 100.);
00310 
00311   // histograms for cynematic of ZMuStatagged muons when unMatched track has wrong charge
00312   h_zMuStaMass_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("zMuStaMass_wrongTrkCharge_ZMuStaTagged","inv Mass ZMuSta cand (global-sta wrongUnMatcehdTrkCharge)",100, 0., 200.);
00313   h_etaSta_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("etaSta_wrongTrkCharge_ZMuStaTagged","eta of Sta (global-sta wrongUnMatchedTrkCharge)",50, -2.5, 2.5);
00314   h_phiSta_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("phiSta_wrongTrkCharge_ZMuStaTagged","phi of Sta (global-sta wrongUnMatchedTrkCharge)",50, -3.1415, 3.1415);
00315   h_ptSta_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("ptSta_wrongTrkCharge_ZMuStaTagged","pt of Sta (global-sta wrongUnMatchedTrkCharge)",100, 0., 100.);
00316 
00317   // clear global counters
00318   totalNumberOfZfound=0;  
00319   totalNumberOfZpassed=0;  
00320   nZMuMuSameSign_mcMatched =  0;
00321   nZMuMuSameSign = 0;
00322   n_goodTrack_ZMuMutagged = 0;
00323   n_correctStaCharge_ZMuMutagged = 0;
00324   n_wrongStaCharge_ZMuMutagged = 0;
00325   n_goodSta_ZMuMutagged = 0;
00326   n_correctTrkCharge_ZMuMutagged = 0;
00327   n_wrongTrkCharge_ZMuMutagged = 0;
00328   n_goodTrack_ZMuTracktagged = 0;
00329   n_correctStaCharge_ZMuTracktagged = 0;
00330   n_wrongStaCharge_ZMuTracktagged = 0;
00331   n_StaNotFound_ZMuTracktagged=0;
00332 
00333   n_goodSta_ZMuStatagged = 0;
00334   n_correctTrkCharge_ZMuStatagged = 0;
00335   n_wrongTrkCharge_ZMuStatagged = 0;
00336   n_TrkNotFound_ZMuStatagged=0;
00337 
00338   n_OneGoodZMuTrack=0;
00339   n_MultipleGoodZMuTrack=0;
00340   numberOfMatchedZMuSta_=0;
00341   n_ZMuStaTaggedMatched=0; 
00342 }
00343 
00344 void ZMuMuPerformances::analyze(const Event& event, const EventSetup& setup) {
00345   Handle<CandidateView> zMuMu;  
00346   Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global (can be used also for same sign Zmumu)
00347   Handle<CandidateView> zMuTrack;  
00348   Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
00349   Handle<CandidateView> zMuStandAlone; 
00350   Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
00351   Handle<CandidateView> muons; //Collection of Muons
00352   Handle<GenParticleMatch> muonMatchMap; 
00353   Handle<IsolationCollection> muonIso; 
00354   Handle<CandidateView> tracks; //Collection of Tracks
00355   Handle<IsolationCollection> trackIso; 
00356   Handle<GenParticleCollection> genParticles;  // Collection of Generatd Particles
00357   
00358   event.getByLabel(zMuMu_, zMuMu); 
00359   event.getByLabel(zMuTrack_, zMuTrack); 
00360   event.getByLabel(zMuStandAlone_, zMuStandAlone); 
00361   event.getByLabel(muons_, muons); 
00362   event.getByLabel(muonMatchMap_, muonMatchMap); 
00363   event.getByLabel(tracks_, tracks); 
00364   event.getByLabel(genParticles_, genParticles);
00365 
00366   /*  
00367   cout << "*********  zMuMu         size : " << zMuMu->size() << endl;
00368   cout << "*********  zMuMuSameSign size : " << zMuMuSameSign->size() << endl;
00369   cout << "*********  zMuStandAlone size : " << zMuStandAlone->size() << endl;
00370   cout << "*********  zMuTrack      size : " << zMuTrack->size() << endl;
00371   cout << "*********  muons         size : " << muons->size()<< endl;
00372   cout << "*********  standAlone    size : " << standAlone->size()<< endl;
00373   cout << "*********  tracks        size : " << tracks->size()<< endl;
00374   cout << "*********  generated     size : " << genParticles->size()<< endl;
00375   cout << "***************************************************" << endl;
00376   */
00377  
00378   int n_globalMuon_perEvent=0;
00379   int n_staOnlyMuon_perEvent=0;
00380   int n_trackerOnlyMuon_perEvent=0;
00381   int n_trackerStaOnlyMuon_perEvent=0;
00382   int n_globalMuon_perEvent_MCmatch=0;
00383   int n_staOnlyMuon_perEvent_MCmatch=0;
00384   int n_trackerOnlyMuon_perEvent_MCmatch=0;
00385   int n_trackerStaOnlyMuon_perEvent_MCmatch=0;
00386 
00387   for(unsigned int j = 0; j < muons->size() ; ++j) {
00388     CandidateBaseRef muCandRef = muons->refAt(j); 
00389     const Candidate & muCand = (*muons)[j]; //the candidate
00390     const reco::Muon & muon = dynamic_cast<const reco::Muon &>(muCand);
00391     reco::TrackRef innerTrackRef = muon.track();
00392     reco::TrackRef outerTrackRef = muon.standAloneMuon();
00393     TrackRef muStaComponentRef = muCand.get<TrackRef,reco::StandAloneMuonTag>();  // standalone part of muon
00394     TrackRef muTrkComponentRef = muCand.get<TrackRef>();  // track part of muon
00395     GenParticleRef muonMatch = (*muonMatchMap)[muCandRef]; 
00396     if (muCandRef->isGlobalMuon()==1) n_globalMuon_perEvent++;
00397     if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==0 && muCandRef->isStandAloneMuon()==1) n_staOnlyMuon_perEvent++;
00398     if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==0) n_trackerOnlyMuon_perEvent++;
00399     if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==1) n_trackerStaOnlyMuon_perEvent++;
00400 
00401     if (muonMatch.isNonnull()) {
00402       if (muCandRef->isGlobalMuon()==1) n_globalMuon_perEvent_MCmatch++;
00403       if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==0 && muCandRef->isStandAloneMuon()==1) n_staOnlyMuon_perEvent_MCmatch++;
00404       if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==0) n_trackerOnlyMuon_perEvent_MCmatch++;
00405       if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==1) n_trackerStaOnlyMuon_perEvent_MCmatch++;
00406       double productCharge = muCandRef->charge() * muonMatch->charge();
00407       if (muCandRef->isGlobalMuon()==1) {
00408         h_GlobalMuonChargeTimeGenCharge->Fill(productCharge);
00409         h_GlobalMuonEtaMinusGenEta->Fill(muCandRef->eta() - muonMatch->eta());
00410         h_GlobalMuonPtMinusGenPt->Fill((muCandRef->pt() - muonMatch->pt())/muonMatch->pt());
00411         h_GlobalMuonStaComponentEtaMinusGenEta->Fill(muStaComponentRef->eta() - muonMatch->eta());
00412         h_GlobalMuonStaComponentPtMinusGenPt->Fill((muStaComponentRef->pt() - muonMatch->pt())/muonMatch->pt());
00413         h_DEtaGlobalGenvsEtaGen->Fill(muonMatch->eta(),muCandRef->eta() - muonMatch->eta());
00414         h_DPtGlobalGenvsPtGen->Fill(muonMatch->pt(),(muCandRef->pt() - muonMatch->pt())/muonMatch->pt());
00415         h_DEtaGlobalStaComponentGenvsEtaGen->Fill(muonMatch->eta(),muStaComponentRef->eta() - muonMatch->eta());
00416         h_DPtGlobalStaComponentGenvsPtGen->Fill(muonMatch->pt(),(muStaComponentRef->pt() - muonMatch->pt())/muonMatch->pt());
00417        }
00418       if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1) { 
00419         h_TrackerMuonChargeTimeGenCharge->Fill(productCharge);
00420         h_TrackerMuonEtaMinusGenEta->Fill(muCandRef->eta() - muonMatch->eta());
00421         h_TrackerMuonPtMinusGenPt->Fill((muCandRef->pt() - muonMatch->pt())/muonMatch->pt());
00422       }
00423     }
00424   }
00425   h_n_globalMuon_perEvent->Fill(n_globalMuon_perEvent);
00426   h_n_staOnlyMuon_perEvent->Fill(n_staOnlyMuon_perEvent);
00427   h_n_trackerOnlyMuon_perEvent->Fill(n_trackerOnlyMuon_perEvent);
00428   h_n_trackerStaOnlyMuon_perEvent->Fill(n_trackerStaOnlyMuon_perEvent);
00429   h_n_globalMuon_perEvent_MCmatch->Fill(n_globalMuon_perEvent_MCmatch);
00430   h_n_staOnlyMuon_perEvent_MCmatch->Fill(n_staOnlyMuon_perEvent_MCmatch);
00431   h_n_trackerOnlyMuon_perEvent_MCmatch->Fill(n_trackerOnlyMuon_perEvent_MCmatch);
00432   h_n_trackerStaOnlyMuon_perEvent_MCmatch->Fill(n_trackerStaOnlyMuon_perEvent_MCmatch);
00433   h_n_tracks_perEvent->Fill(tracks->size());
00434 
00435   h_n_zMuMu_perEvent->Fill(zMuMu->size());
00436   h_n_zMuSta_perEvent->Fill(zMuStandAlone->size());
00437   h_n_zMuTrack_perEvent->Fill(zMuTrack->size());
00438             
00439   //      std::cout<<"Run-> "<<event.id().run()<<std::endl;
00440   //      std::cout<<"Event-> "<<event.id().event()<<std::endl; 
00441 
00442 
00443   // loop on ZMuMu
00444   if (zMuMu->size() > 0 ) {
00445     event.getByLabel(zMuMuMatchMap_, zMuMuMatchMap); 
00446     event.getByLabel(muonIso_, muonIso); 
00447     event.getByLabel(muonMatchMap_, muonMatchMap); 
00448     float muGenplus_pt = 0, muGenminus_pt = 0, muGenplus_eta = 100, muGenminus_eta = 100;
00449     for(unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
00450       const Candidate & zMuMuCand = (*zMuMu)[i]; //the candidate
00451       CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
00452       GenParticleRef zMuMuMatch = (*zMuMuMatchMap)[zMuMuCandRef];
00453       bool isMCMatched = false;
00454       if(zMuMuMatch.isNonnull()) {
00455         isMCMatched = true;   // ZMuMu matched
00456         if(zMuMuMatch->pdgId() == 23 && zMuMuMatch->status()==3 && zMuMuMatch->numberOfDaughters() == 3) {  
00457                                              // Z0 decays in mu+ mu-, the 3rd daughter is the same Z0
00458           const Candidate * dauGen0 = zMuMuMatch->daughter(0);
00459           const Candidate * dauGen1 = zMuMuMatch->daughter(1);
00460           const Candidate * dauGen2 = zMuMuMatch->daughter(2);
00461           if (check_ifZmumu(dauGen0, dauGen1, dauGen2)) {         // Z0 in mu+ mu-
00462             muGenplus_pt = getParticlePt(-13,dauGen0,dauGen1,dauGen2);
00463             muGenminus_pt = getParticlePt(13,dauGen0,dauGen1,dauGen2);
00464             muGenplus_eta = getParticleEta(-13,dauGen0,dauGen1,dauGen2);
00465             muGenminus_eta = getParticleEta(13,dauGen0,dauGen1,dauGen2);
00466             Particle::LorentzVector pZ(0, 0, 0, 0);
00467             Particle::LorentzVector muplusp4 = getParticleP4(-13,dauGen0,dauGen1,dauGen2);
00468             Particle::LorentzVector muminusp4 = getParticleP4(13,dauGen0,dauGen1,dauGen2);
00469             pZ = muplusp4 + muminusp4;
00470           }  // en if is Z
00471         }  // end if is Z->mumu
00472 
00473       }
00474 
00475       TrackRef as1 = zMuMuCand.daughter(0)->get<TrackRef,reco::StandAloneMuonTag>();  // standalone part of ZMuMu cand0
00476       TrackRef as2 = zMuMuCand.daughter(1)->get<TrackRef,reco::StandAloneMuonTag>();  // standalone part of ZMuMu cand1
00477       TrackRef a1 = zMuMuCand.daughter(0)->get<TrackRef,reco::CombinedMuonTag>();  // global part of ZMuMu cand0
00478       TrackRef a2 = zMuMuCand.daughter(1)->get<TrackRef,reco::CombinedMuonTag>();  // global part of ZMuMu cand1
00479       TrackRef at1 = zMuMuCand.daughter(0)->get<TrackRef>();  // tracker part of ZMuMu cand0
00480       TrackRef at2 = zMuMuCand.daughter(1)->get<TrackRef>();  // tracker part of ZMuMu cand1
00481 
00482       math::XYZTLorentzVector ps1(as1->px(),as1->py(),as1->pz(),as1->p());
00483       math::XYZTLorentzVector ps2(as2->px(),as2->py(),as2->pz(),as2->p());
00484       math::XYZTLorentzVector pg1(a1->px(),a1->py(),a1->pz(),a1->p());
00485       math::XYZTLorentzVector pg2(a2->px(),a2->py(),a2->pz(),a2->p());
00486       math::XYZTLorentzVector ptrk1(at1->px(),at1->py(),at1->pz(),at1->p());
00487       math::XYZTLorentzVector ptrk2(at2->px(),at2->py(),at2->pz(),at2->p());
00488 
00489       //      double mass2global = (pg1+pg2).mass();         // inv. Mass done with the two global muons (is th same like m)
00490       double massGlobalSta = (pg1+ps2).mass();       // inv. mass done with the global daughter(0) and the Sta part of Daughter(1)
00491       double massStaGlobal = (ps1+pg2).mass();       // inv. mass done with the global daughter(1) and the Sta part of Daughter(0)
00492       //      double mass2Tracker = (ptrk1+ptrk2).mass();    // inv. mass done with the two tracker compnents
00493       double massGlobalTracker = (pg1+ptrk2).mass(); // inv. mass done with the global daughter(0) and the tracker part of Daughter(1)
00494       double massTrackerGlobal = (ptrk1+pg2).mass(); // inv. mass done with the global daughter(1) and the tracker part of Daughter(0)
00495       double etaGlobal1 = a1->eta();
00496       double etaGlobal2 = a2->eta();
00497       double etaSta1 = as1->eta();
00498       double etaSta2 = as2->eta();
00499       double etaTracker1 = at1->eta();
00500       double etaTracker2 = at2->eta();
00501       //      double phiGlobal1 = a1->phi();
00502       //      double phiGlobal2 = a2->phi();
00503       double phiSta1 = as1->phi();
00504       double phiSta2 = as2->phi();
00505       double phiTracker1 = at1->phi();
00506       double phiTracker2 = at2->phi();
00507       double ptGlobal1 = a1->pt();
00508       double ptGlobal2 = a2->pt();
00509       double ptSta1 = as1->pt();
00510       double ptSta2 = as2->pt();
00511       double ptTracker1 = at1->pt();
00512       double ptTracker2 = at2->pt();
00513       double chargeGlobal1 = a1->charge();
00514       double chargeGlobal2 = a2->charge();
00515       double chargeSta1 = as1->charge();
00516       double chargeSta2 = as2->charge();
00517       double chargeTracker1 = at1->charge();
00518       double chargeTracker2 = at2->charge();
00519       double DR1 = deltaR(etaSta1, phiSta1, etaTracker1, phiTracker1);
00520       double DR2 = deltaR(etaSta2, phiSta2, etaTracker2, phiTracker2);
00521 
00522       if (chargeGlobal1 == chargeGlobal2) {
00523         nZMuMuSameSign++;
00524         h_zMuMuMassSameSign->Fill(zMuMuCand.mass());
00525         if (isMCMatched) {
00526           nZMuMuSameSign_mcMatched++;
00527           h_zMuMuMassSameSign_MCmatch->Fill(zMuMuCand.mass());
00528 
00529         }
00530       } else {
00531         h_zMuMuMassOppositeSign->Fill(zMuMuCand.mass());
00532       }
00533 
00534       bool etaCut = false;
00535       bool ptCut = false;
00536       //bool isoCut = false;
00537       bool massCut = false;
00538 
00539       // ******************************************************************************************************************************
00540       // Start study for StandAlone charge mis-id: select global-global events according to global1+track2 (or global2+track1) 
00541       // *******************************************************************************************************************************
00542 
00543       // cynematical cuts for Zglobal1Track2
00544       if (abs(etaGlobal1)<etamax_ && abs(etaTracker2)<etamax_) etaCut = true;
00545       if (ptGlobal1>ptmin_ && ptTracker2>ptmin_) ptCut = true;
00546       if (massGlobalTracker>massMin_ && massGlobalTracker<massMax_) massCut = true;
00547 
00548       if (noCut_) {
00549         etaCut = true;
00550         ptCut = true;
00551         massCut = true;
00552       }
00553 
00554       if (etaCut && ptCut && massCut) {
00555         // check first global1-track2 if they have opposite charge and if global1 has consistent charge between sta and track
00556         if (chargeSta1 == chargeTracker1 && chargeTracker1 != chargeTracker2) {      // event tagged to study StandAlone2 charge
00557           n_goodTrack_ZMuMutagged++;
00558           h_zMuTrackMass_ZMuMuTagged->Fill(massGlobalTracker);  // inv mass global+tracker part
00559           h_etaTrack_ZMuMuTagged->Fill(etaTracker2);      // eta of tagged track
00560           h_phiTrack_ZMuMuTagged->Fill(phiTracker2);      // phi of tagged track
00561           h_ptTrack_ZMuMuTagged->Fill(ptTracker2);        // pt of tagged track
00562           h_DRTrack_ZMuMuTagged->Fill(DR2);               // DR between sta2 and tracker2 for tagged track
00563 
00564           if (isMCMatched) {             // if MC match .. resolution plots of global1 respect to gen particles
00565             double etaGen, ptGen;
00566             if (chargeGlobal1==1) {
00567               etaGen = muGenplus_eta;
00568               ptGen = muGenplus_pt;
00569             } else {
00570               etaGen = muGenminus_eta;
00571               ptGen = muGenminus_pt;
00572             }
00573             h_GlobalMuonEtaMinusGenEta_ZMuMuTagged->Fill(etaGlobal1 - etaGen);
00574             h_GlobalMuonPtMinusGenPt_ZMuMuTagged->Fill((ptGlobal1 - ptGen)/ptGen);
00575             h_GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged->Fill(etaSta1 - etaGen);
00576             h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged->Fill((ptSta1 - ptGen)/ptGen);
00577             h_DEtaGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaGlobal1-etaGen);
00578             h_DPtGlobalGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptGlobal1-ptGen)/ptGen);
00579             h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaSta1-etaGen);
00580             h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptSta1-ptGen)/ptGen);
00581             h_DPtGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptGlobal1-ptGen)/ptGen);
00582             h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptSta1-ptGen)/ptGen);    
00583             h_DPtTrackGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptTracker1-ptGen)/ptGen);
00584             h_DPtTrackGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptTracker1-ptGen)/ptGen);
00585 
00586           } // end if MC Match
00587 
00588           if (chargeSta2 == chargeTracker2) {   // StandAlone2 has correct charge
00589             n_correctStaCharge_ZMuMutagged++;
00590             h_zMuStaMass_correctStaCharge_ZMuMuTagged->Fill(massGlobalSta);  // inv mass of global-Sta part for correct charge muons
00591             h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged->Fill((ptSta2-ptTracker2)/ptTracker2);
00592             h_ptStaMinusptTrack_vsEtaTracker_correctStaCharge_ZMuMuTagged->Fill(etaTracker2,(ptSta2-ptTracker2)/ptTracker2);
00593             h_ptStaMinusptTrack_vsPtTracker_correctStaCharge_ZMuMuTagged->Fill(ptTracker2,(ptSta2-ptTracker2)/ptTracker2);
00594             // qui posso aggiungere plot col MC match
00595           }  
00596           if (chargeSta2 != chargeTracker2) {  // StandAlone2 has wrong charge
00597             n_wrongStaCharge_ZMuMutagged++;
00598             h_zMuTrackMass_wrongStaCharge_ZMuMuTagged->Fill(massGlobalTracker);  // inv mass global+tracker part (wrong Sta charge)
00599             h_etaTrack_wrongStaCharge_ZMuMuTagged->Fill(etaTracker2);      // eta of tagged track (wrong Sta charge)
00600             h_phiTrack_wrongStaCharge_ZMuMuTagged->Fill(phiTracker2);      // phi of tagged track (wrong Sta charge)
00601             h_ptTrack_wrongStaCharge_ZMuMuTagged->Fill(ptTracker2);      // pt of tagged track (wrong Sta charge)
00602             h_DRTrack_wrongStaCharge_ZMuMuTagged->Fill(DR2);            // DR between sta2 and tracker2 for tagged track (wrong Sta charge)
00603           }
00604         }  // end if check chrge global1-tracker2
00605       }  // end if cut selection
00606 
00607       // cynematical cuts for Zglobal2Track1
00608       etaCut = false;
00609       ptCut = false;
00610       massCut = false;
00611       //isoCut = false;
00612       if (abs(etaGlobal2)<etamax_ && abs(etaTracker1)<etamax_) etaCut = true;
00613       if (ptGlobal2>ptmin_ && ptTracker1>ptmin_) ptCut = true;
00614       if (massTrackerGlobal>massMin_ && massTrackerGlobal<massMax_) massCut = true;
00615 
00616       if (noCut_) {
00617         etaCut = true;
00618         ptCut = true;
00619         massCut = true;
00620       }
00621 
00622       if (etaCut && ptCut && massCut) {
00623         // check global2-track1 if they have opposite charge and if global2 has consistent charge between sta and track
00624         if (chargeSta2 == chargeTracker2 && chargeTracker1 != chargeTracker2) {      // event tagged to study StandAlone2 charge
00625           n_goodTrack_ZMuMutagged++;
00626           h_zMuTrackMass_ZMuMuTagged->Fill(massTrackerGlobal);  // inv mass global+tracker part
00627           h_etaTrack_ZMuMuTagged->Fill(etaTracker1);      // eta of tagged track
00628           h_phiTrack_ZMuMuTagged->Fill(phiTracker1);      // phi of tagged track
00629           h_ptTrack_ZMuMuTagged->Fill(ptTracker1);        // pt of tagged track
00630           h_DRTrack_ZMuMuTagged->Fill(DR1);               // DR between sta1 and tracker1 for tagged track
00631 
00632           // qui posso aggiungere plot col MC match
00633           if (isMCMatched) {             // if MC match .. resolution plots of global2 respect to gen particles
00634             double etaGen, ptGen;
00635             if (chargeGlobal2==1) {
00636               etaGen = muGenplus_eta;
00637               ptGen = muGenplus_pt;
00638             } else {
00639               etaGen = muGenminus_eta;
00640               ptGen = muGenminus_pt;
00641             }
00642             h_GlobalMuonEtaMinusGenEta_ZMuMuTagged->Fill(etaGlobal2 - etaGen);
00643             h_GlobalMuonPtMinusGenPt_ZMuMuTagged->Fill((ptGlobal2 - ptGen)/ptGen);
00644             h_GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged->Fill(etaSta2 - etaGen);
00645             h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged->Fill((ptSta2 - ptGen)/ptGen);
00646             h_DEtaGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaGlobal2-etaGen);
00647             h_DPtGlobalGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptGlobal2-ptGen)/ptGen);
00648             h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaSta2-etaGen);
00649             h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptSta2-ptGen)/ptGen);
00650             h_DPtGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptGlobal2-ptGen)/ptGen);
00651             h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptSta2-ptGen)/ptGen);
00652             h_DPtTrackGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptTracker2-ptGen)/ptGen);
00653             h_DPtTrackGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptTracker2-ptGen)/ptGen);
00654           } // end if MC Match
00655           
00656 
00657           if (chargeSta1 == chargeTracker1) {   // StandAlone1 has correct charge
00658             n_correctStaCharge_ZMuMutagged++;
00659             h_zMuStaMass_correctStaCharge_ZMuMuTagged->Fill(massStaGlobal);  // inv mass of Sta-global part for correct charge muons
00660             h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged->Fill((ptSta1-ptTracker1)/ptTracker1);
00661             h_ptStaMinusptTrack_vsEtaTracker_correctStaCharge_ZMuMuTagged->Fill(etaTracker1,(ptSta1-ptTracker1)/ptTracker1);
00662             h_ptStaMinusptTrack_vsPtTracker_correctStaCharge_ZMuMuTagged->Fill(ptTracker1,(ptSta1-ptTracker1)/ptTracker1);
00663 
00664           }  
00665           if (chargeSta1 != chargeTracker1) {  // StandAlone2 has wrong charge
00666             n_wrongStaCharge_ZMuMutagged++;
00667             h_zMuTrackMass_wrongStaCharge_ZMuMuTagged->Fill(massTrackerGlobal);  // inv mass global+tracker part (wrong Sta charge)
00668             h_etaTrack_wrongStaCharge_ZMuMuTagged->Fill(etaTracker1);      // eta of tagged track (wrong Sta charge)
00669             h_phiTrack_wrongStaCharge_ZMuMuTagged->Fill(phiTracker1);      // phi of tagged track (wrong Sta charge)
00670             h_ptTrack_wrongStaCharge_ZMuMuTagged->Fill(ptTracker1);      // pt of tagged track (wrong Sta charge)
00671             h_DRTrack_wrongStaCharge_ZMuMuTagged->Fill(DR1);            // DR between sta1 and tracker1 for tagged track (wrong Sta charge)
00672           }
00673         }  // end if check charge global1-tracker2
00674       }  // end if cuts
00675 
00676       // ******************************************************************************************************************************
00677       // Start study for tracker charge mis-id: select global-global events according to global1+staComponent2 (or global2+staComponent1) 
00678       // *******************************************************************************************************************************
00679 
00680       etaCut = false;
00681       ptCut = false;
00682       //isoCut = false;
00683       massCut = false;
00684 
00685      // cynematical cuts for Zglobal1Sta2
00686       if (abs(etaGlobal1)<etamax_ && abs(etaSta2)<etamax_) etaCut = true;
00687       if (ptGlobal1>ptmin_ && ptSta2>ptmin_) ptCut = true;
00688       if (massGlobalSta>massMin_ && massGlobalSta<massMax_) massCut = true;
00689 
00690       if (noCut_) {
00691         etaCut = true;
00692         ptCut = true;
00693         massCut = true;
00694       }
00695 
00696       if (etaCut && ptCut && massCut) {
00697         // check first global1-sta2 if they have opposite charge and if global1 has consistent charge between sta and track
00698         if (chargeSta1 == chargeTracker1 && chargeTracker1 != chargeSta2) {      // event tagged to study track2 charge
00699           n_goodSta_ZMuMutagged++;
00700           h_zMuStaMass_ZMuMuTagged->Fill(massGlobalSta);  // inv mass global+sta part
00701           h_etaSta_ZMuMuTagged->Fill(etaSta2);            // eta of tagged sta
00702           h_phiSta_ZMuMuTagged->Fill(phiSta2);      // phi of tagged sta
00703           h_ptSta_ZMuMuTagged->Fill(ptSta2);        // pt of tagged sta
00704           h_DRSta_ZMuMuTagged->Fill(DR2);               // DR between sta2 and tracker2 for tagged sta
00705 
00706           if (chargeSta2 == chargeTracker2) {   // track2 has correct charge
00707             n_correctTrkCharge_ZMuMutagged++;
00708             // qui posso aggiungere plot col MC match
00709           }  
00710           if (chargeSta2 != chargeTracker2) {  // track2 has wrong charge
00711             n_wrongTrkCharge_ZMuMutagged++;
00712             h_zMuStaMass_wrongTrkCharge_ZMuMuTagged->Fill(massGlobalSta);  // inv mass global+sta part (wrong Trk charge)
00713             h_etaSta_wrongTrkCharge_ZMuMuTagged->Fill(etaSta2);      // eta of tagged sta (wrong trk charge)
00714             h_phiSta_wrongTrkCharge_ZMuMuTagged->Fill(phiSta2);      // phi of tagged sta (wrong Trk charge)
00715             h_ptSta_wrongTrkCharge_ZMuMuTagged->Fill(ptSta2);      // pt of tagged sta (wrong Trk charge)
00716             h_DRSta_wrongTrkCharge_ZMuMuTagged->Fill(DR2);            // DR between sta2 and tracker2 for tagged sta (wrong trk charge)
00717           }
00718         }  // end if check chrge global1-sta2
00719       }  // end if cut selection
00720 
00721       etaCut = false;
00722       ptCut = false;
00723       //isoCut = false;
00724       massCut = false;
00725 
00726      // cynematical cuts for Zglobal2Sta1
00727       if (abs(etaGlobal2)<etamax_ && abs(etaSta1)<etamax_) etaCut = true;
00728       if (ptGlobal2>ptmin_ && ptSta1>ptmin_) ptCut = true;
00729       if (massStaGlobal>massMin_ && massStaGlobal<massMax_) massCut = true;
00730 
00731       if (noCut_) {
00732         etaCut = true;
00733         ptCut = true;
00734         massCut = true;
00735       }
00736 
00737       if (etaCut && ptCut && massCut) {
00738         // check first global2-sta1 if they have opposite charge and if global2 has consistent charge between sta and track
00739         if (chargeSta2 == chargeTracker2 && chargeTracker2 != chargeSta1) {      // event tagged to study track1 charge
00740           n_goodSta_ZMuMutagged++;
00741           h_zMuStaMass_ZMuMuTagged->Fill(massStaGlobal);  // inv mass global+sta part
00742           h_etaSta_ZMuMuTagged->Fill(etaSta1);            // eta of tagged sta
00743           h_phiSta_ZMuMuTagged->Fill(phiSta1);      // phi of tagged sta
00744           h_ptSta_ZMuMuTagged->Fill(ptSta1);        // pt of tagged sta
00745           h_DRSta_ZMuMuTagged->Fill(DR1);               // DR between sta1 and tracker1 for tagged sta
00746 
00747           if (chargeSta1 == chargeTracker1) {   // track1 has correct charge
00748             n_correctTrkCharge_ZMuMutagged++;
00749             // qui posso aggiungere plot col MC match
00750           }  
00751           if (chargeSta1 != chargeTracker1) {  // track1 has wrong charge
00752             n_wrongTrkCharge_ZMuMutagged++;
00753             h_zMuStaMass_wrongTrkCharge_ZMuMuTagged->Fill(massStaGlobal);  // inv mass global+sta part (wrong Trk charge)
00754             h_etaSta_wrongTrkCharge_ZMuMuTagged->Fill(etaSta1);      // eta of tagged sta (wrong trk charge)
00755             h_phiSta_wrongTrkCharge_ZMuMuTagged->Fill(phiSta1);      // phi of tagged sta (wrong Trk charge)
00756             h_ptSta_wrongTrkCharge_ZMuMuTagged->Fill(ptSta1);      // pt of tagged sta (wrong Trk charge)
00757             h_DRSta_wrongTrkCharge_ZMuMuTagged->Fill(DR1);            // DR between sta2 and tracker2 for tagged sta (wrong trk charge)
00758           }
00759         }  // end if check chrge global2-sta1
00760       }  // end if cut selection
00761 
00762 
00763     }  // end loop on ZMuMu cand
00764   }    // end if ZMuMu size > 0
00765 
00766 
00767   // loop on ZMuTrack in order to recover some unMatched StandAlone
00768 
00769   //double LargerDRCut=2.; // larger DR cut to recover unMatched Sta
00770   int taggedZ_index = -1; // index of Z with minimum DR respect to unMatched Sta
00771   int taggedMuon_index = -1; // index of Sta muon with minimum DR respect to unMatched track
00772   int n_ZMuTrackTagged_inEvent = 0;  // number of tagged Z in the event
00773   if (zMuTrack->size() > 0 && zMuMu->size()==0) {           // check ZMuTrack just if no ZMuMu has been found in the event
00774     event.getByLabel(zMuTrackMatchMap_, zMuTrackMatchMap); 
00775     for(unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
00776       const Candidate & zMuTrackCand = (*zMuTrack)[i]; //the candidate
00777       CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(i);
00778       GenParticleRef zMuTrackMatch = (*zMuTrackMatchMap)[zMuTrackCandRef];
00779       //bool isMCMatched = false;
00780       //if(zMuTrackMatch.isNonnull()) isMCMatched = true;   // ZMuTrack matched
00781       // forzo isMCMatched
00782       //      isMCMatched = true;
00783 
00784       double m = zMuTrackCand.mass();
00785       CandidateBaseRef zglobalDaughter = zMuTrackCand.daughter(0)->masterClone();
00786       CandidateBaseRef ztrackerDaughter = zMuTrackCand.daughter(1)->masterClone();
00787       TrackRef zglobalDaughter_StaComponentRef = zMuTrackCand.daughter(0)->get<TrackRef,reco::StandAloneMuonTag>();  
00788                                                                                   // standalone part of global component of ZMuMu
00789       TrackRef zglobalDaughter_TrackComponentRef = zMuTrackCand.daughter(0)->get<TrackRef>();  
00790                                                                                   // track part Of the global component of ZMuMu
00791       double ZtrackerDaughterCharge = ztrackerDaughter->charge();
00792       double ZtrackerDaughterPt = ztrackerDaughter->pt();
00793       double ZtrackerDaughterEta = ztrackerDaughter->eta();
00794       double ZtrackerDaughterPhi = ztrackerDaughter->phi();
00795       double ZglobalDaughterPt = zglobalDaughter->pt();
00796       double ZglobalDaughterEta = zglobalDaughter->eta();
00797       double ZglobalDaughter_StaComponentCharge = zglobalDaughter_StaComponentRef->charge(); 
00798       double ZglobalDaughter_TrackComponentCharge = zglobalDaughter_TrackComponentRef->charge(); 
00799 
00800       //*********************************************************************************************************************
00801       // study of standAlone charge mis-id and efficiency selecting ZMuTrack events (tag the index of Z and of muon)
00802       // for Sta charge mis-id just use unMatched standAlone muons trackerMuons that are standAlone Muons but no globalMuons
00803       // ********************************************************************************************************************
00804       // cynematical cuts for ZMuTrack
00805       bool etaCut = false;
00806       bool ptCut = false;
00807       //      bool isoCut = false;
00808       bool massCut = false;
00809       if (abs(ZglobalDaughterEta)<etamax_ && abs(ZtrackerDaughterEta)<etamax_) etaCut = true;
00810       if (ZglobalDaughterPt>ptmin_ && ZtrackerDaughterPt>ptmin_) ptCut = true;
00811       if (m>massMin_ && m<massMax_) massCut = true;
00812 
00813        if (noCut_) {
00814         etaCut = true;
00815         ptCut = true;
00816         massCut = true;
00817       }
00818       if (etaCut && ptCut && massCut && ZglobalDaughter_StaComponentCharge == ZglobalDaughter_TrackComponentCharge && 
00819           ZglobalDaughter_TrackComponentCharge != ZtrackerDaughterCharge) {   // cynematic cuts and global charge consistent and opposite tracker charge
00820         n_ZMuTrackTagged_inEvent++;
00821 
00822         // posso inserire istogrammi eta e pt track per studio Sta efficiency
00823         // ...
00824 
00825         for(unsigned int j = 0; j < muons->size() ; ++j) {
00826           CandidateBaseRef muCandRef = muons->refAt(j); 
00827           const Candidate & muCand = (*muons)[j]; //the candidate
00828           TrackRef muStaComponentRef = muCand.get<TrackRef,reco::StandAloneMuonTag>();  // standalone part of muon
00829           TrackRef muTrkComponentRef = muCand.get<TrackRef>();  // track part of muon
00830 
00831           if (muCandRef->isStandAloneMuon()==1 && muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1) {          
00832             double muEta = muCandRef->eta();
00833             double muPhi = muCandRef->phi();
00834             // check DeltaR between Sta muon and tracks of ZMuTrack
00835             double DRmuSta_trackOfZ = deltaR(muEta, muPhi, ZtrackerDaughterEta, ZtrackerDaughterPhi);
00836             if (DRmuSta_trackOfZ == 0) {  // match track track ... standalone-muTracker 
00837               taggedZ_index = i;
00838               taggedMuon_index = j;
00839             } // end check minimum DR
00840           }  // end if isStandAlone
00841         }    // end loop on muon candidates
00842       } // end cynematic cuts    
00843 
00844     }  // end loop on zMuTrack size
00845   }   // end if zMuTrack size > 0
00846 
00847   // analyze the tagged ZMuTRack and the Sta muons with minimal DR
00848   if (n_ZMuTrackTagged_inEvent>0) {   // at Least one ZMuTRack tagged
00849 
00850     if (taggedZ_index==-1) { // StandAlone inefficient
00851       n_StaNotFound_ZMuTracktagged++;
00852       //      h_etaTrack_StaNotFound_ZMuTrackTagged->Fill(ztrackerDaughter->eta());
00853     } else {
00854       const Candidate & zMuTrackCand = (*zMuTrack)[taggedZ_index]; //the candidate tagged
00855       CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(taggedZ_index);
00856       double m = zMuTrackCand.mass();
00857       CandidateBaseRef zglobalDaughter = zMuTrackCand.daughter(0)->masterClone();
00858       CandidateBaseRef ztrackerDaughter = zMuTrackCand.daughter(1)->masterClone();
00859       TrackRef zglobalDaughter_StaComponentRef = zMuTrackCand.daughter(0)->get<TrackRef,reco::StandAloneMuonTag>();  
00860                                                                           // standalone part of global component of ZMuMu
00861       TrackRef zglobalDaughter_TrackComponentRef = zMuTrackCand.daughter(0)->get<TrackRef>();  
00862                                                                           // track part Of the global component of ZMuMu
00863       double ZtrackerDaughterCharge = ztrackerDaughter->charge();
00864       double ZtrackerDaughterPt = ztrackerDaughter->pt();
00865       double ZtrackerDaughterEta = ztrackerDaughter->eta();
00866       double ZtrackerDaughterPhi = ztrackerDaughter->phi();
00867 
00868       CandidateBaseRef muCandRef = muons->refAt(taggedMuon_index);  // the tagged muon
00869       const Candidate & muCand = (*muons)[taggedMuon_index]; //the candidate
00870       TrackRef muStaComponentRef = muCand.get<TrackRef,reco::StandAloneMuonTag>();  // standalone part of muon
00871       TrackRef muTrkComponentRef = muCand.get<TrackRef>();  // track part of muon
00872 
00873       double muEta = muStaComponentRef->eta();
00874       double muPhi = muStaComponentRef->phi();
00875       double muCharge = muStaComponentRef->charge();
00876       // check DeltaR between Sta muon and tracks of ZMuTrack
00877       double DRmuSta_trackOfZ = deltaR(muEta, muPhi, ZtrackerDaughterEta, ZtrackerDaughterPhi);
00878 
00879       n_goodTrack_ZMuTracktagged++;
00880       h_zMuTrackMass_ZMuTrackTagged->Fill(m);         // inv mass ZMuTrack for tagged events
00881       h_etaTrack_ZMuTrackTagged->Fill(ZtrackerDaughterEta);   // eta of tagged track
00882       h_phiTrack_ZMuTrackTagged->Fill(ZtrackerDaughterPhi);      // phi of tagged track
00883       h_ptTrack_ZMuTrackTagged->Fill(ZtrackerDaughterPt);        // pt of tagged track
00884       h_DRTrack_ZMuTrackTagged->Fill(DRmuSta_trackOfZ);          // DR between sta1 and tracker1 for tagged track
00885 
00886       // check StandAlone charge    
00887       if (muCharge != ZtrackerDaughterCharge) {  // wrong Sta charge
00888         n_wrongStaCharge_ZMuTracktagged++;                              // number of events wrong charge for unMatched Sta
00889         h_zMuTrackMass_wrongStaCharge_ZMuTrackTagged->Fill(m);         // inv mass ZMuTrack for tagged events wrong unMatched Sta charge
00890         h_etaTrack_wrongStaCharge_ZMuTrackTagged->Fill(ZtrackerDaughterEta);   // eta of tagged track wrong unMatched Sta charge
00891         h_phiTrack_wrongStaCharge_ZMuTrackTagged->Fill(ZtrackerDaughterPhi);      // phi of tagged track wrong unMatched Sta charge
00892         h_ptTrack_wrongStaCharge_ZMuTrackTagged->Fill(ZtrackerDaughterPt);        // pt of tagged track wrong unMatched Sta charge
00893         h_DRTrack_wrongStaCharge_ZMuTrackTagged->Fill(DRmuSta_trackOfZ);          // DR between unMatched Sta and tracker for wrong sta charge 
00894       } else {  // correct Sta charge
00895         n_correctStaCharge_ZMuTracktagged++;                              // number of events correct charge for unMatched Sta
00896       }  // end if Sta charge check
00897     }   // end if StandAlone is present    
00898   }  // end if zMuTrack tagged
00899 
00900   //*********************************************************************************************************************
00901   // study of track charge mis-id and efficiency selecting ZMuSta events 
00902   // for Track charge mis-id just use unMatched standAlone muons trackerMuons that are standAlone Muons but no globalMuons
00903   // ********************************************************************************************************************
00904   
00905   // loop on ZMuSta in order to recover some unMatched StandAlone 
00906   bool isZMuStaMatched=false;
00907   //LargerDRCut=2.; // larger DR cut to recover unMatched Sta
00908   taggedZ_index = -1; // index of Z with minimum DR respect to unMatched Sta
00909   taggedMuon_index = -1; // index of Sta muon with minimum DR respect to unMatched track
00910   int n_ZMuStaTagged_inEvent = 0;  // number of tagged Z in the event
00911   if (zMuStandAlone->size() > 0) {           // check ZMuSta just if no ZMuMu has been found in the event
00912     event.getByLabel(zMuStandAloneMatchMap_, zMuStandAloneMatchMap); 
00913     for(unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
00914       const Candidate & zMuStaCand = (*zMuStandAlone)[i]; //the candidate
00915       CandidateBaseRef zMuStaCandRef = zMuStandAlone->refAt(i);
00916 
00917       GenParticleRef zMuStaMatch = (*zMuStandAloneMatchMap)[zMuStaCandRef];
00918       if(zMuStaMatch.isNonnull()) {        // ZMuSta Macthed
00919         numberOfMatchedZMuSta_++;
00920         isZMuStaMatched = true;
00921       }
00922 
00923       double m = zMuStaCand.mass();
00924       CandidateBaseRef zglobalDaughter = zMuStaCand.daughter(0)->masterClone();
00925       CandidateBaseRef zstandaloneDaughter = zMuStaCand.daughter(1)->masterClone();
00926       int iglb = 0;
00927       int ista = 1;
00928       if (zglobalDaughter->isGlobalMuon()==0 && zstandaloneDaughter->isGlobalMuon()==1) {  // invert definition
00929         CandidateBaseRef buffer = zglobalDaughter;
00930         zglobalDaughter = zstandaloneDaughter;
00931         zstandaloneDaughter = buffer;
00932         iglb = 1;
00933         ista = 0;
00934       }
00935       TrackRef zglobalDaughter_StaComponentRef = zMuStaCand.daughter(iglb)->get<TrackRef,reco::StandAloneMuonTag>();  
00936                                                                                   // standalone part of global component of ZMuMu
00937       TrackRef zglobalDaughter_TrackComponentRef = zMuStaCand.daughter(iglb)->get<TrackRef>();  
00938                                                                                   // track part Of the global component of ZMuMu
00939       TrackRef zstaDaughter_StaComponentRef = zMuStaCand.daughter(ista)->get<TrackRef,reco::StandAloneMuonTag>();  
00940                                                                                   // standalone part of global component of ZMuMu
00941       TrackRef zstaDaughter_TrackComponentRef = zMuStaCand.daughter(ista)->get<TrackRef>();  
00942                                                                                   // track part Of the global component of ZMuMu
00943       double ZglobalDaughterPt = zglobalDaughter->pt();
00944       double ZglobalDaughterEta = zglobalDaughter->eta();
00945 
00946       double ZstaDaughter_StaComponentCharge = zstaDaughter_StaComponentRef->charge(); 
00947       double ZstaDaughter_StaComponentPt = zstaDaughter_StaComponentRef->pt(); 
00948       double ZstaDaughter_StaComponentEta = zstaDaughter_StaComponentRef->eta(); 
00949       double ZstaDaughter_StaComponentPhi = zstaDaughter_StaComponentRef->phi(); 
00950       double ZstaDaughter_TrackComponentCharge = zstaDaughter_TrackComponentRef->charge(); 
00951 
00952       double ZglobalDaughter_StaComponentCharge = zglobalDaughter_StaComponentRef->charge(); 
00953       double ZglobalDaughter_TrackComponentCharge = zglobalDaughter_TrackComponentRef->charge(); 
00954 
00955       // cynematical cuts for ZMuSta
00956       bool etaCut = false;
00957       bool ptCut = false;
00958       //      bool isoCut = false;
00959       bool massCut = false;
00960       if (abs(ZglobalDaughterEta)<etamax_ && abs(ZstaDaughter_StaComponentEta)<etamax_) etaCut = true;
00961       if (ZglobalDaughterPt>ptmin_ && ZstaDaughter_StaComponentPt>ptmin_) ptCut = true;
00962       if (m>massMin_ && m<massMax_) massCut = true;          // dovrei usare la massa fatta con la sola parte sta 
00963                                                              // (Se è anche trackerMu non è cosi') 
00964        if (noCut_) {
00965         etaCut = true;
00966         ptCut = true;
00967         massCut = true;
00968       }
00969       if (etaCut && ptCut && massCut && ZglobalDaughter_StaComponentCharge == ZglobalDaughter_TrackComponentCharge && 
00970           ZglobalDaughter_StaComponentCharge != ZstaDaughter_StaComponentCharge) {   // cynematic cuts and global charge consistent and opposite sta charge
00971         n_ZMuStaTagged_inEvent++;
00972         if (isZMuStaMatched) n_ZMuStaTaggedMatched++;
00973         // posso inserire istogrammi eta e pt track per studio Sta efficiency
00974         // ...
00975         if (zstandaloneDaughter->isStandAloneMuon()==1 && zstandaloneDaughter->isTrackerMuon()==1) {  // track matched
00976           n_goodSta_ZMuStatagged++;
00977           h_zMuStaMass_ZMuStaTagged->Fill(m);         // inv mass ZMuSta for tagged events
00978           h_etaSta_ZMuStaTagged->Fill(ZstaDaughter_StaComponentEta);   // eta of tagged sta
00979           h_phiSta_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPhi);  // phi of tagged sta
00980           h_ptSta_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPt);        // pt of tagged sta
00981           
00982           // check Track charge    
00983           if (ZstaDaughter_StaComponentCharge != ZstaDaughter_TrackComponentCharge) {  // wrong Trk charge
00984             n_wrongTrkCharge_ZMuStatagged++;                              // number of events wrong track charge for unMatched track
00985             h_zMuStaMass_wrongTrkCharge_ZMuStaTagged->Fill(m);         // inv mass ZMuSta for tagged evts wrong unMatched track charge
00986             h_etaSta_wrongTrkCharge_ZMuStaTagged->Fill(ZstaDaughter_StaComponentEta);   // eta of tagged sta wrong unMatched track charge
00987             h_phiSta_wrongTrkCharge_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPhi);   // phi of tagged sta wrong unMatched track charge
00988             h_ptSta_wrongTrkCharge_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPt);        // pt of tagged sta wrong unMatched track charge
00989           } else {  // correct Sta charge
00990             n_correctTrkCharge_ZMuStatagged++;                              // number of events correct charge for unMatched Sta
00991           }  // end if Sta charge check
00992           
00993         } else {   // tracker inefficient
00994           n_TrkNotFound_ZMuStatagged++;
00995         }
00996       } // end cynematic cuts    
00997       if (n_ZMuStaTagged_inEvent==0) {
00998       }
00999 
01000 
01001     }  // end loop on zMuSta candidates
01002   }   // end check ZMuSta size
01003   
01004 }       // end analyze
01005 
01006 bool ZMuMuPerformances::check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
01007 {
01008   int partId0 = dauGen0->pdgId();
01009   int partId1 = dauGen1->pdgId();
01010   int partId2 = dauGen2->pdgId();
01011   bool muplusFound=false;
01012   bool muminusFound=false;
01013   bool ZFound=false;
01014   if (partId0==13 || partId1==13 || partId2==13) muminusFound=true;
01015   if (partId0==-13 || partId1==-13 || partId2==-13) muplusFound=true;
01016   if (partId0==23 || partId1==23 || partId2==23) ZFound=true;
01017   return muplusFound*muminusFound*ZFound;   
01018 }
01019  
01020 float ZMuMuPerformances::getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
01021 {
01022   int partId0 = dauGen0->pdgId();
01023   int partId1 = dauGen1->pdgId();
01024   int partId2 = dauGen2->pdgId();
01025   float ptpart=0.;
01026   if (partId0 == ipart) {
01027     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
01028       const Candidate * dauMuGen = dauGen0->daughter(k);
01029       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01030         ptpart = dauMuGen->pt();
01031       }
01032     }
01033   }
01034   if (partId1 == ipart) {
01035     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
01036       const Candidate * dauMuGen = dauGen1->daughter(k);
01037       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01038         ptpart = dauMuGen->pt();
01039       }
01040     }
01041   }
01042   if (partId2 == ipart) {
01043     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
01044       const Candidate * dauMuGen = dauGen2->daughter(k);
01045       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
01046         ptpart = dauMuGen->pt();
01047       }
01048     }
01049   }
01050   return ptpart;
01051 }
01052  
01053 float ZMuMuPerformances::getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
01054 {
01055   int partId0 = dauGen0->pdgId();
01056   int partId1 = dauGen1->pdgId();
01057   int partId2 = dauGen2->pdgId();
01058   float etapart=0.;
01059   if (partId0 == ipart) {
01060     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
01061       const Candidate * dauMuGen = dauGen0->daughter(k);
01062       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01063         etapart = dauMuGen->eta();
01064       }
01065     }
01066   }
01067   if (partId1 == ipart) {
01068     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
01069       const Candidate * dauMuGen = dauGen1->daughter(k);
01070       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01071         etapart = dauMuGen->eta();
01072       }
01073     }
01074   }
01075   if (partId2 == ipart) {
01076     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
01077       const Candidate * dauMuGen = dauGen2->daughter(k);
01078       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
01079         etapart = dauMuGen->eta();
01080       }
01081     }
01082   }
01083   return etapart;
01084 }
01085 
01086 float ZMuMuPerformances::getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
01087 {
01088   int partId0 = dauGen0->pdgId();
01089   int partId1 = dauGen1->pdgId();
01090   int partId2 = dauGen2->pdgId();
01091   float phipart=0.;
01092   if (partId0 == ipart) {
01093     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
01094       const Candidate * dauMuGen = dauGen0->daughter(k);
01095       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01096         phipart = dauMuGen->phi();
01097       }
01098     }
01099   }
01100   if (partId1 == ipart) {
01101     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
01102       const Candidate * dauMuGen = dauGen1->daughter(k);
01103       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01104         phipart = dauMuGen->phi();
01105       }
01106     }
01107   }
01108   if (partId2 == ipart) {
01109     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
01110       const Candidate * dauMuGen = dauGen2->daughter(k);
01111       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
01112         phipart = dauMuGen->phi();
01113       }
01114     }
01115   }
01116   return phipart;
01117 }
01118 
01119 Particle::LorentzVector ZMuMuPerformances::getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
01120 {
01121   int partId0 = dauGen0->pdgId();
01122   int partId1 = dauGen1->pdgId();
01123   int partId2 = dauGen2->pdgId();
01124   Particle::LorentzVector p4part(0.,0.,0.,0.);
01125   if (partId0 == ipart) {
01126     for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
01127       const Candidate * dauMuGen = dauGen0->daughter(k);
01128       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01129         p4part = dauMuGen->p4();
01130       }
01131     }
01132   }
01133   if (partId1 == ipart) {
01134     for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
01135       const Candidate * dauMuGen = dauGen1->daughter(k);
01136       if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
01137         p4part = dauMuGen->p4();
01138       }
01139     }
01140   }
01141   if (partId2 == ipart) {
01142     for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
01143       const Candidate * dauMuGen = dauGen2->daughter(k);
01144       if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
01145         p4part = dauMuGen->p4();
01146       }
01147     }
01148   }
01149   return p4part;
01150 }
01151  
01152 
01153 
01154 void ZMuMuPerformances::endJob() {
01155 
01156   cout << "------------------------------------  Counters  --------------------------------" << endl;
01157   cout << "totalNumberOfZfound = " << totalNumberOfZfound << endl;
01158   cout << "totalNumberOfZpassed = " << totalNumberOfZpassed << endl;
01159   cout << "Number Of ZMuMu Same Sign (no cuts) " << nZMuMuSameSign << endl;
01160   cout << "Number Of ZMuMu Same Sign (no cuts) MC matched " << nZMuMuSameSign_mcMatched << endl;
01161 
01162   cout << "------------------------------------  Counters for standAlone charge mis-id studies --------------------------------" << endl;
01163   cout << " number of goodTracks tagged for ZMuMu collection = " << n_goodTrack_ZMuMutagged << endl;
01164   cout << " number of goodTracks tagged for ZMuMu collection (correct Sta charge) = " << n_correctStaCharge_ZMuMutagged << endl;
01165   cout << " number of goodTracks tagged for ZMuMu collection (wrong Sta charge) = " << n_wrongStaCharge_ZMuMutagged << endl<<endl;
01166   cout << " number of goodTracks tagged for ZMuTrack collection unMatchedSTA = " << n_goodTrack_ZMuTracktagged << endl;
01167   cout << " number of goodTracks tagged for ZMuTrack collection unMatchedSTA (correct Sta charge) = " << n_correctStaCharge_ZMuTracktagged << endl;
01168   cout << " number of goodTracks tagged for ZMuTrack collection unMatchedSTA (wrong Sta charge) = " << n_wrongStaCharge_ZMuTracktagged << endl<<endl;
01169   cout << " number of goodTracks tagged for ZMuTrack collection (No STA found) = " << n_StaNotFound_ZMuTracktagged << endl;
01170 
01171   cout << "------------------------------------  Counters for Track charge mis-id studies --------------------------------" << endl;
01172   cout << " number of goodStandAlone tagged for ZMuMu collection = " << n_goodSta_ZMuMutagged << endl;
01173   cout << " number of goodStandAlone tagged for ZMuMu collection (correct Trk charge) = " << n_correctTrkCharge_ZMuMutagged << endl;
01174   cout << " number of goodStandAlone tagged for ZMuMu collection (wrong Trk charge) = " << n_wrongTrkCharge_ZMuMutagged << endl<<endl;
01175   cout << " number of goodSta tagged for ZMuSta collection unMatchedTrk = " << n_goodSta_ZMuStatagged << endl;
01176   cout << " number of goodSta tagged for ZMuSta collection unMatchedTrk (correct Trk charge) = " << n_correctTrkCharge_ZMuStatagged << endl;
01177   cout << " number of goodSta tagged for ZMuSta collection unMatchedTrk (wrong Trk charge) = " << n_wrongTrkCharge_ZMuStatagged << endl<<endl;
01178   cout << " number of goodSta tagged for ZMuSta collection (No Trk found) = " << n_TrkNotFound_ZMuStatagged << endl;
01179   cout << " number of ZMuSta mactched = " << numberOfMatchedZMuSta_ << endl;
01180   cout << " number of ZMuSta Tagged matched = " << n_ZMuStaTaggedMatched << endl;
01181 }
01182   
01183 #include "FWCore/Framework/interface/MakerMacros.h"
01184 
01185 DEFINE_FWK_MODULE(ZMuMuPerformances);
01186