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)
0034 {
0035 trackerTopoToken_ = iCC.esConsumes<TrackerTopology, TrackerTopologyRcd>();
0036 trackerGeomToken_ = iCC.esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>();
0037 }
0038
0039 SiPixelFedCablingTree* SiPixelFedCablingMapBuilder::produce(const edm::EventSetup& setup) {
0040
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
0046
0047
0048
0049
0050
0051
0052
0053
0054 if ((pDD->isThere(GeomDetEnumerators::P1PXB)) || (pDD->isThere(GeomDetEnumerators::P1PXEC))) {
0055 phase1_ = true;
0056
0057 edm::LogInfo("SiPixelFedCablingMapBuilder") << " pixel phase1 setup ";
0058 } else {
0059 phase1_ = false;
0060
0061 edm::LogInfo("SiPixelFedCablingMapBuilder") << " pixel phase0 setup ";
0062 }
0063
0064 int MINFEDID = FEDNumbering::MINSiPixelFEDID;
0065 int MAXFEDID = FEDNumbering::MAXSiPixelFEDID;
0066 if (phase1_) {
0067
0068 MINFEDID = FEDNumbering::MINSiPixeluTCAFEDID;
0069 MAXFEDID = FEDNumbering::MAXSiPixeluTCAFEDID;
0070 }
0071 TRange<int> fedIds(MINFEDID, MAXFEDID);
0072 edm::LogInfo("SiPixelFedCablingMapBuilder") << "pixel fedid range: " << fedIds;
0073
0074
0075
0076
0077
0078
0079
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
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()) {
0104 name = new PixelBarrelName(geomid, tt, phase1_);
0105 } else {
0106 name = new PixelEndcapName(geomid, tt, phase1_);
0107 }
0108 edm::LogInfo(" NAME: ") << name->name();
0109
0110
0111 units.push_back(std::make_pair(name, geomid.rawId()));
0112 }
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
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
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 {
0173 edm::LogInfo(" failed ") << name->name() << " " << rocDetId;
0174
0175 }
0176 }
0177 }
0178
0179
0180
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
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 }