Print

Print


Commit in java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield on MAIN
HitOnTrackChecker.java+32added 818
StraightTrack.java+261added 818
StraightTrackFinder.java+204added 818
TrackChecker.java+22added 818
+519
4 added files
A first shot at straight track == 0 b-field tracking.  Still lots to do to get this more flexible...this may lead to an HPS-specific tracking routine.  

java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield
HitOnTrackChecker.java added at 818
--- java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/HitOnTrackChecker.java	                        (rev 0)
+++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/HitOnTrackChecker.java	2014-07-22 17:23:29 UTC (rev 818)
@@ -0,0 +1,32 @@
+package org.hps.recon.tracking.nobfield;
+
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+
+/**
+ *
+ * @author mgraham
+ */
+public class HitOnTrackChecker {
+
+    //define some criteria for adding this hit to  a track prior to track fit
+    private double _maxDeltaX;
+    private double _maxDeltaY;
+
+    public HitOnTrackChecker() {
+
+    }
+
+    public boolean checkNewHit(StraightTrack trk, HelicalTrackHit newhit) {
+
+        return true;
+    }
+
+    public void setDeltaX(double del) {
+        _maxDeltaX = del;
+    }
+
+    public void setDeltaY(double del) {
+        _maxDeltaY = del;
+    }
+
+}

