CMS 3D CMS Logo

DiMuonHistograms.cc
Go to the documentation of this file.
1 /* This Class Header */
3 
4 /* Collaborating Class Header */
16 
19 
20 #include "TLorentzVector.h"
21 #include "TFile.h"
22 #include <vector>
23 #include <cmath>
24 
25 /* C++ Headers */
26 #include <iostream>
27 #include <fstream>
28 #include <cmath>
29 using namespace std;
30 using namespace edm;
31 
33 
34  // initialise parameters:
35  parameters = pSet;
36 
37  // counter
38  nTightTight = 0;
39  nMediumMedium = 0;
40  nLooseLoose = 0;
41  nGlbGlb = 0;
42 
43  // declare consumes:
44  theMuonCollectionLabel_ = consumes<edm::View<reco::Muon> > (parameters.getParameter<edm::InputTag>("MuonCollection"));
45  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
46 
47  theBeamSpotLabel_ = mayConsume<reco::BeamSpot> (parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
48 
49  etaBin = parameters.getParameter<int>("etaBin");
50  etaBBin = parameters.getParameter<int>("etaBBin");
51  etaEBin = parameters.getParameter<int>("etaEBin");
52 
53  etaBMin = parameters.getParameter<double>("etaBMin");
54  etaBMax = parameters.getParameter<double>("etaBMax");
55  etaECMin = parameters.getParameter<double>("etaECMin");
56  etaECMax = parameters.getParameter<double>("etaECMax");
57 
58  LowMassMin = parameters.getParameter<double>("LowMassMin");
59  LowMassMax = parameters.getParameter<double>("LowMassMax");
60  HighMassMin = parameters.getParameter<double>("HighMassMin");
61  HighMassMax = parameters.getParameter<double>("HighMassMax");
62 
63  theFolder = parameters.getParameter<string>("folder");
64 }
65 
67 
69  edm::Run const & /*iRun*/,
70  edm::EventSetup const & /* iSetup */){
71 
72  ibooker.cd();
73  ibooker.setCurrentFolder(theFolder);
74 
75  int nBin[3] = {etaBin,etaBBin,etaEBin};
76  EtaName[0] = ""; EtaName[1] = "_Barrel"; EtaName[2] = "_EndCap";
77  test = ibooker.book1D("test","InvMass_{Tight,Tight}",100, 0., 200.);
78  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
79 
80  GlbGlbMuon_LM.push_back(ibooker.book1D("GlbGlbMuon_LM"+EtaName[iEtaRegion],"InvMass_{GLB,GLB}"+EtaName[iEtaRegion],nBin[iEtaRegion], LowMassMin, LowMassMax));
81  TrkTrkMuon_LM.push_back(ibooker.book1D("TrkTrkMuon_LM"+EtaName[iEtaRegion],"InvMass_{TRK,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], LowMassMin, LowMassMax));
82  StaTrkMuon_LM.push_back(ibooker.book1D("StaTrkMuon_LM"+EtaName[iEtaRegion],"InvMass_{STA,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], LowMassMin, LowMassMax));
83 
84  GlbGlbMuon_HM.push_back(ibooker.book1D("GlbGlbMuon_HM"+EtaName[iEtaRegion],"InvMass_{GLB,GLB}"+EtaName[iEtaRegion],nBin[iEtaRegion], HighMassMin, HighMassMax));
85  TrkTrkMuon_HM.push_back(ibooker.book1D("TrkTrkMuon_HM"+EtaName[iEtaRegion],"InvMass_{TRK,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], HighMassMin, HighMassMax));
86  StaTrkMuon_HM.push_back(ibooker.book1D("StaTrkMuon_HM"+EtaName[iEtaRegion],"InvMass_{STA,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], HighMassMin, HighMassMax));
87 
88  // arround the Z peak
89  TightTightMuon.push_back(ibooker.book1D("TightTightMuon"+EtaName[iEtaRegion],"InvMass_{Tight,Tight}"+EtaName[iEtaRegion], nBin[iEtaRegion], LowMassMin, LowMassMax));
90  MediumMediumMuon.push_back(ibooker.book1D("MediumMediumMuon"+EtaName[iEtaRegion],"InvMass_{Medium,Medium}"+EtaName[iEtaRegion],nBin[iEtaRegion], LowMassMin, LowMassMax));
91  LooseLooseMuon.push_back(ibooker.book1D("LooseLooseMuon"+EtaName[iEtaRegion],"InvMass_{Loose,Loose}"+EtaName[iEtaRegion], nBin[iEtaRegion], LowMassMin, LowMassMax));
92  //Fraction of bad hits in the tracker track to the total
93  TightTightMuonBadFrac.push_back(ibooker.book1D("TightTightMuonBadFrac"+EtaName[iEtaRegion],"BadFrac_{Tight,Tight}"+EtaName[iEtaRegion], 10, 0, 0.4));
94  MediumMediumMuonBadFrac.push_back(ibooker.book1D("MediumMediumMuonBadFrac"+EtaName[iEtaRegion],"BadFrac_{Medium,Medium}"+EtaName[iEtaRegion], 10, 0, 0.4));
95  LooseLooseMuonBadFrac.push_back(ibooker.book1D("LooseLooseMuonBadFrac"+EtaName[iEtaRegion],"BadFrac_{Loose,Loose}"+EtaName[iEtaRegion], 10, 0, 0.4));
96 
97  // low-mass resonances
98  SoftSoftMuon.push_back(ibooker.book1D("SoftSoftMuon"+EtaName[iEtaRegion],"InvMass_{Soft,Soft}"+EtaName[iEtaRegion],nBin[iEtaRegion], 0.0, 55.0));
99  SoftSoftMuonBadFrac.push_back(ibooker.book1D("SoftSoftMuonBadFrac"+EtaName[iEtaRegion],"BadFrac_{Soft,Soft}"+EtaName[iEtaRegion], 10, 0, 0.4));
100 
101  }
102 }
103 
105 
106  LogTrace(metname)<<"[DiMuonHistograms] Analyze the mu in different eta regions";
108  iEvent.getByToken(theMuonCollectionLabel_, muons);
109 
110  // =================================================================================
111  // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
112  reco::Vertex::Point posVtx;
113  reco::Vertex::Error errVtx;
114  unsigned int theIndexOfThePrimaryVertex = 999.;
115 
117  iEvent.getByToken(theVertexLabel_, vertex);
118  if (vertex.isValid()){
119  for (unsigned int ind=0; ind<vertex->size(); ++ind) {
120  if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
121  theIndexOfThePrimaryVertex = ind;
122  break;
123  }
124  }
125  }
126 
127  if (theIndexOfThePrimaryVertex<100) {
128  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
129  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
130  }
131  else {
132  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
133 
134  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
135  iEvent.getByToken(theBeamSpotLabel_,recoBeamSpotHandle);
136  reco::BeamSpot bs = *recoBeamSpotHandle;
137 
138  posVtx = bs.position();
139  errVtx(0,0) = bs.BeamWidthX();
140  errVtx(1,1) = bs.BeamWidthY();
141  errVtx(2,2) = bs.sigmaZ();
142  }
143 
144  const reco::Vertex vtx(posVtx,errVtx);
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  //Eta regions
154  double EtaCutMin[] = {0, etaBMin, etaECMin};
155  double EtaCutMax[] = {2.4, etaBMax, etaECMax};
156 
157  for (edm::View<reco::Muon>::const_iterator muon1 = muons->begin(); muon1 != muons->end(); ++muon1){
158  LogTrace(metname)<<"[DiMuonHistograms] loop over 1st muon"<<endl;
159 
160  // Loop on second muons to fill invariant mass plots
161  for (edm::View<reco::Muon>::const_iterator muon2 = muon1; muon2 != muons->end(); ++muon2){
162  LogTrace(metname)<<"[DiMuonHistograms] loop over 2nd muon"<<endl;
163  if (muon1==muon2) continue;
164 
165  // Global-Global Muon
166  if (muon1->isGlobalMuon() && muon2->isGlobalMuon()) {
167  LogTrace(metname)<<"[DiMuonHistograms] Glb-Glb pair"<<endl;
168  reco::TrackRef recoCombinedGlbTrack1 = muon1->combinedMuon();
169  reco::TrackRef recoCombinedGlbTrack2 = muon2->combinedMuon();
170  Mu1.SetPxPyPzE(recoCombinedGlbTrack1->px(), recoCombinedGlbTrack1->py(),recoCombinedGlbTrack1->pz(), recoCombinedGlbTrack1->p());
171  Mu2.SetPxPyPzE(recoCombinedGlbTrack2->px(), recoCombinedGlbTrack2->py(),recoCombinedGlbTrack2->pz(), recoCombinedGlbTrack2->p());
172 
173  charge = recoCombinedGlbTrack1->charge()*recoCombinedGlbTrack2->charge();
174  if (charge < 0) {
175  InvMass = (Mu1+Mu2).M();
176  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
177  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax[iEtaRegion] &&
178  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax[iEtaRegion]){
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  if ( muon::isTightMuon(*muon1, vtx) &&
186  muon::isTightMuon(*muon2, vtx) ) {
187  test->Fill(InvMass);
188  LogTrace(metname)<<"[DiMuonHistograms] Tight-Tight pair"<<endl;
189  if (charge < 0){
190  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
191  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax[iEtaRegion] &&
192  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax[iEtaRegion]){
193  if (InvMass > 55. && InvMass < 125.) {
194  TightTightMuon[iEtaRegion]->Fill(InvMass);
195  TightTightMuonBadFrac[iEtaRegion]->Fill(muon1->innerTrack()->lost()/muon1->innerTrack()->found());
196  }
197  }
198  }
199  }
200  }
201  // Also Medium-Medium Muon Selection
202  if ( muon::isMediumMuon(*muon1) &&
203  muon::isMediumMuon(*muon2) ) {
204  test->Fill(InvMass);
205  LogTrace(metname)<<"[DiMuonHistograms] Medium-Medium pair"<<endl;
206  if (charge < 0){
207  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
208  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax[iEtaRegion] &&
209  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax[iEtaRegion]){
210  if (InvMass > 55. && InvMass < 125.) {
211  MediumMediumMuon[iEtaRegion]->Fill(InvMass);
212  MediumMediumMuonBadFrac[iEtaRegion]->Fill(muon1->innerTrack()->lost()/muon1->innerTrack()->found());
213  }
214  }
215  }
216  }
217  }
218  // Also Loose-Loose Muon Selection
219  if ( muon::isLooseMuon(*muon1) &&
220  muon::isLooseMuon(*muon2) ) {
221  test->Fill(InvMass);
222  LogTrace(metname)<<"[DiMuonHistograms] Loose-Loose pair"<<endl;
223  if (charge < 0){
224  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
225  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax[iEtaRegion] &&
226  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin[iEtaRegion] && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax[iEtaRegion]){
227  if (InvMass > 55. && InvMass < 125.) {
228  LooseLooseMuon[iEtaRegion]->Fill(InvMass);
229  LooseLooseMuonBadFrac[iEtaRegion]->Fill(muon1->innerTrack()->lost()/muon1->innerTrack()->found());
230  }
231  }
232  }
233  }
234  }
235  }
236 
237  // Now check for STA-TRK
238  if (muon2->isStandAloneMuon() && muon1->isTrackerMuon()) {
239  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
240  reco::TrackRef recoStaTrack = muon2->standAloneMuon();
241  reco::TrackRef recoTrack = muon1->track();
242  Mu2.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
243  Mu1.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
244 
245  charge = recoStaTrack->charge()*recoTrack->charge();
246  if (charge < 0) {
247  InvMass = (Mu1+Mu2).M();
248  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
249  if(fabs(recoStaTrack->eta())>EtaCutMin[iEtaRegion] && fabs(recoStaTrack->eta())<EtaCutMax[iEtaRegion] &&
250  fabs(recoTrack->eta())>EtaCutMin[iEtaRegion] && fabs(recoTrack->eta())<EtaCutMax[iEtaRegion]){
251  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
252  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
253  }
254  }
255  }
256  }
257  if (muon1->isStandAloneMuon() && muon2->isTrackerMuon()) {
258  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
259  reco::TrackRef recoStaTrack = muon1->standAloneMuon();
260  reco::TrackRef recoTrack = muon2->track();
261  Mu1.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
262  Mu2.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
263 
264  charge = recoStaTrack->charge()*recoTrack->charge();
265  if (charge < 0) {
266  InvMass = (Mu1+Mu2).M();
267  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
268  if(fabs(recoStaTrack->eta())>EtaCutMin[iEtaRegion] && fabs(recoStaTrack->eta())<EtaCutMax[iEtaRegion] &&
269  fabs(recoTrack->eta())>EtaCutMin[iEtaRegion] && fabs(recoTrack->eta())<EtaCutMax[iEtaRegion]){
270  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
271  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
272  }
273  }
274  }
275  }
276 
277  // TRK-TRK dimuon
278  if (muon1->isTrackerMuon() && muon2->isTrackerMuon()) {
279  LogTrace(metname)<<"[DiMuonHistograms] Trk-Trk dimuon pair"<<endl;
280  reco::TrackRef recoTrack2 = muon2->track();
281  reco::TrackRef recoTrack1 = muon1->track();
282  Mu2.SetPxPyPzE(recoTrack2->px(), recoTrack2->py(),recoTrack2->pz(), recoTrack2->p());
283  Mu1.SetPxPyPzE(recoTrack1->px(), recoTrack1->py(),recoTrack1->pz(), recoTrack1->p());
284 
285  charge = recoTrack1->charge()*recoTrack2->charge();
286  if (charge < 0) {
287  InvMass = (Mu1+Mu2).M();
288  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
289  if(fabs(recoTrack1->eta())>EtaCutMin[iEtaRegion] && fabs(recoTrack1->eta())<EtaCutMax[iEtaRegion] &&
290  fabs(recoTrack2->eta())>EtaCutMin[iEtaRegion] && fabs(recoTrack2->eta())<EtaCutMax[iEtaRegion]){
291  if (InvMass < LowMassMax) TrkTrkMuon_LM[iEtaRegion]->Fill(InvMass);
292  if (InvMass > HighMassMin) TrkTrkMuon_HM[iEtaRegion]->Fill(InvMass);
293  }
294  }
295  }
296 
297 
298  LogTrace(metname)<<"[DiMuonHistograms] Soft-Soft pair"<<endl;
299 
300  if (muon::isSoftMuon(*muon1, vtx) &&
301  muon::isSoftMuon(*muon2, vtx) ) {
302 
303  if (charge < 0) {
304  InvMass = (Mu1+Mu2).M();
305  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
306 
307  if(fabs(recoTrack1->eta())>EtaCutMin[iEtaRegion] && fabs(recoTrack1->eta())<EtaCutMax[iEtaRegion] &&
308  fabs(recoTrack2->eta())>EtaCutMin[iEtaRegion] && fabs(recoTrack2->eta())<EtaCutMax[iEtaRegion]){
309  SoftSoftMuon[iEtaRegion]->Fill(InvMass);
310  SoftSoftMuonBadFrac[iEtaRegion]->Fill(muon1->innerTrack()->lost()/muon1->innerTrack()->found());
311  }
312  }
313  }
314  }
315  }
316  } //muon2
317  } //Muon1
318 
319 
320 }
321 
~DiMuonHistograms() override
void analyze(const edm::Event &, const edm::EventSetup &) override
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const std::string metname
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
bool isLooseMuon(const reco::Muon &)
int iEvent
Definition: GenABIO.cc:224
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
DiMuonHistograms(const edm::ParameterSet &pset)
bool isSoftMuon(const reco::Muon &, const reco::Vertex &, bool run2016_hip_mitigation=false)
bool isValid() const
Definition: HandleBase.h:74
#define LogTrace(id)
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
static int position[264][3]
Definition: ReadPGInfo.cc:509
const Point & position() const
position
Definition: BeamSpot.h:62
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
Definition: Run.h:45