CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
L1TkMuMantra Class Reference

#include <L1TkMuMantra.h>

Public Member Functions

std::vector< int > find_match (const std::vector< L1TkMuMantraDF::track_df > &tracks, const std::vector< L1TkMuMantraDF::muon_df > &muons)
 
 L1TkMuMantra (const std::vector< double > &bounds, TFile *fIn_theta, TFile *fIn_phi, std::string name)
 
void relax_windows (double &low, double cent, double &high)
 
void set_safety_factor (float sf_l, float sf_h)
 
void setArbitrationType (std::string type)
 
int sign (double x)
 
void test (double eta, double pt)
 
 ~L1TkMuMantra ()
 

Static Public Member Functions

static double eta_to_theta (double x)
 
static std::vector< double > prepare_corr_bounds (std::string fname, std::string hname)
 
static double to_mpio2_pio2 (double x)
 

Private Types

enum  sortParType { kMaxPt, kMinDeltaPt }
 

Private Member Functions

int findBin (double val)
 

Private Attributes

std::vector< double > bounds_
 
double max_chi2 = 100
 
int min_nstubs = 4
 
std::string name_
 
int nbins_
 
float safety_factor_h_
 
float safety_factor_l_
 
sortParType sort_type_
 
int verbosity_ = 0
 
std::vector< MuMatchWindowwdws_phi_
 
std::vector< MuMatchWindowwdws_theta_
 

Detailed Description

Definition at line 51 of file L1TkMuMantra.h.

Member Enumeration Documentation

◆ sortParType

Enumerator
kMaxPt 
kMinDeltaPt 

Definition at line 115 of file L1TkMuMantra.h.

115  {
116  kMaxPt, // pick the highest pt track matched
117  kMinDeltaPt // pick the track with the smallest pt difference w.r.t the muon
118  };

Constructor & Destructor Documentation

◆ L1TkMuMantra()

L1TkMuMantra::L1TkMuMantra ( const std::vector< double > &  bounds,
TFile *  fIn_theta,
TFile *  fIn_phi,
std::string  name = "mantra" 
)

Definition at line 10 of file L1TkMuMantra.cc.

References bounds_, Exception, cuy::ib, kMaxPt, LogTrace, Skims_PA_cff::name, name_, nbins_, safety_factor_h_, safety_factor_l_, sort_type_, AlCaHLTBitMon_QueryRunRegistry::string, cond::impl::to_string(), verbosity_, wdws_phi_, and wdws_theta_.

