CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonUpdatorAtVertex.cc
Go to the documentation of this file.
1 
11 
18 
20 
24 
25 using namespace std;
26 
29  : theService(service) {
30  thePropagatorName = pset.getParameter<string>("Propagator");
31 
32  // Errors on the Beam spot position
33  vector<double> errors = pset.getParameter<vector<double> >("BeamSpotPositionErrors");
34  if (errors.size() != 3)
35  edm::LogError("Muon|RecoMuon|MuonUpdatorAtVertex")
36  << "MuonUpdatorAtVertex::BeamSpotPositionErrors wrong number of parameters!!";
37 
38  // assume:
39  // errors[0] = sigma(x)
40  // errors[1] = sigma(y)
41  // errors[2] = sigma(z)
42 
44  mat(0, 0) = errors[0] * errors[0];
45  mat(1, 1) = errors[1] * errors[1];
46  mat(2, 2) = errors[2] * errors[2];
47  GlobalError glbErrPos(mat);
48 
49  thePositionErrors = glbErrPos;
50 
51  // cut on chi^2
52  theChi2Cut = pset.getParameter<double>("MaxChi2");
53 }
54 
57 
58 // Operations
59 
61 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos,
62  const reco::BeamSpot &beamSpot) const {
63  const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
64 
66  LogTrace(metname) << "Trajectory inside the Tracker";
67 
68  TSCBLBuilderNoMaterial tscblBuilder;
69  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(tsos.freeState()), beamSpot);
70 
71  if (tscbl.isValid())
72  return pair<bool, FreeTrajectoryState>(true, tscbl.trackStateAtPCA());
73  else
74  edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
75  << " This can cause a severe bug.";
76  } else {
77  LogTrace(metname) << "Trajectory inside the muon system";
78 
79  FreeTrajectoryState result = theService->propagator(thePropagatorName)->propagate(*tsos.freeState(), beamSpot);
80 
81  LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: " << result << " parameters: " << result.parameters();
82 
83  if (result.hasError())
84  return pair<bool, FreeTrajectoryState>(true, result);
85  else
86  edm::LogInfo(metname) << "Propagation to the PCA failed!";
87  }
88  return pair<bool, FreeTrajectoryState>(false, FreeTrajectoryState());
89 }
90 
91 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::update(const reco::TransientTrack &track,
92  const reco::BeamSpot &beamSpot) const {
93  const std::string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
94 
95  pair<bool, FreeTrajectoryState> result(false, FreeTrajectoryState());
96 
97  GlobalPoint spotPos(beamSpot.x0(), beamSpot.y0(), beamSpot.z0());
98 
99  SingleTrackVertexConstraint::BTFtuple constrainedTransientTrack;
100 
101  // Temporary hack here. A fix in the SingleTrackVertexConstraint code
102  // is needed. Once available try&catch will be removed
103  try {
104  constrainedTransientTrack = theConstrictor.constrain(track, spotPos, thePositionErrors);
105  } catch (cms::Exception &e) {
106  edm::LogWarning(metname) << "cms::Exception caught in MuonUpdatorAtVertex::update\n"
107  << "Exception from SingleTrackVertexConstraint\n"
108  << e.explainSelf();
109  return result;
110  }
111 
112  if (std::get<0>(constrainedTransientTrack))
113  if (std::get<2>(constrainedTransientTrack) <= theChi2Cut) {
114  result.first = true;
115  result.second = *std::get<1>(constrainedTransientTrack).impactPointState().freeState();
116  } else
117  LogTrace(metname) << "Constraint at vertex failed: too large chi2";
118  else
119  LogTrace(metname) << "Constraint at vertex failed";
120 
121  return result;
122 }
123 
124 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::update(const FreeTrajectoryState &ftsAtVtx,
125  const reco::BeamSpot &beamSpot) const {
126  return update(theTransientTrackFactory.build(ftsAtVtx), beamSpot);
127 }
128 
129 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagateWithUpdate(const TrajectoryStateOnSurface &tsos,
130  const reco::BeamSpot &beamSpot) const {
131  pair<bool, FreeTrajectoryState> propagationResult = propagate(tsos, beamSpot);
132 
133  if (propagationResult.first) {
134  return update(propagationResult.second, beamSpot);
135  } else {
136  edm::LogInfo("Muon|RecoMuon|MuonUpdatorAtVertex") << "Constraint at vertex failed";
137  return pair<bool, FreeTrajectoryState>(false, FreeTrajectoryState());
138  }
139 }
140 
141 std::pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagateToNominalLine(
142  const TrajectoryStateOnSurface &tsos) const {
143  const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
144 
146  LogTrace(metname) << "Trajectory inside the Tracker";
147 
148  TSCPBuilderNoMaterial tscpBuilder;
149  TrajectoryStateClosestToPoint tscp = tscpBuilder(*(tsos.freeState()), GlobalPoint(0., 0., 0.));
150 
151  if (tscp.isValid())
152  return pair<bool, FreeTrajectoryState>(true, tscp.theState());
153  else
154  edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
155  << " This can cause a severe bug.";
156  } else {
157  LogTrace(metname) << "Trajectory inside the muon system";
158 
159  // Define a line using two 3D-points
160  GlobalPoint p1(0., 0., -1500);
161  GlobalPoint p2(0., 0., 1500);
162 
163  pair<FreeTrajectoryState, double> result =
164  theService->propagator(thePropagatorName)->propagateWithPath(*tsos.freeState(), p1, p2);
165 
166  LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: " << result.second
167  << " parameters: " << result.first.parameters();
168 
169  if (result.first.hasError())
170  return pair<bool, FreeTrajectoryState>(true, result.first);
171  else
172  edm::LogInfo(metname) << "Propagation to the PCA failed! Path: " << result.second;
173  }
174  return pair<bool, FreeTrajectoryState>(false, FreeTrajectoryState());
175 }
176 
177 std::pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos) const {
178  return propagateToNominalLine(tsos);
179 }
double z0() const
z coordinate
Definition: BeamSpot.h:65
static bool isInside(const GlobalPoint &)
MuonUpdatorAtVertex(const edm::ParameterSet &pset, const MuonServiceProxy *service)
Constructor.
std::tuple< bool, reco::TransientTrack, float > BTFtuple
const TString p2
Definition: fwPaths.cc:13
const GlobalTrajectoryParameters & parameters() const
const std::string metname
virtual std::string explainSelf() const
Definition: Exception.cc:108
const FreeTrajectoryState & theState() const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::pair< bool, FreeTrajectoryState > propagate(const TrajectoryStateOnSurface &tsos, const reco::BeamSpot &beamSpot) const
Propagate the state to the 2D-PCA.
GlobalPoint globalPosition() const
#define LogTrace(id)
const MuonServiceProxy * theService
tuple result
Definition: mps_fire.py:311
TransientTrackFromFTSFactory theTransientTrackFactory
std::pair< bool, FreeTrajectoryState > update(const reco::TransientTrack &track, const reco::BeamSpot &beamSpot) const
Applies the vertex constraint.
FreeTrajectoryState const * freeState(bool withErrors=true) const
const TString p1
Definition: fwPaths.cc:12
Log< level::Info, false > LogInfo
reco::TransientTrack build(const FreeTrajectoryState &fts) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::pair< bool, FreeTrajectoryState > propagateWithUpdate(const TrajectoryStateOnSurface &tsos, const reco::BeamSpot &beamSpot) const
Propagate to the 2D-PCA and apply the vertex constraint.
BTFtuple constrain(const reco::TransientTrack &track, const GlobalPoint &priorPos, const GlobalError &priorError) const
virtual ~MuonUpdatorAtVertex()
Destructor.
double y0() const
y coordinate
Definition: BeamSpot.h:63
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
SingleTrackVertexConstraint theConstrictor
Log< level::Warning, false > LogWarning
double x0() const
x coordinate
Definition: BeamSpot.h:61
std::pair< bool, FreeTrajectoryState > propagateToNominalLine(const TrajectoryStateOnSurface &tsos) const
Propagate the state to the 2D-PCA (nominal CMS axis)
const MuonServiceProxy * theService