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  * $Date: 2011/06/01 15:09:38 $
5  * $Revision: 1.7 $
6  * \author S. Bolognesi, Erik - CERN
7  */
8 
10 
14 
18 
26 
28 
29 using namespace std;
30 using namespace edm;
31 using namespace reco;
32 
34  // Muon Collection Label
35  theMuonCollectionLabel = parameters.getParameter<InputTag>("MuonCollection");
36  vertex = parameters.getParameter<InputTag>("vertex");
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 }
62 
64  // the services
65  theDbe = Service<DQMStore>().operator->();
66 
67  metname = "oniaAnalyzer";
68  LogTrace(metname)<<"[BPhysicsOniaDQM] Parameters initialization";
69 
70  if(theDbe!=NULL){
71  theDbe->setCurrentFolder("Physics/BPhysics"); // Use folder with name of PAG
72  global_background = theDbe->book1D("global_background", "Same-sign global-global dimuon mass", 750, 0, 15);
73  diMuonMass_global = theDbe->book1D("diMuonMass_global", "Opposite-sign global-global dimuon mass", 750, 0, 15);
74  tracker_background = theDbe->book1D("tracker_background", "Same-sign tracker-tracker (arbitrated) dimuon mass", 750, 0, 15);
75  diMuonMass_tracker = theDbe->book1D("diMuonMass_tracker", "Opposite-sign tracker-tracker (arbitrated) dimuon mass", 750, 0, 15);
76  standalone_background = theDbe->book1D("standalone_background", "Same-sign standalone-standalone dimuon mass", 500, 0, 15);
77  diMuonMass_standalone = theDbe->book1D("diMuonMass_standalone", "Opposite-sign standalone-standalone dimuon mass", 500, 0, 15);
78 
79  glbSigCut = theDbe->book1D("glbSigCut", "Opposite-sign glb-glb dimuon mass", 650, 0, 130);
80  glbSigNoCut = theDbe->book1D("glbSigNoCut", "Opposite-sign glb-glb dimuon mass (no cut)", 650, 0, 130);
81  glbBkgNoCut = theDbe->book1D("glbBkgNoCut", "Same-sign glb-glb dimuon mass (no cut)", 650, 0, 130);
82  staSigCut = theDbe->book1D("staSigCut", "Opposite-sign sta-sta dimuon mass", 430, 0, 129);
83  staSigNoCut = theDbe->book1D("staSigNoCut", "Opposite-sign sta-sta dimuon mass (no cut)", 430, 0, 129);
84  staBkgNoCut = theDbe->book1D("staBkgNoCut", "Same-sign sta-sta dimuon mass (no cut)", 430, 0, 129);
85  trkSigCut = theDbe->book1D("trkSigCut", "Opposite-sign trk-trk dimuon mass", 650, 0, 130);
86  trkSigNoCut = theDbe->book1D("trkSigNoCut", "Opposite-sign trk-trk dimuon mass (no cut)", 650, 0, 130);
87  trkBkgNoCut = theDbe->book1D("trkBkgNoCutt", "Same-sign trk-trk dimuon mass (no cut)", 650, 0, 130);
88  }
89 
90 }
91 
92 void BPhysicsOniaDQM::analyze(const Event& iEvent, const EventSetup& iSetup) {
93 
94  LogTrace(metname)<<"[BPhysicsOniaDQM] Analysis of event # ";
95 
96  // Take the STA muon container
98  iEvent.getByLabel(theMuonCollectionLabel,muons);
99 
101  iEvent.getByLabel(vertex,privtxs);
102  VertexCollection::const_iterator privtx;
103 
104  if(privtxs->begin() != privtxs->end()){
105  privtx = privtxs->begin();
106  RefVtx = privtx->position();
107  } else {
108  RefVtx.SetXYZ(0.,0.,0.);
109  }
110 
111  if(muons.isValid()){
112  for (MuonCollection::const_iterator recoMu1 = muons->begin(); recoMu1!=muons->end(); ++recoMu1){
113 
114  // only loop over the remaining muons if recoMu1 is one of the following
115  if(recoMu1->isGlobalMuon() || recoMu1->isTrackerMuon() || recoMu1->isStandAloneMuon()){
116  for (MuonCollection::const_iterator recoMu2 = recoMu1+1; recoMu2!=muons->end(); ++recoMu2){
117 
118  // fill the relevant histograms if recoMu2 satisfies one of the following
119  if (recoMu1->isGlobalMuon() && recoMu2->isGlobalMuon()){
120  math::XYZVector vec1 = recoMu1->globalTrack()->momentum();
121  math::XYZVector vec2 = recoMu2->globalTrack()->momentum();
122  float massJPsi = computeMass(vec1,vec2);
123 
124  // if opposite charges, fill glbSig, else fill glbBkg
125  if (((*recoMu1).charge()*(*recoMu2).charge())<0) {
126  if(diMuonMass_global!=NULL){ // BPhysicsOniaDQM original one
127  diMuonMass_global->Fill(massJPsi);
128  }
129 
130  if(glbSigNoCut!=NULL){
131  glbSigNoCut->Fill(massJPsi);
132  if (selGlobalMuon(*recoMu1) && selGlobalMuon(*recoMu2)) {
133  if (glbSigCut!=NULL) glbSigCut->Fill(massJPsi);
134  if (massJPsi >= 3.0 && massJPsi <= 3.2) jpsiGlbSigPerLS++;
135  }
136  }
137  } else {
138  if(global_background!=NULL){ // BPhysicsOniaDQM original one
139  global_background->Fill (massJPsi);
140  }
141 
142  if(glbBkgNoCut!=NULL){
143  glbBkgNoCut->Fill(massJPsi);
144  }
145  }
146  }
147 
148  if(recoMu1->isStandAloneMuon() && recoMu2->isStandAloneMuon() &&
149  fabs(recoMu1->outerTrack()->d0()) < 5 && fabs(recoMu1->outerTrack()->dz()) < 30 &&
150  fabs(recoMu2->outerTrack()->d0()) < 5 && fabs(recoMu2->outerTrack()->dz()) < 30){
151  math::XYZVector vec1 = recoMu1->outerTrack()->momentum();
152  math::XYZVector vec2 = recoMu2->outerTrack()->momentum();
153  float massJPsi = computeMass(vec1,vec2);
154 
155  // if opposite charges, fill staSig, else fill staBkg
156  if (((*recoMu1).charge()*(*recoMu2).charge())<0) {
157  if(diMuonMass_standalone!=NULL){
158  diMuonMass_standalone->Fill(massJPsi);
159  }
160 
161  if(staSigNoCut!=NULL){
162  staSigNoCut->Fill(massJPsi);
163  /*if (selStandaloneMuon(*recoMu1) && selStandaloneMuon(*recoMu2)) {
164  if (staSigCut!=NULL) staSigCut->Fill(massJPsi);
165  if (massJPsi >= 3.0 && massJPsi <= 3.2) jpsiStaSigPerLS++;
166  }*/
167  }
168  } else {
169  if(standalone_background!=NULL){
170  standalone_background->Fill (massJPsi);
171  }
172 
173  if(staBkgNoCut!=NULL){
174  staBkgNoCut->Fill(massJPsi);
175  }
176  }
177  }
178 
179  if(recoMu1->isTrackerMuon() && recoMu2->isTrackerMuon() &&
182  math::XYZVector vec1 = recoMu1->innerTrack()->momentum();
183  math::XYZVector vec2 = recoMu2->innerTrack()->momentum();
184  float massJPsi = computeMass(vec1,vec2);
185 
186  // if opposite charges, fill trkSig, else fill trkBkg
187  if (((*recoMu1).charge()*(*recoMu2).charge())<0) {
188  if(diMuonMass_tracker!=NULL){
189  diMuonMass_tracker->Fill(massJPsi);
190  }
191 
192  if(trkSigNoCut!=NULL){
193  trkSigNoCut->Fill(massJPsi);
194  if (selTrackerMuon(*recoMu1) && selTrackerMuon(*recoMu2)) {
195  if (trkSigCut!=NULL) trkSigCut->Fill(massJPsi);
196  if(massJPsi >= 3.0 && massJPsi <= 3.2) jpsiTrkSigPerLS++;
197  }
198  }
199  } else {
200  if(tracker_background!=NULL){
201  tracker_background->Fill (massJPsi);
202  }
203 
204  if(trkBkgNoCut!=NULL){
205  trkBkgNoCut->Fill(massJPsi);
206  }
207  }
208  }
209 
210  }//end of 2nd MuonCollection
211  }//end of GLB,STA,TRK muon check
212  }//end of 1st MuonCollection
213  }//Is this MuonCollection vaild?
214 
215 }
216 
218  LogTrace(metname)<<"[BPhysicsOniaDQM] EndJob";
219 }
220 
222 {
223  LogTrace(metname)<<"[BPhysicsOniaDQM] Start of a LuminosityBlock";
224 
225  jpsiGlbSigPerLS = 0;
226  jpsiStaSigPerLS = 0;
227  jpsiTrkSigPerLS = 0;
228 }
229 
231 {
232  LogTrace(metname)<<"[BPhysicsOniaDQM] Start of a LuminosityBlock";
233 
235  lumiBlock.getByLabel("lumiProducer",lumiSummary);
236 
237  int LBlockNum = lumiBlock.id().luminosityBlock();
238 
239  jpsiGlbSig.insert( pair<int,int>(LBlockNum, jpsiGlbSigPerLS) );
240  jpsiStaSig.insert( pair<int,int>(LBlockNum, jpsiStaSigPerLS) );
241  jpsiTrkSig.insert( pair<int,int>(LBlockNum, jpsiTrkSigPerLS) );
242 // cout << "lumi: " << LBlockNum << "\t" << jpsiGlbSig[LBlockNum] << "\t" << jpsiStaSig[LBlockNum] << "\t" << jpsiTrkSig[LBlockNum] << endl;
243 
244  if (jpsiGlbSig.size()%5 != 0) return;
245 
246  theDbe->setCurrentFolder("Physics/BPhysics");
247 // if(JPsiGlbYdLumi!=NULL) {
248 // theDbe->removeElement("JPsiGlbYdLumi"); // Remove histograms from previous run
249 // theDbe->removeElement("JPsiStaYdLumi");
250 // theDbe->removeElement("JPsiTrkYdLumi");
251 // }
252 
253 // int xmin = (*jpsiGlbSig.begin()).first;
254 // int xmax = (*jpsiGlbSig.rbegin()).first;
255 // int nx = (xmax - xmin + 1)/5 + 1; // Merge 5 lumisections into 1 bin
256 // // cout << "x-axis " << xmin << " " << xmax << endl;
257 
258 // JPsiGlbYdLumi = theDbe->book1D("JPsiGlbYdLumi", "JPsi yield from global-global dimuon", nx, xmin, xmax);
259 // JPsiStaYdLumi = theDbe->book1D("JPsiStaYdLumi", "JPsi yield from standalone-standalone dimuon", nx, xmin, xmax);
260 // JPsiTrkYdLumi = theDbe->book1D("JPsiTrkYdLumi", "JPsi yield from tracker-tracker dimuon", nx, xmin, xmax);
261 
262 // map<int,int>::iterator glb;
263 // map<int,int>::iterator sta;
264 // map<int,int>::iterator trk;
265 // for (glb = jpsiGlbSig.begin(); glb != jpsiGlbSig.end(); ++glb)
266 // {
267 // int bin = ((*glb).first - xmin + 1)/5 + 1; //X-axis bin #
268 // sta = jpsiStaSig.find((*glb).first);
269 // trk = jpsiTrkSig.find((*glb).first);
270 // JPsiGlbYdLumi->setBinContent(bin,JPsiGlbYdLumi->getBinContent(bin)+(*glb).second);
271 // JPsiStaYdLumi->setBinContent(bin,JPsiStaYdLumi->getBinContent(bin)+(*sta).second);
272 // JPsiTrkYdLumi->setBinContent(bin,JPsiTrkYdLumi->getBinContent(bin)+(*trk).second);
273 // // cout << "glb: " << bin << "\t" << (*glb).first << "\t" << (*glb).second << endl;
274 // // cout << "sta: " << bin << "\t" << (*sta).first << "\t" << (*sta).second << endl;
275 // // cout << "trk: " << bin << "\t" << (*trk).first << "\t" << (*trk).second << endl;
276 // }
277 }
278 
279 void BPhysicsOniaDQM::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
280 {
281  LogTrace(metname)<<"[BPhysicsOniaDQM] Start of a Run";
282 }
283 
284 void BPhysicsOniaDQM::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
285 {
286  LogTrace(metname)<<"[BPhysicsOniaDQM] End of a Run";
287 
288  if (!jpsiGlbSig.empty()) {
289  jpsiGlbSig.clear();
290  jpsiStaSig.clear();
291  jpsiTrkSig.clear();
292  }
293 }
294 
296  // mass of muon
297  float massMu = 0.10566;
298  float eMu1 = -999;
299  if(massMu*massMu + vec1.Mag2()>0)
300  eMu1 = sqrt(massMu*massMu + vec1.Mag2());
301  float eMu2 = -999;
302  if(massMu*massMu + vec2.Mag2()>0)
303  eMu2 = sqrt(massMu*massMu + vec2.Mag2());
304 
305  float pJPsi = -999;
306  if((vec1+vec2).Mag2()>0)
307  pJPsi = sqrt((vec1+vec2).Mag2());
308  float eJPsi = eMu1 + eMu2;
309 
310  float massJPsi = -999;
311  if((eJPsi*eJPsi - pJPsi*pJPsi) > 0)
312  massJPsi = sqrt(eJPsi*eJPsi - pJPsi*pJPsi);
313 
314  return massJPsi;
315 }
316 
318 {
319  return (fabs(recoMu.eta()) < 2.4 &&
320  ((fabs(recoMu.eta()) < 1.3 && recoMu.pt() > 3.3) ||
321  (fabs(recoMu.eta()) > 1.3 && fabs(recoMu.eta()) < 2.2 && recoMu.p() > 2.9) ||
322  (fabs(recoMu.eta()) > 2.2 && recoMu.pt() > 0.8)));
323 }
324 
326 {
327  TrackRef iTrack = recoMu.innerTrack();
328  const reco::HitPattern &p = iTrack->hitPattern();
329 
330  TrackRef gTrack = recoMu.globalTrack();
331  const reco::HitPattern &q = gTrack->hitPattern();
332 
333  return (isMuonInAccept(recoMu) &&
334  iTrack->found() > 11 &&
335  gTrack->chi2()/gTrack->ndof() < 20.0 &&
336  q.numberOfValidMuonHits() > 0 &&
337  iTrack->chi2()/iTrack->ndof() < 4.0 &&
338  //recoMu.muonID("TrackerMuonArbitrated") &&
339  //recoMu.muonID("TMLastStationAngTight") &&
340  p.pixelLayersWithMeasurement() > 1 &&
341  fabs(iTrack->dxy(RefVtx)) < 3.0 &&
342  fabs(iTrack->dz(RefVtx)) < 15.0 );
343 }
344 
346 {
347  TrackRef iTrack = recoMu.innerTrack();
348  const reco::HitPattern &p = iTrack->hitPattern();
349 
350  return (isMuonInAccept(recoMu) &&
351  iTrack->found() > 11 &&
352  iTrack->chi2()/iTrack->ndof() < 4.0 &&
353  //recoMu.muonID("TrackerMuonArbitrated") &&
354  //recoMu.muonID("TMLastStationAngTight") &&
355  p.pixelLayersWithMeasurement() > 1 &&
356  fabs(iTrack->dxy(RefVtx)) < 3.0 &&
357  fabs(iTrack->dz(RefVtx)) < 15.0 );
358 }
359 
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 TrackRef innerTrack() const
Definition: Muon.h:49
const std::string metname
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
int pixelLayersWithMeasurement() const
Definition: HitPattern.h:710
#define NULL
Definition: scimark2.h:8
tuple lumiSummary
Definition: runregparse.py:290
bool getByLabel(std::string const &label, Handle< PROD > &result) const
virtual double eta() const
momentum pseudorapidity
void beginLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:243
bool isMuonInAccept(const reco::Muon &recoMu)
T sqrt(T t)
Definition: SSEVec.h:46
BPhysicsOniaDQM(const edm::ParameterSet &)
Constructor.
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
#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:31
virtual double pt() const
transverse momentum
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:562
Definition: Run.h:33
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:55
void endLuminosityBlock(const edm::LuminosityBlock &lumiBlock, const edm::EventSetup &iSetup)