Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-24 02:13:02

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0004 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
0005 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0006 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0007 #include "RecoLocalTracker/Records/interface/TrackerCPERecord.h"
0008 #include "RecoLocalTracker/ClusterParameterEstimator/interface/StripClusterParameterEstimator.h"
0009 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
0010 #include "RecoLocalTracker/SiStripRecHitConverter/interface/SiStripRecHitMatcher.h"
0011 #include "RecoLocalTracker/ClusterParameterEstimator/interface/ClusterParameterEstimator.h"
0012 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
0013 
0014 #include "MagneticField/Engine/interface/MagneticField.h"
0015 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0016 
0017 #include "RecoLocalTracker/Phase2TrackerRecHits/interface/Phase2StripCPE.h"
0018 
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/Framework/interface/ModuleFactory.h"
0022 #include "FWCore/Utilities/interface/ESGetToken.h"
0023 
0024 #include <string>
0025 #include <memory>
0026 #include <optional>
0027 
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 
0030 class TkTransientTrackingRecHitBuilderESProducer : public edm::ESProducer {
0031 public:
0032   TkTransientTrackingRecHitBuilderESProducer(const edm::ParameterSet& p);
0033 
0034   std::unique_ptr<TransientTrackingRecHitBuilder> produce(const TransientRecHitRecord&);
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 private:
0039   std::optional<edm::ESGetToken<StripClusterParameterEstimator, TkStripCPERecord>> spToken_;
0040   std::optional<edm::ESGetToken<PixelClusterParameterEstimator, TkPixelCPERecord>> ppToken_;
0041   std::optional<edm::ESGetToken<SiStripRecHitMatcher, TkStripCPERecord>> mpToken_;
0042   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0043   std::optional<edm::ESGetToken<ClusterParameterEstimator<Phase2TrackerCluster1D>, TkPhase2OTCPERecord>> p2OTToken_;
0044   bool const computeCoarseLocalPositionFromDisk_;
0045 };
0046 
0047 using namespace edm;
0048 
0049 TkTransientTrackingRecHitBuilderESProducer::TkTransientTrackingRecHitBuilderESProducer(const edm::ParameterSet& p)
0050     : computeCoarseLocalPositionFromDisk_(p.getParameter<bool>("ComputeCoarseLocalPositionFromDisk")) {
0051   std::string const myname = p.getParameter<std::string>("ComponentName");
0052   auto c = setWhatProduced(this, myname);
0053   geomToken_ = c.consumes();
0054 
0055   std::string const sname = p.getParameter<std::string>("StripCPE");
0056   if (sname != "Fake") {
0057     spToken_ = c.consumes(edm::ESInputTag("", sname));
0058   }
0059 
0060   std::string const pname = p.getParameter<std::string>("PixelCPE");
0061   if (pname != "Fake") {
0062     ppToken_ = c.consumes(edm::ESInputTag("", pname));
0063   }
0064 
0065   auto const mname = p.getParameter<std::string>("Matcher");
0066   if (mname != "Fake") {
0067     mpToken_ = c.consumes(edm::ESInputTag("", mname));
0068   }
0069 
0070   auto const P2otname = p.getParameter<std::string>("Phase2StripCPE");
0071   if (!P2otname.empty()) {
0072     p2OTToken_ = c.consumes(edm::ESInputTag("", P2otname));
0073   }
0074 }
0075 
0076 std::unique_ptr<TransientTrackingRecHitBuilder> TkTransientTrackingRecHitBuilderESProducer::produce(
0077     const TransientRecHitRecord& iRecord) {
0078   const StripClusterParameterEstimator* sp = nullptr;
0079   if (spToken_ && !p2OTToken_) {  // no strips in Phase-2
0080     sp = &iRecord.get(*spToken_);
0081   }
0082 
0083   const PixelClusterParameterEstimator* pp = nullptr;
0084   if (ppToken_) {
0085     pp = &iRecord.get(*ppToken_);
0086   }
0087 
0088   const SiStripRecHitMatcher* mp = nullptr;
0089   if (mpToken_) {
0090     mp = &iRecord.get(*mpToken_);
0091   }
0092 
0093   if (computeCoarseLocalPositionFromDisk_)
0094     edm::LogWarning("TkTransientTrackingRecHitBuilderESProducer")
0095         << " The tracking rec hit positions and errors are not a persistent in data formats.\n"
0096         << " They are not available from disk.\n"
0097         << " However, TkTransientTrackingRecHitBuilderESProducer::ComputeCoarseLocalPositionFromDisk=True \n"
0098         << " will make the coarse estimation of this position/error available without track refit.\n"
0099         << " Position/error obtained from rechit with already defined position/error are not recomputed.\n"
0100         << " Position/error obtained from track refit are precise.";
0101 
0102   auto const& dd = iRecord.get(geomToken_);
0103 
0104   //For Phase2 upgrade
0105   if (p2OTToken_) {
0106     return std::make_unique<TkTransientTrackingRecHitBuilder>(&dd, pp, &iRecord.get(*p2OTToken_));
0107   }
0108   return std::make_unique<TkTransientTrackingRecHitBuilder>(&dd, pp, sp, mp, computeCoarseLocalPositionFromDisk_);
0109 }
0110 
0111 void TkTransientTrackingRecHitBuilderESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0112   edm::ParameterSetDescription desc;
0113   desc.add<std::string>("ComponentName", "Fake");
0114   desc.add<bool>("ComputeCoarseLocalPositionFromDisk", false);
0115   desc.add<std::string>("StripCPE", "Fake")->setComment("Using \"Fake\" disables use of StripCPE");
0116   desc.add<std::string>("PixelCPE", "Fake")->setComment("Using \"Fake\" disables use of PixelCPE");
0117   desc.add<std::string>("Matcher", "Fake")->setComment("Using \"Fake\" disables use of SiStripRecHitMatcher");
0118   desc.add<std::string>("Phase2StripCPE", "")->setComment("Using empty string disables use of Phase2StripCPE");
0119   descriptions.addWithDefaultLabel(desc);
0120 }
0121 
0122 DEFINE_FWK_EVENTSETUP_MODULE(TkTransientTrackingRecHitBuilderESProducer);