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 
20 // system include files
21 #include <memory>
22 
23 // user include files
27 
30 
32 
44 
45 //
46 // class declaration
47 //
48 
50 public:
52  ~TrackFromSeedProducer() override;
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
58 
59  // ----------member data ---------------------------
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78 {
79  //register your products
80  produces<reco::TrackCollection>();
81  produces<TrackingRecHitCollection>();
82  produces<reco::TrackExtraCollection>();
83 
84  // read parametes
87  tTRHBuilderName = iConfig.getParameter<std::string>("TTRHBuilder");
88 
89  //consumes
90  seedsToken = consumes<edm::View<TrajectorySeed> >(seedsTag);
91  beamSpotToken = consumes<reco::BeamSpot>(beamSpotTag);
92 }
93 
94 
96 
97 // ------------ method called to produce the data ------------
98 void
100 {
101  using namespace edm;
102  using namespace reco;
103  using namespace std;
104 
105  // output collection
106  unique_ptr<TrackCollection> tracks(new TrackCollection);
107  unique_ptr<TrackingRecHitCollection> rechits(new TrackingRecHitCollection);
108  unique_ptr<TrackExtraCollection> trackextras(new TrackExtraCollection);
109 
110  // product references
111  TrackExtraRefProd ref_trackextras = iEvent.getRefBeforePut<TrackExtraCollection>();
113 
114  // input collection
116  iEvent.getByToken(seedsToken,hseeds);
117  const auto& seeds = *hseeds;
118 
119  // beam spot
121  iEvent.getByToken(beamSpotToken,beamSpot);
122 
123  // some objects to build to tracks
124  TSCBLBuilderNoMaterial tscblBuilder;
125 
127  iSetup.get<TransientRecHitRecord>().get(tTRHBuilderName,tTRHBuilder);
128 
130  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
131 
133  iSetup.get<TrackerTopologyRcd>().get(httopo);
134  const TrackerTopology& ttopo = *httopo;
135 
136  // create tracks from seeds
137  int nfailed = 0;
138  for(size_t iSeed=0; iSeed < seeds.size(); ++iSeed) {
139  auto const& seed = seeds[iSeed];
140  // try to create a track
141  TransientTrackingRecHit::RecHitPointer lastRecHit = tTRHBuilder->build(&*(seed.recHits().second-1));
142  TrajectoryStateOnSurface state = trajectoryStateTransform::transientState( seed.startingState(), lastRecHit->surface(), theMF.product());
143  TrajectoryStateClosestToBeamLine tsAtClosestApproachSeed = tscblBuilder(*state.freeState(),*beamSpot);//as in TrackProducerAlgorithm
144  if(tsAtClosestApproachSeed.isValid()) {
145  const reco::TrackBase::Point vSeed1(tsAtClosestApproachSeed.trackStateAtPCA().position().x(),
146  tsAtClosestApproachSeed.trackStateAtPCA().position().y(),
147  tsAtClosestApproachSeed.trackStateAtPCA().position().z());
148  const reco::TrackBase::Vector pSeed(tsAtClosestApproachSeed.trackStateAtPCA().momentum().x(),
149  tsAtClosestApproachSeed.trackStateAtPCA().momentum().y(),
150  tsAtClosestApproachSeed.trackStateAtPCA().momentum().z());
151  //GlobalPoint vSeed(vSeed1.x()-beamSpot->x0(),vSeed1.y()-beamSpot->y0(),vSeed1.z()-beamSpot->z0());
152  PerigeeTrajectoryError seedPerigeeErrors = PerigeeConversions::ftsToPerigeeError(tsAtClosestApproachSeed.trackStateAtPCA());
153  tracks->emplace_back(0.,0., vSeed1, pSeed, state.charge(), seedPerigeeErrors.covarianceMatrix());
154  }
155  else {
156  edm::LogVerbatim("SeedValidator")<<"TrajectoryStateClosestToBeamLine not valid";
157  // use magic values chi2<0, ndof<0, charge=0 to denote a case where the fit has failed
158  // If this definition is changed, change also interface/trackFromSeedFitFailed.h
160  nfailed++;
161  }
162 
163  tracks->back().appendHits(seed.recHits().first,seed.recHits().second,ttopo);
164  // store the hits
165  size_t firsthitindex = rechits->size();
166  for(auto hitit = seed.recHits().first;hitit != seed.recHits().second;++hitit){
167  rechits->push_back(*hitit);
168  }
169 
170  // create a trackextra, just to store the hit range
171  trackextras->push_back(TrackExtra());
172  trackextras->back().setHits(ref_rechits,firsthitindex,rechits->size() - firsthitindex);
173  trackextras->back().setSeedRef(edm::RefToBase<TrajectorySeed>(hseeds, iSeed));
174  // create link between track and trackextra
175  tracks->back().setExtra( TrackExtraRef( ref_trackextras, trackextras->size() - 1) );
176  }
177 
178  if (nfailed > 0) {
179  edm::LogInfo("SeedValidator") << "failed to create tracks from " << nfailed << " out of " << seeds.size() << " seeds ";
180  }
181  iEvent.put(std::move(tracks));
182  iEvent.put(std::move(rechits));
183  iEvent.put(std::move(trackextras));
184 }
185 
186 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
187 void
189  //The following says we do not know what parameters are allowed so do no validation
190  // Please change this to state exactly what you do use, even if it is no parameters
192  desc.setUnknown();
193  descriptions.addDefault(desc);
194 }
195 
196 //define this as a plug-in
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:17
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedsToken
FreeTrajectoryState const * freeState(bool withErrors=true) const
math::XYZPoint Point
point in the space
Definition: TrackBase.h:83
std::shared_ptr< TrackingRecHit const > RecHitPointer
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
TrackFromSeedProducer(const edm::ParameterSet &)
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:71
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
PerigeeTrajectoryError ftsToPerigeeError(const FTS &originalFTS)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:80
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77