1 |
#ifndef RecoAlgos_TrackSelector_h
|
2 |
#define RecoAlgos_TrackSelector_h
|
3 |
/** \class TrackSelector
|
4 |
*
|
5 |
* selects a subset of a track collection. Also clones
|
6 |
* TrackExtra part and RecHits collection
|
7 |
*
|
8 |
* \author Luca Lista, INFN
|
9 |
* Reorganized by Petar Maksimovic, JHU
|
10 |
* Reorganized again by Giovanni Petrucciani
|
11 |
* \version $Revision: 1.23 $
|
12 |
*
|
13 |
* $Id: TrackSelector.h,v 1.23 2008/06/06 18:01:40 gpetrucc Exp $
|
14 |
*
|
15 |
*/
|
16 |
#include "DataFormats/TrackReco/interface/Track.h"
|
17 |
#include "DataFormats/TrackReco/interface/TrackFwd.h"
|
18 |
#include "DataFormats/TrackReco/interface/TrackExtra.h"
|
19 |
#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
|
20 |
#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
|
21 |
#include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
|
22 |
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
|
23 |
#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
|
24 |
#include "DataFormats/Common/interface/DetSetVectorNew.h"
|
25 |
#include "PhysicsTools/UtilAlgos/interface/ObjectSelector.h"
|
26 |
|
27 |
|
28 |
#include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
|
29 |
// Apparently this is not anywhere defined
|
30 |
typedef edm::RefProd<SiStripClusterCollection> SiStripClusterRefProd;
|
31 |
|
32 |
namespace helper {
|
33 |
|
34 |
//------------------------------------------------------------------
|
35 |
//! \brief Class to manage copying of RecHits and Clusters from Tracks.
|
36 |
//------------------------------------------------------------------
|
37 |
struct TrackCollectionStoreManager {
|
38 |
public:
|
39 |
typedef reco::TrackCollection collection;
|
40 |
|
41 |
TrackCollectionStoreManager(const edm::Handle<reco::TrackCollection> & );
|
42 |
|
43 |
//------------------------------------------------------------------
|
44 |
//! Use these to turn off/on the cloning of clusters. The default
|
45 |
//! is to clone them. To not clone (and save space in a quick local
|
46 |
//! job, do:
|
47 |
//! setCloneClusters(false);
|
48 |
//------------------------------------------------------------------
|
49 |
inline bool cloneClusters() {return cloneClusters_ ; }
|
50 |
inline void setCloneClusters(bool w) { cloneClusters_ = w; }
|
51 |
|
52 |
//------------------------------------------------------------------
|
53 |
//! Put tracks, track extras and hits+clusters into the event.
|
54 |
//------------------------------------------------------------------
|
55 |
edm::OrphanHandle<reco::TrackCollection> put( edm::Event & evt );
|
56 |
|
57 |
//------------------------------------------------------------------
|
58 |
//! Get the size.
|
59 |
//------------------------------------------------------------------
|
60 |
inline size_t size() const { return selTracks_->size(); }
|
61 |
|
62 |
|
63 |
//------------------------------------------------------------------
|
64 |
//! \brief Method to clone tracks, track extras and their hits and clusters.
|
65 |
//! typename I = this is an interator over a track collection, **I needs
|
66 |
//! to dereference into a Track.
|
67 |
//------------------------------------------------------------------
|
68 |
template<typename I>
|
69 |
void cloneAndStore( const I & begin, const I & end, edm::Event & evt ) ;
|
70 |
|
71 |
private:
|
72 |
//--- A struct for clusters associated to hits
|
73 |
template<typename RecHitType, typename ClusterRefType = typename RecHitType::ClusterRef>
|
74 |
class ClusterHitRecord {
|
75 |
public:
|
76 |
/// Create a record for a hit with a given index in the TrackingRecHitCollection
|
77 |
ClusterHitRecord(const RecHitType &hit, size_t idx) :
|
78 |
detid_(hit.geographicalId().rawId()), index_(idx), ref_(hit.cluster()) {}
|
79 |
/// returns the detid
|
80 |
uint32_t detid() const { return detid_; }
|
81 |
/// this method is to be able to compare and see if two refs are the same
|
82 |
const ClusterRefType & clusterRef() const { return ref_; }
|
83 |
/// this one is to sort by detid and then by index of the rechit
|
84 |
bool operator<(const ClusterHitRecord<RecHitType,ClusterRefType> &other) const {
|
85 |
return (detid_ != other.detid_) ? detid_ < other.detid_ : ref_ < other.ref_;
|
86 |
}
|
87 |
/// correct the corresponding hit in the TrackingRecHitCollection with the new cluster ref
|
88 |
/// will not modify the ref stored in this object
|
89 |
void rekey(TrackingRecHitCollection &hits, const ClusterRefType &newRef) const ;
|
90 |
private:
|
91 |
uint32_t detid_;
|
92 |
size_t index_;
|
93 |
ClusterRefType ref_;
|
94 |
};
|
95 |
typedef ClusterHitRecord<SiPixelRecHit> PixelClusterHitRecord;
|
96 |
typedef ClusterHitRecord<SiStripRecHit2D> StripClusterHitRecord;
|
97 |
|
98 |
//--- Collections:
|
99 |
std::auto_ptr<reco::TrackCollection> selTracks_;
|
100 |
std::auto_ptr<reco::TrackExtraCollection> selTrackExtras_;
|
101 |
std::auto_ptr<TrackingRecHitCollection> selHits_;
|
102 |
std::auto_ptr< edmNew::DetSetVector<SiStripCluster> > selStripClusters_;
|
103 |
std::auto_ptr< edmNew::DetSetVector<SiPixelCluster> > selPixelClusters_;
|
104 |
//--- Information about the cloned clusters
|
105 |
std::vector<StripClusterHitRecord> stripClusterRecords_;
|
106 |
std::vector<PixelClusterHitRecord> pixelClusterRecords_;
|
107 |
//--- RefProd<>'s
|
108 |
reco::TrackRefProd rTracks_ ;
|
109 |
reco::TrackExtraRefProd rTrackExtras_ ;
|
110 |
TrackingRecHitRefProd rHits_ ;
|
111 |
edm::RefProd< edmNew::DetSetVector<SiStripCluster> > rStripClusters_ ;
|
112 |
edm::RefProd< edmNew::DetSetVector<SiPixelCluster> > rPixelClusters_ ;
|
113 |
|
114 |
//--- Indices into collections handled with RefProd
|
115 |
size_t idx_ ; //!< index to track extra coll
|
116 |
size_t hidx_ ; //!< index to tracking rec hits
|
117 |
|
118 |
//--- Switches
|
119 |
bool cloneClusters_ ; //!< Clone clusters, or not? Default: true.
|
120 |
|
121 |
//--- Methods
|
122 |
//------------------------------------------------------------------
|
123 |
//! Process a single track.
|
124 |
//------------------------------------------------------------------
|
125 |
void processTrack( const reco::Track & trk );
|
126 |
|
127 |
//------------------------------------------------------------------
|
128 |
//! Processes all the clusters of the tracks
|
129 |
//! (after the tracks have been dealt with)
|
130 |
//------------------------------------------------------------------
|
131 |
void processAllClusters() ;
|
132 |
|
133 |
//------------------------------------------------------------------
|
134 |
//! Processes all the clusters of a specific type
|
135 |
//! (after the tracks have been dealt with)
|
136 |
//------------------------------------------------------------------
|
137 |
template<typename HitType, typename ClusterType>
|
138 |
void processClusters( std::vector<ClusterHitRecord<HitType> > & clusterRecords,
|
139 |
edmNew::DetSetVector<ClusterType> & dsv,
|
140 |
edm::RefProd< edmNew::DetSetVector<ClusterType> > & refprod ) ;
|
141 |
|
142 |
|
143 |
};
|
144 |
// (end of struct TrackCollectionStoreManager)
|
145 |
|
146 |
|
147 |
template<typename I>
|
148 |
void
|
149 |
TrackCollectionStoreManager::cloneAndStore( const I & begin, const I & end, edm::Event & evt )
|
150 |
{
|
151 |
using namespace reco;
|
152 |
|
153 |
rTracks_ = evt.template getRefBeforePut<TrackCollection>();
|
154 |
rTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>();
|
155 |
rHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>();
|
156 |
//--- New: save clusters too
|
157 |
rStripClusters_
|
158 |
= evt.template getRefBeforePut< edmNew::DetSetVector<SiStripCluster> >();
|
159 |
|
160 |
rPixelClusters_
|
161 |
= evt.template getRefBeforePut< edmNew::DetSetVector<SiPixelCluster> >();
|
162 |
|
163 |
//--- Indices into collections handled with RefProd
|
164 |
idx_ = 0; //!< index to track extra coll
|
165 |
hidx_ = 0; //!< index to tracking rec hits
|
166 |
|
167 |
//--- Records about the clusters we want to clone
|
168 |
stripClusterRecords_.clear();
|
169 |
pixelClusterRecords_.clear();
|
170 |
|
171 |
//--- Loop over tracks
|
172 |
for( I i = begin; i != end; ++ i ) {
|
173 |
//--- Whatever type the iterator i is, deref to reco::Track &
|
174 |
const reco::Track & trk = * * i;
|
175 |
//--- Clone this track, and store references aside
|
176 |
processTrack( trk );
|
177 |
}
|
178 |
//--- Clone the clusters and fixup refs
|
179 |
processAllClusters();
|
180 |
}
|
181 |
|
182 |
|
183 |
//----------------------------------------------------------------------
|
184 |
class TrackSelectorBase : public edm::EDFilter {
|
185 |
public:
|
186 |
TrackSelectorBase( const edm::ParameterSet & cfg ) {
|
187 |
std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
|
188 |
produces<reco::TrackCollection>().setBranchAlias( alias + "Tracks" );
|
189 |
produces<reco::TrackExtraCollection>().setBranchAlias( alias + "TrackExtras" );
|
190 |
produces<TrackingRecHitCollection>().setBranchAlias( alias + "RecHits" );
|
191 |
//--- New: save clusters too
|
192 |
// FIXME: For the following two, need to check what names
|
193 |
// FIXME: of the output collections are needed downstream.
|
194 |
produces< edmNew::DetSetVector<SiPixelCluster> >().setBranchAlias( alias + "PixelClusters" );
|
195 |
produces< edmNew::DetSetVector<SiStripCluster> >().setBranchAlias( alias + "StripClusters" );
|
196 |
}
|
197 |
}; // (end of class TrackSelectorBase)
|
198 |
|
199 |
|
200 |
template<>
|
201 |
struct StoreManagerTrait<reco::TrackCollection> {
|
202 |
typedef TrackCollectionStoreManager type;
|
203 |
typedef TrackSelectorBase base;
|
204 |
};
|
205 |
|
206 |
}
|
207 |
|
208 |
#endif
|