Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:27

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