Commit in lcsim-contrib/src/main/java/org/lcsim/contrib/jeremym/hps on MAIN
HPSECalPlotsDriver.java+189added 1.1
driver with HPS Ecal diagnostic plots

lcsim-contrib/src/main/java/org/lcsim/contrib/jeremym/hps
HPSECalPlotsDriver.java added at 1.1
diff -N HPSECalPlotsDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSECalPlotsDriver.java	22 Apr 2011 01:10:07 -0000	1.1
@@ -0,0 +1,189 @@
+package org.lcsim.contrib.jeremym.hps;
+
+
+import hep.aida.ICloud1D;
+import hep.aida.ICloud2D;
+import hep.aida.IHistogram1D;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.units.SystemOfUnits;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: HPSECalPlotsDriver.java,v 1.1 2011/04/22 01:10:07 jeremy Exp $
+ */
+public class HPSECalPlotsDriver extends Driver 
+{
+    String ecalCollectionName = "EcalHits";
+    AIDA aida = AIDA.defaultInstance();
+    
+    IHistogram1D hitEPlot;
+    ICloud1D ecalEPlot; 
+    ICloud1D primaryEPlot;
+    ICloud1D eventEPlot;
+    ICloud1D residualPlot;
+    ICloud1D residualAllPlot;
+    ICloud1D residualMaxHitPlot;    
+    ICloud1D maxHitEPlot;
+    ICloud2D hitYZPlot;
+    IHistogram1D maxTimePlot;
+    ICloud1D timePlot;
+    ICloud1D hitCountPlot;
+    ICloud1D idCountPlot;
+    
+    public void startOfData()
+    {
+        timePlot = aida.cloud1D(ecalCollectionName + " : Hit Time [ns]");
+        timePlot.annotation().addItem("yAxisScale", "log");
+        
+        maxTimePlot = aida.histogram1D(ecalCollectionName + " : Max Time [ns]", 200, 0, 1000);
+        maxTimePlot.annotation().addItem("yAxisScale", "log");
+        
+        maxHitEPlot = aida.cloud1D(ecalCollectionName + " : Max Hit E in Event [GeV]");
+        
+        hitEPlot = aida.histogram1D(ecalCollectionName + " : Hit Energy [MeV]", 200, 0, 3500);
+        hitEPlot.annotation().addItem("yAxisScale", "log");
+        
+        hitCountPlot = aida.cloud1D(ecalCollectionName + " : Hit Count");
+        
+        idCountPlot = aida.cloud1D(ecalCollectionName + " : Uniq Hit IDS");
+        
+        ecalEPlot = aida.cloud1D(ecalCollectionName + " : E Event [GeV]");
+        
+        primaryEPlot = aida.cloud1D("Highest Primary Particle Energy in Event [GeV]");
+        
+        eventEPlot = aida.cloud1D("Sum of Final State Electron Energies in Event [GeV]");
+        
+        residualPlot = aida.cloud1D(ecalCollectionName + " : E Residual with Highest E Particle [GeV]");
+        
+        residualAllPlot = aida.cloud1D(ecalCollectionName + " : E Residual with All Final State Electrons [GeV]");
+        
+        residualMaxHitPlot = aida.cloud1D(ecalCollectionName + " : Residual of Max Hit and Electron E");
+        
+        hitYZPlot = aida.cloud2D(ecalCollectionName + " : Y vs Z");
+    }
+    
+    public void process(EventHeader event)
+    {
+        // sum and max vars
+        double esum = 0;
+        double emax = 0;
+        double tmax = 0;
+                
+        // Loop over hits from ECal collection.
+        List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
+        int nhits = hits.size();
+        
+        Set<Long> ids = new HashSet<Long>();
+        
+        // n hits
+        hitCountPlot.fill(nhits);
+        
+        for (CalorimeterHit hit : hits)
+        {
+            // time
+            timePlot.fill(hit.getTime());
+            
+            // YZ
+            hitYZPlot.fill(hit.getPosition()[1], hit.getPosition()[2]);
+            
+            // get raw E
+            double eraw = hit.getRawEnergy();
+                        
+            // hit E
+            hitEPlot.fill(eraw / SystemOfUnits.MeV);
+            
+            // check E max
+            if (eraw > emax)
+                emax = eraw;
+            
+            // check T max
+            if (hit.getTime() > tmax)            
+                tmax = hit.getTime();
+            
+            ids.add(hit.getCellID());
+                                    
+            // incr E sum
+            esum += eraw;
+
+        }        
+        
+        //System.out.println("tmax: " + tmax);
+                 
+        // total E in Cal
+        ecalEPlot.fill(esum);
+        
+        // max hit E in event
+        maxHitEPlot.fill(emax);
+        
+        // max hit time
+        maxTimePlot.fill(tmax);
+        
+        // number of unique hit ids
+        idCountPlot.fill(ids.size());
+                                                      
+        // primary particle with most E
+        MCParticle primary = getPrimary(event.get(MCParticle.class).get(0));
+        double primaryE = primary.getEnergy();
+        primaryEPlot.fill(primaryE);
+        
+        // residual using highest E primary
+        double singleResidual = esum - primaryE;
+        residualPlot.fill(singleResidual);        
+     
+        // event energy                         
+        double eventE = getPrimaryE(event.get(MCParticle.class).get(0));
+        eventEPlot.fill(eventE);
+        
+        // event residual
+        double residual = esum - eventE;
+        residualAllPlot.fill(residual);
+        
+        // hottest hit residual with highest E particle
+        residualMaxHitPlot.fill(emax - primaryE);
+
+    }
+    
+    private double getPrimaryE(List<MCParticle> particles)
+    {
+        double electronE = 0;
+        for (MCParticle particle : particles)
+        {
+            if (particle.getGeneratorStatus() == MCParticle.FINAL_STATE 
+                    && Math.abs(particle.getPDGID()) == 11)
+            {
+                electronE += particle.getEnergy();
+            }
+        }
+        return electronE;
+    }
+    
+    private MCParticle getPrimary(List<MCParticle> particles)
+    {
+        double maxE = 0;
+        MCParticle primary = null;
+        for (MCParticle particle : particles)
+        {
+            if (particle.getGeneratorStatus() == MCParticle.FINAL_STATE 
+                    && particle.getEnergy() > maxE)
+            {
+                maxE = particle.getEnergy();
+                primary = particle;
+            }
+        }
+        return primary;        
+    }
+    
+    public void setEcalCollectionName(String ecalCollectionName)
+    {
+        this.ecalCollectionName = ecalCollectionName;
+    }
+}
CVSspam 0.2.8