Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-23 04:29:19

0001 // -*- C++ -*-
0002 //
0003 // Package:    FastSimulation/TrackFromSeedProducer
0004 // Class:      TrackFromSeedProducer
0005 //
0006 /**\class TrackFromSeedProducer TrackFromSeedProducer.cc FastSimulation/TrackFromSeedProducer/plugins/TrackFromSeedProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Lukas Vanelderen
0015 //         Created:  Thu, 28 May 2015 13:27:33 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/global/EDProducer.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 #include "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0034 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0035 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0036 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
0037 #include "TrackingTools/TrajectoryState/interface/PerigeeConversions.h"
0038 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0039 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0040 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0041 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0042 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0043 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0044 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0045 
0046 //
0047 // class declaration
0048 //
0049 
0050 class TrackFromSeedProducer : public edm::global::EDProducer<> {
0051 public:
0052   explicit TrackFromSeedProducer(const edm::ParameterSet&);
0053   ~TrackFromSeedProducer() override;
0054 
0055   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0056 
0057 private:
0058   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0059 
0060   // ----------member data ---------------------------
0061   edm::EDGetTokenT<edm::View<TrajectorySeed> > seedsToken;
0062   edm::EDGetTokenT<reco::BeamSpot> beamSpotToken;
0063   const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> geoToken_;
0064   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0065   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> mfToken_;
0066   const edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> ttrhToken_;
0067 };
0068 
0069 //
0070 // constants, enums and typedefs
0071 //
0072 
0073 //
0074 // static data member definitions
0075 //
0076 
0077 //
0078 // constructors and destructor
0079 //
0080 TrackFromSeedProducer::TrackFromSeedProducer(const edm::ParameterSet& iConfig)
0081     : geoToken_(esConsumes()),
0082       tTopoToken_(esConsumes()),
0083       mfToken_(esConsumes()),
0084       ttrhToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("TTRHBuilder")))) {
0085   //register your products
0086   produces<reco::TrackCollection>();
0087   produces<TrackingRecHitCollection>();
0088   produces<reco::TrackExtraCollection>();
0089 
0090   // read parametes
0091   edm::InputTag seedsTag(iConfig.getParameter<edm::InputTag>("src"));
0092   edm::InputTag beamSpotTag(iConfig.getParameter<edm::InputTag>("beamSpot"));
0093 
0094   //consumes
0095   seedsToken = consumes<edm::View<TrajectorySeed> >(seedsTag);
0096   beamSpotToken = consumes<reco::BeamSpot>(beamSpotTag);
0097 }
0098 
0099 TrackFromSeedProducer::~TrackFromSeedProducer() {}
0100 
0101 // ------------ method called to produce the data  ------------
0102 void TrackFromSeedProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0103   using namespace edm;
0104   using namespace reco;
0105   using namespace std;
0106 
0107   // output collection
0108   unique_ptr<TrackCollection> tracks(new TrackCollection);
0109   unique_ptr<TrackingRecHitCollection> rechits(new TrackingRecHitCollection);
0110   unique_ptr<TrackExtraCollection> trackextras(new TrackExtraCollection);
0111 
0112   // product references
0113   TrackExtraRefProd ref_trackextras = iEvent.getRefBeforePut<TrackExtraCollection>();
0114   TrackingRecHitRefProd ref_rechits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
0115 
0116   // input collection
0117   Handle<edm::View<TrajectorySeed> > hseeds;
0118   iEvent.getByToken(seedsToken, hseeds);
0119   const auto& seeds = *hseeds;
0120 
0121   // beam spot
0122   edm::Handle<reco::BeamSpot> beamSpot;
0123   iEvent.getByToken(beamSpotToken, beamSpot);
0124 
0125   // some objects to build to tracks
0126   TSCBLBuilderNoMaterial tscblBuilder;
0127 
0128   const auto& tTRHBuilder = &iSetup.getData(ttrhToken_);
0129   const auto& theMF = &iSetup.getData(mfToken_);
0130   const TrackerTopology& ttopo = iSetup.getData(tTopoToken_);
0131   const GlobalTrackingGeometry* const geometry_ = &iSetup.getData(geoToken_);
0132 
0133   // create tracks from seeds
0134   int nfailed = 0;
0135   for (size_t iSeed = 0; iSeed < seeds.size(); ++iSeed) {
0136     auto const& seed = seeds[iSeed];
0137     // try to create a track
0138     TrajectoryStateOnSurface state;
0139     if (seed.nHits() == 0) {  //this is for deepCore seeds only
0140       const Surface* deepCore_sruface = &geometry_->idToDet(seed.startingState().detId())->specificSurface();
0141       state = trajectoryStateTransform::transientState(seed.startingState(), deepCore_sruface, theMF);
0142     } else {
0143       TransientTrackingRecHit::RecHitPointer lastRecHit = tTRHBuilder->build(&*(seed.recHits().end() - 1));
0144       state = trajectoryStateTransform::transientState(seed.startingState(), lastRecHit->surface(), theMF);
0145     }
0146     TrajectoryStateClosestToBeamLine tsAtClosestApproachSeed =
0147         tscblBuilder(*state.freeState(), *beamSpot);  //as in TrackProducerAlgorithm
0148     if (tsAtClosestApproachSeed.isValid()) {
0149       const reco::TrackBase::Point vSeed1(tsAtClosestApproachSeed.trackStateAtPCA().position().x(),
0150                                           tsAtClosestApproachSeed.trackStateAtPCA().position().y(),
0151                                           tsAtClosestApproachSeed.trackStateAtPCA().position().z());
0152       const reco::TrackBase::Vector pSeed(tsAtClosestApproachSeed.trackStateAtPCA().momentum().x(),
0153                                           tsAtClosestApproachSeed.trackStateAtPCA().momentum().y(),
0154                                           tsAtClosestApproachSeed.trackStateAtPCA().momentum().z());
0155       //GlobalPoint vSeed(vSeed1.x()-beamSpot->x0(),vSeed1.y()-beamSpot->y0(),vSeed1.z()-beamSpot->z0());
0156       PerigeeTrajectoryError seedPerigeeErrors =
0157           PerigeeConversions::ftsToPerigeeError(tsAtClosestApproachSeed.trackStateAtPCA());
0158       tracks->emplace_back(0., 0., vSeed1, pSeed, state.charge(), seedPerigeeErrors.covarianceMatrix());
0159     } else {
0160       edm::LogVerbatim("SeedValidator") << "TrajectoryStateClosestToBeamLine not valid";
0161       // use magic values chi2<0, ndof<0, charge=0 to denote a case where the fit has failed
0162       // If this definition is changed, change also interface/trackFromSeedFitFailed.h
0163       tracks->emplace_back(
0164           -1, -1, reco::TrackBase::Point(), reco::TrackBase::Vector(), 0, reco::TrackBase::CovarianceMatrix());
0165       nfailed++;
0166     }
0167 
0168     tracks->back().appendHits(seed.recHits().begin(), seed.recHits().end(), ttopo);
0169     // store the hits
0170     size_t firsthitindex = rechits->size();
0171     for (auto const& recHit : seed.recHits()) {
0172       rechits->push_back(recHit);
0173     }
0174 
0175     // create a trackextra, just to store the hit range
0176     trackextras->push_back(TrackExtra());
0177     trackextras->back().setHits(ref_rechits, firsthitindex, rechits->size() - firsthitindex);
0178     trackextras->back().setSeedRef(edm::RefToBase<TrajectorySeed>(hseeds, iSeed));
0179     // create link between track and trackextra
0180     tracks->back().setExtra(TrackExtraRef(ref_trackextras, trackextras->size() - 1));
0181   }
0182 
0183   if (nfailed > 0) {
0184     edm::LogInfo("SeedValidator") << "failed to create tracks from " << nfailed << " out of " << seeds.size()
0185                                   << " seeds ";
0186   }
0187   iEvent.put(std::move(tracks));
0188   iEvent.put(std::move(rechits));
0189   iEvent.put(std::move(trackextras));
0190 }
0191 
0192 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0193 void TrackFromSeedProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0194   //The following says we do not know what parameters are allowed so do no validation
0195   // Please change this to state exactly what you do use, even if it is no parameters
0196   edm::ParameterSetDescription desc;
0197   desc.setUnknown();
0198   descriptions.addDefault(desc);
0199 }
0200 
0201 //define this as a plug-in
0202 DEFINE_FWK_MODULE(TrackFromSeedProducer);