CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonTrackingRegionByPtBuilder.cc
Go to the documentation of this file.
2 
3 //-------------------------------
4 // Collaborating Class Headers --
5 //-------------------------------
6 
8 
13 
20 
24 
25 //
26 // constructor
27 //
29  // Adjust errors on dz
30  theNsigmaDz = par.getParameter<double>("Rescale_Dz");
31 
32  // Flag to switch to use Vertices instead of BeamSpot
33  useVertex = par.getParameter<bool>("UseVertex");
34 
35  // Flag to use fixed limits for Eta, Phi, Z, pT
36  useFixedZ = par.getParameter<bool>("Z_fixed");
37  useFixedPt = par.getParameter<bool>("Pt_fixed");
38 
39  // Minimum value for pT
40  thePtMin = par.getParameter<double>("Pt_min");
41 
42  // The static region size along the Z direction
43  theHalfZ = par.getParameter<double>("DeltaZ");
44 
45  // The transverse distance of the region from the BS/PV
46  theDeltaR = par.getParameter<double>("DeltaR");
47 
48  // Parameterized ROIs depending on the pt
49  ptRanges_ = par.getParameter<std::vector<double>>("ptRanges");
50  if (ptRanges_.size() < 2) {
51  edm::LogError("MuonTrackingRegionByPtBuilder") << "Size of ptRanges does not be less than 2." << std::endl;
52  }
53 
54  deltaEtas_ = par.getParameter<std::vector<double>>("deltaEtas");
55  if (deltaEtas_.size() != ptRanges_.size() - 1) {
56  edm::LogError("MuonTrackingRegionByPtBuilder")
57  << "Size of deltaEtas does not match number of pt bins." << std::endl;
58  }
59 
60  deltaPhis_ = par.getParameter<std::vector<double>>("deltaPhis");
61  if (deltaPhis_.size() != ptRanges_.size() - 1) {
62  edm::LogError("MuonTrackingRegionByPtBuilder")
63  << "Size of deltaPhis does not match number of pt bins." << std::endl;
64  }
65 
66  // Maximum number of regions to build when looping over Muons
67  theMaxRegions = par.getParameter<int>("maxRegions");
68 
69  // Flag to use precise??
70  thePrecise = par.getParameter<bool>("precise");
71 
72  // perigee reference point
76  iC.consumes<MeasurementTrackerEvent>(par.getParameter<edm::InputTag>("MeasurementTrackerName"));
77  }
78 
79  // Vertex collection and Beam Spot
82 
83  // Input muon collection
85 
86  bfieldToken = iC.esConsumes();
87  if (thePrecise) {
88  msmakerToken = iC.esConsumes();
89  }
90 }
91 
92 //
93 // Member function to be compatible with TrackingRegionProducerFactory: create many ROI for many tracks
94 //
95 std::vector<std::unique_ptr<TrackingRegion>> MuonTrackingRegionByPtBuilder::regions(const edm::Event& ev,
96  const edm::EventSetup& es) const {
97  std::vector<std::unique_ptr<TrackingRegion>> result;
98 
100  ev.getByToken(inputCollectionToken, tracks);
101 
102  int nRegions = 0;
103  for (auto it = tracks->cbegin(), ed = tracks->cend(); it != ed && nRegions < theMaxRegions; ++it) {
104  result.push_back(region(*it, ev, es));
105  nRegions++;
106  }
107 
108  return result;
109 }
110 
111 //
112 // Call region on Track from TrackRef
113 //
114 std::unique_ptr<RectangularEtaPhiTrackingRegion> MuonTrackingRegionByPtBuilder::region(
115  const reco::TrackRef& track) const {
116  return region(*track);
117 }
118 
119 //
120 // ToDo: Not sure if this is needed?
121 //
123  theEvent = &event;
124  theEventSetup = &es;
125 }
126 
127 //
128 // Main member function called to create the ROI
129 //
130 std::unique_ptr<RectangularEtaPhiTrackingRegion> MuonTrackingRegionByPtBuilder::region(
131  const reco::Track& staTrack, const edm::Event& ev, const edm::EventSetup& es) const {
132  // get track momentum/direction at vertex
133  const math::XYZVector& mom = staTrack.momentum();
134  GlobalVector dirVector(mom.x(), mom.y(), mom.z());
135  double pt = staTrack.pt();
136 
137  // Fix for StandAlone tracks with low momentum
138  const math::XYZVector& innerMomentum = staTrack.innerMomentum();
139  GlobalVector forSmallMomentum(innerMomentum.x(), innerMomentum.y(), innerMomentum.z());
140  if (staTrack.p() <= 1.5) {
141  pt = std::abs(forSmallMomentum.perp());
142  }
143 
144  // initial vertex position - in the following it is replaced with beamspot/vertexing
145  GlobalPoint vertexPos(0.0, 0.0, 0.0);
146  // standard 15.9, if useVertex than use error from vertex
147  double deltaZ = theHalfZ;
148 
149  // retrieve beam spot information
151  bool bsHandleFlag = ev.getByToken(beamSpotToken, bs);
152 
153  // check the validity, otherwise vertexing
154  if (bsHandleFlag && bs.isValid() && !useVertex) {
155  vertexPos = GlobalPoint(bs->x0(), bs->y0(), bs->z0());
156  deltaZ = useFixedZ ? theHalfZ : bs->sigmaZ() * theNsigmaDz;
157  } else {
158  // get originZPos from list of reconstructed vertices (first or all)
160  bool vtxHandleFlag = ev.getByToken(vertexCollectionToken, vertexCollection);
161  // check if there exists at least one reconstructed vertex
162  if (vtxHandleFlag && !vertexCollection->empty()) {
163  // use the first vertex in the collection and assume it is the primary event vertex
164  reco::VertexCollection::const_iterator vtx = vertexCollection->begin();
165  if (!vtx->isFake() && vtx->isValid()) {
166  vertexPos = GlobalPoint(vtx->x(), vtx->y(), vtx->z());
167  deltaZ = useFixedZ ? theHalfZ : vtx->zError() * theNsigmaDz;
168  }
169  }
170  }
171 
172  // set delta eta and delta phi depending on the pt
173  auto region_dEta = deltaEtas_.at(0);
174  auto region_dPhi = deltaPhis_.at(0);
175  if (pt < ptRanges_.back()) {
176  auto lowEdge = std::upper_bound(ptRanges_.begin(), ptRanges_.end(), pt);
177  region_dEta = deltaEtas_.at(lowEdge - ptRanges_.begin() - 1);
178  region_dPhi = deltaPhis_.at(lowEdge - ptRanges_.begin() - 1);
179  }
180 
181  float deltaR = theDeltaR;
182  double minPt = useFixedPt ? thePtMin : std::max(thePtMin, pt * 0.6);
183 
188  measurementTracker = hmte.product();
189  }
190 
191  const auto& bfield = es.getData(bfieldToken);
192  const MultipleScatteringParametrisationMaker* msmaker = nullptr;
193  if (thePrecise) {
194  msmaker = &es.getData(msmakerToken);
195  }
196 
197  auto region = std::make_unique<RectangularEtaPhiTrackingRegion>(dirVector,
198  vertexPos,
199  minPt,
200  deltaR,
201  deltaZ,
202  region_dEta,
203  region_dPhi,
204  bfield,
205  msmaker,
206  thePrecise,
207  theOnDemand,
209 
210  LogDebug("MuonTrackingRegionByPtBuilder")
211  << "the region parameters are:\n"
212  << "\n dirVector: " << dirVector << "\n vertexPos: " << vertexPos << "\n minPt: " << minPt
213  << "\n deltaR:" << deltaR << "\n deltaZ:" << deltaZ << "\n region_dEta:" << region_dEta
214  << "\n region_dPhi:" << region_dPhi << "\n on demand parameter: " << static_cast<int>(theOnDemand);
215 
216  return region;
217 }
218 
221  desc.add<double>("DeltaR", 0.2);
222  desc.add<edm::InputTag>("beamSpot", edm::InputTag(""));
223  desc.add<int>("OnDemand", -1);
224  desc.add<edm::InputTag>("vertexCollection", edm::InputTag(""));
225  desc.add<edm::InputTag>("MeasurementTrackerName", edm::InputTag(""));
226  desc.add<bool>("UseVertex", false);
227  desc.add<double>("Rescale_Dz", 3.0);
228  desc.add<bool>("Pt_fixed", false);
229  desc.add<bool>("Z_fixed", true);
230  desc.add<double>("Pt_min", 1.5);
231  desc.add<double>("DeltaZ", 15.9);
232  desc.add<std::vector<double>>("ptRanges", {0., 1.e9});
233  desc.add<std::vector<double>>("deltaEtas", {0.2});
234  desc.add<std::vector<double>>("deltaPhis", {0.15});
235  desc.add<int>("maxRegions", 1);
236  desc.add<bool>("precise", true);
237  desc.add<edm::InputTag>("input", edm::InputTag(""));
238  descriptions.add("MuonTrackingRegionByPtBuilder", desc);
239 
240  descriptions.setComment(
241  "Build a TrackingRegion around a standalone muon. Options to define region around beamspot or primary vertex and "
242  "dynamic regions are included.");
243 }
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
tuple measurementTracker
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
__host__ __device__ constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
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
Log< level::Error, false > LogError
edm::EDGetTokenT< reco::VertexCollection > vertexCollectionToken
tuple vertexCollection
tuple result
Definition: mps_fire.py:311
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &, const edm::EventSetup &) const override
Create Region of Interest.
std::unique_ptr< RectangularEtaPhiTrackingRegion > region(const reco::TrackRef &) const
Define tracking region.
double pt() const
track transverse momentum
Definition: TrackBase.h:637
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)
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken
void build(const edm::ParameterSet &, edm::ConsumesCollector &)
T const * product() const
Definition: Handle.h:70
edm::ESGetToken< MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord > msmakerToken
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)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Add Fill Descriptions.
RectangularEtaPhiTrackingRegion::UseMeasurementTracker theOnDemand
edm::EDGetTokenT< MeasurementTrackerEvent > theMeasurementTrackerToken
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
static UseMeasurementTracker intToUseMeasurementTracker(int value)
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bfieldToken
void setEvent(const edm::Event &, const edm::EventSetup &)
Pass the Event to the algo at each event.
#define LogDebug(id)