Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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