Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:36

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "Geometry/EcalTestBeam/plugins/EcalTBHodoscopeGeometryLoaderFromDDD.h"
0003 #include "Geometry/EcalTestBeam/interface/EcalTBHodoscopeGeometry.h"
0004 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0005 
0006 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0007 #include "DetectorDescription/Core/interface/DDFilter.h"
0008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0009 #include "DetectorDescription/Core/interface/DDSolid.h"
0010 #include "DetectorDescription/Core/interface/DDTransform.h"
0011 #include "DetectorDescription/Core/interface/DDExpandedView.h"
0012 #include "DetectorDescription/Core/interface/DDName.h"
0013 
0014 typedef CaloCellGeometry::CCGFloat CCGFloat;
0015 
0016 #include <iostream>
0017 #include <utility>
0018 #include <vector>
0019 #include <memory>
0020 
0021 std::unique_ptr<CaloSubdetectorGeometry> EcalTBHodoscopeGeometryLoaderFromDDD::load(const DDCompactView* cpv) {
0022   edm::LogVerbatim("EcalTBHodoscopeGeometry")
0023       << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: start the construction of EcalTBHodoscope";
0024 
0025   std::unique_ptr<CaloSubdetectorGeometry> ebg(new EcalTBHodoscopeGeometry());
0026 
0027   makeGeometry(cpv, ebg.get());
0028 
0029   edm::LogVerbatim("EcalTBHodoscopeGeometry")
0030       << "[EcalTBHodoscopeGeometryLoaderFromDDD]:: Returning EcalTBHodoscopeGeometry";
0031 
0032   return ebg;
0033 }
0034 
0035 void EcalTBHodoscopeGeometryLoaderFromDDD::makeGeometry(const DDCompactView* cpv, CaloSubdetectorGeometry* ebg) {
0036   if (ebg->cornersMgr() == nullptr)
0037     ebg->allocateCorners(EBDetId::kSizeForDenseIndexing);
0038   if (ebg->parMgr() == nullptr)
0039     ebg->allocatePar(10, 3);
0040 
0041   std::unique_ptr<DDFilter> filter{getDDFilter()};
0042 
0043   DDFilteredView fv(*cpv, *filter);
0044 
0045   bool doSubDets;
0046   for (doSubDets = fv.firstChild(); doSubDets; doSubDets = fv.nextSibling()) {
0047 #if 0
0048       std::string answer = getDDDString("ReadOutName",&fv);
0049       if (answer != "EcalTBH4BeamHits")
0050         continue;
0051 #endif
0052 
0053     const DDSolid& solid = fv.logicalPart().solid();
0054 
0055     if (solid.shape() != DDSolidShape::ddbox) {
0056       throw cms::Exception("DDException")
0057           << std::string(__FILE__)
0058           << "\n CaloGeometryEcalTBHodoscope::upDate(...): currently only box fiber shapes supported ";
0059       edm::LogWarning("EcalTBHodoscopeGeometry") << "Wrong shape for sensitive volume!" << solid;
0060     }
0061 
0062     std::vector<double> pv = solid.parameters();
0063 
0064     // use preshower strip as box in space representation
0065 
0066     // rotate the box and then move it
0067     DD3Vector x, y, z;
0068     fv.rotation().GetComponents(x, y, z);
0069     CLHEP::Hep3Vector hx(x.X(), x.Y(), x.Z());
0070     CLHEP::Hep3Vector hy(y.X(), y.Y(), y.Z());
0071     CLHEP::Hep3Vector hz(z.X(), z.Y(), z.Z());
0072     CLHEP::HepRotation hrot(hx, hy, hz);
0073     CLHEP::Hep3Vector htran(fv.translation().X(), fv.translation().Y(), fv.translation().Z());
0074 
0075     const HepGeom::Transform3D ht3d(hrot,  // only scale translation
0076                                     CaloCellGeometry::k_ScaleFromDDDtoGeant * htran);
0077 
0078     const HepGeom::Point3D<float> ctr(ht3d * HepGeom::Point3D<float>(0, 0, 0));
0079 
0080     const GlobalPoint refPoint(ctr.x(), ctr.y(), ctr.z());
0081 
0082     std::vector<CCGFloat> vv;
0083     vv.reserve(pv.size() + 1);
0084     for (unsigned int i(0); i != pv.size(); ++i) {
0085       vv.emplace_back(CaloCellGeometry::k_ScaleFromDDDtoGeant * pv[i]);
0086     }
0087     vv.emplace_back(0.);  // tilt=0 here
0088     const CCGFloat* pP(CaloCellGeometry::getParmPtr(vv, ebg->parMgr(), ebg->parVecVec()));
0089 
0090     const DetId detId(getDetIdForDDDNode(fv));
0091 
0092     //Adding cell to the Geometry
0093 
0094     ebg->newCell(refPoint, refPoint, refPoint, pP, detId);
0095   }  // loop over all children
0096 }
0097 
0098 unsigned int EcalTBHodoscopeGeometryLoaderFromDDD::getDetIdForDDDNode(const DDFilteredView& fv) {
0099   // perform some consistency checks
0100   // get the parents and grandparents of this node
0101   DDGeoHistory parents = fv.geoHistory();
0102 
0103   assert(parents.size() >= 3);
0104 
0105   EcalBaseNumber baseNumber;
0106   //baseNumber.setSize(parents.size());
0107 
0108   for (unsigned int i = 1; i <= parents.size(); i++) {
0109     baseNumber.addLevel(parents[parents.size() - i].logicalPart().name().name(), parents[parents.size() - i].copyno());
0110   }
0111 
0112   return _scheme.getUnitID(baseNumber);
0113 }
0114 
0115 DDFilter* EcalTBHodoscopeGeometryLoaderFromDDD::getDDFilter() {
0116   return new DDAndFilter<DDSpecificsMatchesValueFilter, DDSpecificsMatchesValueFilter>(
0117       DDSpecificsMatchesValueFilter{DDValue("SensitiveDetector", "EcalTBH4BeamDetector", 0)},
0118       DDSpecificsMatchesValueFilter{DDValue("ReadOutName", "EcalTBH4BeamHits", 0)});
0119 }