Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-21 00:19:08

0001 #include "FWCore/Framework/interface/EventSetup.h"
0002 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0003 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0004 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0005 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0006 #include "Geometry/Records/interface/PTrackerParametersRcd.h"
0007 #include "Geometry/Records/interface/PTrackerAdditionalParametersPerDetRcd.h"
0008 
0009 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
0010 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0011 
0012 #include "CondFormats/Alignment/interface/Alignments.h"
0013 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0014 
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 
0018 #include "Alignment/SurveyAnalysis/plugins/SurveyMisalignmentInput.h"
0019 
0020 SurveyMisalignmentInput::SurveyMisalignmentInput(const edm::ParameterSet& cfg)
0021     : tTopoToken_(esConsumes()),
0022       geomDetToken_(esConsumes()),
0023       ptpToken_(esConsumes()),
0024       aliToken_(esConsumes()),
0025       textFileName(cfg.getParameter<std::string>("textFileName")) {}
0026 
0027 void SurveyMisalignmentInput::analyze(const edm::Event&, const edm::EventSetup& setup) {
0028   if (theFirstEvent) {
0029     //Retrieve tracker topology from geometry
0030     const TrackerTopology* const tTopo = &setup.getData(tTopoToken_);
0031     const GeometricDet* geom = &setup.getData(geomDetToken_);
0032     const PTrackerParameters& ptp = setup.getData(ptpToken_);
0033     TrackerGeometry* tracker = TrackerGeomBuilderFromGeometricDet().build(geom, ptp, tTopo);
0034 
0035     addComponent(new AlignableTracker(tracker, tTopo));
0036 
0037     edm::LogInfo("SurveyMisalignmentInput") << "Starting!";
0038     // Retrieve alignment[Error]s from DBase
0039     alignments = setup.getHandle(aliToken_);
0040 
0041     //Get map from textreader
0042     SurveyInputTextReader dataReader;
0043     dataReader.readFile(textFileName);
0044     uIdMap = dataReader.UniqueIdMap();
0045 
0046     addSurveyInfo(detector());
0047 
0048     theFirstEvent = false;
0049   }
0050 }
0051 
0052 void SurveyMisalignmentInput::addSurveyInfo(Alignable* ali) {
0053   const align::Alignables& comp = ali->components();
0054   unsigned int nComp = comp.size();
0055   for (unsigned int i = 0; i < nComp; ++i)
0056     addSurveyInfo(comp[i]);
0057 
0058   SurveyInputTextReader::MapType::const_iterator it = uIdMap.find(std::make_pair(ali->id(), ali->alignableObjectId()));
0059 
0060   align::ErrorMatrix error;
0061 
0062   if (it != uIdMap.end()) {
0063     //survey error values
0064     const align::Scalars& parameters = (it)->second;
0065     //sets the errors for the hierarchy level
0066     double* errorData = error.Array();
0067     for (unsigned int i = 0; i < 21; ++i) {
0068       errorData[i] = parameters[i + 6];
0069     }
0070 
0071     //because record only needs global value of modules
0072     if (ali->alignableObjectId() == align::AlignableDetUnit) {
0073       // fill survey values
0074       ali->setSurvey(new SurveyDet(getAlignableSurface(ali->id()), error));
0075     } else {
0076       ali->setSurvey(new SurveyDet(ali->surface(), error));
0077     }
0078   } else {
0079     //fill
0080     error = ROOT::Math::SMatrixIdentity();
0081     ali->setSurvey(new SurveyDet(ali->surface(), error * (1e-6)));
0082   }
0083   //std::cout << "UniqueId: " << id.first << ", " << id.second << std::endl;
0084   //std::cout << error << std::endl;
0085 }
0086 
0087 AlignableSurface SurveyMisalignmentInput::getAlignableSurface(align::ID id) {
0088   std::vector<AlignTransform>::const_iterator it;
0089 
0090   for (it = alignments->m_align.begin(); it != alignments->m_align.end(); ++it) {
0091     if (id == (*it).rawId()) {
0092       align::PositionType position((*it).translation().x(), (*it).translation().y(), (*it).translation().z());
0093       CLHEP::HepRotation rot((*it).rotation());
0094       align::RotationType rotation(
0095           rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz());
0096       return AlignableSurface(position, rotation);
0097     }
0098   }
0099 
0100   return AlignableSurface();
0101 }
0102 
0103 // Plug in to framework
0104 
0105 #include "FWCore/Framework/interface/MakerMacros.h"
0106 
0107 DEFINE_FWK_MODULE(SurveyMisalignmentInput);