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 
92 
95 };
96 
98  : verbosity_(iConfig.getUntrackedParameter<unsigned int>("verbosity")),
99  buildMisalignedGeometry_(iConfig.getParameter<bool>("buildMisalignedGeometry")),
100  isRun2_(iConfig.getParameter<bool>("isRun2")),
101  fromPreprocessedDB_(iConfig.getUntrackedParameter<bool>("fromPreprocessedDB", false)),
102  fromDD4hep_(iConfig.getUntrackedParameter<bool>("fromDD4hep", false)) {
103  if (fromPreprocessedDB_) {
105  dbToken_ = c.consumes<PDetGeomDesc>(edm::ESInputTag("", iConfig.getParameter<std::string>("dbTag")));
106 
110 
115  }
116  } else if (!fromDD4hep_) {
118  ddToken_ = c.consumes<DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));
119 
123 
128  }
129  } else {
131  dd4hepToken_ =
132  c.consumes<cms::DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));
133 
137 
142  }
143  }
144 
146  dgdRealToken_ = c_RTG.consumes<DetGeomDesc>(edm::ESInputTag());
147 
150  dgdMisToken_ = c_MTG.consumes<DetGeomDesc>(edm::ESInputTag());
151  }
152 }
153 
156  desc.addUntracked<unsigned int>("verbosity", 1);
157  desc.add<bool>("buildMisalignedGeometry", false)->setComment("switch if misaligned geometry shall be built");
158  desc.add<bool>("isRun2", false)->setComment("Switch to legacy (2017-18) definition of diamond geometry");
159  desc.add<std::string>("dbTag", std::string());
160  desc.add<std::string>("compactViewTag", std::string());
161  desc.addUntracked<bool>("fromPreprocessedDB", false);
162  desc.addUntracked<bool>("fromDD4hep", false);
163  descriptions.add("CTPPSGeometryESModule", desc);
164 }
165 
166 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGD(const IdealGeometryRecord& iRecord) {
167  if (!fromDD4hep_) {
168  // Get the DDCompactView from EventSetup
169  auto const& myCompactView = iRecord.get(ddToken_);
170 
171  // Build geo from compact view.
173  }
174 
175  else {
176  // Get the DDCompactView from EventSetup
177  auto const& myCompactView = iRecord.get(dd4hepToken_);
178 
179  // Build geo from compact view.
181  }
182 }
183 
185  const VeryForwardIdealGeometryRecord& iRecord) {
186  // Get the PDetGeomDesc from EventSetup
187  auto const& myDB = iRecord.get(dbToken_);
188 
189  edm::LogInfo("CTPPSGeometryESModule") << " myDB size = " << myDB.container_.size();
190 
191  // Build geo from PDetGeomDesc DB object.
192  auto pdet = std::make_unique<DetGeomDesc>(myDB);
193  return pdet;
194 }
195 
196 template <typename REC, typename GEO>
197 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(
198  GEO const& iIdealRec,
199  std::optional<REC> const& iAlignRec,
200  edm::ESGetToken<DetGeomDesc, GEO> const& iGDToken,
202  const char* name) {
203  // get the input GeometricalDet
204  auto const& idealGD = iIdealRec.get(iGDToken);
205 
206  // load alignments
207  CTPPSRPAlignmentCorrectionsData const* alignments = nullptr;
208  if (iAlignRec) {
209  auto alignmentsHandle = iAlignRec->getHandle(iAlignToken);
210  if (alignmentsHandle.isValid()) {
211  alignments = alignmentsHandle.product();
212  }
213  }
214 
215  if (verbosity_) {
216  if (alignments) {
217  edm::LogVerbatim(name) << ">> " << name << " > Real geometry: " << alignments->getRPMap().size() << " RP and "
218  << alignments->getSensorMap().size() << " sensor alignments applied.";
219  } else {
220  edm::LogVerbatim(name) << ">> " << name << " > Real geometry: No alignment applied.";
221  }
222  }
223 
224  return CTPPSGeometryESCommon::applyAlignments(idealGD, alignments);
225 }
226 
228  const VeryForwardRealGeometryRecord& iRecord) {
233  "CTPPSGeometryESModule::produceRealGDFromPreprocessedDB");
234 }
235 
236 //----------------------------------------------------------------------------------------------------
237 
239  const VeryForwardMisalignedGeometryRecord& iRecord) {
244  "CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB");
245 }
246 
247 //----------------------------------------------------------------------------------------------------
248 
249 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGD(const VeryForwardRealGeometryRecord& iRecord) {
250  return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
254  "CTPPSGeometryESModule::produceRealGD");
255 }
256 
257 //----------------------------------------------------------------------------------------------------
258 
259 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGD(
260  const VeryForwardMisalignedGeometryRecord& iRecord) {
261  return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
265  "CTPPSGeometryESModule::produceMisalignedGD");
266 }
267 
268 //----------------------------------------------------------------------------------------------------
269 
270 std::unique_ptr<CTPPSGeometry> CTPPSGeometryESModule::produceRealTG(const VeryForwardRealGeometryRecord& iRecord) {
271  auto const& gD = iRecord.get(dgdRealToken_);
272 
273  return std::make_unique<CTPPSGeometry>(&gD, verbosity_);
274 }
275 
276 //----------------------------------------------------------------------------------------------------
277 
278 std::unique_ptr<CTPPSGeometry> CTPPSGeometryESModule::produceMisalignedTG(
279  const VeryForwardMisalignedGeometryRecord& iRecord) {
280  auto const& gD = iRecord.get(dgdMisToken_);
281 
282  return std::make_unique<CTPPSGeometry>(&gD, verbosity_);
283 }
284 
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:163
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const mapType & getSensorMap() const
returns the map of sensor alignment corrections
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)
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_
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
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 &)