CMS 3D CMS Logo

SelectiveReadoutTask.cc
Go to the documentation of this file.
2 
5 
9 
12 
14 
17 
18 namespace ecaldqm {
19 
21  : DQWorkerTask(),
22  useCondDb_(false),
23  iFirstSample_(0),
24  ZSFIRWeights_(nFIRTaps, 0.),
25  suppressed_(),
26  flags_(nRU, -1) {}
27 
29  useCondDb_ = _params.getUntrackedParameter<bool>("useCondDb");
30  iFirstSample_ = _params.getUntrackedParameter<int>("DCCZS1stSample");
31 
32  if (!useCondDb_) {
33  std::vector<double> normWeights(_params.getUntrackedParameter<std::vector<double> >("ZSFIRWeights"));
34  setFIRWeights_(normWeights);
35  }
36  }
37 
41  }
42 
44  using namespace std;
45 
46  if (useCondDb_) {
48  _es.get<EcalSRSettingsRcd>().get(hSr);
49 
50  vector<vector<float> > weights(hSr->dccNormalizedWeights_);
51  if (weights.size() == 1) {
52  vector<double> normWeights;
53  for (vector<float>::iterator it(weights[0].begin()); it != weights[0].end(); it++)
54  normWeights.push_back(*it);
55 
56  setFIRWeights_(normWeights);
57  } else
58  edm::LogWarning("EcalDQM") << "SelectiveReadoutTask: DCC weight set is not exactly 1.";
59  }
60  }
61 
63  flags_.assign(nRU, -1);
64  suppressed_.clear();
65  }
66 
68  MESet& meDCCSize(MEs_.at("DCCSize"));
69  MESet& meDCCSizeProf(MEs_.at("DCCSizeProf"));
70  MESet& meEventSize(MEs_.at("EventSize"));
71 
72  float ebSize(0.), eemSize(0.), eepSize(0.);
73 
74  // DCC event size
75  for (int iFED(601); iFED <= 654; iFED++) {
76  float size(_fedRaw.FEDData(iFED).size() / 1024.);
77  meDCCSize.fill(iFED - 600, size);
78  meDCCSizeProf.fill(iFED - 600, size);
79  if (iFED - 601 <= kEEmHigh)
80  eemSize += size;
81  else if (iFED - 601 >= kEEpLow)
82  eepSize += size;
83  else
84  ebSize += size;
85  }
86 
87  meEventSize.fill(-EcalEndcap, eemSize / 9.);
88  meEventSize.fill(EcalEndcap, eepSize / 9.);
89  meEventSize.fill(EcalBarrel, ebSize / 36.);
90  }
91 
93  for (EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr) {
94  std::vector<short> const& feStatus(dcchItr->getFEStatus());
95  unsigned nFE(feStatus.size());
96  for (unsigned iFE(0); iFE < nFE; ++iFE)
97  if (feStatus[iFE] == Disabled)
98  suppressed_.insert(std::make_pair(dcchItr->id(), iFE + 1));
99  }
100  }
101 
102  template <typename SRFlagCollection>
103  void SelectiveReadoutTask::runOnSrFlags(SRFlagCollection const& _srfs, Collections _col) {
104  MESet& meFlagCounterMap(MEs_.at("FlagCounterMap"));
105  MESet& meFullReadoutMap(MEs_.at("FullReadoutMap"));
106  MESet& meZS1Map(MEs_.at("ZS1Map"));
107  MESet& meZSMap(MEs_.at("ZSMap"));
108  MESet& meRUForcedMap(MEs_.at("RUForcedMap"));
109 
110  double nFR(0.);
111 
112  std::for_each(_srfs.begin(), _srfs.end(), [&](typename SRFlagCollection::value_type const& srf) {
113  DetId const& id(srf.id());
114  int flag(srf.value());
115 
116  meFlagCounterMap.fill(id);
117 
118  unsigned iRU(-1);
119  if (id.subdetId() == EcalTriggerTower)
120  iRU = EcalTrigTowerDetId(id).hashedIndex();
121  else
123  flags_[iRU] = flag;
124 
125  switch (flag & ~EcalSrFlag::SRF_FORCED_MASK) {
127  meFullReadoutMap.fill(id);
128  nFR += 1.;
129  break;
130  case EcalSrFlag::SRF_ZS1:
131  meZS1Map.fill(id);
132  // fallthrough
133  case EcalSrFlag::SRF_ZS2:
134  meZSMap.fill(id);
135  break;
136  default:
137  break;
138  }
139 
141  meRUForcedMap.fill(id);
142  });
143 
144  MEs_.at("FullReadout").fill(_col == kEBSrFlag ? EcalBarrel : EcalEndcap, nFR);
145  }
146 
147  template <typename DigiCollection>
149  MESet& meHighIntOutput(MEs_.at("HighIntOutput"));
150  MESet& meLowIntOutput(MEs_.at("LowIntOutput"));
151  MESet& meHighIntPayload(MEs_.at("HighIntPayload"));
152  MESet& meLowIntPayload(MEs_.at("LowIntPayload"));
153  MESet& meTowerSize(MEs_.at("TowerSize"));
154  MESet& meZSFullReadoutMap(MEs_.at("ZSFullReadoutMap"));
155  MESet& meFRDroppedMap(MEs_.at("FRDroppedMap"));
156  MESet& meZSFullReadout(MEs_.at("ZSFullReadout"));
157  MESet& meFRDropped(MEs_.at("FRDropped"));
158 
159  bool isEB(_collection == kEBDigi);
160 
161  unsigned const nTower(isEB ? unsigned(EcalTrigTowerDetId::kEBTotalTowers)
163 
164  std::vector<unsigned> sizes(nTower, 0);
165 
166  int nHighInt[] = {0, 0};
167  int nLowInt[] = {0, 0};
168 
169  for (typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
170  DetId const& id(digiItr->id());
171 
172  unsigned iTower(-1);
173  unsigned iRU(-1);
174 
175  if (isEB) {
176  iTower = EBDetId(id).tower().hashedIndex();
177  iRU = iTower;
178  } else {
179  iTower = EEDetId(id).sc().hashedIndex();
180  iRU = iTower + EcalTrigTowerDetId::kEBTotalTowers;
181  }
182 
183  if (flags_[iRU] < 0)
184  continue;
185 
186  sizes[iTower] += 1;
187 
188  // SR filter output calculation
189 
190  EcalDataFrame frame(*digiItr);
191 
192  int ZSFIRValue(0); // output
193 
194  bool gain12saturated(false);
195  const int gain12(0x01);
196 
197  for (int iWeight(0); iWeight < nFIRTaps; ++iWeight) {
198  int iSample(iFirstSample_ + iWeight - 1);
199 
200  if (iSample >= 0 && iSample < frame.size()) {
201  EcalMGPASample sample(frame[iSample]);
202  if (sample.gainId() != gain12) {
203  gain12saturated = true;
204  break;
205  }
206  ZSFIRValue += sample.adc() * ZSFIRWeights_[iWeight];
207  } else {
208  edm::LogWarning("EcalDQM") << "SelectiveReadoutTask: Not enough samples in data frame or "
209  "'ecalDccZs1stSample' module parameter is not valid";
210  }
211  }
212 
213  if (gain12saturated)
214  ZSFIRValue = std::numeric_limits<int>::max();
215  else
216  ZSFIRValue /= (0x1 << 8); //discards the 8 LSBs
217 
218  //ZS passed if weighted sum above ZS threshold or if
219  //one sample has a lower gain than gain 12 (that is gain 12 output
220  //is saturated)
221 
222  bool highInterest((flags_[iRU] & ~EcalSrFlag::SRF_FORCED_MASK) == EcalSrFlag::SRF_FULL);
223 
224  if (highInterest) {
225  meHighIntOutput.fill(id, ZSFIRValue);
226  if (isEB || dccId(id) - 1 <= kEEmHigh)
227  nHighInt[0] += 1;
228  else
229  nHighInt[1] += 1;
230  } else {
231  meLowIntOutput.fill(id, ZSFIRValue);
232  if (isEB || dccId(id) - 1 <= kEEmHigh)
233  nLowInt[0] += 1;
234  else
235  nLowInt[1] += 1;
236  }
237  }
238 
239  if (isEB) {
240  meHighIntPayload.fill(EcalBarrel, nHighInt[0] * bytesPerCrystal / 1024. / nEBDCC);
241  meLowIntPayload.fill(EcalBarrel, nLowInt[0] * bytesPerCrystal / 1024. / nEBDCC);
242  } else {
243  meHighIntPayload.fill(-EcalEndcap, nHighInt[0] * bytesPerCrystal / 1024. / (nEEDCC / 2));
244  meHighIntPayload.fill(EcalEndcap, nHighInt[1] * bytesPerCrystal / 1024. / (nEEDCC / 2));
245  meLowIntPayload.fill(-EcalEndcap, nLowInt[0] * bytesPerCrystal / 1024. / (nEEDCC / 2));
246  meLowIntPayload.fill(EcalEndcap, nLowInt[1] * bytesPerCrystal / 1024. / (nEEDCC / 2));
247  }
248 
249  unsigned iRU(isEB ? 0 : EcalTrigTowerDetId::kEBTotalTowers);
250  for (unsigned iTower(0); iTower < nTower; ++iTower, ++iRU) {
251  DetId id;
252  if (isEB)
254  else
255  id = EcalScDetId::unhashIndex(iTower);
256 
257  double towerSize(sizes[iTower] * bytesPerCrystal);
258 
259  meTowerSize.fill(id, towerSize);
260 
261  if (flags_[iRU] < 0)
262  continue;
263 
264  int dccid(dccId(id));
265  int towerid(towerId(id));
266 
267  if (suppressed_.find(std::make_pair(dccid, towerid)) != suppressed_.end())
268  continue;
269 
271 
272  bool ruFullyReadout(sizes[iTower] == getElectronicsMap()->dccTowerConstituents(dccid, towerid).size());
273 
274  if (ruFullyReadout && (flag == EcalSrFlag::SRF_ZS1 || flag == EcalSrFlag::SRF_ZS2)) {
275  meZSFullReadoutMap.fill(id);
276  meZSFullReadout.fill(id);
277  }
278 
279  if (sizes[iTower] == 0 && flag == EcalSrFlag::SRF_FULL) {
280  meFRDroppedMap.fill(id);
281  meFRDropped.fill(id);
282  }
283  }
284  }
285 
286  void SelectiveReadoutTask::setFIRWeights_(std::vector<double> const& _normWeights) {
287  if (_normWeights.size() < nFIRTaps)
288  throw cms::Exception("InvalidConfiguration") << "weightsForZsFIR" << std::endl;
289 
290  bool notNormalized(false), notInt(false);
291  for (std::vector<double>::const_iterator it(_normWeights.begin()); it != _normWeights.end(); ++it) {
292  if (*it > 1.)
293  notNormalized = true;
294  if (int(*it) != *it)
295  notInt = true;
296  }
297  if (notInt && notNormalized) {
298  throw cms::Exception("InvalidConfiguration") << "weigtsForZsFIR paramater values are not valid: they "
299  << "must either be integer and uses the hardware representation "
300  << "of the weights or less or equal than 1 and used the normalized "
301  << "representation.";
302  }
303 
304  ZSFIRWeights_.clear();
305  ZSFIRWeights_.resize(_normWeights.size());
306 
307  if (notNormalized) {
308  for (unsigned i(0); i < ZSFIRWeights_.size(); ++i)
309  ZSFIRWeights_[i] = int(_normWeights[i]);
310  } else {
311  const int maxWeight(0xEFF); //weights coded on 11+1 signed bits
312  for (unsigned i(0); i < ZSFIRWeights_.size(); ++i) {
313  ZSFIRWeights_[i] = lround(_normWeights[i] * (0x1 << 10));
314  if (std::abs(ZSFIRWeights_[i]) > maxWeight) //overflow
315  ZSFIRWeights_[i] = ZSFIRWeights_[i] < 0 ? -maxWeight : maxWeight;
316  }
317  }
318  }
319 
321 } // namespace ecaldqm
size
Write out results.
T getUntrackedParameter(std::string const &, T const &) const
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:112
static const int SRF_ZS2
Definition: EcalSrFlag.h:21
static const int SRF_FORCED_MASK
Definition: EcalSrFlag.h:29
EcalElectronicsMapping const * getElectronicsMap()
std::vector< T >::const_iterator const_iterator
void runOnDigis(DigiCollection const &, Collections)
int hashedIndex() const
get a compact index for arrays [TODO: NEEDS WORK]
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:117
std::vector< std::vector< float > > dccNormalizedWeights_
void setFIRWeights_(std::vector< double > const &)
void beginEvent(edm::Event const &, edm::EventSetup const &) override
int gainId() const
get the gainId (2 bits)
void runOnRawData(EcalRawDataCollection const &)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
int size() const
Definition: EcalDataFrame.h:26
void setParams(edm::ParameterSet const &) override
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void addDependencies(DependencySet &) override
void beginRun(edm::Run const &, edm::EventSetup const &) override
static const int SRF_FULL
Definition: EcalSrFlag.h:24
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
void runOnSrFlags(SRFlagCollection const &, Collections)
int hashedIndex() const
Definition: EcalScDetId.h:106
unsigned towerId(DetId const &)
static const int SRF_ZS1
Definition: EcalSrFlag.h:18
const_iterator end() const
void runOnSource(FEDRawDataCollection const &)
Definition: DetId.h:17
MESetCollection MEs_
Definition: DQWorker.h:78
EcalScDetId sc() const
Definition: EEDetId.h:89
#define begin
Definition: vmac.h:32
T get() const
Definition: EventSetup.h:73
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:46
unsigned dccId(DetId const &)
std::set< std::pair< int, int > > suppressed_
const_iterator begin() const
Definition: Run.h:45
int adc() const
get the ADC sample (12 bits)