5 #include <DD4hep/DD4hepUnits.h>
61 usesResource(
"CocoaAnalyzer");
96 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML: world object = " << worldVolume.name();
101 worldInfo.
name_ = worldVolume.name();
102 worldInfo.
type_ =
"system";
137 const std::string cocoaParameterAttribute =
"COCOA";
141 allSpecParSections.filter(cocoaParameterSpecParSections, cocoaParameterAttribute, cocoaParameterValue);
163 oaInfo.
name_ = nodePath;
166 oaInfo.
parentName_ = nodePath.substr(0, nodePath.rfind(
'/', nodePath.length()));
169 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML reading object " <<
name;
178 const dd4hep::Direction& transl = myPlacedVolume.position();
181 edm::LogInfo(
"Alignment") <<
"Local translation in dd4hep units = " << transl;
189 oaInfo.
x_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
195 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_X_quality", 0));
200 oaInfo.
y_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
206 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_Y_quality", 0));
211 oaInfo.
z_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
217 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_Z_quality", 0));
229 const TGeoHMatrix parentToChild = myPlacedVolume.matrix();
231 const TGeoHMatrix& childToParent = parentToChild.Inverse();
236 const Double_t*
rot = childToParent.GetRotationMatrix();
237 const double xx =
rot[0];
238 const double xy =
rot[1];
239 const double xz =
rot[2];
240 const double yx =
rot[3];
241 const double yy =
rot[4];
242 const double yz =
rot[5];
243 const double zx =
rot[6];
244 const double zy =
rot[7];
245 const double zz =
rot[8];
252 const CLHEP::Hep3Vector colX(
xx, yx, zx);
253 const CLHEP::Hep3Vector colY(
xy,
yy, zy);
254 const CLHEP::Hep3Vector colZ(
xz,
yz,
zz);
255 const CLHEP::HepRotation rotclhep(colX, colY, colZ);
263 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_value", 0);
265 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_sigma", 0);
267 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_quality", 0));
272 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_value", 0);
274 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_sigma", 0);
276 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_quality", 0));
281 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_value", 0);
283 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_sigma", 0);
285 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_quality", 0));
288 cms::getParameterValueFromSpecParSections<std::string>(allSpecParSections, nodePath,
"cocoa_type", 0);
290 oaInfo.
ID_ = static_cast<int>(
291 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"cmssw_ID", 0));
294 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML OBJECT " << oaInfo.
name_ <<
" pos/angles read ";
308 const std::vector<std::string>&
names =
309 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"extra_entry");
310 const std::vector<std::string>& dims =
311 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"dimType");
312 const std::vector<double>&
values =
313 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"value");
314 const std::vector<double>&
errors =
315 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"sigma");
316 const std::vector<double>&
quality =
317 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"quality");
320 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML: Fill extra entries with read parameters ";
325 for (
size_t i = 0;
i <
names.size(); ++
i) {
326 double dimFactor = 1.;
328 if (
type ==
"centre" ||
type ==
"length") {
331 }
else if (
type ==
"angles" ||
type ==
"angle" ||
type ==
"nodim") {
345 edm::LogInfo(
"Alignment") <<
"WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do"
346 <<
" not match! Did not add " << nObjects <<
" item to OpticalAlignments.";
350 const std::vector<std::string>& measNames =
351 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"meas_name");
352 const std::vector<std::string>& measTypes =
353 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"meas_type");
355 std::map<std::string, std::vector<std::string>> measObjectNames;
356 std::map<std::string, std::vector<std::string>> measParamNames;
357 std::map<std::string, std::vector<double>> measParamValues;
358 std::map<std::string, std::vector<double>> measParamSigmas;
359 std::map<std::string, std::vector<double>> measIsSimulatedValue;
360 for (
const auto&
name : measNames) {
361 measObjectNames[
name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
362 allSpecParSections, nodePath,
"meas_object_name_" +
name);
363 measParamNames[
name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
364 allSpecParSections, nodePath,
"meas_value_name_" +
name);
365 measParamValues[
name] =
366 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"meas_value_" +
name);
367 measParamSigmas[
name] =
368 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"meas_sigma_" +
name);
369 measIsSimulatedValue[
name] = cms::getAllParameterValuesFromSpecParSections<double>(
370 allSpecParSections, nodePath,
"meas_is_simulated_value_" +
name);
374 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML: Fill measurements with read parameters ";
377 if (measNames.size() == measTypes.size()) {
378 for (
size_t i = 0;
i < measNames.size(); ++
i) {
380 oaMeas.
name_ = measNames[
i];
381 oaMeas.
type_ = measTypes[
i];
383 if (measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size()) {
384 for (
size_t i2 = 0;
i2 < measParamNames[oaMeas.
name_].size();
i2++) {
389 if (oaMeas.
type_ ==
"SENSOR2D" || oaMeas.
type_ ==
"COPS" || oaMeas.
type_ ==
"DISTANCEMETER" ||
390 oaMeas.
type_ ==
"DISTANCEMETER!DIM" || oaMeas.
type_ ==
"DISTANCEMETER3DIM") {
392 }
else if (oaMeas.
type_ ==
"TILTMETER") {
395 edm::LogError(
"Alignment") <<
"CocoaAnalyzer::readXMLFile. Invalid measurement type: " << oaMeas.
type_;
398 oaMeas.
values_.emplace_back(oaParam);
403 << measIsSimulatedValue[oaMeas.
name_][
i2];
409 edm::LogWarning(
"Alignment") <<
"WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do"
410 <<
" not match! for measurement " << oaMeas.
name_
411 <<
" !Did not fill parameters for this measurement ";
416 edm::LogInfo(
"Alignment") <<
"CocoaAnalyser: MEASUREMENT " << oaMeas.
name_ <<
" extra entries read "
424 edm::LogWarning(
"Alignment") <<
"WARNING FOR NOW: sizes of measurements (names, types do"
425 <<
" not match! Did not add " << nObjects <<
" item to XXXMeasurements";
434 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML: Finished building " << nObjects + 1
435 <<
" OpticalAlignInfo objects"
437 <<
" OpticalAlignMeasurementInfo objects ";
452 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::readCalibrationDB: ";
461 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ "
462 << infoFromDB.size();
463 for (
const auto& myInfoFromDB : infoFromDB) {
464 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::readCalibrationDB: OpticalAlignInfo READ " << myInfoFromDB;
476 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::correctAllOpticalAlignments: ";
479 for (
const auto& myDBInfo : allDBOpticalAlignments) {
481 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::findOpticalAlignInfoXML: Looking for OAI " << myDBInfo.name_;
485 const auto& myXMLInfo = std::find_if(
486 allXMLOpticalAlignments.begin(), allXMLOpticalAlignments.end(), [&](
const auto& myXMLInfoCandidate) {
487 return myXMLInfoCandidate.name_ == myDBInfo.name_;
490 if (myXMLInfo != allXMLOpticalAlignments.end()) {
492 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::findOpticalAlignInfoXML: OAI found " << myXMLInfo->name_;
494 <<
"CocoaAnalyzer::correctAllOpticalAlignments: correcting data from XML with DB info.";
504 const std::vector<OpticalAlignParam>& allDBExtraEntries = myDBInfo.extraEntries_;
505 std::vector<OpticalAlignParam>& allXMLExtraEntries = myXMLInfo->extraEntries_;
506 for (
const auto& myDBExtraEntry : allDBExtraEntries) {
507 const auto& myXMLExtraEntry = std::find_if(
508 allXMLExtraEntries.begin(), allXMLExtraEntries.end(), [&](
const auto& myXMLExtraEntryCandidate) {
509 return myXMLExtraEntryCandidate.name_ == myDBExtraEntry.name_;
512 if (myXMLExtraEntry != allXMLExtraEntries.end()) {
515 if (myDBExtraEntry.name_ !=
"None") {
518 <<
"CocoaAnalyzer::correctAllOpticalAlignments: extra entry read from DB is not present in XML "
519 << myDBExtraEntry <<
" in object " << myDBInfo;
526 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::correctAllOpticalAlignments: corrected OpticalAlingInfo "
531 edm::LogError(
"Alignment") <<
"CocoaAnalyzer::correctAllOpticalAlignments: OpticalAlignInfo read from DB "
532 << myDBInfo <<
" is not present in XML.";
543 if (myDBParam.
value_ != -9.999E9) {
545 double dimFactor = 1.;
547 if (
type ==
"centre" ||
type ==
"length") {
549 }
else if (
type ==
"angles" ||
type ==
"angle" ||
type ==
"nodim") {
555 const double correctedValue = myDBParam.
value_ * dimFactor;
557 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::correctOpticalAlignmentParameter old value= " << myXMLParam.
value_
558 <<
" new value= " << correctedValue;
560 myXMLParam.
value_ = correctedValue;
569 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::runCocoa: ";
577 edm::LogInfo(
"Alignment") <<
"$$ CocoaAnalyzer::runCocoa: geometry built ";
584 edm::LogInfo(
"Alignment") <<
"$$ CocoaAnalyzer::runCocoa: measurements built ";
592 edm::LogInfo(
"Alignment") <<
"............ program ended OK";
595 fileout <<
"............ program ended OK";