CMS 3D CMS Logo

ListIds.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 #include <iostream>
4 #include <algorithm>
5 
14 
26 
29  std::vector<const DDsvalues_type *> result;
30  view.specificsV(result);
31  for (std::vector<const DDsvalues_type *>::iterator it = result.begin(); it != result.end(); ++it) {
32  if (DDfetch(*it, parameter)) {
33  if (parameter.strings().size() == 1) {
34  value = parameter.strings().front();
35  return true;
36  } else {
37  return false;
38  }
39  }
40  }
41  return false;
42 }
43 
44 /*
45 static inline
46 double dddGetDouble(const std::string & s, const DDFilteredView & view) {
47  std::string value;
48  if (dddGetStringRaw(view, s, value))
49  return double(::atof(value.c_str()));
50  else
51  return NAN;
52 }
53 */
54 
55 static inline std::string dddGetString(const std::string &s, const DDFilteredView &view) {
57  if (dddGetStringRaw(view, s, value))
58  return value;
59  else
60  return std::string();
61 }
62 
63 static inline std::ostream &operator<<(std::ostream &out, const math::XYZVector &v) {
64  return out << "(" << v.rho() << ", " << v.z() << ", " << v.phi() << ")";
65 }
66 
67 class ListIds : public edm::one::EDAnalyzer<> {
68 public:
69  ListIds(const edm::ParameterSet &);
70  ~ListIds() override;
71 
72 private:
73  void analyze(const edm::Event &, const edm::EventSetup &) override;
74  void beginJob() override {}
75  void endJob() override;
76  // List of material names used to select specific detectors.
77  // Names are matched literally, w/o any usage of regexp.
78  // Names should also be specified with the correct namespace,
79  // otherwise the matching will fail.
81  std::vector<std::string> materials_;
84 };
85 
87  : printMaterial_(pset.getUntrackedParameter<bool>("printMaterial")),
88  materials_(pset.getUntrackedParameter<std::vector<std::string> >("materials")),
89  dddToken_(esConsumes()),
90  geoToken_(esConsumes()) {}
91 
93 
95  std::cout << "______________________________ DDD ______________________________" << std::endl;
96  auto hDdd = setup.getTransientHandle(dddToken_);
97 
98  std::string attribute = "TkDDDStructure";
99  CmsTrackerStringToEnum theCmsTrackerStringToEnum;
101  DDFilteredView fv(*hDdd, filter);
102  if (theCmsTrackerStringToEnum.type(dddGetString(attribute, fv)) != GeometricDet::Tracker) {
103  fv.firstChild();
104  if (theCmsTrackerStringToEnum.type(dddGetString(attribute, fv)) != GeometricDet::Tracker)
105  throw cms::Exception("Configuration") << "The first child of the DDFilteredView is not what is expected \n"
106  << dddGetString(attribute, fv);
107  }
108 
109  std::cout << std::fixed << std::setprecision(3);
110  bool printAnyMaterial = (std::find(materials_.begin(), materials_.end(), "ANY") != materials_.end());
111  do {
112  // print the full hierarchy of all elements whose material
113  // has been specified by the user. An empty list of
114  // materials will print no elements. The special
115  // keyword ANY (in any location of the vector)
116  // will select all elements.
117  if (printAnyMaterial ||
118  (std::find(materials_.begin(), materials_.end(), fv.logicalPart().material().name().fullname()) !=
119  materials_.end())) {
120  // start from 2 to skip the leading /OCMS[0]/CMSE[1] part
121  const DDGeoHistory &history = fv.geoHistory();
122  std::cout << '/';
123  for (unsigned int h = 2; h < history.size(); ++h) {
124  std::cout << '/' << history[h].logicalPart().name().ns() << ":" << history[h].logicalPart().name().name() << '['
125  << history[h].copyno() << ']';
126  }
127  if (printMaterial_)
128  std::cout << " Material: |" << fv.logicalPart().material().name() << "|";
129  // DD3Vector and DDTranslation are the same type as math::XYZVector
130  math::XYZVector position = fv.translation() / 10.; // mm -> cm
131  std::cout << "\t" << position << std::endl;
132  }
133  } while (fv.next());
134  std::cout << std::endl;
135 
136  std::cout << "______________________________ std::vector<GeomDet*> from TrackerGeometry::dets() "
137  "______________________________"
138  << std::endl;
139  auto const &geo = setup.getData(geoToken_);
140 
141  std::cout << std::fixed << std::setprecision(3);
142  auto const &dets = geo.dets();
143  for (unsigned int i = 0; i < dets.size(); ++i) {
144  const GeomDet &det = *dets[i];
145 
146  // Surface::PositionType is a typedef for Point3DBase<float,GlobalTag> a.k.a. GlobalPoint
147  const Surface::PositionType &p = det.position();
148  math::XYZVector position(p.x(), p.y(), p.z());
149 
150  std::cout << det.subDetector() << '\t' << det.geographicalId().det() << '\t' << det.geographicalId().subdetId()
151  << '\t' << det.geographicalId().rawId() << "\t" << position;
152  const std::vector<const GeomDet *> &parts = det.components();
153  if (!parts.empty()) {
154  std::cout << "\t[" << parts[0]->geographicalId().rawId();
155  for (unsigned int j = 1; j < parts.size(); ++j)
156  std::cout << '\t' << parts[j]->geographicalId().rawId();
157  std::cout << ']';
158  }
159  std::cout << std::endl;
160  }
161 }
162 
164 
165 //-------------------------------------------------------------------------
166 // define as a plugin
virtual std::vector< const GeomDet * > components() const
Returns direct components, if any.
Definition: GeomDet.h:73
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ListIds.cc:94
static bool dddGetStringRaw(const DDFilteredView &view, const std::string &name, std::string &value)
Definition: ListIds.cc:27
bool printMaterial_
Definition: ListIds.cc:80
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
bool next()
set current node to the next node in the filtered tree
static std::ostream & operator<<(std::ostream &out, const math::XYZVector &v)
Definition: ListIds.cc:63
void endJob() override
Definition: ListIds.cc:163
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static std::string dddGetString(const std::string &s, const DDFilteredView &view)
Definition: ListIds.cc:55
Definition: value.py:1
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
GeometricDet::GeometricEnumType type(std::string const &) const
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
std::vector< DDExpandedNode > DDGeoHistory
Geometrical &#39;path&#39; of the current node up to the root-node.
const N & name() const
Definition: DDBase.h:59
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
const std::string fullname() const
Definition: DDName.h:43
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:38
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:43
std::vector< std::string > materials_
Definition: ListIds.cc:81
static int position[264][3]
Definition: ReadPGInfo.cc:289
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geoToken_
Definition: ListIds.cc:83
bool firstChild()
set the current node to the first child ...
ListIds(const edm::ParameterSet &)
Definition: ListIds.cc:86
edm::ESGetToken< DDCompactView, IdealGeometryRecord > dddToken_
Definition: ListIds.cc:82
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
const DDTranslation & translation() const
The absolute translation of the current node.
void beginJob() override
Definition: ListIds.cc:74
~ListIds() override
Definition: ListIds.cc:92