CMS 3D CMS Logo

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