Author: [log in to unmask] Date: Mon Sep 21 17:21:37 2015 New Revision: 3662 Log: fix bug with GBL tracks Modified: java/trunk/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java java/trunk/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java Modified: java/trunk/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java ============================================================================= --- java/trunk/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java (original) +++ java/trunk/recon/src/main/java/org/hps/recon/utils/TrackClusterMatcher.java Mon Sep 21 17:21:37 2015 @@ -22,33 +22,37 @@ /** * Utility used to determine if a track and cluster are matched. - * + * * @author <a href="mailto:[log in to unmask]">Omar Moreno</a> */ public class TrackClusterMatcher { - /** The B field map */ + /** + * The B field map + */ FieldMap bFieldMap = null; - + // Plotting - private ITree tree; - private IHistogramFactory histogramFactory; + private ITree tree; + private IHistogramFactory histogramFactory; private Map<String, IHistogram1D> plots1D; private Map<String, IHistogram2D> plots2D; - - /** Flag used to determine if plots are enabled/disabled */ - boolean enablePlots = false; - - /** + + /** + * Flag used to determine if plots are enabled/disabled + */ + boolean enablePlots = false; + + /** * Flag used to determine whether the analytic or field map extrapolator - * should be used. - */ - boolean useAnalyticExtrapolator = false; - - /** - * These cuts are set at +/- 4 sigma extracted from Gaussian fits to the - * track-cluster residual distributions. The data used to determine these - * limits is a pass 2 test file (t2.6) using run 5772. + * should be used. + */ + boolean useAnalyticExtrapolator = false; + + /** + * These cuts are set at +/- 4 sigma extracted from Gaussian fits to the + * track-cluster residual distributions. The data used to determine these + * limits is a pass 2 test file (t2.6) using run 5772. */ private double topClusterTrackMatchDeltaXLow = -14.5; // mm private double topClusterTrackMatchDeltaXHigh = 23.5; // mm @@ -60,17 +64,28 @@ private double bottomClusterTrackMatchDeltaYLow = -28; // mm private double bottomClusterTrackMatchDeltaYHigh = 24; // mm - /** Z position to start extrapolation from */ + /** + * Z position to start extrapolation from + */ double extStartPos = 700; // mm - - /** The extrapolation step size */ + + /** + * The extrapolation step size + */ double stepSize = 5.; // mm - - /** Constant denoting the index of the {@link TrackState} at the Ecal */ - private static final int ECAL_TRACK_STATE_INDEX = 1; - - /** Constructor */ - public TrackClusterMatcher() {}; + + /** + * Constant denoting the index of the {@link TrackState} at the Ecal + */ + private static final int ECAL_TRACK_STATE_INDEX = 1; + + /** + * Constructor + */ + public TrackClusterMatcher() { + } + + ; /** * Enable/disable booking, filling of Ecal cluster and extrapolated track @@ -78,37 +93,39 @@ * * @param enablePlots true to enable, false to disable */ - public void enablePlots(boolean enablePlots) { + public void enablePlots(boolean enablePlots) { this.enablePlots = enablePlots; - if (enablePlots == true) this.bookHistograms(); - } - + if (enablePlots == true) { + this.bookHistograms(); + } + } + /** * Set the 3D field map to be used by the extrapolator. - * + * * @param bFieldMap The {@link FieldMap} object containing a mapping to the - * 3D field map. - */ - public void setBFieldMap(FieldMap bFieldMap) { - this.bFieldMap = bFieldMap; - } - - /** - * Use the analytic track extrapolator i.e. the no fringe extrapolator. - * The field map extrapolator is used by default. - * - * @param useAnalyticExtrapolator Set to true to use the analytic - * extrapolator, false otherwise. - */ - public void setUseAnalyticExtrapolator(boolean useAnalyticExtrapolator) { - this.useAnalyticExtrapolator = useAnalyticExtrapolator; - } - - /** - * Set the window in which the x residual of the extrapolated bottom track + * 3D field map. + */ + public void setBFieldMap(FieldMap bFieldMap) { + this.bFieldMap = bFieldMap; + } + + /** + * Use the analytic track extrapolator i.e. the no fringe extrapolator. The + * field map extrapolator is used by default. + * + * @param useAnalyticExtrapolator Set to true to use the analytic + * extrapolator, false otherwise. + */ + public void setUseAnalyticExtrapolator(boolean useAnalyticExtrapolator) { + this.useAnalyticExtrapolator = useAnalyticExtrapolator; + } + + /** + * Set the window in which the x residual of the extrapolated bottom track * position at the Ecal and the Ecal cluster position must be within to be * considered a 'good match' - * + * * @param xLow * @param xHigh */ @@ -119,9 +136,9 @@ /** * Set the window in which the y residual of the extrapolated bottom track - * position at the Ecal and the Ecal cluster position must be within to be + * position at the Ecal and the Ecal cluster position must be within to be * considered a 'good match' - * + * * @param yLow * @param yHigh */ @@ -129,12 +146,12 @@ this.topClusterTrackMatchDeltaYLow = yLow; this.topClusterTrackMatchDeltaYHigh = yHigh; } - - /** - * Set the window in which the x residual of the extrapolated top track position - * at the Ecal and the Ecal cluster position must be within to be considered - * a 'good match' - * + + /** + * Set the window in which the x residual of the extrapolated top track + * position at the Ecal and the Ecal cluster position must be within to be + * considered a 'good match' + * * @param xLow * @param xHigh */ @@ -144,10 +161,10 @@ } /** - * Set the window in which the y residual of the extrapolated top track position - * at the Ecal and the Ecal cluster position must be within to be considered - * a 'good match' - * + * Set the window in which the y residual of the extrapolated top track + * position at the Ecal and the Ecal cluster position must be within to be + * considered a 'good match' + * * @param yLow * @param yHigh */ @@ -157,26 +174,28 @@ } /** - * Determine if a track is matched to a cluster. Currently, this is + * Determine if a track is matched to a cluster. Currently, this is * determined by checking that the track and cluster are within the same - * detector volume of each other and that the extrapolated track position - * is within some defined distance of the cluster. - * + * detector volume of each other and that the extrapolated track position is + * within some defined distance of the cluster. + * * @param cluster : The Ecal cluster to check * @param track : The SVT track to check - * @return true if all cuts are pased, false otherwise. - */ - public boolean isMatch(Cluster cluster, Track track) { + * @return true if all cuts are pased, false otherwise. + */ + public boolean isMatch(Cluster cluster, Track track) { // Check that the track and cluster are in the same detector volume. // If not, there is no way they can be a match. if ((track.getTrackStates().get(0).getTanLambda() > 0 && cluster.getPosition()[1] < 0) - || (track.getTrackStates().get(0).getTanLambda() < 0 && cluster.getPosition()[1] > 0 )) return false; + || (track.getTrackStates().get(0).getTanLambda() < 0 && cluster.getPosition()[1] > 0)) { + return false; + } // Get the cluster position Hep3Vector clusterPosition = new BasicHep3Vector(cluster.getPosition()); //System.out.println("Cluster Position: " + clusterPosition.toString()); - + // Extrapolate the track to the Ecal cluster position Hep3Vector trackPosAtEcal = null; if (this.useAnalyticExtrapolator) { @@ -184,159 +203,162 @@ trackPosAtEcal = TrackUtils.extrapolateTrack(track, clusterPosition.z()); } else { //System.out.println("Using field map extrapolator"); - TrackState trackStateAtEcal = (TrackState) track.getTrackStates().get(this.ECAL_TRACK_STATE_INDEX); - trackPosAtEcal = new BasicHep3Vector(trackStateAtEcal.getReferencePoint()); + TrackState trackStateAtEcal = TrackUtils.getTrackStateAtECal(track); + trackPosAtEcal = new BasicHep3Vector(trackStateAtEcal.getReferencePoint()); trackPosAtEcal = CoordinateTransformations.transformVectorToDetector(trackPosAtEcal); } //System.out.println("Track position at Ecal: " + trackPosAtEcal.toString()); - - - + // Calculate the difference between the cluster position at the Ecal and // the track in both the x and y directions - double deltaX = clusterPosition.x() - trackPosAtEcal.x(); + double deltaX = clusterPosition.x() - trackPosAtEcal.x(); double deltaY = clusterPosition.y() - trackPosAtEcal.y(); - + //System.out.println("delta X: " + deltaX); //System.out.println("delta Y: " + deltaY); - if (enablePlots) { - if (track.getTrackStates().get(0).getTanLambda() > 0) { - - plots1D.get("Ecal cluster x - track x @ Ecal - top - all").fill(deltaX); - plots2D.get("Ecal cluster x v track x @ Ecal - top - all").fill(clusterPosition.x(), - trackPosAtEcal.x()); - plots1D.get("Ecal cluster y - track y @ Ecal - top - all").fill(deltaY); - plots2D.get("Ecal cluster y v track y @ Ecal - top - all").fill(clusterPosition.y(), - trackPosAtEcal.y()); - - } else if (track.getTrackStates().get(0).getTanLambda() < 0) { - - plots1D.get("Ecal cluster x - track x @ Ecal - bottom - all").fill(deltaX); - plots2D.get("Ecal cluster x v track x @ Ecal - bottom - all").fill(clusterPosition.x(), - trackPosAtEcal.x()); - plots1D.get("Ecal cluster y - track y @ Ecal - bottom - all").fill(deltaY); - plots2D.get("Ecal cluster y v track y @ Ecal - bottom - all").fill(clusterPosition.y(), - trackPosAtEcal.y()); + if (track.getTrackStates().get(0).getTanLambda() > 0) { + + plots1D.get("Ecal cluster x - track x @ Ecal - top - all").fill(deltaX); + plots2D.get("Ecal cluster x v track x @ Ecal - top - all").fill(clusterPosition.x(), + trackPosAtEcal.x()); + plots1D.get("Ecal cluster y - track y @ Ecal - top - all").fill(deltaY); + plots2D.get("Ecal cluster y v track y @ Ecal - top - all").fill(clusterPosition.y(), + trackPosAtEcal.y()); + + } else if (track.getTrackStates().get(0).getTanLambda() < 0) { + + plots1D.get("Ecal cluster x - track x @ Ecal - bottom - all").fill(deltaX); + plots2D.get("Ecal cluster x v track x @ Ecal - bottom - all").fill(clusterPosition.x(), + trackPosAtEcal.x()); + plots1D.get("Ecal cluster y - track y @ Ecal - bottom - all").fill(deltaY); + plots2D.get("Ecal cluster y v track y @ Ecal - bottom - all").fill(clusterPosition.y(), + trackPosAtEcal.y()); } } // Check that dx and dy between the extrapolated track and cluster // positions is reasonable. Different requirements are imposed on // top and bottom tracks in order to account for offsets. - if ((track.getTrackStates().get(0).getTanLambda() > 0 && (deltaX > topClusterTrackMatchDeltaXHigh || - deltaX < topClusterTrackMatchDeltaXLow)) || - (track.getTrackStates().get(0).getTanLambda() < 0 && (deltaX > bottomClusterTrackMatchDeltaXHigh || - deltaX < bottomClusterTrackMatchDeltaXLow))) return false; - - if ((track.getTrackStates().get(0).getTanLambda() > 0 && (deltaY > topClusterTrackMatchDeltaYHigh || - deltaY < topClusterTrackMatchDeltaYLow)) || - (track.getTrackStates().get(0).getTanLambda() < 0 && (deltaY > bottomClusterTrackMatchDeltaYHigh || - deltaY < bottomClusterTrackMatchDeltaYLow))) return false; + if ((track.getTrackStates().get(0).getTanLambda() > 0 && (deltaX > topClusterTrackMatchDeltaXHigh + || deltaX < topClusterTrackMatchDeltaXLow)) + || (track.getTrackStates().get(0).getTanLambda() < 0 && (deltaX > bottomClusterTrackMatchDeltaXHigh + || deltaX < bottomClusterTrackMatchDeltaXLow))) { + return false; + } + + if ((track.getTrackStates().get(0).getTanLambda() > 0 && (deltaY > topClusterTrackMatchDeltaYHigh + || deltaY < topClusterTrackMatchDeltaYLow)) + || (track.getTrackStates().get(0).getTanLambda() < 0 && (deltaY > bottomClusterTrackMatchDeltaYHigh + || deltaY < bottomClusterTrackMatchDeltaYLow))) { + return false; + } if (enablePlots) { - if (track.getTrackStates().get(0).getTanLambda() > 0) { - - plots1D.get("Ecal cluster x - track x @ Ecal - top - matched").fill(deltaX); - plots2D.get("Ecal cluster x v track x @ Ecal - top - matched").fill(clusterPosition.x(), - trackPosAtEcal.x()); - plots1D.get("Ecal cluster y - track y @ Ecal - top - matched").fill(deltaY); - plots2D.get("Ecal cluster y v track y @ Ecal - top - matched").fill(clusterPosition.y(), - trackPosAtEcal.y()); - - } else if (track.getTrackStates().get(0).getTanLambda() < 0) { - - plots1D.get("Ecal cluster x - track x @ Ecal - bottom - matched").fill(deltaX); - plots2D.get("Ecal cluster x v track x @ Ecal - bottom - matched").fill(clusterPosition.x(), - trackPosAtEcal.x()); - plots1D.get("Ecal cluster y - track y @ Ecal - bottom - matched").fill(deltaY); - plots2D.get("Ecal cluster y v track y @ Ecal - bottom - matched").fill(clusterPosition.y(), - trackPosAtEcal.y()); + if (track.getTrackStates().get(0).getTanLambda() > 0) { + + plots1D.get("Ecal cluster x - track x @ Ecal - top - matched").fill(deltaX); + plots2D.get("Ecal cluster x v track x @ Ecal - top - matched").fill(clusterPosition.x(), + trackPosAtEcal.x()); + plots1D.get("Ecal cluster y - track y @ Ecal - top - matched").fill(deltaY); + plots2D.get("Ecal cluster y v track y @ Ecal - top - matched").fill(clusterPosition.y(), + trackPosAtEcal.y()); + + } else if (track.getTrackStates().get(0).getTanLambda() < 0) { + + plots1D.get("Ecal cluster x - track x @ Ecal - bottom - matched").fill(deltaX); + plots2D.get("Ecal cluster x v track x @ Ecal - bottom - matched").fill(clusterPosition.x(), + trackPosAtEcal.x()); + plots1D.get("Ecal cluster y - track y @ Ecal - bottom - matched").fill(deltaY); + plots2D.get("Ecal cluster y v track y @ Ecal - bottom - matched").fill(clusterPosition.y(), + trackPosAtEcal.y()); } } - + // If all cuts are pased, return true. return true; } - - /** Book histograms of Ecal cluster x/y vs extrapolated track x/y */ - private void bookHistograms() { - + + /** + * Book histograms of Ecal cluster x/y vs extrapolated track x/y + */ + private void bookHistograms() { + plots1D = new HashMap<String, IHistogram1D>(); plots2D = new HashMap<String, IHistogram2D>(); - + tree = IAnalysisFactory.create().createTreeFactory().create(); histogramFactory = IAnalysisFactory.create().createHistogramFactory(tree); - + //--- All tracks and clusters ---// //-------------------------------// - //--- Top ---// - plots1D.put("Ecal cluster x - track x @ Ecal - top - all", - histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - top - all", 200, -200, 200)); - - plots2D.put("Ecal cluster x v track x @ Ecal - top - all", - histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - top - all", 200, -200, 200, 200, -200, 200)); - - plots1D.put("Ecal cluster y - track y @ Ecal - top - all", - histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - top - all", 100, -100, 100)); - - plots2D.put("Ecal cluster y v track y @ Ecal - top - all", - histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - top - all", 100, -100, 100, 100, -100, 100)); - + plots1D.put("Ecal cluster x - track x @ Ecal - top - all", + histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - top - all", 200, -200, 200)); + + plots2D.put("Ecal cluster x v track x @ Ecal - top - all", + histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - top - all", 200, -200, 200, 200, -200, 200)); + + plots1D.put("Ecal cluster y - track y @ Ecal - top - all", + histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - top - all", 100, -100, 100)); + + plots2D.put("Ecal cluster y v track y @ Ecal - top - all", + histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - top - all", 100, -100, 100, 100, -100, 100)); + //--- Bottom ---// - plots1D.put("Ecal cluster x - track x @ Ecal - bottom - all", - histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - bottom - all", 200, -200, 200)); - - plots2D.put("Ecal cluster x v track x @ Ecal - bottom - all", - histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - bottom - all", 200, -200, 200, 200, -200, 200)); - - plots1D.put("Ecal cluster y - track y @ Ecal - bottom - all", - histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - bottom - all", 100, -100, 100)); - - plots2D.put("Ecal cluster y v track y @ Ecal - bottom - all", - histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - bottom - all", 100, -100, 100, 100, -100, 100)); + plots1D.put("Ecal cluster x - track x @ Ecal - bottom - all", + histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - bottom - all", 200, -200, 200)); + + plots2D.put("Ecal cluster x v track x @ Ecal - bottom - all", + histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - bottom - all", 200, -200, 200, 200, -200, 200)); + + plots1D.put("Ecal cluster y - track y @ Ecal - bottom - all", + histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - bottom - all", 100, -100, 100)); + + plots2D.put("Ecal cluster y v track y @ Ecal - bottom - all", + histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - bottom - all", 100, -100, 100, 100, -100, 100)); //--- Matched tracks ---// //----------------------// - //--- Top ---// - plots1D.put("Ecal cluster x - track x @ Ecal - top - matched", - histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - top - matched", 200, -200, 200)); - - plots2D.put("Ecal cluster x v track x @ Ecal - top - matched", - histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - top - matched", 200, -200, 200, 200, -200, 200)); - - plots1D.put("Ecal cluster y - track y @ Ecal - top - matched", - histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - top - matched", 100, -100, 100)); - - plots2D.put("Ecal cluster y v track y @ Ecal - top - matched", - histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - top - matched", 100, -100, 100, 100, -100, 100)); - + plots1D.put("Ecal cluster x - track x @ Ecal - top - matched", + histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - top - matched", 200, -200, 200)); + + plots2D.put("Ecal cluster x v track x @ Ecal - top - matched", + histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - top - matched", 200, -200, 200, 200, -200, 200)); + + plots1D.put("Ecal cluster y - track y @ Ecal - top - matched", + histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - top - matched", 100, -100, 100)); + + plots2D.put("Ecal cluster y v track y @ Ecal - top - matched", + histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - top - matched", 100, -100, 100, 100, -100, 100)); + //--- Bottom ---// - plots1D.put("Ecal cluster x - track x @ Ecal - bottom - matched", - histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - bottom - matched", 200, -200, 200)); - - plots2D.put("Ecal cluster x v track x @ Ecal - bottom - matched", - histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - bottom - matched", 200, -200, 200, 200, -200, 200)); - - plots1D.put("Ecal cluster y - track y @ Ecal - bottom - matched", - histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - bottom - matched", 100, -100, 100)); - - plots2D.put("Ecal cluster y v track y @ Ecal - bottom - matched", - histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - bottom - matched", 100, -100, 100, 100, -100, 100)); - - } - - /** Save the histograms to a ROO file */ - public void saveHistograms() { - + plots1D.put("Ecal cluster x - track x @ Ecal - bottom - matched", + histogramFactory.createHistogram1D("Ecal cluster x - track x @ Ecal - bottom - matched", 200, -200, 200)); + + plots2D.put("Ecal cluster x v track x @ Ecal - bottom - matched", + histogramFactory.createHistogram2D("Ecal cluster x v track x @ Ecal - bottom - matched", 200, -200, 200, 200, -200, 200)); + + plots1D.put("Ecal cluster y - track y @ Ecal - bottom - matched", + histogramFactory.createHistogram1D("Ecal cluster y - track y @ Ecal - bottom - matched", 100, -100, 100)); + + plots2D.put("Ecal cluster y v track y @ Ecal - bottom - matched", + histogramFactory.createHistogram2D("Ecal cluster y v track @ Ecal - bottom - matched", 100, -100, 100, 100, -100, 100)); + + } + + /** + * Save the histograms to a ROO file + */ + public void saveHistograms() { + String rootFile = "track_cluster_matching_plots.root"; RootFileStore store = new RootFileStore(rootFile); try { store.open(); store.add(tree); - store.close(); + store.close(); } catch (IOException e) { e.printStackTrace(); } Modified: java/trunk/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java ============================================================================= --- java/trunk/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java (original) +++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/TrackUtils.java Mon Sep 21 17:21:37 2015 @@ -1272,4 +1272,12 @@ return new Line(r0, phi, lambda); } + public static TrackState getTrackStateAtECal(Track trk) { + for (TrackState state : trk.getTrackStates()) { + if (state.getLocation() == TrackState.AtCalorimeter) { + return state; + } + } + return null; + } }