LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  April 2015

HPS-SVN April 2015

Subject:

r2827 - /java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtHitPlots.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Mon, 27 Apr 2015 22:28:24 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (287 lines)

Author: [log in to unmask]
Date: Mon Apr 27 15:28:17 2015
New Revision: 2827

Log:
Reset plots at the start of a run.

Modified:
    java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtHitPlots.java

Modified: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtHitPlots.java
 =============================================================================
--- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtHitPlots.java	(original)
+++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtHitPlots.java	Mon Apr 27 15:28:17 2015
@@ -6,6 +6,7 @@
 import hep.aida.IPlotter;
 import hep.aida.IPlotterFactory;
 import hep.aida.IPlotterStyle;
+import hep.aida.ITree;
 
 import java.util.HashMap;
 import java.util.List;
@@ -18,8 +19,8 @@
 import org.lcsim.event.RawTrackerHit;
 
 /**
- *  Monitoring driver that provides information about the number
- *  of SVT hits per event.
+ *  Monitoring driver that provides information about the number of SVT hits
+ *  per event.
  *   
  *  @author Omar Moreno <[log in to unmask]>
  */
@@ -31,16 +32,21 @@
         hep.aida.jfree.AnalysisFactory.register();
     } 
 
-    static IHistogramFactory histogramFactory = IAnalysisFactory.create().createHistogramFactory(null);
-	IPlotterFactory plotterFactory = IAnalysisFactory.create().createPlotterFactory();
+    // Plotting
+    private static ITree tree = null;
+    private IAnalysisFactory analysisFactory = IAnalysisFactory.create();
+	private IPlotterFactory plotterFactory = analysisFactory.createPlotterFactory();
+    private IHistogramFactory histogramFactory = null; 
+	protected Map<String, IPlotter> plotters = new HashMap<String, IPlotter>(); 
+
+    // Histogram Maps
+    private static Map<String, IHistogram1D> hitsPerSensorPlots = new HashMap<String, IHistogram1D>();
+    private static Map<String, int[]> hitsPerSensor = new HashMap<String, int[]>();
+    private static Map<String, IHistogram1D> layersHitPlots = new HashMap<String, IHistogram1D>();
+	private static Map<String, IHistogram1D> hitCountPlots = new HashMap<String, IHistogram1D>();
+   
+    private List<HpsSiSensor> sensors;
 	
-	protected Map<String, IPlotter> plotters = new HashMap<String, IPlotter>(); 
-    private List<HpsSiSensor> sensors;
-    protected Map<HpsSiSensor, IHistogram1D> hitsPerSensorPlots = new HashMap<HpsSiSensor, IHistogram1D>();
-    protected Map<HpsSiSensor, int[]> hitsPerSensor = new HashMap<HpsSiSensor, int[]>();
-    protected Map<String, IHistogram1D> layersHitPlots = new HashMap<String, IHistogram1D>();
-	protected Map<String, IHistogram1D> hitCountPlots = new HashMap<String, IHistogram1D>();
-    
     private static final String SUBDETECTOR_NAME = "Tracker";
     private String rawTrackerHitCollectionName = "SVTRawTrackerHits";
    
@@ -74,34 +80,134 @@
 				}
 			}
 		}
-		
 		return -1; 
     }
     
