CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DiMuonHistograms.cc
Go to the documentation of this file.
1 /* This Class Header */
3 
4 /* Collaborating Class Header */
14 
15 using namespace edm;
16 
17 #include "TLorentzVector.h"
18 #include "TFile.h"
19 #include <vector>
20 #include "math.h"
21 
22 
25 
26 
29 
30 /* C++ Headers */
31 #include <iostream>
32 #include <fstream>
33 #include <cmath>
34 using namespace std;
35 using namespace edm;
36 
38  parameters = pSet;
39 }
40 
42 
44 
45  metname = "DiMuonhistograms";
46  LogTrace(metname)<<"[DiMuonHistograms] Parameters initialization";
47  dbe->setCurrentFolder("Muons/DiMuonHistograms");
48 
50 
51  etaBin = parameters.getParameter<int>("etaBin");
52  etaBBin = parameters.getParameter<int>("etaBBin");
53  etaEBin = parameters.getParameter<int>("etaEBin");
54 
55  etaBMin = parameters.getParameter<double>("etaBMin");
56  etaBMax = parameters.getParameter<double>("etaBMax");
57  etaECMin = parameters.getParameter<double>("etaECMin");
58  etaECMax = parameters.getParameter<double>("etaECMax");
59 
60  LowMassMin = parameters.getParameter<double>("LowMassMin");
61  LowMassMax = parameters.getParameter<double>("LowMassMax");
62  HighMassMin = parameters.getParameter<double>("HighMassMin");
63  HighMassMax = parameters.getParameter<double>("HighMassMax");
64 
65  int nBin = 0;
66  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
67  if (iEtaRegion==0) { EtaName = ""; nBin = etaBin;}
68  if (iEtaRegion==1) { EtaName = "_Barrel"; nBin = etaBBin;}
69  if (iEtaRegion==2) { EtaName = "_EndCap"; nBin = etaEBin;}
70 
71  GlbGlbMuon_LM.push_back(dbe->book1D("GlbGlbMuon_LM"+EtaName,"InvMass_{GLB,GLB}"+EtaName,nBin, LowMassMin, LowMassMax));
72  TrkTrkMuon_LM.push_back(dbe->book1D("TrkTrkMuon_LM"+EtaName,"InvMass_{TRK,TRK}"+EtaName,nBin, LowMassMin, LowMassMax));
73  StaTrkMuon_LM.push_back(dbe->book1D("StaTrkMuon_LM"+EtaName,"InvMass_{STA,TRK}"+EtaName,nBin, LowMassMin, LowMassMax));
74 
75  GlbGlbMuon_HM.push_back(dbe->book1D("GlbGlbMuon_HM"+EtaName,"InvMass_{GLB,GLB}"+EtaName,nBin, HighMassMin, HighMassMax));
76  TrkTrkMuon_HM.push_back(dbe->book1D("TrkTrkMuon_HM"+EtaName,"InvMass_{TRK,TRK}"+EtaName,nBin, HighMassMin, HighMassMax));
77  StaTrkMuon_HM.push_back(dbe->book1D("StaTrkMuon_HM"+EtaName,"InvMass_{STA,TRK}"+EtaName,nBin, HighMassMin, HighMassMax));
78 
79  // arround the Z peak
80  TightTightMuon.push_back(dbe->book1D("TightTightMuon"+EtaName,"InvMass_{Tight,Tight}"+EtaName,nBin, 55.0, 125.0));
81 
82  // low-mass resonances
83  SoftSoftMuon.push_back(dbe->book1D("SoftSoftMuon"+EtaName,"InvMass_{Soft,Soft}"+EtaName,nBin, 5.0, 55.0));
84  }
85 }
87 
88  LogTrace(metname)<<"[DiMuonHistograms] Analyze the mu in different eta regions";
90  iEvent.getByLabel(theMuonCollectionLabel, muons);
91 
93  Handle<reco::BeamSpot> beamSpotHandle;
94  iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
95  beamSpot = *beamSpotHandle;
96 
97  if(!muons.isValid()) return;
98 
99  // Loop on muon collection
100  TLorentzVector Mu1, Mu2;
101  float charge = 99.;
102  float InvMass = -99.;
103 
104  for (reco::MuonCollection::const_iterator recoMu1 = muons->begin(); recoMu1!=muons->end(); ++recoMu1) {
105  LogTrace(metname)<<"[DiMuonHistograms] loop over 1st muon"<<endl;
106 
107  // Loop on second muons to fill invariant mass plots
108  for (reco::MuonCollection::const_iterator recoMu2 = recoMu1; recoMu2!=muons->end(); ++recoMu2){
109  LogTrace(metname)<<"[DiMuonHistograms] loop over 2nd muon"<<endl;
110  if (recoMu1==recoMu2) continue;
111 
112  // Global-Global Muon
113  if (recoMu1->isGlobalMuon() && recoMu2->isGlobalMuon()) {
114  LogTrace(metname)<<"[DiMuonHistograms] Glb-Glb pair"<<endl;
115  reco::TrackRef recoCombinedGlbTrack1 = recoMu1->combinedMuon();
116  reco::TrackRef recoCombinedGlbTrack2 = recoMu2->combinedMuon();
117  Mu1.SetPxPyPzE(recoCombinedGlbTrack1->px(), recoCombinedGlbTrack1->py(),recoCombinedGlbTrack1->pz(), recoCombinedGlbTrack1->p());
118  Mu2.SetPxPyPzE(recoCombinedGlbTrack2->px(), recoCombinedGlbTrack2->py(),recoCombinedGlbTrack2->pz(), recoCombinedGlbTrack2->p());
119 
120  charge = recoCombinedGlbTrack1->charge()*recoCombinedGlbTrack2->charge();
121  if (charge < 0) {
122  InvMass = (Mu1+Mu2).M();
123  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
124  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
125  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
126  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
127 
128  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax &&
129  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax){
130  if (InvMass < LowMassMax) GlbGlbMuon_LM[iEtaRegion]->Fill(InvMass);
131  if (InvMass > HighMassMin) GlbGlbMuon_HM[iEtaRegion]->Fill(InvMass);
132  }
133  }
134  }
135  // Also Tight-Tight Muon Selection
136  if (recoMu1->isGlobalMuon() && recoMu1->isTrackerMuon() && recoMu1->combinedMuon()->normalizedChi2()<10.
137  && recoMu1->combinedMuon()->hitPattern().numberOfValidMuonHits()>0 && fabs(recoMu1->combinedMuon()->dxy(beamSpot.position()))<0.2
138  && recoMu1->combinedMuon()->hitPattern().numberOfValidPixelHits()>0 && recoMu1->numberOfMatches() > 1
139  && recoMu2->isGlobalMuon() && recoMu2->isTrackerMuon() && recoMu2->combinedMuon()->normalizedChi2()<10.
140  && recoMu2->combinedMuon()->hitPattern().numberOfValidMuonHits()>0 && fabs(recoMu2->combinedMuon()->dxy(beamSpot.position()))<0.2
141  && recoMu2->combinedMuon()->hitPattern().numberOfValidPixelHits()>0 && recoMu2->numberOfMatches() > 1) {
142  LogTrace(metname)<<"[DiMuonHistograms] Tight-Tight pair"<<endl;
143  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
144  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
145  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
146  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
147 
148  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax &&
149  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax){
150  if (InvMass > 55. && InvMass < 125.) TightTightMuon[iEtaRegion]->Fill(InvMass);
151  }
152  }
153  }
154  }
155 
156  // Now check for STA-TRK
157  if (recoMu2->isStandAloneMuon() && recoMu1->isTrackerMuon()) {
158  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
159  reco::TrackRef recoStaTrack = recoMu2->standAloneMuon();
160  reco::TrackRef recoTrack = recoMu1->track();
161  Mu2.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
162  Mu1.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
163 
164  charge = recoStaTrack->charge()*recoTrack->charge();
165  if (charge < 0) {
166  InvMass = (Mu1+Mu2).M();
167  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
168  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
169  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
170  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
171 
172  if(fabs(recoStaTrack->eta())>EtaCutMin && fabs(recoStaTrack->eta())<EtaCutMax &&
173  fabs(recoTrack->eta())>EtaCutMin && fabs(recoTrack->eta())<EtaCutMax){
174  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
175  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
176  }
177  }
178  }
179  }
180  if (recoMu1->isStandAloneMuon() && recoMu2->isTrackerMuon()) {
181  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
182  reco::TrackRef recoStaTrack = recoMu1->standAloneMuon();
183  reco::TrackRef recoTrack = recoMu2->track();
184  Mu1.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
185  Mu2.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
186 
187  charge = recoStaTrack->charge()*recoTrack->charge();
188  if (charge < 0) {
189  InvMass = (Mu1+Mu2).M();
190  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
191  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
192  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
193  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
194 
195  if(fabs(recoStaTrack->eta())>EtaCutMin && fabs(recoStaTrack->eta())<EtaCutMax &&
196  fabs(recoTrack->eta())>EtaCutMin && fabs(recoTrack->eta())<EtaCutMax){
197  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
198  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
199  }
200  }
201  }
202  }
203 
204  // TRK-TRK dimuon
205  if (recoMu1->isTrackerMuon() && recoMu2->isTrackerMuon()) {
206  LogTrace(metname)<<"[DiMuonHistograms] Trk-Trk dimuon pair"<<endl;
207  reco::TrackRef recoTrack2 = recoMu2->track();
208  reco::TrackRef recoTrack1 = recoMu1->track();
209  Mu2.SetPxPyPzE(recoTrack2->px(), recoTrack2->py(),recoTrack2->pz(), recoTrack2->p());
210  Mu1.SetPxPyPzE(recoTrack1->px(), recoTrack1->py(),recoTrack1->pz(), recoTrack1->p());
211 
212  charge = recoTrack1->charge()*recoTrack2->charge();
213  if (charge < 0) {
214  InvMass = (Mu1+Mu2).M();
215  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
216  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
217  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
218  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
219 
220  if(fabs(recoTrack1->eta())>EtaCutMin && fabs(recoTrack1->eta())<EtaCutMax &&
221  fabs(recoTrack2->eta())>EtaCutMin && fabs(recoTrack2->eta())<EtaCutMax){
222  if (InvMass < LowMassMax) TrkTrkMuon_LM[iEtaRegion]->Fill(InvMass);
223  if (InvMass > HighMassMin) TrkTrkMuon_HM[iEtaRegion]->Fill(InvMass);
224  }
225  }
226  }
227 
228  if (recoMu1->isTrackerMuon() && recoMu2->isTrackerMuon() &&
229  recoMu1->innerTrack()->found() > 11 && recoMu2->innerTrack()->found() &&
230  recoMu1->innerTrack()->chi2()/recoMu1->innerTrack()->ndof() < 4.0 &&
231  recoMu2->innerTrack()->chi2()/recoMu2->innerTrack()->ndof() < 4.0 &&
232  recoMu1->numberOfMatches() > 0 && recoMu2->numberOfMatches() > 0 &&
233  recoMu1->innerTrack()->hitPattern().pixelLayersWithMeasurement() > 1 &&
234  recoMu2->innerTrack()->hitPattern().pixelLayersWithMeasurement() > 1 &&
235  fabs(recoMu1->innerTrack()->dxy()) < 3.0 && fabs(recoMu1->innerTrack()->dxy()) < 3.0 &&
236  fabs(recoMu1->innerTrack()->dz()) < 15.0 && fabs(recoMu1->innerTrack()->dz()) < 15.0){
237 
238  if (charge < 0) {
239  InvMass = (Mu1+Mu2).M();
240  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
241  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
242  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
243  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
244 
245  if(fabs(recoTrack1->eta())>EtaCutMin && fabs(recoTrack1->eta())<EtaCutMax &&
246  fabs(recoTrack2->eta())>EtaCutMin && fabs(recoTrack2->eta())<EtaCutMax){
247  SoftSoftMuon[iEtaRegion]->Fill(InvMass);
248  }
249  }
250  }
251  }
252  }
253  } //muon2
254  } //Muon1
255 }
256 
T getParameter(std::string const &) const
std::string metname
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
std::vector< MonitorElement * > GlbGlbMuon_LM
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
edm::ParameterSet parameters
double charge(const std::vector< uint8_t > &Ampls)
int iEvent
Definition: GenABIO.cc:243
std::vector< MonitorElement * > SoftSoftMuon
std::vector< MonitorElement * > TrkTrkMuon_LM
void beginJob(DQMStore *dbe)
Inizialize parameters for histo binning.
std::vector< MonitorElement * > StaTrkMuon_LM
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag theMuonCollectionLabel
#define LogTrace(id)
DiMuonHistograms(const edm::ParameterSet &pset, MuonServiceProxy *theService)
std::vector< MonitorElement * > TrkTrkMuon_HM
virtual ~DiMuonHistograms()
tuple muons
Definition: patZpeak.py:38
std::vector< MonitorElement * > StaTrkMuon_HM
std::vector< MonitorElement * > GlbGlbMuon_HM
const Point & position() const
position
Definition: BeamSpot.h:63
std::vector< MonitorElement * > TightTightMuon
std::string EtaName
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429