CMS 3D CMS Logo

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