Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:29:34

0001 #include <iostream>
0002 
0003 #include "CalibTracker/SiPixelConnectivity/interface/SiPixelFedCablingMapBuilder.h"
0004 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0005 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0006 
0007 #include <ostream>
0008 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0009 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0010 
0011 #include "CalibTracker/SiPixelConnectivity/interface/PixelToFEDAssociate.h"
0012 #include "CalibTracker/SiPixelConnectivity/interface/TRange.h"
0013 #include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h"
0014 #include "CalibTracker/SiPixelConnectivity/interface/PixelBarrelLinkMaker.h"
0015 #include "CalibTracker/SiPixelConnectivity/interface/PixelEndcapLinkMaker.h"
0016 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0017 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0018 
0019 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0020 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0021 #include "CalibTracker/SiPixelConnectivity/interface/PixelToLNKAssociateFromAscii.h"
0022 
0023 #include <bitset>
0024 
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 
0027 using namespace std;
0028 using namespace sipixelobjects;
0029 
0030 SiPixelFedCablingMapBuilder::SiPixelFedCablingMapBuilder(edm::ConsumesCollector&& iCC,
0031                                                          const string fileName,
0032                                                          const bool phase1)
0033     : fileName_(fileName)  //, phase1_(phase1) not used anymore
0034 {
0035   trackerTopoToken_ = iCC.esConsumes<TrackerTopology, TrackerTopologyRcd>();
0036   trackerGeomToken_ = iCC.esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
0037 }
0038 
0039 SiPixelFedCablingTree* SiPixelFedCablingMapBuilder::produce(const edm::EventSetup& setup) {
0040   // Access geometry
0041   edm::LogInfo("read tracker geometry...");
0042   edm::ESHandle<TrackerGeometry> pDD = setup.getHandle(trackerGeomToken_);
0043   edm::LogInfo("tracker geometry read") << "There are: " << pDD->dets().size() << " detectors";
0044 
0045   // Test new TrackerGeometry features
0046   //cout << "Test of TrackerGeometry::isThere";
0047   //cout  << " is there PixelBarrel: " << pDD->isThere(GeomDetEnumerators::PixelBarrel);
0048   //cout  << " is there PixelEndcap: " << pDD->isThere(GeomDetEnumerators::PixelEndcap);
0049   //cout  << " is there P1PXB: " << pDD->isThere(GeomDetEnumerators::P1PXB);
0050   //cout  << " is there P1PXEC: " << pDD->isThere(GeomDetEnumerators::P1PXEC);
0051   //cout  << endl;
0052 
0053   // switch on the phase1
0054   if ((pDD->isThere(GeomDetEnumerators::P1PXB)) || (pDD->isThere(GeomDetEnumerators::P1PXEC))) {
0055     phase1_ = true;
0056     //cout<<" this is phase1 "<<endl;
0057     edm::LogInfo("SiPixelFedCablingMapBuilder") << " pixel phase1 setup ";
0058   } else {
0059     phase1_ = false;
0060     //cout<<" this is phase0 "<<endl;
0061     edm::LogInfo("SiPixelFedCablingMapBuilder") << " pixel phase0 setup ";
0062   }
0063 
0064   int MINFEDID = FEDNumbering::MINSiPixelFEDID;
0065   int MAXFEDID = FEDNumbering::MAXSiPixelFEDID;
0066   if (phase1_) {
0067     // bpix 1200-1239, fpix 1240-1255
0068     MINFEDID = FEDNumbering::MINSiPixeluTCAFEDID;
0069     MAXFEDID = FEDNumbering::MAXSiPixeluTCAFEDID;  // is actually 1349, might work
0070   }
0071   TRange<int> fedIds(MINFEDID, MAXFEDID);
0072   edm::LogInfo("SiPixelFedCablingMapBuilder") << "pixel fedid range: " << fedIds;
0073 
0074   // in the constrcuctor init() is called which reads the ascii file and makes
0075   // the map roc<->link
0076   // what is this junk? Replace by fixed associator.
0077   //edm::ESHandle<PixelToFEDAssociate> associator;
0078   //setup.get<TrackerDigiGeometryRecord>().get(theAssociatorName,associator);
0079   //PixelToFEDAssociate * associator = new PixelToLNKAssociateFromAscii("pixelToLNK.ascii",phase1_);
0080   PixelToFEDAssociate* associator = new PixelToLNKAssociateFromAscii(fileName_, phase1_);
0081 
0082   const PixelToFEDAssociate& name2fed = *associator;
0083 
0084   string version = name2fed.version();
0085   SiPixelFedCablingTree* result = new SiPixelFedCablingTree(version);
0086   edm::LogInfo(" version ") << version << endl;
0087 
0088   // Access topology
0089   edm::ESHandle<TrackerTopology> tTopo = setup.getHandle(trackerTopoToken_);
0090   const TrackerTopology* tt = tTopo.product();
0091 
0092   typedef TrackerGeometry::DetContainer::const_iterator ITG;
0093   int npxdets = 0;
0094 
0095   typedef std::vector<pair<PixelModuleName*, uint32_t> > UNITS;
0096   UNITS units;
0097 
0098   for (ITG it = pDD->dets().begin(); it != pDD->dets().end(); it++) {
0099     const PixelGeomDetUnit* pxUnit = dynamic_cast<const PixelGeomDetUnit*>(*it);
0100     if (pxUnit == nullptr)
0101       continue;
0102     npxdets++;
0103     DetId geomid = pxUnit->geographicalId();
0104     PixelModuleName* name = nullptr;
0105     if (1 == geomid.subdetId()) {  // bpix
0106       name = new PixelBarrelName(geomid, tt, phase1_);
0107     } else {  // fpix
0108       name = new PixelEndcapName(geomid, tt, phase1_);
0109     }
0110     edm::LogInfo(" NAME: ") << name->name();
0111     //cout << " NAME: "<<name->name()<<" "<<geomid.rawId()<<
0112     //" "<<myprint(pxUnit)<<endl;
0113     units.push_back(std::make_pair(name, geomid.rawId()));
0114   }
0115 
0116   // This produces  a simple, unrealistic map, NOT USED ANYMORE
0117   // if (theAssociatorName=="PixelToFEDAssociateFromAscii") {
0118   //   cout <<" HERE PixelToFEDAssociateFromAscii"<<endl;
0119   //   vector<FedSpec> fedSpecs(fedIds.max()-fedIds.min()+1);
0120   //   for (int id=fedIds.first; id<=fedIds.second; id++) {
0121   //     FedSpec fs={ id, vector<PixelModuleName* >(), vector<uint32_t>()};
0122   //     int idx = id - fedIds.min();
0123   //     fedSpecs[idx]= fs;
0124   //   }
0125   //   for (UNITS::iterator iu=units.begin(); iu != units.end(); iu++) {
0126   //     PixelModuleName* name = (*iu).first;
0127   //     uint32_t rawId = (*iu).second;
0128   //     int fedId = name2fed( *name);
0129   //     if ( fedIds.inside(fedId) ) {
0130   //    int idx = fedId - fedIds.min();
0131   //    fedSpecs[idx].rawids.push_back(rawId);
0132   //    fedSpecs[idx].names.push_back(name);
0133   //     } else edm::LogError("SiPixelFedCablingMapBuilder")
0134   //           <<"problem with numbering! "<<fedId<<" name: " << name->name();
0135   //   }
0136   //   edm::LogInfo("tracker geometry read")<<"There are: "<< npxdets<<" pixel detetors";
0137   //   // construct FEDs
0138   //   typedef vector<FedSpec>::iterator FI;
0139   //   for ( FI it = fedSpecs.begin(); it != fedSpecs.end(); it++) {
0140   //     int fedId = it->fedId;
0141   //     vector<PixelModuleName* > names = it->names;
0142   //     vector<uint32_t> units = it->rawids;
0143   //     if ( names.size() == 0) continue;
0144   //     PixelFEDCabling fed(fedId);
0145   //     bool barrel = it->names.front()->isBarrel();
0146   //     if (barrel) {
0147   //    PixelFEDCabling::Links links =
0148   //         PixelBarrelLinkMaker(&fed).links(names,units);
0149   //    fed.setLinks(links);
0150   //    result->addFed(fed);
0151   //     } else {
0152   //    PixelFEDCabling::Links links =
0153   //         PixelEndcapLinkMaker(&fed).links(names,units);
0154   //    fed.setLinks(links);
0155   //    result->addFed(fed);
0156   //     }
0157   //   }
0158   // } else {     // This is what is really used
0159 
0160   PixelToFEDAssociate::DetectorRocId detectorRocId;
0161   edm::LogInfo(" HERE PixelToLNKAssociateFromAscii");
0162   for (UNITS::iterator iu = units.begin(); iu != units.end(); iu++) {
0163     PixelModuleName* name = (*iu).first;
0164     detectorRocId.module = name;
0165     //for (int rocDetId=0; rocDetId<=16; rocDetId++) {
0166     for (int rocDetId = 0; rocDetId < 16; rocDetId++) {
0167       detectorRocId.rocDetId = rocDetId;
0168       const PixelToFEDAssociate::CablingRocId* cablingRocId = name2fed(detectorRocId);
0169       if (cablingRocId) {
0170         sipixelobjects::PixelROC roc(iu->second, rocDetId, cablingRocId->rocLinkId);
0171         result->addItem(cablingRocId->fedId, cablingRocId->linkId, roc);
0172         edm::LogInfo(" ok ") << name->name() << " " << rocDetId << " " << cablingRocId->fedId << " "
0173                              << cablingRocId->linkId;
0174       } else {  // did it fail?
0175         edm::LogInfo(" failed ") << name->name() << " " << rocDetId;
0176         //cout<<" failed "<<name->name()<<" "<<rocDetId<<endl;
0177       }
0178     }
0179   }
0180   //}
0181 
0182   //clear names:
0183   for (UNITS::iterator iu = units.begin(); iu != units.end(); iu++)
0184     delete iu->first;
0185 
0186   return result;
0187 }
0188 std::string SiPixelFedCablingMapBuilder::myprint(const PixelGeomDetUnit* pxUnit) {
0189   std::ostringstream str;
0190   const PixelTopology& tpl = pxUnit->specificTopology();
0191   LocalPoint local;
0192   GlobalPoint global;
0193 
0194   local = LocalPoint(0, 0, 0);
0195   global = (*pxUnit).toGlobal(local);
0196   // phi measured from Y axis
0197   float phi = 180 * atan2(global.x(), global.y()) / M_PI;
0198   if (phi > 180.)
0199     phi = phi - 360;
0200   float r = global.perp();
0201   float z = global.z();
0202   str << "    POSITION: "
0203       << " r=" << r << " phi=" << phi << " z=" << z;
0204   str << "   (rows,coll:" << tpl.nrows() << "," << tpl.ncolumns() << ")";
0205   str << endl;
0206   local = LocalPoint(0, 0, 0);
0207   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0208   local = LocalPoint(1, 0, 0);
0209   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0210   local = LocalPoint(0, 1, 0);
0211   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0212   local = LocalPoint(0, 0, 1);
0213   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0214 
0215   return str.str();
0216 }