Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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<TrackerTopology, TrackerTopologyRcd> topoToken_;
0052 
0053   const bool theSaveToDB;  /// whether or not writing to DB
0054   const bool
0055       theSaveFakeScenario;  /// if theSaveToDB is true, save a fake scenario (empty alignments), irrespective of the misalignment scenario below
0056   const edm::ParameterSet theScenario;  /// misalignment scenario
0057   const std::string theAlignRecordName, theErrorRecordName;
0058 };
0059 
0060 //__________________________________________________________________________________________________
0061 //__________________________________________________________________________________________________
0062 //__________________________________________________________________________________________________
0063 
0064 //__________________________________________________________________________________________________
0065 MisalignedTrackerESProducer::MisalignedTrackerESProducer(const edm::ParameterSet& p)
0066     : theSaveToDB(p.getUntrackedParameter<bool>("saveToDbase")),
0067       theSaveFakeScenario(p.getUntrackedParameter<bool>("saveFakeScenario")),
0068       theScenario(p.getParameter<edm::ParameterSet>("scenario")),
0069       theAlignRecordName("TrackerAlignmentRcd"),
0070       theErrorRecordName("TrackerAlignmentErrorExtendedRcd") {
0071   auto cc = setWhatProduced(this);
0072   geomDetToken_ = cc.consumes();
0073   ptpToken_ = cc.consumes();
0074   topoToken_ = cc.consumes();
0075 }
0076 
0077 //__________________________________________________________________________________________________
0078 MisalignedTrackerESProducer::~MisalignedTrackerESProducer() {}
0079 
0080 //__________________________________________________________________________________________________
0081 std::unique_ptr<TrackerGeometry> MisalignedTrackerESProducer::produce(const TrackerDigiGeometryRecord& iRecord) {
0082   //Retrieve tracker topology from geometry
0083   const TrackerTopology* tTopo = &iRecord.get(topoToken_);
0084 
0085   edm::LogInfo("MisalignedTracker") << "Producer called";
0086 
0087   // Create the tracker geometry from ideal geometry
0088   const GeometricDet* gD = &iRecord.get(geomDetToken_);
0089   const PTrackerParameters& ptp = iRecord.get(ptpToken_);
0090 
0091   TrackerGeomBuilderFromGeometricDet trackerBuilder;
0092   std::unique_ptr<TrackerGeometry> theTracker(trackerBuilder.build(gD, ptp, tTopo));
0093 
0094   // Create the alignable hierarchy
0095   auto theAlignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
0096 
0097   // Create misalignment scenario, apply to geometry
0098   TrackerScenarioBuilder scenarioBuilder(&(*theAlignableTracker));
0099   scenarioBuilder.applyScenario(theScenario);
0100   Alignments alignments = *(theAlignableTracker->alignments());
0101   AlignmentErrorsExtended alignmentErrors = *(theAlignableTracker->alignmentErrors());
0102 
0103   // Store result to EventSetup
0104   GeometryAligner aligner;
0105   aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
0106                                            &alignments,
0107                                            &alignmentErrors,
0108                                            AlignTransform());  // dummy global position
0109 
0110   // Write alignments to DB: have to sort beforhand!
0111   if (theSaveToDB) {
0112     // Call service
0113     edm::Service<cond::service::PoolDBOutputService> poolDbService;
0114     if (!poolDbService.isAvailable())  // Die if not available
0115       throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0116     if (theSaveFakeScenario) {  // make empty!
0117       alignments.clear();
0118       alignmentErrors.clear();
0119     }
0120     poolDbService->writeOneIOV<Alignments>(alignments, poolDbService->currentTime(), theAlignRecordName);
0121     poolDbService->writeOneIOV<AlignmentErrorsExtended>(
0122         alignmentErrors, poolDbService->currentTime(), theErrorRecordName);
0123   }
0124 
0125   edm::LogInfo("MisalignedTracker") << "Producer done";
0126   return theTracker;
0127 }
0128 
0129 DEFINE_FWK_EVENTSETUP_MODULE(MisalignedTrackerESProducer);