lcsim/src/org/lcsim/contrib/Partridge/TrackingTest
diff -N FindableTrack.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ FindableTrack.java 4 Nov 2008 21:18:54 -0000 1.1
@@ -0,0 +1,169 @@
+/*
+ * FindableTrack.java
+ *
+ * Created on October 24, 2008, 9:50 PM
+ *
+ */
+
+package org.lcsim.contrib.Partridge.TrackingTest;
+
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.lcsim.event.EventHeader;
+
+import org.lcsim.event.MCParticle;
+import org.lcsim.fit.helicaltrack.HelicalTrackHit;
+import org.lcsim.fit.helicaltrack.HelixParamCalculator;
+import org.lcsim.recon.tracking.seedtracker.SeedLayer;
+import org.lcsim.recon.tracking.seedtracker.SeedLayer.SeedType;
+import org.lcsim.recon.tracking.seedtracker.SeedStrategy;
+
+/**
+ *
+ * @author Richard Partridge
+ * @version 1.0
+ */
+public class FindableTrack {
+ public enum Ignore {NoPTCut, NoDCACut, NoZ0Cut, NoSeedCheck, NoConfirmCheck, NoMinHitCut};
+ private double _bfield;
+ private List<HelicalTrackHit> _hitlist;
+ private Map<MCParticle, List<HelicalTrackHit>> _hitmap;
+
+ /** Creates a new instance of FindableTrack */
+ public FindableTrack(EventHeader event, String hitcolname) {
+
+ // Get the magnetic field
+ Hep3Vector IP = new BasicHep3Vector(0., 0., 1.);
+ _bfield = event.getDetector().getFieldMap().getField(IP).z();
+
+ // Get the HelicalTrackHits
+ _hitlist = (List<HelicalTrackHit>) event.get(HelicalTrackHit.class, hitcolname);
+
+ // Make a map between the MCParticles and the hits on the MCParticle
+ _hitmap = new HashMap<MCParticle, List<HelicalTrackHit>>();
+ for (HelicalTrackHit hit : _hitlist) {
+ for (MCParticle mcp : hit.getMCParticles()) {
+ if (!_hitmap.containsKey(mcp)) _hitmap.put(mcp, new ArrayList<HelicalTrackHit>());
+ _hitmap.get(mcp).add(hit);
+ }
+ }
+ }
+
+ public boolean isFindable(MCParticle mcp, List<SeedStrategy> slist) {
+ return isFindable(mcp, slist, new ArrayList<Ignore>());
+ }
+
+ public boolean isFindable(MCParticle mcp, List<SeedStrategy> slist, List<Ignore> ignores) {
+
+ // We can't find neutral particles'
+ if (mcp.getCharge() == 0) return false;
+
+ // Find the helix parameters in the L3 convention used by org.lcsim
+ HelixParamCalculator helix = new HelixParamCalculator(mcp, _bfield);
+
+ // We haven't yet determined the track is findable
+ boolean findable = false;
+
+ // Loop over strategies and check if the track is findable
+ for (SeedStrategy strat : slist) {
+
+ // Check the MC Particle's pT
+ if (!CheckPT(helix, ignores, strat)) continue;
+
+ // Check the MC Particle's DCA
+ if (!CheckDCA(helix, ignores, strat)) continue;
+
+ // Check the MC Particle's Z0
+ if (!CheckZ0(helix, ignores, strat)) continue;
+
+ // Check that we have hits on the seed layers
+ if (!CheckSeed(mcp, ignores, strat)) continue;
+
+ // Check that we have the required confirmation hits
+ if (!CheckConfirm(mcp, ignores, strat)) continue;
+
+ // Check for the minimum number of hits
+ if (!CheckMinHits(mcp, ignores, strat)) continue;
+
+ // Passed all the checks - track is findable
+ findable = true;
+ break;
+ }
+
+ return findable;
+ }
+
+ private boolean CheckPT(HelixParamCalculator helix, List<Ignore> ignores, SeedStrategy strat) {
+
+ // First see if we are skipping this check
+ if (ignores.contains(Ignore.NoPTCut)) return true;
+
+ return helix.getMCTransverseMomentum() >= strat.getMinPT();
+ }
+
+ private boolean CheckDCA(HelixParamCalculator helix, List<Ignore> ignores, SeedStrategy strat) {
+
+ // First see if we are skipping this check
+ if (ignores.contains(Ignore.NoDCACut)) return true;
+
+ return Math.abs(helix.getDCA()) <= strat.getMaxDCA();
+ }
+
+ private boolean CheckZ0(HelixParamCalculator helix, List<Ignore> ignores, SeedStrategy strat) {
+
+ // First see if we are skipping this check
+ if (ignores.contains(Ignore.NoZ0Cut)) return true;
+
+ return Math.abs(helix.getZ0()) <= strat.getMaxZ0();
+ }
+
+ private boolean CheckSeed(MCParticle mcp, List<Ignore> ignores, SeedStrategy strat) {
+
+ // First see if we are skipping this check
+ if (ignores.contains(Ignore.NoSeedCheck)) return true;
+
+ return HitCount(mcp, strat.getLayers(SeedType.Seed)) == 3;
+ }
+
+ private boolean CheckConfirm(MCParticle mcp, List<Ignore> ignores, SeedStrategy strat) {
+
+ // First see if we are skipping this check
+ if (ignores.contains(Ignore.NoConfirmCheck)) return true;
+
+ return HitCount(mcp, strat.getLayers(SeedType.Confirm)) >= strat.getMinConfirm();
+ }
+
+ private boolean CheckMinHits(MCParticle mcp, List<Ignore> ignores, SeedStrategy strat) {
+
+ // First see if we are skipping this check
+ if (ignores.contains(Ignore.NoMinHitCut)) return true;
+
+ return HitCount(mcp, strat.getLayerList()) >= strat.getMinHits();
+ }
+
+
+ private int HitCount(MCParticle mcp, List<SeedLayer> lyrlist) {
+
+ // Get the list of hits associated with the MCParticle
+ List<HelicalTrackHit> hitlist = _hitmap.get(mcp);
+
+ // Count the number of hits in layers specified by the strategy
+ int hitcount = 0;
+ for (HelicalTrackHit hit : hitlist) {
+
+ // See if this hit is on one of the specified layers
+ for (SeedLayer lyr : lyrlist) {
+ if (!lyr.getDetName().equals(hit.Detector())) continue;
+ if (lyr.getLayer() != hit.Layer()) continue;
+ if (!lyr.getBarrelEndcapFlag().equals(hit.BarrelEndcapFlag())) continue;
+ hitcount++;
+ }
+ }
+
+ return hitcount;
+ }
+}
\ No newline at end of file