Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small enhancements to geometry DB payload validation scripts #31320

Merged
merged 12 commits into from
Sep 5, 2020
34 changes: 22 additions & 12 deletions DetectorDescription/OfflineDBLoader/src/GeometryInfoDump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
using Graph = DDCompactView::Graph;
using adjl_iterator = Graph::const_adj_iterator;

// For output of values to four decimal places, round negative values
// equivalent to 0 within the precision to 0 to prevent printing "-0".
template <class valType>
static constexpr valType roundNeg0(valType value) {
if (value < 0. && value > -5.0e-5)
return (0.0);
else
return (value);
}

GeometryInfoDump::GeometryInfoDump() {}

GeometryInfoDump::~GeometryInfoDump() {}
Expand Down Expand Up @@ -52,18 +62,18 @@ void GeometryInfoDump::dumpInfo(
size_t s = snprintf(buf,
256,
",%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f,%12.4f",
epv.translation().x(),
epv.translation().y(),
epv.translation().z(),
x.X(),
y.X(),
z.X(),
x.Y(),
y.Y(),
z.Y(),
x.Z(),
y.Z(),
z.Z());
roundNeg0(epv.translation().x()),
roundNeg0(epv.translation().y()),
roundNeg0(epv.translation().z()),
roundNeg0(x.X()),
roundNeg0(y.X()),
roundNeg0(z.X()),
roundNeg0(x.Y()),
roundNeg0(y.Y()),
roundNeg0(z.Y()),
roundNeg0(x.Z()),
roundNeg0(y.Z()),
roundNeg0(z.Z()));
assert(s < 256);
dump << buf;
}
Expand Down
2 changes: 1 addition & 1 deletion Geometry/CSCGeometry/test/testCSCGeometry_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# ====================
process.load("Geometry.MuonNumbering.muonGeometryConstants_cff")
process.load("Geometry.MuonNumbering.muonNumberingInitialization_cfi")
process.load("Geometry.MuonCommonData.muonEndcapIdealGeometryXML_cfi")
process.load('Configuration.Geometry.GeometryExtended_cff')
cvuosalo marked this conversation as resolved.
Show resolved Hide resolved

# Fake alignment is/should be ideal geometry
# ==========================================
Expand Down
28 changes: 21 additions & 7 deletions Geometry/DTGeometry/test/DTGeometryAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <FWCore/Framework/interface/one/EDAnalyzer.h>
#include <FWCore/Framework/interface/EventSetup.h>
#include <FWCore/Framework/interface/ESHandle.h>
#include "FWCore/ParameterSet/interface/ParameterSet.h"
cvuosalo marked this conversation as resolved.
Show resolved Hide resolved
#include "DataFormats/Math/interface/Rounding.h"

#include <Geometry/CommonDetUnit/interface/GeomDet.h>

Expand All @@ -22,6 +24,7 @@
#include <vector>

using namespace std;
using namespace cms_rounding;

