Skip to content

Commit

Permalink
Merge pull request #33851 from wpcarvalho/pps_db_reco_geom
Browse files Browse the repository at this point in the history
Change PPS geometry ES producer to read preprocessed geometry from DB
  • Loading branch information
cmsbuild authored May 28, 2021
2 parents 025e9cc + 4f8c283 commit 628c74d
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "FWCore/Framework/interface/DependentRecordImplementation.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/Records/interface/VeryForwardIdealGeometryRecord.h"

#include "FWCore/Utilities/interface/mplVector.h"

Expand All @@ -24,6 +25,7 @@
class VeryForwardMisalignedGeometryRecord
: public edm::eventsetup::DependentRecordImplementation<
VeryForwardMisalignedGeometryRecord,
edm::mpl::Vector<IdealGeometryRecord, RPMisalignedAlignmentRecord /*, ... */> > {};
edm::mpl::Vector<VeryForwardIdealGeometryRecord, IdealGeometryRecord, RPMisalignedAlignmentRecord /*, ... */> > {
};

#endif
8 changes: 5 additions & 3 deletions Geometry/Records/interface/VeryForwardRealGeometryRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "FWCore/Framework/interface/DependentRecordImplementation.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/Records/interface/VeryForwardIdealGeometryRecord.h"

#include "FWCore/Utilities/interface/mplVector.h"

Expand All @@ -20,8 +21,9 @@
* \ingroup TotemRPGeometry
* \brief Event setup record containing the real (actual) geometry information.
**/
class VeryForwardRealGeometryRecord : public edm::eventsetup::DependentRecordImplementation<
VeryForwardRealGeometryRecord,
edm::mpl::Vector<IdealGeometryRecord, RPRealAlignmentRecord /*, ... */> > {};
class VeryForwardRealGeometryRecord
: public edm::eventsetup::DependentRecordImplementation<
VeryForwardRealGeometryRecord,
edm::mpl::Vector<VeryForwardIdealGeometryRecord, IdealGeometryRecord, RPRealAlignmentRecord /*, ... */> > {};

#endif
6 changes: 5 additions & 1 deletion Geometry/VeryForwardGeometryBuilder/interface/DetGeomDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "DetectorDescription/Core/interface/DDFilteredView.h"
#include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
#include "CondFormats/GeometryObjects/interface/PDetGeomDesc.h"

