4 #include <DD4hep/DD4hepUnits.h> 62 usesResource(
"CocoaAnalyzer");
95 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML: world object = " << worldVolume.name();
100 worldInfo.
name_ = worldVolume.name();
101 worldInfo.
type_ =
"system";
136 const std::string cocoaParameterAttribute =
"COCOA";
140 allSpecParSections.filter(cocoaParameterSpecParSections, cocoaParameterAttribute, cocoaParameterValue);
162 oaInfo.
name_ = nodePath;
165 oaInfo.
parentName_ = nodePath.substr(0, nodePath.rfind(
'/', nodePath.length()));
168 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML reading object " <<
name;
177 const dd4hep::Direction& transl = myPlacedVolume.position();
180 edm::LogInfo(
"Alignment") <<
"Local translation in dd4hep units = " << transl;
188 oaInfo.
x_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
194 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_X_quality", 0));
199 oaInfo.
y_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
205 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_Y_quality", 0));
210 oaInfo.
z_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
216 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_Z_quality", 0));
228 const TGeoHMatrix parentToChild = myPlacedVolume.matrix();
230 const TGeoHMatrix& childToParent = parentToChild.Inverse();
235 const Double_t*
rot = childToParent.GetRotationMatrix();
236 const double xx =
rot[0];
237 const double xy =
rot[1];
238 const double xz =
rot[2];
239 const double yx =
rot[3];
240 const double yy =
rot[4];
241 const double yz =
rot[5];
242 const double zx =
rot[6];
243 const double zy =
rot[7];
244 const double zz =
rot[8];
251 const CLHEP::Hep3Vector colX(
xx, yx, zx);
252 const CLHEP::Hep3Vector colY(
xy,
yy, zy);
253 const CLHEP::Hep3Vector colZ(
xz,
yz,
zz);
254 const CLHEP::HepRotation rotclhep(colX, colY, colZ);
262 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_value", 0);
264 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_sigma", 0);
266 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_quality", 0));
271 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_value", 0);
273 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_sigma", 0);
275 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_quality", 0));
280 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_value", 0);
282 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_sigma", 0);
284 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_quality", 0));
287 cms::getParameterValueFromSpecParSections<std::string>(allSpecParSections, nodePath,
"cocoa_type", 0);
289 oaInfo.
ID_ =
static_cast<int>(
290 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"cmssw_ID", 0));
293 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML OBJECT " << oaInfo.
name_ <<
" pos/angles read ";
307 const std::vector<std::string>&
names =
308 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"extra_entry");
309 const std::vector<std::string>& dims =
310 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"dimType");
311 const std::vector<double>&
values =
312 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"value");
313 const std::vector<double>&
errors =
314 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"sigma");
315 const std::vector<double>&
quality =
316 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"quality");
319 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML: Fill extra entries with read parameters ";
324 for (
size_t i = 0;
i <
names.size(); ++
i) {
325 double dimFactor = 1.;
327 if (
type ==
"centre" ||
type ==
"length") {
330 }
else if (
type ==
"angles" ||
type ==
"angle" ||
type ==
"nodim") {
344 edm::LogInfo(
"Alignment") <<
"WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do" 345 <<
" not match! Did not add " << nObjects <<
" item to OpticalAlignments.";
349 const std::vector<std::string>& measNames =
350 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"meas_name");
351 const std::vector<std::string>& measTypes =
352 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"meas_type");
354 std::map<std::string, std::vector<std::string>> measObjectNames;
355 std::map<std::string, std::vector<std::string>> measParamNames;
356 std::map<std::string, std::vector<double>> measParamValues;
357 std::map<std::string, std::vector<double>> measParamSigmas;
358 std::map<std::string, std::vector<double>> measIsSimulatedValue;
359 for (
const auto&
name : measNames) {
360 measObjectNames[
name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
361 allSpecParSections, nodePath,
"meas_object_name_" +
name);
362 measParamNames[
name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
363 allSpecParSections, nodePath,
"meas_value_name_" +
name);
364 measParamValues[
name] =
365 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"meas_value_" +
name);
366 measParamSigmas[
name] =
367 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"meas_sigma_" +
name);
368 measIsSimulatedValue[
name] = cms::getAllParameterValuesFromSpecParSections<double>(
369 allSpecParSections, nodePath,
"meas_is_simulated_value_" +
name);
373 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML: Fill measurements with read parameters ";
376 if (measNames.size() == measTypes.size()) {
377 for (
size_t i = 0;
i < measNames.size(); ++
i) {
379 oaMeas.
name_ = measNames[
i];
380 oaMeas.
type_ = measTypes[
i];
382 if (measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size()) {
383 for (
size_t i2 = 0;
i2 < measParamNames[oaMeas.
name_].size();
i2++) {
388 if (oaMeas.
type_ ==
"SENSOR2D" || oaMeas.
type_ ==
"COPS" || oaMeas.
type_ ==
"DISTANCEMETER" ||
389 oaMeas.
type_ ==
"DISTANCEMETER!DIM" || oaMeas.
type_ ==
"DISTANCEMETER3DIM") {
391 }
else if (oaMeas.
type_ ==
"TILTMETER") {
394 edm::LogError(
"Alignment") <<
"CocoaAnalyzer::readXMLFile. Invalid measurement type: " << oaMeas.
type_;
397 oaMeas.
values_.emplace_back(oaParam);
402 << measIsSimulatedValue[oaMeas.
name_][
i2];
408 edm::LogWarning(
"Alignment") <<
"WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do" 409 <<
" not match! for measurement " << oaMeas.
name_ 410 <<
" !Did not fill parameters for this measurement ";
415 edm::LogInfo(
"Alignment") <<
"CocoaAnalyser: MEASUREMENT " << oaMeas.
name_ <<
" extra entries read " 423 edm::LogWarning(
"Alignment") <<
"WARNING FOR NOW: sizes of measurements (names, types do" 424 <<
" not match! Did not add " << nObjects <<
" item to XXXMeasurements";
433 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML: Finished building " << nObjects + 1
434 <<
" OpticalAlignInfo objects" 436 <<
" OpticalAlignMeasurementInfo objects ";
451 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::readCalibrationDB: ";
459 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ " 460 << infoFromDB.size();
461 for (
const auto& myInfoFromDB : infoFromDB) {
462 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::readCalibrationDB: OpticalAlignInfo READ " << myInfoFromDB;
474 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::correctAllOpticalAlignments: ";
477 for (
const auto& myDBInfo : allDBOpticalAlignments) {
479 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::findOpticalAlignInfoXML: Looking for OAI " << myDBInfo.name_;
483 const auto& myXMLInfo = std::find_if(
484 allXMLOpticalAlignments.begin(), allXMLOpticalAlignments.end(), [&](
const auto& myXMLInfoCandidate) {
485 return myXMLInfoCandidate.name_ == myDBInfo.name_;
488 if (myXMLInfo != allXMLOpticalAlignments.end()) {
490 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::findOpticalAlignInfoXML: OAI found " << myXMLInfo->name_;
492 <<
"CocoaAnalyzer::correctAllOpticalAlignments: correcting data from XML with DB info.";
502 const std::vector<OpticalAlignParam>& allDBExtraEntries = myDBInfo.extraEntries_;
503 std::vector<OpticalAlignParam>& allXMLExtraEntries = myXMLInfo->extraEntries_;
504 for (
const auto& myDBExtraEntry : allDBExtraEntries) {
505 const auto& myXMLExtraEntry = std::find_if(
506 allXMLExtraEntries.begin(), allXMLExtraEntries.end(), [&](
const auto& myXMLExtraEntryCandidate) {
507 return myXMLExtraEntryCandidate.name_ == myDBExtraEntry.name_;
510 if (myXMLExtraEntry != allXMLExtraEntries.end()) {
513 if (myDBExtraEntry.name_ !=
"None") {
516 <<
"CocoaAnalyzer::correctAllOpticalAlignments: extra entry read from DB is not present in XML " 517 << myDBExtraEntry <<
" in object " << myDBInfo;
524 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::correctAllOpticalAlignments: corrected OpticalAlingInfo " 529 edm::LogError(
"Alignment") <<
"CocoaAnalyzer::correctAllOpticalAlignments: OpticalAlignInfo read from DB " 530 << myDBInfo <<
" is not present in XML.";
541 if (myDBParam.
value_ != -9.999E9) {
543 double dimFactor = 1.;
545 if (
type ==
"centre" ||
type ==
"length") {
547 }
else if (
type ==
"angles" ||
type ==
"angle" ||
type ==
"nodim") {
553 const double correctedValue = myDBParam.
value_ * dimFactor;
555 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::correctOpticalAlignmentParameter old value= " << myXMLParam.
value_ 556 <<
" new value= " << correctedValue;
558 myXMLParam.
value_ = correctedValue;
567 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::runCocoa: ";
575 edm::LogInfo(
"Alignment") <<
"$$ CocoaAnalyzer::runCocoa: geometry built ";
582 edm::LogInfo(
"Alignment") <<
"$$ CocoaAnalyzer::runCocoa: measurements built ";
590 edm::LogInfo(
"Alignment") <<
"............ program ended OK";
593 fileout <<
"............ program ended OK";
~CocoaAnalyzer() override
CocoaAnalyzer(edm::ParameterSet const &p)
void readXMLFile(const edm::EventSetup &evts)
std::string theCocoaDaqRootFileName_
void mergedSpecifics(DDSpecParRefs const &)
User specific data.
const std::string path() const
The full path to the current node.
dd4hep::SpecParRefs DDSpecParRefs
static std::vector< double > getRotationAnglesFromMatrix(const CLHEP::HepRotation &rmLocal, double origAngleX, double origAngleY, double origAngleZ)
#define DEFINE_FWK_MODULE(type)
std::vector< std::string > measObjectNames_
const cms::DDDetector * detector() const
static ALIstring & ReportFName()
the name of the report File
static Fit & getInstance()
DDSpecParRegistry const & specpars() const
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > ddcvToken
Log< level::Error, false > LogError
static GlobalOptionMgr * getInstance()
const std::string names[nVars_]
dd4hep::SpecParRegistry DDSpecParRegistry
void correctAllOpticalAlignments(std::vector< OpticalAlignInfo > &allDBOpticalAlignments)
std::vector< OpticalAlignInfo > opticalAlignments_
dd4hep::PlacedVolume PlacedVolume
edm::ESGetToken< OpticalAlignments, OpticalAlignmentsRcd > optAliToken
static Model & getInstance()
-------— Gets the only instance of this class
bool getData(T &iHolder) const
std::vector< OpticalAlignMeasurementInfo > oaMeasurements_
bool firstChild()
set the current node to the first child
void setGlobalOption(const ALIstring go, const ALIdouble val, ALIFileIn &filein)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Log< level::Info, false > LogInfo
void setDefaultGlobalOptions()
Set the list of default global options.
void correctOpticalAlignmentParameter(OpticalAlignParam &myXMLParam, const OpticalAlignParam &myDBParam)
dd4hep::Volume worldVolume() const
Handle to the world volume containing everything.
std::vector< OpticalAlignParam > extraEntries_
std::vector< OpticalAlignInfo > readCalibrationDB(const edm::EventSetup &evts)
OpticalAlignMeasurements measList_
static void setDebugVerbosity(ALIint val)
const PlacedVolume volume() const
The physical volume of the current node.
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
std::vector< OpticalAlignParam > values_
Log< level::Warning, false > LogWarning
static ALIFileOut & getInstance(const ALIstring &filename)
std::vector< bool > isSimulatedValue_
std::string dimType() const
OpticalAlignments oaList_