CMS 3D CMS Logo

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