CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BPhysicsOniaDQM.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author S. Bolognesi, Erik - CERN
5  */
6 
8 
12 
16 
22 
24 
25 using namespace std;
26 using namespace edm;
27 using namespace reco;
28 
30  // Muon Collection Label
31  vertex_ = consumes<reco::VertexCollection>(
32  parameters.getParameter<InputTag>("vertex"));
33  theMuonCollectionLabel_ = consumes<reco::MuonCollection>(
34  parameters.getParameter<InputTag>("MuonCollection"));
35  lumiSummaryToken_ = consumes<LumiSummary, edm::InLumi>(
36  parameters.getParameter<InputTag>("lumiSummary"));
37 
38  global_background = NULL;
39  diMuonMass_global = NULL;
40  tracker_background = NULL;
41  diMuonMass_tracker = NULL;
42  standalone_background = NULL;
43  diMuonMass_standalone = NULL;
44 
45  glbSigCut = NULL;
46  glbSigNoCut = NULL;
47  glbBkgNoCut = NULL;
48  staSigCut = NULL;
49  staSigNoCut = NULL;
50  staBkgNoCut = NULL;
51  trkSigCut = NULL;
52  trkSigNoCut = NULL;
53  trkBkgNoCut = NULL;
54 
55  // JPsiGlbYdLumi = NULL;
56  // JPsiStaYdLumi = NULL;
57  // JPsiTrkYdLumi = NULL;
58 }
59 
61 
63  // the services
64  theDbe = Service<DQMStore>().operator->();
65 
66  metname = "oniaAnalyzer";
67  LogTrace(metname) << "[BPhysicsOniaDQM] Parameters initialization";
68 
69  if (theDbe != NULL) {
70  theDbe->setCurrentFolder(
71  "Physics/BPhysics"); // Use folder with name of PAG
72  global_background = theDbe->book1D(
73  "global_background", "Same-sign global-global dimuon mass", 750, 0, 15);
74  diMuonMass_global =
75  theDbe->book1D("diMuonMass_global",
76  "Opposite-sign global-global dimuon mass", 750, 0, 15);
77  tracker_background = theDbe->book1D(
78  "tracker_background",
79  "Same-sign tracker-tracker (arbitrated) dimuon mass", 750, 0, 15);
80  diMuonMass_tracker = theDbe->book1D(
81  "diMuonMass_tracker",
82  "Opposite-sign tracker-tracker (arbitrated) dimuon mass", 750, 0, 15);
83  standalone_background = theDbe->book1D(
84  "standalone_background", "Same-sign standalone-standalone dimuon mass",
85  500, 0, 15);
86  diMuonMass_standalone = theDbe->book1D(
87  "diMuonMass_standalone",
88  "Opposite-sign standalone-standalone dimuon mass", 500, 0, 15);
89 
90  glbSigCut = theDbe->book1D("glbSigCut", "Opposite-sign glb-glb dimuon mass",
91  650, 0, 130);
92  glbSigNoCut = theDbe->book1D("glbSigNoCut",
93  "Opposite-sign glb-glb dimuon mass (no cut)",
94  650, 0, 130);
95  glbBkgNoCut = theDbe->book1D(
96  "glbBkgNoCut", "Same-sign glb-glb dimuon mass (no cut)", 650, 0, 130);
97  staSigCut = theDbe->book1D("staSigCut", "Opposite-sign sta-sta dimuon mass",
98  430, 0, 129);
99  staSigNoCut = theDbe->book1D("staSigNoCut",
100  "Opposite-sign sta-sta dimuon mass (no cut)",
101  430, 0, 129);
102  staBkgNoCut = theDbe->book1D(
103  "staBkgNoCut", "Same-sign sta-sta dimuon mass (no cut)", 430, 0, 129);
104  trkSigCut = theDbe->book1D("trkSigCut", "Opposite-sign trk-trk dimuon mass",
105  650, 0, 130);
106  trkSigNoCut = theDbe->book1D("trkSigNoCut",
107  "Opposite-sign trk-trk dimuon mass (no cut)",
108  650, 0, 130);
109  trkBkgNoCut = theDbe->book1D(
110  "trkBkgNoCutt", "Same-sign trk-trk dimuon mass (no cut)", 650, 0, 130);
111  }
112 }
113 
114 void BPhysicsOniaDQM::analyze(const Event &iEvent, const EventSetup &iSetup) {
115 
116  LogTrace(metname) << "[BPhysicsOniaDQM] Analysis of event # ";
117 
118  // Take the STA muon container
120  iEvent.getByToken(theMuonCollectionLabel_, muons);
121 
123  iEvent.getByToken(vertex_, privtxs);
124  VertexCollection::const_iterator privtx;
125 
126  if (privtxs->begin() != privtxs->end()) {
127  privtx = privtxs->begin();
128  RefVtx = privtx->position();
129  } else {
130  RefVtx.SetXYZ(0., 0., 0.);
131  }
132 
133  if (muons.isValid()) {
134  for (MuonCollection::const_iterator recoMu1 = muons->begin();
135  recoMu1 != muons->end(); ++recoMu1) {
136 
137  // only loop over the remaining muons if recoMu1 is one of the following
138  if (recoMu1->isGlobalMuon() || recoMu1->isTrackerMuon() ||
139  recoMu1->isStandAloneMuon()) {
140  for (MuonCollection::const_iterator recoMu2 = recoMu1 + 1;
141  recoMu2 != muons->end(); ++recoMu2) {
142 
143  // fill the relevant histograms if recoMu2 satisfies one of the
144  // following
145  if (recoMu1->isGlobalMuon() && recoMu2->isGlobalMuon()) {
146  math::XYZVector vec1 = recoMu1->globalTrack()->momentum();
147  math::XYZVector vec2 = recoMu2->globalTrack()->momentum();
148  float massJPsi = computeMass(vec1, vec2);
149 
150  // if opposite charges, fill glbSig, else fill glbBkg
151  if (((*recoMu1).charge() * (*recoMu2).charge()) < 0) {
152  if (diMuonMass_global != NULL) { // BPhysicsOniaDQM original one
153  diMuonMass_global->Fill(massJPsi);
154  }
155 
156  if (glbSigNoCut != NULL) {
157  glbSigNoCut->Fill(massJPsi);
158  if (selGlobalMuon(*recoMu1) && selGlobalMuon(*recoMu2)) {
159  if (glbSigCut != NULL) glbSigCut->Fill(massJPsi);
160  if (massJPsi >= 3.0 && massJPsi <= 3.2) jpsiGlbSigPerLS++;
161  }
162  }
163  } else {
164  if (global_background != NULL) { // BPhysicsOniaDQM original one
165  global_background->Fill(massJPsi);
166  }
167 
168  if (glbBkgNoCut != NULL) {
169  glbBkgNoCut->Fill(massJPsi);
170  }
171  }
172  }
173 
174  if (recoMu1->isStandAloneMuon() && recoMu2->isStandAloneMuon() &&
175  fabs(recoMu1->outerTrack()->d0()) < 5 &&
176  fabs(recoMu1->outerTrack()->dz()) < 30 &&
177  fabs(recoMu2->outerTrack()->d0()) < 5 &&
178  fabs(recoMu2->outerTrack()->dz()) < 30) {
179  math::XYZVector vec1 = recoMu1->outerTrack()->momentum();
180  math::XYZVector vec2 = recoMu2->outerTrack()->momentum();
181  float massJPsi = computeMass(vec1, vec2);
182 
183  // if opposite charges, fill staSig, else fill staBkg
184  if (((*recoMu1).charge() * (*recoMu2).charge()) < 0) {
185  if (diMuonMass_standalone != NULL) {
186  diMuonMass_standalone->Fill(massJPsi);
187  }
188 
189  if (staSigNoCut != NULL) {
190  staSigNoCut->Fill(massJPsi);
191  /*if (selStandaloneMuon(*recoMu1) &&
192  selStandaloneMuon(*recoMu2)) {
193  if (staSigCut!=NULL) staSigCut->Fill(massJPsi);
194  if (massJPsi >= 3.0 && massJPsi <= 3.2) jpsiStaSigPerLS++;
195  }*/
196  }
197  } else {
198  if (standalone_background != NULL) {
199  standalone_background->Fill(massJPsi);
200  }
201 
202  if (staBkgNoCut != NULL) {
203  staBkgNoCut->Fill(massJPsi);
204  }
205  }
206  }
207 
208  if (recoMu1->isTrackerMuon() && recoMu2->isTrackerMuon() &&
211  math::XYZVector vec1 = recoMu1->innerTrack()->momentum();
212  math::XYZVector vec2 = recoMu2->innerTrack()->momentum();
213  float massJPsi = computeMass(vec1, vec2);
214 
215  // if opposite charges, fill trkSig, else fill trkBkg
216  if (((*recoMu1).charge() * (*recoMu2).charge()) < 0) {
217  if (diMuonMass_tracker != NULL) {
218  diMuonMass_tracker->Fill(massJPsi);
219  }
220 
221  if (trkSigNoCut != NULL) {
222  trkSigNoCut->Fill(massJPsi);
223  if (selTrackerMuon(*recoMu1) && selTrackerMuon(*recoMu2)) {
224  if (trkSigCut != NULL) trkSigCut->Fill(massJPsi);
225  if (massJPsi >= 3.0 && massJPsi <= 3.2) jpsiTrkSigPerLS++;
226  }
227  }
228  } else {
229  if (tracker_background != NULL) {
230  tracker_background->Fill(massJPsi);
231  }
232 
233  if (trkBkgNoCut != NULL) {
234  trkBkgNoCut->Fill(massJPsi);
235  }
236  }
237  }
238 
239  } // end of 2nd MuonCollection
240  } // end of GLB,STA,TRK muon check
241  } // end of 1st MuonCollection
242  } // Is this MuonCollection vaild?
243 }
244 
246  LogTrace(metname) << "[BPhysicsOniaDQM] EndJob";
247 }
248 
250  const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup) {
251  LogTrace(metname) << "[BPhysicsOniaDQM] Start of a LuminosityBlock";
252 
253  jpsiGlbSigPerLS = 0;
254  jpsiStaSigPerLS = 0;
255  jpsiTrkSigPerLS = 0;
256 }
257 
259  const edm::EventSetup &iSetup) {
260  LogTrace(metname) << "[BPhysicsOniaDQM] Start of a LuminosityBlock";
261 
263  lumiBlock.getByToken(lumiSummaryToken_, lumiSummary);
264 
265  int LBlockNum = lumiBlock.id().luminosityBlock();
266 
267  jpsiGlbSig.insert(pair<int, int>(LBlockNum, jpsiGlbSigPerLS));
268  jpsiStaSig.insert(pair<int, int>(LBlockNum, jpsiStaSigPerLS));
269  jpsiTrkSig.insert(pair<int, int>(LBlockNum, jpsiTrkSigPerLS));
270  // cout << "lumi: " << LBlockNum << "\t" << jpsiGlbSig[LBlockNum] << "\t" <<
271  // jpsiStaSig[LBlockNum] << "\t" << jpsiTrkSig[LBlockNum] << endl;
272 
273  if (jpsiGlbSig.size() % 5 != 0) return;
274 
275  theDbe->setCurrentFolder("Physics/BPhysics");
276  // if(JPsiGlbYdLumi!=NULL) {
277  // theDbe->removeElement("JPsiGlbYdLumi"); // Remove histograms from
278  // previous run
279  // theDbe->removeElement("JPsiStaYdLumi");
280  // theDbe->removeElement("JPsiTrkYdLumi");
281  // }
282 
283  // int xmin = (*jpsiGlbSig.begin()).first;
284  // int xmax = (*jpsiGlbSig.rbegin()).first;
285  // int nx = (xmax - xmin + 1)/5 + 1; // Merge 5 lumisections into 1 bin
286  // // cout << "x-axis " << xmin << " " << xmax << endl;
287 
288  // JPsiGlbYdLumi = theDbe->book1D("JPsiGlbYdLumi", "JPsi yield from
289  // global-global dimuon", nx, xmin, xmax);
290  // JPsiStaYdLumi = theDbe->book1D("JPsiStaYdLumi", "JPsi yield from
291  // standalone-standalone dimuon", nx, xmin, xmax);
292  // JPsiTrkYdLumi = theDbe->book1D("JPsiTrkYdLumi", "JPsi yield from
293  // tracker-tracker dimuon", nx, xmin, xmax);
294 
295  // map<int,int>::iterator glb;
296  // map<int,int>::iterator sta;
297  // map<int,int>::iterator trk;
298  // for (glb = jpsiGlbSig.begin(); glb != jpsiGlbSig.end(); ++glb)
299  // {
300  // int bin = ((*glb).first - xmin + 1)/5 + 1; //X-axis bin #
301  // sta = jpsiStaSig.find((*glb).first);
302  // trk = jpsiTrkSig.find((*glb).first);
303  // JPsiGlbYdLumi->setBinContent(bin,JPsiGlbYdLumi->getBinContent(bin)+(*glb).second);
304  // JPsiStaYdLumi->setBinContent(bin,JPsiStaYdLumi->getBinContent(bin)+(*sta).second);
305  // JPsiTrkYdLumi->setBinContent(bin,JPsiTrkYdLumi->getBinContent(bin)+(*trk).second);
306  // // cout << "glb: " << bin << "\t" << (*glb).first << "\t" <<
307  // (*glb).second << endl;
308  // // cout << "sta: " << bin << "\t" << (*sta).first << "\t" <<
309  // (*sta).second << endl;
310  // // cout << "trk: " << bin << "\t" << (*trk).first << "\t" <<
311  // (*trk).second << endl;
312  // }
313 }
314 
316  const edm::EventSetup &iSetup) {
317  LogTrace(metname) << "[BPhysicsOniaDQM] Start of a Run";
318 }
319 
321  const edm::EventSetup &iSetup) {
322  LogTrace(metname) << "[BPhysicsOniaDQM] End of a Run";
323 
324  if (!jpsiGlbSig.empty()) {
325  jpsiGlbSig.clear();
326  jpsiStaSig.clear();
327  jpsiTrkSig.clear();
328  }
329 }
330 
332  const math::XYZVector &vec2) {
333  // mass of muon
334  float massMu = 0.10566;
335  float eMu1 = -999;
336  if (massMu * massMu + vec1.Mag2() > 0)
337  eMu1 = sqrt(massMu * massMu + vec1.Mag2());
338  float eMu2 = -999;
339  if (massMu * massMu + vec2.Mag2() > 0)
340  eMu2 = sqrt(massMu * massMu + vec2.Mag2());
341 
342  float pJPsi = -999;
343  if ((vec1 + vec2).Mag2() > 0) pJPsi = sqrt((vec1 + vec2).Mag2());
344  float eJPsi = eMu1 + eMu2;
345 
346  float massJPsi = -999;
347  if ((eJPsi * eJPsi - pJPsi * pJPsi) > 0)
348  massJPsi = sqrt(eJPsi * eJPsi - pJPsi * pJPsi);
349 
350  return massJPsi;
351 }
352 
354  return (fabs(recoMu.eta()) < 2.4 &&
355  ((fabs(recoMu.eta()) < 1.3 && recoMu.pt() > 3.3) ||
356  (fabs(recoMu.eta()) > 1.3 && fabs(recoMu.eta()) < 2.2 &&
357  recoMu.p() > 2.9) ||
358  (fabs(recoMu.eta()) > 2.2 && recoMu.pt() > 0.8)));
359 }
360 
362  TrackRef iTrack = recoMu.innerTrack();
363  const reco::HitPattern &p = iTrack->hitPattern();
364 
365  TrackRef gTrack = recoMu.globalTrack();
366  const reco::HitPattern &q = gTrack->hitPattern();
367 
368  return (isMuonInAccept(recoMu) && iTrack->found() > 11 &&
369  gTrack->chi2() / gTrack->ndof() < 20.0 &&
370  q.numberOfValidMuonHits() > 0 &&
371  iTrack->chi2() / iTrack->ndof() < 4.0 &&
372  // recoMu.muonID("TrackerMuonArbitrated") &&
373  // recoMu.muonID("TMLastStationAngTight") &&
374  p.pixelLayersWithMeasurement() > 1 &&
375  fabs(iTrack->dxy(RefVtx)) < 3.0 && fabs(iTrack->dz(RefVtx)) < 15.0);
376 }
377 
379  TrackRef iTrack = recoMu.innerTrack();
380  const reco::HitPattern &p = iTrack->hitPattern();
381 
382  return (isMuonInAccept(recoMu) && iTrack->found() > 11 &&
383  iTrack->chi2() / iTrack->ndof() < 4.0 &&
384  // recoMu.muonID("TrackerMuonArbitrated") &&
385  // recoMu.muonID("TMLastStationAngTight") &&
386  p.pixelLayersWithMeasurement() > 1 &&
387  fabs(iTrack->dxy(RefVtx)) < 3.0 && fabs(iTrack->dz(RefVtx)) < 15.0);
388 }
389 
390 // Local Variables:
391 // show-trailing-whitespace: t
392 // truncate-lines: t
393 // End:
LuminosityBlockID id() const
T getParameter(std::string const &) const
virtual double p() const
magnitude of momentum vector
dictionary parameters
Definition: Parameters.py:2
bool selGlobalMuon(const reco::Muon &recoMu)
virtual float pt() const
transverse momentum
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
const std::string metname
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
#define NULL
Definition: scimark2.h:8
tuple lumiSummary
Definition: runregparse.py:290
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:458
void beginLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:230
bool isMuonInAccept(const reco::Muon &recoMu)
std::vector< double > vec1
Definition: HCALResponse.h:15
virtual float eta() const
momentum pseudorapidity
T sqrt(T t)
Definition: SSEVec.h:48
BPhysicsOniaDQM(const edm::ParameterSet &)
Constructor.
bool isValid() const
Definition: HandleBase.h:76
#define LogTrace(id)
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
LuminosityBlockNumber_t luminosityBlock() const
tuple muons
Definition: patZpeak.py:38
bool selTrackerMuon(const reco::Muon &recoMu)
void endRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
void beginJob()
Inizialize parameters for histo binning.
float computeMass(const math::XYZVector &vec1, const math::XYZVector &vec2)
virtual ~BPhysicsOniaDQM()
Destructor.
void analyze(const edm::Event &, const edm::EventSetup &)
Get the analysis.
int numberOfValidMuonHits() const
Definition: HitPattern.h:744
std::vector< vec1 > vec2
Definition: HCALResponse.h:16
Definition: Run.h:41
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54
void endLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup)