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:

r2825 - /java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SensorOccupancyPlotsDriver.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 21:09:11 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (336 lines)

Author: [log in to unmask]
Date: Mon Apr 27 14:09:04 2015
New Revision: 2825

Log:
Reset plots between runs.

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

Modified: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SensorOccupancyPlotsDriver.java
 =============================================================================
--- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SensorOccupancyPlotsDriver.java	(original)
+++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SensorOccupancyPlotsDriver.java	Mon Apr 27 14:09:04 2015
@@ -16,7 +16,6 @@
 import hep.aida.ref.rootwriter.RootFileStore;
 import hep.aida.jfree.plotter.Plotter;
 import hep.aida.jfree.plotter.PlotterRegion;
-
 import hep.physics.vec.Hep3Vector;
 
 import org.lcsim.detector.tracker.silicon.HpsSiSensor;
@@ -30,7 +29,6 @@
 
 /**
  * This Driver makes plots of SVT sensor occupancies across a run.
- *
  * 
  * @author Omar Moreno <[log in to unmask]>
  */
@@ -40,15 +38,19 @@
    static {
         hep.aida.jfree.AnalysisFactory.register();
     } 
-  
-    ITree tree; 
-    IHistogramFactory histogramFactory;
-    IPlotterFactory plotterFactory = IAnalysisFactory.create().createPlotterFactory();
-
-    protected Map<String, IPlotter> plotters = new HashMap<String, IPlotter>();
-    protected Map<HpsSiSensor, IHistogram1D> occupancyPlots = new HashMap<HpsSiSensor, IHistogram1D>();
-    protected Map<HpsSiSensor, IHistogram1D> occupancyVPositionPlots = new HashMap<HpsSiSensor, IHistogram1D>();
-    protected Map<HpsSiSensor, int[]> occupancyMap = new HashMap<HpsSiSensor, int[]>();
+ 
+    // Plotting
+    private static ITree tree = null;
+    private IAnalysisFactory analysisFactory = IAnalysisFactory.create();
+    private IPlotterFactory plotterFactory = analysisFactory.createPlotterFactory();
+    private IHistogramFactory histogramFactory;
+
+    // Histogram maps
+    static protected Map<String, IPlotter> plotters = new HashMap<String, IPlotter>();
+    static protected Map<String, IHistogram1D> occupancyPlots = new HashMap<String, IHistogram1D>();
+    static protected Map<String, IHistogram1D> positionPlots = new HashMap<String, IHistogram1D>();
+    static protected Map<String, int[]> occupancyMap = new HashMap<String, int[]>();
+
     private List<HpsSiSensor> sensors;
     private Map<HpsSiSensor, Map<Integer, Hep3Vector>> stripPositions = new HashMap<HpsSiSensor, Map<Integer, Hep3Vector>>(); 
 
@@ -115,17 +117,26 @@
 
         return -1;
     }
