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 deg_to_rad (double x)
 
static double eta_to_theta (double x)
 
static std::vector< double > prepare_corr_bounds (std::string fname, std::string hname)
 
static double to_mpi_pi (double x)
 
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 125 of file L1TkMuMantra.h.

125  {
126  kMaxPt, // pick the highest pt track matched
127  kMinDeltaPt // pick the track with the smallest pt difference w.r.t the muon
128  };

Constructor & Destructor Documentation

◆ L1TkMuMantra()

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

Definition at line 8 of file L1TkMuMantra.cc.

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

References bounds_, Exception, benchmark_cfg::fc, cuy::ib, kMaxPt, LogTrace, Skims_PA_cff::name, name_, nbins_, safety_factor_h_, safety_factor_l_, sort_type_, AlCaHLTBitMon_QueryRunRegistry::string, tools::TF1, verbosity_, wdws_phi_, and wdws_theta_.

◆ ~L1TkMuMantra()

L1TkMuMantra::~L1TkMuMantra ( )
inline

Definition at line 54 of file L1TkMuMantra.h.

54 {};

Member Function Documentation

◆ deg_to_rad()

static double L1TkMuMantra::deg_to_rad ( double  x)
inlinestatic

Definition at line 85 of file L1TkMuMantra.h.

85 { return (x * angle_units::degPerRad); }

References angle_units::degPerRad, and x.

Referenced by L1TkMuonProducer::product_to_muvec().

◆ eta_to_theta()

static double L1TkMuMantra::eta_to_theta ( double  x)
inlinestatic

Definition at line 87 of file L1TkMuMantra.h.

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

References JetChargeProducer_cfi::exp, and x.

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

◆ 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 115 of file L1TkMuMantra.cc.

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

References funct::abs(), L1TkMuMantraDF::track_df::charge, L1TkMuMantraDF::track_df::chi2, 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(), sort_type_, L1TkMuMantraDF::track_df::theta, to_mpi_pi(), PDWG_EXOHSCP_cff::tracks, parallelization::uint, wdws_phi_, and wdws_theta_.

◆ findBin()

int L1TkMuMantra::findBin ( double  val)
private

Definition at line 80 of file L1TkMuMantra.cc.

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

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

Referenced by find_match(), and test().

◆ prepare_corr_bounds()

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

Definition at line 199 of file L1TkMuMantra.cc.

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

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

Referenced by L1TkMuonProducer::L1TkMuonProducer().

◆ relax_windows()

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

Definition at line 178 of file L1TkMuMantra.cc.

178  {
179  double delta_high = high - cent;
180  double delta_low = cent - low;
181 
182  high = high + safety_factor_h_ * delta_high;
183  low = low - safety_factor_l_ * delta_low;
184 
185  return;
186 }

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

Referenced by find_match().

◆ set_safety_factor()

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

Definition at line 64 of file L1TkMuMantra.h.

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  }

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

◆ setArbitrationType()

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

Definition at line 188 of file L1TkMuMantra.cc.

188  {
189  if (verbosity_ > 0)
190  LogTrace("L1TkMuMantra") << "L1TkMuMantra : setting arbitration type to " << type << std::endl;
191  if (type == "MaxPt")
192  sort_type_ = kMaxPt;
193  else if (type == "MinDeltaPt")
195  else
196  throw cms::Exception("L1TkMuMantra") << "setArbitrationType : cannot understand the arbitration type passed.\n";
197 }

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

◆ sign()

int L1TkMuMantra::sign ( double  x)
inline

Definition at line 73 of file L1TkMuMantra.h.

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

References x.

Referenced by find_match().

◆ test()

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

Definition at line 97 of file L1TkMuMantra.cc.

97  {
98  int ibin = findBin(eta);
99 
100  LogTrace("L1TkMuMantra") << " ---- eta : " << eta << " pt: " << pt << std::endl;
101  LogTrace("L1TkMuMantra") << " ---- bin " << ibin << std::endl;
102  LogTrace("L1TkMuMantra") << " ---- "
103  << "- low_phi : " << wdws_phi_.at(ibin).bound_low(pt)
104  << "- cent_phi : " << wdws_phi_.at(ibin).bound_cent(pt)
105  << "- high_phi : " << wdws_phi_.at(ibin).bound_high(pt) << std::endl;
106 
107  LogTrace("L1TkMuMantra") << " ---- "
108  << "- low_theta : " << wdws_theta_.at(ibin).bound_low(pt)
109  << "- cent_theta : " << wdws_theta_.at(ibin).bound_cent(pt)
110  << "- high_theta : " << wdws_theta_.at(ibin).bound_high(pt) << std::endl;
111 
112  return;
113 }

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

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

◆ to_mpi_pi()

static double L1TkMuMantra::to_mpi_pi ( double  x)
inlinestatic

Definition at line 101 of file L1TkMuMantra.h.

101  {
102  while (x >= M_PI)
103  x -= 2. * M_PI;
104  while (x < -M_PI)
105  x += 2. * M_PI;
106  return x;
107  }

References M_PI, and x.

Referenced by find_match().

◆ to_mpio2_pio2()

static double L1TkMuMantra::to_mpio2_pio2 ( double  x)
inlinestatic

