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(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) - 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) != rtHalf_[index])
136  continue;
137 
138  meOccupancy.fill(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((index <= kEEmHigh ? index : index + nEBDCC) + 1, enable_[index] ? 1 : 0);
190  }
191 
192  if (!enable && isemptyLS >= 0)
193  isemptyLS = 1;
194  else if (enable)
195  isemptyLS = -1;
196 
197  if (enable)
198  emptyLS_ = 0;
199  else if (ledOnExpected)
200  return;
201 
202  iME = -1;
203 
204  for (EEDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
205  const DetId& id(digiItr->id());
206 
207  unsigned iDCC(dccId(id) - 1);
208  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
209  continue;
210  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
211 
212  if (!enable_[index])
213  continue;
214  if (rtHalf(id) != rtHalf_[index])
215  continue;
216 
217  if (iME != wlToME_[wavelength_[index]]) {
218  iME = wlToME_[wavelength_[index]];
219  static_cast<MESetMulti&>(meShape).use(iME);
220  }
221 
222  // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
223  EcalDataFrame dataFrame(*digiItr);
224 
225  for (int iSample(0); iSample < 10; iSample++)
226  meShape.fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
227 
228  EcalPnDiodeDetId pnidA(pnForCrystal(id, 'a'));
229  EcalPnDiodeDetId pnidB(pnForCrystal(id, 'b'));
230  if (pnidA.null() || pnidB.null())
231  continue;
232  pnAmp_.insert(std::make_pair(pnidA.rawId(), 0.));
233  pnAmp_.insert(std::make_pair(pnidB.rawId(), 0.));
234  }
235  }
236 
238  MESet& mePNAmplitude(MEs_.at("PNAmplitude"));
239 
240  unsigned iME(-1);
241 
242  for (EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
243  if (digiItr->sample(0).gainId() != 0 && digiItr->sample(0).gainId() != 1)
244  continue;
245 
246  const EcalPnDiodeDetId& id(digiItr->id());
247 
248  std::map<uint32_t, float>::iterator ampItr(pnAmp_.find(id.rawId()));
249  if (ampItr == pnAmp_.end())
250  continue;
251 
252  unsigned iDCC(dccId(id) - 1);
253  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
254  continue;
255  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
256 
257  float pedestal(0.);
258  for (int iSample(0); iSample < 4; iSample++)
259  pedestal += digiItr->sample(iSample).adc();
260  pedestal /= 4.;
261 
262  float max(0.);
263  for (int iSample(0); iSample < 50; iSample++) {
264  float amp(digiItr->sample(iSample).adc() - pedestal);
265  if (amp > max)
266  max = amp;
267  }
268 
269  if (iME != wlToME_[wavelength_[index]]) {
270  iME = wlToME_[wavelength_[index]];
271  static_cast<MESetMulti&>(mePNAmplitude).use(iME);
272  }
273 
274  mePNAmplitude.fill(id, max);
275 
276  ampItr->second = max;
277  }
278  }
279 
281  using namespace std;
282 
283  MESet& meAmplitude(MEs_.at("Amplitude"));
284  MESet& meAmplitudeSummary(MEs_.at("AmplitudeSummary"));
285  MESet& meTiming(MEs_.at("Timing"));
286  MESet& meAOverP(MEs_.at("AOverP"));
287 
288  unsigned iME(-1);
289 
290  for (EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr) {
291  EEDetId id(uhitItr->id());
292 
293  unsigned iDCC(dccId(id) - 1);
294  if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
295  continue;
296  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
297 
298  if (!enable_[index])
299  continue;
300  if (rtHalf(id) != rtHalf_[index])
301  continue;
302 
303  if (iME != wlToME_[wavelength_[index]]) {
304  iME = wlToME_[wavelength_[index]];
305  static_cast<MESetMulti&>(meAmplitude).use(iME);
306  static_cast<MESetMulti&>(meAmplitudeSummary).use(iME);
307  static_cast<MESetMulti&>(meTiming).use(iME);
308  static_cast<MESetMulti&>(meAOverP).use(iME);
309  }
310 
311  float amp(max((double)uhitItr->amplitude(), 0.));
312  float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
313 
314  meAmplitude.fill(id, amp);
315  meAmplitudeSummary.fill(id, amp);
316  meTiming.fill(id, jitter);
317 
318  float aop(0.);
319 
320  map<uint32_t, float>::iterator ampItrA(pnAmp_.find(pnForCrystal(id, 'a')));
321  map<uint32_t, float>::iterator ampItrB(pnAmp_.find(pnForCrystal(id, 'b')));
322  if (ampItrA == pnAmp_.end() && ampItrB == pnAmp_.end())
323  continue;
324  else if (ampItrB == pnAmp_.end())
325  aop = amp / ampItrA->second;
326  else if (ampItrA == pnAmp_.end())
327  aop = amp / ampItrB->second;
328  else
329  aop = amp / (ampItrA->second + ampItrB->second) * 2.;
330 
331  meAOverP.fill(id, aop);
332  }
333  }
334 
336  if (isemptyLS == 1)
337  emptyLS_ += 1;
338  }
339 
341 } // namespace ecaldqm
ecaldqm::LedTask
Definition: LedTask.h:14
LedTask.h
EcalDataFrame::sample
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
mps_fire.i
i
Definition: mps_fire.py:428
CustomPhysics_cfi.amplitude
amplitude
Definition: CustomPhysics_cfi.py:12
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
ecaldqm
Definition: DQWorker.h:24
ecaldqm::LedTask::rtHalf_
unsigned rtHalf_[nEEDCC]
Definition: LedTask.h:43
edm::DataFrameContainer::const_iterator
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: DataFrameContainer.h:61
ecaldqm::LedTask::isemptyLS
int isemptyLS
Definition: LedTask.h:48
LaserClient_cfi.wl
wl
Definition: LaserClient_cfi.py:46
ecaldqm::DependencySet
Definition: DQWorkerTask.h:44
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
min
T min(T a, T b)
Definition: MathUtil.h:58
ecaldqm::kEEDigi
Definition: Collections.h:26
ecaldqm::MESet::PathReplacements
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:31
Reconstruction_hiPF_cff.enable
enable
Definition: Reconstruction_hiPF_cff.py:87
l1extraParticles_cfi._params
_params
Definition: l1extraParticles_cfi.py:29
ecaldqm::nEBDCC
Definition: EcalDQMCommonUtils.h:93
ecaldqm::LedTask::runOnRawData
void runOnRawData(EcalRawDataCollection const &)
Definition: LedTask.cc:66
edm::SortedCollection
Definition: SortedCollection.h:49
ecaldqm::LedTask::enable_
bool enable_[nEEDCC]
Definition: LedTask.h:41
ecaldqm::LedTask::wlToME_
std::map< int, unsigned > wlToME_
Definition: LedTask.h:39
DetId::null
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
ecaldqm::Dependency
Definition: DQWorkerTask.h:19
EcalPnDiodeDetId
Definition: EcalPnDiodeDetId.h:22
ecaldqm::kEcalRawData
Definition: Collections.h:10
EcalDataFrame
Definition: EcalDataFrame.h:16
ecaldqm::kEELaserLedUncalibRecHit
Definition: Collections.h:33
EcalDCCHeaderBlock::LED_GAP
Definition: EcalDCCHeaderBlock.h:45
ecaldqm::LedTask::runOnPnDigis
void runOnPnDigis(EcalPnDiodeDigiCollection const &)
Definition: LedTask.cc:237
ecalLiteDTU::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalLiteDTUSample.h:12
DetId
Definition: DetId.h:17
EcalMGPASample::adc
int adc() const
get the ADC sample (12 bits)
Definition: EcalMGPASample.h:31
ecaldqm::LedTask::LedTask
LedTask()
Definition: LedTask.cc:9
ecaldqm::LedTask::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: LedTask.cc:335
ecaldqm::DQWorkerTask
Definition: DQWorkerTask.h:71
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
ecaldqm::LedTask::pnAmp_
std::map< unsigned, float > pnAmp_
Definition: LedTask.h:44
ecaldqm::LedTask::emptyLSLimit_
int emptyLSLimit_
Definition: LedTask.h:47
ecaldqm::LedTask::runOnDigis
void runOnDigis(EEDigiCollection const &)
Definition: LedTask.cc:112
ecaldqm::kEBpHigh
Definition: EcalDQMCommonUtils.h:88
ecaldqm::LedTask::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: LedTask.cc:58
ecaldqm::kEEmHigh
Definition: EcalDQMCommonUtils.h:82
ecaldqm::rtHalf
unsigned rtHalf(DetId const &)
Definition: EcalDQMCommonUtils.cc:119
ecaldqm::nEEDCC
Definition: EcalDQMCommonUtils.h:94
ecaldqm::LedTask::runOnUncalibRecHits
void runOnUncalibRecHits(EcalUncalibratedRecHitCollection const &)
Definition: LedTask.cc:280
ecaldqm::DQWorker::MEs_
MESetCollection MEs_
Definition: DQWorker.h:78
EEDetId
Definition: EEDetId.h:14
edm::ParameterSet
Definition: ParameterSet.h:47
ecaldqm::LedTask::setParams
void setParams(edm::ParameterSet const &) override
Definition: LedTask.cc:15
ecaldqm::MESetMulti
Definition: MESetMulti.h:13
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
ecaldqm::pnForCrystal
EcalPnDiodeDetId pnForCrystal(DetId const &, char)
Definition: EcalDQMCommonUtils2.cc:10
EEDigiCollection
Definition: EcalDigiCollections.h:69
ecaldqm::MESetCollection::at
MESet & at(const std::string &key)
Definition: MESet.h:362
ecaldqm::DependencySet::push_back
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:46
edm::DataFrameContainer::begin
const_iterator begin() const
The iterator returned can not safely be used across threads.
Definition: DataFrameContainer.h:149
ecaldqm::kPnDiodeDigi
Definition: Collections.h:27
ecaldqm::kEBmLow
Definition: EcalDQMCommonUtils.h:85
EcalCondDBWriter_cfi.pedestal
pedestal
Definition: EcalCondDBWriter_cfi.py:49
edm::EventSetup
Definition: EventSetup.h:57
CalibrationSummaryClient_cfi.ledWavelengths
ledWavelengths
Definition: CalibrationSummaryClient_cfi.py:16
ecaldqm::LedTask::addDependencies
void addDependencies(DependencySet &) override
Definition: LedTask.cc:33
ecaldqm::LedTask::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: LedTask.cc:56
ecaldqm::LedTask::beginEvent
void beginEvent(edm::Event const &, edm::EventSetup const &, bool const &, bool &) override
Definition: LedTask.cc:64
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
Exception
Definition: hltDiff.cc:246
ecaldqm::LedTask::filterRunType
bool filterRunType(short const *) override
Definition: LedTask.cc:39
MESetMulti.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ecaldqm::nDCC
Definition: EcalDQMCommonUtils.h:92
DEFINE_ECALDQM_WORKER
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:112
ParameterSet.h
EcalDCCHeaderBlock::LED_STD
Definition: EcalDCCHeaderBlock.h:34
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
edm::Event
Definition: Event.h:73
edm::DataFrameContainer::end
const_iterator end() const
Definition: DataFrameContainer.h:152
ecaldqm::LedTask::wavelength_
unsigned wavelength_[nEEDCC]
Definition: LedTask.h:42
ecaldqm::MESet
Definition: MESet.h:27
ecaldqm::LedTask::emptyLS_
int emptyLS_
Definition: LedTask.h:46
ecaldqm::dccId
unsigned dccId(DetId const &)
Definition: EcalDQMCommonUtils.cc:16