#include "DataFormats/DetId/interface/DetId.h"
#include <Math/Rotation3D.h>
Expand Down Expand Up @@ -59,7 +60,10 @@ class DetGeomDesc {
// Constructor from DD4Hep DDFilteredView
/// \param[in] isRun2 Switch between legacy run 2-like geometry and 2021+ scenarii
DetGeomDesc(const cms::DDFilteredView& fv, const bool isRun2);

// Constructor from DB object PDetGeomDesc
DetGeomDesc(const PDetGeomDesc& gd);
// Constructor from DB object PDetGeomDesc::Item
DetGeomDesc(const PDetGeomDesc::Item& item);
virtual ~DetGeomDesc();

enum CopyMode { cmWithChildren, cmWithoutChildren };
Expand Down
1 change: 1 addition & 0 deletions Geometry/VeryForwardGeometryBuilder/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<use name="CondFormats/AlignmentRecord"/>
<use name="CondFormats/PPSObjects"/>
<use name="CondFormats/GeometryObjects"/>
<use name="DataFormats/CTPPSDetId"/>
<use name="DetectorDescription/Core"/>
<use name="DetectorDescription/DDCMS"/>
Expand Down
142 changes: 106 additions & 36 deletions Geometry/VeryForwardGeometryBuilder/plugins/CTPPSGeometryESModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Rewritten + Moved out common functionailities to DetGeomDesc(Builder) by Gabrielle Hugo.
* Migrated to DD4hep by Wagner Carvalho and Gabrielle Hugo.
*
* Add the capability of reading PPS reco geometry from the database
*
****************************************************************************/

#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand All @@ -19,9 +21,11 @@
#include "DetectorDescription/DDCMS/interface/DDCompactView.h"
#include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h"

#include "CondFormats/GeometryObjects/interface/PDetGeomDesc.h"
#include "CondFormats/AlignmentRecord/interface/RPRealAlignmentRecord.h"
#include "CondFormats/AlignmentRecord/interface/RPMisalignedAlignmentRecord.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/Records/interface/VeryForwardIdealGeometryRecord.h"
#include "Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h"
#include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h"

Expand Down Expand Up @@ -55,68 +59,96 @@ class CTPPSGeometryESModule : public edm::ESProducer {

private:
std::unique_ptr<DetGeomDesc> produceIdealGD(const IdealGeometryRecord&);
std::unique_ptr<DetGeomDesc> produceIdealGDFromPreprocessedDB(const VeryForwardIdealGeometryRecord&);
std::vector<int> fillCopyNos(TGeoIterator& it);

template <typename ALIGNMENT_REC>
struct GDTokens {
explicit GDTokens(edm::ESConsumesCollector&& iCC)
: idealGDToken_{iCC.consumesFrom<DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag())},
alignmentToken_{iCC.consumesFrom<CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC>(edm::ESInputTag())} {}
const edm::ESGetToken<DetGeomDesc, IdealGeometryRecord> idealGDToken_;
const edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC> alignmentToken_;
};

std::unique_ptr<DetGeomDesc> produceRealGD(const VeryForwardRealGeometryRecord&);
std::unique_ptr<DetGeomDesc> produceRealGDFromPreprocessedDB(const VeryForwardRealGeometryRecord&);
std::unique_ptr<CTPPSGeometry> produceRealTG(const VeryForwardRealGeometryRecord&);

std::unique_ptr<DetGeomDesc> produceMisalignedGD(const VeryForwardMisalignedGeometryRecord&);
std::unique_ptr<DetGeomDesc> produceMisalignedGDFromPreprocessedDB(const VeryForwardMisalignedGeometryRecord&);
std::unique_ptr<CTPPSGeometry> produceMisalignedTG(const VeryForwardMisalignedGeometryRecord&);

template <typename REC>
std::unique_ptr<DetGeomDesc> produceGD(IdealGeometryRecord const&,
template <typename REC, typename GEO>
std::unique_ptr<DetGeomDesc> produceGD(const GEO&,
const std::optional<REC>&,
GDTokens<REC> const&,
edm::ESGetToken<DetGeomDesc, GEO> const&,
edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, REC> const&,
const char* name);

const unsigned int verbosity_;
const bool isRun2_;

edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddToken_;
edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepToken_;
const bool fromDD4hep_;
edm::ESGetToken<PDetGeomDesc, VeryForwardIdealGeometryRecord> dbToken_;
const bool fromPreprocessedDB_, fromDD4hep_;

const GDTokens<RPRealAlignmentRecord> gdRealTokens_;
const GDTokens<RPMisalignedAlignmentRecord> gdMisTokens_;
edm::ESGetToken<DetGeomDesc, IdealGeometryRecord> idealGDToken_;
edm::ESGetToken<DetGeomDesc, VeryForwardIdealGeometryRecord> idealDBGDToken_;
edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord> realAlignmentToken_;
edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord> misAlignmentToken_;

const edm::ESGetToken<DetGeomDesc, VeryForwardRealGeometryRecord> dgdRealToken_;
const edm::ESGetToken<DetGeomDesc, VeryForwardMisalignedGeometryRecord> dgdMisToken_;
edm::ESGetToken<DetGeomDesc, VeryForwardRealGeometryRecord> dgdRealToken_;
edm::ESGetToken<DetGeomDesc, VeryForwardMisalignedGeometryRecord> dgdMisToken_;
};

CTPPSGeometryESModule::CTPPSGeometryESModule(const edm::ParameterSet& iConfig)
: verbosity_(iConfig.getUntrackedParameter<unsigned int>("verbosity")),
isRun2_(iConfig.getParameter<bool>("isRun2")),
fromDD4hep_(iConfig.getUntrackedParameter<bool>("fromDD4hep", false)),
gdRealTokens_{setWhatProduced(this, &CTPPSGeometryESModule::produceRealGD)},
gdMisTokens_{setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGD)},
dgdRealToken_{
setWhatProduced(this, &CTPPSGeometryESModule::produceRealTG).consumes<DetGeomDesc>(edm::ESInputTag())},
dgdMisToken_{
setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedTG).consumes<DetGeomDesc>(edm::ESInputTag())} {
auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGD);

