File indexing completed on 2024-04-06 11:59:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <memory>
0019
0020 #include "FWCore/Framework/interface/ESProducer.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/Utilities/interface/ESProductTag.h"
0023 #include "FWCore/Utilities/interface/do_nothing_deleter.h"
0024
0025 #include "FWCore/Framework/interface/ModuleFactory.h"
0026 #include "MagneticField/Engine/interface/MagneticField.h"
0027
0028 #include "CondFormats/SiPixelObjects/interface/SiPixelTemplateDBObject.h"
0029 #include "CalibTracker/Records/interface/SiPixelTemplateDBObjectESProducerRcd.h"
0030
0031 using namespace edm;
0032
0033 class SiPixelTemplateDBObjectESProducer : public edm::ESProducer {
0034 public:
0035 SiPixelTemplateDBObjectESProducer(const edm::ParameterSet& iConfig);
0036 std::shared_ptr<const SiPixelTemplateDBObject> produce(const SiPixelTemplateDBObjectESProducerRcd&);
0037
0038 private:
0039 edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magfieldToken_;
0040 edm::ESGetToken<SiPixelTemplateDBObject, SiPixelTemplateDBObjectRcd> templateToken_;
0041 };
0042
0043 SiPixelTemplateDBObjectESProducer::SiPixelTemplateDBObjectESProducer(const edm::ParameterSet& iConfig) {
0044 auto cc = setWhatProduced(this);
0045 cc.setMayConsume(
0046 templateToken_,
0047 [](const auto& get, edm::ESTransientHandle<MagneticField> iMagfield) {
0048 const GlobalPoint center(0.0, 0.0, 0.0);
0049 const float theMagField = iMagfield->inTesla(center).mag();
0050 if (theMagField >= -0.1 && theMagField < 1.0)
0051 return get("", "0T");
0052 else {
0053 if (theMagField >= 3.9 || theMagField < 3.65)
0054 edm::LogWarning("UnexpectedMagneticFieldUsingDefaultPixelTemplate") << "Magnetic field is " << theMagField;
0055 return get("", "");
0056 }
0057 },
0058 edm::ESProductTag<MagneticField, IdealMagneticFieldRecord>("", ""));
0059 magfieldToken_ = cc.consumes();
0060 }
0061
0062 std::shared_ptr<const SiPixelTemplateDBObject> SiPixelTemplateDBObjectESProducer::produce(
0063 const SiPixelTemplateDBObjectESProducerRcd& iRecord) {
0064 const GlobalPoint center(0.0, 0.0, 0.0);
0065 const float theMagField = iRecord.get(magfieldToken_).inTesla(center).mag();
0066
0067 const auto& dbobject = iRecord.get(templateToken_);
0068
0069 if (std::fabs(theMagField - dbobject.sVector()[22]) > 0.1)
0070 edm::LogWarning("UnexpectedMagneticFieldUsingNonIdealPixelTemplate")
0071 << "Magnetic field is " << theMagField << " Template Magnetic field is " << dbobject.sVector()[22];
0072
0073 return std::shared_ptr<const SiPixelTemplateDBObject>(&dbobject, edm::do_nothing_deleter());
0074 }
0075
0076 DEFINE_FWK_EVENTSETUP_MODULE(SiPixelTemplateDBObjectESProducer);