From b21b9e7a256625702acac11197dc3f933ac5fe6f Mon Sep 17 00:00:00 2001 From: fairlyons Date: Tue, 29 Oct 2024 16:36:55 +0100 Subject: [PATCH] Update tracking for new genfit --- CHANGELOG.md | 1 + python/shipDigiReco.py | 35 +++++++++++++++++++++++------------ python/shipStrawTracking.py | 4 +++- python/shipVertex.py | 6 +++--- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7883dca47f..fda9d8a361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ it in future. * shipStrawTracking: Move to argparse * CMake: Use external genfit2 +* shipStrawTracking, shipDigiReco, shipVertex: Make compatible with current genfit ### Removed diff --git a/python/shipDigiReco.py b/python/shipDigiReco.py index e137cbe9c6..a7e1747177 100644 --- a/python/shipDigiReco.py +++ b/python/shipDigiReco.py @@ -931,11 +931,15 @@ def findTracks(self): #check atrack = entry[1] theTrack = entry[0] - if not theTrack.checkConsistency(): - print('Problem with track before fit, not consistent',atrack,theTrack) - continue + try: + theTrack.checkConsistency() + except ROOT.genfit.Exception as e: + print('Problem with track before fit, not consistent',atrack,theTrack) + print(e.what()) + ut.reportError(e) # do the fit - try: self.fitter.processTrack(theTrack) # processTrackWithRep(theTrack,rep,True) + try: + self.fitter.processTrack(theTrack) # processTrackWithRep(theTrack,rep,True) except: if global_variables.debug: print("genfit failed to fit track") @@ -943,12 +947,14 @@ def findTracks(self): ut.reportError(error) continue #check - if not theTrack.checkConsistency(): - if global_variables.debug: - print('Problem with track after fit, not consistent', atrack, theTrack) - error = "Problem with track after fit, not consistent" - ut.reportError(error) - continue + try: + theTrack.checkConsistency() + except ROOT.genfit.Exception as e: + if global_variables.debug: + print('Problem with track after fit, not consistent', atrack, theTrack) + print(e.what()) + error = "Problem with track after fit, not consistent" + ut.reportError(error) try: fittedState = theTrack.getFittedState() fittedMom = fittedState.getMomMag() @@ -956,9 +962,14 @@ def findTracks(self): error = "Problem with fittedstate" ut.reportError(error) continue - fitStatus = theTrack.getFitStatus() + fitStatus = theTrack.getFitStatus() + try: + fitStatus.isFitConverged() + except ROOT.genfit.Exception as e: + error = "Fit not converged" + ut.reportError(error) nmeas = fitStatus.getNdf() - chi2 = fitStatus.getChi2()/nmeas + chi2 = fitStatus.getChi2() / nmeas global_variables.h['chi2'].Fill(chi2) # make track persistent nTrack = self.fGenFitArray.GetEntries() diff --git a/python/shipStrawTracking.py b/python/shipStrawTracking.py index a2b53869ca..5a93cb67fb 100644 --- a/python/shipStrawTracking.py +++ b/python/shipStrawTracking.py @@ -522,8 +522,10 @@ def extrapolateToPlane(fT,z): state = ROOT.genfit.StateOnPlane(rep) pos,mom = fstate.getPos(),fstate.getMom() rep.setPosMom(state,pos,mom) + detPlane = ROOT.genfit.DetPlane(NewPosition, parallelToZ) + detPlanePtr = ROOT.genfit.SharedPlanePtr(detPlane) try: - rep.extrapolateToPlane(state, NewPosition, parallelToZ ) + rep.extrapolateToPlane(state, detPlanePtr) pos,mom = state.getPos(),state.getMom() rc = True except: diff --git a/python/shipVertex.py b/python/shipVertex.py index fd200e92d0..54278bce93 100644 --- a/python/shipVertex.py +++ b/python/shipVertex.py @@ -156,16 +156,16 @@ def TwoTrackVertex(self): #print "*********************************** vertex fit precise ******************************************** " detPlane = ROOT.genfit.DetPlane(ROOT.TVector3(0,0,HNLPos[2]),ROOT.TVector3(1,0,0),ROOT.TVector3(0,1,0)) - plane = ROOT.genfit.RKTrackRep().makePlane(ROOT.TVector3(0,0,HNLPos[2]),ROOT.TVector3(1,0,0),ROOT.TVector3(0,1,0)) + detPlanePtr = ROOT.genfit.SharedPlanePtr(detPlane) st1 = fittedTracks[t1].getFittedState() st2 = fittedTracks[t2].getFittedState() try: - st1.extrapolateToPlane(plane) + st1.extrapolateToPlane(detPlanePtr) except: ut.reportError("shipVertex.TwoTrackVertex: extrapolation did not work") continue try: - st2.extrapolateToPlane(plane) + st2.extrapolateToPlane(detPlanePtr) except: ut.reportError("shipVertex.TwoTrackVertex: extrapolation did not work") continue