Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-22 04:03:05

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