Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-12 23:19:13

0001 #include "Geometry/MTDGeometryBuilder/interface/MTDGeomBuilderFromGeometricTimingDet.h"
0002 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0003 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0004 #include "Geometry/MTDGeometryBuilder/interface/MTDGeomDetType.h"
0005 #include "Geometry/MTDGeometryBuilder/interface/MTDGeomDetUnit.h"
0006 #include "Geometry/MTDGeometryBuilder/interface/MTDPixelTopologyBuilder.h"
0007 #include "DataFormats/DetId/interface/DetId.h"
0008 #include "DataFormats/ForwardDetId/interface/MTDDetId.h"
0009 #include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
0010 #include "DataFormats/GeometrySurface/interface/MediumProperties.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 
0014 #include <cfloat>
0015 #include <cassert>
0016 using std::string;
0017 using std::vector;
0018 
0019 namespace {
0020   void verifyDUinTG(MTDGeometry const& tg) {
0021     int off = 0;
0022     int end = 0;
0023     for (int i = 1; i != 2; i++) {
0024       auto det = i - 1;
0025       off = tg.offsetDU(det);
0026       end = tg.endsetDU(det);
0027       assert(end >= off);  // allow empty subdetectors. Needed for upgrade
0028       for (int j = off; j != end; ++j) {
0029         assert(tg.detUnits()[j]->geographicalId().subdetId() == i);
0030         assert(tg.detUnits()[j]->index() == j);
0031       }
0032     }
0033   }
0034 }  // namespace
0035 
0036 MTDGeometry* MTDGeomBuilderFromGeometricTimingDet::build(const GeometricTimingDet* gd, const PMTDParameters& ptp) {
0037   theMTDDetTypeMap.clear();
0038 
0039   MTDGeometry* tracker = new MTDGeometry(gd);
0040   std::vector<const GeometricTimingDet*> comp;
0041   gd->deepComponents(comp);
0042 
0043   //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
0044 
0045   std::vector<GeometricTimingDet::GTDEnumType> gdsubdetmap(
0046       2, GeometricTimingDet::unknown);  // hardcoded "2" should not be a surprise...
0047   GeometricTimingDet::ConstGeometricTimingDetContainer subdetgd = gd->components();
0048 
0049   LogDebug("SubDetectorGeometricTimingDetType") << "MTD GeometricTimingDet enumerator values of the subdetectors";
0050   for (unsigned int i = 0; i < subdetgd.size(); ++i) {
0051     MTDDetId mtdid(subdetgd[i]->geographicalId());
0052     assert(mtdid.mtdSubDetector() > 0 && mtdid.mtdSubDetector() < 3);
0053     gdsubdetmap[mtdid.mtdSubDetector() - 1] = subdetgd[i]->type();
0054     LogTrace("SubDetectorGeometricTimingDetType") << "MTD subdet " << i << " type " << subdetgd[i]->type() << " detid "
0055                                                   << std::hex << subdetgd[i]->geographicalId().rawId() << std::dec
0056                                                   << " subdetid " << subdetgd[i]->geographicalId().subdetId();
0057   }
0058 
0059   std::vector<const GeometricTimingDet*> dets[2];
0060   std::vector<const GeometricTimingDet*>& btl = dets[0];
0061   btl.reserve(comp.size());
0062   std::vector<const GeometricTimingDet*>& etl = dets[1];
0063   etl.reserve(comp.size());
0064 
0065   for (auto& i : comp) {
0066     MTDDetId mtdid(i->geographicalId());
0067     dets[mtdid.mtdSubDetector() - 1].emplace_back(i);
0068   }
0069 
0070   //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 GeometricTimingDet must be empty !!
0071   // this order is VERY IMPORTANT!!!!! For the moment I (AndreaV) understand that some pieces of code rely on pixel-like being before strip-like
0072 
0073   // now building the Pixel-like subdetectors
0074   for (unsigned int i = 0; i < 2; ++i) {
0075     if (gdsubdetmap[i] == GeometricTimingDet::BTL)
0076       buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::TimingBarrel, ptp);
0077     if (gdsubdetmap[i] == GeometricTimingDet::ETL)
0078       buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::TimingEndcap, ptp);
0079   }
0080 
0081   buildGeomDet(tracker);  //"GeomDet"
0082 
0083   verifyDUinTG(*tracker);
0084 
0085   return tracker;
0086 }
0087 
0088 void MTDGeomBuilderFromGeometricTimingDet::buildPixel(
0089     std::vector<const GeometricTimingDet*> const& gdv,
0090     MTDGeometry* tracker,
0091     GeomDetType::SubDetector det,
0092     const PMTDParameters& ptp)  // in y direction, cols. BIG_PIX_PER_ROC_Y = 0 for SLHC
0093 {
0094   LogDebug("BuildingGeomDetUnits") << " MTD Pixel type. Size of vector: " << gdv.size()
0095                                    << " GeomDetType subdetector: " << det
0096                                    << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det]
0097                                    << " big pix per ROC x: " << 0 << " y: " << 0 << " is upgrade: " << true;
0098 
0099   // this is a hack while we put things into the DDD
0100   int ROCrows(0), ROCcols(0), ROCSx(0), ROCSy(0);
0101   int GAPxInterpad(0), GAPxBorder(0), GAPyInterpad(0), GAPyBorder(0);
0102   switch (det) {
0103     case GeomDetType::SubDetector::TimingBarrel:
0104       GAPxInterpad = ptp.vitems_[0].vpars_[4];  // Value given in microns
0105       GAPxBorder = ptp.vitems_[0].vpars_[5];    // Value given in microns
0106       GAPyInterpad = ptp.vitems_[0].vpars_[6];  // Value given in microns
0107       GAPyBorder = ptp.vitems_[0].vpars_[7];    // Value given in microns
0108       ROCrows = ptp.vitems_[0].vpars_[8];
0109       ROCcols = ptp.vitems_[0].vpars_[9];
0110       ROCSx = ptp.vitems_[0].vpars_[10];
0111       ROCSy = ptp.vitems_[0].vpars_[11];
0112       break;
0113     case GeomDetType::SubDetector::TimingEndcap:
0114       GAPxInterpad = ptp.vitems_[1].vpars_[4];
0115       GAPxBorder = ptp.vitems_[1].vpars_[5];
0116       GAPyInterpad = ptp.vitems_[1].vpars_[6];
0117       GAPyBorder = ptp.vitems_[1].vpars_[7];
0118       ROCrows = ptp.vitems_[1].vpars_[8];
0119       ROCcols = ptp.vitems_[1].vpars_[9];
0120       ROCSx = ptp.vitems_[1].vpars_[10];
0121       ROCSy = ptp.vitems_[1].vpars_[11];
0122       break;
0123       break;
0124     default:
0125       throw cms::Exception("UnknownDet") << "MTDGeomBuilderFromGeometricTimingDet got a weird detector: " << det;
0126   }
0127 
0128   switch (det) {
0129     case GeomDetEnumerators::TimingBarrel:
0130       tracker->setOffsetDU(0);
0131       break;
0132     case GeomDetEnumerators::TimingEndcap:
0133       tracker->setOffsetDU(1);
0134       break;
0135     default:
0136       throw cms::Exception("MTDGeomBuilderFromGeometricTimingDet") << det << " is not a timing detector!";
0137   }
0138 
0139   for (auto i : gdv) {
0140     std::string const& detName = i->name();
0141     if (theMTDDetTypeMap.find(detName) == theMTDDetTypeMap.end()) {
0142       std::unique_ptr<const Bounds> bounds(i->bounds());
0143 
0144       PixelTopology* t = MTDPixelTopologyBuilder().build(
0145           &*bounds, ROCrows, ROCcols, ROCSx, ROCSy, GAPxInterpad, GAPxBorder, GAPyInterpad, GAPyBorder);
0146 
0147       theMTDDetTypeMap[detName] = new MTDGeomDetType(t, detName, det);
0148       tracker->addType(theMTDDetTypeMap[detName]);
0149     }
0150 
0151     PlaneBuilderFromGeometricTimingDet::ResultType plane = buildPlaneWithMaterial(i);
0152     GeomDetUnit* temp = new MTDGeomDetUnit(&(*plane), theMTDDetTypeMap[detName], i->geographicalID());
0153 
0154     tracker->addDetUnit(temp);
0155     tracker->addDetUnitId(i->geographicalID());
0156   }
0157   switch (det) {
0158     case GeomDetEnumerators::TimingBarrel:
0159       tracker->setEndsetDU(0);
0160       break;
0161     case GeomDetEnumerators::TimingEndcap:
0162       tracker->setEndsetDU(1);
0163       break;
0164     default:
0165       throw cms::Exception("MTDGeomBuilderFromGeometricTimingDet") << det << " is not a timing detector!";
0166   }
0167 }
0168 
0169 void MTDGeomBuilderFromGeometricTimingDet::buildGeomDet(MTDGeometry* tracker) {
0170   auto const& gdu = tracker->detUnits();
0171   auto const& gduId = tracker->detUnitIds();
0172 
0173   for (u_int32_t i = 0; i < gdu.size(); i++) {
0174     tracker->addDet(gdu[i]);
0175     tracker->addDetId(gduId[i]);
0176     string gduTypeName = gdu[i]->type().name();
0177   }
0178 }
0179 
0180 PlaneBuilderFromGeometricTimingDet::ResultType MTDGeomBuilderFromGeometricTimingDet::buildPlaneWithMaterial(
0181     const GeometricTimingDet* gd, double scale) const {
0182   PlaneBuilderFromGeometricTimingDet planeBuilder;
0183   PlaneBuilderFromGeometricTimingDet::ResultType plane = planeBuilder.plane(gd);
0184   //
0185   // set medium properties (if defined)
0186   //
0187   plane->setMediumProperties(MediumProperties(gd->radLength() * scale, gd->xi() * scale));
0188 
0189   return plane;
0190 }