Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-15 23:06:50

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