CMS 3D CMS Logo

GEMGeometryESModule.cc
Go to the documentation of this file.
1 /*
2 //\class GEMGeometryESModule
3 
4  Description: GEM Geometry ES Module from DD & DD4hep
5  DD4hep part added to the original old file (DD version) made by M. Maggi (INFN Bari)
6 //
7 // Author: Sergio Lo Meo (sergio.lo.meo@cern.ch) following what Ianna Osburne made for DTs (DD4hep migration)
8 // Created: 27 Jan 2020
9 */
13 
20 
22 
29 
30 // Alignments
37 
38 #include <memory>
39 
41 public:
44 
47 
49  std::unique_ptr<GEMGeometry> produce(const MuonGeometryRecord& record);
50 
51 private:
52  // use the DDD as Geometry source
53  const bool fromDDD_;
54  const bool fromDD4hep_;
64 };
65 
67  : fromDDD_{p.getParameter<bool>("fromDDD")},
68  fromDD4hep_{p.getParameter<bool>("fromDD4hep")},
69  applyAlignment_(p.getParameter<bool>("applyAlignment")),
70  alignmentsLabel_(p.getParameter<std::string>("alignmentsLabel")) {
71  auto cc = setWhatProduced(this);
72  if (fromDDD_) {
73  cpvToken_ = cc.consumes();
74  mdcToken_ = cc.consumes();
75  } else if (fromDD4hep_) {
76  dd4hepcpvToken_ = cc.consumes();
77  mdcToken_ = cc.consumes();
78  } else {
79  riggemToken_ = cc.consumes();
80  }
81  if (applyAlignment_) {
82  globalPositionToken_ = cc.consumes(edm::ESInputTag{"", alignmentsLabel_});
83  alignmentsToken_ = cc.consumes(edm::ESInputTag{"", alignmentsLabel_});
84  alignmentErrorsToken_ = cc.consumes(edm::ESInputTag{"", alignmentsLabel_});
85  }
86  edm::LogVerbatim("GEMGeometry") << "GEMGeometryESModule::initailized with flags " << fromDDD_ << ":" << fromDD4hep_;
87 }
88 
91  desc.add<bool>("fromDDD", true);
92  desc.add<bool>("fromDD4hep", false);
93  desc.add<bool>("applyAlignment", false);
94  desc.add<std::string>("alignmentsLabel", "");
95  descriptions.add("gemGeometry", desc);
96 }
97 
98 std::unique_ptr<GEMGeometry> GEMGeometryESModule::produce(const MuonGeometryRecord& record) {
99  auto gemGeometry = std::make_unique<GEMGeometry>();
100 
101  if (fromDDD_) {
102  edm::LogVerbatim("GEMGeometry") << "GEMGeometryESModule::produce :: GEMGeometryBuilder builder ddd";
103  auto cpv = record.getTransientHandle(cpvToken_);
104  const auto& mdc = record.get(mdcToken_);
105  GEMGeometryBuilder builder;
106  builder.build(*gemGeometry, cpv.product(), mdc);
107  } else if (fromDD4hep_) {
108  edm::LogVerbatim("GEMGeometry") << "GEMGeometryESModule::produce :: GEMGeometryBuilder builder dd4hep";
110  const auto& mdc = record.get(mdcToken_);
111  GEMGeometryBuilder builder;
112  builder.build(*gemGeometry, cpv.product(), mdc);
113  } else {
114  edm::LogVerbatim("GEMGeometry") << "GEMGeometryESModule::produce :: GEMGeometryBuilder builder db";
115  const auto& riggem = record.get(riggemToken_);
117  builder.build(*gemGeometry, riggem);
118  }
119 
120  if (applyAlignment_) {
121  const auto& globalPosition = record.get(globalPositionToken_);
122  const auto& alignments = record.get(alignmentsToken_);
123  const auto& alignmentErrors = record.get(alignmentErrorsToken_);
124 
125  // No alignment records, assume ideal geometry is wanted
126  if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
127  edm::LogInfo("Config") << "@SUB=GEMGeometryRecord::produce"
128  << "Alignment(Error)s and global position (label '" << alignmentsLabel_
129  << "') empty: it is assumed fake and will not apply.";
130  } else {
131  GeometryAligner aligner;
132  aligner.applyAlignments<GEMGeometry>(gemGeometry.get(),
133  &alignments,
134  &alignmentErrors,
136  }
137  }
138 
139  return gemGeometry;
140 }
141 
Log< level::Info, true > LogVerbatim
edm::ESGetToken< AlignmentErrorsExtended, GEMAlignmentErrorExtendedRcd > alignmentErrorsToken_
Class to update a given geometry with a set of alignments.
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepcpvToken_
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
std::unique_ptr< GEMGeometry > produce(const MuonGeometryRecord &record)
Produce GEMGeometry.
void build(GEMGeometry &theGeometry, const DDCompactView *cview, const MuonGeometryConstants &muonConstants)
edm::ESGetToken< Alignments, GlobalPositionRcd > globalPositionToken_
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
edm::ESGetToken< MuonGeometryConstants, IdealGeometryRecord > mdcToken_
Log< level::Info, false > LogInfo
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &)
Define the cfi file.
edm::ESGetToken< DDCompactView, IdealGeometryRecord > cpvToken_
GEMGeometryESModule(const edm::ParameterSet &p)
Constructor.
edm::ESGetToken< RecoIdealGeometry, GEMRecoGeometryRcd > riggemToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T const * product() const
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
edm::ESGetToken< Alignments, GEMAlignmentRcd > alignmentsToken_
const std::string alignmentsLabel_
void build(GEMGeometry &theGeometry, const RecoIdealGeometry &rgeo)