Print

Print


Commit in lcsim/src/org/lcsim/contrib/uiowa on MAIN
ReclusterDriver.java+43-31.40 -> 1.41
MJC: (contrib) Snippet from Ron to calculate the track momentum less fudgedly

lcsim/src/org/lcsim/contrib/uiowa
ReclusterDriver.java 1.40 -> 1.41
diff -u -r1.40 -r1.41
--- ReclusterDriver.java	23 Sep 2008 00:00:28 -0000	1.40
+++ ReclusterDriver.java	29 Sep 2008 20:35:56 -0000	1.41
@@ -1,5 +1,6 @@
 package org.lcsim.contrib.uiowa;
 
+import org.lcsim.util.swim.HelixSwimmer;
 import java.util.*; 
 import java.io.IOException; 
 import hep.aida.*;
@@ -38,7 +39,7 @@
   *
   * This version is PRELIMINARY.
   *
-  * @version $Id: ReclusterDriver.java,v 1.40 2008/09/23 00:00:28 tjkim Exp $
+  * @version $Id: ReclusterDriver.java,v 1.41 2008/09/29 20:35:56 mcharles Exp $
   * @author Mat Charles
   */
 
@@ -57,6 +58,7 @@
     boolean m_useSteveMipsForChargedCalibration = false;
     boolean m_useSteveMipsForConeScoring = false;
     boolean m_useOldReassignmentAlgorithmForConeScore = false;
+    boolean m_calculateMomentumProperly = true;
 
     boolean m_megaDebug = false;
     boolean m_debug = false;
@@ -1635,6 +1637,8 @@
 	if (inputClusters == null) { throw new NullPointerException("null cluster collection"); }
 	BasicCluster magicCombinedCluster = new BasicCluster();
 	for (Cluster clus : inputClusters) {
+	    if (clus == null) { throw new AssertionError("Null cluster! Seen when combining "+inputClusters.size()+" clusters."); }
+	    for (CalorimeterHit hit : clus.getCalorimeterHits()) { if (hit == null) { throw new AssertionError("Null hit!"); } }
 	    magicCombinedCluster.addCluster(clus);
 	}
 	return magicCombinedCluster;
@@ -3322,7 +3326,32 @@
     protected Hep3Vector momentum(Track tr) {
 	Hep3Vector totalMomentum = null;
 	if (tr instanceof BaseTrackMC) {
-	    totalMomentum = ((BaseTrackMC)(tr)).getMCParticle().getMomentum();
+	    // Use MC info
+	    if (m_calculateMomentumProperly) {
+		// Code from Ron
+		List<LCRelation> tml1 = m_event.get(LCRelation.class,"ReconTracksToMCP");
+		List<LCRelation> tml2 = m_event.get(LCRelation.class,"TracksToMCP");
+		MCParticle p = null;
+		for(LCRelation tm:tml1) {
+		    if( (Track) (tm.getFrom()) == tr ) {
+			p = (MCParticle) (tm.getTo());
+			break;
+		    }
+		}
+		Hep3Vector mom = null;
+		Hep3Vector ref = null;
+		Track smt = null;
+		for(LCRelation tm:tml2) {
+		    if( (MCParticle) tm.getTo() == p) {
+			mom = ( (ReconTrack) (tm.getFrom()) ).getDocaMomentumVec(p.getOrigin());
+			ref = ( (ReconTrack) (tm.getFrom()) ).getDocaPositionVec(p.getOrigin());
+			smt = (Track)(tm.getFrom());
+		    }
+		}
+		totalMomentum = mom;
+	    } else {
+		totalMomentum = ((BaseTrackMC)(tr)).getMCParticle().getMomentum();
+	    }
 	} else if (tr instanceof MultipleTrackTrack) {
 	    totalMomentum = new BasicHep3Vector(0,0,0);
 	    for (Track subtr : tr.getTracks()) {
@@ -3335,7 +3364,18 @@
 		totalMomentum = VecOp.add(totalMomentum, subTrackMomentum);
 	    }
 	} else {
-	    totalMomentum = new BasicHep3Vector(tr.getMomentum());
+	    if (m_calculateMomentumProperly) {
+		// Code from Ron
+		HelixSwimmer hs = new HelixSwimmer(5.); // FIXME: Don't hard-code B-field!!!
+		hs.setTrack(tr);
+		Hep3Vector refPoint = new BasicHep3Vector(tr.getReferencePoint()); // IFFY -- This may not be the start point of track.
+		double d = hs.getTrackLengthToPoint(refPoint);
+		Hep3Vector smom = hs.getMomentumAtLength(d);
+		Hep3Vector sref = hs.getPointAtLength(d);
+		totalMomentum = smom;
+	    } else {
+		totalMomentum = new BasicHep3Vector(tr.getMomentum());
+	    }
 	}
 	return totalMomentum;
     }
CVSspam 0.2.8