CMS 3D CMS Logo

ZMuMuPerformances.cc
Go to the documentation of this file.
1 /* \class ZMuMuPerformances
2  *
3  * author: Davide Piccolo
4  *
5  * ZMuMu Performances:
6  * check charge mis-id for standAlone and global muons,
7  * check standAlne resolution vs track resolution
8  *
9  */
10 
31 #include "TH1.h"
32 #include "TH2.h"
33 #include "TH3.h"
34 #include <vector>
35 
36 using namespace edm;
37 using namespace std;
38 using namespace reco;
39 
41 
43 public:
45 private:
46  virtual void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
47  bool check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
48  float getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
49  float getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
50  float getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
51  Particle::LorentzVector getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2);
52  virtual void endJob() override;
53 
66 
67  bool noCut_;
68  double zMassMin_, zMassMax_;
69  double ptminPlus_, ptmaxPlus_, etaminPlus_, etamaxPlus_;
70  double ptminMinus_, ptmaxMinus_, etaminMinus_, etamaxMinus_, isomax_;
71 
72  double etamax_, ptmin_, massMin_, massMax_, isoMax_;
73 
74  reco::CandidateBaseRef globalMuonCandRef_, trackMuonCandRef_, standAloneMuonCandRef_;
76 
77  // general histograms
78  TH1D *h_n_globalMuon_perEvent, *h_n_staOnlyMuon_perEvent, *h_n_trackerOnlyMuon_perEvent, *h_n_trackerStaOnlyMuon_perEvent;
79  TH1D *h_n_globalMuon_perEvent_MCmatch, *h_n_staOnlyMuon_perEvent_MCmatch, *h_n_trackerOnlyMuon_perEvent_MCmatch;
80  TH1D *h_n_trackerStaOnlyMuon_perEvent_MCmatch, *h_n_tracks_perEvent;
81  TH1D *h_n_zMuMu_perEvent, *h_n_zMuSta_perEvent, *h_n_zMuTrack_perEvent;
82 
83  // zMuMu inv mass
84  TH1D *h_zMuMuMassSameSign, *h_zMuMuMassSameSign_MCmatch,*h_zMuMuMassOppositeSign;
85  // histograms with MC truth
86  // charge truth
87  TH1D *h_GlobalMuonChargeTimeGenCharge,*h_TrackerMuonChargeTimeGenCharge;
88  // resolution respect to gen particles
89  TH1D *h_GlobalMuonEtaMinusGenEta,*h_TrackerMuonEtaMinusGenEta,*h_GlobalMuonPtMinusGenPt,*h_TrackerMuonPtMinusGenPt;
90  TH1D *h_GlobalMuonStaComponentEtaMinusGenEta, *h_GlobalMuonStaComponentPtMinusGenPt;
91  TH2D *h_DEtaGlobalGenvsEtaGen, *h_DPtGlobalGenvsPtGen, *h_DEtaGlobalStaComponentGenvsEtaGen,*h_DPtGlobalStaComponentGenvsPtGen;
92  TH2D *h_DPtGlobalGenvsEtaGen, *h_DPtGlobalStaComponentGenvsEtaGen;
93  // resolution respect to gen particles for ZMuMuTagged events
96  TH1D *h_GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged, *h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged;
97  TH2D *h_DEtaGlobalGenvsEtaGen_ZMuMuTagged, *h_DPtGlobalGenvsPtGen_ZMuMuTagged;
98  TH2D *h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged,*h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged;
99  TH2D *h_DPtGlobalGenvsEtaGen_ZMuMuTagged, *h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged;
100  TH2D *h_DPtTrackGenvsPtGen_ZMuMuTagged, *h_DPtTrackGenvsEtaGen_ZMuMuTagged;
101 
102  // histograms for cynematic of ZMuMutagged muons for STA performances studies
103  TH1D *h_zMuTrackMass_ZMuMuTagged, *h_etaTrack_ZMuMuTagged, *h_phiTrack_ZMuMuTagged, *h_ptTrack_ZMuMuTagged, *h_DRTrack_ZMuMuTagged;
104  // histograms for cynematic of ZMuMutagged muons when StandAlone has wrong charge
105  TH1D *h_zMuTrackMass_wrongStaCharge_ZMuMuTagged, *h_etaTrack_wrongStaCharge_ZMuMuTagged;
106  TH1D *h_phiTrack_wrongStaCharge_ZMuMuTagged, *h_ptTrack_wrongStaCharge_ZMuMuTagged, *h_DRTrack_wrongStaCharge_ZMuMuTagged;
107 
108  // hisograms for performances of Standlone when Sta has correct charge
109  TH1D *h_zMuStaMass_correctStaCharge_ZMuMuTagged, *h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged;
112 
113  // histograms for cynematic of ZMuMutagged muons for TRK performances studies
114  TH1D *h_zMuStaMass_ZMuMuTagged, *h_etaSta_ZMuMuTagged, *h_phiSta_ZMuMuTagged, *h_ptSta_ZMuMuTagged, *h_DRSta_ZMuMuTagged;
115  // histograms for cynematic of ZMuMutagged muons when TRK has wrong charge
116  TH1D *h_zMuStaMass_wrongTrkCharge_ZMuMuTagged, *h_etaSta_wrongTrkCharge_ZMuMuTagged;
117  TH1D *h_phiSta_wrongTrkCharge_ZMuMuTagged, *h_ptSta_wrongTrkCharge_ZMuMuTagged, *h_DRSta_wrongTrkCharge_ZMuMuTagged;
118 
119  // histograms for cynematic of ZMuTracktagged muons with unMatchd StandAlone for STA performances studies
120  TH1D *h_zMuTrackMass_ZMuTrackTagged, *h_etaTrack_ZMuTrackTagged, *h_phiTrack_ZMuTrackTagged, *h_ptTrack_ZMuTrackTagged, *h_DRTrack_ZMuTrackTagged;
121  // histograms for cynematic of ZMuTracktagged muons when unMatched StandAlone has wrong charge
122  TH1D *h_zMuTrackMass_wrongStaCharge_ZMuTrackTagged, *h_etaTrack_wrongStaCharge_ZMuTrackTagged;
123  TH1D *h_phiTrack_wrongStaCharge_ZMuTrackTagged, *h_ptTrack_wrongStaCharge_ZMuTrackTagged, *h_DRTrack_wrongStaCharge_ZMuTrackTagged;
124 
125  // histograms for cynematic of ZMuStatagged muons with unMatchd Track for Track performances studies
126  TH1D *h_zMuStaMass_ZMuStaTagged, *h_etaSta_ZMuStaTagged, *h_phiSta_ZMuStaTagged, *h_ptSta_ZMuStaTagged;
127  // histograms for cynematic of ZMuStatagged muons when unMatched Track has wrong charge
128  TH1D *h_zMuStaMass_wrongTrkCharge_ZMuStaTagged, *h_etaSta_wrongTrkCharge_ZMuStaTagged;
129  TH1D *h_phiSta_wrongTrkCharge_ZMuStaTagged, *h_ptSta_wrongTrkCharge_ZMuStaTagged;
130 
131 
132  // global counters
133  int totalNumberOfZfound; // total number of events with Z found
134  int totalNumberOfZpassed; // total number of Z that pass cynematical cuts at generator level
135 
136  int nZMuMuSameSign; // number of ZMuMu SameSIgn (no Cuts)
137  int nZMuMuSameSign_mcMatched; // number of ZMuMu Same Sign (no cuts) MCmatch
138 
139  int n_goodTrack_ZMuMutagged; // total number of tracks selected and tagged to study Sta charge
140  int n_correctStaCharge_ZMuMutagged; // total number of tracks selected and tagged with correct charge of Sta
141  int n_wrongStaCharge_ZMuMutagged; // total number of tracks selected and tagged with wrong charge of Sta
142 
143  int n_goodSta_ZMuMutagged; // total number of standAlone selected and tagged to study Trk charge
144  int n_correctTrkCharge_ZMuMutagged; // total number of standAlone selected and tagged with correct charge of Trk
145  int n_wrongTrkCharge_ZMuMutagged; // total number of standAlone selected and tagged with wrong charge of Trk
146 
147  int n_goodTrack_ZMuTracktagged; // number of traks selected and tagged to study Sta charge (for ZMuTrack colllection no ZMuMu found)
148  int n_correctStaCharge_ZMuTracktagged; // total number of tracks selected and tagged with correct charge of unMatched Sta
149  int n_wrongStaCharge_ZMuTracktagged; // total number of tracks selected and tagged with wrong charge of unMatched Sta
150  int n_StaNotFound_ZMuTracktagged; // total number of tracks selected and tagged with no STA found
151 
152  int n_goodSta_ZMuStatagged; // number of sta selected and tagged to study Trk charge (for ZMuSta collection no ZMuMu found)
153  int n_correctTrkCharge_ZMuStatagged; // total number of sta selected and tagged with correct charge of unMatched track
154  int n_wrongTrkCharge_ZMuStatagged; // total number of sta selected and tagged with wrong charge of unMatched track
155  int n_TrkNotFound_ZMuStatagged; // total number of selected selected and tagged with no Trk found
156 
157  int n_OneGoodZMuTrack; // total number with just 1 good ZMuTrack found
158  int n_MultipleGoodZMuTrack; // total number with more than 1 good ZMuTrack found
161 };
162 
168 #include <iostream>
169 #include <iterator>
170 #include <cmath>
171 
173  zMuMuToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuMu"))),
174  zMuMuMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuMuMatchMap"))),
175  zMuTrackToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuTrack"))),
176  zMuTrackMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuTrackMatchMap"))),
177  zMuStandAloneToken_(consumes<CandidateView>(pset.getParameter<InputTag>("zMuStandAlone"))),
178  zMuStandAloneMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("zMuStandAloneMatchMap"))),
179  muonsToken_(consumes<CandidateView>(pset.getParameter<InputTag>("muons"))),
180  muonMatchMapToken_(mayConsume<GenParticleMatch>(pset.getParameter<InputTag>("muonMatchMap"))),
181  muonIsoToken_(mayConsume<IsolationCollection>(pset.getParameter<InputTag>("muonIso"))),
182  tracksToken_(consumes<CandidateView>(pset.getParameter<InputTag>("tracks"))),
183  trackIsoToken_(mayConsume<IsolationCollection>(pset.getParameter<InputTag>("trackIso"))),
184  genParticlesToken_(consumes<GenParticleCollection>(pset.getParameter<InputTag>( "genParticles"))),
185 
186  noCut_(pset.getParameter<bool>("noCut")),
187 
188  zMassMin_(pset.getUntrackedParameter<double>("zMassMin")),
189  zMassMax_(pset.getUntrackedParameter<double>("zMassMax")),
190  ptminPlus_(pset.getUntrackedParameter<double>("ptminPlus")),
191  ptmaxPlus_(pset.getUntrackedParameter<double>("ptmaxPlus")),
192  etaminPlus_(pset.getUntrackedParameter<double>("etaminPlus")),
193  etamaxPlus_(pset.getUntrackedParameter<double>("etamaxPlus")),
194  ptminMinus_(pset.getUntrackedParameter<double>("ptminMinus")),
195  ptmaxMinus_(pset.getUntrackedParameter<double>("ptmaxMinus")),
196  etaminMinus_(pset.getUntrackedParameter<double>("etaminMinus")),
197  etamaxMinus_(pset.getUntrackedParameter<double>("etamaxMinus")),
198  isomax_(pset.getUntrackedParameter<double>("isomax")) {
200 
201  // cut setting
203  ptmin_ = ptminPlus_;
206  isoMax_ = isomax_;
207 
208  // general histograms
209  h_n_globalMuon_perEvent = fs->make<TH1D>("n_globalMuon_perEvent","n.of globalMuons per Event",6,-.5,5.5);
210  h_n_staOnlyMuon_perEvent = fs->make<TH1D>("n_staOnlyMuon_perEvent","n.of standAlone Only Muons per Event",6,-.5,5.5);
211  h_n_trackerOnlyMuon_perEvent = fs->make<TH1D>("n_trackerOnlyMuon_perEvent","n.of tracker Only Muons per Event",6,-.5,5.5);
212  h_n_trackerStaOnlyMuon_perEvent = fs->make<TH1D>("n_trackerStaOnlyMuon_perEvent","n.of tracker & StandAlone Only Muons per Event",6,-.5,5.5);
213  h_n_globalMuon_perEvent_MCmatch = fs->make<TH1D>("n_globalMuon_perEvent_MCmatch","n.of globalMuons per Event (MCmatch)",6,-.5,5.5);
214  h_n_staOnlyMuon_perEvent_MCmatch = fs->make<TH1D>("n_staOnlyMuon_perEvent_MCmatch","n.of standAlone Only Muons per Event (MCmatch)",6,-.5,5.5);
215  h_n_trackerOnlyMuon_perEvent_MCmatch = fs->make<TH1D>("n_trackerOnlyMuon_perEvent_MCmatch","n.of tracker Only Muons per Event (MCmatch)",6,-.5,5.5);
216  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);
217  h_n_tracks_perEvent = fs->make<TH1D>("n_tracks_perEvent","n.of tracks per Event",100,-.5,99.5);
218  h_n_zMuMu_perEvent = fs->make<TH1D>("n_zMuMu_perEvent","n.of global-global muons per Event",6,-.5,5.5);
219  h_n_zMuSta_perEvent = fs->make<TH1D>("n_zMuSta_perEvent","n.of global-sta muons per Event",6,-.5,5.5);
220  h_n_zMuTrack_perEvent = fs->make<TH1D>("n_zMuTrack_perEvent","n.of global-track muons per Event",100,-.5,99.5);
221 
222  // zMuMu inv mass
223  h_zMuMuMassSameSign = fs->make<TH1D>("zMuMuMassSameSign","inv Mass ZMuMu cand SameSign",100, 0., 200.);
224  h_zMuMuMassOppositeSign = fs->make<TH1D>("zMuMuMassOppositeSign","inv Mass ZMuMu cand OppositeSign",100, 0., 200.);
225  h_zMuMuMassSameSign_MCmatch = fs->make<TH1D>("zMuMuMassSameSign_MCmatch","inv Mass ZMuMu cand SameSign (MC match)",100, 0., 200.);
226 
227  // histograms for MC truth
228  // charge truth
229  h_GlobalMuonChargeTimeGenCharge = fs->make<TH1D>("GlobalMuonChargeTimeGenCharge","charge global mu times charge generated mu",3, -1.5, 1.5);
230  h_TrackerMuonChargeTimeGenCharge = fs->make<TH1D>("TrackerMuonChargeTimeGenCharge","charge Tracker mu times charge generated mu",3, -1.5, 1.5);
231  // resolution respect to gen particles
232  h_GlobalMuonEtaMinusGenEta = fs->make<TH1D>("GlobalMuonEtaMinusGenEta","global mu Eta minus generated mu Eta",100, -.005, .005);
233  h_GlobalMuonPtMinusGenPt = fs->make<TH1D>("GlobalMuonPtMinusGenPtoverPt","global mu Pt minus generated mu Pt over Pt",100, -.5, .5);
234  h_GlobalMuonStaComponentEtaMinusGenEta = fs->make<TH1D>("GlobalMuonStaComponentEtaMinusGenEta","global mu Sta cmponent Eta minus generated mu Eta",100, -.5, .5);
235  h_GlobalMuonStaComponentPtMinusGenPt = fs->make<TH1D>("GlobalMuonStaComponentPtMinusGenPtoerPt","global mu Sta component Pt minus generated mu Pt over Pt",100, -1., 1.);
236  h_TrackerMuonEtaMinusGenEta = fs->make<TH1D>("TrackerMuonEtaMinusGenEta","Tracker mu Eta minus Eta generated mu",100, -.005, .005);
237  h_TrackerMuonPtMinusGenPt = fs->make<TH1D>("TrackerMuonPtMinusenPtoverPt","Tracker mu Pt minus Pt generated mu over Pt",100, -.5, .5);
238 
239  h_DEtaGlobalGenvsEtaGen = fs->make<TH2D>("h_DEtaGlobalGenvsEtaGen","Eta global - Eta Gen vs Eta gen",50,-2.5,2.5,100,-.005,.005);
240  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);
241  h_DPtGlobalGenvsPtGen = fs->make<TH2D>("h_DPtGlobalGenovePtvsPtGen","Pt global - Pt Gen over Pt vs Pt gen",50,0.,100.,100,-.5,.5);
242  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.);
243 
244  // resolution respect to gen particles for ZMuMuTagged events
245  h_GlobalMuonEtaMinusGenEta_ZMuMuTagged = fs->make<TH1D>("GlobalMuonEtaMinusGenEta_ZMuMuTagged","global mu Eta minus generated mu Eta",100, -.005, .005);
246  h_GlobalMuonPtMinusGenPt_ZMuMuTagged = fs->make<TH1D>("GlobalMuonPtMinusGenPtoverPt_ZMuMuTagged","global mu Pt minus generated mu Pt over Pt",100, -.5, .5);
247  h_GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged = fs->make<TH1D>("GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged","global mu Sta cmponent Eta minus generated mu Eta",100, -.5, .5);
248  h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged = fs->make<TH1D>("GlobalMuonStaComponentPtMinusGenPtoverPt_ZMuMuTagged","global mu Sta component Pt minus generated mu Pt over Pt",100, -1., 1.);
249  h_DEtaGlobalGenvsEtaGen_ZMuMuTagged = fs->make<TH2D>("h_DEtaGlobalGenvsEtaGen_ZMuMuTagged","Eta global - Eta Gen vs Eta gen",50,-2.5,2.5,100,-.005,.005);
250  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);
251  h_DPtGlobalGenvsPtGen_ZMuMuTagged = fs->make<TH2D>("h_DPtGlobalGenOverPtvsPtGen_ZMuMuTagged","Pt global - Pt Gen vs Pt gen over Pt",50,0.,100.,100,-.5,.5);
252  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.);
253  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);
254  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.);
255  h_DPtTrackGenvsPtGen_ZMuMuTagged = fs->make<TH2D>("h_DPtTrackGenOverPtvsPtGen_ZMuMuTagged","Pt track - Pt Gen vs Pt gen over Pt",50,0.,100.,100,-.5,.5);
256  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);
257 
258  // histograms for cynematic of ZMuMutagged muons for Sta performances studies
259  h_zMuTrackMass_ZMuMuTagged = fs->make<TH1D>("zMuTrackMass_ZMuMuTagged","inv Mass ZMuTrack cand (global-global)",100, 0., 200.);
260  h_etaTrack_ZMuMuTagged = fs->make<TH1D>("etaTrack_ZMuMuTagged","eta of Track (global-global)",50, -2.5, 2.5);
261  h_phiTrack_ZMuMuTagged = fs->make<TH1D>("phiTrack_ZMuMuTagged","phi of Track (global-global)",50, -3.1415, 3.1415);
262  h_ptTrack_ZMuMuTagged = fs->make<TH1D>("ptTrack_ZMuMuTagged","pt of Track (global-global)",100, 0., 100.);
263  h_DRTrack_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_ZMuMuTagged","DR track-sta (global-global)",100, 0., 5.);
264 
265  // histograms for cynematic of ZMuMutagged muons when StandAlone has wrong charge
266  h_zMuTrackMass_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("zMuTrackMass_wrongStaCharge_ZMuMuTagged","inv Mass ZMuTrack cand (global-global wrongStaCharge)",100, 0., 200.);
267  h_etaTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("etaTrack_wrongStaCharge_ZMuMuTagged","eta of Track (global-global wrongStaCharge)",50, -2.5, 2.5);
268  h_phiTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("phiTrack_wrongStaCharge_ZMuMuTagged","phi of Track (global-global wrongStaCharge)",50, -3.1415, 3.1415);
269  h_ptTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("ptTrack_wrongStaCharge_ZMuMuTagged","pt of Track (global-global wrongStaCharge)",100, 0., 100.);
270  h_DRTrack_wrongStaCharge_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_wrongStaCharge_ZMuMuTagged","DR track-sta (global-global wrongStaCharge)",100, 0., 5.);
271 
272  // hisograms for performances of StandAlone when StandAlone has correct charge
273  h_zMuStaMass_correctStaCharge_ZMuMuTagged = fs->make<TH1D>("zMuStaMass_correctStaCharge_ZMuMuTagged","inv Mass ZMuSta cand (global-global correctStaCharge)",100, 0., 200.);
274  h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged = fs->make<TH1D>("ptStaMinusptTrackoverPT_correctStaCharge_ZMuMuTagged","ptSta - ptTrack over Pt (global-global correctStaCharge)",100, -1., 1.);
275  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.);
276  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.);
277 
278  // histograms for cynematic of ZMuMutagged muons for TRK performances studies
279  h_zMuStaMass_ZMuMuTagged = fs->make<TH1D>("zMuStaMass_ZMuMuTagged","inv Mass ZMuSta cand (global-global)",100, 0., 200.);
280  h_etaSta_ZMuMuTagged = fs->make<TH1D>("etaSta_ZMuMuTagged","eta of Sta (global-global)",50, -2.5, 2.5);
281  h_phiSta_ZMuMuTagged = fs->make<TH1D>("phiSta_ZMuMuTagged","phi of Sta (global-global)",50, -3.1415, 3.1415);
282  h_ptSta_ZMuMuTagged = fs->make<TH1D>("ptSta_ZMuMuTagged","pt of Sta (global-global)",100, 0., 100.);
283  h_DRSta_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_ZMuMuTagged_staSelected","DR track-sta sta selected (global-global)",100, 0., 5.);
284 
285  // histograms for cynematic of ZMuMutagged muons when Track has wrong charge
286  h_zMuStaMass_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("zMuStaMass_wrongTrkCharge_ZMuMuTagged","inv Mass ZMuSta cand (global-global wrongTrkCharge)",100, 0., 200.);
287  h_etaSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("etaSta_wrongTrkCharge_ZMuMuTagged","eta of Sta (global-global wrongTrkCharge)",50, -2.5, 2.5);
288  h_phiSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("phiSta_wrongTrkCharge_ZMuMuTagged","phi of Sta (global-global wrongTrkCharge)",50, -3.1415, 3.1415);
289  h_ptSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("ptSta_wrongTrkCharge_ZMuMuTagged","pt of Sta (global-global wrongTrkCharge)",100, 0., 100.);
290  h_DRSta_wrongTrkCharge_ZMuMuTagged = fs->make<TH1D>("DRTrackSta_wrongTrkCharge_ZMuMuTagged","DR track-sta (global-global wrongTrkCharge)",100, 0., 5.);
291 
292  //
293  // ****************************************************************************************************
294  // histograms for cynematic of ZMuTracktagged muons with unMatched StandAlone
295  h_zMuTrackMass_ZMuTrackTagged = fs->make<TH1D>("zMuTrackMass_ZMuTrackTagged","inv Mass ZMuTrack cand (global-track)",100, 0., 200.);
296  h_etaTrack_ZMuTrackTagged = fs->make<TH1D>("etaTrack_ZMuTrackTagged","eta of Track (global-track)",50, -2.5, 2.5);
297  h_phiTrack_ZMuTrackTagged = fs->make<TH1D>("phiTrack_ZMuTrackTagged","phi of Track (global-track)",50, -3.1415, 3.1415);
298  h_ptTrack_ZMuTrackTagged = fs->make<TH1D>("ptTrack_ZMuTrackTagged","pt of Track (global-track)",100, 0., 100.);
299  h_DRTrack_ZMuTrackTagged = fs->make<TH1D>("DRTrackSta_ZMuTrackTagged","DR track-sta (global-track)",100, 0., 5.);
300 
301  // histograms for cynematic of ZMuTracktagged muons when unMatched StandAlone has wrong charge
302  h_zMuTrackMass_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("zMuTrackMass_wrongStaCharge_ZMuTrackTagged","inv Mass ZMuTrack cand (global-track wrongUnMatcehdStaCharge)",100, 0., 200.);
303  h_etaTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("etaTrack_wrongStaCharge_ZMuTrackTagged","eta of Track (global-track wrongUnMatchedStaCharge)",50, -2.5, 2.5);
304  h_phiTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("phiTrack_wrongStaCharge_ZMuTrackTagged","phi of Track (global-track wrongUnMatchedStaCharge)",50, -3.1415, 3.1415);
305  h_ptTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("ptTrack_wrongStaCharge_ZMuTrackTagged","pt of Track (global-track wrongUnMatchedStaCharge)",100, 0., 100.);
306  h_DRTrack_wrongStaCharge_ZMuTrackTagged = fs->make<TH1D>("DRTrackSta_wrongStaCharge_ZMuTrackTagged","DR track-sta (global-track wrongUnMatchedStaCharge)",100, 0., 5.);
307 
308  // histograms for cynematic of ZMuStatagged muons with unMatched Track
309  h_zMuStaMass_ZMuStaTagged = fs->make<TH1D>("zMuStaMass_ZMuStaTagged","inv Mass ZMuSta cand (global-sta)",100, 0., 200.);
310  h_etaSta_ZMuStaTagged = fs->make<TH1D>("etaSta_ZMuStaTagged","eta of Sta (global-sta)",50, -2.5, 2.5);
311  h_phiSta_ZMuStaTagged = fs->make<TH1D>("phiSta_ZMuStaTagged","phi of Sta (global-sta)",50, -3.1415, 3.1415);
312  h_ptSta_ZMuStaTagged = fs->make<TH1D>("ptSta_ZMuStaTagged","pt of Sta (global-sta)",100, 0., 100.);
313 
314  // histograms for cynematic of ZMuStatagged muons when unMatched track has wrong charge
315  h_zMuStaMass_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("zMuStaMass_wrongTrkCharge_ZMuStaTagged","inv Mass ZMuSta cand (global-sta wrongUnMatcehdTrkCharge)",100, 0., 200.);
316  h_etaSta_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("etaSta_wrongTrkCharge_ZMuStaTagged","eta of Sta (global-sta wrongUnMatchedTrkCharge)",50, -2.5, 2.5);
317  h_phiSta_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("phiSta_wrongTrkCharge_ZMuStaTagged","phi of Sta (global-sta wrongUnMatchedTrkCharge)",50, -3.1415, 3.1415);
318  h_ptSta_wrongTrkCharge_ZMuStaTagged = fs->make<TH1D>("ptSta_wrongTrkCharge_ZMuStaTagged","pt of Sta (global-sta wrongUnMatchedTrkCharge)",100, 0., 100.);
319 
320  // clear global counters
324  nZMuMuSameSign = 0;
335 
340 
345 }
346 
348  Handle<CandidateView> zMuMu;
349  Handle<GenParticleMatch> zMuMuMatchMap; //Map of Z made by Mu global + Mu global (can be used also for same sign Zmumu)
350  Handle<CandidateView> zMuTrack;
351  Handle<GenParticleMatch> zMuTrackMatchMap; //Map of Z made by Mu + Track
352  Handle<CandidateView> zMuStandAlone;
353  Handle<GenParticleMatch> zMuStandAloneMatchMap; //Map of Z made by Mu + StandAlone
354  Handle<CandidateView> muons; //Collection of Muons
355  Handle<GenParticleMatch> muonMatchMap;
357  Handle<CandidateView> tracks; //Collection of Tracks
359  Handle<GenParticleCollection> genParticles; // Collection of Generatd Particles
360 
361  event.getByToken(zMuMuToken_, zMuMu);
362  event.getByToken(zMuTrackToken_, zMuTrack);
363  event.getByToken(zMuStandAloneToken_, zMuStandAlone);
364  event.getByToken(muonsToken_, muons);
365  event.getByToken(tracksToken_, tracks);
366  event.getByToken(genParticlesToken_, genParticles);
367 
368  /*
369  cout << "********* zMuMu size : " << zMuMu->size() << endl;
370  cout << "********* zMuMuSameSign size : " << zMuMuSameSign->size() << endl;
371  cout << "********* zMuStandAlone size : " << zMuStandAlone->size() << endl;
372  cout << "********* zMuTrack size : " << zMuTrack->size() << endl;
373  cout << "********* muons size : " << muons->size()<< endl;
374  cout << "********* standAlone size : " << standAlone->size()<< endl;
375  cout << "********* tracks size : " << tracks->size()<< endl;
376  cout << "********* generated size : " << genParticles->size()<< endl;
377  cout << "***************************************************" << endl;
378  */
379 
380  int n_globalMuon_perEvent=0;
381  int n_staOnlyMuon_perEvent=0;
382  int n_trackerOnlyMuon_perEvent=0;
383  int n_trackerStaOnlyMuon_perEvent=0;
384  int n_globalMuon_perEvent_MCmatch=0;
385  int n_staOnlyMuon_perEvent_MCmatch=0;
386  int n_trackerOnlyMuon_perEvent_MCmatch=0;
387  int n_trackerStaOnlyMuon_perEvent_MCmatch=0;
388 
389  for(unsigned int j = 0; j < muons->size() ; ++j) {
390  CandidateBaseRef muCandRef = muons->refAt(j);
391  const Candidate & muCand = (*muons)[j]; //the candidate
392  const reco::Muon & muon = dynamic_cast<const reco::Muon &>(muCand);
393  reco::TrackRef innerTrackRef = muon.track();
394  reco::TrackRef outerTrackRef = muon.standAloneMuon();
395  TrackRef muStaComponentRef = muCand.get<TrackRef,reco::StandAloneMuonTag>(); // standalone part of muon
396  TrackRef muTrkComponentRef = muCand.get<TrackRef>(); // track part of muon
397  GenParticleRef muonMatch = (*muonMatchMap)[muCandRef];
398  if (muCandRef->isGlobalMuon()==1) n_globalMuon_perEvent++;
399  if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==0 && muCandRef->isStandAloneMuon()==1) n_staOnlyMuon_perEvent++;
400  if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==0) n_trackerOnlyMuon_perEvent++;
401  if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==1) n_trackerStaOnlyMuon_perEvent++;
402 
403  if (muonMatch.isNonnull()) {
404  if (muCandRef->isGlobalMuon()==1) n_globalMuon_perEvent_MCmatch++;
405  if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==0 && muCandRef->isStandAloneMuon()==1) n_staOnlyMuon_perEvent_MCmatch++;
406  if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==0) n_trackerOnlyMuon_perEvent_MCmatch++;
407  if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1 && muCandRef->isStandAloneMuon()==1) n_trackerStaOnlyMuon_perEvent_MCmatch++;
408  double productCharge = muCandRef->charge() * muonMatch->charge();
409  if (muCandRef->isGlobalMuon()==1) {
410  h_GlobalMuonChargeTimeGenCharge->Fill(productCharge);
411  h_GlobalMuonEtaMinusGenEta->Fill(muCandRef->eta() - muonMatch->eta());
412  h_GlobalMuonPtMinusGenPt->Fill((muCandRef->pt() - muonMatch->pt())/muonMatch->pt());
413  h_GlobalMuonStaComponentEtaMinusGenEta->Fill(muStaComponentRef->eta() - muonMatch->eta());
414  h_GlobalMuonStaComponentPtMinusGenPt->Fill((muStaComponentRef->pt() - muonMatch->pt())/muonMatch->pt());
415  h_DEtaGlobalGenvsEtaGen->Fill(muonMatch->eta(),muCandRef->eta() - muonMatch->eta());
416  h_DPtGlobalGenvsPtGen->Fill(muonMatch->pt(),(muCandRef->pt() - muonMatch->pt())/muonMatch->pt());
417  h_DEtaGlobalStaComponentGenvsEtaGen->Fill(muonMatch->eta(),muStaComponentRef->eta() - muonMatch->eta());
418  h_DPtGlobalStaComponentGenvsPtGen->Fill(muonMatch->pt(),(muStaComponentRef->pt() - muonMatch->pt())/muonMatch->pt());
419  }
420  if (muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1) {
421  h_TrackerMuonChargeTimeGenCharge->Fill(productCharge);
422  h_TrackerMuonEtaMinusGenEta->Fill(muCandRef->eta() - muonMatch->eta());
423  h_TrackerMuonPtMinusGenPt->Fill((muCandRef->pt() - muonMatch->pt())/muonMatch->pt());
424  }
425  }
426  }
427  h_n_globalMuon_perEvent->Fill(n_globalMuon_perEvent);
428  h_n_staOnlyMuon_perEvent->Fill(n_staOnlyMuon_perEvent);
429  h_n_trackerOnlyMuon_perEvent->Fill(n_trackerOnlyMuon_perEvent);
430  h_n_trackerStaOnlyMuon_perEvent->Fill(n_trackerStaOnlyMuon_perEvent);
431  h_n_globalMuon_perEvent_MCmatch->Fill(n_globalMuon_perEvent_MCmatch);
432  h_n_staOnlyMuon_perEvent_MCmatch->Fill(n_staOnlyMuon_perEvent_MCmatch);
433  h_n_trackerOnlyMuon_perEvent_MCmatch->Fill(n_trackerOnlyMuon_perEvent_MCmatch);
434  h_n_trackerStaOnlyMuon_perEvent_MCmatch->Fill(n_trackerStaOnlyMuon_perEvent_MCmatch);
435  h_n_tracks_perEvent->Fill(tracks->size());
436 
437  h_n_zMuMu_perEvent->Fill(zMuMu->size());
438  h_n_zMuSta_perEvent->Fill(zMuStandAlone->size());
439  h_n_zMuTrack_perEvent->Fill(zMuTrack->size());
440 
441  // std::cout<<"Run-> "<<event.id().run()<<std::endl;
442  // std::cout<<"Event-> "<<event.id().event()<<std::endl;
443 
444 
445  // loop on ZMuMu
446  if (zMuMu->size() > 0 ) {
447  event.getByToken(zMuMuMatchMapToken_, zMuMuMatchMap);
448  event.getByToken(muonIsoToken_, muonIso);
449  event.getByToken(muonMatchMapToken_, muonMatchMap);
450  float muGenplus_pt = 0, muGenminus_pt = 0, muGenplus_eta = 100, muGenminus_eta = 100;
451  for(unsigned int i = 0; i < zMuMu->size(); ++i) { //loop on candidates
452  const Candidate & zMuMuCand = (*zMuMu)[i]; //the candidate
453  CandidateBaseRef zMuMuCandRef = zMuMu->refAt(i);
454  GenParticleRef zMuMuMatch = (*zMuMuMatchMap)[zMuMuCandRef];
455  bool isMCMatched = false;
456  if(zMuMuMatch.isNonnull()) {
457  isMCMatched = true; // ZMuMu matched
458  if(zMuMuMatch->pdgId() == 23 && zMuMuMatch->status()==3 && zMuMuMatch->numberOfDaughters() == 3) {
459  // Z0 decays in mu+ mu-, the 3rd daughter is the same Z0
460  const Candidate * dauGen0 = zMuMuMatch->daughter(0);
461  const Candidate * dauGen1 = zMuMuMatch->daughter(1);
462  const Candidate * dauGen2 = zMuMuMatch->daughter(2);
463  if (check_ifZmumu(dauGen0, dauGen1, dauGen2)) { // Z0 in mu+ mu-
464  muGenplus_pt = getParticlePt(-13,dauGen0,dauGen1,dauGen2);
465  muGenminus_pt = getParticlePt(13,dauGen0,dauGen1,dauGen2);
466  muGenplus_eta = getParticleEta(-13,dauGen0,dauGen1,dauGen2);
467  muGenminus_eta = getParticleEta(13,dauGen0,dauGen1,dauGen2);
468  Particle::LorentzVector pZ(0, 0, 0, 0);
469  Particle::LorentzVector muplusp4 = getParticleP4(-13,dauGen0,dauGen1,dauGen2);
470  Particle::LorentzVector muminusp4 = getParticleP4(13,dauGen0,dauGen1,dauGen2);
471  pZ = muplusp4 + muminusp4;
472  } // en if is Z
473  } // end if is Z->mumu
474 
475  }
476 
477  TrackRef as1 = zMuMuCand.daughter(0)->get<TrackRef,reco::StandAloneMuonTag>(); // standalone part of ZMuMu cand0
478  TrackRef as2 = zMuMuCand.daughter(1)->get<TrackRef,reco::StandAloneMuonTag>(); // standalone part of ZMuMu cand1
479  TrackRef a1 = zMuMuCand.daughter(0)->get<TrackRef,reco::CombinedMuonTag>(); // global part of ZMuMu cand0
480  TrackRef a2 = zMuMuCand.daughter(1)->get<TrackRef,reco::CombinedMuonTag>(); // global part of ZMuMu cand1
481  TrackRef at1 = zMuMuCand.daughter(0)->get<TrackRef>(); // tracker part of ZMuMu cand0
482  TrackRef at2 = zMuMuCand.daughter(1)->get<TrackRef>(); // tracker part of ZMuMu cand1
483 
484  math::XYZTLorentzVector ps1(as1->px(),as1->py(),as1->pz(),as1->p());
485  math::XYZTLorentzVector ps2(as2->px(),as2->py(),as2->pz(),as2->p());
486  math::XYZTLorentzVector pg1(a1->px(),a1->py(),a1->pz(),a1->p());
487  math::XYZTLorentzVector pg2(a2->px(),a2->py(),a2->pz(),a2->p());
488  math::XYZTLorentzVector ptrk1(at1->px(),at1->py(),at1->pz(),at1->p());
489  math::XYZTLorentzVector ptrk2(at2->px(),at2->py(),at2->pz(),at2->p());
490 
491  // double mass2global = (pg1+pg2).mass(); // inv. Mass done with the two global muons (is th same like m)
492  double massGlobalSta = (pg1+ps2).mass(); // inv. mass done with the global daughter(0) and the Sta part of Daughter(1)
493  double massStaGlobal = (ps1+pg2).mass(); // inv. mass done with the global daughter(1) and the Sta part of Daughter(0)
494  // double mass2Tracker = (ptrk1+ptrk2).mass(); // inv. mass done with the two tracker compnents
495  double massGlobalTracker = (pg1+ptrk2).mass(); // inv. mass done with the global daughter(0) and the tracker part of Daughter(1)
496  double massTrackerGlobal = (ptrk1+pg2).mass(); // inv. mass done with the global daughter(1) and the tracker part of Daughter(0)
497  double etaGlobal1 = a1->eta();
498  double etaGlobal2 = a2->eta();
499  double etaSta1 = as1->eta();
500  double etaSta2 = as2->eta();
501  double etaTracker1 = at1->eta();
502  double etaTracker2 = at2->eta();
503  // double phiGlobal1 = a1->phi();
504  // double phiGlobal2 = a2->phi();
505  double phiSta1 = as1->phi();
506  double phiSta2 = as2->phi();
507  double phiTracker1 = at1->phi();
508  double phiTracker2 = at2->phi();
509  double ptGlobal1 = a1->pt();
510  double ptGlobal2 = a2->pt();
511  double ptSta1 = as1->pt();
512  double ptSta2 = as2->pt();
513  double ptTracker1 = at1->pt();
514  double ptTracker2 = at2->pt();
515  double chargeGlobal1 = a1->charge();
516  double chargeGlobal2 = a2->charge();
517  double chargeSta1 = as1->charge();
518  double chargeSta2 = as2->charge();
519  double chargeTracker1 = at1->charge();
520  double chargeTracker2 = at2->charge();
521  double DR1 = deltaR(etaSta1, phiSta1, etaTracker1, phiTracker1);
522  double DR2 = deltaR(etaSta2, phiSta2, etaTracker2, phiTracker2);
523 
524  if (chargeGlobal1 == chargeGlobal2) {
525  nZMuMuSameSign++;
526  h_zMuMuMassSameSign->Fill(zMuMuCand.mass());
527  if (isMCMatched) {
529  h_zMuMuMassSameSign_MCmatch->Fill(zMuMuCand.mass());
530 
531  }
532  } else {
533  h_zMuMuMassOppositeSign->Fill(zMuMuCand.mass());
534  }
535 
536  bool etaCut = false;
537  bool ptCut = false;
538  //bool isoCut = false;
539  bool massCut = false;
540 
541  // ******************************************************************************************************************************
542  // Start study for StandAlone charge mis-id: select global-global events according to global1+track2 (or global2+track1)
543  // *******************************************************************************************************************************
544 
545  // cynematical cuts for Zglobal1Track2
546  if (abs(etaGlobal1)<etamax_ && abs(etaTracker2)<etamax_) etaCut = true;
547  if (ptGlobal1>ptmin_ && ptTracker2>ptmin_) ptCut = true;
548  if (massGlobalTracker>massMin_ && massGlobalTracker<massMax_) massCut = true;
549 
550  if (noCut_) {
551  etaCut = true;
552  ptCut = true;
553  massCut = true;
554  }
555 
556  if (etaCut && ptCut && massCut) {
557  // check first global1-track2 if they have opposite charge and if global1 has consistent charge between sta and track
558  if (chargeSta1 == chargeTracker1 && chargeTracker1 != chargeTracker2) { // event tagged to study StandAlone2 charge
560  h_zMuTrackMass_ZMuMuTagged->Fill(massGlobalTracker); // inv mass global+tracker part
561  h_etaTrack_ZMuMuTagged->Fill(etaTracker2); // eta of tagged track
562  h_phiTrack_ZMuMuTagged->Fill(phiTracker2); // phi of tagged track
563  h_ptTrack_ZMuMuTagged->Fill(ptTracker2); // pt of tagged track
564  h_DRTrack_ZMuMuTagged->Fill(DR2); // DR between sta2 and tracker2 for tagged track
565 
566  if (isMCMatched) { // if MC match .. resolution plots of global1 respect to gen particles
567  double etaGen, ptGen;
568  if (chargeGlobal1==1) {
569  etaGen = muGenplus_eta;
570  ptGen = muGenplus_pt;
571  } else {
572  etaGen = muGenminus_eta;
573  ptGen = muGenminus_pt;
574  }
575  h_GlobalMuonEtaMinusGenEta_ZMuMuTagged->Fill(etaGlobal1 - etaGen);
576  h_GlobalMuonPtMinusGenPt_ZMuMuTagged->Fill((ptGlobal1 - ptGen)/ptGen);
578  h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged->Fill((ptSta1 - ptGen)/ptGen);
579  h_DEtaGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaGlobal1-etaGen);
580  h_DPtGlobalGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptGlobal1-ptGen)/ptGen);
581  h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaSta1-etaGen);
582  h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptSta1-ptGen)/ptGen);
583  h_DPtGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptGlobal1-ptGen)/ptGen);
584  h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptSta1-ptGen)/ptGen);
585  h_DPtTrackGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptTracker1-ptGen)/ptGen);
586  h_DPtTrackGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptTracker1-ptGen)/ptGen);
587 
588  } // end if MC Match
589 
590  if (chargeSta2 == chargeTracker2) { // StandAlone2 has correct charge
592  h_zMuStaMass_correctStaCharge_ZMuMuTagged->Fill(massGlobalSta); // inv mass of global-Sta part for correct charge muons
593  h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged->Fill((ptSta2-ptTracker2)/ptTracker2);
594  h_ptStaMinusptTrack_vsEtaTracker_correctStaCharge_ZMuMuTagged->Fill(etaTracker2,(ptSta2-ptTracker2)/ptTracker2);
595  h_ptStaMinusptTrack_vsPtTracker_correctStaCharge_ZMuMuTagged->Fill(ptTracker2,(ptSta2-ptTracker2)/ptTracker2);
596  // qui posso aggiungere plot col MC match
597  }
598  if (chargeSta2 != chargeTracker2) { // StandAlone2 has wrong charge
600  h_zMuTrackMass_wrongStaCharge_ZMuMuTagged->Fill(massGlobalTracker); // inv mass global+tracker part (wrong Sta charge)
601  h_etaTrack_wrongStaCharge_ZMuMuTagged->Fill(etaTracker2); // eta of tagged track (wrong Sta charge)
602  h_phiTrack_wrongStaCharge_ZMuMuTagged->Fill(phiTracker2); // phi of tagged track (wrong Sta charge)
603  h_ptTrack_wrongStaCharge_ZMuMuTagged->Fill(ptTracker2); // pt of tagged track (wrong Sta charge)
604  h_DRTrack_wrongStaCharge_ZMuMuTagged->Fill(DR2); // DR between sta2 and tracker2 for tagged track (wrong Sta charge)
605  }
606  } // end if check chrge global1-tracker2
607  } // end if cut selection
608 
609  // cynematical cuts for Zglobal2Track1
610  etaCut = false;
611  ptCut = false;
612  massCut = false;
613  //isoCut = false;
614  if (abs(etaGlobal2)<etamax_ && abs(etaTracker1)<etamax_) etaCut = true;
615  if (ptGlobal2>ptmin_ && ptTracker1>ptmin_) ptCut = true;
616  if (massTrackerGlobal>massMin_ && massTrackerGlobal<massMax_) massCut = true;
617 
618  if (noCut_) {
619  etaCut = true;
620  ptCut = true;
621  massCut = true;
622  }
623 
624  if (etaCut && ptCut && massCut) {
625  // check global2-track1 if they have opposite charge and if global2 has consistent charge between sta and track
626  if (chargeSta2 == chargeTracker2 && chargeTracker1 != chargeTracker2) { // event tagged to study StandAlone2 charge
628  h_zMuTrackMass_ZMuMuTagged->Fill(massTrackerGlobal); // inv mass global+tracker part
629  h_etaTrack_ZMuMuTagged->Fill(etaTracker1); // eta of tagged track
630  h_phiTrack_ZMuMuTagged->Fill(phiTracker1); // phi of tagged track
631  h_ptTrack_ZMuMuTagged->Fill(ptTracker1); // pt of tagged track
632  h_DRTrack_ZMuMuTagged->Fill(DR1); // DR between sta1 and tracker1 for tagged track
633 
634  // qui posso aggiungere plot col MC match
635  if (isMCMatched) { // if MC match .. resolution plots of global2 respect to gen particles
636  double etaGen, ptGen;
637  if (chargeGlobal2==1) {
638  etaGen = muGenplus_eta;
639  ptGen = muGenplus_pt;
640  } else {
641  etaGen = muGenminus_eta;
642  ptGen = muGenminus_pt;
643  }
644  h_GlobalMuonEtaMinusGenEta_ZMuMuTagged->Fill(etaGlobal2 - etaGen);
645  h_GlobalMuonPtMinusGenPt_ZMuMuTagged->Fill((ptGlobal2 - ptGen)/ptGen);
647  h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged->Fill((ptSta2 - ptGen)/ptGen);
648  h_DEtaGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaGlobal2-etaGen);
649  h_DPtGlobalGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptGlobal2-ptGen)/ptGen);
650  h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,etaSta2-etaGen);
651  h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptSta2-ptGen)/ptGen);
652  h_DPtGlobalGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptGlobal2-ptGen)/ptGen);
653  h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptSta2-ptGen)/ptGen);
654  h_DPtTrackGenvsPtGen_ZMuMuTagged->Fill(ptGen,(ptTracker2-ptGen)/ptGen);
655  h_DPtTrackGenvsEtaGen_ZMuMuTagged->Fill(etaGen,(ptTracker2-ptGen)/ptGen);
656  } // end if MC Match
657 
658 
659  if (chargeSta1 == chargeTracker1) { // StandAlone1 has correct charge
661  h_zMuStaMass_correctStaCharge_ZMuMuTagged->Fill(massStaGlobal); // inv mass of Sta-global part for correct charge muons
662  h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged->Fill((ptSta1-ptTracker1)/ptTracker1);
663  h_ptStaMinusptTrack_vsEtaTracker_correctStaCharge_ZMuMuTagged->Fill(etaTracker1,(ptSta1-ptTracker1)/ptTracker1);
664  h_ptStaMinusptTrack_vsPtTracker_correctStaCharge_ZMuMuTagged->Fill(ptTracker1,(ptSta1-ptTracker1)/ptTracker1);
665 
666  }
667  if (chargeSta1 != chargeTracker1) { // StandAlone2 has wrong charge
669  h_zMuTrackMass_wrongStaCharge_ZMuMuTagged->Fill(massTrackerGlobal); // inv mass global+tracker part (wrong Sta charge)
670  h_etaTrack_wrongStaCharge_ZMuMuTagged->Fill(etaTracker1); // eta of tagged track (wrong Sta charge)
671  h_phiTrack_wrongStaCharge_ZMuMuTagged->Fill(phiTracker1); // phi of tagged track (wrong Sta charge)
672  h_ptTrack_wrongStaCharge_ZMuMuTagged->Fill(ptTracker1); // pt of tagged track (wrong Sta charge)
673  h_DRTrack_wrongStaCharge_ZMuMuTagged->Fill(DR1); // DR between sta1 and tracker1 for tagged track (wrong Sta charge)
674  }
675  } // end if check charge global1-tracker2
676  } // end if cuts
677 
678  // ******************************************************************************************************************************
679  // Start study for tracker charge mis-id: select global-global events according to global1+staComponent2 (or global2+staComponent1)
680  // *******************************************************************************************************************************
681 
682  etaCut = false;
683  ptCut = false;
684  //isoCut = false;
685  massCut = false;
686 
687  // cynematical cuts for Zglobal1Sta2
688  if (abs(etaGlobal1)<etamax_ && abs(etaSta2)<etamax_) etaCut = true;
689  if (ptGlobal1>ptmin_ && ptSta2>ptmin_) ptCut = true;
690  if (massGlobalSta>massMin_ && massGlobalSta<massMax_) massCut = true;
691 
692  if (noCut_) {
693  etaCut = true;
694  ptCut = true;
695  massCut = true;
696  }
697 
698  if (etaCut && ptCut && massCut) {
699  // check first global1-sta2 if they have opposite charge and if global1 has consistent charge between sta and track
700  if (chargeSta1 == chargeTracker1 && chargeTracker1 != chargeSta2) { // event tagged to study track2 charge
702  h_zMuStaMass_ZMuMuTagged->Fill(massGlobalSta); // inv mass global+sta part
703  h_etaSta_ZMuMuTagged->Fill(etaSta2); // eta of tagged sta
704  h_phiSta_ZMuMuTagged->Fill(phiSta2); // phi of tagged sta
705  h_ptSta_ZMuMuTagged->Fill(ptSta2); // pt of tagged sta
706  h_DRSta_ZMuMuTagged->Fill(DR2); // DR between sta2 and tracker2 for tagged sta
707 
708  if (chargeSta2 == chargeTracker2) { // track2 has correct charge
710  // qui posso aggiungere plot col MC match
711  }
712  if (chargeSta2 != chargeTracker2) { // track2 has wrong charge
714  h_zMuStaMass_wrongTrkCharge_ZMuMuTagged->Fill(massGlobalSta); // inv mass global+sta part (wrong Trk charge)
715  h_etaSta_wrongTrkCharge_ZMuMuTagged->Fill(etaSta2); // eta of tagged sta (wrong trk charge)
716  h_phiSta_wrongTrkCharge_ZMuMuTagged->Fill(phiSta2); // phi of tagged sta (wrong Trk charge)
717  h_ptSta_wrongTrkCharge_ZMuMuTagged->Fill(ptSta2); // pt of tagged sta (wrong Trk charge)
718  h_DRSta_wrongTrkCharge_ZMuMuTagged->Fill(DR2); // DR between sta2 and tracker2 for tagged sta (wrong trk charge)
719  }
720  } // end if check chrge global1-sta2
721  } // end if cut selection
722 
723  etaCut = false;
724  ptCut = false;
725  //isoCut = false;
726  massCut = false;
727 
728  // cynematical cuts for Zglobal2Sta1
729  if (abs(etaGlobal2)<etamax_ && abs(etaSta1)<etamax_) etaCut = true;
730  if (ptGlobal2>ptmin_ && ptSta1>ptmin_) ptCut = true;
731  if (massStaGlobal>massMin_ && massStaGlobal<massMax_) massCut = true;
732 
733  if (noCut_) {
734  etaCut = true;
735  ptCut = true;
736  massCut = true;
737  }
738 
739  if (etaCut && ptCut && massCut) {
740  // check first global2-sta1 if they have opposite charge and if global2 has consistent charge between sta and track
741  if (chargeSta2 == chargeTracker2 && chargeTracker2 != chargeSta1) { // event tagged to study track1 charge
743  h_zMuStaMass_ZMuMuTagged->Fill(massStaGlobal); // inv mass global+sta part
744  h_etaSta_ZMuMuTagged->Fill(etaSta1); // eta of tagged sta
745  h_phiSta_ZMuMuTagged->Fill(phiSta1); // phi of tagged sta
746  h_ptSta_ZMuMuTagged->Fill(ptSta1); // pt of tagged sta
747  h_DRSta_ZMuMuTagged->Fill(DR1); // DR between sta1 and tracker1 for tagged sta
748 
749  if (chargeSta1 == chargeTracker1) { // track1 has correct charge
751  // qui posso aggiungere plot col MC match
752  }
753  if (chargeSta1 != chargeTracker1) { // track1 has wrong charge
755  h_zMuStaMass_wrongTrkCharge_ZMuMuTagged->Fill(massStaGlobal); // inv mass global+sta part (wrong Trk charge)
756  h_etaSta_wrongTrkCharge_ZMuMuTagged->Fill(etaSta1); // eta of tagged sta (wrong trk charge)
757  h_phiSta_wrongTrkCharge_ZMuMuTagged->Fill(phiSta1); // phi of tagged sta (wrong Trk charge)
758  h_ptSta_wrongTrkCharge_ZMuMuTagged->Fill(ptSta1); // pt of tagged sta (wrong Trk charge)
759  h_DRSta_wrongTrkCharge_ZMuMuTagged->Fill(DR1); // DR between sta2 and tracker2 for tagged sta (wrong trk charge)
760  }
761  } // end if check chrge global2-sta1
762  } // end if cut selection
763 
764 
765  } // end loop on ZMuMu cand
766  } // end if ZMuMu size > 0
767 
768 
769  // loop on ZMuTrack in order to recover some unMatched StandAlone
770 
771  //double LargerDRCut=2.; // larger DR cut to recover unMatched Sta
772  int taggedZ_index = -1; // index of Z with minimum DR respect to unMatched Sta
773  int taggedMuon_index = -1; // index of Sta muon with minimum DR respect to unMatched track
774  int n_ZMuTrackTagged_inEvent = 0; // number of tagged Z in the event
775  if (zMuTrack->size() > 0 && zMuMu->size()==0) { // check ZMuTrack just if no ZMuMu has been found in the event
776  event.getByToken(zMuTrackMatchMapToken_, zMuTrackMatchMap);
777  for(unsigned int i = 0; i < zMuTrack->size(); ++i) { //loop on candidates
778  const Candidate & zMuTrackCand = (*zMuTrack)[i]; //the candidate
779  CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(i);
780  GenParticleRef zMuTrackMatch = (*zMuTrackMatchMap)[zMuTrackCandRef];
781  //bool isMCMatched = false;
782  //if(zMuTrackMatch.isNonnull()) isMCMatched = true; // ZMuTrack matched
783  // forzo isMCMatched
784  // isMCMatched = true;
785 
786  double m = zMuTrackCand.mass();
787  CandidateBaseRef zglobalDaughter = zMuTrackCand.daughter(0)->masterClone();
788  CandidateBaseRef ztrackerDaughter = zMuTrackCand.daughter(1)->masterClone();
789  TrackRef zglobalDaughter_StaComponentRef = zMuTrackCand.daughter(0)->get<TrackRef,reco::StandAloneMuonTag>();
790  // standalone part of global component of ZMuMu
791  TrackRef zglobalDaughter_TrackComponentRef = zMuTrackCand.daughter(0)->get<TrackRef>();
792  // track part Of the global component of ZMuMu
793  double ZtrackerDaughterCharge = ztrackerDaughter->charge();
794  double ZtrackerDaughterPt = ztrackerDaughter->pt();
795  double ZtrackerDaughterEta = ztrackerDaughter->eta();
796  double ZtrackerDaughterPhi = ztrackerDaughter->phi();
797  double ZglobalDaughterPt = zglobalDaughter->pt();
798  double ZglobalDaughterEta = zglobalDaughter->eta();
799  double ZglobalDaughter_StaComponentCharge = zglobalDaughter_StaComponentRef->charge();
800  double ZglobalDaughter_TrackComponentCharge = zglobalDaughter_TrackComponentRef->charge();
801 
802  //*********************************************************************************************************************
803  // study of standAlone charge mis-id and efficiency selecting ZMuTrack events (tag the index of Z and of muon)
804  // for Sta charge mis-id just use unMatched standAlone muons trackerMuons that are standAlone Muons but no globalMuons
805  // ********************************************************************************************************************
806  // cynematical cuts for ZMuTrack
807  bool etaCut = false;
808  bool ptCut = false;
809  // bool isoCut = false;
810  bool massCut = false;
811  if (abs(ZglobalDaughterEta)<etamax_ && abs(ZtrackerDaughterEta)<etamax_) etaCut = true;
812  if (ZglobalDaughterPt>ptmin_ && ZtrackerDaughterPt>ptmin_) ptCut = true;
813  if (m>massMin_ && m<massMax_) massCut = true;
814 
815  if (noCut_) {
816  etaCut = true;
817  ptCut = true;
818  massCut = true;
819  }
820  if (etaCut && ptCut && massCut && ZglobalDaughter_StaComponentCharge == ZglobalDaughter_TrackComponentCharge &&
821  ZglobalDaughter_TrackComponentCharge != ZtrackerDaughterCharge) { // cynematic cuts and global charge consistent and opposite tracker charge
822  n_ZMuTrackTagged_inEvent++;
823 
824  // posso inserire istogrammi eta e pt track per studio Sta efficiency
825  // ...
826 
827  for(unsigned int j = 0; j < muons->size() ; ++j) {
828  CandidateBaseRef muCandRef = muons->refAt(j);
829  const Candidate & muCand = (*muons)[j]; //the candidate
830  TrackRef muStaComponentRef = muCand.get<TrackRef,reco::StandAloneMuonTag>(); // standalone part of muon
831  TrackRef muTrkComponentRef = muCand.get<TrackRef>(); // track part of muon
832 
833  if (muCandRef->isStandAloneMuon()==1 && muCandRef->isGlobalMuon()==0 && muCandRef->isTrackerMuon()==1) {
834  double muEta = muCandRef->eta();
835  double muPhi = muCandRef->phi();
836  // check DeltaR between Sta muon and tracks of ZMuTrack
837  double DRmuSta_trackOfZ = deltaR(muEta, muPhi, ZtrackerDaughterEta, ZtrackerDaughterPhi);
838  if (DRmuSta_trackOfZ == 0) { // match track track ... standalone-muTracker
839  taggedZ_index = i;
840  taggedMuon_index = j;
841  } // end check minimum DR
842  } // end if isStandAlone
843  } // end loop on muon candidates
844  } // end cynematic cuts
845 
846  } // end loop on zMuTrack size
847  } // end if zMuTrack size > 0
848 
849  // analyze the tagged ZMuTRack and the Sta muons with minimal DR
850  if (n_ZMuTrackTagged_inEvent>0) { // at Least one ZMuTRack tagged
851 
852  if (taggedZ_index==-1) { // StandAlone inefficient
854  // h_etaTrack_StaNotFound_ZMuTrackTagged->Fill(ztrackerDaughter->eta());
855  } else {
856  const Candidate & zMuTrackCand = (*zMuTrack)[taggedZ_index]; //the candidate tagged
857  CandidateBaseRef zMuTrackCandRef = zMuTrack->refAt(taggedZ_index);
858  double m = zMuTrackCand.mass();
859  CandidateBaseRef zglobalDaughter = zMuTrackCand.daughter(0)->masterClone();
860  CandidateBaseRef ztrackerDaughter = zMuTrackCand.daughter(1)->masterClone();
861  TrackRef zglobalDaughter_StaComponentRef = zMuTrackCand.daughter(0)->get<TrackRef,reco::StandAloneMuonTag>();
862  // standalone part of global component of ZMuMu
863  TrackRef zglobalDaughter_TrackComponentRef = zMuTrackCand.daughter(0)->get<TrackRef>();
864  // track part Of the global component of ZMuMu
865  double ZtrackerDaughterCharge = ztrackerDaughter->charge();
866  double ZtrackerDaughterPt = ztrackerDaughter->pt();
867  double ZtrackerDaughterEta = ztrackerDaughter->eta();
868  double ZtrackerDaughterPhi = ztrackerDaughter->phi();
869 
870  CandidateBaseRef muCandRef = muons->refAt(taggedMuon_index); // the tagged muon
871  const Candidate & muCand = (*muons)[taggedMuon_index]; //the candidate
872  TrackRef muStaComponentRef = muCand.get<TrackRef,reco::StandAloneMuonTag>(); // standalone part of muon
873  TrackRef muTrkComponentRef = muCand.get<TrackRef>(); // track part of muon
874 
875  double muEta = muStaComponentRef->eta();
876  double muPhi = muStaComponentRef->phi();
877  double muCharge = muStaComponentRef->charge();
878  // check DeltaR between Sta muon and tracks of ZMuTrack
879  double DRmuSta_trackOfZ = deltaR(muEta, muPhi, ZtrackerDaughterEta, ZtrackerDaughterPhi);
880 
882  h_zMuTrackMass_ZMuTrackTagged->Fill(m); // inv mass ZMuTrack for tagged events
883  h_etaTrack_ZMuTrackTagged->Fill(ZtrackerDaughterEta); // eta of tagged track
884  h_phiTrack_ZMuTrackTagged->Fill(ZtrackerDaughterPhi); // phi of tagged track
885  h_ptTrack_ZMuTrackTagged->Fill(ZtrackerDaughterPt); // pt of tagged track
886  h_DRTrack_ZMuTrackTagged->Fill(DRmuSta_trackOfZ); // DR between sta1 and tracker1 for tagged track
887 
888  // check StandAlone charge
889  if (muCharge != ZtrackerDaughterCharge) { // wrong Sta charge
890  n_wrongStaCharge_ZMuTracktagged++; // number of events wrong charge for unMatched Sta
891  h_zMuTrackMass_wrongStaCharge_ZMuTrackTagged->Fill(m); // inv mass ZMuTrack for tagged events wrong unMatched Sta charge
892  h_etaTrack_wrongStaCharge_ZMuTrackTagged->Fill(ZtrackerDaughterEta); // eta of tagged track wrong unMatched Sta charge
893  h_phiTrack_wrongStaCharge_ZMuTrackTagged->Fill(ZtrackerDaughterPhi); // phi of tagged track wrong unMatched Sta charge
894  h_ptTrack_wrongStaCharge_ZMuTrackTagged->Fill(ZtrackerDaughterPt); // pt of tagged track wrong unMatched Sta charge
895  h_DRTrack_wrongStaCharge_ZMuTrackTagged->Fill(DRmuSta_trackOfZ); // DR between unMatched Sta and tracker for wrong sta charge
896  } else { // correct Sta charge
897  n_correctStaCharge_ZMuTracktagged++; // number of events correct charge for unMatched Sta
898  } // end if Sta charge check
899  } // end if StandAlone is present
900  } // end if zMuTrack tagged
901 
902  //*********************************************************************************************************************
903  // study of track charge mis-id and efficiency selecting ZMuSta events
904  // for Track charge mis-id just use unMatched standAlone muons trackerMuons that are standAlone Muons but no globalMuons
905  // ********************************************************************************************************************
906 
907  // loop on ZMuSta in order to recover some unMatched StandAlone
908  bool isZMuStaMatched=false;
909  //LargerDRCut=2.; // larger DR cut to recover unMatched Sta
910  taggedZ_index = -1; // index of Z with minimum DR respect to unMatched Sta
911  taggedMuon_index = -1; // index of Sta muon with minimum DR respect to unMatched track
912  int n_ZMuStaTagged_inEvent = 0; // number of tagged Z in the event
913  if (zMuStandAlone->size() > 0) { // check ZMuSta just if no ZMuMu has been found in the event
914  event.getByToken(zMuStandAloneMatchMapToken_, zMuStandAloneMatchMap);
915  for(unsigned int i = 0; i < zMuStandAlone->size(); ++i) { //loop on candidates
916  const Candidate & zMuStaCand = (*zMuStandAlone)[i]; //the candidate
917  CandidateBaseRef zMuStaCandRef = zMuStandAlone->refAt(i);
918 
919  GenParticleRef zMuStaMatch = (*zMuStandAloneMatchMap)[zMuStaCandRef];
920  if(zMuStaMatch.isNonnull()) { // ZMuSta Macthed
922  isZMuStaMatched = true;
923  }
924 
925  double m = zMuStaCand.mass();
926  CandidateBaseRef zglobalDaughter = zMuStaCand.daughter(0)->masterClone();
927  CandidateBaseRef zstandaloneDaughter = zMuStaCand.daughter(1)->masterClone();
928  int iglb = 0;
929  int ista = 1;
930  if (zglobalDaughter->isGlobalMuon()==0 && zstandaloneDaughter->isGlobalMuon()==1) { // invert definition
931  CandidateBaseRef buffer = zglobalDaughter;
932  zglobalDaughter = zstandaloneDaughter;
933  zstandaloneDaughter = buffer;
934  iglb = 1;
935  ista = 0;
936  }
937  TrackRef zglobalDaughter_StaComponentRef = zMuStaCand.daughter(iglb)->get<TrackRef,reco::StandAloneMuonTag>();
938  // standalone part of global component of ZMuMu
939  TrackRef zglobalDaughter_TrackComponentRef = zMuStaCand.daughter(iglb)->get<TrackRef>();
940  // track part Of the global component of ZMuMu
941  TrackRef zstaDaughter_StaComponentRef = zMuStaCand.daughter(ista)->get<TrackRef,reco::StandAloneMuonTag>();
942  // standalone part of global component of ZMuMu
943  TrackRef zstaDaughter_TrackComponentRef = zMuStaCand.daughter(ista)->get<TrackRef>();
944  // track part Of the global component of ZMuMu
945  double ZglobalDaughterPt = zglobalDaughter->pt();
946  double ZglobalDaughterEta = zglobalDaughter->eta();
947 
948  double ZstaDaughter_StaComponentCharge = zstaDaughter_StaComponentRef->charge();
949  double ZstaDaughter_StaComponentPt = zstaDaughter_StaComponentRef->pt();
950  double ZstaDaughter_StaComponentEta = zstaDaughter_StaComponentRef->eta();
951  double ZstaDaughter_StaComponentPhi = zstaDaughter_StaComponentRef->phi();
952  double ZstaDaughter_TrackComponentCharge = zstaDaughter_TrackComponentRef->charge();
953 
954  double ZglobalDaughter_StaComponentCharge = zglobalDaughter_StaComponentRef->charge();
955  double ZglobalDaughter_TrackComponentCharge = zglobalDaughter_TrackComponentRef->charge();
956 
957  // cynematical cuts for ZMuSta
958  bool etaCut = false;
959  bool ptCut = false;
960  // bool isoCut = false;
961  bool massCut = false;
962  if (abs(ZglobalDaughterEta)<etamax_ && abs(ZstaDaughter_StaComponentEta)<etamax_) etaCut = true;
963  if (ZglobalDaughterPt>ptmin_ && ZstaDaughter_StaComponentPt>ptmin_) ptCut = true;
964  if (m>massMin_ && m<massMax_) massCut = true; // dovrei usare la massa fatta con la sola parte sta
965  // (Se è anche trackerMu non è cosi')
966  if (noCut_) {
967  etaCut = true;
968  ptCut = true;
969  massCut = true;
970  }
971  if (etaCut && ptCut && massCut && ZglobalDaughter_StaComponentCharge == ZglobalDaughter_TrackComponentCharge &&
972  ZglobalDaughter_StaComponentCharge != ZstaDaughter_StaComponentCharge) { // cynematic cuts and global charge consistent and opposite sta charge
973  n_ZMuStaTagged_inEvent++;
974  if (isZMuStaMatched) n_ZMuStaTaggedMatched++;
975  // posso inserire istogrammi eta e pt track per studio Sta efficiency
976  // ...
977  if (zstandaloneDaughter->isStandAloneMuon()==1 && zstandaloneDaughter->isTrackerMuon()==1) { // track matched
979  h_zMuStaMass_ZMuStaTagged->Fill(m); // inv mass ZMuSta for tagged events
980  h_etaSta_ZMuStaTagged->Fill(ZstaDaughter_StaComponentEta); // eta of tagged sta
981  h_phiSta_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPhi); // phi of tagged sta
982  h_ptSta_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPt); // pt of tagged sta
983 
984  // check Track charge
985  if (ZstaDaughter_StaComponentCharge != ZstaDaughter_TrackComponentCharge) { // wrong Trk charge
986  n_wrongTrkCharge_ZMuStatagged++; // number of events wrong track charge for unMatched track
987  h_zMuStaMass_wrongTrkCharge_ZMuStaTagged->Fill(m); // inv mass ZMuSta for tagged evts wrong unMatched track charge
988  h_etaSta_wrongTrkCharge_ZMuStaTagged->Fill(ZstaDaughter_StaComponentEta); // eta of tagged sta wrong unMatched track charge
989  h_phiSta_wrongTrkCharge_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPhi); // phi of tagged sta wrong unMatched track charge
990  h_ptSta_wrongTrkCharge_ZMuStaTagged->Fill(ZstaDaughter_StaComponentPt); // pt of tagged sta wrong unMatched track charge
991  } else { // correct Sta charge
992  n_correctTrkCharge_ZMuStatagged++; // number of events correct charge for unMatched Sta
993  } // end if Sta charge check
994 
995  } else { // tracker inefficient
997  }
998  } // end cynematic cuts
999  if (n_ZMuStaTagged_inEvent==0) {
1000  }
1001 
1002 
1003  } // end loop on zMuSta candidates
1004  } // end check ZMuSta size
1005 
1006 } // end analyze
1007 
1008 bool ZMuMuPerformances::check_ifZmumu(const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
1009 {
1010  int partId0 = dauGen0->pdgId();
1011  int partId1 = dauGen1->pdgId();
1012  int partId2 = dauGen2->pdgId();
1013  bool muplusFound=false;
1014  bool muminusFound=false;
1015  bool ZFound=false;
1016  if (partId0==13 || partId1==13 || partId2==13) muminusFound=true;
1017  if (partId0==-13 || partId1==-13 || partId2==-13) muplusFound=true;
1018  if (partId0==23 || partId1==23 || partId2==23) ZFound=true;
1019  return muplusFound*muminusFound*ZFound;
1020 }
1021 
1022 float ZMuMuPerformances::getParticlePt(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
1023 {
1024  int partId0 = dauGen0->pdgId();
1025  int partId1 = dauGen1->pdgId();
1026  int partId2 = dauGen2->pdgId();
1027  float ptpart=0.;
1028  if (partId0 == ipart) {
1029  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
1030  const Candidate * dauMuGen = dauGen0->daughter(k);
1031  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1032  ptpart = dauMuGen->pt();
1033  }
1034  }
1035  }
1036  if (partId1 == ipart) {
1037  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
1038  const Candidate * dauMuGen = dauGen1->daughter(k);
1039  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1040  ptpart = dauMuGen->pt();
1041  }
1042  }
1043  }
1044  if (partId2 == ipart) {
1045  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
1046  const Candidate * dauMuGen = dauGen2->daughter(k);
1047  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
1048  ptpart = dauMuGen->pt();
1049  }
1050  }
1051  }
1052  return ptpart;
1053 }
1054 
1055 float ZMuMuPerformances::getParticleEta(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
1056 {
1057  int partId0 = dauGen0->pdgId();
1058  int partId1 = dauGen1->pdgId();
1059  int partId2 = dauGen2->pdgId();
1060  float etapart=0.;
1061  if (partId0 == ipart) {
1062  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
1063  const Candidate * dauMuGen = dauGen0->daughter(k);
1064  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1065  etapart = dauMuGen->eta();
1066  }
1067  }
1068  }
1069  if (partId1 == ipart) {
1070  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
1071  const Candidate * dauMuGen = dauGen1->daughter(k);
1072  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1073  etapart = dauMuGen->eta();
1074  }
1075  }
1076  }
1077  if (partId2 == ipart) {
1078  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
1079  const Candidate * dauMuGen = dauGen2->daughter(k);
1080  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
1081  etapart = dauMuGen->eta();
1082  }
1083  }
1084  }
1085  return etapart;
1086 }
1087 
1088 float ZMuMuPerformances::getParticlePhi(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
1089 {
1090  int partId0 = dauGen0->pdgId();
1091  int partId1 = dauGen1->pdgId();
1092  int partId2 = dauGen2->pdgId();
1093  float phipart=0.;
1094  if (partId0 == ipart) {
1095  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
1096  const Candidate * dauMuGen = dauGen0->daughter(k);
1097  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1098  phipart = dauMuGen->phi();
1099  }
1100  }
1101  }
1102  if (partId1 == ipart) {
1103  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
1104  const Candidate * dauMuGen = dauGen1->daughter(k);
1105  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1106  phipart = dauMuGen->phi();
1107  }
1108  }
1109  }
1110  if (partId2 == ipart) {
1111  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
1112  const Candidate * dauMuGen = dauGen2->daughter(k);
1113  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
1114  phipart = dauMuGen->phi();
1115  }
1116  }
1117  }
1118  return phipart;
1119 }
1120 
1121 Particle::LorentzVector ZMuMuPerformances::getParticleP4(const int ipart, const Candidate * dauGen0, const Candidate * dauGen1, const Candidate * dauGen2)
1122 {
1123  int partId0 = dauGen0->pdgId();
1124  int partId1 = dauGen1->pdgId();
1125  int partId2 = dauGen2->pdgId();
1126  Particle::LorentzVector p4part(0.,0.,0.,0.);
1127  if (partId0 == ipart) {
1128  for(unsigned int k = 0; k < dauGen0->numberOfDaughters(); ++k) {
1129  const Candidate * dauMuGen = dauGen0->daughter(k);
1130  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1131  p4part = dauMuGen->p4();
1132  }
1133  }
1134  }
1135  if (partId1 == ipart) {
1136  for(unsigned int k = 0; k < dauGen1->numberOfDaughters(); ++k) {
1137  const Candidate * dauMuGen = dauGen1->daughter(k);
1138  if(dauMuGen->pdgId() == ipart && dauMuGen->status() ==1) {
1139  p4part = dauMuGen->p4();
1140  }
1141  }
1142  }
1143  if (partId2 == ipart) {
1144  for(unsigned int k = 0; k < dauGen2->numberOfDaughters(); ++k) {
1145  const Candidate * dauMuGen = dauGen2->daughter(k);
1146  if(abs(dauMuGen->pdgId()) == ipart && dauMuGen->status() ==1) {
1147  p4part = dauMuGen->p4();
1148  }
1149  }
1150  }
1151  return p4part;
1152 }
1153 
1154 
1155 
1157 
1158  cout << "------------------------------------ Counters --------------------------------" << endl;
1159  cout << "totalNumberOfZfound = " << totalNumberOfZfound << endl;
1160  cout << "totalNumberOfZpassed = " << totalNumberOfZpassed << endl;
1161  cout << "Number Of ZMuMu Same Sign (no cuts) " << nZMuMuSameSign << endl;
1162  cout << "Number Of ZMuMu Same Sign (no cuts) MC matched " << nZMuMuSameSign_mcMatched << endl;
1163 
1164  cout << "------------------------------------ Counters for standAlone charge mis-id studies --------------------------------" << endl;
1165  cout << " number of goodTracks tagged for ZMuMu collection = " << n_goodTrack_ZMuMutagged << endl;
1166  cout << " number of goodTracks tagged for ZMuMu collection (correct Sta charge) = " << n_correctStaCharge_ZMuMutagged << endl;
1167  cout << " number of goodTracks tagged for ZMuMu collection (wrong Sta charge) = " << n_wrongStaCharge_ZMuMutagged << endl<<endl;
1168  cout << " number of goodTracks tagged for ZMuTrack collection unMatchedSTA = " << n_goodTrack_ZMuTracktagged << endl;
1169  cout << " number of goodTracks tagged for ZMuTrack collection unMatchedSTA (correct Sta charge) = " << n_correctStaCharge_ZMuTracktagged << endl;
1170  cout << " number of goodTracks tagged for ZMuTrack collection unMatchedSTA (wrong Sta charge) = " << n_wrongStaCharge_ZMuTracktagged << endl<<endl;
1171  cout << " number of goodTracks tagged for ZMuTrack collection (No STA found) = " << n_StaNotFound_ZMuTracktagged << endl;
1172 
1173  cout << "------------------------------------ Counters for Track charge mis-id studies --------------------------------" << endl;
1174  cout << " number of goodStandAlone tagged for ZMuMu collection = " << n_goodSta_ZMuMutagged << endl;
1175  cout << " number of goodStandAlone tagged for ZMuMu collection (correct Trk charge) = " << n_correctTrkCharge_ZMuMutagged << endl;
1176  cout << " number of goodStandAlone tagged for ZMuMu collection (wrong Trk charge) = " << n_wrongTrkCharge_ZMuMutagged << endl<<endl;
1177  cout << " number of goodSta tagged for ZMuSta collection unMatchedTrk = " << n_goodSta_ZMuStatagged << endl;
1178  cout << " number of goodSta tagged for ZMuSta collection unMatchedTrk (correct Trk charge) = " << n_correctTrkCharge_ZMuStatagged << endl;
1179  cout << " number of goodSta tagged for ZMuSta collection unMatchedTrk (wrong Trk charge) = " << n_wrongTrkCharge_ZMuStatagged << endl<<endl;
1180  cout << " number of goodSta tagged for ZMuSta collection (No Trk found) = " << n_TrkNotFound_ZMuStatagged << endl;
1181  cout << " number of ZMuSta mactched = " << numberOfMatchedZMuSta_ << endl;
1182  cout << " number of ZMuSta Tagged matched = " << n_ZMuStaTaggedMatched << endl;
1183 }
1184 
1186 
1188 
float getParticlePhi(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
EDGetTokenT< IsolationCollection > trackIsoToken_
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
float getParticleEta(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
TH1D * h_etaSta_wrongTrkCharge_ZMuMuTagged
TH1D * h_etaSta_wrongTrkCharge_ZMuStaTagged
TH1D * h_TrackerMuonEtaMinusGenEta
TH1D * h_phiSta_wrongTrkCharge_ZMuMuTagged
virtual bool isStandAloneMuon() const =0
TH1D * h_GlobalMuonStaComponentPtMinusGenPt_ZMuMuTagged
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TH1D * h_GlobalMuonStaComponentPtMinusGenPt
TH1D * h_ptStaMinusptTrack_correctStaCharge_ZMuMuTagged
EDGetTokenT< GenParticleCollection > genParticlesToken_
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
stand alone muon component tag
Definition: RecoCandidate.h:78
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:49
TH1D * h_DRTrack_wrongStaCharge_ZMuTrackTagged
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
ValueMap< float > IsolationCollection
size_type size() const
TH1D * h_zMuTrackMass_ZMuTrackTagged
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
TH2D * h_ptStaMinusptTrack_vsEtaTracker_correctStaCharge_ZMuMuTagged
TH1D * h_GlobalMuonStaComponentEtaMinusGenEta
bool check_ifZmumu(const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
TH1D * h_n_globalMuon_perEvent_MCmatch
TH2D * h_DPtTrackGenvsPtGen_ZMuMuTagged
float getParticlePt(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
TH2D * h_DPtGlobalStaComponentGenvsPtGen
RefToBase< value_type > refAt(size_type i) const
OverlapChecker overlap_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual bool isTrackerMuon() const =0
virtual int status() const =0
status word
TH1D * h_ptTrack_wrongStaCharge_ZMuMuTagged
TH1D * h_etaTrack_wrongStaCharge_ZMuMuTagged
EDGetTokenT< GenParticleMatch > muonMatchMapToken_
TH1D * h_n_trackerStaOnlyMuon_perEvent_MCmatch
TH1D * h_n_trackerStaOnlyMuon_perEvent
TH1D * h_zMuStaMass_correctStaCharge_ZMuMuTagged
TH1D * h_zMuStaMass_wrongTrkCharge_ZMuMuTagged
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
TH2D * h_DPtGlobalGenvsEtaGen_ZMuMuTagged
virtual int pdgId() const =0
PDG identifier.
EDGetTokenT< CandidateView > tracksToken_
EDGetTokenT< CandidateView > zMuTrackToken_
EDGetTokenT< GenParticleMatch > zMuStandAloneMatchMapToken_
TH1D * h_n_trackerOnlyMuon_perEvent
EDGetTokenT< GenParticleMatch > zMuTrackMatchMapToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TH1D * h_zMuStaMass_wrongTrkCharge_ZMuStaTagged
TH2D * h_DPtGlobalStaComponentGenvsEtaGen_ZMuMuTagged
TH2D * h_DPtGlobalStaComponentGenvsEtaGen
TH1D * h_DRSta_wrongTrkCharge_ZMuMuTagged
TH2D * h_DEtaGlobalStaComponentGenvsEtaGen_ZMuMuTagged
reco::CandidateBaseRef trackMuonCandRef_
ZMuMuPerformances(const edm::ParameterSet &pset)
TH2D * h_DPtTrackGenvsEtaGen_ZMuMuTagged
TH1D * h_n_staOnlyMuon_perEvent_MCmatch
EDGetTokenT< IsolationCollection > muonIsoToken_
TH1D * h_GlobalMuonEtaMinusGenEta_ZMuMuTagged
TH1D * h_GlobalMuonStaComponentEtaMinusGenEta_ZMuMuTagged
int k[5][pyjets_maxn]
virtual void endJob() override
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
TH2D * h_ptStaMinusptTrack_vsPtTracker_correctStaCharge_ZMuMuTagged
TH1D * h_phiSta_wrongTrkCharge_ZMuStaTagged
TH1D * h_zMuTrackMass_wrongStaCharge_ZMuTrackTagged
TH2D * h_DPtGlobalGenvsPtGen_ZMuMuTagged
virtual const CandidateBaseRef & masterClone() const =0
virtual bool isGlobalMuon() const =0
virtual double eta() const =0
momentum pseudorapidity
TH1D * h_TrackerMuonChargeTimeGenCharge
virtual double pt() const =0
transverse momentum
conbined muon component tag
Definition: RecoCandidate.h:80
TH1D * h_n_trackerOnlyMuon_perEvent_MCmatch
virtual double mass() const =0
mass
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
TH1D * h_DRTrack_wrongStaCharge_ZMuMuTagged
TH1D * h_GlobalMuonPtMinusGenPt_ZMuMuTagged
EDGetTokenT< CandidateView > zMuStandAloneToken_
TH1D * h_ptSta_wrongTrkCharge_ZMuStaTagged
TH1D * h_ptSta_wrongTrkCharge_ZMuMuTagged
virtual int charge() const =0
electric charge
EDGetTokenT< CandidateView > zMuMuToken_
fixed size matrix
HLT enums.
EDGetTokenT< GenParticleMatch > zMuMuMatchMapToken_
TH1D * h_GlobalMuonChargeTimeGenCharge
T get() const
get a component
Definition: Candidate.h:217
TH1D * h_zMuMuMassSameSign_MCmatch
TH1D * h_zMuTrackMass_wrongStaCharge_ZMuMuTagged
TH1D * h_etaTrack_wrongStaCharge_ZMuTrackTagged
TH2D * h_DEtaGlobalGenvsEtaGen_ZMuMuTagged
TH2D * h_DEtaGlobalStaComponentGenvsEtaGen
TH1D * h_phiTrack_wrongStaCharge_ZMuTrackTagged
virtual size_type numberOfDaughters() const =0
number of daughters
TH2D * h_DPtGlobalStaComponentGenvsPtGen_ZMuMuTagged
virtual double phi() const =0
momentum azimuthal angle
EDGetTokenT< CandidateView > muonsToken_
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup) override
Particle::LorentzVector getParticleP4(const int ipart, const Candidate *dauGen0, const Candidate *dauGen1, const Candidate *dauGen2)
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector
TH1D * h_ptTrack_wrongStaCharge_ZMuTrackTagged
TH1D * h_phiTrack_wrongStaCharge_ZMuMuTagged
virtual TrackRef standAloneMuon() const
reference to a stand-alone muon Track
Definition: Muon.h:52