CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
TotemRPLocalTrackFitterAlgorithm Class Reference

Algorithm for fitting tracks through a single RP. More...

#include <TotemRPLocalTrackFitterAlgorithm.h>

Classes

struct  RPDetCoordinateAlgebraObjs
 

Public Member Functions

bool fitTrack (const edm::DetSetVector< TotemRPRecHit > &hits, double z_0, const CTPPSGeometry &tot_geom, TotemRPLocalTrack &fitted_track)
 performs the track fit, returns true if successful More...
 
void reset ()
 Resets the reconstruction-data cache. More...
 
 TotemRPLocalTrackFitterAlgorithm (const edm::ParameterSet &conf)
 

Private Member Functions

RPDetCoordinateAlgebraObjsgetDetAlgebraData (unsigned int det_id, const CTPPSGeometry &tot_rp_geom)
 
void multiplyByDiagonalInPlace (TMatrixD &mt, const TVectorD &diag)
 A matrix multiplication shorthand. More...
 
RPDetCoordinateAlgebraObjs prepareReconstAlgebraData (unsigned int det_id, const CTPPSGeometry &tot_rp_geom)
 Build the reconstruction data. More...
 

Static Private Member Functions

static TVector3 convert3vector (const CLHEP::Hep3Vector &v)
 

Private Attributes

std::unordered_map< unsigned int, RPDetCoordinateAlgebraObjsdet_data_map_
 A cache of reconstruction data. Must be reset every time the geometry chagnges. More...
 
RPTopology rp_topology_
 

Detailed Description

Algorithm for fitting tracks through a single RP.

Definition at line 32 of file TotemRPLocalTrackFitterAlgorithm.h.

Constructor & Destructor Documentation

TotemRPLocalTrackFitterAlgorithm::TotemRPLocalTrackFitterAlgorithm ( const edm::ParameterSet conf)

Definition at line 23 of file TotemRPLocalTrackFitterAlgorithm.cc.

23 {}

Member Function Documentation

static TVector3 TotemRPLocalTrackFitterAlgorithm::convert3vector ( const CLHEP::Hep3Vector &  v)
inlinestaticprivate

Definition at line 68 of file TotemRPLocalTrackFitterAlgorithm.h.

68 { return TVector3(v.x(), v.y(), v.z()); }
bool TotemRPLocalTrackFitterAlgorithm::fitTrack ( const edm::DetSetVector< TotemRPRecHit > &  hits,
double  z_0,
const CTPPSGeometry tot_geom,
TotemRPLocalTrack fitted_track 
)

performs the track fit, returns true if successful

Definition at line 71 of file TotemRPLocalTrackFitterAlgorithm.cc.

References a, TotemRPLocalTrack::addHit(), TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::available_, TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::centre_of_det_global_position_, MillePedeFileConverter_cfg::e, h, class-composition::H, mps_fire::i, JetComb::kMult, TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::readout_direction_, TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::rec_u_0_, TotemRPLocalTrack::setChiSquared(), TotemRPLocalTrack::setCovarianceMatrix(), TotemRPLocalTrack::setParameterVector(), TotemRPLocalTrack::setValid(), TotemRPLocalTrack::setZ0(), mathSSE::sqrt(), TotemRPLocalTrack::trackPoint(), TotemRPLocalTrack::trackPointInterpolationCovariance(), mitigatedMETSequence_cff::U, and trigObjTnPSource_cfi::var.

Referenced by TotemRPLocalTrackFitter::produce().

