CMS 3D CMS Logo

L1TkGlbMuonProducer.cc
Go to the documentation of this file.
1 // input: L1TkTracks and L1Muon
2 // match the two and produce a collection of L1TkGlbMuonParticle
3 // eventually, this should be made modular and allow to swap out different algorithms
4 
5 // user include files
23 
24 // system include files
25 #include <memory>
26 #include <string>
27 
28 static constexpr float mu_mass = 0.105658369;
29 static constexpr float dr2_cutoff = 0.3;
30 static constexpr float matching_factor_eta = 3.;
31 static constexpr float matching_factor_phi = 4.;
32 static constexpr float min_mu_propagator_p = 3.5;
33 static constexpr float min_mu_propagator_barrel_pT = 3.5;
34 static constexpr float min_mu_propagator_barrel_eta = 1.1;
35 static constexpr float max_mu_propagator_eta = 2.5;
36 static constexpr float sigmaEtaTP_loweta = 0.0288;
37 static constexpr float sigmaEtaTP_mediumeta = 0.025;
38 static constexpr float sigmaEtaTP_higheta = 0.0144;
39 static constexpr float sigmaPhiTP_value = 0.0126;
40 static constexpr float eta_boundary1 = 1.55;
41 static constexpr float eta_boundary2 = 1.65;
42 static constexpr float eta_boundary3 = 2.4;
43 static constexpr float sigmaEta_scaling = 0.100;
44 static constexpr float sigmaPhi_scaling = 0.106;
45 static constexpr float scaling_to_2ndstation = 850.;
46 static constexpr float deta_tkz_scaling = 550.;
47 
48 using namespace l1t;
49 
51 public:
53  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
54 
55  struct PropState { //something simple, imagine it's hardware emulation
56  PropState() : pt(-99), eta(-99), phi(-99), sigmaPt(-99), sigmaEta(-99), sigmaPhi(-99), valid(false) {}
57  float pt;
58  float eta;
59  float phi;
60  float sigmaPt;
61  float sigmaEta;
62  float sigmaPhi;
63  bool valid;
64  };
65 
66  enum AlgoType { kTP = 1, kDynamicWindows = 2, kMantra = 3 };
67 
68  explicit L1TkGlbMuonProducer(const edm::ParameterSet&);
69  ~L1TkGlbMuonProducer() override;
70 
71  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
72 
73 private:
74  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
75  PropState propagateToGMT(const L1TTTrackType& l1tk) const;
76  double sigmaEtaTP(const Muon& mu) const;
77  double sigmaPhiTP(const Muon& mu) const;
78 
79  // the TP algorithm
80  void runOnMuonCollection_v1(const edm::Handle<MuonBxCollection>&,
83 
84  float etaMin_;
85  float etaMax_;
86  float etaBO_; //eta value for barrel-overlap fontier
87  float etaOE_; //eta value for overlap-endcap fontier
88  float zMax_; // |z_track| < zMax_ in cm
89  float chi2Max_;
90  float pTMinTra_;
91  float dRMax_;
92  int nStubsmin_; // minimum number of stubs
96 
99 };
100 
102  : etaMin_((float)iConfig.getParameter<double>("ETAMIN")),
103  etaMax_((float)iConfig.getParameter<double>("ETAMAX")),
104  zMax_((float)iConfig.getParameter<double>("ZMAX")),
105  chi2Max_((float)iConfig.getParameter<double>("CHI2MAX")),
106  pTMinTra_((float)iConfig.getParameter<double>("PTMINTRA")),
107  dRMax_((float)iConfig.getParameter<double>("DRmax")),
108  nStubsmin_(iConfig.getParameter<int>("nStubsmin")),
109  muToken(consumes<MuonBxCollection>(iConfig.getParameter<edm::InputTag>("L1MuonInputTag"))),
110  trackToken_(consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(
111  iConfig.getParameter<edm::InputTag>("L1TrackInputTag"))) {
112  correctGMTPropForTkZ_ = iConfig.getParameter<bool>("correctGMTPropForTkZ");
113 
114  use5ParameterFit_ = iConfig.getParameter<bool>("use5ParameterFit");
115  useTPMatchWindows_ = iConfig.getParameter<bool>("useTPMatchWindows");
116  produces<TkGlbMuonCollection>();
117 }
118 
120 
121 // ------------ method called to produce the data ------------
123  // the L1Mu objects
125  iEvent.getByToken(muToken, l1musH);
126 
127  // the L1Tracks
129  iEvent.getByToken(trackToken_, l1tksH);
130 
131  auto tkMuons = std::make_unique<TkGlbMuonCollection>();
132 
133  // Fill the collection
134  runOnMuonCollection_v1(l1musH, l1tksH, *tkMuons);
135 
136  // put the new track+muon objects in the event!
137  iEvent.put(std::move(tkMuons));
138 };
139 
142  TkGlbMuonCollection& tkMuons) const {
143  const L1TTTrackCollectionType& l1tks = (*l1tksH.product());
144  const MuonBxCollection& l1mus = (*muonH.product());
145 
146  int imu = 0;
147 
148  for (auto l1mu = l1mus.begin(0); l1mu != l1mus.end(0); ++l1mu) { // considering BX = only
149  edm::Ref<MuonBxCollection> l1muRef(muonH, imu);
150  imu++;
151 
152  float l1mu_eta = l1mu->eta();
153  float l1mu_phi = l1mu->phi();
154 
155  float l1mu_feta = std::abs(l1mu_eta);
156  if (l1mu_feta < etaMin_)
157  continue;
158  if (l1mu_feta > etaMax_)
159  continue;
160 
161  float drmin = 999;
162 
163  PropState matchProp;
164  int match_idx = -1;
165  int il1tk = -1;
166 
167  int nTracksMatch = 0;
168 
169  for (const auto& l1tk : l1tks) {
170  il1tk++;
171 
172  float l1tk_pt = l1tk.momentum().perp();
173  if (l1tk_pt < pTMinTra_)
174  continue;
175 
176  float l1tk_z = l1tk.POCA().z();
177  if (std::abs(l1tk_z) > zMax_)
178  continue;
179 
180  float l1tk_chi2 = l1tk.chi2();
181  if (l1tk_chi2 > chi2Max_)
182  continue;
183 
184  int l1tk_nstubs = l1tk.getStubRefs().size();
185  if (l1tk_nstubs < nStubsmin_)
186  continue;
187 
188  float l1tk_eta = l1tk.momentum().eta();
189  float l1tk_phi = l1tk.momentum().phi();
190 
191  float dr2 = reco::deltaR2(l1mu_eta, l1mu_phi, l1tk_eta, l1tk_phi);
192  if (dr2 > dr2_cutoff)
193  continue;
194 
195  nTracksMatch++;
196 
197  const PropState& pstate = propagateToGMT(l1tk);
198  if (!pstate.valid)
199  continue;
200 
201  float dr2prop = reco::deltaR2(l1mu_eta, l1mu_phi, pstate.eta, pstate.phi);
202  // FIXME: check if this matching procedure can be improved with
203  // a pT dependent dR window
204  if (dr2prop < drmin) {
205  drmin = dr2prop;
206  match_idx = il1tk;
207  matchProp = pstate;
208  }
209  } // over l1tks
210 
211  LogDebug("L1TkGlbMuonProducer") << "matching index is " << match_idx;
212  if (match_idx >= 0) {
213  const L1TTTrackType& matchTk = l1tks[match_idx];
214 
215  float sigmaEta = sigmaEtaTP(*l1mu);
216  float sigmaPhi = sigmaPhiTP(*l1mu);
217 
218  float etaCut = matching_factor_eta * sqrt(sigmaEta * sigmaEta + matchProp.sigmaEta * matchProp.sigmaEta);
219  float phiCut = matching_factor_phi * sqrt(sigmaPhi * sigmaPhi + matchProp.sigmaPhi * matchProp.sigmaPhi);
220 
221  float dEta = std::abs(matchProp.eta - l1mu_eta);
222  float dPhi = std::abs(deltaPhi(matchProp.phi, l1mu_phi));
223 
224  bool matchCondition = useTPMatchWindows_ ? dEta < etaCut && dPhi < phiCut : drmin < dRMax_;
225 
226  if (matchCondition) {
227  edm::Ptr<L1TTTrackType> l1tkPtr(l1tksH, match_idx);
228 
229  const auto& p3 = matchTk.momentum();
230  float p4e = sqrt(mu_mass * mu_mass + p3.mag2());
231 
232  math::XYZTLorentzVector l1tkp4(p3.x(), p3.y(), p3.z(), p4e);
233 
234  const auto& tkv3 = matchTk.POCA();
235  math::XYZPoint v3(tkv3.x(), tkv3.y(), tkv3.z()); // why is this defined?
236 
237  float trkisol = -999;
238 
239  TkGlbMuon l1tkmu(l1tkp4, l1muRef, l1tkPtr, trkisol);
240 
241  l1tkmu.setTrkzVtx((float)tkv3.z());
242  l1tkmu.setdR(drmin);
243  l1tkmu.setNTracksMatched(nTracksMatch);
244  tkMuons.push_back(l1tkmu);
245  }
246  }
247  } //over l1mus
248 }
249 
250 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
252  // L1TkGlbMuons
254  desc.add<edm::InputTag>("L1MuonInputTag", edm::InputTag("simGmtStage2Digis"));
255  desc.add<edm::InputTag>("L1TrackInputTag", edm::InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks"));
256  desc.add<double>("ETAMIN", 0);
257  desc.add<double>("ETAMAX", 5.0);
258  desc.add<double>("ZMAX", 25.0);
259  desc.add<double>("CHI2MAX", 100.0);
260  desc.add<double>("PTMINTRA", 2.0);
261  desc.add<double>("DRmax", 0.5);
262  desc.add<int>("nStubsmin", 4);
263  desc.add<bool>("correctGMTPropForTkZ", true);
264  desc.add<bool>("use5ParameterFit", false);
265  desc.add<bool>("useTPMatchWindows", true);
266  descriptions.add("L1TkGlbMuons", desc);
267  // or use the following to generate the label from the module's C++ type
268  //descriptions.addWithDefaultLabel(desc);
269 }
270 
272  auto p3 = tk.momentum();
273  float tk_pt = p3.perp();
274  float tk_p = p3.mag();
275  float tk_eta = p3.eta();
276  float tk_aeta = std::abs(tk_eta);
277  float tk_phi = p3.phi();
278  float tk_q = tk.rInv() > 0 ? 1. : -1.;
279  float tk_z = tk.POCA().z();
281  tk_z = 0;
282 
284  if (tk_p < min_mu_propagator_p)
285  return dest;
287  return dest;
288  if (tk_aeta > max_mu_propagator_eta)
289  return dest;
290 
291  //0th order:
292  dest.valid = true;
293 
294  float dzCorrPhi = 1.;
295  float deta = 0;
296  float etaProp = tk_aeta;
297 
298  if (tk_aeta < min_mu_propagator_barrel_eta) {
300  deta = tk_z / deta_tkz_scaling / cosh(tk_aeta);
301  } else {
302  float delta = tk_z / scaling_to_2ndstation; //roughly scales as distance to 2nd station
303  if (tk_eta > 0)
304  delta *= -1;
305  dzCorrPhi = 1. + delta;
306 
307  float zOzs = tk_z / scaling_to_2ndstation;
308  if (tk_eta > 0)
309  deta = zOzs / (1. - zOzs);
310  else
311  deta = zOzs / (1. + zOzs);
312  deta = deta * tanh(tk_eta);
313  }
314  float resPhi = tk_phi - 1.464 * tk_q * cosh(1.7) / cosh(etaProp) / tk_pt * dzCorrPhi - M_PI / 144.;
315  resPhi = reco::reduceRange(resPhi);
316 
317  dest.eta = tk_eta + deta;
318  dest.phi = resPhi;
319  dest.pt = tk_pt; //not corrected for eloss
320 
321  dest.sigmaEta = sigmaEta_scaling / tk_pt; //multiple scattering term
322  dest.sigmaPhi = sigmaPhi_scaling / tk_pt; //need a better estimate for these
323  return dest;
324 }
325 
326 double L1TkGlbMuonProducer::sigmaEtaTP(const Muon& l1mu) const {
327  float l1mu_eta = l1mu.eta();
328  if (std::abs(l1mu_eta) <= eta_boundary1)
329  return sigmaEtaTP_loweta;
330  else if (std::abs(l1mu_eta) > eta_boundary1 && std::abs(l1mu_eta) <= eta_boundary2)
331  return sigmaEtaTP_mediumeta;
332  else if (std::abs(l1mu_eta) > eta_boundary2 && std::abs(l1mu_eta) <= eta_boundary3)
333  return sigmaEtaTP_higheta;
334  return sigmaEtaTP_loweta;
335 }
336 
337 double L1TkGlbMuonProducer::sigmaPhiTP(const Muon& mu) const { return sigmaPhiTP_value; }
338 
339 //define this as a plug-in
double sigmaEtaTP(const Muon &mu) const
std::vector< TkGlbMuon > TkGlbMuonCollection
Definition: TkGlbMuonFwd.h:16
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static constexpr float dr2_cutoff
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
T z() const
Definition: PV3DBase.h:61
static constexpr float scaling_to_2ndstation
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< MuonBxCollection > muToken
T const * product() const
Definition: Handle.h:70
static constexpr float sigmaEtaTP_higheta
static constexpr float matching_factor_phi
delete x;
Definition: CaloConfig.h:22
GlobalVector momentum() const
Track momentum.
Definition: TTTrack.h:295
const_iterator begin(int bx) const
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
L1TkGlbMuonProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
static constexpr float sigmaEta_scaling
Definition: Muon.py:1
T sqrt(T t)
Definition: SSEVec.h:19
static constexpr float eta_boundary3
double sigmaPhiTP(const Muon &mu) const
static constexpr float deta_tkz_scaling
void setTrkzVtx(float TrkzVtx)
Definition: TkGlbMuon.h:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr float min_mu_propagator_barrel_eta
double rInv() const
Track curvature.
Definition: TTTrack.h:300
void runOnMuonCollection_v1(const edm::Handle< MuonBxCollection > &, const edm::Handle< L1TTTrackCollectionType > &, TkGlbMuonCollection &tkMuons) const
static constexpr float min_mu_propagator_p
static constexpr float sigmaPhi_scaling
static constexpr float min_mu_propagator_barrel_pT
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static constexpr float matching_factor_eta
static constexpr float sigmaPhiTP_value
#define M_PI
static constexpr float eta_boundary1
void setdR(float dR)
Definition: TkGlbMuon.h:50
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static constexpr float mu_mass
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void setNTracksMatched(int nTracksMatch)
Definition: TkGlbMuon.h:51
static constexpr float eta_boundary2
const_iterator end(int bx) const
HLT enums.
PropState propagateToGMT(const L1TTTrackType &l1tk) const
static constexpr float max_mu_propagator_eta
std::vector< L1TTTrackType > L1TTTrackCollectionType
GlobalPoint POCA() const
POCA.
Definition: TTTrack.h:335
def move(src, dest)
Definition: eostools.py:511
static constexpr float sigmaEtaTP_mediumeta
#define LogDebug(id)
static constexpr float sigmaEtaTP_loweta
double eta() const final
momentum pseudorapidity