CMS 3D CMS Logo

DTGeometryESModule.cc
Go to the documentation of this file.
1 
41 
42 #include <memory>
43 #include <iostream>
44 #include <iterator>
45 #include <string>
46 
47 using namespace edm;
48 using namespace std;
49 
51 public:
54 
57 
59  std::shared_ptr<DTGeometry> produce(const MuonGeometryRecord& record);
60 
61 private:
63 
64  void setupDDDGeometry(MuonNumberingRecord const&, std::shared_ptr<HostType>&);
65  void setupDD4hepGeometry(MuonNumberingRecord const&, std::shared_ptr<HostType>&);
66  void setupDBGeometry(DTRecoGeometryRcd const&, std::shared_ptr<HostType>&);
67 
69 
78 
84  bool fromDDD_;
86  bool applyAlignment_; // Switch to apply alignment corrections
87 };
88 
90  : m_tag(p.getParameter<edm::ESInputTag>("DDDetector")),
91  alignmentsLabel_(p.getParameter<std::string>("alignmentsLabel")),
92  myLabel_(p.getParameter<std::string>("appendToDataLabel")),
93  m_attribute(p.getParameter<std::string>("attribute")),
94  m_value(p.getParameter<std::string>("value")),
95  fromDDD_(p.getParameter<bool>("fromDDD")),
96  fromDD4hep_(p.getParameter<bool>("fromDD4hep")) {
97  applyAlignment_ = p.getParameter<bool>("applyAlignment");
98 
99  auto cc = setWhatProduced(this);
100  if (applyAlignment_) {
105  }
106  if (fromDDD_) {
109  } else if (fromDD4hep_) {
113  } else {
115  }
116 
117  edm::LogVerbatim("Geometry") << "@SUB=DTGeometryESModule Label '" << myLabel_ << "' "
118  << (applyAlignment_ ? "looking for" : "IGNORING") << " alignment labels '"
119  << alignmentsLabel_ << "'.";
120 }
121 
123  //
124  // This cfi should be included to build the DT geometry model.
125  //
127  desc.add<bool>("fromDDD", true);
128  desc.add<bool>("fromDD4hep", false);
129  desc.add<edm::ESInputTag>("DDDetector", edm::ESInputTag("", ""));
130  desc.add<std::string>("alignmentsLabel", "");
131  desc.add<std::string>("appendToDataLabel", "");
132  desc.add<std::string>("attribute", "MuStructure");
133  desc.add<std::string>("value", "MuonBarrelDT");
134  desc.add<bool>("applyAlignment", true);
135  descriptions.add("DTGeometryESModule", desc);
136 }
137 
138 std::shared_ptr<DTGeometry> DTGeometryESModule::produce(const MuonGeometryRecord& record) {
139  auto host = holder_.makeOrGet([]() { return new HostType; });
140 
141  if (fromDDD_) {
142  host->ifRecordChanges<MuonNumberingRecord>(record, [this, &host](auto const& rec) { setupDDDGeometry(rec, host); });
143  } else if (fromDD4hep_) {
144  host->ifRecordChanges<MuonNumberingRecord>(record,
145  [this, &host](auto const& rec) { setupDD4hepGeometry(rec, host); });
146  } else {
147  host->ifRecordChanges<DTRecoGeometryRcd>(record, [this, &host](auto const& rec) { setupDBGeometry(rec, host); });
148  }
149  //
150  // Called whenever the alignments or alignment errors change
151  //
152  if (applyAlignment_) {
153  // applyAlignment_ is scheduled for removal.
154  // Ideal geometry obtained by using 'fake alignment' (with applyAlignment_ = true)
155  const auto& globalPosition = record.get(globalPositionToken_);
156  const auto& alignments = record.get(alignmentsToken_);
157  const auto& alignmentErrors = record.get(alignmentErrorsToken_);
158  // Only apply alignment if values exist
159  if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
160  edm::LogVerbatim("Geometry") << "@SUB=DTGeometryRecord::produce Alignment(Error)s and global position (label '"
161  << alignmentsLabel_ << "') empty: Geometry producer (label '" << myLabel_
162  << "') assumes fake and does not apply.";
163  } else {
164  GeometryAligner aligner;
165  aligner.applyAlignments<DTGeometry>(
166  &(*host), &alignments, &alignmentErrors, align::DetectorGlobalPosition(globalPosition, DetId(DetId::Muon)));
167  }
168  }
169 
170  return host; // automatically converts to std::shared_ptr<DTGeometry>
171 }
172 
173 void DTGeometryESModule::setupDDDGeometry(const MuonNumberingRecord& record, std::shared_ptr<HostType>& host) {
174  //
175  // Called whenever the muon numbering (or ideal geometry) changes
176  //
177 
178  host->clear();
179 
180  const auto& mdc = record.get(mdcToken_);
181  edm::ESTransientHandle<DDCompactView> cpv = record.getTransientHandle(cpvToken_);
182 
183  DTGeometryBuilderFromDDD builder;
184  builder.build(*host, cpv.product(), mdc);
185 }
186 
187 void DTGeometryESModule::setupDD4hepGeometry(const MuonNumberingRecord& record, std::shared_ptr<HostType>& host) {
188  host->clear();
189 
190  const auto& mdc = record.get(mdcToken_);
191  edm::ESTransientHandle<cms::DDDetector> cpv = record.getTransientHandle(m_cpvToken);
192  ESTransientHandle<cms::DDSpecParRegistry> registry = record.getTransientHandle(m_registryToken);
193 
194  cms::DDSpecParRefs myReg;
195  registry->filter(myReg, m_attribute, m_value);
196 
198  builder.build(*host, cpv.product(), mdc, myReg);
199 }
200 
201 void DTGeometryESModule::setupDBGeometry(const DTRecoGeometryRcd& record, std::shared_ptr<HostType>& host) {
202  //
203  // Called whenever the muon numbering (or ideal geometry) changes
204  //
205 
206  host->clear();
207 
208  const auto& rig = record.get(rigToken_);
209 
211  builder.build(host, rig);
212 }
213 
Log< level::Info, true > LogVerbatim
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
void setupDD4hepGeometry(MuonNumberingRecord const &, std::shared_ptr< HostType > &)
void setupDDDGeometry(MuonNumberingRecord const &, std::shared_ptr< HostType > &)
std::shared_ptr< DTGeometry > produce(const MuonGeometryRecord &record)
Produce DTGeometry.
edm::ESGetToken< DDCompactView, IdealGeometryRecord > cpvToken_
string host
Definition: query.py:115
Class to update a given geometry with a set of alignments.
dd4hep::SpecParRefs DDSpecParRefs
Definition: DDCompactView.h:29
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
edm::ReusableObjectHolder< HostType > holder_
void build(DTGeometry &theGeometry, const DDCompactView *cview, const MuonGeometryConstants &muonConstants)
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
edm::ESGetToken< cms::DDSpecParRegistry, DDSpecParRegistryRcd > m_registryToken
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
dd4hep::SpecParRegistry DDSpecParRegistry
Definition: DDCompactView.h:28
const std::string m_attribute
const std::string myLabel_
edm::ESGetToken< cms::DDDetector, IdealGeometryRecord > m_cpvToken
const edm::ESInputTag m_tag
const std::string alignmentsLabel_
static void fillDescriptions(edm::ConfigurationDescriptions &)
Creation of configuration file.
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
void setupDBGeometry(DTRecoGeometryRcd const &, std::shared_ptr< HostType > &)
edm::ESGetToken< MuonGeometryConstants, IdealGeometryRecord > mdcToken_
edm::ESGetToken< Alignments, GlobalPositionRcd > globalPositionToken_
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string m_value
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T const * product() const
HLT enums.
edm::ESGetToken< Alignments, DTAlignmentRcd > alignmentsToken_
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
void build(DTGeometry &, const cms::DDDetector *, const MuonGeometryConstants &, const dd4hep::SpecParRefs &)
DTGeometryESModule(const edm::ParameterSet &p)
Constructor.
void build(const std::shared_ptr< DTGeometry > &theGeometry, const RecoIdealGeometry &rig)
edm::ESGetToken< AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd > alignmentErrorsToken_
edm::ESGetToken< RecoIdealGeometry, DTRecoGeometryRcd > rigToken_