CMS 3D CMS Logo

CandidatePointSeededTrackingRegionsProducer.h
Go to the documentation of this file.
1 #ifndef CandidatePointSeededTrackingRegionsProducer_h
2 #define CandidatePointSeededTrackingRegionsProducer_h
3 
4 
8 
22 
23 #include "VertexBeamspotOrigins.h"
24 
60 {
61 public:
62 
64 
66  m_origins(conf.getParameter<edm::ParameterSet>("RegionPSet"), iC)
67  {
68  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
69 
70  // seeding mode
71  std::string seedingModeString = regPSet.getParameter<std::string>("seedingMode");
72  if (seedingModeString == "Candidate") m_seedingMode = SeedingMode::CANDIDATE_SEEDED;
73  else if (seedingModeString == "Point") m_seedingMode = SeedingMode::POINT_SEEDED;
74  else if (seedingModeString == "CandidatePoint") m_seedingMode = SeedingMode::CANDIDATE_POINT_SEEDED;
75  else 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
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())) throw edm::Exception(edm::errors::Configuration) << "The parameters 'eta' and 'phi' must have the same size";
88  if (etaPoints.empty()) throw edm::Exception(edm::errors::Configuration) << "At least one point should be defined for point or candidate+point seeding modes";
89 
90  for(size_t i = 0; i < etaPoints.size(); ++i ){
91 
92  m_etaPhiPoints.push_back(std::make_pair(etaPoints[i],phiPoints[i]));
93 
94  double x = std::cos(phiPoints[i]);
95  double y = std::sin(phiPoints[i]);
96  double theta = 2*std::atan(std::exp(-etaPoints[i]));
97  double z = 1./std::tan(theta);
98  GlobalVector direction( x,y,z );
99  m_directionPoints.push_back(direction);
100 
101  }
102 
103  }
104 
105  m_maxNRegions = regPSet.getParameter<unsigned int>("maxNRegions");
106  if(m_maxNRegions==0) throw edm::Exception(edm::errors::Configuration) << "maxNRegions should be greater than or equal to 1";
107 
108  // RectangularEtaPhiTrackingRegion parameters:
109  m_ptMin = regPSet.getParameter<double>("ptMin");
110  m_originRadius = regPSet.getParameter<double>("originRadius");
111 
113  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
114  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
115  if (m_deltaEta_Cand<0 || m_deltaPhi_Cand<0) throw edm::Exception(edm::errors::Configuration) << "Delta eta and phi parameters must be set for candidates in candidate seeding mode";
116  }
118  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
119  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
120  if (m_deltaEta_Point<0 || m_deltaPhi_Point<0) throw edm::Exception(edm::errors::Configuration) << "Delta eta and phi parameters must be set for points in point seeding mode";
121  }
123  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
124  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
125  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
126  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
127  if (m_deltaEta_Cand<0 || m_deltaPhi_Cand<0 || m_deltaEta_Point<0 || m_deltaPhi_Point<0) throw edm::Exception(edm::errors::Configuration) << "Delta eta and phi parameters must be set separately for candidates and points in candidate+point seeding mode";
128  }
129 
130  m_precise = regPSet.getParameter<bool>("precise");
132  if(m_whereToUseMeasurementTracker != RectangularEtaPhiTrackingRegion::UseMeasurementTracker::kNever) {
133  m_token_measurementTracker = iC.consumes<MeasurementTrackerEvent>(regPSet.getParameter<edm::InputTag>("measurementTrackerName"));
134  }
135  m_searchOpt = false;
136  if (regPSet.exists("searchOpt")) m_searchOpt = regPSet.getParameter<bool>("searchOpt");
137  }
138 
140 
143 
144  desc.add<std::string>("seedingMode", "Candidate");
145 
146  desc.add<edm::InputTag>("input", edm::InputTag(""));
147  edm::ParameterSetDescription descPoints;
148  descPoints.add<std::vector<double>> ("eta", {} );
149  descPoints.add<std::vector<double>> ("phi", {} );
150  desc.add<edm::ParameterSetDescription>("points", descPoints);
151 
152  desc.add<unsigned int>("maxNRegions", 10);
153 
154  VertexBeamspotOrigins::fillDescriptions(desc, "hltOnlineBeamSpot", "hltPixelVertices", 1);
155 
156  desc.add<double>("ptMin", 0.9);
157  desc.add<double>("originRadius", 0.2);
158  desc.add<double>("deltaEta_Cand", -1.);
159  desc.add<double>("deltaPhi_Cand", -1.);
160  desc.add<double>("deltaEta_Point", -1.);
161  desc.add<double>("deltaPhi_Point", -1.);
162  desc.add<bool>("precise", true);
163 
164  desc.add<std::string>("whereToUseMeasurementTracker", "ForSiStrips");
165  desc.add<edm::InputTag>("measurementTrackerName", edm::InputTag(""));
166 
167  desc.add<bool>("searchOpt", false);
168 
169  // Only for backwards-compatibility
170  edm::ParameterSetDescription descRegion;
171  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
172 
173  descriptions.add("candidatePointSeededTrackingRegionsFromBeamSpot", descRegion);
174  }
175 
176 
177  std::vector<std::unique_ptr<TrackingRegion> > regions(const edm::Event& e, const edm::EventSetup& es) const override
178  {
179  std::vector<std::unique_ptr<TrackingRegion> > result;
180 
181  // pick up the candidate objects of interest
183  size_t n_objects = 0;
184 
186  e.getByToken( m_token_input, objects );
187  n_objects = objects->size();
188  if (n_objects == 0) return result;
189  }
190 
191  const auto& objs = *objects;
192 
193  const auto& origins = m_origins.origins(e);
194  if(origins.empty()) {
195  return result;
196  }
197 
198  const MeasurementTrackerEvent *measurementTracker = nullptr;
202  measurementTracker = hmte.product();
203  }
204 
205  // create tracking regions (maximum MaxNRegions of them) in directions of the
206  // objects of interest (we expect that the collection was sorted in decreasing pt order)
207  int n_regions = 0;
208 
210 
211  for(const auto& object : objs) {
212 
213  GlobalVector direction( object.momentum().x(), object.momentum().y(), object.momentum().z() );
214 
215  for(const auto& origin : origins) {
216 
217  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(
218  direction,
219  origin.first,
220  m_ptMin,
222  origin.second,
226  m_precise,
227  measurementTracker,
229  ));
230  ++n_regions;
231  if( n_regions >= m_maxNRegions ) break;
232 
233  }
234 
235  if( n_regions >= m_maxNRegions ) break;
236 
237  }
238 
239  }
240 
241 
243 
244  for( const auto& direction : m_directionPoints ){
245 
246  for(const auto& origin : origins) {
247 
248  result.push_back( std::make_unique<RectangularEtaPhiTrackingRegion>(
249  direction, // GlobalVector
250  origin.first, // GlobalPoint
251  m_ptMin,
253  origin.second,
257  m_precise,
258  measurementTracker,
260  ));
261  ++n_regions;
262  if( n_regions >= m_maxNRegions ) break;
263 
264  }
265 
266  if( n_regions >= m_maxNRegions ) break;
267 
268  }
269 
270  }
271 
272 
274 
275  for(const auto& object : objs) {
276 
277  double eta_Cand = object.eta();
278  double phi_Cand = object.phi();
279 
280  for (const auto& etaPhiPoint : m_etaPhiPoints ){
281 
282  double eta_Point = etaPhiPoint.first;
283  double phi_Point = etaPhiPoint.second;
284  double dEta_Cand_Point = std::abs(eta_Cand-eta_Point);
285  double dPhi_Cand_Point = std::abs(deltaPhi(phi_Cand,phi_Point));
286 
287  //Check if there is an overlap between Candidate- and Point-based regions of interest
288  if(dEta_Cand_Point > (m_deltaEta_Cand + m_deltaEta_Point) || dPhi_Cand_Point > (m_deltaPhi_Cand + m_deltaPhi_Point)) continue;
289 
290  //Determines boundaries of intersection of RoIs
291  double etaMin_RoI = std::max(eta_Cand-m_deltaEta_Cand,eta_Point-m_deltaEta_Point);
292  double etaMax_RoI = std::min(eta_Cand+m_deltaEta_Cand,eta_Point+m_deltaEta_Point);
293 
294  double phi_Cand_minus = normalizedPhi(phi_Cand-m_deltaPhi_Cand);
295  double phi_Point_minus = normalizedPhi(phi_Point-m_deltaPhi_Point);
296  double phi_Cand_plus = normalizedPhi(phi_Cand+m_deltaPhi_Cand);
297  double phi_Point_plus = normalizedPhi(phi_Point+m_deltaPhi_Point);
298 
299  double phiMin_RoI = deltaPhi(phi_Cand_minus,phi_Point_minus)>0. ? phi_Cand_minus : phi_Point_minus ;
300  double phiMax_RoI = deltaPhi(phi_Cand_plus,phi_Point_plus)<0. ? phi_Cand_plus : phi_Point_plus;
301 
302  //Determines position and width of new RoI
303  double eta_RoI = 0.5*(etaMax_RoI+etaMin_RoI);
304  double deltaEta_RoI = etaMax_RoI - eta_RoI;
305 
306  double phi_RoI = 0.5*(phiMax_RoI+phiMin_RoI);
307  if( phiMax_RoI < phiMin_RoI ) phi_RoI-=M_PI;
308  phi_RoI = normalizedPhi(phi_RoI);
309  double deltaPhi_RoI = deltaPhi(phiMax_RoI,phi_RoI);
310 
311  double x = std::cos(phi_RoI);
312  double y = std::sin(phi_RoI);
313  double theta = 2*std::atan(std::exp(-eta_RoI));
314  double z = 1./std::tan(theta);
315 
316  GlobalVector direction( x,y,z );
317 
318  for(const auto& origin : origins) {
319 
320  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(
321  direction,
322  origin.first,
323  m_ptMin,
325  origin.second,
326  deltaEta_RoI,
327  deltaPhi_RoI,
329  m_precise,
330  measurementTracker,
332  ));
333  ++n_regions;
334  if( n_regions >= m_maxNRegions ) break;
335 
336  }
337 
338  if( n_regions >= m_maxNRegions ) break;
339 
340  }
341 
342  if( n_regions >= m_maxNRegions ) break;
343 
344  }
345 
346  }
347 
348  edm::LogInfo ("CandidatePointSeededTrackingRegionsProducer") << "produced "<<n_regions<<" regions";
349 
350  return result;
351  }
352 
353 private:
354 
357 
360 
361  std::vector<std::pair<double,double> > m_etaPhiPoints;
362  std::vector<GlobalVector> m_directionPoints;
363 
364  float m_ptMin;
370  bool m_precise;
374 };
375 
376 #endif
Origins origins(const edm::Event &iEvent) const
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:9
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
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
size_type size() const
static UseMeasurementTracker stringToUseMeasurementTracker(const std::string &name)
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
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define M_PI
CandidatePointSeededTrackingRegionsProducer(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
T const * product() const
Definition: Handle.h:81
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &e, const edm::EventSetup &es) const override
bool isUninitialized() const
Definition: EDGetToken.h:73