+    /**
+     *  Create a plotter style.
+     * 
+     * @param xAxisTitle : Title of the x axis
+     * @param yAxisTitle : Title of the y axis
+     * @return plotter style
+     */
+    // TODO: Move this to a utilities class
+    IPlotterStyle createStyle(String xAxisTitle, String yAxisTitle) { 
+       
+        // Create a default style
+        IPlotterStyle style = this.plotterFactory.createPlotterStyle();
+        
+        // Set the style of the X axis
+        style.xAxisStyle().setLabel(xAxisTitle);
+        style.xAxisStyle().labelStyle().setFontSize(14);
+        style.xAxisStyle().setVisible(true);
+        
+        // Set the style of the Y axis
+        style.yAxisStyle().setLabel(yAxisTitle);
+        style.yAxisStyle().labelStyle().setFontSize(14);
+        style.yAxisStyle().setVisible(true);
+        
+        // Turn off the histogram grid 
+        style.gridStyle().setVisible(false);
+        
+        // Set the style of the data
+        style.dataStyle().lineStyle().setVisible(false);
+        style.dataStyle().outlineStyle().setVisible(false);
+        style.dataStyle().outlineStyle().setThickness(3);
+        style.dataStyle().fillStyle().setVisible(true);
+        style.dataStyle().fillStyle().setOpacity(.30);
+        style.dataStyle().fillStyle().setColor("31, 137, 229, 1");
+        style.dataStyle().outlineStyle().setColor("31, 137, 229, 1");
+        style.dataStyle().errorBarStyle().setVisible(false);
+        
+        // Turn off the legend
+        style.legendBoxStyle().setVisible(false);
+       
+        return style;
+    }
+    
+    /**
+     *  Create a plotter style.
+     * 
+     * @param sensor : HpsSiSensor associated with the plot.  This is used to
+     *                 set certain attributes based on the position of the 
+     *                 sensor.
+     * @param xAxisTitle : Title of the x axis
+     * @param yAxisTitle : Title of the y axis
+     * @return plotter style
+     */
+    // TODO: Move this to a utilities class
+    IPlotterStyle createStyle(HpsSiSensor sensor, String xAxisTitle, String yAxisTitle) { 
+        IPlotterStyle style = this.createStyle(xAxisTitle, yAxisTitle);
+        
+        if (sensor.isTopLayer()) { 
+            style.dataStyle().fillStyle().setColor("31, 137, 229, 1");
+            style.dataStyle().outlineStyle().setColor("31, 137, 229, 1");
+        } else { 
+            style.dataStyle().fillStyle().setColor("93, 228, 47, 1");
+            style.dataStyle().outlineStyle().setColor("93, 228, 47, 1");
+        }
+        
+        return style;
+    }
+
     private void clearHitMaps() { 
         for (HpsSiSensor sensor : sensors) {
-            hitsPerSensor.get(sensor)[0] = 0; 
-        }
-    }
-
+            hitsPerSensor.get(sensor.getName())[0] = 0; 
+        }
+    }
+
+    /**
+     *  Clear all histograms of it's current data.
+     */
+    private void resetPlots() { 
+      
+        // Reset all hit maps
+        this.clearHitMaps();
+        
+        // Since all plots are mapped to the name of a sensor, loop 
+        // through the sensors, get the corresponding plots and clear them.
+        for (HpsSiSensor sensor : sensors) { 
+            hitsPerSensorPlots.get(sensor.getName()).reset();
+        }
+       
+        for (IHistogram1D histogram : layersHitPlots.values()) {
+            histogram.reset();
+        }
+        
+        for (IHistogram1D histogram : hitCountPlots.values()) { 
+            histogram.reset();
+        }
+        
+    }
+    
     protected void detectorChanged(Detector detector) {
 
-        sensors 
-			= detector.getSubdetector(SUBDETECTOR_NAME).getDetectorElement().findDescendants(HpsSiSensor.class);
+        // Get the HpsSiSensor objects from the geometry
+        sensors = detector.getSubdetector(SUBDETECTOR_NAME).getDetectorElement().findDescendants(HpsSiSensor.class);
    
         if (sensors.size() == 0) {
             throw new RuntimeException("No sensors were found in this detector.");
         }
         
+        // If the tree already exist, clear all existing plots of any old data
+        // they might contain.
+        if (tree != null) { 
+            this.resetPlots();
+            return; 
+        }
+        
+        tree = analysisFactory.createTreeFactory().create();
+        histogramFactory = analysisFactory.createHistogramFactory(tree);
+        
         plotters.put("Raw hits per sensor", plotterFactory.create("Raw hits per sensor")); 
 		plotters.get("Raw hits per sensor").createRegions(6,6);
         
 		for (HpsSiSensor sensor : sensors) {
-		   hitsPerSensorPlots.put(sensor, 
+		   hitsPerSensorPlots.put(sensor.getName(), 
 		           histogramFactory.createHistogram1D(sensor.getName() + " - Raw Hits", 25, 0, 25)); 
 		   plotters.get("Raw hits per sensor").region(this.computePlotterRegion(sensor))
-		                                      .plot(hitsPerSensorPlots.get(sensor), this.createStyle(sensor, "Number of Raw Hits", ""));
-		   hitsPerSensor.put(sensor, new int[1]);
+		                                      .plot(hitsPerSensorPlots.get(sensor.getName()), this.createStyle(sensor, "Number of Raw Hits", ""));
+		   hitsPerSensor.put(sensor.getName(), new int[1]);
 		}
 
 		plotters.put("Number of layers hit", plotterFactory.create("Number of layers hit"));
@@ -145,7 +251,7 @@
         this.clearHitMaps();
         for (RawTrackerHit rawHit : rawHits) { 
             HpsSiSensor sensor = (HpsSiSensor) rawHit.getDetectorElement();
-            hitsPerSensor.get(sensor)[0]++;
+            hitsPerSensor.get(sensor.getName())[0]++;
         }
         
         int[] topLayersHit = new int[12];
@@ -154,12 +260,12 @@
         int topEventHitCount = 0;
         int botEventHitCount = 0;
         for (HpsSiSensor sensor : sensors) { 
-            int hitCount = hitsPerSensor.get(sensor)[0];
-            hitsPerSensorPlots.get(sensor).fill(hitCount);
+            int hitCount = hitsPerSensor.get(sensor.getName())[0];
+            hitsPerSensorPlots.get(sensor.getName()).fill(hitCount);
             
             eventHitCount += hitCount;
             
-            if (hitsPerSensor.get(sensor)[0] > 0) { 
+            if (hitsPerSensor.get(sensor.getName())[0] > 0) { 
                 if (sensor.isTopLayer()) { 
                     topLayersHit[sensor.getLayerNumber() - 1]++;
                     topEventHitCount += hitCount;
@@ -203,51 +309,4 @@
         System.out.println("\n%================================================%");
     }
     
-    IPlotterStyle createStyle(String xAxisTitle, String yAxisTitle) { 
-       
-        // Create a default style
-        IPlotterStyle style = this.plotterFactory.createPlotterStyle();
-        
-        // Set the style of the X axis
-        style.xAxisStyle().setLabel(xAxisTitle);
-        style.xAxisStyle().labelStyle().setFontSize(14);
-        style.xAxisStyle().setVisible(true);
-        
-        // Set the style of the Y axis
-        style.yAxisStyle().setLabel(yAxisTitle);
-        style.yAxisStyle().labelStyle().setFontSize(14);
-        style.yAxisStyle().setVisible(true);
-        
-        // Turn off the histogram grid 
-        style.gridStyle().setVisible(false);
-        
-        // Set the style of the data
-        style.dataStyle().lineStyle().setVisible(false);
-        style.dataStyle().outlineStyle().setVisible(false);
-        style.dataStyle().outlineStyle().setThickness(3);
-        style.dataStyle().fillStyle().setVisible(true);
-        style.dataStyle().fillStyle().setOpacity(.30);
-        style.dataStyle().fillStyle().setColor("31, 137, 229, 1");
-        style.dataStyle().outlineStyle().setColor("31, 137, 229, 1");
-        style.dataStyle().errorBarStyle().setVisible(false);
-        
-        // Turn off the legend
-        style.legendBoxStyle().setVisible(false);
-       
-        return style;
-    }
-    
-    IPlotterStyle createStyle(HpsSiSensor sensor, String xAxisTitle, String yAxisTitle) { 
-        IPlotterStyle style = this.createStyle(xAxisTitle, yAxisTitle);
-        
-        if (sensor.isTopLayer()) { 
-            style.dataStyle().fillStyle().setColor("31, 137, 229, 1");
-            style.dataStyle().outlineStyle().setColor("31, 137, 229, 1");
-        } else { 
-            style.dataStyle().fillStyle().setColor("93, 228, 47, 1");
-            style.dataStyle().outlineStyle().setColor("93, 228, 47, 1");
-        }
-        
-        return style;
-    }
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use