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 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  if (!checkDets())
176  throw MeasurementDetException("Number of dets in MeasurementTracker not consistent with TrackerGeometry!");
177 }
178 
179 void MeasurementTrackerImpl::initStMeasurementConditionSet(std::vector<TkStripMeasurementDet>& stripDets) {
180  // assume vector is full and ordered!
181  int size = stripDets.size();
183  for (int i = 0; i != size; ++i) {
184  auto& mdet = stripDets[i];
185  mdet.setIndex(i);
186  //intialize the detId !
187  theStDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
189  //initalize the total number of strips
190  theStDetConditions.totalStrips_[i] = mdet.specificGeomDet().specificTopology().nstrips();
191  }
192 }
193 
194 void MeasurementTrackerImpl::initPxMeasurementConditionSet(std::vector<TkPixelMeasurementDet>& pixelDets) {
195  // assume vector is full and ordered!
196  int size = pixelDets.size();
198 
199  for (int i = 0; i != size; ++i) {
200  auto& mdet = pixelDets[i];
201  mdet.setIndex(i);
202  thePxDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
203  }
204 }
205 
206 void MeasurementTrackerImpl::initPhase2OTMeasurementConditionSet(std::vector<TkPhase2OTMeasurementDet>& phase2Dets) {
207  // assume vector is full and ordered!
208  int size = phase2Dets.size();
210 
211  for (int i = 0; i != size; ++i) {
212  auto& mdet = phase2Dets[i];
213  mdet.setIndex(i);
214  thePhase2DetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
215  }
216 }
217 
218 void MeasurementTrackerImpl::addDets(const TrackingGeometry::DetContainer& dets, bool subIsPixel, bool subIsOT) {
219  //in phase2, we can have composed subDetector made by Pixel or Strip
220  for (TrackerGeometry::DetContainer::const_iterator gd = dets.begin(); gd != dets.end(); gd++) {
221  const GeomDetUnit* gdu = dynamic_cast<const GeomDetUnit*>(*gd);
222 
223  //Pixel or Strip GeomDetUnit
224  if (gdu->isLeaf()) {
225  if (subIsPixel) {
226  if (!subIsOT) {
227  addPixelDet(*gd);
228  } else {
229  addPhase2Det(*gd);
230  }
231  } else {
232  addStripDet(*gd);
233  }
234  } else {
235  //Glued or Stack GeomDet
236  const GluedGeomDet* gluedDet = dynamic_cast<const GluedGeomDet*>(*gd);
237  const StackGeomDet* stackDet = dynamic_cast<const StackGeomDet*>(*gd);
238 
239  if ((gluedDet == nullptr && stackDet == nullptr) || (gluedDet != nullptr && stackDet != nullptr)) {
240  throw MeasurementDetException("MeasurementTracker ERROR: GeomDet neither DetUnit nor GluedDet nor StackDet");
241  }
242  if (gluedDet != nullptr)
243  addGluedDet(gluedDet);
244  else
245  addStackDet(stackDet);
246  }
247  }
248 }
249 
251  if (theTrackerGeom->dets().size() == theDetMap.size())
252  return true;
253  return false;
254 }
255 
257  try {
259  } catch (MeasurementDetException& err) {
260  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what();
261  }
262 }
263 
265  try {
267  } catch (MeasurementDetException& err) {
268  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what();
269  }
270 }
271 
273  try {
275  } catch (MeasurementDetException& err) {
276  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what();
277  }
278 }
279 
282 }
283 
285  //since the Stack will be composed by PS or 2S,
286  //both cluster parameter estimators are needed? - right now just the thePixelCPE is used.
288 }
289 
291  const GluedGeomDet& gd = det.specificGeomDet();
292  const MeasurementDet* monoDet = findDet(gd.monoDet()->geographicalId());
293  const MeasurementDet* stereoDet = findDet(gd.stereoDet()->geographicalId());
294  if (monoDet == nullptr || stereoDet == nullptr) {
295  edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: GluedDet components not found as MeasurementDets ";
296  throw MeasurementDetException("MeasurementTracker ERROR: GluedDet components not found as MeasurementDets");
297  }
298  det.init(monoDet, stereoDet, trackerTopology);
299  theDetMap[gd.geographicalId()] = &det;
300 }
301 
303  const StackGeomDet& gd = det.specificGeomDet();
304  const MeasurementDet* lowerDet = findDet(gd.lowerDet()->geographicalId());
305  const MeasurementDet* upperDet = findDet(gd.upperDet()->geographicalId());
306  if (lowerDet == nullptr || upperDet == nullptr) {
307  edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: StackDet components not found as MeasurementDets ";
308  throw MeasurementDetException("MeasurementTracker ERROR: StackDet components not found as MeasurementDets");
309  }
310  det.init(lowerDet, upperDet);
311  theDetMap[gd.geographicalId()] = &det;
312 }
313 
315  const SiStripQuality* quality,
316  int qualityFlags,
317  int qualityDebugFlags) {
318  if (qualityFlags & BadStrips) {
323  }
325 
326  if ((quality != nullptr) && (qualityFlags != 0)) {
327  edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
328  unsigned int on = 0, tot = 0;
329  unsigned int foff = 0, ftot = 0, aoff = 0, atot = 0;
330  for (int i = 0; i != theStDetConditions.nDet(); i++) {
331  uint32_t detid = theStDetConditions.id(i);
332  if (qualityFlags & BadModules) {
333  bool isOn = quality->IsModuleUsable(detid);
335  tot++;
336  on += (unsigned int)isOn;
337  if (qualityDebugFlags & BadModules) {
338  edm::LogInfo("MeasurementTracker")
339  << "MeasurementTrackerImpl::initializeStripStatus : detid " << detid << " is " << (isOn ? "on" : "off");
340  }
341  } else {
343  }
344  // first turn all APVs and fibers ON
346  if (qualityFlags & BadAPVFibers) {
347  short badApvs = quality->getBadApvs(detid);
348  short badFibers = quality->getBadFibers(detid);
349  for (int j = 0; j < 6; j++) {
350  atot++;
351  if (badApvs & (1 << j)) {
353  aoff++;
354  }
355  }
356  for (int j = 0; j < 3; j++) {
357  ftot++;
358  if (badFibers & (1 << j)) {
360  theStDetConditions.set128StripStatus(i, false, 2 * j + 1);
361  foff++;
362  }
363  }
364  }
365  auto& badStrips = theStDetConditions.getBadStripBlocks(i);
366  badStrips.clear();
367  if (qualityFlags & BadStrips) {
368  SiStripBadStrip::Range range = quality->getRange(detid);
369  for (SiStripBadStrip::ContainerIterator bit = range.first; bit != range.second; ++bit) {
370  badStrips.push_back(quality->decode(*bit));
371  }
372  }
373  }
374  if (qualityDebugFlags & BadModules) {
375  edm::LogInfo("MeasurementTracker StripModuleStatus")
376  << " Total modules: " << tot << ", active " << on << ", inactive " << (tot - on);
377  }
378  if (qualityDebugFlags & BadAPVFibers) {
379  edm::LogInfo("MeasurementTracker StripAPVStatus")
380  << " Total APVs: " << atot << ", active " << (atot - aoff) << ", inactive " << (aoff);
381  edm::LogInfo("MeasurementTracker StripFiberStatus")
382  << " Total Fibers: " << ftot << ", active " << (ftot - foff) << ", inactive " << (foff);
383  }
384  } else {
385  for (int i = 0; i != theStDetConditions.nDet(); i++) {
386  theStDetConditions.setActive(i, true); // module ON
387  theStDetConditions.set128StripStatus(i, true); // all APVs and fibers ON
388  }
389  }
390 }
391 
393  const SiPixelFedCabling* pixelCabling,
394  int qualityFlags,
395  int qualityDebugFlags) {
396  if ((quality != nullptr) && (qualityFlags != 0)) {
397  edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
398  unsigned int on = 0, tot = 0, badrocs = 0;
399  for (std::vector<TkPixelMeasurementDet>::iterator i = thePixelDets.begin(); i != thePixelDets.end(); i++) {
400  uint32_t detid = ((*i).geomDet().geographicalId()).rawId();
401  if (qualityFlags & BadModules) {
402  bool isOn = quality->IsModuleUsable(detid);
403  (i)->setActive(isOn);
404  tot++;
405  on += (unsigned int)isOn;
406  if (qualityDebugFlags & BadModules) {
407  edm::LogInfo("MeasurementTracker")
408  << "MeasurementTrackerImpl::initializePixelStatus : detid " << detid << " is " << (isOn ? "on" : "off");
409  }
410  } else {
411  (i)->setActive(true);
412  }
413  if ((qualityFlags & BadROCs) && (quality->getBadRocs(detid) != 0)) {
414  std::vector<LocalPoint> badROCs = quality->getBadRocPositions(detid, *theTrackerGeom, pixelCabling);
415  badrocs += badROCs.size();
416  (i)->setBadRocPositions(badROCs);
417  } else {
418  (i)->clearBadRocPositions();
419  }
420  }
421  if (qualityDebugFlags & BadModules) {
422  edm::LogInfo("MeasurementTracker PixelModuleStatus")
423  << " Total modules: " << tot << ", active " << on << ", inactive " << (tot - on);
424  }
425  if (qualityDebugFlags & BadROCs) {
426  edm::LogInfo("MeasurementTracker PixelROCStatus") << " Total of bad ROCs: " << badrocs;
427  }
428  } else {
429  for (std::vector<TkPixelMeasurementDet>::iterator i = thePixelDets.begin(); i != thePixelDets.end(); i++) {
430  (i)->setActive(true); // module ON
431  }
432  }
433 }
size
Write out results.
const DetContainer & detsTIB() const
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
std::vector< TkStripMeasurementDet > theStripDets
const DetContainer & detsPXB() const
std::vector< TkStackMeasurementDet > theStackDets
StMeasurementConditionSet theStDetConditions
static constexpr auto TID
Definition: SiStripDetId.h:38
const GeomDetUnit * upperDet() const
Definition: StackGeomDet.h:20
unsigned int id(int i) const
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
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< 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)
void set128StripStatus(int i, bool good, int idx=-1)
string quality
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