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

HPS-SVN August 2015

Subject:

r3477 - in /java/trunk/users: pom.xml src/main/java/org/hps/users/jeremym/LuminosityAnalysisDriver.java src/main/java/org/hps/users/jeremym/LuminosityDriver.java src/test/java/org/hps/users/jeremym/LuminosityAnalysisDriverTest.java

From:

[log in to unmask]

Reply-To:

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

Date:

Tue, 1 Sep 2015 00:42:28 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (246 lines)

Author: [log in to unmask]
Date: Mon Aug 31 17:42:25 2015
New Revision: 3477

Log:
Add sample Drivers for calculating integrated luminosity for a job.

Added:
    java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityAnalysisDriver.java
    java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityDriver.java
    java/trunk/users/src/test/java/org/hps/users/jeremym/LuminosityAnalysisDriverTest.java
Modified:
    java/trunk/users/pom.xml

Modified: java/trunk/users/pom.xml
 =============================================================================
--- java/trunk/users/pom.xml	(original)
+++ java/trunk/users/pom.xml	Mon Aug 31 17:42:25 2015
@@ -14,6 +14,19 @@
         <connection>scm:svn:svn://svn.freehep.org/hps/java/trunk/users/</connection>
         <developerConnection>scm:svn:svn://svn.freehep.org/hps/java/trunk/users/</developerConnection>
     </scm>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>org/hps/users/**</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
     <dependencies>
         <dependency>
             <groupId>org.hps</groupId>

Added: java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityAnalysisDriver.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityAnalysisDriver.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityAnalysisDriver.java	Mon Aug 31 17:42:25 2015
@@ -0,0 +1,46 @@
+package org.hps.users.jeremym;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+/**
+ * Parent <code>Driver</code> showing how to use the {@link LuminosityDriver}.
+ *
+ * @author Jeremy McCormick, SLAC
+ */
+public class LuminosityAnalysisDriver extends Driver {
+
+    /**
+     * Reference to the <code>Driver</code> which will perform the calculation.
+     */
+    private final LuminosityDriver lumiDriver;
+
+    /**
+     * Class constructor.
+     * <p>
+     * Adds an instance of this <code>Driver</code>.
+     */
+    public LuminosityAnalysisDriver() {
+        lumiDriver = new LuminosityDriver();
+        this.add(lumiDriver);
+    }
+
+    /**
+     * End of job hook.
+     */
+    @Override
+    public void endOfData() {
+        super.endOfData();
+        System.out.println("luminosity for job was " + lumiDriver.getLuminosity() + "C");
+    }
+
+    /**
+     * Event processing hook.
+     *
+     * @param eventHeader the event to process
+     */
+    @Override
+    public void process(final EventHeader eventHeader) {
+        super.process(eventHeader);
+    }
+}

