CMS 3D CMS Logo

RPCMonitorDigi.cc
Go to the documentation of this file.
4 
7 
11 
12 #include <set>
13 #include <fmt/format.h>
14 
15 const std::array<std::string, 3> RPCMonitorDigi::regionNames_ = {{"Endcap-", "Barrel", "Endcap+"}};
16 
18  : counter(0),
19  muonRPCEvents_(nullptr),
20  NumberOfRecHitMuon_(nullptr),
21  NumberOfMuon_(nullptr),
22  numberOfDisks_(0),
23  numberOfInnerRings_(0) {
24  useMuonDigis_ = pset.getUntrackedParameter<bool>("UseMuon", true);
25  useRollInfo_ = pset.getUntrackedParameter<bool>("UseRollInfo", false);
26 
27  muPtCut_ = pset.getUntrackedParameter<double>("MuonPtCut", 3.0);
28  muEtaCut_ = pset.getUntrackedParameter<double>("MuonEtaCut", 1.9);
29 
30  subsystemFolder_ = pset.getUntrackedParameter<std::string>("RPCFolder", "RPC");
31  globalFolder_ = pset.getUntrackedParameter<std::string>("GlobalFolder", "SummaryHistograms");
32 
33  //Parametersets for tokens
34  muonLabel_ = consumes<reco::CandidateView>(pset.getParameter<edm::InputTag>("MuonLabel"));
35  rpcRecHitLabel_ = consumes<RPCRecHitCollection>(pset.getParameter<edm::InputTag>("RecHitLabel"));
36  scalersRawToDigiLabel_ = consumes<DcsStatusCollection>(pset.getParameter<edm::InputTag>("ScalersRawToDigiLabel"));
37 
38  noiseFolder_ = pset.getUntrackedParameter<std::string>("NoiseFolder", "AllHits");
39  muonFolder_ = pset.getUntrackedParameter<std::string>("MuonFolder", "Muon");
40 
41  rpcGeomToken_ = esConsumes<edm::Transition::BeginRun>();
42 }
43 
45  edm::LogInfo("rpcmonitordigi") << "[RPCMonitorDigi]: Begin Run ";
46 
47  numberOfInnerRings_ = 4; // set default value
48 
49  std::set<int> disk_set;
50  const auto& rpcGeo = iSetup.getData(rpcGeomToken_);
51 
52  //loop on geometry to book all MEs
53  edm::LogInfo("rpcmonitordigi") << "[RPCMonitorDigi]: Booking histograms per roll. ";
54  for (auto ich : rpcGeo.dets()) {
55  const RPCChamber* ch = dynamic_cast<const RPCChamber*>(ich);
56  if (!ch)
57  continue;
58  const auto& roles = ch->rolls();
59 
60  if (useRollInfo_) {
61  for (auto roll : roles) {
62  const RPCDetId& rpcId = roll->id();
63 
64  //get station and inner ring
65  if (rpcId.region() != 0) {
66  disk_set.insert(rpcId.station());
68  }
69 
70  //booking all histograms
71  const std::string nameID = RPCNameHelper::rollName(rpcId);
72  if (useMuonDigis_)
73  bookRollME(ibooker, rpcId, &rpcGeo, muonFolder_, meMuonCollection[nameID]);
74  bookRollME(ibooker, rpcId, &rpcGeo, noiseFolder_, meNoiseCollection[nameID]);
75  }
76  } else {
77  const RPCDetId& rpcId = roles[0]->id(); //any roll would do - here I just take the first one
78  const std::string nameID = RPCNameHelper::chamberName(rpcId);
79  if (useMuonDigis_)
80  bookRollME(ibooker, rpcId, &rpcGeo, muonFolder_, meMuonCollection[nameID]);
81  bookRollME(ibooker, rpcId, &rpcGeo, noiseFolder_, meNoiseCollection[nameID]);
82  if (rpcId.region() != 0) {
83  disk_set.insert(rpcId.station());
85  }
86  }
87  } //end loop on geometry to book all MEs
88 
89  numberOfDisks_ = disk_set.size();
90 
91  //Book
95 
97 
98  noiseRPCEvents_ = ibooker.book1D("RPCEvents", "RPCEvents", 1, 0.5, 1.5);
99 
100  if (useMuonDigis_) {
104 
106 
107  muonRPCEvents_ = ibooker.book1D("RPCEvents", "RPCEvents", 1, 0.5, 1.5);
108  NumberOfMuon_ = ibooker.book1D("NumberOfMuons", "Number of Muons", 11, -0.5, 10.5);
109  NumberOfRecHitMuon_ = ibooker.book1D("NumberOfRecHitMuons", "Number of RPC RecHits per Muon", 8, -0.5, 7.5);
110  }
111 }
112 
114  counter++;
115  edm::LogInfo("rpcmonitordigi") << "[RPCMonitorDigi]: Beginning analyzing event " << counter;
116 
117  //Muons
119  event.getByToken(muonLabel_, muonCands);
120 
121  std::map<RPCDetId, std::vector<RPCRecHit> > rechitMuon;
122 
123  int numMuons = 0;
124  int numRPCRecHit = 0;
125 
126  if (muonCands.isValid()) {
127  int nStaMuons = muonCands->size();
128 
129  for (int i = 0; i < nStaMuons; i++) {
130  const reco::Candidate& goodMuon = (*muonCands)[i];
131  const reco::Muon* muCand = dynamic_cast<const reco::Muon*>(&goodMuon);
132 
133  if (!muCand->isGlobalMuon())
134  continue;
135  if (muCand->pt() < muPtCut_ || fabs(muCand->eta()) > muEtaCut_)
136  continue;
137  numMuons++;
138  reco::Track muTrack = (*(muCand->outerTrack()));
139  std::vector<TrackingRecHitRef> rpcTrackRecHits;
140  //loop on mu rechits
141  for (trackingRecHit_iterator it = muTrack.recHitsBegin(); it != muTrack.recHitsEnd(); it++) {
142  if (!(*it)->isValid())
143  continue;
144  int muSubDetId = (*it)->geographicalId().subdetId();
145  if (muSubDetId == MuonSubdetId::RPC) {
146  numRPCRecHit++;
147  TrackingRecHit* tkRecHit = (*it)->clone();
148  RPCRecHit* rpcRecHit = dynamic_cast<RPCRecHit*>(tkRecHit);
149  int detId = (int)rpcRecHit->rpcId();
150  if (rechitMuon.find(detId) == rechitMuon.end() || rechitMuon[detId].empty()) {
151  std::vector<RPCRecHit> myVect(1, *rpcRecHit);
152  rechitMuon[detId] = myVect;
153  } else {
154  rechitMuon[detId].push_back(*rpcRecHit);
155  }
156  }
157  } // end loop on mu rechits
158  }
159 
160  //Fill muon counter
161  if (NumberOfMuon_) {
163  }
164 
165  //Fill rechit counter for muons
166  if (NumberOfRecHitMuon_ && numMuons > 0) {
167  NumberOfRecHitMuon_->Fill(numRPCRecHit);
168  }
169 
170  //Fill counter of RPC events with rechits associated in with a muon
171  if (muonRPCEvents_ != nullptr && numRPCRecHit > 0) {
172  muonRPCEvents_->Fill(1);
173  }
174 
175  //Perform client operation
176  this->performSourceOperation(rechitMuon, muonFolder_);
177 
178  } else {
179  edm::LogError("rpcmonitordigi") << "[RPCMonitorDigi]: Muons - Product not valid for event" << counter;
180  }
181 
182  //RecHits
184  event.getByToken(rpcRecHitLabel_, rpcHits);
185  std::map<RPCDetId, std::vector<RPCRecHit> > rechitNoise;
186 
187  if (rpcHits.isValid()) {
188  // RPC rec hits NOT associated to a muon
189  for (auto rpcRecHitIter = rpcHits->begin(); rpcRecHitIter != rpcHits->end(); rpcRecHitIter++) {
190  const RPCRecHit& rpcRecHit = (*rpcRecHitIter);
191  int detId = (int)rpcRecHit.rpcId();
192  if (rechitNoise.find(detId) == rechitNoise.end() || rechitNoise[detId].empty()) {
193  std::vector<RPCRecHit> myVect(1, rpcRecHit);
194  rechitNoise[detId] = myVect;
195  } else {
196  rechitNoise[detId].push_back(rpcRecHit);
197  }
198  }
199  } else {
200  edm::LogError("rpcmonitordigi") << "[RPCMonitorDigi]: RPCRecHits - Product not valid for event" << counter;
201  }
202 
203  //Fill counter for all RPC events
204  if (noiseRPCEvents_ != nullptr && !rechitNoise.empty()) {
205  noiseRPCEvents_->Fill(1);
206  }
207  //Perform client operation
208  this->performSourceOperation(rechitNoise, noiseFolder_);
209 }
210 
211 void RPCMonitorDigi::performSourceOperation(std::map<RPCDetId, std::vector<RPCRecHit> >& recHitMap,
212  std::string recHittype) {
213  edm::LogInfo("rpcmonitordigi") << "[RPCMonitorDigi]: Performing DQM source operations for ";
214 
215  if (recHitMap.empty())
216  return;
217 
218  std::map<std::string, std::map<std::string, MonitorElement*> > meRollCollection;
219  std::map<std::string, MonitorElement*> meWheelDisk;
220  std::map<std::string, MonitorElement*> meRegion;
221  std::map<std::string, MonitorElement*> meSectorRing;
222 
223  if (recHittype == muonFolder_) {
224  meRollCollection = meMuonCollection;
225  meWheelDisk = wheelDiskMuonCollection;
226  meRegion = regionMuonCollection;
227  meSectorRing = sectorRingMuonCollection;
228  } else if (recHittype == noiseFolder_) {
229  meRollCollection = meNoiseCollection;
230  meWheelDisk = wheelDiskNoiseCollection;
231  meRegion = regionNoiseCollection;
232  meSectorRing = sectorRingNoiseCollection;
233  } else {
234  edm::LogWarning("rpcmonitordigi") << "[RPCMonitorDigi]: RecHit type not valid.";
235  return;
236  }
237 
238  int totalNumberOfRecHits[3] = {0, 0, 0};
239 
240  //Loop on Rolls
241  for (std::map<RPCDetId, std::vector<RPCRecHit> >::const_iterator detIdIter = recHitMap.begin();
242  detIdIter != recHitMap.end();
243  detIdIter++) {
244  RPCDetId detId = (*detIdIter).first;
245  RPCGeomServ geoServ(detId);
246 
247  //get roll number
248  rpcdqm::utils rpcUtils;
249  int nr = rpcUtils.detId2RollNr(detId);
250 
252 
253  int region = (int)detId.region();
254  int wheelOrDiskNumber;
255  std::string wheelOrDiskType;
256  int ring = 0;
257  int sector = detId.sector();
258  int totalRolls = 3;
259  int roll = detId.roll();
260  if (region == 0) {
261  wheelOrDiskType = "Wheel";
262  wheelOrDiskNumber = (int)detId.ring();
263  int station = detId.station();
264 
265  if (station == 1) {
266  if (detId.layer() == 1) {
267  totalRolls = 2; //RB1in
268  } else {
269  totalRolls = 2; //RB1out
270  }
271  if (roll == 3)
272  roll = 2; // roll=3 is Forward
273  } else if (station == 2) {
274  if (detId.layer() == 1) {
275  //RB2in
276  if (abs(wheelOrDiskNumber) == 2 && roll == 3) {
277  roll = 2; //W -2, +2 RB2in has only 2 rolls
278  totalRolls = 2;
279  }
280  } else {
281  //RB2out
282  if (abs(wheelOrDiskNumber) != 2 && roll == 3) {
283  roll = 2; //W -1, 0, +1 RB2out has only 2 rolls
284  totalRolls = 2;
285  }
286  }
287  } else if (station == 3) {
288  totalRolls = 2; //RB3
289  if (roll == 3)
290  roll = 2;
291  } else {
292  totalRolls = 2; //RB4
293  if (roll == 3)
294  roll = 2;
295  }
296 
297  } else {
298  wheelOrDiskType = "Disk";
299  wheelOrDiskNumber = region * (int)detId.station();
300  ring = detId.ring();
301  }
302 
303  std::vector<RPCRecHit> recHits = (*detIdIter).second;
304  const int numberOfRecHits = recHits.size();
305  totalNumberOfRecHits[region + 1] += numberOfRecHits;
306 
307  std::set<int> bxSet;
308  int numDigi = 0;
309 
310  std::map<std::string, MonitorElement*> meMap = meRollCollection[nameRoll];
311 
312  //Loop on recHits
313  std::string tmpName;
314  for (std::vector<RPCRecHit>::const_iterator recHitIter = recHits.begin(); recHitIter != recHits.end();
315  recHitIter++) {
316  const RPCRecHit& recHit = (*recHitIter);
317 
318  int bx = recHit.BunchX();
319  bxSet.insert(bx);
320  int clusterSize = (int)recHit.clusterSize();
321  numDigi += clusterSize;
322  int firstStrip = recHit.firstClusterStrip();
323  int lastStrip = clusterSize + firstStrip - 1;
324 
325  // ###################### Roll Level #################################
326 
327  tmpName = "Occupancy_" + nameRoll;
328  if (meMap[tmpName]) {
329  for (int s = firstStrip; s <= lastStrip; s++) {
330  if (useRollInfo_) {
331  meMap[tmpName]->Fill(s);
332  } else {
333  const int nstrips = meMap[tmpName]->getNbinsX() / totalRolls;
334  meMap[tmpName]->Fill(s + nstrips * (roll - 1));
335  }
336  }
337  }
338 
339  tmpName = "BXDistribution_" + nameRoll;
340  if (meMap[tmpName])
341  meMap[tmpName]->Fill(bx);
342 
343  // ###################### Sector- Ring Level #################################
344 
345  tmpName = fmt::format("Occupancy_{}_{}_Sector_{}", wheelOrDiskType, wheelOrDiskNumber, sector);
346  if (meSectorRing[tmpName]) {
347  for (int s = firstStrip; s <= lastStrip; s++) { //Loop on digis
348  meSectorRing[tmpName]->Fill(s, nr);
349  }
350  }
351 
352  tmpName = fmt::format("ClusterSize_{}_{}_Sector_{}", wheelOrDiskType, wheelOrDiskNumber, sector);
353  if (meSectorRing[tmpName]) {
354  if (clusterSize >= meSectorRing[tmpName]->getNbinsX())
355  meSectorRing[tmpName]->Fill(meSectorRing[tmpName]->getNbinsX(), nr);
356  else
357  meSectorRing[tmpName]->Fill(clusterSize, nr);
358  }
359 
360  tmpName = fmt::format("Occupancy_{}_{}_Ring_{}", wheelOrDiskType, wheelOrDiskNumber, ring);
361  if (geoServ.segment() > 0 && geoServ.segment() <= 18) {
362  tmpName += "_CH01-CH18";
363  } else if (geoServ.segment() >= 19) {
364  tmpName += "_CH19-CH36";
365  }
366 
367  if (meSectorRing[tmpName]) {
368  for (int s = firstStrip; s <= lastStrip; s++) { //Loop on digis
369  meSectorRing[tmpName]->Fill(s + 32 * (detId.roll() - 1), geoServ.segment());
370  }
371  }
372 
373  tmpName = fmt::format("ClusterSize_{}_{}_Ring_{}", wheelOrDiskType, wheelOrDiskNumber, ring);
374  if (geoServ.segment() > 0 && geoServ.segment() <= 9) {
375  tmpName += "_CH01-CH09";
376  } else if (geoServ.segment() >= 10 && geoServ.segment() <= 18) {
377  tmpName += "_CH10-CH18";
378  } else if (geoServ.segment() >= 19 && geoServ.segment() <= 27) {
379  tmpName += "_CH19-CH27";
380  } else if (geoServ.segment() >= 28 && geoServ.segment() <= 36) {
381  tmpName += "_CH28-CH36";
382  }
383 
384  if (meSectorRing[tmpName]) {
385  if (clusterSize >= meSectorRing[tmpName]->getNbinsX())
386  meSectorRing[tmpName]->Fill(meSectorRing[tmpName]->getNbinsX(),
387  3 * (geoServ.segment() - 1) + (3 - detId.roll()) + 1);
388  else
389  meSectorRing[tmpName]->Fill(clusterSize, 3 * (geoServ.segment() - 1) + (3 - detId.roll()) + 1);
390  }
391 
392  // ###################### Wheel/Disk Level #########################
393  if (region == 0) {
394  tmpName = fmt::format("1DOccupancy_Wheel_{}", wheelOrDiskNumber);
395  if (meWheelDisk[tmpName])
396  meWheelDisk[tmpName]->Fill(sector, clusterSize);
397 
398  tmpName = fmt::format("Occupancy_Roll_vs_Sector_{}_{}", wheelOrDiskType, wheelOrDiskNumber);
399  if (meWheelDisk[tmpName])
400  meWheelDisk[tmpName]->Fill(sector, nr, clusterSize);
401 
402  } else {
403  tmpName = fmt::format("1DOccupancy_Ring_{}", ring);
404  if ((meWheelDisk[tmpName])) {
405  if (wheelOrDiskNumber > 0) {
406  meWheelDisk[tmpName]->Fill(wheelOrDiskNumber + numberOfDisks_, clusterSize);
407  } else {
408  meWheelDisk[tmpName]->Fill(wheelOrDiskNumber + numberOfDisks_ + 1, clusterSize);
409  }
410  }
411 
412  tmpName = fmt::format("Occupancy_Ring_vs_Segment_{}_{}", wheelOrDiskType, wheelOrDiskNumber);
413  if (meWheelDisk[tmpName])
414  meWheelDisk[tmpName]->Fill(geoServ.segment(), (ring - 1) * 3 - detId.roll() + 1, clusterSize);
415  }
416 
417  tmpName = fmt::format("BxDistribution_{}_{}", wheelOrDiskType, wheelOrDiskNumber);
418  if (meWheelDisk[tmpName])
419  meWheelDisk[tmpName]->Fill(bx);
420 
421  } //end loop on recHits
422 
423  tmpName = "BXWithData_" + nameRoll;
424  if (meMap[tmpName])
425  meMap[tmpName]->Fill(bxSet.size());
426 
427  tmpName = "NumberOfClusters_" + nameRoll;
428  if (meMap[tmpName])
429  meMap[tmpName]->Fill(numberOfRecHits);
430 
431  tmpName = "Multiplicity_" + RPCMonitorDigi::regionNames_[region + 1];
432  if (meRegion[tmpName])
433  meRegion[tmpName]->Fill(numDigi);
434 
435  if (region == 0) {
436  if (meRegion["Occupancy_for_Barrel"])
437  meRegion["Occupancy_for_Barrel"]->Fill(sector, wheelOrDiskNumber, numDigi);
438  } else {
439  int xbin = wheelOrDiskNumber + numberOfDisks_;
440  if (region == -1) {
441  xbin = wheelOrDiskNumber + numberOfDisks_ + 1;
442  }
443  if (meRegion["Occupancy_for_Endcap"]) {
444  meRegion["Occupancy_for_Endcap"]->Fill(xbin, ring, numDigi);
445  }
446  }
447 
448  tmpName = "Multiplicity_" + nameRoll;
449  if (meMap[tmpName])
450  meMap[tmpName]->Fill(numDigi);
451 
452  } //end loop on rolls
453 
454  for (int i = 0; i < 3; i++) {
455  const std::string tmpName = "NumberOfClusters_" + RPCMonitorDigi::regionNames_[i];
456  if (meRegion[tmpName])
457  meRegion[tmpName]->Fill(totalNumberOfRecHits[i]);
458  }
459 }
std::map< std::string, std::map< std::string, MonitorElement * > > meMuonCollection
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::string globalFolder_
double pt() const final
transverse momentum
std::string muonFolder_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::map< std::string, MonitorElement * > wheelDiskNoiseCollection
std::map< std::string, MonitorElement * > sectorRingMuonCollection
int ring() const
Definition: RPCDetId.h:59
MonitorElement * muonRPCEvents_
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:48
RPCMonitorDigi(const edm::ParameterSet &)
Log< level::Error, false > LogError
void analyze(const edm::Event &, const edm::EventSetup &) override
std::string noiseFolder_
static std::string rollName(const RPCDetId &detId)
void bookSectorRingME(DQMStore::IBooker &, const std::string &, std::map< std::string, MonitorElement *> &)
Booking of MonitoringElement at Sector/Ring level.
size_type size() const
void Fill(long long x)
RPCDetId rpcId() const
Return the rpcId.
Definition: RPCRecHit.h:71
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
static const std::array< std::string, 3 > regionNames_
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeomToken_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
MonitorElement * NumberOfRecHitMuon_
static std::string name(const RPCDetId &detId, const bool useRoll)
Definition: RPCNameHelper.cc:6
virtual TrackingRecHit * clone() const =0
std::map< std::string, MonitorElement * > regionMuonCollection
Log< level::Info, false > LogInfo
virtual int segment()
Definition: RPCGeomServ.cc:361
int detId2RollNr(const RPCDetId &_id)
Definition: utils.h:31
std::map< std::string, MonitorElement * > sectorRingNoiseCollection
static constexpr int RPC
Definition: MuonSubdetId.h:13
void bookWheelDiskME(DQMStore::IBooker &, const std::string &, std::map< std::string, MonitorElement *> &)
Booking of MonitoringElemnt at Wheel/Disk level.
static std::string chamberName(const RPCDetId &detId)
edm::EDGetTokenT< RPCRecHitCollection > rpcRecHitLabel_
int station() const
Definition: RPCDetId.h:78
edm::EDGetTokenT< DcsStatusCollection > scalersRawToDigiLabel_
std::map< std::string, std::map< std::string, MonitorElement * > > meNoiseCollection
bool isValid() const
Definition: HandleBase.h:70
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
void bookRegionME(DQMStore::IBooker &, const std::string &, std::map< std::string, MonitorElement *> &)
Booking of MonitoringElemnt at region (Barrel/Endcap) level.
void performSourceOperation(std::map< RPCDetId, std::vector< RPCRecHit > > &, std::string)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::map< std::string, MonitorElement * > wheelDiskMuonCollection
std::map< std::string, MonitorElement * > regionNoiseCollection
MonitorElement * noiseRPCEvents_
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
const std::vector< const RPCRoll * > & rolls() const
Return the Rolls.
Definition: RPCChamber.cc:40
MonitorElement * NumberOfMuon_
bool isGlobalMuon() const override
Definition: Muon.h:303
std::string subsystemFolder_
void bookRollME(DQMStore::IBooker &, const RPCDetId &, const RPCGeometry *rpcGeo, const std::string &, std::map< std::string, MonitorElement *> &)
Booking of MonitoringElement for one RPCDetId (= roll)
Definition: event.py:1
Definition: Run.h:45
edm::EDGetTokenT< reco::CandidateView > muonLabel_
double eta() const final
momentum pseudorapidity