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