class DTGeometryAnalyzer : public edm::one::EDAnalyzer<> {
public:
Expand All @@ -37,16 +40,26 @@ class DTGeometryAnalyzer : public edm::one::EDAnalyzer<> {
const int dashedLineWidth_;
const string dashedLine_;
const string myName_;
bool tinyDifferences_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvuosalo - why not a tolerance_ itself rather then the hardcoded numbers? I think, there are other analysers that define tolerance.

};

DTGeometryAnalyzer::DTGeometryAnalyzer(const edm::ParameterSet& iConfig)
: dashedLineWidth_(104), dashedLine_(string(dashedLineWidth_, '-')), myName_("DTGeometryAnalyzer") {}
: dashedLineWidth_(104),
dashedLine_(string(dashedLineWidth_, '-')),
myName_("DTGeometryAnalyzer"),
tinyDifferences_(iConfig.getUntrackedParameter<bool>("tinyDifferences", true))
// Set tinyDifferences to True to show values as small as |1.e-23|;
// otherwise values <|1.e-7| will be rounded to 0.
{}

DTGeometryAnalyzer::~DTGeometryAnalyzer() {}

void DTGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::ESHandle<DTGeometry> pDD;
iSetup.get<MuonGeometryRecord>().get(pDD);
double tolerance = 1.e-7;
if (tinyDifferences_)
tolerance = 1.e-23;

cout << myName() << ": Analyzer..." << endl;
cout << "start " << dashedLine_ << endl;
Expand Down Expand Up @@ -83,7 +96,7 @@ void DTGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup
cout << "Layer " << det->id() << " SL " << det->superLayer()->id() << " chamber " << det->chamber()->id()
<< " Topology W/H/L: " << topo.cellWidth() << "/" << topo.cellHeight() << "/" << topo.cellLenght()
<< " first/last/# wire " << topo.firstChannel() << "/" << topo.lastChannel() << "/" << topo.channels()
<< " Position " << surf.position() << " normVect " << surf.normalVector()
<< " Position " << surf.position() << " normVect " << roundVecIfNear0(surf.normalVector(), tolerance)
<< " bounds W/H/L: " << surf.bounds().width() << "/" << surf.bounds().thickness() << "/"
<< surf.bounds().length() << endl;
}
Expand All @@ -93,8 +106,9 @@ void DTGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup
for (auto det : pDD->superLayers()) {
const BoundPlane& surf = det->surface();
cout << "SuperLayer " << det->id() << " chamber " << det->chamber()->id() << " Position " << surf.position()
<< " normVect " << surf.normalVector() << " bounds W/H/L: " << surf.bounds().width() << "/"
<< surf.bounds().thickness() << "/" << surf.bounds().length() << endl;
<< " normVect " << roundVecIfNear0(surf.normalVector(), tolerance)
<< " bounds W/H/L: " << surf.bounds().width() << "/" << surf.bounds().thickness() << "/"
<< surf.bounds().length() << endl;
}

// check chamber
Expand All @@ -103,9 +117,9 @@ void DTGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup
//cout << "Chamber " << (*det)->geographicalId().det() << endl;
const BoundPlane& surf = det->surface();
//cout << "surf " << &surf << endl;
cout << "Chamber " << det->id() << " Position " << surf.position() << " normVect " << surf.normalVector()
<< " bounds W/H/L: " << surf.bounds().width() << "/" << surf.bounds().thickness() << "/"
<< surf.bounds().length() << endl;
cout << "Chamber " << det->id() << " Position " << surf.position() << " normVect "
<< roundVecIfNear0(surf.normalVector(), tolerance) << " bounds W/H/L: " << surf.bounds().width() << "/"
<< surf.bounds().thickness() << "/" << surf.bounds().length() << endl;
}
cout << "END " << dashedLine_ << endl;

Expand Down
4 changes: 3 additions & 1 deletion Geometry/DTGeometry/test/testDTGeometryFromDB_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

process.source = cms.Source("EmptySource")

process.prod = cms.EDAnalyzer("DTGeometryAnalyzer")
process.prod = cms.EDAnalyzer("DTGeometryAnalyzer",
tinyDifferences = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.prod)
4 changes: 3 additions & 1 deletion Geometry/DTGeometry/test/testDTGeometryFromLocalDB_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

process.source = cms.Source("EmptySource")

process.prod = cms.EDAnalyzer("DTGeometryAnalyzer")
process.prod = cms.EDAnalyzer("DTGeometryAnalyzer",
tinyDifferences = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.prod)
4 changes: 3 additions & 1 deletion Geometry/DTGeometry/test/testDTGeometry_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

process.out = cms.OutputModule("AsciiOutputModule")

process.prod = cms.EDAnalyzer("DTGeometryAnalyzer")
process.prod = cms.EDAnalyzer("DTGeometryAnalyzer",
tinyDifferences = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.prod)

Expand Down
31 changes: 24 additions & 7 deletions Geometry/TrackerGeometryBuilder/test/ModuleInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
#include "DataFormats/GeometrySurface/interface/BoundSurface.h"
#include "DataFormats/Math/interface/Rounding.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "Geometry/TrackerNumberingBuilder/interface/CmsTrackerDebugNavigator.h"
Expand All @@ -59,6 +60,8 @@
#include <cmath>
#include <bitset>

using namespace cms_rounding;

