Print

Print


Commit in lcsim-contrib/src/main/java/org/lcsim/contrib/jeremym/analysis/pandora on MAIN
SingleParticleAnalDriver.java+152added 1.1


lcsim-contrib/src/main/java/org/lcsim/contrib/jeremym/analysis/pandora
SingleParticleAnalDriver.java added at 1.1
diff -N SingleParticleAnalDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SingleParticleAnalDriver.java	19 Oct 2011 15:17:14 -0000	1.1
@@ -0,0 +1,152 @@
+package org.lcsim.contrib.jeremym.analysis.pandora;
+
+import hep.aida.ICloud1D;
+import hep.aida.ICloud2D;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.ReconstructedParticle;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+
+/**
+ * <p>
+ * Assuming single particle events, plot the following for a collection of LCIO 
+ * ReconstructedParticles from PandoraPFA ...
+ * </p>
+ * 
+ * <ul>
+ * <li>efficiency</li>
+ * <li>purity</li>
+ * <li>[x] PFO energy distribution</li>
+ * <li>[x] E_recon - E_particle</li>
+ * <li>[x] E_recon vs. E_particle</li>
+ * <li>[x] Number of PFOs found</li>
+ * </ul>
+ *  
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class SingleParticleAnalDriver extends Driver
+{
+    static final String pfoCollName = "PandoraPFOCollection";
+    static AIDA aida = AIDA.defaultInstance();
+    
+    ICloud1D reconE_c1d;
+    ICloud1D nPfo_c1d;
+    ICloud1D eDiff_c1d;
+    ICloud2D eReconVsMC_c2d;
+    ICloud1D misId_c1d;
+    ICloud1D corrId_c1d;
+    ICloud1D pid_c1d;
+    ICloud1D mcid_c1d;
+    //ICloud1D eff_c1d;
+    //ICloud1D purity_c1d;
+    
+    // Number of events with at least 1 PFO.
+    int nfound = 0;
+    
+    // Number of particles misidentified in run.
+    int nwrong = 0;
+    
+    // Number of particles correctly identified in run.
+    int nright = 0;
+    
+    // Total number of events where no PFOs were found.
+    int nnotfound = 0;
+    
+    // Total number of events in run.
+    int nevents = 0;
+    
+    public SingleParticleAnalDriver()
+    {}
+    
+    public void process(EventHeader event)
+    {
+        MCParticle primary = findPrimaryParticle(event.get(MCParticle.class, EventHeader.MC_PARTICLES));
+        double primaryE = primary.getEnergy();
+        int primaryId = primary.getPDGID();
+        mcid_c1d.fill((double)primaryId);
+        List<ReconstructedParticle> reconParticles = event.get(ReconstructedParticle.class, pfoCollName);
+        double reconESum = 0;
+        for (ReconstructedParticle p : reconParticles)
+        {
+            reconE_c1d.fill(p.getEnergy());            
+            reconESum += p.getEnergy();
+        }
+        eDiff_c1d.fill(reconESum - primaryE);
+        eReconVsMC_c2d.fill(reconESum, primaryE);
+        
+        if (reconParticles.size() > 0)
+        {
+            int reconId = reconParticles.get(reconParticles.size() - 1).getType();
+            pid_c1d.fill((double)reconId);
+            if (primaryId == reconId)
+            {
+                ++nright;
+            }
+            else
+            {
+                ++nwrong;
+            }
+        }
+        else
+        {
+            ++nnotfound;
+        }
+        ++nevents;
+    }
+    
+    public void startOfData()
+    {
+        reconE_c1d = aida.cloud1D("PFO Energy");
+        nPfo_c1d = aida.cloud1D("Number of PFOs in Event");
+        eDiff_c1d = aida.cloud1D("E_recon - E_particle");
+        eReconVsMC_c2d = aida.cloud2D("E_recon vs E_particle");
+        misId_c1d = aida.cloud1D("Number of MisIDed Particles in Run");
+        corrId_c1d = aida.cloud1D("Number of Correctly IDed Particles in Run");
+        pid_c1d = aida.cloud1D("PID of ReconParticle");
+        mcid_c1d = aida.cloud1D("PDGID of MCParticle");
+        //eff_c1d = aida.cloud1D("Efficiency");
+    }
+    
+    public void endOfData()
+    {
+        misId_c1d.fill((double)nwrong);
+        corrId_c1d.fill((double)nright);
+        //eff_c1d.fill((double)n / (double)nevents);
+        //purity_c1d.fill((double)(nevents - nwrong) / (double)nevents);
+    }
+    
+    static MCParticleEnergyComparator pcompare = new MCParticleEnergyComparator();
+    public MCParticle findPrimaryParticle(List<MCParticle> particles)
+    {
+        List<MCParticle> pcopy = new ArrayList<MCParticle>(particles);
+        Collections.sort(pcopy, pcompare);
+        return pcopy.get(pcopy.size() - 1);
+    }
+    
+    static class MCParticleEnergyComparator implements Comparator<MCParticle>
+    {
+        public int compare(MCParticle p1, MCParticle p2)
+        {
+            if (p1.getEnergy() < p2.getEnergy())
+            {
+                return -1;
+            }
+            else if (p1.getEnergy() > p2.getEnergy())
+            {
+                return 1;
+            }
+            else
+            {
+                return 0;
+            }
+        }
+    }
+}
\ No newline at end of file
CVSspam 0.2.8