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 <cmath>
4 
6 
14 
16 
18  useSimpleGeometry_(iConfig.getParameter<bool>("useSimpleGeometry")),
19  useMB2_(iConfig.existsAs<bool>("useStation2") ? iConfig.getParameter<bool>("useStation2") : true),
20  fallbackToME1_(iConfig.existsAs<bool>("fallbackToME1") ? iConfig.getParameter<bool>("fallbackToME1") : false),
21  whichTrack_(None), whichState_(AtVertex),
22  cosmicPropagation_(iConfig.existsAs<bool>("cosmicPropagationHypothesis") ? iConfig.getParameter<bool>("cosmicPropagationHypothesis") : false)
23 {
24  std::string whichTrack = iConfig.getParameter<std::string>("useTrack");
25  if (whichTrack == "none") { whichTrack_ = None; }
26  else if (whichTrack == "tracker") { whichTrack_ = TrackerTk; }
27  else if (whichTrack == "muon") { whichTrack_ = MuonTk; }
28  else if (whichTrack == "global") { whichTrack_ = GlobalTk; }
29  else throw cms::Exception("Configuration") << "Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n";
30  if (whichTrack_ != None) {
31  std::string whichState = iConfig.getParameter<std::string>("useState");
32  if (whichState == "atVertex") { whichState_ = AtVertex; }
33  else if (whichState == "innermost") { whichState_ = Innermost; }
34  else if (whichState == "outermost") { whichState_ = Outermost; }
35  else throw cms::Exception("Configuration") << "Parameter 'useState' must be 'atVertex', 'innermost', 'outermost'\n";
36  }
38  throw cms::Exception("Configuration") << "When using 'cosmicPropagationHypothesis' useTrack must not be 'none', and the state must not be 'atVertex'\n";
39  }
40 }
41 
43 
44 void
45 PropagateToMuon::init(const edm::EventSetup & iSetup) {
46  iSetup.get<IdealMagneticFieldRecord>().get(magfield_);
47  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAlong", propagator_);
48  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorOpposite", propagatorOpposite_);
49  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagatorAny_);
51 
52  // Get the barrel cylinder
53  const DetLayer * dtLay = muonGeometry_->allDTLayers()[useMB2_ ? 1 : 0];
54  barrelCylinder_ = dynamic_cast<const BoundCylinder *>(&dtLay->surface());
55  barrelHalfLength_ = barrelCylinder_->bounds().length()/2;;
56  //std::cout << "L1MuonMatcher: barrel radius = " << barrelCylinder_->radius() << ", half length = " << barrelHalfLength_ << std::endl;
57 
58  // Get the endcap disks. Note that ME1 has two disks (ME1/1 and ME2/1-ME3/2-ME4/1), so there's one more index
59  for (size_t i = 0; i <= (useMB2_ ? 2 : 1); ++i) {
60  endcapDiskPos_[i] = dynamic_cast<const BoundDisk *>(& muonGeometry_->forwardCSCLayers()[i]->surface());
61  endcapDiskNeg_[i] = dynamic_cast<const BoundDisk *>(& muonGeometry_->backwardCSCLayers()[i]->surface());
62  endcapRadii_[i] = std::make_pair(endcapDiskPos_[i]->innerRadius(), endcapDiskPos_[i]->outerRadius());
63  //std::cout << "L1MuonMatcher: endcap " << i << " Z = " << endcapDiskPos_[i]->position().z() << ", radii = " << endcapRadii_[i].first << "," << endcapRadii_[i].second << std::endl;
64  }
65 }
66 
70  if (whichTrack_ != None) {
71  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&reco);
72  if (rc == 0) throw cms::Exception("Invalid Data") << "Input object is not a RecoCandidate.\n";
73  reco::TrackRef tk;
74  switch (whichTrack_) {
75  case TrackerTk: tk = rc->track(); break;
76  case MuonTk : tk = rc->standAloneMuon(); break;
77  case GlobalTk : tk = rc->combinedMuon(); break;
78  default: break; // just to make gcc happy
79  }
80  if (tk.isNull()) {
81  ret = FreeTrajectoryState();
82  } else {
83  ret = startingState(*tk);
84  }
85  } else {
86  ret = FreeTrajectoryState( GlobalPoint( reco.vx(), reco.vy(), reco.vz()),
87  GlobalVector(reco.px(), reco.py(), reco.pz()),
88  reco.charge(),
89  magfield_.product());
90  }
91  return ret;
92 }
93 
96  if (!magfield_.isValid()) throw cms::Exception("NotInitialized") << "PropagateToMuon: You must call init(const edm::EventSetup &iSetup) before using this object.\n";
97  WhichState state = whichState_;
98  if (cosmicPropagation_) {
99  if (whichState_ == Innermost) {
100  state = tk.innerPosition().Mag2() <= tk.outerPosition().Mag2() ? Innermost : Outermost;
101  } else if (whichState_ == Outermost) {
102  state = tk.innerPosition().Mag2() <= tk.outerPosition().Mag2() ? Outermost : Innermost;
103  }
104  }
105  switch (state) {
108 
109  case AtVertex:
110  default:
112  }
113 
114 }
115 
118  if (!magfield_.isValid()) throw cms::Exception("NotInitialized") << "PropagateToMuon: You must call init(const edm::EventSetup &iSetup) before using this object.\n";
119  if (tk.noVertex()) throw cms::Exception("UnsupportedOperation") << "I can't propagate simtracks without a vertex, I don't know where to start from.\n";
120  const math::XYZTLorentzVectorD & vtx = (vtxs)[tk.vertIndex()].position();
121  return FreeTrajectoryState( GlobalPoint(vtx.X(), vtx.Y(), vtx.Z()),
122  GlobalVector(tk.momentum().X(), tk.momentum().Y(), tk.momentum().Z()),
123  int(tk.charge()),
124  magfield_.product());
125 }
126 
127 
128 
131  if (!magfield_.isValid() || barrelCylinder_ == 0) {
132  throw cms::Exception("NotInitialized") << "PropagateToMuon: You must call init(const edm::EventSetup &iSetup) before using this object.\n";
133  }
134 
136  if (start.momentum().mag() == 0) return final;
137  double eta = start.momentum().eta();
138 
139  const Propagator * propagatorBarrel = &*propagator_;
140  const Propagator * propagatorEndcaps = &*propagator_;
141  if (whichState_ != AtVertex) {
142  if (start.position().perp() > barrelCylinder_->radius()) propagatorBarrel = &*propagatorOpposite_;
143  if (fabs(start.position().z()) > endcapDiskPos_[useMB2_?2:1]->position().z()) propagatorEndcaps = &*propagatorOpposite_;
144  }
145  if (cosmicPropagation_) {
146  if (start.momentum().dot(GlobalVector(start.position().x(), start.position().y(), start.position().z())) < 0) {
147  // must flip the propagations
148  propagatorBarrel = (propagatorBarrel == &*propagator_ ? &*propagatorOpposite_ : &*propagator_);
149  propagatorEndcaps = (propagatorEndcaps == &*propagator_ ? &*propagatorOpposite_ : &*propagator_);
150  }
151  }
152 
153  TrajectoryStateOnSurface tsos = propagatorBarrel->propagate(start, *barrelCylinder_);
154  if (tsos.isValid()) {
155  if (useSimpleGeometry_) {
156  //std::cout << " propagated to barrel, z = " << tsos.globalPosition().z() << ", bound = " << barrelHalfLength_ << std::endl;
157  if (fabs(tsos.globalPosition().z()) <= barrelHalfLength_) final = tsos;
158  } else {
159  final = getBestDet(tsos, muonGeometry_->allDTLayers()[1]);
160  }
161  }
162  if (!final.isValid()) {
163  for (int ie = (useMB2_ ? 2 : 1); ie >= 0; --ie) {
164  tsos = propagatorEndcaps->propagate(start, (eta > 0 ? *endcapDiskPos_[ie] : *endcapDiskNeg_[ie]));
165  if (tsos.isValid()) {
166  if (useSimpleGeometry_) {
167  float rho = tsos.globalPosition().perp();
168  //std::cout << " propagated to endcap " << ie << ", rho = " << rho << ", bounds [ " << endcapRadii_[ie].first << ", " << endcapRadii_[ie].second << "]" << std::endl;
169  if ((rho >= endcapRadii_[ie].first) && (rho <= endcapRadii_[ie].second)) final = tsos;
170  } else {
171  final = getBestDet(tsos, (eta > 0 ? muonGeometry_->forwardCSCLayers()[ie] : muonGeometry_->backwardCSCLayers()[ie]));
172  }
173  } //else //std::cout << " failed to propagated to endcap " << ie << std::endl;
174  if (final.isValid()) break;
175  if (ie == 2 && !fallbackToME1_) break;
176  }
177  }
178  return final;
179 }
180 
182 PropagateToMuon::getBestDet(const TrajectoryStateOnSurface &tsos, const DetLayer *layer) const {
183  TrajectoryStateOnSurface ret; // start as null
184  Chi2MeasurementEstimator estimator(1e10, 3.); // require compatibility at 3 sigma
185  std::vector<GeometricSearchDet::DetWithState> dets = layer->compatibleDets(tsos, *propagatorAny_, estimator);
186  if (!dets.empty()) {
187  ret = dets.front().second;
188  }
189  return ret;
190 }
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
int i
Definition: DBlmapReader.cc:9
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.
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
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
bool useMB2_
Propagate to MB2 (default) instead of MB1.
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
float charge() const
charge
Definition: CoreSimTrack.cc:18
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
U second(std::pair< T, U > const &p)
T mag() const
Definition: PV3DBase.h:67
T z() const
Definition: PV3DBase.h:64
bool noVertex() const
Definition: SimTrack.h:30
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
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:29
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
std::vector< SimVertex > SimVertexContainer
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.
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
static int position[264][3]
Definition: ReadPGInfo.cc:509
edm::ESHandle< MuonDetLayerGeometry > muonGeometry_
bool fallbackToME1_
Fallback to ME1 if propagation to ME2 fails.
double barrelHalfLength_
volatile std::atomic< bool > shutdown_flag false
FreeTrajectoryState innerFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
bool isValid() const
Definition: ESHandle.h:47
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