CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PropagateToMuon.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <cmath>
5 
7 
15 
17 
19  useSimpleGeometry_(iConfig.getParameter<bool>("useSimpleGeometry")),
20  whichTrack_(None), whichState_(AtVertex),
21  cosmicPropagation_(iConfig.existsAs<bool>("cosmicPropagationHypothesis") ? iConfig.getParameter<bool>("cosmicPropagationHypothesis") : false)
22 {
23  std::string whichTrack = iConfig.getParameter<std::string>("useTrack");
24  if (whichTrack == "none") { whichTrack_ = None; }
25  else if (whichTrack == "tracker") { whichTrack_ = TrackerTk; }
26  else if (whichTrack == "muon") { whichTrack_ = MuonTk; }
27  else if (whichTrack == "global") { whichTrack_ = GlobalTk; }
28  else throw cms::Exception("Configuration") << "Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n";
29  if (whichTrack_ != None) {
30  std::string whichState = iConfig.getParameter<std::string>("useState");
31  if (whichState == "atVertex") { whichState_ = AtVertex; }
32  else if (whichState == "innermost") { whichState_ = Innermost; }
33  else if (whichState == "outermost") { whichState_ = Outermost; }
34  else throw cms::Exception("Configuration") << "Parameter 'useState' must be 'atVertex', 'innermost', 'outermost'\n";
35  }
37  throw cms::Exception("Configuration") << "When using 'cosmicPropagationHypothesis' useTrack must not be 'none', and the state must not be 'atVertex'\n";
38  }
39 }
40 
42 
43 void
45  iSetup.get<IdealMagneticFieldRecord>().get(magfield_);
46  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", propagator_);
47  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorOpposite", propagatorOpposite_);
48  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagatorAny_);
50 
51  const DetLayer * dt2 = muonGeometry_->allDTLayers()[1];
52  const DetLayer * csc2Pos = muonGeometry_->forwardCSCLayers()[2];
53  const DetLayer * csc2Neg = muonGeometry_->backwardCSCLayers()[2];
54  barrelCylinder_ = dynamic_cast<const BoundCylinder *>(&dt2->surface());
55  endcapDiskPos_ = dynamic_cast<const BoundDisk *>(& csc2Pos->surface());
56  endcapDiskNeg_ = dynamic_cast<const BoundDisk *>(& csc2Neg->surface());
57  if (barrelCylinder_==0 || endcapDiskPos_==0 || endcapDiskNeg_==0) throw cms::Exception("Geometry") << "Bad muon geometry!?";
58  barrelHalfLength_ = barrelCylinder_->bounds().length()/2;;
59  endcapRadii_ = std::make_pair(endcapDiskPos_->innerRadius(), endcapDiskPos_->outerRadius());
60  //std::cout << "L1MuonMatcher: barrel radius = " << barrelCylinder_->radius() << ", half length = " << barrelHalfLength_ <<
61  // "; endcap Z = " << endcapDiskPos_->position().z() << ", radii = " << endcapRadii_.first << "," << endcapRadii_.second << std::std::endl;
62 }
63 
67  if (whichTrack_ != None) {
68  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&reco);
69  if (rc == 0) throw cms::Exception("Invalid Data") << "Input object is not a RecoCandidate.\n";
70  reco::TrackRef tk;
71  switch (whichTrack_) {
72  case TrackerTk: tk = rc->track(); break;
73  case MuonTk : tk = rc->standAloneMuon(); break;
74  case GlobalTk : tk = rc->combinedMuon(); break;
75  default: break; // just to make gcc happy
76  }
77  if (tk.isNull()) {
78  ret = FreeTrajectoryState();
79  } else {
80  ret = startingState(*tk);
81  }
82  } else {
83  ret = FreeTrajectoryState( GlobalPoint( reco.vx(), reco.vy(), reco.vz()),
84  GlobalVector(reco.px(), reco.py(), reco.pz()),
85  reco.charge(),
86  magfield_.product());
87  }
88  return ret;
89 }
90 
93  WhichState state = whichState_;
94  if (cosmicPropagation_) {
95  if (whichState_ == Innermost) {
96  state = tk.innerPosition().Mag2() <= tk.outerPosition().Mag2() ? Innermost : Outermost;
97  } else if (whichState_ == Outermost) {
98  state = tk.innerPosition().Mag2() <= tk.outerPosition().Mag2() ? Outermost : Innermost;
99  }
100  }
101  switch (state) {
104 
105  case AtVertex:
106  default:
108  }
109 
110 }
111 
112 
116  if (start.momentum().mag() == 0) return final;
117  double eta = start.momentum().eta();
118 
119  const Propagator * propagatorBarrel = &*propagator_;
120  const Propagator * propagatorEndcaps = &*propagator_;
121 
122  if (whichState_ != AtVertex) {
123  if (start.position().perp() > barrelCylinder_->radius()) propagatorBarrel = &*propagatorOpposite_;
124  if (fabs(start.position().z()) > endcapDiskPos_->position().z()) propagatorEndcaps = &*propagatorOpposite_;
125  }
126  if (cosmicPropagation_) {
127  if (start.momentum().dot(GlobalVector(start.position().x(), start.position().y(), start.position().z())) < 0) {
128  // must flip the propagations
129  propagatorBarrel = (propagatorBarrel == &*propagator_ ? &*propagatorOpposite_ : &*propagator_);
130  propagatorEndcaps = (propagatorEndcaps == &*propagator_ ? &*propagatorOpposite_ : &*propagator_);
131  }
132  }
133 
134  TrajectoryStateOnSurface tsos = propagatorBarrel->propagate(start, *barrelCylinder_);
135  if (tsos.isValid()) {
136  if (useSimpleGeometry_) {
137  if (fabs(tsos.globalPosition().z()) <= barrelHalfLength_) final = tsos;
138  } else {
139  final = getBestDet(tsos, muonGeometry_->allDTLayers()[1]);
140  }
141  }
142 
143  if (!final.isValid()) {
144  tsos = propagatorEndcaps->propagate(start, (eta > 0 ? *endcapDiskPos_ : *endcapDiskNeg_));
145  if (tsos.isValid()) {
146  if (useSimpleGeometry_) {
147  float rho = tsos.globalPosition().perp();
148  if ((rho >= endcapRadii_.first) && (rho <= endcapRadii_.second)) final = tsos;
149  } else {
150  final = getBestDet(tsos, (eta > 0 ? muonGeometry_->forwardCSCLayers()[2] : muonGeometry_->backwardCSCLayers()[2]));
151  }
152  }
153  }
154  return final;
155 }
156 
159  TrajectoryStateOnSurface ret; // start as null
160  Chi2MeasurementEstimator estimator(1e10, 3.); // require compatibility at 3 sigma
161  std::vector<GeometricSearchDet::DetWithState> dets = layer->compatibleDets(tsos, *propagatorAny_, estimator);
162  if (!dets.empty()) {
163  ret = dets.front().second;
164  }
165  return ret;
166 }
WhichTrack whichTrack_
Labels for input collections.
T getParameter(std::string const &) const
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
PropagateToMuon(const edm::ParameterSet &iConfig)
TrajectoryStateOnSurface extrapolate(const reco::Track &tk) const
Extrapolate reco::Track to the muon station 2, return an invalid TSOS if it fails.
edm::ESHandle< Propagator > propagatorAny_
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
const BoundDisk * endcapDiskNeg_
T perp() const
Definition: PV3DBase.h:72
FreeTrajectoryState startingState(const reco::Candidate &reco) const
Starting state for the propagation.
WhichState whichState_
virtual double pz() const =0
z coordinate of momentum vector
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
virtual double vx() const =0
x coordinate of vertex position
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 reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track
TrajectoryStateOnSurface getBestDet(const TrajectoryStateOnSurface &tsos, const DetLayer *station) const
Get the best TSOS on one of the chambres of this DetLayer, or an invalid TSOS if none match...
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
virtual double vy() const =0
y coordinate of vertex position
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:55
T mag() const
Definition: PV3DBase.h:67
T z() const
Definition: PV3DBase.h:64
virtual int charge() const =0
electric charge
virtual double py() const =0
y coordinate of momentum vector
edm::ESHandle< Propagator > propagator_
bool isNull() const
Checks for null.
Definition: Ref.h:249
GlobalVector momentum() const
virtual double px() const =0
x coordinate of momentum vector
bool cosmicPropagation_
for cosmics, some things change: the along-opposite is not in-out, nor the innermost/outermost states...
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
void init(const edm::EventSetup &iSetup)
Call this method at the beginning of each run, to initialize geometry, magnetic field and propagators...
T eta() const
Definition: PV3DBase.h:76
virtual double vz() const =0
z coordinate of vertex position
bool useSimpleGeometry_
Labels for input collections.
edm::ESHandle< MuonDetLayerGeometry > muonGeometry_
double barrelHalfLength_
volatile std::atomic< bool > shutdown_flag false
FreeTrajectoryState innerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
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_
Global3DVector GlobalVector
Definition: GlobalVector.h:10
std::pair< float, float > endcapRadii_
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track