CMS 3D CMS Logo

LedTask.cc
Go to the documentation of this file.
2 
4 
6 
7 namespace ecaldqm {
8 
9  LedTask::LedTask() : DQWorkerTask(), wlToME_(), pnAmp_(), emptyLS_(0), emptyLSLimit_(0) {
10  std::fill_n(enable_, nEEDCC, false);
11  std::fill_n(wavelength_, nEEDCC, 0);
12  std::fill_n(rtHalf_, nEEDCC, 0);
13  }
14 
16  emptyLSLimit_ = _params.getUntrackedParameter<int>("emptyLSLimit");
17 
18  std::vector<int> ledWavelengths(_params.getUntrackedParameter<std::vector<int> >("ledWavelengths"));
19 
21 
22  MESetMulti& amplitude(static_cast<MESetMulti&>(MEs_.at("Amplitude")));
23  unsigned nWL(ledWavelengths.size());
24  for (unsigned iWL(0); iWL != nWL; ++iWL) {
25  int wl(ledWavelengths[iWL]);
26  if (wl != 1 && wl != 2)
27  throw cms::Exception("InvalidConfiguration") << "Led Wavelength";
28  repl["wl"] = std::to_string(wl);
29  wlToME_[wl] = amplitude.getIndex(repl);
30  }
31  }
32 
33  void LedTask::addDependencies(DependencySet& _dependencies) {
34  _dependencies.push_back(Dependency(kEEDigi, kEcalRawData));
37  }
38 
39  bool LedTask::filterRunType(short const* _runType) {
40  bool enable(false);
41 
42  for (unsigned iDCC(0); iDCC != nDCC; iDCC++) {
43  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
44  continue;
45  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
46  if (_runType[iDCC] == EcalDCCHeaderBlock::LED_STD || _runType[iDCC] == EcalDCCHeaderBlock::LED_GAP) {
47  enable = true;
48  enable_[index] = true;
49  } else
50  enable_[index] = false;
51  }
52 
53  return enable;
54  }
55 
56  void LedTask::beginRun(edm::Run const&, edm::EventSetup const&) { emptyLS_ = 0; }
57 
59  isemptyLS = 0;
60  if (emptyLS_ + 1 > emptyLSLimit_)
61  emptyLS_ = -1;
62  }
63 
64  void LedTask::beginEvent(edm::Event const&, edm::EventSetup const&, bool const&, bool&) { pnAmp_.clear(); }
65 
67  MESet& meCalibStatus(MEs_.at("CalibStatus"));
68  for (EcalRawDataCollection::const_iterator rItr(_rawData.begin()); rItr != _rawData.end(); ++rItr) {
69  unsigned iDCC(rItr->id() - 1);
70  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
71  continue;
72  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
73 
74  if (!enable_[index]) {
75  wavelength_[index] = -1;
76  rtHalf_[index] = -1;
77  continue;
78  }
79  if (rItr->getEventSettings().wavelength == 0)
80  wavelength_[index] = 1;
81  else if (rItr->getEventSettings().wavelength == 2)
82  wavelength_[index] = 2;
83  else
84  wavelength_[index] = -1;
85 
86  if (wlToME_.find(wavelength_[index]) == wlToME_.end())
87  enable_[index] = false;
88 
89  rtHalf_[index] = rItr->getRtHalf();
90  }
91  bool LedStatus[2];
92  for (unsigned iW(0); iW < 2; iW++) {
93  LedStatus[iW] = false;
94  }
95  for (unsigned index(0); index < nEEDCC; ++index) {
96  switch (wavelength_[index]) {
97  case 1:
98  LedStatus[0] = true;
99  break;
100  case 2:
101  LedStatus[1] = true;
102  break;
103  default:
104  break;
105  }
106  }
107  for (unsigned iWL(0); iWL < 2; iWL++) {
108  meCalibStatus.fill(getEcalDQMSetupObjects(), double(iWL + 3), LedStatus[iWL] ? 1 : 0);
109  }
110  }
111 
112  void LedTask::runOnDigis(EEDigiCollection const& _digis) {
113  MESet& meOccupancy(MEs_.at("Occupancy"));
114  MESet& meShape(MEs_.at("Shape"));
115  MESet& meSignalRate(MEs_.at("SignalRate"));
116 
117  int nReadouts[nEEDCC];
118  int maxpos[nEEDCC][10];
119  for (unsigned index(0); index < nEEDCC; ++index) {
120  nReadouts[index] = 0;
121  for (int i(0); i < 10; i++)
122  maxpos[index][i] = 0;
123  }
124 
125  for (EEDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
126  const DetId& id(digiItr->id());
127 
128  unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
129  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
130  continue;
131  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
132 
133  if (!enable_[index])
134  continue;
135  if (rtHalf(id, GetElectronicsMap()) != rtHalf_[index])
136  continue;
137 
138  meOccupancy.fill(getEcalDQMSetupObjects(), id);
139 
140  ++nReadouts[index];
141 
142  EcalDataFrame dataFrame(*digiItr);
143 
144  int iMax(-1);
145  int max(0);
146  int min(4096);
147  for (int i(0); i < 10; i++) {
148  int adc(dataFrame.sample(i).adc());
149  if (adc > max) {
150  max = adc;
151  iMax = i;
152  }
153  if (adc < min)
154  min = adc;
155  }
156  if (iMax >= 0 && max - min > 3) // normal RMS of pedestal is ~2.5
157  maxpos[index][iMax] += 1;
158  }
159 
160  // signal existence check
161  bool enable(false);
162  bool ledOnExpected(emptyLS_ >= 0);
163 
164  unsigned iME(-1);
165 
166  for (int index(0); index < nEEDCC; ++index) {
167  if (nReadouts[index] == 0) {
168  enable_[index] = false;
169  continue;
170  }
171 
172  int threshold(nReadouts[index] / 3);
173  if (ledOnExpected)
174  enable_[index] = false;
175 
176  for (int i(0); i < 10; i++) {
177  if (maxpos[index][i] > threshold) {
178  enable = true;
179  enable_[index] = true;
180  break;
181  }
182  }
183 
184  if (iME != wlToME_[wavelength_[index]]) {
185  iME = wlToME_[wavelength_[index]];
186  static_cast<MESetMulti&>(meSignalRate).use(iME);
187  }
188 
189  meSignalRate.fill(
190  getEcalDQMSetupObjects(), (index <= kEEmHigh ? index : index + nEBDCC) + 1, enable_[index] ? 1 : 0);
191  }
192 
193  if (!enable && isemptyLS >= 0)
194  isemptyLS = 1;
195  else if (enable)
196  isemptyLS = -1;
197 
198  if (enable)
199  emptyLS_ = 0;
200  else if (ledOnExpected)
201  return;
202 
203  iME = -1;
204 
205  for (EEDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
206  const DetId& id(digiItr->id());
207 
208  unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
209  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
210  continue;
211  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
212 
213  if (!enable_[index])
214  continue;
215  if (rtHalf(id, GetElectronicsMap()) != rtHalf_[index])
216  continue;
217 
218  if (iME != wlToME_[wavelength_[index]]) {
219  iME = wlToME_[wavelength_[index]];
220  static_cast<MESetMulti&>(meShape).use(iME);
221  }
222 
223  // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
224  EcalDataFrame dataFrame(*digiItr);
225 
226  for (int iSample(0); iSample < 10; iSample++)
227  meShape.fill(getEcalDQMSetupObjects(), id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
228 
231  if (pnidA.null() || pnidB.null())
232  continue;
233  pnAmp_.insert(std::make_pair(pnidA.rawId(), 0.));
234  pnAmp_.insert(std::make_pair(pnidB.rawId(), 0.));
235  }
236  }
237 
239  MESet& mePNAmplitude(MEs_.at("PNAmplitude"));
240 
241  unsigned iME(-1);
242 
243  for (EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
244  if (digiItr->sample(0).gainId() != 0 && digiItr->sample(0).gainId() != 1)
245  continue;
246 
247  const EcalPnDiodeDetId& id(digiItr->id());
248 
249  std::map<uint32_t, float>::iterator ampItr(pnAmp_.find(id.rawId()));
250  if (ampItr == pnAmp_.end())
251  continue;
252 
253  unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
254  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
255  continue;
256  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
257 
258  float pedestal(0.);
259  for (int iSample(0); iSample < 4; iSample++)
260  pedestal += digiItr->sample(iSample).adc();
261  pedestal /= 4.;
262 
263  float max(0.);
264  for (int iSample(0); iSample < 50; iSample++) {
265  float amp(digiItr->sample(iSample).adc() - pedestal);
266  if (amp > max)
267  max = amp;
268  }
269 
270  if (iME != wlToME_[wavelength_[index]]) {
271  iME = wlToME_[wavelength_[index]];
272  static_cast<MESetMulti&>(mePNAmplitude).use(iME);
273  }
274 
275  mePNAmplitude.fill(getEcalDQMSetupObjects(), id, max);
276 
277  ampItr->second = max;
278  }
279  }
280 
282  using namespace std;
283 
284  MESet& meAmplitude(MEs_.at("Amplitude"));
285  MESet& meAmplitudeSummary(MEs_.at("AmplitudeSummary"));
286  MESet& meTiming(MEs_.at("Timing"));
287  MESet& meAOverP(MEs_.at("AOverP"));
288 
289  unsigned iME(-1);
290 
291  for (EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr) {
292  EEDetId id(uhitItr->id());
293 
294  unsigned iDCC(dccId(id, GetElectronicsMap()) - 1);
295  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
296  continue;
297  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
298 
299  if (!enable_[index])
300  continue;
301  if (rtHalf(id, GetElectronicsMap()) != rtHalf_[index])
302  continue;
303 
304  if (iME != wlToME_[wavelength_[index]]) {
305  iME = wlToME_[wavelength_[index]];
306  static_cast<MESetMulti&>(meAmplitude).use(iME);
307  static_cast<MESetMulti&>(meAmplitudeSummary).use(iME);
308  static_cast<MESetMulti&>(meTiming).use(iME);
309  static_cast<MESetMulti&>(meAOverP).use(iME);
310  }
311 
312  float amp(max((double)uhitItr->amplitude(), 0.));
313  float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
314 
315  meAmplitude.fill(getEcalDQMSetupObjects(), id, amp);
316  meAmplitudeSummary.fill(getEcalDQMSetupObjects(), id, amp);
317  meTiming.fill(getEcalDQMSetupObjects(), id, jitter);
318 
319  float aop(0.);
320 
321  map<uint32_t, float>::iterator ampItrA(pnAmp_.find(pnForCrystal(id, 'a', GetElectronicsMap())));
322  map<uint32_t, float>::iterator ampItrB(pnAmp_.find(pnForCrystal(id, 'b', GetElectronicsMap())));
323  if (ampItrA == pnAmp_.end() && ampItrB == pnAmp_.end())
324  continue;
325  else if (ampItrB == pnAmp_.end())
326  aop = amp / ampItrA->second;
327  else if (ampItrA == pnAmp_.end())
328  aop = amp / ampItrB->second;
329  else
330  aop = amp / (ampItrA->second + ampItrB->second) * 2.;
331 
332  meAOverP.fill(getEcalDQMSetupObjects(), id, aop);
333  }
334  }
335 
337  if (isemptyLS == 1)
338  emptyLS_ += 1;
339  }
340 
342 } // namespace ecaldqm
bool enable_[nEEDCC]
Definition: LedTask.h:41
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:168
MESet & at(const std::string &key)
Definition: MESet.h:399
std::vector< T >::const_iterator const_iterator
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: LedTask.cc:58
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
void addDependencies(DependencySet &) override
Definition: LedTask.cc:33
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
void runOnDigis(EEDigiCollection const &)
Definition: LedTask.cc:112
void runOnUncalibRecHits(EcalUncalibratedRecHitCollection const &)
Definition: LedTask.cc:281
unsigned rtHalf_[nEEDCC]
Definition: LedTask.h:43
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: LedTask.cc:56
void runOnRawData(EcalRawDataCollection const &)
Definition: LedTask.cc:66
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
unsigned dccId(DetId const &, EcalElectronicsMapping const *)
EcalPnDiodeDetId pnForCrystal(DetId const &, char, EcalElectronicsMapping const *)
const_iterator begin() const
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: LedTask.cc:336
int emptyLSLimit_
Definition: LedTask.h:47
enable
Messages.
Definition: DiMuonV_cfg.py:92
unsigned wavelength_[nEEDCC]
Definition: LedTask.h:42
const_iterator end() const
const_iterator end() const
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:150
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
Definition: DetId.h:17
const_iterator begin() const
The iterator returned can not safely be used across threads.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
MESetCollection MEs_
Definition: DQWorker.h:131
std::map< unsigned, float > pnAmp_
Definition: LedTask.h:44
std::map< int, unsigned > wlToME_
Definition: LedTask.h:39
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool filterRunType(short const *) override
Definition: LedTask.cc:39
unsigned rtHalf(DetId const &, EcalElectronicsMapping const *)
int adc() const
get the ADC sample (12 bits)
void setParams(edm::ParameterSet const &) override
Definition: LedTask.cc:15
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:46
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:46
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
Definition: Run.h:45
uint16_t *__restrict__ uint16_t const *__restrict__ adc
void runOnPnDigis(EcalPnDiodeDigiCollection const &)
Definition: LedTask.cc:238
void beginEvent(edm::Event const &, edm::EventSetup const &, bool const &, bool &) override
Definition: LedTask.cc:64