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 <unordered_map>
26 
27 // #define VISTAT
28 
29 #ifdef VISTAT
30 #include<iostream>
31 #define COUT std::cout
32 #else
33 #define COUT LogDebug("")
34 #endif
35 
36 /* Struct of arrays supporting "members of Tk...MeasurementDet
37  * implemented with vectors, to be optimized...
38  ITEMS THAT DO NOT DEPEND ON THE EVENT
39  */
41 public:
42  enum QualityFlags { BadModules=1, // for everybody
44  /* Pixels: */ BadROCs=2 };
45 
46  struct BadStripCuts {
49  maxBad(pset.getParameter<uint32_t>("maxBad")),
50  maxConsecutiveBad(pset.getParameter<uint32_t>("maxConsecutiveBad")) {}
52  };
53 
54  struct BadStripBlock {
55  short first;
56  short last;
57  BadStripBlock(const SiStripBadStrip::data &data) : first(data.firstStrip), last(data.firstStrip+data.range-1) { }
58  };
59 
60 
63  theMatcher(matcher), theCPE(cpe){}
64 
65 
66  void init(int size);
67 
68  const SiStripRecHitMatcher* matcher() const { return theMatcher;}
70 
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 {
77  return std::lower_bound(id_.begin()+i,id_.end(),jd)-id_.begin();
78  }
79 
80  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
81 
82 
84  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
85 
86  int totalStrips(int i) const { return totalStrips_[i];}
87 
88  void setMaskBad128StripBlocks(bool maskThem) { maskBad128StripBlocks_ = maskThem; }
89  const BadStripCuts & badStripCuts(int i) const { return badStripCuts_[subId_[i]];}
90 
92  bool hasAny128StripBad(int i) const { return hasAny128StripBad_[i];}
93 
95  bool bad128Strip(int offset) const { return bad128Strip_[offset];}
96  bool bad128Strip(int index, int strip) const { return bad128Strip_[nbad128*index+(strip>>7)];}
97 
98  std::vector<BadStripBlock> & getBadStripBlocks(int i) { return badStripBlocks_[i]; }
99  std::vector<BadStripBlock> const & badStripBlocks(int i) const {return badStripBlocks_[i]; }
100 
101  bool isMasked(int i, const SiStripCluster &cluster) const {
102  int offset = nbad128*i;
103  if ( bad128Strip_[offset+( cluster.firstStrip() >> 7)] ) {
104  if ( bad128Strip_[offset+( (cluster.firstStrip()+cluster.amplitudes().size()) >> 7)] ||
105  bad128Strip_[offset+( static_cast<int32_t>(cluster.barycenter()-0.499999) >> 7)] ) {
106  return true;
107  }
108  } else {
109  if ( bad128Strip_[offset+( (cluster.firstStrip()+cluster.amplitudes().size()) >> 7)] &&
110  bad128Strip_[offset+( static_cast<int32_t>(cluster.barycenter()-0.499999) >> 7)] ) {
111  return true;
112  }
113  }
114  return false;
115  }
116 
117 
118  void set128StripStatus(int i, bool good, int idx=-1);
119 
120 private:
121 
123 
124  // globals
127 
130 
131  // members of TkStripMeasurementDet
132  std::vector<unsigned int> id_;
133  std::vector<unsigned char> subId_;
134 
135  std::vector<int> totalStrips_;
136 
137  static const int nbad128 = 6;
138  std::vector<bool> bad128Strip_;
139  std::vector<bool> hasAny128StripBad_;
140 
141  std::vector<std::vector<BadStripBlock>> badStripBlocks_;
142 
143  std::vector<bool> activeThisPeriod_;
144 };
145 
147 public:
148 
151 
152 
154  conditionSet_(&cond),
155  empty_(cond.nDet(), true),
156  activeThisEvent_(cond.nDet(), true),
157  detSet_(cond.nDet()),
158  detIndex_(cond.nDet(),-1),
159  ready_(cond.nDet(),true),
160  theRawInactiveStripDetIds_(),
161  stripDefined_(0),
162  stripUpdated_(0),
163  stripRegions_(0)
164  {
165  }
166 
168  printStat();
169  }
170 
171  const StMeasurementConditionSet & conditions() const { return *conditionSet_; }
172 
173 
174  void update(int i,const StripDetset & detSet ) {
175  detSet_[i] = detSet;
176  empty_[i] = false;
177  }
178 
179  void update(int i, int j ) {
180  assert(j>=0); assert(empty_[i]); assert(ready_[i]);
181  detIndex_[i] = j;
182  empty_[i] = false;
183  incReady();
184  }
185 
186  int size() const { return conditions().nDet(); }
187  int nDet() const { return size();}
188  unsigned int id(int i) const { return conditions().id(i); }
189  int find(unsigned int jd, int i=0) const {
190  return conditions().find(jd,i);
191  }
192 
193  bool empty(int i) const { return empty_[i];}
194  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
195 
196  void setEmpty(int i) {empty_[i] = true; activeThisEvent_[i] = true; }
197  void setUpdated(int i) { stripUpdated_[i] = true; }
198 
199  void setEmpty() {
200  printStat();
201  std::fill(empty_.begin(),empty_.end(),true);
202  std::fill(ready_.begin(),ready_.end(),true);
203  std::fill(detIndex_.begin(),detIndex_.end(),-1);
204  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(),true);
205  incTot(size());
206  }
207 
210  void setActiveThisEvent(int i, bool active) { activeThisEvent_[i] = active; if (!active) empty_[i] = true; }
211 
213  const edm::Handle<edmNew::DetSetVector<SiStripCluster> > & handle() const { return handle_; }
214  // StripDetset & detSet(int i) { return detSet_[i]; }
215  const StripDetset & detSet(int i) const { if (ready_[i]) const_cast<StMeasurementDetSet*>(this)->getDetSet(i); return detSet_[i]; }
216 
217 
219  std::vector<uint32_t> & rawInactiveStripDetIds() { return theRawInactiveStripDetIds_; }
220  const std::vector<uint32_t> & rawInactiveStripDetIds() const { return theRawInactiveStripDetIds_; }
221 
222  void resetOnDemandStrips() { std::fill(stripDefined_.begin(), stripDefined_.end(), false); std::fill(stripUpdated_.begin(), stripUpdated_.end(), false); }
223  const bool stripDefined(int i) const { return stripDefined_[i]; }
224  const bool stripUpdated(int i) const { return stripUpdated_[i]; }
225  void defineStrip(int i, std::pair<unsigned int, unsigned int> range) {
226  stripDefined_[i] = true;
227  stripUpdated_[i] = false;
228  stripRegions_[i] = range;
229  }
230 
231 private:
232 
233  void getDetSet(int i) {
234  if(detIndex_[i]>=0) {
235  detSet_[i].set(*handle_,handle_->item(detIndex_[i]));
236  empty_[i]=false; // better be false already
237  incAct();
238  } else { // we should not be here
239  detSet_[i] = StripDetset();
240  empty_[i]=true;
241  }
242  ready_[i]=false;
243  incSet();
244  }
245 
246 
248 
250 
251 
252  // Globals, per-event
254 
255 
256  std::vector<bool> empty_;
257  std::vector<bool> activeThisEvent_;
258 
259  // full reco
260  std::vector<StripDetset> detSet_;
261  std::vector<int> detIndex_;
262  std::vector<bool> ready_; // to be cleaned
263 
264 
265  // note: not aligned to the index
266  std::vector<uint32_t> theRawInactiveStripDetIds_;
267  // keyed on si-strip index
268  std::vector<bool> stripDefined_, stripUpdated_;
269  std::vector<std::pair<unsigned int, unsigned int> > stripRegions_;
270  // keyed on glued
271  // std::vector<bool> gluedUpdated_;
272 
273 
274 
275 #ifdef VISTAT
276  struct Stat {
277  int totDet=0; // all dets
278  int detReady=0; // dets "updated"
279  int detSet=0; // det actually set not empty
280  int detAct=0; // det actually set with content
281  };
282 
283  mutable Stat stat;
284  void zeroStat() const { stat = Stat(); }
285  void incTot(int n) const { stat.totDet=n;}
286  void incReady() const { stat.detReady++;}
287  void incSet() const { stat.detSet++;}
288  void incAct() const { stat.detAct++;}
289  void printStat() const {
290  COUT << "VI detsets " << stat.totDet <<','<< stat.detReady <<','<< stat.detSet <<','<< stat.detAct << std::endl;
291  }
292 
293 #else
294  static void zeroStat(){}
295  static void incTot(int){}
296  static void incReady() {}
297  static void incSet() {}
298  static void incAct() {}
299  static void printStat(){}
300 #endif
301 
302 };
303 
305 public:
307  theCPE(cpe) {}
308 
309  void init(int size);
310 
311  int nDet() const { return id_.size();}
312  unsigned int id(int i) const { return id_[i]; }
313  int find(unsigned int jd, int i=0) const {
314  return std::lower_bound(id_.begin()+i,id_.end(),jd)-id_.begin();
315  }
316 
318  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
319 
322  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
323 
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 };
336 
337 
339 public:
342  typedef std::vector<std::pair<LocalPoint,LocalPoint> > BadFEDChannelPositions;
343 
345  conditionSet_(&cond),
346  detSet_(cond.nDet()),
347  empty_(cond.nDet(), true),
348  activeThisEvent_(cond.nDet(), true) {}
349 
350  const PxMeasurementConditionSet & conditions() const { return *conditionSet_; }
351 
352  int size() const { return conditions().nDet(); }
353  int nDet() const { return size();}
354  unsigned int id(int i) const { return conditions().id(i); }
355  int find(unsigned int jd, int i=0) const {
356  return conditions().find(jd,i);
357  }
358 
359  void update(int i,const PixelDetSet & detSet ) {
360  detSet_[i] = detSet;
361  empty_[i] = false;
362  }
363 
364  bool empty(int i) const { return empty_[i];}
365  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
366 
367  void setEmpty(int i) {
368  empty_[i] = true;
369  activeThisEvent_[i] = true;
370  auto found = badFEDChannelPositionsSet_.find(i);
371  if(found != badFEDChannelPositionsSet_.end()) {
372  badFEDChannelPositionsSet_.erase(found);
373  }
374  }
375 
376  void setEmpty() {
377  std::fill(empty_.begin(),empty_.end(),true);
378  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(),true);
379  badFEDChannelPositionsSet_.clear();
380  }
381  void setActiveThisEvent(bool active) {
382  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(),active);
383  }
384 
385  const BadFEDChannelPositions* getBadFEDChannelPositions(int i) const {
386  auto found = badFEDChannelPositionsSet_.find(i);
387  if(found == badFEDChannelPositionsSet_.end())
388  return nullptr;
389  return &(found->second);
390  }
391  void addBadFEDChannelPositions(int i, BadFEDChannelPositions& positions) {
392  auto found = badFEDChannelPositionsSet_.find(i);
393  if(found == badFEDChannelPositionsSet_.end()) {
394  badFEDChannelPositionsSet_.emplace(i, positions);
395  }
396  else {
397  found->second.insert(found->second.end(), positions.begin(), positions.end());
398  }
399  }
400 
403  void setActiveThisEvent(int i, bool active) { activeThisEvent_[i] = active; if (!active) empty_[i] = true; }
404  const edm::Handle<edmNew::DetSetVector<SiPixelCluster> > & handle() const { return handle_;}
406  const PixelDetSet & detSet(int i) const { return detSet_[i];}
407 private:
409 
411 
412  // Globals, per-event
414 
415  // Locals, per-event
416  std::vector<PixelDetSet> detSet_;
417  std::vector<bool> empty_;
418  std::vector<bool> activeThisEvent_;
419  std::unordered_map<int, BadFEDChannelPositions> badFEDChannelPositionsSet_;
420 };
421 
422 //FIXME:just temporary solution for phase2 OT that works!
424 public:
426  theCPE(cpe) {}
427 
428  void init(int size);
429 
430  int nDet() const { return id_.size();}
431  unsigned int id(int i) const { return id_[i]; }
432  int find(unsigned int jd, int i=0) const {
433  return std::lower_bound(id_.begin()+i,id_.end(),jd)-id_.begin();
434  }
435 
437  bool isActiveThisPeriod(int i) const { return activeThisPeriod_[i]; }
438 
441  void setActive(int i, bool active) { activeThisPeriod_[i] = active; }
442 
443 
444 private:
446 
447  // Globals (not-per-event)
449 
450  // Locals, per-event
451  std::vector<unsigned int> id_;
452  std::vector<bool> activeThisPeriod_;
453 
454 };
455 
457 public:
460 
462  conditionSet_(&cond),
463  detSet_(cond.nDet()),
464  empty_(cond.nDet(), true),
465  activeThisEvent_(cond.nDet(), true) {}
466 
467  const Phase2OTMeasurementConditionSet & conditions() const { return *conditionSet_; }
468 
469  int size() const { return conditions().nDet(); }
470  int nDet() const { return size();}
471  unsigned int id(int i) const { return conditions().id(i); }
472  int find(unsigned int jd, int i=0) const {
473  return conditions().find(jd,i);
474  }
475 
476  void update(int i,const Phase2DetSet & detSet ) {
477  detSet_[i] = detSet;
478  empty_[i] = false;
479  }
480 
481  bool empty(int i) const { return empty_[i];}
482  bool isActive(int i) const { return activeThisEvent_[i] && conditions().isActiveThisPeriod(i); }
483 
484  void setEmpty(int i) {empty_[i] = true; activeThisEvent_[i] = true; }
485 
486  void setEmpty() {
487  std::fill(empty_.begin(),empty_.end(),true);
488  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(),true);
489  }
490  void setActiveThisEvent(bool active) {
491  std::fill(activeThisEvent_.begin(), activeThisEvent_.end(),active);
492  }
493  void setActiveThisEvent(int i, bool active) { activeThisEvent_[i] = active; if (!active) empty_[i] = true; }
496  const Phase2DetSet & detSet(int i) const { return detSet_[i];}
497 private:
499 
501 
502  //Globals, per-event
504 
505  // Locals, per-event
506  std::vector<Phase2DetSet> detSet_;
507  std::vector<bool> empty_;
508  std::vector<bool> activeThisEvent_;
509 };
510 
511 #endif // StMeasurementDetSet_H
bool isMasked(int i, const SiStripCluster &cluster) const
size
Write out results.
edmNew::DetSet< Phase2TrackerCluster1D > Phase2DetSet
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
StMeasurementDetSet(const StMeasurementConditionSet &cond)
void update(int i, int j)
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:30
const edm::Handle< edmNew::DetSetVector< SiPixelCluster > > & handle() const
bool isActiveThisPeriod(int i) const
std::vector< std::pair< LocalPoint, LocalPoint > > BadFEDChannelPositions
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
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
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_
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.
BadStripCuts(const edm::ParameterSet &pset)
Definition: plugin.cc:24
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static void incTot(int)
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
unsigned char subId(int i) const
const std::vector< uint8_t > & amplitudes() 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()