File indexing completed on 2024-09-15 23:07:00
0001 #include "MeasurementTrackerImpl.h"
0002
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005
0006 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0007 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0008 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0009 #include "Geometry/CommonDetUnit/interface/StackGeomDet.h"
0010 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0011
0012 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0013
0014 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0015 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0016 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0017 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
0018 #include "DataFormats/Common/interface/ContainerMask.h"
0019
0020 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
0021
0022 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
0023 #include "RecoLocalTracker/Records/interface/TrackerCPERecord.h"
0024 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
0025 #include "RecoLocalTracker/SiStripRecHitConverter/interface/StripCPE.h"
0026
0027 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
0028 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
0029 #include "TkStripMeasurementDet.h"
0030 #include "TkPixelMeasurementDet.h"
0031 #include "TkPhase2OTMeasurementDet.h"
0032 #include "TkGluedMeasurementDet.h"
0033 #include "TkStackMeasurementDet.h"
0034
0035 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0036 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
0037
0038 #include <iostream>
0039 #include <typeinfo>
0040 #include <map>
0041 #include <algorithm>
0042
0043
0044
0045 using namespace std;
0046
0047 namespace {
0048
0049 class StrictWeakOrdering {
0050 public:
0051 bool operator()(uint32_t p, const uint32_t& i) const { return p < i; }
0052 };
0053
0054 struct CmpTKD {
0055 bool operator()(MeasurementDet const* rh, MeasurementDet const* lh) {
0056 return rh->fastGeomDet().geographicalId().rawId() < lh->fastGeomDet().geographicalId().rawId();
0057 }
0058 bool operator()(MeasurementDet const& rh, MeasurementDet const& lh) {
0059 return rh.fastGeomDet().geographicalId().rawId() < lh.fastGeomDet().geographicalId().rawId();
0060 }
0061 };
0062
0063 template <typename TKD>
0064 void sortTKD(std::vector<TKD*>& det) {
0065 std::sort(det.begin(), det.end(), CmpTKD());
0066 }
0067 template <typename TKD>
0068 void sortTKD(std::vector<TKD>& det) {
0069 std::sort(det.begin(), det.end(), CmpTKD());
0070 }
0071
0072 }
0073
0074 MeasurementTrackerImpl::MeasurementTrackerImpl(const BadStripCutsDet& badStripCuts,
0075 const PixelClusterParameterEstimator* pixelCPE,
0076 const StripClusterParameterEstimator* stripCPE,
0077 const SiStripRecHitMatcher* hitMatcher,
0078 const TrackerTopology* trackerTopology,
0079 const TrackerGeometry* trackerGeom,
0080 const GeometricSearchTracker* geometricSearchTracker,
0081 const SiStripQuality* stripQuality,
0082 int stripQualityFlags,
0083 int stripQualityDebugFlags,
0084 const SiPixelQuality* pixelQuality,
0085 const SiPixelFedCabling* pixelCabling,
0086 int pixelQualityFlags,
0087 int pixelQualityDebugFlags,
0088 const ClusterParameterEstimator<Phase2TrackerCluster1D>* phase2OTCPE)
0089 : MeasurementTracker(trackerGeom, geometricSearchTracker),
0090 theStDetConditions(hitMatcher, stripCPE),
0091 thePxDetConditions(pixelCPE),
0092 thePhase2DetConditions(phase2OTCPE) {
0093 this->initialize(trackerTopology);
0094 this->initializeStripStatus(badStripCuts, stripQuality, stripQualityFlags, stripQualityDebugFlags);
0095 this->initializePixelStatus(pixelQuality, pixelCabling, pixelQualityFlags, pixelQualityDebugFlags);
0096 }
0097
0098 MeasurementTrackerImpl::~MeasurementTrackerImpl() {}
0099
0100 void MeasurementTrackerImpl::initialize(const TrackerTopology* trackerTopology) {
0101 bool subIsPixel = false;
0102
0103
0104 bool subIsOT = false;
0105
0106
0107 if (!theTrackerGeom->detsPXB().empty()) {
0108 subIsPixel = GeomDetEnumerators::isTrackerPixel(
0109 theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsPXB().front()->geographicalId().subdetId()));
0110 addDets(theTrackerGeom->detsPXB(), subIsPixel, subIsOT);
0111 }
0112
0113 if (!theTrackerGeom->detsPXF().empty()) {
0114 subIsPixel = GeomDetEnumerators::isTrackerPixel(
0115 theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsPXF().front()->geographicalId().subdetId()));
0116 addDets(theTrackerGeom->detsPXF(), subIsPixel, subIsOT);
0117 }
0118
0119 subIsOT = true;
0120
0121 if (!theTrackerGeom->detsTIB().empty()) {
0122 subIsPixel = GeomDetEnumerators::isTrackerPixel(
0123 theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTIB().front()->geographicalId().subdetId()));
0124 addDets(theTrackerGeom->detsTIB(), subIsPixel, subIsOT);
0125 }
0126
0127 if (!theTrackerGeom->detsTID().empty()) {
0128 subIsPixel = GeomDetEnumerators::isTrackerPixel(
0129 theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTID().front()->geographicalId().subdetId()));
0130 addDets(theTrackerGeom->detsTID(), subIsPixel, subIsOT);
0131 }
0132
0133 if (!theTrackerGeom->detsTOB().empty()) {
0134 subIsPixel = GeomDetEnumerators::isTrackerPixel(
0135 theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTOB().front()->geographicalId().subdetId()));
0136 addDets(theTrackerGeom->detsTOB(), subIsPixel, subIsOT);
0137 }
0138
0139 if (!theTrackerGeom->detsTEC().empty()) {
0140 subIsPixel = GeomDetEnumerators::isTrackerPixel(
0141 theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTEC().front()->geographicalId().subdetId()));
0142 addDets(theTrackerGeom->detsTEC(), subIsPixel, subIsOT);
0143 }
0144
0145
0146 sortTKD(theStripDets);
0147 initStMeasurementConditionSet(theStripDets);
0148 for (unsigned int i = 0; i != theStripDets.size(); ++i)
0149 theDetMap[theStDetConditions.id(i)] = &theStripDets[i];
0150
0151
0152 sortTKD(theGluedDets);
0153 for (unsigned int i = 0; i != theGluedDets.size(); ++i)
0154 initGluedDet(theGluedDets[i], trackerTopology);
0155
0156
0157 sortTKD(thePixelDets);
0158 initPxMeasurementConditionSet(thePixelDets);
0159 for (unsigned int i = 0; i != thePixelDets.size(); ++i)
0160 theDetMap[thePxDetConditions.id(i)] = &thePixelDets[i];
0161
0162
0163 sortTKD(thePhase2Dets);
0164 initPhase2OTMeasurementConditionSet(thePhase2Dets);
0165 for (unsigned int i = 0; i != thePhase2Dets.size(); ++i)
0166 theDetMap[thePhase2DetConditions.id(i)] = &thePhase2Dets[i];
0167
0168
0169 sortTKD(theStackDets);
0170 for (unsigned int i = 0; i != theStackDets.size(); ++i)
0171 initStackDet(theStackDets[i]);
0172
0173 if (!checkDets())
0174 throw MeasurementDetException("Number of dets in MeasurementTracker not consistent with TrackerGeometry!");
0175 }
0176
0177 void MeasurementTrackerImpl::initStMeasurementConditionSet(std::vector<TkStripMeasurementDet>& stripDets) {
0178
0179 int size = stripDets.size();
0180 theStDetConditions.init(size);
0181 for (int i = 0; i != size; ++i) {
0182 auto& mdet = stripDets[i];
0183 mdet.setIndex(i);
0184
0185 theStDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
0186 theStDetConditions.subId_[i] = SiStripDetId(theStDetConditions.id_[i]).subdetId() - 3;
0187
0188 theStDetConditions.totalStrips_[i] = mdet.specificGeomDet().specificTopology().nstrips();
0189 }
0190 }
0191
0192 void MeasurementTrackerImpl::initPxMeasurementConditionSet(std::vector<TkPixelMeasurementDet>& pixelDets) {
0193
0194 int size = pixelDets.size();
0195 thePxDetConditions.init(size);
0196
0197 for (int i = 0; i != size; ++i) {
0198 auto& mdet = pixelDets[i];
0199 mdet.setIndex(i);
0200 thePxDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
0201 }
0202 }
0203
0204 void MeasurementTrackerImpl::initPhase2OTMeasurementConditionSet(std::vector<TkPhase2OTMeasurementDet>& phase2Dets) {
0205
0206 int size = phase2Dets.size();
0207 thePhase2DetConditions.init(size);
0208
0209 for (int i = 0; i != size; ++i) {
0210 auto& mdet = phase2Dets[i];
0211 mdet.setIndex(i);
0212 thePhase2DetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
0213 }
0214 }
0215
0216 void MeasurementTrackerImpl::addDets(const TrackingGeometry::DetContainer& dets, bool subIsPixel, bool subIsOT) {
0217
0218 for (TrackerGeometry::DetContainer::const_iterator gd = dets.begin(); gd != dets.end(); gd++) {
0219 const GeomDetUnit* gdu = dynamic_cast<const GeomDetUnit*>(*gd);
0220
0221
0222 if (gdu->isLeaf()) {
0223 if (subIsPixel) {
0224 if (!subIsOT) {
0225 addPixelDet(*gd);
0226 } else {
0227 addPhase2Det(*gd);
0228 }
0229 } else {
0230 addStripDet(*gd);
0231 }
0232 } else {
0233
0234 const GluedGeomDet* gluedDet = dynamic_cast<const GluedGeomDet*>(*gd);
0235 const StackGeomDet* stackDet = dynamic_cast<const StackGeomDet*>(*gd);
0236
0237 if ((gluedDet == nullptr && stackDet == nullptr) || (gluedDet != nullptr && stackDet != nullptr)) {
0238 throw MeasurementDetException("MeasurementTracker ERROR: GeomDet neither DetUnit nor GluedDet nor StackDet");
0239 }
0240 if (gluedDet != nullptr)
0241 addGluedDet(gluedDet);
0242 else if (stackDet != nullptr)
0243 addStackDet(stackDet);
0244 }
0245 }
0246 }
0247
0248 bool MeasurementTrackerImpl::checkDets() {
0249 if (theTrackerGeom->dets().size() == theDetMap.size())
0250 return true;
0251 return false;
0252 }
0253
0254 void MeasurementTrackerImpl::addStripDet(const GeomDet* gd) {
0255 try {
0256 theStripDets.push_back(TkStripMeasurementDet(gd, theStDetConditions));
0257 } catch (MeasurementDetException& err) {
0258 edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what();
0259 }
0260 }
0261
0262 void MeasurementTrackerImpl::addPixelDet(const GeomDet* gd) {
0263 try {
0264 thePixelDets.push_back(TkPixelMeasurementDet(gd, thePxDetConditions));
0265 } catch (MeasurementDetException& err) {
0266 edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what();
0267 }
0268 }
0269
0270 void MeasurementTrackerImpl::addPhase2Det(const GeomDet* gd) {
0271 try {
0272 thePhase2Dets.push_back(TkPhase2OTMeasurementDet(gd, thePhase2DetConditions));
0273 } catch (MeasurementDetException& err) {
0274 edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what();
0275 }
0276 }
0277
0278 void MeasurementTrackerImpl::addGluedDet(const GluedGeomDet* gd) {
0279 theGluedDets.push_back(TkGluedMeasurementDet(gd, theStDetConditions.matcher(), theStDetConditions.stripCPE()));
0280 }
0281
0282 void MeasurementTrackerImpl::addStackDet(const StackGeomDet* gd) {
0283
0284
0285 theStackDets.push_back(TkStackMeasurementDet(gd, thePxDetConditions.pixelCPE()));
0286 }
0287
0288 void MeasurementTrackerImpl::initGluedDet(TkGluedMeasurementDet& det, const TrackerTopology* trackerTopology) {
0289 const GluedGeomDet& gd = det.specificGeomDet();
0290 const MeasurementDet* monoDet = findDet(gd.monoDet()->geographicalId());
0291 const MeasurementDet* stereoDet = findDet(gd.stereoDet()->geographicalId());
0292 if (monoDet == nullptr || stereoDet == nullptr) {
0293 edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: GluedDet components not found as MeasurementDets ";
0294 throw MeasurementDetException("MeasurementTracker ERROR: GluedDet components not found as MeasurementDets");
0295 }
0296 det.init(monoDet, stereoDet, trackerTopology);
0297 theDetMap[gd.geographicalId()] = &det;
0298 }
0299
0300 void MeasurementTrackerImpl::initStackDet(TkStackMeasurementDet& det) {
0301 const StackGeomDet& gd = det.specificGeomDet();
0302 const MeasurementDet* lowerDet = findDet(gd.lowerDet()->geographicalId());
0303 const MeasurementDet* upperDet = findDet(gd.upperDet()->geographicalId());
0304 if (lowerDet == nullptr || upperDet == nullptr) {
0305 edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: StackDet components not found as MeasurementDets ";
0306 throw MeasurementDetException("MeasurementTracker ERROR: StackDet components not found as MeasurementDets");
0307 }
0308 det.init(lowerDet, upperDet);
0309 theDetMap[gd.geographicalId()] = &det;
0310 }
0311
0312 void MeasurementTrackerImpl::initializeStripStatus(const BadStripCutsDet& badStripCuts,
0313 const SiStripQuality* quality,
0314 int qualityFlags,
0315 int qualityDebugFlags) {
0316 if (qualityFlags & BadStrips) {
0317 theStDetConditions.badStripCuts_[SiStripDetId::TIB - 3] = badStripCuts.tib;
0318 theStDetConditions.badStripCuts_[SiStripDetId::TOB - 3] = badStripCuts.tob;
0319 theStDetConditions.badStripCuts_[SiStripDetId::TID - 3] = badStripCuts.tid;
0320 theStDetConditions.badStripCuts_[SiStripDetId::TEC - 3] = badStripCuts.tec;
0321 }
0322 theStDetConditions.setMaskBad128StripBlocks((qualityFlags & MaskBad128StripBlocks) != 0);
0323
0324 if ((quality != nullptr) && (qualityFlags != 0)) {
0325 edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
0326 unsigned int on = 0, tot = 0;
0327 unsigned int foff = 0, ftot = 0, aoff = 0, atot = 0;
0328 for (int i = 0; i != theStDetConditions.nDet(); i++) {
0329 uint32_t detid = theStDetConditions.id(i);
0330 if (qualityFlags & BadModules) {
0331 bool isOn = quality->IsModuleUsable(detid);
0332 theStDetConditions.setActive(i, isOn);
0333 tot++;
0334 on += (unsigned int)isOn;
0335 if (qualityDebugFlags & BadModules) {
0336 edm::LogInfo("MeasurementTracker")
0337 << "MeasurementTrackerImpl::initializeStripStatus : detid " << detid << " is " << (isOn ? "on" : "off");
0338 }
0339 } else {
0340 theStDetConditions.setActive(i, true);
0341 }
0342
0343 theStDetConditions.set128StripStatus(i, true);
0344 if (qualityFlags & BadAPVFibers) {
0345 short badApvs = quality->getBadApvs(detid);
0346 short badFibers = quality->getBadFibers(detid);
0347 for (int j = 0; j < 6; j++) {
0348 atot++;
0349 if (badApvs & (1 << j)) {
0350 theStDetConditions.set128StripStatus(i, false, j);
0351 aoff++;
0352 }
0353 }
0354 for (int j = 0; j < 3; j++) {
0355 ftot++;
0356 if (badFibers & (1 << j)) {
0357 theStDetConditions.set128StripStatus(i, false, 2 * j);
0358 theStDetConditions.set128StripStatus(i, false, 2 * j + 1);
0359 foff++;
0360 }
0361 }
0362 }
0363 auto& badStrips = theStDetConditions.getBadStripBlocks(i);
0364 badStrips.clear();
0365 if (qualityFlags & BadStrips) {
0366 SiStripBadStrip::Range range = quality->getRange(detid);
0367 for (SiStripBadStrip::ContainerIterator bit = range.first; bit != range.second; ++bit) {
0368 badStrips.push_back(quality->decode(*bit));
0369 }
0370 }
0371 }
0372 if (qualityDebugFlags & BadModules) {
0373 edm::LogInfo("MeasurementTracker StripModuleStatus")
0374 << " Total modules: " << tot << ", active " << on << ", inactive " << (tot - on);
0375 }
0376 if (qualityDebugFlags & BadAPVFibers) {
0377 edm::LogInfo("MeasurementTracker StripAPVStatus")
0378 << " Total APVs: " << atot << ", active " << (atot - aoff) << ", inactive " << (aoff);
0379 edm::LogInfo("MeasurementTracker StripFiberStatus")
0380 << " Total Fibers: " << ftot << ", active " << (ftot - foff) << ", inactive " << (foff);
0381 }
0382 } else {
0383 for (int i = 0; i != theStDetConditions.nDet(); i++) {
0384 theStDetConditions.setActive(i, true);
0385 theStDetConditions.set128StripStatus(i, true);
0386 }
0387 }
0388 }
0389
0390 void MeasurementTrackerImpl::initializePixelStatus(const SiPixelQuality* quality,
0391 const SiPixelFedCabling* pixelCabling,
0392 int qualityFlags,
0393 int qualityDebugFlags) {
0394 if ((quality != nullptr) && (qualityFlags != 0)) {
0395 edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
0396 unsigned int on = 0, tot = 0, badrocs = 0;
0397 for (std::vector<TkPixelMeasurementDet>::iterator i = thePixelDets.begin(); i != thePixelDets.end(); i++) {
0398 uint32_t detid = ((*i).geomDet().geographicalId()).rawId();
0399 if (qualityFlags & BadModules) {
0400 bool isOn = quality->IsModuleUsable(detid);
0401 (i)->setActive(isOn);
0402 tot++;
0403 on += (unsigned int)isOn;
0404 if (qualityDebugFlags & BadModules) {
0405 edm::LogInfo("MeasurementTracker")
0406 << "MeasurementTrackerImpl::initializePixelStatus : detid " << detid << " is " << (isOn ? "on" : "off");
0407 }
0408 } else {
0409 (i)->setActive(true);
0410 }
0411 if ((qualityFlags & BadROCs) && (quality->getBadRocs(detid) != 0)) {
0412 std::vector<LocalPoint> badROCs = quality->getBadRocPositions(detid, *theTrackerGeom, pixelCabling);
0413 badrocs += badROCs.size();
0414 (i)->setBadRocPositions(badROCs);
0415 } else {
0416 (i)->clearBadRocPositions();
0417 }
0418 }
0419 if (qualityDebugFlags & BadModules) {
0420 edm::LogInfo("MeasurementTracker PixelModuleStatus")
0421 << " Total modules: " << tot << ", active " << on << ", inactive " << (tot - on);
0422 }
0423 if (qualityDebugFlags & BadROCs) {
0424 edm::LogInfo("MeasurementTracker PixelROCStatus") << " Total of bad ROCs: " << badrocs;
0425 }
0426 } else {
0427 for (std::vector<TkPixelMeasurementDet>::iterator i = thePixelDets.begin(); i != thePixelDets.end(); i++) {
0428 (i)->setActive(true);
0429 }
0430 }
0431 }