CMS 3D CMS Logo

L1TkMuonProducer.cc
Go to the documentation of this file.
1 // input: L1TkTracks and RegionalMuonCand (standalone with component details)
2 // match the two and produce a collection of TkMuon
3 // eventually, this should be made modular and allow to swap out different algorithms
4 
5 // user include files
13 
25 
26 // system include files
27 #include <memory>
28 #include <string>
29 
30 static constexpr float mu_mass = 0.105658369;
31 static constexpr int barrel_MTF_region = 1;
32 static constexpr int overlap_MTF_region = 2;
33 static constexpr int endcap_MTF_region = 3;
34 static constexpr float eta_scale = 0.010875;
35 static constexpr float phi_scale = 2 * M_PI / 576.;
36 static constexpr float dr2_cutoff = 0.3;
37 static constexpr float matching_factor_eta = 3.;
38 static constexpr float matching_factor_phi = 4.;
39 static constexpr float min_mu_propagator_p = 3.5;
40 static constexpr float min_mu_propagator_barrel_pT = 3.5;
41 static constexpr float max_mu_propagator_eta = 2.5;
42 
43 using namespace l1t;
44 
46 public:
48  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
49 
50  struct PropState { //something simple, imagine it's hardware emulation
51  PropState() : pt(-99), eta(-99), phi(-99), sigmaPt(-99), sigmaEta(-99), sigmaPhi(-99), valid(false) {}
52  float pt;
53  float eta;
54  float phi;
55  float sigmaPt;
56  float sigmaEta;
57  float sigmaPhi;
58  bool valid;
59  };
60 
61  enum AlgoType { kTP = 1, kDynamicWindows = 2, kMantra = 3 };
62 
63  explicit L1TkMuonProducer(const edm::ParameterSet&);
64  ~L1TkMuonProducer() override;
65 
66  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
67 
68 private:
69  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
70  PropState propagateToGMT(const L1TTTrackType& l1tk) const;
71  double sigmaEtaTP(const RegionalMuonCand& mu) const;
72  double sigmaPhiTP(const RegionalMuonCand& mu) const;
73 
74  // the TP algorithm
75  void runOnMTFCollection_v1(const edm::Handle<RegionalMuonCandBxCollection>&,
78  const int detector) const;
79 
80  // algo for endcap regions using dynamic windows for making the match
81  void runOnMTFCollection_v2(const edm::Handle<EMTFTrackCollection>&,
83  TkMuonCollection& tkMuons) const;
84 
85  // given the matching indexes, build the output collection of track muons
86  void build_tkMuons_from_idxs(TkMuonCollection& tkMuons,
87  const std::vector<int>& matches,
90  int detector) const;
91 
92  // dump and convert tracks to the format needed for the MAnTra correlator
93  std::vector<L1TkMuMantraDF::track_df> product_to_trkvec(const L1TTTrackCollectionType& l1tks) const; // tracks
94  // regional muon finder
95  std::vector<L1TkMuMantraDF::muon_df> product_to_muvec(const RegionalMuonCandBxCollection& l1mtfs) const;
96  // endcap muon finder - eventually to be moved to regional candidate
97  std::vector<L1TkMuMantraDF::muon_df> product_to_muvec(const EMTFTrackCollection& l1mus) const;
98 
99  float etaMin_;
100  float etaMax_;
101  float zMax_; // |z_track| < zMax_ in cm
102  float chi2Max_;
103  float pTMinTra_;
104  float dRMax_;
105  int nStubsmin_; // minimum number of stubs
109 
113 
114  std::unique_ptr<L1TkMuCorrDynamicWindows> dwcorr_;
115 
116  std::unique_ptr<L1TkMuMantra> mantracorr_barr_;
117  std::unique_ptr<L1TkMuMantra> mantracorr_ovrl_;
118  std::unique_ptr<L1TkMuMantra> mantracorr_endc_;
120 
124  // the track collection, directly from the EMTF and not formatted by GT
127 };
128 
130  : etaMin_((float)iConfig.getParameter<double>("ETAMIN")),
131  etaMax_((float)iConfig.getParameter<double>("ETAMAX")),
132  zMax_((float)iConfig.getParameter<double>("ZMAX")),
133  chi2Max_((float)iConfig.getParameter<double>("CHI2MAX")),
134  pTMinTra_((float)iConfig.getParameter<double>("PTMINTRA")),
135  dRMax_((float)iConfig.getParameter<double>("DRmax")),
136  nStubsmin_(iConfig.getParameter<int>("nStubsmin")),
137  // --- mantra corr params
138  mantra_n_trk_par_(iConfig.getParameter<int>("mantra_n_trk_par")),
139  bmtfToken_(consumes<RegionalMuonCandBxCollection>(iConfig.getParameter<edm::InputTag>("L1BMTFInputTag"))),
140  omtfToken_(consumes<RegionalMuonCandBxCollection>(iConfig.getParameter<edm::InputTag>("L1OMTFInputTag"))),
141  emtfToken_(consumes<RegionalMuonCandBxCollection>(iConfig.getParameter<edm::InputTag>("L1EMTFInputTag"))),
142  emtfTCToken_(consumes<EMTFTrackCollection>(iConfig.getParameter<edm::InputTag>("L1EMTFTrackCollectionInputTag"))),
143  trackToken_(consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(
144  iConfig.getParameter<edm::InputTag>("L1TrackInputTag"))) {
145  // --------------------- configuration of the muon algorithm type
146 
147  std::string bmtfMatchAlgoVersionString = iConfig.getParameter<std::string>("bmtfMatchAlgoVersion");
148  std::transform(bmtfMatchAlgoVersionString.begin(),
149  bmtfMatchAlgoVersionString.end(),
150  bmtfMatchAlgoVersionString.begin(),
151  ::tolower); // make lowercase
152 
153  std::string omtfMatchAlgoVersionString = iConfig.getParameter<std::string>("omtfMatchAlgoVersion");
154  std::transform(omtfMatchAlgoVersionString.begin(),
155  omtfMatchAlgoVersionString.end(),
156  omtfMatchAlgoVersionString.begin(),
157  ::tolower); // make lowercase
158 
159  std::string emtfMatchAlgoVersionString = iConfig.getParameter<std::string>("emtfMatchAlgoVersion");
160  std::transform(emtfMatchAlgoVersionString.begin(),
161  emtfMatchAlgoVersionString.end(),
162  emtfMatchAlgoVersionString.begin(),
163  ::tolower); // make lowercase
164 
165  if (bmtfMatchAlgoVersionString == "tp")
167  else if (bmtfMatchAlgoVersionString == "mantra")
169  else
170  throw cms::Exception("TkMuAlgoConfig")
171  << "the ID " << bmtfMatchAlgoVersionString << " of the BMTF algo matcher passed is invalid\n";
172 
173  if (omtfMatchAlgoVersionString == "tp")
175  else if (omtfMatchAlgoVersionString == "mantra")
177  else
178  throw cms::Exception("TkMuAlgoConfig")
179  << "the ID " << omtfMatchAlgoVersionString << " of the OMTF algo matcher passed is invalid\n";
180 
181  if (emtfMatchAlgoVersionString == "tp")
183  else if (emtfMatchAlgoVersionString == "dynamicwindows")
185  else if (emtfMatchAlgoVersionString == "mantra")
187  else
188  throw cms::Exception("TkMuAlgoConfig")
189  << "the ID " << emtfMatchAlgoVersionString << " of the EMTF algo matcher passed is invalid\n";
190 
191  correctGMTPropForTkZ_ = iConfig.getParameter<bool>("correctGMTPropForTkZ");
192 
193  use5ParameterFit_ = iConfig.getParameter<bool>("use5ParameterFit");
194  useTPMatchWindows_ = iConfig.getParameter<bool>("useTPMatchWindows");
195  produces<TkMuonCollection>();
196 
197  // initializations
199  // FIXME: to merge eventually into an unique file with bith phi and theta boundaries
200  std::string fIn_bounds_name = iConfig.getParameter<edm::FileInPath>("emtfcorr_boundaries").fullPath();
201  std::string fIn_theta_name = iConfig.getParameter<edm::FileInPath>("emtfcorr_theta_windows").fullPath();
202  std::string fIn_phi_name = iConfig.getParameter<edm::FileInPath>("emtfcorr_phi_windows").fullPath();
203  const auto& bounds = L1TkMuCorrDynamicWindows::prepare_corr_bounds(fIn_bounds_name, "h_dphi_l");
204  TFile* fIn_theta = TFile::Open(fIn_theta_name.c_str());
205  TFile* fIn_phi = TFile::Open(fIn_phi_name.c_str());
206  dwcorr_ = std::make_unique<L1TkMuCorrDynamicWindows>(bounds, fIn_theta, fIn_phi);
207 
208  // files can be closed since the correlator code clones the TF1s
209  fIn_theta->Close();
210  fIn_phi->Close();
211 
212  // FIXME: more initialisation using the parameters passed from the cfg
213  dwcorr_->set_safety_factor(iConfig.getParameter<double>("final_window_factor"));
214  dwcorr_->set_sf_initialrelax(iConfig.getParameter<double>("initial_window_factor"));
215 
216  dwcorr_->set_relaxation_pattern(iConfig.getParameter<double>("pt_start_relax"),
217  iConfig.getParameter<double>("pt_end_relax"));
218 
219  dwcorr_->set_do_relax_factor(iConfig.getParameter<bool>("do_relax_factors"));
220 
221  dwcorr_->set_n_trk_par(iConfig.getParameter<int>("n_trk_par"));
222  dwcorr_->set_min_trk_p(iConfig.getParameter<double>("min_trk_p"));
223  dwcorr_->set_max_trk_aeta(iConfig.getParameter<double>("max_trk_aeta"));
224  dwcorr_->set_max_trk_chi2(iConfig.getParameter<double>("max_trk_chi2"));
225  dwcorr_->set_min_trk_nstubs(iConfig.getParameter<int>("min_trk_nstubs"));
226  dwcorr_->set_do_trk_qual_presel(true);
227  }
228 
230  std::string fIn_bounds_name = iConfig.getParameter<edm::FileInPath>("mantra_bmtfcorr_boundaries").fullPath();
231  std::string fIn_theta_name = iConfig.getParameter<edm::FileInPath>("mantra_bmtfcorr_theta_windows").fullPath();
232  std::string fIn_phi_name = iConfig.getParameter<edm::FileInPath>("mantra_bmtfcorr_phi_windows").fullPath();
233 
234  const auto& bounds = L1TkMuMantra::prepare_corr_bounds(fIn_bounds_name, "h_dphi_l");
235 
236  TFile* fIn_theta = TFile::Open(fIn_theta_name.c_str());
237  TFile* fIn_phi = TFile::Open(fIn_phi_name.c_str());
238 
239  mantracorr_barr_ = std::make_unique<L1TkMuMantra>(bounds, fIn_theta, fIn_phi, "mantra_barrel");
240 
241  fIn_theta->Close();
242  fIn_phi->Close();
243 
244  // settings : NB : now hardcoded, could be read from cfg
245  mantracorr_barr_->set_safety_factor(0.5, 0.5);
246  mantracorr_barr_->setArbitrationType("MaxPt");
247  }
248 
250  std::string fIn_bounds_name = iConfig.getParameter<edm::FileInPath>("mantra_omtfcorr_boundaries").fullPath();
251  std::string fIn_theta_name = iConfig.getParameter<edm::FileInPath>("mantra_omtfcorr_theta_windows").fullPath();
252  std::string fIn_phi_name = iConfig.getParameter<edm::FileInPath>("mantra_omtfcorr_phi_windows").fullPath();
253 
254  const auto& bounds = L1TkMuMantra::prepare_corr_bounds(fIn_bounds_name, "h_dphi_l");
255 
256  TFile* fIn_theta = TFile::Open(fIn_theta_name.c_str());
257  TFile* fIn_phi = TFile::Open(fIn_phi_name.c_str());
258 
259  mantracorr_ovrl_ = std::make_unique<L1TkMuMantra>(bounds, fIn_theta, fIn_phi, "mantra_overlap");
260 
261  fIn_theta->Close();
262  fIn_phi->Close();
263 
264  // settings : NB : now hardcoded, could be read from cfg
265  mantracorr_ovrl_->set_safety_factor(0.5, 0.5);
266  mantracorr_ovrl_->setArbitrationType("MaxPt");
267  }
268 
270  std::string fIn_bounds_name = iConfig.getParameter<edm::FileInPath>("mantra_emtfcorr_boundaries").fullPath();
271  std::string fIn_theta_name = iConfig.getParameter<edm::FileInPath>("mantra_emtfcorr_theta_windows").fullPath();
272  std::string fIn_phi_name = iConfig.getParameter<edm::FileInPath>("mantra_emtfcorr_phi_windows").fullPath();
273 
274  const auto& bounds = L1TkMuMantra::prepare_corr_bounds(fIn_bounds_name, "h_dphi_l");
275 
276  TFile* fIn_theta = TFile::Open(fIn_theta_name.c_str());
277  TFile* fIn_phi = TFile::Open(fIn_phi_name.c_str());
278 
279  mantracorr_endc_ = std::make_unique<L1TkMuMantra>(bounds, fIn_theta, fIn_phi, "mantra_endcap");
280 
281  fIn_theta->Close();
282  fIn_phi->Close();
283 
284  // settings : NB : now hardcoded, could be read from cfg
285  mantracorr_endc_->set_safety_factor(0.5, 0.5);
286  mantracorr_endc_->setArbitrationType("MaxPt");
287  }
288 }
289 
291 
292 // ------------ method called to produce the data ------------
294  // the L1Mu objects
299 
300  iEvent.getByToken(bmtfToken_, l1bmtfH);
301  iEvent.getByToken(omtfToken_, l1omtfH);
302  iEvent.getByToken(emtfToken_, l1emtfH);
303  iEvent.getByToken(emtfTCToken_, l1emtfTCH);
304 
305  // the L1Tracks
307  iEvent.getByToken(trackToken_, l1tksH);
308 
309  TkMuonCollection oc_bmtf_tkmuon;
310  TkMuonCollection oc_omtf_tkmuon;
311  TkMuonCollection oc_emtf_tkmuon;
312 
313  std::vector<L1TkMuMantraDF::track_df> mantradf_tracks; // if needed, just encode once for all trk finders
315  mantradf_tracks = product_to_trkvec(*l1tksH.product());
316  }
317 
318  // process each of the MTF collections separately! -- we don't want to filter the muons
319 
320  // ----------------------------------------------------- barrel
321  if (bmtfMatchAlgoVersion_ == kTP)
322  runOnMTFCollection_v1(l1bmtfH, l1tksH, oc_bmtf_tkmuon, barrel_MTF_region);
323  else if (bmtfMatchAlgoVersion_ == kMantra) {
324  const auto& muons = product_to_muvec(*l1bmtfH.product());
325  const auto& match_idx = mantracorr_barr_->find_match(mantradf_tracks, muons);
326  build_tkMuons_from_idxs(oc_bmtf_tkmuon, match_idx, l1tksH, l1bmtfH, barrel_MTF_region);
327  } else
328  throw cms::Exception("TkMuAlgoConfig") << " barrel : trying to run an invalid algorithm version "
329  << bmtfMatchAlgoVersion_ << " (this should never happen)\n";
330 
331  // ----------------------------------------------------- overlap
332  if (omtfMatchAlgoVersion_ == kTP)
333  runOnMTFCollection_v1(l1omtfH, l1tksH, oc_omtf_tkmuon, overlap_MTF_region);
334  else if (omtfMatchAlgoVersion_ == kMantra) {
335  const auto& muons = product_to_muvec(*l1omtfH.product());
336  const auto& match_idx = mantracorr_ovrl_->find_match(mantradf_tracks, muons);
337  build_tkMuons_from_idxs(oc_omtf_tkmuon, match_idx, l1tksH, l1omtfH, overlap_MTF_region);
338  } else
339  throw cms::Exception("TkMuAlgoConfig") << " overlap : trying to run an invalid algorithm version "
340  << omtfMatchAlgoVersion_ << " (this should never happen)\n";
341 
342  // ----------------------------------------------------- endcap
343  if (emtfMatchAlgoVersion_ == kTP)
344  runOnMTFCollection_v1(l1emtfH, l1tksH, oc_emtf_tkmuon, endcap_MTF_region);
346  runOnMTFCollection_v2(l1emtfTCH, l1tksH, oc_emtf_tkmuon);
347  else if (emtfMatchAlgoVersion_ == kMantra) {
348  const auto& muons = product_to_muvec(*l1emtfTCH.product());
349  const auto& match_idx = mantracorr_endc_->find_match(mantradf_tracks, muons);
350  //for the TkMu that were built from a EMTFCollection - do not produce a valid muon ref
352  build_tkMuons_from_idxs(oc_emtf_tkmuon, match_idx, l1tksH, invalidMuonH, endcap_MTF_region);
353  } else
354  throw cms::Exception("TkMuAlgoConfig") << "endcap : trying to run an invalid algorithm version "
355  << emtfMatchAlgoVersion_ << " (this should never happen)\n";
356 
357  // now combine all trk muons into a single output collection!
358  auto oc_tkmuon = std::make_unique<TkMuonCollection>();
359  for (const auto& p : {oc_bmtf_tkmuon, oc_omtf_tkmuon, oc_emtf_tkmuon}) {
360  oc_tkmuon->insert(oc_tkmuon->end(), p.begin(), p.end());
361  }
362 
363  // put the new track+muon objects in the event!
364  iEvent.put(std::move(oc_tkmuon));
365 };
366 
370  const int detector) const {
371  const L1TTTrackCollectionType& l1tks = (*l1tksH.product());
372  const RegionalMuonCandBxCollection& l1mtfs = (*muonH.product());
373 
374  int imu = 0;
375  for (auto l1mu = l1mtfs.begin(0); l1mu != l1mtfs.end(0); ++l1mu) { // considering BX = only
376 
377  edm::Ref<RegionalMuonCandBxCollection> l1muRef(muonH, imu);
378  imu++;
379 
380  float l1mu_eta = l1mu->hwEta() * eta_scale;
381  // get the global phi
382  float l1mu_phi =
383  MicroGMTConfiguration::calcGlobalPhi(l1mu->hwPhi(), l1mu->trackFinderType(), l1mu->processor()) * phi_scale;
384 
385  float l1mu_feta = std::abs(l1mu_eta);
386  if (l1mu_feta < etaMin_)
387  continue;
388  if (l1mu_feta > etaMax_)
389  continue;
390 
391  float drmin = 999;
392 
393  PropState matchProp;
394  int match_idx = -1;
395  int il1tk = -1;
396 
397  int nTracksMatch = 0;
398 
399  for (const auto& l1tk : l1tks) {
400  il1tk++;
401 
402  float l1tk_pt = l1tk.momentum().perp();
403  if (l1tk_pt < pTMinTra_)
404  continue;
405 
406  float l1tk_z = l1tk.POCA().z();
407  if (std::abs(l1tk_z) > zMax_)
408  continue;
409 
410  float l1tk_chi2 = l1tk.chi2();
411  if (l1tk_chi2 > chi2Max_)
412  continue;
413 
414  int l1tk_nstubs = l1tk.getStubRefs().size();
415  if (l1tk_nstubs < nStubsmin_)
416  continue;
417 
418  float l1tk_eta = l1tk.momentum().eta();
419  float l1tk_phi = l1tk.momentum().phi();
420 
421  float dr2 = reco::deltaR2(l1mu_eta, l1mu_phi, l1tk_eta, l1tk_phi);
422  if (dr2 > dr2_cutoff)
423  continue;
424 
425  nTracksMatch++;
426 
427  const PropState& pstate = propagateToGMT(l1tk);
428  if (!pstate.valid)
429  continue;
430 
431  float dr2prop = reco::deltaR2(l1mu_eta, l1mu_phi, pstate.eta, pstate.phi);
432  // FIXME: check if this matching procedure can be improved with
433  // a pT dependent dR window
434  if (dr2prop < drmin) {
435  drmin = dr2prop;
436  match_idx = il1tk;
437  matchProp = pstate;
438  }
439  } // over l1tks
440 
441  LogDebug("L1TkMuonProducer") << "matching index is " << match_idx;
442  if (match_idx >= 0) {
443  const L1TTTrackType& matchTk = l1tks[match_idx];
444 
445  float sigmaEta = sigmaEtaTP(*l1mu);
446  float sigmaPhi = sigmaPhiTP(*l1mu);
447 
448  float etaCut = matching_factor_eta * sqrt(sigmaEta * sigmaEta + matchProp.sigmaEta * matchProp.sigmaEta);
449  float phiCut = matching_factor_phi * sqrt(sigmaPhi * sigmaPhi + matchProp.sigmaPhi * matchProp.sigmaPhi);
450 
451  float dEta = std::abs(matchProp.eta - l1mu_eta);
452  float dPhi = std::abs(deltaPhi(matchProp.phi, l1mu_phi));
453 
454  bool matchCondition = useTPMatchWindows_ ? dEta < etaCut && dPhi < phiCut : drmin < dRMax_;
455 
456  if (matchCondition) {
457  edm::Ptr<L1TTTrackType> l1tkPtr(l1tksH, match_idx);
458 
459  const auto& p3 = matchTk.momentum();
460  float p4e = sqrt(mu_mass * mu_mass + p3.mag2());
461 
462  math::XYZTLorentzVector l1tkp4(p3.x(), p3.y(), p3.z(), p4e);
463 
464  const auto& tkv3 = matchTk.POCA();
465  math::XYZPoint v3(tkv3.x(), tkv3.y(), tkv3.z()); // why is this defined?
466 
467  float trkisol = -999;
468 
469  TkMuon l1tkmu(l1tkp4, l1muRef, l1tkPtr, trkisol);
470 
471  l1tkmu.setTrackCurvature(matchTk.rInv());
472  l1tkmu.setTrkzVtx((float)tkv3.z());
473  l1tkmu.setdR(drmin);
474  l1tkmu.setNTracksMatched(nTracksMatch);
475  l1tkmu.setMuonDetector(detector);
476  tkMuons.push_back(l1tkmu);
477  }
478  }
479  } //over l1mus
480 }
481 
484  TkMuonCollection& tkMuons) const {
485  const EMTFTrackCollection& l1mus = (*muonH.product());
486  const L1TTTrackCollectionType& l1trks = (*l1tksH.product());
487  const auto& corr_mu_idxs = dwcorr_->find_match(l1mus, l1trks);
488  // it's a vector with as many entries as the L1TT vector.
489  // >= 0 : the idx in the EMTF vector of matched mu
490  // < 0: no match
491 
492  // sanity check
493  if (corr_mu_idxs.size() != l1trks.size())
494  throw cms::Exception("TkMuAlgoOutput")
495  << "the size of tkmu indices does not match the size of input trk collection\n";
496 
497  for (uint il1ttrack = 0; il1ttrack < corr_mu_idxs.size(); ++il1ttrack) {
498  int emtf_idx = corr_mu_idxs[il1ttrack];
499  if (emtf_idx < 0)
500  continue;
501 
502  const L1TTTrackType& matchTk = l1trks[il1ttrack];
503  const auto& p3 = matchTk.momentum();
504  const auto& tkv3 = matchTk.POCA();
505  float p4e = sqrt(mu_mass * mu_mass + p3.mag2());
506  math::XYZTLorentzVector l1tkp4(p3.x(), p3.y(), p3.z(), p4e);
507 
509  edm::Ptr<L1TTTrackType> l1tkPtr(l1tksH, il1ttrack);
510  float trkisol = -999; // now doing as in the TP algo
511  TkMuon l1tkmu(l1tkp4, l1muRef, l1tkPtr, trkisol);
512  l1tkmu.setTrackCurvature(matchTk.rInv());
513  l1tkmu.setTrkzVtx((float)tkv3.z());
515  tkMuons.push_back(l1tkmu);
516  }
517 
518  return;
519 }
520 
521 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
523  //The following says we do not know what parameters are allowed so do no validation
524  // Please change this to state exactly what you do use, even if it is no parameters
526  desc.setUnknown();
527  descriptions.addDefault(desc);
528 }
529 
531  auto p3 = tk.momentum();
532  float tk_pt = p3.perp();
533  float tk_p = p3.mag();
534  float tk_eta = p3.eta();
535  float tk_aeta = std::abs(tk_eta);
536  float tk_phi = p3.phi();
537  float tk_q = tk.rInv() > 0 ? 1. : -1.;
538  float tk_z = tk.POCA().z();
540  tk_z = 0;
541 
543  if (tk_p < min_mu_propagator_p)
544  return dest;
545  if (tk_aeta < 1.1 && tk_pt < min_mu_propagator_barrel_pT)
546  return dest;
547  if (tk_aeta > max_mu_propagator_eta)
548  return dest;
549 
550  //0th order:
551  dest.valid = true;
552 
553  float dzCorrPhi = 1.;
554  float deta = 0;
555  float etaProp = tk_aeta;
556 
557  if (tk_aeta < 1.1) {
558  etaProp = 1.1;
559  deta = tk_z / 550. / cosh(tk_aeta);
560  } else {
561  float delta = tk_z / 850.; //roughly scales as distance to 2nd station
562  if (tk_eta > 0)
563  delta *= -1;
564  dzCorrPhi = 1. + delta;
565 
566  float zOzs = tk_z / 850.;
567  if (tk_eta > 0)
568  deta = zOzs / (1. - zOzs);
569  else
570  deta = zOzs / (1. + zOzs);
571  deta = deta * tanh(tk_eta);
572  }
573  float resPhi = tk_phi - 1.464 * tk_q * cosh(1.7) / cosh(etaProp) / tk_pt * dzCorrPhi - M_PI / 144.;
574  resPhi = reco::reduceRange(resPhi);
575 
576  dest.eta = tk_eta + deta;
577  dest.phi = resPhi;
578  dest.pt = tk_pt; //not corrected for eloss
579 
580  dest.sigmaEta = 0.100 / tk_pt; //multiple scattering term
581  dest.sigmaPhi = 0.106 / tk_pt; //need a better estimate for these
582  return dest;
583 }
584 
586  float l1mu_eta = l1mu.hwEta() * eta_scale;
587  if (std::abs(l1mu_eta) <= 1.55)
588  return 0.0288;
589  else if (std::abs(l1mu_eta) > 1.55 && std::abs(l1mu_eta) <= 1.65)
590  return 0.025;
591  else if (std::abs(l1mu_eta) > 1.65 && std::abs(l1mu_eta) <= 2.4)
592  return 0.0144;
593  return 0.0288;
594 }
595 
596 double L1TkMuonProducer::sigmaPhiTP(const RegionalMuonCand& mu) const { return 0.0126; }
597 
598 // ------------------------------------------------------------------------------------------------------------
599 
600 std::vector<L1TkMuMantraDF::track_df> L1TkMuonProducer::product_to_trkvec(const L1TTTrackCollectionType& l1tks) const {
601  std::vector<L1TkMuMantraDF::track_df> result(l1tks.size());
602  for (uint itrk = 0; itrk < l1tks.size(); ++itrk) {
603  auto& trk = l1tks[itrk];
604 
605  result[itrk].pt = trk.momentum().perp();
606  result[itrk].eta = trk.momentum().eta();
607  result[itrk].theta = L1TkMuMantra::to_mpio2_pio2(L1TkMuMantra::eta_to_theta(trk.momentum().eta()));
608  result[itrk].phi = trk.momentum().phi();
609  result[itrk].nstubs = trk.getStubRefs().size();
610  result[itrk].chi2 = trk.chi2();
611  result[itrk].charge = (trk.rInv() > 0 ? 1 : -1);
612  }
613 
614  return result;
615 }
616 
617 std::vector<L1TkMuMantraDF::muon_df> L1TkMuonProducer::product_to_muvec(
618  const RegionalMuonCandBxCollection& l1mtfs) const {
619  std::vector<L1TkMuMantraDF::muon_df> result;
620  for (auto l1mu = l1mtfs.begin(0); l1mu != l1mtfs.end(0); ++l1mu) // considering BX = 0 only
621  {
622  L1TkMuMantraDF::muon_df this_mu;
623  this_mu.pt = l1mu->hwPt() * 0.5;
624  this_mu.eta = l1mu->hwEta() * eta_scale;
626  this_mu.phi =
627  MicroGMTConfiguration::calcGlobalPhi(l1mu->hwPhi(), l1mu->trackFinderType(), l1mu->processor()) * phi_scale;
628  this_mu.charge = (l1mu->hwSign() == 0 ? 1 : -1); // charge sign bit (charge = (-1)^(sign))
629  result.push_back(this_mu);
630  }
631  return result;
632 }
633 
634 std::vector<L1TkMuMantraDF::muon_df> L1TkMuonProducer::product_to_muvec(const EMTFTrackCollection& l1mus) const {
635  std::vector<L1TkMuMantraDF::muon_df> result(l1mus.size());
636  for (uint imu = 0; imu < l1mus.size(); ++imu) {
637  auto& mu = l1mus[imu];
638  result[imu].pt = mu.Pt();
639  result[imu].eta = mu.Eta();
641  result[imu].phi = L1TkMuMantra::deg_to_rad(mu.Phi_glob());
642  result[imu].charge = mu.Charge();
643  }
644  return result;
645 }
646 
648  const std::vector<int>& matches,
651  int detector) const {
652  for (uint imatch = 0; imatch < matches.size(); ++imatch) {
653  int match_trk_idx = matches[imatch];
654  if (match_trk_idx < 0)
655  continue; // this muon was not matched to any candidate
656 
657  // take properties of the track
658  const L1TTTrackType& matchTk = (*l1tksH.product())[match_trk_idx];
659  const auto& p3 = matchTk.momentum();
660  const auto& tkv3 = matchTk.POCA();
661  float p4e = sqrt(mu_mass * mu_mass + p3.mag2());
662  math::XYZTLorentzVector l1tkp4(p3.x(), p3.y(), p3.z(), p4e);
663 
664  edm::Ptr<L1TTTrackType> l1tkPtr(l1tksH, match_trk_idx);
665  auto l1muRef = muonH.isValid() ? edm::Ref<RegionalMuonCandBxCollection>(muonH, imatch)
667 
668  float trkisol = -999;
669  TkMuon l1tkmu(l1tkp4, l1muRef, l1tkPtr, trkisol);
670  l1tkmu.setTrackCurvature(matchTk.rInv());
671  l1tkmu.setTrkzVtx((float)tkv3.z());
672  l1tkmu.setMuonDetector(detector);
673  tkMuons.push_back(l1tkmu);
674  }
675  return;
676 }
677 
678 //define this as a plug-in
L1TkMuonProducer::sigmaPhiTP
double sigmaPhiTP(const RegionalMuonCand &mu) const
Definition: L1TkMuonProducer.cc:596
edm::StreamID
Definition: StreamID.h:30
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
L1TkMuonProducer::pTMinTra_
float pTMinTra_
Definition: L1TkMuonProducer.cc:103
L1TkMuMantraDF::muon_df::theta
double theta
Definition: L1TkMuMantra.h:27
Handle.h
L1TkMuonProducer::omtfMatchAlgoVersion_
AlgoType omtfMatchAlgoVersion_
Definition: L1TkMuonProducer.cc:111
L1TkMuonProducer::L1TTTrackType
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
Definition: L1TkMuonProducer.cc:47
L1TkMuonProducer::product_to_muvec
std::vector< L1TkMuMantraDF::muon_df > product_to_muvec(const RegionalMuonCandBxCollection &l1mtfs) const
Definition: L1TkMuonProducer.cc:617
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
funct::false
false
Definition: Factorize.h:34
edm::Handle::product
T const * product() const
Definition: Handle.h:70
TTTrack::momentum
GlobalVector momentum() const
Track momentum.
Definition: TTTrack.h:281
L1TkMuonProducer::etaMax_
float etaMax_
Definition: L1TkMuonProducer.cc:100
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
L1TkMuonProducer::runOnMTFCollection_v1
void runOnMTFCollection_v1(const edm::Handle< RegionalMuonCandBxCollection > &, const edm::Handle< L1TTTrackCollectionType > &, TkMuonCollection &tkMuons, const int detector) const
Definition: L1TkMuonProducer.cc:367
edm::EDGetTokenT< RegionalMuonCandBxCollection >
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
L1TkMuonProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: L1TkMuonProducer.cc:293
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Muon.h
l1t::TkMuon::setTrackCurvature
void setTrackCurvature(double trackCurvature)
Definition: TkMuon.h:55
L1TkMuonProducer::dRMax_
float dRMax_
Definition: L1TkMuonProducer.cc:104
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
L1TkMuonProducer::PropState::valid
bool valid
Definition: L1TkMuonProducer.cc:58
L1TkMuMantra::prepare_corr_bounds
static std::vector< double > prepare_corr_bounds(std::string fname, std::string hname)
Definition: L1TkMuMantra.cc:199
TTTrack
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:26
L1TkMuonProducer::bmtfMatchAlgoVersion_
AlgoType bmtfMatchAlgoVersion_
Definition: L1TkMuonProducer.cc:110
l1t::TkMuon::setNTracksMatched
void setNTracksMatched(int nTracksMatch)
Definition: TkMuon.h:54
L1TkMuonProducer::zMax_
float zMax_
Definition: L1TkMuonProducer.cc:101
max_mu_propagator_eta
static constexpr float max_mu_propagator_eta
Definition: L1TkMuonProducer.cc:41
endcap_MTF_region
static constexpr int endcap_MTF_region
Definition: L1TkMuonProducer.cc:33
L1TkMuonProducer::mantra_n_trk_par_
int mantra_n_trk_par_
Definition: L1TkMuonProducer.cc:119
L1TkMuonProducer::PropState::phi
float phi
Definition: L1TkMuonProducer.cc:54
L1TkMuonProducer::emtfMatchAlgoVersion_
AlgoType emtfMatchAlgoVersion_
Definition: L1TkMuonProducer.cc:112
edm::Handle
Definition: AssociativeIterator.h:50
L1TkMuonProducer::omtfToken_
const edm::EDGetTokenT< RegionalMuonCandBxCollection > omtfToken_
Definition: L1TkMuonProducer.cc:122
parallelization.uint
uint
Definition: parallelization.py:124
TTTrack::rInv
double rInv() const
Track curvature.
Definition: TTTrack.h:286
validateGeometry_cfg.valid
valid
Definition: validateGeometry_cfg.py:21
l1t::RegionalMuonCand::hwEta
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
Definition: RegionalMuonCand.h:169
HLT_2018_cff.dEta
dEta
Definition: HLT_2018_cff.py:12289
edm::Ref
Definition: AssociativeIterator.h:58
TkMuon.h
l1pfProducer_cfi.tkMuons
tkMuons
Definition: l1pfProducer_cfi.py:8
L1TkMuCorrDynamicWindows::prepare_corr_bounds
static std::vector< double > prepare_corr_bounds(const string &fname, const string &hname)
Definition: L1TkMuCorrDynamicWindows.cc:387
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
deltaR.h
phi_scale
static constexpr float phi_scale
Definition: L1TkMuonProducer.cc:35
BXVector< RegionalMuonCand >
TTTrack::POCA
GlobalPoint POCA() const
POCA.
Definition: TTTrack.h:316
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
L1TkMuonProducer::kTP
Definition: L1TkMuonProducer.cc:61
L1TkMuonProducer::kDynamicWindows
Definition: L1TkMuonProducer.cc:61
l1t::EMTFTrackCollection
std::vector< EMTFTrack > EMTFTrackCollection
Definition: EMTFTrack.h:219
L1TkMuonProducer::emtfToken_
const edm::EDGetTokenT< RegionalMuonCandBxCollection > emtfToken_
Definition: L1TkMuonProducer.cc:123
min_mu_propagator_barrel_pT
static constexpr float min_mu_propagator_barrel_pT
Definition: L1TkMuonProducer.cc:40
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TkMuonProducer
Definition: L1TkMuonProducer.cc:45
L1TkMuonProducer::dwcorr_
std::unique_ptr< L1TkMuCorrDynamicWindows > dwcorr_
Definition: L1TkMuonProducer.cc:114
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
MicroGMTConfiguration.h
L1TkMuonProducer::PropState::pt
float pt
Definition: L1TkMuonProducer.cc:52
PVValHelper::eta
Definition: PVValidationHelpers.h:69
L1TkMuCorrDynamicWindows.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
L1TkMuonProducer::kMantra
Definition: L1TkMuonProducer.cc:61
HLT_2018_cff.dPhi
dPhi
Definition: HLT_2018_cff.py:12290
L1TkMuonProducer::correctGMTPropForTkZ_
bool correctGMTPropForTkZ_
Definition: L1TkMuonProducer.cc:106
matching_factor_eta
static constexpr float matching_factor_eta
Definition: L1TkMuonProducer.cc:37
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
min_mu_propagator_p
static constexpr float min_mu_propagator_p
Definition: L1TkMuonProducer.cc:39
dr2_cutoff
static constexpr float dr2_cutoff
Definition: L1TkMuonProducer.cc:36
overlap_MTF_region
static constexpr int overlap_MTF_region
Definition: L1TkMuonProducer.cc:32
BXVector::begin
const_iterator begin(int bx) const
L1TkMuonProducer::useTPMatchWindows_
bool useTPMatchWindows_
Definition: L1TkMuonProducer.cc:108
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1TkMuMantraDF::muon_df::phi
double phi
Definition: L1TkMuMantra.h:28
L1TkMuonProducer::chi2Max_
float chi2Max_
Definition: L1TkMuonProducer.cc:102
L1TkMuonProducer::product_to_trkvec
std::vector< L1TkMuMantraDF::track_df > product_to_trkvec(const L1TTTrackCollectionType &l1tks) const
Definition: L1TkMuonProducer.cc:600
L1TkMuMantraDF::muon_df::eta
double eta
Definition: L1TkMuMantra.h:26
L1TkMuonProducer::PropState::sigmaPhi
float sigmaPhi
Definition: L1TkMuonProducer.cc:57
BXVector::end
const_iterator end(int bx) const
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
l1t::TkMuon::setdR
void setdR(float dR)
Definition: TkMuon.h:53
L1TkMuonProducer::PropState
Definition: L1TkMuonProducer.cc:50
L1TkMuonProducer::emtfTCToken_
const edm::EDGetTokenT< EMTFTrackCollection > emtfTCToken_
Definition: L1TkMuonProducer.cc:125
eta_scale
static constexpr float eta_scale
Definition: L1TkMuonProducer.cc:34
Event.h
fftjetproducer_cfi.etaCut
etaCut
Definition: fftjetproducer_cfi.py:168
L1TkMuonProducer::use5ParameterFit_
bool use5ParameterFit_
Definition: L1TkMuonProducer.cc:107
l1t
delete x;
Definition: CaloConfig.h:22
barrel_MTF_region
static constexpr int barrel_MTF_region
Definition: L1TkMuonProducer.cc:31
L1TkMuonProducer::PropState::PropState
PropState()
Definition: L1TkMuonProducer.cc:51
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
LorentzVector.h
createfilelist.int
int
Definition: createfilelist.py:10
L1TkMuonProducer::PropState::eta
float eta
Definition: L1TkMuonProducer.cc:53
iEvent
int iEvent
Definition: GenABIO.cc:224
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
L1TkMuonProducer::L1TTTrackCollectionType
std::vector< L1TTTrackType > L1TTTrackCollectionType
Definition: L1TkMuonProducer.cc:48
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
L1TkMuMantra.h
L1TkMuMantraDF::muon_df
Definition: L1TkMuMantra.h:24
edm::EventSetup
Definition: EventSetup.h:57
L1TkMuonProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TkMuonProducer.cc:522
Common.h
l1t::TkMuon
Definition: TkMuon.h:12
L1TkMuonProducer::sigmaEtaTP
double sigmaEtaTP(const RegionalMuonCand &mu) const
Definition: L1TkMuonProducer.cc:585
InputTag.h
edm::Ptr
Definition: AssociationVector.h:31
L1TkMuonProducer::mantracorr_ovrl_
std::unique_ptr< L1TkMuMantra > mantracorr_ovrl_
Definition: L1TkMuonProducer.cc:117
L1TkMuonProducer::L1TkMuonProducer
L1TkMuonProducer(const edm::ParameterSet &)
Definition: L1TkMuonProducer.cc:129
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
mu_mass
static constexpr float mu_mass
Definition: L1TkMuonProducer.cc:30
L1TkMuMantra::to_mpio2_pio2
static double to_mpio2_pio2(double x)
Definition: L1TkMuMantra.h:92
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
l1t::TkMuon::setMuonDetector
void setMuonDetector(unsigned int detector)
Definition: TkMuon.h:56
L1TkMuMantra::eta_to_theta
static double eta_to_theta(double x)
Definition: L1TkMuMantra.h:87
L1TkMuonProducer::PropState::sigmaEta
float sigmaEta
Definition: L1TkMuonProducer.cc:56
L1TkMuMantraDF::muon_df::charge
int charge
Definition: L1TkMuMantra.h:29
Frameworkfwd.h
L1TkMuonProducer::trackToken_
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
Definition: L1TkMuonProducer.cc:126
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Exception
Definition: hltDiff.cc:246
L1TkMuonProducer::etaMin_
float etaMin_
Definition: L1TkMuonProducer.cc:99
L1TkMuMantraDF::muon_df::pt
double pt
Definition: L1TkMuMantra.h:25
L1TkMuonProducer::bmtfToken_
const edm::EDGetTokenT< RegionalMuonCandBxCollection > bmtfToken_
Definition: L1TkMuonProducer.cc:121
EventSetup.h
L1TkMuonProducer::PropState::sigmaPt
float sigmaPt
Definition: L1TkMuonProducer.cc:55
p3
double p3[4]
Definition: TauolaWrapper.h:91
patCandidatesForDimuonsSequences_cff.matches
matches
Definition: patCandidatesForDimuonsSequences_cff.py:131
L1TkMuonProducer::AlgoType
AlgoType
Definition: L1TkMuonProducer.cc:61
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
matching_factor_phi
static constexpr float matching_factor_phi
Definition: L1TkMuonProducer.cc:38
l1t::TkMuonCollection
std::vector< TkMuon > TkMuonCollection
Definition: TkMuonFwd.h:16
L1TkMuMantra::deg_to_rad
static double deg_to_rad(double x)
Definition: L1TkMuMantra.h:85
L1TkMuonProducer::mantracorr_barr_
std::unique_ptr< L1TkMuMantra > mantracorr_barr_
Definition: L1TkMuonProducer.cc:116
mps_fire.result
result
Definition: mps_fire.py:303
cms::Exception
Definition: Exception.h:70
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
L1TkMuonProducer::mantracorr_endc_
std::unique_ptr< L1TkMuMantra > mantracorr_endc_
Definition: L1TkMuonProducer.cc:118
EDProducer.h
L1TkMuonProducer::propagateToGMT
PropState propagateToGMT(const L1TTTrackType &l1tk) const
Definition: L1TkMuonProducer.cc:530
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
L1TkMuonProducer::~L1TkMuonProducer
~L1TkMuonProducer() override
Definition: L1TkMuonProducer.cc:290
TkMuonFwd.h
L1TkMuonProducer::nStubsmin_
int nStubsmin_
Definition: L1TkMuonProducer.cc:105
L1TkMuonProducer::runOnMTFCollection_v2
void runOnMTFCollection_v2(const edm::Handle< EMTFTrackCollection > &, const edm::Handle< L1TTTrackCollectionType > &, TkMuonCollection &tkMuons) const
Definition: L1TkMuonProducer.cc:482
L1TkMuonProducer::build_tkMuons_from_idxs
void build_tkMuons_from_idxs(TkMuonCollection &tkMuons, const std::vector< int > &matches, const edm::Handle< L1TTTrackCollectionType > &l1tksH, const edm::Handle< RegionalMuonCandBxCollection > &muonH, int detector) const
Definition: L1TkMuonProducer.cc:647
l1t::RegionalMuonCand
Definition: RegionalMuonCand.h:8
deltaPhi.h
mps_fire.dest
dest
Definition: mps_fire.py:179
l1t::TkMuon::setTrkzVtx
void setTrkzVtx(float TrkzVtx)
Definition: TkMuon.h:48
reco::reduceRange
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18