CMS 3D CMS Logo

MeasurementTrackerImpl.cc
Go to the documentation of this file.
2 
5 
11 
13 
15 
21 
23 
28 
31 #include "TkStripMeasurementDet.h"
32 #include "TkPixelMeasurementDet.h"
34 #include "TkGluedMeasurementDet.h"
35 #include "TkStackMeasurementDet.h"
36 
39 
40 #include <iostream>
41 #include <typeinfo>
42 #include <map>
43 #include <algorithm>
44 
45 
46 //
47 
48 using namespace std;
49 
50 namespace {
51 
52  class StrictWeakOrdering{
53  public:
54  bool operator() ( uint32_t p,const uint32_t& i) const {return p < i;}
55  };
56 
57 
58  struct CmpTKD {
59  bool operator()(MeasurementDet const* rh, MeasurementDet const * lh) {
60  return rh->fastGeomDet().geographicalId().rawId() < lh->fastGeomDet().geographicalId().rawId();
61  }
62  bool operator()(MeasurementDet const & rh, MeasurementDet const & lh) {
64  }
65  };
66 
67  template<typename TKD>
68  void sortTKD( std::vector<TKD*> & det) {
69  std::sort(det.begin(),det.end(),CmpTKD());
70  }
71  template<typename TKD>
72  void sortTKD( std::vector<TKD> & det) {
73  std::sort(det.begin(),det.end(),CmpTKD());
74  }
75 
76 }
77 
78 
81  const StripClusterParameterEstimator* stripCPE,
82  const SiStripRecHitMatcher* hitMatcher,
83  const TrackerTopology* trackerTopology,
84  const TrackerGeometry* trackerGeom,
85  const GeometricSearchTracker* geometricSearchTracker,
86  const SiStripQuality *stripQuality,
87  int stripQualityFlags,
88  int stripQualityDebugFlags,
89  const SiPixelQuality *pixelQuality,
90  const SiPixelFedCabling *pixelCabling,
91  int pixelQualityFlags,
92  int pixelQualityDebugFlags,
94  MeasurementTracker(trackerGeom,geometricSearchTracker),
95  pset_(conf),
96  name_(conf.getParameter<std::string>("ComponentName")),
97  theStDetConditions(hitMatcher,stripCPE),
98  thePxDetConditions(pixelCPE),
99  thePhase2DetConditions(phase2OTCPE)
100 {
101  this->initialize(trackerTopology);
102  this->initializeStripStatus(stripQuality, stripQualityFlags, stripQualityDebugFlags);
103  this->initializePixelStatus(pixelQuality, pixelCabling, pixelQualityFlags, pixelQualityDebugFlags);
104 }
105 
107 {
108 }
109 
110 
112 {
113 
114  bool subIsPixel = false;
115  //FIXME:just temporary solution for phase2 :
116  //the OT is defined as PixelSubDetector!
117  bool subIsOT = false;
118 
119  //if the TkGeometry has the subDet vector filled, the theDetMap is filled, otherwise nothing should happen
120  if(!theTrackerGeom->detsPXB().empty()) {
121  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsPXB().front()->geographicalId().subdetId()));
122  addDets(theTrackerGeom->detsPXB(), subIsPixel, subIsOT);
123  }
124 
125  if(!theTrackerGeom->detsPXF().empty()) {
126  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsPXF().front()->geographicalId().subdetId()));
127  addDets(theTrackerGeom->detsPXF(), subIsPixel, subIsOT);
128  }
129 
130  subIsOT = true;
131 
132  if(!theTrackerGeom->detsTIB().empty()) {
133  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTIB().front()->geographicalId().subdetId()));
134  addDets(theTrackerGeom->detsTIB(), subIsPixel, subIsOT);
135  }
136 
137  if(!theTrackerGeom->detsTID().empty()) {
138  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTID().front()->geographicalId().subdetId()));
139  addDets(theTrackerGeom->detsTID(), subIsPixel, subIsOT);
140  }
141 
142  if(!theTrackerGeom->detsTOB().empty()) {
143  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTOB().front()->geographicalId().subdetId()));
144  addDets(theTrackerGeom->detsTOB(), subIsPixel, subIsOT);
145  }
146 
147  if(!theTrackerGeom->detsTEC().empty()) {
148  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTEC().front()->geographicalId().subdetId()));
149  addDets(theTrackerGeom->detsTEC(), subIsPixel, subIsOT);
150  }
151 
152  // fist all stripdets
153  sortTKD(theStripDets);
155  for (unsigned int i=0; i!=theStripDets.size(); ++i)
157 
158  // now the glued dets
159  sortTKD(theGluedDets);
160  for (unsigned int i=0; i!=theGluedDets.size(); ++i)
161  initGluedDet(theGluedDets[i], trackerTopology);
162 
163  // then the pixels
164  sortTKD(thePixelDets);
166  for (unsigned int i=0; i!=thePixelDets.size(); ++i)
168 
169  // then the phase2 dets
170  sortTKD(thePhase2Dets);
172  for (unsigned int i=0; i!=thePhase2Dets.size(); ++i)
174 
175  // and then the stack dets, at last
176  sortTKD(theStackDets);
177  for (unsigned int i=0; i!=theStackDets.size(); ++i)
179 
180  if(!checkDets())
181  throw MeasurementDetException("Number of dets in MeasurementTracker not consistent with TrackerGeometry!");
182 
183 }
184 
185 void MeasurementTrackerImpl::initStMeasurementConditionSet(std::vector<TkStripMeasurementDet> & stripDets)
186 {
187  // assume vector is full and ordered!
188  int size = stripDets.size();
189  theStDetConditions.init(size);
190  for (int i=0; i!=size; ++i) {
191  auto & mdet = stripDets[i];
192  mdet.setIndex(i);
193  //intialize the detId !
194  theStDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
196  //initalize the total number of strips
197  theStDetConditions.totalStrips_[i] = mdet.specificGeomDet().specificTopology().nstrips();
198  }
199 }
200 
201 void MeasurementTrackerImpl::initPxMeasurementConditionSet(std::vector<TkPixelMeasurementDet> & pixelDets)
202 {
203  // assume vector is full and ordered!
204  int size = pixelDets.size();
205  thePxDetConditions.init(size);
206 
207  for (int i=0; i!=size; ++i) {
208  auto & mdet = pixelDets[i];
209  mdet.setIndex(i);
210  thePxDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
211  }
212 }
213 
214 void MeasurementTrackerImpl::initPhase2OTMeasurementConditionSet(std::vector<TkPhase2OTMeasurementDet> & phase2Dets)
215 {
216  // assume vector is full and ordered!
217  int size = phase2Dets.size();
219 
220  for (int i=0; i!=size; ++i) {
221  auto & mdet = phase2Dets[i];
222  mdet.setIndex(i);
223  thePhase2DetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
224  }
225 }
226 
227 void MeasurementTrackerImpl::addDets( const TrackingGeometry::DetContainer& dets, bool subIsPixel, bool subIsOT){
228 
229  //in phase2, we can have composed subDetector made by Pixel or Strip
230  for (TrackerGeometry::DetContainer::const_iterator gd=dets.begin();
231  gd != dets.end(); gd++) {
232 
233  const GeomDetUnit* gdu = dynamic_cast<const GeomDetUnit*>(*gd);
234 
235  //Pixel or Strip GeomDetUnit
236  if (gdu->isLeaf()) {
237  if(subIsPixel) {
238  if(!subIsOT) {
239  addPixelDet(*gd);
240  } else {
241  addPhase2Det(*gd);
242  }
243  } else {
244  addStripDet(*gd);
245  }
246  } else {
247 
248  //Glued or Stack GeomDet
249  const GluedGeomDet* gluedDet = dynamic_cast<const GluedGeomDet*>(*gd);
250  const StackGeomDet* stackDet = dynamic_cast<const StackGeomDet*>(*gd);
251 
252  if ((gluedDet == nullptr && stackDet == nullptr) || (gluedDet != nullptr && stackDet != nullptr)) {
253  throw MeasurementDetException("MeasurementTracker ERROR: GeomDet neither DetUnit nor GluedDet nor StackDet");
254  }
255  if(gluedDet != nullptr)
256  addGluedDet(gluedDet);
257  else
258  addStackDet(stackDet);
259 
260  }
261  }
262 
263 }
264 
266  if(theTrackerGeom->dets().size() == theDetMap.size())
267  return true;
268  return false;
269 }
270 
272 {
273  try {
275  }
276  catch(MeasurementDetException& err){
277  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what() ;
278  }
279 }
280 
282 {
283  try {
285  }
286  catch(MeasurementDetException& err){
287  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what() ;
288  }
289 }
290 
292 {
293  try {
295  }
296  catch(MeasurementDetException& err){
297  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what() ;
298  }
299 }
300 
302 {
304 }
305 
307 {
308  //since the Stack will be composed by PS or 2S,
309  //both cluster parameter estimators are needed? - right now just the thePixelCPE is used.
311 }
312 
314 {
315  const GluedGeomDet& gd = det.specificGeomDet();
316  const MeasurementDet* monoDet = findDet( gd.monoDet()->geographicalId());
317  const MeasurementDet* stereoDet = findDet( gd.stereoDet()->geographicalId());
318  if (monoDet == nullptr || stereoDet == nullptr) {
319  edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: GluedDet components not found as MeasurementDets ";
320  throw MeasurementDetException("MeasurementTracker ERROR: GluedDet components not found as MeasurementDets");
321  }
322  det.init(monoDet, stereoDet, trackerTopology);
323  theDetMap[gd.geographicalId()] = &det;
324 }
325 
327 {
328  const StackGeomDet& gd = det.specificGeomDet();
329  const MeasurementDet* lowerDet = findDet( gd.lowerDet()->geographicalId());
330  const MeasurementDet* upperDet = findDet( gd.upperDet()->geographicalId());
331  if (lowerDet == nullptr || upperDet == nullptr) {
332  edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: StackDet components not found as MeasurementDets ";
333  throw MeasurementDetException("MeasurementTracker ERROR: StackDet components not found as MeasurementDets");
334  }
335  det.init(lowerDet,upperDet);
336  theDetMap[gd.geographicalId()] = &det;
337 }
338 
339 void MeasurementTrackerImpl::initializeStripStatus(const SiStripQuality *quality, int qualityFlags, int qualityDebugFlags) {
340  edm::ParameterSet cutPset = pset_.getParameter<edm::ParameterSet>("badStripCuts");
341  if (qualityFlags & BadStrips) {
342  typedef StMeasurementConditionSet::BadStripCuts BadStripCuts;
347  }
349 
350 
351  if ((quality != nullptr) && (qualityFlags != 0)) {
352  edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
353  unsigned int on = 0, tot = 0;
354  unsigned int foff = 0, ftot = 0, aoff = 0, atot = 0;
355  for (int i=0; i!= theStDetConditions.nDet(); i++) {
356  uint32_t detid = theStDetConditions.id(i);
357  if (qualityFlags & BadModules) {
358  bool isOn = quality->IsModuleUsable(detid);
360  tot++; on += (unsigned int) isOn;
361  if (qualityDebugFlags & BadModules) {
362  edm::LogInfo("MeasurementTracker")<< "MeasurementTrackerImpl::initializeStripStatus : detid " << detid << " is " << (isOn ? "on" : "off");
363  }
364  } else {
366  }
367  // first turn all APVs and fibers ON
369  if (qualityFlags & BadAPVFibers) {
370  short badApvs = quality->getBadApvs(detid);
371  short badFibers = quality->getBadFibers(detid);
372  for (int j = 0; j < 6; j++) {
373  atot++;
374  if (badApvs & (1 << j)) {
376  aoff++;
377  }
378  }
379  for (int j = 0; j < 3; j++) {
380  ftot++;
381  if (badFibers & (1 << j)) {
383  theStDetConditions.set128StripStatus(i,false, 2*j+1);
384  foff++;
385  }
386  }
387  }
388  auto & badStrips = theStDetConditions.getBadStripBlocks(i);
389  badStrips.clear();
390  if (qualityFlags & BadStrips) {
391  SiStripBadStrip::Range range = quality->getRange(detid);
392  for (SiStripBadStrip::ContainerIterator bit = range.first; bit != range.second; ++bit) {
393  badStrips.push_back(quality->decode(*bit));
394  }
395  }
396  }
397  if (qualityDebugFlags & BadModules) {
398  edm::LogInfo("MeasurementTracker StripModuleStatus") <<
399  " Total modules: " << tot << ", active " << on <<", inactive " << (tot - on);
400  }
401  if (qualityDebugFlags & BadAPVFibers) {
402  edm::LogInfo("MeasurementTracker StripAPVStatus") <<
403  " Total APVs: " << atot << ", active " << (atot-aoff) <<", inactive " << (aoff);
404  edm::LogInfo("MeasurementTracker StripFiberStatus") <<
405  " Total Fibers: " << ftot << ", active " << (ftot-foff) <<", inactive " << (foff);
406  }
407  } else {
408  for (int i=0; i!=theStDetConditions.nDet(); i++) {
409  theStDetConditions.setActive(i,true); // module ON
410  theStDetConditions.set128StripStatus(i,true); // all APVs and fibers ON
411  }
412  }
413 
414 }
415 
416 void MeasurementTrackerImpl::initializePixelStatus(const SiPixelQuality *quality, const SiPixelFedCabling *pixelCabling, int qualityFlags, int qualityDebugFlags) {
417  if ((quality != nullptr) && (qualityFlags != 0)) {
418  edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
419  unsigned int on = 0, tot = 0, badrocs = 0;
420  for (std::vector<TkPixelMeasurementDet>::iterator i=thePixelDets.begin();
421  i!=thePixelDets.end(); i++) {
422  uint32_t detid = ((*i).geomDet().geographicalId()).rawId();
423  if (qualityFlags & BadModules) {
424  bool isOn = quality->IsModuleUsable(detid);
425  (i)->setActive(isOn);
426  tot++; on += (unsigned int) isOn;
427  if (qualityDebugFlags & BadModules) {
428  edm::LogInfo("MeasurementTracker")<< "MeasurementTrackerImpl::initializePixelStatus : detid " << detid << " is " << (isOn ? "on" : "off");
429  }
430  } else {
431  (i)->setActive(true);
432  }
433  if ((qualityFlags & BadROCs) && (quality->getBadRocs(detid) != 0)) {
434  std::vector<LocalPoint> badROCs = quality->getBadRocPositions(detid, *theTrackerGeom, pixelCabling);
435  badrocs += badROCs.size();
436  (i)->setBadRocPositions(badROCs);
437  } else {
438  (i)->clearBadRocPositions();
439  }
440  }
441  if (qualityDebugFlags & BadModules) {
442  edm::LogInfo("MeasurementTracker PixelModuleStatus") <<
443  " Total modules: " << tot << ", active " << on <<", inactive " << (tot - on);
444  }
445  if (qualityDebugFlags & BadROCs) {
446  edm::LogInfo("MeasurementTracker PixelROCStatus") << " Total of bad ROCs: " << badrocs ;
447  }
448  } else {
449  for (std::vector<TkPixelMeasurementDet>::iterator i=thePixelDets.begin();
450  i!=thePixelDets.end(); i++) {
451  (i)->setActive(true); // module ON
452  }
453  }
454 }
455 
size
Write out results.
const GeomDetUnit * lowerDet() const
Definition: StackGeomDet.h:20
T getParameter(std::string const &) const
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
short getBadFibers(const uint32_t &detid) const
void addStripDet(const GeomDet *gd)
void addStackDet(const StackGeomDet *gd)
unsigned int id(int i) const
std::vector< TkStripMeasurementDet > theStripDets
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
const MeasurementDet * findDet(const DetId &id) const
std::vector< TkStackMeasurementDet > theStackDets
StMeasurementConditionSet theStDetConditions
std::vector< unsigned int >::const_iterator ContainerIterator
void initializeStripStatus(const SiStripQuality *stripQuality, int qualityFlags, int qualityDebugFlags)
void addDets(const TrackingGeometry::DetContainer &dets, bool subIsPixel, bool subIsOT)
const TrackerGeometry * theTrackerGeom
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
char const * what() const override
Definition: Exception.cc:103
bool int lh
Definition: SIMDVec.h:21
std::vector< TkPhase2OTMeasurementDet > thePhase2Dets
MeasurementTrackerImpl(const edm::ParameterSet &conf, const PixelClusterParameterEstimator *pixelCPE, const StripClusterParameterEstimator *stripCPE, const SiStripRecHitMatcher *hitMatcher, const TrackerTopology *trackerTopology, const TrackerGeometry *trackerGeom, const GeometricSearchTracker *geometricSearchTracker, const SiStripQuality *stripQuality, int stripQualityFlags, int stripQualityDebugFlags, const SiPixelQuality *pixelQuality, const SiPixelFedCabling *pixelCabling, int pixelQualityFlags, int pixelQualityDebugFlags, const ClusterParameterEstimator< Phase2TrackerCluster1D > *phase2OTCPE=0)
unsigned int id(int i) const
void addPixelDet(const GeomDet *gd)
const GeomDet & fastGeomDet() const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
void init(const MeasurementDet *lowerDet, const MeasurementDet *upperDet)
std::vector< unsigned char > subId_
unsigned int id(int i) const
void initGluedDet(TkGluedMeasurementDet &det, const TrackerTopology *trackerTopology)
const SiStripRecHitMatcher * matcher() const
const DetContainer & detsTEC() const
const std::vector< TkStripMeasurementDet > & stripDets() const
short getBadApvs(const uint32_t &detid) const
bool IsModuleUsable(const uint32_t &detid) const
std::vector< TkPixelMeasurementDet > thePixelDets
void initializePixelStatus(const SiPixelQuality *stripQuality, const SiPixelFedCabling *pixelCabling, int qualityFlags, int qualityDebugFlags)
const std::vector< LocalPoint > getBadRocPositions(const uint32_t &detid, const TrackerGeometry &theTracker, const SiPixelFedCabling *map) const
void initPhase2OTMeasurementConditionSet(std::vector< TkPhase2OTMeasurementDet > &phase2Dets)
void setActive(int i, bool active)
Turn on/off the module for reconstruction, for the full run or lumi (using info from DB...
const GluedGeomDet & specificGeomDet() const
std::vector< BadStripBlock > & getBadStripBlocks(int i)
void initialize(const TrackerTopology *trackerTopology)
void initStMeasurementConditionSet(std::vector< TkStripMeasurementDet > &stripDets)
const DetContainer & detsPXB() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
const StripClusterParameterEstimator * stripCPE() const
virtual bool isLeaf() const
is a Unit
Definition: GeomDet.h:85
const edm::ParameterSet & pset_
std::vector< unsigned int > id_
const std::vector< TkPixelMeasurementDet > & pixelDets() const
bool IsModuleUsable(const uint32_t &detid) const
std::vector< int > totalStrips_
const DetContainer & detsTIB() const
void addPhase2Det(const GeomDet *gd)
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
void setMaskBad128StripBlocks(bool maskThem)
std::vector< unsigned int > id_
void addGluedDet(const GluedGeomDet *gd)
std::vector< unsigned int > id_
std::vector< TkGluedMeasurementDet > theGluedDets
short getBadRocs(const uint32_t &detid) const
void init(const MeasurementDet *monoDet, const MeasurementDet *stereoDet, const TrackerTopology *tTopo)
PxMeasurementConditionSet thePxDetConditions
Phase2OTMeasurementConditionSet thePhase2DetConditions
std::vector< const GeomDet * > DetContainer
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
const GeomDetUnit * upperDet() const
Definition: StackGeomDet.h:21
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
const StackGeomDet & specificGeomDet() const
const PixelClusterParameterEstimator * pixelCPE() const
void initPxMeasurementConditionSet(std::vector< TkPixelMeasurementDet > &pixelDets)
void set128StripStatus(int i, bool good, int idx=-1)
void initStackDet(TkStackMeasurementDet &det)
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
data decode(const unsigned int &value) const
const DetContainer & detsTID() const