Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-21 00:19:33

0001 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0002 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0003 #include "Geometry/TrackerGeometryBuilder/interface/PlaneBuilderForGluedDet.h"
0004 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0005 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0006 #include "Geometry/CommonDetUnit/interface/StackGeomDet.h"
0007 #include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
0008 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0009 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
0010 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0011 #include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h"
0012 #include "Geometry/TrackerGeometryBuilder/interface/StripTopologyBuilder.h"
0013 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0014 #include "DataFormats/DetId/interface/DetId.h"
0015 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0016 #include "DataFormats/GeometrySurface/interface/MediumProperties.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/Utilities/interface/Exception.h"
0019 
0020 #include <cfloat>
0021 #include <cassert>
0022 using std::string;
0023 using std::vector;
0024 
0025 namespace {
0026   void verifyDUinTG(TrackerGeometry const& tg) {
0027     int off = 0;
0028     int end = 0;
0029     for (int i = 1; i != 7; i++) {
0030       auto det = GeomDetEnumerators::tkDetEnum[i];
0031       off = tg.offsetDU(det);
0032       end = tg.endsetDU(det);
0033       assert(end >= off);  // allow empty subdetectors. Needed for upgrade
0034       for (int j = off; j != end; ++j) {
0035         assert(tg.detUnits()[j]->geographicalId().subdetId() == i);
0036         assert(GeomDetEnumerators::subDetGeom[tg.detUnits()[j]->subDetector()] == det);
0037         assert(tg.detUnits()[j]->index() == j);
0038       }
0039     }
0040   }
0041 }  // namespace
0042 
0043 TrackerGeometry* TrackerGeomBuilderFromGeometricDet::build(const GeometricDet* gd,
0044                                                            const PTrackerParameters& ptp,
0045                                                            const TrackerTopology* tTopo) {
0046   if (ptp.vpars.size() != 6) {
0047     throw cms::Exception("TrackerGeomBuilderFromGeometricDet")
0048         << "Tracker parameters block from XMLs called vPars is expected to have 6 entries, but has " << ptp.vpars.size()
0049         << " entrie(s).";
0050   }
0051 
0052   const int BIG_PIX_PER_ROC_X = ptp.vpars[2];
0053   const int BIG_PIX_PER_ROC_Y = ptp.vpars[3];
0054 
0055   thePixelDetTypeMap.clear();
0056   theStripDetTypeMap.clear();
0057 
0058   TrackerGeometry* tracker = new TrackerGeometry(gd);
0059   std::vector<const GeometricDet*> comp;
0060   gd->deepComponents(comp);
0061 
0062   if (tTopo)
0063     theTopo = tTopo;
0064 
0065   //define a vector which associate to the detid subdetector index -1 (from 0 to 5) the GeometridDet enumerator to be able to know which type of subdetector it is
0066 
0067   std::vector<GeometricDet::GDEnumType> gdsubdetmap(
0068       6, GeometricDet::unknown);  // hardcoded "6" should not be a surprise...
0069   GeometricDet::ConstGeometricDetContainer subdetgd = gd->components();
0070 
0071   LogDebug("SubDetectorGeometricDetType") << "GeometriDet enumerator values of the subdetectors";
0072   for (unsigned int i = 0; i < subdetgd.size(); ++i) {
0073     assert(subdetgd[i]->geographicalId().subdetId() > 0 && subdetgd[i]->geographicalId().subdetId() < 7);
0074     gdsubdetmap[subdetgd[i]->geographicalId().subdetId() - 1] = subdetgd[i]->type();
0075     LogTrace("SubDetectorGeometricDetType")
0076         << "subdet " << i << " type " << subdetgd[i]->type() << " detid " << subdetgd[i]->geographicalId().rawId()
0077         << " subdetid " << subdetgd[i]->geographicalId().subdetId();
0078   }
0079 
0080   std::vector<const GeometricDet*> dets[6];
0081   std::vector<const GeometricDet*>& pixB = dets[0];
0082   pixB.reserve(comp.size());
0083   std::vector<const GeometricDet*>& pixF = dets[1];
0084   pixF.reserve(comp.size());
0085   std::vector<const GeometricDet*>& tib = dets[2];
0086   tib.reserve(comp.size());
0087   std::vector<const GeometricDet*>& tid = dets[3];
0088   tid.reserve(comp.size());
0089   std::vector<const GeometricDet*>& tob = dets[4];
0090   tob.reserve(comp.size());
0091   std::vector<const GeometricDet*>& tec = dets[5];
0092   tec.reserve(comp.size());
0093 
0094   for (auto& i : comp)
0095     dets[i->geographicalId().subdetId() - 1].emplace_back(i);
0096 
0097   //loop on all the six elements of dets and firstly check if they are from pixel-like detector and call buildPixel, then loop again and check if they are strip and call buildSilicon. "unknown" can be filled either way but the vector of GeometricDet must be empty !!
0098   // this order is VERY IMPORTANT!!!!! For the moment I (AndreaV) understand that some pieces of code rely on pixel-like being before strip-like
0099 
0100   // now building the Pixel-like subdetectors
0101   for (unsigned int i = 0; i < 6; ++i) {
0102     if (gdsubdetmap[i] == GeometricDet::PixelBarrel)
0103       buildPixel(
0104           dets[i], tracker, GeomDetEnumerators::SubDetector::PixelBarrel, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0105     if (gdsubdetmap[i] == GeometricDet::PixelPhase1Barrel)
0106       buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P1PXB, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0107     // Phase2 case
0108     if (gdsubdetmap[i] == GeometricDet::PixelPhase2Barrel)
0109       buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2PXB, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0110     //
0111     if (gdsubdetmap[i] == GeometricDet::PixelEndCap)
0112       buildPixel(
0113           dets[i], tracker, GeomDetEnumerators::SubDetector::PixelEndcap, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0114     if (gdsubdetmap[i] == GeometricDet::PixelPhase1EndCap)
0115       buildPixel(
0116           dets[i], tracker, GeomDetEnumerators::SubDetector::P1PXEC, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0117     if (gdsubdetmap[i] == GeometricDet::PixelPhase2EndCap)
0118       buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2PXEC, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0119     if (gdsubdetmap[i] == GeometricDet::OTPhase2Barrel)
0120       buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2OTB, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0121     if (gdsubdetmap[i] == GeometricDet::OTPhase2EndCap)
0122       buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2OTEC, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
0123   }
0124   //now building Strips
0125   for (unsigned int i = 0; i < 6; ++i) {
0126     if (gdsubdetmap[i] == GeometricDet::TIB)
0127       buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TIB, "barrel");
0128     if (gdsubdetmap[i] == GeometricDet::TID)
0129       buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TID, "endcap");
0130     if (gdsubdetmap[i] == GeometricDet::TOB)
0131       buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TOB, "barrel");
0132     if (gdsubdetmap[i] == GeometricDet::TEC)
0133       buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TEC, "endcap");
0134   }
0135   // and finally the "empty" subdetectors (maybe it is not needed)
0136   for (unsigned int i = 0; i < 6; ++i) {
0137     if (gdsubdetmap[i] == GeometricDet::unknown) {
0138       if (!dets[i].empty())
0139         throw cms::Exception("NotEmptyUnknownSubDet")
0140             << "Subdetector " << i + 1 << " is unknown but it is not empty: " << dets[i].size();
0141       buildSilicon(
0142           dets[i], tracker, GeomDetEnumerators::tkDetEnum[i + 1], "barrel");  // "barrel" is used but it is irrelevant
0143     }
0144   }
0145   buildGeomDet(tracker);  //"GeomDet"
0146 
0147   verifyDUinTG(*tracker);
0148 
0149   return tracker;
0150 }
0151 
0152 void TrackerGeomBuilderFromGeometricDet::buildPixel(
0153     std::vector<const GeometricDet*> const& gdv,
0154     TrackerGeometry* tracker,
0155     GeomDetType::SubDetector det,
0156     bool upgradeGeometry,
0157     int BIG_PIX_PER_ROC_X,  // in x direction, rows. BIG_PIX_PER_ROC_X = 0 for SLHC
0158     int BIG_PIX_PER_ROC_Y)  // in y direction, cols. BIG_PIX_PER_ROC_Y = 0 for SLHC
0159 {
0160   LogDebug("BuildingGeomDetUnits") << " Pixel type. Size of vector: " << gdv.size()
0161                                    << " GeomDetType subdetector: " << det
0162                                    << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det]
0163                                    << " big pix per ROC x: " << BIG_PIX_PER_ROC_X << " y: " << BIG_PIX_PER_ROC_Y
0164                                    << " is upgrade: " << upgradeGeometry;
0165 
0166   tracker->setOffsetDU(GeomDetEnumerators::subDetGeom[det]);
0167 
0168   for (auto const& i : gdv) {
0169     std::string const& detName = i->name();
0170     if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
0171       std::unique_ptr<const Bounds> bounds(i->bounds());
0172       PixelTopology* t = PixelTopologyBuilder().build(bounds.get(),
0173                                                       upgradeGeometry,
0174                                                       (int)i->pixROCRows(),
0175                                                       (int)i->pixROCCols(),
0176                                                       BIG_PIX_PER_ROC_X,
0177                                                       BIG_PIX_PER_ROC_Y,
0178                                                       (int)i->pixROCx(),
0179                                                       (int)i->pixROCy());
0180 
0181       thePixelDetTypeMap[detName] = new PixelGeomDetType(t, detName, det);
0182       tracker->addType(thePixelDetTypeMap[detName]);
0183     }
0184 
0185     PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(i);
0186     GeomDetUnit* temp = new PixelGeomDetUnit(&(*plane), thePixelDetTypeMap[detName], i->geographicalId());
0187 
0188     tracker->addDetUnit(temp);
0189     tracker->addDetUnitId(i->geographicalId());
0190   }
0191   tracker->setEndsetDU(GeomDetEnumerators::subDetGeom[det]);
0192 }
0193 
0194 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*> const& gdv,
0195                                                       TrackerGeometry* tracker,
0196                                                       GeomDetType::SubDetector det,
0197                                                       const std::string& part) {
0198   LogDebug("BuildingGeomDetUnits") << " Strip type. Size of vector: " << gdv.size()
0199                                    << " GeomDetType subdetector: " << det
0200                                    << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det] << " part "
0201                                    << part;
0202 
0203   tracker->setOffsetDU(GeomDetEnumerators::subDetGeom[det]);
0204 
0205   for (auto const& i : gdv) {
0206     std::string const& detName = i->name();
0207     if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
0208       std::unique_ptr<const Bounds> bounds(i->bounds());
0209       StripTopology* t = StripTopologyBuilder().build(bounds.get(), i->siliconAPVNum(), part);
0210       theStripDetTypeMap[detName] = new StripGeomDetType(t, detName, det, i->stereo());
0211       tracker->addType(theStripDetTypeMap[detName]);
0212     }
0213 
0214     double scale = (theTopo->partnerDetId(i->geographicalId())) ? 0.5 : 1.0;
0215 
0216     PlaneBuilderFromGeometricDet::ResultType plane = buildPlaneWithMaterial(i, scale);
0217     GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName], i->geographicalId());
0218 
0219     tracker->addDetUnit(temp);
0220     tracker->addDetUnitId(i->geographicalId());
0221   }
0222   tracker->setEndsetDU(GeomDetEnumerators::subDetGeom[det]);
0223 }
0224 
0225 void TrackerGeomBuilderFromGeometricDet::buildGeomDet(TrackerGeometry* tracker) {
0226   PlaneBuilderForGluedDet gluedplaneBuilder;
0227   auto const& gdu = tracker->detUnits();
0228   auto const& gduId = tracker->detUnitIds();
0229 
0230   for (u_int32_t i = 0; i < gdu.size(); i++) {
0231     tracker->addDet(gdu[i]);
0232     tracker->addDetId(gduId[i]);
0233     string gduTypeName = gdu[i]->type().name();
0234 
0235     //this step is time consuming >> TO FIX with a MAP?
0236     if ((gduTypeName.find("Ster") != std::string::npos || gduTypeName.find("Lower") != std::string::npos) &&
0237         (theTopo->glued(gduId[i]) != 0 || theTopo->stack(gduId[i]) != 0)) {
0238       int partner_pos = -1;
0239       for (u_int32_t jj = 0; jj < gduId.size(); jj++) {
0240         if (theTopo->partnerDetId(gduId[i]) == gduId[jj]) {
0241           partner_pos = jj;
0242           break;
0243         }
0244       }
0245       if (partner_pos == -1) {
0246         throw cms::Exception("Configuration") << "Module Type is Stereo or Lower but no partner detector found \n"
0247                                               << "There is a problem on Tracker geometry configuration\n";
0248       }
0249 
0250       const GeomDetUnit* dus = gdu[i];
0251       const GeomDetUnit* dum = gdu[partner_pos];
0252       std::vector<const GeomDetUnit*> composed(2);
0253       composed[0] = dum;
0254       composed[1] = dus;
0255       DetId composedDetId;
0256       if (gduTypeName.find("Ster") != std::string::npos) {
0257         PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(composed);
0258         composedDetId = theTopo->glued(gduId[i]);
0259         GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane), dum, dus, composedDetId);
0260         tracker->addDet((GeomDet*)gluedDet);
0261         tracker->addDetId(composedDetId);
0262 
0263       } else if (gduTypeName.find("Lower") != std::string::npos) {
0264         //The plane is *not* built in the middle, but on the Lower surface
0265         Plane* plane = new Plane(dus->surface());
0266         composedDetId = theTopo->stack(gduId[i]);
0267         StackGeomDet* stackDet = new StackGeomDet(&(*plane), dus, dum, composedDetId);
0268         tracker->addDet((GeomDet*)stackDet);
0269         tracker->addDetId(composedDetId);
0270       }
0271     }
0272   }
0273 }
0274 
0275 PlaneBuilderFromGeometricDet::ResultType TrackerGeomBuilderFromGeometricDet::buildPlaneWithMaterial(
0276     const GeometricDet* gd, double scale) const {
0277   PlaneBuilderFromGeometricDet planeBuilder;
0278   PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);
0279   //
0280   // set medium properties (if defined)
0281   //
0282   plane->setMediumProperties(MediumProperties(gd->radLength() * scale, gd->xi() * scale));
0283 
0284   return plane;
0285 }