Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // Framework
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005 #include "FWCore/Framework/interface/ESProducer.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 // Conditions database
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0012 
0013 // Geometry
0014 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
0015 #include "Geometry/CommonTopologies/interface/GeometryAligner.h"
0016 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0017 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0019 
0020 // Alignment
0021 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0022 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0023 #include "Alignment/TrackerAlignment/interface/TrackerScenarioBuilder.h"
0024 #include "Alignment/CommonAlignment/interface/Alignable.h"
0025 
0026 // C++
0027 #include <memory>
0028 #include <algorithm>
0029 
0030 ///
0031 /// An ESProducer that fills the TrackerDigiGeometryRcd with a misaligned tracker
0032 ///
0033 /// This should replace the standard TrackerDigiGeometryESModule when producing
0034 /// Misalignment scenarios.
0035 ///
0036 
0037 class MisalignedTrackerESProducer : public edm::ESProducer {
0038 public:
0039   /// Constructor
0040   MisalignedTrackerESProducer(const edm::ParameterSet& p);
0041 
0042   /// Destructor
0043   ~MisalignedTrackerESProducer() override;
0044 
0045   /// Produce the misaligned tracker geometry and store it
0046   std::unique_ptr<TrackerGeometry> produce(const TrackerDigiGeometryRecord& iRecord);
0047 
0048 private:
0049   edm::ESGetToken<GeometricDet, IdealGeometryRecord> geomDetToken_;
0050   edm::ESGetToken<PTrackerParameters, PTrackerParametersRcd> ptpToken_;
0051   edm::ESGetToken<PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd> ptitpToken_;
0052   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0053 
0054   const bool theSaveToDB;  /// whether or not writing to DB
0055   const bool
0056       theSaveFakeScenario;  /// if theSaveToDB is true, save a fake scenario (empty alignments), irrespective of the misalignment scenario below
0057   const edm::ParameterSet theScenario;  /// misalignment scenario
0058   const std::string theAlignRecordName, theErrorRecordName;
0059 };
0060 
0061 //__________________________________________________________________________________________________
0062 //__________________________________________________________________________________________________
0063 //__________________________________________________________________________________________________
0064 
0065 //__________________________________________________________________________________________________
0066 MisalignedTrackerESProducer::MisalignedTrackerESProducer(const edm::ParameterSet& p)
0067     : theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
0068       theSaveFakeScenario(p.getUntrackedParameter<bool>("saveFakeScenario")),
0069       theScenario(p.getParameter<edm::ParameterSet>("scenario")),
0070       theAlignRecordName("TrackerAlignmentRcd"),
0071       theErrorRecordName("TrackerAlignmentErrorExtendedRcd") {
0072   auto cc = setWhatProduced(this);
0073   geomDetToken_ = cc.consumes();
0074   ptpToken_ = cc.consumes();
0075   ptitpToken_ = cc.consumes();
0076   topoToken_ = cc.consumes();
0077 }
0078 
0079 //__________________________________________________________________________________________________
0080 MisalignedTrackerESProducer::~MisalignedTrackerESProducer() {}
0081 
0082 //__________________________________________________________________________________________________
0083 std::unique_ptr<TrackerGeometry> MisalignedTrackerESProducer::produce(const TrackerDigiGeometryRecord& iRecord) {
0084   //Retrieve tracker topology from geometry
0085   const TrackerTopology* tTopo = &iRecord.get(topoToken_);
0086 
0087   edm::LogInfo("MisalignedTracker") << "Producer called";
0088 
0089   // Create the tracker geometry from ideal geometry
0090   const GeometricDet* gD = &iRecord.get(geomDetToken_);
0091   const PTrackerParameters& ptp = iRecord.get(ptpToken_);
0092   const PTrackerAdditionalParametersPerDet* ptitp = &iRecord.get(ptitpToken_);
0093 
0094   TrackerGeomBuilderFromGeometricDet trackerBuilder;
0095   std::unique_ptr<TrackerGeometry> theTracker(trackerBuilder.build(gD, ptitp, ptp, tTopo));
0096 
0097   // Create the alignable hierarchy
0098   auto theAlignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
0099 
0100   // Create misalignment scenario, apply to geometry
0101   TrackerScenarioBuilder scenarioBuilder(&(*theAlignableTracker));
0102   scenarioBuilder.applyScenario(theScenario);
0103   Alignments alignments = *(theAlignableTracker->alignments());
0104   AlignmentErrorsExtended alignmentErrors = *(theAlignableTracker->alignmentErrors());
0105 
0106   // Store result to EventSetup
0107   GeometryAligner aligner;
0108   aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
0109                                            &alignments,
0110                                            &alignmentErrors,
0111                                            AlignTransform());  // dummy global position
0112 
0113   // Write alignments to DB: have to sort beforhand!
0114   if (theSaveToDB) {
0115     // Call service
0116     edm::Service<cond::service::PoolDBOutputService> poolDbService;
0117     if (!poolDbService.isAvailable())  // Die if not available
0118       throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0119     if (theSaveFakeScenario) {  // make empty!
0120       alignments.clear();
0121       alignmentErrors.clear();
0122     }
0123     poolDbService->writeOneIOV<Alignments>(alignments, poolDbService->currentTime(), theAlignRecordName);
0124     poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0125         alignmentErrors, poolDbService->currentTime(), theErrorRecordName);
0126   }
0127 
0128   edm::LogInfo("MisalignedTracker") << "Producer done";
0129   return theTracker;
0130 }
0131 
0132 DEFINE_FWK_EVENTSETUP_MODULE(MisalignedTrackerESProducer);