Commit in SlicDiagnostics/src/org/lcsim/slic/diagnostics on MAIN
calorimeterhit/BasicCalorimeterHitPlots.java+106added 1.1
layer/SingleLayerPlots.java+373added 1.1
+479
2 added files
more plotting drivers

SlicDiagnostics/src/org/lcsim/slic/diagnostics/calorimeterhit
BasicCalorimeterHitPlots.java added at 1.1
diff -N BasicCalorimeterHitPlots.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ BasicCalorimeterHitPlots.java	5 May 2010 22:41:27 -0000	1.1
@@ -0,0 +1,106 @@
+package org.lcsim.slic.diagnostics.calorimeterhit;
+
+import static org.lcsim.slic.diagnostics.util.AidaHelper.c1d;
+import static org.lcsim.slic.diagnostics.util.AidaHelper.c2d;
+import static org.lcsim.units.clhep.SystemOfUnits.keV;
+
+import java.util.List;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.slic.diagnostics.util.AbstractCollectionPlots;
+import org.lcsim.slic.diagnostics.util.VecUtil;
+
+/**
+ * This Driver creates a set of basic CalorimeterHit plots that
+ * do not require a {@link org.lcsim.geometry.Subdetector} to be 
+ * associated with the hits.  The plots use raw energy and do not 
+ * assume that the corrected energy is available.
+ * 
+ * The collections are assumed not to have an IDDecoder.  A single
+ * IDDecoder can be set using the {@link #setDecoderName(String)}
+ * method.  Since only one decoder can be set and the Driver may
+ * be applied to multiple collections, it is best to only specify
+ * a single collection to plot when doing this.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: BasicCalorimeterHitPlots.java,v 1.1 2010/05/05 22:41:27 jeremy Exp $
+ */
+public class BasicCalorimeterHitPlots extends AbstractCollectionPlots<CalorimeterHit> 
+{
+    String decoderName = null;
+    IDDecoder decoder = null;
+    
+    public Class<CalorimeterHit> getType() 
+    {
+        return CalorimeterHit.class;
+    }
+    
+    public void setDecoderName(String decoderName)
+    {
+        this.decoderName = decoderName;
+    }
+    
+    protected void defineCollectionPlots()
+    {
+        c1d("Hit Energy", "Energy [keV]", "Number of Entries");
+        c1d("Hit Cylindrical Radius", "Radius [mm]", "Number of Entries");
+        c1d("Hit Time", "Time [ns]", "Number of Entries");
+        c2d("Hit X vs Y", "X [mm]", "Y [mm]");
+        c2d("Hit Y vs Z", "Y [mm]", "Z [mm]");        
+        c1d("Event Energy", "Energy [GeV]", "Number of Entries");
+        c1d("Event Hits", "Number of Hits", "Number of Entries");
+        c2d("Event Energy vs Hits", "Energy [GeV]", "Number Of Hits");
+        c1d("Hit Layer", "Layer Number", "Number of Entries");
+        c1d("Event Average Hit Energy", "Energy [keV]", "Number of Entries");
+        c1d("Event Max Cylindrical Radius", "Radius [mm]", "Number of Entries");
+    }
+    
+    protected void detectorChanged(Detector detector)
+    {
+        if (decoderName != null)
+        {
+            //System.out.println("setting decoder to " + decoderName);
+            decoder = detector.getReadout(decoderName).getIDDecoder();
+        }
+    }
+    
+    public void plotCollection(EventHeader event, String collectionName, List<CalorimeterHit> collection) 
+    {
+        double energySum = 0;
+        double maxCylR = 0.;
+        double maxE = 0.;
+        int nhits = 0;
+        for (CalorimeterHit hit : collection)
+        {
+            double e = hit.getCorrectedEnergy();
+            if (e > maxE)
+                maxE = e;
+            c1d("Hit Energy").fill(e / keV);
+            double cylR = VecUtil.getCylindricalRadius(hit.getPosition());
+            if (cylR > maxCylR)
+                maxCylR = cylR;
+            c1d("Hit Cylindrical Radius").fill(cylR);
+            c2d("Hit X vs Y").fill(hit.getPosition()[0], hit.getPosition()[1]);
+            c2d("Hit Y vs Z").fill(hit.getPosition()[1], hit.getPosition()[2]);
+            c1d("Hit Time").fill(hit.getTime());
+            if (decoder != null)
+            {
+                //System.out.println("filling layer plot");
+                decoder.setID(hit.getCellID());
+                int layern = decoder.getValue("layer");
+                c1d("Hit Layer").fill(layern);
+            }
+            energySum += e; 
+            ++nhits;
+        }        
+        c1d("Event Energy").fill(energySum);        
+        c1d("Event Hits").fill(nhits);
+        c2d("Event Energy vs Hits").fill(energySum, nhits);
+        c1d("Event Average Hit Energy").fill(energySum / nhits);
+        c1d("Event Max Hit Cylindrical Radius").fill(maxCylR);
+        c1d("Event Max Hit Energy").fill(maxE);
+    }    
+}
\ No newline at end of file

