CMS 3D CMS Logo

TrackFullCloneSelectorBase.h
Go to the documentation of this file.
1 #ifndef RecoAlgos_TrackFullCloneSelectorBase_h
2 #define RecoAlgos_TrackFullCloneSelectorBase_h
3 
15 #include <utility>
16 #include <vector>
17 #include <memory>
18 #include <algorithm>
19 #include <map>
25 
31 
32 namespace reco {
33  namespace modules {
34 
35  template <typename Selector>
37  public:
40  : hSrcTrackToken_(consumes<reco::TrackCollection>(cfg.template getParameter<edm::InputTag>("src"))),
41  hTrajToken_(mayConsume<std::vector<Trajectory> >(cfg.template getParameter<edm::InputTag>("src"))),
42  hTTAssToken_(mayConsume<TrajTrackAssociationCollection>(cfg.template getParameter<edm::InputTag>("src"))),
43  copyExtras_(cfg.template getUntrackedParameter<bool>("copyExtras", false)),
44  copyTrajectories_(cfg.template getUntrackedParameter<bool>("copyTrajectories", false)),
45  selector_(cfg, consumesCollector()) {
46  std::string alias(cfg.getParameter<std::string>("@module_label"));
47  produces<reco::TrackCollection>().setBranchAlias(alias + "Tracks");
48  if (copyExtras_) {
49  produces<reco::TrackExtraCollection>().setBranchAlias(alias + "TrackExtras");
50  produces<TrackingRecHitCollection>().setBranchAlias(alias + "RecHits");
51  if (copyTrajectories_) {
52  produces<std::vector<Trajectory> >().setBranchAlias(alias + "Trajectories");
53  produces<TrajTrackAssociationCollection>().setBranchAlias(alias + "TrajectoryTrackAssociations");
54  }
55  }
56  }
59 
60  private:
62  void produce(edm::Event& evt, const edm::EventSetup& es) override {
64  evt.getByToken(hSrcTrackToken_, hSrcTrack);
65 
66  selTracks_ = std::unique_ptr<reco::TrackCollection>(new reco::TrackCollection());
67  if (copyExtras_) {
68  selTrackExtras_ = std::unique_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection());
69  selHits_ = std::unique_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection());
70  }
71 
72  TrackRefProd rTracks = evt.template getRefBeforePut<TrackCollection>();
73 
75  TrackExtraRefProd rTrackExtras;
76  if (copyExtras_) {
77  rHits = evt.template getRefBeforePut<TrackingRecHitCollection>();
78  rTrackExtras = evt.template getRefBeforePut<TrackExtraCollection>();
79  }
80 
81  typedef reco::TrackRef::key_type TrackRefKey;
82  std::map<TrackRefKey, reco::TrackRef> goodTracks;
83  TrackRefKey current = 0;
84 
85  selector_.init(evt, es);
86  auto tkBegin = hSrcTrack->begin();
87  for (reco::TrackCollection::const_iterator it = tkBegin, ed = hSrcTrack->end(); it != ed; ++it, ++current) {
88  const reco::Track& trk = *it;
89  const reco::TrackRef tkref(hSrcTrack, std::distance(tkBegin, it));
90  if (!selector_(tkref))
91  continue;
92 
93  selTracks_->push_back(Track(trk)); // clone and store
94  if (!copyExtras_)
95  continue;
96 
97  // TrackExtras
98  selTrackExtras_->push_back(TrackExtra(trk.outerPosition(),
99  trk.outerMomentum(),
100  trk.outerOk(),
101  trk.innerPosition(),
102  trk.innerMomentum(),
103  trk.innerOk(),
104  trk.outerStateCovariance(),
105  trk.outerDetId(),
106  trk.innerStateCovariance(),
107  trk.innerDetId(),
108  trk.seedDirection()));
109  selTracks_->back().setExtra(TrackExtraRef(rTrackExtras, selTrackExtras_->size() - 1));
110  TrackExtra& tx = selTrackExtras_->back();
111  // TrackingRecHits
112  auto const firstHitIndex = selHits_->size();
113  for (auto const& hit : trk.recHits())
114  selHits_->push_back(hit->clone());
115  tx.setHits(rHits, firstHitIndex, selHits_->size() - firstHitIndex);
116  tx.setTrajParams(trk.extra()->trajParams(), trk.extra()->chi2sX5());
117  assert(tx.trajParams().size() == tx.recHitsSize());
118  if (copyTrajectories_) {
119  goodTracks[current] = reco::TrackRef(rTracks, selTracks_->size() - 1);
120  }
121  }
122  if (copyTrajectories_) {
125  evt.getByToken(hTTAssToken_, hTTAss);
126  evt.getByToken(hTrajToken_, hTraj);
127  edm::RefProd<std::vector<Trajectory> > TrajRefProd = evt.template getRefBeforePut<std::vector<Trajectory> >();
128  selTrajs_ = std::unique_ptr<std::vector<Trajectory> >(new std::vector<Trajectory>());
129  selTTAss_ = std::unique_ptr<TrajTrackAssociationCollection>(new TrajTrackAssociationCollection());
130  for (size_t i = 0, n = hTraj->size(); i < n; ++i) {
131  edm::Ref<std::vector<Trajectory> > trajRef(hTraj, i);
133  if (match != hTTAss->end()) {
134  const edm::Ref<reco::TrackCollection>& trkRef = match->val;
135  TrackRefKey oldKey = trkRef.key();
136  std::map<TrackRefKey, reco::TrackRef>::iterator getref = goodTracks.find(oldKey);
137  if (getref != goodTracks.end()) {
138  // do the clone
139  selTrajs_->push_back(Trajectory(*trajRef));
140  selTTAss_->insert(edm::Ref<std::vector<Trajectory> >(TrajRefProd, selTrajs_->size() - 1),
141  getref->second);
142  }
143  }
144  }
145  }
146 
147  evt.put(std::move(selTracks_));
148  if (copyExtras_) {
150  evt.put(std::move(selHits_));
151  if (copyTrajectories_) {
152  evt.put(std::move(selTrajs_));
153  evt.put(std::move(selTTAss_));
154  }
155  }
156  }
167  // some space
168  std::unique_ptr<reco::TrackCollection> selTracks_;
169  std::unique_ptr<reco::TrackExtraCollection> selTrackExtras_;
170  std::unique_ptr<TrackingRecHitCollection> selHits_;
171  std::unique_ptr<std::vector<Trajectory> > selTrajs_;
172  std::unique_ptr<TrajTrackAssociationCollection> selTTAss_;
173  };
174 
175  } // namespace modules
176 } // namespace reco
177 #endif
reco::Track::outerPosition
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:62
reco::Track::outerMomentum
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:65
edm::RefProd< TrackCollection >
TrackExtra.h
reco::modules::TrackFullCloneSelectorBase::hSrcTrackToken_
edm::EDGetTokenT< reco::TrackCollection > hSrcTrackToken_
source collection label
Definition: TrackFullCloneSelectorBase.h:158
reco::Track::outerStateCovariance
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:68
Selector
Functor that operates on <T>
Definition: Selector.h:22
reco::Track::outerDetId
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:79
electrons_cff.bool
bool
Definition: electrons_cff.py:393
edm::AssociationMap::find
const_iterator find(const key_type &k) const
find element with specified reference key
Definition: AssociationMap.h:173
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
reco::modules::TrackFullCloneSelectorBase::copyTrajectories_
bool copyTrajectories_
copy also trajectories and trajectory->track associations
Definition: TrackFullCloneSelectorBase.h:164
modules
Definition: ZHLTMatchFilter.cc:17
reco::modules::TrackFullCloneSelectorBase::selector_
Selector selector_
filter event
Definition: TrackFullCloneSelectorBase.h:166
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
cms::cuda::assert
assert(be >=bs)
EDProducer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
reco::Track::outerOk
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:50
edm::Handle< reco::TrackCollection >
reco::Track::extra
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:139
edm::Ref< TrackCollection >
reco::Track::innerStateCovariance
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:71
reco::Track::innerOk
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:53
reco::TrackExtra
Definition: TrackExtra.h:26
edm::AssociationMap::end
const_iterator end() const
last iterator over the map (read only)
Definition: AssociationMap.h:171
reco::Track::innerMomentum
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
reco::modules::TrackFullCloneSelectorBase::hTTAssToken_
edm::EDGetTokenT< TrajTrackAssociationCollection > hTTAssToken_
Definition: TrackFullCloneSelectorBase.h:160
Track.h
TrackFwd.h
reco::Track
Definition: Track.h:27
reco::TrackExtraCollection
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
reco::Track::recHits
auto recHits() const
Access to reconstructed hits on the track.
Definition: Track.h:85
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
reco::modules::TrackFullCloneSelectorBase::TrackFullCloneSelectorBase
TrackFullCloneSelectorBase(const edm::ParameterSet &cfg)
constructor
Definition: TrackFullCloneSelectorBase.h:39
TrajTrackAssociation.h
reco::modules::TrackFullCloneSelectorBase::hTrajToken_
edm::EDGetTokenT< std::vector< Trajectory > > hTrajToken_
Definition: TrackFullCloneSelectorBase.h:159
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::TrackExtraBase::setTrajParams
void setTrajParams(TrajParams tmps, Chi2sFive chi2s)
Definition: TrackExtraBase.h:36
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > >::const_iterator
friend struct const_iterator
Definition: AssociationMap.h:274
reco::modules::TrackFullCloneSelectorBase
Definition: TrackFullCloneSelectorBase.h:36
reco::Track::seedDirection
const PropagationDirection & seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:148
edm::ParameterSet
Definition: ParameterSet.h:47
reco::modules::TrackFullCloneSelectorBase::selHits_
std::unique_ptr< TrackingRecHitCollection > selHits_
Definition: TrackFullCloneSelectorBase.h:170
Event.h
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > >
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
reco::TrackExtraRef
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:16
reco::Track::innerPosition
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:56
reco::TrackExtraBase::trajParams
TrajParams const & trajParams() const
Definition: TrackExtraBase.h:76
reco::modules::TrackFullCloneSelectorBase::copyExtras_
bool copyExtras_
copy only the tracks, not extras and rechits (for AOD)
Definition: TrackFullCloneSelectorBase.h:162
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
reco::Track::innerDetId
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:82
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
reco::modules::TrackFullCloneSelectorBase::selTrajs_
std::unique_ptr< std::vector< Trajectory > > selTrajs_
Definition: TrackFullCloneSelectorBase.h:171
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::Ref< TrackCollection >::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
InputTag.h
reco::TrackExtraBase::setHits
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
Definition: TrackExtraBase.h:30
looper.cfg
cfg
Definition: looper.py:297
reco::TrackExtraBase::recHitsSize
unsigned int recHitsSize() const
number of RecHits
Definition: TrackExtraBase.h:44
Trajectory.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Trajectory
Definition: Trajectory.h:38
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:128
reco::modules::TrackFullCloneSelectorBase::selTTAss_
std::unique_ptr< TrajTrackAssociationCollection > selTTAss_
Definition: TrackFullCloneSelectorBase.h:172
TrackingRecHitCollection
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
Definition: TrackingRecHitFwd.h:10
TrajTrackAssociationCollection
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
Definition: TrajTrackAssociation.h:9
goodTracks_cfi.goodTracks
goodTracks
Definition: goodTracks_cfi.py:3
reco::modules::TrackFullCloneSelectorBase::selTracks_
std::unique_ptr< reco::TrackCollection > selTracks_
Definition: TrackFullCloneSelectorBase.h:168
reco::modules::TrackFullCloneSelectorBase::selTrackExtras_
std::unique_ptr< reco::TrackExtraCollection > selTrackExtras_
Definition: TrackFullCloneSelectorBase.h:169
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
ConsumesCollector.h
ParameterSet.h
reco::modules::TrackFullCloneSelectorBase::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
process one event
Definition: TrackFullCloneSelectorBase.h:62
reco::modules::TrackFullCloneSelectorBase::~TrackFullCloneSelectorBase
~TrackFullCloneSelectorBase() override
destructor
Definition: TrackFullCloneSelectorBase.h:58
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
hit
Definition: SiStripHitEffFromCalibTree.cc:88