From 8b079392a320c4e5a24b914643d9fb7646f8e2f6 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 24 Nov 2017 18:41:53 -0500 Subject: [PATCH 1/2] Add an exception if the tracks goes backwards in extrapolateTrackUsingFieldMap(). Catch exception in TrackDataDriver::process() --- .../hps/recon/tracking/TrackDataDriver.java | 274 +++++++++--------- .../org/hps/recon/tracking/TrackUtils.java | 12 +- 2 files changed, 152 insertions(+), 134 deletions(-) diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java b/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java index 63b1fb1ffc..e75b54b9b2 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; import org.lcsim.detector.tracker.silicon.HpsSiSensor; @@ -33,25 +34,25 @@ public final class TrackDataDriver extends Driver { /** logger **/ private static final Logger LOGGER = Logger.getLogger(TrackDataDriver.class.getPackage().getName()); - - + + /** The B field map */ FieldMap bFieldMap = null; - + /** Collection Names */ - + /** Collection name of TrackResidualData objects */ private static final String TRK_RESIDUALS_COL_NAME = "TrackResiduals"; - + /** * Collection name of LCRelations between a Track and Rotated * HelicalTrackHits */ private static final String ROTATED_HTH_REL_COL_NAME = "RotatedHelicalTrackHitRelations"; - + /** Collection name of Rotated HelicalTrackHits */ private static final String ROTATED_HTH_COL_NAME = "RotatedHelicalTrackHits"; - + /** * Collection name of LCRelations between a Track and TrackResidualsData * objects. @@ -63,23 +64,23 @@ public final class TrackDataDriver extends Driver { * compact description. */ private static final String ECAL_POSITION_CONSTANT_NAME = "ecal_dface"; - + /** Position of the Ecal face */ private double ecalPosition = 0; // mm - + /** Z position to start extrapolation from */ double extStartPos = 700; // mm - + /** The extrapolation step size */ double stepSize = 5.0; // mm - + /** The default number of layers */ int layerNum = 6; - + /** Default constructor */ public TrackDataDriver() { } - + /** * Set the position along Z where the extrapolation of a track should * begin. @@ -90,7 +91,7 @@ public TrackDataDriver() { void setExtrapolationStartPosition(double extStartPos) { this.extStartPos = extStartPos; } - + /** * Set the extrapolation length between iterations through the magnetic * field. @@ -100,16 +101,16 @@ void setExtrapolationStartPosition(double extStartPos) { void setStepSize(double stepSize) { this.stepSize = stepSize; } - + /** * Set number of tracking layers. Default is 6 layers. * */ - + public void setLayerNum(int layerNum) { this.layerNum = layerNum; } - + /** * Method called by the framework when a new {@link Detector} geometry is * loaded. This method is called at the beginning of every run and @@ -119,14 +120,14 @@ public void setLayerNum(int layerNum) { */ @Override protected void detectorChanged(Detector detector) { - + // Get the field map from the detector object bFieldMap = detector.getFieldMap(); - + // Get the position of the Ecal from the compact description ecalPosition = detector.getConstants().get(ECAL_POSITION_CONSTANT_NAME).getValue(); } - + /** * Method called by the framework to process the event. * @@ -151,7 +152,7 @@ protected void process(EventHeader event) { RelationalTable hitToStrips = TrackUtils.getHitToStripsTable(event); RelationalTable hitToRotated = TrackUtils.getHitToRotatedTable(event); -// List rotatedHths = event.get(HelicalTrackHit.class, ROTATED_HTH_COL_NAME); + // List rotatedHths = event.get(HelicalTrackHit.class, ROTATED_HTH_COL_NAME); // Create a container that will be used to store all TrackData objects. List trackDataCollection = new ArrayList(); @@ -191,129 +192,136 @@ protected void process(EventHeader event) { // Loop over each of the track collections retrieved from the event for (List tracks : trackCollections) { - + // Loop over all the tracks in the event for (Track track : tracks) { - totalT0 = 0; - totalHits = 0; - t0Residuals.clear(); - sensorLayers.clear(); - trackResidualsX.clear(); - trackResidualsY.clear(); - stereoLayers.clear(); - isFirstHit = true; - -// TrackState trackStateForResiduals = TrackUtils.getTrackStateAtLocation(track, TrackState.AtLastHit); -// if (trackStateForResiduals == null ) trackStateForResiduals= TrackUtils.getTrackStateAtLocation(track, TrackState.AtIP); - TrackState trackStateForResiduals = TrackUtils.getTrackStateAtLocation(track, TrackState.AtIP); - - // Change the position of a HelicalTrackHit to be the corrected - // one. - // FIXME: Now that multiple track collections are being used, - // which track should be used to apply the correction? - // The best track from each of the collections? - // How is the "best track" defined? --OM - // - // Loop over all stereo hits comprising a track - for (TrackerHit rotatedStereoHit : track.getTrackerHits()) { - - // Add the stereo layer number associated with the track - // residual - stereoLayers.add(((HelicalTrackHit) rotatedStereoHit).Layer()); - - // Extrapolate the track to the stereo hit position and - // calculate track residuals - stereoHitPosition = ((HelicalTrackHit) rotatedStereoHit).getCorrectedPosition(); - trackPosition = TrackUtils.extrapolateTrack(trackStateForResiduals, stereoHitPosition.x()); - xResidual = trackPosition.x() - stereoHitPosition.y(); - yResidual = trackPosition.y() - stereoHitPosition.z(); - trackResidualsX.add(xResidual); - trackResidualsY.add((float) yResidual); - + try { + totalT0 = 0; + totalHits = 0; + t0Residuals.clear(); + sensorLayers.clear(); + trackResidualsX.clear(); + trackResidualsY.clear(); + stereoLayers.clear(); + isFirstHit = true; + + // TrackState trackStateForResiduals = TrackUtils.getTrackStateAtLocation(track, TrackState.AtLastHit); + // if (trackStateForResiduals == null ) trackStateForResiduals= TrackUtils.getTrackStateAtLocation(track, TrackState.AtIP); + TrackState trackStateForResiduals = TrackUtils.getTrackStateAtLocation(track, TrackState.AtIP); + + // Change the position of a HelicalTrackHit to be the corrected + // one. + // FIXME: Now that multiple track collections are being used, + // which track should be used to apply the correction? + // The best track from each of the collections? + // How is the "best track" defined? --OM // - // Change the persisted position of both - // RotatedHelicalTrackHits and HelicalTrackHits to the - // corrected position. - // - - // Get the HelicalTrackHit corresponding to the - // RotatedHelicalTrackHit associated with a track - helicalTrackHit = (HelicalTrackHit) hitToRotated.from(rotatedStereoHit); - ((HelicalTrackHit) rotatedStereoHit).setPosition(stereoHitPosition.v()); - stereoHitPosition = CoordinateTransformations.transformVectorToDetector(stereoHitPosition); - helicalTrackHit.setPosition(stereoHitPosition.v()); - - // Loop over the clusters comprising the stereo hit - for (HelicalTrackStrip cluster : ((HelicalTrackCross) rotatedStereoHit).getStrips()) { - - totalT0 += cluster.time(); - totalHits++; - - if (isFirstHit) { - sensor = (HpsSiSensor) ((RawTrackerHit) cluster.rawhits().get(0)).getDetectorElement(); - if (sensor.isTopLayer()) { - trackerVolume = 0; - } else if (sensor.isBottomLayer()) { - trackerVolume = 1; + // Loop over all stereo hits comprising a track + for (TrackerHit rotatedStereoHit : track.getTrackerHits()) { + + // Add the stereo layer number associated with the track + // residual + stereoLayers.add(((HelicalTrackHit) rotatedStereoHit).Layer()); + + // Extrapolate the track to the stereo hit position and + // calculate track residuals + stereoHitPosition = ((HelicalTrackHit) rotatedStereoHit).getCorrectedPosition(); + trackPosition = TrackUtils.extrapolateTrack(trackStateForResiduals, stereoHitPosition.x()); + xResidual = trackPosition.x() - stereoHitPosition.y(); + yResidual = trackPosition.y() - stereoHitPosition.z(); + trackResidualsX.add(xResidual); + trackResidualsY.add((float) yResidual); + + // + // Change the persisted position of both + // RotatedHelicalTrackHits and HelicalTrackHits to the + // corrected position. + // + + // Get the HelicalTrackHit corresponding to the + // RotatedHelicalTrackHit associated with a track + helicalTrackHit = (HelicalTrackHit) hitToRotated.from(rotatedStereoHit); + ((HelicalTrackHit) rotatedStereoHit).setPosition(stereoHitPosition.v()); + stereoHitPosition = CoordinateTransformations.transformVectorToDetector(stereoHitPosition); + helicalTrackHit.setPosition(stereoHitPosition.v()); + + // Loop over the clusters comprising the stereo hit + for (HelicalTrackStrip cluster : ((HelicalTrackCross) rotatedStereoHit).getStrips()) { + + totalT0 += cluster.time(); + totalHits++; + + if (isFirstHit) { + sensor = (HpsSiSensor) ((RawTrackerHit) cluster.rawhits().get(0)).getDetectorElement(); + if (sensor.isTopLayer()) { + trackerVolume = 0; + } else if (sensor.isBottomLayer()) { + trackerVolume = 1; + } + isFirstHit = false; } - isFirstHit = false; } } - } - // - // Add a track state that contains the extrapolated track position and - // parameters at the face of the Ecal. - // - LOGGER.fine("Extrapolating track with type " + Integer.toString(track.getType()) ); - - // Extrapolate the track to the face of the Ecal and get the TrackState - if( TrackType.isGBL(track.getType())) { - TrackState stateIP = TrackUtils.getTrackStateAtLocation(track, TrackState.AtIP); - if( stateIP == null) - throw new RuntimeException("IP track state for GBL track was not found"); - TrackState stateEcalIP = TrackUtils.extrapolateTrackUsingFieldMap(stateIP, extStartPos, ecalPosition, stepSize, bFieldMap); - track.getTrackStates().add(stateEcalIP); - - } else { - LOGGER.fine("Extrapolate seed track to ECal from vertex"); - TrackState state = TrackUtils.extrapolateTrackUsingFieldMap(track, extStartPos, ecalPosition, stepSize, bFieldMap); - track.getTrackStates().add(state); - } - - LOGGER.fine(Integer.toString(track.getTrackStates().size()) + " track states for this track at this point:"); - for(TrackState state : track.getTrackStates()) { - String s = "type " + Integer.toString(track.getType()) + " location " + Integer.toString(state.getLocation()) + " refPoint (" + state.getReferencePoint()[0] + " " + state.getReferencePoint()[1] + " " + state.getReferencePoint()[2] + ") " + " params: "; - for(int i=0;i<5;++i) s += String.format(" %f", state.getParameter(i)); - LOGGER.fine(s); - } - - - // The track time is the mean t0 of hits on a track - trackTime = totalT0 / totalHits; - - // Calculate the track isolation constants for each of the - // layers - Double[] isolations = TrackUtils.getIsolations(track, hitToStrips, hitToRotated,layerNum); - double qualityArray[] = new double[isolations.length]; - for (int i = 0; i < isolations.length; i++) { - qualityArray[i] = isolations[i] == null ? -99999999.0 : isolations[i]; + // + // Add a track state that contains the extrapolated track position and + // parameters at the face of the Ecal. + // + LOGGER.fine("Extrapolating track with type " + Integer.toString(track.getType()) ); + + // Extrapolate the track to the face of the Ecal and get the TrackState + if( TrackType.isGBL(track.getType())) { + TrackState stateIP = TrackUtils.getTrackStateAtLocation(track, TrackState.AtIP); + if( stateIP == null) + throw new RuntimeException("IP track state for GBL track was not found"); + TrackState stateEcalIP = TrackUtils.extrapolateTrackUsingFieldMap(stateIP, extStartPos, ecalPosition, stepSize, bFieldMap); + track.getTrackStates().add(stateEcalIP); + + } else { + LOGGER.fine("Extrapolate seed track to ECal from vertex"); + TrackState state = TrackUtils.extrapolateTrackUsingFieldMap(track, extStartPos, ecalPosition, stepSize, bFieldMap); + track.getTrackStates().add(state); + } + + LOGGER.fine(Integer.toString(track.getTrackStates().size()) + " track states for this track at this point:"); + for(TrackState state : track.getTrackStates()) { + String s = "type " + Integer.toString(track.getType()) + " location " + Integer.toString(state.getLocation()) + " refPoint (" + state.getReferencePoint()[0] + " " + state.getReferencePoint()[1] + " " + state.getReferencePoint()[2] + ") " + " params: "; + for(int i=0;i<5;++i) s += String.format(" %f", state.getParameter(i)); + LOGGER.fine(s); + } + + + // The track time is the mean t0 of hits on a track + trackTime = totalT0 / totalHits; + + // Calculate the track isolation constants for each of the + // layers + Double[] isolations = TrackUtils.getIsolations(track, hitToStrips, hitToRotated,layerNum); + double qualityArray[] = new double[isolations.length]; + for (int i = 0; i < isolations.length; i++) { + qualityArray[i] = isolations[i] == null ? -99999999.0 : isolations[i]; + } + + // Create a new TrackData object and add it to the event + TrackData trackData = new TrackData(trackerVolume, trackTime, qualityArray); + trackDataCollection.add(trackData); + trackDataRelations.add(new BaseLCRelation(trackData, track)); + + // Create a new TrackResidualsData object and add it to the event + TrackResidualsData trackResiduals = new TrackResidualsData((int) trackerVolume, stereoLayers, + trackResidualsX, trackResidualsY); + trackResidualsCollection.add(trackResiduals); + trackToTrackResidualsRelations.add(new BaseLCRelation(trackResiduals, track)); + + }catch( Exception e){ + LOGGER.warning("Exception in TrackDataDriver - TrackExtrapolate \n"); + LOGGER.log(Level.SEVERE, e.getMessage(), e); + continue; } - - // Create a new TrackData object and add it to the event - TrackData trackData = new TrackData(trackerVolume, trackTime, qualityArray); - trackDataCollection.add(trackData); - trackDataRelations.add(new BaseLCRelation(trackData, track)); - - // Create a new TrackResidualsData object and add it to the event - TrackResidualsData trackResiduals = new TrackResidualsData((int) trackerVolume, stereoLayers, - trackResidualsX, trackResidualsY); - trackResidualsCollection.add(trackResiduals); - trackToTrackResidualsRelations.add(new BaseLCRelation(trackResiduals, track)); } } - + // Add all collections to the event event.put(TrackData.TRACK_DATA_COLLECTION, trackDataCollection, TrackData.class, 0); event.put(TrackData.TRACK_DATA_RELATION_COLLECTION, trackDataRelations, LCRelation.class, 0); 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 170e06981a..4b16645044 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.logging.Logger; import org.apache.commons.math3.util.Pair; import org.hps.recon.tracking.EventQuality.Quality; @@ -81,6 +82,8 @@ public class TrackUtils { private TrackUtils() { } + private static Logger LOGGER = Logger.getLogger(TrackUtils.class.getPackage().getName()); + /** * Extrapolate track to a position along the x-axis. Turn the track into a * helix object in order to use HelixUtils. @@ -1555,7 +1558,8 @@ public static TrackState extrapolateTrackUsingFieldMap(TrackState track, double // size up to ~90% of the final position. At this point, a finer // track size will be used. boolean stepSizeChange = false; - while (currentPosition.x() < endPositionX) { + + while (currentPosition.x() < endPositionX){ // The field map coordinates are in the detector frame so the // extrapolated track position needs to be transformed from the @@ -1588,6 +1592,12 @@ public static TrackState extrapolateTrackUsingFieldMap(TrackState track, double // System.out.println("Changing step size: " + stepSize); stepSizeChange = true; } + + if(currentMomentum.x() < 0 ){ + LOGGER.warning("extrapolateTrackUsingFieldMap track going backwards - Killed\n"); + throw new RuntimeException("extrapolateTrackUsingFieldMap track going backwards - Killed\n"); + } + } // Calculate the track parameters at the Extrapolation point From 477d02b48662ee102c6edf6ab5c5ff99a4bcdc61 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 24 Nov 2017 20:09:05 -0500 Subject: [PATCH 2/2] Add a check in TrackClusterMatcher to see if cluster was matched. It is not if the search aborted. Clean up the LOGGER messages. --- .../main/java/org/hps/recon/utils/TrackClusterMatcher.java | 4 ++++ .../src/main/java/org/hps/recon/tracking/TrackDataDriver.java | 1 - tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java b/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java index 5ed4b39986..9d250031b3 100644 --- a/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java +++ b/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java @@ -322,6 +322,10 @@ public double getNSigmaPosition(Cluster cluster, Track track, double p){ // Get the extrapolated track position at the calorimeter: TrackState trackStateAtEcal = TrackUtils.getTrackStateAtECal(track); + if(trackStateAtEcal == null){ + // Track never made it to the ECAL, so it curled before doing this and probably extrapolateTrackUsingFieldMap aborted. + return Double.MAX_VALUE; + } Hep3Vector tPos = new BasicHep3Vector(trackStateAtEcal.getReferencePoint()); tPos = CoordinateTransformations.transformVectorToDetector(tPos); diff --git a/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java b/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java index e75b54b9b2..1ce9d1b76d 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackDataDriver.java @@ -315,7 +315,6 @@ protected void process(EventHeader event) { trackToTrackResidualsRelations.add(new BaseLCRelation(trackResiduals, track)); }catch( Exception e){ - LOGGER.warning("Exception in TrackDataDriver - TrackExtrapolate \n"); LOGGER.log(Level.SEVERE, e.getMessage(), e); continue; } 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 4b16645044..dd96eb9ef7 100644 --- a/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java +++ b/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java @@ -1594,8 +1594,7 @@ public static TrackState extrapolateTrackUsingFieldMap(TrackState track, double } if(currentMomentum.x() < 0 ){ - LOGGER.warning("extrapolateTrackUsingFieldMap track going backwards - Killed\n"); - throw new RuntimeException("extrapolateTrackUsingFieldMap track going backwards - Killed\n"); + throw new RuntimeException("extrapolateTrackUsingFieldMap track going backwards - abort search\n"); } }