-    
-    protected void detectorChanged(Detector detector) {
-
-        sensors = detector.getSubdetector(SUBDETECTOR_NAME).getDetectorElement().findDescendants(HpsSiSensor.class);
-
-        if (sensors.size() == 0) {
-            throw new RuntimeException("There are no sensors associated with this detector");
-        }
-        
-        // Create a Map from sensor to bad channels and from bad channels to
-        // strip position
+
+    /**
+     *  Get the global strip position of a physical channel number for a given
+     *  sensor.
+     *  
+     *  @param sensor : HpsSiSensor 
+     *  @param physicalChannel : physical channel number 
+     *  @return The strip position (mm) in the global coordinate system
+     */
+    private Hep3Vector getStripPosition(HpsSiSensor sensor, int physicalChannel){ 
+        return stripPositions.get(sensor).get(physicalChannel);
+    }
+   
+    /**
+     *  For each sensor, create a mapping between a physical channel number and
+     *  it's global strip position.
+     */
+    // TODO: Move this to a utility class
+    private void createStripPositionMap() { 
+
         for(ChargeCarrier carrier : ChargeCarrier.values()){
             for(HpsSiSensor sensor : sensors){ 
                 if(sensor.hasElectrodesOnSide(carrier)){ 
@@ -142,10 +153,106 @@
                 }
             }
         }
-
-        tree = IAnalysisFactory.create().createTreeFactory().create();
-        histogramFactory = IAnalysisFactory.create().createHistogramFactory(tree);
-
+    }
+
+    /**
+     *  Create a plotter style.
+     * 
+     * @param xAxisTitle : Title of the x axis
+     * @param sensor : HpsSiSensor associated with the plot.  This is used to
+     *                 set certain attributes based on the position of the 
+     *                 sensor.
+     * @return plotter style
+     */
+    // TODO: Move this to a utilities class
+    IPlotterStyle createOccupancyPlotStyle(String xAxisTitle, HpsSiSensor sensor) {
+        // 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("Occupancy");
+        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(true);
+        style.dataStyle().outlineStyle().setThickness(3);
+        style.dataStyle().fillStyle().setVisible(true);
+        style.dataStyle().fillStyle().setOpacity(.10);
+        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");
+        }
+        style.dataStyle().errorBarStyle().setVisible(false);
+        
+        // Turn off the legend
+        style.legendBoxStyle().setVisible(false);
+       
+        style.regionBoxStyle().backgroundStyle().setOpacity(.10);
+        if (sensor.isAxial()) style.regionBoxStyle().backgroundStyle().setColor("229, 114, 31, 1");
+        
+        return style;
+    }
+
+    /**
+     *  Clear all histograms of it's current data.
+     */
+    private void resetPlots() { 
+      
+        // Clear the hit counter map of all previously stored data. 
+        occupancyMap.clear();
+        
+        // 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) { 
+
+            // Clear the occupancy plots.
+            occupancyPlots.get(sensor.getName()).reset();
+            positionPlots.get(sensor.getName()).reset();
+            
+            // Reset the hit counters.
+            occupancyMap.put(sensor.getName(), new int[640]);
+        }
+    }
+    
+    protected void detectorChanged(Detector detector) {
+
+        // Get the HpsSiSensor objects from the geometry
+        sensors = detector.getSubdetector(SUBDETECTOR_NAME).getDetectorElement().findDescendants(HpsSiSensor.class);
+
+        // If there were no sensors found, throw an exception
+        if (sensors.size() == 0) {
+            throw new RuntimeException("There are no sensors associated with this detector");
+        }
+        
+        // For each sensor, create a mapping between a physical channel number
+        // and the global strip position
+        this.createStripPositionMap();
+        
+        // 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);
+
+        // Create the plotter and regions.  A region is created for each
+        // sensor for a total of 36.
         plotters.put("Occupancy", plotterFactory.create("Occupancy"));
         plotters.get("Occupancy").createRegions(6, 6);
 
@@ -155,30 +262,32 @@
         }
         
         for (HpsSiSensor sensor : sensors) {
-            occupancyPlots.put(sensor, histogramFactory.createHistogram1D(sensor.getName() + " - Occupancy", 640, 0, 640));
+            occupancyPlots.put(sensor.getName(), histogramFactory.createHistogram1D(sensor.getName() + " - Occupancy", 640, 0, 640));
             plotters.get("Occupancy").region(this.computePlotterRegion(sensor))
-                                     .plot(occupancyPlots.get(sensor), this.createOccupancyPlotStyle("Physical Channel", sensor));
+                                     .plot(occupancyPlots.get(sensor.getName()), this.createOccupancyPlotStyle("Physical Channel", sensor));
         
             if (enablePositionPlots) {
                 if (sensor.isTopLayer()) {
-                    occupancyVPositionPlots.put(sensor, 
+                    positionPlots.put(sensor.getName(), 
                             histogramFactory.createHistogram1D(sensor.getName() + " - Occupancy vs Position", 1000, 0, 60));
                 } else { 
-                    occupancyVPositionPlots.put(sensor, 
+                    positionPlots.put(sensor.getName(), 
                             histogramFactory.createHistogram1D(sensor.getName() + " - Occupancy vs Position", 1000, -60, 0));
                 }
                 
                 plotters.get("Occupancy vs Position").region(this.computePlotterRegion(sensor))
-                                                     .plot(occupancyVPositionPlots.get(sensor), this.createOccupancyPlotStyle("Distance from Beam [mm]", sensor));
-            }
-            occupancyMap.put(sensor, new int[640]);
-        }
+                                                     .plot(positionPlots.get(sensor.getName()), this.createOccupancyPlotStyle("Distance from Beam [mm]", sensor));
+            }
+            occupancyMap.put(sensor.getName(), new int[640]);
+        }
+        
+        System.out.println("Size of occupancyPlots map: " + occupancyPlots.size());
 
         for (IPlotter plotter : plotters.values()) {
-            for (int regionN = 0; regionN < 36; regionN++) { 
+            /*for (int regionN = 0; regionN < 36; regionN++) { 
                 PlotterRegion region = ((PlotterRegion) ((Plotter) plotter).region(regionN));
                 region.getPanel().addMouseListener(new PopupPlotterListener(region));
-            }
+            }*/
             plotter.show();
         }
     }