74  {
75  fitted_track.setValid(false);
76 
77  // bind hits with their algebra objects
78  struct HitWithAlg {
79  unsigned int detId;
80  const TotemRPRecHit *hit;
81  RPDetCoordinateAlgebraObjs *alg;
82  };
83 
84  vector<HitWithAlg> applicable_hits;
85 
86  for (auto &ds : hits) {
87  unsigned int detId = ds.detId();
88 
89  for (auto &h : ds) {
90  RPDetCoordinateAlgebraObjs *alg = getDetAlgebraData(detId, tot_geom);
91  if (alg->available_)
92  applicable_hits.push_back({detId, &h, alg});
93  }
94  }
95 
96  if (applicable_hits.size() < 5)
97  return false;
98 
99  TMatrixD H(applicable_hits.size(), 4);
100  TVectorD V(applicable_hits.size());
101  TVectorD V_inv(applicable_hits.size());
102  TVectorD U(applicable_hits.size());
103 
104  for (unsigned int i = 0; i < applicable_hits.size(); ++i) {
105  RPDetCoordinateAlgebraObjs *alg_obj = applicable_hits[i].alg;
106 
107  H(i, 0) = alg_obj->readout_direction_.X();
108  H(i, 1) = alg_obj->readout_direction_.Y();
109  double delta_z = alg_obj->centre_of_det_global_position_.Z() - z_0;
110  H(i, 2) = alg_obj->readout_direction_.X() * delta_z;
111  H(i, 3) = alg_obj->readout_direction_.Y() * delta_z;
112  double var = applicable_hits[i].hit->sigma();
113  var *= var;
114  V[i] = var;
115  V_inv[i] = 1.0 / var;
116  U[i] = applicable_hits[i].hit->position() - alg_obj->rec_u_0_;
117  }
118 
119  TMatrixD H_T_V_inv(TMatrixD::kTransposed, H);
120  multiplyByDiagonalInPlace(H_T_V_inv, V_inv);
121  TMatrixD V_a(H_T_V_inv);
122  TMatrixD V_a_mult(V_a, TMatrixD::kMult, H);
123  try {
124  V_a_mult.Invert();
125  } catch (cms::Exception &e) {
126  LogError("TotemRPLocalTrackFitterAlgorithm") << "Error in TotemRPLocalTrackFitterAlgorithm::fitTrack > "
127  << "Fit matrix is singular. Skipping.";
128  return false;
129  }
130 
131  TMatrixD u_to_a(V_a_mult, TMatrixD::kMult, H_T_V_inv);
132  TVectorD a(U);
133  a *= u_to_a;
134 
135  fitted_track.setZ0(z_0);
136  fitted_track.setParameterVector(a);
137  fitted_track.setCovarianceMatrix(V_a_mult);
138 
139  double Chi_2 = 0;
140  for (unsigned int i = 0; i < applicable_hits.size(); ++i) {
141  RPDetCoordinateAlgebraObjs *alg_obj = applicable_hits[i].alg;
142  TVector2 readout_dir = alg_obj->readout_direction_;
143  double det_z = alg_obj->centre_of_det_global_position_.Z();
144  double sigma_str = applicable_hits[i].hit->sigma();
145  double sigma_str_2 = sigma_str * sigma_str;
146  TVector2 fited_det_xy_point = fitted_track.trackPoint(det_z);
147  double U_readout = applicable_hits[i].hit->position() - alg_obj->rec_u_0_;
148  double U_fited = (readout_dir *= fited_det_xy_point);
149  double residual = U_fited - U_readout;
150  TMatrixD V_T_Cov_X_Y(1, 2);
151  V_T_Cov_X_Y(0, 0) = readout_dir.X();
152  V_T_Cov_X_Y(0, 1) = readout_dir.Y();
153  TMatrixD V_T_Cov_X_Y_mult(V_T_Cov_X_Y, TMatrixD::kMult, fitted_track.trackPointInterpolationCovariance(det_z));
154  double fit_strip_var = V_T_Cov_X_Y_mult(0, 0) * readout_dir.X() + V_T_Cov_X_Y_mult(0, 1) * readout_dir.Y();
155  double pull_normalization = sqrt(sigma_str_2 - fit_strip_var);
156  double pull = residual / pull_normalization;
157 
158  Chi_2 += residual * residual / sigma_str_2;
159 
161  *(applicable_hits[i].hit), TVector3(fited_det_xy_point.X(), fited_det_xy_point.Y(), det_z), residual, pull);
162  fitted_track.addHit(applicable_hits[i].detId, hit_point);
163  }
164 
165  fitted_track.setChiSquared(Chi_2);
166  fitted_track.setValid(true);
167  return true;
168 }
void setChiSquared(double &chiSquared)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void multiplyByDiagonalInPlace(TMatrixD &mt, const TVectorD &diag)
A matrix multiplication shorthand.
void addHit(unsigned int detId, const FittedRecHit &hit)
TVector2 trackPoint(double z) const
returns (x, y) vector
TMatrixD trackPointInterpolationCovariance(double z) const
void setZ0(double z0)
T sqrt(T t)
Definition: SSEVec.h:19
Reconstructed hit in TOTEM RP.
Definition: TotemRPRecHit.h:18
void setValid(bool valid)
void setCovarianceMatrix(const TMatrixD &par_covariance_matrix)
double a
Definition: hdecay.h:119
void setParameterVector(const TVectorD &track_params_vector)
RPDetCoordinateAlgebraObjs * getDetAlgebraData(unsigned int det_id, const CTPPSGeometry &tot_rp_geom)
TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs * TotemRPLocalTrackFitterAlgorithm::getDetAlgebraData ( unsigned int  det_id,
const CTPPSGeometry tot_rp_geom 
)
private

Returns the reconstruction data for the chosen detector from the cache DetReconstructionDataMap. If it is not yet in the cache, calls PrepareReconstAlgebraData to make it.

