Print

Print


Author: [log in to unmask]
Date: Wed Nov 19 14:45:54 2014
New Revision: 1572

Log:
Add Driver and steering to plot ADC values from all ECAL channels.

Added:
    java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalChannelADCPlotsDriver.java
    java/trunk/steering-files/src/main/resources/org/hps/steering/monitoring/EcalChannelADCPlots.lcsim

Added: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalChannelADCPlotsDriver.java
 =============================================================================
--- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalChannelADCPlotsDriver.java	(added)
+++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalChannelADCPlotsDriver.java	Wed Nov 19 14:45:54 2014
@@ -0,0 +1,99 @@
+package org.hps.monitoring.ecal.plots;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IHistogram1D;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterFactory;
+import hep.aida.IPlotterStyle;
+import hep.aida.ref.plotter.style.registry.StyleRegistry;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hps.conditions.database.TableConstants;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalConditions;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ * This Driver will create a histogram for every channel in the ECAL and plot its ADC values
+ * from the LCSim event collection of raw hits.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalChannelADCPlotsDriver extends Driver {
+
+    EcalConditions conditions = null;
+    EcalChannelCollection channels = null;
+
+    List<List<IPlotter>> plotterLists = new ArrayList<List<IPlotter>>();
+
+    AIDA aida = AIDA.defaultInstance();
+    IAnalysisFactory analysisFactory = aida.analysisFactory();
+
+    public void detectorChanged(Detector detector) {
+
+        conditions = ConditionsManager.defaultInstance().getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+
+        channels = conditions.getChannelCollection();
+
+        Set<Integer> crates = new HashSet<Integer>();
+        Set<Integer> slots = new HashSet<Integer>();
+        Set<Integer> channels = new HashSet<Integer>();
+
+        for (EcalChannel channel : conditions.getChannelCollection()) {
+            crates.add(channel.getCrate());
+            slots.add(channel.getSlot());
+            channels.add(channel.getChannel());
+        }
+                
+        IPlotterStyle style = StyleRegistry.getStyleRegistry().getStore("DefaultStyleStore").getStyle("DefaultHistogram1DStyle");
+        style.dataStyle().lineStyle().setVisible(false);
+        style.legendBoxStyle().setVisible(false);
+
+        for (Integer crate : crates) {
+            IPlotterFactory plotterFactory = analysisFactory.createPlotterFactory("ECAL Crate " + crate);
+            int plottersIndex = crate - 1;
+            plotterLists.add(new ArrayList<IPlotter>());
+            List<IPlotter> plotters = plotterLists.get(plottersIndex);
+            for (Integer slot : slots) {
+                IPlotter plotter = plotterFactory.create("Slot " + slot);
+                plotters.add(plotter);
+                plotter.createRegions(4, 4);
+                for (Integer channel : channels) {
+                    String histogramName = "ADC Values : " + crate + " : " + slot + " : " + channel;
+                    IHistogram1D histogram = aida.histogram1D(histogramName, 150, 50, 200.);
+                    plotter.region(channel).plot(histogram, style);
+                }
+                plotter.show();
+            }
+        }
+    }
+
+    public void process(EventHeader event) {
+        if (event.hasCollection(RawTrackerHit.class, "EcalReadoutHits")) {
+            List<RawTrackerHit> hits = event.get(RawTrackerHit.class, "EcalReadoutHits");
+            for (RawTrackerHit hit : hits) {
+                EcalChannel channel = channels.findGeometric(hit.getCellID());
+                if (channel != null) {
+                    for (short adcValue : hit.getADCValues()) {
+                        try {
+                            aida.histogram1D("ADC Values : " + channel.getCrate() + " : " + channel.getSlot() + " : " + channel.getChannel()).fill(adcValue);
+                        } catch (IllegalArgumentException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                } else {
+                    System.err.println("EcalChannel not found for cell ID 0x" + String.format("%08d", Long.toHexString(hit.getCellID())));
+                }
+            }
+        }
+    }
+}

Added: java/trunk/steering-files/src/main/resources/org/hps/steering/monitoring/EcalChannelADCPlots.lcsim
 =============================================================================
--- java/trunk/steering-files/src/main/resources/org/hps/steering/monitoring/EcalChannelADCPlots.lcsim	(added)
+++ java/trunk/steering-files/src/main/resources/org/hps/steering/monitoring/EcalChannelADCPlots.lcsim	Wed Nov 19 14:45:54 2014
@@ -0,0 +1,13 @@
+<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
+       xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd">           
+    <execute>
+        <driver name="EventMarkerDriver"/>
+        <driver name="EcalChannelADCPlotsDriver"/>
+    </execute>        
+    <drivers>    
+        <driver name="EventMarkerDriver" type="org.lcsim.job.EventMarkerDriver">
+            <eventInterval>1</eventInterval>
+        </driver>
+        <driver name="EcalChannelADCPlotsDriver" type="org.hps.monitoring.ecal.plots.EcalChannelADCPlotsDriver"/>
+    </drivers>
+</lcsim>