lcsim/src/org/lcsim/recon/pfa/cheat
diff -u -r1.7 -r1.8
--- PerfectIdentifier.java 13 Oct 2007 20:07:00 -0000 1.7
+++ PerfectIdentifier.java 2 Oct 2009 01:06:50 -0000 1.8
@@ -1,224 +1,255 @@
package org.lcsim.recon.pfa.cheat;
-import java.util.*;
-
import hep.physics.particle.Particle;
import hep.physics.vec.BasicHep3Vector;
-import hep.physics.vec.Hep3Vector;
import hep.physics.vec.BasicHepLorentzVector;
+import hep.physics.vec.Hep3Vector;
-import org.lcsim.util.*;
-import org.lcsim.event.*;
-import org.lcsim.mc.fast.tracking.ReconTrack;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.ReconstructedParticle;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.Track;
import org.lcsim.event.base.BaseReconstructedParticle;
+import org.lcsim.event.base.BaseTrackMC;
+import org.lcsim.mc.fast.tracking.ReconTrack;
+import org.lcsim.util.Driver;
/**
*
- * @version $Id: PerfectIdentifier.java,v 1.7 2007/10/13 20:07:00 mcharles Exp $
+ * @version $Id: PerfectIdentifier.java,v 1.8 2009/10/02 01:06:50 jeremy Exp $
*/
public class PerfectIdentifier extends Driver
{
- public PerfectIdentifier() {
- }
-
- public void process(EventHeader event)
- {
- List<Cluster> inputClusterList = event.get(Cluster.class, m_inputClusterListName);
- List<ReconstructedParticle> outputParticleList = new Vector<ReconstructedParticle>();
- List<MCParticle> mcList = event.get(MCParticle.class, m_mcName);
- List<Track> trackList = null;
- if (m_inputTrackListName != null) {
- trackList = event.get(Track.class, m_inputTrackListName);
- }
- List<Track> outputTrackList = new Vector<Track>();
- if (trackList != null) {
- outputTrackList.addAll(trackList);
- }
-
- for (Cluster clus : inputClusterList) {
- // Identify
- MCParticle truthID = findTruthID(clus, mcList);
- if (truthID == null) {
- // This is going to cause a null pointer exception shortly
- // (as soon as we try to compute the truth particle's
- // energy, momentum, etc). So pre-emptively throw a diagnostic
- // exception.
- String printme = new String();
- printme += ("Warning: truthID==null for cluster with "+clus.getCalorimeterHits().size()+" hits and MC list of "+mcList.size()+" particles named '"+m_mcName+"'.\n");
- printme += "Probably the MC list is not complete or is not self-consistent.\n";
- printme += "Here are the contributing particles:\n";
- Set<MCParticle> contributingParticles = new HashSet<MCParticle>();
+ public PerfectIdentifier() {
+ }
+
+ public void process(EventHeader event)
+ {
+ List<Cluster> inputClusterList = event.get(Cluster.class, m_inputClusterListName);
+ List<ReconstructedParticle> outputParticleList = new Vector<ReconstructedParticle>();
+ List<MCParticle> mcList = event.get(MCParticle.class, m_mcName);
+ List<Track> trackList = null;
+ if (m_inputTrackListName != null) {
+ trackList = event.get(Track.class, m_inputTrackListName);
+ }
+ List<Track> outputTrackList = new Vector<Track>();
+ if (trackList != null) {
+ outputTrackList.addAll(trackList);
+ }
+
+ for (Cluster clus : inputClusterList) {
+ // Identify
+ MCParticle truthID = findTruthID(clus, mcList);
+ if (truthID == null) {
+ // This is going to cause a null pointer exception shortly
+ // (as soon as we try to compute the truth particle's
+ // energy, momentum, etc). So pre-emptively throw a diagnostic
+ // exception.
+ String printme = new String();
+ printme += ("Warning: truthID==null for cluster with "+clus.getCalorimeterHits().size()+" hits and MC list of "+mcList.size()+" particles named '"+m_mcName+"'.\n");
+ printme += "Probably the MC list is not complete or is not self-consistent.\n";
+ printme += "Here are the contributing particles:\n";
+ Set<MCParticle> contributingParticles = new HashSet<MCParticle>();
+ for (CalorimeterHit hit : clus.getCalorimeterHits()) {
+ SimCalorimeterHit simHit = (SimCalorimeterHit) (hit);
+ int nContributingParticles = simHit.getMCParticleCount();
+ for (int i=0; i<nContributingParticles; i++) {
+ MCParticle part = simHit.getMCParticle(i);
+ contributingParticles.add(part);
+ }
+ }
+ for (MCParticle part : contributingParticles) {
+ List<MCParticle> parentsInList = findParentsInList(part, mcList);
+ printme += " ";
+ printme += part.getType().getName();
+ printme += " with energy "+part.getEnergy();
+ printme += " with parents in list: { ";
+ for (MCParticle parent : parentsInList) {
+ printme += parent.getType().getName();
+ printme += "(E="+parent.getEnergy()+") ";
+ }
+ printme += " } \n";
+ }
+ throw new NullPointerException(printme);
+ }
+ // Add to output list
+ LocalReconstructedParticle part = new LocalReconstructedParticle();
+ part.addCluster(clus);
+ // Match track(s):
+ if (trackList != null) {
+ // Use supplied track list
+ for (Track currentTrack : trackList) {
+ // From FastMC.
+ if (currentTrack instanceof ReconTrack)
+ {
+ ReconTrack cheatTrack = (ReconTrack)(currentTrack);
+ Particle cheatTrackParticle = cheatTrack.getMCParticle();
+ if (cheatTrackParticle == truthID) {
+ part.addTrack(currentTrack);
+ outputTrackList.remove(currentTrack);
+ }
+ }
+ // From CheatTrackDriver. --jeremy
+ else if (currentTrack instanceof BaseTrackMC)
+ {
+ BaseTrackMC cheatTrack = (BaseTrackMC)(currentTrack);
+ Particle cheatTrackParticle = cheatTrack.getMCParticle();
+ if (cheatTrackParticle == truthID)
+ {
+ part.addTrack(currentTrack);
+ outputTrackList.remove(currentTrack);
+ }
+
+ }
+ }
+ } else {
+ // Skip track list
+ }
+ // This step has to be done last, since addTrack() now over-writes kinematic info
+ part.setEnergy(truthID.getEnergy());
+ // Set the other particle properties that are needed to render
+ // properly in the event display.
+ part.setMomentum(truthID.getMomentum());
+ part.setReferencePoint(truthID.getOrigin());
+ part.setCharge(truthID.getCharge());
+ // Add to the output list
+ if (!m_requireTrack || part.getTracks().size()>0) {
+ outputParticleList.add(part);
+ }
+ }
+ event.put(m_outputParticleListName, outputParticleList);
+
+ if (outputTrackList != null && m_outputTrackListName != null) {
+ event.put(m_outputTrackListName, outputTrackList);
+ }
+ }
+
+ protected MCParticle findTruthID(Cluster clus, List<MCParticle> mcList) {
+ // Find the dominant MC particle in some way.
+ // For now, do something ugly
+ Map<MCParticle, Integer> tmpMap = new HashMap<MCParticle, Integer> ();
for (CalorimeterHit hit : clus.getCalorimeterHits()) {
- SimCalorimeterHit simHit = (SimCalorimeterHit) (hit);
- int nContributingParticles = simHit.getMCParticleCount();
- for (int i=0; i<nContributingParticles; i++) {
- MCParticle part = simHit.getMCParticle(i);
- contributingParticles.add(part);
- }
- }
- for (MCParticle part : contributingParticles) {
- List<MCParticle> parentsInList = findParentsInList(part, mcList);
- printme += " ";
- printme += part.getType().getName();
- printme += " with energy "+part.getEnergy();
- printme += " with parents in list: { ";
- for (MCParticle parent : parentsInList) {
- printme += parent.getType().getName();
- printme += "(E="+parent.getEnergy()+") ";
- }
- printme += " } \n";
- }
- throw new NullPointerException(printme);
- }
- // Add to output list
- LocalReconstructedParticle part = new LocalReconstructedParticle();
- part.addCluster(clus);
- // Match track(s):
- if (trackList != null) {
- // Use supplied track list
- for (Track currentTrack : trackList) {
- if (currentTrack instanceof ReconTrack) {
- ReconTrack cheatTrack = (ReconTrack)(currentTrack);
- Particle cheatTrackParticle = cheatTrack.getMCParticle();
- if (cheatTrackParticle == truthID) {
- part.addTrack(currentTrack);
- outputTrackList.remove(currentTrack);
- }
- }
- }
- } else {
- // Skip track list
- }
- // This step has to be done last, since addTrack() now over-writes kinematic info
- part.setEnergy(truthID.getEnergy());
- // Set the other particle properties that are needed to render
- // properly in the event display.
- part.setMomentum(truthID.getMomentum());
- part.setReferencePoint(truthID.getOrigin());
- part.setCharge(truthID.getCharge());
- // Add to the output list
- if (!m_requireTrack || part.getTracks().size()>0) {
- outputParticleList.add(part);
- }
- }
- event.put(m_outputParticleListName, outputParticleList);
-
- if (outputTrackList != null && m_outputTrackListName != null) {
- event.put(m_outputTrackListName, outputTrackList);
- }
- }
-
- protected MCParticle findTruthID(Cluster clus, List<MCParticle> mcList) {
- // Find the dominant MC particle in some way.
- // For now, do something ugly
- Map<MCParticle, Integer> tmpMap = new HashMap<MCParticle, Integer> ();
- for (CalorimeterHit hit : clus.getCalorimeterHits()) {
- Set<MCParticle> particles = findMCParticles(hit, mcList);
- for (MCParticle part : particles) {
- Integer oldValue = tmpMap.get(part);
- if (oldValue==null) {
- oldValue = new Integer(0);
- }
- Integer newValue = new Integer(oldValue + 1);
- tmpMap.put(part, newValue);
- }
- }
-
- // Which particle contributed the most?
- int max = 0;
- MCParticle best = null;
- for (MCParticle part : tmpMap.keySet()) {
- int numHits = tmpMap.get(part).intValue();
- if (numHits > max || best==null) {
- max = numHits;
- best = part;
- }
- }
- return best;
- }
-
- // Duplicate code w.r.t. PerfectClusterer
- protected Set<MCParticle> findMCParticles(CalorimeterHit hit, List<MCParticle> mcList)
- {
- if ( ! (hit instanceof SimCalorimeterHit) ) {
- throw new AssertionError("Non-simulated hit!");
- } else {
- SimCalorimeterHit simHit = (SimCalorimeterHit) (hit);
- Set<MCParticle> contributingParticlesFromList = new HashSet<MCParticle>();
- int nContributingParticles = simHit.getMCParticleCount();
- for (int i=0; i<nContributingParticles; i++) {
- MCParticle part = simHit.getMCParticle(i);
- List<MCParticle> parentsInList = findParentsInList(part, mcList);
- contributingParticlesFromList.addAll(parentsInList);
- }
- return contributingParticlesFromList;
- }
- }
-
- protected List<MCParticle> findParentsInList(MCParticle part, List<MCParticle> mcList)
- {
- List<MCParticle> outputList = new Vector<MCParticle>();
- if (mcList.contains(part)) {
- // Already in there
- outputList.add(part);
- } else {
- // Not in there -- recurse up through parents
- List<MCParticle> parents = part.getParents();
- if (parents.size()==0) {
- // Ran out of options -- add nothing and return below
- } else {
- for (MCParticle parent : parents) {
- List<MCParticle> ancestorsInList = findParentsInList(parent, mcList);
- outputList.addAll(ancestorsInList);
- }
- }
- }
- return outputList;
- }
-
- public void setInputClusterList(String name) {
- m_inputClusterListName = name;
- }
- public void setOutputParticleList(String name) {
- m_outputParticleListName = name;
- }
- public void setMCParticleList(String name) {
- m_mcName = name;
- }
- public void setInputTrackList(String name) {
- m_inputTrackListName = name;
- }
- public void setOutputTrackList(String name) {
- m_outputTrackListName = name;
- }
- public void requireTrack(boolean b) {
- m_requireTrack = b;
- }
-
- boolean m_requireTrack = false;
- String m_inputTrackListName;
- String m_outputTrackListName;
- String m_inputClusterListName;
- String m_outputParticleListName;
- String m_mcName;
-
- // This should be replaced by a central implementation
- private class LocalReconstructedParticle extends BaseReconstructedParticle
- {
- public void setEnergy(double e) {
- super.set4Vector(new BasicHepLorentzVector(e,_fourVec.v3()));
- }
- public void setMomentum(Hep3Vector p3) {
- super.set4Vector(new BasicHepLorentzVector(_fourVec.t(),p3));
- }
-
- public void setReferencePoint(Hep3Vector p3) {
- // FIXME this cast may not be intended
- _referencePoint = (BasicHep3Vector) p3;
+ Set<MCParticle> particles = findMCParticles(hit, mcList);
+ for (MCParticle part : particles) {
+ Integer oldValue = tmpMap.get(part);
+ if (oldValue==null) {
+ oldValue = new Integer(0);
+ }
+ Integer newValue = new Integer(oldValue + 1);
+ tmpMap.put(part, newValue);
+ }
+ }
+
+ // Which particle contributed the most?
+ int max = 0;
+ MCParticle best = null;
+ for (MCParticle part : tmpMap.keySet()) {
+ int numHits = tmpMap.get(part).intValue();
+ if (numHits > max || best==null) {
+ max = numHits;
+ best = part;
+ }
+ }
+ return best;
}
- public void setCharge(double q) {
- _charge = q;
+
+ // Duplicate code w.r.t. PerfectClusterer
+ protected Set<MCParticle> findMCParticles(CalorimeterHit hit, List<MCParticle> mcList)
+ {
+ if ( ! (hit instanceof SimCalorimeterHit) ) {
+ throw new AssertionError("Non-simulated hit!");
+ } else {
+ SimCalorimeterHit simHit = (SimCalorimeterHit) (hit);
+ Set<MCParticle> contributingParticlesFromList = new HashSet<MCParticle>();
+ int nContributingParticles = simHit.getMCParticleCount();
+ for (int i=0; i<nContributingParticles; i++) {
+ MCParticle part = simHit.getMCParticle(i);
+ List<MCParticle> parentsInList = findParentsInList(part, mcList);
+ contributingParticlesFromList.addAll(parentsInList);
+ }
+ return contributingParticlesFromList;
+ }
+ }
+
+ protected List<MCParticle> findParentsInList(MCParticle part, List<MCParticle> mcList)
+ {
+ List<MCParticle> outputList = new Vector<MCParticle>();
+ if (mcList.contains(part)) {
+ // Already in there
+ outputList.add(part);
+ } else {
+ // Not in there -- recurse up through parents
+ List<MCParticle> parents = part.getParents();
+ if (parents.size()==0) {
+ // Ran out of options -- add nothing and return below
+ } else {
+ for (MCParticle parent : parents) {
+ List<MCParticle> ancestorsInList = findParentsInList(parent, mcList);
+ outputList.addAll(ancestorsInList);
+ }
+ }
+ }
+ return outputList;
+ }
+
+ public void setInputClusterList(String name) {
+ m_inputClusterListName = name;
+ }
+ public void setOutputParticleList(String name) {
+ m_outputParticleListName = name;
+ }
+ public void setMCParticleList(String name) {
+ m_mcName = name;
+ }
+ public void setInputTrackList(String name) {
+ m_inputTrackListName = name;
+ }
+ public void setOutputTrackList(String name) {
+ m_outputTrackListName = name;
+ }
+ public void requireTrack(boolean b) {
+ m_requireTrack = b;
+ }
+
+ public void setRequireTrack(boolean b)
+ {
+ m_requireTrack = b;
+ }
+
+ boolean m_requireTrack = false;
+ String m_inputTrackListName;
+ String m_outputTrackListName;
+ String m_inputClusterListName;
+ String m_outputParticleListName;
+ String m_mcName;
+
+ // This should be replaced by a central implementation
+ private class LocalReconstructedParticle extends BaseReconstructedParticle
+ {
+ public void setEnergy(double e) {
+ super.set4Vector(new BasicHepLorentzVector(e,_fourVec.v3()));
+ }
+ public void setMomentum(Hep3Vector p3) {
+ super.set4Vector(new BasicHepLorentzVector(_fourVec.t(),p3));
+ }
+
+ public void setReferencePoint(Hep3Vector p3) {
+ // FIXME this cast may not be intended
+ _referencePoint = (BasicHep3Vector) p3;
+ }
+ public void setCharge(double q) {
+ _charge = q;
+ }
}
- }
}