CMS 3D CMS Logo

TrackFromSeedProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FastSimulation/TrackFromSeedProducer
4 // Class: TrackFromSeedProducer
5 //
13 //
14 // Original Author: Lukas Vanelderen
15 // Created: Thu, 28 May 2015 13:27:33 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
26 
29 
31 
45 
46 //
47 // class declaration
48 //
49 
51 public:
53  ~TrackFromSeedProducer() override;
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57 private:
58  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
59 
60  // ----------member data ---------------------------
67 };
68 
69 //
70 // constants, enums and typedefs
71 //
72 
73 //
74 // static data member definitions
75 //
76 
77 //
78 // constructors and destructor
79 //
81  : geoToken_(esConsumes()),
82  tTopoToken_(esConsumes()),
83  mfToken_(esConsumes()),
84  ttrhToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("TTRHBuilder")))) {
85  //register your products
86  produces<reco::TrackCollection>();
87  produces<TrackingRecHitCollection>();
88  produces<reco::TrackExtraCollection>();
89 
90  // read parametes
93 
94  //consumes
95  seedsToken = consumes<edm::View<TrajectorySeed> >(seedsTag);
96  beamSpotToken = consumes<reco::BeamSpot>(beamSpotTag);
97 }
98 
100 
101 // ------------ method called to produce the data ------------
103  using namespace edm;
104  using namespace reco;
105  using namespace std;
106 
107  // output collection
108  unique_ptr<TrackCollection> tracks(new TrackCollection);
109  unique_ptr<TrackingRecHitCollection> rechits(new TrackingRecHitCollection);
110  unique_ptr<TrackExtraCollection> trackextras(new TrackExtraCollection);
111 
112  // product references
113  TrackExtraRefProd ref_trackextras = iEvent.getRefBeforePut<TrackExtraCollection>();
114  TrackingRecHitRefProd ref_rechits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
115 
116  // input collection
118  iEvent.getByToken(seedsToken, hseeds);
119  const auto& seeds = *hseeds;
120 
121  // beam spot
123  iEvent.getByToken(beamSpotToken, beamSpot);
124 
125  // some objects to build to tracks
126  TSCBLBuilderNoMaterial tscblBuilder;
127 
128  const auto& tTRHBuilder = &iSetup.getData(ttrhToken_);
129  const auto& theMF = &iSetup.getData(mfToken_);
130  const TrackerTopology& ttopo = iSetup.getData(tTopoToken_);
131  const GlobalTrackingGeometry* const geometry_ = &iSetup.getData(geoToken_);
132 
133  // create tracks from seeds
134  int nfailed = 0;
135  for (size_t iSeed = 0; iSeed < seeds.size(); ++iSeed) {
136  auto const& seed = seeds[iSeed];
137  // try to create a track
139  if (seed.nHits() == 0) { //this is for deepCore seeds only
140  const Surface* deepCore_sruface = &geometry_->idToDet(seed.startingState().detId())->specificSurface();
141  state = trajectoryStateTransform::transientState(seed.startingState(), deepCore_sruface, theMF);
142  } else {
143  TransientTrackingRecHit::RecHitPointer lastRecHit = tTRHBuilder->build(&*(seed.recHits().end() - 1));
144  state = trajectoryStateTransform::transientState(seed.startingState(), lastRecHit->surface(), theMF);
145  }
146  TrajectoryStateClosestToBeamLine tsAtClosestApproachSeed =
147  tscblBuilder(*state.freeState(), *beamSpot); //as in TrackProducerAlgorithm
148  if (tsAtClosestApproachSeed.isValid()) {
149  const reco::TrackBase::Point vSeed1(tsAtClosestApproachSeed.trackStateAtPCA().position().x(),
150  tsAtClosestApproachSeed.trackStateAtPCA().position().y(),
151  tsAtClosestApproachSeed.trackStateAtPCA().position().z());
152  const reco::TrackBase::Vector pSeed(tsAtClosestApproachSeed.trackStateAtPCA().momentum().x(),
153  tsAtClosestApproachSeed.trackStateAtPCA().momentum().y(),
154  tsAtClosestApproachSeed.trackStateAtPCA().momentum().z());
155  //GlobalPoint vSeed(vSeed1.x()-beamSpot->x0(),vSeed1.y()-beamSpot->y0(),vSeed1.z()-beamSpot->z0());
156  PerigeeTrajectoryError seedPerigeeErrors =
157  PerigeeConversions::ftsToPerigeeError(tsAtClosestApproachSeed.trackStateAtPCA());
158  tracks->emplace_back(0., 0., vSeed1, pSeed, state.charge(), seedPerigeeErrors.covarianceMatrix());
159  } else {
160  edm::LogVerbatim("SeedValidator") << "TrajectoryStateClosestToBeamLine not valid";
161  // use magic values chi2<0, ndof<0, charge=0 to denote a case where the fit has failed
162  // If this definition is changed, change also interface/trackFromSeedFitFailed.h
163  tracks->emplace_back(
165  nfailed++;
166  }
167 
168  tracks->back().appendHits(seed.recHits().begin(), seed.recHits().end(), ttopo);
169  // store the hits
170  size_t firsthitindex = rechits->size();
171  for (auto const& recHit : seed.recHits()) {
172  rechits->push_back(recHit);
173  }
174 
175  // create a trackextra, just to store the hit range
176  trackextras->push_back(TrackExtra());
177  trackextras->back().setHits(ref_rechits, firsthitindex, rechits->size() - firsthitindex);
178  trackextras->back().setSeedRef(edm::RefToBase<TrajectorySeed>(hseeds, iSeed));
179  // create link between track and trackextra
180  tracks->back().setExtra(TrackExtraRef(ref_trackextras, trackextras->size() - 1));
181  }
182 
183  if (nfailed > 0) {
184  edm::LogInfo("SeedValidator") << "failed to create tracks from " << nfailed << " out of " << seeds.size()
185  << " seeds ";
186  }
187  iEvent.put(std::move(tracks));
188  iEvent.put(std::move(rechits));
189  iEvent.put(std::move(trackextras));
190 }
191 
192 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
194  //The following says we do not know what parameters are allowed so do no validation
195  // Please change this to state exactly what you do use, even if it is no parameters
197  desc.setUnknown();
198  descriptions.addDefault(desc);
199 }
200 
201 //define this as a plug-in
Log< level::Info, true > LogVerbatim
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T z() const
Definition: PV3DBase.h:61
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:16
const GeomDet * idToDet(DetId) const override
GlobalPoint position() const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedsToken
GlobalVector momentum() const
bool getData(T &iHolder) const
Definition: EventSetup.h:122
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > geoToken_
std::shared_ptr< TrackingRecHit const > RecHitPointer
Log< level::Info, false > LogInfo
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhToken_
auto const & tracks
cannot be loose
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
TrackFromSeedProducer(const edm::ParameterSet &)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
fixed size matrix
HLT enums.
PerigeeTrajectoryError ftsToPerigeeError(const FTS &originalFTS)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:77
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
def move(src, dest)
Definition: eostools.py:511
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74