CMS 3D CMS Logo

CTPPSGeometryESModule.cc
Go to the documentation of this file.
1 /****************************************************************************
2 * Based on CTPPSGeometryESModule.cc by:
3 * Jan Kaspar (jan.kaspar@gmail.com)
4 * Dominik Mierzejewski <dmierzej@cern.ch>
5 *
6 * Rewritten + Moved out common functionailities to DetGeomDesc(Builder) by Gabrielle Hugo.
7 * Migrated to DD4hep by Wagner Carvalho and Gabrielle Hugo.
8 *
9 * Add the capability of reading PPS reco geometry from the database
10 *
11 ****************************************************************************/
12 
18 
22 
30 
35 
37 
38 #include <regex>
39 
49 using RotationMatrix = ROOT::Math::Rotation3D;
50 using Translation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
51 
53 public:
55  ~CTPPSGeometryESModule() override {}
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59 private:
60  std::unique_ptr<DetGeomDesc> produceIdealGD(const IdealGeometryRecord&);
61  std::unique_ptr<DetGeomDesc> produceIdealGDFromPreprocessedDB(const VeryForwardIdealGeometryRecord&);
62  std::vector<int> fillCopyNos(TGeoIterator& it);
63 
64  std::unique_ptr<DetGeomDesc> produceRealGD(const VeryForwardRealGeometryRecord&);
65  std::unique_ptr<DetGeomDesc> produceRealGDFromPreprocessedDB(const VeryForwardRealGeometryRecord&);
66  std::unique_ptr<CTPPSGeometry> produceRealTG(const VeryForwardRealGeometryRecord&);
67 
68  std::unique_ptr<DetGeomDesc> produceMisalignedGD(const VeryForwardMisalignedGeometryRecord&);
70  std::unique_ptr<CTPPSGeometry> produceMisalignedTG(const VeryForwardMisalignedGeometryRecord&);
71 
72  template <typename REC, typename GEO>
73  std::unique_ptr<DetGeomDesc> produceGD(const GEO&,
74  const std::optional<REC>&,
77  const char* name);
78 
79  const unsigned int verbosity_;
81  const bool isRun2_;
82 
87 
94 
97 };
98 
100  : verbosity_(iConfig.getUntrackedParameter<unsigned int>("verbosity")),
101  buildMisalignedGeometry_(iConfig.getParameter<bool>("buildMisalignedGeometry")),
102  isRun2_(iConfig.getParameter<bool>("isRun2")),
103  fromPreprocessedDB_(iConfig.getUntrackedParameter<bool>("fromPreprocessedDB", false)),
104  fromDD4hep_(iConfig.getUntrackedParameter<bool>("fromDD4hep", false)) {
105  if (fromPreprocessedDB_) {
107  dbToken_ = c.consumes<PDetGeomDesc>(edm::ESInputTag("", iConfig.getParameter<std::string>("dbTag")));
108 
112 
118  }
119  } else if (!fromDD4hep_) {
121  ddToken_ = c.consumes<DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));
122 
126 
132  }
133  } else {
135  dd4hepToken_ =
136  c.consumes<cms::DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));
137 
141 
147  }
148  }
149 
151  dgdRealToken_ = c_RTG.consumes<DetGeomDesc>(edm::ESInputTag());
152 
155  dgdMisToken_ = c_MTG.consumes<DetGeomDesc>(edm::ESInputTag());
156  }
157 }
158 
161  desc.addUntracked<unsigned int>("verbosity", 1);
162  desc.add<bool>("buildMisalignedGeometry", false)->setComment("switch if misaligned geometry shall be built");
163  desc.add<bool>("isRun2", false)->setComment("Switch to legacy (2017-18) definition of diamond geometry");
164  desc.add<std::string>("dbTag", std::string());
165  desc.add<std::string>("compactViewTag", std::string());
166  desc.addUntracked<bool>("fromPreprocessedDB", false);
167  desc.addUntracked<bool>("fromDD4hep", false);
168  descriptions.add("CTPPSGeometryESModule", desc);
169 }
170 
171 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGD(const IdealGeometryRecord& iRecord) {
172  if (!fromDD4hep_) {
173  // Get the DDCompactView from EventSetup
174  auto const& myCompactView = iRecord.get(ddToken_);
175 
176  // Build geo from compact view.
178  }
179 
180  else {
181  // Get the DDCompactView from EventSetup
182  auto const& myCompactView = iRecord.get(dd4hepToken_);
183 
184  // Build geo from compact view.
186  }
187 }
188 
190  const VeryForwardIdealGeometryRecord& iRecord) {
191  // Get the PDetGeomDesc from EventSetup
192  auto const& myDB = iRecord.get(dbToken_);
193 
194  edm::LogInfo("CTPPSGeometryESModule") << " myDB size = " << myDB.container_.size();
195 
196  // Build geo from PDetGeomDesc DB object.
197  auto pdet = std::make_unique<DetGeomDesc>(myDB);
198  return pdet;
199 }
200 
201 template <typename REC, typename GEO>
202 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(
203  GEO const& iIdealRec,
204  std::optional<REC> const& iAlignRec,
205  edm::ESGetToken<DetGeomDesc, GEO> const& iGDToken,
207  const char* name) {
208  // get the input GeometricalDet
209  auto const& idealGD = iIdealRec.get(iGDToken);
210 
211  // load alignments
212  CTPPSRPAlignmentCorrectionsData const* alignments = nullptr;
213  if (iAlignRec) {
214  auto alignmentsHandle = iAlignRec->getHandle(iAlignToken);
215  if (alignmentsHandle.isValid()) {
216  alignments = alignmentsHandle.product();
217  }
218  }
219 
220  if (verbosity_) {
221  if (alignments) {
222  edm::LogVerbatim(name) << ">> " << name << " > Real geometry: " << alignments->getRPMap().size() << " RP and "
223  << alignments->getSensorMap().size() << " sensor alignments applied.";
224  } else {
225  edm::LogVerbatim(name) << ">> " << name << " > Real geometry: No alignment applied.";
226  }
227  }
228 
229  return CTPPSGeometryESCommon::applyAlignments(idealGD, alignments);
230 }
231 
233  const VeryForwardRealGeometryRecord& iRecord) {
238  "CTPPSGeometryESModule::produceRealGDFromPreprocessedDB");
239 }
240 
241 //----------------------------------------------------------------------------------------------------
242 
244  const VeryForwardMisalignedGeometryRecord& iRecord) {
249  "CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB");
250 }
251 
252 //----------------------------------------------------------------------------------------------------
253 
254 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGD(const VeryForwardRealGeometryRecord& iRecord) {
255  return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
259  "CTPPSGeometryESModule::produceRealGD");
260 }
261 
262 //----------------------------------------------------------------------------------------------------
263 
264 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGD(
265  const VeryForwardMisalignedGeometryRecord& iRecord) {
266  return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
270  "CTPPSGeometryESModule::produceMisalignedGD");
271 }
272 
273 //----------------------------------------------------------------------------------------------------
274 
275 std::unique_ptr<CTPPSGeometry> CTPPSGeometryESModule::produceRealTG(const VeryForwardRealGeometryRecord& iRecord) {
276  auto const& gD = iRecord.get(dgdRealToken_);
277 
278  return std::make_unique<CTPPSGeometry>(&gD, verbosity_);
279 }
280 
281 //----------------------------------------------------------------------------------------------------
282 
283 std::unique_ptr<CTPPSGeometry> CTPPSGeometryESModule::produceMisalignedTG(
284  const VeryForwardMisalignedGeometryRecord& iRecord) {
285  auto const& gD = iRecord.get(dgdMisToken_);
286 
287  return std::make_unique<CTPPSGeometry>(&gD, verbosity_);
288 }
289 
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepToken_
Log< level::Info, true > LogVerbatim
Event setup record containing the ideal PPS geometry information.
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:165
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const mapType & getSensorMap() const
returns the map of sensor alignment corrections
edm::ESGetToken< DetGeomDesc, VeryForwardIdealGeometryRecord > idealDBGDToken2_
edm::ESGetToken< DetGeomDesc, IdealGeometryRecord > idealGDToken2_
edm::ESGetToken< DetGeomDesc, IdealGeometryRecord > idealGDToken_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > Translation
std::unique_ptr< DetGeomDesc > applyAlignments(const DetGeomDesc &, const CTPPSRPAlignmentCorrectionsData *)
edm::ESGetToken< DDCompactView, IdealGeometryRecord > ddToken_
std::unique_ptr< CTPPSGeometry > produceRealTG(const VeryForwardRealGeometryRecord &)
std::vector< int > fillCopyNos(TGeoIterator &it)
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Event setup record containing the real (actual) geometry information.
const mapType & getRPMap() const
returns the map of RP alignment corrections
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
std::unique_ptr< CTPPSGeometry > produceMisalignedTG(const VeryForwardMisalignedGeometryRecord &)
edm::ESGetToken< CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord > misAlignmentToken_
std::unique_ptr< DetGeomDesc > produceGD(const GEO &, const std::optional< REC > &, edm::ESGetToken< DetGeomDesc, GEO > const &, edm::ESGetToken< CTPPSRPAlignmentCorrectionsData, REC > const &, const char *name)
std::unique_ptr< DetGeomDesc > produceRealGD(const VeryForwardRealGeometryRecord &)
std::unique_ptr< DetGeomDesc > buildDetGeomDescFromCompactView(const DDCompactView &myCompactView, const bool isRun2)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
edm::ESGetToken< DetGeomDesc, VeryForwardRealGeometryRecord > dgdRealToken_
Log< level::Info, false > LogInfo
edm::ESGetToken< DetGeomDesc, VeryForwardMisalignedGeometryRecord > dgdMisToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ROOT::Math::Rotation3D RotationMatrix
edm::ESGetToken< CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord > realAlignmentToken_
edm::ESGetToken< DetGeomDesc, VeryForwardIdealGeometryRecord > idealDBGDToken_
edm::ESGetToken< PDetGeomDesc, VeryForwardIdealGeometryRecord > dbToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< DetGeomDesc > produceMisalignedGD(const VeryForwardMisalignedGeometryRecord &)
Container for CTPPS RP alignment corrections. The corrections are stored on two levels - RP and senso...
CTPPSGeometryESModule(const edm::ParameterSet &)
std::unique_ptr< DetGeomDesc > produceMisalignedGDFromPreprocessedDB(const VeryForwardMisalignedGeometryRecord &)
Event setup record containing the misaligned geometry information. It is used for alignment studies o...
std::unique_ptr< DetGeomDesc > produceIdealGD(const IdealGeometryRecord &)
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
const unsigned int verbosity_
std::unique_ptr< DetGeomDesc > produceIdealGDFromPreprocessedDB(const VeryForwardIdealGeometryRecord &)
std::unique_ptr< DetGeomDesc > produceRealGDFromPreprocessedDB(const VeryForwardRealGeometryRecord &)