21 #include "GFRaveConverters.h"
23 #include "Exception.h"
25 #include "rave/Plane.h"
27 #include "GFRaveTrackParameters.h"
35 std::vector < rave::Track >
37 std::vector < genfit::MeasuredStateOnPlane* > * GFStates,
38 std::map<int, genfit::trackAndState>& IdGFTrackStateMap,
41 unsigned int ntracks(GFTracks.size());
43 if (GFStates !=
nullptr)
44 if (GFTracks.size() != GFStates->size()) {
45 Exception exc(
"GFTracksToTracks ==> GFStates has not the same size as GFTracks!",__LINE__,__FILE__);
49 std::vector < rave::Track > ravetracks;
50 ravetracks.reserve(ntracks);
52 for (
unsigned int i=0; i<ntracks; ++i){
54 if (GFTracks[i] ==
nullptr) {
55 Exception exc(
"GFTracksToTracks ==> genfit::Track is nullptr",__LINE__,__FILE__);
60 if (!GFTracks[i]->getFitStatus(GFTracks[i]->getCardinalRep())->isFitConverged())
continue;
62 if (IdGFTrackStateMap.count(startID) > 0){
63 Exception exc(
"GFTracksToTracks ==> IdGFTrackStateMap has already an entry for this id",__LINE__,__FILE__);
66 IdGFTrackStateMap[startID].track_ = GFTracks[i];
67 if (GFStates ==
nullptr)
70 IdGFTrackStateMap[startID].state_ = (*GFStates)[i];
72 ravetracks.push_back(GFTrackToTrack(IdGFTrackStateMap[startID], startID) );
83 GFTrackToTrack(trackAndState trackAndState,
int id, std::string tag){
85 if (trackAndState.track_ ==
nullptr) {
86 Exception exc(
"GFTrackToTrack ==> originaltrack is nullptr",__LINE__,__FILE__);
90 if (! trackAndState.track_->getFitStatus()->isFitConverged()) {
91 Exception exc(
"GFTrackToTrack ==> Trackfit is not converged",__LINE__,__FILE__);
98 trackAndState.track_->getFittedState().getPosMomCov(pos, mom, cov);
101 rave::Vector6D ravestate(pos.X(), pos.Y(), pos.Z(),
102 mom.X(), mom.Y(), mom.Z());
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));
117 rave::Track ret(
id, ravestate, ravecov,
118 trackAndState.track_->getFitStatus()->getCharge(),
119 trackAndState.track_->getFitStatus()->getChi2(),
120 trackAndState.track_->getFitStatus()->getNdf(),
121 static_cast<void*
>(
const_cast<Track*
>(trackAndState.track_)), tag);
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()));
141 RaveToGFVertex(
const rave::Vertex & raveVertex,
142 const std::map<int, genfit::trackAndState>& IdGFTrackStateMap){
144 if (!(raveVertex.isValid())) {
145 Exception exc(
"RaveToGFVertex ==> rave Vertex is not valid!",__LINE__,__FILE__);
149 std::vector < std::pair < float, rave::Track > > raveWeightedTracks(raveVertex.weightedTracks());
150 std::vector < std::pair < float, rave::Track > > raveSmoothedTracks(raveVertex.weightedRefittedTracks());
153 unsigned int nTrks(raveWeightedTracks.size());
156 bool smoothing(
true);
157 if (! (raveVertex.hasRefittedTracks()) ) {
162 if (smoothing && nTrks != raveSmoothedTracks.size()){
163 Exception exc(
"RaveToGFVertex ==> number of smoothed tracks != number of tracks",__LINE__,__FILE__);
168 std::vector < GFRaveTrackParameters* > trackParameters;
169 trackParameters.reserve(nTrks);
172 for (
unsigned int i=0; i<nTrks; ++i){
173 id = raveWeightedTracks[i].second.id();
175 if (IdGFTrackStateMap.count(
id) == 0){
176 Exception exc(
"RaveToGFVertex ==> rave track id is not present in IdGFTrackStateMap",__LINE__,__FILE__);
180 GFRaveTrackParameters* trackparams;
184 trackparams =
new GFRaveTrackParameters(IdGFTrackStateMap.at(
id).track_,
185 IdGFTrackStateMap.at(
id).state_,
186 raveWeightedTracks[i].first,
187 Vector6DToTVectorD(raveSmoothedTracks[i].second.state()),
188 Covariance6DToTMatrixDSym(raveSmoothedTracks[i].second.error()),
193 trackparams =
new GFRaveTrackParameters(IdGFTrackStateMap.at(
id).track_,
194 IdGFTrackStateMap.at(
id).state_,
195 raveWeightedTracks[i].first,
196 Vector6DToTVectorD(raveWeightedTracks[i].second.state()),
197 Covariance6DToTMatrixDSym(raveWeightedTracks[i].second.error()),
200 trackParameters.push_back(trackparams);
203 return new GFRaveVertex(Point3DToTVector3(raveVertex.position()),
204 Covariance3DToTMatrixDSym(raveVertex.error()),
206 raveVertex.ndf(), raveVertex.chiSquared(), raveVertex.id());
210 RaveToGFVertices(std::vector<GFRaveVertex*> * GFVertices,
211 const std::vector<rave::Vertex> & raveVertices,
212 const std::map<int, genfit::trackAndState>& IdGFTrackStateMap){
214 unsigned int nVert(raveVertices.size());
216 GFVertices->reserve(nVert);
218 for (
unsigned int i=0; i<nVert; ++i){
219 GFVertices->push_back(RaveToGFVertex(raveVertices[i], IdGFTrackStateMap));
225 PlaneToGFDetPlane(
const ravesurf::Plane& rplane) {
226 return SharedPlanePtr(
new DetPlane(Point3DToTVector3(rplane.position()),
227 Vector3DToTVector3(rplane.normalVector()) ));
233 return TVector3(v.x(), v.y(), v.z());
238 return TVector3(v.x(), v.y(), v.z());
243 Covariance3DToTMatrixDSym(
const rave::Covariance3D& ravecov){
246 cov(0,0) = ravecov.dxx();
247 cov(0,1) = ravecov.dxy();
248 cov(0,2) = ravecov.dxz();
250 cov(1,0) = ravecov.dxy();
251 cov(1,1) = ravecov.dyy();
252 cov(1,2) = ravecov.dyz();
254 cov(2,0) = ravecov.dxz();
255 cov(2,1) = ravecov.dyz();
256 cov(2,2) = ravecov.dzz();
263 Vector6DToTVectorD(
const rave::Vector6D& ravevec){
266 vec[0] = ravevec.x();
267 vec[1] = ravevec.y();
268 vec[2] = ravevec.z();
270 vec[3] = ravevec.px();
271 vec[4] = ravevec.py();
272 vec[5] = ravevec.pz();
279 Covariance6DToTMatrixDSym(
const rave::Covariance6D& ravecov){
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();
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();
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();
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();
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();
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();
329 TVector3ToPoint3D(
const TVector3 & vec){
335 TMatrixDSymToCovariance3D(
const TMatrixDSym & matrix){
336 if (matrix.GetNrows()!=3) {
337 Exception exc(
"TMatrixDSymToCovariance3D ==> TMatrixDSym is not 3x3!",__LINE__,__FILE__);
341 return rave::Covariance3D(matrix(0,0), matrix(0,1), matrix(0,2),
342 matrix(1,1), matrix(1,2), matrix(2,2));
Exception class for error handling in GENFIT (provides storage for diagnostic information)
#StateOnPlane with additional covariance matrix.
HepGeom::Vector3D< double > Vector3D
3D Vector
HepGeom::Point3D< double > Point3D
3D point
Defines for I/O streams used for error and debug printing.
void setData(const rave::Track &orig, MeasuredStateOnPlane *state)
set state and cov of a MeasuredStateOnPlane according to rave track
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
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)
Convert a vector of genfit::Tracks to rave::Tracks also builds a map of unique ids to genfit::Tracks;...