CMS 3D CMS Logo

CSCGeometryESModule.cc
Go to the documentation of this file.
1 /*
2 // \class CSCGeometryESModule
3 //
4 // Description: CSC ESModule for DD4hep
5 //
6 //
7 // \author Sergio Lo Meo (sergio.lo.meo@cern.ch) following what Ianna Osborne made for DTs (DD4hep migration)
8 // Created: Thu, 05 March 2020
9 // Modified: Thu, 04 June 2020, following what made in PR #30047
10 //
11 // Original author: Tim Cox
12 */
13 
38 
39 // Alignments
45 
46 #include <memory>
47 #include <string>
48 
50 public:
53 
56 
58  std::shared_ptr<CSCGeometry> produce(const MuonGeometryRecord& record);
59 
60 private:
62 
63  void initCSCGeometry_(const MuonGeometryRecord&, std::shared_ptr<HostType>& host);
64 
66  // DDD
69  //dd4hep
71 
74 
78 
79  // Flags for controlling geometry modelling during build of CSCGeometry
84  bool debugV_;
85  bool applyAlignment_; // Switch to apply alignment corrections
86  bool fromDDD_; // whether to build from DDD or DB
90 };
91 
92 using namespace edm;
93 
95  : fromDDD_(p.getParameter<bool>("fromDDD")),
96  fromDD4hep_(p.getParameter<bool>("fromDD4hep")),
97  alignmentsLabel_(p.getParameter<std::string>("alignmentsLabel")),
98  myLabel_(p.getParameter<std::string>("appendToDataLabel")) {
99  auto cc = setWhatProduced(this);
100 
101  // Choose wire geometry modelling
102  // We now _require_ some wire geometry specification in the CSCOrcaSpec.xml file
103  // in the DDD Geometry.
104  // Default as of transition to CMSSW is to use real values.
105  // Alternative is to use pseudo-values which match reasonably closely
106  // the calculated geometry values used up to and including ORCA_8_8_1.
107  // (This was the default in ORCA.)
108 
109  useRealWireGeometry_ = p.getParameter<bool>("useRealWireGeometry");
110 
111  // Suppress strips altogether in ME1a region of ME11?
112 
113  useOnlyWiresInME1a_ = p.getParameter<bool>("useOnlyWiresInME1a");
114 
115  // Allow strips in ME1a region of ME11 but gang them?
116  // Default is now to treat ME1a with ganged strips (e.g. in clusterizer)
117 
118  useGangedStripsInME1a_ = p.getParameter<bool>("useGangedStripsInME1a");
119 
121  useOnlyWiresInME1a_ = false; // override possible inconsistentcy
122 
123  // Use the backed-out offsets that correct the CTI
124  useCentreTIOffsets_ = p.getParameter<bool>("useCentreTIOffsets");
125 
126  // Debug printout etc. in CSCGeometry etc.
127 
128  debugV_ = p.getUntrackedParameter<bool>("debugV", false);
129 
130  if (fromDDD_) {
131  cpvToken_ = cc.consumes();
132  mdcToken_ = cc.consumes();
133  } else if (fromDD4hep_) {
134  cpvTokendd4hep_ = cc.consumes();
135  mdcToken_ = cc.consumes();
136  } else {
139  }
140 
141  // Feed these value to where I need them
142  applyAlignment_ = p.getParameter<bool>("applyAlignment");
143  if (applyAlignment_) {
148  }
149 
150  edm::LogVerbatim("Geometry") << "@SUB=CSCGeometryESModule Label '" << myLabel_ << "' "
151  << (applyAlignment_ ? "looking for" : "IGNORING") << " alignment labels '"
152  << alignmentsLabel_ << "'.";
153 }
154 
156  //
157  // This cfi should be included to build the CSC geometry model.
158  //
159  // modelling flags (for completeness - internal defaults are already sane)
160  // GF would like to have a shorter name (e.g. CSCGeometry), but since originally
161  // there was no name, replace statements in other configs would not work anymore...
163  desc.add<bool>("fromDDD", true);
164  desc.add<bool>("fromDD4hep", false);
165  desc.add<std::string>("alignmentsLabel", "");
166  desc.add<std::string>("appendToDataLabel", "");
167  desc.add<bool>("useRealWireGeometry", true);
168  desc.add<bool>("useOnlyWiresInME1a", false);
169  desc.add<bool>("useGangedStripsInME1a", true);
170  desc.add<bool>("useCentreTIOffsets", false);
171  desc.add<bool>("applyAlignment", true); //GF: to be abandoned
172  desc.addUntracked<bool>("debugV", false);
173  descriptions.add("CSCGeometryESModule", desc);
174 }
175 
176 std::shared_ptr<CSCGeometry> CSCGeometryESModule::produce(const MuonGeometryRecord& record) {
177  auto host = holder_.makeOrGet([this]() {
178  return new HostType(
179  debugV_, useGangedStripsInME1a_, useOnlyWiresInME1a_, useRealWireGeometry_, useCentreTIOffsets_);
180  });
181 
182  initCSCGeometry_(record, host);
183 
184  // Called whenever the alignments or alignment errors change
185 
186  if (applyAlignment_) {
187  // applyAlignment_ is scheduled for removal.
188  // Ideal geometry obtained by using 'fake alignment' (with applyAlignment_ = true)
189  const auto& globalPosition = record.get(globalPositionToken_);
190  const auto& alignments = record.get(alignmentsToken_);
191  const auto& alignmentErrors = record.get(alignmentErrorsToken_);
192  // Only apply alignment if values exist
193  if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
194  edm::LogVerbatim("Config") << "@SUB=CSCGeometryRecord::produce Alignment(Error)s and global position (label '"
195  << alignmentsLabel_ << "') empty: Geometry producer (label "
196  << "'" << myLabel_ << "') assumes fake and does not apply.";
197  } else {
198  GeometryAligner aligner;
199  aligner.applyAlignments<CSCGeometry>(
200  &(*host), &alignments, &alignmentErrors, align::DetectorGlobalPosition(globalPosition, DetId(DetId::Muon)));
201  }
202  }
203  return host; // automatically converts to std::shared_ptr<CSCGeometry>
204 }
205 
206 void CSCGeometryESModule::initCSCGeometry_(const MuonGeometryRecord& record, std::shared_ptr<HostType>& host) {
207  if (fromDDD_) {
208  edm::LogVerbatim("CSCGeoemtryESModule") << "(0) CSCGeometryESModule - DDD ";
209  host->ifRecordChanges<IdealGeometryRecord>(record, [&host, &record, this](auto const& rec) {
210  host->clear();
211  edm::ESTransientHandle<DDCompactView> cpv = record.getTransientHandle(cpvToken_);
212  const auto& mdc = rec.get(mdcToken_);
214  builder.build(*host, cpv.product(), mdc);
215  });
216  } else if (fromDD4hep_) {
217  edm::LogVerbatim("CSCGeoemtryESModule") << "(0) CSCGeometryESModule - DD4hep ";
218  host->ifRecordChanges<IdealGeometryRecord>(record, [&host, &record, this](auto const& rec) {
219  host->clear();
220  edm::ESTransientHandle<cms::DDCompactView> cpv = record.getTransientHandle(cpvTokendd4hep_);
221  const auto& mdc = rec.get(mdcToken_);
223  builder.build(*host, cpv.product(), mdc);
224  });
225  } else {
226  bool recreateGeometry = false;
227 
228  host->ifRecordChanges<CSCRecoGeometryRcd>(record,
229  [&recreateGeometry](auto const& rec) { recreateGeometry = true; });
230 
231  host->ifRecordChanges<CSCRecoDigiParametersRcd>(record,
232  [&recreateGeometry](auto const& rec) { recreateGeometry = true; });
233  edm::LogVerbatim("CSCGeoemtryESModule") << "(0) CSCGeometryESModule - DB recreateGeometry=false ";
234  if (recreateGeometry) {
235  edm::LogVerbatim("CSCGeoemtryESModule") << "(0) CSCGeometryESModule - DB recreateGeometry=true ";
236  host->clear();
237  const auto& rig = record.get(rigToken_);
238  const auto& rdp = record.get(rdpToken_);
239  CSCGeometryBuilder cscgb;
240  cscgb.build(*host, rig, rdp);
241  }
242  }
243 }
244 
Log< level::Info, true > LogVerbatim
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
edm::ESGetToken< Alignments, CSCAlignmentRcd > alignmentsToken_
void build(CSCGeometry &geom, const DDCompactView *fv, const MuonGeometryConstants &muonConstants)
string host
Definition: query.py:115
CSCGeometryESModule(const edm::ParameterSet &p)
Constructor.
const std::string alignmentsLabel_
Class to update a given geometry with a set of alignments.
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > cpvTokendd4hep_
static void fillDescriptions(edm::ConfigurationDescriptions &)
Creation of configuration file.
const std::string myLabel_
void build(CSCGeometry &theGeometry, const RecoIdealGeometry &rig, const CSCRecoDigiParameters &cscpars)
Build the geometry.
edm::ESGetToken< CSCRecoDigiParameters, CSCRecoDigiParametersRcd > rdpToken_
void initCSCGeometry_(const MuonGeometryRecord &, std::shared_ptr< HostType > &host)
edm::ESGetToken< Alignments, GlobalPositionRcd > globalPositionToken_
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
std::shared_ptr< CSCGeometry > produce(const MuonGeometryRecord &record)
Produce CSCGeometry.
edm::ESGetToken< AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd > alignmentErrorsToken_
edm::ESGetToken< DDCompactView, IdealGeometryRecord > cpvToken_
Definition: DetId.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T const * product() const
HLT enums.
edm::ESGetToken< MuonGeometryConstants, IdealGeometryRecord > mdcToken_
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
edm::ReusableObjectHolder< HostType > holder_
edm::ESGetToken< RecoIdealGeometry, CSCRecoGeometryRcd > rigToken_