lcsim/src/org/lcsim/contrib/Partridge/TrackingTest
diff -N ResolutionAnalysis.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ResolutionAnalysis.java 8 Nov 2008 02:33:40 -0000 1.1
@@ -0,0 +1,65 @@
+/*
+ * ResolutionAnalysis.java
+ *
+ * Created on November 7, 2008, 5:37 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.lcsim.contrib.Partridge.TrackingTest;
+
+import hep.physics.vec.BasicHep3Vector;
+import java.util.List;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.LCRelation;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.RelationalTable;
+import org.lcsim.event.Track;
+import org.lcsim.event.base.BaseRelationalTable;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ *
+ * @author richp
+ */
+public class ResolutionAnalysis extends Driver {
+ private AIDA aida = AIDA.defaultInstance();
+
+ /** Creates a new instance of ResolutionAnalysis */
+ public ResolutionAnalysis() {
+ }
+
+ public void process(EventHeader event) {
+
+ // Create a relational table that maps TrackerHits to MCParticles
+ RelationalTable hittomc = new BaseRelationalTable(RelationalTable.Mode.MANY_TO_MANY, RelationalTable.Weighting.UNWEIGHTED);
+ List<LCRelation> mcrelations = event.get(LCRelation.class, "HelicalTrackMCRelations");
+ for (LCRelation relation : mcrelations) {
+ hittomc.add(relation.getFrom(), relation.getTo());
+ }
+
+ List<Track> tracklist = event.getTracks();
+ if (tracklist.size() > 1) System.out.println("Found "+tracklist.size()+" Tracks!");
+ for (Track track : tracklist) {
+ TrackAnalysis tkanal = new TrackAnalysis(track, hittomc);
+ MCParticle mcp = tkanal.getMCParticle();
+ if (mcp != null) {
+ double ptrk = (new BasicHep3Vector(track.getMomentum())).magnitude();
+ double pmc = mcp.getMomentum().magnitude();
+ double pdif = ptrk - pmc;
+ if (mcp.getCharge() > 0.) {
+ aida.cloud1D("Momentum error for positive tracks").fill(pdif);
+ } else {
+ aida.cloud1D("Momentum error for negative tracks").fill(pdif);
+ }
+ aida.cloud1D("Momentum error for all tracks").fill(pdif);
+ aida.cloud1D("Track momentum for all tracks").fill(ptrk);
+ aida.cloud1D("MC momentum for all tracks").fill(pmc);
+ aida.cloud1D("Momentum resolution for all tracks").fill(pdif/pmc);
+ }
+
+ }
+ }
+}
\ No newline at end of file
lcsim/src/org/lcsim/contrib/Partridge/TrackingTest
diff -u -r1.1 -r1.2
--- TrackAnalysis.java 18 Oct 2008 01:36:01 -0000 1.1
+++ TrackAnalysis.java 8 Nov 2008 02:33:40 -0000 1.2
@@ -9,11 +9,12 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import org.lcsim.event.MCParticle;
+import org.lcsim.event.RelationalTable;
import org.lcsim.event.Track;
import org.lcsim.event.TrackerHit;
-import org.lcsim.fit.helicaltrack.HelicalTrackHit;
/**
*
@@ -21,13 +22,13 @@
*/
public class TrackAnalysis {
private enum HelixPar {Curvature, Phi0, DCA, Z0, Slope};
- private MCParticle _mcp;
+ private MCParticle _mcp = null;
private int _nhits;
private int _nbadhits;
private double _purity;
/** Creates a new instance of TrackAnalysis */
- public TrackAnalysis(Track trk) {
+ public TrackAnalysis(Track trk, RelationalTable hittomc) {
// Get the number of hits on the track
_nhits = trk.getTrackerHits().size();
@@ -37,27 +38,30 @@
// Loop over the hits on the track and make sure we have HelicalTrackHits (which contain the MC particle)
for (TrackerHit hit : trk.getTrackerHits()) {
- if (!(hit instanceof HelicalTrackHit)) throw new RuntimeException("AnalysisUtils found track with non-HelicalTrackHits");
-
- // Loop over the MCParticles for this hit and update their hit count
- for (MCParticle mcp : ((HelicalTrackHit) hit).getMCParticles()) {
+
+ // get the set of MCParticles associated with this hit and update the hit count for each MCParticle
+ Set<MCParticle> mclist = hittomc.allFrom(hit);
+ for (MCParticle mcp : mclist) {
Integer mchits = 0;
if (mcmap.containsKey(mcp)) mchits = mcmap.get(mcp);
- mcmap.put(mcp, mchits++);
+ mchits++;
+ mcmap.put(mcp, mchits);
}
}
// Find the MCParticle that has the most hits on the track
int nbest = 0;
+ MCParticle mcbest = null;
for (MCParticle mcp : mcmap.keySet()) {
int count = mcmap.get(mcp);
if (count > nbest) {
nbest = count;
- _mcp = mcp;
+ mcbest = mcp;
}
}
+ if (nbest > 1) _mcp = mcbest;
_purity = (double) nbest / (double) _nhits;
_nbadhits = _nhits - nbest;
@@ -79,7 +83,4 @@
return _purity;
}
-// public double getHelixResidual(HelixPar par) {
-// if (par == HelixPar.Curvature) return
-// }
}