Print

Print


Commit in lcsim/src/org/lcsim/contrib/uiowa/structural/likelihood on MAIN
LikelihoodEvaluator.java+103-21.2 -> 1.3
Added a series of getLikelihoodQuantities methods to allow easy access to the quantities. Also added a public makePlots() method, together with internal utility methods to help implement it -- this will write out a set of histograms showing the distributions of the various likelihood quantities for signal and background.

lcsim/src/org/lcsim/contrib/uiowa/structural/likelihood
LikelihoodEvaluator.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- LikelihoodEvaluator.java	14 Oct 2005 17:44:49 -0000	1.2
+++ LikelihoodEvaluator.java	18 Oct 2005 17:49:56 -0000	1.3
@@ -1,5 +1,6 @@
 package structural.likelihood; // package org.lcsim.recon.cluster.structural.likelihood;
 
+import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Vector;
@@ -11,6 +12,11 @@
 import java.io.Serializable;
 import java.io.IOException; 
 
+import hep.aida.ITree;
+import hep.aida.IAnalysisFactory; 
+import hep.aida.IHistogramFactory; 
+import hep.aida.IHistogram1D; 
+
 import org.lcsim.event.Cluster;
 
 public class LikelihoodEvaluator implements java.io.Serializable {
@@ -33,6 +39,31 @@
         m_LikelihoodDistributionsClumpToClump.put(Boolean.valueOf(false),  new Vector<LikelihoodDistribution>());
     }
 
+    public List<StructuralLikelihoodQuantity> getLikelihoodQuantities() {
+	Vector<StructuralLikelihoodQuantity> vOut = new Vector<StructuralLikelihoodQuantity>();
+	vOut.addAll(getLikelihoodQuantitiesTrackToTrack());
+	vOut.addAll(getLikelihoodQuantitiesTrackToClump());
+	vOut.addAll(getLikelihoodQuantitiesClumpToClump());
+	return vOut;
+    }
+    public List<StructuralLikelihoodQuantity> getLikelihoodQuantitiesTrackToTrack() {
+	return getLikelihoodQuantities(m_LikelihoodDistributionsTrackToTrack.get(Boolean.valueOf(true)));
+    }
+    public List<StructuralLikelihoodQuantity> getLikelihoodQuantitiesTrackToClump() {
+	return getLikelihoodQuantities(m_LikelihoodDistributionsTrackToClump.get(Boolean.valueOf(true)));
+    }
+    public List<StructuralLikelihoodQuantity> getLikelihoodQuantitiesClumpToClump() {
+	return getLikelihoodQuantities(m_LikelihoodDistributionsClumpToClump.get(Boolean.valueOf(true)));
+    }
+    protected List<StructuralLikelihoodQuantity> getLikelihoodQuantities(Vector<LikelihoodDistribution> vect) {
+	Vector<StructuralLikelihoodQuantity> vOut = new Vector<StructuralLikelihoodQuantity>();
+	for (LikelihoodDistribution dist : vect) {
+	    StructuralLikelihoodQuantity quant = dist.getQuantity();
+	    vOut.add(quant);
+	}
+	return vOut;
+    }
+
     public void addLikelihoodQuantityTrackToTrack(StructuralLikelihoodQuantity quant, int nbins, double min, double max, boolean useUnderFlow, boolean useOverFlow) {
         Vector<LikelihoodDistribution> vTrue  = m_LikelihoodDistributionsTrackToTrack.get(Boolean.valueOf(true));
         Vector<LikelihoodDistribution> vFalse = m_LikelihoodDistributionsTrackToTrack.get(Boolean.valueOf(false));
@@ -91,8 +122,8 @@
         double totalGoodLikelihood = 1.0;
         double totalBadLikelihood = 1.0;
         for (int i=0; i<vLinked.size(); i++) {
-            LikelihoodDistribution distLinked = (LikelihoodDistribution) (vLinked.get(i));
-            LikelihoodDistribution distUnlinked = (LikelihoodDistribution) (vUnlinked.get(i));
+            LikelihoodDistribution distLinked = vLinked.get(i);
+            LikelihoodDistribution distUnlinked = vUnlinked.get(i);
             try {
                 double goodPDF = distLinked.getPDF(clus1, clus2);
                 double badPDF = distUnlinked.getPDF(clus1, clus2);
@@ -136,4 +167,74 @@
             throw new AssertionError("java.io.IOException: "+x);
         }
     }
+
+    // Routines to make interesting plots:
+
+    /**
+      * Write the likelihood distributions out to the given file
+      */
+    public void makePlots(String filename)
+    {
+        IAnalysisFactory af = IAnalysisFactory.create();
+        try {
+            ITree t = af.createTreeFactory().create(filename,"xml",false,true); 
+            IHistogramFactory hf = af.createHistogramFactory(t); 
+            makePlots(hf, "hTrackTrack", m_LikelihoodDistributionsTrackToTrack);
+            makePlots(hf, "hTrackClump", m_LikelihoodDistributionsTrackToClump);
+            makePlots(hf, "hClumpClump", m_LikelihoodDistributionsClumpToClump);
+            t.commit();
+        } catch(IOException ioe1) {
+            ioe1.printStackTrace(); 
+        }
+    }
+
+    /**
+     * Make the plots for a particular set of variables (clump-clump, track-track, track-clump)
+     */
+    protected void makePlots(IHistogramFactory hf, String name1, Map<Boolean, Vector<LikelihoodDistribution> > map)
+    {
+	for (LikelihoodDistribution dist : map.get(Boolean.valueOf(true))) {
+	    makePlot(hf, name1, "Signal", dist);
+	}
+	for (LikelihoodDistribution dist : map.get(Boolean.valueOf(false))) {
+	    makePlot(hf, name1, "Background", dist);
+	}
+    }
+
+    /**
+     * Make one plot
+     */
+    protected void makePlot(IHistogramFactory hf, String name1, String name2, LikelihoodDistribution dist)
+    {
+        String subName = dist.getQuantity().getClass().getName();
+        String fullName = new String(name1 + "_" + name2 + "_" + subName);
+        System.out.println("DEBUG: Making histogram for ["+fullName+"]");
+        int nbins = dist.getNbins();
+        double min = dist.getMin();
+        double max = dist.getMax();
+        double binsize = (max-min) / ( (double)(nbins) );
+        int histo_nbins = nbins;
+        double histo_min = min;
+        double histo_max = max;
+        if (dist.useUnderFlow()) {
+            histo_nbins++;
+            histo_min -= binsize;
+        }
+        if (dist.useOverFlow()) {
+            histo_nbins++;
+            histo_max += binsize;
+        }
+        IHistogram1D histo = hf.createHistogram1D(fullName, histo_nbins, histo_min, histo_max);
+        for (int i=0; i<nbins; i++) { 
+            double binCenter = min + binsize*( (double)(i) + 0.5);
+            histo.fill(binCenter, dist.getPDF(i));
+        }
+        if (dist.useUnderFlow()) {
+            histo.fill(min-0.5*binsize, dist.getPDF(-1));
+        }
+        if (dist.useOverFlow()) {
+            histo.fill(max+0.5*binsize, dist.getPDF(nbins));
+        }
+    }
+
 }
CVSspam 0.2.8