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 #include "VertexBeamspotOrigins.h"
22 
58 {
59 public:
60 
62 
64  m_origins(conf.getParameter<edm::ParameterSet>("RegionPSet"), iC)
65  {
66  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
67 
68  // seeding mode
69  std::string seedingModeString = regPSet.getParameter<std::string>("seedingMode");
70  if (seedingModeString == "Candidate") m_seedingMode = SeedingMode::CANDIDATE_SEEDED;
71  else if (seedingModeString == "Point") m_seedingMode = SeedingMode::POINT_SEEDED;
72  else if (seedingModeString == "CandidatePoint") m_seedingMode = SeedingMode::CANDIDATE_POINT_SEEDED;
73  else throw edm::Exception(edm::errors::Configuration) << "Unknown seeding mode string: "<<seedingModeString;
74 
75  // basic inputs
77  m_token_input = iC.consumes<reco::CandidateView>(regPSet.getParameter<edm::InputTag>("input"));
78 
79  // Specific points in the detector
82  std::vector<double> etaPoints = points.getParameter<std::vector<double>>("eta");
83  std::vector<double> phiPoints = points.getParameter<std::vector<double>>("phi");
84 
85  if (!(etaPoints.size() == phiPoints.size())) throw edm::Exception(edm::errors::Configuration) << "The parameters 'eta' and 'phi' must have the same size";
86  if (etaPoints.empty()) throw edm::Exception(edm::errors::Configuration) << "At least one point should be defined for point or candidate+point seeding modes";
87 
88  for(size_t i = 0; i < etaPoints.size(); ++i ){
89 
90  m_etaPhiPoints.push_back(std::make_pair(etaPoints[i],phiPoints[i]));
91 
92  double x = std::cos(phiPoints[i]);
93  double y = std::sin(phiPoints[i]);
94  double theta = 2*std::atan(std::exp(-etaPoints[i]));
95  double z = 1./std::tan(theta);
96  GlobalVector direction( x,y,z );
97  m_directionPoints.push_back(direction);
98 
99  }
100 
101  }
102 
103  m_maxNRegions = regPSet.getParameter<unsigned int>("maxNRegions");
104  if(m_maxNRegions==0) throw edm::Exception(edm::errors::Configuration) << "maxNRegions should be greater than or equal to 1";
105 
106  // RectangularEtaPhiTrackingRegion parameters:
107  m_ptMin = regPSet.getParameter<double>("ptMin");
108  m_originRadius = regPSet.getParameter<double>("originRadius");
109 
111  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
112  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
113  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";
114  }
116  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
117  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
118  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";
119  }
121  m_deltaEta_Cand = regPSet.getParameter<double>("deltaEta_Cand");
122  m_deltaPhi_Cand = regPSet.getParameter<double>("deltaPhi_Cand");
123  m_deltaEta_Point = regPSet.getParameter<double>("deltaEta_Point");
124  m_deltaPhi_Point = regPSet.getParameter<double>("deltaPhi_Point");
125  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";
126  }
127 
128  m_precise = regPSet.getParameter<bool>("precise");
130  if(m_whereToUseMeasurementTracker != RectangularEtaPhiTrackingRegion::UseMeasurementTracker::kNever) {
131  m_token_measurementTracker = iC.consumes<MeasurementTrackerEvent>(regPSet.getParameter<edm::InputTag>("measurementTrackerName"));
132  }
133  m_searchOpt = false;
134  if (regPSet.exists("searchOpt")) m_searchOpt = regPSet.getParameter<bool>("searchOpt");
135  }
136 
138 
141 
142  desc.add<std::string>("seedingMode", "Candidate");
143 
144  desc.add<edm::InputTag>("input", edm::InputTag(""));
145  edm::ParameterSetDescription descPoints;
146  descPoints.add<std::vector<double>> ("eta", {} );
147  descPoints.add<std::vector<double>> ("phi", {} );
148  desc.add<edm::ParameterSetDescription>("points", descPoints);
149 
150  desc.add<unsigned int>("maxNRegions", 10);
151 
152  VertexBeamspotOrigins::fillDescriptions(desc, "hltOnlineBeamSpot", "hltPixelVertices", 1);
153 
154  desc.add<double>("ptMin", 0.9);
155  desc.add<double>("originRadius", 0.2);
156  desc.add<double>("deltaEta_Cand", -1.);
157  desc.add<double>("deltaPhi_Cand", -1.);
158  desc.add<double>("deltaEta_Point", -1.);
159  desc.add<double>("deltaPhi_Point", -1.);
160  desc.add<bool>("precise", true);
161 
162  desc.add<std::string>("whereToUseMeasurementTracker", "ForSiStrips");
163  desc.add<edm::InputTag>("measurementTrackerName", edm::InputTag(""));
164 
165  desc.add<bool>("searchOpt", false);
166 
167  // Only for backwards-compatibility
168  edm::ParameterSetDescription descRegion;
169  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
170 
171  descriptions.add("candidatePointSeededTrackingRegionsFromBeamSpot", descRegion);
172  }
173 
174 
175  std::vector<std::unique_ptr<TrackingRegion> > regions(const edm::Event& e, const edm::EventSetup& es) const override
176  {
177  std::vector<std::unique_ptr<TrackingRegion> > result;
178 
179  // pick up the candidate objects of interest
181  size_t n_objects = 0;
182 
184  e.getByToken( m_token_input, objects );
185  n_objects = objects->size();
186  if (n_objects == 0) return result;
187  }
188 
189  const auto& objs = *objects;
190 
191  const auto& origins = m_origins.origins(e);
192  if(origins.empty()) {
193  return result;
194  }
195 
196  const MeasurementTrackerEvent *measurementTracker = nullptr;
200  measurementTracker = hmte.product();
201  }
202 
203  // create tracking regions (maximum MaxNRegions of them) in directions of the
204  // objects of interest (we expect that the collection was sorted in decreasing pt order)
205  int n_regions = 0;
206 
208 
209  for(const auto& object : objs) {
210 
211  GlobalVector direction( object.momentum().x(), object.momentum().y(), object.momentum().z() );
212 
213  for(const auto& origin : origins) {
214 
215  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(
216  direction,
217  origin.first,
218  m_ptMin,
220  origin.second,
224  m_precise,
225  measurementTracker,
227  ));
228  ++n_regions;
229  if( n_regions >= m_maxNRegions ) break;
230 
231  }
232 
233  if( n_regions >= m_maxNRegions ) break;
234 
235  }
236 
237  }
238 
239 
241 
242  for( const auto& direction : m_directionPoints ){
243 
244  for(const auto& origin : origins) {
245 
246  result.push_back( std::make_unique<RectangularEtaPhiTrackingRegion>(
247  direction, // GlobalVector
248  origin.first, // GlobalPoint
249  m_ptMin,
251  origin.second,
255  m_precise,
256  measurementTracker,
258  ));
259  ++n_regions;
260  if( n_regions >= m_maxNRegions ) break;
261 
262  }
263 
264  if( n_regions >= m_maxNRegions ) break;
265 
266  }
267 
268  }
269 
270 
272 
273  for(const auto& object : objs) {
274 
275  double eta_Cand = object.eta();
276  double phi_Cand = object.phi();
277 
278  for (const auto& etaPhiPoint : m_etaPhiPoints ){
279 
280  double eta_Point = etaPhiPoint.first;
281  double phi_Point = etaPhiPoint.second;
282  double dEta_Cand_Point = std::abs(eta_Cand-eta_Point);
283  double dPhi_Cand_Point = std::abs(deltaPhi(phi_Cand,phi_Point));
284 
285  //Check if there is an overlap between Candidate- and Point-based regions of interest
286  if(dEta_Cand_Point > (m_deltaEta_Cand + m_deltaEta_Point) || dPhi_Cand_Point > (m_deltaPhi_Cand + m_deltaPhi_Point)) continue;
287 
288  //Determines boundaries of intersection of RoIs
289  double etaMin_RoI = std::max(eta_Cand-m_deltaEta_Cand,eta_Point-m_deltaEta_Point);
290  double etaMax_RoI = std::min(eta_Cand+m_deltaEta_Cand,eta_Point+m_deltaEta_Point);
291 
292  double phi_Cand_minus = normalizedPhi(phi_Cand-m_deltaPhi_Cand);
293  double phi_Point_minus = normalizedPhi(phi_Point-m_deltaPhi_Point);
294  double phi_Cand_plus = normalizedPhi(phi_Cand+m_deltaPhi_Cand);
295  double phi_Point_plus = normalizedPhi(phi_Point+m_deltaPhi_Point);
296 
297  double phiMin_RoI = deltaPhi(phi_Cand_minus,phi_Point_minus)>0. ? phi_Cand_minus : phi_Point_minus ;
298  double phiMax_RoI = deltaPhi(phi_Cand_plus,phi_Point_plus)<0. ? phi_Cand_plus : phi_Point_plus;
299 
300  //Determines position and width of new RoI
301  double eta_RoI = 0.5*(etaMax_RoI+etaMin_RoI);
302  double deltaEta_RoI = etaMax_RoI - eta_RoI;
303 
304  double phi_RoI = 0.5*(phiMax_RoI+phiMin_RoI);
305  if( phiMax_RoI < phiMin_RoI ) phi_RoI-=M_PI;
306  phi_RoI = normalizedPhi(phi_RoI);
307  double deltaPhi_RoI = deltaPhi(phiMax_RoI,phi_RoI);
308 
309  double x = std::cos(phi_RoI);
310  double y = std::sin(phi_RoI);
311  double theta = 2*std::atan(std::exp(-eta_RoI));
312  double z = 1./std::tan(theta);
313 
314  GlobalVector direction( x,y,z );
315 
316  for(const auto& origin : origins) {
317 
318  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(
319  direction,
320  origin.first,
321  m_ptMin,
323  origin.second,
324  deltaEta_RoI,
325  deltaPhi_RoI,
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  if( n_regions >= m_maxNRegions ) break;
341 
342  }
343 
344  }
345 
346  edm::LogInfo ("CandidatePointSeededTrackingRegionsProducer") << "produced "<<n_regions<<" regions";
347 
348  return result;
349  }
350 
351 private:
352 
355 
358 
359  std::vector<std::pair<double,double> > m_etaPhiPoints;
360  std::vector<GlobalVector> m_directionPoints;
361 
362  float m_ptMin;
368  bool m_precise;
372 };
373 
374 #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:519
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)
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)
#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