CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56 private:
57  virtual 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  produces<std::vector<int> >();
84 
85  // read parametes
86  edm::InputTag seedsTag(iConfig.getParameter<edm::InputTag>("src"));
88  tTRHBuilderName = iConfig.getParameter<std::string>("TTRHBuilder");
89 
90  //consumes
91  seedsToken = consumes<std::vector<TrajectorySeed> >(seedsTag);
92  beamSpotToken = consumes<reco::BeamSpot>(beamSpotTag);
93 }
94 
95 
97 
98 // ------------ method called to produce the data ------------
99 void
101 {
102  using namespace edm;
103  using namespace reco;
104  using namespace std;
105 
106  // output collection
107  auto_ptr<TrackCollection> tracks(new TrackCollection);
108  auto_ptr<TrackingRecHitCollection> rechits(new TrackingRecHitCollection);
109  auto_ptr<TrackExtraCollection> trackextras(new TrackExtraCollection);
110  auto_ptr<vector<int> > seedToTrack(new vector<int>());
111 
112  // product references
113  TrackExtraRefProd ref_trackextras = iEvent.getRefBeforePut<TrackExtraCollection>();
115 
116  // input collection
118  iEvent.getByToken(seedsToken,seeds);
119 
120  // beam spot
123 
124  // some objects to build to tracks
125  TSCBLBuilderNoMaterial tscblBuilder;
126 
128  iSetup.get<TransientRecHitRecord>().get(tTRHBuilderName,tTRHBuilder);
129 
131  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
132 
134  iSetup.get<TrackerTopologyRcd>().get(httopo);
135  const TrackerTopology& ttopo = *httopo;
136 
137  // create tracks from seeds
138  int nfailed = 0;
139  for (auto const & seed : *seeds.product()){
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  edm::LogVerbatim("SeedValidator")<<"TrajectoryStateClosestToBeamLine not valid";
146  seedToTrack->push_back(-1);
147  nfailed++;
148  continue;
149  }
150  const reco::TrackBase::Point vSeed1(tsAtClosestApproachSeed.trackStateAtPCA().position().x(),
151  tsAtClosestApproachSeed.trackStateAtPCA().position().y(),
152  tsAtClosestApproachSeed.trackStateAtPCA().position().z());
153  const reco::TrackBase::Vector pSeed(tsAtClosestApproachSeed.trackStateAtPCA().momentum().x(),
154  tsAtClosestApproachSeed.trackStateAtPCA().momentum().y(),
155  tsAtClosestApproachSeed.trackStateAtPCA().momentum().z());
156  //GlobalPoint vSeed(vSeed1.x()-beamSpot->x0(),vSeed1.y()-beamSpot->y0(),vSeed1.z()-beamSpot->z0());
157  PerigeeTrajectoryError seedPerigeeErrors = PerigeeConversions::ftsToPerigeeError(tsAtClosestApproachSeed.trackStateAtPCA());
158  tracks->push_back(Track(0.,0., vSeed1, pSeed, 1, seedPerigeeErrors.covarianceMatrix()));
159  seedToTrack->push_back(tracks->size()-1);
160  tracks->back().appendHits(seed.recHits().first,seed.recHits().second,ttopo);
161  // store the hits
162  size_t firsthitindex = rechits->size();
163  for(auto hitit = seed.recHits().first;hitit != seed.recHits().second;++hitit){
164  rechits->push_back(*hitit);
165  }
166  // create a trackextra, just to store the hit range
167  trackextras->push_back(TrackExtra());
168  trackextras->back().setHits(ref_rechits,firsthitindex,rechits->size() - firsthitindex);
169  // create link between track and trackextra
170  tracks->back().setExtra( TrackExtraRef( ref_trackextras, trackextras->size() - 1) );
171  }
172 
173  if (nfailed > 0) {
174  edm::LogInfo("SeedValidator") << "failed to create tracks from " << nfailed << " out of " << seeds->size() << " seeds ";
175  }
176  iEvent.put(tracks);
177  iEvent.put(seedToTrack);
178  iEvent.put(rechits);
179  iEvent.put(trackextras);
180 }
181 
182 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
183 void
185  //The following says we do not know what parameters are allowed so do no validation
186  // Please change this to state exactly what you do use, even if it is no parameters
188  desc.setUnknown();
189  descriptions.addDefault(desc);
190 }
191 
192 //define this as a plug-in
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:17
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
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:141
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 &)
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< std::vector< TrajectorySeed > > seedsToken
PerigeeTrajectoryError ftsToPerigeeError(const FTS &originalFTS)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:80
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override