Definition at line 92 of file L1TkMuMantra.h.

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

References M_PI, and x.

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

Member Data Documentation

◆ bounds_

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

Definition at line 115 of file L1TkMuMantra.h.

Referenced by findBin(), and L1TkMuMantra().

◆ max_chi2

double L1TkMuMantra::max_chi2 = 100
private

Definition at line 120 of file L1TkMuMantra.h.

Referenced by find_match().

◆ min_nstubs

int L1TkMuMantra::min_nstubs = 4
private

Definition at line 119 of file L1TkMuMantra.h.

Referenced by find_match().

◆ name_

std::string L1TkMuMantra::name_
private

Definition at line 112 of file L1TkMuMantra.h.

Referenced by L1TkMuMantra(), and set_safety_factor().

◆ nbins_

int L1TkMuMantra::nbins_
private

Definition at line 114 of file L1TkMuMantra.h.

Referenced by findBin(), and L1TkMuMantra().

◆ safety_factor_h_

float L1TkMuMantra::safety_factor_h_
private

Definition at line 123 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 122 of file L1TkMuMantra.h.

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

◆ sort_type_

sortParType L1TkMuMantra::sort_type_
private

Definition at line 130 of file L1TkMuMantra.h.

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

◆ verbosity_

int L1TkMuMantra::verbosity_ = 0
private

Definition at line 132 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 117 of file L1TkMuMantra.h.

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

◆ wdws_theta_

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

Definition at line 116 of file L1TkMuMantra.h.

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

PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
L1TkMuMantra::safety_factor_l_
float safety_factor_l_
Definition: L1TkMuMantra.h:122
L1TkMuMantra::max_chi2
double max_chi2
Definition: L1TkMuMantra.h:120
L1TkMuMantra::wdws_theta_
std::vector< MuMatchWindow > wdws_theta_
Definition: L1TkMuMantra.h:116
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
L1TkMuMantraDF::track_df
Definition: L1TkMuMantra.h:14
DDAxes::x
L1TkMuMantraDF::track_df::charge
int charge
Definition: L1TkMuMantra.h:21
L1TkMuMantraDF::track_df::nstubs
int nstubs
Definition: L1TkMuMantra.h:19
L1TkMuMantra::kMaxPt
Definition: L1TkMuMantra.h:126
tools.TF1
TF1
Definition: tools.py:23
parallelization.uint
uint
Definition: parallelization.py:124
L1TkMuMantra::sort_type_
sortParType sort_type_
Definition: L1TkMuMantra.h:130
L1TkMuMantra::wdws_phi_
std::vector< MuMatchWindow > wdws_phi_
Definition: L1TkMuMantra.h:117
L1TkMuMantra::relax_windows
void relax_windows(double &low, double cent, double &high)
Definition: L1TkMuMantra.cc:178
angle_units::degPerRad
constexpr long double degPerRad
Definition: angle_units.h:9
L1TkMuMantra::kMinDeltaPt
Definition: L1TkMuMantra.h:127
PVValHelper::eta
Definition: PVValidationHelpers.h:69
benchmark_cfg.fc
fc
Definition: benchmark_cfg.py:15
L1TkMuMantra::bounds_
std::vector< double > bounds_
Definition: L1TkMuMantra.h:115
L1TkMuMantra::safety_factor_h_
float safety_factor_h_
Definition: L1TkMuMantra.h:123
MuMatchWindow
Definition: MuMatchWindow.h:17
L1TkMuMantraDF::track_df::phi
double phi
Definition: L1TkMuMantra.h:18
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1TkMuMantraDF::track_df::pt
double pt
Definition: L1TkMuMantra.h:15
L1TkMuMantraDF::track_df::theta
double theta
Definition: L1TkMuMantra.h:17
L1TkMuMantra::findBin
int findBin(double val)
Definition: L1TkMuMantra.cc:80
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
L1TkMuMantraDF::track_df::chi2
double chi2
Definition: L1TkMuMantra.h:20
cuy.ib
ib
Definition: cuy.py:662
L1TkMuMantraDF::muon_df
Definition: L1TkMuMantra.h:24
L1TkMuMantra::min_nstubs
int min_nstubs
Definition: L1TkMuMantra.h:119
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
L1TkMuMantra::nbins_
int nbins_
Definition: L1TkMuMantra.h:114
LaserClient_cfi.high
high
Definition: LaserClient_cfi.py:50
type
type
Definition: HCALResponse.h:21
heppy_batch.val
val
Definition: heppy_batch.py:351
L1TkMuMantraDF::track_df::eta
double eta
Definition: L1TkMuMantra.h:16
Exception
Definition: hltDiff.cc:246
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
L1TkMuMantra::to_mpi_pi
static double to_mpi_pi(double x)
Definition: L1TkMuMantra.h:101
mps_fire.result
result
Definition: mps_fire.py:303
L1TkMuMantra::verbosity_
int verbosity_
Definition: L1TkMuMantra.h:132
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
L1TkMuMantra::name_
std::string name_
Definition: L1TkMuMantra.h:112
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
L1TkMuMantra::sign
int sign(double x)
Definition: L1TkMuMantra.h:73