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

[DD4hep] Update to master 21 10 2020 #31879

Merged
merged 16 commits into from
Oct 22, 2020
43 changes: 0 additions & 43 deletions Alignment/CocoaApplication/interface/CocoaAnalyzer.h

This file was deleted.

146 changes: 70 additions & 76 deletions Alignment/CocoaApplication/src/CocoaAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "FWCore/Framework/interface/ESTransientHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"

#include "Alignment/CocoaApplication/interface/CocoaAnalyzer.h"
#include "Alignment/CocoaUtilities/interface/ALIUtils.h"
#include "Alignment/CocoaModel/interface/Model.h"
#include "Alignment/CocoaFit/interface/Fit.h"
Expand All @@ -22,6 +22,34 @@
#include "Alignment/CocoaModel/interface/OpticalObject.h"
#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
#include "Alignment/CocoaFit/interface/CocoaDBMgr.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h"
#include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h"
#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h"

class CocoaAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit CocoaAnalyzer(edm::ParameterSet const& p);
explicit CocoaAnalyzer(int i) {}
~CocoaAnalyzer() override {}

void beginJob() override;
void analyze(const edm::Event& e, const edm::EventSetup& c) override;

private:
void readXMLFile(const edm::EventSetup& evts);

std::vector<OpticalAlignInfo> readCalibrationDB(const edm::EventSetup& evts);
void correctAllOpticalAlignments(std::vector<OpticalAlignInfo>& allDBOpticalAlignments);
void correctOpticalAlignmentParameter(OpticalAlignParam& myXMLParam, const OpticalAlignParam& myDBParam);

void runCocoa();

private:
OpticalAlignments oaList_;
OpticalAlignMeasurements measList_;
std::string theCocoaDaqRootFileName_;
};

using namespace cms_units::operators;

Expand Down Expand Up @@ -160,35 +188,35 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
oaInfo.x_.name_ = "X";
oaInfo.x_.dim_type_ = "centre";
oaInfo.x_.value_ = transl.x() / (1._m); // COCOA units are m
oaInfo.x_.error_ = getParameterValueFromSpecParSections<double>(allSpecParSections,
nodePath,
"centre_X_sigma",
0) /
oaInfo.x_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
nodePath,
"centre_X_sigma",
0) /
(1._m); // COCOA units are m
oaInfo.x_.quality_ = static_cast<int>(
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_X_quality", 0));
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_X_quality", 0));
// Y
oaInfo.y_.name_ = "Y";
oaInfo.y_.dim_type_ = "centre";
oaInfo.y_.value_ = transl.y() / (1._m); // COCOA units are m
oaInfo.y_.error_ = getParameterValueFromSpecParSections<double>(allSpecParSections,
nodePath,
"centre_Y_sigma",
0) /
oaInfo.y_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
nodePath,
"centre_Y_sigma",
0) /
(1._m); // COCOA units are m
oaInfo.y_.quality_ = static_cast<int>(
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Y_quality", 0));
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Y_quality", 0));
// Z
oaInfo.z_.name_ = "Z";
oaInfo.z_.dim_type_ = "centre";
oaInfo.z_.value_ = transl.z() / (1._m); // COCOA units are m
oaInfo.z_.error_ = getParameterValueFromSpecParSections<double>(allSpecParSections,
nodePath,
"centre_Z_sigma",
0) /
oaInfo.z_.error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
nodePath,
"centre_Z_sigma",
0) /
(1._m); // COCOA units are m
oaInfo.z_.quality_ = static_cast<int>(
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Z_quality", 0));
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Z_quality", 0));

// ROTATIONS

Expand Down Expand Up @@ -234,34 +262,35 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
oaInfo.angx_.name_ = "X";
oaInfo.angx_.dim_type_ = "angles";
oaInfo.angx_.value_ =
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_value", 0);
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_value", 0);
oaInfo.angx_.error_ =
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_sigma", 0);
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_sigma", 0);
oaInfo.angx_.quality_ = static_cast<int>(
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_quality", 0));
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_X_quality", 0));
// Y
oaInfo.angy_.name_ = "Y";
oaInfo.angy_.dim_type_ = "angles";
oaInfo.angy_.value_ =
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_value", 0);
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_value", 0);
oaInfo.angy_.error_ =
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_sigma", 0);
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_sigma", 0);
oaInfo.angy_.quality_ = static_cast<int>(
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_quality", 0));
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Y_quality", 0));
// Z
oaInfo.angz_.name_ = "Z";
oaInfo.angz_.dim_type_ = "angles";
oaInfo.angz_.value_ =
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_value", 0);
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_value", 0);
oaInfo.angz_.error_ =
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_sigma", 0);
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_sigma", 0);
oaInfo.angz_.quality_ = static_cast<int>(
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_quality", 0));
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "angles_Z_quality", 0));

oaInfo.type_ = getParameterValueFromSpecParSections<std::string>(allSpecParSections, nodePath, "cocoa_type", 0);
oaInfo.type_ =
cms::getParameterValueFromSpecParSections<std::string>(allSpecParSections, nodePath, "cocoa_type", 0);

oaInfo.ID_ =
static_cast<int>(getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "cmssw_ID", 0));
oaInfo.ID_ = static_cast<int>(
cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "cmssw_ID", 0));

