CMS 3D CMS Logo

SeedToTrackProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SeedToTrackProducer
4 // Class: SeedToTrackProducer
5 //
14 //
15 // Original Author: Hugues Brun
16 // Created: Tue, 05 Nov 2013 13:42:04 GMT
17 // $Id$
18 //
19 //
20 
21 #include "SeedToTrackProducer.h"
22 
25 
26 //
27 // constructors and destructor
28 //
30  : theMGFieldToken(esConsumes()), theTrackingGeometryToken(esConsumes()), theTopoToken(esConsumes()) {
31  L2seedsTagT_ = consumes<TrajectorySeedCollection>(iConfig.getParameter<edm::InputTag>("L2seedsCollection"));
32  L2seedsTagS_ = consumes<edm::View<TrajectorySeed>>(iConfig.getParameter<edm::InputTag>("L2seedsCollection"));
33 
34  produces<reco::TrackCollection>();
35  produces<reco::TrackExtraCollection>();
36  produces<TrackingRecHitCollection>();
37 }
38 
39 //
40 // member functions
41 //
42 
43 // ------------ method called to produce the data ------------
45  using namespace edm;
46  using namespace std;
47 
48  std::unique_ptr<reco::TrackCollection> selectedTracks(new reco::TrackCollection);
49  std::unique_ptr<reco::TrackExtraCollection> selectedTrackExtras(new reco::TrackExtraCollection());
50  std::unique_ptr<TrackingRecHitCollection> selectedTrackHits(new TrackingRecHitCollection());
51 
52  reco::TrackRefProd rTracks = iEvent.getRefBeforePut<reco::TrackCollection>();
53  reco::TrackExtraRefProd rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
54  TrackingRecHitRefProd rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
55 
58 
59  // magnetic fied and detector geometry
60  auto const &mgField = iSetup.getData(theMGFieldToken);
61  auto const &trackingGeometry = iSetup.getData(theTrackingGeometryToken);
62 
63  const TrackerTopology &ttopo = iSetup.getData(theTopoToken);
64 
65  // now read the L2 seeds collection :
68  const std::vector<TrajectorySeed> *L2seeds = nullptr;
69  if (L2seedsCollection.isValid())
70  L2seeds = L2seedsCollection.product();
71  else
72  edm::LogError("SeedToTrackProducer") << "L2 seeds collection not found !! " << endl;
73 
75  iEvent.getByToken(L2seedsTagS_, seedHandle);
76 
77  // now loop on the seeds :
78  for (unsigned int i = 0; i < L2seeds->size(); i++) {
79  // get the kinematic extrapolation from the seed
80  TrajectoryStateOnSurface theTrajectory = seedTransientState(L2seeds->at(i), mgField, trackingGeometry);
81  float seedEta = theTrajectory.globalMomentum().eta();
82  float seedPhi = theTrajectory.globalMomentum().phi();
83  float seedPt = theTrajectory.globalMomentum().perp();
84  CovarianceMatrix matrixSeedErr = theTrajectory.curvilinearError().matrix();
85  edm::LogVerbatim("SeedToTrackProducer")
86  << "seedPt=" << seedPt << " seedEta=" << seedEta << " seedPhi=" << seedPhi << endl;
87  /*AlgebraicSymMatrix66 errors = theTrajectory.cartesianError().matrix();
88  double partialPterror =
89  errors(3,3)*pow(theTrajectory.globalMomentum().x(),2) +
90  errors(4,4)*pow(theTrajectory.globalMomentum().y(),2);
91  edm::LogVerbatim("SeedToTrackProducer") << "seedPtError=" <<
92  sqrt(partialPterror)/theTrajectory.globalMomentum().perp() <<
93  "seedPhiError=" << theTrajectory.curvilinearError().matrix()(2,2) << endl;*/
94  // fill the track in a way that its pt, phi and eta will be the same as the
95  // seed
96  math::XYZPoint initPoint(0, 0, 0);
97  math::XYZVector initMom(seedPt * cos(seedPhi), seedPt * sin(seedPhi), seedPt * sinh(seedEta));
98  reco::Track theTrack(1,
99  1, // dummy Chi2 and ndof
100  initPoint,
101  initMom,
102  1,
103  matrixSeedErr,
105  reco::TrackBase::TrackQuality::tight);
106 
107  // fill the extra track with dummy information
108  math::XYZPoint dummyFinalPoint(1, 1, 1);
109  math::XYZVector dummyFinalMom(0, 0, 10);
111  CovarianceMatrix matrixExtra = ROOT::Math::SMatrixIdentity();
112  reco::TrackExtra theTrackExtra(dummyFinalPoint,
113  dummyFinalMom,
114  true,
115  initPoint,
116  initMom,
117  true,
118  matrixSeedErr,
119  1,
120  matrixExtra,
121  2,
122  (L2seeds->at(i)).direction(),
123  seed);
124  theTrack.setExtra(reco::TrackExtraRef(rTrackExtras, idx++));
125  edm::LogVerbatim("SeedToTrackProducer")
126  << "trackPt=" << theTrack.pt() << " trackEta=" << theTrack.eta() << " trackPhi=" << theTrack.phi() << endl;
127  edm::LogVerbatim("SeedToTrackProducer")
128  << "trackPtError=" << theTrack.ptError() << "trackPhiError=" << theTrack.phiError() << endl;
129 
130  // fill the seed segments in the track
131  unsigned int nHitsAdded = 0;
132  for (auto const &recHit : L2seeds->at(i).recHits()) {
133  TrackingRecHit *hit = recHit.clone();
134  theTrack.appendHitPattern(*hit, ttopo);
135  selectedTrackHits->push_back(hit);
136  nHitsAdded++;
137  }
138  theTrackExtra.setHits(rHits, hidx, nHitsAdded);
139  hidx += nHitsAdded;
140  selectedTracks->push_back(theTrack);
141  selectedTrackExtras->push_back(theTrackExtra);
142  }
144  iEvent.put(std::move(selectedTrackExtras));
145  iEvent.put(std::move(selectedTrackHits));
146 }
147 
149  const MagneticField &mgField,
150  const GlobalTrackingGeometry &trackingGeometry) const {
151  PTrajectoryStateOnDet tmpTSOD = tmpSeed.startingState();
152  DetId tmpDetId(tmpTSOD.detId());
153  const GeomDet *tmpGeomDet = trackingGeometry.idToDet(tmpDetId);
154  TrajectoryStateOnSurface tmpTSOS =
155  trajectoryStateTransform::transientState(tmpTSOD, &(tmpGeomDet->surface()), &mgField);
156  return tmpTSOS;
157 }
158 
159 // define this as a plug-in
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > theTopoToken
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
T perp() const
Definition: PV3DBase.h:69
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:754
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T eta() const
Definition: PV3DBase.h:73
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
Log< level::Error, false > LogError
const GeomDet * idToDet(DetId) const override
unsigned int detId() const
double pt() const
track transverse momentum
Definition: TrackBase.h:637
int iEvent
Definition: GenABIO.cc:224
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > theMGFieldToken
TrajectoryStateOnSurface seedTransientState(const TrajectorySeed &, const MagneticField &, const GlobalTrackingGeometry &) const
edm::EDGetTokenT< TrajectorySeedCollection > L2seedsTagT_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
bool getData(T &iHolder) const
Definition: EventSetup.h:122
PTrajectoryStateOnDet const & startingState() const
SeedToTrackProducer(const edm::ParameterSet &)
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
Definition: DetId.h:17
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
void setExtra(const TrackExtraRef &ref)
set reference to "extra" object
Definition: Track.h:136
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
const CurvilinearTrajectoryError & curvilinearError() const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
bool appendHitPattern(const TrackingRecHit &hit, const TrackerTopology &ttopo)
append a single hit to the HitPattern
Definition: TrackBase.h:510
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > theTrackingGeometryToken
edm::EDGetTokenT< edm::View< TrajectorySeed > > L2seedsTagS_
HLT enums.
double phiError() const
error on phi
Definition: TrackBase.h:766
def move(src, dest)
Definition: eostools.py:511