CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

MuonAlignmentOutputXML Class Reference

#include <Alignment/MuonAlignment/interface/MuonAlignmentOutputXML.h>

List of all members.

Public Member Functions

 MuonAlignmentOutputXML (const edm::ParameterSet &iConfig)
void write (AlignableMuon *alignableMuon, const edm::EventSetup &iSetup) const
virtual ~MuonAlignmentOutputXML ()

Private Member Functions

 MuonAlignmentOutputXML (const MuonAlignmentOutputXML &)
const MuonAlignmentOutputXMLoperator= (const MuonAlignmentOutputXML &)
void writeComponents (std::vector< Alignable * > &alignables, std::vector< Alignable * > &ideals, std::map< align::ID, CLHEP::HepSymMatrix > &errors, std::ofstream &outputFile, bool DT) const

Private Attributes

bool m_eulerAngles
std::string m_fileName
int m_precision
bool m_rawIds
int m_relativeto
bool m_suppressCSCChambers
bool m_suppressCSCEndcaps
bool m_suppressCSCLayers
bool m_suppressCSCRings
bool m_suppressCSCStations
bool m_suppressDTBarrel
bool m_suppressDTChambers
bool m_suppressDTLayers
bool m_suppressDTStations
bool m_suppressDTSuperLayers
bool m_suppressDTWheels
bool m_survey

Detailed Description

Description: <one line="" class="" summary>="">

Usage: <usage>

Definition at line 34 of file MuonAlignmentOutputXML.h.


Constructor & Destructor Documentation

MuonAlignmentOutputXML::MuonAlignmentOutputXML ( const edm::ParameterSet iConfig)

Definition at line 44 of file MuonAlignmentOutputXML.cc.

References Exception, edm::ParameterSet::getParameter(), and m_relativeto.

   : m_fileName(iConfig.getParameter<std::string>("fileName"))
   , m_survey(iConfig.getParameter<bool>("survey"))
   , m_rawIds(iConfig.getParameter<bool>("rawIds"))
   , m_eulerAngles(iConfig.getParameter<bool>("eulerAngles"))
   , m_precision(iConfig.getParameter<int>("precision"))
   , m_suppressDTBarrel(iConfig.getUntrackedParameter<bool>("suppressDTBarrel", false))
   , m_suppressDTWheels(iConfig.getUntrackedParameter<bool>("suppressDTWheels", false))
   , m_suppressDTStations(iConfig.getUntrackedParameter<bool>("suppressDTStations", false))
   , m_suppressDTChambers(iConfig.getUntrackedParameter<bool>("suppressDTChambers", false))
   , m_suppressDTSuperLayers(iConfig.getUntrackedParameter<bool>("suppressDTSuperLayers", false))
   , m_suppressDTLayers(iConfig.getUntrackedParameter<bool>("suppressDTLayers", false))
   , m_suppressCSCEndcaps(iConfig.getUntrackedParameter<bool>("suppressCSCEndcaps", false))
   , m_suppressCSCStations(iConfig.getUntrackedParameter<bool>("suppressCSCStations", false))
   , m_suppressCSCRings(iConfig.getUntrackedParameter<bool>("suppressCSCRings", false))
   , m_suppressCSCChambers(iConfig.getUntrackedParameter<bool>("suppressCSCChambers", false))
   , m_suppressCSCLayers(iConfig.getUntrackedParameter<bool>("suppressCSCLayers", false))
{
   std::string str_relativeto = iConfig.getParameter<std::string>("relativeto");

   if (str_relativeto == std::string("none")) {
      m_relativeto = 0;
   }
   else if (str_relativeto == std::string("ideal")) {
      m_relativeto = 1;
   }
   else if (str_relativeto == std::string("container")) {
      m_relativeto = 2;
   }
   else {
      throw cms::Exception("BadConfig") << "relativeto must be \"none\", \"ideal\", or \"container\"" << std::endl;
   }
}
MuonAlignmentOutputXML::~MuonAlignmentOutputXML ( ) [virtual]

Definition at line 83 of file MuonAlignmentOutputXML.cc.

{
}
MuonAlignmentOutputXML::MuonAlignmentOutputXML ( const MuonAlignmentOutputXML ) [private]

Member Function Documentation

