CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LedTask.cc
Go to the documentation of this file.
1 #include "../interface/LedTask.h"
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  for(EcalRawDataCollection::const_iterator rItr(_rawData.begin()); rItr != _rawData.end(); ++rItr){
91  unsigned iDCC(rItr->id() - 1);
92  if(iDCC >= kEBmLow && iDCC <= kEBpHigh) continue;
93  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
94 
95  if(!enable_[index]){
96  wavelength_[index] = -1;
97  rtHalf_[index] = -1;
98  continue;
99  }
100  if(rItr->getEventSettings().wavelength == 0)
101  wavelength_[index] = 1;
102  else if(rItr->getEventSettings().wavelength == 2)
103  wavelength_[index] = 2;
104  else
105  wavelength_[index] = -1;
106 
107  if(wlToME_.find(wavelength_[index]) == wlToME_.end())
108  enable_[index] = false;
109 
110  rtHalf_[index] = rItr->getRtHalf();
111  }
112  }
113 
114  void
116  {
117  MESet& meOccupancy(MEs_.at("Occupancy"));
118  MESet& meShape(MEs_.at("Shape"));
119  MESet& meSignalRate(MEs_.at("SignalRate"));
120 
121  int nReadouts[nEEDCC];
122  int maxpos[nEEDCC][10];
123  for(unsigned index(0); index < nEEDCC; ++index){
124  nReadouts[index] = 0;
125  for(int i(0); i < 10; i++) maxpos[index][i] = 0;
126  }
127 
128  for(EEDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
129  const DetId& id(digiItr->id());
130 
131  unsigned iDCC(dccId(id) - 1);
132  if(iDCC >= kEBmLow && iDCC <= kEBpHigh) continue;
133  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
134 
135  if(!enable_[index]) continue;
136  if(rtHalf(id) != rtHalf_[index]) 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) min = adc;
154  }
155  if(iMax >= 0 && max - min > 3) // normal RMS of pedestal is ~2.5
156  maxpos[index][iMax] += 1;
157  }
158 
159  // signal existence check
160  bool enable(false);
161  bool ledOnExpected(emptyLS_ >= 0);
162 
163  unsigned iME(-1);
164 
165  for(int index(0); index < nEEDCC; ++index){
166  if(nReadouts[index] == 0){
167  enable_[index] = false;
168  continue;
169  }
170 
171  int threshold(nReadouts[index] / 3);
172  if(ledOnExpected) enable_[index] = false;
173 
174  for(int i(0); i < 10; i++){
175  if(maxpos[index][i] > threshold){
176  enable = true;
177  enable_[index] = true;
178  break;
179  }
180  }
181 
182  if(iME != wlToME_[wavelength_[index]]){
183  iME = wlToME_[wavelength_[index]];
184  static_cast<MESetMulti&>(meSignalRate).use(iME);
185  }
186 
187  meSignalRate.fill((index <= kEEmHigh ? index : index + nEBDCC) + 1, enable_[index] ? 1 : 0);
188  }
189 
190  if(!enable && isemptyLS >= 0) isemptyLS = 1;
191  else if(enable) isemptyLS = -1;
192 
193  if(enable) emptyLS_ = 0;
194  else if(ledOnExpected) return;
195 
196  iME = -1;
197 
198  for(EEDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
199  const DetId& id(digiItr->id());
200 
201  unsigned iDCC(dccId(id) - 1);
202  if(iDCC >= kEBmLow && iDCC <= kEBpHigh) continue;
203  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
204 
205  if(!enable_[index]) continue;
206  if(rtHalf(id) != rtHalf_[index]) continue;
207 
208  if(iME != wlToME_[wavelength_[index]]){
209  iME = wlToME_[wavelength_[index]];
210  static_cast<MESetMulti&>(meShape).use(iME);
211  }
212 
213  // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
214  EcalDataFrame dataFrame(*digiItr);
215 
216  for(int iSample(0); iSample < 10; iSample++)
217  meShape.fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
218 
219  EcalPnDiodeDetId pnidA(pnForCrystal(id, 'a'));
220  EcalPnDiodeDetId pnidB(pnForCrystal(id, 'b'));
221  if(pnidA.null() || pnidB.null()) continue;
222  pnAmp_.insert(std::make_pair(pnidA.rawId(), 0.));
223  pnAmp_.insert(std::make_pair(pnidB.rawId(), 0.));
224  }
225  }
226 
227  void
229  {
230  MESet& mePNAmplitude(MEs_.at("PNAmplitude"));
231 
232  unsigned iME(-1);
233 
234  for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
235  if(digiItr->sample(0).gainId() != 0 && digiItr->sample(0).gainId() != 1) continue;
236 
237  const EcalPnDiodeDetId& id(digiItr->id());
238 
239  std::map<uint32_t, float>::iterator ampItr(pnAmp_.find(id.rawId()));
240  if(ampItr == pnAmp_.end()) continue;
241 
242  unsigned iDCC(dccId(id) - 1);
243  if(iDCC >= kEBmLow && iDCC <= kEBpHigh) continue;
244  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
245 
246  float pedestal(0.);
247  for(int iSample(0); iSample < 4; iSample++)
248  pedestal += digiItr->sample(iSample).adc();
249  pedestal /= 4.;
250 
251  float max(0.);
252  for(int iSample(0); iSample < 50; iSample++){
253  float amp(digiItr->sample(iSample).adc() - pedestal);
254  if(amp > max) max = amp;
255  }
256 
257  if(iME != wlToME_[wavelength_[index]]){
258  iME = wlToME_[wavelength_[index]];
259  static_cast<MESetMulti&>(mePNAmplitude).use(iME);
260  }
261 
262  mePNAmplitude.fill(id, max);
263 
264  ampItr->second = max;
265  }
266  }
267 
268  void
270  {
271  using namespace std;
272 
273  MESet& meAmplitude(MEs_.at("Amplitude"));
274  MESet& meAmplitudeSummary(MEs_.at("AmplitudeSummary"));
275  MESet& meTiming(MEs_.at("Timing"));
276  MESet& meAOverP(MEs_.at("AOverP"));
277 
278  unsigned iME(-1);
279 
280  for(EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr){
281  EEDetId id(uhitItr->id());
282 
283  unsigned iDCC(dccId(id) - 1);
284  if(iDCC >= kEBmLow && iDCC <= kEBpHigh) continue;
285  unsigned index(iDCC <= kEEmHigh ? iDCC : iDCC - nEBDCC);
286 
287  if(!enable_[index]) continue;
288  if(rtHalf(id) != rtHalf_[index]) continue;
289 
290  if(iME != wlToME_[wavelength_[index]]){
291  iME = wlToME_[wavelength_[index]];
292  static_cast<MESetMulti&>(meAmplitude).use(iME);
293  static_cast<MESetMulti&>(meAmplitudeSummary).use(iME);
294  static_cast<MESetMulti&>(meTiming).use(iME);
295  static_cast<MESetMulti&>(meAOverP).use(iME);
296  }
297 
298  float amp(max((double)uhitItr->amplitude(), 0.));
299  float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
300 
301  meAmplitude.fill(id, amp);
302  meAmplitudeSummary.fill(id, amp);
303  meTiming.fill(id, jitter);
304 
305  float aop(0.);
306 
307  map<uint32_t, float>::iterator ampItrA(pnAmp_.find(pnForCrystal(id, 'a')));
308  map<uint32_t, float>::iterator ampItrB(pnAmp_.find(pnForCrystal(id, 'b')));
309  if(ampItrA == pnAmp_.end() && ampItrB == pnAmp_.end()) continue;
310  else if(ampItrB == pnAmp_.end()) aop = amp / ampItrA->second;
311  else if(ampItrA == pnAmp_.end()) aop = amp / ampItrB->second;
312  else aop = amp / (ampItrA->second + ampItrB->second) * 2.;
313 
314  meAOverP.fill(id, aop);
315  }
316  }
317 
318  void
320  if(isemptyLS == 1)emptyLS_ += 1;
321  }
322 
324 }
325 
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
int i
Definition: DBlmapReader.cc:9
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:108
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
void setParams(edm::ParameterSet const &)
Definition: LedTask.cc:22
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
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::string to_string(const T &t)
Definition: Logger.cc:26
void beginEvent(edm::Event const &, edm::EventSetup const &) override
Definition: LedTask.cc:82
void runOnDigis(EEDigiCollection const &)
Definition: LedTask.cc:115
void runOnUncalibRecHits(EcalUncalibratedRecHitCollection const &)
Definition: LedTask.cc:269
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:319
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
bool null() const
is this a null id ?
Definition: DetId.h:45
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
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:43
int adc() const
get the ADC sample (12 bits)
void runOnPnDigis(EcalPnDiodeDigiCollection const &)
Definition: LedTask.cc:228