Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/ServiceRegistry/interface/Service.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ESTransientHandle.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "CondFormats/GeometryObjects/interface/PGeometricDet.h"
0011 #include "DataFormats/Math/interface/Rounding.h"
0012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0013 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0014 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0015 #include "DetectorDescription/Core/interface/DDCompactView.h"
0016 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include <vector>
0019 
0020 using DD3Vector = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
0021 using Translation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
0022 using RotationMatrix = ROOT::Math::Rotation3D;
0023 
0024 class PGeometricDetBuilder : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0025 public:
0026   PGeometricDetBuilder(const edm::ParameterSet&);
0027 
0028   void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
0029   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0030   void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0031 
0032 private:
0033   void putOne(const GeometricDet* gd, PGeometricDet* pgd, int lev);
0034   bool fromDD4hep_;
0035   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4HepCompactViewToken_;
0036   edm::ESGetToken<DDCompactView, IdealGeometryRecord> compactViewToken_;
0037   edm::ESGetToken<GeometricDet, IdealGeometryRecord> geometricDetToken_;
0038 };
0039 
0040 PGeometricDetBuilder::PGeometricDetBuilder(const edm::ParameterSet& iConfig) {
0041   fromDD4hep_ = iConfig.getParameter<bool>("fromDD4hep");
0042   dd4HepCompactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0043   compactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0044   geometricDetToken_ = esConsumes<edm::Transition::BeginRun>();
0045 }
0046 
0047 void PGeometricDetBuilder::beginRun(const edm::Run&, edm::EventSetup const& es) {
0048   PGeometricDet pgd;
0049   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0050   if (!mydbservice.isAvailable()) {
0051     edm::LogError("PGeometricDetBuilder") << "PoolDBOutputService unavailable";
0052     return;
0053   }
0054   if (!fromDD4hep_) {
0055     auto pDD = es.getTransientHandle(compactViewToken_);
0056   } else {
0057     auto pDD = es.getTransientHandle(dd4HepCompactViewToken_);
0058   }
0059   const GeometricDet* tracker = &es.getData(geometricDetToken_);
0060 
0061   // so now I have the tracker itself. loop over all its components to store them.
0062   putOne(tracker, &pgd, 0);
0063   std::vector<const GeometricDet*> tc = tracker->components();
0064   std::vector<const GeometricDet*>::const_iterator git = tc.begin();
0065   std::vector<const GeometricDet*>::const_iterator egit = tc.end();
0066   int lev = 1;
0067   for (; git != egit; ++git) {  // one level below "tracker"
0068     putOne(*git, &pgd, lev);
0069     std::vector<const GeometricDet*> inone = (*git)->components();
0070     std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
0071     std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
0072     ++lev;
0073     for (; git2 != egit2; ++git2) {  // level 2
0074       putOne(*git2, &pgd, lev);
0075       std::vector<const GeometricDet*> intwo = (*git2)->components();
0076       std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
0077       std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
0078       ++lev;
0079       for (; git3 != egit3; ++git3) {  // level 3
0080         putOne(*git3, &pgd, lev);
0081         std::vector<const GeometricDet*> inthree = (*git3)->components();
0082         std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
0083         std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
0084         ++lev;
0085         for (; git4 != egit4; ++git4) {  //level 4
0086           putOne(*git4, &pgd, lev);
0087           std::vector<const GeometricDet*> infour = (*git4)->components();
0088           std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
0089           std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
0090           ++lev;
0091           for (; git5 != egit5; ++git5) {  // level 5
0092             putOne(*git5, &pgd, lev);
0093             std::vector<const GeometricDet*> infive = (*git5)->components();
0094             std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
0095             std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
0096             ++lev;
0097             for (; git6 != egit6; ++git6) {  //level 6
0098               putOne(*git6, &pgd, lev);
0099               std::vector<const GeometricDet*> insix = (*git6)->components();
0100             }  // level 6
0101             --lev;
0102           }  // level 5
0103           --lev;
0104         }  // level 4
0105         --lev;
0106       }  //level 3
0107       --lev;
0108     }  // level 2
0109     --lev;
0110   }
0111   if (mydbservice->isNewTagRequest("IdealGeometryRecord")) {
0112     mydbservice->createOneIOV(pgd, mydbservice->beginOfTime(), "IdealGeometryRecord");
0113   } else {
0114     edm::LogError("PGeometricDetBuilder") << "PGeometricDetBuilder Tag already present";
0115   }
0116 }
0117 
0118 void PGeometricDetBuilder::putOne(const GeometricDet* gd, PGeometricDet* pgd, int lev) {
0119   PGeometricDet::Item item;
0120   const Translation& tran = gd->translation();
0121   const RotationMatrix& rot = gd->rotation();
0122   DD3Vector x, y, z;
0123   rot.GetComponents(x, y, z);
0124   item._name = gd->name();
0125   item._ns = std::string();
0126   item._level = lev;
0127   using cms_rounding::roundIfNear0;
0128   const double tol = 1.e-10;
0129   // Round very small calculated values to 0 to avoid discrepancies
0130   // between +0 and -0 in comparisons.
0131   item._x = roundIfNear0(tran.X(), tol);
0132   item._y = roundIfNear0(tran.Y(), tol);
0133   item._z = roundIfNear0(tran.Z(), tol);
0134   item._phi = gd->phi();
0135   item._rho = gd->rho();
0136   item._a11 = roundIfNear0(x.X(), tol);
0137   item._a12 = roundIfNear0(y.X(), tol);
0138   item._a13 = roundIfNear0(z.X(), tol);
0139   item._a21 = roundIfNear0(x.Y(), tol);
0140   item._a22 = roundIfNear0(y.Y(), tol);
0141   item._a23 = roundIfNear0(z.Y(), tol);
0142   item._a31 = roundIfNear0(x.Z(), tol);
0143   item._a32 = roundIfNear0(y.Z(), tol);
0144   item._a33 = roundIfNear0(z.Z(), tol);
0145   item._shape = static_cast<int>(gd->shape_dd4hep());
0146   item._type = gd->type();
0147   if (gd->shape_dd4hep() == cms::DDSolidShape::ddbox) {
0148     item._params0 = gd->params()[0];
0149     item._params1 = gd->params()[1];
0150     item._params2 = gd->params()[2];
0151     item._params3 = 0;
0152     item._params4 = 0;
0153     item._params5 = 0;
0154     item._params6 = 0;
0155     item._params7 = 0;
0156     item._params8 = 0;
0157     item._params9 = 0;
0158     item._params10 = 0;
0159   } else if (gd->shape_dd4hep() == cms::DDSolidShape::ddtrap) {
0160     item._params0 = gd->params()[0];
0161     item._params1 = gd->params()[1];
0162     item._params2 = gd->params()[2];
0163     item._params3 = gd->params()[3];
0164     item._params4 = gd->params()[4];
0165     item._params5 = gd->params()[5];
0166     item._params6 = gd->params()[6];
0167     item._params7 = gd->params()[7];
0168     item._params8 = gd->params()[8];
0169     item._params9 = gd->params()[9];
0170     item._params10 = gd->params()[10];
0171   } else {
0172     item._params0 = 0;
0173     item._params1 = 0;
0174     item._params2 = 0;
0175     item._params3 = 0;
0176     item._params4 = 0;
0177     item._params5 = 0;
0178     item._params6 = 0;
0179     item._params7 = 0;
0180     item._params8 = 0;
0181     item._params9 = 0;
0182     item._params10 = 0;
0183   }
0184   item._geographicalID = gd->geographicalId();
0185   item._radLength = gd->radLength();
0186   item._xi = gd->xi();
0187   item._pixROCRows = gd->pixROCRows();
0188   item._pixROCCols = gd->pixROCCols();
0189   item._pixROCx = gd->pixROCx();
0190   item._pixROCy = gd->pixROCy();
0191   item._stereo = gd->stereo();
0192   item._siliconAPVNum = gd->siliconAPVNum();
0193 
0194   GeometricDet::nav_type const& nt = gd->navType();
0195   size_t nts = nt.size();
0196   item._numnt = nts;
0197   std::vector<int> tempnt(nt.begin(), nt.end());
0198   for (size_t extrant = nt.size(); extrant < 11; ++extrant) {
0199     tempnt.push_back(-1);
0200   }
0201   item._nt0 = tempnt[0];
0202   item._nt1 = tempnt[1];
0203   item._nt2 = tempnt[2];
0204   item._nt3 = tempnt[3];
0205   item._nt4 = tempnt[4];
0206   item._nt5 = tempnt[5];
0207   item._nt6 = tempnt[6];
0208   item._nt7 = tempnt[7];
0209   item._nt8 = tempnt[8];
0210   item._nt9 = tempnt[9];
0211   item._nt10 = tempnt[10];
0212 
0213   pgd->pgeomdets_.push_back(item);
0214 }
0215 
0216 DEFINE_FWK_MODULE(PGeometricDetBuilder);