const MuonAlignmentOutputXML& MuonAlignmentOutputXML::operator= ( const MuonAlignmentOutputXML ) [private]
void MuonAlignmentOutputXML::write ( AlignableMuon alignableMuon,
const edm::EventSetup iSetup 
) const

Definition at line 103 of file MuonAlignmentOutputXML.cc.

References DTGeometryBuilderFromDDD::build(), CSCGeometryBuilderFromDDD::build(), AlignableMuon::cscAlignmentErrors(), AlignableMuon::CSCEndcaps(), AlignableMuon::dtAlignmentErrors(), AlignableMuon::DTBarrel(), benchmark_cfg::errors, edm::EventSetup::get(), AlignmentErrors::m_alignError, m_fileName, m_precision, m_relativeto, download_sqlite_cfg::outputFile, and writeComponents().

Referenced by MuonAlignment::writeXML().

                                                                                                  {
   std::ofstream outputFile(m_fileName.c_str());
   outputFile << std::setprecision(m_precision) << std::fixed;

   outputFile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
   outputFile << "<?xml-stylesheet type=\"text/xml\" href=\"MuonAlignment.xsl\"?>" << std::endl;
   outputFile << "<MuonAlignment>" << std::endl << std::endl;
   
   std::map<align::ID, CLHEP::HepSymMatrix> errors;
   AlignmentErrors *dtErrors = alignableMuon->dtAlignmentErrors();
   AlignmentErrors *cscErrors = alignableMuon->cscAlignmentErrors();
   for (std::vector<AlignTransformError>::const_iterator dtError = dtErrors->m_alignError.begin();  dtError != dtErrors->m_alignError.end();  ++dtError) {
      errors[dtError->rawId()] = dtError->matrix();
   }
   for (std::vector<AlignTransformError>::const_iterator cscError = cscErrors->m_alignError.begin();  cscError != cscErrors->m_alignError.end();  ++cscError) {
      errors[cscError->rawId()] = cscError->matrix();
   }

   std::vector<Alignable*> barrels = alignableMuon->DTBarrel();
   std::vector<Alignable*> endcaps = alignableMuon->CSCEndcaps();

   if (m_relativeto == 1) {
      edm::ESTransientHandle<DDCompactView> cpv;
      iSetup.get<IdealGeometryRecord>().get(cpv);

      edm::ESHandle<MuonDDDConstants> mdc;
      iSetup.get<MuonNumberingRecord>().get(mdc);
      DTGeometryBuilderFromDDD DTGeometryBuilder;
      CSCGeometryBuilderFromDDD CSCGeometryBuilder;
 
      boost::shared_ptr<DTGeometry> dtGeometry(new DTGeometry );
      DTGeometryBuilder.build(dtGeometry, &(*cpv), *mdc);

      boost::shared_ptr<CSCGeometry> boost_cscGeometry(new CSCGeometry);
      CSCGeometryBuilder.build(boost_cscGeometry, &(*cpv), *mdc);

      AlignableMuon ideal_alignableMuon(&(*dtGeometry), &(*boost_cscGeometry));

      std::vector<Alignable*> ideal_barrels = ideal_alignableMuon.DTBarrel();
      std::vector<Alignable*> ideal_endcaps = ideal_alignableMuon.CSCEndcaps();

      writeComponents(barrels, ideal_barrels, errors, outputFile, true);
      writeComponents(endcaps, ideal_endcaps, errors, outputFile, false);
   }
   else {
      std::vector<Alignable*> empty1, empty2;

      writeComponents(barrels, empty1, errors, outputFile, true);
      writeComponents(endcaps, empty2, errors, outputFile, false);
   }

   outputFile << "</MuonAlignment>" << std::endl;
}
void MuonAlignmentOutputXML::writeComponents ( std::vector< Alignable * > &  alignables,
std::vector< Alignable * > &  ideals,
std::map< align::ID, CLHEP::HepSymMatrix > &  errors,
std::ofstream &  outputFile,
bool  DT 
) const [private]

Definition at line 157 of file MuonAlignmentOutputXML.cc.