if (ALIUtils::debug >= 4) {
edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read ";
Expand All @@ -279,15 +308,15 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
// EXTRA PARAM ENTRIES (FROM XMLS)
// Here initial code to define the containers was fully removed, this is much more compact.
const std::vector<std::string>& names =
getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "extra_entry");
cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "extra_entry");
const std::vector<std::string>& dims =
getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "dimType");
cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "dimType");
const std::vector<double>& values =
getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "value");
cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "value");
const std::vector<double>& errors =
getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "sigma");
cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "sigma");
const std::vector<double>& quality =
getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "quality");
cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "quality");

if (ALIUtils::debug >= 4) {
edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters ";
Expand Down Expand Up @@ -320,25 +349,25 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {

// MEASUREMENTS (FROM XMLS)
const std::vector<std::string>& measNames =
getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_name");
cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_name");
const std::vector<std::string>& measTypes =
getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_type");
cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_type");

std::map<std::string, std::vector<std::string>> measObjectNames;
std::map<std::string, std::vector<std::string>> measParamNames;
std::map<std::string, std::vector<double>> measParamValues;
std::map<std::string, std::vector<double>> measParamSigmas;
std::map<std::string, std::vector<double>> measIsSimulatedValue;
for (const auto& name : measNames) {
measObjectNames[name] = getAllParameterValuesFromSpecParSections<std::string>(
measObjectNames[name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
allSpecParSections, nodePath, "meas_object_name_" + name);
measParamNames[name] = getAllParameterValuesFromSpecParSections<std::string>(
measParamNames[name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
allSpecParSections, nodePath, "meas_value_name_" + name);
measParamValues[name] =
getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_value_" + name);
cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_value_" + name);
measParamSigmas[name] =
getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_sigma_" + name);
measIsSimulatedValue[name] = getAllParameterValuesFromSpecParSections<double>(
cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath, "meas_sigma_" + name);
measIsSimulatedValue[name] = cms::getAllParameterValuesFromSpecParSections<double>(
allSpecParSections, nodePath, "meas_is_simulated_value_" + name);
}

Expand Down Expand Up @@ -568,39 +597,4 @@ void CocoaAnalyzer::runCocoa() {
}
}

/* Helper: For a given node, get the values associated to a given parameter, from the XMLs SpecPar sections.
* NB: The same parameter can appear several times WITHIN the same SpecPar section (hence, we have a std::vector).
* WARNING: This stops at the first relevant SpecPar section encountered.
* Hence, if A GIVEN NODE HAS SEVERAL SPECPAR XML SECTIONS RE-DEFINING THE SAME PARAMETER,
* only the first XML SpecPar block will be considered.
*/
template <typename T>
std::vector<T> CocoaAnalyzer::getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
const std::string& nodePath,
const std::string& parameterName) {
cms::DDSpecParRefs filteredSpecParSections;
allSpecParSections.filter(filteredSpecParSections, parameterName);
for (const auto& mySpecParSection : filteredSpecParSections) {
if (mySpecParSection->hasPath(nodePath)) {
return mySpecParSection->value<std::vector<T>>(parameterName);
}
}

return std::vector<T>();
}

/* Helper: For a given node, get the value associated to a given parameter, from the XMLs SpecPar sections.
* This is the parameterValueIndex-th value (within a XML SpecPar block.) of the desired parameter.
*/
template <typename T>
T CocoaAnalyzer::getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
const std::string& nodePath,
const std::string& parameterName,
const unsigned int parameterValueIndex) {
const std::vector<T>& allParameterValues =
getAllParameterValuesFromSpecParSections<T>(allSpecParSections, nodePath, parameterName);
if (parameterValueIndex < allParameterValues.size()) {
return allParameterValues.at(parameterValueIndex);
}
return T();
}
DEFINE_FWK_MODULE(CocoaAnalyzer);
4 changes: 0 additions & 4 deletions Alignment/CocoaApplication/src/SealModule.cc

This file was deleted.

39 changes: 39 additions & 0 deletions DetectorDescription/DDCMS/interface/DDCompactView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace cms {
using DDSpecParRegistry = dd4hep::SpecParRegistry;
using DDSpecParRefs = dd4hep::SpecParRefs;

class DDCompactView {
public:
Expand All @@ -43,6 +44,44 @@ namespace cms {
private:
const cms::DDDetector& m_det;
};

/* Helper: For a given node, get the values associated to a given parameter, from the XMLs SpecPar sections.
* NB: The same parameter can appear several times WITHIN the same SpecPar section (hence, we have a std::vector).
* WARNING: This stops at the first relevant SpecPar section encountered.
* Hence, if A GIVEN NODE HAS SEVERAL SPECPAR XML SECTIONS RE-DEFINING THE SAME PARAMETER,
* only the first XML SpecPar block will be considered.
*/
template <typename T>
std::vector<T> getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
const std::string& nodePath,
const std::string& parameterName) {
cms::DDSpecParRefs filteredSpecParSections;
allSpecParSections.filter(filteredSpecParSections, parameterName);
for (const auto& mySpecParSection : filteredSpecParSections) {
if (mySpecParSection.second->hasPath(nodePath)) {
return mySpecParSection.second->value<std::vector<T>>(parameterName);
}
}

return std::vector<T>();
}

/* Helper: For a given node, get the value associated to a given parameter, from the XMLs SpecPar sections.
* This is the parameterValueIndex-th value (within a XML SpecPar block.) of the desired parameter.
*/
template <typename T>
T getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
const std::string& nodePath,
const std::string& parameterName,
const unsigned int parameterValueIndex) {
const std::vector<T>& allParameterValues =
getAllParameterValuesFromSpecParSections<T>(allSpecParSections, nodePath, parameterName);
if (parameterValueIndex < allParameterValues.size()) {
return allParameterValues.at(parameterValueIndex);
}
return T();
}

} // namespace cms

