ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/RecoAlgos/interface/MuonSelector.h
Revision: 1.1.1.1 (vendor branch)
Committed: Tue Oct 20 17:15:14 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/plain
Branch: ANA
CVS Tags: start
Changes since 1.1: +0 -0 lines
Log Message:
version CMSSW_2_2_10

File Contents

# Content
1 #ifndef RecoAlgos_MuonSelector_h
2 #define RecoAlgos_MuonSelector_h
3 /** \class MuonSelector
4 *
5 * selects a subset of a muon collection and clones
6 * Track, TrackExtra parts and RecHits collection
7 * for SA, GB and Tracker Only options
8 *
9 * \author Javier Fernandez, Uniovi
10 *
11 * \version $Revision: 1.11 $
12 *
13 * $Id: MuonSelector.h,v 1.11 2008/09/16 22:54:18 jfernan2 Exp $
14 *
15 */
16 #include "DataFormats/MuonReco/interface/Muon.h"
17 #include "DataFormats/MuonReco/interface/MuonFwd.h"
18 #include "DataFormats/TrackReco/interface/Track.h"
19 #include "DataFormats/TrackReco/interface/TrackExtra.h"
20 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
21 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
22 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
23 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
24 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
25 #include "DataFormats/Common/interface/DetSetVectorNew.h"
26 #include "PhysicsTools/UtilAlgos/interface/ObjectSelector.h"
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 struct MuonCollectionStoreManager {
34 public:
35 typedef reco::MuonCollection collection;
36
37 MuonCollectionStoreManager(const edm::Handle<reco::MuonCollection>&) ;
38
39 //------------------------------------------------------------------
40 //! Use these to turn off/on the cloning of clusters. The default
41 //! is to clone them. To not clone (and save space in a quick local
42 //! job, do:
43 //! setCloneClusters(false);
44 //------------------------------------------------------------------
45 inline bool cloneClusters() {return cloneClusters_ ; }
46 inline void setCloneClusters(bool w) { cloneClusters_ = w; }
47
48 //------------------------------------------------------------------
49 //! Put tracks, track extras and hits+clusters into the event.
50 //------------------------------------------------------------------
51 edm::OrphanHandle<reco::MuonCollection> put( edm::Event & evt );
52
53 //------------------------------------------------------------------
54 //! Get the size.
55 //------------------------------------------------------------------
56 inline size_t size() const { return selMuons_->size(); }
57
58
59 //------------------------------------------------------------------
60 //! \brief Method to clone tracks, track extras and their hits and clusters.
61 //! typename I = this is an interator over a Muon collection, **I needs
62 //! to dereference into a Muon.
63 //------------------------------------------------------------------
64
65 template<typename I>
66 void cloneAndStore( const I & begin, const I & end, edm::Event & evt ) ;
67
68 private:
69 //--- A struct for clusters associated to hits
70 template<typename RecHitType, typename ClusterRefType = typename RecHitType::ClusterRef>
71 class ClusterHitRecord {
72 public:
73 /// Create a record for a hit with a given index in the TrackingRecHitCollection
74 ClusterHitRecord(const RecHitType &hit, edm::OwnVector<TrackingRecHit> * hitVector, size_t idx) :
75 detid_(hit.geographicalId().rawId()), hitVector_(hitVector), index_(idx), ref_(hit.cluster()) {}
76 /// returns the detid
77 uint32_t detid() const { return detid_; }
78 /// this method is to be able to compare and see if two refs are the same
79 const ClusterRefType & clusterRef() const { return ref_; }
80 /// this one is to sort by detid and then by index of the rechit
81 bool operator<(const ClusterHitRecord<RecHitType,ClusterRefType> &other) const {
82 return (detid_ != other.detid_) ? detid_ < other.detid_ : ref_ < other.ref_;
83 }
84 /// correct the corresponding hit in the TrackingRecHitCollection with the new cluster ref
85 /// will not modify the ref stored in this object
86 void rekey(const ClusterRefType &newRef) const ;
87 private:
88 uint32_t detid_;
89 edm::OwnVector<TrackingRecHit> * hitVector_;
90 size_t index_;
91 ClusterRefType ref_;
92 };
93
94 typedef ClusterHitRecord<SiPixelRecHit> PixelClusterHitRecord;
95 typedef ClusterHitRecord<SiStripRecHit2D> StripClusterHitRecord;
96
97 //--- Collections:
98 std::auto_ptr<reco::MuonCollection> selMuons_;
99 std::auto_ptr<reco::TrackCollection> selTracks_;
100 std::auto_ptr<reco::TrackExtraCollection> selTracksExtras_;
101 std::auto_ptr<TrackingRecHitCollection> selTracksHits_;
102 std::auto_ptr<reco::TrackCollection> selGlobalMuonTracks_;
103 std::auto_ptr<reco::TrackExtraCollection> selGlobalMuonTracksExtras_;
104 std::auto_ptr<TrackingRecHitCollection> selGlobalMuonTracksHits_;
105 std::auto_ptr<reco::TrackCollection> selStandAloneTracks_;
106 std::auto_ptr<reco::TrackExtraCollection> selStandAloneTracksExtras_;
107 std::auto_ptr<TrackingRecHitCollection> selStandAloneTracksHits_;
108
109 std::auto_ptr< edmNew::DetSetVector<SiStripCluster> > selStripClusters_;
110 std::auto_ptr< edmNew::DetSetVector<SiPixelCluster> > selPixelClusters_;
111 //--- Information about the cloned clusters
112 std::vector<StripClusterHitRecord> stripClusterRecords_;
113 std::vector<PixelClusterHitRecord> pixelClusterRecords_;
114
115 reco::MuonRefProd rMuons_;
116
117 reco::TrackRefProd rTracks_;
118 reco::TrackExtraRefProd rTrackExtras_;
119 TrackingRecHitRefProd rHits_;
120
121 // New: clusters
122 edm::RefProd< edmNew::DetSetVector<SiStripCluster> > rStripClusters_ ;
123 edm::RefProd< edmNew::DetSetVector<SiPixelCluster> > rPixelClusters_ ;
124
125 reco::TrackRefProd rGBTracks_;
126 reco::TrackExtraRefProd rGBTrackExtras_;
127 TrackingRecHitRefProd rGBHits_;
128
129 reco::TrackRefProd rSATracks_;
130 reco::TrackExtraRefProd rSATrackExtras_;
131 TrackingRecHitRefProd rSAHits_;
132
133 //--- Indices into collections handled with RefProd
134 size_t id_, igbd_, isad_, idx_, igbdx_, isadx_, hidx_, higbdx_, hisadx_;
135
136 //--- Switches
137 bool cloneClusters_ ; //!< Clone clusters, or not? Default: true.
138
139 //--- Methods
140 //------------------------------------------------------------------
141 //! Process a single muon.
142 //------------------------------------------------------------------
143 void processMuon( const reco::Muon & mu );
144
145 //------------------------------------------------------------------
146 //! Process a single hit.
147 //------------------------------------------------------------------
148 void processHit( const TrackingRecHit * hit, edm::OwnVector<TrackingRecHit> &hits );
149
150
151 //------------------------------------------------------------------
152 //! Processes all the clusters of the tracks
153 //! (after the tracks have been dealt with)
154 //------------------------------------------------------------------
155 void processAllClusters() ;
156
157 //------------------------------------------------------------------
158 //! Processes all the clusters of a specific type
159 //! (after the tracks have been dealt with)
160 //------------------------------------------------------------------
161 template<typename HitType, typename ClusterType>
162 void processClusters( std::vector<ClusterHitRecord<HitType> > & clusterRecords,
163 edmNew::DetSetVector<ClusterType> & dsv,
164 edm::RefProd< edmNew::DetSetVector<ClusterType> > & refprod ) ;
165
166 bool clusterRefsOK(const reco::Track &track) const;
167 };
168 // (end of struct MuonCollectionStoreManager)
169
170 template<typename I>
171 void
172 MuonCollectionStoreManager::cloneAndStore( const I & begin, const I & end, edm::Event & evt )
173 {
174 using namespace reco;
175 rHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("TrackerOnly");
176 rGBHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("GlobalMuon");
177 rSAHits_ = evt.template getRefBeforePut<TrackingRecHitCollection>("StandAlone");
178 rTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("TrackerOnly");
179 rGBTrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("GlobalMuon");
180 rSATrackExtras_ = evt.template getRefBeforePut<TrackExtraCollection>("StandAlone");
181 rTracks_ = evt.template getRefBeforePut<TrackCollection>("TrackerOnly");
182 rGBTracks_ = evt.template getRefBeforePut<TrackCollection>("GlobalMuon");
183 rSATracks_ = evt.template getRefBeforePut<TrackCollection>("StandAlone");
184
185 rMuons_ = evt.template getRefBeforePut<MuonCollection>("SelectedMuons");
186
187 //--- New: save clusters too
188 rStripClusters_
189 = evt.template getRefBeforePut< edmNew::DetSetVector<SiStripCluster> >();
190
191 rPixelClusters_
192 = evt.template getRefBeforePut< edmNew::DetSetVector<SiPixelCluster> >();
193
194 id_=0; igbd_=0; isad_=0;
195 idx_ = 0; igbdx_=0; isadx_=0;
196 hidx_=0; higbdx_=0; hisadx_=0;
197
198 //--- Records about the clusters we want to clone
199 stripClusterRecords_.clear();
200 pixelClusterRecords_.clear();
201
202 for( I i = begin; i != end; ++ i ) {
203 const Muon & mu = * * i;
204 //--- Clone this track, and store references aside
205 processMuon( mu );
206 }
207 //--- Clone the clusters and fixup refs
208 processAllClusters();
209 }
210
211 //----------------------------------------------------------------------
212 class MuonSelectorBase : public edm::EDFilter {
213 public:
214 MuonSelectorBase( const edm::ParameterSet & cfg ) {
215 std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
216
217
218 produces<reco::MuonCollection>("SelectedMuons").setBranchAlias( alias + "SelectedMuons" );
219 produces<reco::TrackCollection>("TrackerOnly").setBranchAlias( alias + "TrackerOnlyTracks" );
220 produces<reco::TrackExtraCollection>("TrackerOnly").setBranchAlias( alias + "TrackerOnlyExtras" );
221 produces<TrackingRecHitCollection>("TrackerOnly").setBranchAlias( alias + "TrackerOnlyHits" );
222 //--- New: save clusters too
223 // FIXME: For the following two, need to check what names
224 // FIXME: of the output collections are needed downstream.
225 produces< edmNew::DetSetVector<SiPixelCluster> >().setBranchAlias( alias + "PixelClusters" );
226 produces< edmNew::DetSetVector<SiStripCluster> >().setBranchAlias( alias + "StripClusters" );
227 produces<reco::TrackCollection>("GlobalMuon").setBranchAlias( alias + "GlobalMuonTracks" );
228 produces<reco::TrackExtraCollection>("GlobalMuon").setBranchAlias( alias + "GlobalMuonExtras" );
229 produces<TrackingRecHitCollection>("GlobalMuon").setBranchAlias( alias + "GlobalMuonHits" );
230 produces<reco::TrackCollection>("StandAlone").setBranchAlias( alias + "StandAloneTracks" );
231 produces<reco::TrackExtraCollection>("StandAlone").setBranchAlias( alias + "StandAloneExtras" );
232 produces<TrackingRecHitCollection>("StandAlone").setBranchAlias( alias + "StandAloneHits" );
233
234 }
235 }; // (end of class MuonSelectorBase)
236
237
238 template<>
239 struct StoreManagerTrait<reco::MuonCollection> {
240 typedef MuonCollectionStoreManager type;
241 typedef MuonSelectorBase base;
242 };
243
244 }
245
246 #endif