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_);
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_; }
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_ = true;
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_)
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  if (detIndex_[i] >= 0) {
236  // edmNew::DetSet<T>::set() internally does an atomic update
237  det.detSet_.set(*handle_, handle_->item(detIndex_[i]));
238  det.empty_ = false; // better be false already
239  incAct();
240  } else { // we should not be here
241  det.detSet_ = StripDetset();
242  det.empty_ = true;
243  }
244  det.ready_ = false;
245  incSet();
246  }
247 
249 
251 
252  // Globals, per-event
254 
255  // Helper struct to define only the vector elements as mutable and
256  // to have a vector of atomics without an explicit loop over
257  // elements to set their values
258  struct DetSetHelper {
259  mutable std::atomic<bool> empty_ = true;
260  mutable std::atomic<bool> ready_ = true; // to be cleaned
261  // only thread-safe non-const member functions are called from a const function
263  };
264 
265  std::vector<bool> activeThisEvent_;
266 
267  // full reco
268  std::vector<DetSetHelper> detSet_;
269  std::vector<int> detIndex_;
270 
271  // note: not aligned to the index
272  std::vector<uint32_t> theRawInactiveStripDetIds_;
273  // keyed on si-strip index
274  std::vector<bool> stripDefined_, stripUpdated_;
275  std::vector<std::pair<unsigned int, unsigned int>> stripRegions_;
276  // keyed on glued
277  // std::vector<bool> gluedUpdated_;
278 
279 #ifdef VISTAT
280  struct Stat {
281  int totDet = 0; // all dets
282  int detReady = 0; // dets "updated"
283  int detSet = 0; // det actually set not empty
284  int detAct = 0; // det actually set with content
285  };
286 
287  mutable Stat stat;
288  void zeroStat() const { stat = Stat(); }
289  void incTot(int n) const { stat.totDet = n; }
290  void incReady() const { stat.detReady++; }
291  void incSet() const { stat.detSet++; }
292  void incAct() const { stat.detAct++; }
293  void printStat() const {
294  COUT << "VI detsets " << stat.totDet << ',' << stat.detReady << ',' << stat.detSet << ',' << stat.detAct
295  << std::endl;
296  }
297 
298 #else
299  static void zeroStat() {}
300  static void incTot(int) {}
301  static void incReady() {}
302  static void incSet() {}
303  static void incAct() {}
304  static void printStat() {}
305 #endif
306 };
307 
309 public:
311 
312  void init(int size);
313 
314  int nDet() const { return id_.size(); }
315  unsigned int id(int i) const { return id_[i]; }
316  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
317 
318  const PixelClusterParameterEstimator* pixelCPE() const { return theCPE; }
319  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
320 
323  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
324 
325 private:
327 
328  // Globals (not-per-event)
330 
331  // Locals, per-event
332  std::vector<unsigned int> id_;
333  std::vector<bool> activeThisPeriod_;
334 };
335 
337 public:
340  typedef std::vector<std::pair<LocalPoint, LocalPoint>> BadFEDChannelPositions;
341 
344 
346 
347  int size() const { return conditions().nDet(); }
348  int nDet() const { return size(); }
349  unsigned int id(int i) const { return conditions().id(i); }
350  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
351 
352  void update(int i, const PixelDetSet& detSet) {
353  detSet_[i] = detSet;
354  empty_[i] = false;
355  }
356 
357  bool empty(int i) const { return empty_[i]; }
358  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
359 
360  void setEmpty(int i) {
361  empty_[i] = true;
362  activeThisEvent_[i] = true;
363  auto found = badFEDChannelPositionsSet_.find(i);
364  if (found != badFEDChannelPositionsSet_.end()) {
366  }
367  }
368 
369  void setEmpty() {
370  std::fill(empty_.begin(), empty_.end(), true);
371  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
373  }
374  void setActiveThisEvent(bool active) { std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), active); }
375 
377  auto found = badFEDChannelPositionsSet_.find(i);
378  if (found == badFEDChannelPositionsSet_.end())
379  return nullptr;
380  return &(found->second);
381  }
383  auto found = badFEDChannelPositionsSet_.find(i);
384  if (found == badFEDChannelPositionsSet_.end()) {
385  badFEDChannelPositionsSet_.emplace(i, positions);
386  } else {
387  found->second.insert(found->second.end(), positions.begin(), positions.end());
388  }
389  }
390 
393  void setActiveThisEvent(int i, bool active) {
394  activeThisEvent_[i] = active;
395  if (!active)
396  empty_[i] = true;
397  }
400  const PixelDetSet& detSet(int i) const { return detSet_[i]; }
401 
402 private:
404 
406 
407  // Globals, per-event
409 
410  // Locals, per-event
411  std::vector<PixelDetSet> detSet_;
412  std::vector<bool> empty_;
413  std::vector<bool> activeThisEvent_;
414  std::unordered_map<int, BadFEDChannelPositions> badFEDChannelPositionsSet_;
415 };
416 
417 //FIXME:just temporary solution for phase2 OT that works!
419 public:
421 
422  void init(int size);
423 
424  int nDet() const { return id_.size(); }
425  unsigned int id(int i) const { return id_[i]; }
426  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
427 
429  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
430 
433  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
434 
435 private:
437 
438  // Globals (not-per-event)
440 
441  // Locals, per-event
442  std::vector<unsigned int> id_;
443  std::vector<bool> activeThisPeriod_;
444 };
445 
447 public:
450 
453 
455 
456  int size() const { return conditions().nDet(); }
457  int nDet() const { return size(); }
458  unsigned int id(int i) const { return conditions().id(i); }
459  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
460 
461  void update(int i, const Phase2DetSet& detSet) {
462  detSet_[i] = detSet;
463  empty_[i] = false;
464  }
465 
466  bool empty(int i) const { return empty_[i]; }
467  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
468 
469  void setEmpty(int i) {
470  empty_[i] = true;
471  activeThisEvent_[i] = true;
472  }
473 
474  void setEmpty() {
475  std::fill(empty_.begin(), empty_.end(), true);
476  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
477  }
478  void setActiveThisEvent(bool active) { std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), active); }
479  void setActiveThisEvent(int i, bool active) {
480  activeThisEvent_[i] = active;
481  if (!active)
482  empty_[i] = true;
483  }
486  const Phase2DetSet& detSet(int i) const { return detSet_[i]; }
487 
488 private:
490 
492 
493  //Globals, per-event
495 
496  // Locals, per-event
497  std::vector<Phase2DetSet> detSet_;
498  std::vector<bool> empty_;
499  std::vector<bool> activeThisEvent_;
500 };
501 
502 #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
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
std::vector< Phase2DetSet > detSet_
PxMeasurementDetSet(const PxMeasurementConditionSet &cond)
#define CMS_THREAD_SAFE
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.
Definition: plugin.cc:23
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
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