Commit in hps-java/src/main/java/org/lcsim/hps/monitoring on MAIN | |||
SensorOccupancyPlotsDriver.java | +72 | -42 | 1.1 -> 1.2 |
diff -u -r1.1 -r1.2 --- SensorOccupancyPlotsDriver.java 23 Mar 2012 22:50:14 -0000 1.1 +++ SensorOccupancyPlotsDriver.java 23 Mar 2012 23:47:05 -0000 1.2 @@ -20,10 +20,13 @@
private AIDA aida = AIDA.defaultInstance(); private IPlotter occuPlotter;
+ private Detector detector; + private List<SiSensor> sensors;
private Map<SiSensor,int[]> occupancyMap; private String rawTrackerHitCollectionName = "RawTrackerHitMaker_RawTrackerHits"; private String trackerName = "Tracker";
- private int eventCount;
+ private int eventCount = 0;
+ private int eventRefreshRate = 1;
public SensorOccupancyPlotsDriver() {}
@@ -32,36 +35,50 @@
this.rawTrackerHitCollectionName = rawTrackerHitCollectionName; }
+ public void setEventRefreshRate(int eventRefreshRate) { + this.eventRefreshRate = eventRefreshRate; + } +
protected void detectorChanged(Detector detector) {
- - if (occuPlotter != null) - occuPlotter.hide();
- // Setup plotter.
+ // If called > 1 then destroy plots that might be currently up. + if (occuPlotter != null) { + occuPlotter.hide(); + } + + // Setup the plotter. Should only need to be done once per job.
IAnalysisFactory fac = aida.analysisFactory();
- occuPlotter = fac.createPlotterFactory().create(detector.getDetectorName() + " : HPS SVT Sensor Occupancy Plots"); - IPlotterStyle pstyle = occuPlotter.style(); - pstyle.dataStyle().fillStyle().setColor("green"); - pstyle.dataStyle().markerStyle().setColor("green"); - pstyle.dataStyle().errorBarStyle().setVisible(false); - pstyle.statisticsBoxStyle().setVisible(false); - occuPlotter.createRegions(5, 4); // FIXME Hard-coded to 20 sensors. - - // Make a list of sensors in the SVT. - List<SiSensor> sensors = detector.getSubdetector(trackerName).getDetectorElement().findDescendants(SiSensor.class); - int ns = sensors.size();
+ if (occuPlotter == null) { + occuPlotter = fac.createPlotterFactory().create(detector.getDetectorName() + " : HPS SVT Sensor Occupancy Plots"); + IPlotterStyle pstyle = occuPlotter.style(); + pstyle.dataStyle().fillStyle().setColor("green"); + pstyle.dataStyle().markerStyle().setColor("green"); + pstyle.dataStyle().errorBarStyle().setVisible(false); + pstyle.statisticsBoxStyle().setVisible(false); + occuPlotter.createRegions(5, 4); // FIXME Hard-coded to 20 sensors. + }
- // Data structure for occupancy calculations by sensor. - occupancyMap = new HashMap<SiSensor,int[]>(); - for (SiSensor sensor : sensors) { - occupancyMap.put(sensor, new int[640]);
+ // Cache Detector object. + this.detector = detector; + + // Make a list of SiSensors in the SVT. + sensors = this.detector.getSubdetector(trackerName).getDetectorElement().findDescendants(SiSensor.class); + + // For now throw an error if there are "too many" sensors. + if (sensors.size() > 20) { + throw new RuntimeException("Can't handle > 20 sensors at a time.");
}
-
+
+ // Reset or setup the data structure for occupancy calculations by sensor.
+ resetOccupancyMap();
+
+ // Setup the occupancy plots.
+ int region = 0;
aida.tree().cd("/");
- for (int i = 0; i < ns; i++) - { - IHistogram1D occupancyPlot = aida.histogram1D(sensors.get(i).getName(), 640, 0, 639); - occuPlotter.region(i).plot(occupancyPlot);
+ for (SiSensor sensor : sensors) { + IHistogram1D occupancyPlot = aida.histogram1D(sensor.getName(), 640, 0, 639); + occuPlotter.region(region).plot(occupancyPlot); + ++region;
} occuPlotter.show(); }
@@ -71,35 +88,48 @@
// Increment event counter. ++eventCount;
- // Get collections from event.
+ // Get RawTrackerHit collection from event.
List<RawTrackerHit> rawTrackerHits = event.get(RawTrackerHit.class, rawTrackerHitCollectionName);
- // Loop over RawTrackerHit collection.
+ // Loop over RawTrackerHit collection and increment occupancies.
for (RawTrackerHit hit : rawTrackerHits) {
- // Increment hit counts for occupancy calculations.
+ // Increment hit counts for each strip.
int[] strips = occupancyMap.get((SiSensor) hit.getDetectorElement()); strips[hit.getIdentifierFieldValue("strip")] += 1; }
+ + if (eventCount % this.eventRefreshRate == 0) {
- // Occupancy plots are redrawn every event. - occuPlotter.clearRegions(); - int si = 0; - for (SiSensor sensor : occupancyMap.keySet()) { - int[] strips = occupancyMap.get(sensor); - aida.histogram1D(sensor.getName()).reset(); - for (int i = 0; i < strips.length; i++) { - double stripOccupancy = (double) strips[i] / (double) (eventCount); - if (stripOccupancy != 0) { - aida.histogram1D(sensor.getName()).fill(i, stripOccupancy);
+ // Occupancy plots are redrawn each time. + occuPlotter.clearRegions(); + int region = 0; + for (SiSensor sensor : sensors) { + IHistogram1D sensorHist = aida.histogram1D(sensor.getName()); + sensorHist.reset(); + int[] strips = occupancyMap.get(sensor); + for (int i = 0; i < strips.length; i++) { + double stripOccupancy = (double) strips[i] / (double) (eventCount); + if (stripOccupancy != 0) { + sensorHist.fill(i, stripOccupancy); + }
}
+ occuPlotter.region(region).plot(aida.histogram1D(sensor.getName())); + ++region;
}
- occuPlotter.region(si).plot(aida.histogram1D(sensor.getName())); - ++si;
+ occuPlotter.show();
}
- occuPlotter.show(); - }
+ } + + private void resetOccupancyMap() { + // Data structure for occupancy calculations by sensor. + occupancyMap = new HashMap<SiSensor,int[]>(); + for (SiSensor sensor : sensors) { + occupancyMap.put(sensor, new int[640]); + } + }
public void reset() { eventCount = 0;
+ resetOccupancyMap();
} }
\ No newline at end of file
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1