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:

r2848 - /java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtClusterPlots.java

From:

[log in to unmask]

Reply-To:

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

Date:

Tue, 28 Apr 2015 23:06:41 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (294 lines)

Author: [log in to unmask]
Date: Tue Apr 28 16:06:34 2015
New Revision: 2848

Log:
Monitoring driver that looks at SVT cluster charge.

Added:
    java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtClusterPlots.java   (with props)

Added: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtClusterPlots.java
 =============================================================================
--- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtClusterPlots.java	(added)
+++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/drivers/svt/SvtClusterPlots.java	Tue Apr 28 16:06:34 2015
@@ -0,0 +1,278 @@
+package org.hps.monitoring.drivers.svt;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+
+import hep.aida.IAnalysisFactory;
+import hep.aida.IHistogram1D;
+import hep.aida.IHistogramFactory;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterFactory;
+import hep.aida.IPlotterStyle;
+import hep.aida.ITree;
+import hep.aida.jfree.plotter.Plotter;
+import hep.aida.jfree.plotter.PlotterRegion;
+import hep.aida.ref.rootwriter.RootFileStore;
+
+import org.lcsim.detector.tracker.silicon.HpsSiSensor;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHitStrip1D;
+import org.lcsim.util.Driver;
+
+import org.hps.recon.tracking.FittedRawTrackerHit;
+
+/**
+ *  Monitoring driver that looks at the SVT cluster charge.
+ * 
+ * @author Omar Moreno <[log in to unmask]>
+ *
+ */
+public class SvtClusterPlots extends Driver {
+    
+    // TODO: Add documentation
+
+    static {
+        hep.aida.jfree.AnalysisFactory.register();
+    }
+   
+    // 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 Map<String, IHistogram1D> clusterChargePlots = new HashMap<String, IHistogram1D>();
+	private Map<String, IHistogram1D> singleHitClusterChargePlots = new HashMap<String, IHistogram1D>();
+   
+    private List<HpsSiSensor> sensors;
+    private Map<RawTrackerHit, FittedRawTrackerHit> fittedRawTrackerHitMap 
+        = new HashMap<RawTrackerHit, FittedRawTrackerHit>();
+	
+    // Detector name
+    private static final String SUBDETECTOR_NAME = "Tracker";
+    
+    // Collections
+    private String clusterCollectionName = "StripClusterer_SiTrackerHitStrip1D";
+    private String fittedHitsCollectionName = "SVTFittedRawTrackerHits";
+    
+    private int runNumber = -1; 
+	
+    private int computePlotterRegion(HpsSiSensor sensor) {
+
+		if (sensor.getLayerNumber() < 7) {
+			if (sensor.isTopLayer()) {
+				return 6*(sensor.getLayerNumber() - 1); 
+			} else { 
+				return 6*(sensor.getLayerNumber() - 1) + 1;
+			} 
+		} else { 
+		
+			if (sensor.isTopLayer()) {
+				if (sensor.getSide() == HpsSiSensor.POSITRON_SIDE) {
+					return 6*(sensor.getLayerNumber() - 7) + 2;
+				} else { 
+					return 6*(sensor.getLayerNumber() - 7) + 3;
+				}
+			} else if (sensor.isBottomLayer()) {
+				if (sensor.getSide() == HpsSiSensor.POSITRON_SIDE) {
+					return 6*(sensor.getLayerNumber() - 7) + 4;
+				} else {
+					return 6*(sensor.getLayerNumber() - 7) + 5;
+				}
+			}
+		}
+		return -1; 
+    }
+    
+    IPlotterStyle createStyle(HpsSiSensor sensor, 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(4);
+        style.dataStyle().fillStyle().setVisible(true);
+        style.dataStyle().fillStyle().setOpacity(.30);
+       
+        if (sensor == null) { 
+            style.dataStyle().fillStyle().setColor("255, 38, 38, 1");
+            style.dataStyle().outlineStyle().setColor("255, 38, 38, 1");
+            style.dataStyle().fillStyle().setOpacity(.70);
+        } else if (sensor.isTopLayer()) { 
+            style.dataStyle().fillStyle().setColor("31, 137, 229, 1");
+            style.dataStyle().outlineStyle().setColor("31, 137, 229, 1");
+        } else if (sensor.isBottomLayer()){ 
+            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);
+       
+        return style;
+    }
+    
+    /**
+     *  Clear all histograms of it's current data.
+     */
+    private void resetPlots() { 
+
+        // Clear the fitted raw hit map of old values
+        fittedRawTrackerHitMap.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) { 
+           clusterChargePlots.get(sensor.getName()).reset();
+           singleHitClusterChargePlots.get(sensor.getName()).reset();
+        }
+    }
+    
+    /**
+     *  Method that creates a map between a fitted raw hit and it's corresponding raw fit
+     *  
+     * @param fittedHits : List of fitted hits to map
+     */
+    private void mapFittedRawHits(List<FittedRawTrackerHit> fittedHits) { 
+        
+        // Clear the fitted raw hit map of old values
+        fittedRawTrackerHitMap.clear();
+       
+        // Loop through all fitted hits and map them to their corresponding raw hits
+        for (FittedRawTrackerHit fittedHit : fittedHits) { 
+            fittedRawTrackerHitMap.put(fittedHit.getRawTrackerHit(), fittedHit);
+        }
+    }
+  
+    /**
+     * 
+     * @param rawHit
+     * @return
+     */
+    private FittedRawTrackerHit getFittedHit(RawTrackerHit rawHit) { 
+        return fittedRawTrackerHitMap.get(rawHit);
+    }
+    
+    
+    protected void detectorChanged(Detector detector) {
+
+        // 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("Cluster Amplitude", plotterFactory.create("Cluster Amplitude"));
+        plotters.get("Cluster Amplitude").createRegions(6, 6);
+   
+        for (HpsSiSensor sensor : sensors) { 
+        
+            clusterChargePlots.put(sensor.getName(), 
+                    histogramFactory.createHistogram1D(sensor.getName() + " - Cluster Charge", 100, 0, 5000));
+            plotters.get("Cluster Amplitude").region(this.computePlotterRegion(sensor))
+                                             .plot(clusterChargePlots.get(sensor.getName()), this.createStyle(sensor, "Cluster Amplitude [ADC Counts]", ""));
+        
+            singleHitClusterChargePlots.put(sensor.getName(), 
+                    histogramFactory.createHistogram1D(sensor.getName() + " - Single Hit Cluster Charge", 100, 0, 5000));
+            plotters.get("Cluster Amplitude").region(this.computePlotterRegion(sensor))
+                                             .plot(singleHitClusterChargePlots.get(sensor.getName()), this.createStyle(null, "Cluster Amplitude [ADC Counts]", ""));
+        }
+    
+		for (IPlotter plotter : plotters.values()) { 
+			plotter.show();
+			for (int regionN = 0; regionN < plotter.numberOfRegions(); regionN++) { 
+			    PlotterRegion region = ((PlotterRegion) ((Plotter) plotter).region(regionN));
+			    if (region.getPlottedObjects().size() == 0) continue;
+                region.getPanel().addMouseListener(new PopupPlotterListener(region));
+			}
+		}
+    }
+    
+    public void process(EventHeader event) { 
+     
+        if (runNumber == -1) runNumber = event.getRunNumber();
+        
+        // If the event doesn't contain fitted raw hits, skip it
+        if (!event.hasCollection(FittedRawTrackerHit.class, fittedHitsCollectionName)) return;
+        
+        // Get the list of fitted hits from the event
+        List<FittedRawTrackerHit> fittedHits = event.get(FittedRawTrackerHit.class, fittedHitsCollectionName);
+        
+        // Map the fitted hits to their corresponding raw hits
+        this.mapFittedRawHits(fittedHits);
+        
+        // If the event doesn't contain any clusters, skip it
+        if (!event.hasCollection(SiTrackerHitStrip1D.class, clusterCollectionName)) return;
+        
+        // Get the list of clusters in the event
+        List<SiTrackerHitStrip1D> clusters = event.get(SiTrackerHitStrip1D.class, clusterCollectionName);
+       
+        for (SiTrackerHitStrip1D cluster : clusters) { 
+            
+            // Get the sensor associated with this cluster
+            HpsSiSensor sensor = (HpsSiSensor) cluster.getSensor();
+            
+            // Get the raw hits composing this cluster and use them to calculate the amplitude of the hit
+            double amplitude = 0;
+            for (RawTrackerHit rawHit : cluster.getRawHits()) {
+                
+                // Add the amplitude of that channel to the total amplitude
+                amplitude += this.getFittedHit(rawHit).getAmp();
+            }
+            
+            // Fill all plots
+            clusterChargePlots.get(sensor.getName()).fill(amplitude);
+            
+            if (cluster.getRawHits().size() == 1) { 
+                singleHitClusterChargePlots.get(sensor.getName()).fill(amplitude);
+            } 
+        }
+    }
+    
+    public void endOfData() { 
+        
+        String rootFile = "run" + runNumber + "_cluster_analysis.root";
+        RootFileStore store = new RootFileStore(rootFile);
+        try {
+            store.open();
+            store.add(tree);
+            store.close(); 
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    
+}

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