class ModuleInfo : public edm::one::EDAnalyzer<> {
public:
explicit ModuleInfo(const edm::ParameterSet&);
Expand All @@ -71,14 +74,18 @@ class ModuleInfo : public edm::one::EDAnalyzer<> {
private:
bool fromDDD_;
bool printDDD_;
bool tinyDifferences_;
};

static const double density_units = 6.24151e+18;

ModuleInfo::ModuleInfo(const edm::ParameterSet& ps) {
fromDDD_ = ps.getParameter<bool>("fromDDD");
printDDD_ = ps.getUntrackedParameter<bool>("printDDD", true);
}
ModuleInfo::ModuleInfo(const edm::ParameterSet& ps)
: fromDDD_(ps.getParameter<bool>("fromDDD")),
printDDD_(ps.getUntrackedParameter<bool>("printDDD", true)),
tinyDifferences_(ps.getUntrackedParameter<bool>("tinyDifferences", true))
// Set tinyDifferences to True to show values as small as |1.e-23|;
// otherwise values <|1.e-7| will be rounded to 0.
{}

ModuleInfo::~ModuleInfo() {}

Expand All @@ -94,6 +101,10 @@ void ModuleInfo::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
std::ofstream NumberingOutput("ModuleNumbering.dat", std::ios::out);
//

double tolerance = 1.e-7;
if (tinyDifferences_)
tolerance = 1.e-23;

//
// get the GeometricDet
//
Expand Down Expand Up @@ -473,12 +484,12 @@ void ModuleInfo::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
} else {
out_module = tTopo->tecModule(id);
}
double out_x = module->translation().X();
double out_y = module->translation().Y();
double out_x = roundIfNear0(module->translation().X(), tolerance);
double out_y = roundIfNear0(module->translation().Y(), tolerance);
double out_z = module->translation().Z();
double out_r = sqrt(module->translation().X() * module->translation().X() +
module->translation().Y() * module->translation().Y());
double out_phi_rad = atan2(module->translation().Y(), module->translation().X());
double out_phi_rad = roundIfNear0(atan2(module->translation().Y(), module->translation().X()), tolerance);
TECOutput << out_side << " " << out_disk << " " << out_sector << " " << out_petal << " " << out_ring << " "
<< out_module << " " << out_sensor << " " << out_x << " " << out_y << " " << out_z << " " << out_r
<< " " << out_phi_rad << std::endl;
Expand Down Expand Up @@ -526,6 +537,12 @@ void ModuleInfo::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
// active area versors (rotation matrix)
DD3Vector x, y, z;
module->rotation().GetComponents(x, y, z);
x = roundVecIfNear0(x, tolerance);
y = roundVecIfNear0(y, tolerance);
z = roundVecIfNear0(z, tolerance);
xGlobal = roundVecIfNear0(xGlobal, tolerance);
yGlobal = roundVecIfNear0(yGlobal, tolerance);
zGlobal = roundVecIfNear0(zGlobal, tolerance);
Output << "\tActive Area Rotation Matrix" << std::endl;
Output << "\t z = n = (" << std::fixed << std::setprecision(4) << z.X() << "," << std::fixed << std::setprecision(4)
<< z.Y() << "," << std::fixed << std::setprecision(4) << z.Z() << ")" << std::endl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
process.out = cms.OutputModule("AsciiOutputModule")

process.prod = cms.EDAnalyzer("ModuleInfo",
fromDDD = cms.bool(False)
fromDDD = cms.bool(False),
tinyDifferences = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.prod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

process.prod = cms.EDAnalyzer("ModuleInfo",
fromDDD = cms.bool(True),
printDDD = cms.untracked.bool(False)
printDDD = cms.untracked.bool(False),
tinyDifferences = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.prod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

process.prod = cms.EDAnalyzer("ModuleInfo",
fromDDD = cms.bool(True),
printDDD = cms.untracked.bool(False)
printDDD = cms.untracked.bool(False),
tinyDifferences = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.prod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
process.out = cms.OutputModule("AsciiOutputModule")

process.prod = cms.EDAnalyzer("ModuleInfo",
fromDDD = cms.bool(False)
fromDDD = cms.bool(False),
tinyDifferences = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.prod)
Expand Down
Loading