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 */
18 
19 
20 using namespace edm;
21 
22 #include "TLorentzVector.h"
23 #include "TFile.h"
24 #include <vector>
25 #include "math.h"
26 
27 
30 
31 
34 
35 /* C++ Headers */
36 #include <iostream>
37 #include <fstream>
38 #include <cmath>
39 using namespace std;
40 using namespace edm;
41 
43  parameters = pSet;
44 }
45 
47 
49 
50  metname = "DiMuonhistograms";
51  LogTrace(metname)<<"[DiMuonHistograms] Parameters initialization";
52  dbe->setCurrentFolder("Muons/DiMuonHistograms");
53 
57 
58  etaBin = parameters.getParameter<int>("etaBin");
59  etaBBin = parameters.getParameter<int>("etaBBin");
60  etaEBin = parameters.getParameter<int>("etaEBin");
61 
62  etaBMin = parameters.getParameter<double>("etaBMin");
63  etaBMax = parameters.getParameter<double>("etaBMax");
64  etaECMin = parameters.getParameter<double>("etaECMin");
65  etaECMax = parameters.getParameter<double>("etaECMax");
66 
67  LowMassMin = parameters.getParameter<double>("LowMassMin");
68  LowMassMax = parameters.getParameter<double>("LowMassMax");
69  HighMassMin = parameters.getParameter<double>("HighMassMin");
70  HighMassMax = parameters.getParameter<double>("HighMassMax");
71 
72  int nBin = 0;
73  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
74  if (iEtaRegion==0) { EtaName = ""; nBin = etaBin;}
75  if (iEtaRegion==1) { EtaName = "_Barrel"; nBin = etaBBin;}
76  if (iEtaRegion==2) { EtaName = "_EndCap"; nBin = etaEBin;}
77 
78  GlbGlbMuon_LM.push_back(dbe->book1D("GlbGlbMuon_LM"+EtaName,"InvMass_{GLB,GLB}"+EtaName,nBin, LowMassMin, LowMassMax));
79  TrkTrkMuon_LM.push_back(dbe->book1D("TrkTrkMuon_LM"+EtaName,"InvMass_{TRK,TRK}"+EtaName,nBin, LowMassMin, LowMassMax));
80  StaTrkMuon_LM.push_back(dbe->book1D("StaTrkMuon_LM"+EtaName,"InvMass_{STA,TRK}"+EtaName,nBin, LowMassMin, LowMassMax));
81 
82  GlbGlbMuon_HM.push_back(dbe->book1D("GlbGlbMuon_HM"+EtaName,"InvMass_{GLB,GLB}"+EtaName,nBin, HighMassMin, HighMassMax));
83  TrkTrkMuon_HM.push_back(dbe->book1D("TrkTrkMuon_HM"+EtaName,"InvMass_{TRK,TRK}"+EtaName,nBin, HighMassMin, HighMassMax));
84  StaTrkMuon_HM.push_back(dbe->book1D("StaTrkMuon_HM"+EtaName,"InvMass_{STA,TRK}"+EtaName,nBin, HighMassMin, HighMassMax));
85 
86  // arround the Z peak
87  TightTightMuon.push_back(dbe->book1D("TightTightMuon"+EtaName,"InvMass_{Tight,Tight}"+EtaName,nBin, 55.0, 125.0));
88 
89  // low-mass resonances
90  SoftSoftMuon.push_back(dbe->book1D("SoftSoftMuon"+EtaName,"InvMass_{Soft,Soft}"+EtaName,nBin, 5.0, 55.0));
91  }
92 }
94 
95 
96  // ==========================================================
97  // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
98 
99  reco::Vertex::Point posVtx;
100  reco::Vertex::Error errVtx;
101 
102  unsigned int theIndexOfThePrimaryVertex = 999.;
103 
105  iEvent.getByLabel(vertexTag, vertex);
106 
107  if ( vertex.isValid() ){
108  for (unsigned int ind=0; ind<vertex->size(); ++ind) {
109  if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
110  theIndexOfThePrimaryVertex = ind;
111  break;
112  }
113  }
114  }
115  if (theIndexOfThePrimaryVertex<100) {
116  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
117  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
118  } else {
119  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
120 
121  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
122  iEvent.getByLabel(bsTag,recoBeamSpotHandle);
123 
124  reco::BeamSpot bs = *recoBeamSpotHandle;
125 
126  posVtx = bs.position();
127  errVtx(0,0) = bs.BeamWidthX();
128  errVtx(1,1) = bs.BeamWidthY();
129  errVtx(2,2) = bs.sigmaZ();
130  }
131  const reco::Vertex thePrimaryVertex(posVtx,errVtx);
132  // ==========================================================
133 
134 
135 
136 
137  LogTrace(metname)<<"[DiMuonHistograms] Analyze the mu in different eta regions";
139  iEvent.getByLabel(theMuonCollectionLabel, muons);
140 
142  Handle<reco::BeamSpot> beamSpotHandle;
143  iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
144  beamSpot = *beamSpotHandle;
145 
146  if(!muons.isValid()) return;
147 
148  // Loop on muon collection
149  TLorentzVector Mu1, Mu2;
150  float charge = 99.;
151  float InvMass = -99.;
152 
153  for (reco::MuonCollection::const_iterator recoMu1 = muons->begin(); recoMu1!=muons->end(); ++recoMu1) {
154  LogTrace(metname)<<"[DiMuonHistograms] loop over 1st muon"<<endl;
155 
156  // Loop on second muons to fill invariant mass plots
157  for (reco::MuonCollection::const_iterator recoMu2 = recoMu1; recoMu2!=muons->end(); ++recoMu2){
158  LogTrace(metname)<<"[DiMuonHistograms] loop over 2nd muon"<<endl;
159  if (recoMu1==recoMu2) continue;
160 
161  // Global-Global Muon
162  if (recoMu1->isGlobalMuon() && recoMu2->isGlobalMuon()) {
163  LogTrace(metname)<<"[DiMuonHistograms] Glb-Glb pair"<<endl;
164  reco::TrackRef recoCombinedGlbTrack1 = recoMu1->combinedMuon();
165  reco::TrackRef recoCombinedGlbTrack2 = recoMu2->combinedMuon();
166  Mu1.SetPxPyPzE(recoCombinedGlbTrack1->px(), recoCombinedGlbTrack1->py(),recoCombinedGlbTrack1->pz(), recoCombinedGlbTrack1->p());
167  Mu2.SetPxPyPzE(recoCombinedGlbTrack2->px(), recoCombinedGlbTrack2->py(),recoCombinedGlbTrack2->pz(), recoCombinedGlbTrack2->p());
168 
169  charge = recoCombinedGlbTrack1->charge()*recoCombinedGlbTrack2->charge();
170  if (charge < 0) {
171  InvMass = (Mu1+Mu2).M();
172  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
173  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
174  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
175  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
176 
177  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax &&
178  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax){
179  if (InvMass < LowMassMax) GlbGlbMuon_LM[iEtaRegion]->Fill(InvMass);
180  if (InvMass > HighMassMin) GlbGlbMuon_HM[iEtaRegion]->Fill(InvMass);
181  }
182  }
183  }
184  // Also Tight-Tight Muon Selection
185 
186  if ( muon::isTightMuon(*recoMu1, thePrimaryVertex) &&
187  muon::isTightMuon(*recoMu2, thePrimaryVertex) ) {
188 
189  LogTrace(metname)<<"[DiMuonHistograms] Tight-Tight pair"<<endl;
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(recoCombinedGlbTrack1->eta())>EtaCutMin && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax &&
196  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax){
197  if (InvMass > 55. && InvMass < 125.) TightTightMuon[iEtaRegion]->Fill(InvMass);
198  }
199  }
200  }
201  }
202 
203  // Now check for STA-TRK
204  if (recoMu2->isStandAloneMuon() && recoMu1->isTrackerMuon()) {
205  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
206  reco::TrackRef recoStaTrack = recoMu2->standAloneMuon();
207  reco::TrackRef recoTrack = recoMu1->track();
208  Mu2.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
209  Mu1.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
210 
211  charge = recoStaTrack->charge()*recoTrack->charge();
212  if (charge < 0) {
213  InvMass = (Mu1+Mu2).M();
214  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
215  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
216  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
217  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
218 
219  if(fabs(recoStaTrack->eta())>EtaCutMin && fabs(recoStaTrack->eta())<EtaCutMax &&
220  fabs(recoTrack->eta())>EtaCutMin && fabs(recoTrack->eta())<EtaCutMax){
221  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
222  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
223  }
224  }
225  }
226  }
227  if (recoMu1->isStandAloneMuon() && recoMu2->isTrackerMuon()) {
228  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
229  reco::TrackRef recoStaTrack = recoMu1->standAloneMuon();
230  reco::TrackRef recoTrack = recoMu2->track();
231  Mu1.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
232  Mu2.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
233 
234  charge = recoStaTrack->charge()*recoTrack->charge();
235  if (charge < 0) {
236  InvMass = (Mu1+Mu2).M();
237  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
238  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
239  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
240  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
241 
242  if(fabs(recoStaTrack->eta())>EtaCutMin && fabs(recoStaTrack->eta())<EtaCutMax &&
243  fabs(recoTrack->eta())>EtaCutMin && fabs(recoTrack->eta())<EtaCutMax){
244  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
245  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
246  }
247  }
248  }
249  }
250 
251  // TRK-TRK dimuon
252  if (recoMu1->isTrackerMuon() && recoMu2->isTrackerMuon()) {
253  LogTrace(metname)<<"[DiMuonHistograms] Trk-Trk dimuon pair"<<endl;
254  reco::TrackRef recoTrack2 = recoMu2->track();
255  reco::TrackRef recoTrack1 = recoMu1->track();
256  Mu2.SetPxPyPzE(recoTrack2->px(), recoTrack2->py(),recoTrack2->pz(), recoTrack2->p());
257  Mu1.SetPxPyPzE(recoTrack1->px(), recoTrack1->py(),recoTrack1->pz(), recoTrack1->p());
258 
259  charge = recoTrack1->charge()*recoTrack2->charge();
260  if (charge < 0) {
261  InvMass = (Mu1+Mu2).M();
262  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
263  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
264  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
265  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
266 
267  if(fabs(recoTrack1->eta())>EtaCutMin && fabs(recoTrack1->eta())<EtaCutMax &&
268  fabs(recoTrack2->eta())>EtaCutMin && fabs(recoTrack2->eta())<EtaCutMax){
269  if (InvMass < LowMassMax) TrkTrkMuon_LM[iEtaRegion]->Fill(InvMass);
270  if (InvMass > HighMassMin) TrkTrkMuon_HM[iEtaRegion]->Fill(InvMass);
271  }
272  }
273  }
274 
275 
276  LogTrace(metname)<<"[DiMuonHistograms] Soft-Soft pair"<<endl;
277 
278  if (muon::isSoftMuon(*recoMu1, thePrimaryVertex) &&
279  muon::isSoftMuon(*recoMu2, thePrimaryVertex) ) {
280 
281  if (charge < 0) {
282  InvMass = (Mu1+Mu2).M();
283  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
284  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
285  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
286  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
287 
288  if(fabs(recoTrack1->eta())>EtaCutMin && fabs(recoTrack1->eta())<EtaCutMax &&
289  fabs(recoTrack2->eta())>EtaCutMin && fabs(recoTrack2->eta())<EtaCutMax){
290  SoftSoftMuon[iEtaRegion]->Fill(InvMass);
291  }
292  }
293  }
294  }
295  }
296  } //muon2
297  } //Muon1
298 }
299 
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:722
std::vector< MonitorElement * > GlbGlbMuon_LM
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
edm::ParameterSet parameters
double charge(const std::vector< uint8_t > &Ampls)
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
bool isSoftMuon(const reco::Muon &, const reco::Vertex &)
int iEvent
Definition: GenABIO.cc:243
std::vector< MonitorElement * > SoftSoftMuon
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:87
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:361
edm::InputTag theMuonCollectionLabel
#define LogTrace(id)
edm::InputTag vertexTag
DiMuonHistograms(const edm::ParameterSet &pset, MuonServiceProxy *theService)
std::vector< MonitorElement * > TrkTrkMuon_HM
double sigmaZ() const
sigma z
Definition: BeamSpot.h:81
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:89
edm::InputTag bsTag
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
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
std::string EtaName
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434