Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:54

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/global/EDProducer.h"
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 
0009 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0010 #include "DataFormats/TrackReco/interface/Track.h"
0011 #include "DataFormats/VertexReco/interface/Vertex.h"
0012 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0013 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0014 #include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
0015 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0016 
0017 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0019 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
0020 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0021 
0022 #include "RecoTracker/MeasurementDet/interface/MeasurementTrackerEvent.h"
0023 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0024 
0025 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0026 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimatorBase.h"
0027 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0028 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0029 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0030 
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include <vector>
0033 
0034 class dso_hidden SeedGeneratorFromL1TTracksEDProducer : public edm::global::EDProducer<> {
0035 public:
0036   SeedGeneratorFromL1TTracksEDProducer(const edm::ParameterSet& cfg);
0037   ~SeedGeneratorFromL1TTracksEDProducer() override = default;
0038 
0039   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0040 
0041   void findSeedsOnLayer(const GeometricSearchDet& layer,
0042                         const TrajectoryStateOnSurface& tsosAtIP,
0043                         Propagator& propagatorAlong,
0044                         const TTTrack<Ref_Phase2TrackerDigi_>& l1,
0045                         const MeasurementEstimator& estimator,
0046                         unsigned int& numSeedsMade,
0047                         std::unique_ptr<std::vector<TrajectorySeed>>& out) const;
0048 
0049   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0050 
0051 private:
0052   const edm::EDGetTokenT<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>> theInputCollectionTag_;
0053   const edm::EDGetTokenT<MeasurementTrackerEvent> theMeasurementTrackerTag_;
0054 
0055   // Minimum eta value to activate searching in the TEC
0056   const double theMinEtaForTEC_;
0057 
0058   // Maximum eta value to activate searching in the TOB
0059   const double theMaxEtaForTOB_;
0060 
0061   const double theErrorSFHitless_;
0062 
0063   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> mfToken_;
0064   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0065   const edm::ESGetToken<Chi2MeasurementEstimatorBase, TrackingComponentsRecord> estToken_;
0066   const edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorAlongToken_;
0067   const edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorOppositeToken_;
0068 };
0069 
0070 SeedGeneratorFromL1TTracksEDProducer::SeedGeneratorFromL1TTracksEDProducer(const edm::ParameterSet& cfg)
0071     : theInputCollectionTag_(
0072           consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_>>>(cfg.getParameter<edm::InputTag>("InputCollection"))),
0073       theMeasurementTrackerTag_(
0074           consumes<MeasurementTrackerEvent>(cfg.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
0075       theMinEtaForTEC_(cfg.getParameter<double>("minEtaForTEC")),
0076       theMaxEtaForTOB_(cfg.getParameter<double>("maxEtaForTOB")),
0077       theErrorSFHitless_(cfg.getParameter<double>("errorSFHitless")),
0078       mfToken_{esConsumes<MagneticField, IdealMagneticFieldRecord>()},
0079       geomToken_{esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()},
0080       estToken_{esConsumes<Chi2MeasurementEstimatorBase, TrackingComponentsRecord>(
0081           edm::ESInputTag("", cfg.getParameter<std::string>("estimator")))},
0082       propagatorAlongToken_{esConsumes<Propagator, TrackingComponentsRecord>(
0083           edm::ESInputTag("", cfg.getParameter<std::string>("propagator")))},
0084       propagatorOppositeToken_{esConsumes<Propagator, TrackingComponentsRecord>(
0085           edm::ESInputTag("", cfg.getParameter<std::string>("propagator")))} {
0086   produces<TrajectorySeedCollection>();
0087 }
0088 
0089 void SeedGeneratorFromL1TTracksEDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0090   edm::ParameterSetDescription desc;
0091   desc.add<edm::InputTag>("InputCollection", {"l1tTTTracksFromTrackletEmulation", "Level1TTTracks"});
0092   desc.add<std::string>("estimator", "");
0093   desc.add<std::string>("propagator", "");
0094   desc.add<edm::InputTag>("MeasurementTrackerEvent", {""});
0095   desc.add<double>("minEtaForTEC", 0.9);
0096   desc.add<double>("maxEtaForTOB", 1.2);
0097   desc.add<double>("errorSFHitless", 1e-9);
0098   descriptions.addWithDefaultLabel(desc);
0099 }
0100 
0101 void SeedGeneratorFromL1TTracksEDProducer::findSeedsOnLayer(const GeometricSearchDet& layer,
0102                                                             const TrajectoryStateOnSurface& tsosAtIP,
0103                                                             Propagator& propagatorAlong,
0104                                                             const TTTrack<Ref_Phase2TrackerDigi_>& l1,
0105                                                             const MeasurementEstimator& estimator,
0106                                                             unsigned int& numSeedsMade,
0107                                                             std::unique_ptr<std::vector<TrajectorySeed>>& out) const {
0108   std::vector<GeometricSearchDet::DetWithState> dets;
0109   layer.compatibleDetsV(tsosAtIP, propagatorAlong, estimator, dets);
0110 
0111   if (!dets.empty()) {
0112     auto const& detOnLayer = dets.front().first;
0113     auto const& tsosOnLayer = dets.front().second;
0114     if (!tsosOnLayer.isValid()) {
0115       LogDebug("SeedGeneratorFromL1TTracks") << "Hitless TSOS is not valid!";
0116     } else {
0117       dets.front().second.rescaleError(theErrorSFHitless_);
0118 
0119       PTrajectoryStateOnDet const& ptsod =
0120           trajectoryStateTransform::persistentState(tsosOnLayer, detOnLayer->geographicalId().rawId());
0121       TrajectorySeed::RecHitContainer rHC;
0122       if (numSeedsMade < 1) {  // only outermost seed
0123         out->emplace_back(ptsod, rHC, oppositeToMomentum);
0124         numSeedsMade++;
0125       }
0126     }
0127   }
0128 }
0129 
0130 void SeedGeneratorFromL1TTracksEDProducer::produce(edm::StreamID, edm::Event& ev, const edm::EventSetup& es) const {
0131   std::unique_ptr<std::vector<TrajectorySeed>> result(new std::vector<TrajectorySeed>());
0132 
0133   // TTrack Collection
0134   auto const& trks = ev.get(theInputCollectionTag_);
0135 
0136   // Trk Geometry
0137   const auto& geom = es.getData(geomToken_);
0138 
0139   // Mag field
0140   const auto& mag = es.getData(mfToken_);
0141 
0142   // Estimator
0143   auto const& estimator = es.getData(estToken_);
0144 
0145   // Get Propagators
0146   const auto& propagatorAlongH = es.getData(propagatorAlongToken_);
0147   std::unique_ptr<Propagator> propagatorAlong = SetPropagationDirection(propagatorAlongH, alongMomentum);
0148 
0149   const auto& propagatorOppositeH = es.getData(propagatorOppositeToken_);
0150   std::unique_ptr<Propagator> propagatorOpposite = SetPropagationDirection(propagatorOppositeH, oppositeToMomentum);
0151 
0152   // Get vector of Detector layers
0153   auto const& measurementTracker = ev.get(theMeasurementTrackerTag_);
0154   std::vector<BarrelDetLayer const*> const& tob = measurementTracker.geometricSearchTracker()->tobLayers();
0155 
0156   std::vector<ForwardDetLayer const*> const& tecPositive =
0157       geom.isThere(GeomDetEnumerators::P2OTEC) ? measurementTracker.geometricSearchTracker()->posTidLayers()
0158                                                : measurementTracker.geometricSearchTracker()->posTecLayers();
0159   std::vector<ForwardDetLayer const*> const& tecNegative =
0160       geom.isThere(GeomDetEnumerators::P2OTEC) ? measurementTracker.geometricSearchTracker()->negTidLayers()
0161                                                : measurementTracker.geometricSearchTracker()->negTecLayers();
0162 
0163   /// Surface used to make a TSOS at the PCA to the beamline
0164   Plane::PlanePointer dummyPlane = Plane::build(Plane::PositionType(), Plane::RotationType());
0165 
0166   // Loop over the L1's and make seeds for all of them:
0167   for (auto const& l1 : trks) {
0168     std::unique_ptr<std::vector<TrajectorySeed>> out(new std::vector<TrajectorySeed>());
0169     FreeTrajectoryState fts = trajectoryStateTransform::initialFreeStateL1TTrack(l1, &mag, true);
0170     dummyPlane->move(fts.position() - dummyPlane->position());
0171     TrajectoryStateOnSurface tsosAtIP = TrajectoryStateOnSurface(fts, *dummyPlane);
0172 
0173     unsigned int numSeedsMade = 0;
0174     //BARREL
0175     if (std::abs(l1.momentum().eta()) < theMaxEtaForTOB_) {
0176       for (auto it = tob.rbegin(); it != tob.rend(); ++it) {  //This goes from outermost to innermost layer
0177         findSeedsOnLayer(**it, tsosAtIP, *(propagatorAlong.get()), l1, estimator, numSeedsMade, out);
0178       }
0179     }
0180     if (std::abs(l1.momentum().eta()) > theMinEtaForTEC_) {
0181       numSeedsMade = 0;  // reset num of seeds
0182     }
0183     //ENDCAP+
0184     if (l1.momentum().eta() > theMinEtaForTEC_) {
0185       for (auto it = tecPositive.rbegin(); it != tecPositive.rend(); ++it) {
0186         findSeedsOnLayer(**it, tsosAtIP, *(propagatorAlong.get()), l1, estimator, numSeedsMade, out);
0187       }
0188     }
0189     //ENDCAP-
0190     if (l1.momentum().eta() < -theMinEtaForTEC_) {
0191       for (auto it = tecNegative.rbegin(); it != tecNegative.rend(); ++it) {
0192         findSeedsOnLayer(**it, tsosAtIP, *(propagatorAlong.get()), l1, estimator, numSeedsMade, out);
0193       }
0194     }
0195     std::copy(out->begin(), out->end(), std::back_inserter(*result));
0196   }  // end loop over L1Tracks
0197 
0198   ev.put(std::move(result));
0199 }
0200 
0201 #include "FWCore/PluginManager/interface/ModuleDef.h"
0202 #include "FWCore/Framework/interface/MakerMacros.h"
0203 DEFINE_FWK_MODULE(SeedGeneratorFromL1TTracksEDProducer);