From 9a6ed8369bfbc5ec4f1e09772d032d7ff128b503 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Wed, 7 Jun 2023 12:05:04 -0700 Subject: [PATCH 01/18] added two new track collections, AtTarget, and AtECal, and save those tracks with references to original track --- ...2016FullRecon_KF_TrackClusterMatcher.lcsim | 2 +- .../org/hps/recon/tracking/TrackUtils.java | 11 ++++ .../tracking/kalman/KalmanInterface.java | 58 ++++++++++++++++++- .../tracking/kalman/KalmanPatRecDriver.java | 23 +++++++- 4 files changed, 90 insertions(+), 4 deletions(-) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim index ecf143a43b..9fd4cdcfa0 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim @@ -7,7 +7,7 @@ @author Norman Graf --> - + diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index 08ba4f7527..52e6e3a969 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -1732,6 +1732,13 @@ public static org.hps.util.Pair extrapolateTrackUsingFie return RKint.integrate(startPosition, p0Trans, distance); } + public static BaseTrackState getTrackExtrapAtTarget(Track track, double target_pos, FieldMap fm) + { + BaseTrackState bts = extrapolateTrackUsingFieldMap(TrackStateUtils.getTrackStateAtIP(track),BeamlineConstants.DIPOLE_EDGE_ENG_RUN, target_pos, 0, fm); + bts.setLocation(TrackState.LastLocation); + return bts; + } + public static BaseTrackState extrapolateTrackUsingFieldMap(TrackState track, double startPositionX, double endPosition, double stepSize, double epsilon, FieldMap fieldMap) { // Start by extrapolating the track to the approximate point where the // fringe field begins. @@ -1869,6 +1876,10 @@ public static TrackState getTrackStateAtLocation(Track trk, int location) { return null; } + public static TrackState getTrackStateAtTarget(Track trk){ + return getTrackStateAtLocation(trk, TrackState.LastLocation); + } + public static TrackState getTrackStateAtECal(Track trk) { return getTrackStateAtLocation(trk, TrackState.AtCalorimeter); } diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java index 2cb675c58c..8d41cd1087 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java @@ -520,6 +520,59 @@ public List createGBLStripClusterData(KalTrack kT) { public PropagatedTrackState propagateTrackState(TrackState stateHPS, double [] location, double [] direction) { return new PropagatedTrackState(stateHPS, location, direction, detPlanes, fM); } + + public BaseTrack createTrackAtTarget(KalTrack kT, Track track) { + if (kT.SiteList == null) { + logger.log(Level.WARNING, "KalmanInterface.createTrack: Kalman track is incomplete."); + return null; + } + if (kT.covNaN()) { + logger.log(Level.FINE, "KalmanInterface.createTrack: Kalman track has NaN cov matrix."); + return null; + } + kT.sortSites(true); + Vec Bfield = KalmanInterface.getField(new Vec(0., SVTcenter ,0.), kT.SiteList.get(0).m.Bfield); + double B = Bfield.mag(); + + BaseTrack trackAtTarget = new BaseTrack(); + TrackState tsAtTarget = TrackUtils.getTrackStateAtTarget(track); + if (tsAtTarget == null){ + logger.log(Level.WARNING, "KalmanInterface.createTrackAtTarget: No track state at Target exists."); + return null; + } + trackAtTarget.setTrackParameters(tsAtTarget.getParameters(), B); + trackAtTarget.setReferencePoint(tsAtTarget.getReferencePoint()); + trackAtTarget.setCovarianceMatrix(new SymmetricMatrix(5, tsAtTarget.getCovMatrix(), true)); + trackAtTarget.setTrackType(BaseTrack.TrackType.Y_FIELD.ordinal()); + return trackAtTarget; + } + + // Create a Track at ECal using existing Track State at ECal + public BaseTrack createTrackAtECal(KalTrack kT, Track track) { + if (kT.SiteList == null) { + logger.log(Level.WARNING, "KalmanInterface.createTrack: Kalman track is incomplete."); + return null; + } + if (kT.covNaN()) { + logger.log(Level.FINE, "KalmanInterface.createTrack: Kalman track has NaN cov matrix."); + return null; + } + kT.sortSites(true); + Vec Bfield = KalmanInterface.getField(new Vec(0., SVTcenter ,0.), kT.SiteList.get(0).m.Bfield); + double B = Bfield.mag(); + + BaseTrack trackAtECal = new BaseTrack(); + TrackState tsAtECal = TrackUtils.getTrackStateAtECal(track); + if (tsAtECal == null){ + logger.log(Level.WARNING, "KalmanInterface.createTrackAtECal: No track state at ECal exists."); + return null; + } + trackAtECal.setTrackParameters(tsAtECal.getParameters(), B); + trackAtECal.setReferencePoint(tsAtECal.getReferencePoint()); + trackAtECal.setCovarianceMatrix(new SymmetricMatrix(5, tsAtECal.getCovMatrix(), true)); + trackAtECal.setTrackType(BaseTrack.TrackType.Y_FIELD.ordinal()); + return trackAtECal; + } // Create an HPS track from a Kalman track public BaseTrack createTrack(KalTrack kT, boolean storeTrackStates) { @@ -596,9 +649,12 @@ public BaseTrack createTrack(KalTrack kT, boolean storeTrackStates) { } // Extrapolate to the ECAL and make a new trackState there. - BaseTrackState ts_ecal = TrackUtils.getTrackExtrapAtEcalRK(newTrack, fM, runNumber); newTrack.getTrackStates().add(ts_ecal); + + // Extrapolate to Target and make a new trackState there. + BaseTrackState ts_target = TrackUtils.getTrackExtrapAtTarget(newTrack, -4.3, fM); + newTrack.getTrackStates().add(ts_target); // other track properties newTrack.setChisq(kT.chi2); diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index 5000cdd133..17b0740414 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -283,6 +283,10 @@ public void process(EventHeader event) { KI.setRunNumber(runNumber); List outputFullTracks = new ArrayList(); + List outputTracksAtECal = new ArrayList(); + List tracksAtECalRelations = new ArrayList(); + List outputTracksAtTarget = new ArrayList(); + List tracksAtTargetRelations = new ArrayList(); //For additional track information List trackDataCollection = new ArrayList(); @@ -296,10 +300,14 @@ public void process(EventHeader event) { List trackResiduals = new ArrayList(); List trackResidualsRelations = new ArrayList(); - ArrayList[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations); + ArrayList[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations, outputTracksAtECal, tracksAtECalRelations, outputTracksAtTarget, tracksAtTargetRelations); int flag = 1 << LCIOConstants.TRBIT_HITS; event.put(outputFullTrackCollectionName, outputFullTracks, Track.class, flag); + event.put(outputFullTrackCollectionName+"AtECal", outputTracksAtECal, Track.class, flag); + event.put(outputFullTrackCollectionName+"AtECalRelations", tracksAtECalRelations, LCRelation.class,0); + event.put(outputFullTrackCollectionName+"AtTarget", outputTracksAtTarget, Track.class, flag); + event.put(outputFullTrackCollectionName+"AtTargetRelations", tracksAtTargetRelations, LCRelation.class,0); event.put("KFGBLStripClusterData", allClstrs, GBLStripClusterData.class, flag); event.put("KFGBLStripClusterDataRelations", gblStripClusterDataRelations, LCRelation.class, flag); event.put("KFTrackData",trackDataCollection, TrackData.class,0); @@ -339,7 +347,7 @@ public int compare(TrackerHit o1, TrackerHit o2) { } } - private ArrayList[] prepareTrackCollections(EventHeader event, List outputFullTracks, List trackDataCollection, List trackDataRelations, List allClstrs, List gblStripClusterDataRelations, List trackResiduals, List trackResidualsRelations) { + private ArrayList[] prepareTrackCollections(EventHeader event, List outputFullTracks, List trackDataCollection, List trackDataRelations, List allClstrs, List gblStripClusterDataRelations, List trackResiduals, List trackResidualsRelations, List outputTracksAtECal, List tracksAtECalRelations, List outputTracksAtTarget, List tracksAtTargetRelations) { int evtNumb = event.getEventNumber(); String stripHitInputCollectionName = "StripClusterer_SiTrackerHitStrip1D"; @@ -398,6 +406,17 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List clstrs = KI.createGBLStripClusterData(kTk); if (verbose) { for (GBLStripClusterData clstr : clstrs) { From 83d79f23c365631016dbdaebac0a4bf6103e4670 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Thu, 8 Jun 2023 13:44:28 -0700 Subject: [PATCH 02/18] added track ecal and target positions to track data. add new trackAtTarget tracks, save tracks with relations to AtIP tracks. To turn on tracks at target, must pass target position in steering-file under KalmanPatRecDriver --- .../org/hps/recon/tracking/TrackData.java | 49 ++++++++++++++++ .../org/hps/recon/tracking/TrackUtils.java | 58 ++++++++++++++++--- .../tracking/kalman/KalmanInterface.java | 42 ++++---------- .../tracking/kalman/KalmanPatRecDriver.java | 49 +++++++++++----- 4 files changed, 147 insertions(+), 51 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackData.java b/tracking/src/main/java/org/hps/recon/tracking/TrackData.java index 14ae440a52..83dc3cb9e9 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackData.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackData.java @@ -24,6 +24,13 @@ public class TrackData implements GenericObject { public static final int PY_INDEX = 2; public static final int PZ_INDEX = 3; public static final int TRACK_VOLUME_INDEX = 0; + public static final int TRACK_AT_ECAL_X_INDEX = 5; //Tracking coords + public static final int TRACK_AT_ECAL_Y_INDEX = 6; //Tracking coords + public static final int TRACK_AT_ECAL_Z_INDEX = 7; //Tracking coords + public static final int TRACK_AT_TARGET_X_INDEX = 8;//Tracking coords + public static final int TRACK_AT_TARGET_Y_INDEX = 9;//Tracking coords + public static final int TRACK_AT_TARGET_Z_INDEX = 10;//Tracking coords + public static final int TRACK_AT_TARGET_Z0_INDEX = 11;//Tracking coords public static final String TRACK_DATA_COLLECTION = "TrackData"; public static final String TRACK_DATA_RELATION_COLLECTION = "TrackDataRelations"; @@ -66,6 +73,27 @@ public TrackData(int trackVolume, float trackTime, double[] isolations) { this.ints = new int[]{trackVolume}; } + /** + * Constructor + * + * @param trackVolume : SVT volume associated with the track + * @param trackTime : The track time + * @param isolations : an array of doubles containing isolations for every + * sensor layer + * @param momentum : an array of floats containing track momentum in the form (px,py,pz) + * @param trackEcalPos : an array of floats containing track (x,y,z) at ECal *in + * tracking coords + * @param trackTargPos: an array of floats containing track (x,y,z) at + * Target *in tracking coords + * @param trackTargz0: a float containing z0 for track at target + */ + public TrackData(int trackVolume, float trackTime, double[] isolations, float[] momentum, float[] trackEcalPos, float[] trackTargPos, float trackTargZ0) { + + this.doubles = isolations; + this.floats = new float[]{trackTime,momentum[0],momentum[1],momentum[2],trackEcalPos[0],trackEcalPos[1],trackEcalPos[2],trackTargPos[0],trackTargPos[1],trackTargPos[2],trackTargZ0}; + this.ints = new int[]{trackVolume}; + } + /** * Constructor * @@ -108,6 +136,27 @@ public void setTrackMomentum(float[] momentum) { floats[PZ_INDEX] = momentum[2]; } + /** + * @return track position at Ecal in tracking coords + */ + public float[] getTrackAtEcalPosition(){ + return new float[]{floats[TRACK_AT_ECAL_X_INDEX],floats[TRACK_AT_ECAL_Y_INDEX],floats[TRACK_AT_ECAL_Z_INDEX]}; + } + + /** + * @return track position at target in tracking coords + */ + public float[] getTrackAtTargetPosition(){ + return new float[]{floats[TRACK_AT_TARGET_X_INDEX],floats[TRACK_AT_TARGET_Y_INDEX],floats[TRACK_AT_TARGET_Z_INDEX]}; + } + + /** + * @return z0 of track at target + */ + public float getTrackAtTargetZ0(){ + return floats[TRACK_AT_TARGET_Z0_INDEX]; + } + /** * @return The track time */ diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index 52e6e3a969..4c9d50e2d6 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -755,6 +755,57 @@ public static BaseTrackState getTrackExtrapAtHodoRK(Track trk, FieldMap fM, int return getTrackExtrapAtHodoRK(trk, fM, 0, hodoLayer); } + public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target_z, FieldMap fM, double stepSize) { + + TrackState ts = TrackStateUtils.getTrackStateAtFirst(track); + + //if track passed to extrapolateHelixToXPlane, uses first track state + //by default, else if trackstate is passed, uses trackstate params. + //Forms HTF, projects to location, then returns point on helix + Hep3Vector startPos = extrapolateHelixToXPlane(ts, 0.0); + Hep3Vector startPosTrans = CoordinateTransformations.transformVectorToDetector(startPos); + double distanceZ = target_z; + double charge = -1.0 * Math.signum(getR(ts)); + + //extrapolateTrackUsingFieldMapRK gets HTF of input track/trackstate + //if track is passed, defaults to first track state + //if trackstate is passed, uses trackstate params + org.hps.util.Pair RKresults = extrapolateTrackUsingFieldMapRK(ts, startPosTrans, distanceZ, stepSize, fM); + double bFieldY = fM.getField(RKresults.getFirstElement()).y(); + Hep3Vector posTrans = CoordinateTransformations.transformVectorToTracking(RKresults.getFirstElement()); + Hep3Vector momTrans = CoordinateTransformations.transformVectorToTracking(RKresults.getSecondElement()); + + Hep3Vector finalPos = posTrans; + if (RKresults.getFirstElement().z() != target_z) { + Hep3Vector mom = RKresults.getSecondElement(); + double dz = target_z - RKresults.getFirstElement().z(); + double dy = dz * mom.y() / mom.z(); + double dx = dz * mom.x() / mom.z(); + Hep3Vector dPos = new BasicHep3Vector(dx, dy, dz); + finalPos = CoordinateTransformations.transformVectorToTracking(VecOp.add(dPos, RKresults.getFirstElement())); + } + bFieldY = fM.getField(CoordinateTransformations.transformVectorToDetector(finalPos)).y(); + //params are calculated with respect to ref = {trackX, trackY, z=0) + double[] params = getParametersFromPointAndMomentum(finalPos, momTrans, (int) charge, bFieldY); + BaseTrackState bts = new BaseTrackState(params, bFieldY); + //reference point is set to track position in X Y Z + bts.setReferencePoint(finalPos.v()); + //Consider shifting reference point to (trackX, 0, 0)...otherwise d0=0 + boolean case2 = false; + if (case2){ + double [] paramsRefPoint = {finalPos.x(), finalPos.y(), 0.0}; + bts.setReferencePoint(paramsRefPoint); + double[] newRef = {-4.3, 0.0, 0.0}; + params = getParametersAtNewRefPoint(newRef, bts); + bts.setParameters(params, bFieldY); + //Again, persisted reference point is track position in XYZ, not + //ref point used to calculate track params (which is newRef) + bts.setReferencePoint(finalPos.v()); + } + bts.setLocation(TrackState.LastLocation); + return bts; + } + /** * Extrapolate track to given position. For backwards compatibility. * @@ -1732,13 +1783,6 @@ public static org.hps.util.Pair extrapolateTrackUsingFie return RKint.integrate(startPosition, p0Trans, distance); } - public static BaseTrackState getTrackExtrapAtTarget(Track track, double target_pos, FieldMap fm) - { - BaseTrackState bts = extrapolateTrackUsingFieldMap(TrackStateUtils.getTrackStateAtIP(track),BeamlineConstants.DIPOLE_EDGE_ENG_RUN, target_pos, 0, fm); - bts.setLocation(TrackState.LastLocation); - return bts; - } - public static BaseTrackState extrapolateTrackUsingFieldMap(TrackState track, double startPositionX, double endPosition, double stepSize, double epsilon, FieldMap fieldMap) { // Start by extrapolating the track to the approximate point where the // fringe field begins. diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java index 8d41cd1087..47ddadbd87 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java @@ -79,6 +79,7 @@ public class KalmanInterface { private int maxHits; private int nBigEvents; private int eventNumber; + private static double target_pos = -999.9; private static final boolean debug = false; private static final double SVTcenter = 505.57; @@ -97,6 +98,10 @@ public void setSiHitsLimit(int limit) { public int getSiHitsLimit() { return _siHitsLimit; } + + public void setTargetPosition(double target_pos){ + this.target_pos = target_pos; + } // Get the HPS tracker hit corresponding to a Kalman hit public TrackerHit getHpsHit(Measurement km) { @@ -547,33 +552,6 @@ public BaseTrack createTrackAtTarget(KalTrack kT, Track track) { return trackAtTarget; } - // Create a Track at ECal using existing Track State at ECal - public BaseTrack createTrackAtECal(KalTrack kT, Track track) { - if (kT.SiteList == null) { - logger.log(Level.WARNING, "KalmanInterface.createTrack: Kalman track is incomplete."); - return null; - } - if (kT.covNaN()) { - logger.log(Level.FINE, "KalmanInterface.createTrack: Kalman track has NaN cov matrix."); - return null; - } - kT.sortSites(true); - Vec Bfield = KalmanInterface.getField(new Vec(0., SVTcenter ,0.), kT.SiteList.get(0).m.Bfield); - double B = Bfield.mag(); - - BaseTrack trackAtECal = new BaseTrack(); - TrackState tsAtECal = TrackUtils.getTrackStateAtECal(track); - if (tsAtECal == null){ - logger.log(Level.WARNING, "KalmanInterface.createTrackAtECal: No track state at ECal exists."); - return null; - } - trackAtECal.setTrackParameters(tsAtECal.getParameters(), B); - trackAtECal.setReferencePoint(tsAtECal.getReferencePoint()); - trackAtECal.setCovarianceMatrix(new SymmetricMatrix(5, tsAtECal.getCovMatrix(), true)); - trackAtECal.setTrackType(BaseTrack.TrackType.Y_FIELD.ordinal()); - return trackAtECal; - } - // Create an HPS track from a Kalman track public BaseTrack createTrack(KalTrack kT, boolean storeTrackStates) { if (kT.SiteList == null) { @@ -649,12 +627,16 @@ public BaseTrack createTrack(KalTrack kT, boolean storeTrackStates) { } // Extrapolate to the ECAL and make a new trackState there. - BaseTrackState ts_ecal = TrackUtils.getTrackExtrapAtEcalRK(newTrack, fM, runNumber); + BaseTrackState ts_ecal = new BaseTrackState(); + ts_ecal = TrackUtils.getTrackExtrapAtEcalRK(newTrack, fM, runNumber); newTrack.getTrackStates().add(ts_ecal); // Extrapolate to Target and make a new trackState there. - BaseTrackState ts_target = TrackUtils.getTrackExtrapAtTarget(newTrack, -4.3, fM); - newTrack.getTrackStates().add(ts_target); + BaseTrackState ts_target = new BaseTrackState(); + if (target_pos != -999.9){ + ts_target = TrackUtils.getTrackExtrapAtTargetRK(newTrack, target_pos, fM, 0); + newTrack.getTrackStates().add(ts_target); + } // other track properties newTrack.setChisq(kT.chi2); diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index 17b0740414..257a01d392 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -16,6 +16,7 @@ import org.hps.recon.tracking.MaterialSupervisor; import org.hps.recon.tracking.TrackData; import org.hps.recon.tracking.TrackResidualsData; +import org.hps.recon.tracking.TrackUtils; import org.hps.recon.tracking.MaterialSupervisor.ScatteringDetectorVolume; import org.hps.recon.tracking.MaterialSupervisor.SiStripPlane; import org.hps.recon.tracking.gbl.GBLStripClusterData; @@ -56,6 +57,7 @@ public class KalmanPatRecDriver extends Driver { private KalmanParams kPar; private KalmanPatRecPlots kPlot; private static Logger logger; + private static double target_pos = -999.9; // Parameters for the Kalman pattern recognition that can be set by the user in the steering file: private ArrayList strategies; // List of seed strategies for both top and bottom trackers, from steering @@ -130,6 +132,10 @@ public void setSiHitsLimit(int input) { public void setAddResiduals(boolean input) { addResiduals = input; } + + public void setTargetPosition(double target_pos){ + this.target_pos = target_pos; + } @Override public void detectorChanged(Detector det) { @@ -268,6 +274,9 @@ public void detectorChanged(Detector det) { kPar.print(); KI = new KalmanInterface(uniformB, kPar, fm); + if (target_pos != -999.9) { + KI.setTargetPosition(target_pos); + } KI.setSiHitsLimit(siHitsLimit); KI.createSiModules(detPlanes); decoder = det.getSubdetector("Tracker").getIDDecoder(); @@ -283,8 +292,6 @@ public void process(EventHeader event) { KI.setRunNumber(runNumber); List outputFullTracks = new ArrayList(); - List outputTracksAtECal = new ArrayList(); - List tracksAtECalRelations = new ArrayList(); List outputTracksAtTarget = new ArrayList(); List tracksAtTargetRelations = new ArrayList(); @@ -300,12 +307,10 @@ public void process(EventHeader event) { List trackResiduals = new ArrayList(); List trackResidualsRelations = new ArrayList(); - ArrayList[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations, outputTracksAtECal, tracksAtECalRelations, outputTracksAtTarget, tracksAtTargetRelations); + ArrayList[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations, outputTracksAtTarget, tracksAtTargetRelations); int flag = 1 << LCIOConstants.TRBIT_HITS; event.put(outputFullTrackCollectionName, outputFullTracks, Track.class, flag); - event.put(outputFullTrackCollectionName+"AtECal", outputTracksAtECal, Track.class, flag); - event.put(outputFullTrackCollectionName+"AtECalRelations", tracksAtECalRelations, LCRelation.class,0); event.put(outputFullTrackCollectionName+"AtTarget", outputTracksAtTarget, Track.class, flag); event.put(outputFullTrackCollectionName+"AtTargetRelations", tracksAtTargetRelations, LCRelation.class,0); event.put("KFGBLStripClusterData", allClstrs, GBLStripClusterData.class, flag); @@ -347,7 +352,7 @@ public int compare(TrackerHit o1, TrackerHit o2) { } } - private ArrayList[] prepareTrackCollections(EventHeader event, List outputFullTracks, List trackDataCollection, List trackDataRelations, List allClstrs, List gblStripClusterDataRelations, List trackResiduals, List trackResidualsRelations, List outputTracksAtECal, List tracksAtECalRelations, List outputTracksAtTarget, List tracksAtTargetRelations) { + private ArrayList[] prepareTrackCollections(EventHeader event, List outputFullTracks, List trackDataCollection, List trackDataRelations, List allClstrs, List gblStripClusterDataRelations, List trackResiduals, List trackResidualsRelations, List outputTracksAtTarget, List tracksAtTargetRelations) { int evtNumb = event.getEventNumber(); String stripHitInputCollectionName = "StripClusterer_SiTrackerHitStrip1D"; @@ -407,15 +412,12 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List clstrs = KI.createGBLStripClusterData(kTk); if (verbose) { @@ -450,9 +452,28 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List Date: Thu, 8 Jun 2023 13:47:05 -0700 Subject: [PATCH 03/18] default no precleanup --- .../recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim index 9fd4cdcfa0..4f6705f461 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim @@ -7,7 +7,7 @@ @author Norman Graf --> - + @@ -126,6 +126,7 @@ 40 false + -4.3 From 29b3f6bb832fcc7d05e099492104bb48f9c21f5b Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Thu, 8 Jun 2023 15:47:58 -0700 Subject: [PATCH 04/18] undid unecessary replication of track collection --- .../org/hps/recon/tracking/TrackData.java | 49 ------------------- .../tracking/kalman/KalmanInterface.java | 26 ---------- .../tracking/kalman/KalmanPatRecDriver.java | 37 ++------------ 3 files changed, 3 insertions(+), 109 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackData.java b/tracking/src/main/java/org/hps/recon/tracking/TrackData.java index 83dc3cb9e9..14ae440a52 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackData.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackData.java @@ -24,13 +24,6 @@ public class TrackData implements GenericObject { public static final int PY_INDEX = 2; public static final int PZ_INDEX = 3; public static final int TRACK_VOLUME_INDEX = 0; - public static final int TRACK_AT_ECAL_X_INDEX = 5; //Tracking coords - public static final int TRACK_AT_ECAL_Y_INDEX = 6; //Tracking coords - public static final int TRACK_AT_ECAL_Z_INDEX = 7; //Tracking coords - public static final int TRACK_AT_TARGET_X_INDEX = 8;//Tracking coords - public static final int TRACK_AT_TARGET_Y_INDEX = 9;//Tracking coords - public static final int TRACK_AT_TARGET_Z_INDEX = 10;//Tracking coords - public static final int TRACK_AT_TARGET_Z0_INDEX = 11;//Tracking coords public static final String TRACK_DATA_COLLECTION = "TrackData"; public static final String TRACK_DATA_RELATION_COLLECTION = "TrackDataRelations"; @@ -73,27 +66,6 @@ public TrackData(int trackVolume, float trackTime, double[] isolations) { this.ints = new int[]{trackVolume}; } - /** - * Constructor - * - * @param trackVolume : SVT volume associated with the track - * @param trackTime : The track time - * @param isolations : an array of doubles containing isolations for every - * sensor layer - * @param momentum : an array of floats containing track momentum in the form (px,py,pz) - * @param trackEcalPos : an array of floats containing track (x,y,z) at ECal *in - * tracking coords - * @param trackTargPos: an array of floats containing track (x,y,z) at - * Target *in tracking coords - * @param trackTargz0: a float containing z0 for track at target - */ - public TrackData(int trackVolume, float trackTime, double[] isolations, float[] momentum, float[] trackEcalPos, float[] trackTargPos, float trackTargZ0) { - - this.doubles = isolations; - this.floats = new float[]{trackTime,momentum[0],momentum[1],momentum[2],trackEcalPos[0],trackEcalPos[1],trackEcalPos[2],trackTargPos[0],trackTargPos[1],trackTargPos[2],trackTargZ0}; - this.ints = new int[]{trackVolume}; - } - /** * Constructor * @@ -136,27 +108,6 @@ public void setTrackMomentum(float[] momentum) { floats[PZ_INDEX] = momentum[2]; } - /** - * @return track position at Ecal in tracking coords - */ - public float[] getTrackAtEcalPosition(){ - return new float[]{floats[TRACK_AT_ECAL_X_INDEX],floats[TRACK_AT_ECAL_Y_INDEX],floats[TRACK_AT_ECAL_Z_INDEX]}; - } - - /** - * @return track position at target in tracking coords - */ - public float[] getTrackAtTargetPosition(){ - return new float[]{floats[TRACK_AT_TARGET_X_INDEX],floats[TRACK_AT_TARGET_Y_INDEX],floats[TRACK_AT_TARGET_Z_INDEX]}; - } - - /** - * @return z0 of track at target - */ - public float getTrackAtTargetZ0(){ - return floats[TRACK_AT_TARGET_Z0_INDEX]; - } - /** * @return The track time */ diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java index 47ddadbd87..aa3a68d988 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java @@ -526,32 +526,6 @@ public PropagatedTrackState propagateTrackState(TrackState stateHPS, double [] l return new PropagatedTrackState(stateHPS, location, direction, detPlanes, fM); } - public BaseTrack createTrackAtTarget(KalTrack kT, Track track) { - if (kT.SiteList == null) { - logger.log(Level.WARNING, "KalmanInterface.createTrack: Kalman track is incomplete."); - return null; - } - if (kT.covNaN()) { - logger.log(Level.FINE, "KalmanInterface.createTrack: Kalman track has NaN cov matrix."); - return null; - } - kT.sortSites(true); - Vec Bfield = KalmanInterface.getField(new Vec(0., SVTcenter ,0.), kT.SiteList.get(0).m.Bfield); - double B = Bfield.mag(); - - BaseTrack trackAtTarget = new BaseTrack(); - TrackState tsAtTarget = TrackUtils.getTrackStateAtTarget(track); - if (tsAtTarget == null){ - logger.log(Level.WARNING, "KalmanInterface.createTrackAtTarget: No track state at Target exists."); - return null; - } - trackAtTarget.setTrackParameters(tsAtTarget.getParameters(), B); - trackAtTarget.setReferencePoint(tsAtTarget.getReferencePoint()); - trackAtTarget.setCovarianceMatrix(new SymmetricMatrix(5, tsAtTarget.getCovMatrix(), true)); - trackAtTarget.setTrackType(BaseTrack.TrackType.Y_FIELD.ordinal()); - return trackAtTarget; - } - // Create an HPS track from a Kalman track public BaseTrack createTrack(KalTrack kT, boolean storeTrackStates) { if (kT.SiteList == null) { diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index 257a01d392..f9c19d7d7b 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -16,7 +16,6 @@ import org.hps.recon.tracking.MaterialSupervisor; import org.hps.recon.tracking.TrackData; import org.hps.recon.tracking.TrackResidualsData; -import org.hps.recon.tracking.TrackUtils; import org.hps.recon.tracking.MaterialSupervisor.ScatteringDetectorVolume; import org.hps.recon.tracking.MaterialSupervisor.SiStripPlane; import org.hps.recon.tracking.gbl.GBLStripClusterData; @@ -292,8 +291,6 @@ public void process(EventHeader event) { KI.setRunNumber(runNumber); List outputFullTracks = new ArrayList(); - List outputTracksAtTarget = new ArrayList(); - List tracksAtTargetRelations = new ArrayList(); //For additional track information List trackDataCollection = new ArrayList(); @@ -307,12 +304,10 @@ public void process(EventHeader event) { List trackResiduals = new ArrayList(); List trackResidualsRelations = new ArrayList(); - ArrayList[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations, outputTracksAtTarget, tracksAtTargetRelations); + ArrayList[] kPatList = prepareTrackCollections(event, outputFullTracks, trackDataCollection, trackDataRelations, allClstrs, gblStripClusterDataRelations, trackResiduals, trackResidualsRelations); int flag = 1 << LCIOConstants.TRBIT_HITS; event.put(outputFullTrackCollectionName, outputFullTracks, Track.class, flag); - event.put(outputFullTrackCollectionName+"AtTarget", outputTracksAtTarget, Track.class, flag); - event.put(outputFullTrackCollectionName+"AtTargetRelations", tracksAtTargetRelations, LCRelation.class,0); event.put("KFGBLStripClusterData", allClstrs, GBLStripClusterData.class, flag); event.put("KFGBLStripClusterDataRelations", gblStripClusterDataRelations, LCRelation.class, flag); event.put("KFTrackData",trackDataCollection, TrackData.class,0); @@ -352,7 +347,7 @@ public int compare(TrackerHit o1, TrackerHit o2) { } } - private ArrayList[] prepareTrackCollections(EventHeader event, List outputFullTracks, List trackDataCollection, List trackDataRelations, List allClstrs, List gblStripClusterDataRelations, List trackResiduals, List trackResidualsRelations, List outputTracksAtTarget, List tracksAtTargetRelations) { + private ArrayList[] prepareTrackCollections(EventHeader event, List outputFullTracks, List trackDataCollection, List trackDataRelations, List allClstrs, List gblStripClusterDataRelations, List trackResiduals, List trackResidualsRelations) { int evtNumb = event.getEventNumber(); String stripHitInputCollectionName = "StripClusterer_SiTrackerHitStrip1D"; @@ -412,13 +407,6 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List clstrs = KI.createGBLStripClusterData(kTk); if (verbose) { for (GBLStripClusterData clstr : clstrs) { @@ -453,27 +441,8 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List Date: Thu, 8 Jun 2023 16:04:17 -0700 Subject: [PATCH 05/18] fix space --- .../recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim index 4f6705f461..3cb4e42896 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim @@ -7,7 +7,7 @@ @author Norman Graf --> - + From 74cdf2b847257d2efc49abed22b3a546d5a53cf6 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Thu, 8 Jun 2023 16:05:18 -0700 Subject: [PATCH 06/18] removed steering config --- .../recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim | 1 - 1 file changed, 1 deletion(-) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim index 3cb4e42896..ecf143a43b 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim @@ -126,7 +126,6 @@ 40 false - -4.3 From dd445d99d9ff4ac8d9413adaf88caaa522d010e1 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Fri, 9 Jun 2023 08:06:12 -0700 Subject: [PATCH 07/18] fixed hard-code target_pos --- tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index 4c9d50e2d6..8665c9d053 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -790,12 +790,12 @@ public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target BaseTrackState bts = new BaseTrackState(params, bFieldY); //reference point is set to track position in X Y Z bts.setReferencePoint(finalPos.v()); - //Consider shifting reference point to (trackX, 0, 0)...otherwise d0=0 + //Consider shifting params reference point to (trackX, 0, 0)...otherwise d0=0 boolean case2 = false; if (case2){ double [] paramsRefPoint = {finalPos.x(), finalPos.y(), 0.0}; bts.setReferencePoint(paramsRefPoint); - double[] newRef = {-4.3, 0.0, 0.0}; + double[] newRef = {target_z, 0.0, 0.0}; params = getParametersAtNewRefPoint(newRef, bts); bts.setParameters(params, bFieldY); //Again, persisted reference point is track position in XYZ, not From 0a872045d53f287ea5fd5d56f8fb44c2a085dfdd Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Fri, 9 Jun 2023 08:15:37 -0700 Subject: [PATCH 08/18] add line to steering-file that turns on track state at target, but comment out so that by default, no track state at target is created unless user specifies target position --- .../recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim | 1 + 1 file changed, 1 insertion(+) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim index ecf143a43b..470d088611 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim @@ -126,6 +126,7 @@ 40 false + From 48f2bcc28a51f36b6a23886aab9e4ecb3db81e1d Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Wed, 14 Jun 2023 09:42:24 -0700 Subject: [PATCH 09/18] changed trackstate at target param reference to use run dependent beamspot positions from db --- .../org/hps/recon/tracking/TrackUtils.java | 24 ++++++++----------- .../tracking/kalman/KalmanInterface.java | 11 +++++++-- .../tracking/kalman/KalmanPatRecDriver.java | 11 +++++++++ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index 8665c9d053..f2a04f3819 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -755,9 +755,9 @@ public static BaseTrackState getTrackExtrapAtHodoRK(Track trk, FieldMap fM, int return getTrackExtrapAtHodoRK(trk, fM, 0, hodoLayer); } - public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target_z, FieldMap fM, double stepSize) { + public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target_z, double[] beamPosition, FieldMap fM, double stepSize) { - TrackState ts = TrackStateUtils.getTrackStateAtFirst(track); + TrackState ts = track.getTrackStates().at(0); //if track passed to extrapolateHelixToXPlane, uses first track state //by default, else if trackstate is passed, uses trackstate params. @@ -790,18 +790,14 @@ public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target BaseTrackState bts = new BaseTrackState(params, bFieldY); //reference point is set to track position in X Y Z bts.setReferencePoint(finalPos.v()); - //Consider shifting params reference point to (trackX, 0, 0)...otherwise d0=0 - boolean case2 = false; - if (case2){ - double [] paramsRefPoint = {finalPos.x(), finalPos.y(), 0.0}; - bts.setReferencePoint(paramsRefPoint); - double[] newRef = {target_z, 0.0, 0.0}; - params = getParametersAtNewRefPoint(newRef, bts); - bts.setParameters(params, bFieldY); - //Again, persisted reference point is track position in XYZ, not - //ref point used to calculate track params (which is newRef) - bts.setReferencePoint(finalPos.v()); - } + //Define new reference point, to which track parameters are calc wrt + double[] newRef = {target_z, beamPosition[1], beamPosition[2]}; + params = getParametersAtNewRefPoint(newRef, bts); + bts.setParameters(params, bFieldY); + //Reference point records final position of track. + //This does not hold the reference point to which the track params are + //calculated from + bts.setReferencePoint(finalPos.v()); bts.setLocation(TrackState.LastLocation); return bts; } diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java index aa3a68d988..6f0e0d8200 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java @@ -80,6 +80,7 @@ public class KalmanInterface { private int nBigEvents; private int eventNumber; private static double target_pos = -999.9; + private double[] beamPosition = null; private static final boolean debug = false; private static final double SVTcenter = 505.57; @@ -102,6 +103,10 @@ public int getSiHitsLimit() { public void setTargetPosition(double target_pos){ this.target_pos = target_pos; } + + public void setBeamPosition(double[] beamPosition){ + this.beamPosition = beamPosition; + } // Get the HPS tracker hit corresponding to a Kalman hit public TrackerHit getHpsHit(Measurement km) { @@ -608,8 +613,10 @@ public BaseTrack createTrack(KalTrack kT, boolean storeTrackStates) { // Extrapolate to Target and make a new trackState there. BaseTrackState ts_target = new BaseTrackState(); if (target_pos != -999.9){ - ts_target = TrackUtils.getTrackExtrapAtTargetRK(newTrack, target_pos, fM, 0); - newTrack.getTrackStates().add(ts_target); + ts_target = TrackUtils.getTrackExtrapAtTargetRK(newTrack, target_pos, beamPosition, fM, 0); + if (ts_target != null){ + newTrack.getTrackStates().add(ts_target); + } } // other track properties diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index f9c19d7d7b..a554dfb872 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -253,6 +253,9 @@ public void detectorChanged(Detector det) { // Setup optional usage of beam positions from database. final DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance(); + double[] beamPositionArr = {beamPositionX, beamPositionY, beamPositionZ}; + System.out.println("useBPC: "+useBeamPositionConditions); + System.out.println("mgr: "+mgr.hasConditionsRecord("beam_positions")); if (useBeamPositionConditions && mgr.hasConditionsRecord("beam_positions")) { logger.config("Using Kalman beam position from the conditions database"); BeamPositionCollection beamPositions = @@ -262,6 +265,13 @@ public void detectorChanged(Detector det) { else logger.config("Using fixed Kalman beam Z position: " + kPar.beamSpot[1]); kPar.setBeamSpotX(beamPositionCond.getPositionX()); // Includes a transformation to Kalman coordinates kPar.setBeamSpotZ(-beamPositionCond.getPositionY()); + beamPositionArr[0] = beamPositionCond.getPositionX(); + beamPositionArr[1] = beamPositionCond.getPositionY(); + beamPositionArr[2] = beamPositionCond.getPositionZ(); + System.out.println("beamPosition[0]: "+beamPositionArr[0]); + System.out.println("beamPosition[1]: "+beamPositionArr[1]); + System.out.println("beamPosition[2]: "+beamPositionArr[2]); + } else { logger.config("Using Kalman beam position from the steering file or default"); } @@ -273,6 +283,7 @@ public void detectorChanged(Detector det) { kPar.print(); KI = new KalmanInterface(uniformB, kPar, fm); + KI.setBeamPosition(beamPositionArr); if (target_pos != -999.9) { KI.setTargetPosition(target_pos); } From 619ba54aa921b3ab180a452fc83e4fabfa67319b Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Wed, 14 Jun 2023 10:01:34 -0700 Subject: [PATCH 10/18] fix silly typo, get instead of at --- tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index f2a04f3819..35f7fcc843 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -757,7 +757,7 @@ public static BaseTrackState getTrackExtrapAtHodoRK(Track trk, FieldMap fM, int public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target_z, double[] beamPosition, FieldMap fM, double stepSize) { - TrackState ts = track.getTrackStates().at(0); + TrackState ts = track.getTrackStates().get(0); //if track passed to extrapolateHelixToXPlane, uses first track state //by default, else if trackstate is passed, uses trackstate params. From 7f4c777014b6c121e24fbd28bcca3d845ec82290 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Thu, 15 Jun 2023 14:24:15 -0700 Subject: [PATCH 11/18] added bfieldy values at 3 primary trackstate locations to the TrackData class. Allows us to calculate track momentum using curvature later, instead of having to create a new TrackData collection to hold 3-momentum for each Track State --- .../org/hps/recon/tracking/TrackData.java | 24 ++++++++++++++++++- .../org/hps/recon/tracking/TrackUtils.java | 3 +++ .../tracking/kalman/KalmanPatRecDriver.java | 23 +++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackData.java b/tracking/src/main/java/org/hps/recon/tracking/TrackData.java index 14ae440a52..1bb5564c90 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackData.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackData.java @@ -18,11 +18,14 @@ public class TrackData implements GenericObject { public static final int L1_ISOLATION_INDEX = 0; public static final int L2_ISOLATION_INDEX = 1; public static final int N_ISOLATIONS = 14; //Default - public static final int N_TRACK_PARAMS = 4; + public static final int N_TRACK_PARAMS = 7; public static final int TRACK_TIME_INDEX = 0; public static final int PX_INDEX = 1; public static final int PY_INDEX = 2; public static final int PZ_INDEX = 3; + public static final int ORIGIN_BFY_INDEX = 4; //BFieldY at Origin + public static final int TARGET_BFY_INDEX = 5; //BFieldY at Target TrackState + public static final int ECAL_BFY_INDEX = 6; //BFieldY at ECal TrackState public static final int TRACK_VOLUME_INDEX = 0; public static final String TRACK_DATA_COLLECTION = "TrackData"; public static final String TRACK_DATA_RELATION_COLLECTION = "TrackDataRelations"; @@ -81,6 +84,25 @@ public TrackData(int trackVolume, float trackTime, double[] isolations, float[] this.floats = new float[]{trackTime,momentum[0],momentum[1],momentum[2]}; this.ints = new int[]{trackVolume}; } + + /** + * Constructor + * + * @param trackVolume : SVT volume associated with the track + * @param trackTime : The track time + * @param isolations : an array of doubles containing isolations for every + * sensor layer + * @param momentum : an array of floats containing track momentum in the form (px,py,pz) + * @param origin_bfieldY : value of BfieldY at origin ref + * @param target_bfieldY : value of BfieldY at Target Track State + * @param ecal_bfieldY : value of BfieldY at ECal Track State + */ + public TrackData(int trackVolume, float trackTime, double[] isolations, float[] momentum, float origin_bfieldY, float target_bfieldY, float ecal_bfieldY) { + + this.doubles = isolations; + this.floats = new float[]{trackTime,momentum[0],momentum[1],momentum[2],origin_bfieldY,target_bfieldY,ecal_bfieldY}; + this.ints = new int[]{trackVolume}; + } /** * Get isolation value for the hit in the given sensor layer. diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index 35f7fcc843..ca5012d5c4 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -793,6 +793,9 @@ public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target //Define new reference point, to which track parameters are calc wrt double[] newRef = {target_z, beamPosition[1], beamPosition[2]}; params = getParametersAtNewRefPoint(newRef, bts); + //Do I need to change the bFieldY to correspond to new ref point? (Such + //small change, field shouldnt be different anyways) + //bFieldY = fm.getField(CoordinateTransformations.transformVectorToDetector(new BasicHep3Vector(newRef[0], newRef[1], newRef[2]))).y(); bts.setParameters(params, bFieldY); //Reference point records final position of track. //This does not hold the reference point to which the track params are diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index a554dfb872..5823e70701 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -24,6 +24,7 @@ import org.lcsim.event.EventHeader; import org.lcsim.event.LCRelation; import org.lcsim.event.Track; +import org.lcsim.event.TrackState; import org.lcsim.event.TrackerHit; import org.lcsim.event.base.BaseLCRelation; import org.lcsim.geometry.Detector; @@ -452,8 +453,28 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List Date: Fri, 16 Jun 2023 08:47:25 -0700 Subject: [PATCH 12/18] removed some stuff --- tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java | 3 --- .../java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index ca5012d5c4..35f7fcc843 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -793,9 +793,6 @@ public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target //Define new reference point, to which track parameters are calc wrt double[] newRef = {target_z, beamPosition[1], beamPosition[2]}; params = getParametersAtNewRefPoint(newRef, bts); - //Do I need to change the bFieldY to correspond to new ref point? (Such - //small change, field shouldnt be different anyways) - //bFieldY = fm.getField(CoordinateTransformations.transformVectorToDetector(new BasicHep3Vector(newRef[0], newRef[1], newRef[2]))).y(); bts.setParameters(params, bFieldY); //Reference point records final position of track. //This does not hold the reference point to which the track params are diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index 5823e70701..fbccbd541f 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -455,6 +455,7 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List[] prepareTrackCollections(EventHeader event, List Date: Mon, 19 Jun 2023 13:14:16 -0700 Subject: [PATCH 13/18] added covariance at target --- .../src/main/java/org/hps/recon/tracking/TrackUtils.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index 35f7fcc843..c13d181f9a 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -799,6 +799,13 @@ public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target //calculated from bts.setReferencePoint(finalPos.v()); bts.setLocation(TrackState.LastLocation); + + //Get covariance matrix at target. This does not use RK extrap, but + //simple change of reference point + SymmetricMatrix originCovMatrix = new SymmetricMatrix(5, ts.getCovMatrix(),true); + SymmetricMatrix covtrans = getCovarianceAtNewRefPoint(newRef, ts.getReferencePoint(), ts.getParameters(), originCovMatrix); + bts.setCovMatrix(covtrans.asPackedArray(true)); + return bts; } From 335009ce16d7f8d98e89ca57aecad206a0ce0c06 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Mon, 19 Jun 2023 13:38:33 -0700 Subject: [PATCH 14/18] fixed bug in beamposition coordinate use in target extrap --- tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java index c13d181f9a..eccf257eb7 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -791,7 +791,7 @@ public static BaseTrackState getTrackExtrapAtTargetRK(Track track, double target //reference point is set to track position in X Y Z bts.setReferencePoint(finalPos.v()); //Define new reference point, to which track parameters are calc wrt - double[] newRef = {target_z, beamPosition[1], beamPosition[2]}; + double[] newRef = {target_z, beamPosition[0], beamPosition[1]}; params = getParametersAtNewRefPoint(newRef, bts); bts.setParameters(params, bFieldY); //Reference point records final position of track. From 416552cf6aea4bcad10d4d16b3d71f69caf843b8 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Mon, 19 Jun 2023 18:30:40 -0700 Subject: [PATCH 15/18] removed magic code. Separated track at target state beampos from KalmanTracking beampos setting --- ...2016FullRecon_KF_TrackClusterMatcher.lcsim | 3 +- .../tracking/kalman/KalmanInterface.java | 7 ++++- .../tracking/kalman/KalmanPatRecDriver.java | 30 ++++++++++++------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim index 470d088611..c020b61a0f 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim @@ -126,7 +126,8 @@ 40 false - + -4.3 + false diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java index 6f0e0d8200..eda755fb1f 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanInterface.java @@ -80,6 +80,7 @@ public class KalmanInterface { private int nBigEvents; private int eventNumber; private static double target_pos = -999.9; + private static boolean addTrackStateAtTarget = false; private double[] beamPosition = null; private static final boolean debug = false; @@ -104,6 +105,10 @@ public void setTargetPosition(double target_pos){ this.target_pos = target_pos; } + public void setAddTrackStateAtTarget(boolean input){ + this.addTrackStateAtTarget = input; + } + public void setBeamPosition(double[] beamPosition){ this.beamPosition = beamPosition; } @@ -612,7 +617,7 @@ public BaseTrack createTrack(KalTrack kT, boolean storeTrackStates) { // Extrapolate to Target and make a new trackState there. BaseTrackState ts_target = new BaseTrackState(); - if (target_pos != -999.9){ + if (target_pos != -999.9 && addTrackStateAtTarget){ ts_target = TrackUtils.getTrackExtrapAtTargetRK(newTrack, target_pos, beamPosition, fM, 0); if (ts_target != null){ newTrack.getTrackStates().add(ts_target); diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index fbccbd541f..ed8bf9b259 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -58,6 +58,7 @@ public class KalmanPatRecDriver extends Driver { private KalmanPatRecPlots kPlot; private static Logger logger; private static double target_pos = -999.9; + private static boolean addTrackStateAtTarget = false; // Parameters for the Kalman pattern recognition that can be set by the user in the steering file: private ArrayList strategies; // List of seed strategies for both top and bottom trackers, from steering @@ -136,6 +137,10 @@ public void setAddResiduals(boolean input) { public void setTargetPosition(double target_pos){ this.target_pos = target_pos; } + + public void setAddTrackStateAtTarget(boolean input){ + this.addTrackStateAtTarget = input; + } @Override public void detectorChanged(Detector det) { @@ -255,26 +260,27 @@ public void detectorChanged(Detector det) { // Setup optional usage of beam positions from database. final DatabaseConditionsManager mgr = DatabaseConditionsManager.getInstance(); double[] beamPositionArr = {beamPositionX, beamPositionY, beamPositionZ}; - System.out.println("useBPC: "+useBeamPositionConditions); - System.out.println("mgr: "+mgr.hasConditionsRecord("beam_positions")); - if (useBeamPositionConditions && mgr.hasConditionsRecord("beam_positions")) { - logger.config("Using Kalman beam position from the conditions database"); + if (mgr.hasConditionsRecord("beam_positions")){ BeamPositionCollection beamPositions = mgr.getCachedConditions(BeamPositionCollection.class, "beam_positions").getCachedData(); BeamPosition beamPositionCond = beamPositions.get(0); - if (!useFixedVertexZPosition) kPar.setBeamSpotY(beamPositionCond.getPositionZ()); - else logger.config("Using fixed Kalman beam Z position: " + kPar.beamSpot[1]); - kPar.setBeamSpotX(beamPositionCond.getPositionX()); // Includes a transformation to Kalman coordinates - kPar.setBeamSpotZ(-beamPositionCond.getPositionY()); beamPositionArr[0] = beamPositionCond.getPositionX(); beamPositionArr[1] = beamPositionCond.getPositionY(); beamPositionArr[2] = beamPositionCond.getPositionZ(); System.out.println("beamPosition[0]: "+beamPositionArr[0]); System.out.println("beamPosition[1]: "+beamPositionArr[1]); System.out.println("beamPosition[2]: "+beamPositionArr[2]); + if (useBeamPositionConditions) { + logger.config("Using Kalman beam position from the conditions database"); + if (!useFixedVertexZPosition) kPar.setBeamSpotY(beamPositionCond.getPositionZ()); + else logger.config("Using fixed Kalman beam Z position: " + kPar.beamSpot[1]); + kPar.setBeamSpotX(beamPositionCond.getPositionX()); // Includes a transformation to Kalman coordinates + kPar.setBeamSpotZ(-beamPositionCond.getPositionY()); + } + else { + logger.config("Using Kalman beam position from the steering file or default"); + } - } else { - logger.config("Using Kalman beam position from the steering file or default"); } logger.config("Using Kalman beam position [ Z, X, Y ]: " + String.format("[ %f, %f, %f ]", kPar.beamSpot[0], -kPar.beamSpot[2], kPar.beamSpot[1]) + " in HPS coordinates."); @@ -284,8 +290,10 @@ public void detectorChanged(Detector det) { kPar.print(); KI = new KalmanInterface(uniformB, kPar, fm); + //Track State at Target uses beam position as track param reference KI.setBeamPosition(beamPositionArr); - if (target_pos != -999.9) { + if (target_pos != -999.9 && addTrackStateAtTarget) { + KI.setAddTrackStateAtTarget(addTrackStateAtTarget); KI.setTargetPosition(target_pos); } KI.setSiHitsLimit(siHitsLimit); From 6bc8f4f4bdbf3fc82cc673aba5c0407c7cd45ab2 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Tue, 27 Jun 2023 10:24:28 -0700 Subject: [PATCH 16/18] change clustering window from 8ns to 24ns --- ...sRun2016FullReconMC_KF_TrackClusterMatcher.lcsim | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullReconMC_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullReconMC_KF_TrackClusterMatcher.lcsim index 3cbd5c6d85..23ba7a6653 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullReconMC_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullReconMC_KF_TrackClusterMatcher.lcsim @@ -12,7 +12,7 @@ - + @@ -21,7 +21,7 @@ - + - + @@ -93,7 +93,7 @@ false - 8.0 + 24.0 false @@ -110,6 +110,9 @@ + 40 + -4.3 + true false From 0e003b8b4e9e5c9a5f81b372761a30951de54151 Mon Sep 17 00:00:00 2001 From: Alic Spellman Date: Tue, 18 Jul 2023 09:46:48 -0700 Subject: [PATCH 17/18] fix bug in how I accessed trackstate to get bfield at trackstate location --- .../hps/recon/tracking/kalman/KalmanPatRecDriver.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java index ed8bf9b259..d29c48a693 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/kalman/KalmanPatRecDriver.java @@ -19,12 +19,12 @@ import org.hps.recon.tracking.MaterialSupervisor.ScatteringDetectorVolume; import org.hps.recon.tracking.MaterialSupervisor.SiStripPlane; import org.hps.recon.tracking.gbl.GBLStripClusterData; +import org.hps.recon.tracking.TrackUtils; import org.hps.util.Pair; import org.lcsim.detector.tracker.silicon.HpsSiSensor; import org.lcsim.event.EventHeader; import org.lcsim.event.LCRelation; import org.lcsim.event.Track; -import org.lcsim.event.TrackState; import org.lcsim.event.TrackerHit; import org.lcsim.event.base.BaseLCRelation; import org.lcsim.geometry.Detector; @@ -466,17 +466,17 @@ private ArrayList[] prepareTrackCollections(EventHeader event, List Date: Tue, 25 Jul 2023 11:31:53 -0700 Subject: [PATCH 18/18] mod 2016 recon steering to use 24ns strip cluster window, and add track states at target by default --- .../PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim index c020b61a0f..eda4e46117 100644 --- a/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim +++ b/steering-files/src/main/resources/org/hps/steering/recon/PhysicsRun2016FullRecon_KF_TrackClusterMatcher.lcsim @@ -83,7 +83,7 @@ false - 8.0 + 24.0 false @@ -127,7 +127,7 @@ 40 false -4.3 - false + true