Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:33

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixelGenErrorDBObjectESProducer
0004 // Class:      SiPixelGenErrorDBObjectESProducer
0005 //
0006 /**\class SiPixelGenErrorDBObjectESProducer SiPixelGenErrorDBObjectESProducer.cc CalibTracker/SiPixelESProducers/plugin/SiPixelGenErrorDBObjectESProducer.cc
0007 
0008  Description: ESProducer for magnetic-field-dependent local reco GenErrors
0009 
0010  Implementation: Used inside the RecoLocalTracker/Records/TkPixelRecord to select the correct db for given magnetic field
0011 */
0012 //
0013 // Original Author:  D.Fehling
0014 //         Created:  Tue Sep 29 14:49:31 CET 2009
0015 //
0016 //
0017 
0018 #include "FWCore/Framework/interface/ESProducer.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/Utilities/interface/ESProductTag.h"
0021 #include "FWCore/Utilities/interface/do_nothing_deleter.h"
0022 #include "FWCore/Framework/interface/ModuleFactory.h"
0023 
0024 #include "CondFormats/SiPixelObjects/interface/SiPixelGenErrorDBObject.h"
0025 #include "CalibTracker/Records/interface/SiPixelGenErrorDBObjectESProducerRcd.h"
0026 #include "MagneticField/Engine/interface/MagneticField.h"
0027 
0028 #include <memory>
0029 
0030 using namespace edm;
0031 
0032 class SiPixelGenErrorDBObjectESProducer : public edm::ESProducer {
0033 public:
0034   SiPixelGenErrorDBObjectESProducer(const edm::ParameterSet& iConfig);
0035   std::shared_ptr<const SiPixelGenErrorDBObject> produce(const SiPixelGenErrorDBObjectESProducerRcd&);
0036 
0037 private:
0038   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magfieldToken_;
0039   edm::ESGetToken<SiPixelGenErrorDBObject, SiPixelGenErrorDBObjectRcd> genErrorToken_;
0040 };
0041 
0042 SiPixelGenErrorDBObjectESProducer::SiPixelGenErrorDBObjectESProducer(const edm::ParameterSet& iConfig) {
0043   auto cc = setWhatProduced(this);
0044   cc.setMayConsume(
0045       genErrorToken_,
0046       [](const auto& get, edm::ESTransientHandle<MagneticField> iMagfield) {
0047         const GlobalPoint center(0.0, 0.0, 0.0);
0048         const float theMagField = iMagfield->inTesla(center).mag();
0049         if (theMagField >= -0.1 && theMagField < 1.0)
0050           return get("", "0T");
0051         else {
0052           if (theMagField >= 3.9 || theMagField < 3.65)
0053             edm::LogWarning("UnexpectedMagneticFieldUsingDefaultPixelGenError") << "Magnetic field is " << theMagField;
0054           return get("", "");
0055         }
0056       },
0057       edm::ESProductTag<MagneticField, IdealMagneticFieldRecord>("", ""));
0058   magfieldToken_ = cc.consumes();
0059 }
0060 
0061 std::shared_ptr<const SiPixelGenErrorDBObject> SiPixelGenErrorDBObjectESProducer::produce(
0062     const SiPixelGenErrorDBObjectESProducerRcd& iRecord) {
0063   const GlobalPoint center(0.0, 0.0, 0.0);
0064   const float theMagField = iRecord.get(magfieldToken_).inTesla(center).mag();
0065 
0066   const auto& dbobject = iRecord.get(genErrorToken_);
0067 
0068   if (std::fabs(theMagField - dbobject.sVector()[22]) > 0.1)
0069     edm::LogWarning("UnexpectedMagneticFieldUsingNonIdealPixelGenError")
0070         << "Magnetic field is " << theMagField << " GenError Magnetic field is " << dbobject.sVector()[22];
0071 
0072   return std::shared_ptr<const SiPixelGenErrorDBObject>(&dbobject, edm::do_nothing_deleter());
0073 }
0074 
0075 DEFINE_FWK_EVENTSETUP_MODULE(SiPixelGenErrorDBObjectESProducer);