Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "Alignment/CommonAlignment/interface/SurveyDet.h"
0002 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0007 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0008 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0009 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0010 #include "Geometry/Records/interface/PTrackerParametersRcd.h"
0011 #include "Geometry/Records/interface/PTrackerAdditionalParametersPerDetRcd.h"
0012 
0013 // Database
0014 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0015 #include "FWCore/ServiceRegistry/interface/Service.h"
0016 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
0017 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorExtendedRcd.h"
0018 #include "CondFormats/Alignment/interface/Alignments.h"
0019 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0020 
0021 #include "Alignment/SurveyAnalysis/plugins/SurveyInputTrackerFromDB.h"
0022 
0023 SurveyInputTrackerFromDB::SurveyInputTrackerFromDB(const edm::ParameterSet& cfg)
0024     : tTopoToken_(esConsumes()),
0025       geomDetToken_(esConsumes()),
0026       ptpToken_(esConsumes()),
0027       textFileName(cfg.getParameter<std::string>("textFileName")) {}
0028 
0029 void SurveyInputTrackerFromDB::analyze(const edm::Event&, const edm::EventSetup& setup) {
0030   if (theFirstEvent) {
0031     //  std::cout << "***************ENTERING INITIALIZATION******************" << std::endl;
0032 
0033     //Retrieve tracker topology from geometry
0034     const TrackerTopology* const tTopo = &setup.getData(tTopoToken_);
0035 
0036     //Get map from textreader
0037     SurveyInputTextReader dataReader;
0038     dataReader.readFile(textFileName);
0039     uIdMap = dataReader.UniqueIdMap();
0040 
0041     const GeometricDet* geom = &setup.getData(geomDetToken_);
0042     const PTrackerParameters& ptp = setup.getData(ptpToken_);
0043     TrackerGeometry* tracker = TrackerGeomBuilderFromGeometricDet().build(geom, ptp, tTopo);
0044 
0045     addComponent(new AlignableTracker(tracker, tTopo));
0046     addSurveyInfo(detector());
0047 
0048     //write out to a DB ...
0049     Alignments* myAlignments = detector()->alignments();
0050     AlignmentErrorsExtended* myAlignmentErrorsExtended = detector()->alignmentErrors();
0051 
0052     // 2. Store alignment[Error]s to DB
0053     edm::Service<cond::service::PoolDBOutputService> poolDbService;
0054     // Call service
0055 
0056     if (!poolDbService.isAvailable())  // Die if not available
0057       throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0058 
0059     poolDbService->writeOneIOV<Alignments>(*myAlignments, poolDbService->beginOfTime(), "TrackerAlignmentRcd");
0060     poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0061         *myAlignmentErrorsExtended, poolDbService->beginOfTime(), "TrackerAlignmentErrorExtendedRcd");
0062 
0063     theFirstEvent = false;
0064   }
0065 }
0066 
0067 void SurveyInputTrackerFromDB::addSurveyInfo(Alignable* ali) {
0068   const align::Alignables& comp = ali->components();
0069   unsigned int nComp = comp.size();
0070 
0071   for (unsigned int i = 0; i < nComp; ++i)
0072     addSurveyInfo(comp[i]);
0073 
0074   align::ErrorMatrix error;
0075 
0076   SurveyInputTextReader::MapType::const_iterator it = uIdMap.find(std::make_pair(ali->id(), ali->alignableObjectId()));
0077 
0078   if (it != uIdMap.end()) {
0079     const align::Scalars& parameters = (it)->second;
0080 
0081     //move the surface
0082     //displacement
0083     align::LocalVector lvector(parameters[0], parameters[1], parameters[2]);
0084     align::GlobalVector gvector = ali->surface().toGlobal(lvector);
0085     ali->move(gvector);
0086     //rotation
0087     Basic3DVector<align::Scalar> rot_aa(parameters[3], parameters[4], parameters[5]);
0088     align::RotationType rotation(rot_aa, rot_aa.mag());
0089     ali->rotateInLocalFrame(rotation);
0090 
0091     //sets the errors for the hierarchy level
0092     double* errorData = error.Array();
0093     for (unsigned int i = 0; i < 21; ++i) {
0094       errorData[i] = parameters[i + 6];
0095     }
0096 
0097     ali->setSurvey(new SurveyDet(ali->surface(), error * (1e-6)));
0098   } else {
0099     error = ROOT::Math::SMatrixIdentity();
0100     ali->setSurvey(new SurveyDet(ali->surface(), error * 1e-6));
0101   }
0102 }
0103 // Plug in to framework
0104 
0105 #include "FWCore/Framework/interface/MakerMacros.h"
0106 
0107 DEFINE_FWK_MODULE(SurveyInputTrackerFromDB);