Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-29 01:21:32

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