CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CandidatePointSeededTrackingRegionsProducer.h
Go to the documentation of this file.
1 #ifndef CandidatePointSeededTrackingRegionsProducer_h
2 #define CandidatePointSeededTrackingRegionsProducer_h
3 
7 
21 
22 #include "VertexBeamspotOrigins.h"
23 
59 public:
61 
63  : m_origins(conf.getParameter<edm::ParameterSet>("RegionPSet"), iC), token_field(iC.esConsumes()) {
64  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
65 
66  // seeding mode
67  std::string seedingModeString = regPSet.getParameter<std::string>("seedingMode");
68  if (seedingModeString == "Candidate")
70  else if (seedingModeString == "Point")
72  else if (seedingModeString == "CandidatePoint")
74  else
75  throw edm::Exception(edm::errors::Configuration) << "Unknown seeding mode string: " << seedingModeString;
76 
77  // basic inputs
79  m_token_input = iC.consumes<reco::CandidateView>(regPSet.getParameter<edm::InputTag>("input"));
80 
81  // Specific points in the detector
83  edm::ParameterSet points = regPSet.getParameter<edm::ParameterSet>("points");
84  std::vector<double> etaPoints = points.getParameter<std::vector<double>>("eta");
85  std::vector<double> phiPoints = points.getParameter<std::vector<double>>("phi");
86 
87  if (!(etaPoints.size() == phiPoints.size()))
88  throw edm::Exception(edm::errors::Configuration) << "The parameters 'eta' and 'phi' must have the same size";
89  if (etaPoints.empty())
91  << "At least one point should be defined for point or candidate+point seeding modes";
92 
93  for (size_t i = 0; i < etaPoints.size(); ++i) {
94  m_etaPhiPoints.push_back(std::make_pair(etaPoints[i], phiPoints[i]));
95 
96  double x = std::cos(phiPoints[i]);
97  double y = std::sin(phiPoints[i]);
98  double theta = 2 * std::atan(std::exp(-etaPoints[i]));
99  double z = 1. / std::tan(theta);
100  GlobalVector direction(x, y, z);
101  m_directionPoints.push_back(direction);
102  }
103  }
104 
105  m_maxNRegions = regPSet.getParameter<unsigned int>("maxNRegions");
106  if (m_maxNRegions == 0)
107  throw edm::Exception(edm::errors::Configuration) << "maxNRegions should be greater than or equal to 1";
108 
109  // RectangularEtaPhiTrackingRegion parameters:
110  m_ptMin = regPSet.getParameter<double>("ptMin");
111  m_originRadius = regPSet.getParameter<double>("originRadius");
112 
114  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
115  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
116  if (m_deltaEta_Cand < 0 || m_deltaPhi_Cand < 0)
118  << "Delta eta and phi parameters must be set for candidates in candidate seeding mode";
120  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
121  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
122  if (m_deltaEta_Point < 0 || m_deltaPhi_Point < 0)
124  << "Delta eta and phi parameters must be set for points in point seeding mode";
126  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
127  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
128  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
129  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
130  if (m_deltaEta_Cand < 0 || m_deltaPhi_Cand < 0 || m_deltaEta_Point < 0 || m_deltaPhi_Point < 0)
131  throw edm::Exception(edm::errors::Configuration) << "Delta eta and phi parameters must be set separately for "
132  "candidates and points in candidate+point seeding mode";
133  }
134 
135  m_precise = regPSet.getParameter<bool>("precise");
137  regPSet.getParameter<std::string>("whereToUseMeasurementTracker"));
138  if (m_whereToUseMeasurementTracker != RectangularEtaPhiTrackingRegion::UseMeasurementTracker::kNever) {
140  iC.consumes<MeasurementTrackerEvent>(regPSet.getParameter<edm::InputTag>("measurementTrackerName"));
141  }
142  m_searchOpt = false;
143  if (regPSet.exists("searchOpt"))
144  m_searchOpt = regPSet.getParameter<bool>("searchOpt");
145 
146  if (m_precise) {
147  token_msmaker = iC.esConsumes();
148  }
149  }
150 
152 
155 
156  desc.add<std::string>("seedingMode", "Candidate");
157 
158  desc.add<edm::InputTag>("input", edm::InputTag(""));
159  edm::ParameterSetDescription descPoints;
160  descPoints.add<std::vector<double>>("eta", {});
161  descPoints.add<std::vector<double>>("phi", {});
162  desc.add<edm::ParameterSetDescription>("points", descPoints);
163 
164  desc.add<unsigned int>("maxNRegions", 10);
165 
166  VertexBeamspotOrigins::fillDescriptions(desc, "hltOnlineBeamSpot", "hltPixelVertices", 1);
167 
168  desc.add<double>("ptMin", 0.9);
169  desc.add<double>("originRadius", 0.2);
170  desc.add<double>("deltaEta_Cand", -1.);
171  desc.add<double>("deltaPhi_Cand", -1.);
172  desc.add<double>("deltaEta_Point", -1.);
173  desc.add<double>("deltaPhi_Point", -1.);
174  desc.add<bool>("precise", true);
175 
176  desc.add<std::string>("whereToUseMeasurementTracker", "ForSiStrips");
177  desc.add<edm::InputTag>("measurementTrackerName", edm::InputTag(""));
178 
179  desc.add<bool>("searchOpt", false);
180 
181  // Only for backwards-compatibility
182  edm::ParameterSetDescription descRegion;
183  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
184 
185  descriptions.add("candidatePointSeededTrackingRegionsFromBeamSpot", descRegion);
186  }
187 
188  std::vector<std::unique_ptr<TrackingRegion>> regions(const edm::Event& e, const edm::EventSetup& es) const override {
189  std::vector<std::unique_ptr<TrackingRegion>> result;
190 
191  // pick up the candidate objects of interest
193  size_t n_objects = 0;
194 
196  e.getByToken(m_token_input, objects);
197  n_objects = objects->size();
198  if (n_objects == 0)
199  return result;
200  }
201 
202  const auto& objs = *objects;
203 
204  const auto& origins = m_origins.origins(e);
205  if (origins.empty()) {
206  return result;
207  }
208 
213  measurementTracker = hmte.product();
214  }
215 
216  const auto& field = es.getData(token_field);
217  const MultipleScatteringParametrisationMaker* msmaker = nullptr;
218  if (m_precise) {
219  msmaker = &es.getData(token_msmaker);
220  }
221 
222  // create tracking regions (maximum MaxNRegions of them) in directions of the
223  // objects of interest (we expect that the collection was sorted in decreasing pt order)
224  int n_regions = 0;
225 
227  for (const auto& object : objs) {
228  GlobalVector direction(object.momentum().x(), object.momentum().y(), object.momentum().z());
229 
230  for (const auto& origin : origins) {
231  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(direction,
232  origin.first,
233  m_ptMin,
235  origin.second,
238  field,
239  msmaker,
240  m_precise,
242  measurementTracker,
243  m_searchOpt));
244  ++n_regions;
245  if (n_regions >= m_maxNRegions)
246  break;
247  }
248 
249  if (n_regions >= m_maxNRegions)
250  break;
251  }
252 
253  }
254 
256  for (const auto& direction : m_directionPoints) {
257  for (const auto& origin : origins) {
258  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(direction, // GlobalVector
259  origin.first, // GlobalPoint
260  m_ptMin,
262  origin.second,
265  field,
266  msmaker,
267  m_precise,
269  measurementTracker,
270  m_searchOpt));
271  ++n_regions;
272  if (n_regions >= m_maxNRegions)
273  break;
274  }
275 
276  if (n_regions >= m_maxNRegions)
277  break;
278  }
279 
280  }
281 
283  for (const auto& object : objs) {
284  double eta_Cand = object.eta();
285  double phi_Cand = object.phi();
286 
287  for (const auto& etaPhiPoint : m_etaPhiPoints) {
288  double eta_Point = etaPhiPoint.first;
289  double phi_Point = etaPhiPoint.second;
290  double dEta_Cand_Point = std::abs(eta_Cand - eta_Point);
291  double dPhi_Cand_Point = std::abs(deltaPhi(phi_Cand, phi_Point));
292 
293  //Check if there is an overlap between Candidate- and Point-based regions of interest
294  if (dEta_Cand_Point > (m_deltaEta_Cand + m_deltaEta_Point) ||
295  dPhi_Cand_Point > (m_deltaPhi_Cand + m_deltaPhi_Point))
296  continue;
297 
298  //Determines boundaries of intersection of RoIs
299  double etaMin_RoI = std::max(eta_Cand - m_deltaEta_Cand, eta_Point - m_deltaEta_Point);
300  double etaMax_RoI = std::min(eta_Cand + m_deltaEta_Cand, eta_Point + m_deltaEta_Point);
301 
302  double phi_Cand_minus = normalizedPhi(phi_Cand - m_deltaPhi_Cand);
303  double phi_Point_minus = normalizedPhi(phi_Point - m_deltaPhi_Point);
304  double phi_Cand_plus = normalizedPhi(phi_Cand + m_deltaPhi_Cand);
305  double phi_Point_plus = normalizedPhi(phi_Point + m_deltaPhi_Point);
306 
307  double phiMin_RoI = deltaPhi(phi_Cand_minus, phi_Point_minus) > 0. ? phi_Cand_minus : phi_Point_minus;
308  double phiMax_RoI = deltaPhi(phi_Cand_plus, phi_Point_plus) < 0. ? phi_Cand_plus : phi_Point_plus;
309 
310  //Determines position and width of new RoI
311  double eta_RoI = 0.5 * (etaMax_RoI + etaMin_RoI);
312  double deltaEta_RoI = etaMax_RoI - eta_RoI;
313 
314  double phi_RoI = 0.5 * (phiMax_RoI + phiMin_RoI);
315  if (phiMax_RoI < phiMin_RoI)
316  phi_RoI -= M_PI;
317  phi_RoI = normalizedPhi(phi_RoI);
318  double deltaPhi_RoI = deltaPhi(phiMax_RoI, phi_RoI);
319 
320  double x = std::cos(phi_RoI);
321  double y = std::sin(phi_RoI);
322  double theta = 2 * std::atan(std::exp(-eta_RoI));
323  double z = 1. / std::tan(theta);
324 
325  GlobalVector direction(x, y, z);
326 
327  for (const auto& origin : origins) {
328  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(direction,
329  origin.first,
330  m_ptMin,
332  origin.second,
333  deltaEta_RoI,
334  deltaPhi_RoI,
335  field,
336  msmaker,
337  m_precise,
339  measurementTracker,
340  m_searchOpt));
341  ++n_regions;
342  if (n_regions >= m_maxNRegions)
343  break;
344  }
345 
346  if (n_regions >= m_maxNRegions)
347  break;
348  }
349 
350  if (n_regions >= m_maxNRegions)
351  break;
352  }
353  }
354 
355  edm::LogInfo("CandidatePointSeededTrackingRegionsProducer") << "produced " << n_regions << " regions";
356 
357  return result;
358  }
359 
360 private:
363 
366 
367  std::vector<std::pair<double, double>> m_etaPhiPoints;
368  std::vector<GlobalVector> m_directionPoints;
369 
370  float m_ptMin;
376  bool m_precise;
382 };
383 
384 #endif
Origins origins(const edm::Event &iEvent) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~CandidatePointSeededTrackingRegionsProducer() override=default
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
tuple measurementTracker
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:8
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
Geom::Theta< T > theta() const
static void fillDescriptions(edm::ParameterSetDescription &desc, const std::string &defaultBeamSpot="offlineBeamSpot", const std::string &defaultVertex="firstStepPrimaryVertices", int defaultMaxVertices=-1)
bool exists(std::string const &parameterName) const
checks if a parameter exists
static UseMeasurementTracker stringToUseMeasurementTracker(const std::string &name)
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
tuple result
Definition: mps_fire.py:311
bool getData(T &iHolder) const
Definition: EventSetup.h:122
edm::EDGetTokenT< MeasurementTrackerEvent > m_token_measurementTracker
RectangularEtaPhiTrackingRegion::UseMeasurementTracker m_whereToUseMeasurementTracker
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define M_PI
Log< level::Info, false > LogInfo
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &e, const edm::EventSetup &es) const override
CandidatePointSeededTrackingRegionsProducer(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > token_field
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > token_msmaker