CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LaserClient.cc
Go to the documentation of this file.
1 #include "../interface/LaserClient.h"
2 
4 
6 
7 #include <cmath>
8 
9 namespace ecaldqm {
10 
12  DQWorkerClient(_params, _paths, "LaserClient"),
13  laserWavelengths_(),
14  MGPAGainsPN_(),
15  minChannelEntries_(0),
16  expectedAmplitude_(),
17  amplitudeThreshold_(),
18  amplitudeRMSThreshold_(),
19  expectedTiming_(),
20  timingThreshold_(),
21  timingRMSThreshold_(),
22  expectedPNAmplitude_(),
23  pnAmplitudeThreshold_(),
24  pnAmplitudeRMSThreshold_(),
25  towerThreshold_()
26  {
27  using namespace std;
28 
29  edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
30  MGPAGainsPN_ = commonParams.getUntrackedParameter<vector<int> >("MGPAGainsPN");
31 
32  edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
33  laserWavelengths_ = taskParams.getUntrackedParameter<vector<int> >("laserWavelengths");
34  minChannelEntries_ = taskParams.getUntrackedParameter<int>("minChannelEntries");
35  expectedAmplitude_ = taskParams.getUntrackedParameter<vector<double> >("expectedAmplitude");
36  amplitudeThreshold_ = taskParams.getUntrackedParameter<vector<double> >("amplitudeThreshold");
37  amplitudeRMSThreshold_ = taskParams.getUntrackedParameter<vector<double> >("amplitudeRMSThreshold");
38  expectedTiming_ = taskParams.getUntrackedParameter<vector<double> >("expectedTiming");
39  timingThreshold_ = taskParams.getUntrackedParameter<vector<double> >("timingThreshold");
40  timingRMSThreshold_ = taskParams.getUntrackedParameter<vector<double> >("timingRMSThreshold");
41  expectedPNAmplitude_ = taskParams.getUntrackedParameter<vector<double> >("expectedPNAmplitude");
42  pnAmplitudeThreshold_ = taskParams.getUntrackedParameter<vector<double> >("pnAmplitudeThreshold");
43  pnAmplitudeRMSThreshold_ = taskParams.getUntrackedParameter<vector<double> >("pnAmplitudeRMSThreshold");
44  towerThreshold_ = taskParams.getUntrackedParameter<double>("towerThreshold");
45 
46  for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr)
47  if(*wlItr <= 0 || *wlItr >= 5) throw cms::Exception("InvalidConfiguration") << "Laser Wavelength" << endl;
48 
49  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr)
50  if(*gainItr != 1 && *gainItr != 16) throw cms::Exception("InvalidConfiguration") << "PN diode gain" << endl;
51 
52  if(expectedAmplitude_.size() != nWL ||
53  amplitudeThreshold_.size() != nWL ||
54  amplitudeRMSThreshold_.size() != nWL ||
55  expectedTiming_.size() != nWL ||
56  timingThreshold_.size() != nWL ||
57  timingRMSThreshold_.size() != nWL ||
58  expectedPNAmplitude_.size() != nWL * nPNGain ||
59  pnAmplitudeThreshold_.size() != nWL * nPNGain ||
61  throw cms::Exception("InvalidConfiguration") << "Size of quality cut parameter vectors" << endl;
62 
63  map<string, string> replacements;
64  stringstream ss;
65 
66  edm::ParameterSet const& sources(_params.getUntrackedParameterSet("sources"));
67  for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
68  ss.str("");
69  ss << *wlItr;
70  replacements["wl"] = ss.str();
71 
72  unsigned offset(*wlItr - 1);
73  source_(sAmplitude + offset, "LaserTask", LaserTask::kAmplitude + offset, sources);
74  source_(sTiming + offset, "LaserTask", LaserTask::kTiming + offset, sources);
75 
76  sources_[sAmplitude + offset]->name(replacements);
77  sources_[sTiming + offset]->name(replacements);
78 
79  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
80  ss.str("");
81  ss << *gainItr;
82  replacements["pngain"] = ss.str();
83 
84  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
85  source_(sPNAmplitude + offset, "LaserTask", LaserTask::kPNAmplitude, sources);
86 
87  sources_[sPNAmplitude + offset]->name(replacements);
88  }
89  }
90 
92 
93  for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
94  ss.str("");
95  ss << *wlItr;
96  replacements["wl"] = ss.str();
97 
98  unsigned offset(*wlItr - 1);
99 
100  MEs_[kQuality + offset]->name(replacements);
101  MEs_[kQualitySummary + offset]->name(replacements);
102  MEs_[kAmplitudeMean + offset]->name(replacements);
103  MEs_[kAmplitudeRMS + offset]->name(replacements);
104  MEs_[kTimingMean + offset]->name(replacements);
105  MEs_[kTimingRMS + offset]->name(replacements);
106  MEs_[kPNQualitySummary + offset]->name(replacements);
107 
108  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
109  ss.str("");
110  ss << *gainItr;
111  replacements["pngain"] = ss.str();
112 
113  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
114 
115  MEs_[kPNAmplitudeMean + offset]->name(replacements);
116  MEs_[kPNAmplitudeRMS + offset]->name(replacements);
117  }
118  }
119  }
120 
121  void
123  {
124  initialized_ = true;
125 
126  for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
127  unsigned offset(*wlItr - 1);
128 
129  initialized_ &= sources_[sAmplitude + offset]->retrieve();
130  initialized_ &= sources_[sTiming + offset]->retrieve();
131 
132  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
133  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
134 
135  initialized_ &= sources_[sPNAmplitude + offset]->retrieve();
136  }
137  }
138  }
139 
140  void
142  {
143  for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
144  unsigned offset(*wlItr - 1);
145 
146  MEs_[kQuality + offset]->book();
147  MEs_[kQualitySummary + offset]->book();
148  MEs_[kAmplitudeMean + offset]->book();
149  MEs_[kAmplitudeRMS + offset]->book();
150  MEs_[kTimingMean + offset]->book();
151  MEs_[kTimingRMS + offset]->book();
152  MEs_[kPNQualitySummary + offset]->book();
153 
154  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
155  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
156 
157  MEs_[kPNAmplitudeMean + offset]->book();
158  MEs_[kPNAmplitudeRMS + offset]->book();
159  }
160  }
161  }
162 
163  void
165  {
166  for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
167  unsigned offset(*wlItr - 1);
168  MEs_[kQuality + offset]->resetAll(-1.);
169  MEs_[kQualitySummary + offset]->resetAll(-1.);
170 
171  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
172  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
173  MEs_[kPNQualitySummary + offset]->resetAll(-1.);
174  }
175  }
176  }
177 
178  void
180  {
181  using namespace std;
182 
183  for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
184 
185  unsigned offset(*wlItr - 1);
186 
187  MEs_[kQuality + offset]->reset(2.);
188  MEs_[kQualitySummary + offset]->reset(2.);
189  MEs_[kPNQualitySummary + offset]->reset(2.);
190 
191  MEs_[kAmplitudeMean + offset]->reset();
192  MEs_[kAmplitudeRMS + offset]->reset();
193  MEs_[kTimingMean + offset]->reset();
194  MEs_[kTimingRMS + offset]->reset();
195 
196  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
197  unsigned suboffset((*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1));
198 
199  MEs_[kPNAmplitudeMean + suboffset]->reset();
200  MEs_[kPNAmplitudeRMS + suboffset]->reset();
201  }
202 
203  for(unsigned dccid(1); dccid <= 54; dccid++){
204 
205  for(unsigned tower(1); tower <= getNSuperCrystals(dccid); tower++){
206  std::vector<DetId> ids(getElectronicsMap()->dccTowerConstituents(dccid, tower));
207 
208  if(ids.size() == 0) continue;
209 
210  float nBad(0.);
211 
212  for(std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr){
213  float aEntries(sources_[sAmplitude + offset]->getBinEntries(*idItr));
214 
215  if(aEntries < minChannelEntries_) continue;
216 
217  float aMean(sources_[sAmplitude + offset]->getBinContent(*idItr));
218  float aRms(sources_[sAmplitude + offset]->getBinError(*idItr) * std::sqrt(aEntries));
219 
220  MEs_[kAmplitudeMean + offset]->fill(*idItr, aMean);
221  MEs_[kAmplitudeRMS + offset]->fill(*idItr, aRms);
222 
223  float tEntries(sources_[sTiming + offset]->getBinEntries(*idItr));
224 
225  if(tEntries < minChannelEntries_) continue;
226 
227  float tMean(sources_[sTiming + offset]->getBinContent(*idItr));
228  float tRms(sources_[sTiming + offset]->getBinError(*idItr) * std::sqrt(tEntries));
229 
230  MEs_[kTimingMean + offset]->fill(*idItr, tMean);
231  MEs_[kTimingRMS + offset]->fill(*idItr, tRms);
232 
233  if(std::abs(aMean - expectedAmplitude_[offset]) > amplitudeThreshold_[offset] || aRms > amplitudeRMSThreshold_[offset] ||
234  std::abs(tMean - expectedTiming_[offset]) > timingThreshold_[offset] || tRms > timingRMSThreshold_[offset]){
235  MEs_[kQuality + offset]->setBinContent(*idItr, 0.);
236  nBad += 1.;
237  }
238  else
239  MEs_[kQuality + offset]->setBinContent(*idItr, 1.);
240  }
241 
242  if(nBad / ids.size() > towerThreshold_)
243  MEs_[kQualitySummary + offset]->setBinContent(ids[0], 0.);
244  else
245  MEs_[kQualitySummary + offset]->setBinContent(ids[0], 1.);
246  }
247 
248  unsigned subdet;
249  if(dccid <= 9 || dccid >= 46) subdet = EcalEndcap;
250  else subdet = EcalBarrel;
251 
252  for(unsigned pn(1); pn <= 10; pn++){
253  EcalPnDiodeDetId pnid(subdet, dccid, pn);
254 
255  bool bad(false);
256  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
257  unsigned suboffset((*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1));
258 
259  float pEntries(sources_[sPNAmplitude + suboffset]->getBinEntries(pnid));
260 
261  if(pEntries < minChannelEntries_) continue;
262 
263  float pMean(sources_[sPNAmplitude + suboffset]->getBinContent(pnid));
264  float pRms(sources_[sPNAmplitude + suboffset]->getBinError(pnid) * std::sqrt(pEntries));
265 
266  MEs_[kPNAmplitudeMean + suboffset]->fill(pnid, pMean);
267  MEs_[kPNAmplitudeRMS + suboffset]->fill(pnid, pRms);
268 
269  if(std::abs(pMean - expectedPNAmplitude_[suboffset]) > pnAmplitudeThreshold_[suboffset] || pRms > pnAmplitudeRMSThreshold_[suboffset])
270  bad = true;
271  }
272 
273  if(bad)
274  MEs_[kPNQualitySummary + offset]->setBinContent(pnid, 0.);
275  else
276  MEs_[kPNQualitySummary + offset]->setBinContent(pnid, 1.);
277  }
278 
279  }
280  }
281  }
282 
283  /*static*/
284  void
285  LaserClient::setMEData(std::vector<MEData>& _data)
286  {
288 
289  for(unsigned iWL(0); iWL < nWL; iWL++){
291 
292  axis.nbins = 100;
293  axis.low = 0.;
294  axis.high = 4096.;
295  _data[kAmplitudeMean + iWL] = MEData("AmplitudeMean", BinService::kSM, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
296 
297  axis.low = 0.;
298  axis.high = 400.;
300 
301  axis.low = 3.5;
302  axis.high = 5.5;
304 
305  axis.low = 0.;
306  axis.high = 0.5;
308 
311 
312  for(unsigned iPNGain(0); iPNGain < nPNGain; iPNGain++){
313  unsigned offset(iWL * nPNGain + iPNGain);
314 
315  axis.low = 0.;
316  axis.high = 4096.;
318 
319  axis.low = 0.;
320  axis.high = 200.;
322  }
323  }
324  }
325 
327 }
const EcalElectronicsMapping * getElectronicsMap()
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: LaserClient.cc:164
std::vector< int > laserWavelengths_
Definition: LaserClient.h:51
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< double > expectedAmplitude_
Definition: LaserClient.h:55
void source_(unsigned, std::string const &, unsigned, edm::ParameterSet const &)
std::vector< double > timingThreshold_
Definition: LaserClient.h:59
int bad(Items const &cont)
std::vector< double > expectedTiming_
Definition: LaserClient.h:58
ParameterSet const & getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
T sqrt(T t)
Definition: SSEVec.h:46
unsigned int offset(bool)
std::vector< MESet * > MEs_
Definition: DQWorker.h:56
unsigned getNSuperCrystals(unsigned)
std::vector< double > pnAmplitudeThreshold_
Definition: LaserClient.h:62
LaserClient(const edm::ParameterSet &, const edm::ParameterSet &)
Definition: LaserClient.cc:11
std::vector< double > expectedPNAmplitude_
Definition: LaserClient.h:61
std::vector< double > amplitudeThreshold_
Definition: LaserClient.h:56
std::vector< MESet const * > sources_
std::vector< double > amplitudeRMSThreshold_
Definition: LaserClient.h:57
std::vector< double > timingRMSThreshold_
Definition: LaserClient.h:60
DEFINE_ECALDQM_WORKER(CertificationClient)
std::vector< int > MGPAGainsPN_
Definition: LaserClient.h:52
static void setMEData(std::vector< MEData > &)
Definition: LaserClient.cc:285
std::string name_
Definition: DQWorker.h:55
Definition: Run.h:33
std::vector< double > pnAmplitudeRMSThreshold_
Definition: LaserClient.h:63