Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:35

0001 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameReverter.h"
0002 #include "CondFormats/SiPixelObjects/interface/CablingPathToDetUnit.h"
0003 #include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h"
0004 #include "CondFormats/SiPixelObjects/interface/PixelFEDLink.h"
0005 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
0006 // DataFormats
0007 #include "DataFormats/DetId/interface/DetId.h"
0008 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0009 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0010 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0011 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0012 // Geometry
0013 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0014 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0015 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0016 
0017 using namespace std;
0018 using namespace sipixelobjects;
0019 
0020 SiPixelFrameReverter::SiPixelFrameReverter(const SiPixelFedCabling* map) : map_(map), DetToFedMap(map->det2PathMap()) {}
0021 
0022 void SiPixelFrameReverter::buildStructure(const TrackerGeometry* trackerGeometry) {
0023   // Create map connecting each detId to appropriate SiPixelFrameConverter
0024   for (auto it = trackerGeometry->dets().begin(); it != trackerGeometry->dets().end(); it++) {
0025     if (dynamic_cast<PixelGeomDetUnit const*>((*it)) != nullptr) {
0026       DetId detId = (*it)->geographicalId();
0027       uint32_t id = detId();
0028       std::vector<CablingPathToDetUnit> paths = map_->pathToDetUnit(id);
0029       DetToFedMap.insert(pair<uint32_t, std::vector<CablingPathToDetUnit> >(id, paths));
0030     }
0031   }  // for(TrackerGeometry::DetContainer::const_iterator
0032 }  // end buildStructure
0033 
0034 int SiPixelFrameReverter::toCabling(sipixelobjects::ElectronicIndex& cabling,
0035                                     const sipixelobjects::DetectorIndex& detector) const {
0036   if (!hasDetUnit(detector.rawId))
0037     return -1;
0038   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detector.rawId)->second;
0039   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
0040   for (IT it = path.begin(); it != path.end(); ++it) {
0041     const PixelROC* roc = map_->findItem(*it);
0042     if (!roc)
0043       return -3;
0044     if (roc->rawId() != detector.rawId)
0045       return -4;
0046 
0047     GlobalPixel global = {detector.row, detector.col};
0048     LocalPixel local = roc->toLocal(global);
0049     if (!local.valid())
0050       continue;
0051     ElectronicIndex cabIdx = {static_cast<int>(it->link), static_cast<int>(it->roc), local.dcol(), local.pxid()};
0052     cabling = cabIdx;
0053 
0054     return it->fed;
0055   }
0056   return -2;
0057 }
0058 
0059 int SiPixelFrameReverter::findFedId(uint32_t detId) {
0060   if (!hasDetUnit(detId))
0061     return -1;
0062   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
0063   int fedId = (int)path[0].fed;
0064   return fedId;
0065 }
0066 
0067 short SiPixelFrameReverter::findLinkInFed(uint32_t detId, GlobalPixel global) {
0068   if (!hasDetUnit(detId))
0069     return -1;
0070   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
0071   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
0072   for (IT it = path.begin(); it != path.end(); ++it) {
0073     const PixelROC* roc = map_->findItem(*it);
0074     if (!roc)
0075       continue;
0076 
0077     LocalPixel local = roc->toLocal(global);
0078 
0079     if (!local.valid())
0080       continue;
0081     short link = (short)it->link;
0082     return link;
0083   }
0084   return -1;
0085 }
0086 
0087 short SiPixelFrameReverter::findRocInLink(uint32_t detId, GlobalPixel global) {
0088   if (!hasDetUnit(detId))
0089     return -1;
0090   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
0091   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
0092   for (IT it = path.begin(); it != path.end(); ++it) {
0093     const PixelROC* roc = map_->findItem(*it);
0094     if (!roc)
0095       continue;
0096 
0097     LocalPixel local = roc->toLocal(global);
0098 
0099     if (!local.valid())
0100       continue;
0101     short rocInLink = (short)roc->idInLink();
0102     return rocInLink;
0103   }
0104   return -1;
0105 }
0106 
0107 short SiPixelFrameReverter::findRocInDet(uint32_t detId, GlobalPixel global) {
0108   if (!hasDetUnit(detId))
0109     return -1;
0110   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
0111   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
0112   for (IT it = path.begin(); it != path.end(); ++it) {
0113     const PixelROC* roc = map_->findItem(*it);
0114     if (!roc)
0115       continue;
0116 
0117     LocalPixel local = roc->toLocal(global);
0118 
0119     if (!local.valid())
0120       continue;
0121     short rocInDet = (short)roc->idInDetUnit();
0122     return rocInDet;
0123   }
0124   return -1;
0125 }
0126 
0127 LocalPixel SiPixelFrameReverter::findPixelInRoc(uint32_t detId, GlobalPixel global) {
0128   if (!hasDetUnit(detId)) {
0129     LocalPixel::RocRowCol pixel = {-1, -1};
0130     LocalPixel local(pixel);
0131     return local;
0132   }
0133   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
0134   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
0135   for (IT it = path.begin(); it != path.end(); ++it) {
0136     const PixelROC* roc = map_->findItem(*it);
0137     if (!roc)
0138       continue;
0139 
0140     LocalPixel local = roc->toLocal(global);
0141 
0142     if (!local.valid())
0143       continue;
0144     return local;
0145   }
0146   LocalPixel::RocRowCol pixel = {-1, -1};
0147   LocalPixel local(pixel);
0148   return local;
0149 }