SlicDiagnostics/src/org/lcsim/slic/diagnostics/layer
SingleLayerPlots.java added at 1.1
diff -N SingleLayerPlots.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SingleLayerPlots.java	5 May 2010 22:41:28 -0000	1.1
@@ -0,0 +1,373 @@
+package org.lcsim.slic.diagnostics.layer;
+
+import static java.lang.Math.log10;
+import static org.lcsim.slic.diagnostics.SlicDiagnosticsDirectories.SimCalorimeterHitDir;
+import static org.lcsim.slic.diagnostics.SlicDiagnosticsDirectories.SimTrackerHitDir;
+import static org.lcsim.slic.diagnostics.util.AidaHelper.aida;
+import static org.lcsim.slic.diagnostics.util.AidaHelper.c1d;
+import static org.lcsim.slic.diagnostics.util.AidaHelper.c2d;
+import static org.lcsim.slic.diagnostics.util.AidaHelper.cd;
+import static org.lcsim.slic.diagnostics.util.AidaHelper.tree;
+import static org.lcsim.units.SystemOfUnits.keV;
+import hep.aida.IBaseHistogram;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.SimCalorimeterHit;
+import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.geometry.Layered;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.slic.diagnostics.generichit.GenericHit;
+import org.lcsim.util.Driver;
+
+/**
+ * This driver uses GenericHits to make plots for individual layers.
+ * 
+ * @author jeremym
+ * @version $Id: SingleLayerPlots.java,v 1.1 2010/05/05 22:41:28 jeremy Exp $
+ */
+public class SingleLayerPlots extends Driver 
+{
+	List<String> collectionsSeen = new ArrayList<String>();    
+	String directory;    
+	Subdetector detector;
+	Map<Integer,LayerInfo> layerMap = null;    
+	int nlayers;
+	List<GenericHit> hits;
+	Class hitType = null;	
+	boolean doLayer = true;
+	List<String> collectionNames = new ArrayList<String>();
+	
+	public void setCollectionNames(String collectionNames[])
+	{
+	    this.collectionNames.addAll(Arrays.asList(collectionNames));
+	}
+
+	protected void process(EventHeader event)
+	{                        	
+	    for (String collectionName : collectionNames)
+	    {
+	        List<GenericHit> collection = event.get(GenericHit.class, collectionName);
+	        // Setup state for this collection.
+	        setGenericHitList(collection);
+	        LCMetaData meta = event.getMetaData(collection);           
+	        //String collectionName = meta.getName();           
+	        detector = meta.getIDDecoder().getSubdetector(); 
+
+	        if (detector instanceof Layered)
+	        {
+	            nlayers = ((Layered) detector).getLayering().getLayerCount();
+	        }
+	        layerMap = LayerInfoDriver.getLayerMap(detector);
+
+	        if (layerMap == null)
+	            doLayer=false;
+
+	        // Only process collections containing at least 1 object.
+	        if ( collection.size() > 0 )
+	        {            
+	            // Get the type of hit.
+	            hitType = collection.get(0).getHitType();
+
+	            // Set base directory according to type.
+	            if ( hitType == SimCalorimeterHit.class )
+	            {
+	                directory = SimCalorimeterHitDir;
+	            }
+	            else 
+	            {
+	                directory = SimTrackerHitDir;
+	            }
+
+	            // FIXME Hack to get correct collection name.
+	            directory += "/" + collectionName.replace("_GenericHits", "");
+
+	            cd(directory);
+
+	            // If processing this collection for the first time,
+	            // initialize all the plots, then flag as seen.
+	            if ( !collectionsSeen.contains(collectionName))
+	            {                            
+	                definePlots();
+	                collectionsSeen.add(collectionName);
+	            }
+
+	            // Fill plots.				
+	            fill(collection);	           
+	        }              
+	    }
+	}
+
+	protected void definePlots()
+	{                 
+		setupLayerPlots();                     
+	}
+
+	private void setupLayerPlots()
+	{    	        
+		IBaseHistogram plot = null;
+
+		this.layerMap = LayerInfoDriver.getLayerMap(detector);
+
+		if (layerMap == null)
+		{
+			throw new RuntimeException("Missing layerMap for " + detector.getName() + ".  LayerInfoDriver needs to be run first.");
+		}
+
+		for (int i = 0; i < nlayers; i++)
+		{
+			LayerInfo info = layerMap.get(Integer.valueOf(i));        	       
+
+			String layerName = info.getTitle();
+			String dirName = info.getDirName();
+
+			cd(directory);
+
+			// FIXME Hack to get right dir from GenericHit collection.
+			tree().mkdir(dirName);
+			tree().ls(dirName);
+
+			cd(dirName);
+
+			c1d(layerName + ": Total Energy", "Hit Energy Sum (GeV)", "Number of Events");
+
+			c1d(layerName + ": Average Hit Energy","Average Hit Energy (GeV)", "Number of Events");
+
+			c1d(layerName + ": Number of Hits", "Number of Hits", "Number of Events");
+
+			c1d(layerName + ": Fraction of Number of Hits", "Fraction of Total Number of Hits", "Number of Events");
+
+			c1d(layerName + ": Fraction of Total Energy", "Fraction of Total Energy", "Number of Events");
+
+			plot = c1d(layerName + ": Hit Energy", "Hit Energy [keV]", "Number of Hits");
+			//plot.annotation().addItem("yAxisScale", "log");
+
+			c1d(layerName + ": log10(Hit Energy)", "Hit Energy (log10(GeV))", "Number of Hits");
+
+			c1d(layerName + ": Hit Time", "Time (nanoseconds)", "Number of Hits");
+
+			c1d(layerName + ": log10(Hit Time)", "Time (log10(nanoseconds))", "Number of Hits");
+
+			//c1d(layerName + ": Cumulative Energy", "Fraction of Total Energy", "Number of Events");
+
+			//c1d(layerName + ": Cumulative Number of Hits", "Fraction of Total Number of Hits", "Number of Events");
+
+			c2d(layerName + ": Hit XY", "X (mm)", "Y (mm)");
+		}       
+	}
+
+	/**
+	 * Set the list of GenericHits to be processed. NOTE: GenericHitPlotsDriver
+	 * uses this method to set the list.
+	 */
+	protected void setGenericHitList(List<GenericHit> hits)
+	{
+		this.hits = hits;
+	}
+
+	/** Override interface fill method */
+	public void fill(EventHeader event)
+	{
+		fill(hits);
+	}
+
+	/** Make plots from a list of GenericHit objects. */
+	private void fill(List<GenericHit> hits)
+	{       
+		cd(directory);
+
+		// If there are no hits, then we have nothing to do.
+		if (hits.size() == 0)
+			return;
+
+		cd(directory);
+
+		// Initialize statistics variables
+		double eventTotE = 0.0;
+		int nhits = 0;
+		double minE = 9999.0;
+		double maxE = 0;
+
+		int maxLayer = 0;
+		int minLayer = 999;
+
+		// Loop over hits		
+		for (GenericHit hit : hits)
+		{
+			// Get hit data into local variables
+			double x = hit.getX();
+			double y = hit.getY();
+			double energy = hit.getEnergy();
+			double time = hit.getTime();
+			int layern = hit.getLayer();
+
+			// Lookup the LayerInfo from this hit's layer number
+			LayerInfo layerInfo=null;
+			if (layerMap != null)
+				layerInfo = layerMap.get(Integer.valueOf(layern));
+
+			// Enter layer dir
+			if (layerInfo != null)
+			{
+				cd(directory + "/" + layerInfo.getDirName());
+				String layerName = layerInfo.getTitle();
+
+				// Fill layer hit energy
+				c1d(layerName + ": Hit Energy").fill(energy);
+
+				// Fill log10 layer energy
+				c1d(layerName + ": log10(Hit Energy)").fill(energy / keV);
+
+				// Fill layer hit XY
+				c2d(layerName + ": Hit XY").fill(x, y);
+
+				// Fill layer time
+				c1d(layerName + ": Hit Time").fill(time);
+
+				// Fill log10 layer time
+				c1d(layerName + ": log10(Hit Time)").fill(log10(time));                        
+
+				// Leave layer dir
+				cd(directory);
+
+				// add hit to layer
+				layerInfo.addHit(hit);
+			}
+	
+			// Update max edep
+			if (energy > maxE)
+			{
+				maxE = energy;
+			}
+
+			// Update min edep
+			if (energy < minE)
+			{
+				minE = energy;
+			}
+
+			// Update max layer
+			if (layerInfo != null)
+			{
+				if (layern > maxLayer)
+				{
+					maxLayer = layern;
+				}
+			}
+
+			// Update min layer
+			if (layern < minLayer)
+			{
+				minLayer = layern;
+			}
+
+			// Add this energy to event total energy sum
+			eventTotE += energy;
+
+			// Increment total number of hits counter
+			++nhits;
+		}
+
+		// Min layer E
+		double minLayerE = 9999.0;
+
+		// Max layer E
+		double maxLayerE = 0.0;
+
+		// Min layer N hits
+		int minLayerNHits = 99999999;
+
+		// Max layer N hits
+		int maxLayerNHits = 0;
+
+		// Cumulative layer N hits
+		//int cumn = 0;
+
+		// Cumulative layer E
+		//double cume = 0;
+
+		// Loop over the layers after hits are processed
+		if (doLayer)
+		{
+			for (LayerInfo layerInfo : layerMap.values())
+			{
+				// Layer info into local vars
+				String layerName = layerInfo.getTitle();
+				//int layerNumber = layerInfo.getLayerNumber();
+				double layerE = layerInfo.getEnergy();
+				int layerNHits = layerInfo.getNHits();
+
+				// Set percentage of total energy
+				layerInfo.setPercentTotalEnergy(eventTotE);
+
+				// Set percentage of total n hits
+				layerInfo.setPercentNHits(nhits);
+
+				// Compute average hit energy
+				//double layerAvgHitEdep = layerE / layerNHits;
+
+				// Increment cum N hits by this layer's hits
+				//cumn += layerNHits;
+				//double fn = ((double) cumn) / ((double) nhits);
+
+				// Increment cum E by this layer's E
+				//cume += layerE;
+				//double fe = cume / eventTotE;
+
+				// Update max E
+				if (layerE > maxLayerE)
+				{
+					maxLayerE = layerE;
+				}
+
+				// Update min E
+				if (layerE < minLayerE)
+				{
+					minLayerE = layerE;
+				}
+
+				// Update max nhits
+				if (layerNHits > maxLayerNHits)
+				{
+					maxLayerNHits = layerNHits;
+				}
+
+				// Update min nhits
+				if (layerNHits < minLayerNHits)
+				{
+					minLayerNHits = layerNHits;
+				}
+			
+				// cd into layer dir
+				cd(directory);
+				aida().tree().cd(layerInfo.getDirName());
+
+				// Fill cumulative N hits for this layer
+				//c1d(layerName + ": Cumulative Number of Hits").fill(fn);
+
+				// Fill cumulative E for this layer
+				//c1d(layerName + ": Cumulative Energy").fill(fe);
+
+				// Fill layer total E
+				c1d(layerName + ": Total Energy").fill(layerE);
+
+				// Fill layer average hit E
+				c1d(layerName + ": Average Hit Energy").fill(layerInfo.getAverageHitEnergy());
+
+				// Fill layer total # hits
+				c1d(layerName + ": Number of Hits").fill(layerNHits);
+
+				// Fill layer's fraction of N hits
+				c1d(layerName + ": Fraction of Number of Hits").fill(layerInfo.getPercentNHits());
+
+				// Fill layer's fraction of total E
+				c1d(layerName + ": Fraction of Total Energy").fill(layerInfo.getPercentTotalEnergy());
+				cd(directory);
+			}
+		}
+	}
+}
\ No newline at end of file
CVSspam 0.2.8