CMS 3D CMS Logo

VertexFitterResult.cc
Go to the documentation of this file.
5 
6 using namespace reco;
7 using namespace std;
8 
9 VertexFitterResult::VertexFitterResult(const int maxTracks, const MagneticField* magField) : theMagField(magField) {
11  if (theMagField == nullptr)
12  theMaxTracks = 0;
13  for (int i = 0; i < 5; i++) {
14  if (maxTracks > 0) {
15  simPars[i] = new float[maxTracks];
16  recPars[i] = new float[maxTracks];
17  refPars[i] = new float[maxTracks];
18  recErrs[i] = new float[maxTracks];
19  refErrs[i] = new float[maxTracks];
20  } else {
21  simPars[i] = nullptr;
22  recPars[i] = nullptr;
23  refPars[i] = nullptr;
24  recErrs[i] = nullptr;
25  refErrs[i] = nullptr;
26  }
27  }
28  trackWeight = new float[maxTracks];
29  simIndex = new int[maxTracks];
30  recIndex = new int[maxTracks];
33  reset();
34 }
35 
37  //
38  // delete arrays
39  //
40  for (int i = 0; i < 5; i++) {
41  delete[] simPars[i];
42  delete[] recPars[i];
43  delete[] refPars[i];
44  delete[] recErrs[i];
45  delete[] refErrs[i];
46  }
47  delete trackWeight;
48  delete simIndex;
49  delete recIndex;
50 }
51 
53  const TrackingVertex* simv,
54  reco::RecoToSimCollection* recSimColl,
55  const float& time) {
56  TTrackCont recTrackV;
57  if (recVertex.isValid())
58  recTrackV = recVertex.originalTracks();
59  fill(recVertex, recTrackV, simv, recSimColl, time);
60 }
61 
63  const TTrackCont& recTrackV,
64  const TrackingVertex* simv,
65  reco::RecoToSimCollection* recSimColl,
66  const float& time) {
67  TrackingParticleRefVector simTrackV;
68 
70  if (recVertex.isValid()) {
71  recPos[0] = recVertex.position().x();
72  recPos[1] = recVertex.position().y();
73  recPos[2] = recVertex.position().z();
74 
75  recErr[0] = sqrt(recVertex.positionError().cxx());
76  recErr[1] = sqrt(recVertex.positionError().cyy());
77  recErr[2] = sqrt(recVertex.positionError().czz());
78  vert = (Basic3DVector<double>)recVertex.position();
79 
80  chi[0] = recVertex.totalChiSquared();
81  chi[1] = recVertex.degreesOfFreedom();
82  chi[2] = ChiSquaredProbability(recVertex.totalChiSquared(), recVertex.degreesOfFreedom());
83  vertex = 2;
84  fitTime = time;
85  tracks[1] = recVertex.originalTracks().size();
86  }
87 
88  if (simv != nullptr) {
89  simPos[0] = simv->position().x();
90  simPos[1] = simv->position().y();
91  simPos[2] = simv->position().z();
92 
93  simTrackV = simv->daughterTracks();
94  vertex += 1;
97  simTrack++) {
98  Basic3DVector<double> momAtVtx((**simTrack).momentum());
99 
100  std::pair<bool, reco::TrackBase::ParameterVector> paramPair = reco::trackingParametersAtClosestApproachToBeamSpot(
101  vert, momAtVtx, (float)(**simTrack).charge(), *theMagField, recTrackV.front().stateAtBeamLine().beamSpot());
102  if (paramPair.first) {
103  fillParameters(paramPair.second, simPars, numberOfSimTracks);
106  }
107  }
109  }
110 
111  // now store all the recTrack...
112 
113  for (TTrackCont::const_iterator recTrack = recTrackV.begin();
114  (recTrack != recTrackV.end() && (numberOfRecTracks < theMaxTracks));
115  recTrack++) {
116  // std::cout << "Input; 1/Pt " << 1./(*recTrack).momentumAtVertex().transverse() << std::endl;
117 
118  //looking for sim tracks corresponding to our reconstructed tracks:
120 
121  std::vector<std::pair<TrackingParticleRef, double> > simFound;
122  try {
123  const TrackTransientTrack* ttt = dynamic_cast<const TrackTransientTrack*>(recTrack->basicTransientTrack());
124  if ((ttt != nullptr) && (recSimColl != nullptr))
125  simFound = (*recSimColl)[ttt->trackBaseRef()];
126  // if (recSimColl!=0) simFound = (*recSimColl)[recTrack->persistentTrackRef()];
127  // if (recSimColl!=0) simFound = (*recSimColl)[recTrack];
128 
129  } catch (cms::Exception const& e) {
130  // LogDebug("TrackValidator") << "reco::Track #" << rT << " with pt=" << track->pt()
131  // << " NOT associated to any TrackingParticle" << "\n";
132  // edm::LogError("TrackValidator") << e.what() << "\n";
133  }
134 
135  if (!simFound.empty()) {
136  //OK, it was associated, so get the state on the same surface as the 'SimState'
137  TrackingParticleRefVector::const_iterator simTrackI = find(simTrackV.begin(), simTrackV.end(), simFound[0].first);
138  if (simTrackI != simTrackV.end())
139  ++tracks[2];
140  int simTrackIndex = simTrackI - simTrackV.begin();
141  if (simTrackIndex < numberOfSimTracks) {
142  simIndex[numberOfRecTracks] = simTrackIndex;
143  recIndex[simTrackIndex] = numberOfRecTracks;
144  // cout << "Assoc; 1/Pt " << 1./(*recTrack).momentumAtVertex().transverse() << std::endl;
145  }
146  }
147 
148  TrajectoryStateClosestToPoint tscp = recTrack->trajectoryStateClosestToPoint(recVertex.position());
149  fillParameters(recTrack->track().parameters(), recPars, numberOfRecTracks);
151  // trackWeight[numberOfRecTracks] = recVertex.trackWeight(*recTrack);
152  //
153  // if ((recVertex.isValid())&&(recVertex.hasRefittedTracks())) {
154  // //looking for corresponding refitted tracks:
155  // TrajectoryStateOnSurface refip;
156  // RecTrackCont::iterator refTrackI =
157  // find_if(refTracks.begin(), refTracks.end(), RecTrackMatch(*recTrack));
158  // if (refTrackI!=refTracks.end()) {
159  // // If it was not found, it would mean that it was not used in the fit,
160  // // or with a low weight such that the track was then discarded.
161  // if(simFound.size() != 0) {
162  // refip = refTrackI->stateOnSurface(simFound[0]->impactPointStateOnSurface().surface());
163  // } else {
164  // refip = refTrackI->innermostState();
165  // }
166  //
167  // fillParameters(refip, refPars, numberOfRecTracks);
168  // fillErrors(refip, refErrs, numberOfRecTracks);
169  // }
170  // }
171  //
173  }
174 }
175 
177  float* params[5],
178  int trackNumber) {
179  params[0][trackNumber] = perigee[0];
180  params[1][trackNumber] = perigee[1];
181  params[2][trackNumber] = perigee[2];
182  params[3][trackNumber] = perigee[3];
183  params[4][trackNumber] = perigee[4];
184 }
185 
186 void VertexFitterResult::fillParameters(const PerigeeTrajectoryParameters& ptp, float* params[5], int trackNumber) {
187  const AlgebraicVector5& perigee = ptp.vector();
188  params[0][trackNumber] = perigee[0];
189  params[1][trackNumber] = perigee[1];
190  params[2][trackNumber] = perigee[2];
191  params[3][trackNumber] = perigee[3];
192  params[4][trackNumber] = perigee[4];
193 }
194 
195 void VertexFitterResult::fillErrors(const PerigeeTrajectoryError& pte, float* errors[5], int trackNumber) {
196  errors[0][trackNumber] = pte.transverseCurvatureError();
197  errors[1][trackNumber] = pte.thetaError();
198  errors[2][trackNumber] = pte.phiError();
199  errors[3][trackNumber] = pte.transverseImpactParameterError();
200  errors[4][trackNumber] = pte.longitudinalImpactParameterError();
201 }
202 
204  for (int i = 0; i < 3; ++i) {
205  simPos[i] = 0.;
206  recPos[i] = 0.;
207  recErr[i] = 0.;
208  chi[i] = 0.;
209  tracks[i] = 0;
210  }
211  vertex = 0;
212  fitTime = 0;
213 
214  for (int j = 0; j < numberOfRecTracks; ++j) {
215  for (int i = 0; i < 5; ++i) {
216  recPars[i][j] = 0;
217  refPars[i][j] = 0;
218  recErrs[i][j] = 0;
219  refErrs[i][j] = 0;
220  }
221  trackWeight[j] = 0;
222  simIndex[j] = -1;
223  }
224  for (int j = 0; j < numberOfSimTracks; ++j) {
225  for (int i = 0; i < 5; ++i) {
226  simPars[i][j] = 0;
227  }
228  recIndex[j] = -1;
229  }
230 
231  numberOfRecTracks = 0;
232  numberOfSimTracks = 0;
233 }
void fill(const TransientVertex &recv, const TrackingVertex *simv=nullptr, reco::RecoToSimCollection *recSimColl=nullptr, const float &time=0)
const AlgebraicVector5 & vector() const
double transverseCurvatureError() const
float totalChiSquared() const
const MagneticField * theMagField
GlobalPoint position() const
void fillErrors(const PerigeeTrajectoryError &pte, float *errors[5], int trackNumber)
std::vector< reco::TransientTrack > TTrackCont
T z() const
Definition: PV3DBase.h:61
GlobalError positionError() const
double transverseImpactParameterError() const
void fillParameters(const reco::TrackBase::ParameterVector &perigee, float *params[5], int trackNumber)
double longitudinalImpactParameterError() const
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:71
tp_iterator daughterTracks_begin() const
const PerigeeTrajectoryError & perigeeError() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
float degreesOfFreedom() const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
bool isValid() const
T sqrt(T t)
Definition: SSEVec.h:19
VertexFitterResult(const int maxTracks=100, const MagneticField *=nullptr)
ROOT::Math::SVector< double, 5 > AlgebraicVector5
std::vector< reco::TransientTrack > const & originalTracks() const
float ChiSquaredProbability(double chiSquared, double nrDOF)
const LorentzVector & position() const
std::pair< bool, reco::TrackBase::ParameterVector > trackingParametersAtClosestApproachToBeamSpot(const Basic3DVector< double > &vertex, const Basic3DVector< double > &momAtVtx, float charge, const MagneticField &magField, const BeamSpot &bs)
const float * time() const
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
const TrackingParticleRefVector & daughterTracks() const
maxTracks
Definition: DMR_cfg.py:158
fixed size matrix
tp_iterator daughterTracks_end() const
Definition: errors.py:1
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
TrackBaseRef trackBaseRef() const override