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  {
16  std::fill_n(enable_, nDCC, false);
17  std::fill_n(wavelength_, nDCC, 0);
18  std::fill_n(rtHalf_, nDCC, 0);
19  }
20 
21  void
23  {
24  emptyLSLimit_ = _params.getUntrackedParameter<int>("emptyLSLimit");
25 
26  std::vector<int> laserWavelengths(_params.getUntrackedParameter<std::vector<int> >("laserWavelengths"));
27 
29 
30  MESetMulti& amplitude(static_cast<MESetMulti&>(MEs_.at("Amplitude")));
31  unsigned nWL(laserWavelengths.size());
32  for(unsigned iWL(0); iWL != nWL; ++iWL){
33  int wl(laserWavelengths[iWL]);
34  if(wl <= 0 || wl >= 5) throw cms::Exception("InvalidConfiguration") << "Laser 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(kEBDigi, kEcalRawData));
44  _dependencies.push_back(Dependency(kEEDigi, kEcalRawData));
48  }
49 
50  bool
51  LaserTask::filterRunType(short const* _runType)
52  {
53  bool enable(false);
54 
55  for(unsigned iDCC(0); iDCC < nDCC; iDCC++){
56  if(_runType[iDCC] == EcalDCCHeaderBlock::LASER_STD ||
57  _runType[iDCC] == EcalDCCHeaderBlock::LASER_GAP){
58  enable = true;
59  enable_[iDCC] = true;
60  }
61  else
62  enable_[iDCC] = 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 
92  if(!enable_[iDCC]){
93  wavelength_[iDCC] = -1;
94  rtHalf_[iDCC] = -1;
95  continue;
96  }
97  wavelength_[iDCC] = rItr->getEventSettings().wavelength + 1;
98 
99  if(wlToME_.find(wavelength_[iDCC]) == wlToME_.end())
100  enable_[iDCC] = false;
101 
102  rtHalf_[iDCC] = rItr->getRtHalf();
103  }
104  }
105 
106  template<typename DigiCollection>
107  void
108  LaserTask::runOnDigis(DigiCollection const& _digis)
109  {
110  MESet& meOccupancy(MEs_.at("Occupancy"));
111  MESet& meShape(MEs_.at("Shape"));
112  MESet& meSignalRate(MEs_.at("SignalRate"));
113 
114  int nReadouts[nDCC];
115  int maxpos[nDCC][EcalDataFrame::MAXSAMPLES];
116  for(unsigned iDCC(0); iDCC < nDCC; ++iDCC){
117  nReadouts[iDCC] = 0;
118  for(int i(0); i < EcalDataFrame::MAXSAMPLES; i++) maxpos[iDCC][i] = 0;
119  }
120 
121  for(typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
122  const DetId& id(digiItr->id());
123 
124  unsigned iDCC(dccId(id) - 1);
125 
126  if(!enable_[iDCC]) continue;
127  if(rtHalf(id) != rtHalf_[iDCC]) continue;
128 
129  meOccupancy.fill(id);
130 
131  ++nReadouts[iDCC];
132 
133  EcalDataFrame dataFrame(*digiItr);
134 
135  int iMax(-1);
136  int max(0);
137  int min(4096);
138  for (int i(0); i < EcalDataFrame::MAXSAMPLES; i++) {
139  int adc(dataFrame.sample(i).adc());
140  if(adc > max){
141  max = adc;
142  iMax = i;
143  }
144  if(adc < min) min = adc;
145  }
146  if(iMax >= 0 && max - min > 3) // normal RMS of pedestal is ~2.5
147  maxpos[iDCC][iMax] += 1;
148  }
149 
150  // signal existence check
151  bool enable(false);
152  bool laserOnExpected(emptyLS_ >= 0);
153 
154  unsigned iME(-1);
155 
156  for(int iDCC(0); iDCC < nDCC; ++iDCC){
157  if(nReadouts[iDCC] == 0){
158  enable_[iDCC] = false;
159  continue;
160  }
161 
162  int threshold(nReadouts[iDCC] / 3);
163  if(laserOnExpected) enable_[iDCC] = false;
164 
165  for(int i(0); i < EcalDataFrame::MAXSAMPLES; i++){
166  if(maxpos[iDCC][i] > threshold){
167  enable = true;
168  enable_[iDCC] = true;
169  break;
170  }
171  }
172 
173  if(iME != wlToME_[wavelength_[iDCC]]){
174  iME = wlToME_[wavelength_[iDCC]];
175  static_cast<MESetMulti&>(meSignalRate).use(iME);
176  }
177 
178  meSignalRate.fill(iDCC + 1, enable_[iDCC] ? 1 : 0);
179  }
180 
181  if(enable) emptyLS_ = 0;
182  else if(laserOnExpected) return;
183 
184  iME = -1;
185 
186  for(typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
187  const DetId& id(digiItr->id());
188 
189  unsigned iDCC(dccId(id) - 1);
190 
191  if(!enable_[iDCC]) continue;
192  if(rtHalf(id) != rtHalf_[iDCC]) continue;
193 
194  EcalDataFrame dataFrame(*digiItr);
195 
196  if(iME != wlToME_[wavelength_[iDCC]]){
197  iME = wlToME_[wavelength_[iDCC]];
198  static_cast<MESetMulti&>(meShape).use(iME);
199  }
200 
201  for(int iSample(0); iSample < EcalDataFrame::MAXSAMPLES; iSample++)
202  meShape.fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
203 
204  EcalPnDiodeDetId pnidA(pnForCrystal(id, 'a'));
205  EcalPnDiodeDetId pnidB(pnForCrystal(id, 'b'));
206  if(pnidA.null() || pnidB.null()) continue;
207  pnAmp_.insert(std::make_pair(pnidA.rawId(), 0.));
208  pnAmp_.insert(std::make_pair(pnidB.rawId(), 0.));
209  }
210  }
211 
212  void
214  {
215  MESet& mePNAmplitude(MEs_.at("PNAmplitude"));
216 
217  bool enable(false);
218  for(unsigned iDCC(0); iDCC < nDCC; ++iDCC)
219  enable |= enable_[iDCC];
220  if(!enable) return;
221 
222  unsigned iME(-1);
223 
224  for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
225  if(digiItr->sample(0).gainId() != 0 && digiItr->sample(0).gainId() != 1) continue;
226 
227  const EcalPnDiodeDetId& id(digiItr->id());
228 
229  std::map<uint32_t, float>::iterator ampItr(pnAmp_.find(id.rawId()));
230  if(ampItr == pnAmp_.end()) continue;
231 
232  unsigned iDCC(dccId(id) - 1);
233 
234  double pedestal(0.);
235  for(int iSample(0); iSample < 4; iSample++)
236  pedestal += digiItr->sample(iSample).adc();
237  pedestal /= 4.;
238 
239  double max(0.);
240  for(int iSample(0); iSample < 50; iSample++){
241  float amp(digiItr->sample(iSample).adc() - pedestal);
242  if(amp > max) max = amp;
243  }
244 
245  if(iME != wlToME_[wavelength_[iDCC]]){
246  iME = wlToME_[wavelength_[iDCC]];
247  static_cast<MESetMulti&>(mePNAmplitude).use(iME);
248  }
249 
250  mePNAmplitude.fill(id, max);
251 
252  ampItr->second = max;
253  }
254  }
255 
256  void
258  {
259  MESet& meAmplitude(MEs_.at("Amplitude"));
260  MESet& meAmplitudeSummary(MEs_.at("AmplitudeSummary"));
261  MESet& meTiming(MEs_.at("Timing"));
262  MESet& meAOverP(MEs_.at("AOverP"));
263 
264  using namespace std;
265 
266  bool enable(false);
267  for(unsigned iDCC(0); iDCC < nDCC; ++iDCC)
268  enable |= enable_[iDCC];
269  if(!enable) return;
270 
271  unsigned iME(-1);
272 
273  for(EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr){
274  const DetId& id(uhitItr->id());
275 
276  unsigned iDCC(dccId(id) - 1);
277 
278  if(!enable_[iDCC]) continue;
279  if(rtHalf(id) != rtHalf_[iDCC]) continue;
280 
281  if(iME != wlToME_[wavelength_[iDCC]]){
282  iME = wlToME_[wavelength_[iDCC]];
283  static_cast<MESetMulti&>(meAmplitude).use(iME);
284  static_cast<MESetMulti&>(meAmplitudeSummary).use(iME);
285  static_cast<MESetMulti&>(meTiming).use(iME);
286  static_cast<MESetMulti&>(meAOverP).use(iME);
287  }
288 
289  float amp(max((double)uhitItr->amplitude(), 0.));
290  float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
291 
292  meAmplitude.fill(id, amp);
293  meAmplitudeSummary.fill(id, amp);
294  meTiming.fill(id, jitter);
295 
296  float aop(0.);
297 
298  map<uint32_t, float>::iterator ampItrA(pnAmp_.find(pnForCrystal(id, 'a')));
299  map<uint32_t, float>::iterator ampItrB(pnAmp_.find(pnForCrystal(id, 'b')));
300  if(ampItrA == pnAmp_.end() && ampItrB == pnAmp_.end()) continue;
301  else if(ampItrB == pnAmp_.end()) aop = amp / ampItrA->second;
302  else if(ampItrA == pnAmp_.end()) aop = amp / ampItrB->second;
303  else aop = amp / (ampItrA->second + ampItrB->second) * 2.;
304 
305  meAOverP.fill(id, aop);
306  }
307  }
308 
310 }
311 
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
unsigned rtHalf_[nDCC]
Definition: LaserTask.h:41
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: LaserTask.cc:69
std::map< int, unsigned > wlToME_
Definition: LaserTask.h:37
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
bool filterRunType(short const *) override
Definition: LaserTask.cc:51
std::map< uint32_t, float > pnAmp_
Definition: LaserTask.h:42
void fill(DetId const &_id, double _xyw=1., double _yw=1., double _w=1.) override
Definition: MESetMulti.h:31
void runOnPnDigis(EcalPnDiodeDigiCollection const &)
Definition: LaserTask.cc:213
DEFINE_ECALDQM_WORKER(CalibrationSummaryClient)
void runOnDigis(DigiCollection const &)
Definition: LaserTask.cc:108
void runOnRawData(EcalRawDataCollection const &)
Definition: LaserTask.cc:87
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:40
const T & max(const T &a, const T &b)
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: LaserTask.cc:75
EcalPnDiodeDetId pnForCrystal(DetId const &, char)
unsigned rtHalf(DetId const &)
const_iterator end() const
Definition: DetId.h:18
void setParams(edm::ParameterSet const &) override
Definition: LaserTask.cc:22
bool null() const
is this a null id ?
Definition: DetId.h:45
MESetCollection MEs_
Definition: DQWorker.h:76
void runOnUncalibRecHits(EcalUncalibratedRecHitCollection const &)
Definition: LaserTask.cc:257
void addDependencies(DependencySet &) override
Definition: LaserTask.cc:41
bool enable_[nDCC]
Definition: LaserTask.h:39
void beginEvent(edm::Event const &, edm::EventSetup const &) override
Definition: LaserTask.cc:81
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:164
const_iterator begin() const
Definition: Run.h:41
int adc() const
get the ADC sample (12 bits)