Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-08 23:10:54

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiPixel2DTemplateDBObjectESProducer
0004 // Class:      SiPixel2DTemplateDBObjectESProducer
0005 //
0006 /**\class SiPixel2DTemplateDBObjectESProducer SiPixel2DTemplateDBObjectESProducer.cc CalibTracker/SiPixelESProducers/plugin/SiPixel2DTemplateDBObjectESProducer.cc
0007 
0008  Description: ESProducer for magnetic-field-dependent local reco templates
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/do_nothing_deleter.h"
0021 #include "FWCore/Framework/interface/ModuleFactory.h"
0022 
0023 #include "MagneticField/Engine/interface/MagneticField.h"
0024 #include "CondFormats/SiPixelObjects/interface/SiPixel2DTemplateDBObject.h"
0025 #include "CalibTracker/Records/interface/SiPixel2DTemplateDBObjectESProducerRcd.h"
0026 
0027 #include <memory>
0028 
0029 using namespace edm;
0030 
0031 class SiPixel2DTemplateDBObjectESProducer : public edm::ESProducer {
0032 public:
0033   SiPixel2DTemplateDBObjectESProducer(const edm::ParameterSet& iConfig);
0034   ~SiPixel2DTemplateDBObjectESProducer() override;
0035   std::shared_ptr<const SiPixel2DTemplateDBObject> produce(const SiPixel2DTemplateDBObjectESProducerRcd&);
0036 
0037 private:
0038   edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magfieldToken_;
0039   edm::ESGetToken<SiPixel2DTemplateDBObject, SiPixel2DTemplateDBObjectRcd> dbToken_;
0040 };
0041 
0042 SiPixel2DTemplateDBObjectESProducer::SiPixel2DTemplateDBObjectESProducer(const edm::ParameterSet& iConfig) {
0043   auto cc = setWhatProduced(this);
0044   magfieldToken_ = cc.consumes();
0045   dbToken_ = cc.consumes(edm::ESInputTag{"", "numerator"});  // The correct default
0046 }
0047 
0048 SiPixel2DTemplateDBObjectESProducer::~SiPixel2DTemplateDBObjectESProducer() {}
0049 
0050 std::shared_ptr<const SiPixel2DTemplateDBObject> SiPixel2DTemplateDBObjectESProducer::produce(
0051     const SiPixel2DTemplateDBObjectESProducerRcd& iRecord) {
0052   const auto& magfield = iRecord.get(magfieldToken_);
0053 
0054   GlobalPoint center(0.0, 0.0, 0.0);
0055   float theMagField = magfield.inTesla(center).mag();
0056 
0057   if (theMagField >= 4.1 || theMagField < -0.1)
0058     edm::LogWarning("UnexpectedMagneticFieldUsingDefaultPixel2DTemplate") << "Magnetic field is " << theMagField;
0059 
0060   const auto& dbobject = iRecord.get(dbToken_);
0061 
0062   if ((theMagField > 0.1) && (std::fabs(theMagField - dbobject.sVector()[22]) > 0.1))
0063     //2D templates not actually used at 0T, so don't print warning
0064     edm::LogWarning("UnexpectedMagneticFieldUsingNonIdealPixel2DTemplate")
0065         << "Magnetic field is " << theMagField << " Template Magnetic field is " << dbobject.sVector()[22];
0066 
0067   return std::shared_ptr<const SiPixel2DTemplateDBObject>(&dbobject, edm::do_nothing_deleter());
0068 }
0069 
0070 DEFINE_FWK_EVENTSETUP_MODULE(SiPixel2DTemplateDBObjectESProducer);