Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:20

0001 /** \class VolumeBasedMagneticFieldESProducer
0002  *
0003  *  Producer for the VolumeBasedMagneticField.
0004  *
0005  */
0006 
0007 #include "FWCore/Framework/interface/ESTransientHandle.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0010 #include "FWCore/Framework/interface/ESProducer.h"
0011 #include "FWCore/Framework/interface/ModuleFactory.h"
0012 
0013 #include "MagneticField/VolumeBasedEngine/interface/VolumeBasedMagneticField.h"
0014 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0015 #include "MagneticField/Engine/interface/MagneticField.h"
0016 
0017 #include "DetectorDescription/Core/interface/DDCompactView.h"
0018 #include "MagneticField/GeomBuilder/src/MagGeoBuilderFromDDD.h"
0019 #include "CondFormats/MFObjects/interface/MagFieldConfig.h"
0020 
0021 #include <string>
0022 #include <vector>
0023 #include <iostream>
0024 
0025 namespace magneticfield {
0026   class VolumeBasedMagneticFieldESProducer : public edm::ESProducer {
0027   public:
0028     VolumeBasedMagneticFieldESProducer(const edm::ParameterSet& iConfig);
0029 
0030     std::unique_ptr<MagneticField> produce(const IdealMagneticFieldRecord& iRecord);
0031 
0032     // forbid copy ctor and assignment op.
0033     VolumeBasedMagneticFieldESProducer(const VolumeBasedMagneticFieldESProducer&) = delete;
0034     const VolumeBasedMagneticFieldESProducer& operator=(const VolumeBasedMagneticFieldESProducer&) = delete;
0035 
0036   private:
0037     const bool debug_;
0038     const bool useParametrizedTrackerField_;
0039     const MagFieldConfig conf_;
0040     const std::string version_;
0041     edm::ESGetToken<DDCompactView, IdealMagneticFieldRecord> cpvToken_;
0042     edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> paramFieldToken_;
0043   };
0044 }  // namespace magneticfield
0045 
0046 using namespace std;
0047 using namespace magneticfield;
0048 
0049 VolumeBasedMagneticFieldESProducer::VolumeBasedMagneticFieldESProducer(const edm::ParameterSet& iConfig)
0050     : debug_{iConfig.getUntrackedParameter<bool>("debugBuilder", false)},
0051       useParametrizedTrackerField_{iConfig.getParameter<bool>("useParametrizedTrackerField")},
0052       conf_{iConfig, debug_},
0053       version_{iConfig.getParameter<std::string>("version")} {
0054   auto cc = setWhatProduced(this, iConfig.getUntrackedParameter<std::string>("label", ""));
0055   cpvToken_ = cc.consumes(edm::ESInputTag{"", "magfield"});
0056   if (useParametrizedTrackerField_) {
0057     paramFieldToken_ = cc.consumes(edm::ESInputTag{"", iConfig.getParameter<string>("paramLabel")});
0058   }
0059 }
0060 
0061 // ------------ method called to produce the data  ------------
0062 std::unique_ptr<MagneticField> VolumeBasedMagneticFieldESProducer::produce(const IdealMagneticFieldRecord& iRecord) {
0063   LogTrace("MagGeoBuilder") << "VolumeBasedMagneticFieldESProducer::produce() " << version_;
0064 
0065   auto cpv = iRecord.getTransientHandle(cpvToken_);
0066   MagGeoBuilderFromDDD builder(conf_.version, conf_.geometryVersion, debug_);
0067 
0068   // Set scaling factors
0069   if (!conf_.keys.empty()) {
0070     builder.setScaling(conf_.keys, conf_.values);
0071   }
0072 
0073   // Set specification for the grid tables to be used.
0074   if (!conf_.gridFiles.empty()) {
0075     builder.setGridFiles(conf_.gridFiles);
0076   }
0077 
0078   builder.build(*cpv);
0079 
0080   // Get slave field (from ES)
0081   const MagneticField* paramField = nullptr;
0082   if (useParametrizedTrackerField_) {
0083     paramField = &iRecord.get(paramFieldToken_);
0084   }
0085   return std::make_unique<VolumeBasedMagneticField>(conf_.geometryVersion,
0086                                                     builder.barrelLayers(),
0087                                                     builder.endcapSectors(),
0088                                                     builder.barrelVolumes(),
0089                                                     builder.endcapVolumes(),
0090                                                     builder.maxR(),
0091                                                     builder.maxZ(),
0092                                                     paramField,
0093                                                     false);
0094 }
0095 
0096 DEFINE_FWK_EVENTSETUP_MODULE(VolumeBasedMagneticFieldESProducer);