66* Rewritten + Moved out common functionailities to DetGeomDesc(Builder) by Gabrielle Hugo.
77* Migrated to DD4hep by Wagner Carvalho and Gabrielle Hugo.
88*
9+ * Add the capability of reading PPS reco geometry from the database
10+ *
911****************************************************************************/
1012
1113#include " FWCore/ParameterSet/interface/ParameterSet.h"
1921#include " DetectorDescription/DDCMS/interface/DDCompactView.h"
2022#include " CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h"
2123
24+ #include " CondFormats/GeometryObjects/interface/PDetGeomDesc.h"
2225#include " CondFormats/AlignmentRecord/interface/RPRealAlignmentRecord.h"
2326#include " CondFormats/AlignmentRecord/interface/RPMisalignedAlignmentRecord.h"
2427#include " Geometry/Records/interface/IdealGeometryRecord.h"
28+ #include " Geometry/Records/interface/VeryForwardIdealGeometryRecord.h"
2529#include " Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h"
2630#include " Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
2731
@@ -55,68 +59,93 @@ class CTPPSGeometryESModule : public edm::ESProducer {
5559
5660private:
5761 std::unique_ptr<DetGeomDesc> produceIdealGD (const IdealGeometryRecord&);
62+ std::unique_ptr<DetGeomDesc> produceIdealGDFromPreprocessedDB (const VeryForwardIdealGeometryRecord&);
5863 std::vector<int > fillCopyNos (TGeoIterator& it);
5964
60- template <typename ALIGNMENT_REC>
61- struct GDTokens {
62- explicit GDTokens (edm::ESConsumesCollector&& iCC)
63- : idealGDToken_{iCC.consumesFrom <DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag ())},
64- alignmentToken_{iCC.consumesFrom <CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC>(edm::ESInputTag ())} {}
65- const edm::ESGetToken<DetGeomDesc, IdealGeometryRecord> idealGDToken_;
66- const edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC> alignmentToken_;
67- };
68-
6965 std::unique_ptr<DetGeomDesc> produceRealGD (const VeryForwardRealGeometryRecord&);
66+ std::unique_ptr<DetGeomDesc> produceRealGDFromPreprocessedDB (const VeryForwardRealGeometryRecord&);
7067 std::unique_ptr<CTPPSGeometry> produceRealTG (const VeryForwardRealGeometryRecord&);
7168
7269 std::unique_ptr<DetGeomDesc> produceMisalignedGD (const VeryForwardMisalignedGeometryRecord&);
70+ std::unique_ptr<DetGeomDesc> produceMisalignedGDFromPreprocessedDB (const VeryForwardMisalignedGeometryRecord&);
7371 std::unique_ptr<CTPPSGeometry> produceMisalignedTG (const VeryForwardMisalignedGeometryRecord&);
7472
75- template <typename REC>
76- std::unique_ptr<DetGeomDesc> produceGD (IdealGeometryRecord const &,
73+ template <typename REC , typename GEO >
74+ std::unique_ptr<DetGeomDesc> produceGD (const GEO &,
7775 const std::optional<REC>&,
78- GDTokens<REC> const &,
76+ edm::ESGetToken<DetGeomDesc,GEO> const &,
77+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData,REC> const &,
7978 const char * name);
8079
8180 const unsigned int verbosity_;
8281 const bool isRun2_;
8382
8483 edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddToken_;
8584 edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepToken_;
86- const bool fromDD4hep_;
85+ edm::ESGetToken<PDetGeomDesc, VeryForwardIdealGeometryRecord> dbToken_;
86+ const bool fromPreprocessedDB_, fromDD4hep_;
8787
88- const GDTokens<RPRealAlignmentRecord> gdRealTokens_;
89- const GDTokens<RPMisalignedAlignmentRecord> gdMisTokens_;
88+ edm::ESGetToken<DetGeomDesc, IdealGeometryRecord> idealGDToken_;
89+ edm::ESGetToken<DetGeomDesc, VeryForwardIdealGeometryRecord> idealDBGDToken_;
90+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord> realAlignmentToken_;
91+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord> misAlignmentToken_;
9092
91- const edm::ESGetToken<DetGeomDesc, VeryForwardRealGeometryRecord> dgdRealToken_;
92- const edm::ESGetToken<DetGeomDesc, VeryForwardMisalignedGeometryRecord> dgdMisToken_;
93+ edm::ESGetToken<DetGeomDesc, VeryForwardRealGeometryRecord> dgdRealToken_;
94+ edm::ESGetToken<DetGeomDesc, VeryForwardMisalignedGeometryRecord> dgdMisToken_;
9395};
9496
9597CTPPSGeometryESModule::CTPPSGeometryESModule (const edm::ParameterSet& iConfig)
9698 : verbosity_(iConfig.getUntrackedParameter<unsigned int >(" verbosity" )),
9799 isRun2_(iConfig.getParameter<bool >(" isRun2" )),
98- fromDD4hep_(iConfig.getUntrackedParameter<bool >(" fromDD4hep" , false )),
99- gdRealTokens_{setWhatProduced (this , &CTPPSGeometryESModule::produceRealGD)},
100- gdMisTokens_{setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGD)},
101- dgdRealToken_{
102- setWhatProduced (this , &CTPPSGeometryESModule::produceRealTG).consumes <DetGeomDesc>(edm::ESInputTag ())},
103- dgdMisToken_{
104- setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedTG).consumes <DetGeomDesc>(edm::ESInputTag ())} {
105- auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGD);
106-
107- if (!fromDD4hep_) {
100+ fromPreprocessedDB_(iConfig.getUntrackedParameter<bool >(" fromPreprocessedDB" , false )),
101+ fromDD4hep_(iConfig.getUntrackedParameter<bool >(" fromDD4hep" , false )) {
102+ if (fromPreprocessedDB_) {
103+ auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB);
104+ dbToken_ = c.consumes <PDetGeomDesc>(edm::ESInputTag (" " , iConfig.getParameter <std::string>(" dbTag" )));
105+
106+ auto c1 = setWhatProduced (this , &CTPPSGeometryESModule::produceRealGDFromPreprocessedDB);
107+ idealDBGDToken_ = c1.consumesFrom <DetGeomDesc, VeryForwardIdealGeometryRecord>(edm::ESInputTag ());
108+ realAlignmentToken_ = c1.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag ());
109+
110+ auto c2 = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB);
111+ misAlignmentToken_ = c2.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag ());
112+ } else if (!fromDD4hep_) {
113+ auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGD);
108114 ddToken_ = c.consumes <DDCompactView>(edm::ESInputTag (" " , iConfig.getParameter <std::string>(" compactViewTag" )));
115+
116+ auto c1 = setWhatProduced (this , &CTPPSGeometryESModule::produceRealGD);
117+ idealGDToken_ = c1.consumesFrom <DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag ());
118+ realAlignmentToken_ = c1.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag ());
119+
120+ auto c2 = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGD);
121+ misAlignmentToken_ = c2.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag ());
109122 } else {
123+ auto c = setWhatProduced (this , &CTPPSGeometryESModule::produceIdealGD);
110124 dd4hepToken_ =
111125 c.consumes <cms::DDCompactView>(edm::ESInputTag (" " , iConfig.getParameter <std::string>(" compactViewTag" )));
126+
127+ auto c1 = setWhatProduced (this , &CTPPSGeometryESModule::produceRealGD);
128+ idealGDToken_ = c1.consumesFrom <DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag ());
129+ realAlignmentToken_ = c1.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag ());
130+
131+ auto c2 = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedGD);
132+ misAlignmentToken_ = c2.consumesFrom <CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag ());
112133 }
134+
135+ auto c_RTG = setWhatProduced (this , &CTPPSGeometryESModule::produceRealTG);
136+ dgdRealToken_ = c_RTG.consumes <DetGeomDesc>(edm::ESInputTag ());
137+
138+ auto c_MTG = setWhatProduced (this , &CTPPSGeometryESModule::produceMisalignedTG);
139+ dgdMisToken_ = c_MTG.consumes <DetGeomDesc>(edm::ESInputTag ());
113140}
114141
115142void CTPPSGeometryESModule::fillDescriptions (edm::ConfigurationDescriptions& descriptions) {
116143 edm::ParameterSetDescription desc;
117144 desc.addUntracked <unsigned int >(" verbosity" , 1 );
118145 desc.add <bool >(" isRun2" , false )->setComment (" Switch to legacy (2017-18) definition of diamond geometry" );
146+ desc.add <std::string>(" dbTag" , std::string ());
119147 desc.add <std::string>(" compactViewTag" , std::string ());
148+ desc.addUntracked <bool >(" fromPreprocessedDB" , false );
120149 desc.addUntracked <bool >(" fromDD4hep" , false );
121150 descriptions.add (" CTPPSGeometryESModule" , desc);
122151}
@@ -139,18 +168,32 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGD(const IdealGe
139168 }
140169}
141170
142- template <typename REC>
143- std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD (IdealGeometryRecord const & iIdealRec,
144- std::optional<REC> const & iAlignRec,
145- GDTokens<REC> const & iTokens,
146- const char * name) {
171+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB (const VeryForwardIdealGeometryRecord& iRecord) {
172+
173+ // Get the PDetGeomDesc from EventSetup
174+ auto const & myDB = iRecord.get (dbToken_);
175+
176+ edm::LogInfo (" CTPPSGeometryESModule" ) << " myDB size = " << myDB.container_ .size ();
177+
178+ // Build geo from PDetGeomDesc DB object.
179+ auto pdet = std::make_unique<DetGeomDesc>(myDB);
180+ return pdet;
181+
182+ }
183+
184+ template <typename REC , typename GEO>
185+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD (GEO const & iIdealRec,
186+ std::optional<REC> const & iAlignRec,
187+ edm::ESGetToken<DetGeomDesc,GEO> const & iGDToken,
188+ edm::ESGetToken<CTPPSRPAlignmentCorrectionsData,REC> const & iAlignToken,
189+ const char * name) {
147190 // get the input GeometricalDet
148- auto const & idealGD = iIdealRec.get (iTokens. idealGDToken_ );
191+ auto const & idealGD = iIdealRec.get (iGDToken );
149192
150193 // load alignments
151194 CTPPSRPAlignmentCorrectionsData const * alignments = nullptr ;
152195 if (iAlignRec) {
153- auto alignmentsHandle = iAlignRec->getHandle (iTokens. alignmentToken_ );
196+ auto alignmentsHandle = iAlignRec->getHandle (iAlignToken );
154197 if (alignmentsHandle.isValid ()) {
155198 alignments = alignmentsHandle.product ();
156199 }
@@ -168,10 +211,32 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(IdealGeometryRecor
168211 return CTPPSGeometryESCommon::applyAlignments (idealGD, alignments);
169212}
170213
214+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGDFromPreprocessedDB (const VeryForwardRealGeometryRecord& iRecord) {
215+ return produceGD (iRecord.getRecord <VeryForwardIdealGeometryRecord>(),
216+ iRecord.tryToGetRecord <RPRealAlignmentRecord>(),
217+ idealDBGDToken_,
218+ realAlignmentToken_,
219+ " CTPPSGeometryESModule::produceRealGDFromPreprocessedDB" );
220+ }
221+
222+ // ----------------------------------------------------------------------------------------------------
223+
224+ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB (
225+ const VeryForwardMisalignedGeometryRecord& iRecord) {
226+ return produceGD (iRecord.getRecord <VeryForwardIdealGeometryRecord>(),
227+ iRecord.tryToGetRecord <RPMisalignedAlignmentRecord>(),
228+ idealDBGDToken_,
229+ misAlignmentToken_,
230+ " CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB" );
231+ }
232+
233+ // ----------------------------------------------------------------------------------------------------
234+
171235std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGD (const VeryForwardRealGeometryRecord& iRecord) {
172236 return produceGD (iRecord.getRecord <IdealGeometryRecord>(),
173237 iRecord.tryToGetRecord <RPRealAlignmentRecord>(),
174- gdRealTokens_,
238+ idealGDToken_,
239+ realAlignmentToken_,
175240 " CTPPSGeometryESModule::produceRealGD" );
176241}
177242
@@ -181,7 +246,8 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGD(
181246 const VeryForwardMisalignedGeometryRecord& iRecord) {
182247 return produceGD (iRecord.getRecord <IdealGeometryRecord>(),
183248 iRecord.tryToGetRecord <RPMisalignedAlignmentRecord>(),
184- gdMisTokens_,
249+ idealGDToken_,
250+ misAlignmentToken_,
185251 " CTPPSGeometryESModule::produceMisalignedGD" );
186252}
187253
0 commit comments