#endif
4 changes: 2 additions & 2 deletions DetectorDescription/DDCMS/interface/DDFilteredView.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace cms {

std::string path = this->path();
for (const auto& specPar : refs) {
for (const auto& part : specPar->paths) {
for (const auto& part : specPar.second->paths) {
bool flag(true);
std::size_t from = 0;
for (auto name : dd4hep::dd::split(part, "/")) {
Expand All @@ -185,7 +185,7 @@ namespace cms {
}
}
if (flag) {
return specPar->value<std::vector<T>>(key);
return specPar.second->value<std::vector<T>>(key);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions DetectorDescription/DDCMS/interface/DDParsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace cms {
bool debug_specpars = false;

dd4hep::Detector& description;

std::unordered_map<std::string, dd4hep::Assembly> assemblies;
std::unordered_map<std::string, dd4hep::Rotation3D> rotations;
std::unordered_map<std::string, dd4hep::Solid> shapes;
Expand Down
1 change: 1 addition & 0 deletions DetectorDescription/DDCMS/interface/DDSpecParRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace cms {

using DDSpecParRegistry = dd4hep::SpecParRegistry;
using DDSpecPar = dd4hep::SpecPar;
using DDSpecParRefs = dd4hep::SpecParRefs;

} // namespace cms

Expand Down
Loading