SND@LHC Software
Loading...
Searching...
No Matches
GFRaveConverters.cc
Go to the documentation of this file.
1/* Copyright 2008-2010, Technische Universitaet Muenchen,
2 Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
3
4 This file is part of GENFIT.
5
6 GENFIT is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GENFIT is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#include "GFRaveConverters.h"
22
23#include "Exception.h"
24
25#include "rave/Plane.h"
26
28
29#include <iostream>
30
31
32namespace genfit {
33
34
35std::vector < rave::Track >
36GFTracksToTracks(const std::vector < genfit::Track* > & GFTracks,
37 std::vector < genfit::MeasuredStateOnPlane* > * GFStates,
38 std::map<int, genfit::trackAndState>& IdGFTrackStateMap,
39 int startID){
40
41 unsigned int ntracks(GFTracks.size());
42
43 if (GFStates != NULL)
44 if (GFTracks.size() != GFStates->size()) {
45 Exception exc("GFTracksToTracks ==> GFStates has not the same size as GFTracks!",__LINE__,__FILE__);
46 throw exc;
47 }
48
49 std::vector < rave::Track > ravetracks;
50 ravetracks.reserve(ntracks);
51
52 for (unsigned int i=0; i<ntracks; ++i){
53
54 if (GFTracks[i] == NULL) {
55 Exception exc("GFTracksToTracks ==> genfit::Track is NULL",__LINE__,__FILE__);
56 throw exc;
57 }
58
59 // only convert successfully fitted tracks!
60 if (!GFTracks[i]->getFitStatus(GFTracks[i]->getCardinalRep())->isFitConverged()) continue;
61
62 if (IdGFTrackStateMap.count(startID) > 0){
63 Exception exc("GFTracksToTracks ==> IdGFTrackStateMap has already an entry for this id",__LINE__,__FILE__);
64 throw exc;
65 }
66 IdGFTrackStateMap[startID].track_ = GFTracks[i];
67 if (GFStates == NULL)
68 IdGFTrackStateMap[startID].state_ = new MeasuredStateOnPlane(GFTracks[i]->getFittedState()); // here clones are made so that the state of the original GFTracks and their TrackReps will not be altered by the vertexing process
69 else
70 IdGFTrackStateMap[startID].state_ = (*GFStates)[i];
71
72 ravetracks.push_back(GFTrackToTrack(IdGFTrackStateMap[startID], startID) );
73
74 ++startID;
75 }
76
77 //std::cout << "IdGFTrackStateMap size " << IdGFTrackStateMap.size() << std::endl;
78 return ravetracks;
79}
80
81
82rave::Track
83GFTrackToTrack(trackAndState trackAndState, int id, std::string tag){
84
85 if (trackAndState.track_ == NULL) {
86 Exception exc("GFTrackToTrack ==> originaltrack is NULL",__LINE__,__FILE__);
87 throw exc;
88 }
89
91 Exception exc("GFTrackToTrack ==> Trackfit is not converged",__LINE__,__FILE__);
92 throw exc;
93 }
94
95 TVector3 pos, mom;
96 TMatrixDSym cov;
97
99
100 // state
101 rave::Vector6D ravestate(pos.X(), pos.Y(), pos.Z(),
102 mom.X(), mom.Y(), mom.Z());
103
104 // covariance
105 rave::Covariance6D ravecov(cov(0,0), cov(1,0), cov(2,0),
106 cov(1,1), cov(2,1), cov(2,2),
107 cov(3,0), cov(4,0), cov(5,0),
108 cov(3,1), cov(4,1), cov(5,1),
109 cov(3,2), cov(4,2), cov(5,2),
110 cov(3,3), cov(4,3), cov(5,3),
111 cov(4,4), cov(5,4), cov(5,5));
112
113 //std::cerr<<"create rave track with id " << id << std::endl;
114 //std::cerr<<" pos: "; Point3DToTVector3(ravestate.position()).Print();
115 //std::cerr<<" mom: "; Vector3DToTVector3(ravestate.momentum()).Print();
116
117 rave::Track ret(id, ravestate, ravecov,
121 static_cast<void*>(const_cast<Track*>(trackAndState.track_)), tag);
122
123 //std::cout << "ret.originalObject() " << ret.originalObject() << "\n";
124 //std::cout << "ret.id() " << ret.id() << "\n";
125
126 return ret;
127}
128
129
130void
131setData(const rave::Track& orig, MeasuredStateOnPlane* state){
132
133 state->setPosMomCov(TVector3(orig.state().x(), orig.state().y(), orig.state().z()),
134 TVector3(orig.state().px(), orig.state().py(), orig.state().pz()),
135 Covariance6DToTMatrixDSym(orig.error()));
136
137}
138
139
140GFRaveVertex*
141RaveToGFVertex(const rave::Vertex & raveVertex,
142 const std::map<int, genfit::trackAndState>& IdGFTrackStateMap){
143
144 if (!(raveVertex.isValid())) {
145 Exception exc("RaveToGFVertex ==> rave Vertex is not valid!",__LINE__,__FILE__);
146 throw exc;
147 }
148
149 std::vector < std::pair < float, rave::Track > > raveWeightedTracks(raveVertex.weightedTracks());
150 std::vector < std::pair < float, rave::Track > > raveSmoothedTracks(raveVertex.weightedRefittedTracks());
151
152 int id;
153 unsigned int nTrks(raveWeightedTracks.size());
154
155 // check if rave vertex has refitted tracks
156 bool smoothing(true);
157 if (! (raveVertex.hasRefittedTracks()) ) {
158 smoothing = false;
159 }
160
161 // check numbers of tracks and smoothed tracks
162 if (smoothing && nTrks != raveSmoothedTracks.size()){
163 Exception exc("RaveToGFVertex ==> number of smoothed tracks != number of tracks",__LINE__,__FILE__);
164 throw exc;
165 }
166
167 // (smoothed) track parameters
168 std::vector < GFRaveTrackParameters* > trackParameters;
169 trackParameters.reserve(nTrks);
170
171 // convert tracks
172 for (unsigned int i=0; i<nTrks; ++i){
173 id = raveWeightedTracks[i].second.id();
174
175 if (IdGFTrackStateMap.count(id) == 0){
176 Exception exc("RaveToGFVertex ==> rave track id is not present in IdGFTrackStateMap",__LINE__,__FILE__);
177 throw exc;
178 }
179
180 GFRaveTrackParameters* trackparams;
181
182 if(smoothing) {
183 // convert smoothed track parameters
184 trackparams = new GFRaveTrackParameters(IdGFTrackStateMap.at(id).track_, //track
185 IdGFTrackStateMap.at(id).state_, //state
186 raveWeightedTracks[i].first, //weight
187 Vector6DToTVectorD(raveSmoothedTracks[i].second.state()), //smoothed state
188 Covariance6DToTMatrixDSym(raveSmoothedTracks[i].second.error()), //smoothed cov
189 true);
190 }
191 else {
192 // convert track parameters, no smoothed tracks available
193 trackparams = new GFRaveTrackParameters(IdGFTrackStateMap.at(id).track_, //track
194 IdGFTrackStateMap.at(id).state_, //state
195 raveWeightedTracks[i].first, //weight
196 Vector6DToTVectorD(raveWeightedTracks[i].second.state()), //state
197 Covariance6DToTMatrixDSym(raveWeightedTracks[i].second.error()), //cov
198 false);
199 }
200 trackParameters.push_back(trackparams);
201 }
202
203 return new GFRaveVertex(Point3DToTVector3(raveVertex.position()),
204 Covariance3DToTMatrixDSym(raveVertex.error()),
205 trackParameters,
206 raveVertex.ndf(), raveVertex.chiSquared(), raveVertex.id());
207}
208
209void
210RaveToGFVertices(std::vector<GFRaveVertex*> * GFVertices,
211 const std::vector<rave::Vertex> & raveVertices,
212 const std::map<int, genfit::trackAndState>& IdGFTrackStateMap){
213
214 unsigned int nVert(raveVertices.size());
215
216 GFVertices->reserve(nVert);
217
218 for (unsigned int i=0; i<nVert; ++i){
219 GFVertices->push_back(RaveToGFVertex(raveVertices[i], IdGFTrackStateMap));
220 }
221}
222
223
225PlaneToGFDetPlane(const ravesurf::Plane& rplane) {
226 return SharedPlanePtr(new DetPlane(Point3DToTVector3(rplane.position()),
227 Vector3DToTVector3(rplane.normalVector()) ));
228}
229
230
231TVector3
232Point3DToTVector3(const rave::Point3D& v) {
233 return TVector3(v.x(), v.y(), v.z());
234}
235
236TVector3
237Vector3DToTVector3(const rave::Vector3D& v) {
238 return TVector3(v.x(), v.y(), v.z());
239}
240
241
242TMatrixDSym
243Covariance3DToTMatrixDSym(const rave::Covariance3D& ravecov){
244 TMatrixDSym cov(3);
245
246 cov(0,0) = ravecov.dxx();
247 cov(0,1) = ravecov.dxy();
248 cov(0,2) = ravecov.dxz();
249
250 cov(1,0) = ravecov.dxy();
251 cov(1,1) = ravecov.dyy();
252 cov(1,2) = ravecov.dyz();
253
254 cov(2,0) = ravecov.dxz();
255 cov(2,1) = ravecov.dyz();
256 cov(2,2) = ravecov.dzz();
257
258 return cov;
259}
260
261
262TVectorD
263Vector6DToTVectorD(const rave::Vector6D& ravevec){
264 TVectorD vec(6);
265
266 vec[0] = ravevec.x();
267 vec[1] = ravevec.y();
268 vec[2] = ravevec.z();
269
270 vec[3] = ravevec.px();
271 vec[4] = ravevec.py();
272 vec[5] = ravevec.pz();
273
274 return vec;
275}
276
277
278TMatrixDSym
279Covariance6DToTMatrixDSym(const rave::Covariance6D& ravecov){
280 TMatrixDSym cov(6);
281
282 cov(0,0) = ravecov.dxx();
283 cov(0,1) = ravecov.dxy();
284 cov(0,2) = ravecov.dxz();
285 cov(0,3) = ravecov.dxpx();
286 cov(0,4) = ravecov.dxpy();
287 cov(0,5) = ravecov.dxpz();
288
289 cov(1,0) = ravecov.dxy();
290 cov(1,1) = ravecov.dyy();
291 cov(1,2) = ravecov.dyz();
292 cov(1,3) = ravecov.dypx();
293 cov(1,4) = ravecov.dypy();
294 cov(1,5) = ravecov.dypz();
295
296 cov(2,0) = ravecov.dxz();
297 cov(2,1) = ravecov.dyz();
298 cov(2,2) = ravecov.dzz();
299 cov(2,3) = ravecov.dzpx();
300 cov(2,4) = ravecov.dzpy();
301 cov(2,5) = ravecov.dzpz();
302
303 cov(3,0) = ravecov.dxpx();
304 cov(3,1) = ravecov.dypx();
305 cov(3,2) = ravecov.dzpx();
306 cov(3,3) = ravecov.dpxpx();
307 cov(3,4) = ravecov.dpxpy();
308 cov(3,5) = ravecov.dpxpz();
309
310 cov(4,0) = ravecov.dxpy();
311 cov(4,1) = ravecov.dypy();
312 cov(4,2) = ravecov.dzpy();
313 cov(4,3) = ravecov.dpxpy();
314 cov(4,4) = ravecov.dpypy();
315 cov(4,5) = ravecov.dpypz();
316
317 cov(5,0) = ravecov.dxpz();
318 cov(5,1) = ravecov.dypz();
319 cov(5,2) = ravecov.dzpz();
320 cov(5,3) = ravecov.dpxpz();
321 cov(5,4) = ravecov.dpypz();
322 cov(5,5) = ravecov.dpzpz();
323
324 return cov;
325}
326
327
328rave::Point3D
329TVector3ToPoint3D(const TVector3 & vec){
330 return rave::Point3D(vec.X(), vec.Y(), vec.Z());
331}
332
333
334rave::Covariance3D
335TMatrixDSymToCovariance3D(const TMatrixDSym & matrix){
336 if (matrix.GetNrows()!=3) {
337 Exception exc("TMatrixDSymToCovariance3D ==> TMatrixDSym is not 3x3!",__LINE__,__FILE__);
338 throw exc;
339 }
340
341 return rave::Covariance3D(matrix(0,0), matrix(0,1), matrix(0,2),
342 matrix(1,1), matrix(1,2), matrix(2,2));
343
344}
345
346
347} // end of namespace genfit
348
Detector plane.
Definition DetPlane.h:61
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition Exception.h:48
double getCharge() const
Get the fitted charge.
Definition FitStatus.h:72
double getNdf() const
Get the degrees of freedom of the fit.
Definition FitStatus.h:76
bool isFitConverged(bool inAllPoints=true) const
Did the fit converge (in all Points or only partially)?
Definition FitStatus.h:61
double getChi2() const
Get chi^2 of the fit.
Definition FitStatus.h:74
GFRaveTrackParameters class Contains a pointer to the original genfit::Track, the weight of the track...
GFRaveVertex class.
StateOnPlane with additional covariance matrix.
void getPosMomCov(TVector3 &pos, TVector3 &mom, TMatrixDSym &cov) const
void setPosMomCov(const TVector3 &pos, const TVector3 &mom, const TMatrixDSym &cov6x6)
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
Definition Track.h:71
const MeasuredStateOnPlane & getFittedState(int id=0, const AbsTrackRep *rep=NULL, bool biased=true) const
Shortcut to get FittedStates.
Definition Track.cc:231
FitStatus * getFitStatus(const AbsTrackRep *rep=NULL) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
Definition Track.h:149
Matrix inversion tools.
Definition AbsBField.h:29
std::vector< rave::Track > GFTracksToTracks(const std::vector< genfit::Track * > &GFTracks, std::vector< genfit::MeasuredStateOnPlane * > *GFStates, std::map< int, genfit::trackAndState > &IdGFTrackStateMap, int startID=0)
rave::Track GFTrackToTrack(trackAndState, int id=-1, std::string tag="")
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
TVectorD Vector6DToTVectorD(const rave::Vector6D &)
TMatrixDSym Covariance6DToTMatrixDSym(const rave::Covariance6D &)
rave::Covariance3D TMatrixDSymToCovariance3D(const TMatrixDSym &)
void RaveToGFVertices(std::vector< GFRaveVertex * > *, const std::vector< rave::Vertex > &, const std::map< int, genfit::trackAndState > &IdGFTrackStateMap)
GFRaveVertex * RaveToGFVertex(const rave::Vertex &, const std::map< int, genfit::trackAndState > &IdGFTrackStateMap)
TVector3 Vector3DToTVector3(const rave::Vector3D &)
TVector3 Point3DToTVector3(const rave::Point3D &)
void setData(const rave::Track &orig, MeasuredStateOnPlane *state)
rave::Point3D TVector3ToPoint3D(const TVector3 &)
SharedPlanePtr PlaneToGFDetPlane(const ravesurf::Plane &rplane)
TMatrixDSym Covariance3DToTMatrixDSym(const rave::Covariance3D &)
Simple struct containing a Track pointer and a MeasuredStateOnPlane. Used in GFRave.