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