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  February 2015

HPS-SVN February 2015

Subject:

r2173 - in /java/trunk: ecal-recon/src/main/java/org/hps/recon/ecal/ monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/ steering-files/src/main/resources/org/hps/steering/users/baltzell/

From:

[log in to unmask]

Reply-To:

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

Date:

Sat, 21 Feb 2015 00:56:16 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (373 lines)

Author: [log in to unmask]
Date: Fri Feb 20 16:56:08 2015
New Revision: 2173

Log:
Adding pedestal funcionality.

Added:
    java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java
    java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalPedestalViewer.java
    java/trunk/steering-files/src/main/resources/org/hps/steering/users/baltzell/EcalPedestals.lcsim
Modified:
    java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalMonitoringUtilities.java

Added: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java
 =============================================================================
--- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java	(added)
+++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java	Fri Feb 20 16:56:08 2015
@@ -0,0 +1,198 @@
+package org.hps.recon.ecal;
+
+import hep.aida.IHistogram1D;
+
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.hps.conditions.database.TableConstants;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalConditions;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.GenericObject;
+import org.lcsim.event.LCRelation;
+import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ * Calculate pedestals from Mode-7 Data.
+ * 
+ * To be used online with org.hps.monitoring.ecal.plots.EcalPedestalViewer
+ * and ET-ring to create config files for DAQ and/or conditions DB.
+ * 
+ * When user clicks "Disconnect" in monitoring app (after confirming sufficient
+ * statistics), endOfData is called and config files will be written.  Copying
+ * files to proper location for DAQ must be done manually.
+ *gg
+ * TODO: Merge with EcalCalibrationDriver (which works on Mode-1).
+ * 
+ * @version $Id: EcalPedestalCalculator.java,v 0.1 2015/02/20 00:00:00
+ * @author <[log in to unmask]>
+ */
+public class EcalPedestalCalculator extends Driver {
+
+    private static final String rawCollectionName = "EcalReadoutHits";
+    private static final String extraDataRelationsName = "EcalReadoutExtraDataRelations";
+
+    private String histoNameFormat = "Ecal/Pedestals/Mode7/ped%3d";
+    
+    private String outputFilePrefix = "";
+    private static final String[] filenamesDAQ = { "fadc37.ped", "fadc39.ped" };
+    private static final String filenameDB = "EcalPedsForDB.txt";
+    
+    // The number of samples used by FADCs to report an event's pedestal.
+    private int nSamples = 4;
+    
+    private boolean writeFileForDB=true;
+    private boolean writeFileForDAQ=true;
+    
+    private EcalConditions ecalConditions = null;
+
+    AIDA aida = AIDA.defaultInstance();
+
+    private int nDetectorChanges = 0;
+
+    public EcalPedestalCalculator() {
+    }
+
+    public void setOutputFilePrefix(String prefix) {
+        outputFilePrefix = "_"+prefix;
+    }
+
+    @Override
+    protected void startOfData() {
+    }
+
+    @Override
+    public void endOfData() {
+        if (writeFileForDAQ) writeFileForDAQ();
+        if (writeFileForDB)  writeFileForDB();
+    }
+
+    @Override
+    public void detectorChanged(Detector detector) {
+
+        if (nDetectorChanges++ > 1) {
+            throw new RuntimeException("No Detector Change Allowed.");
+        }
+        ecalConditions = ConditionsManager.defaultInstance()
+                .getCachedConditions(EcalConditions.class,TableConstants.ECAL_CONDITIONS)
+                .getCachedData();
+
+        aida.tree().cd("/");
+        for (EcalChannel cc : ecalConditions.getChannelCollection()) {
+            aida.histogram1D(getHistoName(cc),181,19.5,200.5);
+        }
+
+    }
+
+    private String getHistoName(EcalChannel cc) {
+        return String.format(histoNameFormat,cc.getChannelId());
+    }
+
+    private void writeFileForDB() {
+        FileWriter wout = null;
+        try {
+            wout = new FileWriter(outputFilePrefix + filenameDB);
+            for (int cid=1; cid<=442; cid++) {
+                EcalChannel cc= findChannel(cid);
+                IHistogram1D hh = aida.histogram1D(getHistoName(cc));
+                wout.write(String.format("%3d %7.3f %7.3f\n",cid,
+                           hh.mean(),hh.rms()*Math.sqrt(nSamples)));
+            }
+        } catch (IOException ee) {
+            throw new RuntimeException("Error writing file.",ee);
+        } finally {
+            if (wout != null) {
+                try {
+                    wout.close();
+                } catch (IOException ee) {
+                    ee.printStackTrace();
+                }
+            }
+        }
+    }
+    private void writeFileForDAQ() {
+        FileWriter[] wout = { null, null };
+        try {
+            for (int crate = 1; crate <= 2; crate++) {
+                wout[crate - 1] = new FileWriter(outputFilePrefix + filenamesDAQ[crate - 1]);
+                for (int slot = 3; slot <= 20; slot++) {
+                    for (int chan = 0; chan < 16; chan++) {
+                        if (slot > 9 && slot < 14)
+                            continue;
+                        if (slot == 20 && chan > 12)
+                            continue;
+                        EcalChannel cc = findChannel(crate,slot,chan);
+                        IHistogram1D hh = aida.histogram1D(getHistoName(cc));
+                        wout[crate - 1].write(String.format("%2d %2d %7.3f %7.3f\n",slot,chan,
+                                hh.mean(),hh.rms()*Math.sqrt(nSamples)));
+                    }
+                }
+            }
+        } catch (IOException ee) {
+            throw new RuntimeException("Error writing file.",ee);
+        } finally {
+            if (wout[0] != null || wout[1] != null) {
+                try {
+                    if (wout[0] != null)
+                        wout[0].close();
+                    if (wout[1] != null)
+                        wout[1].close();
+                } catch (IOException ee) {
+                    ee.printStackTrace();
+                }
+            }
+        }
+    }
+
+    @Override
+    protected void process(EventHeader event) {
+        if (event.hasCollection(RawCalorimeterHit.class,rawCollectionName)) {
+            if (event.hasCollection(LCRelation.class,extraDataRelationsName)) {
+                for (LCRelation rel : event.get(LCRelation.class,extraDataRelationsName)) {
+                    RawCalorimeterHit hit = (RawCalorimeterHit) rel.getFrom();
+                    GenericObject extraData = (GenericObject) rel.getTo();
+                    fillHisto(event,hit,extraData);
+                }
+            }
+        }
+    }
+
+    private void fillHisto(EventHeader event, RawCalorimeterHit hit, GenericObject mode7data) {
+        final int min = ((HitExtraData.Mode7Data) mode7data).getAmplLow();
+        final int max = ((HitExtraData.Mode7Data) mode7data).getAmplHigh();
+        // ignore if pulse at beginning of window:
+        if (max <= 0) return;
+        EcalChannel cc = findChannel(hit);
+        if (cc == null) {
+            System.err.println("Hit doesn't correspond to ecalchannel.");
+            return;
+        }
+        aida.histogram1D(getHistoName(cc)).fill(min);
+    }
+
+    public EcalChannel findChannel(int channel_id) {
+        return ecalConditions.getChannelCollection().findChannel(channel_id);
+    }
+
+    public EcalChannel findChannel(RawCalorimeterHit hit) {
+        return ecalConditions.getChannelCollection().findGeometric(hit.getCellID());
+    }
+
+    public EcalChannel findChannel(int crate, int slot, int chan) {
+        for (EcalChannel cc : ecalConditions.getChannelCollection()) {
+            if (crate == cc.getCrate() && 
+                 slot == cc.getSlot()  && 
+                 chan == cc.getChannel()) {
+                return cc;
+            }
+        }
+        throw new RuntimeException(String.format(
+                "Could not find channel:  (crate,slot,channel)=(%d,%d,%d)",crate,slot,chan));
+    }
+
+}

