Commit in lcsim on MAIN | |||
sandbox/backup/AbstractTrack.java | +40 | added 1.1 | |
/BaseTrack.java | +408 | added 1.1 | |
/BasicTrack.java | +189 | added 1.1 | |
/FastMCTrack.java | +190 | added 1.1 | |
/FoundTrack.java | +39 | added 1.1 | |
/GarfieldTrack.java | +969 | added 1.1 | |
/LCIOConstants.java | +97 | added 1.1 | |
/MakeTracks.java | +101 | added 1.1 | |
/ReconTrack.java | +562 | added 1.1 | |
/SIOTrack.java | +136 | added 1.1 | |
/SeedTrackerTrackStateDriver.java | +167 | added 1.1 | |
/Track.java | +131 | added 1.1 | |
/TrackTableModel.java | +30 | added 1.1 | |
/ZvTrack.java | +613 | added 1.1 | |
src/org/lcsim/event/TrackState.java | +90 | 1.1 -> 1.2 | |
/Track.java | +3 | -1 | 1.11 -> 1.12 |
src/org/lcsim/event/base/BaseTrackState.java | +249 | 1.1 -> 1.2 | |
/BaseTrack.java | +90 | -56 | 1.12 -> 1.13 |
src/org/lcsim/mc/fast/tracking/ReconTrack.java | +9 | -2 | 1.10 -> 1.11 |
src/org/lcsim/mc/fast/tracking/fix/FastMCTrack.java | +8 | -2 | 1.1 -> 1.2 |
src/org/lcsim/plugin/browser/TrackTableModel.java | +27 | -5 | 1.3 -> 1.4 |
src/org/lcsim/recon/cat/GarfieldTrack.java | +5 | -2 | 1.2 -> 1.3 |
src/org/lcsim/recon/cat/util/BasicTrack.java | +6 | -1 | 1.3 -> 1.4 |
src/org/lcsim/recon/tracking/seedtracker/MakeTracks.java | +4 | -7 | 1.4 -> 1.5 |
/SeedTrackerTrackStateDriver.java | +212 | -5 | 1.8 -> 1.9 |
src/org/lcsim/recon/vertexing/zvtop4/ZvTrack.java | +11 | -9 | 1.24 -> 1.25 |
src/org/lcsim/recon/ztracking/AbstractTrack.java | +5 | 1.3 -> 1.4 | |
/FoundTrack.java | +5 | 1.3 -> 1.4 | |
src/org/lcsim/util/lcio/LCIOConstants.java | +5 | -3 | 1.15 -> 1.16 |
/SIOTrack.java | +175 | -117 | 1.5 -> 1.6 |
+4576 | -210 |
manual merge in of lcio v2 branch; should fix problem with reading in MarlinReco output
diff -N AbstractTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ AbstractTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,40 @@
+/* AbstractTrack.java + + Abstract track used in implementing the LCSim Track interface. + + Created by Mike Ronan July '00 + Modified by + + */ + +package org.lcsim.recon.ztracking; + +import hep.physics.matrix.SymmetricMatrix; +import org.lcsim.event.Track; +import org.lcsim.event.TrackerHit; +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractTrack implements Track +{ + public double[] getReferencePoint() { double[] point = new double[] {0.,0.,0.}; return point; } + public double getReferencePointX() { return 0.; } + public double getReferencePointY() { return 0.; } + public double getReferencePointZ() { return 0.; } + public boolean isReferencePointPCA() { return false; } + + public boolean fitSuccess() { return false; } + public double getTrackParameter(int i) { return 0.; } + public double[] getTrackParameters() { double[] parameters = new double[] {0.,0.,0.,0.,0.}; return parameters; } + public SymmetricMatrix getErrorMatrix() { return new SymmetricMatrix(5); } + public double getChi2() { return 0.; } + public int getNDF() { return 0; } + + public double getdEdx() { return 0.; } + public double getdEdxError() { return 0.; } + public double getRadiusOfInnermostHit() { return 0.; } + public int[] getSubdetectorHitNumbers() { int[] hitNumbers = new int[]{0}; return hitNumbers; } + public List<Track> getTracks() { List<Track> list = new ArrayList<Track>(); return list; } + public List<TrackerHit> getTrackerHits() { List<TrackerHit> list = new ArrayList<TrackerHit>(); return list; } + public int getType() { return 0; } +}
diff -N BaseTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ BaseTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,408 @@
+/* + * BaseTrack.java + * + * Created on March 24, 2006, 9:18 PM + * + * $Id: BaseTrack.java,v 1.1 2012/06/18 23:02:13 jeremy Exp $ + */ + +package org.lcsim.event.base; + +import hep.physics.matrix.SymmetricMatrix; +import java.util.List; +import java.util.ArrayList; +import org.lcsim.constants.Constants; +import org.lcsim.event.LCIOParameters; +import org.lcsim.event.LCIOParameters.ParameterName; +import org.lcsim.event.Track; +import org.lcsim.event.TrackerHit; + +import static java.lang.Math.abs; +import static java.lang.Math.signum; +/** + * + * @author Norman Graf + */ +public class BaseTrack implements Track +{ + protected double[] _refPoint = new double[3]; + protected boolean _refPointIsDCA = true; + protected double[] _parameters = new double[5]; + protected SymmetricMatrix _covMatrix = new SymmetricMatrix(5); + protected double[] _momentum = new double[3]; + protected int _charge; + protected boolean _fitSuccess = true; + protected double _chi2; + protected int _ndf; + protected double _dEdx; + protected double _dEdxErr; + protected double _innermostHitRadius = 9999.; + protected int[] _subdetId = new int[1]; + protected List<Track> _tracks; + protected List<TrackerHit> _hits; + protected int _type; + + protected static final int D0 = ParameterName.d0.ordinal(); + protected static final int PHI = ParameterName.phi0.ordinal(); + protected static final int OMEGA = ParameterName.omega.ordinal(); + protected static final int TANLAMBDA = ParameterName.tanLambda.ordinal(); + protected static final int Z0 = ParameterName.z0.ordinal(); + + /** Creates a new instance of BaseTrack */ + public BaseTrack() + { + _tracks = new ArrayList<Track>(); + _hits = new ArrayList<TrackerHit>(); + } + + // add following setters for subclasses. + + // TODO replace this with a SpacePoint + /** + * Set the reference point for this track. By default it is (0,0,0). + * By definition, DCA, etc. is measured with respect to this point. + * @param point The (x,y,z) reference point for this track. + */ + public void setReferencePoint(double[] point) + { + _refPoint = point; + } + + /** + * Sets whether the reference point is the distance of closest + * approach to the origin. + * @param isDCA true if the reference point is the dca. + */ + // TODO clarify this. + public void setRefPointIsDCA(boolean isDCA) + { + _refPointIsDCA = isDCA; + } + + /** + * If the track has been successfully set, this should be set. + * Should only be set if the results of the fit are also set. + * Should encapsulate all this in a Fit object. + * False by default. + * @param success true if the track has successfully been set. + */ + public void setFitSuccess( boolean success) + { + _fitSuccess = success; + } + + /** + * Set the track parameters. + * @see LCIOParameters + * @param params The array of track parameters. + */ + public void setTrackParameters(double[] params, double magneticField) + { + System.arraycopy(params, 0, _parameters, 0, 5); + double omega = _parameters[OMEGA]; + if(abs(omega) < 0.0000001) omega=0.0000001; + double Pt = abs((1./omega) * magneticField* Constants.fieldConversion); + _momentum[0] = Pt * Math.cos(_parameters[PHI]); + _momentum[1] = Pt * Math.sin(_parameters[PHI]); + _momentum[2] = Pt * _parameters[TANLAMBDA]; + _charge = (int) signum(omega); + } + + /** + * Set the covariance matrix for the track parameters. + * @param cov The covariance matrix as a double array. + */ + public void setCovarianceMatrix(SymmetricMatrix cov) + { + _covMatrix = cov; + } + + /** + * Set the chi-squared for the track fit. + * Not defined whether this is the full or reduced chi-squared. + * @param chisq The value of the track fit chi-squared. + */ +// TODO verify if this is full or reduced chi-squared. + public void setChisq( double chisq) + { + _chi2 = chisq; + } + + /** + * Set the number of degrees of freedom for this track fit. + * @param n The number of degrees of freedom for this track fit. + */ + public void setNDF( int n) + { + _ndf = n; + } + + /** + * Set the track type. Note that this is still undefined. + * @param type The track type + */ +// TODO define this. replace int by enumeration. + public void setTrackType(int type) + { + _type = type; + } + + /** + * Add a hit to this track. + * @param hit The TrackerHit to add to this track. + */ + public void addHit(TrackerHit hit) + { + _hits.add(hit); + double[] pos = hit.getPosition(); + double radius = pos[0]*pos[0]+pos[1]*pos[1]; + if(radius < _innermostHitRadius*_innermostHitRadius) + { + _innermostHitRadius = Math.sqrt(radius); + } + _dEdx += hit.getdEdx(); + } + + /** + * 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); + for(TrackerHit hit : hits) + { + double[] pos = hit.getPosition(); + double radius = pos[0]*pos[0]+pos[1]*pos[1]; + if(radius < _innermostHitRadius*_innermostHitRadius) + { + _innermostHitRadius = Math.sqrt(radius); + } + _dEdx += hit.getdEdx(); + } + } + + // TODO finish this... + 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+" charge: "+ _charge+"\n"); + sb.append("d0= "+_parameters[D0]+"\n"); + sb.append("phi0= "+_parameters[PHI]+"\n"); + sb.append("curvature: "+_parameters[OMEGA]+"\n"); + sb.append("z0= "+_parameters[Z0]+"\n"); + sb.append("tanLambda= "+_parameters[TANLAMBDA]+"\n"); + sb.append(" px="+getPX()+" py= "+getPY()+" pz= "+getPZ()); + return sb.toString(); + } + + +// TODO add convenience methods to replace clunky interface +// Track interface + + /** + * The charge of the particle creating this track in units of the electron charge. + * @return The charge of the track. + */ + public int getCharge() + { + return _charge; + } + + /** + * Return the reference point of this track. Need to clarigy whether this is a point + * on the track or not. + * @return The reference point for this track. + */ +// TODO augment this with a SpacePoint. + public double[] getReferencePoint() + { + return _refPoint; + } + /** + * Return the x position of the reference point for this track. + * @return The x position of the reference point for this track. + */ + public double getReferencePointX() + { + return _refPoint[0]; + } + /** + * Return the y position of the reference point for this track. + * @return The y position of the reference point for this track. + */ + public double getReferencePointY() + { + return _refPoint[1]; + } + /** + * Return the z position of the reference point for this track. + * @return The z position of the reference point for this track. + */ + public double getReferencePointZ() + { + return _refPoint[2]; + } + /** + * Is the reference point for this track the DCA? This needs clarification + * @return true if the reference point is the dca. + */ +// TODO clarify what this means. + public boolean isReferencePointPCA() + { + return false; + } + /** + * The cartesian momentum for this track (px, py, pz) + * @return The momentum of this track. + */ + public double[] getMomentum() + { + return _momentum; + } + /** + * The x component of the momentum of this track. + * @return The x component of the momentum of this track. + */ + public double getPX() + { + return _momentum[0]; + } + /** + * The y component of the momentum of this track. + * @return The y component of the momentum of this track. + */ + public double getPY() + { + return _momentum[1]; + } + /** + * The z component of the momentum of this track. + * @return The z component of the momentum of this track. + */ + public double getPZ() + { + return _momentum[2]; + } + + /** + * Return whether the track was successfully fit. + * @return true if this track was successfully fir. + */ + public boolean fitSuccess() + { + return _fitSuccess; + } + /** + * Return an individual track parameter + *@see Track.Parameter + * @param i the index of the track parameter desired + * @return The value of the ith track parameter + */ + public double getTrackParameter(int i) + { + return _parameters[i]; + } + /** + * Return the track parameters. + *@see Track.Parameter + * @return The track parameters. + */ + public double[] getTrackParameters() + { + return _parameters; + } + + /** + *Return the track covariance matrix. + * @return the track covariance matrix as an array. + */ + public SymmetricMatrix getErrorMatrix() + { + return _covMatrix; + } + /** + * The track fit chi-squared. + * @return The chi-squared of the track fit. + */ + public double getChi2() + { + return _chi2; + } + /** + * The number of degrees of freedom in the track fit. + * @return The number of degrees of freedom in the track fit. + */ + public int getNDF() + { + return _ndf; + } + + /** + * The ionization associated with this track. + * @return the energy deposited along this track in GeV. + */ + public double getdEdx() + { + return _dEdx; + } + /** + * The uncertainty on the ionization associated with this track. + * @return The uncertainty on the ionization associated with this track. + */ + public double getdEdxError() + { + return _dEdxErr; + } + /** + * The innermost radius of a hit on this track. For values smaller than this + * the track must be, or has been, extrapolated. + * @return The innermost radius of a hit on this track. + */ +// TODO verify that this is in global coordinates, not wrt reference point. + public double getRadiusOfInnermostHit() + { + return _innermostHitRadius; + } + /** + * 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. + */ +// TODO define what this means. + public int getType() + { + return _type; + } +}
\ No newline at end of file
diff -N BasicTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ BasicTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,189 @@
+package org.lcsim.recon.cat.util; + +import java.util.*; +import org.lcsim.event.*; +import org.lcsim.util.*; +import hep.physics.matrix.SymmetricMatrix; +import org.lcsim.spacegeom.SpacePoint; +import org.lcsim.spacegeom.SpaceVector; +import org.lcsim.conditions.ConditionsListener; +import org.lcsim.conditions.ConditionsEvent; +import org.lcsim.conditions.ConditionsManager; +import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException; +import org.lcsim.geometry.Detector; +import org.lcsim.util.swim.HelixSwimmer; + +/** + * Basic implementation of {@link org.lcsim.event.Track} interface. + * Includes method for initializing track parameters from momentum at a given point. + * + * @author D. Onoprienko + * @version $Id: BasicTrack.java,v 1.1 2012/06/18 23:02:13 jeremy Exp $ + */ +public class BasicTrack implements Track { + +// -- Constructors and static initialization : -------------------------------- + + /** + * Initialization of static members. + * Runs automatically once the detector classes have been initialized. + */ + static public void initialize(Detector detector) { + _bField = detector.getFieldMap().getField(new double[]{0.,0.,0.})[2]; + _swimmer = new HelixSwimmer(_bField); + } + + /** Default constructor. */ + public BasicTrack() { + _refPoint = new double[3]; + _refPointIsPCA = false; + _parameters = new double[5]; + _covMatrix = new SymmetricMatrix(5); + _momentum = new double[3]; + _charge = 0; + _fitSuccess = false; + _chi2 = 0.; + _ndf = 1; + _dEdx = 0.; + _dEdxErr = 0.; + _innermostHitRadius = 9999.; + _nHitsSubdet = new int[4]; + _tracks = new ArrayList<Track>(1); + _hits = new ArrayList<TrackerHit>(1); + _type = 0; + } + + /** Copy constructor. */ + public BasicTrack(BasicTrack track) { + _refPoint = new double[3]; + System.arraycopy(track._refPoint, 0, _refPoint, 0, 3); + _refPointIsPCA = track._refPointIsPCA; + _parameters = new double[5]; + System.arraycopy(track._parameters, 0, _parameters, 0, 5); + _covMatrix = new SymmetricMatrix(track._covMatrix); + _momentum = new double[3]; + System.arraycopy(track._momentum, 0, _momentum, 0, 3); + _charge = track._charge; + _fitSuccess = track._fitSuccess; + _chi2 = track._chi2; + _ndf = track._ndf; + _dEdx = track._dEdx; + _dEdxErr = track._dEdxErr; + _innermostHitRadius = track._innermostHitRadius; + _nHitsSubdet = new int[4]; + System.arraycopy(track._nHitsSubdet, 0, _nHitsSubdet, 0, 4); + _tracks = new ArrayList<Track>(track._tracks); + _hits = new ArrayList<TrackerHit>(track._hits); + _type = track._type; + } + +// -- Standard getters (implementing Track interface) : ----------------------- + + public int getCharge() {return _charge;} + + public double[] getReferencePoint() {return _refPoint;} + public double getReferencePointX() {return _refPoint[0];} + public double getReferencePointY() {return _refPoint[1];} + public double getReferencePointZ() {return _refPoint[2];} + + public boolean isReferencePointPCA() {return _refPointIsPCA;} + + public double[] getMomentum() {return _momentum;} + public double getPX() {return _momentum[0];} + public double getPY() {return _momentum[1];} + public double getPZ() {return _momentum[2];} + + public double[] getTrackParameters() {return _parameters;} + public double getTrackParameter(int i) {return _parameters[i];} + public SymmetricMatrix getErrorMatrix() {return _covMatrix;} + + public boolean fitSuccess() {return _fitSuccess;} + public double getChi2() {return _chi2;} + public int getNDF() {return _ndf;} + + public double getdEdx() {return _dEdx;} + public double getdEdxError() {return _dEdxErr;} + + public double getRadiusOfInnermostHit() {return _innermostHitRadius;} + + public int[] getSubdetectorHitNumbers() {return _nHitsSubdet;} + + public List<Track> getTracks() {return _tracks;} + + public List<TrackerHit> getTrackerHits() {return _hits;} + + public int getType() {return _type;} + +// -- Additional getters : ---------------------------------------------------- + + /** Returns transverse momentum of the track. */ + public double getPt() { + return Math.hypot(_momentum[0], _momentum[1]); + } + + /** Returns amplitude of the track momentum. */ + public double getP() { + double[] p = getMomentum(); + return Math.sqrt(_momentum[0]*_momentum[0]+_momentum[1]*_momentum[1]+_momentum[2]*_momentum[2]); + } + +// -- Setters : --------------------------------------------------------------- + + /** Add track to the list of tracks associated with this track. */ + public void addTrack(Track track) {_tracks.add(track);} + + /** Removes track from the list of tracks associated with this track. */ + public void removeTrack(Track track) {_tracks.remove(track);} + + /** Remove all tracks from the list of tracks associated with this track. */ + public void removeTracks() {_tracks.clear();} + + public void setHelixParameters(SpacePoint refPoint, SpacePoint position, SpaceVector momentum, int charge) { + _refPoint = refPoint.v(); + _swimmer.setTrack(momentum, position, charge); + double alpha = _swimmer.getTrackLengthToPoint(refPoint); + SpacePoint poca = _swimmer.getPointAtLength(alpha); + SpaceVector momentumAtPoca = _swimmer.getMomentumAtLength(alpha); + LCIOParameters parameters = LCIOParameters.SpaceMomentum2Parameters(poca, momentumAtPoca, refPoint, charge, _bField); + _parameters = parameters.getValues(); + _momentum = momentumAtPoca.v(); + _charge = charge; + } + +// -- Private parts : --------------------------------------------------------- + + protected double[] _refPoint; + protected boolean _refPointIsPCA; + protected double[] _parameters; + protected SymmetricMatrix _covMatrix; + protected double[] _momentum; + protected int _charge; + protected boolean _fitSuccess; + protected double _chi2; + protected int _ndf; + protected double _dEdx; + protected double _dEdxErr; + protected double _innermostHitRadius; + protected int[] _nHitsSubdet; + protected ArrayList<Track> _tracks; + protected ArrayList<TrackerHit> _hits; + protected int _type; + + protected static double _bField; + protected static HelixSwimmer _swimmer; + + protected static ConditionsListener _conListener = new ConditionsListener() { + public void conditionsChanged(ConditionsEvent event) { + ConditionsManager conMan = (event == null) ? ConditionsManager.defaultInstance() : event.getConditionsManager(); + try { + Detector det = conMan.getCachedConditions(Detector.class,"compact.xml").getCachedData(); + initialize(det); + } catch (ConditionsSetNotFoundException x) {} + } + }; + static { + ConditionsManager.defaultInstance().addConditionsListener(_conListener); + _conListener.conditionsChanged(null); + } + +}
diff -N FastMCTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ FastMCTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,190 @@
+/** + * @version $Id: FastMCTrack.java,v 1.1 2012/06/18 23:02:13 jeremy Exp $ + */ +package org.lcsim.mc.fast.tracking.fix; + +import static java.lang.Math.sqrt; +import hep.physics.matrix.SymmetricMatrix; +import hep.physics.vec.Hep3Vector; + +import java.util.List; + +import org.lcsim.event.LCIOParameters; +import org.lcsim.event.MCParticle; +import org.lcsim.event.Track; +import org.lcsim.event.TrackerHit; +import org.lcsim.event.LCIOParameters.ParameterName; +import org.lcsim.spacegeom.CartesianPoint; +import org.lcsim.spacegeom.CartesianVector; +import org.lcsim.spacegeom.SpacePoint; +import org.lcsim.spacegeom.SpaceVector; + + +/** + * @author jstrube + * The class to store the measurement information of the track of a charged particle in a magnetic field. + * This class represents the FastMC simulation. + * An invariant of this class is that the "origin" is the point of closest approach to the reference point. + */ +public class FastMCTrack implements Track { + protected LCIOParameters _parameters; + protected SymmetricMatrix _errorMatrix; + protected SpacePoint _referencePoint; + protected int _charge; + protected MCParticle _particle = null; + + protected FastMCTrack(SpacePoint refPoint, LCIOParameters parameters, SymmetricMatrix errorMatrix, int charge) { + _referencePoint = refPoint; + _parameters = parameters; + _charge = charge; + _errorMatrix = errorMatrix; + } + + protected FastMCTrack(SpacePoint refPoint, LCIOParameters parameters, SymmetricMatrix errorMatrix, int charge, MCParticle part) { + this(refPoint, parameters, errorMatrix, charge); + _particle = part; + } + + public FastMCTrack(Track t) { + double[] p = t.getMomentum(); + double pt = sqrt(p[0]*p[0] + p[1]*p[1]); + _parameters = new LCIOParameters(t.getTrackParameters(), pt); + _errorMatrix = t.getErrorMatrix(); + _referencePoint = new CartesianPoint(t.getReferencePoint()); + _charge = t.getCharge(); + } + + public boolean fitSuccess() { + return false; + } + /* (non-Javadoc) + * @see org.lcsim.contrib.JanStrube.tracking.Track#getCharge() + */ + public int getCharge() { + return _charge; + } + + public double getChi2() { + return -1; + } + + public double getdEdx() { + return 0; + } + + public double getdEdxError() { + return 0; + } + + /* (non-Javadoc) + * @see org.lcsim.contrib.JanStrube.tracking.Track#getErrorMatrix() + */ + public SymmetricMatrix getErrorMatrix() { + return _errorMatrix; + } + + public MCParticle getMCParticle() { + return _particle; + } + + public double[] getMomentum() { + return momentum().v(); + } + + public int getNDF() { + return 0; + } + + /* (non-Javadoc) + * @see org.lcsim.contrib.JanStrube.tracking.Track#getParameter(org.lcsim.contrib.JanStrube.tracking.FastMCTrack.ParameterName) + */ + public double getParameter(ParameterName name) { + return _parameters.get(name); + } + + /* (non-Javadoc) + * @see org.lcsim.contrib.JanStrube.tracking.Track#getParameters() + */ + public LCIOParameters getParameters() { + return _parameters; + } + /* (non-Javadoc) + * @see org.lcsim.contrib.JanStrube.tracking.Track#getPt() + */ + public double getPt() { + return _parameters.getPt(); + } + public double getPX() { + return momentum().x(); + } + + public double getPY() { + return momentum().y(); + } + + public double getPZ() { + return momentum().z(); + } + + public double getRadiusOfInnermostHit() { + return -1; + } + + public double[] getReferencePoint() { + return _referencePoint.v(); + } + public double getReferencePointX() { + return referencePoint().x(); + } + + public double getReferencePointY() { + return referencePoint().y(); + } + + public double getReferencePointZ() { + return referencePoint().z(); + } + + public int[] getSubdetectorHitNumbers() { + return null; + } + + public List<TrackerHit> getTrackerHits() { + return null; + } + + public double getTrackParameter(int i) { + return _parameters.getValues()[i]; + } + + public double[] getTrackParameters() { + return _parameters.getValues(); + } + + public List<Track> getTracks() { + return null; + } + + public int getType() { + return 0; + } + + public boolean isReferencePointPCA() { + return true; + } + + public Hep3Vector momentum() { + return new CartesianVector(LCIOParameters.Parameters2Momentum(_parameters).v()); + } + + public SpacePoint position() { + return LCIOParameters.Parameters2Position(_parameters, _referencePoint); + } + + /* (non-Javadoc) + * @see org.lcsim.contrib.JanStrube.tracking.Track#getReferencePoint() + */ + public SpacePoint referencePoint() { + return _referencePoint; + } +}
diff -N FoundTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ FoundTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,39 @@
+/* FoundTrack.java + + Found track used in constructing cheater and reconstructed tracks. + + Created by Mike Ronan July '00 + Modified by + + */ + +package org.lcsim.recon.ztracking; + +import org.lcsim.event.SimTrackerHit; +import org.lcsim.event.TrackerHit; +import java.util.ArrayList; +import java.util.List; + + +public class FoundTrack extends AbstractTrack +{ + protected List<SimTrackerHit> list = new ArrayList(); + protected double p = 0., px = 0., py = 0., pz = 0.; + protected double[] momentum; + protected int charge = 0; + + /** */ + public FoundTrack() + { + } + + public void addHit(SimTrackerHit hit) { list.add(hit); } + public int getNPoints() { return list.size(); } + public List<SimTrackerHit> getHits() { return list; } + + public int getCharge() { return charge; } + public double getPX() { return px; } + public double getPY() { return py; } + public double getPZ() { return pz; } + public double[] getMomentum() { return momentum; } +}
diff -N GarfieldTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ GarfieldTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,969 @@
+package org.lcsim.recon.cat; + +import java.util.*; + +import hep.physics.matrix.SymmetricMatrix; +import org.lcsim.conditions.ConditionsListener; +import org.lcsim.conditions.ConditionsEvent; +import org.lcsim.conditions.ConditionsManager; +import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException; +import org.lcsim.event.*; +import org.lcsim.geometry.Detector; +import org.lcsim.util.Driver; + +import org.lcsim.recon.cat.util.Const; + + +/** + * Simple track format for linear collider detector. + * Used for calorimeter assisted tracking with the SiD. + * An example on how to create a track from 3D position measurements, + * please see {@link GarfieldTrackFinder}::testGenericTrackFit() + * + * @see GarfieldHit + * @see GarfieldHelix + * + * @author E. von Toerne + * @author D. Onoprienko + * @version $Id: GarfieldTrack.java,v 1.1 2012/06/18 23:02:13 jeremy Exp $ + */ +public class GarfieldTrack implements Track { + + // -- Data : ---------------------------------------------------------------- + + public ArrayList hits; + public GarfieldHelix hel; + private double[] trackPara; + private double minRadius; + private double maxRadius; + private String status; + private MipStub stub; + private int ID=0; + public int ndf; + private double chi2; + private double grade; // grade for track: high= good, low = bad + public int lastLayer; + public int nLayerMissed; + private boolean isEndcap=false; + private boolean hasZ = false; + public int nHits; + public int debugLevel; + private boolean trackDone=false; + + private MCParticle mcParticle; + private boolean mcParticleIsKnown; + + // Indexing array of parameters : + + static int PARA_d0 = 0; + static int PARA_phi0 = 1; + static int PARA_kappa = 2; + static int PARA_z0 = 3; + static int PARA_lambda = 4; + + static int maxEndcapLayer; + static int maxBarrelLayer; + static double chi2NdfFitEnd = 5.; + static double speedOfLight=0.299792458; + + static double emCalZ = 183.9*Const.cm; // EM Calorimeter endcap Z position; + + static ConditionsListener _conListener = new ConditionsListener() { + public void conditionsChanged(ConditionsEvent event) { + ConditionsManager conMan = (event == null) ? ConditionsManager.defaultInstance() : event.getConditionsManager(); + try { + Detector det = conMan.getCachedConditions(Detector.class,"compact.xml").getCachedData(); + initialize(det); + } catch (ConditionsSetNotFoundException x) {} + } + }; + static { + ConditionsManager.defaultInstance().addConditionsListener(_conListener); + _conListener.conditionsChanged(null); + } + + +// -- Constructors and static initialization: --------------------------------- + + /** + * Initialization of static members. + * Runs automatically once {@link org.lcsim.contrib.garfield.util.Const} has been initialized. + */ + public static void initialize(Detector detector) { + maxBarrelLayer = Const.det().VXD_BARREL.nLayers() + Const.det().TRACKER_BARREL.nLayers() - 1; + maxEndcapLayer = Const.det().VXD_BARREL.nLayers() + Const.det().TRACKER_ENDCAP.nLayers(); + } + + /** + * Default constructor. + */ + GarfieldTrack() { + hits = new ArrayList(); + hel = new GarfieldHelix(); + trackPara= new double[]{ 0.,0.,0.,0.,0. }; + minRadius = 0.; + maxRadius = 0.; + status = "DUMMY"; + lastLayer=-1; + nLayerMissed=0; + stub = null; + ndf = 0; + chi2 = 0.; + nHits=0; + debugLevel = 0; + mcParticleIsKnown = false; + } + + /** + * Construct GarfieldTrack from a {@link MipStub}. + */ + GarfieldTrack(MipStub mStub, int debugL) { + hits = new ArrayList(); + hel = new GarfieldHelix(mStub.base, mStub.dir, mStub.kappa); + hel.setDebugLevel(debugL); + trackPara= new double[]{ 0.,0.,0.,0.,0. }; + minRadius = 0.; + maxRadius = 0.; + status = "MIPSTUB_START"; + stub = mStub; + if (stub.isEndcap()){ + isEndcap = true; + lastLayer=maxEndcapLayer+1; + } else{ + isEndcap = false; + lastLayer=maxBarrelLayer+1; + } + nLayerMissed=0; + ndf = 0; + chi2 = 0.; + nHits=0; + debugLevel = debugL; + mcParticleIsKnown = false; + } + + /** + * Construct GarfieldTrack from a standard hep.lcd Track.<br> + * Since <code>hep.lcd.event.Track</code> is not linked to hits, + * and lacks other information used by K0S finder, Monte Carlo pointers + * are used to construct a list of hits, and a fake MipStub created to + * support fitting. This needs to be done better to fully integrate + * garfield tracking into the full tracking algorithm - plan to do + * it later, and hopefully with a better framework (org.lcsim ?). + * For now, any methods requiring access to individual hits might not + * work correctly if called for <code>GarfieldTrack</code> + * object created with this constructor. + */ + GarfieldTrack(Track standardTrack, EventHeader event, int debugLevel) { + + mcParticle = null ; // for some reason org.lcsim has getMCParticle commented out + //mcParticle = standardTrack.getMCParticle(); + mcParticleIsKnown = (mcParticle != null); + + hits = new ArrayList(); + if (mcParticleIsKnown) { + //Enumeration vxdHits = event.getVXDHits().getHits(); + //while (vxdHits.hasMoreElements()) { + //TrackerHit h = (TrackerHit)vxdHits.nextElement(); + //if (h.getMCParticle() == mcParticle) { + // hits.add(new GarfieldHit(h, 0, 0, 0)); + //} + //} + //Enumeration trackerHits = event.getTrackerHits().getHits(); + //while (trackerHits.hasMoreElements()) { + //TrackerHit h = (TrackerHit)trackerHits.nextElement(); + //if (h.getMCParticle() == mcParticle) { + // hits.add(new GarfieldHit(h, 0, 0, 0)); + //} + //} + nHits = hits.size(); + minRadius = 999999.; + ListIterator it = hits.listIterator(); + while (it.hasNext()) { + GarfieldHit gh = (GarfieldHit)it.next(); + minRadius = Math.min(gh.getRxy(), minRadius); + } + } else { + nHits = ndf+3; // just a guess ... + minRadius = standardTrack.getRadiusOfInnermostHit(); + //Math.sqrt(standardTrack.getOriginX()*standardTrack.getOriginX() + + // standardTrack.getOriginY()*standardTrack.getOriginY()); + minRadius = minRadius > 1.2 * Const.cm ? minRadius : 1.2 * Const.cm; // guessing innermost VXD layer + } + + hel = new GarfieldHelix(standardTrack.getReferencePoint(), standardTrack.getMomentum(), + standardTrack.getTrackParameter(2)); + hel.setDebugLevel(debugLevel); + trackPara = new double[5]; + setTrackParameters(); + maxRadius = 125.*Const.cm; + status = "FROM_STANDARD_TRACK"; + stub = null; + ndf = (int)standardTrack.getNDF() > 0 ? (int)standardTrack.getNDF() : 1; + chi2 = standardTrack.getChi2(); + grade = 99999; + this.debugLevel = debugLevel; + trackDone = true; + isEndcap = false; // xxx just a kludge + //(mcParticleIsKnown) ? + //Math.abs(mcParticle.getCalorimeterEntryZ()) > emCalZ : false; + lastLayer = ( isEndcap ? maxEndcapLayer : maxBarrelLayer) + 1; + nLayerMissed = 0; + + stub = new MipStub(standardTrack.getReferencePoint(), standardTrack.getMomentum(), + standardTrack.getTrackParameter(2), nHits, isEndcap, 0); + hasZ = hasZMeasurement(); + } + + /** + * Copy constructor. + */ + GarfieldTrack(GarfieldTrack g) { + hits = (ArrayList)(g.hits.clone()); + hel = new GarfieldHelix(g.hel.base(),g.hel.dir(),g.hel.kappa()); + hel.setDebugLevel(g.debugLevel); + trackPara = new double[5]; + System.arraycopy(g.trackPara, 0, trackPara, 0, 5); + minRadius = g.minRadius; + maxRadius = g.maxRadius; + lastLayer= g.lastLayer; + nLayerMissed= g.nLayerMissed; + status = g.status; + grade = g.grade; + stub = g.stub; + ndf = g.ndf; + chi2 = g.chi2; + nHits=g.nHits; + isEndcap = g.isEndcap; + debugLevel = g.debugLevel; + trackDone = g.trackDone; + if (debugLevel >=4) System.out.println("GarfieldTrack created copy of track with nHit="+g.hits.size()); + mcParticleIsKnown = false; + hasZ = g.hasZ; // fixed Sep 08 2005, evt + } + + // simple data retriever + public int getID(){ return ID;} + public double getGrade(){ return grade;} + + public int getHitID(int i){ + GarfieldHit gh = (GarfieldHit) hits.get(i); + return gh.getID(); + } + + public double[] getHitPoint(int i){ + if (i<0 || i>nHits-1){ + System.out.println("GarfieldTrack getHitPoint problem index="+i); + return new double[]{999.,999.,999.}; + } + GarfieldHit gh = (GarfieldHit) hits.get(i); + return gh.getPoint(); + } + + public int getNumberOfStepovers(){return nLayerMissed;} + + public int getHitLayer(int i){ + if (i<0 || i>nHits-1){ + System.out.println("GarfieldTrack getHitLayer problem index="+i); + return -1; + } + GarfieldHit gh = (GarfieldHit) hits.get(i); + return gh.getLayer(); + } + + /** + * gets track parameters + * parameters refer to point of closest approach (pca) in the xy plane + * magnetic field points along z direction + * + * - getPara("kappa") gives curvature<br> + * - d0: impact parameter in xy plane<br> + * - z0: impact parameter in z direction<br> + * - lambda: tan lambda (dip angle)<br> + * - phi0: phi direction at point of closest approach<br> + * <p> + * how to get pca from track parameter<br> + * x-coordinate pca_x = -d0 * sin(phi0)<br> // see also contrib/timb/mc/fast/tracking/DocaTrackParameters.java + * x-coordinate pca_y = d0 * cos(phi0)<br> + * z-coordinate pca_z = z0<br> + * how to get helix direction at pca<br> + * dir-x =cos(phi0)<br> + * dir-y =sin(phi0)<br> + * dir-z =lambda<br> + */ + public double getPara(String name) { + if (name == "kappa") return trackPara[PARA_kappa]; + if (name == "d0") return trackPara[PARA_d0]; + if (name == "z0") return trackPara[PARA_z0]; + if (name == "lambda") return trackPara[PARA_lambda]; // this is really tan lambda + if (name == "phi0") return trackPara[PARA_phi0]; + System.out.println("GarfieldTrack getPara, severe error, unknown name"+name); + return -999.; + } + + public String getStatus(){return status;} + public int getnHits(){return nHits;} + public int getStubMinLayer(){return stub.getMinLayer();} + public int getEquivnHits(){ + if (isEndcap()) return (int) nHits/2; + else return nHits; + } + public double getMinR(){ return minRadius;} + public double getMaxR(){ return maxRadius;} + public double getChi2(){ return chi2;} + public int getNdf(){ return ndf;} + + /** + * transverse momentum Pt in GeV = 0.299.. * B (in Tesla) * R (in Meter) + * @param bField B field in Tesla + */ + public double getPt(double bField){ + return speedOfLight*bField/Math.abs(getPara("kappa") * Const.m)/Const.GeV; // this division makes the return value independent of the units for momentum + } + + public double getP(double bField){ + double pt = getPt(bField); + double pz = pt*getPara("lambda"); + return Math.sqrt(pt*pt+pz*pz); + } + + public boolean hasZMeasurement(){ + if (status.equals("FROM_STANDARD_TRACK")) { + return true; + } else { + for (int i=0;i<nHits;i++){ + if ( ((GarfieldHit) hits.get(i)).hasZ()) return true; + } + } + return false; + } + + public boolean isPurged(){return (status == "PURGED");} + public boolean isRejected(){return (status=="REJECTED");} + public boolean isDone(){return trackDone;} + public boolean isEndcap(){ return isEndcap;} + public int q() { + if (trackPara[PARA_kappa] == 0.) return hel.q(); + else if (trackPara[PARA_kappa]<0.) return -1; + else return 1; + } + public double getMipStubBase(int i){ return stub.base[i];} + public double[] getMipStubBase(){ return stub.base;} + public double getMipStubKappa(){ return stub.kappa();} + public int getStubNHits(){return stub.getnHits();} + + // simple value setter + public void setID(int id){ ID=id;} + public void setHasZ(boolean val){ hasZ = val;} + /** controls amount of debug text output and test histograms, =0 not output, >0 debug output */ + public void setDebugLevel(int i){ debugLevel = i;} + public void setLastLayer(int i){lastLayer=i;} + public void setDone(){trackDone=true;} + public void setStatus(String stat){status=stat;} + public void setHelix(double[] pbase, double[] p2){ + hel.setBase(pbase[0],pbase[1],pbase[2]); + hel.setDir(p2[0]-pbase[0],p2[1]-pbase[1],p2[2]-pbase[2]); + } + + // -- Simple helper functions : --------------------------------------------- + + public void rejectTrack(){ + status = "REJECTED"; + if (debugLevel>=3) debug(); + } + + public void purgeTrack(){ + status = "PURGED"; + if (debugLevel>=3) debug(); + } + + public void setRadii() { + // xxx how to define minRadius with 2D hits i nthe endcap??? + double R; + minRadius = 10000.; + maxRadius= -10000.; + for (int i= 0; i<nHits; i++){ + R=((GarfieldHit)hits.get(i)).getRxy(); + if (R<minRadius) minRadius = R; + if (R>maxRadius) maxRadius = R; + } + } + + /** calculate grade of track */ + public double setGrade(double chi2Weight) { + double val = (double) nHits; + for (int i=0;i<nHits;i++){ + if (chi2Contrib(i)<25.) val +=1.; // less than 3 sigma + } + val -= chi2 / chi2Weight; + val -= Math.abs(getPara("d0"))/Const.m; + val -= Math.abs(getPara("kappa"))*Const.cm; + val -= (double) getNumberOfStepovers()/2.; + grade=val; + return val; + } + /** + * finds point of closest approach in x,y plane with respect to 0,0,0<br> + * see also getPara() + */ + public void setTrackParameters() { + trackPara[PARA_kappa] = hel.kappa(); + trackPara[PARA_lambda] = hel.dir(2)/Math.sqrt(hel.dir(0)*hel.dir(0)+hel.dir(1)*hel.dir(1)); // tan Lambda = cot theta + hel.setPointOnHelixWithXY(0.,0.); + trackPara[PARA_d0] = Math.sqrt(hel.getPointOnHelix(0)*hel.getPointOnHelix(0)+ + hel.getPointOnHelix(1)*hel.getPointOnHelix(1)); + trackPara[PARA_phi0] = Math.atan2(hel.dirAtPoint(1),hel.dirAtPoint(0)); + if (hel.getPointOnHelix(0)*Math.sin(trackPara[PARA_phi0])<0.) trackPara[PARA_d0] = -trackPara[PARA_d0]; + if (debugLevel>=3) System.out.println("setTrackParameters "+trackPara[PARA_phi0]+" "+hel.dirAtPoint(0)+" "+hel.dirAtPoint(1)); + // + trackPara[PARA_z0] = hel.getPointOnHelix(2); + } + + /** + * Throw avay hits that have worst chi2 until there are no hits left with contribution + * to Chi2 above <code>cutValue</code>, or until the number of hits on the track + * falls below <code>nHitMin</code>. Track is re-fit after removing each hit. + */ + public void purgeHits(double cutValue, int nHitMin, int nIter){ + double c; + double maxContrib; + int maxI=-1; + boolean done=false; + fastChi2Fit(nIter+1); + while (!done){ + maxContrib = -10.; + maxI=-1; + for (int i=0;i<nHits;i++){ + c=chi2Contrib(i); + if (c>cutValue && c>maxContrib) { + maxI=i; + maxContrib = c; + } + } + if (maxContrib>cutValue){ + dropHit(maxI); + if (nHits >= nHitMin) fastChi2Fit(nIter); + } else {done=true;} + if (nHits < nHitMin) done=true; + } + fastChi2Fit(nIter+1); + if (debugLevel>=2) System.out.println("GarfieldTrack purgeHits track="+getID()+" nHits="+nHits); + } + + /** + * Add a new hit to this track.<br> + * Helix parameters are not changed, Chi2 is recalculated. + */ + public void addHit(GarfieldHit h){ + boolean endcapBarrelTransition = (isEndcap() && !h.isEndcap() || (!isEndcap() && h.isEndcap())); + boolean trackerVTXTransition = (hasZ && !h.is3D()) || (!hasZ && h.is3D()); // FixMe, this is very crude + hasZ = hasZ || h.hasZ(); + int hlayer = h.getLayer(); + // calculate if we missed a layer + // update nLayersmissed + if (lastLayer - hlayer>1 && + !endcapBarrelTransition && + !trackerVTXTransition) nLayerMissed+=(lastLayer - hlayer)-1; + + lastLayer = hlayer; + hits.add(h); + nHits++; + if (h.is3D()) { + ndf+=2; // see also dropHit() if this line changes + } else { + ndf++; // see also dropHit() if this line changes + } + calculateChi2(); + } + + /** + * Drop a hit from this track.<br> + * Helix parameters are not changed, Chi2 is recalculated. + */ + public void dropHit(int i){ + if (((GarfieldHit) hits.get(i)).is3D()) ndf-=2;// see also addHit() if this line changes + else ndf--;// see also addHit() if this line changes + if (i!=nHits-1) nLayerMissed++; + hits.remove(i); + nHits=hits.size(); + hasZ = hasZMeasurement(); + setRadii(); + calculateChi2(); + } + + public void setHelixBaseToPCA() { + hel.setPointOnHelixWithXY(0.,0.); + double bx=hel.getPointOnHelix(0); + double by=hel.getPointOnHelix(1); + double bz=hel.getPointOnHelix(2); + double dx=hel.dirAtPoint(0); + double dy=hel.dirAtPoint(1); + double dz=hel.dirAtPoint(2); + double d0=Math.sqrt(dx*dx+dy*dy); + double signkappa=1.; + if (hel.kappa()<0.) signkappa=-1.; + hel.setBase(-d0*signkappa*dy,d0*signkappa*dx,bz); + hel.setDir(dx,dy,dz); + } + + public double distanceCutValue() { + // xxx this function depends on hardcoded length constants + // needs to be changed when we switch to millimeter + if (nHits==0) return 3.0*stub.getBaseError(); // 3 sigma around base point + else if (getEquivnHits()==1) { + return Const.cm*Math.sqrt(400.+(stub.getDirXYError()*30.)*(stub.getDirXYError()*30.)+stub.kappa()*stub.kappa()*1.E6); + } else if (getEquivnHits()==2) { + return Const.cm*Math.sqrt(100.+400.*stub.getDirXYError()*stub.getDirXYError()+stub.kappa()*stub.kappa()*5.E6); + } else if (getEquivnHits()==3) { + return Const.cm*10.; + } else { + return 10.*Const.cm; + } + } + + /** + * updated 03/23/05 to remove vcreation of new double, + * and call to CircleFromPoints to calculate helix parameters for barrel tracks + **/ + public void calculateHelixFromHits(){ + int nh = hits.size(); + if (nh==0) return; + GarfieldHit lastHit = (GarfieldHit) hits.get(nh-1); + if (lastHit.isEndcap() && Math.abs(hel.dir(2))>1.E-2) { + hel.setPointOnHelixWithZ(lastHit.getPoint(2)); + } else { + hel.setPointOnHelixWithXY(lastHit.getPoint(0),lastHit.getPoint(1)); + } + hel.setDir(hel.dirAtPoint(0),hel.dirAtPoint(1),hel.dirAtPoint(2)); + hel.setBase(hel.getPointOnHelix(0),hel.getPointOnHelix(1),hel.getPointOnHelix(2)); + //if (debugLevel>=2) System.out.println("calculateHelixFromhits base="+hel.base(0)+" "+hel.base(1)+" "+hel.base(2)); + //if (debugLevel>=2) System.out.println("calculateHelixFromhits dir="+hel.dir(0)+" "+hel.dir(1)+" "+hel.dir(2)+" kappa="+hel.kappa()); + } + + public void newCalculateHelixFromHits(){ + int nh = hits.size(); + if (nh==0) return; + GarfieldHit lastHit = (GarfieldHit) hits.get(nh-1); + if (lastHit.isEndcap() && Math.abs(hel.dir(2))>1.E-2) { + hel.setPointOnHelixWithZ(lastHit.getPoint(2)); + } else { + hel.setPointOnHelixWithXY(lastHit.getPoint(0),lastHit.getPoint(1)); + } + hel.setDir(hel.dirAtPoint(0),hel.dirAtPoint(1),hel.dirAtPoint(2)); + hel.setBase(hel.getPointOnHelix(0),hel.getPointOnHelix(1),hel.getPointOnHelix(2)); + + if (nh>=2 && !lastHit.isEndcap() && !((GarfieldHit) hits.get(0)).isEndcap()){ + CircleFromPoints cir =new CircleFromPoints(); + if (nh>2){ + cir.calculate( + getPoint(nh-1,0),getPoint(nh-1, 1), + getPoint(nh-2,0),getPoint(nh-2, 1), + getPoint(nh-3,0),getPoint(nh-3, 1) + ); + hel.setDir(cir.getDirAtC(0),cir.getDirAtC(1),hel.dirAtPoint(2)); + hel.setBase(getPoint(nh-1,0),getPoint(nh-1, 1),hel.getPointOnHelix(2)); + } else if (nh==2 && stub != null){ + cir.calculate( + stub.base[0],stub.base[1], + getPoint(nh-1,0),getPoint(nh-1, 1), + getPoint(nh-2,0),getPoint(nh-2, 1) + ); + hel.setDir(cir.getDirAtC(0),cir.getDirAtC(1),hel.dirAtPoint(2)); + hel.setBase(getPoint(nh-1,0),getPoint(nh-1, 1),hel.getPointOnHelix(2)); + } + } + //if (debugLevel>=2) System.out.println("calculateHelixFromhits base="+hel.base(0)+" "+hel.base(1)+" "+hel.base(2)); + //if (debugLevel>=2) System.out.println("calculateHelixFromhits dir="+hel.dir(0)+" "+hel.dir(1)+" "+hel.dir(2)+" kappa="+hel.kappa()); + } + public double getPoint(int i, int j) { + return ((GarfieldHit) hits.get(i)).getPoint(j); + } + + // + // chi-square and fitting + // + + // public void calculateNdf(){ ndf=hits.size();} + + /** + * Chi-square from hits and - if MipStub exists - from mipstub to track matching. + */ + public void calculateChi2(){ + if (status == "FROM_STANDARD_TRACK") return; + double saveErr=1.E-3; // 1 micrometer expressed in mm. + double c; + chi2=0.; + // contribution from hits + for (int i=0;i<nHits;i++){ + GarfieldHit h = (GarfieldHit) hits.get(i); + c=h.distanceToHit(hel,hasZ)/(h.getError()+saveErr); + //c=hel.distanceToHit(h)/(h.getError()+saveErr); + chi2=chi2+c*c; + } + // contribution from mipStub + if (stub != null){ + c=hel.distanceToHit3D(stub.base)/stub.getBaseError(); + chi2=chi2+c*c; + if (!hasZ){ + hel.setPointOnHelixWithXY(stub.base[0],stub.base[1]); + c=Math.abs(stub.dir[2]-hel.dirAtPoint(2))/stub.getDirZError(); + chi2=chi2+c*c; + if (getEquivnHits()<3){ + double cosPhi=stub.dir[0]*hel.dirAtPoint(0)+stub.dir[1]*hel.dirAtPoint(1); + if (Math.abs(cosPhi)>1.000001) System.out.println("Error !!! GarfieldTrack cosPhi="+cosPhi+" "+stub.dir[0]+" "+stub.dir[1]+" "+stub.dir[2]); + if (cosPhi>1.) cosPhi=1.; + if (cosPhi<-1.) cosPhi=-1.; + c=Math.acos(cosPhi)/stub.getDirXYError(); + chi2=chi2+c*c; + c = (hel.kappa()-stub.kappa)/stub.getKappaError(); + chi2=chi2+c*c; + } + } + } + } + + /** + * hit chiSquare contribution + * @param i hit number from 0 to nHits-1 + */ + public double chi2Contrib(int i) { + double saveErr=1.E-3; + GarfieldHit h = (GarfieldHit) hits.get(i); + double c=h.distanceToHit(hel,hasZ)/(h.getError()+saveErr); + //double c=hel.distanceToHit(h)/(h.getError()+saveErr); + return c*c; + } + + public boolean fullChi2Fit(double rangeMax, int nIter){ + return fastChi2Fit(nIter*4); + } + public boolean oldFullChi2Fit(double rangeMax, int nIter){ + calculateChi2(); + //calculateNdf(); + if (debugLevel>=2) System.out.println("++FULLChi2Fit before"+chi2); + boolean done =false; + double range = rangeMax; + if (chi2/ndf<10. && rangeMax>0.5) range = rangeMax/8.; + double oldChi2=chi2; + int oldLevel =debugLevel; + this.debugLevel=0; + int n=0; + int nRounds = 0; + while (nRounds < nIter){ + done=false; + while (!done){ + chi2FitIteration(range,0); + n++; + if (oldChi2<=chi2) done =true; + oldChi2=chi2; + if (n>4000){ + this.debugLevel=oldLevel; + if (debugLevel>=2) System.out.println("GarfieldTrack FullChi2Fit runaway chi2="+chi2); + return false; + } + } + range = range/4.; + nRounds++; + } + this.debugLevel=oldLevel; + if (debugLevel>=2) System.out.println("++FULLChi2Fit after"+chi2+" n="+n); + return true; + } + + public boolean fastChi2Fit(int scale){ + calculateChi2(); + double originalChi=chi2; + boolean done =false; + double range; + double chi2ndf = chi2/ndf; + int nStepMax; + if (chi2ndf<2.) {nStepMax=3; range = 0.02;} + else if (chi2ndf<10.) {nStepMax=5; range = 0.2;} + else if (chi2ndf<100.) {nStepMax=9; range = 1.0;} + else if (chi2ndf<1000.) {nStepMax=12; range = 2.0;} + else if (chi2ndf<10000.) {nStepMax=20; range = 4.0;} + else if (chi2ndf<100000.) {nStepMax=25; range = 5.0;} + else if (chi2ndf<1000000.) {nStepMax=30; range = 6.0;} + else {nStepMax=40; range = 8.0;} + nStepMax = nStepMax * scale; + //System.out.println("fC Tr="+ID+" Chi2="+chi2+ "NstepMax="+nStepMax); + double oldChi2=chi2; + int oldLevel =debugLevel; + //System.out.println("**FastChi2Fit before"+chi2+" "+chi2ndf+" scale"+scale); + this.debugLevel=0; + int n=0; + int nRounds = 0; + while (range > 0.02/scale ){ + done=false; + while (!done){ + chi2FitIteration(range,1); + n++; + if (oldChi2<=chi2*1.05) done =true; + oldChi2=chi2; + if (n>nStepMax){ + //System.out.println("**FastChi2Fit runaway nHits="+getnHits()+" "+originalChi+" n="+n+" chi2="+chi2+" nstepmax "+nStepMax); + this.debugLevel=oldLevel; + return false; + } + } + done=false; + while (!done){ + chi2FitIteration(range,0); + n++; + if (oldChi2<=chi2*1.05) done =true; + oldChi2=chi2; + if (n>nStepMax){ + //System.out.println("**FastChi2Fit runaway nHits="+getnHits()+" "+originalChi+" n="+n+" chi2="+chi2+" nstepmax "+nStepMax); + this.debugLevel=oldLevel; + return false; + } + } + //System.out.println("**FC n="+n+" range="+range); + //debug(); + range = range/2.; + nRounds++; + } + //System.out.println("**FastChi2Fit nHits="+getnHits()+" "+originalChi+" n="+n+" chi2="+chi2+" nstepmax "+nStepMax); + this.debugLevel=oldLevel; + return true; + } + + public void chi2FitIteration(double range, int mode){ + // fast variation of dir and kappa + // mode = 0 fit rphi and z + // mode = 1 fit rphi only + // mode = 2 fit z only + calculateChi2(); + int nIter = 1; + double oldChi2=chi2; + double oldDir0=hel.dir(0); + double oldDir1=hel.dir(1); + double oldDir2=hel.dir(2); + double bestDir0=hel.dir(0); + double bestDir1=hel.dir(1); + double bestDir2=hel.dir(2); + double bestBas0=hel.base(0); + double bestBas1=hel.base(1); + double bestBas2=hel.base(2); + double oldBas0=hel.base(0); + double oldBas1=hel.base(1); + double oldBas2=hel.base(2); + double oldKappa=hel.kappa(); + double bestKappa=oldKappa; + double minChi2=chi2; + double cosphi; + double sinphi; + double phi; + + if (mode == 0 || mode ==2){ + for (int i=-nIter; i<=nIter;i++){ + double delta = 0.05*range*i; + hel.setDir(oldDir0,oldDir1,oldDir2+delta); + for (int j=-nIter; j<=nIter;j++){ + hel.setBase(oldBas0,oldBas1,oldBas2+5.0*range*j); + calculateChi2(); + if (chi2<minChi2){ + bestDir0=hel.dir(0); + bestDir1=hel.dir(1); + bestDir2=hel.dir(2); + bestBas2=hel.base(2); + //if (debugLevel>=4) System.out.println(" Fit found new minimum Z-direction variation old="+minChi2+" new="+chi2+" dir0="+bestDir0+" dir1="+bestDir1+" dir2="+bestDir2); + minChi2=chi2; + } + } + } + hel.setDir(bestDir0,bestDir1,bestDir2); + hel.setBase(bestBas0,bestBas1,bestBas2); + oldDir0=hel.dir(0); + oldDir1=hel.dir(1); + oldDir2=hel.dir(2); + oldBas0=hel.base(0); + oldBas1=hel.base(1); + oldBas2=hel.base(2); + calculateChi2(); + oldChi2=chi2; + minChi2=chi2; + } + + if (mode <=1){ + for (int i=-nIter; i<=nIter;i++){ + hel.setKappa(oldKappa+0.0001*i*range); + for (int j=-nIter; j<=nIter;j++){ + phi = 0.05*range*j; + cosphi=Math.cos(phi); + sinphi=Math.sin(phi); + hel.setDir(cosphi*oldDir0-sinphi*oldDir1,sinphi*oldDir0+cosphi*oldDir1,oldDir2); + for (int k=-nIter; k<=nIter;k++){ + double eps=2.0*range*k/nIter; + hel.setBase(oldBas0-oldDir1*eps,oldBas1+oldDir0*eps,oldBas2+oldDir2*eps); + calculateChi2(); + if (chi2<minChi2){ + bestDir0=hel.dir(0); + bestDir1=hel.dir(1); + bestDir2=hel.dir(2); + bestBas0=hel.base(0); + bestBas1=hel.base(1); + bestBas2=hel.base(2); + bestKappa=hel.kappa(); + //if (debugLevel>=4) System.out.println(" Fit found new minimum old="+minChi2+" new="+chi2+" kappa="+bestKappa+" phi="+phi+" dir0="+bestDir0+" dir1="+bestDir1+" i,j,k="+i+" "+j+" "+k); + minChi2=chi2; + } + } + } + } + } // end of mode check + + hel.setKappa(bestKappa); + hel.setDir(bestDir0,bestDir1,bestDir2); + hel.setBase(bestBas0,bestBas1,bestBas2); + calculateChi2(); + //if (debugLevel>=2) System.out.println("GarfieldTrack chi2FitIteration range="+range+" new chi2="+chi2+" old chi2="+oldChi2+" dir0="+hel.dir(1)); + } + + private double kappaError(){ + return 0.0002*Math.exp(-0.2*nHits); + } + // + // testing debugging and plotting + // + public void debug() { + if (debugLevel<1) return; + System.out.println(" "); + String hasZString=" "; + if (hasZMeasurement()) hasZString="has Z"; + String endc=""; + if (isEndcap()) endc=" endcap"; + + System.out.println("GarfieldTrack "+getID()+" REPORT nh="+hits.size()+" Status="+status+" Chi2="+chi2+" ndf="+ndf+" kappa="+hel.kappa()); + System.out.println(" "+hasZString+", "+endc+" Nstepover="+getNumberOfStepovers()+" Grade="+grade); + if (stub != null){ + System.out.println("REPORT MipStub base"+stub.base[0]+" "+stub.base[1]+" "+stub.base[2]+" d="+hel.distanceToHit3D(stub.base)+" dErr="+stub.getBaseError()); + System.out.println("REPORT MipStub dir"+stub.dir[0]+" "+stub.dir[1]+" "+stub.dir[2]+" kappa="+stub.kappa+" kaErr="+stub.getKappaError()); + System.out.println("REPORT MipStub angle="+stub.angleBaseDir+" nH="+stub.getnHits()); + } + System.out.println("REPORT HELIX base"+hel.base(0)+" "+hel.base(1)+" "+hel.base(2)); + System.out.println("REPORT HELIX dir"+hel.dir(0)+" "+hel.dir(1)+" "+hel.dir(2)+" kappa="+hel.kappa()); + + for (int k=0; k<hits.size(); k++){ + double[] ph = getHitPoint(k); + String endCapString = " barrel"; + if (((GarfieldHit) hits.get(k)).isEndcap()) endCapString = " EndCap"; + String string3d = " "; + if (((GarfieldHit) hits.get(k)).is3D()) string3d=" 3D"; + String stringHasZ = " "; + if (((GarfieldHit) hits.get(k)).hasZ()) stringHasZ=" hasZ"; + System.out.println(" hit ID="+getHitID(k)+" layer="+getHitLayer(k)+" "+ph[0]+" "+ph[1]+" "+ph[2]+" Chi2C="+chi2Contrib(k)+" d="+((GarfieldHit) hits.get(k)).distanceToHit(hel,hasZ)+endCapString+string3d+stringHasZ); + } + + System.out.println("REPORT kappa,phi,lam,d0,z0 = "+this.trackPara[PARA_kappa]+" "+ + this.trackPara[PARA_phi0]+" "+this.trackPara[PARA_lambda]+" "+this.trackPara[PARA_d0]+" "+this.trackPara[PARA_z0]); + System.out.println("REPORT minR="+minRadius+" maxR="+maxRadius+ " q="+q()); + + } + + /** + * Returns MCParticle that produced tracker hits that are associated with + * this track. Returns null if more than one MCParticle was involved. + */ + public MCParticle getMCParticle() { + if (!mcParticleIsKnown) findMCParticle(); + return mcParticle; + } + + private void findMCParticle() { + mcParticle = null; + /* // xxx kludge + ListIterator iter = hits.listIterator(); + while (iter.hasNext()) { + MCParticle particle = (MCParticle)((GarfieldHit)iter.next()).getMCParticle(); + if (mcParticle == null) { + mcParticle = particle; + } else if (mcParticle != particle) { + mcParticle = null; + break; + } + } + mcParticleIsKnown = true; + */ + } + + // -- Implementing org.lcsim.event.Track : ---------------------------------- + // -- (dummy implementations for some methods - this should be fixed later) -- + + public double[] getTrackParameters() {return trackPara;} // FIXME : need conversion once Tony sorts + // out conventions and WIRED swimming is fixed + public double getTrackParameter(int param) { // FIXME : same here + if (param == PARA_kappa) { + //return trackPara[param]*10.; + return - trackPara[param]; + } else if (param == PARA_d0) { + //return - trackPara[param] / 10.; + return - trackPara[param]; + } else if (param == PARA_z0) { + //return trackPara[param] / 10.; + return trackPara[param]; + } else if (param == PARA_lambda) { + return trackPara[param]; + } else { + return trackPara[param]; + } + } + + public double getdEdxError() {return 0.;} // FixMe + + public double getdEdx() {return 0.;} // FixMe + + public int getType() {return 0;} // FixMe + + public List<Track> getTracks() {return new ArrayList<Track>(1);} + + public List<TrackerHit> getTrackerHits() {return (List<TrackerHit>)hits;} + + public int[] getSubdetectorHitNumbers() {return new int[] {0};} //FixMe + + public boolean fitSuccess() {return true;} // FixMe + + public int getCharge() {return q();} + + public SymmetricMatrix getErrorMatrix() {return new SymmetricMatrix(5);} // FixMe + + public double[] getMomentum() {return new double[] {0.,0., 0.};} //FixMe + + public int getNDF() {return ndf;} + + public double getPX() {return 0.;} //FixMe + + public double getPY() {return 0.;} //FixMe + + public double getPZ() {return 0.;} //FixMe + + public double getRadiusOfInnermostHit() {return minRadius;} + + public boolean isReferencePointPCA() {return false;} + + public double[] getReferencePoint() { + setHelixBaseToPCA(); + return hel.base(); + } + + public double getReferencePointX() { + setHelixBaseToPCA(); + return hel.base(0); + } + + public double getReferencePointY() { + setHelixBaseToPCA(); + return hel.base(1); + } + + public double getReferencePointZ() { + setHelixBaseToPCA(); + return hel.base(2); + } + + +} + + + + +
diff -N LCIOConstants.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ LCIOConstants.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,97 @@
+package org.lcsim.util.lcio; + +/** + * + * @author tonyj + */ +public interface LCIOConstants +{ + int MAJORVERSION = 1; + int MINORVERSION = 60; + + // bits in flag words + // SimCalorimeterHit (CH) + int CHBIT_LONG = 31; + + // long(1) - short(0) , incl./excl. position + int CHBIT_BARREL = 30; + + // barrel(1) - endcap(0) + int CHBIT_ID1 = 29; + + // cellid1 stored + int CHBIT_PDG = 28; // deprecated + + int CHBIT_STEP = 28; + + int RCHBIT_LONG = 31; + + // store energy error + int RCHBIT_ENERGY_ERROR = 26; + + // long(1) - short(0) , incl./excl. position + int RCHBIT_BARREL = 30; + + // barrel(1) - endcap(0) + int RCHBIT_ID1 = 29; + + // cellid1 stored + int RCHBIT_NO_PTR = 28; + + // 1: pointer tag not added + int RCHBIT_TIME = 27; + + // 1: time information stored + // SimTrackerHit + int THBIT_BARREL = 31; + + // barrel(1) - endcap(0) + int THBIT_MOMENTUM = 30 ; + + // CellID1 stored for SimTrackerHit and TrackerHit. + int THBIT_ID1 = 29; + + // momentum of particle stored(1) - not stored(0) + // Tracks + int TRBIT_HITS = 31; + + // hits stored(1) - not stored(0) + // Cluster + int CLBIT_HITS = 31; + + // hits stored(1) - not stored(0) + // TPCHit + int TPCBIT_RAW = 31; + + // raw data stored(1) - not stored(0) + int TPCBIT_NO_PTR = 30; + + // cellid1 stored + int TRAWBIT_ID1 = 31; + + // SimTrackerHit references stored (1) - not stored (0). + // FIXME: Non-standard LCIO constant. Needs to be propagated to lcio standalone project. + //int RTHBIT_HITS = 27; + + // 1: pointer tag not added (needed for TrackerHit) + // LCRelation + // public const int LCREL_ONE2MANY = 31 ; // relation is one to many + int LCREL_WEIGHTED = 31; + + // relations has weights + // LCGenericObject + int GOBIT_FIXED = 31; + + int BITTransient = 16 ; + int BITDefault = 17 ; + int BITSubset = 18 ; + + String runRecordName = "LCRunHeader"; + String runBlockName = "RunHeader"; + String eventRecordName = "LCEvent"; + String eventBlockName = "Event"; + String eventHeaderRecordName = "LCEventHeader"; + String eventHeaderBlockName = "EventHeader"; + + String references = "_References"; +}
diff -N MakeTracks.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ MakeTracks.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,101 @@
+/* + * MakeTracks.java + * + * Created on February 6, 2008, 11:40 AM + * + */ + +package org.lcsim.recon.tracking.seedtracker; + +import java.util.ArrayList; +import java.util.List; + +import org.lcsim.event.EventHeader; +import org.lcsim.event.Track; +import org.lcsim.event.TrackerHit; +import org.lcsim.fit.helicaltrack.HelicalTrackFit; +import org.lcsim.fit.helicaltrack.HelicalTrackHit; +import org.lcsim.util.lcio.LCIOConstants; + +/** + * Create a list of SeedTracks from a list of SeedCandidates that have passed + * the SeedTracker algorithm and store these tracks back into the event. + * @author Richard Partridge + * @version 1.0 + */ +public class MakeTracks { + + private String _TrkCollectionName = EventHeader.TRACKS; + TrackCheck _trackCheck; // set by SeedTracker + + /** + * Creates a new instance of MakeTracks. + */ + public MakeTracks() { + } + + /** + * Process a list of SeedCandidates to make a list of SeedTracks and store + * these tracks back into the event. + * @param event event header + * @param seedlist list of SeedCandidates that are to be turned into tracks + * @param bfield magnetic field (used to turn curvature into momentum) + */ + public void Process(EventHeader event, List<SeedCandidate> seedlist, double bfield) { + + // Create a the track list + List<Track> tracks = new ArrayList<Track>(); + + // Initialize the reference point to the origin + double[] ref = new double[3]; + ref[0] = 0.; + ref[1] = 0.; + ref[2] = 0.; + + // Loop over the SeedCandidates that have survived + for (SeedCandidate trackseed : seedlist) { + + // Create a new SeedTrack (SeedTrack extends BaseTrack) + SeedTrack trk = new SeedTrack(); + + // Add the hits to the track + for (HelicalTrackHit hit : trackseed.getHits()) { + trk.addHit((TrackerHit) hit); + } + + // Retrieve the helix and save the relevant bits of helix info + HelicalTrackFit helix = trackseed.getHelix(); + trk.setTrackParameters(helix.parameters(), bfield); + trk.setCovarianceMatrix(helix.covariance()); + trk.setChisq(helix.chisqtot()); + trk.setNDF(helix.ndf()[0]+helix.ndf()[1]); + + // Flag that the fit was successful and set the reference point + trk.setFitSuccess(true); + trk.setReferencePoint(ref); + trk.setRefPointIsDCA(true); + + // Set the strategy used to find this track + trk.setStratetgy(trackseed.getSeedStrategy()); + + // Set the SeedCandidate this track is based on + trk.setSeedCandidate(trackseed); + + // Check the track - hook for plugging in external constraint + if ((_trackCheck != null) && (! _trackCheck.checkTrack(trk))) continue; + + // Add the track to the list of tracks + tracks.add((Track) trk); + } + + // Put the tracks back into the event and exit + int flag = 1<<LCIOConstants.TRBIT_HITS; + event.put(_TrkCollectionName, tracks, Track.class, flag); + + return; + } + + void setTrkCollectionName(String name) { + _TrkCollectionName = name; + } +}
diff -N ReconTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ReconTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,562 @@
+package org.lcsim.mc.fast.tracking; + +import Jama.*; +import hep.physics.matrix.SymmetricMatrix; +import org.lcsim.util.aida.AIDA; +import hep.physics.particle.Particle; +import hep.physics.vec.Hep3Vector; +import org.lcsim.event.Track; +import java.io.*; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import org.lcsim.mc.fast.tracking.SimpleTables; + + +/** + * Provides MC smeared track. <br> + * Handles to smeared and not-smeared set of DocaTrackParameters + * are provided. <br> + * + * @author Tony Johnson, Wolfgang Walkowiak + * @version $Id: ReconTrack.java,v 1.1 2012/06/18 23:02:13 jeremy Exp $ + */ +public class ReconTrack implements Track +{ + private static final String[][] matrixI = + { + { "(1,1):", "(1,2):", "(1,3):", "(1,4):", "(1,5):" }, + { "(2,1):", "(2,2):", "(2,3):", "(2,4):", "(2,5):" }, + { "(3,1):", "(3,2):", "(3,3):", "(3,4):", "(3,5):" }, + { "(4,1):", "(4,2):", "(4,3):", "(4,4):", "(4,5):" }, + { "(5,1):", "(5,2):", "(5,3):", "(5,4):", "(5,5):" } + }; + + //======================================================================= + // + // private members + // + //======================================================================= + private DocaTrackParameters m_nosmear = null; + private DocaTrackParameters m_smear = null; + transient private Particle mc; + private int m_tcharge; + private double[] _refpoint = {0,0,0}; + + ReconTrack(double bField, TrackResolutionTables parm, SimpleTables SmTbl, Random rand, Particle mc, boolean hist, boolean simple) + { + this.mc = mc; + + // get original momentum from MCParticle + // convert to helical parameters + m_nosmear = new DocaTrackParameters(bField, mc); + + double pt = m_nosmear.getPt(); + + if (hist) + { + + double r = Math.abs(m_nosmear.getD0()); + + AIDA aida = AIDA.defaultInstance(); + aida.cloud1D("ptsqr").fill(pt*pt); + aida.cloud1D("pt").fill(pt); + aida.cloud1D("phi").fill(m_nosmear.getPhi0()); + aida.cloud1D("theta").fill(m_nosmear.getTheta()); + aida.cloud1D("tanL").fill(m_nosmear.getTanL()); + aida.cloud1D("r").fill(r); + aida.cloud1D("z").fill(mc.getOriginZ()); + } + // get appropriate resolution table + double abscth = Math.abs(m_nosmear.getCosTheta()); + double ptot = m_nosmear.getPtot(); + ResolutionTable table = (abscth < parm.getPolarInner()) ? parm.getBarrelTable() : parm.getEndcapTable(); + + // get resolution values from interpolation and fill error matrix + m_nosmear.setErrorMatrix(getErrorMatrixFromTable(table, abscth, ptot)); + + // smear tracks according to error matrix + if (simple == true) + { + m_smear = (DocaTrackParameters) SmearTrackSimple.smearTrackSimple(bField, m_nosmear, rand, SmTbl, pt, hist); + //double[] slice = {0, 0, 1, 0, 0}; + //m_smear = (DocaTrackParameters) SmearTrackSimpleII.SmearTrackSimpleII(bField, m_nosmear, rand, SmTbl, slice, hist); + } else { + m_smear = (DocaTrackParameters) SmearTrack.smearTrack(bField, m_nosmear, rand); + } + + if (hist) + { + AIDA aida = AIDA.defaultInstance(); + aida.cloud1D("ptNew").fill(m_smear.getPt()); + aida.cloud1D("tanLNew").fill(m_smear.getTanL()); + aida.cloud1D("rNew").fill(Math.abs(m_smear.getD0())); + aida.cloud1D("phiNew").fill(m_smear.getPhi0()); + aida.cloud1D("zNew").fill(m_smear.getZ0()); + } + m_tcharge = (int) (m_smear.getUnitCharge() * Math.abs(mc.getType().getCharge())); + } + + /** + * Get the full charge. + */ + public int getCharge() + { + return m_tcharge; + } + + /** + * Get the chi2 from smearing. + */ + public double getChi2() + { + return m_smear.getChi2(); + } + + /** + * Get DOCA (2-dim) of smeared track. <br> + * + * Note: Use #getNotSmearedTrack().getDOCA() to access + * parameters of the not smeared track. + */ + public double[] getDoca() + { + return m_smear.getDoca(); + } + + public double[] getDocaMomentum(double[] refPoint) + { + return m_smear.getDocaMomentum(refPoint); + } + + /** + * Get momentum at DOCA (2-dim) of smeared track. <br> + * + * Note: Use #getNotSmearedTrack().getMomentum() + * to access parameters of the not smeared track. + */ + public double[] getDocaMomentum() + { + return m_smear.getMomentum(); + } + + public Hep3Vector getDocaMomentumVec(Hep3Vector refPoint) + { + return m_smear.getDocaMomentumVec(refPoint); + } + + /* + * Calculate and get Doca momentum on smeared track with respect to any space point. + */ + public Hep3Vector getDocaMomentumVec(double[] refPoint) + { + return m_smear.getDocaMomentumVec(refPoint); + } + + /** + * Get x coordinate of momentum of the smeared track at DOCA. + */ + public double getDocaMomentumX() + { + return m_smear.getPX(); + } + + /** + * Get y coordinate of momentum of the smeared track at DOCA. + */ + public double getDocaMomentumY() + { + return m_smear.getPY(); + } + + /** + * Get z coordinate of momentum of the smeared track at DOCA. + */ + public double getDocaMomentumZ() + { + return m_smear.getPZ(); + } + + public double[] getDocaPosition(double[] refPoint) + { + return m_smear.getDocaPosition(refPoint); + } + + /** + * Calculate and get Doca position on the smeared + * track with respect to any space point. + */ + public Hep3Vector getDocaPositionVec(Hep3Vector refPoint) + { + return m_smear.getDocaPositionVec(refPoint); + } + + public Hep3Vector getDocaPositionVec(double[] refPoint) + { + return m_smear.getDocaPositionVec(refPoint); + } + + /** + * Get transverse momentum of the smeared track at DOCA. + */ + public double getDocaPt() + { + return m_smear.getPt(); + } + + /** + * Calculate and get path length on the smeared track + * for a doca to any space point + * in respect to the track defining doca (with respect to the origin). + * The length l is given in the transverse plane. <br> + * Use L = l*tan(lambda) to convert. + */ + public double getDocaTransversePathLength(Hep3Vector refPoint) + { + return m_smear.getDocaTransversePathLength(refPoint); + } + + public double getDocaTransversePathLength(double[] refPoint) + { + return m_smear.getDocaTransversePathLength(refPoint); + } + + /** + * Get x coordinate of DOCA of smeared track. + */ + public double getDocaX() + { + return m_smear.getDocaX(); + } + + /** + * Get y coordinate of DOCA of smeared track. + */ + public double getDocaY() + { + return m_smear.getDocaY(); + } + + /** + * Get z coordinate of DOCA of smeared track. + */ + public double getDocaZ() + { + return m_smear.getDocaZ(); + } + + /** + * Get the full error matrix. + * @see #getTrackParameter + */ + public SymmetricMatrix getErrorMatrix() + { + return m_smear.getErrorMatrix(); + } + + /** + * Get the MC particle for this track. + */ + public Particle getMCParticle() + { + return mc; + } + + public double[] getMomentum(double l) + { + return m_smear.getMomentum(l); + } + + /** + * Get momentum of smeared track at original vertex point. <br> + * + * Note: Use #getNotSmearedTrack().getMomentum() + * to access parameters of the not smeared track. + */ + public double[] getMomentum() + { + return m_smear.getMomentum(m_smear.getL0()); + } + + /** + * Calculate and get momentum on track with respect to + * any path length l on track (l in xy plane). + */ + public Hep3Vector getMomentumVec(double l) + { + return m_smear.getMomentumVec(l); + } + + public Hep3Vector getMomentumVec() + { + return m_smear.getMomentumVec(m_smear.getL0()); + } + + /** + * Get x coordinate of momentum of the smeared track at + * original vertex. + */ + public double getMomentumX() + { + return m_smear.getMomentum(m_smear.getL0())[0]; + } + + /** + * Get y coordinate of momentum of the smeared track at + * original vertex. + */ + public double getMomentumY() + { + return m_smear.getMomentum(m_smear.getL0())[1]; + } + + /** + * Get z coordinate of momentum of the smeared track at + * original vertex. + */ + public double getMomentumZ() + { + return m_smear.getMomentum(m_smear.getL0())[2]; + } + + /** + * Get the number degrees of freedom. + */ + public int getNDF() + { + return m_smear.getNDF(); + } + + /** + * Get the complete parameter set for the not smeared track. + */ + public DocaTrackParameters getNotSmearedTrack() + { + return m_nosmear; + } + + /** + * Get x coordinate of momentum of the smeared track at + * original vertex. + */ + public double getPX() + { + return getMomentumX(); + } + + /** + * Get y coordinate of momentum of the smeared track at + * original vertex. + */ + public double getPY() + { + return getMomentumY(); + } + + /** + * Get z coordinate of momentum of the smeared track at + * original vertex. + */ + public double getPZ() + { + return getMomentumZ(); + } + + public double[] getPosition(double l) + { + return m_smear.getPosition(l); + } + + /** + * Calculate and get position on track with respect to + * any path length l on track (l in xy plane). + */ + public Hep3Vector getPositionVec(double l) + { + return m_smear.getPositionVec(l); + } + + /** + * Get transverse momentum of the smeared track at original vertex. + */ + public double getPt() + { + double[] p = getMomentum(); + + return Math.sqrt((p[0] * p[0]) + (p[1] * p[1])); + } + + public double getRadiusOfInnermostHit() + { + return 0; // FixMe: + } + + /** + * Get the original vertex point of smeared MC track. + */ + + // Get the reference point used for track parameter calculations + // + public double[] getReferencePoint() + { + return _refpoint; + } + + public boolean isReferencePointPCA() + { + return true; + } + + /** + * Get x coordinate of the original vertex point of smeared MC track. + */ + public double getReferencePointX() + { + return getReferencePoint()[0]; + } + + /** + * Get y coordinate of the original vertex point of smeared MC track. + */ + public double getReferencePointY() + { + return getReferencePoint()[1]; + } + + /** + * Get z coordinate of the original vertex point of smeared MC track. + */ + public double getReferencePointZ() + { + return getReferencePoint()[2]; + } + + /** + * Get the complete parameter set for the smeared track. + */ + public DocaTrackParameters getSmearedTrack() + { + return m_smear; + } + + public int[] getSubdetectorHitNumbers() + { + return new int[0]; // FIXME + } + + /** + * Get an individual track parameter. <br> + * + * The track parameters for LCD are defined as follows + * <table> + * <tr><th>Index</th><th>Meaning</th></tr> + * <tr><td> 0 </td><td> d0 = XY impact parameter </td><tr> + * <tr><td> 1 </td><td> phi0 </td><tr> </td><tr> + * <tr><td> 2 </td><td> omega = 1/curv.radius (negative for negative tracks) </td><tr> + * <tr><td> 3 </td><td> z0 = z of track (z impact parameter) </td><tr> + * <tr><td> 4 </td><td> s = tan lambda </td><tr> + * </table> + * @param i The index of the track parameter + * @return The track parameter with the specified index + * + * All parameters are given at the DOCA. + */ + public double getTrackParameter(int i) + { + return m_smear.getTrackParameter(i); + } + + /** + * Get the track parameters as an array + * @see #getTrackParameter + */ + public double[] getTrackParameters() + { + return m_smear.getTrackParameters(); + } + + public List getTrackerHits() + { + return Collections.EMPTY_LIST; + } + + public List getTracks() + { + return Collections.EMPTY_LIST; + } + + public int getType() + { + return 0; // FIXME: + } + + /** + * Calculate the error matrix for the momentum + * for a point on the smeared track specified by l. + */ + public SymmetricMatrix calcMomentumErrorMatrix(double l) + { + return m_smear.calcMomentumErrorMatrix(l); + } + + /** + * Calculate the error matrix for the position coordinates + * for a point on the smeared track specified by l. + * Result is given as a 3x3 array for the matrix. + */ + public double[][] calcPositionErrorMatrix(double l) + { + return m_smear.calcPositionErrorMatrix(l); + } + + public boolean fitSuccess() + { + // FIXME Not implemented in fastMC + return false; + } + + public double getdEdx() + { + return 0; // FIXME + } + + public double getdEdxError() + { + return 0; // FIXME + } + + public String toString() + { + java.io.StringWriter buffer = new java.io.StringWriter(); + java.io.PrintWriter out = new java.io.PrintWriter(buffer); + + java.text.NumberFormat pf = java.text.NumberFormat.getInstance(); + pf.setMinimumFractionDigits(12); + pf.setMaximumFractionDigits(12); + pf.setMinimumIntegerDigits(1); + pf.setMaximumIntegerDigits(3); + pf.setGroupingUsed(false); + + Matrix mHlxPar = new Matrix(m_smear.getTrackParameters(), 1); + + out.println("ReconTrack Parameters: d0 phi0 omega z0 tan(lambda)"); + mHlxPar.print(out, pf, 16); + out.println("Error Matrix:"); + out.println(m_smear.getErrorMatrix()); + + return (buffer.toString()); + } + + private SymmetricMatrix getErrorMatrixFromTable(ResolutionTable table, double abscth, double ptot) + { + SymmetricMatrix errMatrix = new SymmetricMatrix(5); + for (int i = 0; i < 5; i++) + { + for (int j = 0; j <= i; j++) + { + errMatrix.setElement(i,j,table.findTable(matrixI[i][j]).interpolateVal(abscth, ptot)); + } + } + return errMatrix; + } +}
diff -N SIOTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ SIOTrack.java 18 Jun 2012 23:02:13 -0000 1.1 @@ -0,0 +1,136 @@
+package org.lcsim.util.lcio; + +import hep.io.sio.SIOInputStream; +import hep.io.sio.SIOOutputStream; +import hep.io.sio.SIORef; +import hep.physics.matrix.SymmetricMatrix; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.lcsim.event.Track; +import org.lcsim.event.TrackerHit; +import org.lcsim.event.base.BaseTrack; + + +/** + * + * @author Tony Johnson + * @version $Id: SIOTrack.java,v 1.1 2012/06/18 23:02:13 jeremy Exp $ + */ +class SIOTrack extends BaseTrack +{ + private List<SIORef> tempHits; + private List<SIORef> tempTracks; + + SIOTrack(SIOInputStream in, int flag, int version, double bField) throws IOException + { + _type = in.readInt(); + double[] parameters = new double[5]; + for (int i=0; i<parameters.length; i++) parameters[i] = in.readFloat(); + setTrackParameters(parameters,bField); + double[] covMatrix = new double[15]; + for (int i=0; i<covMatrix.length; i++) covMatrix[i] = in.readFloat(); + _covMatrix = new SymmetricMatrix(5,covMatrix,true); + _refPoint = new double[3]; + _refPoint[0] = in.readFloat(); + _refPoint[1] = in.readFloat(); + _refPoint[2] = in.readFloat(); + _chi2 = in.readFloat(); + _ndf = in.readInt() ; + _dEdx = in.readFloat(); + _dEdxErr = in.readFloat(); + _innermostHitRadius = in.readFloat() ; + int nHitNumbers = in.readInt() ; + _subdetId = new int[nHitNumbers] ; + for (int i = 0; i < nHitNumbers; i++) + { + _subdetId[i] = in.readInt() ; + } + int nTracks = in.readInt(); + tempTracks = new ArrayList(nTracks); + _tracks = null; + for (int i=0; i<nTracks; i++) + { + tempTracks.add(in.readPntr()); + } + if (LCIOUtil.bitTest(flag,LCIOConstants.TRBIT_HITS)) + { + int nHits = in.readInt(); + tempHits = new ArrayList(nHits); + _hits = null; + for (int i = 0; i < nHits; i++) + { + tempHits.add(in.readPntr()); + } + } + + in.readPTag(this); + } + static void write(Track track, SIOOutputStream out, int flag) throws IOException + { + out.writeInt(track.getType()); + double[] parm = track.getTrackParameters(); + for (int i=0; i<5; i++) out.writeFloat((float) parm[i]); + double[] covMatrix = track.getErrorMatrix().asPackedArray(true); + for (int i=0; i<15; i++) out.writeFloat((float) covMatrix[i]); + double[] referencePoint = track.getReferencePoint(); + for (int i=0; i<3; i++) out.writeFloat((float) referencePoint[i]); + out.writeFloat((float) track.getChi2()); + out.writeInt(track.getNDF()); + out.writeFloat((float) track.getdEdx()); + out.writeFloat((float) track.getdEdxError()); + out.writeFloat((float) track.getRadiusOfInnermostHit()) ; + int[] hitNumbers = track.getSubdetectorHitNumbers(); + out.writeInt( hitNumbers.length ) ; + for (int i = 0; i < hitNumbers.length; i++) + { + out.writeInt( hitNumbers[i] ) ; + } + List<Track> tracks = track.getTracks() ; + out.writeInt( tracks.size() ) ; + for (Track t : tracks) + { + out.writePntr(t); + } + if(LCIOUtil.bitTest(flag,LCIOConstants.TRBIT_HITS)) + { + List<TrackerHit> hits = track.getTrackerHits(); + out.writeInt(hits.size()); + for (TrackerHit hit : hits) + { + out.writePntr(hit); + } + } + out.writePTag(track); + } + + public List<TrackerHit> getTrackerHits() + { + if (_hits == null && tempHits != null) + { + _hits = new ArrayList<TrackerHit>(tempHits.size()); + for (SIORef ref : tempHits) + { + _hits.add((TrackerHit) ref.getObject()); + } + tempHits = null; + } + return _hits == null ? Collections.<TrackerHit>emptyList() : _hits; + } + + public List<Track> getTracks() + { + if (_tracks == null && tempTracks != null) + { + _tracks = new ArrayList<Track>(tempTracks.size()); + for (SIORef ref : tempTracks) + { + _tracks.add((Track) ref.getObject()); + } + tempTracks = null; + } + return _tracks == null ? Collections.<Track>emptyList() : _tracks; + } +}
diff -N SeedTrackerTrackStateDriver.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ SeedTrackerTrackStateDriver.java 18 Jun 2012 23:02:14 -0000 1.1 @@ -0,0 +1,167 @@
+package org.lcsim.recon.tracking.seedtracker; + +import hep.physics.vec.BasicHep3Vector; +import hep.physics.vec.Hep3Vector; +import hep.physics.vec.VecOp; + +import java.util.ArrayList; +import java.util.List; + +import org.lcsim.event.EventHeader; +import org.lcsim.event.GenericObject; +import org.lcsim.event.Track; +import org.lcsim.fit.helicaltrack.HelicalTrackCross; +import org.lcsim.fit.helicaltrack.HelicalTrackFit; +import org.lcsim.fit.helicaltrack.HelicalTrackHit; +import org.lcsim.fit.helicaltrack.HelixUtils; +import org.lcsim.fit.helicaltrack.TrackDirection; +import org.lcsim.geometry.Calorimeter; +import org.lcsim.geometry.Detector; +import org.lcsim.geometry.Calorimeter.CalorimeterType; +import org.lcsim.spacegeom.SpacePoint; +import org.lcsim.spacegeom.SpaceVector; +import org.lcsim.util.Driver; +import org.lcsim.util.swim.HelixSwimmer; + +/** + * This Driver creates the three TrackState collections expected by slicPandora + * by using information from the SeedTracker objects. It must be run in the same + * job as SeedTracker, NOT by reading in a persisted LCIO file, which will not + * work due to lost data and type information. And it must be run the + * SeedTracker Driver. + * + * @author richp + * @author jeremym + * @author ngraf + * + * @version $Id: SeedTrackerTrackStateDriver.java,v 1.1 2012/06/18 23:02:14 jeremy Exp $ + */ +public class SeedTrackerTrackStateDriver extends Driver +{ + // protected CalorimeterInformation calInfo; + + protected double ecalRadius; + protected int ecalNumSides; + protected double ecalZ; + protected double magField; + protected HelixSwimmer swimmer; + + public SeedTrackerTrackStateDriver() + { + } + + protected void detectorChanged(Detector detector) + { + // get the magnetic field and set up the helix swimmer + magField = detector.getFieldMap().getField(new BasicHep3Vector(0, 0, 0)).magnitude(); + swimmer = new HelixSwimmer(magField); + + // Get calorimeter parameters from Detector. + Calorimeter ecalBarrel = null; + Calorimeter ecalEndcap = null; + + // Get the EM Barrel. + ecalBarrel = detector.getCalorimeterByType(CalorimeterType.EM_BARREL); + if (ecalBarrel == null) + throw new RuntimeException("Missing EM_BARREL subdetector in compact description."); + + // Get the EM Endcap. + ecalEndcap = detector.getCalorimeterByType(CalorimeterType.EM_ENDCAP); + if (ecalEndcap == null) + throw new RuntimeException("Missing EM_ENDCAP subdetector in compact description."); + + ecalRadius = ecalBarrel.getInnerRadius(); + ecalNumSides = ecalBarrel.getNumberOfSides(); + ecalZ = ecalEndcap.getInnerZ(); + + //System.out.println( "ECAL: radius " + ecalRadius + " nsides " + ecalNumSides + " z " + ecalZ ); + } + + public void process(EventHeader event) + { + // Get the Tracks from the event. Collection name is SeedTracker's default. + List<Track> tracks = event.get(Track.class, "Tracks"); + + // TrackState lists. + List<GenericObject> startObjs = new ArrayList<GenericObject>(); + List<GenericObject> endObjs = new ArrayList<GenericObject>(); + List<GenericObject> ecalObjs = new ArrayList<GenericObject>(); + + // Loop over all the Tracks in the collection. + for (Track track : tracks) + { + SeedTrack strk = (SeedTrack) track; + SeedCandidate scand = strk.getSeedCandidate(); + HelicalTrackFit helix = scand.getHelix(); + Hep3Vector ptrk = new BasicHep3Vector(strk.getMomentum()); + double smax = -9999.; + HelicalTrackHit last = null; + for (HelicalTrackHit hit : scand.getHits()) + { + double s = helix.PathMap().get(hit); + if (s > smax) + { + smax = s; + last = hit; + } + } + TrackDirection trkdir = HelixUtils.CalculateTrackDirection(helix, smax); + Hep3Vector dir = trkdir.Direction(); + Hep3Vector pos = null; + if (last instanceof HelicalTrackCross) + { + HelicalTrackCross cross = (HelicalTrackCross) last; + cross.setTrackDirection(trkdir, helix.covariance()); + pos = cross.getCorrectedPosition(); + } + else + { + pos = last.getCorrectedPosition(); + } + + // Set the End TrackState from the outermost hit on the track. + Hep3Vector xmomentum = VecOp.mult(ptrk.magnitude(), dir); + + // Set the End TrackState to the point of closest approach to the last hit + swimmer.setTrack(track); + double s = swimmer.getDistanceToPoint(pos); + Hep3Vector corPos = swimmer.getPointAtLength(s); + + TrackState endState = new TrackState(corPos, xmomentum); + endObjs.add(endState); + + // Calculate the Start state and add to list. + double[] smom = ptrk.v(); + double[] spos = HelixUtils.PointOnHelix(helix, 0.).v(); + TrackState startState = new TrackState(spos[0], spos[1], spos[2], smom[0], smom[1], smom[2]); + startObjs.add(startState); + + // TODO Should set the ECal TrackState by propagating from the outermost hit on the track. + double sZ = swimmer.getDistanceToZ(ecalZ); + double sR = swimmer.getDistanceToPolyhedra(ecalRadius, ecalNumSides); + if (Double.isNaN(sR)) + { + s = sZ; + } + else if (Double.isNaN(sZ)) + { + s = sR; + } + else + { + s = Math.min(swimmer.getDistanceToZ(ecalZ), swimmer.getDistanceToPolyhedra(ecalRadius, ecalNumSides)); + } + SpacePoint ecalPos = swimmer.getPointAtLength(s); + SpaceVector ecalMom = swimmer.getMomentumAtLength(s); + + TrackState ecalState = new TrackState(ecalPos.x(), ecalPos.y(), ecalPos.z(), ecalMom.x(), ecalMom.y(), ecalMom.z()); + ecalObjs.add(ecalState); + + } + + // Add the lists to the event. + event.put("StateAtStart", startObjs, GenericObject.class, 0); + event.put("StateAtECal", ecalObjs, GenericObject.class, 0); + event.put("StateAtEnd", endObjs, GenericObject.class, 0); + } +}
diff -N Track.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Track.java 18 Jun 2012 23:02:14 -0000 1.1 @@ -0,0 +1,131 @@
+package org.lcsim.event; + +import hep.physics.matrix.SymmetricMatrix; + +import java.util.List; + + +/** + * Represents a found (reconstructed) track + * + * @author tonyj + * @version $Id: Track.java,v 1.1 2012/06/18 23:02:14 jeremy Exp $ + */ + +public interface Track +{ + int getCharge(); + + double[] getReferencePoint(); + + double getReferencePointX(); + + double getReferencePointY(); + + double getReferencePointZ(); + + boolean isReferencePointPCA(); + + double[] getMomentum(); + + // Hep3Vector momentum(); + // SpacePoint referencePoint(); + double getPX(); + + double getPY(); + + double getPZ(); + + // MCParticle getMCParticle(); + + /** + * Returns true if the track has been successfully fitted + */ + + boolean fitSuccess(); + + /** + * Get an individual track parameter + * + * The track parameters for LCD are defined as follows <table> + * <tr> + * <th>Index</th> + * <th>Meaning</th> + * </tr> + * <tr> + * <td> 0 </td> + * <td> d0 = XY impact parameter </td> + * <tr> + * <tr> + * <td> 1 </td> + * <td> phi0 </td> + * <tr> </td> + * <tr> + * <tr> + * <td> 2 </td> + * <td> omega = 1/curv.radius (negative for negative tracks) </td> + * <tr> + * <tr> + * <td> 3 </td> + * <td> z0 = z of track origin (z impact parameter) </td> + * <tr> + * <tr> + * <td> 4 </td> + * <td> s = tan lambda </td> + * <tr> </table> Parameters according to <a + * href="../util/swim/doc-files/L3_helix.pdf">the L3 conventions</a><br /> + * + * @param i + * The index of the track parameter + * @return The track parameter with the specified index + */ + double getTrackParameter(int i); + + /** + * Get the track parameters as an array + * + * @see #getTrackParameter + */ + double[] getTrackParameters(); + + /** + * Get the error matrix + * + * @see #getTrackParameter + */ + SymmetricMatrix getErrorMatrix(); + + /** + * Get the Chi Squared for the track fit + * + * @see #getNDF + * @return Chi Squared + */ + double getChi2(); + + /** + * Get the numbers of degrees of freedom for the fit + * + * @see #getChi2 + * @return The number of degrees of freedom + */ + int getNDF(); + + double getdEdx(); + + double getdEdxError(); + + double getRadiusOfInnermostHit(); + + int[] getSubdetectorHitNumbers(); + + List<Track> getTracks(); + + List<TrackerHit> getTrackerHits(); + + int getType(); + + // double parameter(ParameterName n); + // similar name is not a problem, because of different signature + // Parameters parameters(); +}
diff -N TrackTableModel.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ TrackTableModel.java 18 Jun 2012 23:02:14 -0000 1.1 @@ -0,0 +1,30 @@
+package org.lcsim.plugin.browser; +import org.lcsim.event.Track; + + +/** + * + * @author tonyj + */ +class TrackTableModel extends GenericTableModel +{ + private static final String[] columns = {"Type","D0","Phi","Omega","Z0","TanLambda","Chi2","NDF","dEdx","Momentum"}; + private static Class klass = Track.class; + + TrackTableModel() + { + super(klass,columns); + } + + public Object getValueAt(int row, int column) + { + if (column > 0 && column <= 5) return ((Track) getData(row)).getTrackParameter(column-1); + else return super.getValueAt(row,column); + } + + public Class getColumnClass(int column) + { + if (column > 0 && column <= 5) return Double.class; + else return super.getColumnClass(column); + } +}
diff -N ZvTrack.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ZvTrack.java 18 Jun 2012 23:02:14 -0000 1.1 @@ -0,0 +1,613 @@
+package org.lcsim.recon.vertexing.zvtop4; + +import hep.physics.matrix.SymmetricMatrix; +import hep.physics.vec.BasicHep3Vector; +import hep.physics.vec.Hep3Vector; + +import java.util.EnumSet; +import java.util.List; + +import org.lcsim.event.Track; +import org.lcsim.event.TrackerHit; +import org.lcsim.geometry.compact.converter.lcdd.util.Rotation; +import org.lcsim.spacegeom.CartesianPoint; +import org.lcsim.spacegeom.SpacePoint; +import org.lcsim.util.swim.Helix; + +import static java.lang.Math.sqrt; +import static java.lang.Math.cos; +import static java.lang.Math.sin; +import static java.lang.Math.acos; +import static java.lang.Math.PI; + +/** + * Representation of the Gaussian tubes + * + * @author jstrube + * @version $Id: ZvTrack.java,v 1.1 2012/06/18 23:02:14 jeremy Exp $ + */ +public class ZvTrack implements Track { + + // TODO ksi and kappa need to be calculated -- keep in mind the charge of + // the track + + SpacePoint _referencePoint; + Hep3Vector _momentum; + ZvParameters _parameters; + int _charge; + boolean _refPointIsPCA; + SymmetricMatrix _errorMatrix; + // FIXME arbitrary values for the sigmas + static double sigmaT = 0.01; + static double sigmaL = 0.1; + boolean fitSuccess; + Track orgTrack; + + double trackRotationAngle; + + public String toString() { + StringBuffer result = new StringBuffer(); + result.append("ZvTrack: \n"); + result.append("\tRef Point: " + _referencePoint.toString()); + for (ZvParameterNames iParm : EnumSet.allOf(ZvParameterNames.class)) { + result.append("\tParameter " + iParm.name() + " " + _parameters.get(iParm) + "\n"); + } + return result.toString(); + } + // package wide constructor ensures I don't have to worry about anybody + // creating invalid ZvTracks. + // Only used to create Track-IP + ZvTrack() { + _parameters = new ZvParameters(); + _charge = 0; + _referencePoint = new SpacePoint(); + _refPointIsPCA = false; + _errorMatrix = new SymmetricMatrix(5); + fitSuccess = false; + updateMomentum(); + } + + // only useful for package testing + // NEVER use this as a user, as nothing guarantees consistency + ZvTrack(ZvParameters params, SpacePoint refPoint, SymmetricMatrix errorMatrix) { + _parameters = params; + _referencePoint = refPoint; + _errorMatrix = errorMatrix; + updateMomentum(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getCharge() + */ + public int getCharge() { + return _charge; + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getReferencePoint() + */ + @Deprecated + public double[] getReferencePoint() { + return _referencePoint.getCartesianArray(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getReferencePointX() + */ + public double getReferencePointX() { + return _referencePoint.x(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getReferencePointY() + */ + public double getReferencePointY() { + return _referencePoint.y(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getReferencePointZ() + */ + public double getReferencePointZ() { + return _referencePoint.z(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#isReferencePointPCA() + */ + public boolean isReferencePointPCA() { + return _refPointIsPCA; + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getMomentum() + */ + public double[] getMomentum() { + return _momentum.v(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getPX() + */ + public double getPX() { + return _momentum.x(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getPY() + */ + public double getPY() { + return _momentum.y(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getPZ() + */ + public double getPZ() { + return _momentum.z(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#fitSuccess() + */ + public boolean fitSuccess() { + return fitSuccess; + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getTrackParameter(int) + */ + public double zvParameter(ZvParameterNames name) { + return _parameters.get(name); + } + + /** + * returns the parameter by index + * + * @deprecated because the order is arbitrary + * @param i + * <em>Index</em> of the parameter + * @return the parameter + */ + @Deprecated + public double getTrackParameter(int i) { + return orgTrack.getTrackParameter(i); + } + + /** + * returns an array of parameters + * + * @deprecated because the order is arbitrary + * @return the parameters as double[] + */ + @Deprecated + public double[] getTrackParameters() { + return orgTrack.getTrackParameters(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getTrackParameters() + */ + public ZvParameters zvParameters() { + return _parameters; + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getErrorMatrix() + */ + public SymmetricMatrix getZvErrorMatrix() { + return _errorMatrix; + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getErrorMatrix() + */ + /** + * @deprecated because it's expensive + */ + @Deprecated + public SymmetricMatrix getErrorMatrix() { + return convert2TrackErrorMatrix(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getChi2() + */ + public double getChi2() { + return orgTrack.getChi2(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getNDF() + */ + public int getNDF() { + return orgTrack.getNDF(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getdEdx() + */ + public double getdEdx() { + return orgTrack.getdEdx(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getdEdxError() + */ + public double getdEdxError() { + return orgTrack.getdEdxError(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getRadiusOfInnermostHit() + */ + public double getRadiusOfInnermostHit() { + return orgTrack.getRadiusOfInnermostHit(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getSubdetectorHitNumbers() + */ + public int[] getSubdetectorHitNumbers() { + return orgTrack.getSubdetectorHitNumbers(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getTracks() + */ + public List<Track> getTracks() { + return orgTrack.getTracks(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getTrackerHits() + */ + public List<TrackerHit> getTrackerHits() { + return orgTrack.getTrackerHits(); + } + + /* + * (non-Javadoc) + * + * @see org.lcsim.event.Track#getType() + */ + public int getType() { + return orgTrack.getType(); + } + + + /** + * Calculates a Gaussian probability for a track to go through location + * @param location + * The spatial position at which to evaluate the "track + * probability" in the lab frame + * @return the "track probability" at that location + */ + public double getProbability(SpacePoint location) { + Track x; + //x. + return 0; + } + /** + * Calculates a Gaussian uncertainty around the track. A parabolic + * approximation is made instead of a helical parametrization The apex is at + * (x0, 0, z0), which is the POCA in a co-ordinate system that has been + * rotated in the x-y plane, so that the track momentum at the POCA in the + * x-y plane is parallel to the y-axis. + * + * @param location + * The spatial position at which to evaluate the "track + * probability" in the lab frame + * @return the scalar value at that location + */ + public double getTubeValue(SpacePoint location) { + // TODO for debugging only + assert(location != null); + SpacePoint r = rotateLocation(location); + SpacePoint refPrime = rotateLocation(_referencePoint); + double termA = (r.x() - refPrime.x() - _parameters.get(ZvParameterNames.kappa) * r.y() + * r.y()) + / sigmaT; + double termB = (r.z() - refPrime.z() - _parameters.get(ZvParameterNames.s) * r.y()) + / sigmaL; + double result = Math.exp(-0.5 * (termA * termA + termB * termB)); + // System.out.printf("termA: %f\ttermB: %f\tresult: %f", termA, termB, + // result); + return result; + } + + /** + * Projection of the parabolic approximation of the track into the x-y plane + * Useful for visualization + * + * @see #getTubeValue(SpacePoint) + * @param location + * The spatial position at which to evaluate the "track + * probability" in the lab frame + * @return the scalar value at that location + */ + public double getTubeProjection(SpacePoint location) { + SpacePoint r = rotateLocation(location); + SpacePoint refPrime = rotateLocation(_referencePoint); + double termA = (r.x() - refPrime.x() - _parameters.get(ZvParameterNames.kappa) * r.y() + * r.y()) + / sigmaT; + double result = Math.exp(-0.5 * termA * termA); + // System.out.printf("termA: %f\ttermB: %f\tresult: %f", termA, termB, + // result); + return result; + } + + /** + * Returns a point in space in the center of the tube. The parabola is + * parametrized by a length parameter s The value for s=0 ist the reference + * point + * + * @param lengthParameter + * The length parameter of the parabola + * @return The point in space at the length lengthParameter + */ + public SpacePoint getTubeCenter(double lengthParameter) { + SpacePoint startingPoint = rotateLocation(referencePoint()); + double theta = trackRotationAngle; + double yPrime = lengthParameter; + double xPrime = startingPoint.x() + _parameters.kappa * yPrime * yPrime; + double zPrime = startingPoint.z() + _parameters.tanLambda * yPrime; + double x = xPrime * cos(theta) - yPrime * sin(theta); + double y = yPrime * cos(theta) + xPrime * sin(theta); + return new CartesianPoint(x, y, zPrime); + } + + // TODO implementation + public ZvFitStatus getSwimStatus() { + return ZvFitStatus.FAILED_ON_ENTRY; + } + + // Rotate the coordinate system, so that the y axis is parallel to the + // momentum vector + SpacePoint rotateLocation(SpacePoint oldPoint) { + // z stays the same + double z = oldPoint.z(); + // rotate only in the x-y plane + + double x = oldPoint.x(); + double y = oldPoint.y(); + double theta = trackRotationAngle; + + double xPrime = x * cos(theta) + y * sin(theta); + double yPrime = -x * sin(theta) + y * cos(theta); + SpacePoint result = new CartesianPoint(xPrime, yPrime, z); + return result; + } + + public SpacePoint referencePoint() { + updateRefPoint(); + return _referencePoint; + } + + public Hep3Vector momentum() { + updateMomentum(); + return _momentum; + } + + public ZvTrack(Track t) { + fitSuccess = t.fitSuccess(); + orgTrack = t; + _charge = t.getCharge(); + _refPointIsPCA = t.isReferencePointPCA(); + _errorMatrix = t.getErrorMatrix(); + double px = t.getPX(); + double py = t.getPY(); + double pt = sqrt(px * px + py * py); + + _parameters = new ZvParameters(); + _parameters.kappa = t.getTrackParameter(2); + // FIXME hardcoded order - dangerous + // ZvTrack.phi == Track.phi0 :-( + // FIXME phi == trackRotationAngle ? + _parameters.phi = t.getTrackParameter(1); + _parameters.tanLambda = t.getTrackParameter(4); + _parameters.x = t.getReferencePointX(); + _parameters.y = t.getReferencePointY(); + _parameters.z = t.getReferencePointZ(); + updateMomentum(); + updateRefPoint(); + if (!_refPointIsPCA) { + System.err.println("WARNING ! Reference Point should be PCA"); + } + if (px < 0.0) + trackRotationAngle = acos(py / pt); + else + trackRotationAngle = -acos(py / pt); + return; + } + + /** + * Calculates the momentum from the parameters + */ + private void updateMomentum() { + double pt = 1 / _parameters.kappa; + double px = pt * Math.cos(_parameters.phi); + double py = pt * Math.sin(_parameters.phi); + double pz = pt * _parameters.tanLambda; + _momentum = new BasicHep3Vector(px, py, pz); + + } + + /** + * Calculates the reference point from the parameters + */ + private void updateRefPoint() { + _referencePoint = new CartesianPoint(_parameters.x, _parameters.y, _parameters.z); + } + + /** + * Fills the errorMatrix of a ZvTrack from a double[5][5] of a Track + * + * @param trackMatrix + */ + // TODO implementation + private void convert2ZvErrorMatrix(double[][] trackMatrix) { + + } + + /** + * converts the ZvErrorMatrix back to a Track-compatible Matrix + * + * @return the error Matrix in a Track-compatible way + */ + // TODO implementation + private SymmetricMatrix convert2TrackErrorMatrix() { + return _errorMatrix; + } + + + /** + * Calculates the lengthParameter s at which the ZvTrack is closest to the + * given SpacePoint + * + * @param point + * The point in space to which to calculate the distance + * @return the length parameter + */ + // Apologies about the form. Automatic code generation by Maple(C) + double closestParabolaPointOptimized(SpacePoint point) { + double x1 = point.x(); + double y1 = point.y(); + double z1 = point.z(); + double kappa = _parameters.kappa; + double tanLambda = _parameters.tanLambda; + double theta = trackRotationAngle; + double x0 = rotateLocation(_referencePoint).x(); + double z0 = _referencePoint.z(); + double t68; + double t45; + double t25; + double t5; + double t134; + double t172; + double t175; + double t178; + double t39; + double t26; + double t52; + double t157; + double t13; + double t21; + double t3; + double t4; + double t1; + double t2; + double t85; + double t56; + double t8; + double t106; + double t43; + double t96; + double t19; + double t20; + double t31; + double t117; + double t114; + double t27; + double t141; + double t142; + double t9; + double t10; + double t14; + double t65; + double t154; + double t66; + double t67; + double t150; + double t152; + t1 = kappa; + t2 = 0.1e1 / t1; + t3 = tanLambda; + t4 = t3 * t1; + t5 = z0; + t8 = x1 * t1; + t9 = theta; + t10 = Math.sin(t9); + t13 = y1 * t1; + t14 = Math.cos(t9); + t19 = t1 * t1; + t20 = t3 * t3; + t21 = t20 * t19; + t25 = t1 * t19; + t26 = t25 * y1; + t27 = x0 * x0; + t31 = t19 * x1; + t39 = t20 * t20; + t43 = x1 * x1; + t45 = t14 * t14; + t52 = t19 * y1; + t56 = t3 * t19; + t65 = 0.6e1 - 162 * z1 * t5 * t21 - 0.144e3 * t27 * t10 * t26 - 0.144e3 * x0 * t14 * t31 - 0.144e3 * t27 * t14 * t25 * x1 - 0.36e2 * t39 * t14 * t8 + 0.144e3 * x0 * t45 * t25 * t43 - 0.36e2 * t39 * t10 * t13 - 0.144e3 * x0 * t10 * t52 + 0.162e3 * t10 * x1 * t5 * t56 - 0.162e3 * t14 * y1 * t5 * t56; + t66 = y1 * y1; + t67 = t25 * t66; + t68 = t10 * t10; + t85 = t14 * x1; + t96 = t20 * t10; + t106 = -0.144e3 * t14 * x1 * t68 * t67 - 0.18e2 * t14 * x1 * t10 * t52 + 0.6e1 * t20 * t39 - 0.144e3 * t45 * t43 * t10 * t26 + 0.18e2 * t20 + 0.144e3 * t20 * t85 * t10 * t52 + 0.48e2 * t25 * x0 * t27 + 0.288e3 * x0 * t85 * t10 * t26 - 0.144e3 * x0 * t96 * t52 - 0.162e3 * z1 * t3 * t10 * t31 + 0.72e2 * t19 * t27; + t114 = t66 * t19; + t117 = t19 * t43; + t134 = z1 * z1; + t141 = 0.36e2 * t1 * x0 * t39 + 0.72e2 * t1 * x0 * t20 + 0.81e2 * t45 * t114 + 0.72e2 * t45 * t117 - 0.48e2 * t10 * t68 * t25 * y1 * t66 - 0.48e2 * t14 * t45 * t25 * x1 * t43 + 0.81e2 * t68 * t117 + 0.72e2 * t68 * t114 + 81 * t134 * t21 + 0.72e2 * t19 * t27 * t20 + 0.18e2 * t39; + t142 = t20 * t14; + t150 = t1 * x0; + t152 = t14 * t8; + t154 = t5 * t5; + t157 = t10 * t13; + t172 = -0.144e3 * x0 * t142 * t31 + 0.162e3 * z1 * t3 * t14 * t52 + 0.36e2 * t150 - 0.36e2 * t152 + 81 * t154 * t21 - 0.36e2 * t157 - 0.72e2 * t142 * t8 + 0.72e2 * t20 * t68 * t114 + 0.144e3 * x0 * t68 * t67 - 0.72e2 * t96 * t13 + 0.72e2 * t20 * t45 * t117; + t175 = Math.sqrt(t65 + t106 + t141 + t172); + t178 = Math.pow(-54 * t5 * t4 - 0.54e2 * t10 * t8 + 0.54e2 * t14 * t13 + 54 * z1 * t4 + 0.6e1 * t175, 0.1e1 / 0.3e1); + return(t178 * t2 / 0.6e1 + 0.1e1 / t178 * t2 * (0.2e1 * t157 + 0.2e1 * t152 - t20 - 0.2e1 * t150 - 0.1e1)); + } +}
diff -N TrackState.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ TrackState.java 18 Jun 2012 23:02:14 -0000 1.2 @@ -0,0 +1,90 @@
+package org.lcsim.event; + +/** + * The LCIO TrackState interface. + * + * @author gaede, engels + * @author Jeremy McCormick + * @version $Id: TrackState.java,v 1.2 2012/06/18 23:02:14 jeremy Exp $ + */ +public interface TrackState +{ + // TrackState location codes. + public final static int AtOther = 0; // Any location other than the ones defined below. + public final static int AtIP = 1; + public final static int AtFirstHit = 2; + public final static int AtLastHit = 3; + public final static int AtCalorimeter = 4; + public final static int AtVertex = 5; + public final static int LastLocation = AtVertex; + + /** + * The location of the track state. + * Location can be set to: AtIP, AtFirstHit, AtLastHit, AtCalorimeter, AtVertex, AtOther + */ + public int getLocation(); + + /** + * Impact paramter of the track in (r-phi). + */ + public double getD0(); + + /** + * Phi of the track at the reference point. + * @see getReferencePoint + */ + public double getPhi(); + + /** + * Omega is the signed curvature of the track in [1/mm]. + * The sign is that of the particle's charge. + */ + public double getOmega(); + + /** + * Impact paramter of the track in (r-z). + */ + public double getZ0(); + + /** + * Lambda is the dip angle of the track in r-z at the reference point. + * @see getReferencePoint + */ + public double getTanLambda(); + + /** + * Get the ordered list of 5 LCIO track parameters. + * @return The track parameters as a double array of size 5. + */ + public double[] getParameters(); + + /** + * Covariance matrix of the track parameters. Stored as lower triangle matrix where + * the order of parameters is: d0, phi, omega, z0, tan(lambda). + * So we have cov(d0,d0), cov( phi, d0 ), cov( phi, phi), ... + * @return A double array of size 15 containing the covariance matrix of the track parameters. + */ + public double[] getCovMatrix(); + + /** + * Reference point of the track parameters. + * The default for the reference point is the point of closest approach. + * @return The reference point of the track parameters as a double array of size 3. + */ + public double[] getReferencePoint(); + + public double[] getMomentum(); + + /** + * Get an individual track parameter. + * They are returned by the following keys: + * 0 = d0 + * 1 = phi + * 2 = omega + * 3 = z0 + * 4 = tanLambda + * This order is defined in BaseTrack. + * @return The track parameters. + */ + public double getParameter(int iparam); +}
\ No newline at end of file
diff -u -r1.11 -r1.12 --- Track.java 23 May 2008 06:53:35 -0000 1.11 +++ Track.java 18 Jun 2012 23:02:14 -0000 1.12 @@ -9,7 +9,7 @@
* Represents a found (reconstructed) track * * @author tonyj
- * @version $Id: Track.java,v 1.11 2008/05/23 06:53:35 jeremy Exp $
+ * @version $Id: Track.java,v 1.12 2012/06/18 23:02:14 jeremy Exp $
*/ public interface Track
@@ -124,6 +124,8 @@
List<TrackerHit> getTrackerHits(); int getType();
+ + List<TrackState> getTrackStates();
// double parameter(ParameterName n); // similar name is not a problem, because of different signature
diff -N BaseTrackState.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ BaseTrackState.java 18 Jun 2012 23:02:14 -0000 1.2 @@ -0,0 +1,249 @@
+package org.lcsim.event.base; + +import static java.lang.Math.abs; + +import java.io.PrintStream; + +import org.lcsim.constants.Constants; +import org.lcsim.event.TrackState; + +/** + * Implementation of the org.lcsim.event.TrackState interface. + * @author Jeremy McCormick + * @version $Id: BaseTrackState.java,v 1.2 2012/06/18 23:02:14 jeremy Exp $ + */ +public class BaseTrackState implements TrackState +{ + public static final int PARAMETERS_SIZE = 5; // Number of LCIO track parameters. + public static final int REF_POINT_SIZE = 3; // Size of reference point (x, y, z). + public static final int MOMENTUM_SIZE = 3; // Size of momentum array (px, py, pz). + public static final int COV_MATRIX_SIZE = 15; // Size of covariance matrix array. + + // Initialization here is wasteful, but it protects against users leaving these null. + private double[] _parameters = new double[PARAMETERS_SIZE]; // Parameters array. + private double[] _referencePoint = new double[REF_POINT_SIZE]; // Reference point. + private double[] _covMatrix = new double[COV_MATRIX_SIZE]; // Covariance matrix. + //TODO what is momentum doing here? + private double[] momentum; + + // Location encoding. + private int _location = TrackState.AtIP; // default location + + public BaseTrackState() + {} + + //fully qualified constructor + public BaseTrackState(double[] trackParameters, double[] covarianceMatrix, double[] position, int location) + { + _location = location; + System.arraycopy(trackParameters, 0, _parameters, 0, PARAMETERS_SIZE); + System.arraycopy(covarianceMatrix, 0, _covMatrix, 0, COV_MATRIX_SIZE); + System.arraycopy(position,0, _referencePoint, 0, REF_POINT_SIZE); + } + + // Ctor with parameters and B-field. + // The reference point, covariance matrix, and location can be set later. + public BaseTrackState(double[] parameters, double bfield) + { + setParameters(parameters, bfield); + } + + // Fully qualified constructor. + public BaseTrackState(double[] parameters, double[] referencePoint, double[] covMatrix, int location, double bfield) + { + setParameters(parameters, bfield); + setReferencePoint(referencePoint); + setCovMatrix(covMatrix); + setLocation(location); + } + + public int getLocation() + { + return _location; + } + + public double[] getReferencePoint() + { + return _referencePoint; + } + + public double[] getCovMatrix() + { + return _covMatrix; + } + + public double getD0() + { + return _parameters[BaseTrack.D0]; + } + + public double getPhi() + { + return _parameters[BaseTrack.PHI]; + } + + public double getZ0() + { + return _parameters[BaseTrack.Z0]; + } + + public double getOmega() + { + return _parameters[BaseTrack.OMEGA]; + } + + public double getTanLambda() + { + return _parameters[BaseTrack.TANLAMBDA]; + } + + public void setD0(double d0) + { + _parameters[BaseTrack.D0] = d0; + } + + public void setPhi(double phi) + { + _parameters[BaseTrack.PHI] = phi; + } + + public void setZ0(double z0) + { + _parameters[BaseTrack.Z0] = z0; + } + + public void setOmega(double d) + { + _parameters[BaseTrack.OMEGA] = d; + } + + public void setTanLambda(double d) + { + _parameters[BaseTrack.TANLAMBDA] = d; + } + + public void setLocation(int location) + { + if (location < 0 || location > TrackState.LastLocation) + throw new IllegalArgumentException("The location must be between 0 and " + TrackState.LastLocation); + this._location = location; + } + + // FIXME Should be array copy? + public void setReferencePoint(double[] referencePoint) + { + if (referencePoint.length != REF_POINT_SIZE) throw new IllegalArgumentException("referencePoint.length != " + REF_POINT_SIZE); + this._referencePoint = referencePoint; + } + + // FIXME Should be array copy? + public void setCovMatrix(double[] covMatrix) + { + if (covMatrix.length != COV_MATRIX_SIZE) throw new IllegalArgumentException("covMatrix.length != " + COV_MATRIX_SIZE); + this._covMatrix = covMatrix; + } + + // If setParameters or a qualified constructor was not called, this could be null. + public double[] getMomentum() + { + return momentum; + } + + // Get a track parameter by ordinal. + public double getParameter(int param) + { + if (param < 0 || param > (PARAMETERS_SIZE - 1)) + throw new IllegalArgumentException("Parameter ordinal " + param + " is invalid."); + return _parameters[param]; + } + + // Get the parameters as a double array. + // Use ordinals in BaseTrack for the index into the array. + public double[] getParameters() + { + return _parameters; + } + + /** + * Set the track parameters. Computes momentum and charge, also. + * @param p + * @param bfield + */ + public void setParameters(double[] p, double bfield) + { + copyParameters(p, _parameters); + computeMomentum(bfield); + } + + static final void copyParameters(double[] p1, double[] p2) + { + if (p1.length != 5) + throw new IllegalArgumentException("First array is not size " + PARAMETERS_SIZE); + if (p2.length != 5) + throw new IllegalArgumentException("Second aray is not size" + PARAMETERS_SIZE); + System.arraycopy(p1, 0, p2, 0, PARAMETERS_SIZE); + } + + /** + * Compute the momentum of this TrackState, setting the internal array containing (px,py,pz), + * and return the result. + * @param bz The B-field in Z. + * @return The computed momentum. + */ + public double[] computeMomentum(double bz) + { + momentum = computeMomentum(this, bz); + return momentum; + } + + /** + * Compute the momentum of a TrackState, given a Bz field component. + * @param ts The TrackState. + * @param Bz The magnetic field component Bz. + * @return The momentum computed from the TrackState's parameters. + */ + public static final double[] computeMomentum(TrackState ts, double magneticField) + { + double omega = ts.getOmega(); + if(abs(omega) < 0.0000001) omega = 0.0000001; + double Pt = abs((1./omega) * magneticField * Constants.fieldConversion); + double[] momentum = new double[3]; + momentum[0] = Pt * Math.cos(ts.getPhi()); + momentum[1] = Pt * Math.sin(ts.getPhi()); + momentum[2] = Pt * ts.getTanLambda(); + return momentum; + } + + /** + * Convert object to a String. + */ + public String toString() + { + StringBuffer buff = new StringBuffer(); + buff.append("location = " + getLocation() + "\n"); + buff.append("D0 = " + getD0() + "\n"); + buff.append("phi = " + getPhi() + "\n"); + buff.append("Z0 = " + getZ0() + "\n"); + buff.append("tanLambda = " + getTanLambda() + "\n"); + buff.append("omega = " + getOmega() + "\n"); + buff.append("referencePoint = " + _referencePoint[0] + " " + _referencePoint[1] + " " + _referencePoint[2] + "\n"); + buff.append("covarianceMatrix = "); + for (int i=0; i<_covMatrix.length; i++) + { + buff.append(_covMatrix[i] + " "); + } + buff.append("\n"); + buff.append("momentum = "); + for (int i=0; i<this.MOMENTUM_SIZE; i++) + { + buff.append(momentum[i] + " "); + } + buff.append("\n"); + return buff.toString(); + } + + public void printOut(PrintStream ps) + { + ps.println(toString()); + } +}
\ No newline at end of file
diff -u -r1.12 -r1.13 --- BaseTrack.java 12 Jun 2012 17:36:12 -0000 1.12 +++ BaseTrack.java 18 Jun 2012 23:02:14 -0000 1.13 @@ -1,62 +1,104 @@
-/* - * BaseTrack.java - * - * Created on March 24, 2006, 9:18 PM - * - * $Id: BaseTrack.java,v 1.12 2012/06/12 17:36:12 jeremy Exp $ - */ -
package org.lcsim.event.base;
+import static java.lang.Math.abs; +import static java.lang.Math.signum;
import hep.physics.matrix.SymmetricMatrix;
-import java.util.List;
+
import java.util.ArrayList;
+import java.util.List; +
import org.lcsim.constants.Constants;
-import org.lcsim.event.LCIOParameters;
import org.lcsim.event.LCIOParameters.ParameterName; import org.lcsim.event.Track;
+import org.lcsim.event.TrackState;
import org.lcsim.event.TrackerHit;
-import static java.lang.Math.abs; -import static java.lang.Math.signum;
/**
- *
+ * Base implementation of LCIO Track interface. + * + * Modified for LCIO v2 compatibility: added TrackStates. + *
* @author Norman Graf
+ * @author Jeremy McCormick + * @version $Id: BaseTrack.java,v 1.13 2012/06/18 23:02:14 jeremy Exp $
*/
+// FIXME: Needs to be made compatible with LCIO 2.0 which has TrackStates.
public class BaseTrack implements Track {
+ // These three now stored in TrackStates but kept here for backward compatibility.
protected double[] _refPoint = new double[3];
- protected boolean _refPointIsDCA = true;
protected double[] _parameters = new double[5]; protected SymmetricMatrix _covMatrix = new SymmetricMatrix(5);
+
protected double[] _momentum = new double[3];
+ protected double _chi2; + protected boolean _refPointIsDCA = true;
protected int _charge; protected boolean _fitSuccess = true;
- protected double _chi2;
protected int _ndf; protected double _dEdx; protected double _dEdxErr; protected double _innermostHitRadius = 9999.;
+ protected int _type;
protected int[] _subdetId = new int[1];
+ + // References to other objects.
protected List<Track> _tracks; protected List<TrackerHit> _hits;
- protected int _type;
+ protected List<TrackState> _trackStates; + + // Parameter ordering. + public static final int D0 = ParameterName.d0.ordinal(); + public static final int PHI = ParameterName.phi0.ordinal(); + public static final int OMEGA = ParameterName.omega.ordinal(); + public static final int TANLAMBDA = ParameterName.tanLambda.ordinal(); + public static final int Z0 = ParameterName.z0.ordinal();
- protected static final int D0 = ParameterName.d0.ordinal(); - protected static final int PHI = ParameterName.phi0.ordinal(); - protected static final int OMEGA = ParameterName.omega.ordinal(); - protected static final int TANLAMBDA = ParameterName.tanLambda.ordinal(); - protected static final int Z0 = ParameterName.z0.ordinal();
/** Creates a new instance of BaseTrack */ public BaseTrack() { _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, double magneticField) + { + // Copy to this object's parameters array. + System.arraycopy(params, 0, _parameters, 0, 5); + + // Compute momentum from parameters and magnetic field. + double omega = _parameters[OMEGA]; + if(abs(omega) < 0.0000001) omega=0.0000001; + double Pt = abs((1./omega) * magneticField* Constants.fieldConversion); + _momentum[0] = Pt * Math.cos(_parameters[PHI]); + _momentum[1] = Pt * Math.sin(_parameters[PHI]); + _momentum[2] = Pt * _parameters[TANLAMBDA]; + + // Compute charge. + _charge = (int) signum(omega); + + // LCIO v2 ... setup a TrackState with full parameter list. + getFirstTrackState().setParameters(params, magneticField); + } +
// TODO replace this with a SpacePoint /** * Set the reference point for this track. By default it is (0,0,0).
@@ -64,11 +106,26 @@
* @param point The (x,y,z) reference point for this track. */ public void setReferencePoint(double[] point)
- { - _refPoint = point;
+ { + this._refPoint = point; + + // Set the ref point on the first TrackState. + getFirstTrackState().setReferencePoint(point);
} /**
+ * Set the covariance matrix for the track parameters. + * @param cov The covariance matrix as a SymetricMatrix. + */ + public void setCovarianceMatrix(SymmetricMatrix cov) + { + _covMatrix = cov; + + // Set the covariance matrix on the TrackState, converting to a double array. + getFirstTrackState().setCovMatrix(_covMatrix.asPackedArray(true)); + } + + /**
* Sets whether the reference point is the distance of closest * approach to the origin. * @param isDCA true if the reference point is the dca.
@@ -92,38 +149,12 @@
} /**
- * Set the track parameters. - * @see LCIOParameters - * @param params The array of track parameters. - */ - public void setTrackParameters(double[] params, double magneticField) - { - System.arraycopy(params, 0, _parameters, 0, 5); - double omega = _parameters[OMEGA]; - if(abs(omega) < 0.0000001) omega=0.0000001; - double Pt = abs((1./omega) * magneticField* Constants.fieldConversion); - _momentum[0] = Pt * Math.cos(_parameters[PHI]); - _momentum[1] = Pt * Math.sin(_parameters[PHI]); - _momentum[2] = Pt * _parameters[TANLAMBDA]; - _charge = (int) signum(omega); - } - - /** - * Set the covariance matrix for the track parameters. - * @param cov The covariance matrix as a double array. - */ - public void setCovarianceMatrix(SymmetricMatrix cov) - { - _covMatrix = cov; - } - - /**
* Set the chi-squared for the track fit. * Not defined whether this is the full or reduced chi-squared. * @param chisq The value of the track fit chi-squared. */ // TODO verify if this is full or reduced chi-squared.
- public void setChisq( double chisq)
+ public void setChisq(double chisq)
{ _chi2 = chisq; }
@@ -132,7 +163,7 @@
* Set the number of degrees of freedom for this track fit. * @param n The number of degrees of freedom for this track fit. */
- public void setNDF( int n)
+ public void setNDF(int n)
{ _ndf = n; }
@@ -375,11 +406,6 @@
{ 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.
@@ -405,4 +431,12 @@
{ return _type; }
+ /** + * Get the list of associated LCIO v2 TrackStates. + * @return The list of TrackStates. + */ + public List<TrackState> getTrackStates() + { + return this._trackStates; + }
}
\ No newline at end of file
diff -u -r1.10 -r1.11 --- ReconTrack.java 25 Apr 2008 06:13:09 -0000 1.10 +++ ReconTrack.java 18 Jun 2012 23:02:14 -0000 1.11 @@ -6,6 +6,8 @@
import hep.physics.particle.Particle; import hep.physics.vec.Hep3Vector; import org.lcsim.event.Track;
+import org.lcsim.event.TrackState; +
import java.io.*; import java.util.Collections; import java.util.List;
@@ -19,7 +21,7 @@
* are provided. <br> * * @author Tony Johnson, Wolfgang Walkowiak
- * @version $Id: ReconTrack.java,v 1.10 2008/04/25 06:13:09 timb Exp $
+ * @version $Id: ReconTrack.java,v 1.11 2012/06/18 23:02:14 jeremy Exp $
*/ public class ReconTrack implements Track {
@@ -559,4 +561,9 @@
} return errMatrix; }
-}
+ + public List<TrackState> getTrackStates() + { + return null; + } +}
\ No newline at end of file
diff -u -r1.1 -r1.2 --- FastMCTrack.java 29 Nov 2007 21:29:35 -0000 1.1 +++ FastMCTrack.java 18 Jun 2012 23:02:14 -0000 1.2 @@ -1,5 +1,5 @@
/**
- * @version $Id: FastMCTrack.java,v 1.1 2007/11/29 21:29:35 jstrube Exp $
+ * @version $Id: FastMCTrack.java,v 1.2 2012/06/18 23:02:14 jeremy Exp $
*/ package org.lcsim.mc.fast.tracking.fix;
@@ -12,6 +12,7 @@
import org.lcsim.event.LCIOParameters; import org.lcsim.event.MCParticle; import org.lcsim.event.Track;
+import org.lcsim.event.TrackState;
import org.lcsim.event.TrackerHit; import org.lcsim.event.LCIOParameters.ParameterName; import org.lcsim.spacegeom.CartesianPoint;
@@ -187,4 +188,9 @@
public SpacePoint referencePoint() { return _referencePoint; }
-}
+ + public List<TrackState> getTrackStates() + { + return null; + } +}
\ No newline at end of file
diff -u -r1.3 -r1.4 --- TrackTableModel.java 16 Aug 2007 21:06:58 -0000 1.3 +++ TrackTableModel.java 18 Jun 2012 23:02:14 -0000 1.4 @@ -8,18 +8,40 @@
*/ class TrackTableModel extends GenericTableModel {
- private static final String[] columns = {"Type","D0","Phi","Omega","Z0","TanLambda","Chi2","NDF","dEdx","Momentum"};
+ private static final String[] columns = {"Type", "D0", "Phi", "Omega", "Z0", "TanLambda", "Track States", "Momentum", "Chi2", "NDF", "dEdx"}; + //, "Momentum"};
private static Class klass = Track.class; TrackTableModel() {
- super(klass,columns);
+ super(klass,columns);
} public Object getValueAt(int row, int column) {
- if (column > 0 && column <= 5) return ((Track) getData(row)).getTrackParameter(column-1); - else return super.getValueAt(row,column);
+ if (column == 0) + { + // Track type (???). + return ((Track)getData(row)).getType(); + } + else if (column >= 1 && column <= 5) + { + // Displays data about first TrackState, only. + return ((Track)getData(row)).getTrackStates().get(0).getParameter(column-1); + } + else if (column == 6) + { + // Number of total TrackStates. + return ((Track)getData(row)).getTrackStates().size(); + } + else if (column == 7) + { + return ((Track)getData(row)).getTrackStates().get(0).getMomentum(); + } + else + { + return super.getValueAt(row,column); + }
} public Class getColumnClass(int column)
@@ -27,4 +49,4 @@
if (column > 0 && column <= 5) return Double.class; else return super.getColumnClass(column); }
-}
+}
\ No newline at end of file
diff -u -r1.2 -r1.3 --- GarfieldTrack.java 21 Sep 2007 12:07:47 -0000 1.2 +++ GarfieldTrack.java 18 Jun 2012 23:02:14 -0000 1.3 @@ -25,7 +25,7 @@
* * @author E. von Toerne * @author D. Onoprienko
- * @version $Id: GarfieldTrack.java,v 1.2 2007/09/21 12:07:47 onoprien Exp $
+ * @version $Id: GarfieldTrack.java,v 1.3 2012/06/18 23:02:14 jeremy Exp $
*/ public class GarfieldTrack implements Track {
@@ -960,7 +960,10 @@
return hel.base(2); }
-
+ public List<TrackState> getTrackStates() + { + return null; + }
}
diff -u -r1.3 -r1.4 --- BasicTrack.java 29 Nov 2007 02:25:59 -0000 1.3 +++ BasicTrack.java 18 Jun 2012 23:02:14 -0000 1.4 @@ -1,6 +1,7 @@
package org.lcsim.recon.cat.util; import java.util.*;
+
import org.lcsim.event.*; import org.lcsim.util.*; import hep.physics.matrix.SymmetricMatrix;
@@ -18,7 +19,7 @@
* Includes method for initializing track parameters from momentum at a given point. * * @author D. Onoprienko
- * @version $Id: BasicTrack.java,v 1.3 2007/11/29 02:25:59 jstrube Exp $
+ * @version $Id: BasicTrack.java,v 1.4 2012/06/18 23:02:14 jeremy Exp $
*/ public class BasicTrack implements Track {
@@ -186,4 +187,8 @@
_conListener.conditionsChanged(null); }
+ public List<TrackState> getTrackStates() + { + return null; + }
}
diff -u -r1.4 -r1.5 --- MakeTracks.java 7 Aug 2009 23:33:17 -0000 1.4 +++ MakeTracks.java 18 Jun 2012 23:02:14 -0000 1.5 @@ -47,10 +47,7 @@
List<Track> tracks = new ArrayList<Track>(); // Initialize the reference point to the origin
- double[] ref = new double[3]; - ref[0] = 0.; - ref[1] = 0.; - ref[2] = 0.;
+ double[] ref = new double[] {0., 0., 0.};
// Loop over the SeedCandidates that have survived for (SeedCandidate trackseed : seedlist) {
@@ -65,14 +62,14 @@
// Retrieve the helix and save the relevant bits of helix info HelicalTrackFit helix = trackseed.getHelix();
- trk.setTrackParameters(helix.parameters(), bfield); - trk.setCovarianceMatrix(helix.covariance());
+ trk.setTrackParameters(helix.parameters(), bfield); // Sets first TrackState. + trk.setCovarianceMatrix(helix.covariance()); // Modifies first TrackState.
trk.setChisq(helix.chisqtot()); trk.setNDF(helix.ndf()[0]+helix.ndf()[1]); // Flag that the fit was successful and set the reference point trk.setFitSuccess(true);
- trk.setReferencePoint(ref);
+ trk.setReferencePoint(ref); // Modifies first TrackState.
trk.setRefPointIsDCA(true); // Set the strategy used to find this track
diff -u -r1.8 -r1.9 --- SeedTrackerTrackStateDriver.java 3 Dec 2010 21:12:26 -0000 1.8 +++ SeedTrackerTrackStateDriver.java 18 Jun 2012 23:02:14 -0000 1.9 @@ -10,6 +10,8 @@
import org.lcsim.event.EventHeader; import org.lcsim.event.GenericObject; import org.lcsim.event.Track;
+import org.lcsim.event.base.BaseTrack; +import org.lcsim.event.base.BaseTrackState;
import org.lcsim.fit.helicaltrack.HelicalTrackCross; import org.lcsim.fit.helicaltrack.HelicalTrackFit; import org.lcsim.fit.helicaltrack.HelicalTrackHit;
@@ -30,11 +32,11 @@
* work due to lost data and type information. And it must be run the * SeedTracker Driver. *
- * @author richp - * @author jeremym - * @author ngraf
+ * @author Rich Partridge + * @author Jeremy McCormick + * @author Norman Graf
*
- * @version $Id: SeedTrackerTrackStateDriver.java,v 1.8 2010/12/03 21:12:26 ngraf Exp $
+ * @version $Id: SeedTrackerTrackStateDriver.java,v 1.9 2012/06/18 23:02:14 jeremy Exp $
*/ public class SeedTrackerTrackStateDriver extends Driver {
@@ -80,7 +82,7 @@
public void process(EventHeader event) { // Get the Tracks from the event. Collection name is SeedTracker's default.
- List<Track> tracks = event.get(Track.class, "Tracks");
+ List<Track> tracks = event.get(Track.class, EventHeader.TRACKS);
// TrackState lists. List<GenericObject> startObjs = new ArrayList<GenericObject>();
@@ -133,6 +135,7 @@
// Calculate the Start state and add to list. double[] smom = ptrk.v(); double[] spos = HelixUtils.PointOnHelix(helix, 0.).v();
+
TrackState startState = new TrackState(spos[0], spos[1], spos[2], smom[0], smom[1], smom[2]); startObjs.add(startState);
@@ -164,4 +167,208 @@
event.put("StateAtECal", ecalObjs, GenericObject.class, 0); event.put("StateAtEnd", endObjs, GenericObject.class, 0); }
+ + private void setEcalTrackState(Track track) + { + SeedTrack strk = (SeedTrack) track; + SeedCandidate scand = strk.getSeedCandidate(); + HelicalTrackFit helix = scand.getHelix(); + Hep3Vector ptrk = new BasicHep3Vector(strk.getMomentum()); + double smax = -9999.; + HelicalTrackHit last = null; + + for (HelicalTrackHit hit : scand.getHits()) + { + double s = helix.PathMap().get(hit); + if (s > smax) + { + smax = s; + last = hit; + } + } + + TrackDirection trkdir = HelixUtils.CalculateTrackDirection(helix, smax); + + Hep3Vector dir = trkdir.Direction(); + Hep3Vector pos = null; + + if (last instanceof HelicalTrackCross) + { + HelicalTrackCross cross = (HelicalTrackCross) last; + cross.setTrackDirection(trkdir, helix.covariance()); + pos = cross.getCorrectedPosition(); + } + else + { + pos = last.getCorrectedPosition(); + } + + // Set the End TrackState from the outermost hit on the track. + Hep3Vector xmomentum = VecOp.mult(ptrk.magnitude(), dir); + + // Set the End TrackState to the point of closest approach to the last hit. + swimmer.setTrack(track); + double s = swimmer.getDistanceToPoint(pos); + Hep3Vector corPos = swimmer.getPointAtLength(s); + + // FIXME Set AtLastHit LCIO v2 TrackState here. + TrackState endState = new TrackState(corPos, xmomentum); + + // Don't need start state anymore????? + // Calculate the Start state and add to list. + //double[] smom = ptrk.v(); + //double[] spos = HelixUtils.PointOnHelix(helix, 0.).v(); + //TrackState startState = new TrackState(spos[0], spos[1], spos[2], smom[0], smom[1], smom[2]); + + // TODO Should set the ECal TrackState by propagating from the outermost hit on the track. + double sZ = swimmer.getDistanceToZ(ecalZ); + double sR = swimmer.getDistanceToPolyhedra(ecalRadius, ecalNumSides); + if (Double.isNaN(sR)) + { + s = sZ; + } + else if (Double.isNaN(sZ)) + { + s = sR; + } + else + { + s = Math.min(swimmer.getDistanceToZ(ecalZ), swimmer.getDistanceToPolyhedra(ecalRadius, ecalNumSides)); + // Should this be changed to... + // s = Math.min(sZ, sR); ????? + } + SpacePoint ecalPos = swimmer.getPointAtLength(s); + SpaceVector ecalMom = swimmer.getMomentumAtLength(s); + + // FIXME Set AtCalorimeter state here. + TrackState ecalState = new TrackState(ecalPos.x(), ecalPos.y(), ecalPos.z(), ecalMom.x(), ecalMom.y(), ecalMom.z()); + // Hmmm...now to recover the track parameters here! + } + + void setTrackStates(Track track) + { + // we need to populate track states at the following four + // canonical locations: + // AtIP + // AtFirstHit + // AtLastHit + // AtCalorimeter + // + List<BaseTrackState> trackStates = new ArrayList<BaseTrackState>(); + SeedTrack strk = (SeedTrack) track; + SeedCandidate scand = strk.getSeedCandidate(); + HelicalTrackFit helixfit = scand.getHelix(); + + // AtIP should be where this track is already defined, but double-check anyway + + int trackStateLocation = BaseTrackState.AtIP; + double[] parameters = strk.getTrackParameters(); + double[] covMatrix = strk.getErrorMatrix().asPackedArray(true); + double[] referencePoint = strk.getReferencePoint(); + + trackStates.add(new BaseTrackState(parameters, covMatrix, referencePoint, trackStateLocation)); + + // at first and last hits... + + double smax = -9999.; + double smin = 9999.; + HelicalTrackHit lastHit = null; + HelicalTrackHit firstHit = null; + + //loop over this hits on this track and get the first and last + for (HelicalTrackHit hit : scand.getHits()) + { + double s = helixfit.PathMap().get(hit); + if (s > smax) + { + smax = s; + lastHit = hit; + } + if(s < smin) + { + smin = s; + firstHit = hit; + } + } + + // AtFirstHit + trackStateLocation = BaseTrackState.AtFirstHit; + referencePoint = HelixUtils.PointOnHelix(helixfit, smin).v(); + // by definition, z0 and d0 are zero at this point + parameters[BaseTrack.D0] = 0.; + parameters[BaseTrack.Z0] = 0.; + // This is the helical track fit + // There is no energy loss so omega does not change with state location + parameters[BaseTrack.OMEGA] = strk.getTrackParameter(BaseTrack.OMEGA); + // There is no multiple scattering, so tan(lambda) does not change + parameters[BaseTrack.TANLAMBDA] = strk.getTrackParameter(BaseTrack.TANLAMBDA); + // only phi changes as we progress along the helix + parameters[BaseTrack.PHI] = helixfit.phi0()-smin/helixfit.R(); + + // TODO calculate correct covariance matrix at this point... + double[] emptyCovarianceMatrix = new double[15]; + trackStates.add(new BaseTrackState(parameters, emptyCovarianceMatrix, referencePoint, trackStateLocation)); + + + //AtlastHit + trackStateLocation = BaseTrackState.AtLastHit; + referencePoint = HelixUtils.PointOnHelix(helixfit, smax).v(); + // only phi changes as we progress along the helix + parameters[BaseTrack.PHI] = helixfit.phi0()-smax/helixfit.R(); + + // TODO calculate correct covariance matrix at this point... + trackStates.add(new BaseTrackState(parameters, emptyCovarianceMatrix, referencePoint, trackStateLocation)); + + + //AtCalorimeter + trackStateLocation = BaseTrackState.AtCalorimeter; + + // start at the last hit position and extrapolate to the + // face of the ECal. + + TrackDirection trkdir = HelixUtils.CalculateTrackDirection(helixfit, smax); + Hep3Vector lastHitPosition = null; + + if (lastHit instanceof HelicalTrackCross) + { + HelicalTrackCross cross = (HelicalTrackCross) lastHit; + cross.setTrackDirection(trkdir, helixfit.covariance()); + lastHitPosition = cross.getCorrectedPosition(); + } + else + { + lastHitPosition = lastHit.getCorrectedPosition(); + } + + // Set the End TrackState to the point of closest approach to the last hit. + swimmer.setTrack(track); + double s = swimmer.getDistanceToPoint(lastHitPosition); + Hep3Vector corPos = swimmer.getPointAtLength(s); + + // Set the ECal TrackState by propagating from the point on the helix + // closest to the outermost hit on the fitted track. + double sZ = swimmer.getDistanceToZ(ecalZ); + double sR = swimmer.getDistanceToPolyhedra(ecalRadius, ecalNumSides); + if (Double.isNaN(sR)) + { + s = sZ; + } + else if (Double.isNaN(sZ)) + { + s = sR; + } + else + { + s = Math.min(swimmer.getDistanceToZ(ecalZ), swimmer.getDistanceToPolyhedra(ecalRadius, ecalNumSides)); + // Should this be changed to... + // s = Math.min(sZ, sR); ????? + } + referencePoint = HelixUtils.PointOnHelix(helixfit, s).v(); + // only phi changes as we progress along the helix + parameters[BaseTrack.PHI] = helixfit.phi0()-s/helixfit.R(); + + // TODO calculate correct covariance matrix at this point... + trackStates.add(new BaseTrackState(parameters, emptyCovarianceMatrix, referencePoint, trackStateLocation)); + + }
}
diff -u -r1.24 -r1.25 --- ZvTrack.java 23 Oct 2006 19:42:26 -0000 1.24 +++ ZvTrack.java 18 Jun 2012 23:02:14 -0000 1.25 @@ -1,5 +1,9 @@
package org.lcsim.recon.vertexing.zvtop4;
+import static java.lang.Math.acos; +import static java.lang.Math.cos; +import static java.lang.Math.sin; +import static java.lang.Math.sqrt;
import hep.physics.matrix.SymmetricMatrix; import hep.physics.vec.BasicHep3Vector; import hep.physics.vec.Hep3Vector;
@@ -8,23 +12,16 @@
import java.util.List; import org.lcsim.event.Track;
+import org.lcsim.event.TrackState;
import org.lcsim.event.TrackerHit;
-import org.lcsim.geometry.compact.converter.lcdd.util.Rotation;
import org.lcsim.spacegeom.CartesianPoint; import org.lcsim.spacegeom.SpacePoint;
-import org.lcsim.util.swim.Helix; - -import static java.lang.Math.sqrt; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static java.lang.Math.acos; -import static java.lang.Math.PI;
/** * Representation of the Gaussian tubes * * @author jstrube
- * @version $Id: ZvTrack.java,v 1.24 2006/10/23 19:42:26 tonyj Exp $
+ * @version $Id: ZvTrack.java,v 1.25 2012/06/18 23:02:14 jeremy Exp $
*/ public class ZvTrack implements Track {
@@ -610,4 +607,9 @@
t178 = Math.pow(-54 * t5 * t4 - 0.54e2 * t10 * t8 + 0.54e2 * t14 * t13 + 54 * z1 * t4 + 0.6e1 * t175, 0.1e1 / 0.3e1); return(t178 * t2 / 0.6e1 + 0.1e1 / t178 * t2 * (0.2e1 * t157 + 0.2e1 * t152 - t20 - 0.2e1 * t150 - 0.1e1)); }
+ + public List<TrackState> getTrackStates() + { + return null; + }
}
diff -u -r1.3 -r1.4 --- AbstractTrack.java 23 Oct 2006 19:42:36 -0000 1.3 +++ AbstractTrack.java 18 Jun 2012 23:02:14 -0000 1.4 @@ -11,6 +11,7 @@
import hep.physics.matrix.SymmetricMatrix; import org.lcsim.event.Track;
+import org.lcsim.event.TrackState;
import org.lcsim.event.TrackerHit; import java.util.ArrayList; import java.util.List;
@@ -37,4 +38,8 @@
public List<Track> getTracks() { List<Track> list = new ArrayList<Track>(); return list; } public List<TrackerHit> getTrackerHits() { List<TrackerHit> list = new ArrayList<TrackerHit>(); return list; } public int getType() { return 0; }
+ public List<TrackState> getTrackStates() + { + return null; + }
}
diff -u -r1.3 -r1.4 --- FoundTrack.java 5 Aug 2005 00:47:00 -0000 1.3 +++ FoundTrack.java 18 Jun 2012 23:02:14 -0000 1.4 @@ -10,6 +10,7 @@
package org.lcsim.recon.ztracking; import org.lcsim.event.SimTrackerHit;
+import org.lcsim.event.TrackState;
import org.lcsim.event.TrackerHit; import java.util.ArrayList; import java.util.List;
@@ -36,4 +37,8 @@
public double getPY() { return py; } public double getPZ() { return pz; } public double[] getMomentum() { return momentum; }
+ public List<TrackState> getTrackStates() + { + return null; + }
}
diff -u -r1.15 -r1.16 --- LCIOConstants.java 24 Aug 2011 18:51:18 -0000 1.15 +++ LCIOConstants.java 18 Jun 2012 23:02:14 -0000 1.16 @@ -6,9 +6,11 @@
*/ public interface LCIOConstants {
- int MAJORVERSION = 1; - int MINORVERSION = 60; -
+ //int MAJORVERSION = 1; + //int MINORVERSION = 60; + int MAJORVERSION = 2; + int MINORVERSION = 0; +
// bits in flag words // SimCalorimeterHit (CH) int CHBIT_LONG = 31;
diff -u -r1.5 -r1.6 --- SIOTrack.java 17 Oct 2007 02:06:23 -0000 1.5 +++ SIOTrack.java 18 Jun 2012 23:02:14 -0000 1.6 @@ -3,134 +3,192 @@
import hep.io.sio.SIOInputStream; import hep.io.sio.SIOOutputStream; import hep.io.sio.SIORef;
-import hep.physics.matrix.SymmetricMatrix;
import java.io.IOException; import java.util.ArrayList; import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
+
import org.lcsim.event.Track;
+import org.lcsim.event.TrackState;
import org.lcsim.event.TrackerHit; import org.lcsim.event.base.BaseTrack;
-
+import org.lcsim.event.base.BaseTrackState;
/**
- *
+ *
* @author Tony Johnson
- * @version $Id: SIOTrack.java,v 1.5 2007/10/17 02:06:23 tonyj Exp $
+ * @author Jeremy McCormick + * @version $Id: SIOTrack.java,v 1.6 2012/06/18 23:02:14 jeremy Exp $
*/ class SIOTrack extends BaseTrack {
- private List<SIORef> tempHits; - private List<SIORef> tempTracks; - - SIOTrack(SIOInputStream in, int flag, int version, double bField) throws IOException - { - _type = in.readInt(); - double[] parameters = new double[5]; - for (int i=0; i<parameters.length; i++) parameters[i] = in.readFloat(); - setTrackParameters(parameters,bField); - double[] covMatrix = new double[15]; - for (int i=0; i<covMatrix.length; i++) covMatrix[i] = in.readFloat(); - _covMatrix = new SymmetricMatrix(5,covMatrix,true); - _refPoint = new double[3]; - _refPoint[0] = in.readFloat(); - _refPoint[1] = in.readFloat(); - _refPoint[2] = in.readFloat(); - _chi2 = in.readFloat(); - _ndf = in.readInt() ; - _dEdx = in.readFloat(); - _dEdxErr = in.readFloat(); - _innermostHitRadius = in.readFloat() ; - int nHitNumbers = in.readInt() ; - _subdetId = new int[nHitNumbers] ; - for (int i = 0; i < nHitNumbers; i++) - { - _subdetId[i] = in.readInt() ; - } - int nTracks = in.readInt(); - tempTracks = new ArrayList(nTracks); - _tracks = null; - for (int i=0; i<nTracks; i++) - { - tempTracks.add(in.readPntr()); - } - if (LCIOUtil.bitTest(flag,LCIOConstants.TRBIT_HITS)) - { - int nHits = in.readInt(); - tempHits = new ArrayList(nHits); - _hits = null; - for (int i = 0; i < nHits; i++) - { - tempHits.add(in.readPntr()); - } - } - - in.readPTag(this); - } - static void write(Track track, SIOOutputStream out, int flag) throws IOException - { - out.writeInt(track.getType()); - double[] parm = track.getTrackParameters(); - for (int i=0; i<5; i++) out.writeFloat((float) parm[i]); - double[] covMatrix = track.getErrorMatrix().asPackedArray(true); - for (int i=0; i<15; i++) out.writeFloat((float) covMatrix[i]); - double[] referencePoint = track.getReferencePoint(); - for (int i=0; i<3; i++) out.writeFloat((float) referencePoint[i]); - out.writeFloat((float) track.getChi2()); - out.writeInt(track.getNDF()); - out.writeFloat((float) track.getdEdx()); - out.writeFloat((float) track.getdEdxError()); - out.writeFloat((float) track.getRadiusOfInnermostHit()) ; - int[] hitNumbers = track.getSubdetectorHitNumbers(); - out.writeInt( hitNumbers.length ) ; - for (int i = 0; i < hitNumbers.length; i++) - { - out.writeInt( hitNumbers[i] ) ; - } - List<Track> tracks = track.getTracks() ; - out.writeInt( tracks.size() ) ; - for (Track t : tracks) - { - out.writePntr(t); - } - if(LCIOUtil.bitTest(flag,LCIOConstants.TRBIT_HITS)) - { - List<TrackerHit> hits = track.getTrackerHits(); - out.writeInt(hits.size()); - for (TrackerHit hit : hits) - { - out.writePntr(hit); - } - } - out.writePTag(track); - } - - public List<TrackerHit> getTrackerHits() - { - if (_hits == null && tempHits != null) - { - _hits = new ArrayList<TrackerHit>(tempHits.size()); - for (SIORef ref : tempHits) - { - _hits.add((TrackerHit) ref.getObject()); - } - tempHits = null; - } - return _hits == null ? Collections.<TrackerHit>emptyList() : _hits; - } - - public List<Track> getTracks() - { - if (_tracks == null && tempTracks != null) - { - _tracks = new ArrayList<Track>(tempTracks.size()); - for (SIORef ref : tempTracks) - { - _tracks.add((Track) ref.getObject()); - } - tempTracks = null; - } - return _tracks == null ? Collections.<Track>emptyList() : _tracks; - } -}
+ private List<SIORef> tempHits; + private List<SIORef> tempTracks; + + SIOTrack(SIOInputStream in, int flag, int version, double bField) throws IOException + { + _type = in.readInt(); + + // read TrackStates + int nTrackStates = 1; // set to 1 per default for backwards compatibility + + if (version>=2000) + { + nTrackStates = in.readInt(); + } + + for (int i = 0; i<nTrackStates; i++) + { + // TODO put this code into SIOTrackState.java ? + BaseTrackState ts = new BaseTrackState(); + + if (version>=2000) + { + ts.setLocation(in.readInt()); + } + + ts.setD0(in.readFloat()); + ts.setPhi(in.readFloat()); + ts.setOmega(in.readFloat()); + ts.setZ0(in.readFloat()); + ts.setTanLambda(in.readFloat()); + + // Compute the momentum while we have access to the B-field. + ts.computeMomentum(bField); + + double[] covMatrix = new double[15]; // FIXME hardcoded 15 + for (int j = 0; j<covMatrix.length; j++) + covMatrix[j] = in.readFloat(); + ts.setCovMatrix(covMatrix); + double[] referencePoint = new double[3]; // FIXME hardcoded 3 + for (int j = 0; j<referencePoint.length; j++) + referencePoint[j] = in.readFloat(); + ts.setReferencePoint(referencePoint); + + getTrackStates().add(ts); + } + + _chi2 = in.readFloat(); + _ndf = in.readInt(); + _dEdx = in.readFloat(); + _dEdxErr = in.readFloat(); + _innermostHitRadius = in.readFloat(); + + int nHitNumbers = in.readInt(); + _subdetId = new int[nHitNumbers]; + for (int i = 0; i<nHitNumbers; i++) + { + _subdetId[i] = in.readInt(); + } + + int nTracks = in.readInt(); + tempTracks = new ArrayList(nTracks); + _tracks = null; + for (int i = 0; i<nTracks; i++) + { + tempTracks.add(in.readPntr()); + } + + if (LCIOUtil.bitTest(flag, LCIOConstants.TRBIT_HITS)) + { + int nHits = in.readInt(); + tempHits = new ArrayList(nHits); + _hits = null; + for (int i = 0; i<nHits; i++) + { + tempHits.add(in.readPntr()); + } + } + + in.readPTag(this); + } + + static void write(Track track, SIOOutputStream out, int flag) throws IOException + { + out.writeInt(track.getType()); + + // write out TrackStates + List<TrackState> trackstates = track.getTrackStates(); + out.writeInt(trackstates.size()); + + for (Iterator it = trackstates.iterator(); it.hasNext();) + { + TrackState trackstate = (TrackState) it.next(); + + // TODO put this code into SIOTrackState.java ? + out.writeInt(trackstate.getLocation()); + out.writeFloat((float)trackstate.getD0()); + out.writeFloat((float)trackstate.getPhi()); + out.writeFloat((float)trackstate.getOmega()); + out.writeFloat((float)trackstate.getZ0()); + out.writeFloat((float)trackstate.getTanLambda()); + double[] covMatrix = trackstate.getCovMatrix(); + for (int i = 0; i<covMatrix.length; i++) + out.writeFloat((float)covMatrix[i]); + double[] referencePoint = trackstate.getReferencePoint(); + for (int i = 0; i<referencePoint.length; i++) + out.writeFloat((float)referencePoint[i]); + } + + out.writeFloat((float) track.getChi2()); + out.writeInt(track.getNDF()); + out.writeFloat((float) track.getdEdx()); + out.writeFloat((float) track.getdEdxError()); + out.writeFloat((float) track.getRadiusOfInnermostHit()); + + int[] hitNumbers = track.getSubdetectorHitNumbers(); + out.writeInt(hitNumbers.length); + for (int i = 0; i<hitNumbers.length; i++) + { + out.writeInt(hitNumbers[i]); + } + + List<Track> tracks = track.getTracks(); + out.writeInt(tracks.size()); + for (Track t: tracks) + { + out.writePntr(t); + } + + if (LCIOUtil.bitTest(flag, LCIOConstants.TRBIT_HITS)) + { + List<TrackerHit> hits = track.getTrackerHits(); + out.writeInt(hits.size()); + for (TrackerHit hit: hits) + { + out.writePntr(hit); + } + } + out.writePTag(track); + } + + public List<TrackerHit> getTrackerHits() + { + if (_hits==null && tempHits!=null) + { + _hits = new ArrayList<TrackerHit>(tempHits.size()); + for (SIORef ref: tempHits) + { + _hits.add((TrackerHit) ref.getObject()); + } + tempHits = null; + } + return _hits==null ? Collections.<TrackerHit> emptyList() : _hits; + } + + public List<Track> getTracks() + { + if (_tracks==null && tempTracks!=null) + { + _tracks = new ArrayList<Track>(tempTracks.size()); + for (SIORef ref: tempTracks) + { + _tracks.add((Track) ref.getObject()); + } + tempTracks = null; + } + return _tracks==null ? Collections.<Track> emptyList() : _tracks; + } +}
\ No newline at end of file
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1