CMS 3D CMS Logo

CandidatePointSeededTrackingRegionsProducer.h
Go to the documentation of this file.
1 #ifndef CandidatePointSeededTrackingRegionsProducer_h
2 #define CandidatePointSeededTrackingRegionsProducer_h
3 
4 
7 
20 
21 
57 {
58 public:
59 
61  enum class SeedingMode {CANDIDATE_SEEDED, POINT_SEEDED, CANDIDATE_POINT_SEEDED};
62 
65  {
66  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
67 
68  // operation mode
69  std::string operationModeString = regPSet.getParameter<std::string>("operationMode");
70  if (operationModeString == "BeamSpotFixed") m_operationMode = OperationMode::BEAM_SPOT_FIXED;
71  else if (operationModeString == "BeamSpotSigma") m_operationMode = OperationMode::BEAM_SPOT_SIGMA;
72  else if (operationModeString == "VerticesFixed") m_operationMode = OperationMode::VERTICES_FIXED;
73  else if (operationModeString == "VerticesSigma") m_operationMode = OperationMode::VERTICES_SIGMA;
74  else throw edm::Exception(edm::errors::Configuration) << "Unknown operation mode string: "<<operationModeString;
75 
76  // seeding mode
77  std::string seedingModeString = regPSet.getParameter<std::string>("seedingMode");
78  if (seedingModeString == "Candidate") m_seedingMode = SeedingMode::CANDIDATE_SEEDED;
79  else if (seedingModeString == "Point") m_seedingMode = SeedingMode::POINT_SEEDED;
80  else if (seedingModeString == "CandidatePoint") m_seedingMode = SeedingMode::CANDIDATE_POINT_SEEDED;
81  else throw edm::Exception(edm::errors::Configuration) << "Unknown seeding mode string: "<<seedingModeString;
82 
83  // basic inputs
85  m_token_input = iC.consumes<reco::CandidateView>(regPSet.getParameter<edm::InputTag>("input"));
86 
87  // Specific points in the detector
90  std::vector<double> etaPoints = points.getParameter<std::vector<double>>("eta");
91  std::vector<double> phiPoints = points.getParameter<std::vector<double>>("phi");
92 
93  if (!(etaPoints.size() == phiPoints.size())) throw edm::Exception(edm::errors::Configuration) << "The parameters 'eta' and 'phi' must have the same size";
94  if (etaPoints.empty()) throw edm::Exception(edm::errors::Configuration) << "At least one point should be defined for point or candidate+point seeding modes";
95 
96  for(size_t i = 0; i < etaPoints.size(); ++i ){
97 
98  m_etaPhiPoints.push_back(std::make_pair(etaPoints[i],phiPoints[i]));
99 
100  double x = std::cos(phiPoints[i]);
101  double y = std::sin(phiPoints[i]);
102  double theta = 2*std::atan(std::exp(-etaPoints[i]));
103  double z = 1./std::tan(theta);
104  GlobalVector direction( x,y,z );
105  m_directionPoints.push_back(direction);
106 
107  }
108 
109  }
110 
111  m_maxNRegions = regPSet.getParameter<unsigned int>("maxNRegions");
112  if(m_maxNRegions==0) throw edm::Exception(edm::errors::Configuration) << "maxNRegions should be greater than or equal to 1";
113  m_token_beamSpot = iC.consumes<reco::BeamSpot>(regPSet.getParameter<edm::InputTag>("beamSpot"));
114  m_maxNVertices = 1;
116  {
117  m_token_vertex = iC.consumes<reco::VertexCollection>(regPSet.getParameter<edm::InputTag>("vertexCollection"));
118  m_maxNVertices = regPSet.getParameter<unsigned int>("maxNVertices");
119  if(m_maxNVertices==0) throw edm::Exception(edm::errors::Configuration) << "maxNVertices should be greater than or equal to 1";
120  }
121 
122 
123  // RectangularEtaPhiTrackingRegion parameters:
124  m_ptMin = regPSet.getParameter<double>("ptMin");
125  m_originRadius = regPSet.getParameter<double>("originRadius");
126  m_zErrorBeamSpot = regPSet.getParameter<double>("zErrorBeamSpot");
127 
129  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
130  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
131  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";
132  }
134  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
135  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
136  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";
137  }
139  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
140  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
141  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
142  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
143  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";
144  }
145 
146  m_precise = regPSet.getParameter<bool>("precise");
148  if(m_whereToUseMeasurementTracker != RectangularEtaPhiTrackingRegion::UseMeasurementTracker::kNever) {
149  m_token_measurementTracker = iC.consumes<MeasurementTrackerEvent>(regPSet.getParameter<edm::InputTag>("measurementTrackerName"));
150  }
151  m_searchOpt = false;
152  if (regPSet.exists("searchOpt")) m_searchOpt = regPSet.getParameter<bool>("searchOpt");
153 
154  // mode-dependent z-halflength of tracking regions
155  if (m_operationMode == OperationMode::VERTICES_SIGMA) m_nSigmaZVertex = regPSet.getParameter<double>("nSigmaZVertex");
156  if (m_operationMode == OperationMode::VERTICES_FIXED) m_zErrorVetex = regPSet.getParameter<double>("zErrorVetex");
157  m_nSigmaZBeamSpot = -1.;
159  {
160  m_nSigmaZBeamSpot = regPSet.getParameter<double>("nSigmaZBeamSpot");
161  if (m_nSigmaZBeamSpot < 0.)
162  throw edm::Exception(edm::errors::Configuration) << "nSigmaZBeamSpot must be positive for BeamSpotSigma mode!";
163  }
164  }
165 
167 
170 
171  desc.add<std::string>("operationMode", "BeamSpotFixed");
172  desc.add<std::string>("seedingMode", "Candidate");
173 
174  desc.add<edm::InputTag>("input", edm::InputTag(""));
175  edm::ParameterSetDescription descPoints;
176  descPoints.add<std::vector<double>> ("eta", {} );
177  descPoints.add<std::vector<double>> ("phi", {} );
178  desc.add<edm::ParameterSetDescription>("points", descPoints);
179 
180  desc.add<unsigned int>("maxNRegions", 10);
181  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"));
182  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
183  desc.add<unsigned int>("maxNVertices", 1);
184 
185  desc.add<double>("ptMin", 0.9);
186  desc.add<double>("originRadius", 0.2);
187  desc.add<double>("zErrorBeamSpot", 24.2);
188  desc.add<double>("deltaEta_Cand", -1.);
189  desc.add<double>("deltaPhi_Cand", -1.);
190  desc.add<double>("deltaEta_Point", -1.);
191  desc.add<double>("deltaPhi_Point", -1.);
192  desc.add<bool>("precise", true);
193 
194  desc.add<double>("nSigmaZVertex", 3.);
195  desc.add<double>("zErrorVetex", 0.2);
196  desc.add<double>("nSigmaZBeamSpot", 4.);
197 
198  desc.add<std::string>("whereToUseMeasurementTracker", "ForSiStrips");
199  desc.add<edm::InputTag>("measurementTrackerName", edm::InputTag(""));
200 
201  desc.add<bool>("searchOpt", false);
202 
203  // Only for backwards-compatibility
204  edm::ParameterSetDescription descRegion;
205  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
206 
207  descriptions.add("candidatePointSeededTrackingRegionsFromBeamSpot", descRegion);
208  }
209 
210 
211  std::vector<std::unique_ptr<TrackingRegion> > regions(const edm::Event& e, const edm::EventSetup& es) const override
212  {
213  std::vector<std::unique_ptr<TrackingRegion> > result;
214 
215  // pick up the candidate objects of interest
217  size_t n_objects = 0;
218 
220  e.getByToken( m_token_input, objects );
221  n_objects = objects->size();
222  if (n_objects == 0) return result;
223  }
224 
225  const auto& objs = *objects;
226 
227  // always need the beam spot (as a fall back strategy for vertex modes)
229  e.getByToken( m_token_beamSpot, bs );
230  if( !bs.isValid() ) return result;
231 
232  // this is a default origin for all modes
233  GlobalPoint default_origin( bs->x0(), bs->y0(), bs->z0() );
234 
235  // vector of origin & halfLength pairs:
236  std::vector< std::pair< GlobalPoint, float > > origins;
237 
238  // fill the origins and halfLengths depending on the mode
240  {
241  origins.emplace_back( default_origin,
243  );
244  }
246  {
248  e.getByToken( m_token_vertex, vertices );
249  int n_vert = 0;
250  for ( const auto& v : (*vertices) )
251  {
252  if ( v.isFake() || !v.isValid() ) continue;
253  origins.emplace_back( GlobalPoint( v.x(), v.y(), v.z() ),
255  );
256  ++n_vert;
257  if( n_vert >= m_maxNVertices ) break;
258  }
259  // no-vertex fall-back case:
260  if (origins.empty())
261  {
262  origins.emplace_back( default_origin,
264  );
265  }
266  }
267 
272  measurementTracker = hmte.product();
273  }
274 
275  // create tracking regions (maximum MaxNRegions of them) in directions of the
276  // objects of interest (we expect that the collection was sorted in decreasing pt order)
277  int n_regions = 0;
278 
280 
281  for(const auto& object : objs) {
282 
283  GlobalVector direction( object.momentum().x(), object.momentum().y(), object.momentum().z() );
284 
285  for(const auto& origin : origins) {
286 
287  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(
288  direction,
289  origin.first,
290  m_ptMin,
292  origin.second,
296  m_precise,
297  measurementTracker,
299  ));
300  ++n_regions;
301  if( n_regions >= m_maxNRegions ) break;
302 
303  }
304 
305  if( n_regions >= m_maxNRegions ) break;
306 
307  }
308 
309  }
310 
311 
313 
314  for( const auto& direction : m_directionPoints ){
315 
316  for(const auto& origin : origins) {
317 
318  result.push_back( std::make_unique<RectangularEtaPhiTrackingRegion>(
319  direction, // GlobalVector
320  origin.first, // GlobalPoint
321  m_ptMin,
323  origin.second,
327  m_precise,
328  measurementTracker,
330  ));
331  ++n_regions;
332  if( n_regions >= m_maxNRegions ) break;
333 
334  }
335 
336  if( n_regions >= m_maxNRegions ) break;
337 
338  }
339 
340  }
341 
342 
344 
345  for(const auto& object : objs) {
346 
347  double eta_Cand = object.eta();
348  double phi_Cand = object.phi();
349 
350  for (const auto& etaPhiPoint : m_etaPhiPoints ){
351 
352  double eta_Point = etaPhiPoint.first;
353  double phi_Point = etaPhiPoint.second;
354  double dEta_Cand_Point = std::abs(eta_Cand-eta_Point);
355  double dPhi_Cand_Point = std::abs(deltaPhi(phi_Cand,phi_Point));
356 
357  //Check if there is an overlap between Candidate- and Point-based regions of interest
358  if(dEta_Cand_Point > (m_deltaEta_Cand + m_deltaEta_Point) || dPhi_Cand_Point > (m_deltaPhi_Cand + m_deltaPhi_Point)) continue;
359 
360  //Determines boundaries of intersection of RoIs
361  double etaMin_RoI = std::max(eta_Cand-m_deltaEta_Cand,eta_Point-m_deltaEta_Point);
362  double etaMax_RoI = std::min(eta_Cand+m_deltaEta_Cand,eta_Point+m_deltaEta_Point);
363 
364  double phi_Cand_minus = normalizedPhi(phi_Cand-m_deltaPhi_Cand);
365  double phi_Point_minus = normalizedPhi(phi_Point-m_deltaPhi_Point);
366  double phi_Cand_plus = normalizedPhi(phi_Cand+m_deltaPhi_Cand);
367  double phi_Point_plus = normalizedPhi(phi_Point+m_deltaPhi_Point);
368 
369  double phiMin_RoI = deltaPhi(phi_Cand_minus,phi_Point_minus)>0. ? phi_Cand_minus : phi_Point_minus ;
370  double phiMax_RoI = deltaPhi(phi_Cand_plus,phi_Point_plus)<0. ? phi_Cand_plus : phi_Point_plus;
371 
372  //Determines position and width of new RoI
373  double eta_RoI = 0.5*(etaMax_RoI+etaMin_RoI);
374  double deltaEta_RoI = etaMax_RoI - eta_RoI;
375 
376  double phi_RoI = 0.5*(phiMax_RoI+phiMin_RoI);
377  if( phiMax_RoI < phiMin_RoI ) phi_RoI-=M_PI;
378  phi_RoI = normalizedPhi(phi_RoI);
379  double deltaPhi_RoI = deltaPhi(phiMax_RoI,phi_RoI);
380 
381  double x = std::cos(phi_RoI);
382  double y = std::sin(phi_RoI);
383  double theta = 2*std::atan(std::exp(-eta_RoI));
384  double z = 1./std::tan(theta);
385 
386  GlobalVector direction( x,y,z );
387 
388  for(const auto& origin : origins) {
389 
390  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(
391  direction,
392  origin.first,
393  m_ptMin,
395  origin.second,
396  deltaEta_RoI,
397  deltaPhi_RoI,
399  m_precise,
400  measurementTracker,
402  ));
403  ++n_regions;
404  if( n_regions >= m_maxNRegions ) break;
405 
406  }
407 
408  if( n_regions >= m_maxNRegions ) break;
409 
410  }
411 
412  if( n_regions >= m_maxNRegions ) break;
413 
414  }
415 
416  }
417 
418  edm::LogInfo ("CandidatePointSeededTrackingRegionsProducer") << "produced "<<n_regions<<" regions";
419 
420  return result;
421  }
422 
423 private:
424 
427 
433 
434  std::vector<std::pair<double,double> > m_etaPhiPoints;
435  std::vector<GlobalVector> m_directionPoints;
436 
437  float m_ptMin;
444  bool m_precise;
448 
452 };
453 
454 #endif
T getParameter(std::string const &) const
double z0() const
z coordinate
Definition: BeamSpot.h:68
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
bool exists(std::string const &parameterName) const
checks if a parameter exists
size_type size() const
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
static UseMeasurementTracker stringToUseMeasurementTracker(const std::string &name)
T normalizedPhi(T phi)
Definition: normalizedPhi.h:9
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)
bool isValid() const
Definition: HandleBase.h:74
double z0Error() const
error on z
Definition: BeamSpot.h:94
#define M_PI
CandidatePointSeededTrackingRegionsProducer(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
T const * product() const
Definition: Handle.h:81
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &e, const edm::EventSetup &es) const override
double y0() const
y coordinate
Definition: BeamSpot.h:66
bool isUninitialized() const
Definition: EDGetToken.h:73
double x0() const
x coordinate
Definition: BeamSpot.h:64