CMS 3D CMS Logo

PropagateToMuon.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 #include <iostream>
5 
7 
15 
17 
19  : useSimpleGeometry_(iConfig.getParameter<bool>("useSimpleGeometry")),
20  whichTrack_(None),
21  whichState_(AtVertex),
22  cosmicPropagation_(iConfig.existsAs<bool>("cosmicPropagationHypothesis")
23  ? iConfig.getParameter<bool>("cosmicPropagationHypothesis")
24  : false) {
25  std::string whichTrack = iConfig.getParameter<std::string>("useTrack");
26  if (whichTrack == "none") {
27  whichTrack_ = None;
28  } else if (whichTrack == "tracker") {
30  } else if (whichTrack == "muon") {
32  } else if (whichTrack == "global") {
34  } else
35  throw cms::Exception("Configuration") << "Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n";
36  if (whichTrack_ != None) {
37  std::string whichState = iConfig.getParameter<std::string>("useState");
38  if (whichState == "atVertex") {
40  } else if (whichState == "innermost") {
42  } else if (whichState == "outermost") {
44  } else
45  throw cms::Exception("Configuration") << "Parameter 'useState' must be 'atVertex', 'innermost', "
46  "'outermost'\n";
47  }
49  throw cms::Exception("Configuration") << "When using 'cosmicPropagationHypothesis' useTrack must not be "
50  "'none', and the state must not be 'atVertex'\n";
51  }
52 }
53 
55 
57  iSetup.get<IdealMagneticFieldRecord>().get(magfield_);
58  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", propagator_);
59  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorOpposite", propagatorOpposite_);
60  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagatorAny_);
62 
63  const DetLayer *dt2 = muonGeometry_->allDTLayers()[1];
64  const DetLayer *csc2Pos = muonGeometry_->forwardCSCLayers()[2];
65  const DetLayer *csc2Neg = muonGeometry_->backwardCSCLayers()[2];
66  barrelCylinder_ = dynamic_cast<const BoundCylinder *>(&dt2->surface());
67  endcapDiskPos_ = dynamic_cast<const BoundDisk *>(&csc2Pos->surface());
68  endcapDiskNeg_ = dynamic_cast<const BoundDisk *>(&csc2Neg->surface());
69  if (barrelCylinder_ == nullptr || endcapDiskPos_ == nullptr || endcapDiskNeg_ == nullptr)
70  throw cms::Exception("Geometry") << "Bad muon geometry!?";
71  barrelHalfLength_ = barrelCylinder_->bounds().length() / 2;
72  ;
73  endcapRadii_ = std::make_pair(endcapDiskPos_->innerRadius(), endcapDiskPos_->outerRadius());
74  // std::cout << "L1MuonMatcher: barrel radius = " << barrelCylinder_->radius()
75  // << ", half length = " << barrelHalfLength_ <<
76  // "; endcap Z = " << endcapDiskPos_->position().z() << ", radii =
77  // " << endcapRadii_.first << "," << endcapRadii_.second <<
78  // std::std::endl;
79 }
80 
83  if (whichTrack_ != None) {
84  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&reco);
85  if (rc == nullptr)
86  throw cms::Exception("Invalid Data") << "Input object is not a RecoCandidate.\n";
87  reco::TrackRef tk;
88  switch (whichTrack_) {
89  case TrackerTk:
90  tk = rc->track();
91  break;
92  case MuonTk:
93  tk = rc->standAloneMuon();
94  break;
95  case GlobalTk:
96  tk = rc->combinedMuon();
97  break;
98  default:
99  break; // just to make gcc happy
100  }
101  if (tk.isNull()) {
102  ret = FreeTrajectoryState();
103  } else {
104  ret = startingState(*tk);
105  }
106  } else {
107  ret = FreeTrajectoryState(GlobalPoint(reco.vx(), reco.vy(), reco.vz()),
108  GlobalVector(reco.px(), reco.py(), reco.pz()),
109  reco.charge(),
110  magfield_.product());
111  }
112  return ret;
113 }
114 
116  WhichState state = whichState_;
117  if (cosmicPropagation_) {
118  if (whichState_ == Innermost) {
119  state = tk.innerPosition().Mag2() <= tk.outerPosition().Mag2() ? Innermost : Outermost;
120  } else if (whichState_ == Outermost) {
121  state = tk.innerPosition().Mag2() <= tk.outerPosition().Mag2() ? Outermost : Innermost;
122  }
123  }
124  switch (state) {
125  case Innermost:
127  case Outermost:
129 
130  case AtVertex:
131  default:
133  }
134 }
135 
138  if (start.momentum().mag() == 0)
139  return final;
140  double eta = start.momentum().eta();
141 
142  const Propagator *propagatorBarrel = &*propagator_;
143  const Propagator *propagatorEndcaps = &*propagator_;
144 
145  if (whichState_ != AtVertex) {
146  if (start.position().perp() > barrelCylinder_->radius())
147  propagatorBarrel = &*propagatorOpposite_;
148  if (fabs(start.position().z()) > endcapDiskPos_->position().z())
149  propagatorEndcaps = &*propagatorOpposite_;
150  }
151  if (cosmicPropagation_) {
152  if (start.momentum().dot(GlobalVector(start.position().x(), start.position().y(), start.position().z())) < 0) {
153  // must flip the propagations
154  propagatorBarrel = (propagatorBarrel == &*propagator_ ? &*propagatorOpposite_ : &*propagator_);
155  propagatorEndcaps = (propagatorEndcaps == &*propagator_ ? &*propagatorOpposite_ : &*propagator_);
156  }
157  }
158 
159  TrajectoryStateOnSurface tsos = propagatorBarrel->propagate(start, *barrelCylinder_);
160  if (tsos.isValid()) {
161  if (useSimpleGeometry_) {
162  if (fabs(tsos.globalPosition().z()) <= barrelHalfLength_)
163  final = tsos;
164  } else {
165  final = getBestDet(tsos, muonGeometry_->allDTLayers()[1]);
166  }
167  }
168 
169  if (!final.isValid()) {
170  tsos = propagatorEndcaps->propagate(start, (eta > 0 ? *endcapDiskPos_ : *endcapDiskNeg_));
171  if (tsos.isValid()) {
172  if (useSimpleGeometry_) {
173  float rho = tsos.globalPosition().perp();
174  if ((rho >= endcapRadii_.first) && (rho <= endcapRadii_.second))
175  final = tsos;
176  } else {
177  final =
179  }
180  }
181  }
182  return final;
183 }
184 
186  const DetLayer *layer) const {
187  TrajectoryStateOnSurface ret; // start as null
189  3.); // require compatibility at 3 sigma
190  std::vector<GeometricSearchDet::DetWithState> dets = layer->compatibleDets(tsos, *propagatorAny_, estimator);
191  if (!dets.empty()) {
192  ret = dets.front().second;
193  }
194  return ret;
195 }
Definition: start.py:1
WhichTrack whichTrack_
Labels for input collections.
T getParameter(std::string const &) const
PropagateToMuon(const edm::ParameterSet &iConfig)
TrajectoryStateOnSurface extrapolate(const reco::Track &tk) const
edm::ESHandle< Propagator > propagatorAny_
virtual double pz() const =0
z coordinate of momentum vector
const BoundDisk * endcapDiskNeg_
T perp() const
Definition: PV3DBase.h:72
FreeTrajectoryState startingState(const reco::Candidate &reco) const
Starting state for the propagation.
virtual double vx() const =0
x coordinate of vertex position
WhichState whichState_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
const BoundDisk * endcapDiskPos_
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
virtual double vy() const =0
y coordinate of vertex position
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track
TrajectoryStateOnSurface getBestDet(const TrajectoryStateOnSurface &tsos, const DetLayer *station) const
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:67
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
virtual reco::TrackRef track() const
reference to a Track
edm::ESHandle< MagneticField > magfield_
const BoundCylinder * barrelCylinder_
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:57
virtual double py() const =0
y coordinate of momentum vector
T mag() const
Definition: PV3DBase.h:67
T z() const
Definition: PV3DBase.h:64
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
edm::ESHandle< Propagator > propagator_
bool isNull() const
Checks for null.
Definition: Ref.h:248
GlobalVector momentum() const
bool cosmicPropagation_
for cosmics, some things change: the along-opposite is not in-out, nor the innermost/outermost states...
GlobalPoint position() const
const std::vector< const DetLayer * > & allDTLayers() const
return the DT DetLayers (barrel), inside-out
const std::vector< const DetLayer * > & forwardCSCLayers() const
return the forward (+Z) CSC DetLayers, inside-out
void init(const edm::EventSetup &iSetup)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
T eta() const
Definition: PV3DBase.h:76
virtual int charge() const =0
electric charge
fixed size matrix
bool useSimpleGeometry_
Labels for input collections.
T get() const
Definition: EventSetup.h:71
edm::ESHandle< MuonDetLayerGeometry > muonGeometry_
double barrelHalfLength_
const std::vector< const DetLayer * > & backwardCSCLayers() const
return the backward (-Z) CSC DetLayers, inside-out
virtual double vz() const =0
z coordinate of vertex position
FreeTrajectoryState innerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
virtual double px() const =0
x coordinate of momentum vector
T x() const
Definition: PV3DBase.h:62
FreeTrajectoryState outerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
edm::ESHandle< Propagator > propagatorOpposite_
T const * product() const
Definition: ESHandle.h:86
Global3DVector GlobalVector
Definition: GlobalVector.h:10
std::pair< float, float > endcapRadii_
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track