Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-15 04:14:41

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