CMS 3D CMS Logo

TrackerGeometricDetExtraESModule.cc
Go to the documentation of this file.
19 #include "ExtractStringFromDDD.h"
21 
22 #include <memory>
23 
25 public:
27 
28  std::unique_ptr<std::vector<GeometricDetExtra> > produce(const IdealGeometryRecord&);
29 
30  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
31 
32 private:
33  void putOne(std::vector<GeometricDetExtra>& gde, const GeometricDet* gd, const DDExpandedView& ev, int lev);
34 
39  const bool fromDDD_;
40  const bool fromDD4hep_;
41 };
42 
43 using namespace edm;
44 
46  : fromDDD_(p.getParameter<bool>("fromDDD")), fromDD4hep_(p.getParameter<bool>("fromDD4hep")) {
47  auto c = setWhatProduced(this);
49  if (fromDDD_) {
50  ddToken_ = c.consumes<DDCompactView>(edm::ESInputTag());
51  } else if (fromDD4hep_) {
53  } else {
55  }
56 }
57 
60  descDB.add<bool>("fromDDD", false);
61  descDB.add<bool>("fromDD4hep", false);
62  descriptions.add("trackerNumberingExtraGeometryDB", descDB);
63 
65  desc.add<bool>("fromDDD", true);
66  desc.add<bool>("fromDD4hep", false);
67  descriptions.add("trackerNumberingExtraGeometry", desc);
68 
70  descDD4hep.add<bool>("fromDDD", false);
71  descDD4hep.add<bool>("fromDD4hep", true);
72  descriptions.add("DD4hep_trackerNumberingExtraGeometry", descDD4hep);
73 }
74 
75 std::unique_ptr<std::vector<GeometricDetExtra> > TrackerGeometricDetExtraESModule::produce(
76  const IdealGeometryRecord& iRecord) {
77  auto gde = std::make_unique<std::vector<GeometricDetExtra> >();
78  // get the GeometricDet which has a nav_type
79  GeometricDet const& gd = iRecord.get(geometricDetToken_);
80  if (fromDDD_) {
81  // traverse all components from the tracker down;
82  // read the DD if from DD
83  const GeometricDet* tracker = &(gd);
85  DDExpandedView ev(*cpv);
86  ev.goTo(tracker->navType());
87  putOne((*gde), tracker, ev, 0);
88  std::vector<const GeometricDet*> tc = tracker->components();
89  std::vector<const GeometricDet*>::const_iterator git = tc.begin();
90  std::vector<const GeometricDet*>::const_iterator egit = tc.end();
91  int count = 0;
92  int lev = 1;
93  // CmsTrackerStringToEnum ctst
94  gde->reserve(tracker->deepComponents().size());
95  for (; git != egit; ++git) { // one level below "tracker"
96  ev.goTo((*git)->navType());
97  putOne((*gde), *git, ev, lev);
98  std::vector<const GeometricDet*> inone = (*git)->components();
99  // std::cout << lev << " type " << (*git)->type() << " " << int((*git)->geographicalId()) << std::endl; // << " has " << inone.size() << " components." << std::endl;
100  if (inone.empty())
101  ++count;
102  std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
103  std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
104  ++lev;
105  for (; git2 != egit2; ++git2) { // level 2
106  ev.goTo((*git2)->navType());
107  putOne((*gde), *git2, ev, lev);
108  std::vector<const GeometricDet*> intwo = (*git2)->components();
109  // std::cout << lev << "\ttype " << (*git2)->type() << " " << int((*git2)->geographicalId()) << std::endl; // << " has " << intwo.size() << " components." << std::endl;
110  if (intwo.empty())
111  ++count;
112  std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
113  std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
114  ++lev;
115  for (; git3 != egit3; ++git3) { // level 3
116  ev.goTo((*git3)->navType());
117  putOne((*gde), *git3, ev, lev);
118  std::vector<const GeometricDet*> inthree = (*git3)->components();
119  //std::cout << lev << "\t\ttype " << (*git3)->type() << " " << int((*git3)->geographicalId()) << std::endl; // << " has " << inthree.size() << " components." << std::endl;
120  if (inthree.empty())
121  ++count;
122  std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
123  std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
124  ++lev;
125  for (; git4 != egit4; ++git4) { //level 4
126  ev.goTo((*git4)->navType());
127  putOne((*gde), *git4, ev, lev);
128  std::vector<const GeometricDet*> infour = (*git4)->components();
129  // std::cout << lev << "\t\t\ttype " << (*git4)->type() << " " << int((*git4)->geographicalId()) << std::endl; // << " has " << infour.size() << " components." << std::endl;
130  if (infour.empty())
131  ++count;
132  std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
133  std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
134  ++lev;
135  for (; git5 != egit5; ++git5) { // level 5
136  ev.goTo((*git5)->navType());
137  putOne((*gde), *git5, ev, lev);
138  std::vector<const GeometricDet*> infive = (*git5)->components();
139  // std::cout << lev << "\t\t\t\ttype " << (*git5)->type() << " " << int((*git5)->geographicalId()) << std::endl; // << " has " << infive.size() << " components." << std::endl;
140  if (infive.empty())
141  ++count;
142  std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
143  std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
144  ++lev;
145  for (; git6 != egit6; ++git6) { //level 6
146  ev.goTo((*git6)->navType());
147  putOne((*gde), *git6, ev, lev);
148  std::vector<const GeometricDet*> insix = (*git6)->components();
149  // std::cout << lev << "\t\t\t\t\ttype " << (*git6)->type() << " " << int((*git6)->geographicalId()) << std::endl; // << " has " << insix.size() << " components." << std::endl;
150  if (insix.empty()) {
151  ++count;
152  } else {
153  edm::LogError("GeometricDetExtra") << "Hierarchy has exceeded hard-coded level 6 for Tracker ";
154  }
155  } // level 6
156  --lev;
157  } // level 5
158  --lev;
159  } // level 4
160  --lev;
161  } //level 3
162  --lev;
163  } // level 2
164  --lev;
165  }
166  } else if (fromDD4hep_) {
167  // FIXME:
168  // traverse all components from the tracker down;
169  // read the DD if from DD
170  const GeometricDet* tracker = &(gd);
172  edm::LogInfo("GeometricDetExtra") << " Top node is " << tracker << " " << tracker->name() << std::endl;
173  edm::LogInfo("GeometricDetExtra") << " radLength " << tracker->radLength() << "\n"
174  << " xi " << tracker->xi() << "\n"
175  << " PixelROCRows " << tracker->pixROCRows() << "\n"
176  << " PixROCCols " << tracker->pixROCCols() << "\n"
177  << " PixelROC_X " << tracker->pixROCx() << "\n"
178  << " PixelROC_Y " << tracker->pixROCy() << "\n"
179  << "TrackerStereoDetectors " << (tracker->stereo() ? "true" : "false") << "\n"
180  << "SiliconAPVNumber " << tracker->siliconAPVNum() << "\n";
181  } else {
182  // if it is not from the DD, then just get the GDE from ES and match w/ GD.
183  PGeometricDetExtra const& pgde = iRecord.getRecord<PGeometricDetExtraRcd>().get(pgToken_);
184  std::map<uint32_t, const GeometricDet*> helperMap;
185  const GeometricDet* tracker = &gd;
186  helperMap[gd.geographicalID()] = tracker;
187  std::vector<const GeometricDet*> tc = tracker->components();
188  std::vector<const GeometricDet*>::const_iterator git = tc.begin();
189  std::vector<const GeometricDet*>::const_iterator egit = tc.end();
190  for (; git != egit; ++git) { // one level below "tracker"
191  helperMap[(*git)->geographicalID()] = (*git);
192  std::vector<const GeometricDet*> inone = (*git)->components();
193  std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
194  std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
195  for (; git2 != egit2; ++git2) { // level 2
196  helperMap[(*git2)->geographicalID()] = (*git2);
197  std::vector<const GeometricDet*> intwo = (*git2)->components();
198  std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
199  std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
200  for (; git3 != egit3; ++git3) { // level 3
201  helperMap[(*git3)->geographicalID()] = (*git3);
202  std::vector<const GeometricDet*> inthree = (*git3)->components();
203  std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
204  std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
205  for (; git4 != egit4; ++git4) { //level 4
206  helperMap[(*git4)->geographicalID()] = (*git4);
207  std::vector<const GeometricDet*> infour = (*git4)->components();
208  std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
209  std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
210  for (; git5 != egit5; ++git5) { // level 5
211  helperMap[(*git5)->geographicalID()] = (*git5);
212  std::vector<const GeometricDet*> infive = (*git5)->components();
213  std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
214  std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
215  for (; git6 != egit6; ++git6) { //level 6
216  helperMap[(*git6)->geographicalID()] = (*git6);
217  if (!(*git6)->components().empty()) {
218  edm::LogError("GeometricDetExtra") << "Hierarchy has exceeded hard-coded level of 6 for Tracker ";
219  }
220  } // level 6
221  } // level 5
222  } // level 4
223  } //level 3
224  } // level 2
225  }
226 
227  const std::vector<PGeometricDetExtra::Item>& pgdes = pgde.pgdes_;
228  gde->reserve(pgdes.size());
229  std::vector<DDExpandedNode> evs; //EMPTY
230  std::string nm; //EMPTY
231  for (const auto& pgde : pgdes) {
232  // GeometricDetExtra( GeometricDet const *gd, DetId id, GeoHistory& gh, double vol, double dens, double wgt, double cpy, const std::string& mat, const std::string& name, bool dd=false );
233  gde->emplace_back(GeometricDetExtra(helperMap[pgde._geographicalId],
234  pgde._geographicalId,
235  evs,
236  pgde._volume,
237  pgde._density,
238  pgde._weight,
239  pgde._copy,
240  pgde._material,
241  nm));
242  }
243  }
244  return gde;
245 }
246 
247 void TrackerGeometricDetExtraESModule::putOne(std::vector<GeometricDetExtra>& gde,
248  const GeometricDet* gd,
249  const DDExpandedView& ev,
250  int lev) {
251  std::string matname = ((ev.logicalPart()).material()).name().fullname();
252  std::string lpname = ((ev.logicalPart()).name().fullname());
253  std::vector<DDExpandedNode> evs = GeometricDetExtra::GeoHistory(ev.geoHistory().begin(), ev.geoHistory().end());
254  gde.emplace_back(
256  gd->geographicalId(),
257  evs,
258  ((ev.logicalPart()).solid()).volume(),
259  ((ev.logicalPart()).material()).density(),
260  ((ev.logicalPart()).material()).density() * (((ev.logicalPart()).solid()).volume() / 1000.),
261  ev.copyno(),
262  matname,
263  lpname,
264  true));
265 }
266 
double pixROCy() const
Definition: GeometricDet.h:179
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
double radLength() const
Definition: GeometricDet.h:171
void putOne(std::vector< GeometricDetExtra > &gde, const GeometricDet *gd, const DDExpandedView &ev, int lev)
nav_type const & navType() const
Definition: GeometricDet.h:129
std::vector< Item > pgdes_
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
bool ev
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
edm::ESGetToken< DDCompactView, IdealGeometryRecord > ddToken_
ConstGeometricDetContainer & components()
Definition: GeometricDet.h:139
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
std::string const & name() const
Definition: GeometricDet.h:126
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
TrackerGeometricDetExtraESModule(const edm::ParameterSet &p)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double pixROCCols() const
Definition: GeometricDet.h:177
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
int copyno() const
Copy number associated with the current node.
std::unique_ptr< std::vector< GeometricDetExtra > > produce(const IdealGeometryRecord &)
double xi() const
Definition: GeometricDet.h:172
DetId geographicalId() const
Definition: GeometricDet.h:154
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double pixROCx() const
Definition: GeometricDet.h:178
edm::ESGetToken< PGeometricDetExtra, PGeometricDetExtraRcd > pgToken_
ConstGeometricDetContainer deepComponents() const
std::vector< DDExpandedNode > GeoHistory
HLT enums.
bool goTo(const nav_type &)
transversed the DDExpandedView according to the given stack of sibling numbers
double siliconAPVNum() const
Definition: GeometricDet.h:185
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepToken_
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
bool stereo() const
Definition: GeometricDet.h:184
double pixROCRows() const
Definition: GeometricDet.h:176
Provides an exploded view of the detector (tree-view)
edm::ESGetToken< GeometricDet, IdealGeometryRecord > geometricDetToken_