CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
23 #include <unordered_map>
24 
25 // #define VISTAT
26 
27 #ifdef VISTAT
28 #include <iostream>
29 #define COUT std::cout
30 #else
31 #define COUT LogDebug("")
32 #endif
33 
34 /* Struct of arrays supporting "members of Tk...MeasurementDet
35  * implemented with vectors, to be optimized...
36  ITEMS THAT DO NOT DEPEND ON THE EVENT
37  */
39 public:
40  enum QualityFlags {
41  BadModules = 1, // for everybody
42  /* Strips: */ BadAPVFibers = 2,
43  BadStrips = 4,
45  /* Pixels: */ BadROCs = 2
46  };
47 
48  struct BadStripCuts {
50  BadStripCuts(uint32_t iMaxBad, uint32_t iMaxConsecutiveBad)
51  : maxBad(iMaxBad), maxConsecutiveBad(iMaxConsecutiveBad) {}
53  };
54 
55  struct BadStripBlock {
56  short first;
57  short last;
58  BadStripBlock(const SiStripBadStrip::data& data) : first(data.firstStrip), last(data.firstStrip + data.range - 1) {}
59  };
60 
62  : theMatcher(matcher), theCPE(cpe) {}
63 
64  void init(int size);
65 
66  const SiStripRecHitMatcher* matcher() const { return theMatcher; }
67  const StripClusterParameterEstimator* stripCPE() const { return theCPE; }
68 
69  int nDet() const { return id_.size(); }
70  unsigned int id(int i) const { return id_[i]; }
71  unsigned char subId(int i) const { return subId_[i]; }
72 
73  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
74 
75  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
76 
78  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
79 
80  int totalStrips(int i) const { return totalStrips_[i]; }
81 
82  void setMaskBad128StripBlocks(bool maskThem) { maskBad128StripBlocks_ = maskThem; }
83  const BadStripCuts& badStripCuts(int i) const { return badStripCuts_[subId_[i]]; }
84 
86  bool hasAny128StripBad(int i) const { return hasAny128StripBad_[i]; }
87 
89  bool bad128Strip(int offset) const { return bad128Strip_[offset]; }
90  bool bad128Strip(int index, int strip) const { return bad128Strip_[nbad128 * index + (strip >> 7)]; }
91 
92  std::vector<BadStripBlock>& getBadStripBlocks(int i) { return badStripBlocks_[i]; }
93  std::vector<BadStripBlock> const& badStripBlocks(int i) const { return badStripBlocks_[i]; }
94 
95  bool isMasked(int i, const SiStripCluster& cluster) const {
96  int offset = nbad128 * i;
97  if (bad128Strip_[offset + (cluster.firstStrip() >> 7)]) {
98  if (bad128Strip_[offset + ((cluster.firstStrip() + cluster.amplitudes().size()) >> 7)] ||
99  bad128Strip_[offset + (static_cast<int32_t>(cluster.barycenter() - 0.499999) >> 7)]) {
100  return true;
101  }
102  } else {
103  if (bad128Strip_[offset + ((cluster.firstStrip() + cluster.amplitudes().size()) >> 7)] &&
104  bad128Strip_[offset + (static_cast<int32_t>(cluster.barycenter() - 0.499999) >> 7)]) {
105  return true;
106  }
107  }
108  return false;
109  }
110 
111  void set128StripStatus(int i, bool good, int idx = -1);
112 
113 private:
115 
116  // globals
119 
122 
123  // members of TkStripMeasurementDet
124  std::vector<unsigned int> id_;
125  std::vector<unsigned char> subId_;
126 
127  std::vector<int> totalStrips_;
128 
129  static const int nbad128 = 6;
130  std::vector<bool> bad128Strip_;
131  std::vector<bool> hasAny128StripBad_;
132 
133  std::vector<std::vector<BadStripBlock>> badStripBlocks_;
134 
135  std::vector<bool> activeThisPeriod_;
136 };
137 
139 public:
142 
144  : conditionSet_(&cond),
145  empty_(cond.nDet(), true),
146  activeThisEvent_(cond.nDet(), true),
147  detSet_(cond.nDet()),
148  detIndex_(cond.nDet(), -1),
149  ready_(cond.nDet(), true),
151  stripDefined_(0),
152  stripUpdated_(0),
153  stripRegions_(0) {}
154 
156 
158 
159  void update(int i, const StripDetset& detSet) {
160  detSet_[i] = detSet;
161  empty_[i] = false;
162  }
163 
164  void update(int i, int j) {
165  assert(j >= 0);
166  assert(empty_[i]);
167  assert(ready_[i]);
168  detIndex_[i] = j;
169  empty_[i] = false;
170  incReady();
171  }
172 
173  int size() const { return conditions().nDet(); }
174  int nDet() const { return size(); }
175  unsigned int id(int i) const { return conditions().id(i); }
176  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
177 
178  bool empty(int i) const { return empty_[i]; }
179  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
180 
181  void setEmpty(int i) {
182  empty_[i] = true;
183  activeThisEvent_[i] = true;
184  }
185  void setUpdated(int i) { stripUpdated_[i] = true; }
186 
187  void setEmpty() {
188  printStat();
189  std::fill(empty_.begin(), empty_.end(), true);
190  std::fill(ready_.begin(), ready_.end(), true);
191  std::fill(detIndex_.begin(), detIndex_.end(), -1);
192  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
193  incTot(size());
194  }
195 
198  void setActiveThisEvent(int i, bool active) {
199  activeThisEvent_[i] = active;
200  if (!active)
201  empty_[i] = true;
202  }
203 
206  // StripDetset & detSet(int i) { return detSet_[i]; }
207  const StripDetset& detSet(int i) const {
208  if (ready_[i])
209  const_cast<StMeasurementDetSet*>(this)->getDetSet(i);
210  return detSet_[i];
211  }
212 
214  std::vector<uint32_t>& rawInactiveStripDetIds() { return theRawInactiveStripDetIds_; }
215  const std::vector<uint32_t>& rawInactiveStripDetIds() const { return theRawInactiveStripDetIds_; }
216 
218  std::fill(stripDefined_.begin(), stripDefined_.end(), false);
219  std::fill(stripUpdated_.begin(), stripUpdated_.end(), false);
220  }
221  const bool stripDefined(int i) const { return stripDefined_[i]; }
222  const bool stripUpdated(int i) const { return stripUpdated_[i]; }
223  void defineStrip(int i, std::pair<unsigned int, unsigned int> range) {
224  stripDefined_[i] = true;
225  stripUpdated_[i] = false;
226  stripRegions_[i] = range;
227  }
228 
229 private:
230  void getDetSet(int i) {
231  if (detIndex_[i] >= 0) {
232  detSet_[i].set(*handle_, handle_->item(detIndex_[i]));
233  empty_[i] = false; // better be false already
234  incAct();
235  } else { // we should not be here
236  detSet_[i] = StripDetset();
237  empty_[i] = true;
238  }
239  ready_[i] = false;
240  incSet();
241  }
242 
244 
246 
247  // Globals, per-event
249 
250  std::vector<bool> empty_;
251  std::vector<bool> activeThisEvent_;
252 
253  // full reco
254  std::vector<StripDetset> detSet_;
255  std::vector<int> detIndex_;
256  std::vector<bool> ready_; // to be cleaned
257 
258  // note: not aligned to the index
259  std::vector<uint32_t> theRawInactiveStripDetIds_;
260  // keyed on si-strip index
261  std::vector<bool> stripDefined_, stripUpdated_;
262  std::vector<std::pair<unsigned int, unsigned int>> stripRegions_;
263  // keyed on glued
264  // std::vector<bool> gluedUpdated_;
265 
266 #ifdef VISTAT
267  struct Stat {
268  int totDet = 0; // all dets
269  int detReady = 0; // dets "updated"
270  int detSet = 0; // det actually set not empty
271  int detAct = 0; // det actually set with content
272  };
273 
274  mutable Stat stat;
275  void zeroStat() const { stat = Stat(); }
276  void incTot(int n) const { stat.totDet = n; }
277  void incReady() const { stat.detReady++; }
278  void incSet() const { stat.detSet++; }
279  void incAct() const { stat.detAct++; }
280  void printStat() const {
281  COUT << "VI detsets " << stat.totDet << ',' << stat.detReady << ',' << stat.detSet << ',' << stat.detAct
282  << std::endl;
283  }
284 
285 #else
286  static void zeroStat() {}
287  static void incTot(int) {}
288  static void incReady() {}
289  static void incSet() {}
290  static void incAct() {}
291  static void printStat() {}
292 #endif
293 };
294 
296 public:
298 
299  void init(int size);
300 
301  int nDet() const { return id_.size(); }
302  unsigned int id(int i) const { return id_[i]; }
303  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
304 
305  const PixelClusterParameterEstimator* pixelCPE() const { return theCPE; }
306  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
307 
310  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
311 
312 private:
314 
315  // Globals (not-per-event)
317 
318  // Locals, per-event
319  std::vector<unsigned int> id_;
320  std::vector<bool> activeThisPeriod_;
321 };
322 
324 public:
327  typedef std::vector<std::pair<LocalPoint, LocalPoint>> BadFEDChannelPositions;
328 
330  : conditionSet_(&cond), detSet_(cond.nDet()), empty_(cond.nDet(), true), activeThisEvent_(cond.nDet(), true) {}
331 
333 
334  int size() const { return conditions().nDet(); }
335  int nDet() const { return size(); }
336  unsigned int id(int i) const { return conditions().id(i); }
337  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
338 
339  void update(int i, const PixelDetSet& detSet) {
340  detSet_[i] = detSet;
341  empty_[i] = false;
342  }
343 
344  bool empty(int i) const { return empty_[i]; }
345  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
346 
347  void setEmpty(int i) {
348  empty_[i] = true;
349  activeThisEvent_[i] = true;
350  auto found = badFEDChannelPositionsSet_.find(i);
351  if (found != badFEDChannelPositionsSet_.end()) {
353  }
354  }
355 
356  void setEmpty() {
357  std::fill(empty_.begin(), empty_.end(), true);
358  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
360  }
361  void setActiveThisEvent(bool active) { std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), active); }
362 
364  auto found = badFEDChannelPositionsSet_.find(i);
365  if (found == badFEDChannelPositionsSet_.end())
366  return nullptr;
367  return &(found->second);
368  }
370  auto found = badFEDChannelPositionsSet_.find(i);
371  if (found == badFEDChannelPositionsSet_.end()) {
372  badFEDChannelPositionsSet_.emplace(i, positions);
373  } else {
374  found->second.insert(found->second.end(), positions.begin(), positions.end());
375  }
376  }
377 
380  void setActiveThisEvent(int i, bool active) {
381  activeThisEvent_[i] = active;
382  if (!active)
383  empty_[i] = true;
384  }
387  const PixelDetSet& detSet(int i) const { return detSet_[i]; }
388 
389 private:
391 
393 
394  // Globals, per-event
396 
397  // Locals, per-event
398  std::vector<PixelDetSet> detSet_;
399  std::vector<bool> empty_;
400  std::vector<bool> activeThisEvent_;
401  std::unordered_map<int, BadFEDChannelPositions> badFEDChannelPositionsSet_;
402 };
403 
404 //FIXME:just temporary solution for phase2 OT that works!
406 public:
408 
409  void init(int size);
410 
411  int nDet() const { return id_.size(); }
412  unsigned int id(int i) const { return id_[i]; }
413  int find(unsigned int jd, int i = 0) const { return std::lower_bound(id_.begin() + i, id_.end(), jd) - id_.begin(); }
414 
416  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
417 
420  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
421 
422 private:
424 
425  // Globals (not-per-event)
427 
428  // Locals, per-event
429  std::vector<unsigned int> id_;
430  std::vector<bool> activeThisPeriod_;
431 };
432 
434 public:
437 
439  : conditionSet_(&cond), detSet_(cond.nDet()), empty_(cond.nDet(), true), activeThisEvent_(cond.nDet(), true) {}
440 
442 
443  int size() const { return conditions().nDet(); }
444  int nDet() const { return size(); }
445  unsigned int id(int i) const { return conditions().id(i); }
446  int find(unsigned int jd, int i = 0) const { return conditions().find(jd, i); }
447 
448  void update(int i, const Phase2DetSet& detSet) {
449  detSet_[i] = detSet;
450  empty_[i] = false;
451  }
452 
453  bool empty(int i) const { return empty_[i]; }
454  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
455 
456  void setEmpty(int i) {
457  empty_[i] = true;
458  activeThisEvent_[i] = true;
459  }
460 
461  void setEmpty() {
462  std::fill(empty_.begin(), empty_.end(), true);
463  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), true);
464  }
465  void setActiveThisEvent(bool active) { std::fill(activeThisEvent_.begin(), activeThisEvent_.end(), active); }
466  void setActiveThisEvent(int i, bool active) {
467  activeThisEvent_[i] = active;
468  if (!active)
469  empty_[i] = true;
470  }
473  const Phase2DetSet& detSet(int i) const { return detSet_[i]; }
474 
475 private:
477 
479 
480  //Globals, per-event
482 
483  // Locals, per-event
484  std::vector<Phase2DetSet> detSet_;
485  std::vector<bool> empty_;
486  std::vector<bool> activeThisEvent_;
487 };
488 
489 #endif // StMeasurementDetSet_H
bool isMasked(int i, const SiStripCluster &cluster) const
edmNew::DetSet< Phase2TrackerCluster1D > Phase2DetSet
std::vector< std::pair< LocalPoint, LocalPoint > > BadFEDChannelPositions
int find(unsigned int jd, int i=0) const
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 ...
std::vector< std::vector< BadStripBlock > > badStripBlocks_
PxMeasurementConditionSet(const PixelClusterParameterEstimator *cpe)
unsigned int id(int i) const
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...
const StripDetset & detSet(int i) const
edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > handle_
bool bad128Strip(int index, int strip) const
edm::Ref< edmNew::DetSetVector< SiPixelCluster >, SiPixelCluster > SiPixelClusterRef
SiStripCluster const & amplitudes() const
StMeasurementDetSet(const StMeasurementConditionSet &cond)
void update(int i, int j)
std::vector< bool > stripDefined_
std::vector< bool > ready_
const Phase2DetSet & detSet(int i) const
const PxMeasurementConditionSet * conditionSet_
void update(int i, const StripDetset &detSet)
const StMeasurementConditionSet & conditions() const
StripDetset::const_iterator new_const_iterator
uint16_t firstStrip() const
data_type const * const_iterator
Definition: DetSetNew.h:31
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
bool isActiveThisPeriod(int i) const
assert(be >=bs)
unsigned int id(int i) const
const BadFEDChannelPositions * getBadFEDChannelPositions(int i) const
edm::Ref< edmNew::DetSetVector< Phase2TrackerCluster1D >, Phase2TrackerCluster1D > Phase2TrackerCluster1DRef
void defineStrip(int i, std::pair< unsigned int, unsigned int > range)
std::vector< bool > empty_
const bool stripUpdated(int i) const
const uint16_t range(const Frame &aFrame)
unsigned int id(int i) const
bool empty(int i) const
unsigned int id(int i) const
edmNew::DetSet< SiStripCluster > StripDetset
int find(unsigned int jd, int i=0) const
std::vector< unsigned char > subId_
const BadStripCuts & badStripCuts(int i) const
const ClusterParameterEstimator< Phase2TrackerCluster1D > * cpe() const
unsigned int id(int i) const
auto size() const
const SiStripRecHitMatcher * matcher() const
const StMeasurementConditionSet * conditionSet_
int find(unsigned int jd, int i=0) const
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 edm::Handle< edmNew::DetSetVector< Phase2TrackerCluster1D > > & handle() const
void setActive(int i, bool active)
Turn on/off the module for reconstruction, for the full run or lumi (using info from DB...
bool isActive(int i) const
std::vector< BadStripBlock > & getBadStripBlocks(int i)
edm::Handle< edmNew::DetSetVector< SiPixelCluster > > handle_
bool hasAny128StripBad(int i) const
const edm::Handle< edmNew::DetSetVector< SiStripCluster > > & handle() const
std::vector< Phase2DetSet > detSet_
PxMeasurementDetSet(const PxMeasurementConditionSet &cond)
const StripClusterParameterEstimator * stripCPE() const
float barycenter() const
std::vector< uint32_t > theRawInactiveStripDetIds_
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_
std::vector< bool > hasAny128StripBad_
const StripClusterParameterEstimator * theCPE
void setActiveThisEvent(int i, bool active)
std::vector< bool > empty_
std::vector< uint32_t > & rawInactiveStripDetIds()
void setMaskBad128StripBlocks(bool maskThem)
std::vector< bool > activeThisPeriod_
std::vector< unsigned int > id_
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
auto const good
min quality of good
std::vector< unsigned int > id_
std::vector< bool > activeThisPeriod_
const Phase2OTMeasurementConditionSet & conditions() const
BadStripBlock(const SiStripBadStrip::data &data)
bool isActive(int i) const
edm::Handle< edmNew::DetSetVector< SiStripCluster > > handle_
std::vector< bool > bad128Strip_
int find(unsigned int jd, int i=0) const
std::vector< bool > activeThisEvent_
bool empty(int i) const
void setActiveThisEvent(bool active)
Pixel cluster – collection of neighboring pixels above threshold.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
BadStripCuts(uint32_t iMaxBad, uint32_t iMaxConsecutiveBad)
static void incTot(int)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::vector< StripDetset > detSet_
std::vector< bool > activeThisEvent_
int find(unsigned int jd, int i=0) const
const PixelClusterParameterEstimator * pixelCPE() const
std::vector< BadStripBlock > const & badStripBlocks(int i) const
std::vector< bool > activeThisEvent_
int find(unsigned int jd, int i=0) const
const ClusterParameterEstimator< Phase2TrackerCluster1D > * theCPE
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 PixelDetSet & detSet(int i) const
Phase2OTMeasurementDetSet(const Phase2OTMeasurementConditionSet &cond)
std::vector< std::pair< unsigned int, unsigned int > > stripRegions_
std::vector< int > detIndex_
unsigned int id(int i) const
void update(int i, const Phase2DetSet &detSet)
std::vector< PixelDetSet > detSet_
const SiStripRecHitMatcher * theMatcher
edmNew::DetSet< SiPixelCluster > PixelDetSet
const std::vector< uint32_t > & rawInactiveStripDetIds() const
tuple size
Write out results.
unsigned char subId(int i) const
std::vector< bool > stripUpdated_
bool bad128Strip(int offset) const
note: index is 6*detector index + offset!
#define COUT
const bool stripDefined(int i) const
const Phase2OTMeasurementConditionSet * conditionSet_
std::unordered_map< int, BadFEDChannelPositions > badFEDChannelPositionsSet_
bool isActiveThisPeriod(int i) const
Phase2OTMeasurementConditionSet(const ClusterParameterEstimator< Phase2TrackerCluster1D > *cpe)
const PxMeasurementConditionSet & conditions() const
edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle()