CMS 3D CMS Logo

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