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 
60 
64 
65 using namespace std;
66 using namespace edm;
67 
68 //----------------
69 // Constructors --
70 //----------------
71 
73  const MuonServiceProxy* service,
75 
77 
78  theTkCollName = par.getParameter<edm::InputTag>("tkTrajLabel");
79  theBeamSpotInputTag = par.getParameter<edm::InputTag>("tkTrajBeamSpot");
80  theMaxChi2 = par.getParameter<double>("tkTrajMaxChi2");
81  theDXYBeamSpot = par.getParameter<double>("tkTrajMaxDXYBeamSpot");
82  theUseVertex = par.getParameter<bool>("tkTrajUseVertex");
83  theVertexCollInputTag = par.getParameter<edm::InputTag>("tkTrajVertex");
85 }
86 
87 
88 //--------------
89 // Destructor --
90 //--------------
91 
94 }
95 
96 //
97 // get information from event
98 //
100 
101  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|setEvent";
102 
104 
105  // get tracker TrackCollection from Event
106  event.getByToken(trackToken_,allTrackerTracks);
107  LogDebug(category)
108  << "Found " << allTrackerTracks->size()
109  << " tracker Tracks with label "<< theTkCollName;
110 
111  if( theUseVertex ) {
112  // PV
114  if ( pvHandle.isValid() ) {
115  vtx = pvHandle->front();
116  }
117  else {
118  edm::LogInfo(category)
119  << "No Primary Vertex available from EventSetup \n";
120  }
121  }
122  else {
123  // BS
124  event.getByLabel(theBeamSpotInputTag, beamSpotHandle);
125  if( beamSpotHandle.isValid() ) {
127  }
128  else {
129  edm::LogInfo(category)
130  << "No beam spot available from EventSetup \n";
131  }
132  }
133 }
134 
135 //
136 // reconstruct trajectories
137 //
139 
140  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|trajectories";
141 
142  // cut on muons with low momenta
143  if ( (staCandIn).second->pt() < thePtCut || (staCandIn).second->innerMomentum().Rho() < thePtCut || (staCandIn).second->innerMomentum().R() < 2.5 ) return CandidateContainer();
144 
145  // convert the STA track into a Trajectory if Trajectory not already present
146  TrackCand staCand(staCandIn);
147 
148  vector<TrackCand> trackerTracks;
149 
150  vector<TrackCand> regionalTkTracks = makeTkCandCollection(staCand);
151  LogDebug(category) << "Found " << regionalTkTracks.size() << " tracks within region of interest";
152 
153  // match tracker tracks to muon track
154  trackerTracks = trackMatcher()->match(staCand, regionalTkTracks);
155 
156  LogDebug(category) << "Found " << trackerTracks.size() << " matching tracker tracks within region of interest";
157  if ( trackerTracks.empty() ) return CandidateContainer();
158 
159  // build a combined tracker-muon MuonCandidate
160  //
161  // turn tkMatchedTracks into MuonCandidates
162  //
163  LogDebug(category) << "turn tkMatchedTracks into MuonCandidates";
164  CandidateContainer tkTrajs;
165  for (vector<TrackCand>::const_iterator tkt = trackerTracks.begin(); tkt != trackerTracks.end(); tkt++) {
166  if ((*tkt).first != 0 && (*tkt).first->isValid()) {
167  //
168  MuonCandidate* muonCand = new MuonCandidate( 0 ,staCand.second,(*tkt).second, new Trajectory(*(*tkt).first));
169  tkTrajs.push_back(muonCand);
170  // LogTrace(category) << "tpush";
171  //
172  } else {
173  MuonCandidate* muonCand = new MuonCandidate( 0 ,staCand.second,(*tkt).second, 0);
174  tkTrajs.push_back(muonCand);
175  }
176  }
177 
178  if ( tkTrajs.empty() ) {
179  LogDebug(category) << "tkTrajs empty";
180  return CandidateContainer();
181  }
182 
183  CandidateContainer result = build(staCand, tkTrajs);
184  LogDebug(category) << "Found "<< result.size() << " L3Muons from one L2Cand";
185 
186  // free memory
187  if ( staCandIn.first == 0) delete staCand.first;
188 
189  for( CandidateContainer::const_iterator it = tkTrajs.begin(); it != tkTrajs.end(); ++it) {
190  if ( (*it)->trajectory() ) delete (*it)->trajectory();
191  if ( (*it)->trackerTrajectory() ) delete (*it)->trackerTrajectory();
192  if ( *it ) delete (*it);
193  }
194  tkTrajs.clear();
195 
196  for ( vector<TrackCand>::const_iterator is = regionalTkTracks.begin(); is != regionalTkTracks.end(); ++is) {
197  delete (*is).first;
198  }
199 
200  return result;
201 
202 }
203 
204 //
205 // make a TrackCand collection using tracker Track, Trajectory information
206 //
207 vector<L3MuonTrajectoryBuilder::TrackCand> L3MuonTrajectoryBuilder::makeTkCandCollection(const TrackCand& staCand) {
208 
209  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|makeTkCandCollection";
210 
211  vector<TrackCand> tkCandColl;
212 
213  vector<TrackCand> tkTrackCands;
214 
215  for ( unsigned int position = 0; position != allTrackerTracks->size(); ++position ) {
217  TrackCand tkCand = TrackCand((Trajectory*)(0),tkTrackRef);
218  tkCandColl.push_back(tkCand);
219  }
220 
221  for(vector<TrackCand>::const_iterator tk = tkCandColl.begin(); tk != tkCandColl.end() ; ++tk) {
222  edm::Ref<L3MuonTrajectorySeedCollection> l3seedRef = (*tk).second->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >() ;
223  reco::TrackRef staTrack = l3seedRef->l2Track();
224  if( staTrack == (staCand.second) ) {
225  // apply a filter (dxy, chi2 cut)
226  double tk_vtx;
227  if( theUseVertex ) tk_vtx = (*tk).second->dxy(vtx.position());
228  else tk_vtx = (*tk).second->dxy(beamSpot.position());
229 
230  if( fabs(tk_vtx) > theDXYBeamSpot || (*tk).second->normalizedChi2() > theMaxChi2 ) continue;
231 
232  tkTrackCands.push_back(*tk);
233  }
234  }
235 
236  return tkTrackCands;
237 
238 }
239 
#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:10
const Point & position() const
position
Definition: Vertex.h:92
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
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 &)
reconstruct trajectories from standalone and tracker only Tracks
MuonTrajectoryBuilder::CandidateContainer build(const TrackCand &, MuonTrajectoryBuilder::CandidateContainer &) const
build combined trajectory from sta Track and tracker RecHits
TrajectoryCleaner * theTrajectoryCleaner
edm::Handle< reco::BeamSpot > beamSpotHandle
const Point & position() const
position
Definition: BeamSpot.h:62
L3MuonTrajectoryBuilder(const edm::ParameterSet &, const MuonServiceProxy *, edm::ConsumesCollector &)
constructor with Parameter Set and MuonServiceProxy