Definition at line 58 of file TotemRPLocalTrackFitterAlgorithm.cc.

59  {
60  auto it = det_data_map_.find(det_id);
61  if (it != det_data_map_.end()) {
62  return &(it->second);
63  } else {
64  det_data_map_[det_id] = prepareReconstAlgebraData(det_id, tot_rp_geom);
65  return &det_data_map_[det_id];
66  }
67 }
std::unordered_map< unsigned int, RPDetCoordinateAlgebraObjs > det_data_map_
A cache of reconstruction data. Must be reset every time the geometry chagnges.
RPDetCoordinateAlgebraObjs prepareReconstAlgebraData(unsigned int det_id, const CTPPSGeometry &tot_rp_geom)
Build the reconstruction data.
void TotemRPLocalTrackFitterAlgorithm::multiplyByDiagonalInPlace ( TMatrixD &  mt,
const TVectorD &  diag 
)
private

A matrix multiplication shorthand.

Definition at line 172 of file TotemRPLocalTrackFitterAlgorithm.cc.

References mps_fire::i, and dqmiolumiharvest::j.

172  {
173  for (int i = 0; i < mt.GetNrows(); ++i) {
174  for (int j = 0; j < mt.GetNcols(); ++j) {
175  mt[i][j] *= diag[j];
176  }
177  }
178 }
TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs TotemRPLocalTrackFitterAlgorithm::prepareReconstAlgebraData ( unsigned int  det_id,
const CTPPSGeometry tot_rp_geom 
)
private

Build the reconstruction data.

Definition at line 32 of file TotemRPLocalTrackFitterAlgorithm.cc.

References TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::available_, TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::centre_of_det_global_position_, CTPPSGeometry::localToGlobalDirection(), TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::readout_direction_, TotemRPLocalTrackFitterAlgorithm::RPDetCoordinateAlgebraObjs::rec_u_0_, CTPPSGeometry::sensorTranslation(), and findQualityFiles::v.

32  {
33  RPDetCoordinateAlgebraObjs det_algebra_obj;
34 
35  det_algebra_obj.centre_of_det_global_position_ = convert3vector(tot_rp_geom.sensorTranslation(det_id));
36 
37  HepMC::ThreeVector rp_topology_stripaxis = rp_topology_.GetStripReadoutAxisDir();
38  CLHEP::Hep3Vector rp_topology_stripaxis_clhep;
39 
40  rp_topology_stripaxis_clhep.setX(rp_topology_stripaxis.x());
41  rp_topology_stripaxis_clhep.setY(rp_topology_stripaxis.y());
42  rp_topology_stripaxis_clhep.setZ(rp_topology_stripaxis.z());
43 
44  TVector3 rd_dir = convert3vector(tot_rp_geom.localToGlobalDirection(det_id, rp_topology_stripaxis_clhep));
45 
46  TVector2 v(rd_dir.X(), rd_dir.Y());
47  det_algebra_obj.readout_direction_ = v.Unit();
48  det_algebra_obj.rec_u_0_ = 0.0;
49  det_algebra_obj.available_ = true;
50  det_algebra_obj.rec_u_0_ =
51  -(det_algebra_obj.readout_direction_ * det_algebra_obj.centre_of_det_global_position_.XYvector());
52 
53  return det_algebra_obj;
54 }
const HepMC::ThreeVector & GetStripReadoutAxisDir() const
Definition: RPTopology.h:32
CLHEP::Hep3Vector sensorTranslation(unsigned int id) const
CLHEP::Hep3Vector localToGlobalDirection(unsigned int id, const CLHEP::Hep3Vector &) const
static TVector3 convert3vector(const CLHEP::Hep3Vector &v)
void TotemRPLocalTrackFitterAlgorithm::reset ( void  )

Resets the reconstruction-data cache.

Definition at line 27 of file TotemRPLocalTrackFitterAlgorithm.cc.

Referenced by TotemRPLocalTrackFitter::produce().

27 { det_data_map_.clear(); }
std::unordered_map< unsigned int, RPDetCoordinateAlgebraObjs > det_data_map_
A cache of reconstruction data. Must be reset every time the geometry chagnges.

Member Data Documentation

std::unordered_map<unsigned int, RPDetCoordinateAlgebraObjs> TotemRPLocalTrackFitterAlgorithm::det_data_map_
private

A cache of reconstruction data. Must be reset every time the geometry chagnges.

Definition at line 54 of file TotemRPLocalTrackFitterAlgorithm.h.

RPTopology TotemRPLocalTrackFitterAlgorithm::rp_topology_
private

Definition at line 56 of file TotemRPLocalTrackFitterAlgorithm.h.