CMS 3D CMS Logo

RPCRecHitValid.cc
Go to the documentation of this file.
3 
6 
17 
18 #include <algorithm>
19 
20 using namespace std;
21 
23 
25  simHitToken_ = consumes<SimHits>(pset.getParameter<edm::InputTag>("simHit"));
26  recHitToken_ = consumes<RecHits>(pset.getParameter<edm::InputTag>("recHit"));
27  simParticleToken_ = consumes<SimParticles>(pset.getParameter<edm::InputTag>("simTrack"));
28  simHitAssocToken_ = consumes<SimHitAssoc>(pset.getParameter<edm::InputTag>("simHitAssoc"));
29  muonToken_ = consumes<reco::MuonCollection>(pset.getParameter<edm::InputTag>("muon"));
30 
31  subDir_ = pset.getParameter<std::string>("subDir");
32 
33  rpcGeomToken_ = esConsumes();
34  rpcGeomTokenInRun_ = esConsumes<edm::Transition::BeginRun>();
35 }
36 
38  // Book MonitorElements
39  h_.bookHistograms(booker, subDir_);
40 
41  // SimHit plots, not compatible to RPCPoint-RPCRecHit comparison
42  booker.setCurrentFolder(subDir_ + "/HitProperty");
43  h_simParticleType = booker.book1D("SimHitPType", "SimHit particle type", 11, 0, 11);
44  h_simParticleType->getTH1()->SetMinimum(0);
45  if (TH1 *h = h_simParticleType->getTH1()) {
46  h->GetXaxis()->SetBinLabel(1, "#mu^{-}");
47  h->GetXaxis()->SetBinLabel(2, "#mu^{+}");
48  h->GetXaxis()->SetBinLabel(3, "e^{-}");
49  h->GetXaxis()->SetBinLabel(4, "e^{+}");
50  h->GetXaxis()->SetBinLabel(5, "#pi^{+}");
51  h->GetXaxis()->SetBinLabel(6, "#pi^{-}");
52  h->GetXaxis()->SetBinLabel(7, "K^{+}");
53  h->GetXaxis()->SetBinLabel(8, "K^{-}");
54  h->GetXaxis()->SetBinLabel(9, "p^{+}");
55  h->GetXaxis()->SetBinLabel(10, "p^{-}");
56  h->GetXaxis()->SetBinLabel(11, "Other");
57  }
58 
59  booker.setCurrentFolder(subDir_ + "/Track");
60 
61  h_nRPCHitPerSimMuon = booker.book1D("NRPCHitPerSimMuon", "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
62  h_nRPCHitPerSimMuonBarrel =
63  booker.book1D("NRPCHitPerSimMuonBarrel", "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
64  h_nRPCHitPerSimMuonOverlap =
65  booker.book1D("NRPCHitPerSimMuonOverlap", "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
66  h_nRPCHitPerSimMuonEndcap =
67  booker.book1D("NRPCHitPerSimMuonEndcap", "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
68 
69  h_nRPCHitPerRecoMuon = booker.book1D("NRPCHitPerRecoMuon", "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
70  h_nRPCHitPerRecoMuonBarrel =
71  booker.book1D("NRPCHitPerRecoMuonBarrel", "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
72  h_nRPCHitPerRecoMuonOverlap =
73  booker.book1D("NRPCHitPerRecoMuonOverlap", "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
74  h_nRPCHitPerRecoMuonEndcap =
75  booker.book1D("NRPCHitPerRecoMuonEndcap", "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
76 
77  h_nRPCHitPerSimMuon->getTH1()->SetMinimum(0);
78  h_nRPCHitPerSimMuonBarrel->getTH1()->SetMinimum(0);
79  h_nRPCHitPerSimMuonOverlap->getTH1()->SetMinimum(0);
80  h_nRPCHitPerSimMuonEndcap->getTH1()->SetMinimum(0);
81 
82  h_nRPCHitPerRecoMuon->getTH1()->SetMinimum(0);
83  h_nRPCHitPerRecoMuonBarrel->getTH1()->SetMinimum(0);
84  h_nRPCHitPerRecoMuonOverlap->getTH1()->SetMinimum(0);
85  h_nRPCHitPerRecoMuonEndcap->getTH1()->SetMinimum(0);
86 
87  float ptBins[] = {0, 1, 2, 5, 10, 20, 30, 50, 100, 200, 300, 500};
88  const int nPtBins = sizeof(ptBins) / sizeof(float) - 1;
89  h_simMuonBarrel_pt =
90  booker.book1D("SimMuonBarrel_pt", "SimMuon RPCHit in Barrel p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
91  h_simMuonOverlap_pt =
92  booker.book1D("SimMuonOverlap_pt", "SimMuon RPCHit in Overlap p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
93  h_simMuonEndcap_pt =
94  booker.book1D("SimMuonEndcap_pt", "SimMuon RPCHit in Endcap p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
95  h_simMuonNoRPC_pt =
96  booker.book1D("SimMuonNoRPC_pt", "SimMuon without RPCHit p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
97  h_simMuonBarrel_eta = booker.book1D("SimMuonBarrel_eta", "SimMuon RPCHit in Barrel #eta;#eta", 50, -2.5, 2.5);
98  h_simMuonOverlap_eta = booker.book1D("SimMuonOverlap_eta", "SimMuon RPCHit in Overlap #eta;#eta", 50, -2.5, 2.5);
99  h_simMuonEndcap_eta = booker.book1D("SimMuonEndcap_eta", "SimMuon RPCHit in Endcap #eta;#eta", 50, -2.5, 2.5);
100  h_simMuonNoRPC_eta = booker.book1D("SimMuonNoRPC_eta", "SimMuon without RPCHit #eta;#eta", 50, -2.5, 2.5);
101  h_simMuonBarrel_phi =
102  booker.book1D("SimMuonBarrel_phi", "SimMuon RPCHit in Barrel #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
103  h_simMuonOverlap_phi =
104  booker.book1D("SimMuonOverlap_phi", "SimMuon RPCHit in Overlap #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
105  h_simMuonEndcap_phi =
106  booker.book1D("SimMuonEndcap_phi", "SimMuon RPCHit in Endcap #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
107  h_simMuonNoRPC_phi =
108  booker.book1D("SimMuonNoRPC_phi", "SimMuon without RPCHit #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
109 
110  h_recoMuonBarrel_pt =
111  booker.book1D("RecoMuonBarrel_pt", "RecoMuon RPCHit in Barrel p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
112  h_recoMuonOverlap_pt =
113  booker.book1D("RecoMuonOverlap_pt", "RecoMuon RPCHit in Overlap p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
114  h_recoMuonEndcap_pt =
115  booker.book1D("RecoMuonEndcap_pt", "RecoMuon RPCHit in Endcap p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
116  h_recoMuonNoRPC_pt =
117  booker.book1D("RecoMuonNoRPC_pt", "RecoMuon without RPCHit p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
118  h_recoMuonBarrel_eta = booker.book1D("RecoMuonBarrel_eta", "RecoMuon RPCHit in Barrel #eta;#eta", 50, -2.5, 2.5);
119  h_recoMuonOverlap_eta = booker.book1D("RecoMuonOverlap_eta", "RecoMuon RPCHit in Overlap #eta;#eta", 50, -2.5, 2.5);
120  h_recoMuonEndcap_eta = booker.book1D("RecoMuonEndcap_eta", "RecoMuon RPCHit in Endcap #eta;#eta", 50, -2.5, 2.5);
121  h_recoMuonNoRPC_eta = booker.book1D("RecoMuonNoRPC_eta", "RecoMuon without RPCHit #eta;#eta", 50, -2.5, 2.5);
122  h_recoMuonBarrel_phi =
123  booker.book1D("RecoMuonBarrel_phi", "RecoMuon RPCHit in Barrel #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
124  h_recoMuonOverlap_phi =
125  booker.book1D("RecoMuonOverlap_phi", "RecoMuon RPCHit in Overlap #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
126  h_recoMuonEndcap_phi =
127  booker.book1D("RecoMuonEndcap_phi", "RecoMuon RPCHit in Endcap #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
128  h_recoMuonNoRPC_phi =
129  booker.book1D("RecoMuonNoRPC_phi", "RecoMuon without RPCHit #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
130 
131  h_simMuonBarrel_pt->getTH1()->SetMinimum(0);
132  h_simMuonOverlap_pt->getTH1()->SetMinimum(0);
133  h_simMuonEndcap_pt->getTH1()->SetMinimum(0);
134  h_simMuonNoRPC_pt->getTH1()->SetMinimum(0);
135  h_simMuonBarrel_eta->getTH1()->SetMinimum(0);
136  h_simMuonOverlap_eta->getTH1()->SetMinimum(0);
137  h_simMuonEndcap_eta->getTH1()->SetMinimum(0);
138  h_simMuonNoRPC_eta->getTH1()->SetMinimum(0);
139  h_simMuonBarrel_phi->getTH1()->SetMinimum(0);
140  h_simMuonOverlap_phi->getTH1()->SetMinimum(0);
141  h_simMuonEndcap_phi->getTH1()->SetMinimum(0);
142  h_simMuonNoRPC_phi->getTH1()->SetMinimum(0);
143 
144  h_recoMuonBarrel_pt->getTH1()->SetMinimum(0);
145  h_recoMuonOverlap_pt->getTH1()->SetMinimum(0);
146  h_recoMuonEndcap_pt->getTH1()->SetMinimum(0);
147  h_recoMuonNoRPC_pt->getTH1()->SetMinimum(0);
148  h_recoMuonBarrel_eta->getTH1()->SetMinimum(0);
149  h_recoMuonOverlap_eta->getTH1()->SetMinimum(0);
150  h_recoMuonEndcap_eta->getTH1()->SetMinimum(0);
151  h_recoMuonNoRPC_eta->getTH1()->SetMinimum(0);
152  h_recoMuonBarrel_phi->getTH1()->SetMinimum(0);
153  h_recoMuonOverlap_phi->getTH1()->SetMinimum(0);
154  h_recoMuonEndcap_phi->getTH1()->SetMinimum(0);
155  h_recoMuonNoRPC_phi->getTH1()->SetMinimum(0);
156 
157  booker.setCurrentFolder(subDir_ + "/Occupancy");
158 
159  h_eventCount = booker.book1D("EventCount", "Event count", 3, 1, 4);
160  h_eventCount->getTH1()->SetMinimum(0);
161  if (h_eventCount) {
162  TH1 *h = h_eventCount->getTH1();
163  h->GetXaxis()->SetBinLabel(1, "eventBegin");
164  h->GetXaxis()->SetBinLabel(2, "eventEnd");
165  h->GetXaxis()->SetBinLabel(3, "run");
166  }
167  h_eventCount->Fill(3);
168 
169  // Book roll-by-roll histograms
170  auto rpcGeom = eventSetup.getHandle(rpcGeomTokenInRun_);
171 
172  int nRPCRollBarrel = 0, nRPCRollEndcap = 0;
173 
174  TrackingGeometry::DetContainer rpcDets = rpcGeom->dets();
175  for (auto det : rpcDets) {
176  auto rpcCh = dynamic_cast<const RPCChamber *>(det);
177  if (!rpcCh)
178  continue;
179 
180  std::vector<const RPCRoll *> rolls = rpcCh->rolls();
181  for (auto roll : rolls) {
182  if (!roll)
183  continue;
184 
185  const int rawId = roll->geographicalId().rawId();
186 
187  if (roll->isBarrel()) {
188  detIdToIndexMapBarrel_[rawId] = nRPCRollBarrel;
189  ++nRPCRollBarrel;
190  } else {
191  detIdToIndexMapEndcap_[rawId] = nRPCRollEndcap;
192  ++nRPCRollEndcap;
193  }
194  }
195  }
196 
197  booker.setCurrentFolder(subDir_ + "/Occupancy");
198  h_matchOccupancyBarrel_detId = booker.book1D("MatchOccupancyBarrel_detId",
199  "Matched hit occupancy;roll index (can be arbitrary)",
200  nRPCRollBarrel,
201  0,
202  nRPCRollBarrel);
203  h_matchOccupancyEndcap_detId = booker.book1D("MatchOccupancyEndcap_detId",
204  "Matched hit occupancy;roll index (can be arbitrary)",
205  nRPCRollEndcap,
206  0,
207  nRPCRollEndcap);
208  h_refOccupancyBarrel_detId = booker.book1D("RefOccupancyBarrel_detId",
209  "Reference hit occupancy;roll index (can be arbitrary)",
210  nRPCRollBarrel,
211  0,
212  nRPCRollBarrel);
213  h_refOccupancyEndcap_detId = booker.book1D("RefOccupancyEndcap_detId",
214  "Reference hit occupancy;roll index (can be arbitrary)",
215  nRPCRollEndcap,
216  0,
217  nRPCRollEndcap);
218  h_allOccupancyBarrel_detId = booker.book1D(
219  "OccupancyBarrel_detId", "Occupancy;roll index (can be arbitrary)", nRPCRollBarrel, 0, nRPCRollBarrel);
220  h_allOccupancyEndcap_detId = booker.book1D(
221  "OccupancyEndcap_detId", "Occupancy;roll index (can be arbitrary)", nRPCRollEndcap, 0, nRPCRollEndcap);
222 
223  h_matchOccupancyBarrel_detId->getTH1()->SetMinimum(0);
224  h_matchOccupancyEndcap_detId->getTH1()->SetMinimum(0);
225  h_refOccupancyBarrel_detId->getTH1()->SetMinimum(0);
226  h_refOccupancyEndcap_detId->getTH1()->SetMinimum(0);
227  h_allOccupancyBarrel_detId->getTH1()->SetMinimum(0);
228  h_allOccupancyEndcap_detId->getTH1()->SetMinimum(0);
229 
230  h_rollAreaBarrel_detId = booker.bookProfile(
231  "RollAreaBarrel_detId", "Roll area;roll index;Area", nRPCRollBarrel, 0., 1. * nRPCRollBarrel, 0., 1e5);
232  h_rollAreaEndcap_detId = booker.bookProfile(
233  "RollAreaEndcap_detId", "Roll area;roll index;Area", nRPCRollEndcap, 0., 1. * nRPCRollEndcap, 0., 1e5);
234 
235  for (auto detIdToIndex : detIdToIndexMapBarrel_) {
236  const int rawId = detIdToIndex.first;
237  const int index = detIdToIndex.second;
238 
239  const RPCDetId rpcDetId = static_cast<const RPCDetId>(rawId);
240  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(rpcDetId));
241 
242  const StripTopology &topol = roll->specificTopology();
243  const double area = topol.stripLength() * topol.nstrips() * topol.pitch();
244 
245  h_rollAreaBarrel_detId->Fill(index, area);
246  }
247 
248  for (auto detIdToIndex : detIdToIndexMapEndcap_) {
249  const int rawId = detIdToIndex.first;
250  const int index = detIdToIndex.second;
251 
252  const RPCDetId rpcDetId = static_cast<const RPCDetId>(rawId);
253  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(rpcDetId));
254 
255  const StripTopology &topol = roll->specificTopology();
256  const double area = topol.stripLength() * topol.nstrips() * topol.pitch();
257 
258  h_rollAreaEndcap_detId->Fill(index, area);
259  }
260 }
261 
263  h_eventCount->Fill(1);
264 
265  // Get the RPC Geometry
266  auto rpcGeom = eventSetup.getHandle(rpcGeomToken_);
267 
268  // Retrieve SimHits from the event
270  if (!event.getByToken(simHitToken_, simHitHandle)) {
271  edm::LogInfo("RPCRecHitValid") << "Cannot find simHit collection\n";
272  return;
273  }
274 
275  // Retrieve RecHits from the event
277  if (!event.getByToken(recHitToken_, recHitHandle)) {
278  edm::LogInfo("RPCRecHitValid") << "Cannot find recHit collection\n";
279  return;
280  }
281 
282  // Get SimParticles
283  edm::Handle<TrackingParticleCollection> simParticleHandle;
284  if (!event.getByToken(simParticleToken_, simParticleHandle)) {
285  edm::LogInfo("RPCRecHitValid") << "Cannot find TrackingParticle collection\n";
286  return;
287  }
288 
289  // Get SimParticle to SimHit association map
291  if (!event.getByToken(simHitAssocToken_, simHitsTPAssoc)) {
292  edm::LogInfo("RPCRecHitValid") << "Cannot find TrackingParticle to SimHit association map\n";
293  return;
294  }
295 
296  // Get RecoMuons
298  if (!event.getByToken(muonToken_, muonHandle)) {
299  edm::LogInfo("RPCRecHitValid") << "Cannot find muon collection\n";
300  return;
301  }
302 
303  typedef edm::PSimHitContainer::const_iterator SimHitIter;
304  typedef RPCRecHitCollection::const_iterator RecHitIter;
305  typedef std::vector<TrackPSimHitRef> SimHitRefs;
306 
307  // TrackingParticles with (and without) RPC simHits
308  SimHitRefs muonSimHits;
309 
310  for (int i = 0, n = simParticleHandle->size(); i < n; ++i) {
311  TrackingParticleRef simParticle(simParticleHandle, i);
312  if (simParticle->pt() < 1.0 or simParticle->p() < 2.5)
313  continue; // globalMuon acceptance
314 
315  // Collect SimHits from this Tracking Particle
316  SimHitRefs simHitsFromParticle;
317  auto range = std::equal_range(simHitsTPAssoc->begin(),
318  simHitsTPAssoc->end(),
319  std::make_pair(simParticle, TrackPSimHitRef()),
321  for (auto simParticleToHit = range.first; simParticleToHit != range.second; ++simParticleToHit) {
322  auto simHit = simParticleToHit->second;
323  const DetId detId(simHit->detUnitId());
324  if (detId.det() != DetId::Muon or detId.subdetId() != MuonSubdetId::RPC)
325  continue;
326 
327  simHitsFromParticle.push_back(simParticleToHit->second);
328  }
329  const int nRPCHit = simHitsFromParticle.size();
330  const bool hasRPCHit = nRPCHit > 0;
331 
332  if (abs(simParticle->pdgId()) == 13) {
333  muonSimHits.insert(muonSimHits.end(), simHitsFromParticle.begin(), simHitsFromParticle.end());
334 
335  // Count number of Barrel hits and Endcap hits
336  int nRPCHitBarrel = 0;
337  int nRPCHitEndcap = 0;
338  for (const auto &simHit : simHitsFromParticle) {
339  const RPCDetId rpcDetId{simHit->detUnitId()};
340  const RPCRoll *roll = rpcGeom->roll(rpcDetId);
341  if (!roll)
342  continue;
343 
344  if (rpcDetId.region() == 0)
345  ++nRPCHitBarrel;
346  else
347  ++nRPCHitEndcap;
348  }
349 
350  // Fill TrackingParticle related histograms
351  h_nRPCHitPerSimMuon->Fill(nRPCHit);
352  if (nRPCHitBarrel and nRPCHitEndcap) {
353  h_nRPCHitPerSimMuonOverlap->Fill(nRPCHit);
354  h_simMuonOverlap_pt->Fill(simParticle->pt());
355  h_simMuonOverlap_eta->Fill(simParticle->eta());
356  h_simMuonOverlap_phi->Fill(simParticle->phi());
357  } else if (nRPCHitBarrel) {
358  h_nRPCHitPerSimMuonBarrel->Fill(nRPCHit);
359  h_simMuonBarrel_pt->Fill(simParticle->pt());
360  h_simMuonBarrel_eta->Fill(simParticle->eta());
361  h_simMuonBarrel_phi->Fill(simParticle->phi());
362  } else if (nRPCHitEndcap) {
363  h_nRPCHitPerSimMuonEndcap->Fill(nRPCHit);
364  h_simMuonEndcap_pt->Fill(simParticle->pt());
365  h_simMuonEndcap_eta->Fill(simParticle->eta());
366  h_simMuonEndcap_phi->Fill(simParticle->phi());
367  } else {
368  h_simMuonNoRPC_pt->Fill(simParticle->pt());
369  h_simMuonNoRPC_eta->Fill(simParticle->eta());
370  h_simMuonNoRPC_phi->Fill(simParticle->phi());
371  }
372  }
373 
374  if (hasRPCHit) {
375  switch (simParticle->pdgId()) {
376  case 13:
377  h_simParticleType->Fill(0);
378  break;
379  case -13:
380  h_simParticleType->Fill(1);
381  break;
382  case 11:
383  h_simParticleType->Fill(2);
384  break;
385  case -11:
386  h_simParticleType->Fill(3);
387  break;
388  case 211:
389  h_simParticleType->Fill(4);
390  break;
391  case -211:
392  h_simParticleType->Fill(5);
393  break;
394  case 321:
395  h_simParticleType->Fill(6);
396  break;
397  case -321:
398  h_simParticleType->Fill(7);
399  break;
400  case 2212:
401  h_simParticleType->Fill(8);
402  break;
403  case -2212:
404  h_simParticleType->Fill(9);
405  break;
406  default:
407  h_simParticleType->Fill(10);
408  break;
409  }
410  }
411  }
412 
413  // Loop over muon simHits, fill histograms which does not need associations
414  int nRefHitBarrel = 0, nRefHitEndcap = 0;
415  for (const auto &simHit : muonSimHits) {
416  const RPCDetId detId = static_cast<const RPCDetId>(simHit->detUnitId());
417  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(detId));
418 
419  const int region = roll->id().region();
420  const int ring = roll->id().ring();
421  const int station = roll->id().station();
422 
423  if (region == 0) {
424  ++nRefHitBarrel;
425  h_.refHitOccupancyBarrel_wheel->Fill(ring);
426  h_.refHitOccupancyBarrel_station->Fill(station);
427  h_.refHitOccupancyBarrel_wheel_station->Fill(ring, station);
428 
429  h_refOccupancyBarrel_detId->Fill(detIdToIndexMapBarrel_[simHit->detUnitId()]);
430  } else {
431  ++nRefHitEndcap;
432  h_.refHitOccupancyEndcap_disk->Fill(region * station);
433  h_.refHitOccupancyEndcap_disk_ring->Fill(region * station, ring);
434 
435  h_refOccupancyEndcap_detId->Fill(detIdToIndexMapEndcap_[simHit->detUnitId()]);
436  }
437  }
438 
439  h_.nRefHitBarrel->Fill(nRefHitBarrel);
440  h_.nRefHitEndcap->Fill(nRefHitEndcap);
441 
442  // Loop over recHits, fill histograms which does not need associations
443  int sumClusterSizeBarrel = 0, sumClusterSizeEndcap = 0;
444  int nRecHitBarrel = 0, nRecHitEndcap = 0;
445  for (RecHitIter recHitIter = recHitHandle->begin(); recHitIter != recHitHandle->end(); ++recHitIter) {
446  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
447  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(detId()));
448  if (!roll)
449  continue;
450 
451  const int region = roll->id().region();
452  const int ring = roll->id().ring();
453  const int station = roll->id().station();
454 
455  const double time = recHitIter->timeError() >= 0 ? recHitIter->time() : recHitIter->BunchX() * 25;
456 
457  h_.clusterSize->Fill(recHitIter->clusterSize());
458 
459  if (region == 0) {
460  ++nRecHitBarrel;
461  sumClusterSizeBarrel += recHitIter->clusterSize();
462  h_.clusterSizeBarrel->Fill(recHitIter->clusterSize());
463  h_.recHitOccupancyBarrel_wheel->Fill(ring);
464  h_.recHitOccupancyBarrel_station->Fill(station);
465  h_.recHitOccupancyBarrel_wheel_station->Fill(ring, station);
466 
467  h_allOccupancyBarrel_detId->Fill(detIdToIndexMapBarrel_[detId.rawId()]);
468 
469  h_.timeBarrel->Fill(time);
470  } else {
471  ++nRecHitEndcap;
472  sumClusterSizeEndcap += recHitIter->clusterSize();
473  h_.clusterSizeEndcap->Fill(recHitIter->clusterSize());
474  h_.recHitOccupancyEndcap_disk->Fill(region * station);
475  h_.recHitOccupancyEndcap_disk_ring->Fill(region * station, ring);
476 
477  h_allOccupancyEndcap_detId->Fill(detIdToIndexMapEndcap_[detId.rawId()]);
478 
479  h_.timeEndcap->Fill(time);
480  }
481 
482  if (roll->isIRPC()) {
483  h_.timeIRPC->Fill(time);
484  } else {
485  h_.timeCRPC->Fill(time);
486  }
487  }
488  const double nRecHit = nRecHitBarrel + nRecHitEndcap;
489  h_.nRecHitBarrel->Fill(nRecHitBarrel);
490  h_.nRecHitEndcap->Fill(nRecHitEndcap);
491  if (nRecHit > 0) {
492  const int sumClusterSize = sumClusterSizeBarrel + sumClusterSizeEndcap;
493  h_.avgClusterSize->Fill(double(sumClusterSize) / nRecHit);
494 
495  if (nRecHitBarrel > 0) {
496  h_.avgClusterSizeBarrel->Fill(double(sumClusterSizeBarrel) / nRecHitBarrel);
497  }
498  if (nRecHitEndcap > 0) {
499  h_.avgClusterSizeEndcap->Fill(double(sumClusterSizeEndcap) / nRecHitEndcap);
500  }
501  }
502 
503  // Start matching SimHits to RecHits
504  typedef std::map<TrackPSimHitRef, RecHitIter> SimToRecHitMap;
505  SimToRecHitMap simToRecHitMap;
506 
507  for (const auto &simHit : muonSimHits) {
508  const RPCDetId simDetId{simHit->detUnitId()};
509 
510  const double simX = simHit->localPosition().x();
511 
512  for (RecHitIter recHitIter = recHitHandle->begin(); recHitIter != recHitHandle->end(); ++recHitIter) {
513  const RPCDetId recDetId{recHitIter->rpcId()};
514  const RPCRoll *recRoll = rpcGeom->roll(recDetId);
515  if (!recRoll)
516  continue;
517 
518  if (simDetId != recDetId)
519  continue;
520 
521  const double recX = recHitIter->localPosition().x();
522  const double newDx = fabs(recX - simX);
523 
524  // Associate SimHit to RecHit
525  SimToRecHitMap::const_iterator prevSimToReco = simToRecHitMap.find(simHit);
526  if (prevSimToReco == simToRecHitMap.end()) {
527  simToRecHitMap.insert(std::make_pair(simHit, recHitIter));
528  } else {
529  const double oldDx = fabs(prevSimToReco->second->localPosition().x() - simX);
530 
531  if (newDx < oldDx) {
532  simToRecHitMap[simHit] = recHitIter;
533  }
534  }
535  }
536  }
537 
538  // Now we have simHit-recHit mapping
539  // So we can fill up relavant histograms
540  int nMatchHitBarrel = 0, nMatchHitEndcap = 0;
541  for (const auto &match : simToRecHitMap) {
542  TrackPSimHitRef simHit = match.first;
543  RecHitIter recHitIter = match.second;
544 
545  const RPCDetId detId = static_cast<const RPCDetId>(simHit->detUnitId());
546  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(detId));
547 
548  const int region = roll->id().region();
549  const int ring = roll->id().ring();
550  const int station = roll->id().station();
551 
552  const double simX = simHit->localPosition().x();
553  const double recX = recHitIter->localPosition().x();
554  const double errX = sqrt(recHitIter->localPositionError().xx());
555  const double dX = recX - simX;
556  const double pull = errX == 0 ? -999 : dX / errX;
557 
558  if (region == 0) {
559  ++nMatchHitBarrel;
560  h_.resBarrel->Fill(dX);
561  h_.pullBarrel->Fill(pull);
562  h_.matchOccupancyBarrel_wheel->Fill(ring);
563  h_.matchOccupancyBarrel_station->Fill(station);
564  h_.matchOccupancyBarrel_wheel_station->Fill(ring, station);
565 
566  h_.res_wheel_res->Fill(ring, dX);
567  h_.res_station_res->Fill(station, dX);
568  h_.pull_wheel_pull->Fill(ring, pull);
569  h_.pull_station_pull->Fill(station, pull);
570 
571  h_matchOccupancyBarrel_detId->Fill(detIdToIndexMapBarrel_[detId.rawId()]);
572  } else {
573  ++nMatchHitEndcap;
574  h_.resEndcap->Fill(dX);
575  h_.pullEndcap->Fill(pull);
576  h_.matchOccupancyEndcap_disk->Fill(region * station);
577  h_.matchOccupancyEndcap_disk_ring->Fill(region * station, ring);
578 
579  h_.res_disk_res->Fill(region * station, dX);
580  h_.res_ring_res->Fill(ring, dX);
581  h_.pull_disk_pull->Fill(region * station, pull);
582  h_.pull_ring_pull->Fill(ring, pull);
583 
584  h_matchOccupancyEndcap_detId->Fill(detIdToIndexMapEndcap_[detId.rawId()]);
585  }
586  }
587  h_.nMatchHitBarrel->Fill(nMatchHitBarrel);
588  h_.nMatchHitEndcap->Fill(nMatchHitEndcap);
589 
590  // Reco Muon hits
591  for (reco::MuonCollection::const_iterator muon = muonHandle->begin(); muon != muonHandle->end(); ++muon) {
592  if (!muon->isGlobalMuon())
593  continue;
594 
595  int nRPCHitBarrel = 0;
596  int nRPCHitEndcap = 0;
597 
598  const reco::TrackRef glbTrack = muon->globalTrack();
599  for (trackingRecHit_iterator recHit = glbTrack->recHitsBegin(); recHit != glbTrack->recHitsEnd(); ++recHit) {
600  if (!(*recHit)->isValid())
601  continue;
602  const DetId detId = (*recHit)->geographicalId();
603  if (detId.det() != DetId::Muon or detId.subdetId() != MuonSubdetId::RPC)
604  continue;
605  const RPCDetId rpcDetId = static_cast<const RPCDetId>(detId);
606 
607  if (rpcDetId.region() == 0)
608  ++nRPCHitBarrel;
609  else
610  ++nRPCHitEndcap;
611  }
612 
613  const int nRPCHit = nRPCHitBarrel + nRPCHitEndcap;
614  h_nRPCHitPerRecoMuon->Fill(nRPCHit);
615  if (nRPCHitBarrel and nRPCHitEndcap) {
616  h_nRPCHitPerRecoMuonOverlap->Fill(nRPCHit);
617  h_recoMuonOverlap_pt->Fill(muon->pt());
618  h_recoMuonOverlap_eta->Fill(muon->eta());
619  h_recoMuonOverlap_phi->Fill(muon->phi());
620  } else if (nRPCHitBarrel) {
621  h_nRPCHitPerRecoMuonBarrel->Fill(nRPCHit);
622  h_recoMuonBarrel_pt->Fill(muon->pt());
623  h_recoMuonBarrel_eta->Fill(muon->eta());
624  h_recoMuonBarrel_phi->Fill(muon->phi());
625  } else if (nRPCHitEndcap) {
626  h_nRPCHitPerRecoMuonEndcap->Fill(nRPCHit);
627  h_recoMuonEndcap_pt->Fill(muon->pt());
628  h_recoMuonEndcap_eta->Fill(muon->eta());
629  h_recoMuonEndcap_phi->Fill(muon->phi());
630  } else {
631  h_recoMuonNoRPC_pt->Fill(muon->pt());
632  h_recoMuonNoRPC_eta->Fill(muon->eta());
633  h_recoMuonNoRPC_phi->Fill(muon->phi());
634  }
635  }
636 
637  h_eventCount->Fill(2);
638 }
639 
const double Pi
virtual int nstrips() const =0
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
RPCRecHitValid(const edm::ParameterSet &pset)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
std::vector< const GeomDet * > DetContainer
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
virtual float stripLength() const =0
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:408
T sqrt(T t)
Definition: SSEVec.h:23
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
RPCRecHitValid::MonitorElement * MEP
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
Definition: DetId.h:17
float dX(const MatchPair &match)
static constexpr int RPC
Definition: MuonSubdetId.h:13
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
virtual TH1 * getTH1() const
virtual float pitch() const =0
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
const std::vector< const RPCRoll * > & rolls() const
Return the Rolls.
Definition: RPCChamber.cc:40
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: event.py:1
Definition: Run.h:45