CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PPSAssociationCuts.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  * Grzegorz Sroka
5  ****************************************************************************/
6 
9 
10 #include "TF1.h"
11 
12 #include <iostream>
13 
14 //----------------------------------------------------------------------------------------------------
15 
17  const auto &association_cuts = iConfig.getParameterSet("association_cuts_" + std::to_string(sector));
18 
19  const std::vector<std::string> names{"x", "y", "xi", "th_y"};
20  for (std::size_t i = 0; i < names.size(); ++i) {
21  std::string mean = association_cuts.getParameter<std::string>(names[i] + "_cut_mean");
22  s_means_.push_back(mean);
23 
24  std::string threshold = association_cuts.getParameter<std::string>(names[i] + "_cut_threshold");
25  s_thresholds_.push_back(threshold);
26  }
27 
28  ti_tr_min_ = association_cuts.getParameter<double>("ti_tr_min");
29  ti_tr_max_ = association_cuts.getParameter<double>("ti_tr_max");
30 }
31 
32 //----------------------------------------------------------------------------------------------------
33 
35  f_means_.clear();
36  for (const auto &s : s_means_)
37  f_means_.push_back(std::make_shared<TF1>("f", s.c_str()));
38 
39  f_thresholds_.clear();
40  for (const auto &s : s_thresholds_)
41  f_thresholds_.push_back(std::make_shared<TF1>("f", s.c_str()));
42 }
43 
44 //----------------------------------------------------------------------------------------------------
45 
47  return (!s_thresholds_[quantity].empty()) && (!s_means_[quantity].empty());
48 }
49 
50 //----------------------------------------------------------------------------------------------------
51 
53  Quantities quantity, double x_near, double y_near, double xangle, double q_NF_diff) const {
54  // if cut not applied, then condition considered as satisfied
55  if (!isApplied(quantity))
56  return true;
57 
58  // evaluate mean and threshold
59  const double mean = evaluateExpression(f_means_[quantity], x_near, y_near, xangle);
60  const double threshold = evaluateExpression(f_thresholds_[quantity], x_near, y_near, xangle);
61 
62  // make comparison
63  return fabs(q_NF_diff - mean) < threshold;
64 }
65 
66 //----------------------------------------------------------------------------------------------------
67 
68 double PPSAssociationCuts::CutsPerArm::evaluateExpression(std::shared_ptr<TF1> expression,
69  double x_near,
70  double y_near,
71  double xangle) {
72  expression->SetParameter("x_near", x_near);
73  expression->SetParameter("y_near", y_near);
74  expression->SetParameter("xangle", xangle);
75  return expression->EvalPar(nullptr);
76 }
77 
78 //----------------------------------------------------------------------------------------------------
79 
81  unsigned int i = 0;
82  for (const int &sector : {45, 56})
83  association_cuts_[i++] = CutsPerArm(iConfig, sector);
84 
85  initialize();
86 }
87 
88 //----------------------------------------------------------------------------------------------------
89 
92 
93  desc.add<std::string>("x_cut_mean", "")->setComment("mean of track-association cut in x, mm");
94  desc.add<std::string>("x_cut_threshold", "")->setComment("threshold of track-association cut in x, mm");
95 
96  desc.add<std::string>("y_cut_mean", "")->setComment("mean of track-association cut in y, mm");
97  desc.add<std::string>("y_cut_threshold", "")->setComment("threshold of track-association cut in y, mm");
98 
99  desc.add<std::string>("xi_cut_mean", "")->setComment("mean of track-association cut in xi");
100  desc.add<std::string>("xi_cut_threshold", "")->setComment("threshold of track-association cut in xi");
101 
102  desc.add<std::string>("th_y_cut_mean", "")->setComment("mean of track-association cut in th_y, rad");
103  desc.add<std::string>("th_y_cut_threshold", "")->setComment("threshold of track-association cut in th_y, rad");
104 
105  desc.add<double>("ti_tr_min", -1.)->setComment("minimum value for timing-tracking association cut");
106  desc.add<double>("ti_tr_max", +1.)->setComment("maximum value for timing-tracking association cut");
107 
108  return desc;
109 }
110 
111 //----------------------------------------------------------------------------------------------------
112 
114  // valid if association_cuts_ have two entries, with keys 0 and 1
115  if (association_cuts_.size() != 2)
116  return false;
117 
118  if (association_cuts_.find(0) == association_cuts_.end())
119  return false;
120  if (association_cuts_.find(1) == association_cuts_.end())
121  return false;
122 
123  return true;
124 }
125 
126 //----------------------------------------------------------------------------------------------------
127 
129  if (!isValid())
130  throw cms::Exception("PPS") << "Invalid structure of PPSAssociationCuts.";
131 
132  for (auto &p : association_cuts_)
133  p.second.buildFunctions();
134 }
135 
136 //----------------------------------------------------------------------------------------------------
137 
138 std::ostream &operator<<(std::ostream &os, const PPSAssociationCuts::CutsPerArm &cutsPerArm) {
139  os << "CutsPerArm {" << std::endl;
140 
141  os << "\tmeans {";
142  for (auto const &value : cutsPerArm.getMeans()) {
143  os << "\"" << value << "\", ";
144  }
145  os << "}" << std::endl << std::endl;
146 
147  os << "\tthresholds {";
148  for (auto const &value : cutsPerArm.getThresholds()) {
149  os << "\"" << value << "\", ";
150  }
151  os << "}" << std::endl << std::endl;
152 
153  os << "\tti_tr_min " << cutsPerArm.getTiTrMin() << std::endl;
154  os << "\tti_tr_max " << cutsPerArm.getTiTrMax() << std::endl;
155  os << "}" << std::endl;
156 
157  return os;
158 }
159 
160 //----------------------------------------------------------------------------------------------------
161 
162 std::ostream &operator<<(std::ostream &os, const PPSAssociationCuts &ppsAssociationCuts) {
163  os << "PPSAssociationCuts {" << std::endl;
164  os << "45" << std::endl;
165  os << ppsAssociationCuts.getAssociationCuts(0);
166  os << "56" << std::endl;
167  os << ppsAssociationCuts.getAssociationCuts(1);
168  os << "}" << std::endl;
169 
170  return os;
171 }
void setComment(std::string const &value)
const std::vector< std::string > & getThresholds() const
const std::vector< std::string > & getMeans() const
std::string to_string(const V &value)
Definition: OMSAccess.h:71
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
const std::string names[nVars_]
std::map< unsigned int, CutsPerArm > association_cuts_
bool isSatisfied(Quantities quantity, double x_near, double y_near, double xangle, double q_NF_diff) const
bool isApplied(Quantities quantity) const
std::vector< std::string > s_thresholds_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ParameterSet const & getParameterSet(std::string const &) const
static double evaluateExpression(std::shared_ptr< TF1 > expression, double x_near, double y_near, double xangle)
const CutsPerArm & getAssociationCuts(const int sector) const
static edm::ParameterSetDescription getDefaultParameters()
std::vector< std::string > s_means_