Print

Print


Commit in lcsim/src/org/lcsim/contrib/uiowa/template on MAIN
CorrectedEnergySumPlotter.java+136added 1.1
A tool to plot the energy sum, corrected for missing energy

lcsim/src/org/lcsim/contrib/uiowa/template
CorrectedEnergySumPlotter.java added at 1.1
diff -N CorrectedEnergySumPlotter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CorrectedEnergySumPlotter.java	8 Feb 2006 19:05:12 -0000	1.1
@@ -0,0 +1,136 @@
+package template;
+
+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 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 hep.physics.particle.Particle;
+import org.lcsim.event.ReconstructedParticle;
+
+public class CorrectedEnergySumPlotter extends Driver
+{
+    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); 
+	    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(); 
+        }
+
+    }
+
+    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;
+
+	System.out.println("For particle list ["+m_inputParticleListName+"] energy found = "+energySumReconstructed+", corrected="+energySumCorrected);
+	
+	m_histo.fill(energySumCorrected);
+	m_cloud.fill(energySumCorrected);
+    }
+
+    public void suspend() {
+        try {
+            m_tree.commit();
+        } catch(IOException ioe1) {
+            ioe1.printStackTrace(); 
+        }
+        super.suspend();
+    }
+
+    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;
+    }
+
+    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;
+    IHistogram1D m_histo;
+    ICloud1D m_cloud;
+    String m_inputParticleListName;
+    String m_inputHitMapName;
+    String m_inputTruthListName;
+
+}
CVSspam 0.2.8