CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_) {
162  NumberOfMuon_->Fill(numMuons);
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  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 
251  const std::string nameRoll = RPCNameHelper::name(detId, useRollInfo_);
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 layer = 0;
259  int totalRolls = 3;
260  int roll = detId.roll();
261  if (region == 0) {
262  wheelOrDiskType = "Wheel";
263  wheelOrDiskNumber = (int)detId.ring();
264  int station = detId.station();
265 
266  if (station == 1) {
267  if (detId.layer() == 1) {
268  layer = 1; //RB1in
269  totalRolls = 2;
270  } else {
271  layer = 2; //RB1out
272  totalRolls = 2;
273  }
274  if (roll == 3)
275  roll = 2; // roll=3 is Forward
276  } else if (station == 2) {
277  if (detId.layer() == 1) {
278  layer = 3; //RB2in
279  if (abs(wheelOrDiskNumber) == 2 && roll == 3) {
280  roll = 2; //W -2, +2 RB2in has only 2 rolls
281  totalRolls = 2;
282  }
283  } else {
284  layer = 4; //RB2out
285  if (abs(wheelOrDiskNumber) != 2 && roll == 3) {
286  roll = 2; //W -1, 0, +1 RB2out has only 2 rolls
287  totalRolls = 2;
288  }
289  }
290  } else if (station == 3) {
291  layer = 5; //RB3
292  totalRolls = 2;
293  if (roll == 3)
294  roll = 2;
295  } else {
296  layer = 6; //RB4
297  totalRolls = 2;
298  if (roll == 3)
299  roll = 2;
300  }
301 
302  } else {
303  wheelOrDiskType = "Disk";
304  wheelOrDiskNumber = region * (int)detId.station();
305  ring = detId.ring();
306  }
307 
308  std::vector<RPCRecHit> recHits = (*detIdIter).second;
309  const int numberOfRecHits = recHits.size();
310  totalNumberOfRecHits[region + 1] += numberOfRecHits;
311 
312  std::set<int> bxSet;
313  int numDigi = 0;
314 
315  std::map<std::string, MonitorElement*> meMap = meRollCollection[nameRoll];
316 
317  //Loop on recHits
318  std::string tmpName;
319  for (std::vector<RPCRecHit>::const_iterator recHitIter = recHits.begin(); recHitIter != recHits.end();
320  recHitIter++) {
321  RPCRecHit recHit = (*recHitIter);
322 
323  int bx = recHit.BunchX();
324  bxSet.insert(bx);
325  int clusterSize = (int)recHit.clusterSize();
326  numDigi += clusterSize;
327  int firstStrip = recHit.firstClusterStrip();
328  int lastStrip = clusterSize + firstStrip - 1;
329 
330  // ###################### Roll Level #################################
331 
332  tmpName = "Occupancy_" + nameRoll;
333  if (meMap[tmpName]) {
334  for (int s = firstStrip; s <= lastStrip; s++) {
335  if (useRollInfo_) {
336  meMap[tmpName]->Fill(s);
337  } else {
338  const int nstrips = meMap[tmpName]->getNbinsX() / totalRolls;
339  meMap[tmpName]->Fill(s + nstrips * (roll - 1));
340  }
341  }
342  }
343 
344  tmpName = "BXDistribution_" + nameRoll;
345  if (meMap[tmpName])
346  meMap[tmpName]->Fill(bx);
347 
348  tmpName = "ClusterSize_" + nameRoll;
349  if (meMap[tmpName])
350  meMap[tmpName]->Fill(clusterSize);
351 
352  // ###################### Sector- Ring Level #################################
353 
354  tmpName = fmt::format("Occupancy_{}_{}_Sector_{}", wheelOrDiskType, wheelOrDiskNumber, sector);
355  if (meSectorRing[tmpName]) {
356  for (int s = firstStrip; s <= lastStrip; s++) { //Loop on digis
357  meSectorRing[tmpName]->Fill(s, nr);
358  }
359  }
360 
361  tmpName = fmt::format("Occupancy_{}_{}_Ring_{}", wheelOrDiskType, wheelOrDiskNumber, ring);
362  if (geoServ.segment() > 0 && geoServ.segment() <= 18) {
363  tmpName += "_CH01-CH18";
364  } else if (geoServ.segment() >= 19) {
365  tmpName += "_CH19-CH36";
366  }
367 
368  if (meSectorRing[tmpName]) {
369  for (int s = firstStrip; s <= lastStrip; s++) { //Loop on digis
370  meSectorRing[tmpName]->Fill(s + 32 * (detId.roll() - 1), geoServ.segment());
371  }
372  }
373 
374  // ###################### Wheel/Disk Level #########################
375  if (region == 0) {
376  tmpName = fmt::format("1DOccupancy_Wheel_{}", wheelOrDiskNumber);
377  if (meWheelDisk[tmpName])
378  meWheelDisk[tmpName]->Fill(sector, clusterSize);
379 
380  tmpName = fmt::format("Occupancy_Roll_vs_Sector_{}_{}", wheelOrDiskType, wheelOrDiskNumber);
381  if (meWheelDisk[tmpName])
382  meWheelDisk[tmpName]->Fill(sector, nr, clusterSize);
383 
384  } else {
385  tmpName = fmt::format("1DOccupancy_Ring_{}", ring);
386  if ((meWheelDisk[tmpName])) {
387  if (wheelOrDiskNumber > 0) {
388  meWheelDisk[tmpName]->Fill(wheelOrDiskNumber + numberOfDisks_, clusterSize);
389  } else {
390  meWheelDisk[tmpName]->Fill(wheelOrDiskNumber + numberOfDisks_ + 1, clusterSize);
391  }
392  }
393 
394  tmpName = fmt::format("Occupancy_Ring_vs_Segment_{}_{}", wheelOrDiskType, wheelOrDiskNumber);
395  if (meWheelDisk[tmpName])
396  meWheelDisk[tmpName]->Fill(geoServ.segment(), (ring - 1) * 3 - detId.roll() + 1, clusterSize);
397  }
398 
399  tmpName = fmt::format("BxDistribution_{}_{}", wheelOrDiskType, wheelOrDiskNumber);
400  if (meWheelDisk[tmpName])
401  meWheelDisk[tmpName]->Fill(bx);
402 
403  tmpName = fmt::format("ClusterSize_{}_{}_Layer{}", wheelOrDiskType, wheelOrDiskNumber, layer);
404  if (meWheelDisk[tmpName])
405  meWheelDisk[tmpName]->Fill(clusterSize);
406 
407  tmpName = fmt::format("ClusterSize_{}_{}_Ring{}", wheelOrDiskType, wheelOrDiskNumber, ring);
408  if (meWheelDisk[tmpName])
409  meWheelDisk[tmpName]->Fill(clusterSize);
410 
411  // ###################### Global ##################################
412  tmpName = "ClusterSize_" + RPCMonitorDigi::regionNames_[region + 1];
413  if (meRegion[tmpName])
414  meRegion[tmpName]->Fill(clusterSize);
415 
416  tmpName = "";
417  if (region == 0) {
418  tmpName = fmt::format("ClusterSize_Layer{}", layer);
419  } else {
420  tmpName = fmt::format("ClusterSize_Ring{}", ring);
421  }
422  if (meRegion[tmpName])
423  meRegion[tmpName]->Fill(clusterSize);
424 
425  } //end loop on recHits
426 
427  tmpName = "BXWithData_" + nameRoll;
428  if (meMap[tmpName])
429  meMap[tmpName]->Fill(bxSet.size());
430 
431  tmpName = "NumberOfClusters_" + nameRoll;
432  if (meMap[tmpName])
433  meMap[tmpName]->Fill(numberOfRecHits);
434 
435  tmpName = "Multiplicity_" + RPCMonitorDigi::regionNames_[region + 1];
436  if (meRegion[tmpName])
437  meRegion[tmpName]->Fill(numDigi);
438 
439  if (region == 0) {
440  if (meRegion["Occupancy_for_Barrel"])
441  meRegion["Occupancy_for_Barrel"]->Fill(sector, wheelOrDiskNumber, numDigi);
442  } else {
443  int xbin = wheelOrDiskNumber + numberOfDisks_;
444  if (region == -1) {
445  xbin = wheelOrDiskNumber + numberOfDisks_ + 1;
446  }
447  if (meRegion["Occupancy_for_Endcap"]) {
448  meRegion["Occupancy_for_Endcap"]->Fill(xbin, ring, numDigi);
449  }
450  }
451 
452  tmpName = "Multiplicity_" + nameRoll;
453  if (meMap[tmpName])
454  meMap[tmpName]->Fill(numDigi);
455 
456  } //end loop on rolls
457 
458  for (int i = 0; i < 3; i++) {
459  const std::string tmpName = "NumberOfClusters_" + RPCMonitorDigi::regionNames_[i];
460  if (meRegion[tmpName])
461  meRegion[tmpName]->Fill(totalNumberOfRecHits[i]);
462  }
463 }
int firstClusterStrip() const
Definition: RPCRecHit.h:75
T getUntrackedParameter(std::string const &, T const &) const
std::map< std::string, std::map< std::string, MonitorElement * > > meMuonCollection
std::string globalFolder_
double pt() const final
transverse momentum
std::string muonFolder_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
std::map< std::string, MonitorElement * > wheelDiskNoiseCollection
std::map< std::string, MonitorElement * > sectorRingMuonCollection
MonitorElement * muonRPCEvents_
void bookSectorRingME(DQMStore::IBooker &, const std::string &, std::map< std::string, MonitorElement * > &)
Booking of MonitoringElement at Sector/Ring level.
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)
constexpr std::array< uint8_t, layerIndexSize > layer
void Fill(long long x)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
tuple numMuons
Definition: patZpeak.py:41
int clusterSize() const
Definition: RPCRecHit.h:77
RPCDetId rpcId() const
Return the rpcId.
Definition: RPCRecHit.h:71
int roll() const
Definition: RPCDetId.h:92
int ring() const
Definition: RPCDetId.h:59
void bookRollME(DQMStore::IBooker &, const RPCDetId &, const RPCGeometry *rpcGeo, const std::string &, std::map< std::string, MonitorElement * > &)
Booking of MonitoringElement for one RPCDetId (= roll)
const std::vector< const RPCRoll * > & rolls() const
Return the Rolls.
Definition: RPCChamber.cc:40
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
static const std::array< std::string, 3 > regionNames_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
bool isValid() const
Definition: HandleBase.h:70
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeomToken_
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:48
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
int layer() const
Definition: RPCDetId.h:85
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static std::string chamberName(const RPCDetId &detId)
edm::EDGetTokenT< RPCRecHitCollection > rpcRecHitLabel_
edm::EDGetTokenT< DcsStatusCollection > scalersRawToDigiLabel_
std::map< std::string, std::map< std::string, MonitorElement * > > meNoiseCollection
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:81
void performSourceOperation(std::map< RPCDetId, std::vector< RPCRecHit > > &, std::string)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
static std::atomic< unsigned int > counter
std::map< std::string, MonitorElement * > wheelDiskMuonCollection
void bookWheelDiskME(DQMStore::IBooker &, const std::string &, std::map< std::string, MonitorElement * > &)
Booking of MonitoringElemnt at Wheel/Disk level.
std::map< std::string, MonitorElement * > regionNoiseCollection
int BunchX() const
Definition: RPCRecHit.h:73
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
void bookRegionME(DQMStore::IBooker &, const std::string &, std::map< std::string, MonitorElement * > &)
Booking of MonitoringElemnt at region (Barrel/Endcap) level.
MonitorElement * NumberOfMuon_
bool isGlobalMuon() const override
Definition: Muon.h:299
std::string subsystemFolder_
Definition: Run.h:45
edm::EDGetTokenT< reco::CandidateView > muonLabel_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
int station() const
Definition: RPCDetId.h:78
double eta() const final
momentum pseudorapidity