CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonSelector.cc
Go to the documentation of this file.
2 
8 
10 
12 
13 using namespace reco;
14 
15 namespace helper
16 {
17  MuonCollectionStoreManager::
18  MuonCollectionStoreManager(const edm::Handle<reco::MuonCollection>&)
19  :
20  selMuons_( new reco::MuonCollection ),
21  selTracks_( new reco::TrackCollection ),
22  selTracksExtras_( new reco::TrackExtraCollection ),
23  selTracksHits_( new TrackingRecHitCollection ),
24  selGlobalMuonTracks_( new reco::TrackCollection ),
25  selGlobalMuonTracksExtras_( new reco::TrackExtraCollection ),
26  selGlobalMuonTracksHits_( new TrackingRecHitCollection ),
27  selStandAloneTracks_( new reco::TrackCollection ),
28  selStandAloneTracksExtras_( new reco::TrackExtraCollection ),
29  selStandAloneTracksHits_( new TrackingRecHitCollection ),
30  selStripClusters_( new edmNew::DetSetVector<SiStripCluster> ),
31  selPixelClusters_( new edmNew::DetSetVector<SiPixelCluster> ),
32  rMuons_(),
33  rTracks_(), rTrackExtras_(), rHits_(),
34  rGBTracks_(), rGBTrackExtras_(), rGBHits_(),
35  rSATracks_(), rSATrackExtras_(), rSAHits_(),
36  clusterStorer_(),
37  id_(0), igbd_(0), isad_(0), idx_(0), igbdx_(0),
38  isadx_(0), hidx_(0), higbdx_(0), hisadx_(0),
39  cloneClusters_ (true)
40  {
41  }
42 
43 
44  //------------------------------------------------------------------
46  //------------------------------------------------------------------
47  void
49  processMuon( const Muon & mu )
50  {
51  if (this->cloneClusters()
52  && ( (mu.globalTrack().isNonnull() && !this->clusterRefsOK(*mu.globalTrack()))
53  || (mu.innerTrack() .isNonnull() && !this->clusterRefsOK(*mu.innerTrack() ))
54  // || (mu.outerTrack(). isNonnull() && !this->clusterRefsOK(*mu.outerTrack() ))
55  )) { // outer track is muon only and has no strip clusters...
56  // At least until CMSSW_2_1_8, global muon track reconstruction assigns wrong hits in
57  // case of a track from iterative tracking. These hits are fetched from Trajectories
58  // instead of from Tracks and therefore reference temporary cluster collections.
59  // As a hack we skip these muons here - they can anyway not be refitted.
60  edm::LogError("BadRef") << "@SUB=MuonCollectionStoreManager::processMuon"
61  << "Skip muon: One of its tracks references "
62  << "non-available clusters!";
63  return;
64  }
65 
66  selMuons_->push_back( Muon( mu ) );
67  // only tracker Muon Track
68  selMuons_->back().setInnerTrack( TrackRef( rTracks_, id_ ++ ) );
69  TrackRef trkRef = mu.track();
70  if(trkRef.isNonnull()){
71 
72  selTracks_->push_back(Track( *trkRef) );
73 
74  Track & trk= selTracks_->back();
75 
76  selTracksExtras_->push_back( TrackExtra( trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
77  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
78  trk.outerStateCovariance(), trk.outerDetId(),
79  trk.innerStateCovariance(), trk.innerDetId(),
80  trk.seedDirection() ) );
81 
82  TrackExtra & tx = selTracksExtras_->back();
83 
84  auto const firstHitIndex = hidx_;
85  unsigned int nHitsAdded = 0;
86  for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd();
87  ++ hit, ++ hidx_) {
88  selTracksHits_->push_back( (*hit)->clone() );
89  TrackingRecHit * newHit = & (selTracksHits_->back());
90  ++nHitsAdded;
91  if (cloneClusters() && newHit->isValid()
92  && ((*hit)->geographicalId().det() == DetId::Tracker)) {
94  }
95  } // end of for loop over tracking rec hits on this track
96  tx.setHits( rHits_, firstHitIndex, nHitsAdded );
97 
99 
100  }// TO trkRef.isNonnull
101 
102 
103  // global Muon Track
104  selMuons_->back().setGlobalTrack( TrackRef( rGBTracks_, igbd_ ++ ) );
105  trkRef = mu.combinedMuon();
106  if(trkRef.isNonnull()){
107  selGlobalMuonTracks_->push_back(Track( *trkRef) );
108  Track & trk = selGlobalMuonTracks_->back();
109 
111  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
112  trk.outerStateCovariance(), trk.outerDetId(),
113  trk.innerStateCovariance(), trk.innerDetId(), trk.seedDirection() ) );
114  TrackExtra & tx = selGlobalMuonTracksExtras_->back();
115  auto const firstHitIndex = higbdx_;
116  unsigned int nHitsAdded = 0;
117  for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd();
118  ++ hit, ++ higbdx_) {
119  selGlobalMuonTracksHits_->push_back( (*hit)->clone() );
120  TrackingRecHit * newHit = & (selGlobalMuonTracksHits_->back());
121  ++nHitsAdded;
122  if (cloneClusters() && newHit->isValid()
123  && ((*hit)->geographicalId().det() == DetId::Tracker)) {
125  }
126 
127  }
128  tx.setHits( rGBHits_, firstHitIndex, nHitsAdded );
129 
131 
132  } // GB trkRef.isNonnull()
133 
134  // stand alone Muon Track
135  selMuons_->back().setOuterTrack( TrackRef( rSATracks_, isad_ ++ ) );
136  trkRef = mu.standAloneMuon();
137  if(trkRef.isNonnull()){
138  selStandAloneTracks_->push_back(Track( *trkRef) );
139  Track & trk = selStandAloneTracks_->back();
140 
142  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
143  trk.outerStateCovariance(), trk.outerDetId(),
144  trk.innerStateCovariance(), trk.innerDetId(), trk.seedDirection() ) );
145  TrackExtra & tx = selStandAloneTracksExtras_->back();
146  auto const firstHitIndex = hisadx_;
147  unsigned int nHitsAdded = 0;
148  for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit ) {
149  selStandAloneTracksHits_->push_back( (*hit)->clone() );
150  ++nHitsAdded;
151  hisadx_ ++;
152  }
153  tx.setHits( rSAHits_, firstHitIndex, nHitsAdded );
155 
156  } // SA trkRef.isNonnull()
157  }// end of track, and function
158 
159  //-------------------------------------------------------------------------
161  //-------------------------------------------------------------------------
162  bool
164  clusterRefsOK(const reco::Track &track) const
165  {
166 
167  for (trackingRecHit_iterator hitIt = track.recHitsBegin(); hitIt != track.recHitsEnd(); ++hitIt) {
168  const TrackingRecHit &hit = **hitIt;
169  if (!hit.isValid() || hit.geographicalId().det() != DetId::Tracker) continue;
170 
171  // So we are in the tracker - now check hit types and availability of cluster refs:
172  const std::type_info &hit_type = typeid(hit);
173  if (hit_type == typeid(SiPixelRecHit)) {
174  if (!static_cast<const SiPixelRecHit &>(hit).cluster().isAvailable()) return false;
175  } else if (hit_type == typeid(SiStripRecHit2D)) {
176  if (!static_cast<const SiStripRecHit2D &>(hit).cluster().isAvailable()) return false;
177  } else if (hit_type == typeid(SiStripRecHit1D)) {
178  if (!static_cast<const SiStripRecHit1D &>(hit).cluster().isAvailable()) return false;
179  } else if (hit_type == typeid(SiStripMatchedRecHit2D)) {
180  const SiStripMatchedRecHit2D &mHit = static_cast<const SiStripMatchedRecHit2D &>(hit);
181  if (!mHit.monoHit().cluster().isAvailable()) return false;
182  if (!mHit.stereoHit().cluster().isAvailable()) return false;
183  } else if (hit_type == typeid(ProjectedSiStripRecHit2D)) {
184  const ProjectedSiStripRecHit2D &pHit = static_cast<const ProjectedSiStripRecHit2D &>(hit);
185  if (!pHit.originalHit().cluster().isAvailable()) return false;
186  } else {
187  // std::cout << "| It is a " << hit_type.name() << " hit !?" << std::endl;
188  // Do nothing. We might end up here for FastSim hits.
189  } // end 'switch' on hit type
190  }
191 
192  // No tracker hit with bad cluster found, so all fine:
193  return true;
194  }
195 
196  //------------------------------------------------------------------
198  //------------------------------------------------------------------
201  put( edm::Event & evt ) {
203  h = evt.put( selMuons_ , "SelectedMuons");
204  evt.put( selTracks_ , "TrackerOnly");
205  evt.put( selTracksExtras_ , "TrackerOnly");
206  evt.put( selTracksHits_ ,"TrackerOnly");
207  evt.put( selGlobalMuonTracks_,"GlobalMuon" );
208  evt.put( selGlobalMuonTracksExtras_ ,"GlobalMuon");
209  evt.put( selGlobalMuonTracksHits_,"GlobalMuon" );
210  evt.put( selStandAloneTracks_ ,"StandAlone");
211  evt.put( selStandAloneTracksExtras_ ,"StandAlone");
212  evt.put( selStandAloneTracksHits_ ,"StandAlone");
213  if (cloneClusters()) {
214  evt.put( selStripClusters_ );
215  evt.put( selPixelClusters_ );
216  }
217  return h;
218 
219  }
220 
221 
222 } // end of namespace helper
bool isAvailable() const
Definition: Ref.h:576
reco::TrackExtraRefProd rSATrackExtras_
Definition: MuonSelector.h:87
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
std::auto_ptr< edmNew::DetSetVector< SiPixelCluster > > selPixelClusters_
Definition: MuonSelector.h:75
virtual TrackRef innerTrack() const
Definition: Muon.h:48
std::auto_ptr< reco::TrackCollection > selTracks_
Definition: MuonSelector.h:65
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:49
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:50
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:17
void addCluster(TrackingRecHitCollection &hits, size_t index)
add cluster of newHit to list (throws if hit is of unknown type)
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
std::auto_ptr< reco::TrackCollection > selStandAloneTracks_
Definition: MuonSelector.h:71
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
reco::TrackExtraRefProd rTrackExtras_
Definition: MuonSelector.h:79
edm::OrphanHandle< reco::MuonCollection > put(edm::Event &evt)
Put tracks, track extras and hits+clusters into the event.
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
std::auto_ptr< TrackingRecHitCollection > selGlobalMuonTracksHits_
Definition: MuonSelector.h:70
TrackingRecHitRefProd rSAHits_
Definition: MuonSelector.h:88
std::auto_ptr< reco::TrackExtraCollection > selStandAloneTracksExtras_
Definition: MuonSelector.h:72
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:75
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
void processMuon(const reco::Muon &mu)
Process a single muon.
Definition: MuonSelector.cc:49
ClusterRef cluster() const
std::auto_ptr< reco::TrackExtraCollection > selGlobalMuonTracksExtras_
Definition: MuonSelector.h:69
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::auto_ptr< edmNew::DetSetVector< SiStripCluster > > selStripClusters_
Definition: MuonSelector.h:74
TrackingRecHitRefProd rHits_
Definition: MuonSelector.h:80
const int mu
Definition: Constants.h:22
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
SiStripRecHit2D originalHit() const
TrackingRecHitRefProd rGBHits_
Definition: MuonSelector.h:84
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:184
virtual TrackRef combinedMuon() const
reference to a stand-alone muon Track
Definition: Muon.h:55
SiStripRecHit2D stereoHit() const
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:70
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:45
reco::TrackExtraRefProd rGBTrackExtras_
Definition: MuonSelector.h:83
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:80
bool isValid() const
std::auto_ptr< TrackingRecHitCollection > selTracksHits_
Definition: MuonSelector.h:67
SiStripRecHit2D monoHit() const
Pixel cluster – collection of neighboring pixels above threshold.
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
std::auto_ptr< reco::MuonCollection > selMuons_
Definition: MuonSelector.h:64
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:204
DetId geographicalId() const
std::auto_ptr< reco::TrackExtraCollection > selTracksExtras_
Definition: MuonSelector.h:66
std::auto_ptr< reco::TrackCollection > selGlobalMuonTracks_
Definition: MuonSelector.h:68
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99
bool clusterRefsOK(const reco::Track &track) const
Check if all references to silicon strip/pixel clusters are available.
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
std::auto_ptr< TrackingRecHitCollection > selStandAloneTracksHits_
Definition: MuonSelector.h:73
Our base class.
Definition: SiPixelRecHit.h:23
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109
virtual TrackRef standAloneMuon() const
reference to a stand-alone muon Track
Definition: Muon.h:52