hps-java/src/main/java/org/lcsim/hps/monitoring/ecal
diff -u -r1.2 -r1.3
--- EcalEventMonitor.java 2 May 2012 16:53:29 -0000 1.2
+++ EcalEventMonitor.java 2 May 2012 22:11:47 -0000 1.3
@@ -4,19 +4,26 @@
import hep.aida.IPlotter;
import hep.aida.IPlotterStyle;
import hep.aida.ref.plotter.PlotterRegion;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
import java.util.List;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
import org.lcsim.event.EventHeader;
import org.lcsim.event.RawCalorimeterHit;
import org.lcsim.event.RawTrackerHit;
import org.lcsim.geometry.Detector;
import org.lcsim.geometry.IDDecoder;
+import org.lcsim.hps.monitoring.AIDAFrame;
import org.lcsim.hps.recon.ecal.HPSEcalConditions;
import org.lcsim.util.Driver;
import org.lcsim.util.aida.AIDA;
-public class EcalEventMonitor extends Driver {
+public class EcalEventMonitor extends Driver implements ActionListener, ItemListener {
String subdetectorName = "Ecal";
String inputCollectionName = "EcalReadoutHits";
@@ -28,10 +35,19 @@
int eventRefreshRate = 1;
int eventn = 0;
int integralWindow = 0;
+ private AIDAFrame plotterFrame;
+ private boolean singleEvent = false;
+ private JButton nextButton;
+ private JCheckBox logScaleBox;
+ private boolean plotNextEvent = true;
public EcalEventMonitor() {
}
+ public void setSingleEvent(boolean singleEvent) {
+ this.singleEvent = singleEvent;
+ }
+
public void setIntegralWindow(int integralWindow) {
this.integralWindow = integralWindow;
}
@@ -58,56 +74,79 @@
// Cache the IDDecoder for the ECal.
dec = detector.getSubdetector(subdetectorName).getReadout().getIDDecoder();
- // Setup the plotter.
- plotter = aida.analysisFactory().createPlotterFactory().create("HPS ECal Event Monitor");
-
// Setup plots.
aida.tree().cd("/");
hitPlot = aida.histogram2D(detector.getDetectorName() + " : " + inputCollectionName + " : Mean ADC Value", 47, -23.5, 23.5, 11, -5.5, 5.5);
+ // Setup the plotter.
+ plotter = aida.analysisFactory().createPlotterFactory().create("HPS ECal Event Monitor");
+
+ plotterFrame = new AIDAFrame(plotter);
+ plotterFrame.setVisible(true);
+ plotterFrame.setTitle("HPS ECal Event Monitor");
+
// Create the plotter regions.
plotter.createRegion();
plotter.style().statisticsBoxStyle().setVisible(false);
IPlotterStyle style = plotter.region(0).style();
style.setParameter("hist2DStyle", "colorMap");
style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+ style.zAxisStyle().setParameter("scale", "lin");
plotter.region(0).plot(hitPlot);
((PlotterRegion) plotter.region(0)).getPlot().setAllowUserInteraction(false);
((PlotterRegion) plotter.region(0)).getPlot().setAllowPopupMenus(false);
- plotter.show();
+
+ if (singleEvent) {
+ nextButton = new JButton("next");
+ nextButton.addActionListener(this);
+ plotterFrame.getControlsPanel().add(nextButton);
+ }
+
+ logScaleBox = new JCheckBox("log scale");
+ logScaleBox.addItemListener(this);
+ plotterFrame.getControlsPanel().add(logScaleBox);
+
+ plotterFrame.pack();
}
public void process(EventHeader event) {
- if (!HPSEcalConditions.pedestalsLoaded())
- {
+ if (!HPSEcalConditions.pedestalsLoaded()) {
HPSEcalConditions.loadPedestals();
}
- if (event.hasCollection(RawCalorimeterHit.class, inputCollectionName)) {
- if (++eventn % eventRefreshRate != 0) {
- return;
- }
- hitPlot.reset();
- List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, inputCollectionName);
- for (RawCalorimeterHit hit : hits) {
- dec.setID(hit.getCellID());
- int pedestal = integralWindow * HPSEcalConditions.physicalToPedestal(hit.getCellID());
- hitPlot.fill(dec.getValue("ix"), dec.getValue("iy"), hit.getAmplitude() - pedestal);
- }
- }
- if (event.hasCollection(RawTrackerHit.class, inputCollectionName)) {
- if (++eventn % eventRefreshRate != 0) {
- return;
+ if (plotNextEvent) {
+ if (event.hasCollection(RawCalorimeterHit.class, inputCollectionName)) {
+ if (++eventn % eventRefreshRate != 0) {
+ return;
+ }
+ hitPlot.reset();
+ List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, inputCollectionName);
+ for (RawCalorimeterHit hit : hits) {
+ dec.setID(hit.getCellID());
+ int pedestal = integralWindow * HPSEcalConditions.physicalToPedestal(hit.getCellID());
+ hitPlot.fill(dec.getValue("ix"), dec.getValue("iy"), hit.getAmplitude() - pedestal);
+ }
+ if (singleEvent) {
+ plotNextEvent = false;
+ }
}
- hitPlot.reset();
- List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputCollectionName);
- for (RawTrackerHit hit : hits) {
- dec.setID(hit.getCellID());
- double mean = 0;
- for (int i = 0; i < hit.getADCValues().length; i++) {
- mean += hit.getADCValues()[i];
+ if (event.hasCollection(RawTrackerHit.class, inputCollectionName)) {
+ if (++eventn % eventRefreshRate != 0) {
+ return;
+ }
+ hitPlot.reset();
+ List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputCollectionName);
+ for (RawTrackerHit hit : hits) {
+ dec.setID(hit.getCellID());
+ double mean = 0;
+ for (int i = 0; i < hit.getADCValues().length; i++) {
+ mean += hit.getADCValues()[i];
+ }
+ mean /= hit.getADCValues().length;
+ hitPlot.fill(dec.getValue("ix"), dec.getValue("iy"), mean);
+ }
+ if (singleEvent) {
+ plotNextEvent = false;
}
- mean /= hit.getADCValues().length;
- hitPlot.fill(dec.getValue("ix"), dec.getValue("iy"), mean);
}
}
}
@@ -121,4 +160,25 @@
hitPlot.reset();
}
}
+
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ if (ae.getSource() == nextButton) {
+ plotNextEvent = true;
+ }
+
+ }
+
+ @Override
+ public void itemStateChanged(ItemEvent ie) {
+ if (ie.getSource() == logScaleBox) {
+ IPlotterStyle style = plotter.region(0).style();
+ if (ie.getStateChange() == ItemEvent.DESELECTED) {
+ style.zAxisStyle().setParameter("scale", "lin");
+ } else {
+ style.zAxisStyle().setParameter("scale", "log");
+ }
+// plotter.region(0).plot(hitPlot);
+ }
+ }
}
\ No newline at end of file