Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:18

0001 /** \class MuonUpdatorAtVertex
0002  *  This class do the extrapolation of a TrajectoryStateOnSurface to the PCA and can apply, with a different
0003  *  method, the vertex constraint. The vertex constraint is applyed using the Kalman Filter tools used for 
0004  *  the vertex reconstruction.
0005  *
0006  *  \author R. Bellan - INFN Torino <riccardo.bellan@cern.ch>
0007  */
0008 
0009 #include "RecoMuon/TrackingTools/interface/MuonUpdatorAtVertex.h"
0010 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0011 
0012 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0013 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0014 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
0015 #include "TrackingTools/GeomPropagators/interface/TrackerBounds.h"
0016 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
0017 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
0018 
0019 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0020 
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/Utilities/interface/Exception.h"
0024 
0025 using namespace std;
0026 
0027 /// Constructor
0028 MuonUpdatorAtVertex::MuonUpdatorAtVertex(const edm::ParameterSet &pset, const MuonServiceProxy *service)
0029     : theService(service) {
0030   thePropagatorName = pset.getParameter<string>("Propagator");
0031 
0032   // Errors on the Beam spot position
0033   vector<double> errors = pset.getParameter<vector<double> >("BeamSpotPositionErrors");
0034   if (errors.size() != 3)
0035     edm::LogError("Muon|RecoMuon|MuonUpdatorAtVertex")
0036         << "MuonUpdatorAtVertex::BeamSpotPositionErrors wrong number of parameters!!";
0037 
0038   // assume:
0039   // errors[0] = sigma(x)
0040   // errors[1] = sigma(y)
0041   // errors[2] = sigma(z)
0042 
0043   AlgebraicSymMatrix33 mat;
0044   mat(0, 0) = errors[0] * errors[0];
0045   mat(1, 1) = errors[1] * errors[1];
0046   mat(2, 2) = errors[2] * errors[2];
0047   GlobalError glbErrPos(mat);
0048 
0049   thePositionErrors = glbErrPos;
0050 
0051   // cut on chi^2
0052   theChi2Cut = pset.getParameter<double>("MaxChi2");
0053 }
0054 
0055 /// Destructor
0056 MuonUpdatorAtVertex::~MuonUpdatorAtVertex() {}
0057 
0058 // Operations
0059 
0060 /// Propagate the state to the PCA in 2D, i.e. to the beam line
0061 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos,
0062                                                                const reco::BeamSpot &beamSpot) const {
0063   const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
0064 
0065   if (TrackerBounds::isInside(tsos.globalPosition())) {
0066     LogTrace(metname) << "Trajectory inside the Tracker";
0067 
0068     TSCBLBuilderNoMaterial tscblBuilder;
0069     TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(tsos.freeState()), beamSpot);
0070 
0071     if (tscbl.isValid())
0072       return pair<bool, FreeTrajectoryState>(true, tscbl.trackStateAtPCA());
0073     else
0074       edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
0075                                << " This can cause a severe bug.";
0076   } else {
0077     LogTrace(metname) << "Trajectory inside the muon system";
0078 
0079     FreeTrajectoryState result = theService->propagator(thePropagatorName)->propagate(*tsos.freeState(), beamSpot);
0080 
0081     LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: " << result << " parameters: " << result.parameters();
0082 
0083     if (result.hasError())
0084       return pair<bool, FreeTrajectoryState>(true, result);
0085     else
0086       edm::LogInfo(metname) << "Propagation to the PCA failed!";
0087   }
0088   return pair<bool, FreeTrajectoryState>(false, FreeTrajectoryState());
0089 }
0090 
0091 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::update(const reco::TransientTrack &track,
0092                                                             const reco::BeamSpot &beamSpot) const {
0093   const std::string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
0094 
0095   pair<bool, FreeTrajectoryState> result(false, FreeTrajectoryState());
0096 
0097   GlobalPoint spotPos(beamSpot.x0(), beamSpot.y0(), beamSpot.z0());
0098 
0099   SingleTrackVertexConstraint::BTFtuple constrainedTransientTrack;
0100 
0101   // Temporary hack here. A fix in the SingleTrackVertexConstraint code
0102   // is needed. Once available try&catch will be removed
0103   try {
0104     constrainedTransientTrack = theConstrictor.constrain(track, spotPos, thePositionErrors);
0105   } catch (cms::Exception &e) {
0106     edm::LogWarning(metname) << "cms::Exception caught in MuonUpdatorAtVertex::update\n"
0107                              << "Exception from SingleTrackVertexConstraint\n"
0108                              << e.explainSelf();
0109     return result;
0110   }
0111 
0112   if (std::get<0>(constrainedTransientTrack))
0113     if (std::get<2>(constrainedTransientTrack) <= theChi2Cut) {
0114       result.first = true;
0115       result.second = *std::get<1>(constrainedTransientTrack).impactPointState().freeState();
0116     } else
0117       LogTrace(metname) << "Constraint at vertex failed: too large chi2";
0118   else
0119     LogTrace(metname) << "Constraint at vertex failed";
0120 
0121   return result;
0122 }
0123 
0124 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::update(const FreeTrajectoryState &ftsAtVtx,
0125                                                             const reco::BeamSpot &beamSpot) const {
0126   return update(theTransientTrackFactory.build(ftsAtVtx), beamSpot);
0127 }
0128 
0129 pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagateWithUpdate(const TrajectoryStateOnSurface &tsos,
0130                                                                          const reco::BeamSpot &beamSpot) const {
0131   pair<bool, FreeTrajectoryState> propagationResult = propagate(tsos, beamSpot);
0132 
0133   if (propagationResult.first) {
0134     return update(propagationResult.second, beamSpot);
0135   } else {
0136     edm::LogInfo("Muon|RecoMuon|MuonUpdatorAtVertex") << "Constraint at vertex failed";
0137     return pair<bool, FreeTrajectoryState>(false, FreeTrajectoryState());
0138   }
0139 }
0140 
0141 std::pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagateToNominalLine(
0142     const TrajectoryStateOnSurface &tsos) const {
0143   const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
0144 
0145   if (TrackerBounds::isInside(tsos.globalPosition())) {
0146     LogTrace(metname) << "Trajectory inside the Tracker";
0147 
0148     TSCPBuilderNoMaterial tscpBuilder;
0149     TrajectoryStateClosestToPoint tscp = tscpBuilder(*(tsos.freeState()), GlobalPoint(0., 0., 0.));
0150 
0151     if (tscp.isValid())
0152       return pair<bool, FreeTrajectoryState>(true, tscp.theState());
0153     else
0154       edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
0155                                << " This can cause a severe bug.";
0156   } else {
0157     LogTrace(metname) << "Trajectory inside the muon system";
0158 
0159     // Define a line using two 3D-points
0160     GlobalPoint p1(0., 0., -1500);
0161     GlobalPoint p2(0., 0., 1500);
0162 
0163     pair<FreeTrajectoryState, double> result =
0164         theService->propagator(thePropagatorName)->propagateWithPath(*tsos.freeState(), p1, p2);
0165 
0166     LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: " << result.second
0167                       << " parameters: " << result.first.parameters();
0168 
0169     if (result.first.hasError())
0170       return pair<bool, FreeTrajectoryState>(true, result.first);
0171     else
0172       edm::LogInfo(metname) << "Propagation to the PCA failed! Path: " << result.second;
0173   }
0174   return pair<bool, FreeTrajectoryState>(false, FreeTrajectoryState());
0175 }
0176 
0177 std::pair<bool, FreeTrajectoryState> MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos) const {
0178   return propagateToNominalLine(tsos);
0179 }