Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-25 22:35:15

0001 #include <memory>
0002 #include <string>
0003 #include <alpaka/alpaka.hpp>
0004 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0005 
0006 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
0008 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0010 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0011 #include "RecoLocalTracker/Records/interface/TkPixelCPERecord.h"
0012 #include "RecoLocalTracker/SiPixelRecHits/interface/alpaka/PixelCPEFastParamsCollection.h"
0013 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEFastParamsHost.h"
0014 
0015 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0016 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0017 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0018 #include "MagneticField/Engine/interface/MagneticField.h"
0019 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0020 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
0021 
0022 #include "CondFormats/DataRecord/interface/SiPixelGenErrorDBObjectRcd.h"
0023 #include "RecoLocalTracker/Records/interface/PixelCPEFastParamsRecord.h"
0024 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0025 
0026 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0027   template <typename TrackerTraits>
0028   class PixelCPEFastParamsESProducerAlpaka : public ESProducer {
0029   public:
0030     PixelCPEFastParamsESProducerAlpaka(edm::ParameterSet const& iConfig);
0031     std::unique_ptr<PixelCPEFastParamsHost<TrackerTraits>> produce(const PixelCPEFastParamsRecord& iRecord);
0032 
0033     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0034 
0035   private:
0036     edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magfieldToken_;
0037     edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> pDDToken_;
0038     edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> hTTToken_;
0039     edm::ESGetToken<SiPixelLorentzAngle, SiPixelLorentzAngleRcd> lorentzAngleToken_;
0040     edm::ESGetToken<SiPixelLorentzAngle, SiPixelLorentzAngleRcd> lorentzAngleWidthToken_;
0041     edm::ESGetToken<SiPixelGenErrorDBObject, SiPixelGenErrorDBObjectRcd> genErrorDBObjectToken_;
0042 
0043     edm::ParameterSet pset_;
0044     bool useErrorsFromTemplates_;
0045   };
0046 
0047   using namespace edm;
0048 
0049   template <typename TrackerTraits>
0050   PixelCPEFastParamsESProducerAlpaka<TrackerTraits>::PixelCPEFastParamsESProducerAlpaka(const edm::ParameterSet& p)
0051       : ESProducer(p), pset_(p) {
0052     auto const& myname = p.getParameter<std::string>("ComponentName");
0053     auto const& magname = p.getParameter<edm::ESInputTag>("MagneticFieldRecord");
0054     useErrorsFromTemplates_ = p.getParameter<bool>("UseErrorsFromTemplates");
0055 
0056     auto cc = setWhatProduced(this, myname);
0057     magfieldToken_ = cc.consumes(magname);
0058     pDDToken_ = cc.consumes();
0059     hTTToken_ = cc.consumes();
0060     lorentzAngleToken_ = cc.consumes(edm::ESInputTag(""));
0061     lorentzAngleWidthToken_ = cc.consumes(edm::ESInputTag("", "forWidth"));
0062     if (useErrorsFromTemplates_) {
0063       genErrorDBObjectToken_ = cc.consumes();
0064     }
0065   }
0066 
0067   template <typename TrackerTraits>
0068   std::unique_ptr<PixelCPEFastParamsHost<TrackerTraits>> PixelCPEFastParamsESProducerAlpaka<TrackerTraits>::produce(
0069       const PixelCPEFastParamsRecord& iRecord) {
0070     // add the new la width object
0071     const SiPixelLorentzAngle* lorentzAngleWidthProduct = &iRecord.get(lorentzAngleWidthToken_);
0072 
0073     const SiPixelGenErrorDBObject* genErrorDBObjectProduct = nullptr;
0074 
0075     // Errors take only from new GenError
0076     if (useErrorsFromTemplates_) {  // do only when generrors are needed
0077       genErrorDBObjectProduct = &iRecord.get(genErrorDBObjectToken_);
0078       //} else {
0079       //std::cout<<" pass an empty GenError pointer"<<std::endl;
0080     }
0081     return std::make_unique<PixelCPEFastParamsHost<TrackerTraits>>(pset_,
0082                                                                    &iRecord.get(magfieldToken_),
0083                                                                    iRecord.get(pDDToken_),
0084                                                                    iRecord.get(hTTToken_),
0085                                                                    &iRecord.get(lorentzAngleToken_),
0086                                                                    genErrorDBObjectProduct,
0087                                                                    lorentzAngleWidthProduct);
0088   }
0089 
0090   template <typename TrackerTraits>
0091   void PixelCPEFastParamsESProducerAlpaka<TrackerTraits>::fillDescriptions(
0092       edm::ConfigurationDescriptions& descriptions) {
0093     edm::ParameterSetDescription desc;
0094 
0095     // from PixelCPEBase
0096     PixelCPEBase::fillPSetDescription(desc);
0097 
0098     // from PixelCPEFast
0099     PixelCPEFastParamsHost<TrackerTraits>::fillPSetDescription(desc);
0100 
0101     // used by PixelCPEFast
0102     desc.add<double>("EdgeClusterErrorX", 50.0);
0103     desc.add<double>("EdgeClusterErrorY", 85.0);
0104     desc.add<bool>("UseErrorsFromTemplates", true);
0105     desc.add<bool>("TruncatePixelCharge", true);
0106 
0107     std::string name = "PixelCPEFastParams";
0108     name += TrackerTraits::nameModifier;
0109     desc.add<std::string>("ComponentName", name);
0110     desc.add<edm::ESInputTag>("MagneticFieldRecord", edm::ESInputTag());
0111 
0112     descriptions.addWithDefaultLabel(desc);
0113   }
0114 
0115   using PixelCPEFastParamsESProducerAlpakaPhase1 = PixelCPEFastParamsESProducerAlpaka<pixelTopology::Phase1>;
0116   using PixelCPEFastParamsESProducerAlpakaHIonPhase1 = PixelCPEFastParamsESProducerAlpaka<pixelTopology::HIonPhase1>;
0117   using PixelCPEFastParamsESProducerAlpakaPhase2 = PixelCPEFastParamsESProducerAlpaka<pixelTopology::Phase2>;
0118 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0119 
0120 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(PixelCPEFastParamsESProducerAlpakaPhase1);
0121 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(PixelCPEFastParamsESProducerAlpakaHIonPhase1);
0122 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(PixelCPEFastParamsESProducerAlpakaPhase2);