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