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  nGlbGlb = 0;
40 
41  // declare consumes:
42  theMuonCollectionLabel_ = consumes<edm::View<reco::Muon> > (parameters.getParameter<edm::InputTag>("MuonCollection"));
43  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
44 
45  theBeamSpotLabel_ = mayConsume<reco::BeamSpot> (parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
46 
47  etaBin = parameters.getParameter<int>("etaBin");
48  etaBBin = parameters.getParameter<int>("etaBBin");
49  etaEBin = parameters.getParameter<int>("etaEBin");
50 
51  etaBMin = parameters.getParameter<double>("etaBMin");
52  etaBMax = parameters.getParameter<double>("etaBMax");
53  etaECMin = parameters.getParameter<double>("etaECMin");
54  etaECMax = parameters.getParameter<double>("etaECMax");
55 
56  LowMassMin = parameters.getParameter<double>("LowMassMin");
57  LowMassMax = parameters.getParameter<double>("LowMassMax");
58  HighMassMin = parameters.getParameter<double>("HighMassMin");
59  HighMassMax = parameters.getParameter<double>("HighMassMax");
60 
61  theFolder = parameters.getParameter<string>("folder");
62 }
63 
65 
67  edm::Run const & /*iRun*/,
68  edm::EventSetup const & /* iSetup */){
69 
70  ibooker.cd();
71  ibooker.setCurrentFolder(theFolder);
72 
73  int nBin[3] = {etaBin,etaBBin,etaEBin};
74  EtaName[0] = ""; EtaName[1] = "_Barrel"; EtaName[2] = "_EndCap";
75  test = ibooker.book1D("test","InvMass_{Tight,Tight}",100, 0., 200.);
76  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
77 
78  GlbGlbMuon_LM.push_back(ibooker.book1D("GlbGlbMuon_LM"+EtaName[iEtaRegion],"InvMass_{GLB,GLB}"+EtaName[iEtaRegion],nBin[iEtaRegion], LowMassMin, LowMassMax));
79  TrkTrkMuon_LM.push_back(ibooker.book1D("TrkTrkMuon_LM"+EtaName[iEtaRegion],"InvMass_{TRK,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], LowMassMin, LowMassMax));
80  StaTrkMuon_LM.push_back(ibooker.book1D("StaTrkMuon_LM"+EtaName[iEtaRegion],"InvMass_{STA,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], LowMassMin, LowMassMax));
81 
82  GlbGlbMuon_HM.push_back(ibooker.book1D("GlbGlbMuon_HM"+EtaName[iEtaRegion],"InvMass_{GLB,GLB}"+EtaName[iEtaRegion],nBin[iEtaRegion], HighMassMin, HighMassMax));
83  TrkTrkMuon_HM.push_back(ibooker.book1D("TrkTrkMuon_HM"+EtaName[iEtaRegion],"InvMass_{TRK,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], HighMassMin, HighMassMax));
84  StaTrkMuon_HM.push_back(ibooker.book1D("StaTrkMuon_HM"+EtaName[iEtaRegion],"InvMass_{STA,TRK}"+EtaName[iEtaRegion],nBin[iEtaRegion], HighMassMin, HighMassMax));
85 
86  // arround the Z peak
87  TightTightMuon.push_back(ibooker.book1D("TightTightMuon"+EtaName[iEtaRegion],"InvMass_{Tight,Tight}"+EtaName[iEtaRegion],nBin[iEtaRegion], 55.0, 125.0));
88 
89  // low-mass resonances
90  SoftSoftMuon.push_back(ibooker.book1D("SoftSoftMuon"+EtaName[iEtaRegion],"InvMass_{Soft,Soft}"+EtaName[iEtaRegion],nBin[iEtaRegion], 0.0, 55.0));
91  }
92 }
93 
95 
96  LogTrace(metname)<<"[DiMuonHistograms] Analyze the mu in different eta regions";
98  iEvent.getByToken(theMuonCollectionLabel_, muons);
99 
100  // =================================================================================
101  // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
102  reco::Vertex::Point posVtx;
103  reco::Vertex::Error errVtx;
104  unsigned int theIndexOfThePrimaryVertex = 999.;
105 
107  iEvent.getByToken(theVertexLabel_, vertex);
108  if (vertex.isValid()){
109  for (unsigned int ind=0; ind<vertex->size(); ++ind) {
110  if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
111  theIndexOfThePrimaryVertex = ind;
112  break;
113  }
114  }
115  }
116 
117  if (theIndexOfThePrimaryVertex<100) {
118  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
119  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
120  }
121  else {
122  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
123 
124  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
125  iEvent.getByToken(theBeamSpotLabel_,recoBeamSpotHandle);
126  reco::BeamSpot bs = *recoBeamSpotHandle;
127 
128  posVtx = bs.position();
129  errVtx(0,0) = bs.BeamWidthX();
130  errVtx(1,1) = bs.BeamWidthY();
131  errVtx(2,2) = bs.sigmaZ();
132  }
133 
134  const reco::Vertex vtx(posVtx,errVtx);
135 
136  if(!muons.isValid()) return;
137 
138  // Loop on muon collection
139  TLorentzVector Mu1, Mu2;
140  float charge = 99.;
141  float InvMass = -99.;
142 
143 
144  for (edm::View<reco::Muon>::const_iterator muon1 = muons->begin(); muon1 != muons->end(); ++muon1){
145  LogTrace(metname)<<"[DiMuonHistograms] loop over 1st muon"<<endl;
146 
147  // Loop on second muons to fill invariant mass plots
148  for (edm::View<reco::Muon>::const_iterator muon2 = muon1; muon2 != muons->end(); ++muon2){
149  LogTrace(metname)<<"[DiMuonHistograms] loop over 2nd muon"<<endl;
150  if (muon1==muon2) continue;
151 
152  // Global-Global Muon
153  if (muon1->isGlobalMuon() && muon2->isGlobalMuon()) {
154  LogTrace(metname)<<"[DiMuonHistograms] Glb-Glb pair"<<endl;
155  reco::TrackRef recoCombinedGlbTrack1 = muon1->combinedMuon();
156  reco::TrackRef recoCombinedGlbTrack2 = muon2->combinedMuon();
157  Mu1.SetPxPyPzE(recoCombinedGlbTrack1->px(), recoCombinedGlbTrack1->py(),recoCombinedGlbTrack1->pz(), recoCombinedGlbTrack1->p());
158  Mu2.SetPxPyPzE(recoCombinedGlbTrack2->px(), recoCombinedGlbTrack2->py(),recoCombinedGlbTrack2->pz(), recoCombinedGlbTrack2->p());
159 
160  charge = recoCombinedGlbTrack1->charge()*recoCombinedGlbTrack2->charge();
161  if (charge < 0) {
162  InvMass = (Mu1+Mu2).M();
163  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
164  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
165  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
166  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
167 
168  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax &&
169  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax){
170  if (InvMass < LowMassMax) GlbGlbMuon_LM[iEtaRegion]->Fill(InvMass);
171  if (InvMass > HighMassMin) GlbGlbMuon_HM[iEtaRegion]->Fill(InvMass);
172  }
173  }
174  }
175  // Also Tight-Tight Muon Selection
176  if ( muon::isTightMuon(*muon1, vtx) &&
177  muon::isTightMuon(*muon2, vtx) ) {
178  test->Fill(InvMass);
179  LogTrace(metname)<<"[DiMuonHistograms] Tight-Tight pair"<<endl;
180  if (charge < 0){
181  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
182  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
183  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
184  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
185 
186  if(fabs(recoCombinedGlbTrack1->eta())>EtaCutMin && fabs(recoCombinedGlbTrack1->eta())<EtaCutMax &&
187  fabs(recoCombinedGlbTrack2->eta())>EtaCutMin && fabs(recoCombinedGlbTrack2->eta())<EtaCutMax){
188  if (InvMass > 55. && InvMass < 125.) TightTightMuon[iEtaRegion]->Fill(InvMass);
189  }
190  }
191  }
192  }
193  }
194 
195  // Now check for STA-TRK
196  if (muon2->isStandAloneMuon() && muon1->isTrackerMuon()) {
197  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
198  reco::TrackRef recoStaTrack = muon2->standAloneMuon();
199  reco::TrackRef recoTrack = muon1->track();
200  Mu2.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
201  Mu1.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
202 
203  charge = recoStaTrack->charge()*recoTrack->charge();
204  if (charge < 0) {
205  InvMass = (Mu1+Mu2).M();
206  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
207  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
208  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
209  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
210 
211  if(fabs(recoStaTrack->eta())>EtaCutMin && fabs(recoStaTrack->eta())<EtaCutMax &&
212  fabs(recoTrack->eta())>EtaCutMin && fabs(recoTrack->eta())<EtaCutMax){
213  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
214  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
215  }
216  }
217  }
218  }
219  if (muon1->isStandAloneMuon() && muon2->isTrackerMuon()) {
220  LogTrace(metname)<<"[DiMuonHistograms] STA-Trk pair"<<endl;
221  reco::TrackRef recoStaTrack = muon1->standAloneMuon();
222  reco::TrackRef recoTrack = muon2->track();
223  Mu1.SetPxPyPzE(recoStaTrack->px(), recoStaTrack->py(),recoStaTrack->pz(), recoStaTrack->p());
224  Mu2.SetPxPyPzE(recoTrack->px(), recoTrack->py(),recoTrack->pz(), recoTrack->p());
225 
226  charge = recoStaTrack->charge()*recoTrack->charge();
227  if (charge < 0) {
228  InvMass = (Mu1+Mu2).M();
229  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
230  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
231  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
232  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
233 
234  if(fabs(recoStaTrack->eta())>EtaCutMin && fabs(recoStaTrack->eta())<EtaCutMax &&
235  fabs(recoTrack->eta())>EtaCutMin && fabs(recoTrack->eta())<EtaCutMax){
236  if (InvMass < LowMassMax) StaTrkMuon_LM[iEtaRegion]->Fill(InvMass);
237  if (InvMass > HighMassMin) StaTrkMuon_HM[iEtaRegion]->Fill(InvMass);
238  }
239  }
240  }
241  }
242 
243  // TRK-TRK dimuon
244  if (muon1->isTrackerMuon() && muon2->isTrackerMuon()) {
245  LogTrace(metname)<<"[DiMuonHistograms] Trk-Trk dimuon pair"<<endl;
246  reco::TrackRef recoTrack2 = muon2->track();
247  reco::TrackRef recoTrack1 = muon1->track();
248  Mu2.SetPxPyPzE(recoTrack2->px(), recoTrack2->py(),recoTrack2->pz(), recoTrack2->p());
249  Mu1.SetPxPyPzE(recoTrack1->px(), recoTrack1->py(),recoTrack1->pz(), recoTrack1->p());
250 
251  charge = recoTrack1->charge()*recoTrack2->charge();
252  if (charge < 0) {
253  InvMass = (Mu1+Mu2).M();
254  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
255  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
256  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
257  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
258 
259  if(fabs(recoTrack1->eta())>EtaCutMin && fabs(recoTrack1->eta())<EtaCutMax &&
260  fabs(recoTrack2->eta())>EtaCutMin && fabs(recoTrack2->eta())<EtaCutMax){
261  if (InvMass < LowMassMax) TrkTrkMuon_LM[iEtaRegion]->Fill(InvMass);
262  if (InvMass > HighMassMin) TrkTrkMuon_HM[iEtaRegion]->Fill(InvMass);
263  }
264  }
265  }
266 
267 
268  LogTrace(metname)<<"[DiMuonHistograms] Soft-Soft pair"<<endl;
269 
270  if (muon::isSoftMuon(*muon1, vtx) &&
271  muon::isSoftMuon(*muon2, vtx) ) {
272 
273  if (charge < 0) {
274  InvMass = (Mu1+Mu2).M();
275  for (unsigned int iEtaRegion=0; iEtaRegion<3; iEtaRegion++){
276  if (iEtaRegion==0) {EtaCutMin= 0.; EtaCutMax=2.4; }
277  if (iEtaRegion==1) {EtaCutMin= etaBMin; EtaCutMax=etaBMax; }
278  if (iEtaRegion==2) {EtaCutMin= etaECMin; EtaCutMax=etaECMax; }
279 
280  if(fabs(recoTrack1->eta())>EtaCutMin && fabs(recoTrack1->eta())<EtaCutMax &&
281  fabs(recoTrack2->eta())>EtaCutMin && fabs(recoTrack2->eta())<EtaCutMax){
282  SoftSoftMuon[iEtaRegion]->Fill(InvMass);
283  }
284  }
285  }
286  }
287  }
288  } //muon2
289  } //Muon1
290 
291 
292 }
293 
void analyze(const edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
const std::string metname
void cd(void)
Definition: DQMStore.cc:269
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
bool isSoftMuon(const reco::Muon &, const reco::Vertex &)
int iEvent
Definition: GenABIO.cc:230
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
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 isValid() const
Definition: HandleBase.h:74
#define LogTrace(id)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
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.
virtual ~DiMuonHistograms()
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:42