java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield
StraightTrack.java added at 818
--- java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/StraightTrack.java	                        (rev 0)
+++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/StraightTrack.java	2014-07-22 17:23:29 UTC (rev 818)
@@ -0,0 +1,261 @@
+package org.hps.recon.tracking.nobfield;
+
+import hep.physics.matrix.SymmetricMatrix;
+import static java.lang.Math.abs;
+import static java.lang.Math.signum;
+import java.util.ArrayList;
+import java.util.List;
+import org.lcsim.constants.Constants;
+import org.lcsim.event.LCIOParameters;
+import org.lcsim.event.Track;
+import org.lcsim.event.TrackState;
+import org.lcsim.event.TrackerHit;
+import static org.lcsim.event.base.BaseTrack.D0;
+import static org.lcsim.event.base.BaseTrack.OMEGA;
+import static org.lcsim.event.base.BaseTrack.PHI;
+import static org.lcsim.event.base.BaseTrack.TANLAMBDA;
+import static org.lcsim.event.base.BaseTrack.Z0;
+import org.lcsim.event.base.BaseTrackState;
+
+/**
+ *
+ * @author mgraham
+ */
+public class StraightTrack implements Track {
+
+    protected int _type;
+    protected int[] _subdetId = new int[1];
+    // References to other objects.
+    protected List<Track> _tracks;
+    protected List<TrackerHit> _hits;
+    protected List<TrackState> _trackStates;
+    protected double[] _chi2 = new double[2];
+    protected double[] _parameters = new double[5];
+    // Parameter ordering.
+    public static final int x0 = LCIOParameters.ParameterName.d0.ordinal();
+    public static final int slopeXZ = LCIOParameters.ParameterName.phi0.ordinal();
+    public static final int y0 = LCIOParameters.ParameterName.omega.ordinal();
+    public static final int slopeYZ = LCIOParameters.ParameterName.tanLambda.ordinal();
+
+    /**
+     * Creates a new instance of StraightTrack
+     */
+    public StraightTrack() {
+        _tracks = new ArrayList<Track>();
+        _hits = new ArrayList<TrackerHit>();
+        _trackStates = new ArrayList<TrackState>();
+    }
+
+    /**
+     * This gets the first TrackState as a BaseTrackState, so it can be
+     * modified. It will create
+     * this TrackState, if it doesn't exist already.
+     *
+     * @return The first TrackState.
+     */
+    private BaseTrackState getFirstTrackState() {
+        if (_trackStates.size() == 0)
+            _trackStates.add(new BaseTrackState());
+        return (BaseTrackState) _trackStates.get(0);
+    }
+    // add following setters for subclasses.
+
+    public void setTrackParameters(double[] params) {
+        // Copy to this object's parameters array.
+        System.arraycopy(params, 0, _parameters, 0, 5);
+
+        // LCIO v2 ... setup a TrackState with full parameter list.
+        getFirstTrackState().setParameters(params, 0);
+    }
+
+    /**
+     * Add a hit to this track.
+     *
+     * @param hit The TrackerHit to add to this track.
+     */
+    public void addHit(TrackerHit hit) {
+        _hits.add(hit);
+    }
+
+    /**
+     * Add a list of hits to this track.
+     *
+     * @param hits The list of TrackerHits to add to this track.
+     */
+    public void addHits(List<TrackerHit> hits) {
+        _hits.addAll(hits);
+    }
+
+    /**
+     * The ids of the subdetectors hit by this track. Not yet defined.
+     *
+     * @return a list of integers representing the subdetector ids hit by this
+     * track.
+     */
+    // TODO establish what this means.
+    public int[] getSubdetectorHitNumbers() {
+        return _subdetId;
+    }
+
+    public void setSubdetectorHitNumbers(int[] subdetId) {
+        this._subdetId = subdetId;
+    }
+
+    /**
+     * If this is a composite track, return a list of constituent tracks.
+     *
+     * @return the list of individual tracks of which this track is composed.
+     */
+    public List<Track> getTracks() {
+        return _tracks;
+    }
+
+    /**
+     * Return the list of tracker hits of which this track is composed.
+     *
+     * @return the list of hits on this track.
+     */
+    public List<TrackerHit> getTrackerHits() {
+        return _hits;
+    }
+
+    /**
+     * Return the type of this track. Not yet defined.
+     *
+     * @return an integer representation of the type of this track.
+     */
+    public int getType() {
+        return _type;
+    }
+
+    /**
+     * Get the list of associated <code>TrackState</code> objects.
+     *
+     * @return The list of TrackStates.
+     */
+    public List<TrackState> getTrackStates() {
+        return this._trackStates;
+    }
+
+    @Override
+    public int getCharge() {
+        throw new UnsupportedOperationException("StraightTrack...no momentum measured."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double[] getReferencePoint() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getReferencePointX() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getReferencePointY() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getReferencePointZ() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public boolean isReferencePointPCA() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double[] getMomentum() {
+        throw new UnsupportedOperationException("StraightTrack...no momentum measured."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getPX() {
+        throw new UnsupportedOperationException("StraightTrack...no momentum measured."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getPY() {
+        throw new UnsupportedOperationException("StraightTrack...no momentum measured."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getPZ() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public boolean fitSuccess() {
+        throw new UnsupportedOperationException("StraightTrack...no momentum measured."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getTrackParameter(int i) {
+        return _parameters[i];
+    }
+
+    @Override
+    public double[] getTrackParameters() {
+        return _parameters;
+    }
+
+    @Override
+    public SymmetricMatrix getErrorMatrix() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getChi2() {
+        return _chi2[0] + _chi2[1];
+    }
+
+    public double getChi2X() {
+        return _chi2[0];
+    }
+
+    public double getChi2Y() {
+        return _chi2[1];
+    }
+
+    public void setChi2(double chiX, double chiY) {
+        _chi2[0] = chiX;
+        _chi2[1] = chiY;
+    }
+
+    @Override
+    public int getNDF() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getdEdx() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getdEdxError() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public double getRadiusOfInnermostHit() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    public String toString() {
+        String className = getClass().getName();
+        int lastDot = className.lastIndexOf('.');
+        if (lastDot != -1)
+            className = className.substring(lastDot + 1);
+        StringBuffer sb = new StringBuffer(className + ": Type: " + _type + "\n");
+        sb.append("x0= " + _parameters[x0] + "\n");
+        sb.append("slopeXZ= " + _parameters[slopeXZ] + "\n");
+        sb.append("y0: " + _parameters[y0] + "\n");
+        sb.append("slopeYZ= " + _parameters[slopeYZ] + "\n");
+        return sb.toString();
+    }
+
+}

java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield
StraightTrackFinder.java added at 818
--- java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/StraightTrackFinder.java	                        (rev 0)
+++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/StraightTrackFinder.java	2014-07-22 17:23:29 UTC (rev 818)
@@ -0,0 +1,204 @@
+package org.hps.recon.tracking.nobfield;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.hps.recon.tracking.HitCollectionUtilites;
+import org.lcsim.event.EventHeader;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+import org.lcsim.fit.line.SlopeInterceptLineFit;
+import org.lcsim.fit.line.SlopeInterceptLineFitter;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * @author mgraham
+ */
+public class StraightTrackFinder extends Driver {
+
+    // Debug flag.
+    private boolean debug = false;
+    // Tracks found across all events.
+    int ntracks = 0;
+    // Number of events processed.
+    int nevents = 0;
+    // Cache detector object.
+    Detector detector = null;
+    // Tracking strategies resource path.
+    private String strategyResource = "HPS-Test-4pt1.xml";
+    // Output track collection.
+    private String trackCollectionName = "StraightTracks";
+    // HelicalTrackHit input collection.
+    private String stInputCollectionName = "HelicalTrackHits";
+    // Include MS (done by removing XPlanes from the material manager results)
+    private boolean includeMS = true;
+    // number of repetitive fits on confirmed/extended tracks
+    private int _iterativeConfirmed = 3;
+    // use HPS implementation of material manager
+    private boolean _useHPSMaterialManager = true;
+    // enable the use of sectoring using sector binning in SeedTracker
+    private boolean _applySectorBinning = true;
+
+    private SlopeInterceptLineFitter _lfitter = new SlopeInterceptLineFitter();
+
+    public void setDebug(boolean debug) {
+        this.debug = debug;
+    }
+
+    /**
+     * Set the tracking strategy resource.
+     *
+     * @param strategyResource The absolute path to the strategy resource in the
+     * hps-java jar.
+     */
+    public void setStrategyResource(String strategyResource) {
+        this.strategyResource = strategyResource;
+    }
+
+    public void setInputHitCollectionName(String inputHitCollectionName) {
+        this.stInputCollectionName = inputHitCollectionName;
+    }
+
+    public void setTrackCollectionName(String trackCollectionName) {
+        this.trackCollectionName = trackCollectionName;
+    }
+
+    public void setIncludeMS(boolean incMS) {
+        this.includeMS = incMS;
+    }
+
+    /**
+     * Set to enable the use of the HPS material manager implementation
+     *
+     * @param useHPSMaterialManager switch
+     */
+    public void setUseHPSMaterialManager(boolean useHPSMaterialManager) {
+        this._useHPSMaterialManager = useHPSMaterialManager;
+    }
+
+    /**
+     * This is used to setup the Drivers after XML config.
+     */
+    @Override
+    public void detectorChanged(Detector detector) {
+        // Cache Detector object.
+        this.detector = detector;
+//        initialize();
+        super.detectorChanged(detector);
+    }
+
+    @Override
+    public void process(EventHeader event) {
+        if (!event.hasCollection(HelicalTrackHit.class, stInputCollectionName))
+            return;
+
+        List<HelicalTrackHit> allHits = event.get(HelicalTrackHit.class, stInputCollectionName);
+        if (allHits.size() == 0)
+            return;
+        List<List<HelicalTrackHit>> splitTopBot = HitCollectionUtilites.SplitTopBottomHits(allHits);
+        // will always have top(=0) and bottom(=1) lists (though they may be empty)
+        List<HelicalTrackHit> topHits = splitTopBot.get(0);
+        List<HelicalTrackHit> bottomHits = splitTopBot.get(1);
+        //a simple strategy...eventually implement SeedTracker strategies
+        int nTotLayers = 6;
+        int[] layerStrategy = {1, 3, 5, 7, 9, 11};
+        int minHits = 4;
+
+        List<StraightTrack> trackList = new ArrayList<>();
+//sort the hits for some reason
+//        List<List<HelicalTrackHit>> sortedTopHits=new ArrayList<>();
+//         List<List<HelicalTrackHit>> sortedBottomHits=new ArrayList<>();
+//        for(int i = 0;i<nTotLayers;i++){
+//            List<HelicalTrackHit> sortedTop=HitCollectionUtilites.GetSortedHits(topHits,layerStrategy[i]);
+//            sortedTopHits.add(sortedTop);
+//            List<HelicalTrackHit> sortedBot=HitCollectionUtilites.GetSortedHits(bottomHits,layerStrategy[i]);
+//            sortedBottomHits.add(sortedBot);                      
+//        }
+//        
+        if (topHits.size() < 4)
+            return;
+        //first do top...
+        for (HelicalTrackHit h1 : HitCollectionUtilites.GetSortedHits(topHits, layerStrategy[0])) {
+            if (debug)
+                System.out.println(h1.toString());
+            for (HelicalTrackHit h2 : HitCollectionUtilites.GetSortedHits(topHits, layerStrategy[1])) {
+                if (debug)
+                    System.out.println(h2.toString());
+                for (HelicalTrackHit h3 : HitCollectionUtilites.GetSortedHits(topHits, layerStrategy[2])) {
+                    if (debug)
+                        System.out.println(h3.toString());
+                    for (HelicalTrackHit h4 : HitCollectionUtilites.GetSortedHits(topHits, layerStrategy[3])) {
+                        if (debug)
+                            System.out.println(h4.toString());
+                        for (HelicalTrackHit h5 : HitCollectionUtilites.GetSortedHits(topHits, layerStrategy[4])) {
+                            if (debug)
+                                System.out.println(h5.toString());
+                            //  Setup for the line fit
+                            List<HelicalTrackHit> testTrack = new ArrayList<HelicalTrackHit>();
+                            testTrack.add(h1);
+                            testTrack.add(h2);
+                            testTrack.add(h3);
+                            testTrack.add(h4);
+                            testTrack.add(h5);
+                            SlopeInterceptLineFit xfit = FitToLine(testTrack, 0);
+                            SlopeInterceptLineFit yfit = FitToLine(testTrack, 1);
+                            if (debug)
+                                System.out.println("xfit = " + xfit.toString());
+                            if (debug)
+                                System.out.println("yfit = " + yfit.toString());
+                            StraightTrack trk = makeTrack(xfit, yfit);
+                            trackList.add(trk);
+                        }
+                    }
+                }
+            }
+        }
+
+        event.put(trackCollectionName, trackList);
+    }
+
+    public SlopeInterceptLineFit FitToLine(List<HelicalTrackHit> hits, int projection) {
+        SlopeInterceptLineFit _lfit;
+        int npix = hits.size();
+        double[] s = new double[npix];
+        double[] q = new double[npix];
+        double[] dq = new double[npix];
+
+        //  Store the coordinates and errors for the line fit
+        for (int i = 0; i < npix; i++) {
+            HelicalTrackHit hit = hits.get(i);
+            s[i] = hit.z();//probably isn't quite right...track length is not z
+            if (projection == 0) { //do x vs z;
+                q[i] = hit.x();
+                dq[i] = Math.sqrt(hit.getCorrectedCovMatrix().e(0, 0));
+            } else {
+                q[i] = hit.y();
+                dq[i] = Math.sqrt(hit.getCorrectedCovMatrix().e(1, 1));
+            }
+        }
+
+        //  Call the line fitter and check for success
+        boolean success = _lfitter.fit(s, q, dq, npix);
+
+        if (!success)
+            System.out.println("Something is broken in the line fit");
+        //  Save the line fit, chi^2, and DOF
+        _lfit = _lfitter.getFit();
+        return _lfit;
+
+    }
+
+    private StraightTrack makeTrack(SlopeInterceptLineFit xfit, SlopeInterceptLineFit yfit) {
+        StraightTrack track = new StraightTrack();
+        double[] pars = {-99, -99, -99, -99};
+        pars[0] = xfit.intercept();
+        pars[1] = xfit.slope();
+        pars[2] = yfit.intercept();
+        pars[3] = yfit.slope();
+        track.setTrackParameters(pars);
+        track.setChi2(xfit.chisquared(), yfit.chisquared());
+        // TODO:  set convariance, 
+        return track;
+    }
+
+}

java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield
TrackChecker.java added at 818
--- java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/TrackChecker.java	                        (rev 0)
+++ java/trunk/tracking/src/main/java/org/hps/recon/tracking/nobfield/TrackChecker.java	2014-07-22 17:23:29 UTC (rev 818)
@@ -0,0 +1,22 @@
+package org.hps.recon.tracking.nobfield;
+
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+
+/**
+ *
+ * @author mgraham
+ */
+public class TrackChecker {
+
+    //define some criteria for keeping/rejecting a track
+    
+    public TrackChecker() {
+
+    }
+
+    public boolean checkTrack(StraightTrack trk) {
+
+        return true;
+    }
+
+}
SVNspam 0.1