if (!fromDD4hep_) {
fromPreprocessedDB_(iConfig.getUntrackedParameter<bool>("fromPreprocessedDB", false)),
fromDD4hep_(iConfig.getUntrackedParameter<bool>("fromDD4hep", false)) {
if (fromPreprocessedDB_) {
auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB);
dbToken_ = c.consumes<PDetGeomDesc>(edm::ESInputTag("", iConfig.getParameter<std::string>("dbTag")));

auto c1 = setWhatProduced(this, &CTPPSGeometryESModule::produceRealGDFromPreprocessedDB);
idealDBGDToken_ = c1.consumesFrom<DetGeomDesc, VeryForwardIdealGeometryRecord>(edm::ESInputTag());
realAlignmentToken_ = c1.consumesFrom<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag());

auto c2 = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB);
misAlignmentToken_ =
c2.consumesFrom<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag());
} else if (!fromDD4hep_) {
auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGD);
ddToken_ = c.consumes<DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));

auto c1 = setWhatProduced(this, &CTPPSGeometryESModule::produceRealGD);
idealGDToken_ = c1.consumesFrom<DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag());
realAlignmentToken_ = c1.consumesFrom<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag());

auto c2 = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGD);
misAlignmentToken_ =
c2.consumesFrom<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag());
} else {
auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGD);
dd4hepToken_ =
c.consumes<cms::DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));

auto c1 = setWhatProduced(this, &CTPPSGeometryESModule::produceRealGD);
idealGDToken_ = c1.consumesFrom<DetGeomDesc, IdealGeometryRecord>(edm::ESInputTag());
realAlignmentToken_ = c1.consumesFrom<CTPPSRPAlignmentCorrectionsData, RPRealAlignmentRecord>(edm::ESInputTag());

auto c2 = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGD);
misAlignmentToken_ =
c2.consumesFrom<CTPPSRPAlignmentCorrectionsData, RPMisalignedAlignmentRecord>(edm::ESInputTag());
}

auto c_RTG = setWhatProduced(this, &CTPPSGeometryESModule::produceRealTG);
dgdRealToken_ = c_RTG.consumes<DetGeomDesc>(edm::ESInputTag());

auto c_MTG = setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedTG);
dgdMisToken_ = c_MTG.consumes<DetGeomDesc>(edm::ESInputTag());
}

void CTPPSGeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.addUntracked<unsigned int>("verbosity", 1);
desc.add<bool>("isRun2", false)->setComment("Switch to legacy (2017-18) definition of diamond geometry");
desc.add<std::string>("dbTag", std::string());
desc.add<std::string>("compactViewTag", std::string());
desc.addUntracked<bool>("fromPreprocessedDB", false);
desc.addUntracked<bool>("fromDD4hep", false);
descriptions.add("CTPPSGeometryESModule", desc);
}
Expand All @@ -139,18 +171,32 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGD(const IdealGe
}
}

