Commit in hps-java/src/main/java/org/lcsim/hps/recon/ecal on MAIN
EcalCrystalFilter.java+446added 1.1
Driver to filter out noisy clusters.

hps-java/src/main/java/org/lcsim/hps/recon/ecal
EcalCrystalFilter.java added at 1.1
diff -N EcalCrystalFilter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalCrystalFilter.java	6 Jun 2012 18:17:59 -0000	1.1
@@ -0,0 +1,446 @@
+package org.lcsim.hps.recon.ecal;
+
+import org.lcsim.hps.monitoring.ecal.*;
+import hep.aida.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.*;
+import org.lcsim.detector.identifier.*;
+import org.lcsim.event.CalorimeterHit;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.RawTrackerHit;
+import org.lcsim.event.base.BaseRawCalorimeterHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.hps.monitoring.AIDAFrame;
+import org.lcsim.hps.monitoring.Redrawable;
+import org.lcsim.hps.monitoring.Resettable;
+import org.lcsim.hps.recon.ecal.HPSEcalConditions;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+public class EcalCrystalFilter extends Driver implements Resettable, ActionListener, Redrawable {
+
+    private String inputCollection;
+    private IPlotter plotter;
+    private IPlotter plotter2;
+    private IPlotter plotter3;
+    private IPlotter plotter4;
+    private AIDA aida = AIDA.defaultInstance();
+    private AIDAFrame plotterFrame;
+    private IHistogram1D aMeanPlot;
+    private IHistogram1D aSigmaPlot;
+    private IHistogram1D tMeanPlot;
+    private IHistogram1D tSigmaPlot;
+    private IHistogram2D aTOutMeanPlot;
+    private IHistogram2D aTOutSigmaPlot;
+    private IHistogram2D tTOutMeanPlot;
+    private IHistogram2D tTOutSigmaPlot;
+    private IHistogram1D[][] aPlots = new IHistogram1D[47][11];
+    private IHistogram1D[][] tPlots = new IHistogram1D[47][11];
+    private JLabel xLabel, yLabel;
+    private JComboBox xCombo;
+    private JComboBox yCombo;
+    private JButton blankButton;
+    private static final Integer[] xList = new Integer[46];
+    private static final Integer[] yList = new Integer[10];
+    int eventRefreshRate = 1;
+    int eventn = 0;
+    boolean hide = false;
+    int calWindow = 0;
+    double maxE = 1000;
+    double tTOutNSigmaThr = 5.0;
+    String hotCrystalFileName = "ecal_hotcrystals.txt";
+    FileWriter fWriter;
+    PrintWriter pWriter;
+
+    public EcalCrystalFilter() {
+        int count = 0;
+        for (int i = -23; i <= 23; i++) {
+            if (i != 0) {
+                xList[count] = i;
+                count++;
+            }
+        }
+        count = 0;
+        for (int i = -5; i <= 5; i++) {
+            if (i != 0) {
+                yList[count] = i;
+                count++;
+            }
+        }
+        try {
+            fWriter = new FileWriter(hotCrystalFileName);
+            pWriter = new PrintWriter(fWriter);
+        } catch (IOException ex) {
+            Logger.getLogger(EcalCrystalFilter.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        
+    }
+
+    public void closeFile() throws IOException {
+        pWriter.close();
+        fWriter.close();
+    }
+    
+    public void setMaxE(double maxE) {
+        this.maxE = maxE;
+    }
+
+    public void setCalWindow(int calWindow) {
+        this.calWindow = calWindow;
+    }
+
+    public void setHide(boolean hide) {
+        this.hide = hide;
+    }
+
+    public void setInputCollection(String inputCollection) {
+        this.inputCollection = inputCollection;
+    }
+
+    public void detectorChanged(Detector detector) {
+        if (inputCollection == null) {
+            throw new RuntimeException("The inputCollection parameter was not set.");
+        }
+
+        aida = AIDA.defaultInstance();
+        aida.tree().cd("/");
+        
+        aSigmaPlot = aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : <Sigma> (Amplitude)", 50, 0,200);
+        aMeanPlot = aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : <Mean> (Amplitude)", 50, 0,1000);
+        tSigmaPlot = aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : <Sigma> (Time)", 50,0,50);
+        tMeanPlot = aida.histogram1D(detector.getDetectorName() + " : " + inputCollection + " : <Mean> (Time)", 50, 0, 100);
+        
+        aTOutSigmaPlot = aida.histogram2D(detector.getDetectorName() + " : " + inputCollection + " : Sigma (Amplitude) Time Outliers", 47, -23.5, 23.5, 11, -5.5, 5.5);
+        aTOutMeanPlot = aida.histogram2D(detector.getDetectorName() + " : " + inputCollection + " : Mean (Amplitude) Time Outliers", 47, -23.5, 23.5, 11, -5.5, 5.5);
+        tTOutSigmaPlot = aida.histogram2D(detector.getDetectorName() + " : " + inputCollection + " : Sigma (Time) Time Outliers", 47, -23.5, 23.5, 11, -5.5, 5.5);
+        tTOutMeanPlot = aida.histogram2D(detector.getDetectorName() + " : " + inputCollection + " : Mean (Time) Time Outliers", 47, -23.5, 23.5, 11, -5.5, 5.5);
+
+        
+        for (int x = -23; x <= 23; x++) { // slot
+            for (int y = -5; y <= 5; y++) { // crate                
+                //System.out.println("creating plot: " + "ECAL: Crate " + j + "; Slot " + i + " in region " + region);
+//                IHistogram1D hist = aida.histogram1D("ECAL: x=" + i + "; y=" + j, 1000, 0, 16);
+//                plots[x + 23][y + 5] = aida.cloud1D("ECAL: x=" + x + "; y=" + y);
+                if (calWindow == 0) {
+                    aPlots[x + 23][y + 5] = aida.histogram1D("ECAL Amplitudes: x=" + x + "; y=" + y, 500, -100, maxE);
+                } else {
+                    aPlots[x + 23][y + 5] = aida.histogram1D("ECAL Amplitudes: x=" + x + "; y=" + y, 1024, -0.5, 1023.5);
+                }
+                tPlots[x + 23][y + 5] = aida.histogram1D("ECAL Times: x=" + x + "; y=" + y, 100, 0, 100);
+            }
+        }
+
+        plotterFrame = new AIDAFrame();
+        plotterFrame.setTitle("HPS ECal Crystal Filter Plots");
+
+        xCombo = new JComboBox(xList);
+        xCombo.addActionListener(this);
+        xLabel = new JLabel("x");
+        xLabel.setLabelFor(xCombo);
+        plotterFrame.getControlsPanel().add(xLabel);
+        plotterFrame.getControlsPanel().add(xCombo);
+        yCombo = new JComboBox(yList);
+        yCombo.addActionListener(this);
+        yLabel = new JLabel("y");
+        yLabel.setLabelFor(yCombo);
+        plotterFrame.getControlsPanel().add(yLabel);
+        plotterFrame.getControlsPanel().add(yCombo);
+        blankButton = new JButton("Hide histogram");
+        plotterFrame.getControlsPanel().add(blankButton);
+        blankButton.addActionListener(this);
+
+        // Setup the plotter.
+        plotter = aida.analysisFactory().createPlotterFactory().create();
+        plotter.setTitle("HPS ECal Amplitude");
+        plotterFrame.addPlotter(plotter);
+        plotter.createRegions(1, 3);
+
+        plotter.style().statisticsBoxStyle().setVisible(false);
+        plotter.style().dataStyle().errorBarStyle().setVisible(false);
+        plotter.style().zAxisStyle().setParameter("allowZeroSuppression", "true");
+        IPlotterStyle style = plotter.region(0).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        style = plotter.region(1).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        plotter.region(0).plot(aSigmaPlot);
+        plotter.region(1).plot(aMeanPlot);
+        plotter.style().dataStyle().fillStyle().setColor("yellow");
+        
+        // Setup the plotter.
+        plotter2 = aida.analysisFactory().createPlotterFactory().create();
+        plotter2.setTitle("HPS ECal Hit Time ");
+        plotterFrame.addPlotter(plotter2);
+        plotter2.createRegions(1, 3);
+
+        plotter2.style().statisticsBoxStyle().setVisible(true);
+        plotter2.style().dataStyle().errorBarStyle().setVisible(false);
+        plotter2.style().zAxisStyle().setParameter("allowZeroSuppression", "true");
+        style = plotter2.region(0).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        style = plotter2.region(1).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        plotter2.region(0).plot(tSigmaPlot);
+        plotter2.region(1).plot(tMeanPlot);
+        plotter2.style().dataStyle().fillStyle().setColor("green");
+        
+        
+        // Setup the plotter.
+        plotter3 = aida.analysisFactory().createPlotterFactory().create();
+        plotter3.setTitle("HPS ECal for Time Outliers ");
+        plotterFrame.addPlotter(plotter3);
+        plotter3.createRegions(1, 3);
+
+        plotter3.style().statisticsBoxStyle().setVisible(false);
+        plotter3.style().dataStyle().errorBarStyle().setVisible(false);
+        plotter3.style().zAxisStyle().setParameter("allowZeroSuppression", "true");
+        style = plotter3.region(0).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        style = plotter3.region(1).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        plotter3.region(0).plot(tTOutSigmaPlot);
+        plotter3.region(1).plot(tTOutMeanPlot);
+        plotter3.style().dataStyle().fillStyle().setColor("green");
+        
+         // Setup the plotter.
+        plotter4 = aida.analysisFactory().createPlotterFactory().create();
+        plotter4.setTitle("HPS ECal Amplitude for Time Outliers ");
+        plotterFrame.addPlotter(plotter4);
+        plotter4.createRegions(1, 3);
+
+        plotter4.style().statisticsBoxStyle().setVisible(false);
+        plotter4.style().dataStyle().errorBarStyle().setVisible(false);
+        plotter4.style().zAxisStyle().setParameter("allowZeroSuppression", "true");
+        style = plotter4.region(0).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        style = plotter4.region(1).style();
+        style.setParameter("hist2DStyle", "colorMap");
+        style.dataStyle().fillStyle().setParameter("colorMapScheme", "rainbow");
+        plotter4.region(0).plot(aTOutSigmaPlot);
+        plotter4.region(1).plot(aTOutMeanPlot);
+        plotter4.style().dataStyle().fillStyle().setColor("green");
+        
+        plotter.region(2).plot(aPlots[-5 + 23][2 + 5 - 1]);
+        plotter2.region(2).plot(tPlots[-5 + 23][2 + 5 - 1]);
+        plotter3.region(2).plot(tPlots[-5 + 23][2 + 5 - 1]);
+        plotter4.region(2).plot(aPlots[-5 + 23][2 + 5 - 1]);
+        xCombo.setSelectedIndex(-5 + 23);
+        yCombo.setSelectedIndex(2 + 5 - 1);
+        
+        
+        
+        plotterFrame.pack();
+        if (!hide) {
+            plotterFrame.setVisible(true);
+        }
+        
+        
+        
+        
+        
+        
+        
+        
+        
+        
+    }
+
+    
+    public void printOutliers() {
+        
+        //Outliers in time -- threshold is nr of sigma/rms from the mean
+        System.out.printf("Crystals with time RMS more than %.1f times the RMS(<RMS>)=%.1f from <RMS>=%.1f for all crystals\n",tTOutNSigmaThr,tSigmaPlot.rms(),tSigmaPlot.mean());
+        
+        for (int x = -23; x <= 23; x++) { // slot
+            for (int y = -5; y <= 5; y++) { // crate   
+            
+                
+                if(tTOutSigmaPlot.binEntries(tTOutSigmaPlot.coordToIndexX(x), tTOutSigmaPlot.coordToIndexY(y))>0) {
+                    IIdentifierHelper helper = HPSEcalConditions.getHelper();
+                    IExpandedIdentifier expId = new ExpandedIdentifier(helper.getIdentifierDictionary().getNumberOfFields());
+                    //expId.setValue(helper.getFieldIndex("system"), ecal.getSystemID());
+                    expId.setValue(helper.getFieldIndex("ix"), x);
+                    expId.setValue(helper.getFieldIndex("iy"), y);
+                    Long id = helper.pack(expId).getValue();
+                    
+                    
+                    System.out.printf("[%d,%d]\t%d\t%d\t%d\tTime:%f +- %f\tAmp:%f +- %f\n",x,y,HPSEcalConditions.getCrate(id),HPSEcalConditions.getSlot(id) ,HPSEcalConditions.getChannel(id), tPlots[x + 23][y + 5].mean(), tPlots[x + 23][y + 5].rms(), aPlots[x + 23][y + 5].mean(), aPlots[x + 23][y + 5].rms());
+                    
+                    pWriter.printf("%d %d\n",x,y);
+                }
+            
+            }
+        }
+    }
+    
+    
+    
+    public void endOfData() {
+        
+        //Redraw one final time and use those values to print out the outlying crystals
+        redraw();
+        printOutliers();
+        //plotterFrame.dispose();
+        if (calWindow > 0) {
+            for (int crate = 1; crate < 3; crate++) {
+                for (short slot = 0; slot < 20; slot++) {
+                    for (short ch = 0; ch < 16; ch++) {
+                        Long id = HPSEcalConditions.daqToPhysicalID(crate, slot, ch);
+                        IIdentifierHelper helper = HPSEcalConditions.getHelper();
+                        if (id == null) {
+                            continue;
+                        }
+                        IIdentifier compactId = new Identifier(id);
+                        int x = helper.getValue(compactId, "ix");
+                        int y = helper.getValue(compactId, "iy");
+                        System.out.printf("%d\t%d\t%d\t%f\t%f\n", crate, slot, ch, aPlots[x + 23][y + 5].mean(), aPlots[x + 23][y + 5].rms());
+                    }
+                }
+            }
+        }
+        try {
+            closeFile();
+        } catch (IOException ex) {
+            Logger.getLogger(EcalCrystalFilter.class.getName()).log(Level.SEVERE, null, ex);
+        }
+    }
+
+    public void reset() {
+//        if (plotter != null) {
+//            plotter.hide();
+//            plotter.destroyRegions();
+//            for (int x = -23; x <= 23; x++) { // slot
+//                for (int y = -5; y <= 5; y++) { // crate                
+//                    aPlots[x + 23][y + 5].reset();
+//                }
+//            }
+//        }
+    }
+
+    public void process(EventHeader event) {
+        if (event.hasCollection(RawTrackerHit.class, inputCollection)) {
+            List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputCollection);
+            for (RawTrackerHit hit : hits) {
+                int x = hit.getIdentifierFieldValue("ix");
+                int y = hit.getIdentifierFieldValue("iy");
+                if (calWindow > 0) {
+                    for (int i = 0; i < calWindow; i++) {
+                        aPlots[x + 23][y + 5].fill(hit.getADCValues()[i]);
+                    }
+                } else {
+                    for (int i = 0; i < hit.getADCValues().length; i++) {
+                        aPlots[x + 23][y + 5].fill(hit.getADCValues()[i]);
+                    }
+                }
+            }
+            if (eventRefreshRate > 0 && ++eventn % eventRefreshRate == 0) {
+                redraw();
+            }
+        }
+
+        if (event.hasCollection(BaseRawCalorimeterHit.class, inputCollection)) {
+            List<BaseRawCalorimeterHit> hits = event.get(BaseRawCalorimeterHit.class, inputCollection);
+            for (BaseRawCalorimeterHit hit : hits) {
+                int x = hit.getIdentifierFieldValue("ix");
+                int y = hit.getIdentifierFieldValue("iy");
+                aPlots[x + 23][y + 5].fill(hit.getAmplitude());
+                tPlots[x + 23][y + 5].fill(hit.getTimeStamp() / 64);
+            }
+            if (eventRefreshRate > 0 && ++eventn % eventRefreshRate == 0) {
+                redraw();
+            }
+        }
+
+        if (event.hasCollection(CalorimeterHit.class, inputCollection)) {
+            List<CalorimeterHit> hits = event.get(CalorimeterHit.class, inputCollection);
+            for (CalorimeterHit hit : hits) {
+                int x = hit.getIdentifierFieldValue("ix");
+                int y = hit.getIdentifierFieldValue("iy");
+                aPlots[x + 23][y + 5].fill(hit.getRawEnergy());
+                tPlots[x + 23][y + 5].fill(hit.getTime() / 4.0);
+            }
+            if (eventRefreshRate > 0 && ++eventn % eventRefreshRate == 0) {
+                redraw();
+            }
+        }
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent ae) {
+        if (ae.getSource() == blankButton) {
+            plotter.region(2).clear();
+            plotter2.region(2).clear();
+        } else {
+            Integer x, y;
+            x = (Integer) xCombo.getSelectedItem();
+            y = (Integer) yCombo.getSelectedItem();
+            plotter.region(2).clear();
+            plotter.region(2).plot(aPlots[x + 23][y + 5]);
+            plotter2.region(2).clear();
+            plotter2.region(2).plot(tPlots[x + 23][y + 5]);
+//            ((PlotterRegion) plotter.region(2)).getPlot().setAllowUserInteraction(false);
+//            ((PlotterRegion) plotter.region(2)).getPlot().setAllowPopupMenus(false);
+            plotter3.region(2).clear();
+            plotter3.region(2).plot(tPlots[x + 23][y + 5]);
+            plotter4.region(2).clear();
+            plotter4.region(2).plot(aPlots[x + 23][y + 5]);
+        }
+    }
+
+    @Override
+    public void redraw() {
+//        aSigmaPlot.reset();
+//        aMeanPlot.reset();
+//        tSigmaPlot.reset();
+//        tMeanPlot.reset();
+        aTOutSigmaPlot.reset();
+        aTOutMeanPlot.reset();
+        tTOutSigmaPlot.reset();
+        tTOutMeanPlot.reset();
+        for (int x = -23; x <= 23; x++) { // slot
+            for (int y = -5; y <= 5; y++) { // crate   
+                if (aPlots[x + 23][y + 5].entries() > 10) {
+                    aSigmaPlot.fill(aPlots[x + 23][y + 5].rms());
+                    aMeanPlot.fill(aPlots[x + 23][y + 5].mean());
+                }
+                if (tPlots[x + 23][y + 5].entries() > 10) {
+                    tSigmaPlot.fill(tPlots[x + 23][y + 5].rms());
+                    tMeanPlot.fill(tPlots[x + 23][y + 5].mean());
+                }
+            
+                //Outliers in time -- threshold is nr of sigma/rms from the mean
+                
+                if (tPlots[x + 23][y + 5].rms() > (tSigmaPlot.mean()+tSigmaPlot.rms()*tTOutNSigmaThr)  && tPlots[x + 23][y + 5].entries() > 10) {
+                    tTOutSigmaPlot.fill(x,y,tPlots[x + 23][y + 5].rms());
+                    tTOutMeanPlot.fill(x,y,tPlots[x + 23][y + 5].mean());
+                    
+                    aTOutSigmaPlot.fill(x,y,aPlots[x + 23][y + 5].rms());
+                    aTOutMeanPlot.fill(x,y,aPlots[x + 23][y + 5].mean());
+                
+                }
+            
+            }
+        }
+        //printOutliers();
+    }
+
+    @Override
+    public void setEventRefreshRate(int eventRefreshRate) {
+        this.eventRefreshRate = eventRefreshRate;
+    }
+}
CVSspam 0.2.12


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