CMS 3D CMS Logo

PointSeededTrackingRegionsProducer.h
Go to the documentation of this file.
1 #ifndef PointSeededTrackingRegionsProducer_h
2 #define PointSeededTrackingRegionsProducer_h
3 
7 
24 
25 #include <TMath.h>
26 #include <TLorentzVector.h>
27 
53 public:
55 
57  : token_field(iC.esConsumes()) {
58  edm::ParameterSet regPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
59 
60  // operation mode
61  std::string modeString = regPSet.getParameter<std::string>("mode");
62  if (modeString == "BeamSpotFixed")
64  else if (modeString == "BeamSpotSigma")
66  else if (modeString == "VerticesFixed")
68  else if (modeString == "VerticesSigma")
70  else
71  edm::LogError("PointSeededTrackingRegionsProducer") << "Unknown mode string: " << modeString;
72 
73  // basic inputsi
75  etaPoints = points.getParameter<std::vector<double>>("eta");
76  phiPoints = points.getParameter<std::vector<double>>("phi");
77  if (!(etaPoints.size() == phiPoints.size()))
78  throw edm::Exception(edm::errors::Configuration) << "The parameters 'eta' and 'phi' must have the same size";
79  ;
80  m_maxNRegions = regPSet.getParameter<int>("maxNRegions");
81  token_beamSpot = iC.consumes<reco::BeamSpot>(regPSet.getParameter<edm::InputTag>("beamSpot"));
82  m_maxNVertices = 1;
84  token_vertex = iC.consumes<reco::VertexCollection>(regPSet.getParameter<edm::InputTag>("vertexCollection"));
85  m_maxNVertices = regPSet.getParameter<int>("maxNVertices");
86  }
87 
88  // RectangularEtaPhiTrackingRegion parameters:
89  m_ptMin = regPSet.getParameter<double>("ptMin");
90  m_originRadius = regPSet.getParameter<double>("originRadius");
91  m_zErrorBeamSpot = regPSet.getParameter<double>("zErrorBeamSpot");
92  m_deltaEta = regPSet.getParameter<double>("deltaEta");
93  m_deltaPhi = regPSet.getParameter<double>("deltaPhi");
94  m_precise = regPSet.getParameter<bool>("precise");
96  regPSet.getParameter<std::string>("whereToUseMeasurementTracker"));
99  iC.consumes<MeasurementTrackerEvent>(regPSet.getParameter<edm::InputTag>("measurementTrackerName"));
100  }
101  m_searchOpt = false;
102  if (regPSet.exists("searchOpt"))
103  m_searchOpt = regPSet.getParameter<bool>("searchOpt");
104 
105  // mode-dependent z-halflength of tracking regions
106  if (m_mode == VERTICES_SIGMA)
107  m_nSigmaZVertex = regPSet.getParameter<double>("nSigmaZVertex");
108  if (m_mode == VERTICES_FIXED)
109  m_zErrorVetex = regPSet.getParameter<double>("zErrorVetex");
110  m_nSigmaZBeamSpot = -1.;
111  if (m_mode == BEAM_SPOT_SIGMA) {
112  m_nSigmaZBeamSpot = regPSet.getParameter<double>("nSigmaZBeamSpot");
113  if (m_nSigmaZBeamSpot < 0.)
114  edm::LogError("PointSeededTrackingRegionsProducer")
115  << "nSigmaZBeamSpot must be positive for BeamSpotSigma mode!";
116  }
117 
118  if (m_precise) {
119  token_msmaker = iC.esConsumes();
120  }
121  }
122 
124 
127 
128  edm::ParameterSetDescription descPoints;
129  descPoints.add<std::vector<double>>("eta", {0.});
130  descPoints.add<std::vector<double>>("phi", {0.});
131  desc.add<edm::ParameterSetDescription>("points", descPoints);
132 
133  desc.add<std::string>("mode", "BeamSpotFixed");
134  desc.add<int>("maxNRegions", 10);
135  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"));
136  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
137  desc.add<int>("maxNVertices", 1);
138 
139  desc.add<double>("ptMin", 0.9);
140  desc.add<double>("originRadius", 0.2);
141  desc.add<double>("zErrorBeamSpot", 24.2);
142  desc.add<double>("deltaEta", 0.5);
143  desc.add<double>("deltaPhi", 0.5);
144  desc.add<bool>("precise", true);
145 
146  desc.add<double>("nSigmaZVertex", 3.);
147  desc.add<double>("zErrorVetex", 0.2);
148  desc.add<double>("nSigmaZBeamSpot", 4.);
149 
150  desc.add<std::string>("whereToUseMeasurementTracker", "ForSiStrips");
151  desc.add<edm::InputTag>("measurementTrackerName", edm::InputTag(""));
152 
153  desc.add<bool>("searchOpt", false);
154 
155  // Only for backwards-compatibility
156  edm::ParameterSetDescription descRegion;
157  descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
158  //edm::ParameterSetDescription descPoint;
159  //descPoint.add<edm::ParameterSetDescription>("point_input", desc);
160 
161  descriptions.add("pointSeededTrackingRegion", descRegion);
162  }
163 
164  std::vector<std::unique_ptr<TrackingRegion>> regions(const edm::Event& e, const edm::EventSetup& es) const override {
165  std::vector<std::unique_ptr<TrackingRegion>> result;
166 
167  // always need the beam spot (as a fall back strategy for vertex modes)
169  e.getByToken(token_beamSpot, bs);
170  if (!bs.isValid())
171  return result;
172 
173  const auto& field = es.getData(token_field);
174  const MultipleScatteringParametrisationMaker* msmaker = nullptr;
175  if (m_precise) {
176  msmaker = &es.getData(token_msmaker);
177  }
178 
179  // this is a default origin for all modes
180  GlobalPoint default_origin(bs->x0(), bs->y0(), bs->z0());
181 
182  // vector of origin & halfLength pairs:
183  std::vector<std::pair<GlobalPoint, float>> origins;
184 
185  // fill the origins and halfLengths depending on the mode
187  origins.push_back(std::make_pair(
188  default_origin, (m_mode == BEAM_SPOT_FIXED) ? m_zErrorBeamSpot : m_nSigmaZBeamSpot * bs->sigmaZ()));
189  } else if (m_mode == VERTICES_FIXED || m_mode == VERTICES_SIGMA) {
191  e.getByToken(token_vertex, vertices);
192  int n_vert = 0;
193  for (reco::VertexCollection::const_iterator iv = vertices->begin(), ev = vertices->end();
194  iv != ev && n_vert < m_maxNVertices;
195  ++iv) {
196  if (iv->isFake() || !iv->isValid())
197  continue;
198 
199  origins.push_back(std::make_pair(GlobalPoint(iv->x(), iv->y(), iv->z()),
200  (m_mode == VERTICES_FIXED) ? m_zErrorVetex : m_nSigmaZVertex * iv->zError()));
201  ++n_vert;
202  }
203  // no-vertex fall-back case:
204  if (origins.empty()) {
205  origins.push_back(std::make_pair(
206  default_origin, (m_nSigmaZBeamSpot > 0.) ? m_nSigmaZBeamSpot * bs->z0Error() : m_zErrorBeamSpot));
207  }
208  }
209 
213  e.getByToken(token_measurementTracker, hmte);
214  measurementTracker = hmte.product();
215  }
216 
217  // create tracking regions (maximum MaxNRegions of them) in directions of the
218  // points of interest
219  size_t n_points = etaPoints.size();
220  int n_regions = 0;
221  for (size_t i = 0; i < n_points && n_regions < m_maxNRegions; ++i) {
222  double x = std::cos(phiPoints[i]);
223  double y = std::sin(phiPoints[i]);
224  double theta = 2 * std::atan(std::exp(-etaPoints[i]));
225  double z = 1. / std::tan(theta);
226 
227  GlobalVector direction(x, y, z);
228 
229  for (size_t j = 0; j < origins.size() && n_regions < m_maxNRegions; ++j) {
230  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(direction, // GlobalVector
231  origins[j].first, // GlobalPoint
232  m_ptMin,
234  origins[j].second,
235  m_deltaEta,
236  m_deltaPhi,
237  field,
238  msmaker,
239  m_precise,
242  m_searchOpt));
243  ++n_regions;
244  }
245  }
246  edm::LogInfo("PointSeededTrackingRegionsProducer") << "produced " << n_regions << " regions";
247 
248  return result;
249  }
250 
251 private:
253 
258 
259  std::vector<double> etaPoints;
260  std::vector<double> phiPoints;
261 
262  float m_ptMin;
265  float m_deltaEta;
266  float m_deltaPhi;
267  bool m_precise;
273 
277 };
278 
279 #endif
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > token_field
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > token_msmaker
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
int32_t *__restrict__ iv
edm::EDGetTokenT< reco::BeamSpot > token_beamSpot
PointSeededTrackingRegionsProducer(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool exists(std::string const &parameterName) const
checks if a parameter exists
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
static UseMeasurementTracker stringToUseMeasurementTracker(const std::string &name)
Log< level::Error, false > LogError
edm::EDGetTokenT< MeasurementTrackerEvent > token_measurementTracker
RectangularEtaPhiTrackingRegion::UseMeasurementTracker m_whereToUseMeasurementTracker
U second(std::pair< T, U > const &p)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::VertexCollection > token_vertex
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Info, false > LogInfo
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &e, const edm::EventSetup &es) const override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Geom::Theta< T > theta() const