Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:34

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