@@ -215,24 +324,24 @@
             }
            
             if (maxSamplePosition == -1 || maxSamplePosition == maxSamplePositionFound) { 
-                occupancyMap.get((HpsSiSensor) rawHit.getDetectorElement())[rawHit.getIdentifierFieldValue("strip")]++;
+                occupancyMap.get(((HpsSiSensor) rawHit.getDetectorElement()).getName())[rawHit.getIdentifierFieldValue("strip")]++;
             }
         }
 
         // Plot strip occupancies.
         if (eventCount % eventRefreshRate == 0) {
             for (HpsSiSensor sensor : sensors) {
-                int[] strips = occupancyMap.get(sensor);
-                occupancyPlots.get(sensor).reset();
-                if (enablePositionPlots) occupancyVPositionPlots.get(sensor).reset();
+                int[] strips = occupancyMap.get(sensor.getName());
+                occupancyPlots.get(sensor.getName()).reset();
+                if (enablePositionPlots) positionPlots.get(sensor.getName()).reset();
                 for (int channel = 0; channel < strips.length; channel++) {
                     double stripOccupancy = (double) strips[channel] / (double) eventCount;
                     stripOccupancy /= this.timeWindowWeight;
-                    occupancyPlots.get(sensor).fill(channel, stripOccupancy);
+                    occupancyPlots.get(sensor.getName()).fill(channel, stripOccupancy);
               
                     if (enablePositionPlots) {
                         double stripPosition = this.getStripPosition(sensor, channel).y();
-                        occupancyVPositionPlots.get(sensor).fill(stripPosition, stripOccupancy);
+                        positionPlots.get(sensor.getName()).fill(stripPosition, stripOccupancy);
                     }
                 }
             }
@@ -251,52 +360,4 @@
             e.printStackTrace();
         }
     }
-    
-    /**
-     * .
-     */
-    private Hep3Vector getStripPosition(HpsSiSensor sensor, int physicalChannel){ 
-        return stripPositions.get(sensor).get(physicalChannel);
-    }
-
-    IPlotterStyle createOccupancyPlotStyle(String xAxisTitle, HpsSiSensor sensor) {
-        // 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("Occupancy");
-        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(true);
-        style.dataStyle().outlineStyle().setThickness(3);
-        style.dataStyle().fillStyle().setVisible(true);
-        style.dataStyle().fillStyle().setOpacity(.10);
-        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");
-        }
-        style.dataStyle().errorBarStyle().setVisible(false);
-        
-        // Turn off the legend
-        style.legendBoxStyle().setVisible(false);
-       
-        style.regionBoxStyle().backgroundStyle().setOpacity(.10);
-        if (sensor.isAxial()) style.regionBoxStyle().backgroundStyle().setColor("229, 114, 31, 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