References align::AlignableCSCChamber, align::AlignableCSCEndcap, align::AlignableCSCRing, align::AlignableCSCStation, align::AlignableDetUnit, align::AlignableDTBarrel, align::AlignableDTChamber, align::AlignableDTStation, align::AlignableDTSuperLayer, align::AlignableDTWheel, PV3DBase< T, PVType, FrameType >::basicVector(), CSCDetId::endcap(), Exception, m_eulerAngles, m_rawIds, m_relativeto, m_suppressCSCChambers, m_suppressCSCEndcaps, m_suppressCSCLayers, m_suppressCSCRings, m_suppressCSCStations, m_suppressDTBarrel, m_suppressDTChambers, m_suppressDTLayers, m_suppressDTStations, m_suppressDTSuperLayers, m_suppressDTWheels, m_survey, NULL, pos, align::toAngles(), TkRotation< T >::transposed(), AlignableObjectId::typeToName(), DTChamberId::wheel(), PV3DBase< T, PVType, FrameType >::x(), TkRotation< T >::xx(), TkRotation< T >::xy(), TkRotation< T >::xz(), PV3DBase< T, PVType, FrameType >::y(), TkRotation< T >::yz(), PV3DBase< T, PVType, FrameType >::z(), and TkRotation< T >::zz().

