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 
37 
38 
39 
40 template<class T>
42  public:
43  explicit FakeTrackProducer(const edm::ParameterSet & iConfig);
44  virtual ~FakeTrackProducer() { }
45 
46  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
47  private:
50 
52  //StringCutObjectSelector<T> selector_;
53 
54  const PTrajectoryStateOnDet & getState(const TrajectorySeed &seed) const { return seed.startingState(); }
55  const PTrajectoryStateOnDet & getState(const TrackCandidate &seed) const { return seed.trajectoryStateOnDet(); }
56  TrajectorySeed::range getHits (const TrajectorySeed &seed) const { return seed.recHits(); }
57  TrajectorySeed::range getHits (const TrackCandidate &seed) const { return seed.recHits(); }
58 };
59 
60 
61 template<typename T>
63  src_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("src")))
64  //,selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true)
65 {
66  produces<std::vector<reco::Track> >();
67  produces<std::vector<reco::TrackExtra> >();
68  produces<edm::OwnVector<TrackingRecHit> >();
69 }
70 
71 template<typename T>
72 void
74  using namespace edm;
75  using namespace std;
76 
77 
79  iSetup.get<TrackerDigiGeometryRecord>().get(theGeometry);
80  edm::ESHandle<MagneticField> theMagField;
81  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
83  iSetup.get<TrackerTopologyRcd>().get(httopo);
84  const TrackerTopology& ttopo = *httopo;
85 
87  iEvent.getByToken(src_, src);
88 
89  unique_ptr<vector<reco::Track> > out(new vector<reco::Track>());
90  out->reserve(src->size());
91  unique_ptr<vector<reco::TrackExtra> > outEx(new vector<reco::TrackExtra>());
92  outEx->reserve(src->size());
93  unique_ptr<OwnVector<TrackingRecHit> > outHits(new OwnVector<TrackingRecHit>());
94 
97  for (typename vector<T>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
98  const T &mu = *it;
99  //if (!selector_(mu)) continue;
100  const PTrajectoryStateOnDet & pstate = getState(mu);
101  const GeomDet *det = theGeometry->idToDet(DetId(pstate.detId()));
102  if (det == 0) { std::cerr << "ERROR: bogus detid " << pstate.detId() << std::endl; continue; }
103  TrajectoryStateOnSurface state = trajectoryStateTransform::transientState(pstate, & det->surface(), &*theMagField);
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  TrajectorySeed::range hits = getHits(mu);
111  out->back().appendHits(hits.first, hits.second, ttopo);
112  // Now Track Extra
113  const TrackingRecHit *hit0 = &*hits.first;
114  const TrackingRecHit *hit1 = &*(hits.second-1);
115  const GeomDet *det0 = theGeometry->idToDet(hit0->geographicalId());
116  const GeomDet *det1 = theGeometry->idToDet(hit1->geographicalId());
117  if (det0 == 0 || det1 == 0) { std::cerr << "ERROR: bogus detids at beginning or end of range" << std::endl; continue; }
118  GlobalPoint gx0 = det0->toGlobal(hit0->localPosition());
119  GlobalPoint gx1 = det1->toGlobal(hit1->localPosition());
120  reco::Track::Point x0(gx0.x(), gx0.y(), gx0.z());
121  reco::Track::Point x1(gx1.x(), gx1.y(), gx1.z());
122  if (x0.R() > x1.R()) std::swap(x0,x1);
123  outEx->push_back( reco::TrackExtra(x1, p, true, x0, p, true,
126  alongMomentum) );
127  out->back().setExtra( reco::TrackExtraRef( rTrackExtras, outEx->size()-1 ) );
128  reco::TrackExtra &ex = outEx->back();
129  auto const firstHitIndex = outHits->size();
130  for (OwnVector<TrackingRecHit>::const_iterator it2 = hits.first; it2 != hits.second; ++it2) {
131  outHits->push_back(*it2);
132  }
133  ex.setHits( rHits, firstHitIndex, outHits->size()-firstHitIndex);
134  }
135 
136  iEvent.put(std::move(out));
137  iEvent.put(std::move(outEx));
138  iEvent.put(std::move(outHits));
139 }
140 
const LocalTrajectoryParameters & localParameters() const
range recHits() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
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:54
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:42
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
T x() const
Cartesian x coordinate.
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< std::vector< T > > src_
Labels for input collections.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const PTrajectoryStateOnDet & getState(const TrajectorySeed &seed) const
Muon selection.
TrajectorySeed::range getHits(const TrajectorySeed &seed) const
T z() const
Definition: PV3DBase.h:64
def move
Definition: eostools.py:510
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:83
RefProd< PROD > getRefBeforePut()
Definition: Event.h:141
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:56
range recHits() const
TrackCharge charge() const
Charge (-1, 0 or 1)
GlobalVector globalMomentum() const
FakeTrackProducer< TrackCandidate > FakeTrackProducerFromCandidate
DetId geographicalId() const
long double T
T x() const
Definition: PV3DBase.h:62
virtual LocalPoint localPosition() const =0
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:80
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77