Skip to content

Commit

Permalink
More meaningful to use ddhep::Direction than dd4hep::Position for a t…
Browse files Browse the repository at this point in the history
…ranslation + scram b code-format.
  • Loading branch information
ghugo83 committed Jul 2, 2020
1 parent c9f1f2c commit 72c4f77
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 63 deletions.
1 change: 0 additions & 1 deletion Alignment/CocoaApplication/interface/CocoaAnalyzer.h
Expand Up @@ -6,7 +6,6 @@
#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);
Expand Down
55 changes: 15 additions & 40 deletions Alignment/CocoaApplication/src/CocoaAnalyzer.cc
Expand Up @@ -23,10 +23,8 @@
#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
#include "Alignment/CocoaFit/interface/CocoaDBMgr.h"


using namespace cms_units::operators;


CocoaAnalyzer::CocoaAnalyzer(edm::ParameterSet const& pset) {
theCocoaDaqRootFileName = pset.getParameter<std::string>("cocoaDaqRootFile");
int maxEvents = pset.getParameter<int32_t>("maxEvents");
Expand All @@ -37,10 +35,8 @@ CocoaAnalyzer::CocoaAnalyzer(edm::ParameterSet const& pset) {
usesResource("CocoaAnalyzer");
}


void CocoaAnalyzer::beginJob() {}


void CocoaAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evts) {
ALIUtils::setDebugVerbosity(5);

Expand All @@ -55,7 +51,6 @@ void CocoaAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evts)
runCocoa();
}