Added: java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityDriver.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityDriver.java	(added)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/LuminosityDriver.java	Mon Aug 31 17:42:25 2015
@@ -0,0 +1,115 @@
+package org.hps.users.jeremym;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hps.record.epics.EpicsData;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+
+/**
+ * Calculate integrated luminosity using EPICS data.
+ * <p>
+ * This does not calculate luminosity for time period before there is any EPICS data processed in the job, and the time
+ * period between the last EPICS event and the end of the job is also ignored.
+ * <p>
+ * This <code>Driver</code> would be easiest to use as a child of an analysis <code>Driver</code> so that the calculated
+ * luminosity can be easily retrieved in the parent's {@link org.lcsim.util.Driver#endOfData()} method.
+ *
+ * @author Jeremy McCormick, SLAC
+ * @see LuminosityAnalysisDriver
+ */
+public class LuminosityDriver extends Driver {
+
+    /**
+     * EPICS variable to use for current measurement.
+     */
+    private static final String EPICS_VARIABLE = "scaler_calc1";
+
+    /**
+     * Calculate the luminosity in coulomb given a list of EPICS data.
+     *
+     * @param epicsData the list of EPICS data
+     * @return the calculated luminosity
+     */
+    private static double calculateLuminosity(final List<EpicsData> epicsDataList) {
+        if (epicsDataList.isEmpty()) {
+            throw new RuntimeException("The EPICS data list is empty.");
+        }
+        double integratedLuminosity = 0;
+        for (int i = 0; i < epicsDataList.size(); i++) {
+            if (i != epicsDataList.size() - 1) {
+
+                // Get a pair of EPICS records.
+                final EpicsData epicsDataStart = epicsDataList.get(i);
+                final EpicsData epicsDataEnd = epicsDataList.get(i + 1);
+
+                // Calculate elapsed time between the EPICS events.
+                int timeLength = epicsDataEnd.getEpicsHeader().getTimestamp()
+                        - epicsDataStart.getEpicsHeader().getTimestamp();
+
+                if (timeLength == 0) {
+                    // Force at least 1 second time resolution.
+                    timeLength = 1;
+                }
+
+                // Get average current over the time period.
+                final double averageCurrent = (epicsDataStart.getValue(EPICS_VARIABLE) + epicsDataEnd
+                        .getValue(EPICS_VARIABLE)) / 2.;
+
+                // Add the current for the time period to the integrated luminosity total.
+                integratedLuminosity += timeLength * averageCurrent;
+            }
+        }
+        // Convert from nano coulomb to coulomb.
+        integratedLuminosity *= 10e-9;
+        return integratedLuminosity;
+    }
+
+    /**
+     * The list of EPICS data accumulated during the job.
+     */
+    private final List<EpicsData> epicsDataList = new ArrayList<EpicsData>();
+
+    /**
+     * The final measurement of integrated
+     */
+    private double luminosity;
+
+    /**
+     * End of data hook which performs luminosity calculation.
+     */
+    @Override
+    public void endOfData() {
+        if (epicsDataList.isEmpty()) {
+            throw new RuntimeException("The EPICS data list is empty.");
+        }
+        luminosity = calculateLuminosity(this.epicsDataList);
+    }
+
+    /**
+     * Get the calculated luminosity for the job.
+     *
+     * @return the calculated luminosity for the job
+     */
+    public double getLuminosity() {
+        return luminosity;
+    }
+
+    /**
+     * Process an event.
+     *
+     * @param eventHeader the event header
+     */
+    @Override
+    public void process(final EventHeader eventHeader) {
+        final EpicsData epicsData = EpicsData.read(eventHeader);
+        if (epicsData != null) {
+            if (epicsData.hasKey(EPICS_VARIABLE)) {
+                System.out.println("adding EPICS data with timestamp " + epicsData.getEpicsHeader().getTimestamp()
+                        + " and Faraday cup current " + epicsData.getValue(EPICS_VARIABLE));
+                epicsDataList.add(epicsData);
+            }
+        }
+    }
+}

Added: java/trunk/users/src/test/java/org/hps/users/jeremym/LuminosityAnalysisDriverTest.java
 =============================================================================
--- java/trunk/users/src/test/java/org/hps/users/jeremym/LuminosityAnalysisDriverTest.java	(added)
+++ java/trunk/users/src/test/java/org/hps/users/jeremym/LuminosityAnalysisDriverTest.java	Mon Aug 31 17:42:25 2015
@@ -0,0 +1,28 @@
+package org.hps.users.jeremym;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.lcsim.util.loop.LCSimLoop;
+
+/**
+ * Basic test of {@link LuminosityAnalysisDriver}.
+ *
+ * @author Jeremy McCormick, SLAC
+ */
+public class LuminosityAnalysisDriverTest extends TestCase {
+
+    /**
+     * Run the test.
+     *
+     * @throws Exception if any error occurs
+     */
+    public void testLuminosityAnalysisDriver() throws Exception {
+        final LCSimLoop loop = new LCSimLoop();
+        loop.add(new LuminosityAnalysisDriver());
+        loop.setLCIORecordSource(new File("/u1/test/hps/recon/hps_005772_data_only.slcio"));
+        loop.loop(-1);
+    }
+
+}

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