CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L3MuonTrajectoryBuilder.cc
Go to the documentation of this file.
1 
25 
26 
27 //---------------
28 // C++ Headers --
29 //---------------
30 
31 #include <iostream>
32 #include <iomanip>
33 #include <algorithm>
34 
35 //-------------------------------
36 // Collaborating Class Headers --
37 //-------------------------------
38 
41 
43 
46 
50 
52 
55 
58 
62 
63 using namespace std;
64 using namespace edm;
65 
66 //----------------
67 // Constructors --
68 //----------------
69 
72  edm::ConsumesCollector& iC) : GlobalTrajectoryBuilderBase(par, service, iC) {
73 
75 
76  theTkCollName = par.getParameter<edm::InputTag>("tkTrajLabel");
77  theBeamSpotInputTag = par.getParameter<edm::InputTag>("tkTrajBeamSpot");
78  theMaxChi2 = par.getParameter<double>("tkTrajMaxChi2");
79  theDXYBeamSpot = par.getParameter<double>("tkTrajMaxDXYBeamSpot");
80  theUseVertex = par.getParameter<bool>("tkTrajUseVertex");
81  theVertexCollInputTag = par.getParameter<edm::InputTag>("tkTrajVertex");
83 }
84 
85 
86 //--------------
87 // Destructor --
88 //--------------
89 
92 }
93 
94 //
95 // get information from event
96 //
98 
99  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|setEvent";
100 
102 
103  // get tracker TrackCollection from Event
104  event.getByToken(trackToken_,allTrackerTracks);
105  LogDebug(category)
106  << "Found " << allTrackerTracks->size()
107  << " tracker Tracks with label "<< theTkCollName;
108 
109  if( theUseVertex ) {
110  // PV
112  if ( pvHandle.isValid() ) {
113  vtx = pvHandle->front();
114  }
115  else {
116  edm::LogInfo(category)
117  << "No Primary Vertex available from EventSetup \n";
118  }
119  }
120  else {
121  // BS
122  event.getByLabel(theBeamSpotInputTag, beamSpotHandle);
123  if( beamSpotHandle.isValid() ) {
125  }
126  else {
127  edm::LogInfo(category)
128  << "No beam spot available from EventSetup \n";
129  }
130  }
131 }
132 
133 //
134 // reconstruct trajectories
135 //
137 
138  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|trajectories";
139 
140  // cut on muons with low momenta
141  if ( (staCandIn).second->pt() < thePtCut || (staCandIn).second->innerMomentum().Rho() < thePtCut || (staCandIn).second->innerMomentum().R() < 2.5 ) return CandidateContainer();
142 
143  // convert the STA track into a Trajectory if Trajectory not already present
144  TrackCand staCand(staCandIn);
145 
146  vector<TrackCand> trackerTracks;
147 
148  vector<TrackCand> regionalTkTracks = makeTkCandCollection(staCand);
149  LogDebug(category) << "Found " << regionalTkTracks.size() << " tracks within region of interest";
150 
151  // match tracker tracks to muon track
152  trackerTracks = trackMatcher()->match(staCand, regionalTkTracks);
153 
154  LogDebug(category) << "Found " << trackerTracks.size() << " matching tracker tracks within region of interest";
155  if ( trackerTracks.empty() ) return CandidateContainer();
156 
157  // build a combined tracker-muon MuonCandidate
158  //
159  // turn tkMatchedTracks into MuonCandidates
160  //
161  LogDebug(category) << "turn tkMatchedTracks into MuonCandidates";
162  CandidateContainer tkTrajs;
163  for (vector<TrackCand>::const_iterator tkt = trackerTracks.begin(); tkt != trackerTracks.end(); tkt++) {
164  if ((*tkt).first != 0 && (*tkt).first->isValid()) {
165  //
166  MuonCandidate* muonCand = new MuonCandidate( 0 ,staCand.second,(*tkt).second, new Trajectory(*(*tkt).first));
167  tkTrajs.push_back(muonCand);
168  // LogTrace(category) << "tpush";
169  //
170  } else {
171  MuonCandidate* muonCand = new MuonCandidate( 0 ,staCand.second,(*tkt).second, 0);
172  tkTrajs.push_back(muonCand);
173  }
174  }
175 
176  if ( tkTrajs.empty() ) {
177  LogDebug(category) << "tkTrajs empty";
178  return CandidateContainer();
179  }
180 
181  CandidateContainer result = build(staCand, tkTrajs);
182  LogDebug(category) << "Found "<< result.size() << " L3Muons from one L2Cand";
183 
184  // free memory
185  if ( staCandIn.first == 0) delete staCand.first;
186 
187  for( CandidateContainer::const_iterator it = tkTrajs.begin(); it != tkTrajs.end(); ++it) {
188  if ( (*it)->trajectory() ) delete (*it)->trajectory();
189  if ( (*it)->trackerTrajectory() ) delete (*it)->trackerTrajectory();
190  if ( *it ) delete (*it);
191  }
192  tkTrajs.clear();
193 
194  for ( vector<TrackCand>::const_iterator is = regionalTkTracks.begin(); is != regionalTkTracks.end(); ++is) {
195  delete (*is).first;
196  }
197 
198  return result;
199 
200 }
201 
202 //
203 // make a TrackCand collection using tracker Track, Trajectory information
204 //
205 vector<L3MuonTrajectoryBuilder::TrackCand> L3MuonTrajectoryBuilder::makeTkCandCollection(const TrackCand& staCand) {
206 
207  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|makeTkCandCollection";
208 
209  vector<TrackCand> tkCandColl;
210 
211  vector<TrackCand> tkTrackCands;
212 
213  for ( unsigned int position = 0; position != allTrackerTracks->size(); ++position ) {
215  TrackCand tkCand = TrackCand((Trajectory*)(0),tkTrackRef);
216  tkCandColl.push_back(tkCand);
217  }
218 
219  for(vector<TrackCand>::const_iterator tk = tkCandColl.begin(); tk != tkCandColl.end() ; ++tk) {
220  edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef = (*tk).second->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >() ;
221  reco::TrackRef staTrack = l3seedRef->l2Track();
222  if( staTrack == (staCand.second) ) {
223  // apply a filter (dxy, chi2 cut)
224  double tk_vtx;
225  if( theUseVertex ) tk_vtx = (*tk).second->dxy(vtx.position());
226  else tk_vtx = (*tk).second->dxy(beamSpot.position());
227 
228  if( fabs(tk_vtx) > theDXYBeamSpot || (*tk).second->normalizedChi2() > theMaxChi2 ) continue;
229 
230  tkTrackCands.push_back(*tk);
231  }
232  }
233 
234  return tkTrackCands;
235 
236 }
237 
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
MuonCandidate::CandidateContainer CandidateContainer
GlobalMuonTrackMatcher * trackMatcher() const
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
std::pair< const Trajectory *, reco::TrackRef > TrackCand
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
const Point & position() const
position
Definition: Vertex.h:106
virtual void setEvent(const edm::Event &)
pass the Event to the algo at each event
U second(std::pair< T, U > const &p)
edm::EDGetTokenT< reco::TrackCollection > trackToken_
edm::Handle< reco::TrackCollection > allTrackerTracks
edm::Handle< reco::VertexCollection > pvHandle
tuple result
Definition: query.py:137
std::vector< TrackCand > makeTkCandCollection(const TrackCand &)
make a TrackCand collection using tracker Track, Trajectory information
std::vector< MuonCandidate * > CandidateContainer
Definition: MuonCandidate.h:20
double match(const TrackCand &sta, const TrackCand &track, int matchOption=0, int surfaceOption=1) const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
MuonTrajectoryBuilder::CandidateContainer trajectories(const TrackCand &)
return a container reconstructed muons starting from a given track
MuonTrajectoryBuilder::CandidateContainer build(const TrackCand &, MuonTrajectoryBuilder::CandidateContainer &) const
build combined trajectory from sta Track and tracker RecHits
TrajectoryCleaner * theTrajectoryCleaner
edm::Handle< reco::BeamSpot > beamSpotHandle
static int position[264][3]
Definition: ReadPGInfo.cc:509
const Point & position() const
position
Definition: BeamSpot.h:62
L3MuonTrajectoryBuilder(const edm::ParameterSet &, const MuonServiceProxy *, edm::ConsumesCollector &)
constructor with Parameter Set and MuonServiceProxy