From dbf8a0cac45c86306fd65218af0e30637eff1656 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 7 Jul 2022 19:32:55 +0200 Subject: [PATCH 1/4] Attempt to fix crash --- .../src/SiPixelLorentzAnglePCLHarvester.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc index d267b82338538..6ff5d367d16c9 100644 --- a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc +++ b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc @@ -102,6 +102,7 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester { const std::string recordName_; std::unique_ptr f1; float width_; + float theMagField; SiPixelLorentzAngleCalibrationHistograms hists; const SiPixelLorentzAngle* currentLorentzAngle; @@ -136,6 +137,10 @@ void SiPixelLorentzAnglePCLHarvester::beginRun(const edm::Run& iRun, const edm:: 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 +585,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.); From 28e4689d7d71c047f49c10679856a93c7c1ed855 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 7 Jul 2022 19:40:09 +0200 Subject: [PATCH 2/4] code format --- .../SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc index 6ff5d367d16c9..77296bdf2db90 100644 --- a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc +++ b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc @@ -102,7 +102,7 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester { const std::string recordName_; std::unique_ptr f1; float width_; - float theMagField; + float theMagField{0.f}; SiPixelLorentzAngleCalibrationHistograms hists; const SiPixelLorentzAngle* currentLorentzAngle; From 391ba07b0a6a279c87a594810bf598938841e013 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 8 Jul 2022 11:05:03 +0200 Subject: [PATCH 3/4] attemt to ensure creation of geometry once --- .../DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc b/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc index 4a9e5d0e6bdfa..b8e9720dc41a1 100644 --- a/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc +++ b/MagneticField/GeomBuilder/plugins/dd4hep/DD4hep_VolumeBasedMagneticFieldESProducerFromDB.cc @@ -73,6 +73,8 @@ namespace magneticfield { edm::ESGetToken chosenConfigToken_; edm::ESGetToken mayConsumeBlobToken_; + cms::DDDetector* detector_{nullptr}; + const bool debug_; const bool useMergeFileIfAvailable_; }; @@ -187,9 +189,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, From 9d3abc473c31cf89f797c669c57aafb7d22021ae Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 8 Jul 2022 12:09:41 +0200 Subject: [PATCH 4/4] addressed comments --- .../src/SiPixelLorentzAnglePCLHarvester.cc | 15 +++++++-------- ...ep_VolumeBasedMagneticFieldESProducerFromDB.cc | 5 +++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc index 77296bdf2db90..3ebde9fa1bf33 100644 --- a/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc +++ b/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAnglePCLHarvester.cc @@ -102,11 +102,10 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester { const std::string recordName_; std::unique_ptr f1; float width_; - float theMagField{0.f}; + float theMagField_{0.f}; SiPixelLorentzAngleCalibrationHistograms hists; const SiPixelLorentzAngle* currentLorentzAngle; - const MagneticField* magField; std::unique_ptr theTrackerTopology; }; @@ -134,12 +133,12 @@ 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.; + theMagField_ = magField->nominalValue() / 10.; PixelTopologyMap map = PixelTopologyMap(geom, tTopo); hists.nlay = geom->numberOfLayers(PixelSubdetector::PixelBarrel); @@ -641,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 @@ -673,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.); @@ -691,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 b8e9720dc41a1..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=( @@ -132,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_);