Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-25 03:29:19

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 count = 0;
0067   int lev = 1;
0068   for (; git != egit; ++git) {  // one level below "tracker"
0069     putOne(*git, &pgd, lev);
0070     std::vector<const GeometricDet*> inone = (*git)->components();
0071     if (inone.empty())
0072       ++count;
0073     std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
0074     std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
0075     ++lev;
0076     for (; git2 != egit2; ++git2) {  // level 2
0077       putOne(*git2, &pgd, lev);
0078       std::vector<const GeometricDet*> intwo = (*git2)->components();
0079       if (intwo.empty())
0080         ++count;
0081       std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
0082       std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
0083       ++lev;
0084       for (; git3 != egit3; ++git3) {  // level 3
0085         putOne(*git3, &pgd, lev);
0086         std::vector<const GeometricDet*> inthree = (*git3)->components();
0087         if (inthree.empty())
0088           ++count;
0089         std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
0090         std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
0091         ++lev;
0092         for (; git4 != egit4; ++git4) {  //level 4
0093           putOne(*git4, &pgd, lev);
0094           std::vector<const GeometricDet*> infour = (*git4)->components();
0095           if (infour.empty())
0096             ++count;
0097           std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
0098           std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
0099           ++lev;
0100           for (; git5 != egit5; ++git5) {  // level 5
0101             putOne(*git5, &pgd, lev);
0102             std::vector<const GeometricDet*> infive = (*git5)->components();
0103             if (infive.empty())
0104               ++count;
0105             std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
0106             std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
0107             ++lev;
0108             for (; git6 != egit6; ++git6) {  //level 6
0109               putOne(*git6, &pgd, lev);
0110               std::vector<const GeometricDet*> insix = (*git6)->components();
0111               if (insix.empty())
0112                 ++count;
0113             }  // level 6
0114             --lev;
0115           }  // level 5
0116           --lev;
0117         }  // level 4
0118         --lev;
0119       }  //level 3
0120       --lev;
0121     }  // level 2
0122     --lev;
0123   }
0124   if (mydbservice->isNewTagRequest("IdealGeometryRecord")) {
0125     mydbservice->createOneIOV(pgd, mydbservice->beginOfTime(), "IdealGeometryRecord");
0126   } else {
0127     edm::LogError("PGeometricDetBuilder") << "PGeometricDetBuilder Tag already present";
0128   }
0129 }
0130 
0131 void PGeometricDetBuilder::putOne(const GeometricDet* gd, PGeometricDet* pgd, int lev) {
0132   PGeometricDet::Item item;
0133   const Translation& tran = gd->translation();
0134   const RotationMatrix& rot = gd->rotation();
0135   DD3Vector x, y, z;
0136   rot.GetComponents(x, y, z);
0137   item._name = gd->name();
0138   item._ns = std::string();
0139   item._level = lev;
0140   using cms_rounding::roundIfNear0;
0141   const double tol = 1.e-10;
0142   // Round very small calculated values to 0 to avoid discrepancies
0143   // between +0 and -0 in comparisons.
0144   item._x = roundIfNear0(tran.X(), tol);
0145   item._y = roundIfNear0(tran.Y(), tol);
0146   item._z = roundIfNear0(tran.Z(), tol);
0147   item._phi = gd->phi();
0148   item._rho = gd->rho();
0149   item._a11 = roundIfNear0(x.X(), tol);
0150   item._a12 = roundIfNear0(y.X(), tol);
0151   item._a13 = roundIfNear0(z.X(), tol);
0152   item._a21 = roundIfNear0(x.Y(), tol);
0153   item._a22 = roundIfNear0(y.Y(), tol);
0154   item._a23 = roundIfNear0(z.Y(), tol);
0155   item._a31 = roundIfNear0(x.Z(), tol);
0156   item._a32 = roundIfNear0(y.Z(), tol);
0157   item._a33 = roundIfNear0(z.Z(), tol);
0158   item._shape = static_cast<int>(gd->shape_dd4hep());
0159   item._type = gd->type();
0160   if (gd->shape_dd4hep() == cms::DDSolidShape::ddbox) {
0161     item._params0 = gd->params()[0];
0162     item._params1 = gd->params()[1];
0163     item._params2 = gd->params()[2];
0164     item._params3 = 0;
0165     item._params4 = 0;
0166     item._params5 = 0;
0167     item._params6 = 0;
0168     item._params7 = 0;
0169     item._params8 = 0;
0170     item._params9 = 0;
0171     item._params10 = 0;
0172   } else if (gd->shape_dd4hep() == cms::DDSolidShape::ddtrap) {
0173     item._params0 = gd->params()[0];
0174     item._params1 = gd->params()[1];
0175     item._params2 = gd->params()[2];
0176     item._params3 = gd->params()[3];
0177     item._params4 = gd->params()[4];
0178     item._params5 = gd->params()[5];
0179     item._params6 = gd->params()[6];
0180     item._params7 = gd->params()[7];
0181     item._params8 = gd->params()[8];
0182     item._params9 = gd->params()[9];
0183     item._params10 = gd->params()[10];
0184   } else {
0185     item._params0 = 0;
0186     item._params1 = 0;
0187     item._params2 = 0;
0188     item._params3 = 0;
0189     item._params4 = 0;
0190     item._params5 = 0;
0191     item._params6 = 0;
0192     item._params7 = 0;
0193     item._params8 = 0;
0194     item._params9 = 0;
0195     item._params10 = 0;
0196   }
0197   item._geographicalID = gd->geographicalId();
0198   item._radLength = gd->radLength();
0199   item._xi = gd->xi();
0200   item._pixROCRows = gd->pixROCRows();
0201   item._pixROCCols = gd->pixROCCols();
0202   item._pixROCx = gd->pixROCx();
0203   item._pixROCy = gd->pixROCy();
0204   item._stereo = gd->stereo();
0205   item._siliconAPVNum = gd->siliconAPVNum();
0206 
0207   GeometricDet::nav_type const& nt = gd->navType();
0208   size_t nts = nt.size();
0209   item._numnt = nts;
0210   std::vector<int> tempnt(nt.begin(), nt.end());
0211   for (size_t extrant = nt.size(); extrant < 11; ++extrant) {
0212     tempnt.push_back(-1);
0213   }
0214   item._nt0 = tempnt[0];
0215   item._nt1 = tempnt[1];
0216   item._nt2 = tempnt[2];
0217   item._nt3 = tempnt[3];
0218   item._nt4 = tempnt[4];
0219   item._nt5 = tempnt[5];
0220   item._nt6 = tempnt[6];
0221   item._nt7 = tempnt[7];
0222   item._nt8 = tempnt[8];
0223   item._nt9 = tempnt[9];
0224   item._nt10 = tempnt[10];
0225 
0226   pgd->pgeomdets_.push_back(item);
0227 }
0228 
0229 DEFINE_FWK_MODULE(PGeometricDetBuilder);