CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SelectiveReadoutTask.cc
Go to the documentation of this file.
1 #include "../interface/SelectiveReadoutTask.h"
2 
5 
9 
12 
14 
17 
18 namespace ecaldqm {
19 
21  DQWorkerTask(_params, _paths, "SelectiveReadoutTask"),
22  useCondDb_(false),
23  iFirstSample_(0),
24  channelStatus_(0),
25  ebSRFs_(0),
26  eeSRFs_(0),
27  frFlaggedTowers_(),
28  zsFlaggedTowers_()
29  {
31  (0x1 << kRun) |
32  (0x1 << kSource) |
33  (0x1 << kEcalRawData) |
34  (0x1 << kEBSrFlag) |
35  (0x1 << kEESrFlag) |
36  (0x1 << kEBDigi) |
37  (0x1 << kEEDigi);
38 
39  dependencies_.push_back(std::pair<Collections, Collections>(kEBDigi, kEcalRawData));
40  dependencies_.push_back(std::pair<Collections, Collections>(kEEDigi, kEcalRawData));
41 
42  edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
43 
44  useCondDb_ = taskParams.getUntrackedParameter<bool>("useCondDb");
45  iFirstSample_ = taskParams.getUntrackedParameter<int>("DCCZS1stSample");
46 
47  std::vector<double> normWeights(taskParams.getUntrackedParameter<std::vector<double> >("ZSFIRWeights", std::vector<double>(0)));
48  if(normWeights.size()) setFIRWeights_(normWeights);
49  }
50 
52  {
53  }
54 
55  void
57  {
58  using namespace std;
59 
60  if(useCondDb_){
62  _es.get<EcalSRSettingsRcd>().get(hSr);
63 
64  vector<vector<float> > weights(hSr->dccNormalizedWeights_);
65  if(weights.size() == 1){
66  vector<double> normWeights;
67  for(vector<float>::iterator it(weights[0].begin()); it != weights[0].end(); it++)
68  normWeights.push_back(*it);
69 
70  setFIRWeights_(normWeights);
71  }
72  else edm::LogWarning("EcalDQM") << "SelectiveReadoutTask: DCC weight set is not exactly 1.";
73  }
74 
76  _es.get<EcalChannelStatusRcd>().get(chSHndl);
77  channelStatus_ = chSHndl.product();
78  if(!channelStatus_)
79  throw cms::Exception("EventSetup") << "EcalChannelStatusRcd";
80  }
81 
82  void
84  {
85  for(int iDCC(0); iDCC < 54; iDCC++) feStatus_[iDCC].clear();
86  frFlaggedTowers_.clear();
87  zsFlaggedTowers_.clear();
88  }
89 
90  void
92  {
93  float ebSize(0.), eeSize(0.);
94 
95  // DCC event size
96  for(unsigned iFED(601); iFED <= 654; iFED++){
97  float size(_fedRaw.FEDData(iFED).size() / 1024.);
98  MEs_[kDCCSize]->fill(iFED - 600, size);
99  if(iFED - 601 <= kEEmHigh || iFED - 601 >= kEEpLow) eeSize += size;
100  else ebSize += size;
101  }
102 
103  MEs_[kEventSize]->fill(unsigned(BinService::kEE) + 1, eeSize / 18.);
104  MEs_[kEventSize]->fill(unsigned(BinService::kEB) + 1, ebSize / 36.);
105  }
106 
107  void
109  {
110  for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
111  const std::vector<short> &feStatus(dcchItr->getFEStatus());
112  feStatus_[dcchItr->id() - 1].assign(feStatus.begin(), feStatus.end());
113  }
114  }
115 
116  void
118  {
119  float nFR(0.);
120 
121  ebSRFs_ = &_srfs;
122 
123  for(EBSrFlagCollection::const_iterator srfItr(_srfs.begin()); srfItr != _srfs.end(); ++srfItr)
124  runOnSrFlag_(srfItr->id(), srfItr->value(), nFR);
125 
126  MEs_[kFullReadout]->fill(unsigned(BinService::kEB) + 1, nFR);
127  }
128 
129  void
131  {
132  float nFR(0.);
133 
134  eeSRFs_ = &_srfs;
135 
136  for(EESrFlagCollection::const_iterator srfItr(_srfs.begin()); srfItr != _srfs.end(); ++srfItr)
137  runOnSrFlag_(srfItr->id(), srfItr->value(), nFR);
138 
139  MEs_[kFullReadout]->fill(unsigned(BinService::kEE) + 1, nFR);
140  }
141 
142  void
143  SelectiveReadoutTask::runOnSrFlag_(const DetId &_id, int _flag, float& nFR)
144  {
145  uint32_t rawId(_id.rawId());
146  int dccid(dccId(_id));
147  int towerid(towerId(_id));
148 
149  MEs_[kFlagCounterMap]->fill(_id);
150 
151  short status(feStatus_[dccid - 1].size() ? feStatus_[dccid - 1][towerid - 1] : 0); // check: towerid == feId??
152 
153  switch(_flag & ~EcalSrFlag::SRF_FORCED_MASK){
155  MEs_[kFullReadoutMap]->fill(_id);
156  nFR += 1.;
157  if(status != Disabled) frFlaggedTowers_.insert(rawId); // will be used in Digi loop
158  break;
159  case EcalSrFlag::SRF_ZS1:
160  MEs_[kZS1Map]->fill(_id);
161  // fallthrough
162  case EcalSrFlag::SRF_ZS2:
163  MEs_[kZSMap]->fill(_id);
164  if(status != Disabled) zsFlaggedTowers_.insert(rawId);
165  break;
166  default:
167  break;
168  }
169 
170  if(_flag & EcalSrFlag::SRF_FORCED_MASK)
171  MEs_[kRUForcedMap]->fill(_id);
172  }
173 
174  void
176  {
177  using namespace std;
178 
179  map<uint32_t, pair<int, int> > flagAndSizeMap;
180  map<uint32_t, pair<int, int> >::iterator fasItr;
181 
182  int nHighInt(0), nLowInt(0); // one or two entries will be empty
183 
184  for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
185 
186  DetId id(digiItr->id());
187 
188  pair<int, int> *flagAndSize(0);
189 
190  if(_collection == kEBDigi){
191  EcalTrigTowerDetId ttid(EBDetId(id).tower());
192  uint32_t rawId(ttid.rawId());
193 
194  fasItr = flagAndSizeMap.find(rawId);
195 
196  if(fasItr == flagAndSizeMap.end()){
197  flagAndSize = &(flagAndSizeMap[rawId]);
198 
200  if(srItr != ebSRFs_->end()) flagAndSize->first = srItr->value();
201  else flagAndSize->first = -1;
202  }else{
203  flagAndSize = &(fasItr->second);
204  }
205  }else{
206  EcalScDetId scid(EEDetId(id).sc());
207  uint32_t rawId(scid.rawId());
208 
209  fasItr = flagAndSizeMap.find(rawId);
210 
211  if(fasItr == flagAndSizeMap.end()){
212  flagAndSize = &(flagAndSizeMap[rawId]);
213 
215  if(srItr != eeSRFs_->end()) flagAndSize->first = srItr->value();
216  else flagAndSize->first = -1;
217  }else{
218  flagAndSize = &(fasItr->second);
219  }
220  }
221 
222  if(flagAndSize->first < 0) continue;
223 
224  flagAndSize->second += 1;
225 
226  // SR filter output calculation
227 
228  EcalDataFrame frame(*digiItr);
229 
230  int ZSFIRValue(0); // output
231 
232  bool gain12saturated(false);
233  const int gain12(0x01);
234 
235  for(int iWeight(0); iWeight < nFIRTaps; ++iWeight){
236 
237  int iSample(iFirstSample_ + iWeight - 1);
238 
239  if(iSample >= 0 && iSample < frame.size()){
240  EcalMGPASample sample(frame[iSample]);
241  if(sample.gainId() != gain12){
242  gain12saturated = true;
243  break;
244  }
245  ZSFIRValue += sample.adc() * ZSFIRWeights_[iWeight];
246  }else{
247  edm::LogWarning("EcalDQM") << "SelectiveReadoutTask: Not enough samples in data frame or 'ecalDccZs1stSample' module parameter is not valid";
248  }
249 
250  }
251 
252  if(gain12saturated) ZSFIRValue = std::numeric_limits<int>::max();
253  else ZSFIRValue /= (0x1 << 8); //discards the 8 LSBs
254 
255  //ZS passed if weighted sum above ZS threshold or if
256  //one sample has a lower gain than gain 12 (that is gain 12 output
257  //is saturated)
258 
259  bool highInterest((flagAndSize->first & ~EcalSrFlag::SRF_FORCED_MASK) == EcalSrFlag::SRF_FULL);
260 
261  if(highInterest){
262  MEs_[kHighIntOutput]->fill(id, ZSFIRValue);
263  nHighInt += 1;
264  }else{
265  MEs_[kLowIntOutput]->fill(id, ZSFIRValue);
266  nLowInt += 1;
267  }
268  }
269 
270  unsigned iSubdet(_collection == kEBDigi ? BinService::kEB : BinService::kEE);
271  float denom(_collection == kEBDigi ? 36. : 18.);
272 
273  float highIntPayload(nHighInt * bytesPerCrystal / 1024. / denom);
274  MEs_[kHighIntPayload]->fill(iSubdet + 1, highIntPayload);
275 
276  float lowIntPayload(nLowInt * bytesPerCrystal / 1024. / denom);
277  MEs_[kLowIntPayload]->fill(iSubdet + 1, lowIntPayload);
278 
279  // Check for "ZS-flagged but readout" and "FR-flagged but dropped" towers
280 
281  float nZSFullReadout(0.);
282  for(unsigned iTower(0); iTower < EcalTrigTowerDetId::kEBTotalTowers + EcalScDetId::kSizeForDenseIndexing; iTower++){
283  DetId id;
286 
287  fasItr = flagAndSizeMap.find(id.rawId());
288 
289  float towerSize(0.);
290  if(fasItr != flagAndSizeMap.end()) towerSize = fasItr->second.second * bytesPerCrystal;
291 
292  MEs_[kTowerSize]->fill(id, towerSize);
293 
294  if(fasItr == flagAndSizeMap.end() || fasItr->second.first < 0) continue; // not read out || no flag set
295 
296  bool ruFullyReadout(unsigned(fasItr->second.second) == getElectronicsMap()->dccTowerConstituents(dccId(id), towerId(id)).size());
297 
298  if(ruFullyReadout && zsFlaggedTowers_.find(id.rawId()) != zsFlaggedTowers_.end()){
299  MEs_[kZSFullReadoutMap]->fill(id);
300  nZSFullReadout += 1.;
301  }
302 
303  // we will later use the list of FR flagged towers that do not have data
304  // if the tower is in flagAndSizeMap then there is data; remove it from the list
305  if(frFlaggedTowers_.find(id.rawId()) != frFlaggedTowers_.end()) frFlaggedTowers_.erase(id.rawId());
306  }
307 
308  MEs_[kZSFullReadout]->fill(iSubdet + 1, nZSFullReadout);
309 
310  float nFRDropped(0.);
311 
312  for(set<uint32_t>::iterator frItr(frFlaggedTowers_.begin()); frItr != frFlaggedTowers_.end(); ++frItr){
313  DetId id(*frItr);
314 
315  MEs_[kFRDroppedMap]->fill(id);
316  nFRDropped += 1.;
317  }
318 
319  MEs_[kFRDropped]->fill(iSubdet + 1, nFRDropped);
320 
321  }
322 
323  void
324  SelectiveReadoutTask::setFIRWeights_(const std::vector<double> &_normWeights)
325  {
326  if(_normWeights.size() < nFIRTaps)
327  throw cms::Exception("InvalidConfiguration") << "weightsForZsFIR" << std::endl;
328 
329  bool notNormalized(false), notInt(false);
330  for(std::vector<double>::const_iterator it(_normWeights.begin()); it != _normWeights.end(); ++it){
331  if(*it > 1.) notNormalized = true;
332  if((int)(*it) != *it) notInt = true;
333  }
334  if(notInt && notNormalized){
335  throw cms::Exception("InvalidConfiguration")
336  << "weigtsForZsFIR paramater values are not valid: they "
337  << "must either be integer and uses the hardware representation "
338  << "of the weights or less or equal than 1 and used the normalized "
339  << "representation.";
340  }
341 
342  ZSFIRWeights_.clear();
343  ZSFIRWeights_.resize(_normWeights.size());
344 
345  if(notNormalized){
346  for(unsigned i(0); i< ZSFIRWeights_.size(); ++i)
347  ZSFIRWeights_[i] = (int)_normWeights[i];
348  }else{
349  const unsigned maxWeight(0xEFF); //weights coded on 11+1 signed bits
350  for(unsigned i(0); i < ZSFIRWeights_.size(); ++i){
351  ZSFIRWeights_[i] = lround(_normWeights[i] * (1<<10));
352  if(abs(ZSFIRWeights_[i]) > (int)maxWeight) //overflow
353  ZSFIRWeights_[i] = ZSFIRWeights_[i] < 0 ? -maxWeight : maxWeight;
354  }
355  }
356  }
357 
358  /*static*/
359  void
360  SelectiveReadoutTask::setMEData(std::vector<MEData>& _data)
361  {
363 
364  axis.low = 0.;
365  axis.high = 50.;
367 
368  axis.title = "event size (kB)";
369  axis.nbins = 78; // 10 zero-bins + 68
370  axis.edges = new double[79];
371  float fullTTSize(0.608);
372  for(int i(0); i <= 10; i++) axis.edges[i] = fullTTSize / 10. * i;
373  for(int i(11); i < 79; i++) axis.edges[i] = fullTTSize * (i - 10);
375  delete [] axis.edges;
376  axis.edges = 0;
377 
378  axis.nbins = 100;
379  axis.low = 0.;
380  axis.high = 3.;
381  axis.title = "event size (kB)";
385 
386  axis.nbins = 100;
387  axis.low = 0.;
388  axis.high = 200.;
389  axis.title = "number of towers";
394 
395  axis.nbins = 20;
396  axis.low = 0.;
397  axis.high = 20.;
398  axis.title = "number of towers";
403 
404  axis.nbins = 100;
405  axis.low = 0.;
406  axis.high = 3.;
407  axis.title = "event size (kB)";
410 
411  axis.nbins = 100;
412  axis.low = -60.;
413  axis.high = 60.;
414  axis.title = "ADC counts*4";
417  }
418 
420 }
421 
422 
int i
Definition: DBlmapReader.cc:9
std::vector< std::pair< Collections, Collections > > dependencies_
Definition: DQWorkerTask.h:31
void beginEvent(const edm::Event &, const edm::EventSetup &)
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
const EcalElectronicsMapping * getElectronicsMap()
void beginRun(const edm::Run &, const edm::EventSetup &)
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:93
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
static const int SRF_ZS2
Definition: EcalSrFlag.h:22
const EBSrFlagCollection * ebSRFs_
static const int SRF_FORCED_MASK
Definition: EcalSrFlag.h:30
std::vector< T >::const_iterator const_iterator
#define abs(x)
Definition: mlp_lapack.h:159
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:119
const EcalChannelStatus * channelStatus_
unsigned dccId(const DetId &)
const EESrFlagCollection * eeSRFs_
const_iterator begin() const
void runOnDigis(const EcalDigiCollection &, Collections)
int gainId() const
get the gainId (2 bits)
std::set< uint32_t > zsFlaggedTowers_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
int size() const
Definition: EcalDataFrame.h:27
SelectiveReadoutTask(const edm::ParameterSet &, const edm::ParameterSet &)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
unsigned towerId(const DetId &)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const T & max(const T &a, const T &b)
ParameterSet const & getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
void runOnEESrFlags(const EESrFlagCollection &)
std::set< uint32_t > frFlaggedTowers_
static const int SRF_FULL
Definition: EcalSrFlag.h:25
void runOnSource(const FEDRawDataCollection &)
static const int SRF_ZS1
Definition: EcalSrFlag.h:19
static void setMEData(std::vector< MEData > &)
void setFIRWeights_(const std::vector< double > &)
const_iterator end() const
Definition: DetId.h:20
std::vector< MESet * > MEs_
Definition: DQWorker.h:56
void runOnRawData(const EcalRawDataCollection &)
std::vector< short > feStatus_[54]
const T & get() const
Definition: EventSetup.h:55
const_iterator end() const
void runOnEBSrFlags(const EBSrFlagCollection &)
iterator find(key_type k)
#define begin
Definition: vmac.h:31
tuple status
Definition: ntuplemaker.py:245
tuple size
Write out results.
std::string name_
Definition: DQWorker.h:55
const_iterator begin() const
void runOnSrFlag_(const DetId &, int, float &)
Definition: Run.h:33
int adc() const
get the ADC sample (12 bits)