CMS 3D CMS Logo

GEMDQMBase.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 using namespace edm;
6 
8  std::string strRunType = cfg.getUntrackedParameter<std::string>("runType");
9 
11 
12  if (strRunType == "online") {
14  } else if (strRunType == "offline") {
16  } else if (strRunType == "relval") {
18  } else if (strRunType == "allplots") {
20  } else {
21  edm::LogError(log_category_) << "+++ Error : GEM geometry is unavailable on event loop. +++\n";
22  }
23 
24  log_category_ = cfg.getUntrackedParameter<std::string>("logCategory");
25 }
26 
28  GEMGeometry_ = nullptr;
29  if (auto handle = iSetup.getHandle(geomToken_)) {
30  GEMGeometry_ = handle.product();
31  } else {
32  edm::LogError(log_category_) << "+++ Error : GEM geometry is unavailable on event loop. +++\n";
33  return -1;
34  }
35 
36  return 0;
37 }
38 
39 // Borrowed from DQM/GEM/src/GEMOfflineDQMBase.cc
41  const auto&& superchambers = station->superChambers();
42  if (not checkRefs(superchambers)) {
43  edm::LogError(log_category_) << "failed to get a valid vector of GEMSuperChamber ptrs" << std::endl;
44  return 0;
45  }
46 
47  const auto& chambers = superchambers.front()->chambers();
48  if (not checkRefs(chambers)) {
49  edm::LogError(log_category_) << "failed to get a valid vector of GEMChamber ptrs" << std::endl;
50  return 0;
51  }
52 
53  return chambers.front()->nEtaPartitions();
54 }
55 
57  if (GEMGeometry_ == nullptr)
58  return -1;
59  listChamberId_.clear();
60  mapEtaPartition_.clear();
61  for (const GEMRegion* region : GEMGeometry_->regions()) {
62  for (const GEMStation* station : region->stations()) {
63  for (auto sch : station->superChambers()) {
64  for (auto pchamber : sch->chambers()) {
65  GEMDetId gid = pchamber->id();
66  listChamberId_.push_back(pchamber->id());
67  for (auto iEta : pchamber->etaPartitions()) {
68  mapEtaPartition_[gid].push_back(iEta);
69  }
70  }
71  }
72  }
73  }
74 
75  // Borrwed from DQM/GEM/src/GEMOfflineMonitor.cc
76  nMaxNumCh_ = 0;
77  for (const GEMRegion* region : GEMGeometry_->regions()) {
78  const int region_number = region->region();
79 
80  for (const GEMStation* station : region->stations()) {
81  const auto&& superchambers = station->superChambers();
82 
83  const int station_number = station->station();
84  const int num_superchambers = (station_number == 1 ? 36 : 18);
85  const int max_vfat = getMaxVFAT(station->station()); // the number of VFATs per GEMEtaPartition
86  const int num_etas = getNumEtaPartitions(station); // the number of eta partitions per GEMChamber
87  const int num_vfat = num_etas * max_vfat; // the number of VFATs per GEMChamber
88  const int num_digi = GEMeMap::maxChan_; // the number of digis (channels) per VFAT
89 
90  nMaxNumCh_ = std::max(nMaxNumCh_, num_superchambers);
91 
92  Int_t nMinIdxChamber = 1048576;
93  Int_t nMaxIdxChamber = -1048576;
94  for (auto sch : superchambers) {
95  auto nIdxChamber = sch->chambers().front()->id().chamber();
96  if (nMinIdxChamber > nIdxChamber)
97  nMinIdxChamber = nIdxChamber;
98  if (nMaxIdxChamber < nIdxChamber)
99  nMaxIdxChamber = nIdxChamber;
100  }
101 
102  const auto& chambers = superchambers.front()->chambers();
103 
104  for (auto pchamber : chambers) {
105  int layer_number = pchamber->id().layer();
106  ME3IdsKey key3(region_number, station_number, layer_number);
107  mapStationInfo_[key3] =
108  MEStationInfo(region_number, station_number, layer_number, num_superchambers, num_etas, num_vfat, num_digi);
109  mapStationInfo_[key3].nMinIdxChamber_ = nMinIdxChamber;
110  mapStationInfo_[key3].nMaxIdxChamber_ = nMaxIdxChamber;
113  }
114  }
115  }
116 
117  return 0;
118 }
119 
120 int GEMDQMBase::SortingLayers(std::vector<ME3IdsKey>& listLayers) {
121  std::sort(listLayers.begin(), listLayers.end(), [](ME3IdsKey key1, ME3IdsKey key2) {
122  Int_t re1 = std::get<0>(key1), st1 = std::get<1>(key1), la1 = std::get<2>(key1);
123  Int_t re2 = std::get<0>(key2), st2 = std::get<1>(key2), la2 = std::get<2>(key2);
124  if (re1 < 0 && re2 > 0)
125  return false;
126  if (re1 > 0 && re2 < 0)
127  return true;
128  Bool_t bRes = (re1 < 0); // == re2 < 0
129  Int_t sum1 = 256 * std::abs(re1) + 16 * st1 + 1 * la1;
130  Int_t sum2 = 256 * std::abs(re2) + 16 * st2 + 1 * la2;
131  if (sum1 <= sum2)
132  return bRes;
133  return !bRes;
134  });
135 
136  return 0;
137 }
138 
140  std::vector<ME3IdsKey> listLayers;
141  for (auto const& [key, stationInfo] : mapStationInfo_)
142  listLayers.push_back(key);
143  SortingLayers(listLayers);
144  for (Int_t i = 0; i < (Int_t)listLayers.size(); i++)
145  mapStationToIdx_[listLayers[i]] = i + 1;
146 
147  auto h2Res =
148  ibooker.book2D(strName, "", nMaxNumCh_, 0.5, nMaxNumCh_ + 0.5, listLayers.size(), 0.5, listLayers.size() + 0.5);
149  h2Res->setXTitle("Chamber");
150  h2Res->setYTitle("Layer");
151 
152  if (h2Res == nullptr)
153  return nullptr;
154 
155  for (Int_t i = 1; i <= nMaxNumCh_; i++)
156  h2Res->setBinLabel(i, Form("%i", i), 1);
157  for (Int_t i = 1; i <= (Int_t)listLayers.size(); i++) {
158  auto key = listLayers[i - 1];
159  auto strInfo = GEMUtils::getSuffixName(key); // NOTE: It starts with '_'
160  auto region = keyToRegion(key);
161  auto label =
162  Form("GE%+i1-%cL%i;%s", region * keyToStation(key), (region > 0 ? 'P' : 'M'), keyToLayer(key), strInfo.Data());
163  h2Res->setBinLabel(i, label, 2);
164  Int_t nNumCh = mapStationInfo_[key].nNumChambers_;
165  h2Res->setBinContent(0, i, nNumCh);
166  }
167 
168  return h2Res;
169 }
170 
172  MEMap2Check_.clear();
173  MEMap2WithEtaCheck_.clear();
174  MEMap2AbsReWithEtaCheck_.clear();
175  MEMap3Check_.clear();
176  MEMap3WithChCheck_.clear();
177  MEMap4Check_.clear();
178  for (auto gid : listChamberId_) {
179  ME2IdsKey key2{gid.region(), gid.station()};
180  ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
181  ME4IdsKey key3WithChamber{gid.region(), gid.station(), gid.layer(), gid.chamber()};
182  if (!MEMap2Check_[key2]) {
183  auto strSuffixName = GEMUtils::getSuffixName(key2);
184  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2);
185  BookingHelper bh2(ibooker, strSuffixName, strSuffixTitle);
186  ProcessWithMEMap2(bh2, key2);
187  MEMap2Check_[key2] = true;
188  }
189  if (!MEMap3Check_[key3]) {
190  auto strSuffixName = GEMUtils::getSuffixName(key3);
191  auto strSuffixTitle = GEMUtils::getSuffixTitle(key3);
192  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
193  ProcessWithMEMap3(bh3, key3);
194  MEMap3Check_[key3] = true;
195  }
196  if (!MEMap3WithChCheck_[key3WithChamber]) {
197  Int_t nCh = gid.chamber();
198  Int_t nLa = gid.layer();
199  char cLS = (nCh % 2 == 0 ? 'L' : 'S'); // FIXME: Is it general enough?
200  auto strSuffixName = GEMUtils::getSuffixName(key2) + Form("-%02iL%i-%c", nCh, nLa, cLS);
201  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2) + Form("-%02iL%i-%c", nCh, nLa, cLS);
202  BookingHelper bh3Ch(ibooker, strSuffixName, strSuffixTitle);
203  ProcessWithMEMap3WithChamber(bh3Ch, key3WithChamber);
204  MEMap3WithChCheck_[key3WithChamber] = true;
205  }
206  for (auto iEta : mapEtaPartition_[gid]) {
207  GEMDetId eId = iEta->id();
208  ME4IdsKey key4{gid.region(), gid.station(), gid.layer(), eId.ieta()};
209  ME3IdsKey key2WithEta{gid.region(), gid.station(), eId.ieta()};
210  ME3IdsKey key2AbsReWithEta{std::abs(gid.region()), gid.station(), eId.ieta()};
211  if (!MEMap4Check_[key4]) {
212  auto strSuffixName = GEMUtils::getSuffixName(key3) + Form("-E%02i", eId.ieta());
213  auto strSuffixTitle = GEMUtils::getSuffixTitle(key3) + Form("-E%02i", eId.ieta());
214  BookingHelper bh4(ibooker, strSuffixName, strSuffixTitle);
215  ProcessWithMEMap4(bh4, key4);
216  MEMap4Check_[key4] = true;
217  }
218  if (!MEMap2WithEtaCheck_[key2WithEta]) {
219  auto strSuffixName = GEMUtils::getSuffixName(key2) + Form("-E%02i", eId.ieta());
220  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2) + Form("-E%02i", eId.ieta());
221  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
222  ProcessWithMEMap2WithEta(bh3, key2WithEta);
223  MEMap2WithEtaCheck_[key2WithEta] = true;
224  }
225  if (!MEMap2AbsReWithEtaCheck_[key2AbsReWithEta]) {
226  auto strSuffixName = Form("_GE%d1-E%02i", gid.station(), eId.ieta());
227  auto strSuffixTitle = Form(" GE%d1-E%02i", gid.station(), eId.ieta());
228  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
229  ProcessWithMEMap2AbsReWithEta(bh3, key2AbsReWithEta);
230  MEMap2AbsReWithEtaCheck_[key2AbsReWithEta] = true;
231  }
232  }
233  }
234  return 0;
235 }
236 
238  auto listSuperChambers = station->superChambers();
239 
240  Bool_t bDoneEven = false, bDoneOdd = false;
241 
242  // Obtaining radius intervals of even/odd chambers
243  for (auto superchamber : listSuperChambers) {
244  Int_t chamberNo = superchamber->id().chamber();
245  if (chamberNo % 2 == 0 && bDoneEven)
246  continue;
247  if (chamberNo % 2 != 0 && bDoneOdd)
248  continue;
249 
250  auto& etaPartitions = superchamber->chambers().front()->etaPartitions();
251 
252  // A little of additional procedures to list up the radius intervals
253  // It would be independent to local direction of chambers and the order of eta partitions
254  // 1. Obtain the radius of the middle top/bottom points of the trapezoid
255  // 2. Sort these two values and determine which one is the lower/upper one
256  // 3. Keep them all and then sort them
257  // 4. The intermediate radii are set as the mean of the corresponding values of upper/lowers.
258  std::vector<Float_t> listRadiusLower, listRadiusUpper;
259  for (auto iEta : etaPartitions) {
260  const GEMStripTopology& stripTopology = dynamic_cast<const GEMStripTopology&>(iEta->specificTopology());
261  Float_t fHeight = stripTopology.stripLength();
262  LocalPoint lp1(0.0, -0.5 * fHeight), lp2(0.0, 0.5 * fHeight);
263  auto& surface = iEta->surface();
264  GlobalPoint gp1 = surface.toGlobal(lp1), gp2 = surface.toGlobal(lp2);
265  Float_t fR1 = gp1.perp(), fR2 = gp2.perp();
266  Float_t fRL = std::min(fR1, fR2), fRH = std::max(fR1, fR2);
267  listRadiusLower.push_back(fRL);
268  listRadiusUpper.push_back(fRH);
269  // For a future usage
270  //std::cout << "GEO_RADIUS: " << iEta->id().chamber() << " " << iEta->id().ieta() << " "
271  // << fRL << " " << fRH << std::endl;
272  }
273 
274  std::sort(listRadiusLower.begin(), listRadiusLower.end());
275  std::sort(listRadiusUpper.begin(), listRadiusUpper.end());
276 
277  std::vector<Float_t>& listR =
278  (chamberNo % 2 == 0 ? stationInfo.listRadiusEvenChamber_ : stationInfo.listRadiusOddChamber_);
279  listR.clear();
280  listR.push_back(listRadiusLower.front());
281  for (int i = 1; i < (int)listRadiusLower.size(); i++) {
282  listR.push_back(0.5 * (listRadiusLower[i] + listRadiusUpper[i - 1]));
283  }
284  listR.push_back(listRadiusUpper.back());
285 
286  if (chamberNo % 2 == 0)
287  bDoneEven = true;
288  if (chamberNo % 2 != 0)
289  bDoneOdd = true;
290 
291  if (bDoneEven && bDoneOdd)
292  break;
293  }
294 
295  return 0;
296 }
297 
299  auto listSuperChambers = station->superChambers();
300  Int_t nNumStripEta = stationInfo.nNumDigi_ * (stationInfo.nMaxVFAT_ / stationInfo.nNumEtaPartitions_);
301 
302  std::vector<std::pair<Int_t, std::pair<std::pair<Float_t, Float_t>, Bool_t>>> listDivPhi;
303 
304  // Obtaining phi intervals of chambers
305  for (auto superchamber : listSuperChambers) {
306  auto iEta = superchamber->chambers().front()->etaPartitions().front();
307 
308  // What is the index of the first strip? Rather than to ask to someone, let's calculate it!
309  Float_t fWidthStrip = std::abs(iEta->centreOfStrip((Int_t)1).x() - iEta->centreOfStrip((Int_t)0).x());
310  LocalPoint lpRef(-fWidthStrip / 3.0, 0.0);
311  Int_t nStripMid = (Int_t)iEta->strip(lpRef);
312  Int_t nFirstStrip = 1 - ((nNumStripEta / 2) - nStripMid);
313  Int_t nLastStrip = nFirstStrip + nNumStripEta - 1;
314 
315  auto& surface = iEta->surface();
316  LocalPoint lpF = iEta->centreOfStrip((Float_t)(nFirstStrip - 0.5)); // To avoid the round error(?)
317  LocalPoint lpL = iEta->centreOfStrip((Float_t)(nLastStrip + 0.5)); // To avoid the round error(?)
318  GlobalPoint gpF = surface.toGlobal(lpF);
319  GlobalPoint gpL = surface.toGlobal(lpL);
320 
321  Float_t fPhiF = gpF.phi();
322  Float_t fPhiL = gpL.phi();
323  if (fPhiF * fPhiL < 0 && std::abs(fPhiF) > 0.5 * 3.14159265359) {
324  if (fPhiF < 0)
325  fPhiF += 2 * 3.14159265359;
326  if (fPhiL < 0)
327  fPhiL += 2 * 3.14159265359;
328  }
329  Bool_t bFlipped = fPhiF > fPhiL;
330  Float_t fPhiMin = std::min(fPhiF, fPhiL);
331  Float_t fPhiMax = std::max(fPhiF, fPhiL);
332 
333  listDivPhi.emplace_back();
334  listDivPhi.back().first = iEta->id().chamber();
335  listDivPhi.back().second.first.first = fPhiMin;
336  listDivPhi.back().second.first.second = fPhiMax;
337  listDivPhi.back().second.second = bFlipped;
338  }
339 
340  stationInfo.fMinPhi_ = 0.0;
341  for (auto p : listDivPhi) {
342  if (p.first == 1) {
343  stationInfo.fMinPhi_ = p.second.first.first;
344  break;
345  }
346  }
347 
348  // For a future usage
349  //for ( auto p : listDivPhi ) {
350  // std::cout << "GEO_PHI: " << p.first << " "
351  // << p.second.first.first << " " << p.second.first.second << " " << p.second.second << std::endl;
352  //}
353 
354  return 0;
355 }
float stripLength() const override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool checkRefs(const std::vector< T *> &)
Definition: GEMDQMBase.h:595
dqm::impl::MonitorElement * CreateSummaryHist(DQMStore::IBooker &ibooker, TString strName)
Definition: GEMDQMBase.cc:139
T perp() const
Definition: PV3DBase.h:69
Int_t nRunType_
Definition: GEMDQMBase.h:518
virtual int ProcessWithMEMap4(BookingHelper &bh, ME4IdsKey key)
Definition: GEMDQMBase.h:531
TString getSuffixName(Int_t region_id)
std::vector< GEMDetId > listChamberId_
Definition: GEMDQMBase.h:578
virtual int ProcessWithMEMap2AbsReWithEta(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:529
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
int initGeometry(edm::EventSetup const &iSetup)
Definition: GEMDQMBase.cc:27
std::tuple< Int_t, Int_t, Int_t, Int_t > ME4IdsKey
int readGeometryRadiusInfoChamber(const GEMStation *station, MEStationInfo &stationInfo)
Definition: GEMDQMBase.cc:237
std::map< ME3IdsKey, MEStationInfo > mapStationInfo_
Definition: GEMDQMBase.h:590
int keyToRegion(ME2IdsKey key)
Definition: GEMDQMBase.h:534
int readGeometryPhiInfoChamber(const GEMStation *station, MEStationInfo &stationInfo)
Definition: GEMDQMBase.cc:298
int loadChambers()
Definition: GEMDQMBase.cc:56
std::map< ME3IdsKey, int > mapStationToIdx_
Definition: GEMDQMBase.h:589
static const int maxChan_
Definition: GEMeMap.h:72
int keyToLayer(ME3IdsKey key)
Definition: GEMDQMBase.h:540
Log< level::Error, false > LogError
TString getSuffixTitle(Int_t region_id)
std::vector< Float_t > listRadiusOddChamber_
Definition: GEMDQMBase.h:500
std::string log_category_
Definition: GEMDQMBase.h:520
char const * label
std::map< ME3IdsKey, bool > MEMap2AbsReWithEtaCheck_
Definition: GEMDQMBase.h:583
std::map< ME2IdsKey, bool > MEMap2Check_
Definition: GEMDQMBase.h:581
virtual int ProcessWithMEMap3(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:530
virtual void setXTitle(std::string const &title)
int GenerateMEPerChamber(DQMStore::IBooker &ibooker)
Definition: GEMDQMBase.cc:171
std::vector< Float_t > listRadiusEvenChamber_
Definition: GEMDQMBase.h:499
std::map< ME3IdsKey, bool > MEMap3Check_
Definition: GEMDQMBase.h:584
int getNumEtaPartitions(const GEMStation *)
Definition: GEMDQMBase.cc:40
virtual int ProcessWithMEMap3WithChamber(BookingHelper &bh, ME4IdsKey key)
Definition: GEMDQMBase.h:532
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
Definition: GEMDQMBase.h:576
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
int getMaxVFAT(const int)
Definition: GEMDQMBase.h:604
int keyToStation(ME2IdsKey key)
Definition: GEMDQMBase.h:537
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
std::map< ME4IdsKey, bool > MEMap4Check_
Definition: GEMDQMBase.h:586
constexpr int ieta() const
Definition: GEMDetId.h:199
const GEMGeometry * GEMGeometry_
Definition: GEMDQMBase.h:575
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
virtual int ProcessWithMEMap2WithEta(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:528
int SortingLayers(std::vector< ME3IdsKey > &listLayers)
Definition: GEMDQMBase.cc:120
GEMDQMBase(const edm::ParameterSet &cfg)
Definition: GEMDQMBase.cc:7
std::map< ME3IdsKey, bool > MEMap2WithEtaCheck_
Definition: GEMDQMBase.h:582
std::map< GEMDetId, std::vector< const GEMEtaPartition * > > mapEtaPartition_
Definition: GEMDQMBase.h:579
HLT enums.
const std::vector< const GEMRegion * > & regions() const
Return a vector of all GEM regions.
Definition: GEMGeometry.cc:30
int nMaxNumCh_
Definition: GEMDQMBase.h:588
std::tuple< Int_t, Int_t > ME2IdsKey
std::tuple< Int_t, Int_t, Int_t > ME3IdsKey
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
std::map< ME4IdsKey, bool > MEMap3WithChCheck_
Definition: GEMDQMBase.h:585
virtual int ProcessWithMEMap2(BookingHelper &bh, ME2IdsKey key)
Definition: GEMDQMBase.h:527