Modified: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalMonitoringUtilities.java
 =============================================================================
--- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalMonitoringUtilities.java	(original)
+++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalMonitoringUtilities.java	Fri Feb 20 16:56:08 2015
@@ -5,9 +5,13 @@
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  * @author Andrea Celentano <[log in to unmask]>
+ * @author <[log in to unmask]>
  */
 public final class EcalMonitoringUtilities {
 
+    final static int XOFFSET = 23;
+    final static int YOFFSET = 5;
+    
     private EcalMonitoringUtilities() {        
     }
     
@@ -32,4 +36,16 @@
         }
         return ret;
     }
+    
+    public static int getChannelIdFromRowColumn(int row, int col)
+    {
+        int ix = col + XOFFSET + (col>0 ? -1 : 0);
+        int iy = row + YOFFSET + (row>0 ? -1 : 0);
+        iy = YOFFSET*2 - iy - 1;
+        int cid = ix + 2*XOFFSET*iy + 1;
+        if      (row== 1 && col>-10) cid -= 9;
+        else if (row==-1 && col<-10) cid -= 9;
+        else if (row < 0)            cid -= 18;
+        return cid; 
+    }
 }

Added: java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalPedestalViewer.java
 =============================================================================
--- java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalPedestalViewer.java	(added)
+++ java/trunk/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalPedestalViewer.java	Fri Feb 20 16:56:08 2015
@@ -0,0 +1,87 @@
+package org.hps.monitoring.ecal.plots;
+
+import hep.aida.IHistogram1D;
+import hep.aida.IPlotter;
+import hep.aida.IPlotterFactory;
+import hep.aida.IPlotterStyle;
+
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+
+import org.hps.monitoring.ecal.eventdisplay.ui.PDataEventViewer;
+import org.hps.monitoring.ecal.eventdisplay.ui.PEventViewer;
+import org.hps.monitoring.ecal.eventdisplay.ui.Viewer;
+import org.hps.monitoring.ecal.eventdisplay.util.CrystalEvent;
+import org.hps.monitoring.ecal.eventdisplay.util.CrystalListener;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+/*
+ * Display histograms created by org.hps.recon.ecal.EcalPedestalCalculator
+ * 
+ * When user clicks on crystal in Kyle's event viewer, the corresponding channel's
+ * pedestal histogram is drawn.
+ * 
+ * @version $Id: EcalPedestalViewer.java,v 0.1 2015/02/20 00:00:00
+ * @author <[log in to unmask]>
+ */
+public class EcalPedestalViewer extends Driver implements CrystalListener, ActionListener {
+
+    // this has to match the one in EcalPedstalCalculator:
+    private String histoNameFormat = "Ecal/Pedestals/Mode7/ped%3d";
+    
+	private AIDA aida = AIDA.defaultInstance();	
+	private IPlotter plotter;
+	private IPlotterFactory plotterFactory;
+	private IPlotterStyle pstyle;
+	private PEventViewer viewer;
+
+	@Override
+	public void detectorChanged(Detector detector) {
+		plotterFactory = aida.analysisFactory().createPlotterFactory("ECal Peds");
+		plotter = plotterFactory.create("ECal Peds");
+		plotter.createRegions(1,1);
+		plotter.show();
+	}
+	
+	@Override
+	public void startOfData() {
+		File config = new File("ecal-mapping-config.csv");
+		if(config.exists() && config.canRead()) {
+			try { viewer = new PDataEventViewer(config.getAbsolutePath()); }
+			catch (IOException e) { viewer = new PEventViewer(); }
+		} else { viewer = new PEventViewer(); }
+		viewer.addCrystalListener(this);
+		viewer.setVisible(true);
+	}
+	
+	@Override
+	public void actionPerformed(ActionEvent ae) { }
+	
+	@Override
+	public void crystalActivated(CrystalEvent e) { }
+	
+	@Override
+	public void crystalDeactivated(CrystalEvent e) { }
+
+	@Override
+	public void crystalClicked(CrystalEvent e) {
+		aida.tree().cd("/");
+		Point ecalPoint = Viewer.toEcalPoint(e.getCrystalID());
+		if (ecalPoint.x == 0 || ecalPoint.y == 0) return;
+		if (EcalMonitoringUtilities.isInHole(ecalPoint.y,ecalPoint.x)) return;
+		final int cid=EcalMonitoringUtilities.getChannelIdFromRowColumn(ecalPoint.y,ecalPoint.x);
+	    IHistogram1D hist=aida.histogram1D(String.format(histoNameFormat,cid));
+	    if (hist==null) {
+	        System.err.println("Running the Driver?");
+	    } else {
+	        plotter.region(0).clear();
+	        plotter.region(0).plot(hist,pstyle);
+	    }
+	}
+	
+	
+}

