CMS 3D CMS Logo

MuonAlignmentInputXML.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuonAlignment
4 // Class : MuonAlignmentInputXML
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Jim Pivarski
10 // Created: Mon Mar 10 16:37:40 CDT 2008
11 //$Id: MuonAlignmentInputXML.cc,v 1.16 2011/03/22 09:49:50 innocent Exp $
12 //
13 
14 // system include files
17 
18 // Xerces include files
19 #include "xercesc/parsers/XercesDOMParser.hpp"
20 #include "xercesc/dom/DOM.hpp"
21 #include "xercesc/sax/HandlerBase.hpp"
22 #include "xercesc/util/XMLString.hpp"
23 #include "xercesc/util/PlatformUtils.hpp"
24 #include "xercesc/util/XercesDefs.hpp"
26 
27 // user include files
35 
36 //
37 // constants, enums and typedefs
38 //
39 
40 //
41 // static data member definitions
42 //
43 
44 //
45 // constructors and destructor
46 //
49  str_operation = XMLString::transcode("operation");
50  str_collection = XMLString::transcode("collection");
51  str_name = XMLString::transcode("name");
52  str_DTBarrel = XMLString::transcode("DTBarrel");
53  str_DTWheel = XMLString::transcode("DTWheel");
54  str_DTStation = XMLString::transcode("DTStation");
55  str_DTChamber = XMLString::transcode("DTChamber");
56  str_DTSuperLayer = XMLString::transcode("DTSuperLayer");
57  str_DTLayer = XMLString::transcode("DTLayer");
58  str_CSCEndcap = XMLString::transcode("CSCEndcap");
59  str_CSCStation = XMLString::transcode("CSCStation");
60  str_CSCRing = XMLString::transcode("CSCRing");
61  str_CSCChamber = XMLString::transcode("CSCChamber");
62  str_CSCLayer = XMLString::transcode("CSCLayer");
63  str_setposition = XMLString::transcode("setposition");
64  str_setape = XMLString::transcode("setape");
65  str_setsurveyerr = XMLString::transcode("setsurveyerr");
66  str_moveglobal = XMLString::transcode("moveglobal");
67  str_movelocal = XMLString::transcode("movelocal");
68  str_rotatelocal = XMLString::transcode("rotatelocal");
69  str_rotatebeamline = XMLString::transcode("rotatebeamline");
70  str_rotateglobalaxis = XMLString::transcode("rotateglobalaxis");
71  str_relativeto = XMLString::transcode("relativeto");
72  str_rawId = XMLString::transcode("rawId");
73  str_wheel = XMLString::transcode("wheel");
74  str_station = XMLString::transcode("station");
75  str_sector = XMLString::transcode("sector");
76  str_superlayer = XMLString::transcode("superlayer");
77  str_layer = XMLString::transcode("layer");
78  str_endcap = XMLString::transcode("endcap");
79  str_ring = XMLString::transcode("ring");
80  str_chamber = XMLString::transcode("chamber");
81  str_axisx = XMLString::transcode("axisx");
82  str_axisy = XMLString::transcode("axisy");
83  str_axisz = XMLString::transcode("axisz");
84  str_angle = XMLString::transcode("angle");
85  str_x = XMLString::transcode("x");
86  str_y = XMLString::transcode("y");
87  str_z = XMLString::transcode("z");
88  str_phix = XMLString::transcode("phix");
89  str_phiy = XMLString::transcode("phiy");
90  str_phiz = XMLString::transcode("phiz");
91  str_alpha = XMLString::transcode("alpha");
92  str_beta = XMLString::transcode("beta");
93  str_gamma = XMLString::transcode("gamma");
94  str_rphi = XMLString::transcode("rphi");
95  str_phi = XMLString::transcode("phi");
96  str_xx = XMLString::transcode("xx");
97  str_xy = XMLString::transcode("xy");
98  str_xz = XMLString::transcode("xz");
99  str_xa = XMLString::transcode("xa");
100  str_xb = XMLString::transcode("xb");
101  str_xc = XMLString::transcode("xc");
102  str_yy = XMLString::transcode("yy");
103  str_yz = XMLString::transcode("yz");
104  str_ya = XMLString::transcode("ya");
105  str_yb = XMLString::transcode("yb");
106  str_yc = XMLString::transcode("yc");
107  str_zz = XMLString::transcode("zz");
108  str_za = XMLString::transcode("za");
109  str_zb = XMLString::transcode("zb");
110  str_zc = XMLString::transcode("zc");
111  str_aa = XMLString::transcode("aa");
112  str_ab = XMLString::transcode("ab");
113  str_ac = XMLString::transcode("ac");
114  str_bb = XMLString::transcode("bb");
115  str_bc = XMLString::transcode("bc");
116  str_cc = XMLString::transcode("cc");
117  str_none = XMLString::transcode("none");
118  str_ideal = XMLString::transcode("ideal");
119  str_container = XMLString::transcode("container");
120 }
121 
122 // MuonAlignmentInputXML::MuonAlignmentInputXML(const MuonAlignmentInputXML& rhs)
123 // {
124 // // do actual copying here;
125 // }
126 
200 }
201 
202 //
203 // assignment operators
204 //
205 // const MuonAlignmentInputXML& MuonAlignmentInputXML::operator=(const MuonAlignmentInputXML& rhs)
206 // {
207 // //An exception safe implementation is
208 // MuonAlignmentInputXML temp(rhs);
209 // swap(rhs);
210 //
211 // return *this;
212 // }
213 
214 //
215 // member functions
216 //
217 
218 void MuonAlignmentInputXML::recursiveGetId(std::map<unsigned int, Alignable *> &alignableNavigator,
219  const align::Alignables &alignables) const {
220  for (align::Alignables::const_iterator ali = alignables.begin(); ali != alignables.end(); ++ali) {
221  if ((*ali)->alignableObjectId() == align::AlignableDetUnit || (*ali)->alignableObjectId() == align::AlignableDet ||
222  (*ali)->alignableObjectId() == align::AlignableDTChamber ||
223  (*ali)->alignableObjectId() == align::AlignableDTSuperLayer ||
224  (*ali)->alignableObjectId() == align::AlignableDTLayer ||
225  (*ali)->alignableObjectId() == align::AlignableCSCChamber ||
226  (*ali)->alignableObjectId() == align::AlignableCSCLayer) {
227  alignableNavigator[(*ali)->geomDetId().rawId()] = *ali;
228  }
229  recursiveGetId(alignableNavigator, (*ali)->components());
230  }
231 }
232 
233 void MuonAlignmentInputXML::fillAliToIdeal(std::map<Alignable *, Alignable *> &alitoideal,
234  const align::Alignables &alignables,
235  const align::Alignables &ideals) const {
236  align::Alignables::const_iterator alignable = alignables.begin();
237  align::Alignables::const_iterator ideal = ideals.begin();
238 
239  while (alignable != alignables.end() && ideal != ideals.end()) {
240  alitoideal[*alignable] = *ideal;
241 
242  fillAliToIdeal(alitoideal, (*alignable)->components(), (*ideal)->components());
243 
244  ++alignable;
245  ++ideal;
246  }
247 
248  if (alignable != alignables.end() || ideal != ideals.end()) {
249  throw cms::Exception("Alignment")
250  << "alignable and ideal-alignable trees are out of sync (this should never happen)";
251  }
252 }
253 
255  std::shared_ptr<DTGeometry> dtGeometry = idealDTGeometry(iSetup);
256  std::shared_ptr<CSCGeometry> cscGeometry = idealCSCGeometry(iSetup);
257 
258  AlignableMuon *alignableMuon = new AlignableMuon(&(*dtGeometry), &(*cscGeometry));
259  std::map<unsigned int, Alignable *> alignableNavigator; // real AlignableNavigators don't have const methods
260  recursiveGetId(alignableNavigator, alignableMuon->DTBarrel());
261  recursiveGetId(alignableNavigator, alignableMuon->CSCEndcaps());
262 
263  AlignableMuon *ideal_alignableMuon = new AlignableMuon(&(*dtGeometry), &(*cscGeometry));
264  std::map<unsigned int, Alignable *> ideal_alignableNavigator; // real AlignableNavigators don't have const methods
265  recursiveGetId(ideal_alignableNavigator, ideal_alignableMuon->DTBarrel());
266  recursiveGetId(ideal_alignableNavigator, ideal_alignableMuon->CSCEndcaps());
267 
268  try {
270  } catch (const XMLException &toCatch) {
271  throw cms::Exception("XMLException") << "Xerces XML parser threw an exception on initialization." << std::endl;
272  }
273 
274  XercesDOMParser *parser = new XercesDOMParser();
275  parser->setValidationScheme(XercesDOMParser::Val_Always);
276 
277  XERCES_CPP_NAMESPACE::ErrorHandler *errHandler = (XERCES_CPP_NAMESPACE::ErrorHandler *)(new HandlerBase());
278  parser->setErrorHandler(errHandler);
279 
280  try {
281  parser->parse(m_fileName.c_str());
282  } catch (const XMLException &toCatch) {
283  char *message = XMLString::transcode(toCatch.getMessage());
284  throw cms::Exception("XMLException") << "Xerces XML parser threw this exception: " << message << std::endl;
285  } catch (const DOMException &toCatch) {
286  char *message = XMLString::transcode(toCatch.msg);
287  throw cms::Exception("XMLException") << "Xerces XML parser threw this exception: " << message << std::endl;
288  } catch (const SAXException &toCatch) {
289  char *message = XMLString::transcode(toCatch.getMessage());
290  throw cms::Exception("XMLException") << "Xerces XML parser threw this exception: " << message << std::endl;
291  }
292 
293  DOMDocument *doc = parser->getDocument();
294  DOMElement *node_MuonAlignment = doc->getDocumentElement();
295  DOMNodeList *collections = doc->getElementsByTagName(str_collection);
296  DOMNodeList *operations = doc->getElementsByTagName(str_operation);
297 
298  std::map<Alignable *, Alignable *> alitoideal;
299  fillAliToIdeal(alitoideal, alignableMuon->DTBarrel(), ideal_alignableMuon->DTBarrel());
300  fillAliToIdeal(alitoideal, alignableMuon->CSCEndcaps(), ideal_alignableMuon->CSCEndcaps());
301 
302  const auto &alignableObjectId = alignableMuon->objectIdProvider();
303  std::map<std::string, std::map<Alignable *, bool> > alicollections;
304  for (unsigned int i = 0; i < collections->getLength(); i++) {
305  DOMElement *collection = (DOMElement *)(collections->item(i));
306  if (collection->getParentNode() == node_MuonAlignment) {
307  DOMNodeList *children = collection->getChildNodes();
308 
309  DOMAttr *node_name = collection->getAttributeNode(str_name);
310  if (node_name == nullptr) {
311  throw cms::Exception("XMLException") << "<collection> requires a name attribute" << std::endl;
312  }
313  char *ascii_name = XMLString::transcode(node_name->getValue());
314  std::string name(ascii_name);
315  XMLString::release(&ascii_name);
316 
317  std::map<Alignable *, bool> aliset;
318  for (unsigned int j = 0; j < children->getLength(); j++) {
319  DOMNode *node = children->item(j);
320 
321  if (node->getNodeType() == DOMNode::ELEMENT_NODE) {
322  Alignable *ali = getNode(alignableNavigator, (DOMElement *)(node), alignableObjectId);
323  if (ali == nullptr) {
324  throw cms::Exception("XMLException") << "<collection> must contain only alignables" << std::endl;
325  }
326 
327  aliset[ali] = true;
328  } // end if this node is an element
329  } // end loop over collection's children
330 
331  alicollections[name] = aliset;
332  } // end if this is a top-level collection
333  } // end loop over collections
334 
335  for (unsigned int i = 0; i < operations->getLength(); i++) {
336  DOMElement *operation = (DOMElement *)(operations->item(i));
337  if (operation->getParentNode() != node_MuonAlignment) {
338  throw cms::Exception("XMLException") << "All operations must be top-level elements" << std::endl;
339  }
340 
341  DOMNodeList *children = operation->getChildNodes();
342 
343  std::map<Alignable *, bool> aliset;
344  std::vector<DOMNode *> nodesToRemove;
345  for (unsigned int j = 0; j < children->getLength(); j++) {
346  DOMNode *node = children->item(j);
347 
348  if (node->getNodeType() == DOMNode::ELEMENT_NODE) {
349  Alignable *ali = getNode(alignableNavigator, (DOMElement *)(node), alignableObjectId);
350  if (ali != nullptr) {
351  aliset[ali] = true;
352  nodesToRemove.push_back(node);
353  } // end if this node is an alignable
354 
355  else if (XMLString::equals(node->getNodeName(), str_collection)) {
356  DOMAttr *node_name = ((DOMElement *)(node))->getAttributeNode(str_name);
357  if (node_name == nullptr) {
358  throw cms::Exception("XMLException") << "<collection> requires a name attribute" << std::endl;
359  }
360  char *ascii_name = XMLString::transcode(node_name->getValue());
361  std::string name(ascii_name);
362  XMLString::release(&ascii_name);
363 
364  std::map<std::string, std::map<Alignable *, bool> >::const_iterator alicollections_iter =
365  alicollections.find(name);
366  if (alicollections_iter == alicollections.end()) {
367  throw cms::Exception("XMLException")
368  << "<collection name=\"" << name << "\"> hasn't been defined" << std::endl;
369  }
370 
371  for (std::map<Alignable *, bool>::const_iterator aliiter = alicollections_iter->second.begin();
372  aliiter != alicollections_iter->second.end();
373  ++aliiter) {
374  aliset[aliiter->first] = true;
375  } // end loop over alignables in this collection
376 
377  nodesToRemove.push_back(node);
378  } // end if this node is a collection
379 
380  else {
381  } // anything else? assume it's a position/rotation directive
382 
383  } // end if node is node is an element
384  } // end first loop over operation's children
385 
386  // from now on, we only want to see position/rotation directives
387  for (std::vector<DOMNode *>::const_iterator node = nodesToRemove.begin(); node != nodesToRemove.end(); ++node) {
388  operation->removeChild(*node);
389  }
390  children = operation->getChildNodes();
391 
392  for (unsigned int j = 0; j < children->getLength(); j++) {
393  DOMNode *node = children->item(j);
394  if (node->getNodeType() == DOMNode::ELEMENT_NODE) {
395  if (XMLString::equals(node->getNodeName(), str_setposition)) {
396  do_setposition((DOMElement *)(node), aliset, alitoideal);
397  }
398 
399  else if (XMLString::equals(node->getNodeName(), str_setape)) {
400  do_setape((DOMElement *)(node), aliset, alitoideal);
401  }
402 
403  else if (XMLString::equals(node->getNodeName(), str_setsurveyerr)) {
404  do_setsurveyerr((DOMElement *)(node), aliset, alitoideal);
405  }
406 
407  else if (XMLString::equals(node->getNodeName(), str_moveglobal)) {
408  do_moveglobal((DOMElement *)(node), aliset, alitoideal);
409  }
410 
411  else if (XMLString::equals(node->getNodeName(), str_movelocal)) {
412  do_movelocal((DOMElement *)(node), aliset, alitoideal);
413  }
414 
415  else if (XMLString::equals(node->getNodeName(), str_rotatelocal)) {
416  do_rotatelocal((DOMElement *)(node), aliset, alitoideal);
417  }
418 
419  else if (XMLString::equals(node->getNodeName(), str_rotatebeamline)) {
420  do_rotatebeamline((DOMElement *)(node), aliset, alitoideal);
421  }
422 
423  else if (XMLString::equals(node->getNodeName(), str_rotateglobalaxis)) {
424  do_rotateglobalaxis((DOMElement *)(node), aliset, alitoideal);
425  }
426 
427  else {
428  char *message = XMLString::transcode(node->getNodeName());
429  throw cms::Exception("XMLException") << "Unrecognized operation: \"" << message << "\"" << std::endl;
430  }
431 
432  } // end if node is an element
433  } // end second loop over operation's children
434  } // end loop over operations
435 
436  delete parser;
437  delete errHandler;
438 
440 
441  delete ideal_alignableMuon;
442  return alignableMuon;
443 }
444 
445 Alignable *MuonAlignmentInputXML::getNode(std::map<unsigned int, Alignable *> &alignableNavigator,
446  const XERCES_CPP_NAMESPACE::DOMElement *node,
447  const AlignableObjectId &alignableObjectId) const {
448  if (XMLString::equals(node->getNodeName(), str_DTBarrel))
449  return getDTnode(align::AlignableDTBarrel, alignableNavigator, node, alignableObjectId);
450  else if (XMLString::equals(node->getNodeName(), str_DTWheel))
451  return getDTnode(align::AlignableDTWheel, alignableNavigator, node, alignableObjectId);
452  else if (XMLString::equals(node->getNodeName(), str_DTStation))
453  return getDTnode(align::AlignableDTStation, alignableNavigator, node, alignableObjectId);
454  else if (XMLString::equals(node->getNodeName(), str_DTChamber))
455  return getDTnode(align::AlignableDTChamber, alignableNavigator, node, alignableObjectId);
456  else if (XMLString::equals(node->getNodeName(), str_DTSuperLayer))
457  return getDTnode(align::AlignableDTSuperLayer, alignableNavigator, node, alignableObjectId);
458  else if (XMLString::equals(node->getNodeName(), str_DTLayer))
459  return getDTnode(align::AlignableDetUnit, alignableNavigator, node, alignableObjectId);
460  else if (XMLString::equals(node->getNodeName(), str_CSCEndcap))
461  return getCSCnode(align::AlignableCSCEndcap, alignableNavigator, node, alignableObjectId);
462  else if (XMLString::equals(node->getNodeName(), str_CSCStation))
463  return getCSCnode(align::AlignableCSCStation, alignableNavigator, node, alignableObjectId);
464  else if (XMLString::equals(node->getNodeName(), str_CSCRing))
465  return getCSCnode(align::AlignableCSCRing, alignableNavigator, node, alignableObjectId);
466  else if (XMLString::equals(node->getNodeName(), str_CSCChamber))
467  return getCSCnode(align::AlignableCSCChamber, alignableNavigator, node, alignableObjectId);
468  else if (XMLString::equals(node->getNodeName(), str_CSCLayer))
469  return getCSCnode(align::AlignableDetUnit, alignableNavigator, node, alignableObjectId);
470  else
471  return nullptr;
472 }
473 
475  std::map<unsigned int, Alignable *> &alignableNavigator,
476  const XERCES_CPP_NAMESPACE::DOMElement *node,
477  const AlignableObjectId &alignableObjectId) const {
478  unsigned int rawId = 0;
479 
480  DOMAttr *node_rawId = node->getAttributeNode(str_rawId);
481  if (node_rawId != nullptr) {
482  try {
483  rawId = XMLString::parseInt(node_rawId->getValue());
484  } catch (const XMLException &toCatch) {
485  throw cms::Exception("XMLException") << "Value of \"rawId\" must be an integer" << std::endl;
486  }
487  } else {
488  int wheel, station, sector, superlayer, layer;
489  wheel = station = sector = superlayer = layer = 1;
490 
491  if (structureType != align::AlignableDTBarrel) {
492  DOMAttr *node_wheel = node->getAttributeNode(str_wheel);
493  if (node_wheel == nullptr)
494  throw cms::Exception("XMLException") << "DT node is missing required \"wheel\" attribute" << std::endl;
495  try {
496  wheel = XMLString::parseInt(node_wheel->getValue());
497  } catch (const XMLException &toCatch) {
498  throw cms::Exception("XMLException") << "Value of \"wheel\" must be an integer" << std::endl;
499  }
500 
501  if (structureType != align::AlignableDTWheel) {
502  DOMAttr *node_station = node->getAttributeNode(str_station);
503  if (node_station == nullptr)
504  throw cms::Exception("XMLException") << "DT node is missing required \"station\" attribute" << std::endl;
505  try {
506  station = XMLString::parseInt(node_station->getValue());
507  } catch (const XMLException &toCatch) {
508  throw cms::Exception("XMLException") << "Value of \"station\" must be an integer" << std::endl;
509  }
510 
511  if (structureType != align::AlignableDTStation) {
512  DOMAttr *node_sector = node->getAttributeNode(str_sector);
513  if (node_sector == nullptr)
514  throw cms::Exception("XMLException") << "DT node is missing required \"sector\" attribute" << std::endl;
515  try {
516  sector = XMLString::parseInt(node_sector->getValue());
517  } catch (const XMLException &toCatch) {
518  throw cms::Exception("XMLException") << "Value of \"sector\" must be an integer" << std::endl;
519  }
520 
521  if (structureType != align::AlignableDTChamber) {
522  DOMAttr *node_superlayer = node->getAttributeNode(str_superlayer);
523  if (node_superlayer == nullptr)
524  throw cms::Exception("XMLException")
525  << "DT node is missing required \"superlayer\" attribute" << std::endl;
526  try {
527  superlayer = XMLString::parseInt(node_superlayer->getValue());
528  } catch (const XMLException &toCatch) {
529  throw cms::Exception("XMLException") << "Value of \"superlayer\" must be an integer" << std::endl;
530  }
531 
532  if (structureType != align::AlignableDTSuperLayer) {
533  DOMAttr *node_layer = node->getAttributeNode(str_layer);
534  if (node_layer == nullptr)
535  throw cms::Exception("XMLException") << "DT node is missing required \"layer\" attribute" << std::endl;
536  try {
537  layer = XMLString::parseInt(node_layer->getValue());
538  } catch (const XMLException &toCatch) {
539  throw cms::Exception("XMLException") << "Value of \"layer\" must be an integer" << std::endl;
540  }
541 
542  } // end if we need a layer number
543  } // end if we need a superlayer number
544  } // end if we need a sector number
545  } // end if we need a station number
546  } // end if we need a wheel number
547 
548  DTLayerId layerId(wheel, station, sector, superlayer, layer);
549  rawId = layerId.rawId();
550  } // end if it's specified by wheel, station, sector, superlayer, layer
551 
552  Alignable *ali = alignableNavigator[rawId];
553  if (ali == nullptr)
554  throw cms::Exception("XMLException") << "rawId \"" << rawId << "\" is not recognized" << std::endl;
555 
556  while (ali->alignableObjectId() != structureType) {
557  ali = ali->mother();
558 
559  if (ali == nullptr) {
560  throw cms::Exception("XMLException")
561  << "rawId \"" << rawId << "\" is not a " << alignableObjectId.idToString(structureType) << std::endl;
562  }
563  }
564  return ali;
565 }
566 
568  std::map<unsigned int, Alignable *> &alignableNavigator,
569  const XERCES_CPP_NAMESPACE::DOMElement *node,
570  const AlignableObjectId &alignableObjectId) const {
571  unsigned int rawId;
572 
573  DOMAttr *node_rawId = node->getAttributeNode(str_rawId);
574  if (node_rawId != nullptr) {
575  try {
576  rawId = XMLString::parseInt(node_rawId->getValue());
577  } catch (const XMLException &toCatch) {
578  throw cms::Exception("XMLException") << "Value of \"rawId\" must be an integer" << std::endl;
579  }
580  } else {
581  int endcap, station, ring, chamber, layer;
582  endcap = station = ring = chamber = layer = 1;
583 
584  DOMAttr *node_endcap = node->getAttributeNode(str_endcap);
585  if (node_endcap == nullptr)
586  throw cms::Exception("XMLException") << "CSC node is missing required \"endcap\" attribute" << std::endl;
587  try {
588  endcap = XMLString::parseInt(node_endcap->getValue());
589  } catch (const XMLException &toCatch) {
590  throw cms::Exception("XMLException") << "Value of \"endcap\" must be an integer" << std::endl;
591  }
592  if (endcap == -1)
593  endcap = 2;
594 
595  if (structureType != align::AlignableCSCEndcap) {
596  DOMAttr *node_station = node->getAttributeNode(str_station);
597  if (node_station == nullptr)
598  throw cms::Exception("XMLException") << "CSC node is missing required \"station\" attribute" << std::endl;
599  try {
600  station = XMLString::parseInt(node_station->getValue());
601  } catch (const XMLException &toCatch) {
602  throw cms::Exception("XMLException") << "Value of \"station\" must be an integer" << std::endl;
603  }
604 
605  if (structureType != align::AlignableCSCStation) {
606  DOMAttr *node_ring = node->getAttributeNode(str_ring);
607  if (node_ring == nullptr)
608  throw cms::Exception("XMLException") << "CSC node is missing required \"ring\" attribute" << std::endl;
609  try {
610  ring = XMLString::parseInt(node_ring->getValue());
611  } catch (const XMLException &toCatch) {
612  throw cms::Exception("XMLException") << "Value of \"ring\" must be an integer" << std::endl;
613  }
614 
615  if (structureType != align::AlignableCSCRing) {
616  DOMAttr *node_chamber = node->getAttributeNode(str_chamber);
617  if (node_chamber == nullptr)
618  throw cms::Exception("XMLException") << "CSC node is missing required \"chamber\" attribute" << std::endl;
619  try {
620  chamber = XMLString::parseInt(node_chamber->getValue());
621  } catch (const XMLException &toCatch) {
622  throw cms::Exception("XMLException") << "Value of \"chamber\" must be an integer" << std::endl;
623  }
624 
625  if (structureType != align::AlignableCSCChamber) {
626  DOMAttr *node_layer = node->getAttributeNode(str_layer);
627  if (node_layer == nullptr)
628  throw cms::Exception("XMLException") << "CSC node is missing required \"layer\" attribute" << std::endl;
629  try {
630  layer = XMLString::parseInt(node_layer->getValue());
631  } catch (const XMLException &toCatch) {
632  throw cms::Exception("XMLException") << "Value of \"layer\" must be an integer" << std::endl;
633  }
634 
635  } // end if we need a layer number
636  } // end if we need a chamber number
637  } // end if we need a ring number
638  } // end if we need a station number
639 
640  CSCDetId layerId(endcap, station, ring, chamber, layer);
641  rawId = layerId.rawId();
642  } // end if it's specified by endcap, station, ring, chamber, layer
643 
644  Alignable *ali = alignableNavigator[rawId];
645  if (ali == nullptr)
646  throw cms::Exception("XMLException") << "rawId \"" << rawId << "\" is not recognized" << std::endl;
647 
648  while (ali->alignableObjectId() != structureType) {
649  ali = ali->mother();
650 
651  if (ali == nullptr) {
652  throw cms::Exception("XMLException")
653  << "rawId \"" << rawId << "\" is not a " << alignableObjectId.idToString(structureType) << std::endl;
654  }
655  }
656  return ali;
657 }
658 
659 double MuonAlignmentInputXML::parseDouble(const XMLCh *str, const char *attribute) const {
660  unsigned int len = XMLString::stringLen(str);
661  char *cstr = XMLString::transcode(str);
662  std::stringstream errmessage;
663  errmessage << "Value of \"" << attribute << "\" must be a double, not \"" << cstr << "\"" << std::endl;
664 
665  unsigned int i = 0;
666 
667  bool minus = false;
668  if (cstr[i] == '-') {
669  minus = true;
670  i++;
671  } else if (cstr[i] == '+')
672  i++;
673 
674  double output = 0.;
675 
676  while (cstr[i] != '.' && cstr[i] != 'e' && cstr[i] != 'E' && i < len) {
677  if (cstr[i] < '0' || cstr[i] > '9') {
678  XMLString::release(&cstr);
679  throw cms::Exception("XMLException") << errmessage.str();
680  }
681 
682  output *= 10;
683  output += cstr[i] - '0';
684  i++;
685  }
686 
687  if (cstr[i] == '.') {
688  double place = 0.1;
689  i++;
690 
691  while (cstr[i] != 'e' && cstr[i] != 'E' && i < len) {
692  if (cstr[i] < '0' || cstr[i] > '9') {
693  XMLString::release(&cstr);
694  throw cms::Exception("XMLException") << errmessage.str();
695  }
696 
697  output += (cstr[i] - '0') * place;
698  place /= 10.;
699  i++;
700  }
701  }
702 
703  if (cstr[i] == 'e' || cstr[i] == 'E') {
704  i++;
705 
706  int exponent = 0;
707  bool expminus = false;
708  if (cstr[i] == '-') {
709  expminus = true;
710  i++;
711  } else if (cstr[i] == '+')
712  i++;
713 
714  while (i < len) {
715  if (cstr[i] < '0' || cstr[i] > '9') {
716  XMLString::release(&cstr);
717  throw cms::Exception("XMLException") << errmessage.str();
718  }
719 
720  exponent *= 10;
721  exponent += cstr[i] - '0';
722  i++;
723  }
724 
725  if (expminus)
726  exponent *= -1;
727 
728  output *= pow(10., exponent);
729  }
730 
731  if (minus)
732  output *= -1.;
733 
734  XMLString::release(&cstr);
735  return output;
736 }
737 
738 void MuonAlignmentInputXML::do_setposition(const XERCES_CPP_NAMESPACE::DOMElement *node,
739  std::map<Alignable *, bool> &aliset,
740  std::map<Alignable *, Alignable *> &alitoideal) const {
741  DOMAttr *node_relativeto = node->getAttributeNode(str_relativeto);
742  if (node_relativeto == nullptr)
743  throw cms::Exception("XMLException") << "<setposition> is missing required \"relativeto\" attribute" << std::endl;
744 
745  int relativeto = 0;
746  if (XMLString::equals(node_relativeto->getValue(), str_none)) {
747  relativeto = 0;
748  } else if (XMLString::equals(node_relativeto->getValue(), str_ideal)) {
749  relativeto = 1;
750  } else if (XMLString::equals(node_relativeto->getValue(), str_container)) {
751  relativeto = 2;
752  } else {
753  char *message = XMLString::transcode(node_relativeto->getValue());
754  throw cms::Exception("XMLException") << "relativeto must be \"none\", \"ideal\", or \"container\", not \""
755  << message << "\"" << std::endl;
756  }
757 
758  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
759  // first reconstruct the old position: how it would look in this coordinate system
760 
761  Alignable *ali = aliiter->first;
762  Alignable *ideal = alitoideal[ali];
763 
764  align::PositionType oldpos = ali->globalPosition();
765  align::RotationType oldrot = ali->globalRotation();
766 
767  if (relativeto == 0) {
768  }
769 
770  else if (relativeto == 1) {
771  const align::PositionType &idealPosition = ideal->globalPosition();
772  align::RotationType idealRotation = ideal->globalRotation();
773 
774  oldpos = align::PositionType(idealRotation * (oldpos.basicVector() - idealPosition.basicVector()));
775  oldrot = oldrot * idealRotation.transposed();
776  }
777 
778  else if (relativeto == 2 && ali->mother() != nullptr) {
779  align::PositionType globalPosition = ali->mother()->globalPosition();
780  align::RotationType globalRotation = ali->mother()->globalRotation();
781 
782  oldpos = align::PositionType(globalRotation * (oldpos.basicVector() - globalPosition.basicVector()));
783  oldrot = oldrot * globalRotation.transposed();
784  }
785 
786  double x = oldpos.x();
787  double y = oldpos.y();
788  double z = oldpos.z();
789 
790  double phix = atan2(oldrot.yz(), oldrot.zz());
791  double phiy = asin(-oldrot.xz());
792  double phiz = atan2(oldrot.xy(), oldrot.xx());
793 
794  align::EulerAngles oldEulerAngles = align::toAngles(oldrot);
795  double alpha = oldEulerAngles(1);
796  double beta = oldEulerAngles(2);
797  double gamma = oldEulerAngles(3);
798 
799  // now get the new information; if it's incomplete, use the old position for those coordinates
800 
801  DOMAttr *node_x = node->getAttributeNode(str_x);
802  DOMAttr *node_y = node->getAttributeNode(str_y);
803  DOMAttr *node_z = node->getAttributeNode(str_z);
804 
805  if (node_x != nullptr)
806  x = parseDouble(node_x->getValue(), "x");
807  if (node_y != nullptr)
808  y = parseDouble(node_y->getValue(), "y");
809  if (node_z != nullptr)
810  z = parseDouble(node_z->getValue(), "z");
811  align::PositionType pos(x, y, z);
812 
813  DOMAttr *node_phix = node->getAttributeNode(str_phix);
814  DOMAttr *node_phiy = node->getAttributeNode(str_phiy);
815  DOMAttr *node_phiz = node->getAttributeNode(str_phiz);
816  DOMAttr *node_alpha = node->getAttributeNode(str_alpha);
817  DOMAttr *node_beta = node->getAttributeNode(str_beta);
818  DOMAttr *node_gamma = node->getAttributeNode(str_gamma);
820 
821  bool phixyz = (node_phix != nullptr || node_phiy != nullptr || node_phiz != nullptr);
822  bool alphabetagamma = (node_alpha != nullptr || node_beta != nullptr || node_gamma != nullptr);
823  if (phixyz && alphabetagamma)
824  throw cms::Exception("XMLException")
825  << "<setposition> must either have phix, phiy, and phiz or alpha, beta, and gamma, but not both" << std::endl;
826  if (!phixyz && !alphabetagamma)
827  alphabetagamma = true;
828 
829  if (phixyz) {
830  if (node_phix != nullptr)
831  phix = parseDouble(node_phix->getValue(), "phix");
832  if (node_phiy != nullptr)
833  phiy = parseDouble(node_phiy->getValue(), "phiy");
834  if (node_phiz != nullptr)
835  phiz = parseDouble(node_phiz->getValue(), "phiz");
836 
837  // the angle convention originally used in alignment, also known as "non-standard Euler angles with a Z-Y-X convention"
838  // this also gets the sign convention right
839  align::RotationType rotX(1., 0., 0., 0., cos(phix), sin(phix), 0., -sin(phix), cos(phix));
840  align::RotationType rotY(cos(phiy), 0., -sin(phiy), 0., 1., 0., sin(phiy), 0., cos(phiy));
841  align::RotationType rotZ(cos(phiz), sin(phiz), 0., -sin(phiz), cos(phiz), 0., 0., 0., 1.);
842 
843  rot = rotX * rotY * rotZ;
844  }
845 
846  else if (alphabetagamma) {
847  if (node_alpha != nullptr)
848  alpha = parseDouble(node_alpha->getValue(), "alpha");
849  if (node_beta != nullptr)
850  beta = parseDouble(node_beta->getValue(), "beta");
851  if (node_gamma != nullptr)
852  gamma = parseDouble(node_gamma->getValue(), "gamma");
853 
854  // standard Euler angles (how they're internally stored in the database)
855  align::EulerAngles eulerAngles(3);
856  eulerAngles(1) = alpha;
857  eulerAngles(2) = beta;
858  eulerAngles(3) = gamma;
859  rot = align::RotationType(align::toMatrix(eulerAngles));
860  }
861 
862  else
863  assert(false); // see above
864 
865  if (relativeto == 0) {
866  set_one_position(aliiter->first, pos, rot);
867  } // end relativeto="none"
868 
869  else if (relativeto == 1) {
870  Alignable *ali = aliiter->first;
871  Alignable *ideal = alitoideal[ali];
872 
873  const align::PositionType &idealPosition = ideal->globalPosition();
874  align::RotationType idealRotation = ideal->globalRotation();
875  align::PositionType newpos =
876  align::PositionType(idealRotation.transposed() * pos.basicVector() + idealPosition.basicVector());
877  align::RotationType newrot = rot * idealRotation;
878 
879  set_one_position(ali, newpos, newrot);
880  } // end relativeto="ideal"
881 
882  else if (relativeto == 2) {
883  Alignable *ali = aliiter->first;
884  Alignable *container = ali->mother();
885 
886  if (container != nullptr) {
887  const align::PositionType &globalPosition = container->globalPosition();
888  align::RotationType globalRotation = container->globalRotation();
889  align::PositionType newpos =
890  align::PositionType(globalRotation.transposed() * pos.basicVector() + globalPosition.basicVector());
891  align::RotationType newrot = rot * globalRotation;
892  set_one_position(ali, newpos, newrot);
893  } else {
894  set_one_position(ali, pos, rot);
895  }
896  } // end relativeto="container"
897 
898  } // end loop over alignables
899 }
900 
902  const align::PositionType &pos,
903  const align::RotationType &rot) const {
904  const align::PositionType &oldpos = ali->globalPosition();
905  const align::RotationType &oldrot = ali->globalRotation();
906 
907  // shift needed to move from current to new position
908  align::GlobalVector posDiff = pos - oldpos;
909  align::RotationType rotDiff = oldrot.multiplyInverse(rot);
910  align::rectify(rotDiff); // correct for rounding errors
911  ali->move(posDiff);
912  ali->rotateInGlobalFrame(rotDiff);
913 
914  // // check for consistency
915  // const align::PositionType& newpos = ali->globalPosition();
916  // const align::RotationType& newrot = ali->globalRotation();
917  // align::GlobalVector posDiff2 = pos - newpos;
918  // align::RotationType rotDiff2 = newrot.multiplyInverse(rot);
919  // align::rectify(rotDiff2); // correct for rounding errors
920 
921  // if (fabs(posDiff2.x()) > 1e-6 || fabs(posDiff2.y()) > 1e-6 || fabs(posDiff2.z()) > 1e-6) {
922  // std::cout << "zeropos " << posDiff2 << std::endl;
923  // }
924  // if (fabs(rotDiff2.xx() - 1.) > 1e-4 ||
925  // fabs(rotDiff2.yy() - 1.) > 1e-4 ||
926  // fabs(rotDiff2.zz() - 1.) > 1e-4 ||
927  // fabs(rotDiff2.xy()) > 1e-8 ||
928  // fabs(rotDiff2.xz()) > 1e-8 ||
929  // fabs(rotDiff2.yz()) > 1e-8) {
930  // std::cout << "zerorot " << rotDiff2 << std::endl;
931  // }
932 
933  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
934  matrix6x6 *= 1000.; // initial assumption: infinitely weak constraint
935 
936  const SurveyDet *survey = ali->survey();
937  if (survey != nullptr) {
938  matrix6x6 = survey->errors(); // save the constraint information
939  }
940  ali->setSurvey(new SurveyDet(ali->surface(), matrix6x6));
941 }
942 
943 void MuonAlignmentInputXML::do_setape(const XERCES_CPP_NAMESPACE::DOMElement *node,
944  std::map<Alignable *, bool> &aliset,
945  std::map<Alignable *, Alignable *> &alitoideal) const {
946  DOMAttr *node_xx = node->getAttributeNode(str_xx);
947  DOMAttr *node_xy = node->getAttributeNode(str_xy);
948  DOMAttr *node_xz = node->getAttributeNode(str_xz);
949  DOMAttr *node_xa = node->getAttributeNode(str_xa);
950  DOMAttr *node_xb = node->getAttributeNode(str_xb);
951  DOMAttr *node_xc = node->getAttributeNode(str_xc);
952  DOMAttr *node_yy = node->getAttributeNode(str_yy);
953  DOMAttr *node_yz = node->getAttributeNode(str_yz);
954  DOMAttr *node_ya = node->getAttributeNode(str_ya);
955  DOMAttr *node_yb = node->getAttributeNode(str_yb);
956  DOMAttr *node_yc = node->getAttributeNode(str_yc);
957  DOMAttr *node_zz = node->getAttributeNode(str_zz);
958  DOMAttr *node_za = node->getAttributeNode(str_za);
959  DOMAttr *node_zb = node->getAttributeNode(str_zb);
960  DOMAttr *node_zc = node->getAttributeNode(str_zc);
961  DOMAttr *node_aa = node->getAttributeNode(str_aa);
962  DOMAttr *node_ab = node->getAttributeNode(str_ab);
963  DOMAttr *node_ac = node->getAttributeNode(str_ac);
964  DOMAttr *node_bb = node->getAttributeNode(str_bb);
965  DOMAttr *node_bc = node->getAttributeNode(str_bc);
966  DOMAttr *node_cc = node->getAttributeNode(str_cc);
967 
968  if (node_xx == nullptr)
969  throw cms::Exception("XMLException") << "<setape> is missing required \"xx\" attribute" << std::endl;
970  if (node_xy == nullptr)
971  throw cms::Exception("XMLException") << "<setape> is missing required \"xy\" attribute" << std::endl;
972  if (node_xz == nullptr)
973  throw cms::Exception("XMLException") << "<setape> is missing required \"xz\" attribute" << std::endl;
974  if (node_xa == nullptr)
975  throw cms::Exception("XMLException") << "<setape> is missing required \"xa\" attribute" << std::endl;
976  if (node_xb == nullptr)
977  throw cms::Exception("XMLException") << "<setape> is missing required \"xb\" attribute" << std::endl;
978  if (node_xc == nullptr)
979  throw cms::Exception("XMLException") << "<setape> is missing required \"xc\" attribute" << std::endl;
980  if (node_yy == nullptr)
981  throw cms::Exception("XMLException") << "<setape> is missing required \"yy\" attribute" << std::endl;
982  if (node_yz == nullptr)
983  throw cms::Exception("XMLException") << "<setape> is missing required \"yz\" attribute" << std::endl;
984  if (node_ya == nullptr)
985  throw cms::Exception("XMLException") << "<setape> is missing required \"ya\" attribute" << std::endl;
986  if (node_yb == nullptr)
987  throw cms::Exception("XMLException") << "<setape> is missing required \"yb\" attribute" << std::endl;
988  if (node_yc == nullptr)
989  throw cms::Exception("XMLException") << "<setape> is missing required \"yc\" attribute" << std::endl;
990  if (node_zz == nullptr)
991  throw cms::Exception("XMLException") << "<setape> is missing required \"zz\" attribute" << std::endl;
992  if (node_za == nullptr)
993  throw cms::Exception("XMLException") << "<setape> is missing required \"za\" attribute" << std::endl;
994  if (node_zb == nullptr)
995  throw cms::Exception("XMLException") << "<setape> is missing required \"zb\" attribute" << std::endl;
996  if (node_zc == nullptr)
997  throw cms::Exception("XMLException") << "<setape> is missing required \"zc\" attribute" << std::endl;
998  if (node_aa == nullptr)
999  throw cms::Exception("XMLException") << "<setape> is missing required \"aa\" attribute" << std::endl;
1000  if (node_ab == nullptr)
1001  throw cms::Exception("XMLException") << "<setape> is missing required \"ab\" attribute" << std::endl;
1002  if (node_ac == nullptr)
1003  throw cms::Exception("XMLException") << "<setape> is missing required \"ac\" attribute" << std::endl;
1004  if (node_bb == nullptr)
1005  throw cms::Exception("XMLException") << "<setape> is missing required \"bb\" attribute" << std::endl;
1006  if (node_bc == nullptr)
1007  throw cms::Exception("XMLException") << "<setape> is missing required \"bc\" attribute" << std::endl;
1008  if (node_cc == nullptr)
1009  throw cms::Exception("XMLException") << "<setape> is missing required \"cc\" attribute" << std::endl;
1010 
1011  align::ErrorMatrix matrix6x6;
1012  matrix6x6(0, 0) = parseDouble(node_xx->getValue(), "xx");
1013  matrix6x6(0, 1) = parseDouble(node_xy->getValue(), "xy");
1014  matrix6x6(0, 2) = parseDouble(node_xz->getValue(), "xz");
1015  matrix6x6(0, 3) = parseDouble(node_xa->getValue(), "xa");
1016  matrix6x6(0, 4) = parseDouble(node_xb->getValue(), "xb");
1017  matrix6x6(0, 5) = parseDouble(node_xc->getValue(), "xc");
1018  matrix6x6(1, 1) = parseDouble(node_yy->getValue(), "yy");
1019  matrix6x6(1, 2) = parseDouble(node_yz->getValue(), "yz");
1020  matrix6x6(1, 3) = parseDouble(node_ya->getValue(), "ya");
1021  matrix6x6(1, 4) = parseDouble(node_yb->getValue(), "yb");
1022  matrix6x6(1, 5) = parseDouble(node_yc->getValue(), "yc");
1023  matrix6x6(2, 2) = parseDouble(node_zz->getValue(), "zz");
1024  matrix6x6(2, 3) = parseDouble(node_za->getValue(), "za");
1025  matrix6x6(2, 4) = parseDouble(node_zb->getValue(), "zb");
1026  matrix6x6(2, 5) = parseDouble(node_zc->getValue(), "zc");
1027  matrix6x6(3, 3) = parseDouble(node_aa->getValue(), "aa");
1028  matrix6x6(3, 4) = parseDouble(node_ab->getValue(), "ab");
1029  matrix6x6(3, 5) = parseDouble(node_ac->getValue(), "ac");
1030  matrix6x6(4, 4) = parseDouble(node_bb->getValue(), "bb");
1031  matrix6x6(4, 5) = parseDouble(node_bc->getValue(), "bc");
1032  matrix6x6(5, 5) = parseDouble(node_cc->getValue(), "cc");
1033 
1034  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
1035  // this sets APEs at this level and (since 2nd argument is true) all lower levels
1036  aliiter->first->setAlignmentPositionError(AlignmentPositionError(matrix6x6), true);
1037  }
1038 }
1039 
1040 void MuonAlignmentInputXML::do_setsurveyerr(const XERCES_CPP_NAMESPACE::DOMElement *node,
1041  std::map<Alignable *, bool> &aliset,
1042  std::map<Alignable *, Alignable *> &alitoideal) const {
1043  DOMAttr *node_xx = node->getAttributeNode(str_xx);
1044  DOMAttr *node_xy = node->getAttributeNode(str_xy);
1045  DOMAttr *node_xz = node->getAttributeNode(str_xz);
1046  DOMAttr *node_xa = node->getAttributeNode(str_xa);
1047  DOMAttr *node_xb = node->getAttributeNode(str_xb);
1048  DOMAttr *node_xc = node->getAttributeNode(str_xc);
1049  DOMAttr *node_yy = node->getAttributeNode(str_yy);
1050  DOMAttr *node_yz = node->getAttributeNode(str_yz);
1051  DOMAttr *node_ya = node->getAttributeNode(str_ya);
1052  DOMAttr *node_yb = node->getAttributeNode(str_yb);
1053  DOMAttr *node_yc = node->getAttributeNode(str_yc);
1054  DOMAttr *node_zz = node->getAttributeNode(str_zz);
1055  DOMAttr *node_za = node->getAttributeNode(str_za);
1056  DOMAttr *node_zb = node->getAttributeNode(str_zb);
1057  DOMAttr *node_zc = node->getAttributeNode(str_zc);
1058  DOMAttr *node_aa = node->getAttributeNode(str_aa);
1059  DOMAttr *node_ab = node->getAttributeNode(str_ab);
1060  DOMAttr *node_ac = node->getAttributeNode(str_ac);
1061  DOMAttr *node_bb = node->getAttributeNode(str_bb);
1062  DOMAttr *node_bc = node->getAttributeNode(str_bc);
1063  DOMAttr *node_cc = node->getAttributeNode(str_cc);
1064 
1065  if (node_xx == nullptr)
1066  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"xx\" attribute" << std::endl;
1067  if (node_xy == nullptr)
1068  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"xy\" attribute" << std::endl;
1069  if (node_xz == nullptr)
1070  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"xz\" attribute" << std::endl;
1071  if (node_xa == nullptr)
1072  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"xa\" attribute" << std::endl;
1073  if (node_xb == nullptr)
1074  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"xb\" attribute" << std::endl;
1075  if (node_xc == nullptr)
1076  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"xc\" attribute" << std::endl;
1077  if (node_yy == nullptr)
1078  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"yy\" attribute" << std::endl;
1079  if (node_yz == nullptr)
1080  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"yz\" attribute" << std::endl;
1081  if (node_ya == nullptr)
1082  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"ya\" attribute" << std::endl;
1083  if (node_yb == nullptr)
1084  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"yb\" attribute" << std::endl;
1085  if (node_yc == nullptr)
1086  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"yc\" attribute" << std::endl;
1087  if (node_zz == nullptr)
1088  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"zz\" attribute" << std::endl;
1089  if (node_za == nullptr)
1090  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"za\" attribute" << std::endl;
1091  if (node_zb == nullptr)
1092  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"zb\" attribute" << std::endl;
1093  if (node_zc == nullptr)
1094  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"zc\" attribute" << std::endl;
1095  if (node_aa == nullptr)
1096  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"aa\" attribute" << std::endl;
1097  if (node_ab == nullptr)
1098  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"ab\" attribute" << std::endl;
1099  if (node_ac == nullptr)
1100  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"ac\" attribute" << std::endl;
1101  if (node_bb == nullptr)
1102  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"bb\" attribute" << std::endl;
1103  if (node_bc == nullptr)
1104  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"bc\" attribute" << std::endl;
1105  if (node_cc == nullptr)
1106  throw cms::Exception("XMLException") << "<setsurveyerr> is missing required \"cc\" attribute" << std::endl;
1107 
1108  align::ErrorMatrix matrix6x6;
1109  matrix6x6(0, 0) = parseDouble(node_xx->getValue(), "xx");
1110  matrix6x6(0, 1) = parseDouble(node_xy->getValue(), "xy");
1111  matrix6x6(0, 2) = parseDouble(node_xz->getValue(), "xz");
1112  matrix6x6(0, 3) = parseDouble(node_xa->getValue(), "xa");
1113  matrix6x6(0, 4) = parseDouble(node_xb->getValue(), "xb");
1114  matrix6x6(0, 5) = parseDouble(node_xc->getValue(), "xc");
1115  matrix6x6(1, 1) = parseDouble(node_yy->getValue(), "yy");
1116  matrix6x6(1, 2) = parseDouble(node_yz->getValue(), "yz");
1117  matrix6x6(1, 3) = parseDouble(node_ya->getValue(), "ya");
1118  matrix6x6(1, 4) = parseDouble(node_yb->getValue(), "yb");
1119  matrix6x6(1, 5) = parseDouble(node_yc->getValue(), "yc");
1120  matrix6x6(2, 2) = parseDouble(node_zz->getValue(), "zz");
1121  matrix6x6(2, 3) = parseDouble(node_za->getValue(), "za");
1122  matrix6x6(2, 4) = parseDouble(node_zb->getValue(), "zb");
1123  matrix6x6(2, 5) = parseDouble(node_zc->getValue(), "zc");
1124  matrix6x6(3, 3) = parseDouble(node_aa->getValue(), "aa");
1125  matrix6x6(3, 4) = parseDouble(node_ab->getValue(), "ab");
1126  matrix6x6(3, 5) = parseDouble(node_ac->getValue(), "ac");
1127  matrix6x6(4, 4) = parseDouble(node_bb->getValue(), "bb");
1128  matrix6x6(4, 5) = parseDouble(node_bc->getValue(), "bc");
1129  matrix6x6(5, 5) = parseDouble(node_cc->getValue(), "cc");
1130 
1131  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
1132  Alignable *ali = aliiter->first;
1133  ali->setSurvey(new SurveyDet(ali->surface(), matrix6x6));
1134  }
1135 }
1136 
1137 void MuonAlignmentInputXML::do_moveglobal(const XERCES_CPP_NAMESPACE::DOMElement *node,
1138  std::map<Alignable *, bool> &aliset,
1139  std::map<Alignable *, Alignable *> &alitoideal) const {
1140  DOMAttr *node_x = node->getAttributeNode(str_x);
1141  DOMAttr *node_y = node->getAttributeNode(str_y);
1142  DOMAttr *node_z = node->getAttributeNode(str_z);
1143  if (node_x == nullptr)
1144  throw cms::Exception("XMLException") << "<moveglobal> is missing required \"x\" attribute" << std::endl;
1145  if (node_y == nullptr)
1146  throw cms::Exception("XMLException") << "<moveglobal> is missing required \"y\" attribute" << std::endl;
1147  if (node_z == nullptr)
1148  throw cms::Exception("XMLException") << "<moveglobal> is missing required \"z\" attribute" << std::endl;
1149 
1150  double x = parseDouble(node_x->getValue(), "x");
1151  double y = parseDouble(node_y->getValue(), "y");
1152  double z = parseDouble(node_z->getValue(), "z");
1153  align::GlobalVector vect(x, y, z);
1154 
1155  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
1156  Alignable *ali = aliiter->first;
1157 
1158  ali->move(vect);
1159 
1160  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
1161  matrix6x6 *= 1000.; // initial assumption: infinitely weak constraint
1162 
1163  const SurveyDet *survey = ali->survey();
1164  if (survey != nullptr) {
1165  matrix6x6 = survey->errors(); // save the constraint information
1166  }
1167  ali->setSurvey(new SurveyDet(ali->surface(), matrix6x6));
1168  } // end loop over alignables
1169 }
1170 
1171 void MuonAlignmentInputXML::do_movelocal(const XERCES_CPP_NAMESPACE::DOMElement *node,
1172  std::map<Alignable *, bool> &aliset,
1173  std::map<Alignable *, Alignable *> &alitoideal) const {
1174  DOMAttr *node_x = node->getAttributeNode(str_x);
1175  DOMAttr *node_y = node->getAttributeNode(str_y);
1176  DOMAttr *node_z = node->getAttributeNode(str_z);
1177  if (node_x == nullptr)
1178  throw cms::Exception("XMLException") << "<movelocal> is missing required \"x\" attribute" << std::endl;
1179  if (node_y == nullptr)
1180  throw cms::Exception("XMLException") << "<movelocal> is missing required \"y\" attribute" << std::endl;
1181  if (node_z == nullptr)
1182  throw cms::Exception("XMLException") << "<movelocal> is missing required \"z\" attribute" << std::endl;
1183 
1184  double x = parseDouble(node_x->getValue(), "x");
1185  double y = parseDouble(node_y->getValue(), "y");
1186  double z = parseDouble(node_z->getValue(), "z");
1187  align::LocalVector vect(x, y, z);
1188 
1189  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
1190  Alignable *ali = aliiter->first;
1191 
1192  align::GlobalVector globalVector = ali->surface().toGlobal(vect);
1193  ali->move(globalVector);
1194 
1195  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
1196  matrix6x6 *= 1000.; // initial assumption: infinitely weak constraint
1197 
1198  const SurveyDet *survey = ali->survey();
1199  if (survey != nullptr) {
1200  matrix6x6 = survey->errors(); // save the constraint information
1201  }
1202  ali->setSurvey(new SurveyDet(ali->surface(), matrix6x6));
1203  } // end loop over alignables
1204 }
1205 
1206 void MuonAlignmentInputXML::do_rotatelocal(const XERCES_CPP_NAMESPACE::DOMElement *node,
1207  std::map<Alignable *, bool> &aliset,
1208  std::map<Alignable *, Alignable *> &alitoideal) const {
1209  DOMAttr *node_axisx = node->getAttributeNode(str_axisx);
1210  DOMAttr *node_axisy = node->getAttributeNode(str_axisy);
1211  DOMAttr *node_axisz = node->getAttributeNode(str_axisz);
1212  DOMAttr *node_angle = node->getAttributeNode(str_angle);
1213  if (node_axisx == nullptr)
1214  throw cms::Exception("XMLException") << "<rotatelocal> is missing required \"axisx\" attribute" << std::endl;
1215  if (node_axisy == nullptr)
1216  throw cms::Exception("XMLException") << "<rotatelocal> is missing required \"axisy\" attribute" << std::endl;
1217  if (node_axisz == nullptr)
1218  throw cms::Exception("XMLException") << "<rotatelocal> is missing required \"axisz\" attribute" << std::endl;
1219  if (node_angle == nullptr)
1220  throw cms::Exception("XMLException") << "<rotatelocal> is missing required \"angle\" attribute" << std::endl;
1221 
1222  double x = parseDouble(node_axisx->getValue(), "x");
1223  double y = parseDouble(node_axisy->getValue(), "y");
1224  double z = parseDouble(node_axisz->getValue(), "z");
1225  double angle = parseDouble(node_angle->getValue(), "angle");
1226  align::LocalVector vect(x, y, z);
1227 
1228  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
1229  Alignable *ali = aliiter->first;
1230 
1231  ali->rotateAroundLocalAxis(vect, angle);
1232 
1233  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
1234  matrix6x6 *= 1000.; // initial assumption: infinitely weak constraint
1235 
1236  const SurveyDet *survey = ali->survey();
1237  if (survey != nullptr) {
1238  matrix6x6 = survey->errors(); // save the constraint information
1239  }
1240  ali->setSurvey(new SurveyDet(ali->surface(), matrix6x6));
1241  } // end loop over alignables
1242 }
1243 
1244 void MuonAlignmentInputXML::do_rotatebeamline(const XERCES_CPP_NAMESPACE::DOMElement *node,
1245  std::map<Alignable *, bool> &aliset,
1246  std::map<Alignable *, Alignable *> &alitoideal) const {
1247  DOMAttr *node_rphi = node->getAttributeNode(str_rphi);
1248  DOMAttr *node_phi = node->getAttributeNode(str_phi);
1249  if (node_rphi == nullptr && node_phi == nullptr)
1250  throw cms::Exception("XMLException") << "<rotatebeamline> is missing required \"*phi\" attribute" << std::endl;
1251  if (node_rphi != nullptr && node_phi != nullptr)
1252  throw cms::Exception("XMLException") << "<rotatebeamline> can't have both an \"rphi\" and a \"phi\" attribute"
1253  << std::endl;
1254 
1255  double value;
1256  if (node_rphi != nullptr) {
1257  value = parseDouble(node_rphi->getValue(), "rphi");
1258  } else {
1259  value = parseDouble(node_phi->getValue(), "phi");
1260  }
1261 
1262  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
1263  Alignable *ali = aliiter->first;
1264 
1266 
1267  double radius = pos.perp();
1268  double phi0 = pos.phi();
1269  double deltaphi = value;
1270  if (node_rphi != nullptr)
1271  deltaphi = value / radius;
1272 
1273  ali->rotateAroundGlobalZ(deltaphi);
1275  radius * (cos(phi0 + deltaphi) - cos(phi0)), radius * (sin(phi0 + deltaphi) - sin(phi0)), 0.));
1276 
1277  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
1278  matrix6x6 *= 1000.; // initial assumption: infinitely weak constraint
1279 
1280  const SurveyDet *survey = ali->survey();
1281  if (survey != nullptr) {
1282  matrix6x6 = survey->errors(); // save the constraint information
1283  }
1284  ali->setSurvey(new SurveyDet(ali->surface(), matrix6x6));
1285  } // end loop over alignables
1286 }
1287 
1288 void MuonAlignmentInputXML::do_rotateglobalaxis(const XERCES_CPP_NAMESPACE::DOMElement *node,
1289  std::map<Alignable *, bool> &aliset,
1290  std::map<Alignable *, Alignable *> &alitoideal) const {
1291  DOMAttr *node_x = node->getAttributeNode(str_x);
1292  DOMAttr *node_y = node->getAttributeNode(str_y);
1293  DOMAttr *node_z = node->getAttributeNode(str_z);
1294  DOMAttr *node_angle = node->getAttributeNode(str_angle);
1295  if (node_x == nullptr)
1296  throw cms::Exception("XMLException") << "<rotateglobalaxis> is missing required \"x\" attribute" << std::endl;
1297  if (node_y == nullptr)
1298  throw cms::Exception("XMLException") << "<rotateglobalaxis> is missing required \"y\" attribute" << std::endl;
1299  if (node_z == nullptr)
1300  throw cms::Exception("XMLException") << "<rotateglobalaxis> is missing required \"z\" attribute" << std::endl;
1301  if (node_angle == nullptr)
1302  throw cms::Exception("XMLException") << "<rotateglobalaxis> is missing required \"angle\" attribute" << std::endl;
1303 
1304  double x = parseDouble(node_x->getValue(), "x");
1305  double y = parseDouble(node_y->getValue(), "y");
1306  double z = parseDouble(node_z->getValue(), "z");
1307  double angle = parseDouble(node_angle->getValue(), "angle");
1308 
1309  for (std::map<Alignable *, bool>::const_iterator aliiter = aliset.begin(); aliiter != aliset.end(); ++aliiter) {
1310  Alignable *ali = aliiter->first;
1312 
1313  ali->rotateAroundGlobalAxis(align::GlobalVector(x, y, z), angle);
1314 
1315  double aprime = x / sqrt(x * x + y * y + z * z);
1316  double bprime = y / sqrt(x * x + y * y + z * z);
1317  double cprime = z / sqrt(x * x + y * y + z * z);
1318  double q0 = cos(angle / 2.);
1319  double q1 = sin(angle / 2.) * aprime;
1320  double q2 = sin(angle / 2.) * bprime;
1321  double q3 = sin(angle / 2.) * cprime;
1322 
1323  double pos2x = (q0 * q0 + q1 * q1 - q2 * q2 - q3 * q3) * pos.x() + 2. * (q1 * q2 - q0 * q3) * pos.y() +
1324  2. * (q1 * q3 + q0 * q2) * pos.z();
1325  double pos2y = 2. * (q2 * q1 + q0 * q3) * pos.x() + (q0 * q0 - q1 * q1 + q2 * q2 - q3 * q3) * pos.y() +
1326  2. * (q2 * q3 - q0 * q1) * pos.z();
1327  double pos2z = 2. * (q3 * q1 - q0 * q2) * pos.x() + 2. * (q3 * q2 + q0 * q1) * pos.y() +
1328  (q0 * q0 - q1 * q1 - q2 * q2 + q3 * q3) * pos.z();
1329 
1330  double movex = pos2x - pos.x();
1331  double movey = pos2y - pos.y();
1332  double movez = pos2z - pos.z();
1333  ali->move(align::GlobalVector(movex, movey, movez));
1334 
1335  align::ErrorMatrix matrix6x6 = ROOT::Math::SMatrixIdentity();
1336  matrix6x6 *= 1000.; // initial assumption: infinitely weak constraint
1337 
1338  const SurveyDet *survey = ali->survey();
1339  if (survey != nullptr) {
1340  matrix6x6 = survey->errors(); // save the constraint information
1341  }
1342  ali->setSurvey(new SurveyDet(ali->surface(), matrix6x6));
1343  } // end loop over alignables
1344 }
1345 
1346 //
1347 // const member functions
1348 //
1349 
1350 //
1351 // static member functions
1352 //
T xx() const
void do_setsurveyerr(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
TkRotation< Scalar > RotationType
Definition: Definitions.h:27
T perp() const
Definition: PV3DBase.h:69
Alignable * getNode(std::map< unsigned int, Alignable * > &alignableNavigator, const XERCES_CPP_NAMESPACE::DOMElement *node, const AlignableObjectId &) const
virtual void rotateAroundLocalAxis(const LocalVector &axis, Scalar radians)
Rotation around arbitratry local axis.
Definition: Alignable.cc:143
double parseDouble(const XMLCh *str, const char *attribute) const
void do_rotatelocal(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
void xercesTerminate()
Definition: Xerces.cc:23
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
align::Alignables DTBarrel()
const SurveyDet * survey() const
Return survey info.
Definition: Alignable.h:216
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Alignable * getCSCnode(align::StructureType structureType, std::map< unsigned int, Alignable * > &alignableNavigator, const XERCES_CPP_NAMESPACE::DOMElement *node, const AlignableObjectId &) const
T y() const
Definition: PV3DBase.h:60
std::shared_ptr< DTGeometry > idealDTGeometry(const edm::EventSetup &iSetup) const
const RotationType & globalRotation() const
Return the global orientation of the object.
Definition: Alignable.h:138
void do_movelocal(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
virtual void move(const GlobalVector &displacement)=0
Movement with respect to the global reference frame.
void do_moveglobal(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
const align::ErrorMatrix & errors() const
Definition: SurveyDet.h:62
void xercesInitialize()
Definition: Xerces.cc:18
const AlignableObjectId & objectIdProvider() const
Return muon alignable object ID provider derived from the muon system geometry.
Definition: AlignableMuon.h:77
virtual void rotateAroundGlobalAxis(const GlobalVector &axis, Scalar radians)
Rotation around arbitratry global axis.
Definition: Alignable.cc:138
double q2[4]
Definition: TauolaWrapper.h:88
virtual void rotateAroundGlobalZ(Scalar radians)
Rotation around global z-axis.
Definition: Alignable.cc:176
void do_rotatebeamline(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:28
T xy() const
std::shared_ptr< CSCGeometry > idealCSCGeometry(const edm::EventSetup &iSetup) const
T zz() const
align::Alignables CSCEndcaps()
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void rectify(RotationType &)
Correct a rotation matrix for rounding errors.
Definition: Utilities.cc:185
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
void recursiveGetId(std::map< unsigned int, Alignable * > &alignableNavigator, const align::Alignables &alignables) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void do_setape(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
Allows conversion between type and name, and vice-versa.
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:8
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
AlgebraicVector EulerAngles
Definition: Definitions.h:34
bool equals(const edm::RefToBase< Jet > &j1, const edm::RefToBase< Jet > &j2)
AlignableMuon * newAlignableMuon(const edm::EventSetup &iSetup) const override
const char * idToString(align::StructureType type) const
virtual void rotateInGlobalFrame(const RotationType &rotation)=0
double q1[4]
Definition: TauolaWrapper.h:87
void setSurvey(const SurveyDet *)
Set survey info.
Definition: Alignable.cc:266
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
T xz() const
TkRotation transposed() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
RotationType toMatrix(const EulerAngles &)
Convert rotation angles about x-, y-, z-axes to matrix.
Definition: Utilities.cc:34
MuonAlignmentInputXML(const std::string &fileName)
void do_rotateglobalaxis(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:135
alpha
zGenParticlesMatch = cms.InputTag(""),
math::Error< 6 >::type ErrorMatrix
Definition: Definitions.h:37
Alignable * getDTnode(align::StructureType structureType, std::map< unsigned int, Alignable * > &alignableNavigator, const XERCES_CPP_NAMESPACE::DOMElement *node, const AlignableObjectId &) const
void fillAliToIdeal(std::map< Alignable *, Alignable * > &alitoideal, const align::Alignables &alignables, const align::Alignables &ideals) const
void do_setposition(const XERCES_CPP_NAMESPACE::DOMElement *node, std::map< Alignable *, bool > &aliset, std::map< Alignable *, Alignable * > &alitoideal) const
Basic3DVector< T > multiplyInverse(const Basic3DVector< T > &v) const
void set_one_position(Alignable *ali, const align::PositionType &pos, const align::RotationType &rot) const
#define str(s)
Constructor of the full muon geometry.
Definition: AlignableMuon.h:33
T x() const
Definition: PV3DBase.h:59
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
T yz() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11