lcsim/src/org/lcsim/util/decision
diff -N UnphysicalTrackDecision.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ UnphysicalTrackDecision.java 22 Oct 2008 21:08:28 -0000 1.1
@@ -0,0 +1,78 @@
+package org.lcsim.util.decision;
+
+import java.util.*;
+import hep.physics.vec.*;
+import org.lcsim.event.*;
+import org.lcsim.util.*;
+
+public class UnphysicalTrackDecision extends Driver implements DecisionMakerSingle<Track> {
+
+ /** Simple constructor. */
+ public UnphysicalTrackDecision() {
+ // Empty
+ }
+
+ protected double m_eventEnergy = Double.NaN;
+
+ /** Check if track has unphysical energy (greater than sqrt(s)/2). */
+ public boolean valid(Track tr) {
+ double mom = (new BasicHep3Vector(tr.getMomentum())).magnitude();
+ if (Double.isNaN(m_eventEnergy)) {
+ // We don't know the event energy so we can't test tracks.
+ // Assume they're all OK.
+ return true;
+ } else if (mom < m_eventEnergy * 0.52) {
+ // Track has half of event energy or less -- OK.
+ // (Using 0.52 instead of 0.5 to allow a little tolerance for measurement
+ // uncertainties, numerical precision, etc.)
+ return true;
+ } else {
+ // Unphysical energy
+ return false;
+ }
+ }
+
+ /** Process: Used to cache event energy. */
+ public void process(EventHeader event) {
+ List<MCParticle> truthList = event.getMCParticles();
+ // Scan for the initial e+ e- pair, which have no parents:
+ MCParticle initialElectron = null;
+ MCParticle initialPositron = null;
+ for (MCParticle part : truthList) {
+ if (part.getParents().size()==0) {
+ int pdg = part.getPDGID();
+ if (pdg == 11) {
+ // Electron candidate
+ if (initialElectron == null) {
+ // No previously found electron -- this is likely the one.
+ initialElectron = part;
+ } else {
+ // Already found a parentless electron. Check which has higher energy:
+ if (part.getEnergy() > initialElectron.getEnergy()) {
+ initialElectron = part;
+ }
+ }
+ } else if (pdg == -11) {
+ // Positron candidate
+ if (initialPositron == null) {
+ // No previously found positron -- this is likely the one.
+ initialPositron = part;
+ } else {
+ // Already found a parentless posittron. Check which has higher energy:
+ if (part.getEnergy() > initialPositron.getEnergy()) {
+ initialPositron = part;
+ }
+ }
+ }
+ }
+ }
+
+ if (initialElectron==null || initialPositron==null) {
+ // Something went wrong -- set event energy to NaN so that we don't exclude any tracks.
+ m_eventEnergy = Double.NaN;
+ } else {
+ // OK -- found both. Event energy is simply their sum.
+ m_eventEnergy = initialElectron.getEnergy() + initialPositron.getEnergy();
+ }
+ }
+}