CMS 3D CMS Logo

TkMeasurementDetSet.h
Go to the documentation of this file.
1 #ifndef StMeasurementDetSet_H
2 #define StMeasurementDetSet_H
3 
4 #include <vector>
11 class Phase2StripCPE;
12 
19 
22 
24 
25 #include <atomic>
26 #include <unordered_map>
27 
28 // #define VISTAT
29 
30 #ifdef VISTAT
31 #include <iostream>
32 #define COUT std::cout
33 #else
34 #define COUT LogDebug("")
35 #endif
36 
37 /* Struct of arrays supporting "members of Tk...MeasurementDet
38  * implemented with vectors, to be optimized...
39  ITEMS THAT DO NOT DEPEND ON THE EVENT
40  */
42 public:
43  enum QualityFlags {
44  BadModules = 1, // for everybody
45  /* Strips: */ BadAPVFibers = 2,
46  BadStrips = 4,
48  /* Pixels: */ BadROCs = 2
49  };
50 
51  struct BadStripCuts {
53  BadStripCuts(uint32_t iMaxBad, uint32_t iMaxConsecutiveBad)
54  : maxBad(iMaxBad), maxConsecutiveBad(iMaxConsecutiveBad) {}
56  };
57 
58  struct BadStripBlock {
59  short first;
60  short last;
61  BadStripBlock(const SiStripBadStrip::data& data) : first(data.firstStrip), last(data.firstStrip + data.range - 1) {}
62  };
63 
65  : theMatcher(matcher), theCPE(cpe) {}
66 
67  void init(int size);
68 
69  const SiStripRecHitMatcher* matcher() const { return theMatcher; }
70  const StripClusterParameterEstimator* stripCPE() const { return theCPE; }
71 
72  int nDet() const { return id_.size(); }
73  unsigned int id(int i) const { return id_[i]; }
74  unsigned char subId(int i) const { return subId_[i]; }
75 
76  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
77 
78  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
79 
81  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
82 
83  int totalStrips(int i) const { return totalStrips_[i]; }
84 
85  void setMaskBad128StripBlocks(bool maskThem) { maskBad128StripBlocks_ = maskThem; }
86  const BadStripCuts& badStripCuts(int i) const { return badStripCuts_[subId_[i]]; }
87 
89  bool hasAny128StripBad(int i) const { return hasAny128StripBad_[i]; }
90 
92  bool bad128Strip(int offset) const { return bad128Strip_[offset]; }
93  bool bad128Strip(int index, int strip) const { return bad128Strip_[nbad128 * index + (strip >> 7)]; }
94 
95  std::vector<BadStripBlock>& getBadStripBlocks(int i) { return badStripBlocks_[i]; }
96  std::vector<BadStripBlock> const& badStripBlocks(int i) const { return badStripBlocks_[i]; }
97 
98  bool isMasked(int i, const SiStripCluster& cluster) const {
99  int offset = nbad128 * i;
100  if (bad128Strip_[offset + (cluster.firstStrip() >> 7)]) {
101  if (bad128Strip_[offset + ((cluster.firstStrip() + cluster.amplitudes().size()) >> 7)] ||
102  bad128Strip_[offset + (static_cast<int32_t>(cluster.barycenter() - 0.499999) >> 7)]) {
103  return true;
104  }
105  } else {
106  if (bad128Strip_[offset + ((cluster.firstStrip() + cluster.amplitudes().size()) >> 7)] &&
107  bad128Strip_[offset + (static_cast<int32_t>(cluster.barycenter() - 0.499999) >> 7)]) {
108  return true;
109  }
110  }
111  return false;
112  }
113 
114  void set128StripStatus(int i, bool good, int idx = -1);
115 
116 private:
118 
119  // globals
122 
125 
126  // members of TkStripMeasurementDet
127  std::vector<unsigned int> id_;
128  std::vector<unsigned char> subId_;
129 
130  std::vector<int> totalStrips_;
131 
132  static const int nbad128 = 6;
133  std::vector<bool> bad128Strip_;
134  std::vector<bool> hasAny128StripBad_;
135 
136  std::vector<std::vector<BadStripBlock>> badStripBlocks_;
137 
138  std::vector<bool> activeThisPeriod_;
139 };
140 
142 public:
145 
147  : conditionSet_(&cond),
149  detSet_(cond.nDet()),
150  detIndex_(cond.nDet(), -1),
152  stripDefined_(0),
153  stripUpdated_(0),
154  stripRegions_(0) {}
155 
157 
159 
160  void update(int i, const StripDetset& detSet) {
161  detSet_[i].detSet_ = detSet;
162  detSet_[i].empty_ = false;
163  }
164 
165  void update(int i, int j) {
166  assert(j >= 0);
167  assert(detSet_[i].empty_);
168  assert(detSet_[i].ready_ == ReadyState::kUnset);
169  detIndex_[i] = j;
170  detSet_[i].empty_ = false;
171  incReady();
172  }
173 
174  int size() const { return conditions().nDet(); }
175  int nDet() const { return size(); }
176  unsigned int id(int i) const { return conditions().id(i); }
177  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
178 
179  bool empty(int i) const { return detSet_[i].empty_.load(std::memory_order_relaxed); }
180  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
181 
182  void setEmpty(int i) {
183  detSet_[i].empty_ = true;
184  activeThisEvent_[i] = true;
185  }
186  void setUpdated(int i) { stripUpdated_[i] = true; }
187 
188  void setEmpty() {
189  printStat();
190  for (auto& d : detSet_) {
191  d.empty_ = true;
192  d.ready_ = ReadyState::kUnset;
193  }
194  std::fill(detIndex_.begin(), detIndex_.end(), -1);
195  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
196  incTot(size());
197  }
198 
201  void setActiveThisEvent(int i, bool active) {
202  activeThisEvent_[i] = active;
203  if (!active)
204  detSet_[i].empty_ = true;
205  }
206 
209  // StripDetset & detSet(int i) { return detSet_[i]; }
210  const StripDetset& detSet(int i) const {
211  if (detSet_[i].ready_.load(std::memory_order_acquire) != ReadyState::kSet)
212  getDetSet(i);
213  return detSet_[i].detSet_;
214  }
215 
217  std::vector<uint32_t>& rawInactiveStripDetIds() { return theRawInactiveStripDetIds_; }
218  const std::vector<uint32_t>& rawInactiveStripDetIds() const { return theRawInactiveStripDetIds_; }
219 
221  std::fill(stripDefined_.begin(), stripDefined_.end(), false);
222  std::fill(stripUpdated_.begin(), stripUpdated_.end(), false);
223  }
224  const bool stripDefined(int i) const { return stripDefined_[i]; }
225  const bool stripUpdated(int i) const { return stripUpdated_[i]; }
226  void defineStrip(int i, std::pair<unsigned int, unsigned int> range) {
227  stripDefined_[i] = true;
228  stripUpdated_[i] = false;
229  stripRegions_[i] = range;
230  }
231 
232 private:
233  void getDetSet(int i) const {
234  const auto& det = detSet_[i];
235 
236  ReadyState expected = ReadyState::kUnset;
237  if (det.ready_.compare_exchange_strong(expected, ReadyState::kSetting, std::memory_order_acq_rel)) {
238  if (detIndex_[i] >= 0) {
239  det.detSet_ = StripDetset(*handle_, handle_->item(detIndex_[i]), true);
240  det.empty_.store(false, std::memory_order_relaxed); // better be false already
241  incAct();
242  } else { // we should not be here
243  det.detSet_ = StripDetset();
244  det.empty_.store(true, std::memory_order_relaxed);
245  }
246  det.ready_.store(ReadyState::kSet, std::memory_order_release);
247  incSet();
248  } else {
249  // need to wait
250  while (ReadyState::kSet != det.ready_.load(std::memory_order_acquire)) {
251  }
252  }
253  }
254 
256 
258 
259  // Globals, per-event
261 
262  enum class ReadyState : char { kUnset, kSetting, kSet };
263 
264  // Helper struct to define only the vector elements as mutable and
265  // to have a vector of atomics without an explicit loop over
266  // elements to set their values
267  struct DetSetHelper {
268  mutable std::atomic<bool> empty_ = true;
269  mutable std::atomic<ReadyState> ready_ = ReadyState::kUnset; // to be cleaned
271  };
272 
273  std::vector<bool> activeThisEvent_;
274 
275  // full reco
276  std::vector<DetSetHelper> detSet_;
277  std::vector<int> detIndex_;
278 
279  // note: not aligned to the index
280  std::vector<uint32_t> theRawInactiveStripDetIds_;
281  // keyed on si-strip index
282  std::vector<bool> stripDefined_, stripUpdated_;
283  std::vector<std::pair<unsigned int, unsigned int>> stripRegions_;
284  // keyed on glued
285  // std::vector<bool> gluedUpdated_;
286 
287 #ifdef VISTAT
288  struct Stat {
289  int totDet = 0; // all dets
290  int detReady = 0; // dets "updated"
291  int detSet = 0; // det actually set not empty
292  int detAct = 0; // det actually set with content
293  };
294 
295  mutable Stat stat;
296  void zeroStat() const { stat = Stat(); }
297  void incTot(int n) const { stat.totDet = n; }
298  void incReady() const { stat.detReady++; }
299  void incSet() const { stat.detSet++; }
300  void incAct() const { stat.detAct++; }
301  void printStat() const {
302  COUT << "VI detsets " << stat.totDet << ',' << stat.detReady << ',' << stat.detSet << ',' << stat.detAct
303  << std::endl;
304  }
305 
306 #else
307  static void zeroStat() {}
308  static void incTot(int) {}
309  static void incReady() {}
310  static void incSet() {}
311  static void incAct() {}
312  static void printStat() {}
313 #endif
314 };
315 
317 public:
319 
320  void init(int size);
321 
322  int nDet() const { return id_.size(); }
323  unsigned int id(int i) const { return id_[i]; }
324  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
325 
326  const PixelClusterParameterEstimator* pixelCPE() const { return theCPE; }
327  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
328 
331  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
332 
333 private:
335 
336  // Globals (not-per-event)
338 
339  // Locals, per-event
340  std::vector<unsigned int> id_;
341  std::vector<bool> activeThisPeriod_;
342 };
343 
345 public:
348  typedef std::vector<std::pair<LocalPoint, LocalPoint>> BadFEDChannelPositions;
349 
352 
354 
355  int size() const { return conditions().nDet(); }
356  int nDet() const { return size(); }
357  unsigned int id(int i) const { return conditions().id(i); }
358  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
359 
360  void update(int i, const PixelDetSet& detSet) {
361  detSet_[i] = detSet;
362  empty_[i] = false;
363  }
364 
365  bool empty(int i) const { return empty_[i]; }
366  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
367 
368  void setEmpty(int i) {
369  empty_[i] = true;
370  activeThisEvent_[i] = true;
371  auto found = badFEDChannelPositionsSet_.find(i);
372  if (found != badFEDChannelPositionsSet_.end()) {
374  }
375  }
376 
377  void setEmpty() {
378  std::fill(empty_.begin(), empty_.end(), true);
379  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
381  }
382  void setActiveThisEvent(bool active) { std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), active); }
383 
385  auto found = badFEDChannelPositionsSet_.find(i);
386  if (found == badFEDChannelPositionsSet_.end())
387  return nullptr;
388  return &(found->second);
389  }
391  auto found = badFEDChannelPositionsSet_.find(i);
392  if (found == badFEDChannelPositionsSet_.end()) {
393  badFEDChannelPositionsSet_.emplace(i, positions);
394  } else {
395  found->second.insert(found->second.end(), positions.begin(), positions.end());
396  }
397  }
398 
401  void setActiveThisEvent(int i, bool active) {
402  activeThisEvent_[i] = active;
403  if (!active)
404  empty_[i] = true;
405  }
408  const PixelDetSet& detSet(int i) const { return detSet_[i]; }
409 
410 private:
412 
414 
415  // Globals, per-event
417 
418  // Locals, per-event
419  std::vector<PixelDetSet> detSet_;
420  std::vector<bool> empty_;
421  std::vector<bool> activeThisEvent_;
422  std::unordered_map<int, BadFEDChannelPositions> badFEDChannelPositionsSet_;
423 };
424 
425 //FIXME:just temporary solution for phase2 OT that works!
427 public:
429 
430  void init(int size);
431 
432  int nDet() const { return id_.size(); }
433  unsigned int id(int i) const { return id_[i]; }
434  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
435 
437  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
438 
441  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
442 
443 private:
445 
446  // Globals (not-per-event)
448 
449  // Locals, per-event
450  std::vector<unsigned int> id_;
451  std::vector<bool> activeThisPeriod_;
452 };
453 
455 public:
458 
461 
463 
464  int size() const { return conditions().nDet(); }
465  int nDet() const { return size(); }
466  unsigned int id(int i) const { return conditions().id(i); }
467  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
468 
469  void update(int i, const Phase2DetSet& detSet) {
470  detSet_[i] = detSet;
471  empty_[i] = false;
472  }
473 
474  bool empty(int i) const { return empty_[i]; }
475  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
476 
477  void setEmpty(int i) {
478  empty_[i] = true;
479  activeThisEvent_[i] = true;
480  }
481 
482  void setEmpty() {
483  std::fill(empty_.begin(), empty_.end(), true);
484  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
485  }
486  void setActiveThisEvent(bool active) { std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), active); }
487  void setActiveThisEvent(int i, bool active) {
488  activeThisEvent_[i] = active;
489  if (!active)
490  empty_[i] = true;
491  }
494  const Phase2DetSet& detSet(int i) const { return detSet_[i]; }
495 
496 private:
498 
500 
501  //Globals, per-event
503 
504  // Locals, per-event
505  std::vector<Phase2DetSet> detSet_;
506  std::vector<bool> empty_;
507  std::vector<bool> activeThisEvent_;
508 };
509 
510 #endif // StMeasurementDetSet_H
size
Write out results.
edmNew::DetSet< Phase2TrackerCluster1D > Phase2DetSet
std::vector< std::pair< LocalPoint, LocalPoint > > BadFEDChannelPositions
edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > & handle()
void setActiveThisEvent(int i, bool active)
Turn on/off the module for reconstruction for one events. This per-event flag is cleared by any call ...
const PixelDetSet & detSet(int i) const
std::vector< std::vector< BadStripBlock > > badStripBlocks_
uint16_t firstStrip() const
PxMeasurementConditionSet(const PixelClusterParameterEstimator *cpe)
const PixelClusterParameterEstimator * theCPE
void setActive(int i, bool active)
Turn on/off the module for reconstruction, for the full run or lumi (using info from DB...
unsigned int id(int i) const
std::vector< DetSetHelper > detSet_
edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > handle_
bool empty(int i) const
unsigned int id(int i) const
int find(unsigned int jd, int i=0) const
edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > SiPixelClusterRef
unsigned int id(int i) const
StMeasurementDetSet(const StMeasurementConditionSet &cond)
void update(int i, int j)
std::vector< bool > stripDefined_
const PxMeasurementConditionSet * conditionSet_
void update(int i, const StripDetset &detSet)
const StripClusterParameterEstimator * stripCPE() const
StripDetset::const_iterator new_const_iterator
data_type const * const_iterator
Definition: DetSetNew.h:31
bool bad128Strip(int index, int strip) const
assert(be >=bs)
edm::Ref< edmNew::DetSetVector< Phase2TrackerCluster1D >, Phase2TrackerCluster1D > Phase2TrackerCluster1DRef
void defineStrip(int i, std::pair< unsigned int, unsigned int > range)
bool isActive(int i) const
std::atomic< ReadyState > ready_
const edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > & handle() const
const bool stripDefined(int i) const
const SiStripRecHitMatcher * matcher() const
std::vector< bool > empty_
bool isActiveThisPeriod(int i) const
edmNew::DetSet< SiStripCluster > StripDetset
std::vector< unsigned char > subId_
unsigned int id(int i) const
unsigned int id(int i) const
bool hasAny128StripBad(int i) const
const StripDetset & detSet(int i) const
const StMeasurementConditionSet * conditionSet_
void setActiveThisEvent(int i, bool active)
Turn on/off the module for reconstruction for one events. This per-event flag is cleared by any call ...
SiStripCluster const & amplitudes() const
auto size() const
void setActive(int i, bool active)
Turn on/off the module for reconstruction, for the full run or lumi (using info from DB...
std::vector< BadStripBlock > & getBadStripBlocks(int i)
const edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle() const
edm::Handle< edmNew::DetSetVector< SiPixelCluster > > handle_
bool isActiveThisPeriod(int i) const
#define CMS_THREAD_GUARD(_var_)
std::vector< Phase2DetSet > detSet_
PxMeasurementDetSet(const PxMeasurementConditionSet &cond)
unsigned int id(int i) const
int find(unsigned int jd, int i=0) const
std::vector< uint32_t > theRawInactiveStripDetIds_
const std::vector< uint32_t > & rawInactiveStripDetIds() const
std::vector< unsigned int > id_
StMeasurementConditionSet(const SiStripRecHitMatcher *matcher, const StripClusterParameterEstimator *cpe)
void update(int i, const PixelDetSet &detSet)
void addBadFEDChannelPositions(int i, BadFEDChannelPositions &positions)
std::vector< int > totalStrips_
bool bad128Strip(int offset) const
note: index is 6*detector index + offset!
d
Definition: ztail.py:151
const Phase2OTMeasurementConditionSet & conditions() const
std::vector< bool > hasAny128StripBad_
const StripClusterParameterEstimator * theCPE
int find(unsigned int jd, int i=0) const
void setActiveThisEvent(int i, bool active)
const ClusterParameterEstimator< Phase2TrackerCluster1D > * cpe() const
std::vector< uint32_t > & rawInactiveStripDetIds()
const StMeasurementConditionSet & conditions() const
void setMaskBad128StripBlocks(bool maskThem)
std::vector< bool > activeThisPeriod_
const BadFEDChannelPositions * getBadFEDChannelPositions(int i) const
std::vector< unsigned int > id_
bool isMasked(int i, const SiStripCluster &cluster) const
Item const & item(size_t cell) const
std::vector< unsigned int > id_
std::vector< bool > activeThisPeriod_
const BadStripCuts & badStripCuts(int i) const
BadStripBlock(const SiStripBadStrip::data &data)
void getDetSet(int i) const
const bool stripUpdated(int i) const
unsigned char subId(int i) const
edm::Handle< edmNew::DetSetVector< SiStripCluster > > handle_
std::vector< bool > bad128Strip_
std::vector< bool > activeThisEvent_
void setActiveThisEvent(bool active)
Pixel cluster – collection of neighboring pixels above threshold.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
BadStripCuts(uint32_t iMaxBad, uint32_t iMaxConsecutiveBad)
int find(unsigned int jd, int i=0) const
static void incTot(int)
bool empty(int i) const
std::vector< bool > activeThisEvent_
float barycenter() const
std::vector< bool > activeThisEvent_
const ClusterParameterEstimator< Phase2TrackerCluster1D > * theCPE
const Phase2DetSet & detSet(int i) const
void setActiveThisEvent(bool active)
void setActive(int i, bool active)
Turn on/off the module for reconstruction, for the full run or lumi (using info from DB...
edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle()
void set128StripStatus(int i, bool good, int idx=-1)
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
Phase2OTMeasurementDetSet(const Phase2OTMeasurementConditionSet &cond)
int find(unsigned int jd, int i=0) const
std::vector< std::pair< unsigned int, unsigned int > > stripRegions_
std::vector< int > detIndex_
void update(int i, const Phase2DetSet &detSet)
bool isActive(int i) const
std::vector< PixelDetSet > detSet_
const SiStripRecHitMatcher * theMatcher
int find(unsigned int jd, int i=0) const
edmNew::DetSet< SiPixelCluster > PixelDetSet
const PixelClusterParameterEstimator * pixelCPE() const
std::vector< bool > stripUpdated_
#define COUT
const PxMeasurementConditionSet & conditions() const
const Phase2OTMeasurementConditionSet * conditionSet_
std::unordered_map< int, BadFEDChannelPositions > badFEDChannelPositionsSet_
Phase2OTMeasurementConditionSet(const ClusterParameterEstimator< Phase2TrackerCluster1D > *cpe)
edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle()
std::vector< BadStripBlock > const & badStripBlocks(int i) const