CMS 3D CMS Logo

L3MuonTrajectoryBuilder.cc
Go to the documentation of this file.
1 
24 
27 
29 
32 
36 
38 
41 
44 
49 
50 //----------------
51 // Constructors --
52 //----------------
57  theTrajectoryCleaner = std::make_unique<TrajectoryCleanerBySharedHits>();
58  theTkCollName = par.getParameter<edm::InputTag>("tkTrajLabel");
59  theBeamSpotInputTag = par.getParameter<edm::InputTag>("tkTrajBeamSpot");
60  theMaxChi2 = par.getParameter<double>("tkTrajMaxChi2");
61  theDXYBeamSpot = par.getParameter<double>("tkTrajMaxDXYBeamSpot");
62  theUseVertex = par.getParameter<bool>("tkTrajUseVertex");
63  theVertexCollInputTag = par.getParameter<edm::InputTag>("tkTrajVertex");
65 }
66 
67 //--------------
68 // Destructor --
69 //--------------
71 
75  desc.add("MuonTrackingRegionBuilder", descTRB);
76 }
77 
78 //
79 // Get information from event
80 //
82  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|setEvent";
83 
85 
86  // get tracker TrackCollection from Event
87  event.getByToken(theTrackToken, allTrackerTracks);
88  LogDebug(category) << "Found " << allTrackerTracks->size() << " tracker Tracks with label " << theTkCollName;
89 
90  if (theUseVertex) {
91  // PV
93  if (pvHandle.isValid()) {
94  vtx = pvHandle->front();
95  } else {
96  edm::LogInfo(category) << "No Primary Vertex available from EventSetup \n";
97  }
98  } else {
99  // BS
100  event.getByLabel(theBeamSpotInputTag, beamSpotHandle);
101  if (beamSpotHandle.isValid()) {
103  } else {
104  edm::LogInfo(category) << "No beam spot available from EventSetup \n";
105  }
106  }
107 }
108 
109 //
110 // reconstruct trajectories
111 //
113  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|trajectories";
114 
115  // cut on muons with low momenta
116  if ((staCandIn).second->pt() < thePtCut || (staCandIn).second->innerMomentum().Rho() < thePtCut ||
117  (staCandIn).second->innerMomentum().R() < 2.5)
118  return CandidateContainer();
119 
120  // convert the STA track into a Trajectory if Trajectory not already present
121  TrackCand staCand(staCandIn);
122 
123  std::vector<TrackCand> regionalTkTracks = makeTkCandCollection(staCand);
124  LogDebug(category) << "Found " << regionalTkTracks.size() << " tracks within region of interest";
125 
126  // match tracker tracks to muon track
127  std::vector<TrackCand> trackerTracks = trackMatcher()->match(staCand, regionalTkTracks);
128 
129  LogDebug(category) << "Found " << trackerTracks.size() << " matching tracker tracks within region of interest";
130  if (trackerTracks.empty())
131  return CandidateContainer();
132 
133  // build a combined tracker-muon MuonCandidate
134  // turn tkMatchedTracks into MuonCandidates
135  LogDebug(category) << "turn tkMatchedTracks into MuonCandidates";
136  CandidateContainer tkTrajs;
137  tkTrajs.reserve(trackerTracks.size());
138  for (std::vector<TrackCand>::const_iterator tkt = trackerTracks.begin(); tkt != trackerTracks.end(); tkt++) {
139  if ((*tkt).first != nullptr && (*tkt).first->isValid()) {
140  tkTrajs.emplace_back(std::make_unique<MuonCandidate>(
141  nullptr, staCand.second, (*tkt).second, std::make_unique<Trajectory>(*(*tkt).first)));
142  } else {
143  tkTrajs.emplace_back(std::make_unique<MuonCandidate>(nullptr, staCand.second, (*tkt).second, nullptr));
144  }
145  }
146 
147  if (tkTrajs.empty()) {
148  LogDebug(category) << "tkTrajs empty";
149  return CandidateContainer();
150  }
151 
152  CandidateContainer result = build(staCand, tkTrajs);
153  LogDebug(category) << "Found " << result.size() << " L3Muons from one L2Cand";
154 
155  // free memory
156  if (staCandIn.first == nullptr)
157  delete staCand.first;
158 
159  for (std::vector<TrackCand>::const_iterator is = regionalTkTracks.begin(); is != regionalTkTracks.end(); ++is) {
160  delete (*is).first;
161  }
162 
163  return result;
164 }
165 
166 //
167 // make a TrackCand collection using tracker Track, Trajectory information
168 //
169 std::vector<L3MuonTrajectoryBuilder::TrackCand> L3MuonTrajectoryBuilder::makeTkCandCollection(const TrackCand& staCand) {
170  const std::string category = "Muon|RecoMuon|L3MuonTrajectoryBuilder|makeTkCandCollection";
171  std::vector<TrackCand> tkCandColl;
172  std::vector<TrackCand> tkTrackCands;
173 
174  // for (auto&& tkTrack: allTrackerTracks){
175  // auto tkCand = TrackCand((Trajectory*)(0),tkTrack);
176  for (unsigned int position = 0; position != allTrackerTracks->size(); ++position) {
178  TrackCand tkCand = TrackCand((Trajectory*)nullptr, tkTrackRef);
179  tkCandColl.push_back(tkCand);
180  }
181 
182  //Loop over TrackCand collection made from allTrackerTracks in previous step
183  for (auto&& tkCand : tkCandColl) {
184  auto& tk = tkCand.second;
185  bool canUseL3MTS = false;
186  // check the seedRef is non-null first; and then
187  if (tk->seedRef().isNonnull()) {
188  auto a = dynamic_cast<const L3MuonTrajectorySeed*>(tk->seedRef().get());
189  canUseL3MTS = a != nullptr;
190  }
191  if (canUseL3MTS) {
193  tk->seedRef().castTo<edm::Ref<L3MuonTrajectorySeedCollection> >();
194  // May still need provenance here, so using trackref:
195  reco::TrackRef staTrack = l3seedRef->l2Track();
196  if (staTrack == (staCand.second)) {
197  // Apply filters (dxy, chi2 cut)
198  double tk_vtx;
199  if (theUseVertex)
200  tk_vtx = tk->dxy(vtx.position());
201  else
202  tk_vtx = tk->dxy(beamSpot.position());
203  if (fabs(tk_vtx) > theDXYBeamSpot || tk->normalizedChi2() > theMaxChi2)
204  continue;
205  tkTrackCands.push_back(tkCand);
206  }
207  } else {
208  // We will try to match all tracker tracks with the muon:
209  double tk_vtx;
210  if (theUseVertex)
211  tk_vtx = tk->dxy(vtx.position());
212  else
213  tk_vtx = tk->dxy(beamSpot.position());
214  if (fabs(tk_vtx) > theDXYBeamSpot || tk->normalizedChi2() > theMaxChi2)
215  continue;
216  tkTrackCands.push_back(tkCand);
217  }
218  }
219 
220  return tkTrackCands;
221 }
MuonTrajectoryBuilder::CandidateContainer build(const TrackCand &, MuonTrajectoryBuilder::CandidateContainer &) const
build combined trajectory from sta Track and tracker RecHits
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
MuonCandidate::CandidateContainer CandidateContainer
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
MuonTrajectoryBuilder::CandidateContainer trajectories(const TrackCand &) override
return a container reconstructed muons starting from a given track
std::pair< const Trajectory *, reco::TrackRef > TrackCand
const Point & position() const
position
Definition: BeamSpot.h:59
const Point & position() const
position
Definition: Vertex.h:127
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Add default values for fillDescriptions.
U second(std::pair< T, U > const &p)
edm::Handle< reco::TrackCollection > allTrackerTracks
edm::Handle< reco::VertexCollection > pvHandle
void setEvent(const edm::Event &) override
Pass the Event to the algo at each event.
void setEvent(const edm::Event &) override
pass the Event to the algo at each event
double match(const TrackCand &sta, const TrackCand &track, int matchOption=0, int surfaceOption=1) const
Log< level::Info, false > LogInfo
std::vector< std::unique_ptr< MuonCandidate > > CandidateContainer
Definition: MuonCandidate.h:18
edm::EDGetTokenT< reco::TrackCollection > theTrackToken
~L3MuonTrajectoryBuilder() override
Destructor.
bool isValid() const
Definition: HandleBase.h:70
edm::Handle< reco::BeamSpot > beamSpotHandle
double a
Definition: hdecay.h:121
static int position[264][3]
Definition: ReadPGInfo.cc:289
std::unique_ptr< TrajectoryCleaner > theTrajectoryCleaner
std::vector< TrackCand > makeTkCandCollection(const TrackCand &) override
Make a TrackCand collection using tracker Track, Trajectory information.
L3MuonTrajectoryBuilder(const edm::ParameterSet &, const MuonServiceProxy *, edm::ConsumesCollector &)
Constructor with Parameter Set and MuonServiceProxy.
static void fillDescriptionsHLT(edm::ParameterSetDescription &descriptions)
GlobalMuonTrackMatcher * trackMatcher() const
Definition: event.py:1
#define LogDebug(id)