CMS 3D CMS Logo

FakeTrackProducers.cc
Go to the documentation of this file.
1 
2 //
3 //
4 
18 
37 
38 template <class T>
40 public:
41  explicit FakeTrackProducer(const edm::ParameterSet &iConfig);
42  ~FakeTrackProducer() override {}
43 
44  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
45 
46 private:
52 
54  //StringCutObjectSelector<T> selector_;
55 
56  const PTrajectoryStateOnDet &getState(const TrajectorySeed &seed) const { return seed.startingState(); }
57  const PTrajectoryStateOnDet &getState(const TrackCandidate &seed) const { return seed.trajectoryStateOnDet(); }
58 };
59 
60 template <typename T>
62  : src_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("src"))),
65  trackerTopoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd>())
66 //,selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true)
67 {
68  produces<std::vector<reco::Track>>();
69  produces<std::vector<reco::TrackExtra>>();
70  produces<edm::OwnVector<TrackingRecHit>>();
71 }
72 
73 template <typename T>
75  using namespace edm;
76  using namespace std;
77 
78  edm::ESHandle<TrackerGeometry> theGeometry = iSetup.getHandle(geometryToken_);
79  edm::ESHandle<MagneticField> theMagField = iSetup.getHandle(magFieldToken_);
80  edm::ESHandle<TrackerTopology> httopo = iSetup.getHandle(trackerTopoToken_);
81  const TrackerTopology &ttopo = *httopo;
82 
84  iEvent.getByToken(src_, src);
85 
86  unique_ptr<vector<reco::Track>> out(new vector<reco::Track>());
87  out->reserve(src->size());
88  unique_ptr<vector<reco::TrackExtra>> outEx(new vector<reco::TrackExtra>());
89  outEx->reserve(src->size());
90  unique_ptr<OwnVector<TrackingRecHit>> outHits(new OwnVector<TrackingRecHit>());
91 
92  TrackingRecHitRefProd rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
93  reco::TrackExtraRefProd rTrackExtras = iEvent.getRefBeforePut<reco::TrackExtraCollection>();
94  for (typename vector<T>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
95  const T &mu = *it;
96  //if (!selector_(mu)) continue;
97  const PTrajectoryStateOnDet &pstate = getState(mu);
98  const GeomDet *det = theGeometry->idToDet(DetId(pstate.detId()));
99  if (det == nullptr) {
100  std::cerr << "ERROR: bogus detid " << pstate.detId() << std::endl;
101  continue;
102  }
104  GlobalPoint gx = state.globalPosition();
105  GlobalVector gp = state.globalMomentum();
106  reco::Track::Point x(gx.x(), gx.y(), gx.z());
107  reco::Track::Vector p(gp.x(), gp.y(), gp.z());
108  int charge = state.localParameters().charge();
109  out->push_back(reco::Track(1.0, 1.0, x, p, charge, reco::Track::CovarianceMatrix()));
110  auto hits = mu.recHits();
111  out->back().appendHits(hits.begin(), hits.end(), ttopo);
112  // Now Track Extra
113  const TrackingRecHit *hit0 = &*hits.begin();
114  const TrackingRecHit *hit1 = &*(hits.end() - 1);
115  const GeomDet *det0 = theGeometry->idToDet(hit0->geographicalId());
116  const GeomDet *det1 = theGeometry->idToDet(hit1->geographicalId());
117  if (det0 == nullptr || det1 == nullptr) {
118  std::cerr << "ERROR: bogus detids at beginning or end of range" << std::endl;
119  continue;
120  }
121  GlobalPoint gx0 = det0->toGlobal(hit0->localPosition());
122  GlobalPoint gx1 = det1->toGlobal(hit1->localPosition());
123  reco::Track::Point x0(gx0.x(), gx0.y(), gx0.z());
124  reco::Track::Point x1(gx1.x(), gx1.y(), gx1.z());
125  if (x0.R() > x1.R())
126  std::swap(x0, x1);
127  outEx->push_back(reco::TrackExtra(x1,
128  p,
129  true,
130  x0,
131  p,
132  true,
134  hit0->geographicalId().rawId(),
136  hit1->geographicalId().rawId(),
137  alongMomentum));
138  out->back().setExtra(reco::TrackExtraRef(rTrackExtras, outEx->size() - 1));
139  reco::TrackExtra &ex = outEx->back();
140  auto const firstHitIndex = outHits->size();
141  for (auto const &it2 : hits) {
142  outHits->push_back(it2);
143  }
144  ex.setHits(rHits, firstHitIndex, outHits->size() - firstHitIndex);
145  }
146 
147  iEvent.put(std::move(out));
148  iEvent.put(std::move(outEx));
149  iEvent.put(std::move(outHits));
150 }
151 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T z() const
Definition: PV3DBase.h:61
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
unsigned int detId() const
FakeTrackProducer< TrajectorySeed > FakeTrackProducerFromSeed
~FakeTrackProducer() override
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopoToken_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< std::vector< T > > src_
Labels for input collections.
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
size_type size() const
Definition: OwnVector.h:300
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
const TrackerGeomDet * idToDet(DetId) const override
const PTrajectoryStateOnDet & getState(const TrackCandidate &seed) const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
FakeTrackProducer(const edm::ParameterSet &iConfig)
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
Definition: DetId.h:17
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
DetId geographicalId() const
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geometryToken_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const PTrajectoryStateOnDet & getState(const TrajectorySeed &seed) const
Muon selection.
HLT enums.
FakeTrackProducer< TrackCandidate > FakeTrackProducerFromCandidate
float x
long double T
virtual LocalPoint localPosition() const =0
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:77
def move(src, dest)
Definition: eostools.py:511
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74