Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-12 23:19:13

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
0004 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0005 
0006 #include "Geometry/MTDGeometryBuilder/interface/MTDGeomBuilderFromGeometricTimingDet.h"
0007 #include "Geometry/MTDNumberingBuilder/interface/GeometricTimingDet.h"
0008 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0009 #include "Geometry/Records/interface/PMTDParametersRcd.h"
0010 #include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
0011 
0012 // Alignments
0013 #include "CondFormats/Alignment/interface/Alignments.h"
0014 #include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
0015 #include "CondFormats/Alignment/interface/AlignmentSurfaceDeformations.h"
0016 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
0017 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0018 #include "CondFormats/AlignmentRecord/interface/MTDAlignmentRcd.h"
0019 #include "CondFormats/AlignmentRecord/interface/MTDAlignmentErrorExtendedRcd.h"
0020 #include "CondFormats/AlignmentRecord/interface/MTDSurfaceDeformationRcd.h"
0021 #include "Geometry/GeometryAligner/interface/GeometryAligner.h"
0022 
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/ModuleFactory.h"
0026 #include "FWCore/Framework/interface/ESProducer.h"
0027 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0029 
0030 #include <memory>
0031 #include <string>
0032 
0033 class MTDDigiGeometryESModule : public edm::ESProducer {
0034 public:
0035   MTDDigiGeometryESModule(const edm::ParameterSet& p);
0036   std::unique_ptr<MTDGeometry> produce(const MTDDigiGeometryRecord&);
0037 
0038   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0039 
0040 private:
0041   /// Called when geometry description changes
0042   const std::string alignmentsLabel_;
0043   const std::string myLabel_;
0044 
0045   edm::ESGetToken<GeometricTimingDet, IdealGeometryRecord> geomTimingDetToken_;
0046   edm::ESGetToken<PMTDParameters, PMTDParametersRcd> pmtdParamsToken_;
0047 
0048   //alignment
0049   edm::ESGetToken<Alignments, GlobalPositionRcd> globalAlignToken_;
0050   edm::ESGetToken<Alignments, MTDAlignmentRcd> mtdAlignToken_;
0051   edm::ESGetToken<AlignmentErrorsExtended, MTDAlignmentErrorExtendedRcd> alignErrorsToken_;
0052   edm::ESGetToken<AlignmentSurfaceDeformations, MTDSurfaceDeformationRcd> deformationsToken_;
0053 
0054   const bool applyAlignment_;  // Switch to apply alignment corrections
0055   const bool fromDDD_;
0056 };
0057 
0058 //__________________________________________________________________
0059 MTDDigiGeometryESModule::MTDDigiGeometryESModule(const edm::ParameterSet& p)
0060     : alignmentsLabel_(p.getParameter<std::string>("alignmentsLabel")),
0061       myLabel_(p.getParameter<std::string>("appendToDataLabel")),
0062       applyAlignment_(p.getParameter<bool>("applyAlignment")),
0063       fromDDD_(p.getParameter<bool>("fromDDD"))
0064 
0065 {
0066   auto cc = setWhatProduced(this);
0067   const edm::ESInputTag kEmpty;
0068   geomTimingDetToken_ = cc.consumesFrom<GeometricTimingDet, IdealGeometryRecord>(kEmpty);
0069   pmtdParamsToken_ = cc.consumesFrom<PMTDParameters, PMTDParametersRcd>(kEmpty);
0070 
0071   {
0072     const edm::ESInputTag kAlignTag{"", alignmentsLabel_};
0073     globalAlignToken_ = cc.consumesFrom<Alignments, GlobalPositionRcd>(kAlignTag);
0074     mtdAlignToken_ = cc.consumesFrom<Alignments, MTDAlignmentRcd>(kAlignTag);
0075     alignErrorsToken_ = cc.consumesFrom<AlignmentErrorsExtended, MTDAlignmentErrorExtendedRcd>(kAlignTag);
0076     deformationsToken_ = cc.consumesFrom<AlignmentSurfaceDeformations, MTDSurfaceDeformationRcd>(kAlignTag);
0077   }
0078 
0079   edm::LogInfo("Geometry") << "@SUB=MTDDigiGeometryESModule"
0080                            << "Label '" << myLabel_ << "' " << (applyAlignment_ ? "looking for" : "IGNORING")
0081                            << " alignment labels '" << alignmentsLabel_ << "'.";
0082 }
0083 
0084 //__________________________________________________________________
0085 void MTDDigiGeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0086   edm::ParameterSetDescription descDB;
0087   descDB.add<std::string>("appendToDataLabel", "");
0088   descDB.add<bool>("fromDDD", false);
0089   descDB.add<bool>("applyAlignment", true);
0090   descDB.add<std::string>("alignmentsLabel", "");
0091   descriptions.add("mtdGeometryDB", descDB);
0092 
0093   edm::ParameterSetDescription desc;
0094   desc.add<std::string>("appendToDataLabel", "");
0095   desc.add<bool>("fromDDD", true);
0096   desc.add<bool>("applyAlignment", true);
0097   desc.add<std::string>("alignmentsLabel", "");
0098   descriptions.add("mtdGeometry", desc);
0099 }
0100 
0101 //__________________________________________________________________
0102 std::unique_ptr<MTDGeometry> MTDDigiGeometryESModule::produce(const MTDDigiGeometryRecord& iRecord) {
0103   //
0104   // Called whenever the alignments, alignment errors or global positions change
0105   //
0106   GeometricTimingDet const& gD = iRecord.get(geomTimingDetToken_);
0107 
0108   PMTDParameters const& ptp = iRecord.get(pmtdParamsToken_);
0109 
0110   MTDGeomBuilderFromGeometricTimingDet builder;
0111   std::unique_ptr<MTDGeometry> mtd(builder.build(&(gD), ptp));
0112 
0113   if (applyAlignment_) {
0114     // Since fake is fully working when checking for 'empty', we should get rid of applyAlignment_!
0115     Alignments const& globalPosition = iRecord.get(globalAlignToken_);
0116     Alignments const& alignments = iRecord.get(mtdAlignToken_);
0117     AlignmentErrorsExtended const& alignmentErrors = iRecord.get(alignErrorsToken_);
0118     // apply if not empty:
0119     if (alignments.empty() && alignmentErrors.empty() && globalPosition.empty()) {
0120       edm::LogInfo("Config") << "@SUB=MTDDigiGeometryRecord::produce"
0121                              << "Alignment(Error)s and global position (label '" << alignmentsLabel_
0122                              << "') empty: Geometry producer (label "
0123                              << "'" << myLabel_ << "') assumes fake and does not apply.";
0124     } else {
0125       GeometryAligner ali;
0126       ali.applyAlignments<MTDGeometry>(mtd.get(),
0127                                        &(alignments),
0128                                        &(alignmentErrors),
0129                                        align::DetectorGlobalPosition(globalPosition, DetId(DetId::Forward)));
0130     }
0131 
0132     AlignmentSurfaceDeformations const& surfaceDeformations = iRecord.get(deformationsToken_);
0133     // apply if not empty:
0134     if (surfaceDeformations.empty()) {
0135       edm::LogInfo("Config") << "@SUB=MTDDigiGeometryRecord::produce"
0136                              << "AlignmentSurfaceDeformations (label '" << alignmentsLabel_
0137                              << "') empty: Geometry producer (label "
0138                              << "'" << myLabel_ << "') assumes fake and does not apply.";
0139     } else {
0140       GeometryAligner ali;
0141       ali.attachSurfaceDeformations<MTDGeometry>(mtd.get(), &(surfaceDeformations));
0142     }
0143   }
0144 
0145   return mtd;
0146 }
0147 
0148 DEFINE_FWK_EVENTSETUP_MODULE(MTDDigiGeometryESModule);