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 
5 
7 
8 namespace ecaldqm {
9 
10  LedTask::LedTask(const edm::ParameterSet &_params, const edm::ParameterSet& _paths) :
11  DQWorkerTask(_params, _paths, "LedTask"),
12  ledWavelengths_(),
13  MGPAGainsPN_(),
14  pnAmp_()
15  {
16  using namespace std;
17 
19  (0x1 << kEcalRawData) |
20  (0x1 << kEEDigi) |
21  (0x1 << kPnDiodeDigi) |
22  (0x1 << kEBUncalibRecHit) |
23  (0x1 << kEEUncalibRecHit);
24 
25  edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
26  MGPAGainsPN_ = commonParams.getUntrackedParameter<std::vector<int> >("MGPAGainsPN");
27 
28  edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
29  ledWavelengths_ = taskParams.getUntrackedParameter<std::vector<int> >("ledWavelengths");
30 
31  for(std::vector<int>::iterator wlItr(ledWavelengths_.begin()); wlItr != ledWavelengths_.end(); ++wlItr)
32  if(*wlItr != 1 && *wlItr != 2) throw cms::Exception("InvalidConfiguration") << "Led Wavelength" << std::endl;
33 
34  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr)
35  if(*gainItr != 1 && *gainItr != 16) throw cms::Exception("InvalidConfiguration") << "PN diode gain" << std::endl;
36 
37  map<string, string> replacements;
38  stringstream ss;
39 
40  for(vector<int>::iterator wlItr(ledWavelengths_.begin()); wlItr != ledWavelengths_.end(); ++wlItr){
41  ss.str("");
42  ss << *wlItr;
43  replacements["wl"] = ss.str();
44 
45  unsigned offset(*wlItr - 1);
46 
47  MEs_[kAmplitudeSummary + offset]->name(replacements);
48  MEs_[kAmplitude + offset]->name(replacements);
49  MEs_[kOccupancy + offset]->name(replacements);
50  MEs_[kShape + offset]->name(replacements);
51  MEs_[kTiming + offset]->name(replacements);
52  MEs_[kAOverP + offset]->name(replacements);
53 
54  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
55  ss.str("");
56  ss << *gainItr;
57  replacements["pngain"] = ss.str();
58 
59  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
60 
61  MEs_[kPNAmplitude + offset]->name(replacements);
62  }
63  }
64  }
65 
67  {
68  }
69 
70  void
72  {
73  for(std::vector<int>::iterator wlItr(ledWavelengths_.begin()); wlItr != ledWavelengths_.end(); ++wlItr){
74  unsigned offset(*wlItr - 1);
75 
76  MEs_[kAmplitudeSummary + offset]->book();
77  MEs_[kAmplitude + offset]->book();
78  MEs_[kOccupancy + offset]->book();
79  MEs_[kTiming + offset]->book();
80  MEs_[kShape + offset]->book();
81  MEs_[kAOverP + offset]->book();
82 
83  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
84  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
85 
86  MEs_[kPNAmplitude + offset]->book();
87  }
88  }
89 
90  MEs_[kPNOccupancy]->book();
91  }
92 
93  void
95  {
96  for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
97  enable_[iDCC] = false;
98  wavelength_[iDCC] = -1;
99  }
100  pnAmp_.clear();
101  }
102 
103  void
105  {
106  for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
107  enable_[iDCC] = false;
108  wavelength_[iDCC] = -1;
109  }
110  pnAmp_.clear();
111  }
112 
113  bool
114  LedTask::filterRunType(const std::vector<short>& _runType)
115  {
116  bool enable(false);
117 
118  for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
119  if(_runType[iDCC] == EcalDCCHeaderBlock::LED_STD ||
120  _runType[iDCC] == EcalDCCHeaderBlock::LED_GAP){
121  enable = true;
122  enable_[iDCC] = true;
123  }
124  }
125 
126  return enable;
127  }
128 
129  void
131  {
132  for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
133  int iDCC(dcchItr->id() - 1);
134 
135  if(!enable_[iDCC]) continue;
136 
137  wavelength_[iDCC] = dcchItr->getEventSettings().wavelength + 1;
138 
139  if(std::find(ledWavelengths_.begin(), ledWavelengths_.end(), wavelength_[iDCC]) == ledWavelengths_.end()) enable_[iDCC] = false;
140  }
141  }
142 
143  void
145  {
146  for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
147  const DetId& id(digiItr->id());
148 
149  int iDCC(dccId(id) - 1);
150 
151  if(!enable_[iDCC]) continue;
152 
153  unsigned offset(-1);
154  switch(wavelength_[iDCC]){
155  case 1: offset = 0; break;
156  case 3: offset = 1; break;
157  default: continue;
158  }
159 
160  MEs_[kOccupancy + offset]->fill(id);
161 
162  // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
163  EcalDataFrame dataFrame(*digiItr);
164 
165  for(int iSample(0); iSample < 10; iSample++)
166  MEs_[kShape + offset]->fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
167  }
168  }
169 
170  void
172  {
173  for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
174  const EcalPnDiodeDetId& id(digiItr->id());
175 
176  int iDCC(dccId(id) - 1);
177 
178  if(!enable_[iDCC]) continue;
179 
180  MEs_[kPNOccupancy]->fill(id);
181 
182  float pedestal(0.);
183  for(int iSample(0); iSample < 4; iSample++)
184  pedestal += digiItr->sample(iSample).adc();
185  pedestal /= 4.;
186 
187  float max(0.);
188  for(int iSample(0); iSample < 50; iSample++){
189  EcalFEMSample sample(digiItr->sample(iSample));
190 
191  float amp(digiItr->sample(iSample).adc() - pedestal);
192 
193  if(amp > max) max = amp;
194  }
195 
196  int gain(digiItr->sample(0).gainId() == 0 ? 1 : 16);
197  max *= (16. / gain);
198 
199  unsigned offset(-1);
200  switch(wavelength_[iDCC]){
201  case 1: offset = (gain == 1 ? 0 : 1); break;
202  case 3: offset = nPNGain + (gain == 1 ? 0 : 1); break;
203  default: continue;
204  }
205 
206  MEs_[kPNAmplitude + offset]->fill(id, max);
207 
208  if(pnAmp_.find(iDCC) == pnAmp_.end()) pnAmp_[iDCC].resize(10);
209  pnAmp_[iDCC][id.iPnId() - 1] = max;
210  }
211  }
212 
213  void
215  {
216  using namespace std;
217 
218  for(EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr){
219  EEDetId id(uhitItr->id());
220 
221  int iDCC(dccId(id) - 1);
222 
223  if(!enable_[iDCC]) continue;
224 
225  unsigned offset(-1);
226  switch(wavelength_[iDCC]){
227  case 1: offset = 0; break;
228  case 3: offset = 1; break;
229  default: continue;
230  }
231 
232  float amp(max((double)uhitItr->amplitude(), 0.));
233  float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
234 
235  MEs_[kAmplitudeSummary + offset]->fill(id, amp);
236  MEs_[kAmplitude + offset]->fill(id, amp);
237  MEs_[kTiming + offset]->fill(id, jitter);
238 
239  if(pnAmp_.find(iDCC) == pnAmp_.end()) continue;
240 
241  float aop(0.);
242  float pn0(0.), pn1(0.);
243 
244  EcalScDetId scid(id.sc());
245 
246  int dee(MEEEGeom::dee(scid.ix(), scid.iy(), scid.zside()));
247  int lmmod(MEEEGeom::lmmod(scid.ix(), scid.iy()));
248  pair<int, int> pnPair(MEEEGeom::pn(dee, lmmod));
249 
250  int pnAFED(getEEPnDCC(dee, 0)), pnBFED(getEEPnDCC(dee, 1));
251 
252  pn0 = pnAmp_[pnAFED][pnPair.first];
253  pn1 = pnAmp_[pnBFED][pnPair.second];
254 
255  if(pn0 < 10 && pn1 > 10){
256  aop = amp / pn1;
257  }else if(pn0 > 10 && pn1 < 10){
258  aop = amp / pn0;
259  }else if(pn0 + pn1 > 1){
260  aop = amp / (0.5 * (pn0 + pn1));
261  }else{
262  aop = 1000.;
263  }
264 
265  MEs_[kAOverP + offset]->fill(id, aop);
266  }
267  }
268 
269  /*static*/
270  void
271  LedTask::setMEData(std::vector<MEData>& _data)
272  {
274  axis.nbins = 10;
275  axis.low = 0.;
276  axis.high = 10.;
277 
278  for(unsigned iWL(0); iWL < nWL; iWL++){
285 
286  for(unsigned iPNGain(0); iPNGain < nPNGain; iPNGain++){
287  unsigned offset(iWL * nPNGain + iPNGain);
289  }
290  }
292  }
293 
295 }
static int lmmod(SuperCrysCoord iX, SuperCrysCoord iY)
Definition: MEEEGeom.cc:94
string fill
Definition: lumiContext.py:319
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: LedTask.cc:94
int wavelength_[BinService::nDCC]
Definition: LedTask.h:55
unsigned getEEPnDCC(unsigned, unsigned)
void bookMEs() override
Definition: LedTask.cc:71
std::vector< EcalDCCHeaderBlock >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
void runOnRawData(const EcalRawDataCollection &)
Definition: LedTask.cc:130
unsigned dccId(const DetId &)
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
const_iterator begin() const
std::map< int, std::vector< float > > pnAmp_
Definition: LedTask.h:56
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< int > ledWavelengths_
Definition: LedTask.h:51
static std::pair< int, int > pn(int dee, int ilmod)
Definition: MEEEGeom.cc:615
const T & max(const T &a, const T &b)
int ix() const
Definition: EcalScDetId.h:71
void runOnUncalibRecHits(const EcalUncalibratedRecHitCollection &)
Definition: LedTask.cc:214
void endEvent(const edm::Event &, const edm::EventSetup &) override
Definition: LedTask.cc:104
static void setMEData(std::vector< MEData > &)
Definition: LedTask.cc:271
unsigned int offset(bool)
int iy() const
Definition: EcalScDetId.h:77
bool filterRunType(const std::vector< short > &) override
Definition: LedTask.cc:114
const_iterator end() const
Definition: DetId.h:18
std::vector< MESet * > MEs_
Definition: DQWorker.h:56
LedTask(const edm::ParameterSet &, const edm::ParameterSet &)
Definition: LedTask.cc:10
int zside() const
Definition: EcalScDetId.h:65
const_iterator end() const
void runOnPnDigis(const EcalPnDiodeDigiCollection &)
Definition: LedTask.cc:171
static int dee(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:284
DEFINE_ECALDQM_WORKER(CertificationClient)
bool enable_[BinService::nDCC]
Definition: LedTask.h:54
void runOnDigis(const EcalDigiCollection &)
Definition: LedTask.cc:144
std::vector< int > MGPAGainsPN_
Definition: LedTask.h:52
std::string name_
Definition: DQWorker.h:55
const_iterator begin() const
Definition: Run.h:41
int adc() const
get the ADC sample (12 bits)