CMS 3D CMS Logo

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