CMS 3D CMS Logo

PGeometricDetBuilder.cc
Go to the documentation of this file.
18 #include <vector>
19 
20 using DD3Vector = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
21 using Translation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
22 using RotationMatrix = ROOT::Math::Rotation3D;
23 
24 class PGeometricDetBuilder : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
25 public:
27 
28  void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
29  void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
30  void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
31 
32 private:
33  void putOne(const GeometricDet* gd, PGeometricDet* pgd, int lev);
38 };
39 
41  fromDD4hep_ = iConfig.getParameter<bool>("fromDD4hep");
42  dd4HepCompactViewToken_ = esConsumes<edm::Transition::BeginRun>();
43  compactViewToken_ = esConsumes<edm::Transition::BeginRun>();
44  geometricDetToken_ = esConsumes<edm::Transition::BeginRun>();
45 }
46 
48  PGeometricDet pgd;
50  if (!mydbservice.isAvailable()) {
51  edm::LogError("PGeometricDetBuilder") << "PoolDBOutputService unavailable";
52  return;
53  }
54  if (!fromDD4hep_) {
56  } else {
58  }
60 
61  // so now I have the tracker itself. loop over all its components to store them.
62  putOne(tracker, &pgd, 0);
63  std::vector<const GeometricDet*> tc = tracker->components();
64  std::vector<const GeometricDet*>::const_iterator git = tc.begin();
65  std::vector<const GeometricDet*>::const_iterator egit = tc.end();
66  int lev = 1;
67  for (; git != egit; ++git) { // one level below "tracker"
68  putOne(*git, &pgd, lev);
69  std::vector<const GeometricDet*> inone = (*git)->components();
70  std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
71  std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
72  ++lev;
73  for (; git2 != egit2; ++git2) { // level 2
74  putOne(*git2, &pgd, lev);
75  std::vector<const GeometricDet*> intwo = (*git2)->components();
76  std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
77  std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
78  ++lev;
79  for (; git3 != egit3; ++git3) { // level 3
80  putOne(*git3, &pgd, lev);
81  std::vector<const GeometricDet*> inthree = (*git3)->components();
82  std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
83  std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
84  ++lev;
85  for (; git4 != egit4; ++git4) { //level 4
86  putOne(*git4, &pgd, lev);
87  std::vector<const GeometricDet*> infour = (*git4)->components();
88  std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
89  std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
90  ++lev;
91  for (; git5 != egit5; ++git5) { // level 5
92  putOne(*git5, &pgd, lev);
93  std::vector<const GeometricDet*> infive = (*git5)->components();
94  std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
95  std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
96  ++lev;
97  for (; git6 != egit6; ++git6) { //level 6
98  putOne(*git6, &pgd, lev);
99  std::vector<const GeometricDet*> insix = (*git6)->components();
100  } // level 6
101  --lev;
102  } // level 5
103  --lev;
104  } // level 4
105  --lev;
106  } //level 3
107  --lev;
108  } // level 2
109  --lev;
110  }
111  if (mydbservice->isNewTagRequest("IdealGeometryRecord")) {
112  mydbservice->createOneIOV(pgd, mydbservice->beginOfTime(), "IdealGeometryRecord");
113  } else {
114  edm::LogError("PGeometricDetBuilder") << "PGeometricDetBuilder Tag already present";
115  }
116 }
117 
120  const Translation& tran = gd->translation();
121  const RotationMatrix& rot = gd->rotation();
122  DD3Vector x, y, z;
123  rot.GetComponents(x, y, z);
124  item._name = gd->name();
125  item._ns = std::string();
126  item._level = lev;
128  const double tol = 1.e-10;
129  // Round very small calculated values to 0 to avoid discrepancies
130  // between +0 and -0 in comparisons.
131  item._x = roundIfNear0(tran.X(), tol);
132  item._y = roundIfNear0(tran.Y(), tol);
133  item._z = roundIfNear0(tran.Z(), tol);
134  item._phi = gd->phi();
135  item._rho = gd->rho();
136  item._a11 = roundIfNear0(x.X(), tol);
137  item._a12 = roundIfNear0(y.X(), tol);
138  item._a13 = roundIfNear0(z.X(), tol);
139  item._a21 = roundIfNear0(x.Y(), tol);
140  item._a22 = roundIfNear0(y.Y(), tol);
141  item._a23 = roundIfNear0(z.Y(), tol);
142  item._a31 = roundIfNear0(x.Z(), tol);
143  item._a32 = roundIfNear0(y.Z(), tol);
144  item._a33 = roundIfNear0(z.Z(), tol);
145  item._shape = static_cast<int>(gd->shape_dd4hep());
146  item._type = gd->type();
147  if (gd->shape_dd4hep() == cms::DDSolidShape::ddbox) {
148  item._params0 = gd->params()[0];
149  item._params1 = gd->params()[1];
150  item._params2 = gd->params()[2];
151  item._params3 = 0;
152  item._params4 = 0;
153  item._params5 = 0;
154  item._params6 = 0;
155  item._params7 = 0;
156  item._params8 = 0;
157  item._params9 = 0;
158  item._params10 = 0;
159  } else if (gd->shape_dd4hep() == cms::DDSolidShape::ddtrap) {
160  item._params0 = gd->params()[0];
161  item._params1 = gd->params()[1];
162  item._params2 = gd->params()[2];
163  item._params3 = gd->params()[3];
164  item._params4 = gd->params()[4];
165  item._params5 = gd->params()[5];
166  item._params6 = gd->params()[6];
167  item._params7 = gd->params()[7];
168  item._params8 = gd->params()[8];
169  item._params9 = gd->params()[9];
170  item._params10 = gd->params()[10];
171  } else {
172  item._params0 = 0;
173  item._params1 = 0;
174  item._params2 = 0;
175  item._params3 = 0;
176  item._params4 = 0;
177  item._params5 = 0;
178  item._params6 = 0;
179  item._params7 = 0;
180  item._params8 = 0;
181  item._params9 = 0;
182  item._params10 = 0;
183  }
184  item._geographicalID = gd->geographicalId();
185  item._radLength = gd->radLength();
186  item._xi = gd->xi();
187  item._pixROCRows = gd->pixROCRows();
188  item._pixROCCols = gd->pixROCCols();
189  item._pixROCx = gd->pixROCx();
190  item._pixROCy = gd->pixROCy();
191  item._stereo = gd->stereo();
192  item._siliconAPVNum = gd->siliconAPVNum();
193 
194  GeometricDet::nav_type const& nt = gd->navType();
195  size_t nts = nt.size();
196  item._numnt = nts;
197  std::vector<int> tempnt(nt.begin(), nt.end());
198  for (size_t extrant = nt.size(); extrant < 11; ++extrant) {
199  tempnt.push_back(-1);
200  }
201  item._nt0 = tempnt[0];
202  item._nt1 = tempnt[1];
203  item._nt2 = tempnt[2];
204  item._nt3 = tempnt[3];
205  item._nt4 = tempnt[4];
206  item._nt5 = tempnt[5];
207  item._nt6 = tempnt[6];
208  item._nt7 = tempnt[7];
209  item._nt8 = tempnt[8];
210  item._nt9 = tempnt[9];
211  item._nt10 = tempnt[10];
212 
213  pgd->pgeomdets_.push_back(item);
214 }
215 
double siliconAPVNum() const
Definition: GeometricDet.h:144
double pixROCy() const
Definition: GeometricDet.h:137
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4HepCompactViewToken_
edm::ESGetToken< DDCompactView, IdealGeometryRecord > compactViewToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
double phi() const
Definition: GeometricDet.h:105
const std::vector< double > & params() const
Definition: GeometricDet.h:119
const cms::DDSolidShape & shape_dd4hep() const
Definition: GeometricDet.h:117
std::vector< Item > pgeomdets_
Definition: PGeometricDet.h:50
edm::ESGetToken< GeometricDet, IdealGeometryRecord > geometricDetToken_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > Translation
Log< level::Error, false > LogError
PGeometricDetBuilder(const edm::ParameterSet &)
std::vector< int > nav_type
Definition: GeometricDet.h:42
bool stereo() const
Definition: GeometricDet.h:139
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
const Translation & translation() const
Definition: GeometricDet.h:103
int iEvent
Definition: GenABIO.cc:224
bool isNewTagRequest(const std::string &recordName)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double rho() const
Definition: GeometricDet.h:104
const std::string & name() const
Definition: GeometricDet.h:93
constexpr valType roundIfNear0(valType value, double tolerance=1.e-7)
Definition: Rounding.h:11
const RotationMatrix & rotation() const
Definition: GeometricDet.h:106
int nt
Definition: AMPTWrapper.h:42
double xi() const
Definition: GeometricDet.h:130
ROOT::Math::Rotation3D RotationMatrix
const DetId & geographicalId() const
Definition: GeometricDet.h:99
double radLength() const
Definition: GeometricDet.h:129
void putOne(const GeometricDet *gd, PGeometricDet *pgd, int lev)
const GeometricEnumType & type() const
Definition: GeometricDet.h:94
double pixROCRows() const
Definition: GeometricDet.h:134
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
double pixROCx() const
Definition: GeometricDet.h:136
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:141
const nav_type & navType() const
Definition: GeometricDet.h:97
bool isAvailable() const
Definition: Service.h:40
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
double pixROCCols() const
Definition: GeometricDet.h:135
Definition: Run.h:45