CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonTrackingRegionBuilder.cc
Go to the documentation of this file.
1 
11 
12 //-------------------------------
13 // Collaborating Class Headers --
14 //-------------------------------
15 
17 
22 
29 
33 
34 //
35 // constructor
36 //
38  // Adjust errors on Eta, Phi, Z
39  theNsigmaEta = par.getParameter<double>("Rescale_eta");
40  theNsigmaPhi = par.getParameter<double>("Rescale_phi");
41  theNsigmaDz = par.getParameter<double>("Rescale_Dz");
42 
43  // Upper limits parameters
44  theEtaRegionPar1 = par.getParameter<double>("EtaR_UpperLimit_Par1");
45  theEtaRegionPar2 = par.getParameter<double>("EtaR_UpperLimit_Par2");
46  thePhiRegionPar1 = par.getParameter<double>("PhiR_UpperLimit_Par1");
47  thePhiRegionPar2 = par.getParameter<double>("PhiR_UpperLimit_Par2");
48 
49  // Flag to switch to use Vertices instead of BeamSpot
50  useVertex = par.getParameter<bool>("UseVertex");
51 
52  // Flag to use fixed limits for Eta, Phi, Z, pT
53  useFixedZ = par.getParameter<bool>("Z_fixed");
54  useFixedPt = par.getParameter<bool>("Pt_fixed");
55  useFixedPhi = par.getParameter<bool>("Phi_fixed");
56  useFixedEta = par.getParameter<bool>("Eta_fixed");
57 
58  // Minimum value for pT
59  thePtMin = par.getParameter<double>("Pt_min");
60 
61  // Minimum value for Phi
62  thePhiMin = par.getParameter<double>("Phi_min");
63 
64  // Minimum value for Eta
65  theEtaMin = par.getParameter<double>("Eta_min");
66 
67  // The static region size along the Z direction
68  theHalfZ = par.getParameter<double>("DeltaZ");
69 
70  // The transverse distance of the region from the BS/PV
71  theDeltaR = par.getParameter<double>("DeltaR");
72 
73  // The static region size in Eta
74  theDeltaEta = par.getParameter<double>("DeltaEta");
75 
76  // The static region size in Phi
77  theDeltaPhi = par.getParameter<double>("DeltaPhi");
78 
79  // Maximum number of regions to build when looping over Muons
80  theMaxRegions = par.getParameter<int>("maxRegions");
81 
82  // Flag to use precise??
83  thePrecise = par.getParameter<bool>("precise");
84 
85  // perigee reference point ToDo: Check this
89  iC.consumes<MeasurementTrackerEvent>(par.getParameter<edm::InputTag>("MeasurementTrackerName"));
90  }
91 
92  // Vertex collection and Beam Spot
95 
96  // Input muon collection
98 
99  bfieldToken = iC.esConsumes();
100  if (thePrecise) {
101  msmakerToken = iC.esConsumes();
102  }
103 }
104 
105 //
106 // Member function to be compatible with TrackingRegionProducerFactory: create many ROI for many tracks
107 //
108 std::vector<std::unique_ptr<TrackingRegion>> MuonTrackingRegionBuilder::regions(const edm::Event& ev,
109  const edm::EventSetup& es) const {
110  std::vector<std::unique_ptr<TrackingRegion>> result;
111 
113  ev.getByToken(inputCollectionToken, tracks);
114 
115  int nRegions = 0;
116  for (auto it = tracks->cbegin(), ed = tracks->cend(); it != ed && nRegions < theMaxRegions; ++it) {
117  result.push_back(region(*it, ev, es));
118  nRegions++;
119  }
120 
121  return result;
122 }
123 
124 //
125 // Call region on Track from TrackRef
126 //
127 std::unique_ptr<RectangularEtaPhiTrackingRegion> MuonTrackingRegionBuilder::region(const reco::TrackRef& track) const {
128  return region(*track);
129 }
130 
131 //
132 // ToDo: Not sure if this is needed?
133 //
135  theEvent = &event;
136  theEventSetup = &es;
137 }
138 
139 //
140 // Main member function called to create the ROI
141 //
142 std::unique_ptr<RectangularEtaPhiTrackingRegion> MuonTrackingRegionBuilder::region(const reco::Track& staTrack,
143  const edm::Event& ev,
144  const edm::EventSetup& es) const {
145  // get track momentum/direction at vertex
146  const math::XYZVector& mom = staTrack.momentum();
147  GlobalVector dirVector(mom.x(), mom.y(), mom.z());
148  double pt = staTrack.pt();
149 
150  // Fix for StandAlone tracks with low momentum
151  const math::XYZVector& innerMomentum = staTrack.innerMomentum();
152  GlobalVector forSmallMomentum(innerMomentum.x(), innerMomentum.y(), innerMomentum.z());
153  if (staTrack.p() <= 1.5) {
154  pt = std::abs(forSmallMomentum.perp());
155  }
156 
157  // initial vertex position - in the following it is replaced with beamspot/vertexing
158  GlobalPoint vertexPos(0.0, 0.0, 0.0);
159  // standard 15.9, if useVertex than use error from vertex
160  double deltaZ = theHalfZ;
161 
162  // retrieve beam spot information
164  bool bsHandleFlag = ev.getByToken(beamSpotToken, bs);
165 
166  // check the validity, otherwise vertexing
167  if (bsHandleFlag && bs.isValid() && !useVertex) {
168  vertexPos = GlobalPoint(bs->x0(), bs->y0(), bs->z0());
169  deltaZ = useFixedZ ? theHalfZ : bs->sigmaZ() * theNsigmaDz;
170  } else {
171  // get originZPos from list of reconstructed vertices (first or all)
173  bool vtxHandleFlag = ev.getByToken(vertexCollectionToken, vertexCollection);
174  // check if there exists at least one reconstructed vertex
175  if (vtxHandleFlag && !vertexCollection->empty()) {
176  // use the first vertex in the collection and assume it is the primary event vertex
177  reco::VertexCollection::const_iterator vtx = vertexCollection->begin();
178  if (!vtx->isFake() && vtx->isValid()) {
179  vertexPos = GlobalPoint(vtx->x(), vtx->y(), vtx->z());
180  deltaZ = useFixedZ ? theHalfZ : vtx->zError() * theNsigmaDz;
181  }
182  }
183  }
184 
185  // inizialize to the maximum possible value
186  double deta = 0.4;
187  double dphi = 0.6;
188 
189  // evaluate the dynamical region if possible
190  deta = theNsigmaEta * (staTrack.etaError());
191  dphi = theNsigmaPhi * (staTrack.phiError());
192 
193  // Region_Parametrizations to take into account possible L2 error matrix inconsistencies
194  double region_dEta = 0;
195  double region_dPhi = 0;
196  double eta = 0;
197  double phi = 0;
198 
199  // eta, pt parametrization from MC study (circa 2009?)
200  if (pt <= 10.) {
201  // angular coefficients
202  float acoeff_Phi = (thePhiRegionPar2 - thePhiRegionPar1) / 5;
203  float acoeff_Eta = (theEtaRegionPar2 - theEtaRegionPar1) / 5;
204 
205  eta = theEtaRegionPar1 + (acoeff_Eta) * (pt - 5.);
206  phi = thePhiRegionPar1 + (acoeff_Phi) * (pt - 5.);
207  }
208  // parametrization 2nd bin in pt from MC study
209  if (pt > 10. && pt < 100.) {
210  eta = theEtaRegionPar2;
211  phi = thePhiRegionPar2;
212  }
213  // parametrization 3rd bin in pt from MC study
214  if (pt >= 100.) {
215  // angular coefficients
216  float acoeff_Phi = (thePhiRegionPar1 - thePhiRegionPar2) / 900;
217  float acoeff_Eta = (theEtaRegionPar1 - theEtaRegionPar2) / 900;
218 
219  eta = theEtaRegionPar2 + (acoeff_Eta) * (pt - 100.);
220  phi = thePhiRegionPar2 + (acoeff_Phi) * (pt - 100.);
221  }
222 
223  double region_dPhi1 = std::min(phi, dphi);
224  double region_dEta1 = std::min(eta, deta);
225 
226  // decide to use either a parametrization or a dynamical region
227  region_dPhi = useFixedPhi ? theDeltaPhi : std::max(thePhiMin, region_dPhi1);
228  region_dEta = useFixedEta ? theDeltaEta : std::max(theEtaMin, region_dEta1);
229 
230  float deltaR = theDeltaR;
231  double minPt = useFixedPt ? thePtMin : std::max(thePtMin, pt * 0.6);
232 
237  measurementTracker = hmte.product();
238  }
239 
240  const auto& bfield = es.getData(bfieldToken);
241  const MultipleScatteringParametrisationMaker* msmaker = nullptr;
242  if (thePrecise) {
243  msmaker = &es.getData(msmakerToken);
244  }
245 
246  auto region = std::make_unique<RectangularEtaPhiTrackingRegion>(dirVector,
247  vertexPos,
248  minPt,
249  deltaR,
250  deltaZ,
251  region_dEta,
252  region_dPhi,
253  bfield,
254  msmaker,
255  thePrecise,
256  theOnDemand,
258 
259  LogDebug("MuonTrackingRegionBuilder") << "the region parameters are:\n"
260  << "\n dirVector: " << dirVector << "\n vertexPos: " << vertexPos
261  << "\n minPt: " << minPt << "\n deltaR:" << deltaR << "\n deltaZ:" << deltaZ
262  << "\n region_dEta:" << region_dEta << "\n region_dPhi:" << region_dPhi
263  << "\n on demand parameter: " << static_cast<int>(theOnDemand);
264 
265  return region;
266 }
267 
269  {
272  descriptions.add("MuonTrackingRegionBuilder", desc);
273  }
274  {
276  fillDescriptionsHLT(desc);
277  descriptions.add("MuonTrackingRegionBuilderHLT", desc);
278  }
279  descriptions.setComment(
280  "Build a TrackingRegion around a standalone muon. Options to define region around beamspot or primary vertex and "
281  "dynamic regions are included.");
282 }
284  desc.add<double>("EtaR_UpperLimit_Par1", 0.25);
285  desc.add<double>("DeltaR", 0.2);
286  desc.add<edm::InputTag>("beamSpot", edm::InputTag("hltOnlineBeamSpot"));
287  desc.add<int>("OnDemand", -1);
288  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("pixelVertices"));
289  desc.add<double>("Rescale_phi", 3.0);
290  desc.add<bool>("Eta_fixed", false);
291  desc.add<double>("Rescale_eta", 3.0);
292  desc.add<double>("PhiR_UpperLimit_Par2", 0.2);
293  desc.add<double>("Eta_min", 0.05);
294  desc.add<bool>("Phi_fixed", false);
295  desc.add<double>("Phi_min", 0.05);
296  desc.add<double>("PhiR_UpperLimit_Par1", 0.6);
297  desc.add<double>("EtaR_UpperLimit_Par2", 0.15);
298  desc.add<edm::InputTag>("MeasurementTrackerName", edm::InputTag("hltESPMeasurementTracker"));
299  desc.add<bool>("UseVertex", false);
300  desc.add<double>("Rescale_Dz", 3.0);
301  desc.add<bool>("Pt_fixed", false);
302  desc.add<bool>("Z_fixed", true);
303  desc.add<double>("Pt_min", 1.5);
304  desc.add<double>("DeltaZ", 15.9);
305  desc.add<double>("DeltaEta", 0.2);
306  desc.add<double>("DeltaPhi", 0.2);
307  desc.add<int>("maxRegions", 1);
308  desc.add<bool>("precise", true);
309  desc.add<edm::InputTag>("input", edm::InputTag("hltL2Muons", "UpdatedAtVtx"));
310 }
311 
313  desc.add<double>("EtaR_UpperLimit_Par1", 0.25);
314  desc.add<double>("DeltaR", 0.2);
315  desc.add<edm::InputTag>("beamSpot", edm::InputTag(""));
316  desc.add<int>("OnDemand", -1);
317  desc.add<edm::InputTag>("vertexCollection", edm::InputTag(""));
318  desc.add<double>("Rescale_phi", 3.0);
319  desc.add<bool>("Eta_fixed", false);
320  desc.add<double>("Rescale_eta", 3.0);
321  desc.add<double>("PhiR_UpperLimit_Par2", 0.2);
322  desc.add<double>("Eta_min", 0.05);
323  desc.add<bool>("Phi_fixed", false);
324  desc.add<double>("Phi_min", 0.05);
325  desc.add<double>("PhiR_UpperLimit_Par1", 0.6);
326  desc.add<double>("EtaR_UpperLimit_Par2", 0.15);
327  desc.add<edm::InputTag>("MeasurementTrackerName", edm::InputTag(""));
328  desc.add<bool>("UseVertex", false);
329  desc.add<double>("Rescale_Dz", 3.0);
330  desc.add<bool>("Pt_fixed", false);
331  desc.add<bool>("Z_fixed", true);
332  desc.add<double>("Pt_min", 1.5);
333  desc.add<double>("DeltaZ", 15.9);
334  desc.add<double>("DeltaEta", 0.2);
335  desc.add<double>("DeltaPhi", 0.2);
336  desc.add<int>("maxRegions", 1);
337  desc.add<bool>("precise", true);
338  desc.add<edm::InputTag>("input", edm::InputTag(""));
339 }
double p() const
momentum vector magnitude
Definition: TrackBase.h:631
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
tuple measurementTracker
const edm::EventSetup * theEventSetup
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
double etaError() const
error on eta
Definition: TrackBase.h:763
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > msmakerToken
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Add Fill Descriptions.
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
auto const & tracks
cannot be loose
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
tuple vertexCollection
std::unique_ptr< RectangularEtaPhiTrackingRegion > region(const reco::TrackRef &) const
Define tracking region.
tuple result
Definition: mps_fire.py:311
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void build(const edm::ParameterSet &, edm::ConsumesCollector &)
double pt() const
track transverse momentum
Definition: TrackBase.h:637
void setEvent(const edm::Event &, const edm::EventSetup &)
Pass the Event to the algo at each event.
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bfieldToken
double phiError() const
error on phi
Definition: TrackBase.h:766
RectangularEtaPhiTrackingRegion::UseMeasurementTracker theOnDemand
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
void setComment(std::string const &value)
T const * product() const
Definition: Handle.h:70
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
edm::EDGetTokenT< reco::TrackCollection > inputCollectionToken
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &, const edm::EventSetup &) const override
Create Region of Interest.
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
edm::EDGetTokenT< reco::VertexCollection > vertexCollectionToken
static void fillDescriptionsOffline(edm::ParameterSetDescription &descriptions)
static UseMeasurementTracker intToUseMeasurementTracker(int value)
static void fillDescriptionsHLT(edm::ParameterSetDescription &descriptions)
edm::EDGetTokenT< MeasurementTrackerEvent > theMeasurementTrackerToken
#define LogDebug(id)