diff --git a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc index d267b82338538..3ebde9fa1bf33 100644 --- a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc +++ b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc @@ -102,10 +102,10 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester { const std::string recordName_; std::unique_ptr f1; float width_; + float theMagField_{0.f}; SiPixelLorentzAngleCalibrationHistograms hists; const SiPixelLorentzAngle* currentLorentzAngle; - const MagneticField* magField; std::unique_ptr theTrackerTopology; }; @@ -133,9 +133,13 @@ void SiPixelLorentzAnglePCLHarvester::beginRun(const edm::Run& iRun, const edm:: const TrackerGeometry* geom = &iSetup.getData(geomEsToken_); const TrackerTopology* tTopo = &iSetup.getData(topoEsTokenBR_); - magField = &iSetup.getData(magneticFieldToken_); + const MagneticField* magField = &iSetup.getData(magneticFieldToken_); currentLorentzAngle = &iSetup.getData(siPixelLAEsToken_); + // B-field value + // nominalValue returns the magnetic field value in kgauss (1T = 10 kgauss) + theMagField_ = magField->nominalValue() / 10.; + PixelTopologyMap map = PixelTopologyMap(geom, tTopo); hists.nlay = geom->numberOfLayers(PixelSubdetector::PixelBarrel); hists.nModules_.resize(hists.nlay); @@ -580,10 +584,6 @@ SiPixelLAHarvest::fitResults SiPixelLorentzAnglePCLHarvester::fitAndStore( // output results SiPixelLAHarvest::fitResults res; - // B-field value - // nominalValue returns the magnetic field value in kgauss (1T = 10 kgauss) - float theMagField = magField->nominalValue() / 10.; - double half_width = width_ * 10000 / 2; // pixel half thickness in units of micro meter f1 = std::make_unique("f1", "[0] + [1]*x + [2]*x*x + [3]*x*x*x + [4]*x*x*x*x + [5]*x*x*x*x*x", 5., 280.); @@ -640,8 +640,8 @@ SiPixelLAHarvest::fitResults SiPixelLorentzAnglePCLHarvester::fitAndStore( pow((half_width * half_width * half_width * half_width * res.e5), 2)); // Propagation of uncertainty res.error_LA = sqrt(errsq_LA); - hists.h_bySectMeasLA_->setBinContent(i_index, (res.tan_LA / theMagField)); - hists.h_bySectMeasLA_->setBinError(i_index, (res.error_LA / theMagField)); + hists.h_bySectMeasLA_->setBinContent(i_index, (res.tan_LA / theMagField_)); + hists.h_bySectMeasLA_->setBinError(i_index, (res.error_LA / theMagField_)); hists.h_bySectChi2_->setBinContent(i_index, res.redChi2); hists.h_bySectChi2_->setBinError(i_index, 0.); // no errors @@ -672,7 +672,7 @@ SiPixelLAHarvest::fitResults SiPixelLorentzAnglePCLHarvester::fitAndStore( float currentLA = currentLorentzAngle->getLorentzAngle(detIdsToFill.front()); // if the fit quality is OK if ((res.redChi2 != 0.) && (res.redChi2 < fitChi2Cut_) && (nentries > minHitsCut_)) { - LorentzAnglePerTesla_ = res.tan_LA / theMagField; + LorentzAnglePerTesla_ = res.tan_LA / theMagField_; // fill the LA actually written to payload hists.h_bySectSetLA_->setBinContent(i_index, LorentzAnglePerTesla_); hists.h_bySectRejectLA_->setBinContent(i_index, 0.); @@ -690,7 +690,7 @@ SiPixelLAHarvest::fitResults SiPixelLorentzAnglePCLHarvester::fitAndStore( } else { // just copy the values from the existing payload hists.h_bySectSetLA_->setBinContent(i_index, 0.); - hists.h_bySectRejectLA_->setBinContent(i_index, (res.tan_LA / theMagField)); + hists.h_bySectRejectLA_->setBinContent(i_index, (res.tan_LA / theMagField_)); hists.h_bySectLA_->setBinContent(i_index, currentLA); hists.h_bySectDeltaLA_->setBinContent(i_index, 0.); diff --git a/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc b/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc index 4a9e5d0e6bdfa..e21f52421ad54 100644 --- a/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc +++ b/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc @@ -50,6 +50,7 @@ namespace magneticfield { class DD4hep_VolumeBasedMagneticFieldESProducerFromDB : public edm::ESProducer { public: DD4hep_VolumeBasedMagneticFieldESProducerFromDB(const edm::ParameterSet& iConfig); + ~DD4hep_VolumeBasedMagneticFieldESProducerFromDB() override; // forbid copy ctor and assignment op. DD4hep_VolumeBasedMagneticFieldESProducerFromDB(const DD4hep_VolumeBasedMagneticFieldESProducerFromDB&) = delete; const DD4hep_VolumeBasedMagneticFieldESProducerFromDB& operator=( @@ -73,6 +74,8 @@ namespace magneticfield { edm::ESGetToken chosenConfigToken_; edm::ESGetToken mayConsumeBlobToken_; + cms::DDDetector* detector_{nullptr}; + const bool debug_; const bool useMergeFileIfAvailable_; }; @@ -130,6 +133,10 @@ DD4hep_VolumeBasedMagneticFieldESProducerFromDB::DD4hep_VolumeBasedMagneticField chosenConfigToken_ = cc.consumes(myConfigTag); //Use same tag as the choice } +DD4hep_VolumeBasedMagneticFieldESProducerFromDB::~DD4hep_VolumeBasedMagneticFieldESProducerFromDB() { + delete detector_; +} + std::shared_ptr DD4hep_VolumeBasedMagneticFieldESProducerFromDB::chooseConfigAtRuntime( IdealMagneticFieldRecord const& iRcd) { edm::ESHandle config = iRcd.getHandle(mayGetConfigToken_); @@ -187,9 +194,10 @@ std::unique_ptr DD4hep_VolumeBasedMagneticFieldESProducerFromDB:: ""); - auto ddet = make_unique("cmsMagneticField:MAGF", sblob, true); + if (nullptr == detector_) + detector_ = new cms::DDDetector("cmsMagneticField:MAGF", sblob, true); - builder.build(ddet.get()); + builder.build(detector_); // Build the VB map. Ownership of the parametrization is transferred to it return std::make_unique(conf->geometryVersion,