Added: java/trunk/steering-files/src/main/resources/org/hps/steering/users/baltzell/EcalPedestals.lcsim
 =============================================================================
--- java/trunk/steering-files/src/main/resources/org/hps/steering/users/baltzell/EcalPedestals.lcsim	(added)
+++ java/trunk/steering-files/src/main/resources/org/hps/steering/users/baltzell/EcalPedestals.lcsim	Fri Feb 20 16:56:08 2015
@@ -0,0 +1,20 @@
+<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="EcalPedestalCalculator"/>
+        <driver name="EcalRunningPedestal"/>
+        <driver name="EcalPedestalViewer"/>
+        <driver name="CleanupDriver" />
+    </execute>
+    <drivers>
+        <driver name="EcalPedestalCalculator" type="org.hps.recon.ecal.EcalPedestalCalculator">
+        </driver>
+        <driver name="EcalRunningPedestal" type="org.hps.recon.ecal.ECalRunningPedestalDriver">
+            <minLookbackEvents>10</minLookbackEvents>
+            <maxLookbackEvents>50</maxLookbackEvents>
+        </driver>
+        <driver name="EcalPedestalViewer" type="org.hps.monitoring.ecal.plots.EcalPedestalViewer">
+        </driver>
+        <driver name="CleanupDriver" type="org.lcsim.recon.tracking.digitization.sisim.config.ReadoutCleanupDriver" />
+    </drivers>
+</lcsim>

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