14  : wdws_theta_(bounds.size() - 1, MuMatchWindow()), wdws_phi_(bounds.size() - 1, MuMatchWindow()) {
15  name_ = name;
16 
17  safety_factor_l_ = 0.0;
18  safety_factor_h_ = 0.0;
19 
21 
22  // copy boundaries
23  nbins_ = bounds.size() - 1;
24  bounds_ = bounds;
25 
26  // now load in memory the TF1 fits
27 
28  for (int ib = 0; ib < nbins_; ++ib) {
29  std::string wdn;
30  std::string nml;
31  std::string nmc;
32  std::string nmh;
33  TF1* fl;
34  TF1* fc;
35  TF1* fh;
36 
37  wdn = name_ + std::string("_wdw_theta_") + std::to_string(ib + 1);
38  nml = std::string("fit_low_") + std::to_string(ib + 1);
39  nmc = std::string("fit_cent_") + std::to_string(ib + 1);
40  nmh = std::string("fit_high_") + std::to_string(ib + 1);
41 
42  fl = (TF1*)fIn_theta->Get(nml.c_str());
43  fc = (TF1*)fIn_theta->Get(nmc.c_str());
44  fh = (TF1*)fIn_theta->Get(nmh.c_str());
45  if (fl == nullptr || fc == nullptr || fh == nullptr) {
46  if (verbosity_ > 0) {
47  LogTrace("L1TkMuMantra") << "... fit theta low : " << fl << std::endl;
48  LogTrace("L1TkMuMantra") << "... fit theta cent : " << fc << std::endl;
49  LogTrace("L1TkMuMantra") << "... fit theta high : " << fh << std::endl;
50  }
51  throw cms::Exception("L1TkMuMantra") << "TF1 named " << nml << " or " << nmc << " or " << nmh
52  << " not found in file " << fIn_theta->GetName() << ".\n";
53  }
54  wdws_theta_.at(ib).SetName(wdn);
55  wdws_theta_.at(ib).SetLower(fl);
56  wdws_theta_.at(ib).SetCentral(fc);
57  wdws_theta_.at(ib).SetUpper(fh);
58 
59  wdn = name_ + std::string("_wdw_phi_") + std::to_string(ib + 1);
60  nml = std::string("fit_low_") + std::to_string(ib + 1);
61  nmc = std::string("fit_cent_") + std::to_string(ib + 1);
62  nmh = std::string("fit_high_") + std::to_string(ib + 1);
63  fl = (TF1*)fIn_phi->Get(nml.c_str());
64  fc = (TF1*)fIn_phi->Get(nmc.c_str());
65  fh = (TF1*)fIn_phi->Get(nmh.c_str());
66  if (fl == nullptr || fc == nullptr || fh == nullptr) {
67  if (verbosity_ > 0) {
68  LogTrace("L1TkMuMantra") << "... fit phi low : " << fl << std::endl;
69  LogTrace("L1TkMuMantra") << "... fit phi cent : " << fc << std::endl;
70  LogTrace("L1TkMuMantra") << "... fit phi high : " << fh << std::endl;
71  }
72  throw cms::Exception("L1TkMuMantra") << "TF1 named " << nml << " or " << nmc << " or " << nmh
73  << " not found in file " << fIn_theta->GetName() << ".\n";
74  }
75  wdws_phi_.at(ib).SetName(wdn);
76  wdws_phi_.at(ib).SetLower(fl);
77  wdws_phi_.at(ib).SetCentral(fc);
78  wdws_phi_.at(ib).SetUpper(fh);
79  }
80 }
sortParType sort_type_
Definition: L1TkMuMantra.h:120
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::string name_
Definition: L1TkMuMantra.h:102
#define LogTrace(id)
std::vector< MuMatchWindow > wdws_phi_
Definition: L1TkMuMantra.h:107
float safety_factor_h_
Definition: L1TkMuMantra.h:113
float safety_factor_l_
Definition: L1TkMuMantra.h:112
std::vector< MuMatchWindow > wdws_theta_
Definition: L1TkMuMantra.h:106
std::vector< double > bounds_
Definition: L1TkMuMantra.h:105
ib
Definition: cuy.py:661

◆ ~L1TkMuMantra()

L1TkMuMantra::~L1TkMuMantra ( )
inline

Definition at line 54 of file L1TkMuMantra.h.

54 {};

Member Function Documentation

◆ eta_to_theta()

static double L1TkMuMantra::eta_to_theta ( double  x)
inlinestatic

Definition at line 85 of file L1TkMuMantra.h.

References JetChargeProducer_cfi::exp, and x.

Referenced by L1TkMuonProducer::product_to_muvec(), and L1TkMuonProducer::product_to_trkvec().

85  {
86  // give theta in rad
87  return (2. * atan(exp(-1. * x)));
88  }

◆ find_match()

std::vector< int > L1TkMuMantra::find_match ( const std::vector< L1TkMuMantraDF::track_df > &  tracks,
const std::vector< L1TkMuMantraDF::muon_df > &  muons 
)

Definition at line 117 of file L1TkMuMantra.cc.

References funct::abs(), L1TkMuMantraDF::track_df::charge, L1TkMuMantraDF::track_df::chi2, reco::deltaPhi(), L1TkMuMantraDF::track_df::eta, findBin(), kMaxPt, kMinDeltaPt, max_chi2, min_nstubs, amptDefaultParameters_cff::mu, PDWG_BPHSkim_cff::muons, L1TkMuMantraDF::track_df::nstubs, L1TkMuMantraDF::track_df::phi, Pi, L1TkMuMantraDF::track_df::pt, relax_windows(), mps_fire::result, sign(), jetUpdater_cfi::sort, sort_type_, L1TkMuMantraDF::track_df::theta, tracks, parallelization::uint, wdws_phi_, and wdws_theta_.

