CMS 3D CMS Logo

L1MuonSeededTrackingRegionsProducer.h
Go to the documentation of this file.
1 #ifndef RecoTracker_TkTrackingRegions_L1MuonSeededTrackingRegionsProducer_h
2 #define RecoTracker_TkTrackingRegions_L1MuonSeededTrackingRegionsProducer_h
3 
7 
25 #include "CLHEP/Vector/ThreeVector.h"
26 
28 
56 public:
58 
60  : token_field(iC.esConsumes()),
61  l1MinPt_(iConfig.getParameter<double>("L1MinPt")),
62  l1MaxEta_(iConfig.getParameter<double>("L1MaxEta")),
63  l1MinQuality_(iConfig.getParameter<unsigned int>("L1MinQuality")),
64  minPtBarrel_(iConfig.getParameter<double>("SetMinPtBarrelTo")),
65  minPtEndcap_(iConfig.getParameter<double>("SetMinPtEndcapTo")),
66  centralBxOnly_(iConfig.getParameter<bool>("CentralBxOnly")),
67  propagatorName_(iConfig.getParameter<std::string>("Propagator")) {
68  edm::ParameterSet regPSet = iConfig.getParameter<edm::ParameterSet>("RegionPSet");
69 
70  // operation mode
71  std::string modeString = regPSet.getParameter<std::string>("mode");
72  if (modeString == "BeamSpotFixed")
74  else if (modeString == "BeamSpotSigma")
76  else if (modeString == "VerticesFixed")
78  else if (modeString == "VerticesSigma")
80  else
81  edm::LogError("L1MuonSeededTrackingRegionsProducer") << "Unknown mode string: " << modeString;
82 
83  // basic inputs
84  token_input = iC.consumes<l1t::MuonBxCollection>(regPSet.getParameter<edm::InputTag>("input"));
85  m_maxNRegions = regPSet.getParameter<int>("maxNRegions");
86  token_beamSpot = iC.consumes<reco::BeamSpot>(regPSet.getParameter<edm::InputTag>("beamSpot"));
87  m_maxNVertices = 1;
89  token_vertex = iC.consumes<reco::VertexCollection>(regPSet.getParameter<edm::InputTag>("vertexCollection"));
90  m_maxNVertices = regPSet.getParameter<int>("maxNVertices");
91  }
92 
93  // RectangularEtaPhiTrackingRegion parameters:
94  m_ptMin = regPSet.getParameter<double>("ptMin");
95  m_originRadius = regPSet.getParameter<double>("originRadius");
96  m_zErrorBeamSpot = regPSet.getParameter<double>("zErrorBeamSpot");
97  m_ptRanges = regPSet.getParameter<std::vector<double>>("ptRanges");
98  if (m_ptRanges.size() < 2) {
99  edm::LogError("L1MuonSeededTrackingRegionsProducer") << "Size of ptRanges does not be less than 2" << std::endl;
100  }
101  m_deltaEtas = regPSet.getParameter<std::vector<double>>("deltaEtas");
102  if (m_deltaEtas.size() != m_ptRanges.size() - 1) {
103  edm::LogError("L1MuonSeededTrackingRegionsProducer")
104  << "Size of deltaEtas does not match number of pt bins." << std::endl;
105  }
106  m_deltaPhis = regPSet.getParameter<std::vector<double>>("deltaPhis");
107  if (m_deltaPhis.size() != m_ptRanges.size() - 1) {
108  edm::LogError("L1MuonSeededTrackingRegionsProducer")
109  << "Size of deltaPhis does not match number of pt bins." << std::endl;
110  }
111 
112  m_precise = regPSet.getParameter<bool>("precise");
114  regPSet.getParameter<std::string>("whereToUseMeasurementTracker"));
117  iC.consumes<MeasurementTrackerEvent>(regPSet.getParameter<edm::InputTag>("measurementTrackerName"));
118  }
119 
120  m_searchOpt = regPSet.getParameter<bool>("searchOpt");
121 
122  // mode-dependent z-halflength of tracking regions
123  if (m_mode == VERTICES_SIGMA)
124  m_nSigmaZVertex = regPSet.getParameter<double>("nSigmaZVertex");
125  if (m_mode == VERTICES_FIXED)
126  m_zErrorVetex = regPSet.getParameter<double>("zErrorVetex");
127  m_nSigmaZBeamSpot = -1.;
128  if (m_mode == BEAM_SPOT_SIGMA) {
129  m_nSigmaZBeamSpot = regPSet.getParameter<double>("nSigmaZBeamSpot");
130  if (m_nSigmaZBeamSpot < 0.)
131  edm::LogError("L1MuonSeededTrackingRegionsProducer")
132  << "nSigmaZBeamSpot must be positive for BeamSpotSigma mode!";
133  }
134  if (m_precise) {
135  token_msmaker = iC.esConsumes();
136  }
137 
138  // MuonServiceProxy
139  edm::ParameterSet serviceParameters = iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
140  service_ = std::make_unique<MuonServiceProxy>(serviceParameters, std::move(iC));
141  }
142 
143  ~L1MuonSeededTrackingRegionsProducer() override = default;
144 
147 
148  // L1 muon selection parameters
149  desc.add<std::string>("Propagator", "");
150  desc.add<double>("L1MinPt", -1.);
151  desc.add<double>("L1MaxEta", 5.0);
152  desc.add<unsigned int>("L1MinQuality", 0);
153  desc.add<double>("SetMinPtBarrelTo", 3.5);
154  desc.add<double>("SetMinPtEndcapTo", 1.0);
155  desc.add<bool>("CentralBxOnly", true);
156 
157  // Tracking region parameters
158  edm::ParameterSetDescription descRegion;
159  descRegion.add<std::string>("mode", "BeamSpotSigma");
160  descRegion.add<edm::InputTag>("input", edm::InputTag(""));
161  descRegion.add<int>("maxNRegions", 10);
162  descRegion.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"));
163  descRegion.add<edm::InputTag>("vertexCollection", edm::InputTag("notUsed"));
164  descRegion.add<int>("maxNVertices", 1);
165  descRegion.add<double>("ptMin", 0.0);
166  descRegion.add<double>("originRadius", 0.2);
167  descRegion.add<double>("zErrorBeamSpot", 24.2);
168  descRegion.add<std::vector<double>>("ptRanges", {0., 1.e9});
169  descRegion.add<std::vector<double>>("deltaEtas", {0.35});
170  descRegion.add<std::vector<double>>("deltaPhis", {0.2});
171  descRegion.add<bool>("precise", true);
172  descRegion.add<double>("nSigmaZVertex", 3.);
173  descRegion.add<double>("zErrorVetex", 0.2);
174  descRegion.add<double>("nSigmaZBeamSpot", 4.);
175  descRegion.add<std::string>("whereToUseMeasurementTracker", "Never");
176  descRegion.add<edm::InputTag>("measurementTrackerName", edm::InputTag(""));
177  descRegion.add<bool>("searchOpt", false);
178  desc.add<edm::ParameterSetDescription>("RegionPSet", descRegion);
179 
180  // MuonServiceProxy for the propagation
182  psd0.addUntracked<std::vector<std::string>>("Propagators", {"SteppingHelixPropagatorAny"});
183  psd0.add<bool>("RPCLayers", false);
184  psd0.addUntracked<bool>("UseMuonNavigation", false);
185  desc.add<edm::ParameterSetDescription>("ServiceParameters", psd0);
186 
187  descriptions.add("hltIterL3MuonPixelTracksTrackingRegions", desc);
188  }
189 
190  std::vector<std::unique_ptr<TrackingRegion>> regions(const edm::Event& iEvent,
191  const edm::EventSetup& iSetup) const override {
192  std::vector<std::unique_ptr<TrackingRegion>> result;
193 
194  // pick up the candidate objects of interest
196  iEvent.getByToken(token_input, muColl);
197  if (muColl->size() == 0)
198  return result;
199 
200  // always need the beam spot (as a fall back strategy for vertex modes)
202  iEvent.getByToken(token_beamSpot, bs);
203  if (!bs.isValid())
204  return result;
205 
206  // this is a default origin for all modes
207  GlobalPoint default_origin(bs->x0(), bs->y0(), bs->z0());
208 
209  // vector of origin & halfLength pairs:
210  std::vector<std::pair<GlobalPoint, float>> origins;
211 
212  // fill the origins and halfLengths depending on the mode
214  origins.push_back(std::make_pair(
215  default_origin, (m_mode == BEAM_SPOT_FIXED) ? m_zErrorBeamSpot : m_nSigmaZBeamSpot * bs->sigmaZ()));
216  } else if (m_mode == VERTICES_FIXED || m_mode == VERTICES_SIGMA) {
218  iEvent.getByToken(token_vertex, vertices);
219  int n_vert = 0;
220  for (reco::VertexCollection::const_iterator v = vertices->begin();
221  v != vertices->end() && n_vert < m_maxNVertices;
222  ++v) {
223  if (v->isFake() || !v->isValid())
224  continue;
225 
226  origins.push_back(std::make_pair(GlobalPoint(v->x(), v->y(), v->z()),
227  (m_mode == VERTICES_FIXED) ? m_zErrorVetex : m_nSigmaZVertex * v->zError()));
228  ++n_vert;
229  }
230  // no-vertex fall-back case:
231  if (origins.empty()) {
232  origins.push_back(std::make_pair(
233  default_origin, (m_nSigmaZBeamSpot > 0.) ? m_nSigmaZBeamSpot * bs->z0Error() : m_zErrorBeamSpot));
234  }
235  }
236 
240  }
241 
242  const auto& field = iSetup.getData(token_field);
243  const MultipleScatteringParametrisationMaker* msmaker = nullptr;
244  if (m_precise) {
245  msmaker = &iSetup.getData(token_msmaker);
246  }
247 
248  // create tracking regions (maximum MaxNRegions of them) in directions of the
249  // objects of interest (we expect that the collection was sorted in decreasing pt order)
250  int n_regions = 0;
251  for (int ibx = muColl->getFirstBX(); ibx <= muColl->getLastBX() && n_regions < m_maxNRegions; ++ibx) {
252  if (centralBxOnly_ && (ibx != 0))
253  continue;
254 
255  for (auto it = muColl->begin(ibx); it != muColl->end(ibx) && n_regions < m_maxNRegions; it++) {
256  unsigned int quality = it->hwQual();
257  if (quality <= l1MinQuality_)
258  continue;
259 
260  float pt = it->pt();
261  float eta = it->eta();
262  if (pt < l1MinPt_ || std::abs(eta) > l1MaxEta_)
263  continue;
264 
265  float theta = 2 * atan(exp(-eta));
266  float phi = it->phi();
267 
268  int valid_charge = it->hwChargeValid();
269  int charge = it->charge();
270  if (!valid_charge)
271  charge = 0;
272 
273  int link = l1MuonTF_link_EMTFP_i_ + (int)(it->tfMuonIndex() / 3.);
274  bool barrel = true;
277  barrel = false;
278 
279  // propagate L1 FTS to BS
280  service_->update(iSetup);
281  const DetLayer* detLayer = nullptr;
282  float radius = 0.;
283 
284  CLHEP::Hep3Vector vec(0., 1., 0.);
285  vec.setTheta(theta);
286  vec.setPhi(phi);
287 
288  DetId theid;
289  // Get the det layer on which the state should be put
290  if (barrel) {
291  // MB2
292  theid = DTChamberId(0, 2, 0);
293  detLayer = service_->detLayerGeometry()->idToLayer(theid);
294 
295  const BoundSurface* sur = &(detLayer->surface());
296  const BoundCylinder* bc = dynamic_cast<const BoundCylinder*>(sur);
297 
298  radius = std::abs(bc->radius() / sin(theta));
299 
300  if (pt < minPtBarrel_)
301  pt = minPtBarrel_;
302  } else {
303  // ME2
304  theid = theta < M_PI / 2. ? CSCDetId(1, 2, 0, 0, 0) : CSCDetId(2, 2, 0, 0, 0);
305 
306  detLayer = service_->detLayerGeometry()->idToLayer(theid);
307 
308  radius = std::abs(detLayer->position().z() / cos(theta));
309 
310  if (pt < minPtEndcap_)
311  pt = minPtEndcap_;
312  }
313  vec.setMag(radius);
314  GlobalPoint pos(vec.x(), vec.y(), vec.z());
315  GlobalVector mom(pt * cos(phi), pt * sin(phi), pt * cos(theta) / sin(theta));
316  GlobalTrajectoryParameters param(pos, mom, charge, &*service_->magneticField());
317 
319  mat[0][0] = (sigma_qbpt_barrel_ / pt) * (sigma_qbpt_barrel_ / pt); // sigma^2(charge/abs_momentum)
320  if (!barrel)
321  mat[0][0] = (sigma_qbpt_endcap_ / pt) * (sigma_qbpt_endcap_ / pt);
322 
323  //Assign q/pt = 0 +- 1/pt if charge has been declared invalid
324  if (!valid_charge)
326 
327  mat[1][1] = sigma_lambda_ * sigma_lambda_; // sigma^2(lambda)
328  mat[2][2] = sigma_phi_ * sigma_phi_; // sigma^2(phi)
329  mat[3][3] = sigma_x_ * sigma_x_; // sigma^2(x_transverse))
330  mat[4][4] = sigma_y_ * sigma_y_; // sigma^2(y_transverse))
331 
333 
334  const FreeTrajectoryState state(param, error);
335 
336  FreeTrajectoryState state_bs = service_->propagator(propagatorName_)->propagate(state, *bs.product());
337 
338  GlobalVector direction(state_bs.momentum().x(), state_bs.momentum().y(), state_bs.momentum().z());
339 
340  // set deltaEta and deltaPhi from L1 muon pt
341  auto deltaEta = m_deltaEtas.at(0);
342  auto deltaPhi = m_deltaPhis.at(0);
343  if (it->pt() < m_ptRanges.back()) {
344  auto lowEdge = std::upper_bound(m_ptRanges.begin(), m_ptRanges.end(), it->pt());
345  deltaEta = m_deltaEtas.at(lowEdge - m_ptRanges.begin() - 1);
346  deltaPhi = m_deltaPhis.at(lowEdge - m_ptRanges.begin() - 1);
347  }
348 
349  for (size_t j = 0; j < origins.size() && n_regions < m_maxNRegions; ++j) {
350  result.push_back(std::make_unique<RectangularEtaPhiTrackingRegion>(direction,
351  origins[j].first,
352  m_ptMin,
354  origins[j].second,
355  deltaEta,
356  deltaPhi,
357  field,
358  msmaker,
359  m_precise,
362  m_searchOpt));
363  ++n_regions;
364  }
365  }
366  }
367  edm::LogInfo("L1MuonSeededTrackingRegionsProducer") << "produced " << n_regions << " regions";
368 
369  return result;
370  }
371 
372 private:
374 
380 
381  float m_ptMin;
384  std::vector<double> m_ptRanges;
385  std::vector<double> m_deltaEtas;
386  std::vector<double> m_deltaPhis;
387  bool m_precise;
393 
397 
398  const double l1MinPt_;
399  const double l1MaxEta_;
400  const unsigned l1MinQuality_;
401  const double minPtBarrel_;
402  const double minPtEndcap_;
403  const bool centralBxOnly_;
404 
406  std::unique_ptr<MuonServiceProxy> service_;
407 
408  // link number indices of the optical fibres that connect the uGMT with the track finders
409  // EMTF+ : 36-41, OMTF+ : 42-47, BMTF : 48-59, OMTF- : 60-65, EMTF- : 66-71
410  static constexpr int l1MuonTF_link_EMTFP_i_{36};
411  static constexpr int l1MuonTF_link_EMTFP_f_{41};
412  static constexpr int l1MuonTF_link_EMTFN_i_{66};
413  static constexpr int l1MuonTF_link_EMTFN_f_{71};
414 
415  // fixed error matrix parameters for L1 muon FTS
416  static constexpr double sigma_qbpt_barrel_{0.25};
417  static constexpr double sigma_qbpt_endcap_{0.4};
418  static constexpr double sigma_qbpt_invalid_charge_{1.0};
419  static constexpr double sigma_lambda_{0.05};
420  static constexpr double sigma_phi_{0.2};
421  static constexpr double sigma_x_{20.0};
422  static constexpr double sigma_y_{20.0};
423 };
424 
425 #endif
int getLastBX() const
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
int getFirstBX() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual const Surface::PositionType & position() const
Returns position of the surface.
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
T z() const
Definition: PV3DBase.h:61
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
edm::EDGetTokenT< MeasurementTrackerEvent > token_measurementTracker
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
static UseMeasurementTracker stringToUseMeasurementTracker(const std::string &name)
edm::EDGetTokenT< l1t::MuonBxCollection > token_input
Log< level::Error, false > LogError
~L1MuonSeededTrackingRegionsProducer() override=default
static const double deltaEta
Definition: CaloConstants.h:8
const_iterator begin(int bx) const
unsigned size(int bx) const
U second(std::pair< T, U > const &p)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
string quality
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
GlobalVector momentum() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< reco::VertexCollection > token_vertex
#define M_PI
Log< level::Info, false > LogInfo
Definition: DetId.h:17
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > token_field
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
RectangularEtaPhiTrackingRegion::UseMeasurementTracker m_whereToUseMeasurementTracker
const_iterator end(int bx) const
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &iEvent, const edm::EventSetup &iSetup) const override
L1MuonSeededTrackingRegionsProducer(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
Geom::Theta< T > theta() const
def move(src, dest)
Definition: eostools.py:511
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > token_msmaker