Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:31

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 
0094   typedef std::vector<pair<PixelModuleName*, uint32_t> > UNITS;
0095   UNITS units;
0096 
0097   for (ITG it = pDD->dets().begin(); it != pDD->dets().end(); it++) {
0098     const PixelGeomDetUnit* pxUnit = dynamic_cast<const PixelGeomDetUnit*>(*it);
0099     if (pxUnit == nullptr)
0100       continue;
0101     DetId geomid = pxUnit->geographicalId();
0102     PixelModuleName* name = nullptr;
0103     if (1 == geomid.subdetId()) {  // bpix
0104       name = new PixelBarrelName(geomid, tt, phase1_);
0105     } else {  // fpix
0106       name = new PixelEndcapName(geomid, tt, phase1_);
0107     }
0108     edm::LogInfo(" NAME: ") << name->name();
0109     //cout << " NAME: "<<name->name()<<" "<<geomid.rawId()<<
0110     //" "<<myprint(pxUnit)<<endl;
0111     units.push_back(std::make_pair(name, geomid.rawId()));
0112   }
0113 
0114   // This produces  a simple, unrealistic map, NOT USED ANYMORE
0115   // if (theAssociatorName=="PixelToFEDAssociateFromAscii") {
0116   //   cout <<" HERE PixelToFEDAssociateFromAscii"<<endl;
0117   //   vector<FedSpec> fedSpecs(fedIds.max()-fedIds.min()+1);
0118   //   for (int id=fedIds.first; id<=fedIds.second; id++) {
0119   //     FedSpec fs={ id, vector<PixelModuleName* >(), vector<uint32_t>()};
0120   //     int idx = id - fedIds.min();
0121   //     fedSpecs[idx]= fs;
0122   //   }
0123   //   for (UNITS::iterator iu=units.begin(); iu != units.end(); iu++) {
0124   //     PixelModuleName* name = (*iu).first;
0125   //     uint32_t rawId = (*iu).second;
0126   //     int fedId = name2fed( *name);
0127   //     if ( fedIds.inside(fedId) ) {
0128   //    int idx = fedId - fedIds.min();
0129   //    fedSpecs[idx].rawids.push_back(rawId);
0130   //    fedSpecs[idx].names.push_back(name);
0131   //     } else edm::LogError("SiPixelFedCablingMapBuilder")
0132   //           <<"problem with numbering! "<<fedId<<" name: " << name->name();
0133   //   }
0134   //   edm::LogInfo("tracker geometry read")<<"There are: "<< npxdets<<" pixel detetors";
0135   //   // construct FEDs
0136   //   typedef vector<FedSpec>::iterator FI;
0137   //   for ( FI it = fedSpecs.begin(); it != fedSpecs.end(); it++) {
0138   //     int fedId = it->fedId;
0139   //     vector<PixelModuleName* > names = it->names;
0140   //     vector<uint32_t> units = it->rawids;
0141   //     if ( names.size() == 0) continue;
0142   //     PixelFEDCabling fed(fedId);
0143   //     bool barrel = it->names.front()->isBarrel();
0144   //     if (barrel) {
0145   //    PixelFEDCabling::Links links =
0146   //         PixelBarrelLinkMaker(&fed).links(names,units);
0147   //    fed.setLinks(links);
0148   //    result->addFed(fed);
0149   //     } else {
0150   //    PixelFEDCabling::Links links =
0151   //         PixelEndcapLinkMaker(&fed).links(names,units);
0152   //    fed.setLinks(links);
0153   //    result->addFed(fed);
0154   //     }
0155   //   }
0156   // } else {     // This is what is really used
0157 
0158   PixelToFEDAssociate::DetectorRocId detectorRocId;
0159   edm::LogInfo(" HERE PixelToLNKAssociateFromAscii");
0160   for (UNITS::iterator iu = units.begin(); iu != units.end(); iu++) {
0161     PixelModuleName* name = (*iu).first;
0162     detectorRocId.module = name;
0163     //for (int rocDetId=0; rocDetId<=16; rocDetId++) {
0164     for (int rocDetId = 0; rocDetId < 16; rocDetId++) {
0165       detectorRocId.rocDetId = rocDetId;
0166       const PixelToFEDAssociate::CablingRocId* cablingRocId = name2fed(detectorRocId);
0167       if (cablingRocId) {
0168         sipixelobjects::PixelROC roc(iu->second, rocDetId, cablingRocId->rocLinkId);
0169         result->addItem(cablingRocId->fedId, cablingRocId->linkId, roc);
0170         edm::LogInfo(" ok ") << name->name() << " " << rocDetId << " " << cablingRocId->fedId << " "
0171                              << cablingRocId->linkId;
0172       } else {  // did it fail?
0173         edm::LogInfo(" failed ") << name->name() << " " << rocDetId;
0174         //cout<<" failed "<<name->name()<<" "<<rocDetId<<endl;
0175       }
0176     }
0177   }
0178   //}
0179 
0180   //clear names:
0181   for (UNITS::iterator iu = units.begin(); iu != units.end(); iu++)
0182     delete iu->first;
0183 
0184   return result;
0185 }
0186 std::string SiPixelFedCablingMapBuilder::myprint(const PixelGeomDetUnit* pxUnit) {
0187   std::ostringstream str;
0188   const PixelTopology& tpl = pxUnit->specificTopology();
0189   LocalPoint local;
0190   GlobalPoint global;
0191 
0192   local = LocalPoint(0, 0, 0);
0193   global = (*pxUnit).toGlobal(local);
0194   // phi measured from Y axis
0195   float phi = 180 * atan2(global.x(), global.y()) / M_PI;
0196   if (phi > 180.)
0197     phi = phi - 360;
0198   float r = global.perp();
0199   float z = global.z();
0200   str << "    POSITION: "
0201       << " r=" << r << " phi=" << phi << " z=" << z;
0202   str << "   (rows,coll:" << tpl.nrows() << "," << tpl.ncolumns() << ")";
0203   str << endl;
0204   local = LocalPoint(0, 0, 0);
0205   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0206   local = LocalPoint(1, 0, 0);
0207   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0208   local = LocalPoint(0, 1, 0);
0209   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0210   local = LocalPoint(0, 0, 1);
0211   str << local << "global: " << (*pxUnit).toGlobal(local) << endl;
0212 
0213   return str.str();
0214 }