CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FakeTrackProducers.cc
Go to the documentation of this file.
1 
2 //
3 //
4 
18 
35 
36 
37 
38 template<class T>
40  public:
41  explicit FakeTrackProducer(const edm::ParameterSet & iConfig);
42  virtual ~FakeTrackProducer() { }
43 
44  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
45  private:
48 
50  //StringCutObjectSelector<T> selector_;
51 
52  // EventSetup
55 
56  const PTrajectoryStateOnDet & getState(const TrajectorySeed &seed) const { return seed.startingState(); }
57  const PTrajectoryStateOnDet & getState(const TrackCandidate &seed) const { return seed.trajectoryStateOnDet(); }
58  TrajectorySeed::range getHits (const TrajectorySeed &seed) const { return seed.recHits(); }
59  TrajectorySeed::range getHits (const TrackCandidate &seed) const { return seed.recHits(); }
60 };
61 
62 
63 template<typename T>
65  src_(iConfig.getParameter<edm::InputTag>("src"))
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>
74 void
76  using namespace edm;
77  using namespace std;
78 
79 
80  iSetup.get<TrackerDigiGeometryRecord>().get(theGeometry);
81  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
82 
84  iEvent.getByLabel(src_, src);
85 
86  auto_ptr<vector<reco::Track> > out(new vector<reco::Track>());
87  out->reserve(src->size());
88  auto_ptr<vector<reco::TrackExtra> > outEx(new vector<reco::TrackExtra>());
89  outEx->reserve(src->size());
90  auto_ptr<OwnVector<TrackingRecHit> > outHits(new OwnVector<TrackingRecHit>());
91 
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 == 0) { std::cerr << "ERROR: bogus detid " << pstate.detId() << std::endl; continue; }
100  TrajectoryStateOnSurface state = trajectoryStateTransform::transientState(pstate, & det->surface(), &*theMagField);
101  GlobalPoint gx = state.globalPosition();
102  GlobalVector gp = state.globalMomentum();
103  reco::Track::Point x(gx.x(), gx.y(), gx.z());
104  reco::Track::Vector p(gp.x(), gp.y(), gp.z());
105  int charge = state.localParameters().charge();
106  out->push_back(reco::Track(1.0,1.0,x,p,charge,reco::Track::CovarianceMatrix()));
107  TrajectorySeed::range hits = getHits(mu);
108  out->back().appendHits(hits.first, hits.second);
109  // Now Track Extra
110  const TrackingRecHit *hit0 = &*hits.first;
111  const TrackingRecHit *hit1 = &*(hits.second-1);
112  const GeomDet *det0 = theGeometry->idToDet(hit0->geographicalId());
113  const GeomDet *det1 = theGeometry->idToDet(hit1->geographicalId());
114  if (det0 == 0 || det1 == 0) { std::cerr << "ERROR: bogus detids at beginning or end of range" << std::endl; continue; }
115  GlobalPoint gx0 = det0->toGlobal(hit0->localPosition());
116  GlobalPoint gx1 = det1->toGlobal(hit1->localPosition());
117  reco::Track::Point x0(gx0.x(), gx0.y(), gx0.z());
118  reco::Track::Point x1(gx1.x(), gx1.y(), gx1.z());
119  if (x0.R() > x1.R()) std::swap(x0,x1);
120  outEx->push_back( reco::TrackExtra(x1, p, true, x0, p, true,
123  alongMomentum) );
124  out->back().setExtra( reco::TrackExtraRef( rTrackExtras, outEx->size()-1 ) );
125  reco::TrackExtra &ex = outEx->back();
126  for (OwnVector<TrackingRecHit>::const_iterator it2 = hits.first; it2 != hits.second; ++it2) {
127  outHits->push_back(*it2);
128  ex.add( TrackingRecHitRef( rHits, outHits->size()-1 ) );
129  }
130  }
131 
132  iEvent.put(out);
133  iEvent.put(outEx);
134  iEvent.put(outHits);
135 }
136 
const LocalTrajectoryParameters & localParameters() const
range recHits() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ESHandle< MagneticField > theMagField
TrajectorySeed::range getHits(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:52
T y() const
Definition: PV3DBase.h:63
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
GlobalPoint globalPosition() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
FakeTrackProducer< TrajectorySeed > FakeTrackProducerFromSeed
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const PTrajectoryStateOnDet & getState(const TrackCandidate &seed) const
PTrajectoryStateOnDet const & trajectoryStateOnDet() const
int iEvent
Definition: GenABIO.cc:230
void add(const TrackingRecHitRef &ref)
add a reference to a RecHit
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
const PTrajectoryStateOnDet & getState(const TrajectorySeed &seed) const
TrajectorySeed::range getHits(const TrajectorySeed &seed) const
T z() const
Definition: PV3DBase.h:64
std::pair< const_iterator, const_iterator > range
unsigned int detId() const
const int mu
Definition: Constants.h:22
math::XYZPoint Point
point in the space
Definition: TrackBase.h:82
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
RefProd< PROD > getRefBeforePut()
Definition: Event.h:133
tuple out
Definition: dbtoconf.py:99
FakeTrackProducer(const edm::ParameterSet &iConfig)
Definition: DetId.h:18
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
PTrajectoryStateOnDet const & startingState() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
const T & get() const
Definition: EventSetup.h:55
range recHits() const
TrackCharge charge() const
Charge (-1, 0 or 1)
edm::InputTag src_
Labels for input collections.
edm::ESHandle< TrackerGeometry > theGeometry
Muon selection.
GlobalVector globalMomentum() const
FakeTrackProducer< TrackCandidate > FakeTrackProducerFromCandidate
DetId geographicalId() const
Definition: DDAxes.h:10
long double T
T x() const
Definition: PV3DBase.h:62
virtual LocalPoint localPosition() const =0
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:79
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:76