CMS 3D CMS Logo

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