lcsim/src/org/lcsim/recon/cluster/analysis
diff -N ClusterMCPInfo.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ClusterMCPInfo.java 5 Oct 2005 17:29:11 -0000 1.1
@@ -0,0 +1,260 @@
+package org.lcsim.recon.cluster.analysis;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.MCParticle;
+import org.lcsim.recon.cluster.util.*;
+
+/**
+ * Class to hold MCParticle information about a Cluster
+ * @author Ron Cassell
+ */
+public class ClusterMCPInfo
+{
+ private int NMCP;
+ private Map<MCParticle,Contributions> contributers;
+ private MCParticle maxMCP;
+ private int maxNhits;
+ private double maxErawContribution;
+ private double maxEcorrectedContribution;
+ private BasicCluster thisCluster;
+ private MCParticle[] mcparts;
+ private int nPrimary;
+ private int nFragment;
+ private MCParticle[] primaries;
+ private MCParticle[] fragments;
+
+ /**
+ */
+ public ClusterMCPInfo(BasicCluster c, Map<MCParticle,MCParticle> fsmap)
+ {
+ thisCluster = c;
+ contributers = new HashMap();
+ for(CalorimeterHit h:c.getCalorimeterHits())
+ {
+ SimCalorimeterHit simhit = (SimCalorimeterHit) h;
+ Contributions cc = null;
+ double totecorr = simhit.getCorrectedEnergy();
+ double toteraw = simhit.getRawEnergy();
+ Map<MCParticle,Double> pemap = new HashMap<MCParticle,Double>();
+ for(int i=0;i<simhit.getMCParticleCount();i++)
+ {
+ MCParticle p = fsmap.get(simhit.getMCParticle(i));
+ if(p == null)p = simhit.getMCParticle(i);
+ Double ce;
+ if(pemap.containsKey(p))
+ {
+ ce = new Double(simhit.getContributedEnergy(i) + pemap.get(p).doubleValue());
+ pemap.remove(p);
+ }
+ else
+ {
+ ce = new Double(simhit.getContributedEnergy(i));
+ }
+ pemap.put(p,ce);
+ }
+ for(MCParticle p:pemap.keySet())
+ {
+ if(contributers.containsKey(p))
+ {
+ cc = contributers.get(p);
+ }
+ else
+ {
+ contributers.put(p,cc = new Contributions());
+ }
+ cc.addContribution(pemap.get(p).doubleValue());
+ cc.addEcorrected(totecorr*pemap.get(p).doubleValue()/toteraw);
+ }
+ }
+ NMCP = contributers.size();
+ mcparts = new MCParticle[NMCP];
+ int ipart = 0;
+ for(MCParticle p:contributers.keySet())
+ {
+ mcparts[ipart] = p;
+ ipart++;
+ }
+ }
+ /**
+ */
+ public void FillInfo(Map<MCParticle,MCPClusterInfo> m)
+ {
+ maxNhits = 0;
+ maxErawContribution = 0.;
+ nPrimary = 0;
+ nFragment = 0;
+ for(MCParticle p:contributers.keySet())
+ {
+ MCPClusterInfo ci = m.get(p);
+ Contributions co = contributers.get(p);
+ if(ci.isFinalState())co.setFS();
+ if(thisCluster == ci.getMaxCluster())
+ {
+ co.setPrimary();
+ nPrimary++;
+ }
+ else
+ {
+ co.setFragment();
+ nFragment++;
+ }
+ int nh = co.getNhits();
+ if(nh > maxNhits)
+ {
+ maxNhits = nh;
+ maxErawContribution = co.getEraw();
+ maxEcorrectedContribution = co.getEcorrected();
+ maxMCP = p;
+ }
+ else if(nh == maxNhits)
+ {
+ if(co.getEraw() > maxErawContribution)
+ {
+ maxNhits = nh;
+ maxErawContribution = co.getEraw();
+ maxEcorrectedContribution = co.getEcorrected();
+ maxMCP = p;
+ }
+ }
+ }
+ primaries = new MCParticle[nPrimary];
+ fragments = new MCParticle[nFragment];
+ int iprim = 0;
+ int ifrag = 0;
+ for(MCParticle p:contributers.keySet())
+ {
+ Contributions co = contributers.get(p);
+ if(co.isPrimary())
+ {
+ primaries[iprim] = p;
+ iprim++;
+ }
+ if(co.isFragment())
+ {
+ fragments[ifrag] = p;
+ ifrag++;
+ }
+ }
+ }
+ /**
+ * Return the number of MCParticles contributing to this cluster
+ */
+ public int getNContributers()
+ {
+ return NMCP;
+ }
+ /**
+ * Return an array of MCParticles contributing to this cluster
+ */
+ public MCParticle[] getContributers()
+ {
+ return mcparts;
+ }
+ /**
+ * Return the number of MCParticles having this cluster as their maximum cluster
+ */
+ public int getNPrimary()
+ {
+ return nPrimary;
+ }
+ /**
+ * Return the number of MCParticles contributing to this cluster having a different
+ * maximum cluster
+ */
+ public int getNFragment()
+ {
+ return nFragment;
+ }
+ /**
+ * Return an array of MCParticles having this cluster as their maximum cluster
+ */
+ public MCParticle[] getPrimaries()
+ {
+ return primaries;
+ }
+ /**
+ * Return an array of MCParticles contributing to this cluster having a different
+ * maximum cluster
+ */
+ public MCParticle[] getFragments()
+ {
+ return fragments;
+ }
+ /**
+ * Return the MCParticle with the maximum contribution to this cluster
+ */
+ public MCParticle getMaxContributer()
+ {
+ return maxMCP;
+ }
+ /**
+ * Return the number of hits from the MCParticle with the maximum
+ * contribution to this cluster
+ */
+ public int getMaxNHits()
+ {
+ return maxNhits;
+ }
+ /**
+ * Return the raw energy from the MCParticle with the maximum
+ * contribution to this cluster
+ */
+ public double getMaxRawEnergy()
+ {
+ return maxErawContribution;
+ }
+ /**
+ * Return the corrected energy from the MCParticle with the maximum
+ * contribution to this cluster
+ */
+ public double getMaxCorrectedEnergy()
+ {
+ return maxEcorrectedContribution;
+ }
+ public BasicCluster getCluster(){return thisCluster;}
+
+}
+ /**
+ * Class to store contribution information while ClusterMCPInfo being filled
+ */
+class Contributions
+{
+ int nhits;
+ double eraw;
+ double ecorr;
+ boolean isfs;
+ boolean isprimary;
+ boolean isfragment;
+ public Contributions()
+ {
+ nhits = 0;
+ eraw = 0.;
+ ecorr = 0.;
+ isfs = false;
+ isprimary = false;
+ isfragment = false;
+ }
+ public void addContribution(double er)
+ {
+ nhits++;
+ eraw += er;
+ }
+ public void addEcorrected(double ec)
+ {
+ ecorr += ec;
+ }
+ public void setFS(){isfs = true;}
+ public void setPrimary(){isprimary = true;}
+ public void setFragment(){isfragment = true;}
+ public boolean isFS(){return isfs;}
+ public boolean isPrimary(){return isprimary;}
+ public boolean isFragment(){return isfragment;}
+ public int getNhits(){return nhits;}
+ public double getEraw(){return eraw;}
+ public double getEcorrected(){return ecorr;}
+}
\ No newline at end of file