Commit in mcd-analysis/src/main/java/org/lcsim/mcd/analysis on MAIN
CalorimeterOccupancyDriver.java+96added 1.1
First draft calorimeter analysis. Calculates energy sums for the various calorimeters.

mcd-analysis/src/main/java/org/lcsim/mcd/analysis
CalorimeterOccupancyDriver.java added at 1.1
diff -N CalorimeterOccupancyDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CalorimeterOccupancyDriver.java	3 Jun 2011 23:29:10 -0000	1.1
@@ -0,0 +1,96 @@
+package org.lcsim.mcd.analysis;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.util.Driver;
+
+/**
+ *
+ * @author Norman A. Graf
+ *
+ * @version $Id: CalorimeterOccupancyDriver.java,v 1.1 2011/06/03 23:29:10 ngraf Exp $
+ */
+public class CalorimeterOccupancyDriver extends Driver
+{
+    // need a map to hold the cell maps keyed by calorimeter name
+
+    Map<String, Map<Long, Double>> _calHitMaps = new HashMap<String, Map<Long, Double>>();
+    // also need to store the IDDecoder for this detector
+    Map<String, IDDecoder> _calIDDecoders = new HashMap<String, IDDecoder>();
+
+    @Override
+    protected void process(EventHeader event)
+    {
+        // will store each calorimeter cell in a map keyed by its index.
+        // will add energy deposition event by event and analyze at end of run
+
+        // loop over all the collections in this event which contain SimCalorimeterHits
+        List<List<SimCalorimeterHit>> calHitLists = event.get(SimCalorimeterHit.class);
+        for (List<SimCalorimeterHit> calHitList : calHitLists)
+        {
+            LCMetaData meta = event.getMetaData(calHitList);
+
+            String calName = meta.getName();
+            // have we already created a map for this calorimeter?
+            if (!_calHitMaps.containsKey(calName))
+            {
+                // if not create a map keyed on CellId, containing the cell energy sum
+                Map<Long, Double> hitmap = new HashMap<Long, Double>();
+                // add it to our collection, keyed on this collection name
+                _calHitMaps.put(calName, hitmap);
+                IDDecoder decoder = meta.getIDDecoder();
+                _calIDDecoders.put(calName, decoder);
+            }
+            Map<Long, Double> hitmap = _calHitMaps.get(calName);
+//            System.out.println("List: " + calName + " contains " + calHitList.size());
+            for (SimCalorimeterHit h : calHitList)
+            {
+                long id = h.getCellID();
+                double energy = h.getCorrectedEnergy();
+                // do we already have an entry for this cell ID?
+                if (hitmap.containsKey(id))
+                {
+                    // add to the existing contribution
+                    hitmap.put(id, hitmap.get(id) + energy);
+                } else
+                {
+                    hitmap.put(id, energy);
+                }
+            }
+        }
+    }
+
+    @Override
+    protected void endOfData()
+    {
+        Set<String> keys = _calHitMaps.keySet();
+        System.out.println("map contains information for the following collections");
+        for (String key : keys)
+        {
+            System.out.println(key);
+            IDDecoder decoder = _calIDDecoders.get(key);
+            Map<Long, Double> hitmap = _calHitMaps.get(key);
+            double energySum = 0.;
+            Set<Entry<Long, Double>> entries = hitmap.entrySet();
+            for (Entry e : entries)
+            {
+                decoder.setID((Long) e.getKey());
+                double[] pos = decoder.getPosition();
+                double nrg = (Double) e.getValue();
+                energySum += nrg;
+                if (this.getHistogramLevel() == this.HLEVEL_FULL)
+                {
+                    System.out.println(pos[0] + " " + pos[1] + " " + pos[2] + " " + nrg);
+                }
+            }
+            System.out.println("   contains " + hitmap.size() + " hits with " + energySum + " GeV of energy");
+        }
+    }
+}
CVSspam 0.2.8