test
CMS 3D CMS Logo

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