CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Alignment/SurveyAnalysis/plugins/SurveyMisalignmentInput.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EventSetup.h"
00002 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00003 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00004 
00005 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
00006 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
00007 
00008 #include "CondFormats/Alignment/interface/Alignments.h"
00009 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00010 
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 
00014 #include "Alignment/SurveyAnalysis/plugins/SurveyMisalignmentInput.h"
00015 
00016 SurveyMisalignmentInput::SurveyMisalignmentInput(const edm::ParameterSet& cfg):
00017   textFileName( cfg.getParameter<std::string>("textFileName") ),
00018   theParameterSet( cfg )
00019 {}
00020 
00021 void SurveyMisalignmentInput::analyze(const edm::Event&, const edm::EventSetup& setup)
00022 {
00023   if (theFirstEvent) {
00024     //Retrieve tracker topology from geometry
00025     edm::ESHandle<TrackerTopology> tTopoHandle;
00026     setup.get<IdealGeometryRecord>().get(tTopoHandle);
00027     const TrackerTopology* const tTopo = tTopoHandle.product();
00028 
00029     edm::ESHandle<GeometricDet> geom;
00030     setup.get<IdealGeometryRecord>().get(geom);  
00031     TrackerGeometry* tracker = TrackerGeomBuilderFromGeometricDet().build(&*geom, theParameterSet);
00032     
00033     addComponent(new AlignableTracker( tracker, tTopo ));
00034 
00035     edm::LogInfo("SurveyMisalignmentInput") << "Starting!";
00036     // Retrieve alignment[Error]s from DBase
00037     setup.get<TrackerAlignmentRcd>().get( alignments );
00038     
00039     //Get map from textreader
00040     SurveyInputTextReader dataReader;
00041     dataReader.readFile( textFileName );
00042     uIdMap = dataReader.UniqueIdMap();
00043     
00044     addSurveyInfo( detector() );
00045 
00046     theFirstEvent = false;
00047   }
00048 }
00049 
00050 
00051 void SurveyMisalignmentInput::addSurveyInfo(Alignable* ali)
00052 {
00053 
00054   const align::Alignables& comp = ali->components();
00055   unsigned int nComp = comp.size();
00056   for (unsigned int i = 0; i < nComp; ++i) addSurveyInfo(comp[i]);
00057         
00058   SurveyInputTextReader::MapType::const_iterator it
00059     = uIdMap.find(std::make_pair(ali->id(), ali->alignableObjectId()));
00060 
00061   align::ErrorMatrix error;
00062 
00063   if (it != uIdMap.end()){
00064     //survey error values
00065     const align::Scalars& parameters = (it)->second;
00066     //sets the errors for the hierarchy level
00067     double* errorData = error.Array();
00068     for (unsigned int i = 0; i < 21; ++i){errorData[i] = parameters[i+6];}
00069                 
00070     //because record only needs global value of modules
00071     if (ali->alignableObjectId() == align::AlignableDetUnit){
00072       // fill survey values
00073       ali->setSurvey( new SurveyDet(getAlignableSurface(ali->id()), error) );
00074     }
00075     else{
00076       ali->setSurvey( new SurveyDet(ali->surface(), error) );
00077     }
00078   }
00079   else{
00080     //fill
00081     error = ROOT::Math::SMatrixIdentity();
00082     ali->setSurvey( new SurveyDet(ali->surface(), error*(1e-6)) );
00083   }
00084   //std::cout << "UniqueId: " << id.first << ", " << id.second << std::endl;
00085   //std::cout << error << std::endl;
00086         
00087 }
00088 
00089 AlignableSurface SurveyMisalignmentInput::getAlignableSurface(align::ID id)
00090 {
00091   std::vector<AlignTransform>::const_iterator it;
00092 
00093   for (it = alignments->m_align.begin(); it != alignments->m_align.end(); ++it)
00094   {
00095     if (id == (*it).rawId())
00096     {
00097       align::PositionType position( (*it).translation().x(), (*it).translation().y(), (*it).translation().z() );
00098       CLHEP::HepRotation rot( (*it).rotation() );
00099       align::RotationType rotation( rot.xx(), rot.xy(), rot.xz(),
00100                                     rot.yx(), rot.yy(), rot.yz(),
00101                                     rot.zx(), rot.zy(), rot.zz() );
00102       return AlignableSurface(position,rotation);
00103     }
00104   }
00105         
00106   return AlignableSurface();
00107 }
00108 
00109 // Plug in to framework
00110 
00111 #include "FWCore/Framework/interface/MakerMacros.h"
00112 
00113 DEFINE_FWK_MODULE(SurveyMisalignmentInput);