57 theCocoaDaqRootFileName_ =
pset.getParameter<
std::string>(
"cocoaDaqRootFile");
63 usesResource(
"CocoaAnalyzer");
75 std::vector<OpticalAlignInfo> oaListCalib = readCalibrationDB(evts);
76 correctAllOpticalAlignments(oaListCalib);
98 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML: world object = " << worldVolume.name();
103 worldInfo.
name_ = worldVolume.name();
104 worldInfo.
type_ =
"system";
124 oaList_.opticalAlignments_.emplace_back(worldInfo);
139 const std::string cocoaParameterAttribute =
"COCOA";
143 allSpecParSections.filter(cocoaParameterSpecParSections, cocoaParameterAttribute, cocoaParameterValue);
165 oaInfo.
name_ = nodePath;
168 oaInfo.
parentName_ = nodePath.substr(0, nodePath.rfind(
'/', nodePath.length()));
171 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML reading object " <<
name;
180 const dd4hep::Direction& transl = myPlacedVolume.position();
183 edm::LogInfo(
"Alignment") <<
"Local translation in cm = " << transl;
190 oaInfo.
x_.
value_ = transl.x() / (1._m);
191 oaInfo.
x_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
197 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_X_quality", 0));
201 oaInfo.
y_.
value_ = transl.y() / (1._m);
202 oaInfo.
y_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
208 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_Y_quality", 0));
212 oaInfo.
z_.
value_ = transl.z() / (1._m);
213 oaInfo.
z_.
error_ = cms::getParameterValueFromSpecParSections<double>(allSpecParSections,
219 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"centre_Z_quality", 0));
231 const TGeoHMatrix parentToChild = myPlacedVolume.matrix();
233 const TGeoHMatrix& childToParent = parentToChild.Inverse();
238 const Double_t*
rot = childToParent.GetRotationMatrix();
239 const double xx =
rot[0];
240 const double xy =
rot[1];
241 const double xz =
rot[2];
242 const double yx =
rot[3];
243 const double yy =
rot[4];
244 const double yz =
rot[5];
245 const double zx =
rot[6];
246 const double zy =
rot[7];
247 const double zz =
rot[8];
254 const CLHEP::Hep3Vector colX(
xx, yx, zx);
255 const CLHEP::Hep3Vector colY(
xy,
yy, zy);
256 const CLHEP::Hep3Vector colZ(
xz,
yz,
zz);
257 const CLHEP::HepRotation rotclhep(colX, colY, colZ);
265 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_value", 0);
267 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_sigma", 0);
269 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_X_quality", 0));
274 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_value", 0);
276 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_sigma", 0);
278 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Y_quality", 0));
283 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_value", 0);
285 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_sigma", 0);
287 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"angles_Z_quality", 0));
290 cms::getParameterValueFromSpecParSections<std::string>(allSpecParSections, nodePath,
"cocoa_type", 0);
292 oaInfo.
ID_ = static_cast<int>(
293 cms::getParameterValueFromSpecParSections<double>(allSpecParSections, nodePath,
"cmssw_ID", 0));
296 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML OBJECT " << oaInfo.
name_ <<
" pos/angles read ";
310 const std::vector<std::string>&
names =
311 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"extra_entry");
312 const std::vector<std::string>& dims =
313 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"dimType");
314 const std::vector<double>&
values =
315 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"value");
316 const std::vector<double>&
errors =
317 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"sigma");
318 const std::vector<double>&
quality =
319 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"quality");
322 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML: Fill extra entries with read parameters ";
327 for (
size_t i = 0;
i <
names.size(); ++
i) {
328 double dimFactor = 1.;
330 if (
type ==
"centre" ||
type ==
"length") {
331 dimFactor = 1. / (1._m);
332 }
else if (
type ==
"angles" ||
type ==
"angle" ||
type ==
"nodim") {
344 oaList_.opticalAlignments_.emplace_back(oaInfo);
346 edm::LogInfo(
"Alignment") <<
"WARNING FOR NOW: sizes of extra parameters (names, dimType, value, quality) do"
347 <<
" not match! Did not add " << nObjects <<
" item to OpticalAlignments.";
351 const std::vector<std::string>& measNames =
352 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"meas_name");
353 const std::vector<std::string>& measTypes =
354 cms::getAllParameterValuesFromSpecParSections<std::string>(allSpecParSections, nodePath,
"meas_type");
356 std::map<std::string, std::vector<std::string>> measObjectNames;
357 std::map<std::string, std::vector<std::string>> measParamNames;
358 std::map<std::string, std::vector<double>> measParamValues;
359 std::map<std::string, std::vector<double>> measParamSigmas;
360 std::map<std::string, std::vector<double>> measIsSimulatedValue;
361 for (
const auto&
name : measNames) {
362 measObjectNames[
name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
363 allSpecParSections, nodePath,
"meas_object_name_" +
name);
364 measParamNames[
name] = cms::getAllParameterValuesFromSpecParSections<std::string>(
365 allSpecParSections, nodePath,
"meas_value_name_" +
name);
366 measParamValues[
name] =
367 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"meas_value_" +
name);
368 measParamSigmas[
name] =
369 cms::getAllParameterValuesFromSpecParSections<double>(allSpecParSections, nodePath,
"meas_sigma_" +
name);
370 measIsSimulatedValue[
name] = cms::getAllParameterValuesFromSpecParSections<double>(
371 allSpecParSections, nodePath,
"meas_is_simulated_value_" +
name);
375 edm::LogInfo(
"Alignment") <<
" CocoaAnalyzer::ReadXML: Fill measurements with read parameters ";
378 if (measNames.size() == measTypes.size()) {
379 for (
size_t i = 0;
i < measNames.size(); ++
i) {
381 oaMeas.
name_ = measNames[
i];
382 oaMeas.
type_ = measTypes[
i];
384 if (measParamNames.size() == measParamValues.size() && measParamValues.size() == measParamSigmas.size()) {
385 for (
size_t i2 = 0;
i2 < measParamNames[oaMeas.
name_].size();
i2++) {
390 if (oaMeas.
type_ ==
"SENSOR2D" || oaMeas.
type_ ==
"COPS" || oaMeas.
type_ ==
"DISTANCEMETER" ||
391 oaMeas.
type_ ==
"DISTANCEMETER!DIM" || oaMeas.
type_ ==
"DISTANCEMETER3DIM") {
393 }
else if (oaMeas.
type_ ==
"TILTMETER") {
396 edm::LogError(
"Alignment") <<
"CocoaAnalyzer::readXMLFile. Invalid measurement type: " << oaMeas.
type_;
399 oaMeas.
values_.emplace_back(oaParam);
404 << measIsSimulatedValue[oaMeas.
name_][
i2];
410 edm::LogWarning(
"Alignment") <<
"WARNING FOR NOW: sizes of measurement parameters (name, value, sigma) do"
411 <<
" not match! for measurement " << oaMeas.
name_
412 <<
" !Did not fill parameters for this measurement ";
415 measList_.oaMeasurements_.emplace_back(oaMeas);
417 edm::LogInfo(
"Alignment") <<
"CocoaAnalyser: MEASUREMENT " << oaMeas.
name_ <<
" extra entries read "
425 edm::LogWarning(
"Alignment") <<
"WARNING FOR NOW: sizes of measurements (names, types do"
426 <<
" not match! Did not add " << nObjects <<
" item to XXXMeasurements";
435 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::ReadXML: Finished building " << nObjects + 1
436 <<
" OpticalAlignInfo objects"
437 <<
" and " << measList_.oaMeasurements_.size()
438 <<
" OpticalAlignMeasurementInfo objects ";
441 edm::LogInfo(
"Alignment") <<
" @@@@@@ OpticalAlignments " << oaList_;
442 edm::LogInfo(
"Alignment") <<
" @@@@@@ OpticalMeasurements " << measList_;
453 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::readCalibrationDB: ";
462 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::readCalibrationDB: Number of OpticalAlignInfo READ "
463 << infoFromDB.size();
464 for (
const auto& myInfoFromDB : infoFromDB) {
465 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::readCalibrationDB: OpticalAlignInfo READ " << myInfoFromDB;
477 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::correctAllOpticalAlignments: ";
480 for (
const auto& myDBInfo : allDBOpticalAlignments) {
482 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::findOpticalAlignInfoXML: Looking for OAI " << myDBInfo.name_;
485 std::vector<OpticalAlignInfo>& allXMLOpticalAlignments = oaList_.opticalAlignments_;
486 const auto& myXMLInfo = std::find_if(
487 allXMLOpticalAlignments.begin(), allXMLOpticalAlignments.end(), [&](
const auto& myXMLInfoCandidate) {
488 return myXMLInfoCandidate.name_ == myDBInfo.name_;
491 if (myXMLInfo != allXMLOpticalAlignments.end()) {
493 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::findOpticalAlignInfoXML: OAI found " << myXMLInfo->name_;
495 <<
"CocoaAnalyzer::correctAllOpticalAlignments: correcting data from XML with DB info.";
497 correctOpticalAlignmentParameter(myXMLInfo->x_, myDBInfo.x_);
498 correctOpticalAlignmentParameter(myXMLInfo->y_, myDBInfo.y_);
499 correctOpticalAlignmentParameter(myXMLInfo->z_, myDBInfo.z_);
500 correctOpticalAlignmentParameter(myXMLInfo->angx_, myDBInfo.angx_);
501 correctOpticalAlignmentParameter(myXMLInfo->angy_, myDBInfo.angy_);
502 correctOpticalAlignmentParameter(myXMLInfo->angz_, myDBInfo.angz_);
505 const std::vector<OpticalAlignParam>& allDBExtraEntries = myDBInfo.extraEntries_;
506 std::vector<OpticalAlignParam>& allXMLExtraEntries = myXMLInfo->extraEntries_;
507 for (
const auto& myDBExtraEntry : allDBExtraEntries) {
508 const auto& myXMLExtraEntry = std::find_if(
509 allXMLExtraEntries.begin(), allXMLExtraEntries.end(), [&](
const auto& myXMLExtraEntryCandidate) {
510 return myXMLExtraEntryCandidate.name_ == myDBExtraEntry.name_;
513 if (myXMLExtraEntry != allXMLExtraEntries.end()) {
514 correctOpticalAlignmentParameter(*myXMLExtraEntry, myDBExtraEntry);
516 if (myDBExtraEntry.name_ !=
"None") {
519 <<
"CocoaAnalyzer::correctAllOpticalAlignments: extra entry read from DB is not present in XML "
520 << myDBExtraEntry <<
" in object " << myDBInfo;
527 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::correctAllOpticalAlignments: corrected OpticalAlingInfo "
532 edm::LogError(
"Alignment") <<
"CocoaAnalyzer::correctAllOpticalAlignments: OpticalAlignInfo read from DB "
533 << myDBInfo <<
" is not present in XML.";
544 if (myDBParam.
value_ != -9.999E9) {
546 double dimFactor = 1.;
548 if (
type ==
"centre" ||
type ==
"length") {
549 dimFactor = 1. / 1._m;
550 }
else if (
type ==
"angles" ||
type ==
"angle" ||
type ==
"nodim") {
556 const double correctedValue = myDBParam.
value_ * dimFactor;
558 edm::LogInfo(
"Alignment") <<
"CocoaAnalyzer::correctOpticalAlignmentParameter old value= " << myXMLParam.
value_
559 <<
" new value= " << correctedValue;
561 myXMLParam.
value_ = correctedValue;
570 edm::LogInfo(
"Alignment") <<
"$$$ CocoaAnalyzer::runCocoa: ";
575 model.BuildSystemDescriptionFromOA(oaList_);
578 edm::LogInfo(
"Alignment") <<
"$$ CocoaAnalyzer::runCocoa: geometry built ";
582 model.BuildMeasurementsFromOA(measList_);
585 edm::LogInfo(
"Alignment") <<
"$$ CocoaAnalyzer::runCocoa: measurements built ";
593 edm::LogInfo(
"Alignment") <<
"............ program ended OK";
596 fileout <<
"............ program ended OK";