template <typename REC>
std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(IdealGeometryRecord const& iIdealRec,
std::optional<REC> const& iAlignRec,
GDTokens<REC> const& iTokens,
const char* name) {
std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGDFromPreprocessedDB(
const VeryForwardIdealGeometryRecord& iRecord) {
// Get the PDetGeomDesc from EventSetup
auto const& myDB = iRecord.get(dbToken_);

edm::LogInfo("CTPPSGeometryESModule") << " myDB size = " << myDB.container_.size();

// Build geo from PDetGeomDesc DB object.
auto pdet = std::make_unique<DetGeomDesc>(myDB);
return pdet;
}

template <typename REC, typename GEO>
std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(
GEO const& iIdealRec,
std::optional<REC> const& iAlignRec,
edm::ESGetToken<DetGeomDesc, GEO> const& iGDToken,
edm::ESGetToken<CTPPSRPAlignmentCorrectionsData, REC> const& iAlignToken,
const char* name) {
// get the input GeometricalDet
auto const& idealGD = iIdealRec.get(iTokens.idealGDToken_);
auto const& idealGD = iIdealRec.get(iGDToken);

// load alignments
CTPPSRPAlignmentCorrectionsData const* alignments = nullptr;
if (iAlignRec) {
auto alignmentsHandle = iAlignRec->getHandle(iTokens.alignmentToken_);
auto alignmentsHandle = iAlignRec->getHandle(iAlignToken);
if (alignmentsHandle.isValid()) {
alignments = alignmentsHandle.product();
}
Expand All @@ -168,10 +214,33 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(IdealGeometryRecor
return CTPPSGeometryESCommon::applyAlignments(idealGD, alignments);
}

std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGDFromPreprocessedDB(
const VeryForwardRealGeometryRecord& iRecord) {
return produceGD(iRecord.getRecord<VeryForwardIdealGeometryRecord>(),
iRecord.tryToGetRecord<RPRealAlignmentRecord>(),
idealDBGDToken_,
realAlignmentToken_,
"CTPPSGeometryESModule::produceRealGDFromPreprocessedDB");
}

//----------------------------------------------------------------------------------------------------

std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB(
const VeryForwardMisalignedGeometryRecord& iRecord) {
return produceGD(iRecord.getRecord<VeryForwardIdealGeometryRecord>(),
iRecord.tryToGetRecord<RPMisalignedAlignmentRecord>(),
idealDBGDToken_,
misAlignmentToken_,
"CTPPSGeometryESModule::produceMisalignedGDFromPreprocessedDB");
}

//----------------------------------------------------------------------------------------------------

std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGD(const VeryForwardRealGeometryRecord& iRecord) {
return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
iRecord.tryToGetRecord<RPRealAlignmentRecord>(),
gdRealTokens_,
idealGDToken_,
realAlignmentToken_,
"CTPPSGeometryESModule::produceRealGD");
}

Expand All @@ -181,7 +250,8 @@ std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGD(
const VeryForwardMisalignedGeometryRecord& iRecord) {
return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
iRecord.tryToGetRecord<RPMisalignedAlignmentRecord>(),
gdMisTokens_,
idealGDToken_,
misAlignmentToken_,
"CTPPSGeometryESModule::produceMisalignedGD");
}

Expand Down
34 changes: 33 additions & 1 deletion Geometry/VeryForwardGeometryBuilder/src/DetGeomDesc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,38 @@ DetGeomDesc::DetGeomDesc(const DetGeomDesc& ref, CopyMode cm) {
m_z = ref.m_z;
}

// Constructor from DB object PDetGeomDesc::Item
DetGeomDesc::DetGeomDesc(const PDetGeomDesc::Item& item)
: m_name(item.name_),
m_copy(item.copy_),
m_isDD4hep(true),
m_params(item.params_), // default unit from DD4hep
m_sensorType(item.sensorType_),
m_geographicalID(item.geographicalID_),
m_z(item.z_) // converted from DD4hep to mm
{
Translation trans(item.dx_, item.dy_, item.dz_);
m_trans = trans;
RotationMatrix rot(item.axx_, item.axy_, item.axz_, item.ayx_, item.ayy_, item.ayz_, item.azx_, item.azy_, item.azz_);
m_rot = rot;
// Set the m_isABox flag for the box shaped sensors, so that m_params are properly set
if ((m_name == DDD_CTPPS_PIXELS_SENSOR_NAME || m_name == DDD_CTPPS_PIXELS_SENSOR_NAME_2x2 ||
m_name == DDD_CTPPS_DIAMONDS_SEGMENT_NAME || m_name == DDD_CTPPS_UFSD_SEGMENT_NAME ||
m_name.substr(0, 7) == DDD_TOTEM_TIMING_SENSOR_TMPL.substr(0, 7)) &&
m_params.size() > 2)
m_isABox = true;
else
m_isABox = false;
m_diamondBoxParams = computeDiamondDimensions(m_isABox, m_isDD4hep, m_params);
}

DetGeomDesc::DetGeomDesc(const PDetGeomDesc& pd) {
for (const auto& i : pd.container_) {
DetGeomDesc* gd = new DetGeomDesc(i);
this->addComponent(gd);
}
}

DetGeomDesc::~DetGeomDesc() { deepDeleteComponents(); }

void DetGeomDesc::addComponent(DetGeomDesc* det) { m_container.emplace_back(det); }
Expand Down Expand Up @@ -122,7 +154,7 @@ void DetGeomDesc::deepDeleteComponents() {
}

std::string DetGeomDesc::computeNameWithNoNamespace(std::string_view nameFromView) const {
const auto& semiColonPos = nameFromView.find(":");
const auto& semiColonPos = nameFromView.find(':');
const std::string name{(semiColonPos != std::string::npos ? nameFromView.substr(semiColonPos + 1) : nameFromView)};
return name;
}
Expand Down
Loading

0 comments on commit 628c74d

Please sign in to comment.