Print

Print


Commit in lcsim/src/org/lcsim/recon/pfa/output on MAIN
EnergySumPlotter.java+101added 1.1
CorrectedEnergySumPlotter.java+163added 1.1
+264
2 added files
Two files to make simple energy sum plots

lcsim/src/org/lcsim/recon/pfa/output
EnergySumPlotter.java added at 1.1
diff -N EnergySumPlotter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EnergySumPlotter.java	22 Jun 2006 01:50:28 -0000	1.1
@@ -0,0 +1,101 @@
+package org.lcsim.recon.pfa.output;
+
+import java.io.IOException; 
+import java.util.List;
+import java.util.Vector;
+import java.lang.String;
+import hep.aida.ITree;
+import hep.aida.IAnalysisFactory; 
+import hep.aida.IHistogramFactory; 
+import hep.aida.IHistogram1D; 
+import hep.aida.ICloud1D;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+import hep.physics.particle.Particle;
+import org.lcsim.event.ReconstructedParticle;
+
+/**
+ * Plot the total energy given a list of particles.
+ * Write the plot out to a file when done.
+ *
+ * @version $Id: EnergySumPlotter.java,v 1.1 2006/06/22 01:50:28 mcharles Exp $
+ */
+
+public class EnergySumPlotter extends Driver
+{
+    /**
+     * Constructor.
+     *
+     * @param inputParticleListName   Read in a List from the event under this name. The List may contain ReconstructedParticle or Particle objects (but not a mixture)
+     * @param filename               Write the plots to this file
+     */
+    public EnergySumPlotter(String inputParticleListName, String filename)
+    {
+	m_inputParticleListName = inputParticleListName;
+	IAnalysisFactory af = IAnalysisFactory.create();
+	try {
+	    m_tree = af.createTreeFactory().create(filename,"xml",false,true); 
+	    IHistogramFactory histoFactory = af.createHistogramFactory(m_tree); 
+	    m_histo = histoFactory.createHistogram1D("EnergySum", 60, 60.0, 120.0);
+	    m_cloud = histoFactory.createCloud1D("EnergySumCloud");
+	} catch (IOException ioe1) {
+            ioe1.printStackTrace(); 
+        }
+
+    }
+
+    /**
+     * Find total energy for one event
+     */
+    public void process(EventHeader event) 
+    {
+	// Read in the clusters:
+	List inputList;
+	try {
+	    inputList = (List) (event.get(m_inputParticleListName));
+	} catch (java.lang.IllegalArgumentException x) {
+	    System.out.println("WARNING: Particle list ["+m_inputParticleListName+"] not found.");
+	    return;
+	}
+
+	List<Particle> inputParticleList = new Vector<Particle>();
+	List<ReconstructedParticle> inputReconstructedParticleList = new Vector<ReconstructedParticle> ();
+	for (Object obj : inputList) {
+	    if (obj instanceof ReconstructedParticle) {
+		inputReconstructedParticleList.add( (ReconstructedParticle)(obj) );
+	    } else {
+		inputParticleList.add( (Particle)(obj) );
+	    }
+	}
+
+	if (inputReconstructedParticleList.size() * inputParticleList.size() != 0) {
+	    throw new AssertionError("Mixed list!");
+	}
+
+	double energySum = 0.0;
+	for (Particle part : inputParticleList) {
+	    energySum += part.getEnergy();
+	}
+	for (ReconstructedParticle part : inputReconstructedParticleList) {
+	    energySum += part.getEnergy();
+	}
+	
+	m_histo.fill(energySum);
+	m_cloud.fill(energySum);
+    }
+
+    public void suspend() {
+        try {
+            m_tree.commit();
+        } catch(IOException ioe1) {
+            ioe1.printStackTrace(); 
+        }
+        super.suspend();
+    }
+
+    ITree m_tree = null;
+    IHistogram1D m_histo;
+    ICloud1D m_cloud;
+    String m_inputParticleListName;
+}