/*
* This is used to create the ideal geometry description from the XMLs.
* Also get measurements from XMLs for simulation.
Expand Down Expand Up @@ -100,7 +95,6 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
worldInfo.angz_.quality_ = 0;
oaList_.opticalAlignments_.push_back(worldInfo);


// This gathers all the 'SpecPar' sections from the loaded XMLs.
// NB: Definition of a SpecPar section:
// It is a block in the XML file(s), containing paths to specific volumes,
Expand Down Expand Up @@ -128,7 +122,6 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
int nObjects = 0;
bool doCOCOA = myFilteredView.firstChild();


// Loop on all COCOA volumes from filtered view
while (doCOCOA) {
++nObjects;
Expand All @@ -140,7 +133,7 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
// Current volume
const dd4hep::PlacedVolume& myPlacedVolume = myFilteredView.volume();
const std::string& name = myPlacedVolume.name();
const std::string& nodePath = myFilteredView.path();
const std::string& nodePath = myFilteredView.path();
oaInfo.name_ = nodePath;

// Parent name
Expand All @@ -152,12 +145,11 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
<< std::endl;
}


// TRANSLATIONS

// A) GET TRANSLATIONS FROM DDETECTOR.
// Directly get translation from parent to child volume
const dd4hep::Position& transl = myPlacedVolume.position();
const dd4hep::Direction& transl = myPlacedVolume.position();

if (ALIUtils::debug >= 4) {
std::cout << "Local translation in cm = " << transl << std::endl;
Expand Down Expand Up @@ -198,7 +190,6 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
oaInfo.z_.quality_ = static_cast<int>(
getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath, "centre_Z_quality", 0));


// ROTATIONS

// A) GET ROTATIONS FROM DDETECTOR.
Expand Down Expand Up @@ -302,11 +293,8 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
std::cout << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters " << std::endl;
}

if (names.size() == dims.size()
&& dims.size() == values.size()
&& values.size() == errors.size()
&& errors.size() == quality.size()
) {
if (names.size() == dims.size() && dims.size() == values.size() && values.size() == errors.size() &&
errors.size() == quality.size()) {
for (size_t i = 0; i < names.size(); ++i) {
double dimFactor = 1.;
const std::string& type = dims.at(i);
Expand All @@ -330,7 +318,6 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
<< " not match! Did not add " << nObjects << " item to OpticalAlignments." << std::endl;
}


// MEASUREMENTS (FROM XMLS)
const std::vector<std::string>& measNames =
getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath, "meas_name");
Expand Down Expand Up @@ -365,14 +352,12 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
oaMeas.name_ = measNames.at(i);
oaMeas.type_ = measTypes.at(i);
oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_];
if (measParamNames.size() == measParamValues.size()
&& measParamValues.size() == measParamSigmas.size()
) {
if (measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size()) {
for (size_t i2 = 0; i2 < measParamNames[oaMeas.name_].size(); i2++) {
oaParam.name_ = measParamNames[oaMeas.name_].at(i2);
oaParam.value_ = measParamValues[oaMeas.name_].at(i2);
oaParam.error_ = measParamSigmas[oaMeas.name_].at(i2);
oaParam.quality_ = 2;
oaParam.quality_ = 2;
if (oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" ||
oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM") {
oaParam.dim_type_ = "length";
Expand Down Expand Up @@ -428,7 +413,6 @@ void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) {
}
}


/*
* This is used to get the OpticalAlignInfo from DB,
* which can be used to correct the OpticalAlignInfo from IdealGeometry.
Expand All @@ -444,17 +428,16 @@ std::vector<OpticalAlignInfo> CocoaAnalyzer::readCalibrationDB(const edm::EventS
const std::vector<OpticalAlignInfo>& infoFromDB = pObjs.product()->opticalAlignments_;

if (ALIUtils::debug >= 5) {
std::cout << "CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ "
<< infoFromDB.size() << std::endl;
std::cout << "CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ " << infoFromDB.size()
<< std::endl;
for (const auto& myInfoFromDB : infoFromDB) {
std::cout << "CocoaAnalyzer::readCalibrationDB: OpticalAlignInfo READ " << myInfoFromDB << std::endl;
}
}
}

return infoFromDB;
}


/*
* Correct the OpticalAlignInfo from IdealGeometry with values from DB.
*/
Expand Down Expand Up @@ -490,7 +473,7 @@ void CocoaAnalyzer::correctOptAlignments(std::vector<OpticalAlignInfo>& oaListCa
for (itoap1 = extraEntDB.begin(); itoap1 != extraEntDB.end(); ++itoap1) {
bool pFound = false;
//----- Look for the extra parameter in XML oaInfo that has the same name
std::string oaName = (*itoap1).name_;
std::string oaName = (*itoap1).name_;
for (itoap2 = extraEntXML->begin(); itoap2 != extraEntXML->end(); ++itoap2) {
if (oaName == itoap2->name_) {
correctOaParam(&(*itoap2), *itoap1);
Expand All @@ -513,19 +496,16 @@ void CocoaAnalyzer::correctOptAlignments(std::vector<OpticalAlignInfo>& oaListCa
}
}


OpticalAlignInfo* CocoaAnalyzer::findOpticalAlignInfoXML(const OpticalAlignInfo& oaInfo) {
OpticalAlignInfo* oaInfoXML = nullptr;
std::vector<OpticalAlignInfo>::iterator it;
for (it = oaList_.opticalAlignments_.begin(); it != oaList_.opticalAlignments_.end(); ++it) {
std::string oaName = oaInfo.name_;

for (auto& myOpticalAlignInfo : oaList_.opticalAlignments_) {
if (ALIUtils::debug >= 5) {
std::cout << "CocoaAnalyzer::findOpticalAlignInfoXML: looking for OAI " << (*it).name_ << " =? " << oaName
<< std::endl;
std::cout << "CocoaAnalyzer::findOpticalAlignInfoXML: looking for OAI " << myOpticalAlignInfo.name_ << " =? "
<< oaInfo.name_ << std::endl;
}
if ((*it).name_ == oaName) {
oaInfoXML = &(*it);
if (myOpticalAlignInfo.name_ == oaInfo.name_) {
oaInfoXML = &(myOpticalAlignInfo);
if (ALIUtils::debug >= 4) {
std::cout << "CocoaAnalyzer::findOpticalAlignInfoXML: OAI found " << oaInfoXML->name_ << std::endl;
}
Expand All @@ -536,7 +516,6 @@ OpticalAlignInfo* CocoaAnalyzer::findOpticalAlignInfoXML(const OpticalAlignInfo&
return oaInfoXML;
}


bool CocoaAnalyzer::correctOaParam(OpticalAlignParam* oaParamXML, const OpticalAlignParam& oaParamDB) {
if (ALIUtils::debug >= 4) {
std::cout << "CocoaAnalyzer::correctOaParam old value= " << oaParamXML->value_
Expand All @@ -562,7 +541,6 @@ bool CocoaAnalyzer::correctOaParam(OpticalAlignParam* oaParamXML, const OpticalA
return true;
}


/*
* Collect all information, do the fitting, and store results in DB.
*/
Expand Down Expand Up @@ -596,10 +574,8 @@ void CocoaAnalyzer::runCocoa() {
ALIFileOut& fileout = ALIFileOut::getInstance(Model::ReportFName());
fileout << "............ program ended OK" << std::endl;
}

}


/* 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.
Expand All @@ -621,7 +597,6 @@ std::vector<T> CocoaAnalyzer::getAllParameterValuesFromSpecParSections(const cms
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.
*/
Expand Down
18 changes: 6 additions & 12 deletions Alignment/CocoaFit/src/CocoaDBMgr.cc
Expand Up @@ -32,10 +32,8 @@

#include "CondCore/CondDB/interface/Serialization.h"


using namespace cms_units::operators;


CocoaDBMgr* CocoaDBMgr::instance = nullptr;

//----------------------------------------------------------------------
Expand Down Expand Up @@ -184,39 +182,36 @@ OpticalAlignInfo CocoaDBMgr::GetOptAlignInfoFromOptO(OpticalObject* opto) {
const std::vector<Entry*>& theCoordinateEntryVector = opto->CoordinateEntryList();
std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO starting coord " << std::endl;
if (theCoordinateEntryVector.size() == 6) {

const Entry* const translationX = theCoordinateEntryVector.at(0);
OpticalAlignParam translationXDataForDB;
translationXDataForDB.name_ = translationX->name();
translationXDataForDB.dim_type_ = translationX->type();
translationXDataForDB.value_ = centreLocal.x() * 1._m; // m in COCOA, cm in DB
translationXDataForDB.error_ = GetEntryError(translationX) * 1._m; // m in COCOA, cm in DB
translationXDataForDB.value_ = centreLocal.x() * 1._m; // m in COCOA, cm in DB
translationXDataForDB.error_ = GetEntryError(translationX) * 1._m; // m in COCOA, cm in DB
translationXDataForDB.quality_ = translationX->quality();
data.x_ = translationXDataForDB;

const Entry* const translationY = theCoordinateEntryVector.at(1);
OpticalAlignParam translationYDataForDB;
translationYDataForDB.name_ = translationY->name();
translationYDataForDB.dim_type_ = translationY->type();
translationYDataForDB.value_ = centreLocal.y() * 1._m; // m in COCOA, cm in DB
translationYDataForDB.error_ = GetEntryError(translationY) * 1._m; // m in COCOA, cm in DB
translationYDataForDB.value_ = centreLocal.y() * 1._m; // m in COCOA, cm in DB
translationYDataForDB.error_ = GetEntryError(translationY) * 1._m; // m in COCOA, cm in DB
translationYDataForDB.quality_ = translationY->quality();
data.y_ = translationYDataForDB;

const Entry* const translationZ = theCoordinateEntryVector.at(2);
OpticalAlignParam translationZDataForDB;
translationZDataForDB.name_ = translationZ->name();
translationZDataForDB.dim_type_ = translationZ->type();
translationZDataForDB.value_ = centreLocal.z() * 1._m; // m in COCOA, cm in DB
translationZDataForDB.error_ = GetEntryError(translationZ) * 1._m; // m in COCOA, cm in DB
translationZDataForDB.value_ = centreLocal.z() * 1._m; // m in COCOA, cm in DB
translationZDataForDB.error_ = GetEntryError(translationZ) * 1._m; // m in COCOA, cm in DB
translationZDataForDB.quality_ = translationZ->quality();
data.z_ = translationZDataForDB;


//----- angles in local coordinates
std::vector<double> anglocal = opto->getLocalRotationAngles(theCoordinateEntryVector);
if (anglocal.size() == 3) {

const Entry* const rotationX = theCoordinateEntryVector.at(3);
OpticalAlignParam rotationXDataForDB;
rotationXDataForDB.name_ = rotationX->name();
Expand Down Expand Up @@ -246,7 +241,6 @@ OpticalAlignInfo CocoaDBMgr::GetOptAlignInfoFromOptO(OpticalObject* opto) {
}
}


const std::vector<Entry*>& theExtraEntryVector = opto->ExtraEntryList();
std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO starting entry " << std::endl;

Expand Down
13 changes: 3 additions & 10 deletions Alignment/CocoaUtilities/src/ALIUtils.cc
Expand Up @@ -778,16 +778,9 @@ int ALIUtils::checkMatrixEquations(double angleX, double angleY, double angleZ,
double rotzz = cx * cy;

int matrixElemBad = 0;
if ( !eq2ang(rot.xx(), rotxx)
|| !eq2ang(rot.xy(), rotxy)
|| !eq2ang(rot.xz(), rotxz)
|| !eq2ang(rot.yx(), rotyx)
|| !eq2ang(rot.yy(), rotyy)
|| !eq2ang(rot.yz(), rotyz)
|| !eq2ang(rot.zx(), rotzx)
|| !eq2ang(rot.zy(), rotzy)
|| !eq2ang(rot.zz(), rotzz)
) {
if (!eq2ang(rot.xx(), rotxx) || !eq2ang(rot.xy(), rotxy) || !eq2ang(rot.xz(), rotxz) || !eq2ang(rot.yx(), rotyx) ||
!eq2ang(rot.yy(), rotyy) || !eq2ang(rot.yz(), rotyz) || !eq2ang(rot.zx(), rotzx) || !eq2ang(rot.zy(), rotzy) ||
!eq2ang(rot.zz(), rotzz)) {
matrixElemBad++;
}

Expand Down

0 comments on commit 72c4f77

Please sign in to comment.