Referenced by write().

                                                                                                                                 {
   std::vector<Alignable*>::const_iterator ideal = ideals.begin();
   for (std::vector<Alignable*>::const_iterator alignable = alignables.begin();  alignable != alignables.end();  ++alignable) {
      if (m_survey  &&  (*alignable)->survey() == NULL) {
         throw cms::Exception("Alignment") << "SurveyDets must all be defined when writing to XML" << std::endl;
      } // now I can assume it's okay everywhere

      align::StructureType alignableObjectId = (*alignable)->alignableObjectId();

      if ((alignableObjectId == align::AlignableDTBarrel  &&  !m_suppressDTBarrel)  ||
          (alignableObjectId == align::AlignableDTWheel  &&  !m_suppressDTWheels)  ||
          (alignableObjectId == align::AlignableDTStation  &&  !m_suppressDTStations)  ||
          (alignableObjectId == align::AlignableDTChamber  &&  !m_suppressDTChambers)  ||
          (DT  &&  alignableObjectId == align::AlignableDTSuperLayer  &&  !m_suppressDTSuperLayers)  ||
          (DT  &&  alignableObjectId == align::AlignableDetUnit  &&  !m_suppressDTLayers)  ||
          (alignableObjectId == align::AlignableCSCEndcap  &&  !m_suppressCSCEndcaps)  ||
          (alignableObjectId == align::AlignableCSCStation  &&  !m_suppressCSCStations)  ||
          (alignableObjectId == align::AlignableCSCRing  &&  !m_suppressCSCRings)  ||
          (alignableObjectId == align::AlignableCSCChamber  &&  !m_suppressCSCChambers)  ||
          (!DT  &&  alignableObjectId == align::AlignableDetUnit  &&  !m_suppressCSCLayers)) {

         unsigned int rawId = (*alignable)->geomDetId().rawId();
         outputFile << "<operation>" << std::endl;

         if (DT) {
            if (m_rawIds  &&  rawId != 0) {
               static AlignableObjectId converter;
               std::string typeName = converter.typeToName(alignableObjectId);
               if (alignableObjectId == align::AlignableDTSuperLayer) typeName = std::string("DTSuperLayer");
               if (alignableObjectId == align::AlignableDetUnit) typeName = std::string("DTLayer");
               outputFile << "  <" << typeName << " rawId=\"" << rawId << "\" />" << std::endl;
            }
            else {
               if (alignableObjectId == align::AlignableDetUnit) {
                  DTLayerId id(rawId);
                  outputFile << "  <DTLayer wheel=\"" << id.wheel() << "\" station=\"" << id.station() << "\" sector=\"" << id.sector() << "\" superlayer=\"" << id.superlayer() << "\" layer=\"" << id.layer() << "\" />" << std::endl;
               }
               else if (alignableObjectId == align::AlignableDTSuperLayer) {
                  DTSuperLayerId id(rawId);
                  outputFile << "  <DTSuperLayer wheel=\"" << id.wheel() << "\" station=\"" << id.station() << "\" sector=\"" << id.sector() << "\" superlayer=\"" << id.superlayer() << "\" />" << std::endl;
               }
               else if (alignableObjectId == align::AlignableDTChamber) {
                  DTChamberId id(rawId);
                  outputFile << "  <DTChamber wheel=\"" << id.wheel() << "\" station=\"" << id.station() << "\" sector=\"" << id.sector() << "\" />" << std::endl;
               }

               else {
                  DTChamberId id((*alignable)->id());
                  if (alignableObjectId == align::AlignableDTStation) {
                     outputFile << "  <DTStation wheel=\"" << id.wheel() << "\" station=\"" << id.station() << "\" />" << std::endl;
                  }
                  else if (alignableObjectId == align::AlignableDTWheel) {
                     outputFile << "  <DTWheel wheel=\"" << id.wheel() << "\" />" << std::endl;
                  }
                  else if (alignableObjectId == align::AlignableDTBarrel) {
                     outputFile << "  <DTBarrel />" << std::endl;
                  }
                  else throw cms::Exception("Alignment") << "Unknown DT Alignable StructureType" << std::endl;
               }

            } // end if not rawId
         } // end if DT

         else { // CSC
            if (m_rawIds  &&  rawId != 0) {
               static AlignableObjectId converter;
               std::string typeName = converter.typeToName(alignableObjectId);
               if (alignableObjectId == align::AlignableDetUnit) typeName = std::string("CSCLayer");
               outputFile << "  <" << typeName << " rawId=\"" << rawId << "\" />" << std::endl;
            }
            else {
               if (alignableObjectId == align::AlignableDetUnit) {
                  CSCDetId id(rawId);
                  outputFile << "  <CSCLayer endcap=\"" << id.endcap() << "\" station=\"" << id.station() << "\" ring=\"" << id.ring() << "\" chamber=\"" << id.chamber() << "\" layer=\"" << id.layer() << "\" />" << std::endl;
               }
               else if (alignableObjectId == align::AlignableCSCChamber) {
                  CSCDetId id(rawId);
                  outputFile << "  <CSCChamber endcap=\"" << id.endcap() << "\" station=\"" << id.station() << "\" ring=\"" << id.ring() << "\" chamber=\"" << id.chamber() << "\" />" << std::endl;
               }
               else {
                  CSCDetId id((*alignable)->id());
                  if (alignableObjectId == align::AlignableCSCRing) {
                     outputFile << "  <CSCRing endcap=\"" << id.endcap() << "\" station=\"" << id.station() << "\" ring=\"" << id.ring() << "\" />" << std::endl;
                  }
                  else if (alignableObjectId == align::AlignableCSCStation) {
                     outputFile << "  <CSCStation endcap=\"" << id.endcap() << "\" station=\"" << id.station() << "\" />" << std::endl;
                  }
                  else if (alignableObjectId == align::AlignableCSCEndcap) {
                     outputFile << "  <CSCEndcap endcap=\"" << id.endcap() << "\" />" << std::endl;
                  }
                  else throw cms::Exception("Alignment") << "Unknown CSC Alignable StructureType" << std::endl;
               
               }

            } // end if not rawId
         } // end if CSC

         align::PositionType pos = (*alignable)->globalPosition();
         align::RotationType rot = (*alignable)->globalRotation();

         if (m_survey) {
            pos = (*alignable)->survey()->position();
            rot = (*alignable)->survey()->rotation();
         }

         std::string str_relativeto;
         if (m_relativeto == 0) {
            str_relativeto = std::string("none");
         }

         else if (m_relativeto == 1) {
            if (ideal == ideals.end()  ||  (*ideal)->alignableObjectId() != alignableObjectId  ||  (*ideal)->id() != (*alignable)->id()) {
               throw cms::Exception("Alignment") << "AlignableMuon and ideal_AlignableMuon are out of sync!" << std::endl;
            }

            align::PositionType idealPosition = (*ideal)->globalPosition();
            align::RotationType idealRotation = (*ideal)->globalRotation();

            pos = align::PositionType(idealRotation * (pos.basicVector() - idealPosition.basicVector()));
            rot = rot * idealRotation.transposed();

            str_relativeto = std::string("ideal");
         }

         else if (m_relativeto == 2  &&  (*alignable)->mother() != NULL) {
            align::PositionType globalPosition = (*alignable)->mother()->globalPosition();
            align::RotationType globalRotation = (*alignable)->mother()->globalRotation();

            pos = align::PositionType(globalRotation * (pos.basicVector() - globalPosition.basicVector()));
            rot = rot * globalRotation.transposed();

            str_relativeto = std::string("container");
         }

         else assert(false);  // can't happen: see constructor

         outputFile << "  <setposition relativeto=\"" << str_relativeto << "\" "
                    << "x=\"" << pos.x() << "\" y=\"" << pos.y() << "\" z=\"" << pos.z() << "\" ";

         if (m_eulerAngles) {
            align::EulerAngles eulerAngles = align::toAngles(rot);
            outputFile << "alpha=\"" << eulerAngles(1) << "\" beta=\"" << eulerAngles(2) << "\" gamma=\"" << eulerAngles(3) << "\" />" << std::endl;
         }
         
         else {
            // the angle convention originally used in alignment, also known as "non-standard Euler angles with a Z-Y-X convention"
            // this also gets the sign convention right
            double phix = atan2(rot.yz(), rot.zz());
            double phiy = asin(-rot.xz());
            double phiz = atan2(rot.xy(), rot.xx());
            
            outputFile << "phix=\"" << phix << "\" phiy=\"" << phiy << "\" phiz=\"" << phiz << "\" />" << std::endl;
         }

         if (m_survey) {
            align::ErrorMatrix err = (*alignable)->survey()->errors();

            outputFile << "  <setsurveyerr"
                       <<   " xx=\"" << err(0,0) << "\" xy=\"" << err(0,1) << "\" xz=\"" << err(0,2) << "\" xa=\"" << err(0,3) << "\" xb=\"" << err(0,4) << "\" xc=\"" << err(0,5)
                       << "\" yy=\"" << err(1,1) << "\" yz=\"" << err(1,2) << "\" ya=\"" << err(1,3) << "\" yb=\"" << err(1,4) << "\" yc=\"" << err(1,5)
                       << "\" zz=\"" << err(2,2) << "\" za=\"" << err(2,3) << "\" zb=\"" << err(2,4) << "\" zc=\"" << err(2,5)
                       << "\" aa=\"" << err(3,3) << "\" ab=\"" << err(3,4) << "\" ac=\"" << err(3,5)
                       << "\" bb=\"" << err(4,4) << "\" bc=\"" << err(4,5)
                       << "\" cc=\"" << err(5,5) << "\" />" << std::endl;
         }

         else if (rawId != 0) {
            CLHEP::HepSymMatrix err = errors[(*alignable)->id()];

            outputFile << "  <setape xx=\"" << err(1,1) << "\" xy=\"" << err(1,2) << "\" xz=\"" << err(1,3)
                       << "\" yy=\"" << err(2,2) << "\" yz=\"" << err(2,3) << "\" zz=\"" << err(3,3) << "\" />" << std::endl;
         }

         outputFile << "</operation>" << std::endl << std::endl;

      } // end if not suppressed

      // write superstructures before substructures: this is important because <setape> overwrites all substructures' APEs
      if (ideal != ideals.end()) {
         std::vector<Alignable*> components = (*alignable)->components();
         std::vector<Alignable*> ideal_components = (*ideal)->components();
         writeComponents(components, ideal_components, errors, outputFile, DT);
         ++ideal; // important for synchronization in the "for" loop!
      }
      else {
         std::vector<Alignable*> components = (*alignable)->components();
         std::vector<Alignable*> dummy;
         writeComponents(components, dummy, errors, outputFile, DT);
      }

   } // end loop over alignables
}

Member Data Documentation

Definition at line 59 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

std::string MuonAlignmentOutputXML::m_fileName [private]

Definition at line 57 of file MuonAlignmentOutputXML.h.

Referenced by write().

Definition at line 60 of file MuonAlignmentOutputXML.h.

Referenced by write().

Definition at line 59 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 58 of file MuonAlignmentOutputXML.h.

Referenced by MuonAlignmentOutputXML(), write(), and writeComponents().

Definition at line 62 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 62 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 62 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 62 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 62 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 61 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 61 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 61 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 61 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 61 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 61 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().

Definition at line 59 of file MuonAlignmentOutputXML.h.

Referenced by writeComponents().