117  {
118  std::vector<int> result(muons.size(), -1); // init all TkMu to index -1
119  for (uint imu = 0; imu < muons.size(); ++imu) {
120  muon_df mu = muons.at(imu);
121  std::vector<std::pair<double, int>> matched_trks; // sort_par, idx
122  for (uint itrk = 0; itrk < tracks.size(); ++itrk) {
123  // preselection of tracks
124  track_df trk = tracks.at(itrk);
125  if (trk.chi2 >= max_chi2)
126  continue; // require trk.chi2 < max_chi2
127  if (trk.nstubs < min_nstubs)
128  continue; // require trk.nstubs >= min_nstubs
129 
130  double dphi_charge = reco::deltaPhi(trk.phi, mu.phi) * trk.charge;
131  // sign from theta, to avoid division by 0
132  double dtheta_endc = (mu.theta - trk.theta) * sign(mu.theta);
133  if (sign(mu.theta) != sign(trk.theta)) {
134  // crossing the barrel -> remove 180 deg to the theta of the neg candidate to avoid jumps at eta = 0
135  dtheta_endc -= TMath::Pi();
136  }
137 
138  // lookup the values
139  int ibin = findBin(std::abs(trk.eta));
140 
141  double phi_low = wdws_phi_.at(ibin).bound_low(trk.pt);
142  double phi_cent = wdws_phi_.at(ibin).bound_cent(trk.pt);
143  double phi_high = wdws_phi_.at(ibin).bound_high(trk.pt);
144  relax_windows(phi_low, phi_cent, phi_high); // apply the safety factor
145  bool in_phi = (dphi_charge > phi_low && dphi_charge < phi_high);
146 
147  double theta_low = wdws_theta_.at(ibin).bound_low(trk.pt);
148  double theta_cent = wdws_theta_.at(ibin).bound_cent(trk.pt);
149  double theta_high = wdws_theta_.at(ibin).bound_high(trk.pt);
150  relax_windows(theta_low, theta_cent, theta_high); // apply the safety factor
151  bool in_theta = (dtheta_endc > theta_low && dtheta_endc < theta_high);
152 
153  if (in_phi && in_theta) {
154  double sort_par = 99999;
155  if (sort_type_ == kMaxPt)
156  sort_par = trk.pt;
157  else if (sort_type_ == kMinDeltaPt) {
158  // trk.pt should always be > 0, but put this protection just in case
159  sort_par = (trk.pt > 0 ? std::abs(1. - (mu.pt / trk.pt)) : 0);
160  }
161  matched_trks.emplace_back(sort_par, itrk);
162  }
163  }
164 
165  // choose out of the matched tracks the best one
166  if (!matched_trks.empty()) {
167  sort(matched_trks.begin(), matched_trks.end());
168  int ibest = 99999;
169  if (sort_type_ == kMaxPt)
170  ibest = matched_trks.rbegin()->second; // sorted low to high -> take last for highest pT (rbegin)
171  else if (sort_type_ == kMinDeltaPt)
172  ibest = matched_trks.begin()->second; // sorted low to high -> take first for min pT distance (begin)
173  result.at(imu) = ibest;
174  }
175  }
176 
177  return result;
178 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
const double Pi
int findBin(double val)
Definition: L1TkMuMantra.cc:82
sortParType sort_type_
Definition: L1TkMuMantra.h:120
double max_chi2
Definition: L1TkMuMantra.h:110
void relax_windows(double &low, double cent, double &high)
std::vector< MuMatchWindow > wdws_phi_
Definition: L1TkMuMantra.h:107
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int sign(double x)
Definition: L1TkMuMantra.h:73
auto const & tracks
cannot be loose
std::vector< MuMatchWindow > wdws_theta_
Definition: L1TkMuMantra.h:106

◆ findBin()

int L1TkMuMantra::findBin ( double  val)
private

Definition at line 82 of file L1TkMuMantra.cc.

References bounds_, cuy::ib, LogTrace, nbins_, parallelization::uint, heppy_batch::val, and verbosity_.

Referenced by find_match(), and test().

82  {
83  // FIXME: not the most efficient, nor the most elegant implementation for now
84  if (val < bounds_.at(0))
85  return 0;
86  if (val >= bounds_.back())
87  return (nbins_ - 1); // i.e. bounds_size() -2
88 
89  for (uint ib = 0; ib < bounds_.size() - 1; ++ib) {
90  if (val >= bounds_.at(ib) && val < bounds_.at(ib + 1))
91  return ib;
92  }
93 
94  if (verbosity_ > 0)
95  LogTrace("L1TkMuMantra") << "Something strange happened at val " << val << std::endl;
96  return 0;
97 }
#define LogTrace(id)
std::vector< double > bounds_
Definition: L1TkMuMantra.h:105
ib
Definition: cuy.py:661

◆ prepare_corr_bounds()

std::vector< double > L1TkMuMantra::prepare_corr_bounds ( std::string  fname,
std::string  hname 
)
static

Definition at line 201 of file L1TkMuMantra.cc.

References Exception, alignmentValidation::fname, and cuy::ib.

Referenced by L1TkMuonProducer::L1TkMuonProducer().

201  {
202  // find the boundaries of the match windoww
203  TFile* fIn = TFile::Open(fname.c_str());
204  if (fIn == nullptr) {
205  throw cms::Exception("L1TkMuMantra") << "Can't find file " << fname << " to derive bounds.\n";
206  }
207  TH2* h_test = (TH2*)fIn->Get(hname.c_str());
208  if (h_test == nullptr) {
209  throw cms::Exception("L1TkMuMantra") << "Can't find histo " << hname << " in file " << fname
210  << " to derive bounds.\n";
211  }
212 
213  int nbds = h_test->GetNbinsY() + 1;
214  std::vector<double> bounds(nbds);
215  for (int ib = 0; ib < nbds; ++ib) {
216  bounds.at(ib) = h_test->GetYaxis()->GetBinLowEdge(ib + 1);
217  }
218  fIn->Close();
219  return bounds;
220 }
string fname
main script
ib
Definition: cuy.py:661

◆ relax_windows()

void L1TkMuMantra::relax_windows ( double &  low,
double  cent,
double &  high 
)

Definition at line 180 of file L1TkMuMantra.cc.

References LaserClient_cfi::high, LaserClient_cfi::low, safety_factor_h_, and safety_factor_l_.

Referenced by find_match().

180  {
181  double delta_high = high - cent;
182  double delta_low = cent - low;
183 
184  high = high + safety_factor_h_ * delta_high;
185  low = low - safety_factor_l_ * delta_low;
186 
187  return;
188 }
float safety_factor_h_
Definition: L1TkMuMantra.h:113
float safety_factor_l_
Definition: L1TkMuMantra.h:112

◆ set_safety_factor()

void L1TkMuMantra::set_safety_factor ( float  sf_l,
float  sf_h 
)
inline

Definition at line 64 of file L1TkMuMantra.h.

References LogTrace, name_, safety_factor_h_, safety_factor_l_, and verbosity_.

64  {
65  safety_factor_l_ = sf_l;
66  safety_factor_h_ = sf_h;
67  if (verbosity_ > 0)
68  LogTrace("L1TkMuMantra") << name_ << " safety factor LOW is " << safety_factor_l_ << std::endl;
69  if (verbosity_ > 0)
70  LogTrace("L1TkMuMantra") << name_ << " safety factor HIGH is " << safety_factor_h_ << std::endl;
71  }
std::string name_
Definition: L1TkMuMantra.h:102
#define LogTrace(id)
float safety_factor_h_
Definition: L1TkMuMantra.h:113
float safety_factor_l_
Definition: L1TkMuMantra.h:112

◆ setArbitrationType()

void L1TkMuMantra::setArbitrationType ( std::string  type)

Definition at line 190 of file L1TkMuMantra.cc.

References Exception, kMaxPt, kMinDeltaPt, LogTrace, sort_type_, and verbosity_.

190  {
191  if (verbosity_ > 0)
192  LogTrace("L1TkMuMantra") << "L1TkMuMantra : setting arbitration type to " << type << std::endl;
193  if (type == "MaxPt")
194  sort_type_ = kMaxPt;
195  else if (type == "MinDeltaPt")
197  else
198  throw cms::Exception("L1TkMuMantra") << "setArbitrationType : cannot understand the arbitration type passed.\n";
199 }
sortParType sort_type_
Definition: L1TkMuMantra.h:120
#define LogTrace(id)

◆ sign()

int L1TkMuMantra::sign ( double  x)
inline

Definition at line 73 of file L1TkMuMantra.h.

References x.

Referenced by find_match().

73  {
74  if (x == 0)
75  return 1;
76  return (0 < x) - (x < 0);
77  }

◆ test()

void L1TkMuMantra::test ( double  eta,
double  pt 
)

Definition at line 99 of file L1TkMuMantra.cc.

References PVValHelper::eta, findBin(), LogTrace, DiDispStaMuonMonitor_cfi::pt, wdws_phi_, and wdws_theta_.

Referenced by edmIntegrityCheck.IntegrityCheck::report(), and edmIntegrityCheck.IntegrityCheck::structured().

99  {
100  int ibin = findBin(eta);
101 
102  LogTrace("L1TkMuMantra") << " ---- eta : " << eta << " pt: " << pt << std::endl;
103  LogTrace("L1TkMuMantra") << " ---- bin " << ibin << std::endl;
104  LogTrace("L1TkMuMantra") << " ---- "
105  << "- low_phi : " << wdws_phi_.at(ibin).bound_low(pt)
106  << "- cent_phi : " << wdws_phi_.at(ibin).bound_cent(pt)
107  << "- high_phi : " << wdws_phi_.at(ibin).bound_high(pt) << std::endl;
108 
109  LogTrace("L1TkMuMantra") << " ---- "
110  << "- low_theta : " << wdws_theta_.at(ibin).bound_low(pt)
111  << "- cent_theta : " << wdws_theta_.at(ibin).bound_cent(pt)
112  << "- high_theta : " << wdws_theta_.at(ibin).bound_high(pt) << std::endl;
113 
114  return;
115 }
int findBin(double val)
Definition: L1TkMuMantra.cc:82
#define LogTrace(id)
std::vector< MuMatchWindow > wdws_phi_
Definition: L1TkMuMantra.h:107
std::vector< MuMatchWindow > wdws_theta_
Definition: L1TkMuMantra.h:106

◆ to_mpio2_pio2()

static double L1TkMuMantra::to_mpio2_pio2 ( double  x)
inlinestatic

Definition at line 90 of file L1TkMuMantra.h.

References M_PI, and x.

Referenced by L1TkMuonProducer::product_to_muvec(), and L1TkMuonProducer::product_to_trkvec().

90  {
91  // put the angle in radians between -pi/2 and pi/2
92  while (x >= 0.5 * M_PI)
93  x -= M_PI;
94  while (x < -0.5 * M_PI)
95  x += M_PI;
96  return x;
97  }
#define M_PI

Member Data Documentation

◆ bounds_

std::vector<double> L1TkMuMantra::bounds_
private

Definition at line 105 of file L1TkMuMantra.h.

Referenced by findBin(), and L1TkMuMantra().

◆ max_chi2

double L1TkMuMantra::max_chi2 = 100
private

Definition at line 110 of file L1TkMuMantra.h.

Referenced by find_match().

◆ min_nstubs

int L1TkMuMantra::min_nstubs = 4
private

Definition at line 109 of file L1TkMuMantra.h.

Referenced by find_match().

◆ name_

std::string L1TkMuMantra::name_
private

Definition at line 102 of file L1TkMuMantra.h.

Referenced by L1TkMuMantra(), and set_safety_factor().

◆ nbins_

int L1TkMuMantra::nbins_
private

Definition at line 104 of file L1TkMuMantra.h.

Referenced by findBin(), and L1TkMuMantra().

◆ safety_factor_h_

float L1TkMuMantra::safety_factor_h_
private

Definition at line 113 of file L1TkMuMantra.h.

Referenced by L1TkMuMantra(), relax_windows(), and set_safety_factor().

◆ safety_factor_l_

float L1TkMuMantra::safety_factor_l_
private

Definition at line 112 of file L1TkMuMantra.h.

Referenced by L1TkMuMantra(), relax_windows(), and set_safety_factor().

◆ sort_type_

sortParType L1TkMuMantra::sort_type_
private

Definition at line 120 of file L1TkMuMantra.h.

Referenced by find_match(), L1TkMuMantra(), and setArbitrationType().

◆ verbosity_

int L1TkMuMantra::verbosity_ = 0
private

Definition at line 122 of file L1TkMuMantra.h.

Referenced by findBin(), L1TkMuMantra(), set_safety_factor(), and setArbitrationType().

◆ wdws_phi_

std::vector<MuMatchWindow> L1TkMuMantra::wdws_phi_
private

Definition at line 107 of file L1TkMuMantra.h.

Referenced by find_match(), L1TkMuMantra(), and test().

◆ wdws_theta_

std::vector<MuMatchWindow> L1TkMuMantra::wdws_theta_
private

Definition at line 106 of file L1TkMuMantra.h.

Referenced by find_match(), L1TkMuMantra(), and test().