CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/Alignment/MuonAlignment/src/MuonAlignmentInputSurveyDB.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     MuonAlignment
00004 // Class  :     MuonAlignmentInputSurveyDB
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Jim Pivarski
00010 //         Created:  Thu Mar  6 17:30:46 CST 2008
00011 // $Id: MuonAlignmentInputSurveyDB.cc,v 1.2 2008/03/20 21:39:26 pivarski Exp $
00012 //
00013 
00014 // system include files
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 
00017 // user include files
00018 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputSurveyDB.h"
00019 #include "CondFormats/AlignmentRecord/interface/DTSurveyRcd.h"
00020 #include "CondFormats/AlignmentRecord/interface/DTSurveyErrorRcd.h"
00021 #include "CondFormats/AlignmentRecord/interface/CSCSurveyRcd.h"
00022 #include "CondFormats/AlignmentRecord/interface/CSCSurveyErrorRcd.h"
00023 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00024 
00025 //
00026 // constants, enums and typedefs
00027 //
00028 
00029 //
00030 // static data member definitions
00031 //
00032 
00033 //
00034 // constructors and destructor
00035 //
00036 MuonAlignmentInputSurveyDB::MuonAlignmentInputSurveyDB()
00037    : m_dtLabel(""), m_cscLabel("") {}
00038 
00039 MuonAlignmentInputSurveyDB::MuonAlignmentInputSurveyDB(std::string dtLabel, std::string cscLabel)
00040    : m_dtLabel(dtLabel), m_cscLabel(cscLabel) {}
00041 
00042 // MuonAlignmentInputSurveyDB::MuonAlignmentInputSurveyDB(const MuonAlignmentInputSurveyDB& rhs)
00043 // {
00044 //    // do actual copying here;
00045 // }
00046 
00047 MuonAlignmentInputSurveyDB::~MuonAlignmentInputSurveyDB() {}
00048 
00049 //
00050 // assignment operators
00051 //
00052 // const MuonAlignmentInputSurveyDB& MuonAlignmentInputSurveyDB::operator=(const MuonAlignmentInputSurveyDB& rhs)
00053 // {
00054 //   //An exception safe implementation is
00055 //   MuonAlignmentInputSurveyDB temp(rhs);
00056 //   swap(rhs);
00057 //
00058 //   return *this;
00059 // }
00060 
00061 //
00062 // member functions
00063 //
00064 
00065 AlignableMuon *MuonAlignmentInputSurveyDB::newAlignableMuon(const edm::EventSetup& iSetup) const {
00066    boost::shared_ptr<DTGeometry> dtGeometry = idealDTGeometry(iSetup);
00067    boost::shared_ptr<CSCGeometry> cscGeometry = idealCSCGeometry(iSetup);
00068 
00069    edm::ESHandle<Alignments> dtSurvey;
00070    edm::ESHandle<SurveyErrors> dtSurveyError;
00071    edm::ESHandle<Alignments> cscSurvey;
00072    edm::ESHandle<SurveyErrors> cscSurveyError;
00073    iSetup.get<DTSurveyRcd>().get(m_dtLabel, dtSurvey);
00074    iSetup.get<DTSurveyErrorRcd>().get(m_dtLabel, dtSurveyError);
00075    iSetup.get<CSCSurveyRcd>().get(m_cscLabel, cscSurvey);
00076    iSetup.get<CSCSurveyErrorRcd>().get(m_cscLabel, cscSurveyError);
00077 
00078    AlignableMuon *output = new AlignableMuon(&(*dtGeometry), &(*cscGeometry));
00079 
00080    unsigned int theSurveyIndex  = 0;
00081    const Alignments *theSurveyValues = &*dtSurvey;
00082    const SurveyErrors *theSurveyErrors = &*dtSurveyError;
00083    std::vector<Alignable*> barrels = output->DTBarrel();
00084    for (std::vector<Alignable*>::const_iterator iter = barrels.begin();  iter != barrels.end();  ++iter) {
00085       addSurveyInfo_(*iter, &theSurveyIndex, theSurveyValues, theSurveyErrors);
00086    }
00087 
00088    theSurveyIndex  = 0;
00089    theSurveyValues = &*cscSurvey;
00090    theSurveyErrors = &*cscSurveyError;
00091    std::vector<Alignable*> endcaps = output->CSCEndcaps();
00092    for (std::vector<Alignable*>::const_iterator iter = endcaps.begin();  iter != endcaps.end();  ++iter) {
00093       addSurveyInfo_(*iter, &theSurveyIndex, theSurveyValues, theSurveyErrors);
00094    }
00095 
00096    return output;
00097 }
00098 
00099 // This function was copied (with minimal modifications) from
00100 // Alignment/CommonAlignmentProducer/plugins/AlignmentProducer.cc
00101 // (version CMSSW_2_0_0_pre1), guaranteed to work the same way
00102 // unless AlignmentProducer.cc's version changes!
00103 void MuonAlignmentInputSurveyDB::addSurveyInfo_(Alignable* ali,
00104                                                 unsigned int *theSurveyIndex,
00105                                                 const Alignments* theSurveyValues,
00106                                                 const SurveyErrors* theSurveyErrors) const {
00107   const std::vector<Alignable*>& comp = ali->components();
00108 
00109   unsigned int nComp = comp.size();
00110 
00111   for (unsigned int i = 0; i < nComp; ++i) addSurveyInfo_(comp[i], theSurveyIndex, theSurveyValues, theSurveyErrors);
00112 
00113   const SurveyError& error = theSurveyErrors->m_surveyErrors[*theSurveyIndex];
00114 
00115   if ( ali->geomDetId().rawId() != error.rawId() ||
00116        ali->alignableObjectId() != error.structureType() )
00117   {
00118     throw cms::Exception("DatabaseError")
00119       << "Error reading survey info from DB. Mismatched id!";
00120   }
00121 
00122   const CLHEP::Hep3Vector&  pos = theSurveyValues->m_align[*theSurveyIndex].translation();
00123   const CLHEP::HepRotation& rot = theSurveyValues->m_align[*theSurveyIndex].rotation();
00124 
00125   AlignableSurface surf( align::PositionType( pos.x(), pos.y(), pos.z() ),
00126                          align::RotationType( rot.xx(), rot.xy(), rot.xz(),
00127                                               rot.yx(), rot.yy(), rot.yz(),
00128                                               rot.zx(), rot.zy(), rot.zz() ) );
00129 
00130   surf.setWidth( ali->surface().width() );
00131   surf.setLength( ali->surface().length() );
00132 
00133   ali->setSurvey( new SurveyDet( surf, error.matrix() ) );
00134 
00135   (*theSurveyIndex)++;
00136 }
00137 
00138 //
00139 // const member functions
00140 //
00141 
00142 //
00143 // static member functions
00144 //