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 <memory>
16 
22 #include <algorithm>
23 #include <map>
24 #include <memory>
25 #include <utility>
26 #include <vector>
27 
33 
34 namespace reco {
35  namespace modules {
36 
37  template <typename Selector>
39  public:
42  : hSrcTrackToken_(consumes<reco::TrackCollection>(cfg.template getParameter<edm::InputTag>("src"))),
43  hTrajToken_(mayConsume<std::vector<Trajectory> >(cfg.template getParameter<edm::InputTag>("src"))),
44  hTTAssToken_(mayConsume<TrajTrackAssociationCollection>(cfg.template getParameter<edm::InputTag>("src"))),
45  copyExtras_(cfg.template getUntrackedParameter<bool>("copyExtras", false)),
46  copyTrajectories_(cfg.template getUntrackedParameter<bool>("copyTrajectories", false)),
47  selector_(cfg, consumesCollector()) {
48  std::string alias(cfg.getParameter<std::string>("@module_label"));
49  produces<reco::TrackCollection>().setBranchAlias(alias + "Tracks");
50  if (copyExtras_) {
51  produces<reco::TrackExtraCollection>().setBranchAlias(alias + "TrackExtras");
52  produces<TrackingRecHitCollection>().setBranchAlias(alias + "RecHits");
53  if (copyTrajectories_) {
54  produces<std::vector<Trajectory> >().setBranchAlias(alias + "Trajectories");
55  produces<TrajTrackAssociationCollection>().setBranchAlias(alias + "TrajectoryTrackAssociations");
56  }
57  }
58  }
61 
62  private:
64  void produce(edm::Event& evt, const edm::EventSetup& es) override {
66  evt.getByToken(hSrcTrackToken_, hSrcTrack);
67 
68  selTracks_ = std::make_unique<reco::TrackCollection>();
69  if (copyExtras_) {
70  selTrackExtras_ = std::make_unique<reco::TrackExtraCollection>();
71  selHits_ = std::make_unique<TrackingRecHitCollection>();
72  }
73 
74  TrackRefProd rTracks = evt.template getRefBeforePut<TrackCollection>();
75 
77  TrackExtraRefProd rTrackExtras;
78  if (copyExtras_) {
79  rHits = evt.template getRefBeforePut<TrackingRecHitCollection>();
80  rTrackExtras = evt.template getRefBeforePut<TrackExtraCollection>();
81  }
82 
83  typedef reco::TrackRef::key_type TrackRefKey;
84  std::map<TrackRefKey, reco::TrackRef> goodTracks;
85  TrackRefKey current = 0;
86 
87  selector_.init(evt, es);
88  auto tkBegin = hSrcTrack->begin();
89  for (reco::TrackCollection::const_iterator it = tkBegin, ed = hSrcTrack->end(); it != ed; ++it, ++current) {
90  const reco::Track& trk = *it;
91  const reco::TrackRef tkref(hSrcTrack, std::distance(tkBegin, it));
92  if (!selector_(tkref))
93  continue;
94 
95  selTracks_->push_back(Track(trk)); // clone and store
96  if (!copyExtras_)
97  continue;
98 
99  // TrackExtras
100  selTrackExtras_->push_back(TrackExtra(trk.outerPosition(),
101  trk.outerMomentum(),
102  trk.outerOk(),
103  trk.innerPosition(),
104  trk.innerMomentum(),
105  trk.innerOk(),
106  trk.outerStateCovariance(),
107  trk.outerDetId(),
108  trk.innerStateCovariance(),
109  trk.innerDetId(),
110  trk.seedDirection()));
111  selTracks_->back().setExtra(TrackExtraRef(rTrackExtras, selTrackExtras_->size() - 1));
112  TrackExtra& tx = selTrackExtras_->back();
113  // TrackingRecHits
114  auto const firstHitIndex = selHits_->size();
115  for (auto const& hit : trk.recHits())
116  selHits_->push_back(hit->clone());
117  tx.setHits(rHits, firstHitIndex, selHits_->size() - firstHitIndex);
118  tx.setTrajParams(trk.extra()->trajParams(), trk.extra()->chi2sX5());
119  assert(tx.trajParams().size() == tx.recHitsSize());
120  if (copyTrajectories_) {
121  goodTracks[current] = reco::TrackRef(rTracks, selTracks_->size() - 1);
122  }
123  }
124  if (copyTrajectories_) {
127  evt.getByToken(hTTAssToken_, hTTAss);
128  evt.getByToken(hTrajToken_, hTraj);
129  edm::RefProd<std::vector<Trajectory> > TrajRefProd = evt.template getRefBeforePut<std::vector<Trajectory> >();
130  selTrajs_ = std::make_unique<std::vector<Trajectory> >();
131  selTTAss_ = std::make_unique<TrajTrackAssociationCollection>();
132  for (size_t i = 0, n = hTraj->size(); i < n; ++i) {
133  edm::Ref<std::vector<Trajectory> > trajRef(hTraj, i);
135  if (match != hTTAss->end()) {
136  const edm::Ref<reco::TrackCollection>& trkRef = match->val;
137  TrackRefKey oldKey = trkRef.key();
138  std::map<TrackRefKey, reco::TrackRef>::iterator getref = goodTracks.find(oldKey);
139  if (getref != goodTracks.end()) {
140  // do the clone
141  selTrajs_->push_back(Trajectory(*trajRef));
142  selTTAss_->insert(edm::Ref<std::vector<Trajectory> >(TrajRefProd, selTrajs_->size() - 1),
143  getref->second);
144  }
145  }
146  }
147  }
148 
149  evt.put(std::move(selTracks_));
150  if (copyExtras_) {
152  evt.put(std::move(selHits_));
153  if (copyTrajectories_) {
154  evt.put(std::move(selTrajs_));
155  evt.put(std::move(selTTAss_));
156  }
157  }
158  }
169  // some space
170  std::unique_ptr<reco::TrackCollection> selTracks_;
171  std::unique_ptr<reco::TrackExtraCollection> selTrackExtras_;
172  std::unique_ptr<TrackingRecHitCollection> selHits_;
173  std::unique_ptr<std::vector<Trajectory> > selTrajs_;
174  std::unique_ptr<TrajTrackAssociationCollection> selTTAss_;
175  };
176 
177  } // namespace modules
178 } // namespace reco
179 #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:160
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:366
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:166
modules
Definition: MuonCleanerBySegments.cc:35
reco::modules::TrackFullCloneSelectorBase::selector_
Selector selector_
filter event
Definition: TrackFullCloneSelectorBase.h:168
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
cms::cuda::assert
assert(be >=bs)
EDProducer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
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:162
Track.h
TrackFwd.h
reco::Track
Definition: Track.h:27
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:539
reco::modules::TrackFullCloneSelectorBase::TrackFullCloneSelectorBase
TrackFullCloneSelectorBase(const edm::ParameterSet &cfg)
constructor
Definition: TrackFullCloneSelectorBase.h:41
TrajTrackAssociation.h
reco::modules::TrackFullCloneSelectorBase::hTrajToken_
edm::EDGetTokenT< std::vector< Trajectory > > hTrajToken_
Definition: TrackFullCloneSelectorBase.h:161
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
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:38
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:172
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:164
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:173
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:296
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:174
goodTracks_cfi.goodTracks
goodTracks
Definition: goodTracks_cfi.py:3
reco::modules::TrackFullCloneSelectorBase::selTracks_
std::unique_ptr< reco::TrackCollection > selTracks_
Definition: TrackFullCloneSelectorBase.h:170
reco::modules::TrackFullCloneSelectorBase::selTrackExtras_
std::unique_ptr< reco::TrackExtraCollection > selTrackExtras_
Definition: TrackFullCloneSelectorBase.h:171
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:64
reco::modules::TrackFullCloneSelectorBase::~TrackFullCloneSelectorBase
~TrackFullCloneSelectorBase() override
destructor
Definition: TrackFullCloneSelectorBase.h:60
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7746
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
hit
Definition: SiStripHitEffFromCalibTree.cc:88