CMS 3D CMS Logo

LedClient.cc
Go to the documentation of this file.
2 
4 
6 
9 
11 
12 #include <cmath>
13 #include <fstream>
14 namespace ecaldqm {
16  : DQWorkerClient(),
17  wlToME_(),
18  minChannelEntries_(0),
19  expectedAmplitude_(0),
20  toleranceAmplitude_(0.),
21  toleranceAmpRMSRatio_(0.),
22  expectedTiming_(0),
23  toleranceTiming_(0.),
24  toleranceTimRMS_(0.),
25  expectedPNAmplitude_(0),
26  tolerancePNAmp_(0.),
27  tolerancePNRMSRatio_(0.),
28  forwardFactor_(0.) {}
29 
31  minChannelEntries_ = _params.getUntrackedParameter<int>("minChannelEntries");
32  toleranceAmplitude_ = _params.getUntrackedParameter<double>("toleranceAmplitude");
33  toleranceAmpRMSRatio_ = _params.getUntrackedParameter<double>("toleranceAmpRMSRatio");
34  toleranceTiming_ = _params.getUntrackedParameter<double>("toleranceTiming");
35  toleranceTimRMS_ = _params.getUntrackedParameter<double>("toleranceTimRMS");
36  tolerancePNAmp_ = _params.getUntrackedParameter<double>("tolerancePNAmp");
37  tolerancePNRMSRatio_ = _params.getUntrackedParameter<double>("tolerancePNRMSRatio");
38  forwardFactor_ = _params.getUntrackedParameter<double>("forwardFactor");
39 
40  std::vector<int> ledWavelengths(_params.getUntrackedParameter<std::vector<int> >("ledWavelengths"));
41 
42  // wavelengths are not necessarily ordered
43  // create a map wl -> MESet index
44  // using Amplitude here but any multi-wavelength plot is fine
45 
47 
48  MESetMulti const& amplitude(static_cast<MESetMulti const&>(sources_.at("Amplitude")));
49  unsigned nWL(ledWavelengths.size());
50  for (unsigned iWL(0); iWL != nWL; ++iWL) {
51  int wl(ledWavelengths[iWL]);
52  if (wl != 1 && wl != 2)
53  throw cms::Exception("InvalidConfiguration") << "Led Wavelength";
54  repl["wl"] = std::to_string(wl);
55  wlToME_[wl] = amplitude.getIndex(repl);
56  }
57 
58  expectedAmplitude_.resize(nWL);
59  expectedTiming_.resize(nWL);
60  expectedPNAmplitude_.resize(nWL);
61 
62  std::vector<double> inExpectedAmplitude(_params.getUntrackedParameter<std::vector<double> >("expectedAmplitude"));
63  std::vector<double> inExpectedTiming(_params.getUntrackedParameter<std::vector<double> >("expectedTiming"));
64  std::vector<double> inExpectedPNAmplitude(
65  _params.getUntrackedParameter<std::vector<double> >("expectedPNAmplitude"));
66 
67  for (std::map<int, unsigned>::iterator wlItr(wlToME_.begin()); wlItr != wlToME_.end(); ++wlItr) {
68  unsigned iME(wlItr->second);
69  int iWL(wlItr->first - 1);
70  expectedAmplitude_[iME] = inExpectedAmplitude[iWL];
71  expectedTiming_[iME] = inExpectedTiming[iWL];
72  expectedPNAmplitude_[iME] = inExpectedPNAmplitude[iWL];
73  }
74 
75  //Get the list of known problematic Supercrystal ids and store them in the vector SClist_
76  std::string SClistpath = edm::FileInPath("DQM/EcalMonitorClient/data/LedTowers/SClist.dat").fullPath();
77  std::ifstream infile;
78  infile.open((SClistpath).c_str());
79  uint32_t detid;
80  int ix, iy, iz;
81  while (!infile.eof()) {
82  infile >> ix >> iy >> iz >> detid;
83  SClist_.push_back(detid);
84  }
85 
86  qualitySummaries_.insert("Quality");
87  qualitySummaries_.insert("QualitySummary");
88  qualitySummaries_.insert("PNQualitySummary");
89  }
90 
94 
95  MESetMulti& meQuality(static_cast<MESetMulti&>(MEs_.at("Quality")));
96  MESetMulti& meQualitySummary(static_cast<MESetMulti&>(MEs_.at("QualitySummary")));
97  MESetMulti& meAmplitudeMean(static_cast<MESetMulti&>(MEs_.at("AmplitudeMean")));
98  MESetMulti& meAmplitudeRMS(static_cast<MESetMulti&>(MEs_.at("AmplitudeRMS")));
99  MESetMulti& meTimingMean(static_cast<MESetMulti&>(MEs_.at("TimingMean")));
100  MESetMulti& meTimingRMSMap(static_cast<MESetMulti&>(MEs_.at("TimingRMSMap")));
101  MESetMulti& mePNQualitySummary(static_cast<MESetMulti&>(MEs_.at("PNQualitySummary")));
102 
103  MESetMulti const& sAmplitude(static_cast<MESetMulti const&>(sources_.at("Amplitude")));
104  MESetMulti const& sTiming(static_cast<MESetMulti const&>(sources_.at("Timing")));
105  MESetMulti const& sPNAmplitude(static_cast<MESetMulti const&>(sources_.at("PNAmplitude")));
106  MESet const& sCalibStatus(static_cast<MESet const&>(sources_.at("CalibStatus")));
107 
108  for (std::map<int, unsigned>::iterator wlItr(wlToME_.begin()); wlItr != wlToME_.end(); ++wlItr) {
109  meQuality.use(wlItr->second);
110  meQualitySummary.use(wlItr->second);
111  meAmplitudeMean.use(wlItr->second);
112  meAmplitudeRMS.use(wlItr->second);
113  meTimingMean.use(wlItr->second);
114  meTimingRMSMap.use(wlItr->second);
115  mePNQualitySummary.use(wlItr->second);
116 
117  sAmplitude.use(wlItr->second);
118  sTiming.use(wlItr->second);
119  sPNAmplitude.use(wlItr->second);
120 
121  MESet::iterator qEnd(meQuality.end(GetElectronicsMap()));
122 
123  MESet::const_iterator tItr(GetElectronicsMap(), sTiming);
124  MESet::const_iterator aItr(GetElectronicsMap(), sAmplitude);
125 
126  int wl(wlItr->first + 3);
127  bool enabled(wl < 0 ? false : sCalibStatus.getBinContent(getEcalDQMSetupObjects(), wl) > 0 ? true : false);
128  for (MESet::iterator qItr(meQuality.beginChannel(GetElectronicsMap())); qItr != qEnd;
130  DetId id(qItr->getId());
131 
132  bool doMask(meQuality.maskMatches(id, mask, statusManager_, GetTrigTowerMap()));
133 
134  aItr = qItr;
135 
136  float aEntries(aItr->getBinEntries());
137 
138  if (aEntries < minChannelEntries_) {
139  qItr->setBinContent(enabled ? (doMask ? kMUnknown : kUnknown) : kMUnknown);
140  continue;
141  }
142 
143  float aMean(aItr->getBinContent());
144  float aRms(aItr->getBinError() * sqrt(aEntries));
145 
146  meAmplitudeMean.fill(getEcalDQMSetupObjects(), id, aMean);
147  meAmplitudeRMS.setBinContent(getEcalDQMSetupObjects(), id, aRms);
148 
149  tItr = qItr;
150 
151  float tEntries(tItr->getBinEntries());
152 
153  if (tEntries < minChannelEntries_)
154  continue;
155 
156  float tMean(tItr->getBinContent());
157  float tRms(tItr->getBinError() * sqrt(tEntries));
158 
159  meTimingMean.fill(getEcalDQMSetupObjects(), id, tMean);
160  meTimingRMSMap.setBinContent(getEcalDQMSetupObjects(), id, tRms);
161 
162  //Temporarily disabling all cuts on LED Quality plot.
163  qItr->setBinContent(doMask ? kMGood : kGood);
164 
165  /*
166  float intensity(aMean / expectedAmplitude_[wlItr->second]);
167  if (isForward(id))
168  intensity /= forwardFactor_;
169 
170  float aRmsThr(sqrt(pow(aMean * toleranceAmpRMSRatio_, 2) + pow(3., 2)));
171 
172  EcalScDetId scid = EEDetId(id).sc(); //Get the Endcap SC id for the given crystal id.
173 
174  //For the known bad Supercrystals in the SClist, bad quality flag is only set based on the amplitude RMS
175  //and everything else is ignored.
176  if (std::find(SClist_.begin(), SClist_.end(), int(scid)) != SClist_.end()) {
177  if (aRms > aRmsThr)
178  qItr->setBinContent(doMask ? kMBad : kBad);
179  else
180  qItr->setBinContent(doMask ? kMGood : kGood);
181  } else {
182  if (intensity < toleranceAmplitude_ || aRms > aRmsThr ||
183  std::abs(tMean - expectedTiming_[wlItr->second]) > toleranceTiming_ || tRms > toleranceTimRMS_)
184  qItr->setBinContent(doMask ? kMBad : kBad);
185  else
186  qItr->setBinContent(doMask ? kMGood : kGood);
187  }*/
188  }
189 
190  towerAverage_(meQualitySummary, meQuality, 0.2);
191 
192  for (unsigned iDCC(0); iDCC < nDCC; ++iDCC) {
193  if (memDCCIndex(iDCC + 1) == unsigned(-1))
194  continue;
195  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
196  continue;
197 
198  for (unsigned iPN(0); iPN < 10; ++iPN) {
199  EcalPnDiodeDetId id(EcalEndcap, iDCC + 1, iPN + 1);
200 
201  bool doMask(mePNQualitySummary.maskMatches(id, mask, statusManager_, GetTrigTowerMap()));
202 
203  float pEntries(sPNAmplitude.getBinEntries(getEcalDQMSetupObjects(), id));
204 
205  if (pEntries < minChannelEntries_) {
206  mePNQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, doMask ? kMUnknown : kUnknown);
207  continue;
208  }
209 
210  float pMean(sPNAmplitude.getBinContent(getEcalDQMSetupObjects(), id));
211  float pRms(sPNAmplitude.getBinError(getEcalDQMSetupObjects(), id) * sqrt(pEntries));
212  float intensity(pMean / expectedPNAmplitude_[wlItr->second]);
213 
214  if (intensity < tolerancePNAmp_ || pRms > pMean * tolerancePNRMSRatio_)
215  mePNQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, doMask ? kMBad : kBad);
216  else
217  mePNQualitySummary.setBinContent(getEcalDQMSetupObjects(), id, doMask ? kMGood : kGood);
218  }
219  }
220  }
221  }
222 
224 } // namespace ecaldqm
static const int LED_MEAN_ERROR
unsigned memDCCIndex(unsigned)
void setParams(edm::ParameterSet const &) override
Definition: LedClient.cc:30
void use(unsigned) const
Definition: MESetMulti.cc:133
void towerAverage_(MESet &, MESet const &, float)
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:168
std::string fullPath() const
Definition: FileInPath.cc:161
MESet & at(const std::string &key)
Definition: MESet.h:399
const_iterator & toNextChannel(EcalElectronicsMapping const *electronicsMap)
Definition: MESet.h:320
double toleranceAmplitude_
Definition: LedClient.h:21
double getBinContent(EcalDQMSetupObjects const edso, DetId const &_id, int _bin=0) const override
Definition: MESetMulti.h:111
float forwardFactor_
Definition: LedClient.h:29
const_iterator beginChannel(EcalElectronicsMapping const *electronicsMap) const override
Definition: MESetMulti.h:168
std::map< int, unsigned > wlToME_
Definition: LedClient.h:17
constexpr bool enabled
Definition: SoACommon.h:73
static std::string to_string(const XMLCh *ch)
void fill(EcalDQMSetupObjects const edso, DetId const &_id, double _xyw=1., double _yw=1., double _w=1.) override
Definition: MESetMulti.h:29
virtual double getBinContent(EcalDQMSetupObjects const, DetId const &, int=0) const
Definition: MESet.h:100
std::set< std::string > qualitySummaries_
std::vector< double > expectedTiming_
Definition: LedClient.h:23
T sqrt(T t)
Definition: SSEVec.h:19
StatusManager const * statusManager_
void setBinContent(EcalDQMSetupObjects const edso, DetId const &_id, double _content) override
Definition: MESetMulti.h:48
std::vector< double > expectedAmplitude_
Definition: LedClient.h:20
std::vector< double > expectedPNAmplitude_
Definition: LedClient.h:26
static const int LED_TIMING_MEAN_ERROR
double toleranceAmpRMSRatio_
Definition: LedClient.h:22
MESetCollection sources_
double getBinError(EcalDQMSetupObjects const edso, DetId const &_id, int _bin=0) const override
Definition: MESetMulti.h:121
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:150
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
Definition: DetId.h:17
double getBinEntries(EcalDQMSetupObjects const edso, DetId const &_id, int _bin=0) const override
Definition: MESetMulti.h:131
static const int LED_TIMING_RMS_ERROR
MESetCollection MEs_
Definition: DQWorker.h:131
double toleranceTimRMS_
Definition: LedClient.h:25
double toleranceTiming_
Definition: LedClient.h:24
void producePlots(ProcessType) override
Definition: LedClient.cc:91
std::vector< uint32_t > SClist_
Definition: LedClient.h:30
double tolerancePNAmp_
Definition: LedClient.h:27
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
static const int LED_RMS_ERROR
EcalTrigTowerConstituentsMap const * GetTrigTowerMap()
Definition: DQWorker.cc:155
bool maskMatches(DetId const &_id, uint32_t _mask, StatusManager const *_statusManager, EcalTrigTowerConstituentsMap const *trigTowerMap) const override
Definition: MESetMulti.h:144
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:46
const_iterator end(EcalElectronicsMapping const *electronicsMap) const override
Definition: MESetMulti.h:165
double tolerancePNRMSRatio_
Definition: LedClient.h:28