From 6f6b9688fb93cecc19cc7280f120a1a2c597a5d7 Mon Sep 17 00:00:00 2001 From: Gabrielle Hugo Date: Thu, 18 Jun 2020 11:46:44 +0200 Subject: [PATCH 1/2] Revert "Remove dependency on DD". This old legacy CocoaAnalyzer is NOT my code at all. This reverts commit 8212718c2fd65a085f6fe23db30b693dc7e2fc38. --- Alignment/CocoaApplication/BuildFile.xml | 16 + .../interface/CocoaAnalyzer.h | 78 ++ .../CocoaApplication/src/CocoaAnalyzer.cc | 691 ++++++++++++++++++ Alignment/CocoaApplication/src/SealModule.cc | 4 + 4 files changed, 789 insertions(+) create mode 100644 Alignment/CocoaApplication/BuildFile.xml create mode 100644 Alignment/CocoaApplication/interface/CocoaAnalyzer.h create mode 100644 Alignment/CocoaApplication/src/CocoaAnalyzer.cc create mode 100644 Alignment/CocoaApplication/src/SealModule.cc diff --git a/Alignment/CocoaApplication/BuildFile.xml b/Alignment/CocoaApplication/BuildFile.xml new file mode 100644 index 0000000000000..2a5b475a99bea --- /dev/null +++ b/Alignment/CocoaApplication/BuildFile.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/Alignment/CocoaApplication/interface/CocoaAnalyzer.h b/Alignment/CocoaApplication/interface/CocoaAnalyzer.h new file mode 100644 index 0000000000000..fd7e384256e92 --- /dev/null +++ b/Alignment/CocoaApplication/interface/CocoaAnalyzer.h @@ -0,0 +1,78 @@ +#ifndef CocoaAnalyser_HH +#define CocoaAnalyser_HH +//-*- C++ -*- +// +// Package: Alignment/CocoaApplication +// Class: CocoaAnalyzer +// +/* + + Description: test access to the OpticalAlignMeasurements via OpticalAlignMeasurementsGeneratedSource + This also should demonstrate access to a geometry via the XMLIdealGeometryESSource + for use in THE COCOA analyzer. + + Implementation: + Iterate over retrieved alignments. +*/ +// + +#include +#include +#include +#include +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "DetectorDescription/Core/interface/DDPosData.h" + +class Event; +class EventSetup; +class Entry; +//#include "FWCore/Framework/interface/EventSetup.h" + +#include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h" +#include "CondFormats/OptAlignObjects/interface/OpticalAlignInfo.h" +#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h" + +class DDFilteredView; +class DDCompactView; +class DDSpecifics; +class OpticalObject; + + +class CocoaAnalyzer : public edm::one::EDAnalyzer +{ + public: + + explicit CocoaAnalyzer(edm::ParameterSet const& p); + explicit CocoaAnalyzer(int i) { } + virtual ~ CocoaAnalyzer() { } + + virtual void beginJob() override; + virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override; + // see note on endJob() at the bottom of the file. + // virtual void endJob() ; + + private: + void ReadXMLFile( const edm::EventSetup& evts ); + std::vector ReadCalibrationDB( const edm::EventSetup& evts ); + + void CorrectOptAlignments( std::vector& oaListCalib ); + OpticalAlignInfo* FindOpticalAlignInfoXML( const OpticalAlignInfo& oaInfo ); + bool CorrectOaParam( OpticalAlignParam* oaParamXML, const OpticalAlignParam& oaParamDB ); + + void RunCocoa(); + + OpticalAlignInfo GetOptAlignInfoFromOptO( OpticalObject* opto ); + double myFetchDbl(const DDsvalues_type& dvst, + const std::string& spName, + const size_t& vecInd ); + std::string myFetchString(const DDsvalues_type& dvst, + const std::string& spName, + const size_t& vecInd ); + + private: + OpticalAlignments oaList_; + OpticalAlignMeasurements measList_; + std::string theCocoaDaqRootFileName; +}; + +#endif diff --git a/Alignment/CocoaApplication/src/CocoaAnalyzer.cc b/Alignment/CocoaApplication/src/CocoaAnalyzer.cc new file mode 100644 index 0000000000000..87d872d1d8867 --- /dev/null +++ b/Alignment/CocoaApplication/src/CocoaAnalyzer.cc @@ -0,0 +1,691 @@ +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESTransientHandle.h" + +#include "Alignment/CocoaApplication/interface/CocoaAnalyzer.h" +#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurementInfo.h" +#include "CondFormats/DataRecord/interface/OpticalAlignmentsRcd.h" +#include "DetectorDescription/Core/interface/DDFilteredView.h" +#include "DetectorDescription/Core/interface/DDCompactView.h" +#include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" + +#include "Alignment/CocoaUtilities/interface/ALIUtils.h" +#include "Alignment/CocoaModel/interface/Model.h" +#include "Alignment/CocoaFit/interface/Fit.h" +#include "Alignment/CocoaModel/interface/Entry.h" +#include "Alignment/CocoaUtilities/interface/ALIFileOut.h" +#include "Alignment/CocoaModel/interface/CocoaDaqReaderRoot.h" +#include "Alignment/CocoaModel/interface/OpticalObject.h" +#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h" +#include "Alignment/CocoaFit/interface/CocoaDBMgr.h" + +//---------------------------------------------------------------------- +CocoaAnalyzer::CocoaAnalyzer(edm::ParameterSet const& pset) +{ + theCocoaDaqRootFileName = pset.getParameter< std::string >("cocoaDaqRootFile"); + + int maxEvents = pset.getParameter< int32_t >("maxEvents"); + GlobalOptionMgr::getInstance()->setDefaultGlobalOptions(); + GlobalOptionMgr::getInstance()->setGlobalOption("maxEvents",maxEvents); + GlobalOptionMgr::getInstance()->setGlobalOption("writeDBAlign",1); + GlobalOptionMgr::getInstance()->setGlobalOption("writeDBOptAlign",1); + usesResource("CocoaAnalyzer"); +} + +//---------------------------------------------------------------------- +void CocoaAnalyzer::beginJob() +{ +} + + +//------------------------------------------------------------------------ +void CocoaAnalyzer::RunCocoa() +{ + if(ALIUtils::debug >= 3) { + std::cout << std::endl << "$$$ CocoaAnalyzer::RunCocoa: " << std::endl; + } + //-ALIFileIn fin; + //- GlobalOptionMgr::getInstance()->setGlobalOption("debug_verbose",5, fin ); + + //---------- Build the Model out of the system description text file + Model& model = Model::getInstance(); + + model.BuildSystemDescriptionFromOA( oaList_ ); + + if(ALIUtils::debug >= 3) { + std::cout << "$$ CocoaAnalyzer::RunCocoa: geometry built " << std::endl; + } + + model.BuildMeasurementsFromOA( measList_ ); + + if(ALIUtils::debug >= 3) { + std::cout << "$$ CocoaAnalyzer::RunCocoa: measurements built " << std::endl; + } + + Fit::getInstance(); + + Fit::startFit(); + + if(ALIUtils::debug >= 0) std::cout << "............ program ended OK" << std::endl; + if( ALIUtils::report >=1 ) { + ALIFileOut& fileout = ALIFileOut::getInstance( Model::ReportFName() ); + fileout << "............ program ended OK" << std::endl; + } + +} // end of ::beginJob + + +//----------------------------------------------------------------------- +void CocoaAnalyzer::ReadXMLFile( const edm::EventSetup& evts ) +{ + + // STEP ONE: Initial COCOA objects will be built from a DDL geometry + // description. + + edm::ESTransientHandle cpv; + evts.get().get(cpv); + + if(ALIUtils::debug >= 3) { + std::cout << std::endl << "$$$ CocoaAnalyzer::ReadXML: root object= " << cpv->root() << std::endl; + } + + //Build OpticalAlignInfo "system" + const DDLogicalPart lv = cpv->root(); + + OpticalAlignInfo oaInfo; + oaInfo.ID_ = 0; + //--- substract file name to object name + oaInfo.name_ = lv.name().name(); + oaInfo.parentName_ = ""; + oaInfo.x_.quality_ = 0; + oaInfo.x_.value_ = 0.; + oaInfo.x_.error_ = 0.; + oaInfo.x_.quality_ = 0; + oaInfo.y_.value_ = 0.; + oaInfo.y_.error_ = 0.; + oaInfo.y_.quality_ = 0; + oaInfo.z_.value_ = 0.; + oaInfo.z_.error_ = 0.; + oaInfo.z_.quality_ = 0; + oaInfo.angx_.value_ = 0.; + oaInfo.angx_.error_ = 0.; + oaInfo.angx_.quality_ = 0; + oaInfo.angy_.value_ = 0.; + oaInfo.angy_.error_ = 0.; + oaInfo.angy_.quality_ = 0; + oaInfo.angz_.value_ = 0.; + oaInfo.angz_.error_ = 0.; + oaInfo.angz_.quality_ = 0; + + oaInfo.type_ = "system"; + + oaList_.opticalAlignments_.push_back(oaInfo); + oaInfo.clear(); + + // Example of traversing the whole optical alignment geometry. + // At each node we get specpars as variables and use them in + // constructing COCOA objects. + // It stores these objects in a private data member, opt + std::string attribute = "COCOA"; + std::string value = "COCOA"; + + // get all parts labelled with COCOA using a SpecPar + DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)}; + DDFilteredView fv(*cpv, filter); + bool doCOCOA = fv.firstChild(); + + // Loop on parts + int nObjects=0; + OpticalAlignParam oaParam; + OpticalAlignMeasurementInfo oaMeas; + + while ( doCOCOA ){ + ++nObjects; + // oaInfo.ID_ = nObjects; + const DDsvalues_type params(fv.mergedSpecifics()); + + const DDLogicalPart lv = fv.logicalPart(); + if(ALIUtils::debug >= 4) { + std::cout << " CocoaAnalyzer::ReadXML reading object " << lv.name() << std::endl; + } + + std::vector history = fv.geoHistory(); + oaInfo.parentName_ = ""; + size_t ii; + for(ii = 0; ii < history.size()-1;ii++ ) { + if( ii != 0 ) oaInfo.parentName_ += "/"; + std::string name = history[ii].logicalPart().name().name(); + oaInfo.parentName_ += name; + // oaInfo.parentName_ = (fv.geoHistory()[fv.geoHistory().size()-2]).logicalPart().name(); +// icol = oaInfo.parentName_.find(":"); + // oaInfo.parentName_ = oaInfo.parentName_.substr(icol+1,oaInfo.parentName_.length()); + } + + //--- build object name (= parent name + object name) + std::string name = history[ii].logicalPart().name().name(); + //--- substract file name to object name + oaInfo.name_ = oaInfo.parentName_ + "/" + name; + if(ALIUtils::debug >= 5) { + std::cout << " @@ Name built= " << oaInfo.name_ << " short_name= " << name << " parent= " << oaInfo.parentName_ << std::endl; + } + //----- Read centre and angles + oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0)); + DDTranslation transl = (fv.translation()); + DDRotationMatrix rot = (fv.rotation()); + DDExpandedNode parent = fv.geoHistory()[ fv.geoHistory().size()-2 ]; + const DDTranslation& parentTransl = parent.absTranslation(); + const DDRotationMatrix& parentRot = parent.absRotation(); + transl = parentRot.Inverse()*(transl - parentTransl ); + rot = parentRot.Inverse()*rot; + rot = rot.Inverse(); //DDL uses opposite convention than COCOA + /* if(ALIUtils::debug >= 4) { + ALIUtils::dumprm( rot, "local rotation "); + ALIUtils::dump3v( transl, "local translation"); + } */ + + oaInfo.x_.name_ = "X"; + oaInfo.x_.dim_type_ = "centre"; + oaInfo.x_.value_ = transl.x()*0.001; // CLHEP units are mm, COCOA are m + oaInfo.x_.error_ = myFetchDbl(params, "centre_X_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m + oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0)); + + oaInfo.y_.name_ = "Y"; + oaInfo.y_.dim_type_ = "centre"; + oaInfo.y_.value_ = transl.y()*0.001; // CLHEP units are mm, COCOA are m + oaInfo.y_.error_ = myFetchDbl(params, "centre_Y_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m + oaInfo.y_.quality_ = int (myFetchDbl(params, "centre_Y_quality", 0)); + + oaInfo.z_.name_ = "Z"; + oaInfo.z_.dim_type_ = "centre"; + oaInfo.z_.value_ = transl.z()*0.001; // CLHEP units are mm, COCOA are m + oaInfo.z_.error_ = myFetchDbl(params, "centre_Z_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m + oaInfo.z_.quality_ = int (myFetchDbl(params, "centre_Z_quality", 0)); + + //---- DDD convention is to use the inverse matrix, COCOA is the direct one!!! + //---- convert it to CLHEP::Matrix + double xx,xy,xz,yx,yy,yz,zx,zy,zz; + rot.GetComponents (xx, xy, xz, + yx, yy, yz, + zx, zy, zz); + CLHEP::Hep3Vector colX(xx,xy,xz); + CLHEP::Hep3Vector colY(yx,yy,yz); + CLHEP::Hep3Vector colZ(zx,zy,zz); + CLHEP::HepRotation rotclhep( colX, colY, colZ ); + std::vector angles = ALIUtils::getRotationAnglesFromMatrix( rotclhep,0., 0., 0. ); + + oaInfo.angx_.name_ = "X"; + oaInfo.angx_.dim_type_ = "angles"; + //- oaInfo.angx_.value_ = angles[0]; + oaInfo.angx_.value_ = myFetchDbl(params, "angles_X_value", 0); + oaInfo.angx_.error_ = myFetchDbl(params, "angles_X_sigma", 0); + oaInfo.angx_.quality_ = int (myFetchDbl(params, "angles_X_quality", 0)); + + oaInfo.angy_.name_ = "Y"; + oaInfo.angy_.dim_type_ = "angles"; + //- oaInfo.angy_.value_ = angles[1]; + oaInfo.angy_.value_ = myFetchDbl(params, "angles_Y_value", 0); + oaInfo.angy_.error_ = myFetchDbl(params, "angles_Y_sigma", 0); + oaInfo.angy_.quality_ = int (myFetchDbl(params, "angles_Y_quality", 0)); + + oaInfo.angz_.name_ = "Z"; + oaInfo.angz_.dim_type_ = "angles"; + // oaInfo.angz_.value_ = angles[2]; + oaInfo.angz_.value_ = myFetchDbl(params, "angles_Z_value", 0); + oaInfo.angz_.error_ = myFetchDbl(params, "angles_Z_sigma", 0); + oaInfo.angz_.quality_ = int (myFetchDbl(params, "angles_Z_quality", 0)); + + oaInfo.type_ = myFetchString(params, "cocoa_type", 0); + + oaInfo.ID_ = int(myFetchDbl(params, "cmssw_ID", 0)); + + if(ALIUtils::debug >= 4) { + std::cout << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read " << std::endl; + } + + if( fabs( oaInfo.angx_.value_ - angles[0] ) > 1.E-9 || + fabs( oaInfo.angy_.value_ - angles[1] ) > 1.E-9 || + fabs( oaInfo.angz_.value_ - angles[2] ) > 1.E-9 ) { + std::cerr << " WRONG ANGLE IN OBJECT " << oaInfo.name_<< + oaInfo.angx_.value_ << " =? " << angles[0] << + oaInfo.angy_.value_ << " =? " << angles[1] << + oaInfo.angz_.value_ << " =? " << angles[2] << std::endl; + } + + //----- Read extra entries and measurements + const std::vector params2(fv.specifics()); + std::vector::const_iterator spit = params2.begin(); + std::vector::const_iterator endspit = params2.end(); + //--- extra entries variables + std::vector names, dims; + std::vector values, errors, quality; + //--- measurements variables + std::vector measNames; + std::vector measTypes; + std::map > measObjectNames; + std::map > measParamNames; + std::map > measParamValues; + std::map > measParamSigmas; + std::map > measIsSimulatedValue; + + for ( ; spit != endspit; ++spit ) { + DDsvalues_type::const_iterator sit = (**spit).begin(); + DDsvalues_type::const_iterator endsit = (**spit).end(); + for ( ; sit != endsit; ++sit ) { + if (sit->second.name() == "extra_entry") { + names = sit->second.strings(); + } else if (sit->second.name() == "dimType") { + dims = sit->second.strings(); + } else if (sit->second.name() == "value") { + values = sit->second.doubles(); + } else if (sit->second.name() == "sigma") { + errors = sit->second.doubles(); + } else if (sit->second.name() == "quality") { + quality = sit->second.doubles(); + + } else if (sit->second.name() == "meas_name") { + //- std::cout << " meas_name found " << std::endl; + measNames = sit->second.strings(); + } else if (sit->second.name() == "meas_type") { + //- std::cout << " meas_type found " << std::endl; + measTypes = sit->second.strings(); + } + + } + } + + //---- loop again to look for the measurement object names, that have the meas name in the SpecPar title + // + // + + std::vector::iterator vsite; + for ( spit = params2.begin(); spit != params2.end(); ++spit ) { + //- std::cout << "loop vector DDsvalues " << std::endl; + DDsvalues_type::const_iterator sit = (**spit).begin(); + DDsvalues_type::const_iterator endsit = (**spit).end(); + for ( ; sit != endsit; ++sit ) { + for( vsite = measNames.begin(); vsite != measNames.end(); ++vsite ){ + //- std::cout << "looping measObjectNames " << *vsite << std::endl; + if (sit->second.name() == "meas_object_name_"+(*vsite)) { + measObjectNames[*vsite] = sit->second.strings(); + }else if (sit->second.name() == "meas_value_name_"+(*vsite)) { + measParamNames[*vsite] = sit->second.strings(); + }else if (sit->second.name() == "meas_value_"+(*vsite)) { + measParamValues[*vsite] = sit->second.doubles(); + }else if (sit->second.name() == "meas_sigma_"+(*vsite)) { + measParamSigmas[*vsite] = sit->second.doubles(); + }else if (sit->second.name() == "meas_is_simulated_value_"+(*vsite)) { + measIsSimulatedValue[*vsite] = sit->second.doubles(); // this is not in OptAlignParam info + if(ALIUtils::debug >= 5) { + std::cout << *vsite << " setting issimu " << measIsSimulatedValue[*vsite][0] << std::endl; + } + } + if(ALIUtils::debug >= 5) { + std::cout << "CocoaAnalyser: looped measObjectNames " << "meas_object_name_"+(*vsite) << " n obj " << measObjectNames[*vsite].size() << std::endl; + } + + } + + } + } + + if(ALIUtils::debug >= 4) { + std::cout << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters " << std::endl; + } + //--- Fill extra entries with read parameters + if ( names.size() == dims.size() && dims.size() == values.size() + && values.size() == errors.size() && errors.size() == quality.size() ) { + for ( size_t ind = 0; ind < names.size(); ++ind ) { + double dimFactor = 1.; + std::string type = oaParam.dimType(); + if( type == "centre" || type == "length" ) { + dimFactor = 0.001; // in XML it is in mm + }else if ( type == "angles" || type == "angle" || type == "nodim" ){ + dimFactor = 1.; + } + oaParam.value_ = values[ind]*dimFactor; + oaParam.error_ = errors[ind]*dimFactor; + oaParam.quality_ = int (quality[ind]); + oaParam.name_ = names[ind]; + oaParam.dim_type_ = dims[ind]; + oaInfo.extraEntries_.push_back (oaParam); + oaParam.clear(); + } + + //t std::cout << names.size() << " OBJECT " << oaInfo.name_ << " extra entries read " << oaInfo << std::endl; + + oaList_.opticalAlignments_.push_back(oaInfo); + } else { + std::cout << "WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do" + << " not match! Did not add " << nObjects << " item to OpticalAlignments." + << std::endl; + } + + if(ALIUtils::debug >= 4) { + std::cout << " CocoaAnalyzer::ReadXML: Fill measurements with read parameters " << std::endl; + } + //--- Fill measurements with read parameters + if ( measNames.size() == measTypes.size() ) { + for ( size_t ind = 0; ind < measNames.size(); ++ind ) { + oaMeas.ID_ = ind; + oaMeas.name_ = measNames[ind]; + oaMeas.type_ = measTypes[ind]; + oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_]; + if( measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size() ) { + for( size_t ind2 = 0; ind2 < measParamNames[oaMeas.name_].size(); ind2++ ){ + oaParam.name_ = measParamNames[oaMeas.name_][ind2]; + oaParam.value_ = measParamValues[oaMeas.name_][ind2]; + oaParam.error_ = measParamSigmas[oaMeas.name_][ind2]; + if( oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" || oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM" ) { + oaParam.dim_type_ = "length"; + } else if( oaMeas.type_ == "TILTMETER" ) { + oaParam.dim_type_ = "angle"; + } else { + std::cerr << "CocoaAnalyzer::ReadXMLFile. Invalid measurement type: " << oaMeas.type_ << std::endl; + std::exception(); + } + + oaMeas.values_.push_back( oaParam ); + oaMeas.isSimulatedValue_.push_back( measIsSimulatedValue[oaMeas.name_][ind2] ); + if(ALIUtils::debug >= 5) { + std::cout << oaMeas.name_ << " copying issimu " << oaMeas.isSimulatedValue_[oaMeas.isSimulatedValue_.size()-1] << " = " << measIsSimulatedValue[oaMeas.name_][ind2] << std::endl; + //- std::cout << ind2 << " adding meas value " << oaParam << std::endl; + } + oaParam.clear(); + } + } else { + if(ALIUtils::debug >= 2) { + std::cout << "WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do" + << " not match! for measurement " << oaMeas.name_ << " !Did not fill parameters for this measurement " << std::endl; + } + } + measList_.oaMeasurements_.push_back (oaMeas); + if(ALIUtils::debug >= 5) { + std::cout << "CocoaAnalyser: MEASUREMENT " << oaMeas.name_ << " extra entries read " << oaMeas << std::endl; + } + oaMeas.clear(); + } + + } else { + if(ALIUtils::debug >= 2) { + std::cout << "WARNING FOR NOW: sizes of measurements (names, types do" + << " not match! Did not add " << nObjects << " item to XXXMeasurements" + << std::endl; + } + } + +// std::cout << "sizes are values=" << values.size(); +// std::cout << " sigma(errors)=" << errors.size(); +// std::cout << " quality=" << quality.size(); +// std::cout << " names=" << names.size(); +// std::cout << " dimType=" << dims.size() << std::endl; + oaInfo.clear(); + doCOCOA = fv.next(); // go to next part + } // while (doCOCOA) + if(ALIUtils::debug >= 3) { + std::cout << "CocoaAnalyzer::ReadXML: Finished building " << nObjects+1 << " OpticalAlignInfo objects" << " and " << measList_.oaMeasurements_.size() << " OpticalAlignMeasurementInfo objects " << std::endl; + } + if(ALIUtils::debug >= 5) { + std::cout << " @@@@@@ OpticalAlignments " << oaList_ << std::endl; + std::cout << " @@@@@@ OpticalMeasurements " << measList_ << std::endl; + } + +} + +//------------------------------------------------------------------------ +std::vector CocoaAnalyzer::ReadCalibrationDB( const edm::EventSetup& evts ) +{ + if(ALIUtils::debug >= 3) { + std::cout<< std::endl <<"$$$ CocoaAnalyzer::ReadCalibrationDB: " << std::endl; + } + + using namespace edm::eventsetup; + edm::ESHandle pObjs; + evts.get().get(pObjs); + const OpticalAlignments* dbObj = pObjs.product(); + + if(ALIUtils::debug >= 5) { + std::vector::const_iterator it; + for( it=dbObj->opticalAlignments_.begin();it!=dbObj->opticalAlignments_.end(); ++it ){ + std::cout<<"CocoaAnalyzer::ReadCalibrationDB: OpticalAlignInfo READ "<< *it << std::endl; + } + } + + if(ALIUtils::debug >= 4) { + std::cout<<"CocoaAnalyzer::ReadCalibrationDB: Number of OpticalAlignInfo READ "<< dbObj->opticalAlignments_.size() << std::endl; + } + + return dbObj->opticalAlignments_; +} + + +//------------------------------------------------------------------------ +void CocoaAnalyzer::CorrectOptAlignments( std::vector& oaListCalib ) +{ + if(ALIUtils::debug >= 3) { + std::cout<< std::endl<< "$$$ CocoaAnalyzer::CorrectOptAlignments: " << std::endl; + } + + std::vector::const_iterator it; + for( it=oaListCalib.begin();it!=oaListCalib.end(); ++it ){ + OpticalAlignInfo oaInfoDB = *it; + OpticalAlignInfo* oaInfoXML = FindOpticalAlignInfoXML( oaInfoDB ); + std::cerr << "error " << (*it).name_ << std::endl; + if( oaInfoXML == nullptr ) { + if(ALIUtils::debug >= 2) { + std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: OpticalAlignInfo read from DB is not present in XML "<< *it << std::endl; + } + } else { + //------ Correct info + if(ALIUtils::debug >= 5) { + std::cout << "CocoaAnalyzer::CorrectOptAlignments: correcting data from DB info " << std::endl; + } + CorrectOaParam( &oaInfoXML->x_, oaInfoDB.x_ ); + CorrectOaParam( &oaInfoXML->y_, oaInfoDB.y_ ); + CorrectOaParam( &oaInfoXML->z_, oaInfoDB.z_ ); + CorrectOaParam( &oaInfoXML->angx_, oaInfoDB.angx_ ); + CorrectOaParam( &oaInfoXML->angy_, oaInfoDB.angy_ ); + CorrectOaParam( &oaInfoXML->angz_, oaInfoDB.angz_ ); + std::vector::iterator itoap1, itoap2; + std::vector extraEntDB = oaInfoDB.extraEntries_; + std::vector* extraEntXML = &(oaInfoXML->extraEntries_); + 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_.substr( 1, (*itoap1).name_.size()-2 ); + for( itoap2 = extraEntXML->begin(); itoap2 != extraEntXML->end(); ++itoap2 ){ + if( oaName == (*itoap2).name_ ) { + CorrectOaParam( &(*itoap2), *itoap1 ); + pFound = true; + break; + } + } + if( !pFound && oaName != "None" ) { + if(ALIUtils::debug >= 2) { + std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: extra entry read from DB is not present in XML "<< *itoap1 << " in object " << *it << std::endl; + } + } + + } + if(ALIUtils::debug >= 5) { + std::cout << "CocoaAnalyzer::CorrectOptAlignments: corrected OpticalAlingInfo " << oaList_ << std::endl; + } + + } + } + +} + + +//------------------------------------------------------------------------ +OpticalAlignInfo* CocoaAnalyzer::FindOpticalAlignInfoXML( const OpticalAlignInfo& oaInfo ) +{ + OpticalAlignInfo* oaInfoXML = nullptr; + std::vector::iterator it; + for( it=oaList_.opticalAlignments_.begin();it!=oaList_.opticalAlignments_.end(); ++it ){ + std::string oaName = oaInfo.name_.substr( 1, oaInfo.name_.size()-2 ); + + if(ALIUtils::debug >= 5) { + std::cout << "CocoaAnalyzer::FindOpticalAlignInfoXML: looking for OAI " << (*it).name_ << " =? " << oaName << std::endl; + } + if( (*it).name_ == oaName ) { + oaInfoXML = &(*it); + if(ALIUtils::debug >= 4) { + std::cout << "CocoaAnalyzer::FindOpticalAlignInfoXML: OAI found " << oaInfoXML->name_ << std::endl; + } + break; + } + } + + return oaInfoXML; +} + + +//------------------------------------------------------------------------ +bool CocoaAnalyzer::CorrectOaParam( OpticalAlignParam* oaParamXML, const OpticalAlignParam& oaParamDB ) +{ + if(ALIUtils::debug >= 4) { + std::cout << "CocoaAnalyzer::CorrectOaParam old value= " << oaParamXML->value_ << " new value= " << oaParamDB.value_ << std::endl; + } + if( oaParamDB.value_ == -9.999E9 ) return false; + + double dimFactor = 1.; + //loop for an Entry with equal type to entries to know which is the + std::string type = oaParamDB.dimType(); + if( type == "centre" || type == "length" ) { + dimFactor = 0.01; // in DB it is in cm + }else if ( type == "angles" || type == "angle" || type == "nodim" ){ + dimFactor = 1.; + }else { + std::cerr << "!!! COCOA programming error: inform responsible: incorrect OpticalAlignParam type = " << type << std::endl; + std::exception(); + } + + oaParamXML->value_ = oaParamDB.value_*dimFactor; + + return true; + +} + + +//-#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h" +//-#include "Alignment/CocoaUtilities/interface/ALIFileIn.h" + +//----------------------------------------------------------------------- +void CocoaAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evts) +{ + ALIUtils::setDebugVerbosity( 5 ); + + ReadXMLFile( evts ); + + std::vector oaListCalib = ReadCalibrationDB( evts ); + + CorrectOptAlignments( oaListCalib ); + + new CocoaDaqReaderRoot( theCocoaDaqRootFileName ); + + /*- + int nEvents = daqReader->GetNEvents(); + for( int ii = 0; ii < nEvents; ii++) { + if( ! daqReader->ReadEvent( ii ) ) break; + } + */ + + RunCocoa(); + + // std::cout << "!!!! NOT DumpCocoaResults() " << std::endl; + + // CocoaDBMgr::getInstance()->DumpCocoaResults(); + + return; + + + // using namespace edm::eventsetup; + // std::cout <<" I AM IN RUN NUMBER "< oaESHandle; +// context.get().get(oaESHandle); + +// // This assumes they ALL come in together. This may not be +// // the "real" case. One could envision different objects coming +// // in and we would get by label each one (type). + +// std::cout << "========== eventSetup data changes with IOV =========" << std::endl; +// std::cout << *oaESHandle << std::endl; +// //============== COCOA WORK! +// // calibrated values should be used to "correct" the ones read in during beginJob +// //============== + +// // +// // to see how to iterate over the OpticalAlignments, please +// // refer to the << operator of OpticalAlignments, OpticalAlignInfo +// // and OpticalAlignParam. +// // const OpticalAlignments* myoa=oa.product(); + +// // STEP 3: +// // This retrieves the Measurements +// // for each event, a new set of measurements is available. +// edm::Handle measHandle; +// evt.getByLabel("OptAlignGeneratedSource", measHandle); + + +// std::cout << "========== event data product changes with every event =========" << std::endl; +// std::cout << *measHandle << std::endl; + + //============== COCOA WORK! + // Each set of optical alignment measurements can be used + // in whatever type of analysis COCOA does. + //============== + +} //end of ::analyze() + +// STEP 4: one could use ::endJob() to write out the OpticalAlignments +// generated by the analysis. Example code of writing is in +// CondFormats/Alignment/test/testOptAlignWriter.cc + + +//----------------------------------------------------------------------- +double CocoaAnalyzer::myFetchDbl(const DDsvalues_type& dvst, + const std::string& spName, + const size_t& vecInd ) { + DDValue val(spName, 0.0); + if (DDfetch(&dvst,val)) { + if ( val.doubles().size() > vecInd ) { + // std::cout << "about to return: " << val.doubles()[vecInd] << std::endl; + return val.doubles()[vecInd]; + } else { + std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << std::endl; + } + } + return 0.0; +} + +//----------------------------------------------------------------------- +std::string CocoaAnalyzer::myFetchString(const DDsvalues_type& dvst, + const std::string& spName, + const size_t& vecInd ) { + DDValue val(spName, 0.0); + if (DDfetch(&dvst,val)) { + if ( val.strings().size() > vecInd ) { + // std::cout << "about to return: " << val.doubles()[vecInd] << std::endl; + return val.strings()[vecInd]; + } else { + std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << std::endl; + } + } + return ""; +} + diff --git a/Alignment/CocoaApplication/src/SealModule.cc b/Alignment/CocoaApplication/src/SealModule.cc new file mode 100644 index 0000000000000..6fabe6d7c6341 --- /dev/null +++ b/Alignment/CocoaApplication/src/SealModule.cc @@ -0,0 +1,4 @@ +#include "FWCore/Framework/interface/MakerMacros.h" +#include "Alignment/CocoaApplication/interface/CocoaAnalyzer.h" + +DEFINE_FWK_MODULE(CocoaAnalyzer); From 7af821c9afe9537ac8afa5e05e432404c98416f5 Mon Sep 17 00:00:00 2001 From: Gabrielle Hugo Date: Mon, 22 Jun 2020 15:04:28 +0200 Subject: [PATCH 2/2] Port COCOA to DD4hep + Regenerate COCOA input files + Add documentation + 3 bug fixes in legacy COCOA, significantly affecting optical alignment results (Inverse rotation in IdealGeometry from XML + Bug in extra alignment parameters + Conversion error in results written to DB). --- Alignment/CocoaApplication/BuildFile.xml | 13 +- Alignment/CocoaApplication/README.md | 47 + .../interface/CocoaAnalyzer.h | 89 +- .../CocoaApplication/src/CocoaAnalyzer.cc | 1119 ++++++++--------- .../test/OpticalAlignments.db | Bin 54272 -> 69632 bytes .../test/cmsCocoaTable2DWithMirror.xml | 11 + .../test/cocoaAnalyzer_cfg.py | 84 ++ .../test/table2DWithMirror.xml | 593 ++++----- Alignment/CocoaFit/src/CocoaDBMgr.cc | 127 +- Alignment/CocoaUtilities/interface/ALIUtils.h | 4 +- Alignment/CocoaUtilities/src/ALIUtils.cc | 53 +- .../CocoaUtilities/src/GlobalOptionMgr.cc | 2 +- 12 files changed, 1080 insertions(+), 1062 deletions(-) create mode 100644 Alignment/CocoaApplication/README.md create mode 100644 Alignment/CocoaApplication/test/cmsCocoaTable2DWithMirror.xml create mode 100644 Alignment/CocoaApplication/test/cocoaAnalyzer_cfg.py diff --git a/Alignment/CocoaApplication/BuildFile.xml b/Alignment/CocoaApplication/BuildFile.xml index 2a5b475a99bea..833bad49ac850 100644 --- a/Alignment/CocoaApplication/BuildFile.xml +++ b/Alignment/CocoaApplication/BuildFile.xml @@ -1,16 +1,7 @@ - - - - - - - - - + - - + diff --git a/Alignment/CocoaApplication/README.md b/Alignment/CocoaApplication/README.md new file mode 100644 index 0000000000000..101cf9a5233ec --- /dev/null +++ b/Alignment/CocoaApplication/README.md @@ -0,0 +1,47 @@ +# **CMS Object-oriented Code for Optical Alignment** + + +## General COCOA documentation + +General documentation is at [1]. +COCOA website is at [2]. +Notably, a user guide can be found at [3]. + +[1] https://cds.cern.ch/record/1047121/files/p193.pdf +[2] http://cmsdoc.cern.ch/cms/MUON/alignment/software/COCOA/doc/cocoa.html +[3] http://cmsdoc.cern.ch/cms/MUON/alignment/software/COCOA/doc/tex/users_guide.ps + + + +## Run COCOA +This shows how to: +- Run the COCOA simulation of an optical alignment system (described in .txt or XML format, with adjustments from DB description); +- Run the least-squared fit on the alignment system; +- Store results back into DB. + +### Input XML file +An XML file describing the optical alignment system of interest needs to be provided as input to COCOA. + +Such an XML file can be generated from a .txt description, by an independent cocoa application in `Alignment/CocoaApplication/bin`. +For example, one can generate an XML optical alignment system description, by simply doing the following: + + cd Alignment/CocoaApplication/bin + cocoa simple2D.txt + +### Input DB OpticalAlignmentsRcd +For testing purposes, an example input DB `OpticalAlignmentsRcd` can now be found at `Alignment/CocoaApplication/test/OpticalAlignments.db`. +It was generated by adding the following, in `CocoaAnalyzer::analyze`, after `readXMLFile` returns: + + Model& model = Model::getInstance(); + model.BuildSystemDescriptionFromOA(oaList_); + CocoaDBMgr::getInstance()->DumpCocoaResults(); +Of course, in practice, one would actually just need to call the OpticalAlignmentsRcd of interest to the desired alignment study. + +### Run COCOA +One can now just do: + + cd Alignment/CocoaApplication/test + cmsRun cocoaAnalyzer_cfg.py +This will perform the least-squared fit, and store all results in `Alignment/CocoaApplication/test/OpticalAlignments.db`. +The `OpticalAlignmentsRcd` obtained after fit, is stored with `OpticalAlignmentsRcdOutput` tag. +It should also be possible to use the feature of dumping the results into ROOT format. diff --git a/Alignment/CocoaApplication/interface/CocoaAnalyzer.h b/Alignment/CocoaApplication/interface/CocoaAnalyzer.h index fd7e384256e92..3438b652fa2cc 100644 --- a/Alignment/CocoaApplication/interface/CocoaAnalyzer.h +++ b/Alignment/CocoaApplication/interface/CocoaAnalyzer.h @@ -1,78 +1,43 @@ -#ifndef CocoaAnalyser_HH -#define CocoaAnalyser_HH -//-*- C++ -*- -// -// Package: Alignment/CocoaApplication -// Class: CocoaAnalyzer -// -/* +#ifndef ALIGNMENT_COCOA_APPLICATION_COCOA_ANALYZER_H +#define ALIGNMENT_COCOA_APPLICATION_COCOA_ANALYZER_H - Description: test access to the OpticalAlignMeasurements via OpticalAlignMeasurementsGeneratedSource - This also should demonstrate access to a geometry via the XMLIdealGeometryESSource - for use in THE COCOA analyzer. - - Implementation: - Iterate over retrieved alignments. -*/ -// - -#include -#include -#include -#include #include "FWCore/Framework/interface/one/EDAnalyzer.h" -#include "DetectorDescription/Core/interface/DDPosData.h" - -class Event; -class EventSetup; -class Entry; -//#include "FWCore/Framework/interface/EventSetup.h" - +#include "DetectorDescription/DDCMS/interface/DDSpecParRegistry.h" #include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h" -#include "CondFormats/OptAlignObjects/interface/OpticalAlignInfo.h" #include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h" -class DDFilteredView; -class DDCompactView; -class DDSpecifics; -class OpticalObject; - +class CocoaAnalyzer : public edm::one::EDAnalyzer { +public: + explicit CocoaAnalyzer(edm::ParameterSet const& p); + explicit CocoaAnalyzer(int i) {} + ~CocoaAnalyzer() override {} -class CocoaAnalyzer : public edm::one::EDAnalyzer -{ - public: - - explicit CocoaAnalyzer(edm::ParameterSet const& p); - explicit CocoaAnalyzer(int i) { } - virtual ~ CocoaAnalyzer() { } - - virtual void beginJob() override; - virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override; - // see note on endJob() at the bottom of the file. - // virtual void endJob() ; + void beginJob() override; + void analyze(const edm::Event& e, const edm::EventSetup& c) override; - private: - void ReadXMLFile( const edm::EventSetup& evts ); - std::vector ReadCalibrationDB( const edm::EventSetup& evts ); +private: + void readXMLFile(const edm::EventSetup& evts); - void CorrectOptAlignments( std::vector& oaListCalib ); - OpticalAlignInfo* FindOpticalAlignInfoXML( const OpticalAlignInfo& oaInfo ); - bool CorrectOaParam( OpticalAlignParam* oaParamXML, const OpticalAlignParam& oaParamDB ); + std::vector readCalibrationDB(const edm::EventSetup& evts); + void correctAllOpticalAlignments(std::vector& allDBOpticalAlignments); + void correctOpticalAlignmentParameter(OpticalAlignParam& myXMLParam, const OpticalAlignParam& myDBParam); - void RunCocoa(); + void runCocoa(); - OpticalAlignInfo GetOptAlignInfoFromOptO( OpticalObject* opto ); - double myFetchDbl(const DDsvalues_type& dvst, - const std::string& spName, - const size_t& vecInd ); - std::string myFetchString(const DDsvalues_type& dvst, - const std::string& spName, - const size_t& vecInd ); + template + std::vector getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, + const std::string& nodePath, + const std::string& parameterName); + template + T getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, + const std::string& nodePath, + const std::string& parameterName, + const unsigned int parameterValueIndex); - private: +private: OpticalAlignments oaList_; OpticalAlignMeasurements measList_; - std::string theCocoaDaqRootFileName; + std::string theCocoaDaqRootFileName_; }; #endif diff --git a/Alignment/CocoaApplication/src/CocoaAnalyzer.cc b/Alignment/CocoaApplication/src/CocoaAnalyzer.cc index 87d872d1d8867..f9aab2322b4ce 100644 --- a/Alignment/CocoaApplication/src/CocoaAnalyzer.cc +++ b/Alignment/CocoaApplication/src/CocoaAnalyzer.cc @@ -1,18 +1,18 @@ #include "FWCore/ServiceRegistry/interface/Service.h" #include "CondCore/DBOutputService/interface/PoolDBOutputService.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondFormats/DataRecord/interface/OpticalAlignmentsRcd.h" +#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurementInfo.h" +#include "DataFormats/Math/interface/CMSUnits.h" +#include "DetectorDescription/DDCMS/interface/DDCompactView.h" +#include "DetectorDescription/DDCMS/interface/DDFilteredView.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/ESTransientHandle.h" - -#include "Alignment/CocoaApplication/interface/CocoaAnalyzer.h" -#include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurementInfo.h" -#include "CondFormats/DataRecord/interface/OpticalAlignmentsRcd.h" -#include "DetectorDescription/Core/interface/DDFilteredView.h" -#include "DetectorDescription/Core/interface/DDCompactView.h" -#include "Geometry/Records/interface/IdealGeometryRecord.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.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" @@ -23,669 +23,584 @@ #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h" #include "Alignment/CocoaFit/interface/CocoaDBMgr.h" -//---------------------------------------------------------------------- -CocoaAnalyzer::CocoaAnalyzer(edm::ParameterSet const& pset) -{ - theCocoaDaqRootFileName = pset.getParameter< std::string >("cocoaDaqRootFile"); +using namespace cms_units::operators; - int maxEvents = pset.getParameter< int32_t >("maxEvents"); +CocoaAnalyzer::CocoaAnalyzer(edm::ParameterSet const& pset) { + theCocoaDaqRootFileName_ = pset.getParameter("cocoaDaqRootFile"); + int maxEvents = pset.getParameter("maxEvents"); GlobalOptionMgr::getInstance()->setDefaultGlobalOptions(); - GlobalOptionMgr::getInstance()->setGlobalOption("maxEvents",maxEvents); - GlobalOptionMgr::getInstance()->setGlobalOption("writeDBAlign",1); - GlobalOptionMgr::getInstance()->setGlobalOption("writeDBOptAlign",1); + GlobalOptionMgr::getInstance()->setGlobalOption("maxEvents", maxEvents); + GlobalOptionMgr::getInstance()->setGlobalOption("writeDBAlign", 1); + GlobalOptionMgr::getInstance()->setGlobalOption("writeDBOptAlign", 1); usesResource("CocoaAnalyzer"); } -//---------------------------------------------------------------------- -void CocoaAnalyzer::beginJob() -{ -} - - -//------------------------------------------------------------------------ -void CocoaAnalyzer::RunCocoa() -{ - if(ALIUtils::debug >= 3) { - std::cout << std::endl << "$$$ CocoaAnalyzer::RunCocoa: " << std::endl; - } - //-ALIFileIn fin; - //- GlobalOptionMgr::getInstance()->setGlobalOption("debug_verbose",5, fin ); - - //---------- Build the Model out of the system description text file - Model& model = Model::getInstance(); +void CocoaAnalyzer::beginJob() {} - model.BuildSystemDescriptionFromOA( oaList_ ); +void CocoaAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evts) { + ALIUtils::setDebugVerbosity(5); - if(ALIUtils::debug >= 3) { - std::cout << "$$ CocoaAnalyzer::RunCocoa: geometry built " << std::endl; - } + // Get ideal geometry description + measurements for simulation. + readXMLFile(evts); - model.BuildMeasurementsFromOA( measList_ ); + // Correct ideal geometry with data from DB. + std::vector oaListCalib = readCalibrationDB(evts); + correctAllOpticalAlignments(oaListCalib); - if(ALIUtils::debug >= 3) { - std::cout << "$$ CocoaAnalyzer::RunCocoa: measurements built " << std::endl; - } + // Run the least-squared fit and store results in DB. + runCocoa(); +} - Fit::getInstance(); +/* + * This is used to create the ideal geometry description from the XMLs. + * Also get measurements from XMLs for simulation. + * Resulting optical alignment info is stored in oaList_ and measList_. + */ +void CocoaAnalyzer::readXMLFile(const edm::EventSetup& evts) { + edm::ESTransientHandle myCompactView; + evts.get().get(myCompactView); - Fit::startFit(); + const cms::DDDetector* mySystem = myCompactView->detector(); - if(ALIUtils::debug >= 0) std::cout << "............ program ended OK" << std::endl; - if( ALIUtils::report >=1 ) { - ALIFileOut& fileout = ALIFileOut::getInstance( Model::ReportFName() ); - fileout << "............ program ended OK" << std::endl; - } + if (mySystem) { + // Always store world volume first. + const dd4hep::Volume& worldVolume = mySystem->worldVolume(); -} // end of ::beginJob + if (ALIUtils::debug >= 3) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML: world object = " << worldVolume.name(); + } + OpticalAlignInfo worldInfo; + worldInfo.ID_ = 0; + worldInfo.name_ = worldVolume.name(); + worldInfo.type_ = "system"; + worldInfo.parentName_ = ""; + worldInfo.x_.value_ = 0.; + worldInfo.x_.error_ = 0.; + worldInfo.x_.quality_ = 0; + worldInfo.y_.value_ = 0.; + worldInfo.y_.error_ = 0.; + worldInfo.y_.quality_ = 0; + worldInfo.z_.value_ = 0.; + worldInfo.z_.error_ = 0.; + worldInfo.z_.quality_ = 0; + worldInfo.angx_.value_ = 0.; + worldInfo.angx_.error_ = 0.; + worldInfo.angx_.quality_ = 0; + worldInfo.angy_.value_ = 0.; + worldInfo.angy_.error_ = 0.; + worldInfo.angy_.quality_ = 0; + worldInfo.angz_.value_ = 0.; + worldInfo.angz_.error_ = 0.; + worldInfo.angz_.quality_ = 0; + oaList_.opticalAlignments_.emplace_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, + // and ALLOWING THE ASSOCIATION OF SPECIFIC PARAMETERS AND VALUES TO THESE VOLUMES. + const cms::DDSpecParRegistry& allSpecParSections = myCompactView->specpars(); + + // CREATION OF A COCOA FILTERED VIEW + // Creation of the dd4hep-based filtered view. + // NB: not filtered yet! + cms::DDFilteredView myFilteredView(mySystem, worldVolume); + // Declare a container which will gather all the filtered SpecPar sections. + cms::DDSpecParRefs cocoaParameterSpecParSections; + // Define a COCOA filter + const std::string cocoaParameterAttribute = "COCOA"; + const std::string cocoaParameterValue = "COCOA"; + // All the COCOA SpecPar sections are filtered from allSpecParSections, + // and assigned to cocoaParameterSpecParSections. + allSpecParSections.filter(cocoaParameterSpecParSections, cocoaParameterAttribute, cocoaParameterValue); + // This finally allows to filter the filtered view, with the COCOA filter. + // This means that we now have, in myFilteredView, all volumes whose paths were selected: + // ie all volumes with "COCOA" parameter and value in a SpecPar section from a loaded XML. + myFilteredView.mergedSpecifics(cocoaParameterSpecParSections); + + // Loop on parts + int nObjects = 0; + bool doCOCOA = myFilteredView.firstChild(); + + // Loop on all COCOA volumes from filtered view + while (doCOCOA) { + ++nObjects; + + OpticalAlignInfo oaInfo; + OpticalAlignParam oaParam; + OpticalAlignMeasurementInfo oaMeas; + + // Current volume + const dd4hep::PlacedVolume& myPlacedVolume = myFilteredView.volume(); + const std::string& name = myPlacedVolume.name(); + const std::string& nodePath = myFilteredView.path(); + oaInfo.name_ = nodePath; + + // Parent name + oaInfo.parentName_ = nodePath.substr(0, nodePath.rfind('/', nodePath.length())); + + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML reading object " << name; + edm::LogInfo("Alignment") << " @@ Name built= " << oaInfo.name_ << " short_name= " << name + << " parent= " << oaInfo.parentName_; + } -//----------------------------------------------------------------------- -void CocoaAnalyzer::ReadXMLFile( const edm::EventSetup& evts ) -{ + // TRANSLATIONS - // STEP ONE: Initial COCOA objects will be built from a DDL geometry - // description. - - edm::ESTransientHandle cpv; - evts.get().get(cpv); + // A) GET TRANSLATIONS FROM DDETECTOR. + // Directly get translation from parent to child volume + const dd4hep::Direction& transl = myPlacedVolume.position(); - if(ALIUtils::debug >= 3) { - std::cout << std::endl << "$$$ CocoaAnalyzer::ReadXML: root object= " << cpv->root() << std::endl; - } - - //Build OpticalAlignInfo "system" - const DDLogicalPart lv = cpv->root(); - - OpticalAlignInfo oaInfo; - oaInfo.ID_ = 0; - //--- substract file name to object name - oaInfo.name_ = lv.name().name(); - oaInfo.parentName_ = ""; - oaInfo.x_.quality_ = 0; - oaInfo.x_.value_ = 0.; - oaInfo.x_.error_ = 0.; - oaInfo.x_.quality_ = 0; - oaInfo.y_.value_ = 0.; - oaInfo.y_.error_ = 0.; - oaInfo.y_.quality_ = 0; - oaInfo.z_.value_ = 0.; - oaInfo.z_.error_ = 0.; - oaInfo.z_.quality_ = 0; - oaInfo.angx_.value_ = 0.; - oaInfo.angx_.error_ = 0.; - oaInfo.angx_.quality_ = 0; - oaInfo.angy_.value_ = 0.; - oaInfo.angy_.error_ = 0.; - oaInfo.angy_.quality_ = 0; - oaInfo.angz_.value_ = 0.; - oaInfo.angz_.error_ = 0.; - oaInfo.angz_.quality_ = 0; - - oaInfo.type_ = "system"; - - oaList_.opticalAlignments_.push_back(oaInfo); - oaInfo.clear(); - - // Example of traversing the whole optical alignment geometry. - // At each node we get specpars as variables and use them in - // constructing COCOA objects. - // It stores these objects in a private data member, opt - std::string attribute = "COCOA"; - std::string value = "COCOA"; - - // get all parts labelled with COCOA using a SpecPar - DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)}; - DDFilteredView fv(*cpv, filter); - bool doCOCOA = fv.firstChild(); - - // Loop on parts - int nObjects=0; - OpticalAlignParam oaParam; - OpticalAlignMeasurementInfo oaMeas; - - while ( doCOCOA ){ - ++nObjects; - // oaInfo.ID_ = nObjects; - const DDsvalues_type params(fv.mergedSpecifics()); - - const DDLogicalPart lv = fv.logicalPart(); - if(ALIUtils::debug >= 4) { - std::cout << " CocoaAnalyzer::ReadXML reading object " << lv.name() << std::endl; - } + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << "Local translation in cm = " << transl; + } - std::vector history = fv.geoHistory(); - oaInfo.parentName_ = ""; - size_t ii; - for(ii = 0; ii < history.size()-1;ii++ ) { - if( ii != 0 ) oaInfo.parentName_ += "/"; - std::string name = history[ii].logicalPart().name().name(); - oaInfo.parentName_ += name; - // oaInfo.parentName_ = (fv.geoHistory()[fv.geoHistory().size()-2]).logicalPart().name(); -// icol = oaInfo.parentName_.find(":"); - // oaInfo.parentName_ = oaInfo.parentName_.substr(icol+1,oaInfo.parentName_.length()); - } + // B) READ INFO FROM XMLS + // X + oaInfo.x_.name_ = "X"; + oaInfo.x_.dim_type_ = "centre"; + oaInfo.x_.value_ = transl.x() / (1._m); // COCOA units are m + oaInfo.x_.error_ = getParameterValueFromSpecParSections(allSpecParSections, + nodePath, + "centre_X_sigma", + 0) / + (1._m); // COCOA units are m + oaInfo.x_.quality_ = static_cast( + getParameterValueFromSpecParSections(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(allSpecParSections, + nodePath, + "centre_Y_sigma", + 0) / + (1._m); // COCOA units are m + oaInfo.y_.quality_ = static_cast( + getParameterValueFromSpecParSections(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(allSpecParSections, + nodePath, + "centre_Z_sigma", + 0) / + (1._m); // COCOA units are m + oaInfo.z_.quality_ = static_cast( + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "centre_Z_quality", 0)); + + // ROTATIONS + + // A) GET ROTATIONS FROM DDETECTOR. + + // Unlike in the initial code, here we manage to directly get the rotation matrix placement + // of the child in parent, EXPRESSED IN THE PARENT FRAME OF REFERENCE. + // Hence the (ugly) initial block of code is replaced by just 2 lines. + // PlacedVolume::matrix() returns the rotation matrix IN THE PARENT FRAME OF REFERENCE. + // NB: Not using DDFilteredView::rotation(), + // because it returns the rotation matrix IN THE WORLD FRAME OF REFERENCE. + const TGeoHMatrix parentToChild = myPlacedVolume.matrix(); + // COCOA convention is FROM CHILD TO PARENT + const TGeoHMatrix& childToParent = parentToChild.Inverse(); + + // Convert it to CLHEP::Matrix + // Below is not my code, below block is untouched (apart from bug fix). + // I would just directly use childToParent... + const Double_t* rot = childToParent.GetRotationMatrix(); + const double xx = rot[0]; + const double xy = rot[1]; + const double xz = rot[2]; + const double yx = rot[3]; + const double yy = rot[4]; + const double yz = rot[5]; + const double zx = rot[6]; + const double zy = rot[7]; + const double zz = rot[8]; + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << "Local rotation = "; + edm::LogInfo("Alignment") << xx << " " << xy << " " << xz; + edm::LogInfo("Alignment") << yx << " " << yy << " " << yz; + edm::LogInfo("Alignment") << zx << " " << zy << " " << zz; + } + const CLHEP::Hep3Vector colX(xx, yx, zx); + const CLHEP::Hep3Vector colY(xy, yy, zy); + const CLHEP::Hep3Vector colZ(xz, yz, zz); + const CLHEP::HepRotation rotclhep(colX, colY, colZ); + const std::vector& angles = ALIUtils::getRotationAnglesFromMatrix(rotclhep, 0., 0., 0.); + + // B) READ INFO FROM XMLS + // X + oaInfo.angx_.name_ = "X"; + oaInfo.angx_.dim_type_ = "angles"; + oaInfo.angx_.value_ = + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_value", 0); + oaInfo.angx_.error_ = + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_sigma", 0); + oaInfo.angx_.quality_ = static_cast( + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_X_quality", 0)); + // Y + oaInfo.angy_.name_ = "Y"; + oaInfo.angy_.dim_type_ = "angles"; + oaInfo.angy_.value_ = + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_value", 0); + oaInfo.angy_.error_ = + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_sigma", 0); + oaInfo.angy_.quality_ = static_cast( + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Y_quality", 0)); + // Z + oaInfo.angz_.name_ = "Z"; + oaInfo.angz_.dim_type_ = "angles"; + oaInfo.angz_.value_ = + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_value", 0); + oaInfo.angz_.error_ = + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_sigma", 0); + oaInfo.angz_.quality_ = static_cast( + getParameterValueFromSpecParSections(allSpecParSections, nodePath, "angles_Z_quality", 0)); + + oaInfo.type_ = getParameterValueFromSpecParSections(allSpecParSections, nodePath, "cocoa_type", 0); + + oaInfo.ID_ = + static_cast(getParameterValueFromSpecParSections(allSpecParSections, nodePath, "cmssw_ID", 0)); + + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read "; + } - //--- build object name (= parent name + object name) - std::string name = history[ii].logicalPart().name().name(); - //--- substract file name to object name - oaInfo.name_ = oaInfo.parentName_ + "/" + name; - if(ALIUtils::debug >= 5) { - std::cout << " @@ Name built= " << oaInfo.name_ << " short_name= " << name << " parent= " << oaInfo.parentName_ << std::endl; - } - //----- Read centre and angles - oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0)); - DDTranslation transl = (fv.translation()); - DDRotationMatrix rot = (fv.rotation()); - DDExpandedNode parent = fv.geoHistory()[ fv.geoHistory().size()-2 ]; - const DDTranslation& parentTransl = parent.absTranslation(); - const DDRotationMatrix& parentRot = parent.absRotation(); - transl = parentRot.Inverse()*(transl - parentTransl ); - rot = parentRot.Inverse()*rot; - rot = rot.Inverse(); //DDL uses opposite convention than COCOA - /* if(ALIUtils::debug >= 4) { - ALIUtils::dumprm( rot, "local rotation "); - ALIUtils::dump3v( transl, "local translation"); - } */ - - oaInfo.x_.name_ = "X"; - oaInfo.x_.dim_type_ = "centre"; - oaInfo.x_.value_ = transl.x()*0.001; // CLHEP units are mm, COCOA are m - oaInfo.x_.error_ = myFetchDbl(params, "centre_X_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m - oaInfo.x_.quality_ = int (myFetchDbl(params, "centre_X_quality", 0)); - - oaInfo.y_.name_ = "Y"; - oaInfo.y_.dim_type_ = "centre"; - oaInfo.y_.value_ = transl.y()*0.001; // CLHEP units are mm, COCOA are m - oaInfo.y_.error_ = myFetchDbl(params, "centre_Y_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m - oaInfo.y_.quality_ = int (myFetchDbl(params, "centre_Y_quality", 0)); - - oaInfo.z_.name_ = "Z"; - oaInfo.z_.dim_type_ = "centre"; - oaInfo.z_.value_ = transl.z()*0.001; // CLHEP units are mm, COCOA are m - oaInfo.z_.error_ = myFetchDbl(params, "centre_Z_sigma", 0)*0.001; // CLHEP units are mm, COCOA are m - oaInfo.z_.quality_ = int (myFetchDbl(params, "centre_Z_quality", 0)); - - //---- DDD convention is to use the inverse matrix, COCOA is the direct one!!! - //---- convert it to CLHEP::Matrix - double xx,xy,xz,yx,yy,yz,zx,zy,zz; - rot.GetComponents (xx, xy, xz, - yx, yy, yz, - zx, zy, zz); - CLHEP::Hep3Vector colX(xx,xy,xz); - CLHEP::Hep3Vector colY(yx,yy,yz); - CLHEP::Hep3Vector colZ(zx,zy,zz); - CLHEP::HepRotation rotclhep( colX, colY, colZ ); - std::vector angles = ALIUtils::getRotationAnglesFromMatrix( rotclhep,0., 0., 0. ); - - oaInfo.angx_.name_ = "X"; - oaInfo.angx_.dim_type_ = "angles"; - //- oaInfo.angx_.value_ = angles[0]; - oaInfo.angx_.value_ = myFetchDbl(params, "angles_X_value", 0); - oaInfo.angx_.error_ = myFetchDbl(params, "angles_X_sigma", 0); - oaInfo.angx_.quality_ = int (myFetchDbl(params, "angles_X_quality", 0)); - - oaInfo.angy_.name_ = "Y"; - oaInfo.angy_.dim_type_ = "angles"; - //- oaInfo.angy_.value_ = angles[1]; - oaInfo.angy_.value_ = myFetchDbl(params, "angles_Y_value", 0); - oaInfo.angy_.error_ = myFetchDbl(params, "angles_Y_sigma", 0); - oaInfo.angy_.quality_ = int (myFetchDbl(params, "angles_Y_quality", 0)); - - oaInfo.angz_.name_ = "Z"; - oaInfo.angz_.dim_type_ = "angles"; - // oaInfo.angz_.value_ = angles[2]; - oaInfo.angz_.value_ = myFetchDbl(params, "angles_Z_value", 0); - oaInfo.angz_.error_ = myFetchDbl(params, "angles_Z_sigma", 0); - oaInfo.angz_.quality_ = int (myFetchDbl(params, "angles_Z_quality", 0)); - - oaInfo.type_ = myFetchString(params, "cocoa_type", 0); - - oaInfo.ID_ = int(myFetchDbl(params, "cmssw_ID", 0)); - - if(ALIUtils::debug >= 4) { - std::cout << "CocoaAnalyzer::ReadXML OBJECT " << oaInfo.name_ << " pos/angles read " << std::endl; - } + // Check that rotations match with values from XMLs. + // Same, that ugly code is not mine ;p + if (fabs(oaInfo.angx_.value_ - angles[0]) > 1.E-9 || fabs(oaInfo.angy_.value_ - angles[1]) > 1.E-9 || + fabs(oaInfo.angz_.value_ - angles[2]) > 1.E-9) { + edm::LogError("Alignment") << " WRONG ANGLE IN OBJECT " << oaInfo.name_ << oaInfo.angx_.value_ << " =? " + << angles[0] << oaInfo.angy_.value_ << " =? " << angles[1] << oaInfo.angz_.value_ + << " =? " << angles[2]; + } - if( fabs( oaInfo.angx_.value_ - angles[0] ) > 1.E-9 || - fabs( oaInfo.angy_.value_ - angles[1] ) > 1.E-9 || - fabs( oaInfo.angz_.value_ - angles[2] ) > 1.E-9 ) { - std::cerr << " WRONG ANGLE IN OBJECT " << oaInfo.name_<< - oaInfo.angx_.value_ << " =? " << angles[0] << - oaInfo.angy_.value_ << " =? " << angles[1] << - oaInfo.angz_.value_ << " =? " << angles[2] << std::endl; - } + // EXTRA PARAM ENTRIES (FROM XMLS) + // Here initial code to define the containers was fully removed, this is much more compact. + const std::vector& names = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "extra_entry"); + const std::vector& dims = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "dimType"); + const std::vector& values = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "value"); + const std::vector& errors = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "sigma"); + const std::vector& quality = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "quality"); + + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters "; + } - //----- Read extra entries and measurements - const std::vector params2(fv.specifics()); - std::vector::const_iterator spit = params2.begin(); - std::vector::const_iterator endspit = params2.end(); - //--- extra entries variables - std::vector names, dims; - std::vector values, errors, quality; - //--- measurements variables - std::vector measNames; - std::vector measTypes; - std::map > measObjectNames; - std::map > measParamNames; - std::map > measParamValues; - std::map > measParamSigmas; - std::map > measIsSimulatedValue; - - for ( ; spit != endspit; ++spit ) { - DDsvalues_type::const_iterator sit = (**spit).begin(); - DDsvalues_type::const_iterator endsit = (**spit).end(); - for ( ; sit != endsit; ++sit ) { - if (sit->second.name() == "extra_entry") { - names = sit->second.strings(); - } else if (sit->second.name() == "dimType") { - dims = sit->second.strings(); - } else if (sit->second.name() == "value") { - values = sit->second.doubles(); - } else if (sit->second.name() == "sigma") { - errors = sit->second.doubles(); - } else if (sit->second.name() == "quality") { - quality = sit->second.doubles(); - - } else if (sit->second.name() == "meas_name") { - //- std::cout << " meas_name found " << std::endl; - measNames = sit->second.strings(); - } else if (sit->second.name() == "meas_type") { - //- std::cout << " meas_type found " << std::endl; - measTypes = sit->second.strings(); - } - + 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[i]; + if (type == "centre" || type == "length") { + dimFactor = 1. / (1._m); // was converted to cm with getParameterValueFromSpecPar, COCOA unit is m + } else if (type == "angles" || type == "angle" || type == "nodim") { + dimFactor = 1.; + } + oaParam.value_ = values[i] * dimFactor; + oaParam.error_ = errors[i] * dimFactor; + oaParam.quality_ = static_cast(quality[i]); + oaParam.name_ = names[i]; + oaParam.dim_type_ = dims[i]; + oaInfo.extraEntries_.emplace_back(oaParam); + oaParam.clear(); + } + + oaList_.opticalAlignments_.emplace_back(oaInfo); + } else { + edm::LogInfo("Alignment") << "WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do" + << " not match! Did not add " << nObjects << " item to OpticalAlignments."; } - } - //---- loop again to look for the measurement object names, that have the meas name in the SpecPar title - // - // - - std::vector::iterator vsite; - for ( spit = params2.begin(); spit != params2.end(); ++spit ) { - //- std::cout << "loop vector DDsvalues " << std::endl; - DDsvalues_type::const_iterator sit = (**spit).begin(); - DDsvalues_type::const_iterator endsit = (**spit).end(); - for ( ; sit != endsit; ++sit ) { - for( vsite = measNames.begin(); vsite != measNames.end(); ++vsite ){ - //- std::cout << "looping measObjectNames " << *vsite << std::endl; - if (sit->second.name() == "meas_object_name_"+(*vsite)) { - measObjectNames[*vsite] = sit->second.strings(); - }else if (sit->second.name() == "meas_value_name_"+(*vsite)) { - measParamNames[*vsite] = sit->second.strings(); - }else if (sit->second.name() == "meas_value_"+(*vsite)) { - measParamValues[*vsite] = sit->second.doubles(); - }else if (sit->second.name() == "meas_sigma_"+(*vsite)) { - measParamSigmas[*vsite] = sit->second.doubles(); - }else if (sit->second.name() == "meas_is_simulated_value_"+(*vsite)) { - measIsSimulatedValue[*vsite] = sit->second.doubles(); // this is not in OptAlignParam info - if(ALIUtils::debug >= 5) { - std::cout << *vsite << " setting issimu " << measIsSimulatedValue[*vsite][0] << std::endl; - } - } - if(ALIUtils::debug >= 5) { - std::cout << "CocoaAnalyser: looped measObjectNames " << "meas_object_name_"+(*vsite) << " n obj " << measObjectNames[*vsite].size() << std::endl; - } - - } - + // MEASUREMENTS (FROM XMLS) + const std::vector& measNames = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_name"); + const std::vector& measTypes = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_type"); + + std::map> measObjectNames; + std::map> measParamNames; + std::map> measParamValues; + std::map> measParamSigmas; + std::map> measIsSimulatedValue; + for (const auto& name : measNames) { + measObjectNames[name] = getAllParameterValuesFromSpecParSections( + allSpecParSections, nodePath, "meas_object_name_" + name); + measParamNames[name] = getAllParameterValuesFromSpecParSections( + allSpecParSections, nodePath, "meas_value_name_" + name); + measParamValues[name] = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_value_" + name); + measParamSigmas[name] = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, "meas_sigma_" + name); + measIsSimulatedValue[name] = getAllParameterValuesFromSpecParSections( + allSpecParSections, nodePath, "meas_is_simulated_value_" + name); } - } - - if(ALIUtils::debug >= 4) { - std::cout << " CocoaAnalyzer::ReadXML: Fill extra entries with read parameters " << std::endl; - } - //--- Fill extra entries with read parameters - if ( names.size() == dims.size() && dims.size() == values.size() - && values.size() == errors.size() && errors.size() == quality.size() ) { - for ( size_t ind = 0; ind < names.size(); ++ind ) { - double dimFactor = 1.; - std::string type = oaParam.dimType(); - if( type == "centre" || type == "length" ) { - dimFactor = 0.001; // in XML it is in mm - }else if ( type == "angles" || type == "angle" || type == "nodim" ){ - dimFactor = 1.; - } - oaParam.value_ = values[ind]*dimFactor; - oaParam.error_ = errors[ind]*dimFactor; - oaParam.quality_ = int (quality[ind]); - oaParam.name_ = names[ind]; - oaParam.dim_type_ = dims[ind]; - oaInfo.extraEntries_.push_back (oaParam); - oaParam.clear(); + + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << " CocoaAnalyzer::ReadXML: Fill measurements with read parameters "; } - //t std::cout << names.size() << " OBJECT " << oaInfo.name_ << " extra entries read " << oaInfo << std::endl; + if (measNames.size() == measTypes.size()) { + for (size_t i = 0; i < measNames.size(); ++i) { + oaMeas.ID_ = i; + oaMeas.name_ = measNames[i]; + oaMeas.type_ = measTypes[i]; + oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_]; + 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_][i2]; + oaParam.value_ = measParamValues[oaMeas.name_][i2]; + oaParam.error_ = measParamSigmas[oaMeas.name_][i2]; + oaParam.quality_ = 2; + if (oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" || + oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM") { + oaParam.dim_type_ = "length"; + } else if (oaMeas.type_ == "TILTMETER") { + oaParam.dim_type_ = "angle"; + } else { + edm::LogError("Alignment") << "CocoaAnalyzer::readXMLFile. Invalid measurement type: " << oaMeas.type_; + } + + oaMeas.values_.emplace_back(oaParam); + oaMeas.isSimulatedValue_.emplace_back(measIsSimulatedValue[oaMeas.name_][i2]); + if (ALIUtils::debug >= 5) { + edm::LogInfo("Alignment") << oaMeas.name_ << " copying issimu " + << oaMeas.isSimulatedValue_[oaMeas.isSimulatedValue_.size() - 1] << " = " + << measIsSimulatedValue[oaMeas.name_][i2]; + } + oaParam.clear(); + } + } else { + if (ALIUtils::debug >= 2) { + edm::LogWarning("Alignment") << "WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do" + << " not match! for measurement " << oaMeas.name_ + << " !Did not fill parameters for this measurement "; + } + } + measList_.oaMeasurements_.emplace_back(oaMeas); + if (ALIUtils::debug >= 5) { + edm::LogInfo("Alignment") << "CocoaAnalyser: MEASUREMENT " << oaMeas.name_ << " extra entries read " + << oaMeas; + } + oaMeas.clear(); + } + + } else { + if (ALIUtils::debug >= 2) { + edm::LogWarning("Alignment") << "WARNING FOR NOW: sizes of measurements (names, types do" + << " not match! Did not add " << nObjects << " item to XXXMeasurements"; + } + } - oaList_.opticalAlignments_.push_back(oaInfo); - } else { - std::cout << "WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do" - << " not match! Did not add " << nObjects << " item to OpticalAlignments." - << std::endl; - } + oaInfo.clear(); + doCOCOA = myFilteredView.firstChild(); + } // while (doCOCOA) - if(ALIUtils::debug >= 4) { - std::cout << " CocoaAnalyzer::ReadXML: Fill measurements with read parameters " << std::endl; + if (ALIUtils::debug >= 3) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::ReadXML: Finished building " << nObjects + 1 + << " OpticalAlignInfo objects" + << " and " << measList_.oaMeasurements_.size() + << " OpticalAlignMeasurementInfo objects "; } - //--- Fill measurements with read parameters - if ( measNames.size() == measTypes.size() ) { - for ( size_t ind = 0; ind < measNames.size(); ++ind ) { - oaMeas.ID_ = ind; - oaMeas.name_ = measNames[ind]; - oaMeas.type_ = measTypes[ind]; - oaMeas.measObjectNames_ = measObjectNames[oaMeas.name_]; - if( measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size() ) { - for( size_t ind2 = 0; ind2 < measParamNames[oaMeas.name_].size(); ind2++ ){ - oaParam.name_ = measParamNames[oaMeas.name_][ind2]; - oaParam.value_ = measParamValues[oaMeas.name_][ind2]; - oaParam.error_ = measParamSigmas[oaMeas.name_][ind2]; - if( oaMeas.type_ == "SENSOR2D" || oaMeas.type_ == "COPS" || oaMeas.type_ == "DISTANCEMETER" || oaMeas.type_ == "DISTANCEMETER!DIM" || oaMeas.type_ == "DISTANCEMETER3DIM" ) { - oaParam.dim_type_ = "length"; - } else if( oaMeas.type_ == "TILTMETER" ) { - oaParam.dim_type_ = "angle"; - } else { - std::cerr << "CocoaAnalyzer::ReadXMLFile. Invalid measurement type: " << oaMeas.type_ << std::endl; - std::exception(); - } - - oaMeas.values_.push_back( oaParam ); - oaMeas.isSimulatedValue_.push_back( measIsSimulatedValue[oaMeas.name_][ind2] ); - if(ALIUtils::debug >= 5) { - std::cout << oaMeas.name_ << " copying issimu " << oaMeas.isSimulatedValue_[oaMeas.isSimulatedValue_.size()-1] << " = " << measIsSimulatedValue[oaMeas.name_][ind2] << std::endl; - //- std::cout << ind2 << " adding meas value " << oaParam << std::endl; - } - oaParam.clear(); - } - } else { - if(ALIUtils::debug >= 2) { - std::cout << "WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do" - << " not match! for measurement " << oaMeas.name_ << " !Did not fill parameters for this measurement " << std::endl; - } - } - measList_.oaMeasurements_.push_back (oaMeas); - if(ALIUtils::debug >= 5) { - std::cout << "CocoaAnalyser: MEASUREMENT " << oaMeas.name_ << " extra entries read " << oaMeas << std::endl; - } - oaMeas.clear(); - } - - } else { - if(ALIUtils::debug >= 2) { - std::cout << "WARNING FOR NOW: sizes of measurements (names, types do" - << " not match! Did not add " << nObjects << " item to XXXMeasurements" - << std::endl; - } + if (ALIUtils::debug >= 5) { + edm::LogInfo("Alignment") << " @@@@@@ OpticalAlignments " << oaList_; + edm::LogInfo("Alignment") << " @@@@@@ OpticalMeasurements " << measList_; } - -// std::cout << "sizes are values=" << values.size(); -// std::cout << " sigma(errors)=" << errors.size(); -// std::cout << " quality=" << quality.size(); -// std::cout << " names=" << names.size(); -// std::cout << " dimType=" << dims.size() << std::endl; - oaInfo.clear(); - doCOCOA = fv.next(); // go to next part - } // while (doCOCOA) - if(ALIUtils::debug >= 3) { - std::cout << "CocoaAnalyzer::ReadXML: Finished building " << nObjects+1 << " OpticalAlignInfo objects" << " and " << measList_.oaMeasurements_.size() << " OpticalAlignMeasurementInfo objects " << std::endl; - } - if(ALIUtils::debug >= 5) { - std::cout << " @@@@@@ OpticalAlignments " << oaList_ << std::endl; - std::cout << " @@@@@@ OpticalMeasurements " << measList_ << std::endl; } - } -//------------------------------------------------------------------------ -std::vector CocoaAnalyzer::ReadCalibrationDB( const edm::EventSetup& evts ) -{ - if(ALIUtils::debug >= 3) { - std::cout<< std::endl <<"$$$ CocoaAnalyzer::ReadCalibrationDB: " << std::endl; +/* + * This is used to get the OpticalAlignInfo from DB, + * which can be used to correct the OpticalAlignInfo from IdealGeometry. + */ +std::vector CocoaAnalyzer::readCalibrationDB(const edm::EventSetup& evts) { + if (ALIUtils::debug >= 3) { + edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::readCalibrationDB: "; } - + using namespace edm::eventsetup; edm::ESHandle pObjs; evts.get().get(pObjs); - const OpticalAlignments* dbObj = pObjs.product(); - - if(ALIUtils::debug >= 5) { - std::vector::const_iterator it; - for( it=dbObj->opticalAlignments_.begin();it!=dbObj->opticalAlignments_.end(); ++it ){ - std::cout<<"CocoaAnalyzer::ReadCalibrationDB: OpticalAlignInfo READ "<< *it << std::endl; + const std::vector& infoFromDB = pObjs.product()->opticalAlignments_; + + if (ALIUtils::debug >= 5) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ " + << infoFromDB.size(); + for (const auto& myInfoFromDB : infoFromDB) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::readCalibrationDB: OpticalAlignInfo READ " << myInfoFromDB; } } - - if(ALIUtils::debug >= 4) { - std::cout<<"CocoaAnalyzer::ReadCalibrationDB: Number of OpticalAlignInfo READ "<< dbObj->opticalAlignments_.size() << std::endl; - } - return dbObj->opticalAlignments_; + return infoFromDB; } - -//------------------------------------------------------------------------ -void CocoaAnalyzer::CorrectOptAlignments( std::vector& oaListCalib ) -{ - if(ALIUtils::debug >= 3) { - std::cout<< std::endl<< "$$$ CocoaAnalyzer::CorrectOptAlignments: " << std::endl; +/* + * Correct all OpticalAlignInfo from IdealGeometry with values from DB. + */ +void CocoaAnalyzer::correctAllOpticalAlignments(std::vector& allDBOpticalAlignments) { + if (ALIUtils::debug >= 3) { + edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::correctAllOpticalAlignments: "; } - std::vector::const_iterator it; - for( it=oaListCalib.begin();it!=oaListCalib.end(); ++it ){ - OpticalAlignInfo oaInfoDB = *it; - OpticalAlignInfo* oaInfoXML = FindOpticalAlignInfoXML( oaInfoDB ); - std::cerr << "error " << (*it).name_ << std::endl; - if( oaInfoXML == nullptr ) { - if(ALIUtils::debug >= 2) { - std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: OpticalAlignInfo read from DB is not present in XML "<< *it << std::endl; + for (const auto& myDBInfo : allDBOpticalAlignments) { + if (ALIUtils::debug >= 5) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::findOpticalAlignInfoXML: Looking for OAI " << myDBInfo.name_; + } + + std::vector& allXMLOpticalAlignments = oaList_.opticalAlignments_; + const auto& myXMLInfo = std::find_if( + allXMLOpticalAlignments.begin(), allXMLOpticalAlignments.end(), [&](const auto& myXMLInfoCandidate) { + return myXMLInfoCandidate.name_ == myDBInfo.name_; + }); + + if (myXMLInfo != allXMLOpticalAlignments.end()) { + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::findOpticalAlignInfoXML: OAI found " << myXMLInfo->name_; + edm::LogInfo("Alignment") + << "CocoaAnalyzer::correctAllOpticalAlignments: correcting data from XML with DB info."; } - } else { - //------ Correct info - if(ALIUtils::debug >= 5) { - std::cout << "CocoaAnalyzer::CorrectOptAlignments: correcting data from DB info " << std::endl; + correctOpticalAlignmentParameter(myXMLInfo->x_, myDBInfo.x_); + correctOpticalAlignmentParameter(myXMLInfo->y_, myDBInfo.y_); + correctOpticalAlignmentParameter(myXMLInfo->z_, myDBInfo.z_); + correctOpticalAlignmentParameter(myXMLInfo->angx_, myDBInfo.angx_); + correctOpticalAlignmentParameter(myXMLInfo->angy_, myDBInfo.angy_); + correctOpticalAlignmentParameter(myXMLInfo->angz_, myDBInfo.angz_); + + // Also correct extra entries + const std::vector& allDBExtraEntries = myDBInfo.extraEntries_; + std::vector& allXMLExtraEntries = myXMLInfo->extraEntries_; + for (const auto& myDBExtraEntry : allDBExtraEntries) { + const auto& myXMLExtraEntry = std::find_if( + allXMLExtraEntries.begin(), allXMLExtraEntries.end(), [&](const auto& myXMLExtraEntryCandidate) { + return myXMLExtraEntryCandidate.name_ == myDBExtraEntry.name_; + }); + + if (myXMLExtraEntry != allXMLExtraEntries.end()) { + correctOpticalAlignmentParameter(*myXMLExtraEntry, myDBExtraEntry); + } else { + if (myDBExtraEntry.name_ != "None") { + if (ALIUtils::debug >= 2) { + edm::LogError("Alignment") + << "CocoaAnalyzer::correctAllOpticalAlignments: extra entry read from DB is not present in XML " + << myDBExtraEntry << " in object " << myDBInfo; + } + } + } } - CorrectOaParam( &oaInfoXML->x_, oaInfoDB.x_ ); - CorrectOaParam( &oaInfoXML->y_, oaInfoDB.y_ ); - CorrectOaParam( &oaInfoXML->z_, oaInfoDB.z_ ); - CorrectOaParam( &oaInfoXML->angx_, oaInfoDB.angx_ ); - CorrectOaParam( &oaInfoXML->angy_, oaInfoDB.angy_ ); - CorrectOaParam( &oaInfoXML->angz_, oaInfoDB.angz_ ); - std::vector::iterator itoap1, itoap2; - std::vector extraEntDB = oaInfoDB.extraEntries_; - std::vector* extraEntXML = &(oaInfoXML->extraEntries_); - 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_.substr( 1, (*itoap1).name_.size()-2 ); - for( itoap2 = extraEntXML->begin(); itoap2 != extraEntXML->end(); ++itoap2 ){ - if( oaName == (*itoap2).name_ ) { - CorrectOaParam( &(*itoap2), *itoap1 ); - pFound = true; - break; - } - } - if( !pFound && oaName != "None" ) { - if(ALIUtils::debug >= 2) { - std::cerr << "@@@@@ WARNING CocoaAnalyzer::CorrectOptAlignments: extra entry read from DB is not present in XML "<< *itoap1 << " in object " << *it << std::endl; - } - } + if (ALIUtils::debug >= 5) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::correctAllOpticalAlignments: corrected OpticalAlingInfo " + << oaList_; } - if(ALIUtils::debug >= 5) { - std::cout << "CocoaAnalyzer::CorrectOptAlignments: corrected OpticalAlingInfo " << oaList_ << std::endl; + } else { + if (ALIUtils::debug >= 2) { + edm::LogError("Alignment") << "CocoaAnalyzer::correctAllOpticalAlignments: OpticalAlignInfo read from DB " + << myDBInfo << " is not present in XML."; } - } } - } - -//------------------------------------------------------------------------ -OpticalAlignInfo* CocoaAnalyzer::FindOpticalAlignInfoXML( const OpticalAlignInfo& oaInfo ) -{ - OpticalAlignInfo* oaInfoXML = nullptr; - std::vector::iterator it; - for( it=oaList_.opticalAlignments_.begin();it!=oaList_.opticalAlignments_.end(); ++it ){ - std::string oaName = oaInfo.name_.substr( 1, oaInfo.name_.size()-2 ); - - if(ALIUtils::debug >= 5) { - std::cout << "CocoaAnalyzer::FindOpticalAlignInfoXML: looking for OAI " << (*it).name_ << " =? " << oaName << std::endl; +/* + * Correct an OpticalAlignment parameter from IdealGeometry with the value from DB. + */ +void CocoaAnalyzer::correctOpticalAlignmentParameter(OpticalAlignParam& myXMLParam, + const OpticalAlignParam& myDBParam) { + if (myDBParam.value_ != -9.999E9) { + const std::string& type = myDBParam.dimType(); + double dimFactor = 1.; + + if (type == "centre" || type == "length") { + dimFactor = 1. / 1._m; // in DB it is in cm + } else if (type == "angles" || type == "angle" || type == "nodim") { + dimFactor = 1.; + } else { + edm::LogError("Alignment") << "Incorrect OpticalAlignParam type = " << type; } - if( (*it).name_ == oaName ) { - oaInfoXML = &(*it); - if(ALIUtils::debug >= 4) { - std::cout << "CocoaAnalyzer::FindOpticalAlignInfoXML: OAI found " << oaInfoXML->name_ << std::endl; - } - break; + + const double correctedValue = myDBParam.value_ * dimFactor; + if (ALIUtils::debug >= 4) { + edm::LogInfo("Alignment") << "CocoaAnalyzer::correctOpticalAlignmentParameter old value= " << myXMLParam.value_ + << " new value= " << correctedValue; } + myXMLParam.value_ = correctedValue; } - - return oaInfoXML; } - -//------------------------------------------------------------------------ -bool CocoaAnalyzer::CorrectOaParam( OpticalAlignParam* oaParamXML, const OpticalAlignParam& oaParamDB ) -{ - if(ALIUtils::debug >= 4) { - std::cout << "CocoaAnalyzer::CorrectOaParam old value= " << oaParamXML->value_ << " new value= " << oaParamDB.value_ << std::endl; - } - if( oaParamDB.value_ == -9.999E9 ) return false; - - double dimFactor = 1.; - //loop for an Entry with equal type to entries to know which is the - std::string type = oaParamDB.dimType(); - if( type == "centre" || type == "length" ) { - dimFactor = 0.01; // in DB it is in cm - }else if ( type == "angles" || type == "angle" || type == "nodim" ){ - dimFactor = 1.; - }else { - std::cerr << "!!! COCOA programming error: inform responsible: incorrect OpticalAlignParam type = " << type << std::endl; - std::exception(); +/* + * Collect all information, do the fitting, and store results in DB. + */ +void CocoaAnalyzer::runCocoa() { + if (ALIUtils::debug >= 3) { + edm::LogInfo("Alignment") << "$$$ CocoaAnalyzer::runCocoa: "; } - oaParamXML->value_ = oaParamDB.value_*dimFactor; - - return true; - -} - - -//-#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h" -//-#include "Alignment/CocoaUtilities/interface/ALIFileIn.h" + // Geometry model built from XML file (corrected with values from DB) + Model& model = Model::getInstance(); + model.BuildSystemDescriptionFromOA(oaList_); -//----------------------------------------------------------------------- -void CocoaAnalyzer::analyze(const edm::Event& evt, const edm::EventSetup& evts) -{ - ALIUtils::setDebugVerbosity( 5 ); + if (ALIUtils::debug >= 3) { + edm::LogInfo("Alignment") << "$$ CocoaAnalyzer::runCocoa: geometry built "; + } - ReadXMLFile( evts ); + // Build measurements + model.BuildMeasurementsFromOA(measList_); - std::vector oaListCalib = ReadCalibrationDB( evts ); + if (ALIUtils::debug >= 3) { + edm::LogInfo("Alignment") << "$$ CocoaAnalyzer::runCocoa: measurements built "; + } - CorrectOptAlignments( oaListCalib ); + // Do fit and store results in DB + Fit::getInstance(); + Fit::startFit(); - new CocoaDaqReaderRoot( theCocoaDaqRootFileName ); - - /*- - int nEvents = daqReader->GetNEvents(); - for( int ii = 0; ii < nEvents; ii++) { - if( ! daqReader->ReadEvent( ii ) ) break; - } - */ - - RunCocoa(); - - // std::cout << "!!!! NOT DumpCocoaResults() " << std::endl; - - // CocoaDBMgr::getInstance()->DumpCocoaResults(); - - return; - - - // using namespace edm::eventsetup; - // std::cout <<" I AM IN RUN NUMBER "< oaESHandle; -// context.get().get(oaESHandle); - -// // This assumes they ALL come in together. This may not be -// // the "real" case. One could envision different objects coming -// // in and we would get by label each one (type). - -// std::cout << "========== eventSetup data changes with IOV =========" << std::endl; -// std::cout << *oaESHandle << std::endl; -// //============== COCOA WORK! -// // calibrated values should be used to "correct" the ones read in during beginJob -// //============== - -// // -// // to see how to iterate over the OpticalAlignments, please -// // refer to the << operator of OpticalAlignments, OpticalAlignInfo -// // and OpticalAlignParam. -// // const OpticalAlignments* myoa=oa.product(); - -// // STEP 3: -// // This retrieves the Measurements -// // for each event, a new set of measurements is available. -// edm::Handle measHandle; -// evt.getByLabel("OptAlignGeneratedSource", measHandle); - - -// std::cout << "========== event data product changes with every event =========" << std::endl; -// std::cout << *measHandle << std::endl; - - //============== COCOA WORK! - // Each set of optical alignment measurements can be used - // in whatever type of analysis COCOA does. - //============== - -} //end of ::analyze() - -// STEP 4: one could use ::endJob() to write out the OpticalAlignments -// generated by the analysis. Example code of writing is in -// CondFormats/Alignment/test/testOptAlignWriter.cc - - -//----------------------------------------------------------------------- -double CocoaAnalyzer::myFetchDbl(const DDsvalues_type& dvst, - const std::string& spName, - const size_t& vecInd ) { - DDValue val(spName, 0.0); - if (DDfetch(&dvst,val)) { - if ( val.doubles().size() > vecInd ) { - // std::cout << "about to return: " << val.doubles()[vecInd] << std::endl; - return val.doubles()[vecInd]; - } else { - std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << std::endl; - } + if (ALIUtils::debug >= 0) + edm::LogInfo("Alignment") << "............ program ended OK"; + if (ALIUtils::report >= 1) { + ALIFileOut& fileout = ALIFileOut::getInstance(Model::ReportFName()); + fileout << "............ program ended OK"; } - return 0.0; } -//----------------------------------------------------------------------- -std::string CocoaAnalyzer::myFetchString(const DDsvalues_type& dvst, - const std::string& spName, - const size_t& vecInd ) { - DDValue val(spName, 0.0); - if (DDfetch(&dvst,val)) { - if ( val.strings().size() > vecInd ) { - // std::cout << "about to return: " << val.doubles()[vecInd] << std::endl; - return val.strings()[vecInd]; - } else { - std::cout << "WARNING: OUT OF BOUNDS RETURNING 0 for index " << vecInd << " of SpecPar " << spName << 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. + * 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 +std::vector 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>(parameterName); } } - return ""; + + return std::vector(); } +/* 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 +T CocoaAnalyzer::getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections, + const std::string& nodePath, + const std::string& parameterName, + const unsigned int parameterValueIndex) { + const std::vector& allParameterValues = + getAllParameterValuesFromSpecParSections(allSpecParSections, nodePath, parameterName); + if (parameterValueIndex < allParameterValues.size()) { + return allParameterValues.at(parameterValueIndex); + } + return T(); +} diff --git a/Alignment/CocoaApplication/test/OpticalAlignments.db b/Alignment/CocoaApplication/test/OpticalAlignments.db index b460a70969f7b886bc008c1c543a445b2b333110..50944ced13d4359cb161003291882e8594567a22 100644 GIT binary patch literal 69632 zcmeI5e{9>>5!?ENZGoR zrBqUqCTZ(9&DsLH7Kb80yY32fxIfzcGqitnKzj$IINZ8+IIO$v3S69^l3mA1dtV|kDZa<=kI(zQM}8kgYVNMdTt)F`i={=W;%9A}Yy@E& z_4{o$n;reX0sYq&7ux93KA<&W*lx9Hx9z;;#a`dXwqDnHoA;>ipL;L${A=$&beDQw za{p&{jC#fWs_Q)UK&!)HKM(){KmZ5;f&V`QmX#jYz~CV9Fjuv={1!HhxC~z=3IWaboJRI;J zm`qF~5!2&FMq}~0*zCkiaw0L^Ok_4b8IR6cke!>3&dlvkBvZ)=6+HSomyAx$7$r|k z&&6l4+!ZRB$*OiEdTh6IV0>!_^bF*B&fZ122DWS=&Ye`L;l`XyjMr9fGq2iS6;{hu z55y0~r&sjw0CLbeVgmaUbIBG(vBcC=blM^;qcQ7NP}ShrZfYPiKHZZcqv=C|n%u!5 z|Gva*d}4gM8pnF|LH}%gUwk$`9gEMQ?l!(Xpf$v>+c^;3(yAe_0E9S2*ET$7Z+E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Xi3i>V_$K#r?%Uj#xesxtI4`#a zvgp^HRw&+PjhF ztmU_39$pnW6`MXaf4cXwv@o4JJ$Z7T=8Z39cU7@cu@&ARkMZ;jY&)UZ*vZ*3I9PcC z^&WZEbk9Q%f3I!>D-oM94<$<_qB|xh=1-&Ev(k!ud!>}67K{OjEb*L%ZR=@bC9cKB z3g`uUXl6QQkFRF8RV32rYBn`(T_UYql~$feD^sPFCDM3R8lOlrsnSe|G@~lbm`F3I z(hP|-qDmu)G;U?uPEJa*0IoDm>PY)?yeA*FVksSZ2a=IJ-g}TC-hC9YYH|dT-;kHd zv#|RAXLu9X!{kBom*g|#6Xb*BPBIUt0w0Gg`lTbFBajyY zH^?DWDTNTKSTBdxRmh?8b#kbzTn_PNa>&HXA)`qS8H{p>7~~K~!Fv^a66StPh! zsf|gOC9lOv?!^mTCa!w@QqVF1RN4Zya!_gussU8m{IznnZc!1G+U@c&7_g9rAO$na zidtH5$Ma=hUBlW^UWUgDv^5NDHJOjKW*S;)Mu02*x^_RzJ;T7Z0t<7eEzIqv`aj2g z9g&;ire8V&R|f*3jWae~vZ}o)>C3b8dhz8kUntt0cm+YpUgjOI+ckrf1W_(dGf^7(e*l&Is!TZ84=h*n$%p8+e%thv6K + + + + + + + + + + diff --git a/Alignment/CocoaApplication/test/cocoaAnalyzer_cfg.py b/Alignment/CocoaApplication/test/cocoaAnalyzer_cfg.py new file mode 100644 index 0000000000000..021816597169b --- /dev/null +++ b/Alignment/CocoaApplication/test/cocoaAnalyzer_cfg.py @@ -0,0 +1,84 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("TestCocoa") + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.MessageLogger.debugModules = cms.untracked.vstring('cocoa') +process.MessageLogger.cout = cms.untracked.PSet( + threshold = cms.untracked.string('DEBUG') +) + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) ) + +# A data source must always be defined. We don't need it, so here's a dummy one. +process.source = cms.Source("EmptyIOVSource", + timetype = cms.string('runnumber'), + firstValue = cms.uint64(1), + lastValue = cms.uint64(1), + interval = cms.uint64(1) +) + + +# dd4hep-based geometry +process.DDDetectorESProducer = cms.ESSource("DDDetectorESProducer", + confGeomXMLFiles = cms.FileInPath('Alignment/CocoaApplication/test/cmsCocoaTable2DWithMirror.xml'), + appendToDataLabel = cms.string('') + ) + +process.DDCompactViewESProducer = cms.ESProducer("DDCompactViewESProducer", + appendToDataLabel = cms.string('') + ) + + +process.load("CondCore.CondDB.CondDB_cfi") +process.CondDB.connect = 'sqlite_file:OpticalAlignments.db' + + +# Read DB: this is used to correct internal geometry with geo from DB. +process.PoolDBESSource = cms.ESSource("PoolDBESSource", + process.CondDB, + DumpStat=cms.untracked.bool(True), + toGet = cms.VPSet(cms.PSet( + record = cms.string('OpticalAlignmentsRcd'), + tag = cms.string("OpticalAlignmentsRcdInput") + )), +) + + +# Write COCOA output to DB ('Output tag') +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + process.CondDB, + timetype = cms.untracked.string('runnumber'), + toPut = cms.VPSet( + cms.PSet( + record = cms.string('OpticalAlignmentsRcd'), + tag = cms.string('OpticalAlignmentsRcdOutput') + ), + cms.PSet( + record = cms.string('DTAlignmentRcd'), + tag = cms.string('DTAlignmentRcdOutput') + ), + cms.PSet( + record = cms.string('DTAlignmentErrorExtendedRcd'), + tag = cms.string('DTAlignmentErrorExtendedRcdOutput') + ), + cms.PSet( + record = cms.string('CSCAlignmentRcd'), + tag = cms.string('CSCAlignmentRcdOutput') + ), + cms.PSet( + record = cms.string('CSCAlignmentErrorExtendedRcd'), + tag = cms.string('CSCAlignmentErrorExtendedRcdOutput') + ), + ) +) + + +# Run COCOA +process.cocoa = cms.EDAnalyzer('CocoaAnalyzer', + maxEvents = cms.int32(1), + cocoaDaqRootFile = cms.string("cocoaDaqTest.root") + ) + +process.p = cms.Path(process.cocoa) + diff --git a/Alignment/CocoaApplication/test/table2DWithMirror.xml b/Alignment/CocoaApplication/test/table2DWithMirror.xml index db979e6a6a681..69376dff18d3f 100644 --- a/Alignment/CocoaApplication/test/table2DWithMirror.xml +++ b/Alignment/CocoaApplication/test/table2DWithMirror.xml @@ -1,303 +1,312 @@ - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Alignment/CocoaFit/src/CocoaDBMgr.cc b/Alignment/CocoaFit/src/CocoaDBMgr.cc index 12f00903d6182..3b54402d34106 100644 --- a/Alignment/CocoaFit/src/CocoaDBMgr.cc +++ b/Alignment/CocoaFit/src/CocoaDBMgr.cc @@ -3,6 +3,7 @@ #include "CondFormats/Alignment/interface/AlignTransform.h" #include "CondFormats/Alignment/interface/AlignTransformErrorExtended.h" #include "DataFormats/GeometryCommonDetAlgo/interface/GlobalError.h" +#include "DataFormats/Math/interface/CMSUnits.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "CondCore/DBOutputService/interface/PoolDBOutputService.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -31,6 +32,8 @@ #include "CondCore/CondDB/interface/Serialization.h" +using namespace cms_units::operators; + CocoaDBMgr* CocoaDBMgr::instance = nullptr; //---------------------------------------------------------------------- @@ -165,7 +168,7 @@ bool CocoaDBMgr::DumpCocoaResults() { //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ OpticalAlignInfo CocoaDBMgr::GetOptAlignInfoFromOptO(OpticalObject* opto) { - std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO " << opto->name() << std::endl; + LogDebug("Alignment") << " CocoaDBMgr::GetOptAlignInfoFromOptO " << opto->name(); OpticalAlignInfo data; data.ID_ = opto->getCmsswID(); data.type_ = opto->type(); @@ -177,48 +180,80 @@ OpticalAlignInfo CocoaDBMgr::GetOptAlignInfoFromOptO(OpticalObject* opto) { centreLocal = parentRmGlobInv * centreLocal; const std::vector& theCoordinateEntryVector = opto->CoordinateEntryList(); - std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO starting coord " << std::endl; - - data.x_.value_ = centreLocal.x() / 100.; // in cm - std::cout << " matrix " << Fit::GetAtWAMatrix() << std::endl; - std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[0]->fitPos() << std::endl; - data.x_.error_ = GetEntryError(theCoordinateEntryVector[0]) / 100.; // in cm - - data.y_.value_ = centreLocal.y() / 100.; // in cm - std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[1]->fitPos() << std::endl; - data.y_.error_ = GetEntryError(theCoordinateEntryVector[1]) / 100.; // in cm - - data.z_.value_ = centreLocal.z() / 100.; // in cm - std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << " " << theCoordinateEntryVector[2]->fitPos() << std::endl; - data.z_.error_ = GetEntryError(theCoordinateEntryVector[2]) / 100.; // in cm - - //----- angles in local coordinates - std::vector anglocal = opto->getLocalRotationAngles(theCoordinateEntryVector); - - data.angx_.value_ = anglocal[0] * 180. / M_PI; // in deg - std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[3]->fitPos() << std::endl; - data.angx_.error_ = GetEntryError(theCoordinateEntryVector[3]) * 180. / M_PI; // in deg; - - data.angy_.value_ = anglocal[1] * 180. / M_PI; // in deg - std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[4]->fitPos() << std::endl; - data.angy_.error_ = GetEntryError(theCoordinateEntryVector[4]) * 180. / M_PI; // in deg;; - - data.angz_.value_ = anglocal[2] * 180. / M_PI; // in deg - std::cout << " matrix " << Fit::GetAtWAMatrix()->Mat() << theCoordinateEntryVector[5]->fitPos() << std::endl; - data.angz_.error_ = GetEntryError(theCoordinateEntryVector[5]) * 180. / M_PI; // in deg; + LogDebug("Alignment") << " CocoaDBMgr::GetOptAlignInfoFromOptO starting coord "; + 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.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.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.quality_ = translationZ->quality(); + data.z_ = translationZDataForDB; + + //----- angles in local coordinates + std::vector anglocal = opto->getLocalRotationAngles(theCoordinateEntryVector); + if (anglocal.size() == 3) { + const Entry* const rotationX = theCoordinateEntryVector.at(3); + OpticalAlignParam rotationXDataForDB; + rotationXDataForDB.name_ = rotationX->name(); + rotationXDataForDB.dim_type_ = rotationX->type(); + rotationXDataForDB.value_ = anglocal.at(0); + rotationXDataForDB.error_ = GetEntryError(rotationX); + rotationXDataForDB.quality_ = rotationX->quality(); + data.angx_ = rotationXDataForDB; + + const Entry* const rotationY = theCoordinateEntryVector.at(4); + OpticalAlignParam rotationYDataForDB; + rotationYDataForDB.name_ = rotationY->name(); + rotationYDataForDB.dim_type_ = rotationY->type(); + rotationYDataForDB.value_ = anglocal.at(1); + rotationYDataForDB.error_ = GetEntryError(rotationY); + rotationYDataForDB.quality_ = rotationY->quality(); + data.angy_ = rotationYDataForDB; + + const Entry* const rotationZ = theCoordinateEntryVector.at(5); + OpticalAlignParam rotationZDataForDB; + rotationZDataForDB.name_ = rotationZ->name(); + rotationZDataForDB.dim_type_ = rotationZ->type(); + rotationZDataForDB.value_ = anglocal.at(2); + rotationZDataForDB.error_ = GetEntryError(rotationZ); + rotationZDataForDB.quality_ = rotationZ->quality(); + data.angz_ = rotationZDataForDB; + } + } - const std::vector& theExtraEntryVector = opto->ExtraEntryList(); std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO starting entry " << std::endl; - - std::vector::const_iterator ite; - for (ite = theExtraEntryVector.begin(); ite != theExtraEntryVector.end(); ++ite) { + for (const auto& myDBExtraEntry : opto->ExtraEntryList()) { OpticalAlignParam extraEntry; - extraEntry.name_ = (*ite)->name(); - extraEntry.dim_type_ = (*ite)->type(); - extraEntry.value_ = (*ite)->value(); - extraEntry.error_ = (*ite)->sigma(); - extraEntry.quality_ = (*ite)->quality(); - data.extraEntries_.push_back(extraEntry); + extraEntry.name_ = myDBExtraEntry->name(); + extraEntry.dim_type_ = myDBExtraEntry->type(); + extraEntry.value_ = myDBExtraEntry->value(); + extraEntry.error_ = myDBExtraEntry->sigma(); + if (extraEntry.dim_type_ == "centre" || extraEntry.dim_type_ == "length") { + extraEntry.value_ *= 1._m; // m in COCOA, cm in DB + extraEntry.error_ *= 1._m; // m in COCOA, cm in DB + } + extraEntry.quality_ = myDBExtraEntry->quality(); + data.extraEntries_.emplace_back(extraEntry); std::cout << " CocoaDBMgr::GetOptAlignInfoFromOptO done extra entry " << extraEntry.name_ << std::endl; } @@ -330,12 +365,12 @@ AlignTransformErrorExtended* CocoaDBMgr::GetAlignInfoErrorFromOptO(OpticalObject CLHEP::HepMatrix errm(3, 3); const std::vector& theCoordinateEntryVector = opto->CoordinateEntryList(); std::cout << "@@@ CocoaDBMgr::GetAlignInfoFromOptOfill errm " << opto->name() << std::endl; - errm(0, 0) = GetEntryError(theCoordinateEntryVector[0]) / 100.; // in cm - errm(1, 1) = GetEntryError(theCoordinateEntryVector[1]) / 100.; // in cm - errm(2, 2) = GetEntryError(theCoordinateEntryVector[2]) / 100.; // in cm - errm(0, 1) = GetEntryError(theCoordinateEntryVector[0], theCoordinateEntryVector[1]) / 100.; // in cm - errm(0, 2) = GetEntryError(theCoordinateEntryVector[0], theCoordinateEntryVector[2]) / 100.; // in cm - errm(1, 2) = GetEntryError(theCoordinateEntryVector[1], theCoordinateEntryVector[2]) / 100.; // in cm + errm(0, 0) = GetEntryError(theCoordinateEntryVector[0]) * 1._m; // m in COCOA, cm in DB + errm(1, 1) = GetEntryError(theCoordinateEntryVector[1]) * 1._m; // m in COCOA, cm in DB + errm(2, 2) = GetEntryError(theCoordinateEntryVector[2]) * 1._m; // m in COCOA, cm in DB + errm(0, 1) = GetEntryError(theCoordinateEntryVector[0], theCoordinateEntryVector[1]) * 1._m; // m in COCOA, cm in DB + errm(0, 2) = GetEntryError(theCoordinateEntryVector[0], theCoordinateEntryVector[2]) * 1._m; // m in COCOA, cm in DB + errm(1, 2) = GetEntryError(theCoordinateEntryVector[1], theCoordinateEntryVector[2]) * 1._m; // m in COCOA, cm in DB // errm(1,0) = errm(0,1); // errm(2,0) = errm(0,2); // errm(2,1) = errm(1,2); diff --git a/Alignment/CocoaUtilities/interface/ALIUtils.h b/Alignment/CocoaUtilities/interface/ALIUtils.h index 965729b7cab66..5772049595d4b 100644 --- a/Alignment/CocoaUtilities/interface/ALIUtils.h +++ b/Alignment/CocoaUtilities/interface/ALIUtils.h @@ -89,7 +89,7 @@ class ALIUtils { static ALIdouble getMaximumDeviationDerivative() { return maximum_deviation_derivative; } static void setMaximumDeviationDerivative(ALIdouble val) { maximum_deviation_derivative = val; } - static std::vector getRotationAnglesFromMatrix(CLHEP::HepRotation& rmLocal, + static std::vector getRotationAnglesFromMatrix(const CLHEP::HepRotation& rmLocal, double origAngleX, double origAngleY, double origAngleZ); @@ -97,7 +97,7 @@ class ALIUtils { static bool eq2ang(double ang1, double ang2); static double approxTo0(double val); static double addPii(double val); - static int checkMatrixEquations(double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot); + static int checkMatrixEquations(double angleX, double angleY, double angleZ, const CLHEP::HepRotation& rot); private: static ALIdouble _LengthValueDimensionFactor; diff --git a/Alignment/CocoaUtilities/src/ALIUtils.cc b/Alignment/CocoaUtilities/src/ALIUtils.cc index ca34c6e25ddb8..d0c03f1cdfc42 100644 --- a/Alignment/CocoaUtilities/src/ALIUtils.cc +++ b/Alignment/CocoaUtilities/src/ALIUtils.cc @@ -12,7 +12,7 @@ #include #include -ALIint ALIUtils::debug = -1; +ALIint ALIUtils::debug = 99; ALIint ALIUtils::report = 1; ALIdouble ALIUtils::_LengthValueDimensionFactor = 1.; ALIdouble ALIUtils::_LengthSigmaDimensionFactor = 1.; @@ -546,7 +546,7 @@ std::string ALIUtils::changeName(const std::string& oldName, const std::string& } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -std::vector ALIUtils::getRotationAnglesFromMatrix(CLHEP::HepRotation& rmLocal, +std::vector ALIUtils::getRotationAnglesFromMatrix(const CLHEP::HepRotation& rmLocal, double origAngleX, double origAngleY, double origAngleZ) { @@ -691,7 +691,7 @@ std::vector ALIUtils::getRotationAnglesFromMatrix(CLHEP::HepRotation& rm } // double rotnewyx = cos( newang[1] ) * sin( newang[2] ); - if (checkMatrixEquations(newang[0], newang[1], newang[2], &rmLocal) != 0) { + if (checkMatrixEquations(newang[0], newang[1], newang[2], rmLocal) != 0) { std::cerr << " wrong rotation matrix " << newang[0] << " " << newang[1] << " " << newang[2] << std::endl; ALIUtils::dumprm(rmLocal, " matrix is "); } @@ -759,14 +759,7 @@ double ALIUtils::addPii(double val) { } //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -int ALIUtils::checkMatrixEquations(double angleX, double angleY, double angleZ, CLHEP::HepRotation* rot) { - //- std::cout << " cme " << angleX << " " << angleY << " " << angleZ << std::endl; - if (rot == nullptr) { - rot = new CLHEP::HepRotation(); - rot->rotateX(angleX); - rot->rotateY(angleY); - rot->rotateZ(angleZ); - } +int ALIUtils::checkMatrixEquations(double angleX, double angleY, double angleZ, const CLHEP::HepRotation& rot) { double sx = sin(angleX); double cx = cos(angleX); double sy = sin(angleY); @@ -785,43 +778,11 @@ int ALIUtils::checkMatrixEquations(double angleX, double angleY, double angleZ, double rotzz = cx * cy; int matrixElemBad = 0; - if (!eq2ang(rot->xx(), rotxx)) { - std::cerr << " EQUATION for xx() IS BAD " << rot->xx() << " <> " << rotxx << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->xy(), rotxy)) { - std::cerr << " EQUATION for xy() IS BAD " << rot->xy() << " <> " << rotxy << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->xz(), rotxz)) { - std::cerr << " EQUATION for xz() IS BAD " << rot->xz() << " <> " << rotxz << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->yx(), rotyx)) { - std::cerr << " EQUATION for yx() IS BAD " << rot->yx() << " <> " << rotyx << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->yy(), rotyy)) { - std::cerr << " EQUATION for yy() IS BAD " << rot->yy() << " <> " << rotyy << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->yz(), rotyz)) { - std::cerr << " EQUATION for yz() IS BAD " << rot->yz() << " <> " << rotyz << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->zx(), rotzx)) { - std::cerr << " EQUATION for zx() IS BAD " << rot->zx() << " <> " << rotzx << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->zy(), rotzy)) { - std::cerr << " EQUATION for zy() IS BAD " << rot->zy() << " <> " << rotzy << std::endl; - matrixElemBad++; - } - if (!eq2ang(rot->zz(), rotzz)) { - std::cerr << " EQUATION for zz() IS BAD " << rot->zz() << " <> " << rotzz << std::endl; + 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++; } - //- std::cout << " cme: matrixElemBad " << matrixElemBad << std::endl; return matrixElemBad; } diff --git a/Alignment/CocoaUtilities/src/GlobalOptionMgr.cc b/Alignment/CocoaUtilities/src/GlobalOptionMgr.cc index 2fff48aae433b..f10a1fc155dff 100644 --- a/Alignment/CocoaUtilities/src/GlobalOptionMgr.cc +++ b/Alignment/CocoaUtilities/src/GlobalOptionMgr.cc @@ -79,7 +79,7 @@ void GlobalOptionMgr::setDefaultGlobalOptions() { theGlobalOptions[ALIstring("stopAfter1stIteration")] = 0; theGlobalOptions[ALIstring("calParamInyfMatrix")] = 0; - theGlobalOptions[ALIstring("writeXML")] = 0; + theGlobalOptions[ALIstring("writeXML")] = 1; theGlobalOptions[ALIstring("dumpInAllFrames")] = 0; theGlobalOptions[ALIstring("rootResults")] = 0; theGlobalOptions[ALIstring("writeDBAlign")] = 0;