lcsim/src/org/lcsim/recon/pfa/output
CorrectedEnergySumPlotter.java added at 1.1
diff -N CorrectedEnergySumPlotter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CorrectedEnergySumPlotter.java	22 Jun 2006 01:50:28 -0000	1.1
@@ -0,0 +1,163 @@
+package org.lcsim.recon.pfa.output;
+
+import java.io.IOException; 
+import java.util.List;
+import java.util.Vector;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashSet;
+import java.lang.String;
+import hep.aida.ITree;
+import hep.aida.IAnalysisFactory; 
+import hep.aida.IHistogramFactory; 
+import hep.aida.IHistogram1D; 
+import hep.aida.ICloud1D;
+import hep.aida.ICloud2D;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+import org.lcsim.event.MCParticle;
+import org.lcsim.recon.cluster.util.BasicCluster;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.recon.cluster.cheat.*;
+import org.lcsim.recon.cluster.util.*;
+import org.lcsim.util.hitmap.HitMap;
+
+import hep.physics.particle.Particle;
+import org.lcsim.event.ReconstructedParticle;
+
+/**
+ * Plot the total energy given a list of particles,
+ * correcting for the energy of particles which are
+ * not seen by the calorimeter.
+ * Write the plot out to a file when done.
+ *
+ * @version $Id: CorrectedEnergySumPlotter.java,v 1.1 2006/06/22 01:50:28 mcharles Exp $
+ */
+
+public class CorrectedEnergySumPlotter extends Driver
+{
+    /**
+     * Constructor.
+     *
+     * @param inputParticleListName   Read in a List from the event under this name. The List may contain ReconstructedParticle or Particle objects (but not a mixture)
+     * @param filename               Write the plots to this file
+     */
+    public CorrectedEnergySumPlotter(String inputHitMap, String inputParticleList, String inputTruthList, String filename)
+    {
+	m_inputParticleListName = inputParticleList;
+	m_inputHitMapName = inputHitMap;
+	m_inputTruthListName = inputTruthList;
+
+	IAnalysisFactory af = IAnalysisFactory.create();
+	try {
+	    m_tree = af.createTreeFactory().create(filename,"xml",false,true); 
+	    m_histoFactory = af.createHistogramFactory(m_tree); 
+	    m_histo = m_histoFactory.createHistogram1D("EnergySum", 60, 60.0, 120.0);
+	    m_cloud = m_histoFactory.createCloud1D("EnergySumCloud");
+	} catch (IOException ioe1) {
+            ioe1.printStackTrace(); 
+        }
+
+    }
+
+    /**
+     * Find total energy for one event
+     */
+    public void process(EventHeader event) 
+    {
+	// Read in the ReconstructedParticles
+	List<ReconstructedParticle> inputParticleList;
+	try {
+	    inputParticleList = event.get(ReconstructedParticle.class, m_inputParticleListName);
+	} catch (java.lang.IllegalArgumentException x) {
+	    System.out.println("WARNING: Particle list ["+m_inputParticleListName+"] not found.");
+	    return;
+	}
+
+	Map<Long,CalorimeterHit> inputHitMap = (Map<Long,CalorimeterHit>)(event.get(m_inputHitMapName));
+	List<MCParticle> truthList = event.get(MCParticle.class, m_inputTruthListName);
+
+	double energySumReconstructed = 0.0;
+	for (ReconstructedParticle part : inputParticleList) {
+	    energySumReconstructed += part.getEnergy();
+	}
+
+	double energySumMissed = computeMissingEnergy(truthList, inputHitMap);
+	double energySumCorrected = energySumReconstructed+energySumMissed;
+
+	m_histo.fill(energySumCorrected);
+	m_cloud.fill(energySumCorrected);
+    }
+
+    public void suspend() {
+        try {
+            m_tree.commit();
+        } catch(IOException ioe1) {
+            ioe1.printStackTrace(); 
+        }
+        super.suspend();
+    }
+
+    /**
+     * Internal utility routine
+     */
+    protected double computeMissingEnergy(List<MCParticle> truthParticles, Map<Long,CalorimeterHit> inputHitMap)
+    {
+	List<SimCalorimeterHit> hitList = new Vector<SimCalorimeterHit>();
+	for (CalorimeterHit hit : inputHitMap.values()) {
+	    SimCalorimeterHit simHit = (SimCalorimeterHit) (hit);
+	    hitList.add(simHit);
+	}
+
+	CheatClusterer clusterer = new CheatClusterer();	
+	Map<MCParticle,CheatCluster> clusterMap = clusterer.findClusters(hitList);
+
+	double foundEnergy = 0.0;
+	double missedEnergy = 0.0;
+
+	for (MCParticle part : truthParticles) {
+	    List<MCParticle> particlePlusDaughters = recursivelyFindParticles(part);
+	    BasicCluster newCluster = new BasicCluster();
+	    boolean found = false;
+	    for (MCParticle subParticle : particlePlusDaughters) {
+		if (clusterMap.containsKey(subParticle)) {
+		    newCluster.addCluster(clusterMap.get(subParticle));
+		    found = true;
+		}
+	    }
+	    if (found) {
+		foundEnergy += part.getEnergy();
+	    } else {
+		missedEnergy += part.getEnergy();
+	    }
+	}	    
+
+	return missedEnergy;
+    }
+
+    /**
+     * Internal utility routine
+     */
+    List<MCParticle> recursivelyFindParticles(MCParticle part)
+    {
+	List<MCParticle> output = new Vector<MCParticle>();
+	for (MCParticle dau : part.getDaughters()) {
+	    output.addAll(recursivelyFindParticles(dau));
+	}
+	output.add(part);
+	return output;
+    }
+
+    ITree m_tree = null;
+    IHistogramFactory m_histoFactory;
+    IHistogram1D m_histo;
+    ICloud1D m_cloud;
+    String m_inputParticleListName;
+    String m_inputHitMapName;
+    String m_inputTruthListName;
+
+    String m_ecalHitMapName;
+    String m_hcalHitMapName;
+}
CVSspam 0.2.8