Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Added CVT unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
naharrison committed Jul 19, 2017
1 parent 0d6e1ff commit a768d2d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
7 changes: 7 additions & 0 deletions validation/unit-tests/run-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ if [ $? != 0 ] ; then echo "RandomEventGenerator compilation failure" ; exit 1 ;
javac -cp $classPath src/dc/DCReconstructionTest.java
if [ $? != 0 ] ; then echo "DCReconstructionTest compilation failure" ; exit 1 ; fi

javac -cp $classPath src/cvt/CVTReconstructionTest.java
if [ $? != 0 ] ; then echo "CVTReconstructionTest compilation failure" ; exit 1 ; fi

javac -cp $classPath src/ec/ECReconstructionTest.java
if [ $? != 0 ] ; then echo "ECReconstructionTest compilation failure" ; exit 1 ; fi

Expand All @@ -25,6 +28,10 @@ if [ $? != 0 ] ; then echo "ECReconstructionTest compilation failure" ; exit 1 ;
java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath org.junit.runner.JUnitCore dc.DCReconstructionTest
if [ $? != 0 ] ; then echo "dc unit test failure" ; exit 1 ; else echo "dc passed unit tests" ; fi

# run cvt junit tests
java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath org.junit.runner.JUnitCore cvt.CVTReconstructionTest
if [ $? != 0 ] ; then echo "cvt unit test failure" ; exit 1 ; else echo "cvt passed unit tests" ; fi

# run ec junit tests
java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath org.junit.runner.JUnitCore ec.ECReconstructionTest
if [ $? != 0 ] ; then echo "ec unit test failure" ; exit 1 ; else echo "ec passed unit tests" ; fi
Expand Down
53 changes: 53 additions & 0 deletions validation/unit-tests/src/cvt/CVTReconstructionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cvt;

import org.junit.Test;
import static org.junit.Assert.*;

import events.TestEvent;

import org.jlab.io.base.DataEvent;
import org.jlab.rec.cvt.services.CVTReconstruction;
import org.jlab.service.eb.EBHBEngine;
import org.jlab.service.eb.EBTBEngine;

/**
*
* @author naharrison
*/
public class CVTReconstructionTest {

@Test
public void testCVTReconstruction() {

DataEvent testEvent = TestEvent.getCVTTestEvent();

CVTReconstruction CVTengine = new CVTReconstruction();
CVTengine.init();
CVTengine.processDataEvent(testEvent);

EBHBEngine EBHBengine = new EBHBEngine();
EBHBengine.init();
EBHBengine.processDataEvent(testEvent);

EBTBEngine EBTBengine = new EBTBEngine();
EBTBengine.init();
EBTBengine.processDataEvent(testEvent);

assertEquals(testEvent.hasBank("REC::Particle"), true);
assertEquals(testEvent.getBank("REC::Particle").rows(), 1);
assertEquals(testEvent.getBank("REC::Particle").getByte("charge", 0), 1);
assertEquals(isWithinXPercent(10.0, testEvent.getBank("REC::Particle").getFloat("px", 0), -0.375), true);
assertEquals(isWithinXPercent(10.0, testEvent.getBank("REC::Particle").getFloat("py", 0), 0.483), true);
assertEquals(isWithinXPercent(10.0, testEvent.getBank("REC::Particle").getFloat("pz", 0), 0.674), true);
assertEquals(isWithinXPercent(30.0, testEvent.getBank("REC::Particle").getFloat("vz", 0), -13.9), true);
}


public static boolean isWithinXPercent(double X, double val, double standard) {
if(standard >= 0 && val > (1.0 - (X/100.0))*standard && val < (1.0 + (X/100.0))*standard) return true;
else if(standard < 0 && val < (1.0 - (X/100.0))*standard && val > (1.0 + (X/100.0))*standard) return true;
return false;
}


}
77 changes: 77 additions & 0 deletions validation/unit-tests/src/events/TestEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,83 @@ public static HipoDataEvent getDCSector1ElectronEvent() {
}


public static HipoDataEvent getCVTTestEvent() {
HipoDataSync writer = new HipoDataSync();
HipoDataEvent testEvent = (HipoDataEvent) writer.createEvent();
DataBank config = testEvent.createBank("RUN::config", 1);
DataBank SVTadc = testEvent.createBank("SVT::adc", 7);

// this event is based on a gemc (4a.1.1 aka 4a.2.0) event with
// torus = -1.0 , solenoid = 1.0
// <option name="BEAM_P" value="proton, 0.91*GeV, 42.2*deg, 127.8*deg"/>
// <option name="SPREAD_P" value="0*GeV, 0*deg, 0*deg"/>
// <option name="BEAM_V" value="(0, 0, -1.39)cm"/>
// <option name="SPREAD_V" value="(0.0, 0.0)cm"/>

config.setInt("run", 0, (int) 11);
config.setInt("event", 0, (int) 1);
config.setInt("trigger", 0, (int) 0);
config.setLong("timestamp", 0, (long) 0);
config.setByte("type", 0, (byte) 0);
config.setByte("mode", 0, (byte) 0);
config.setFloat("torus", 0, (float) -1.0);
config.setFloat("solenoid", 0, (float) 1.0);
config.setFloat("rf", 0, (float) 0.0);
config.setFloat("startTime", 0, (float) 0.0);

for(int i = 0; i < 7; i++) {
SVTadc.setByte("order", i, (byte) 0);
SVTadc.setShort("ped", i, (short) 0);
SVTadc.setLong("timestamp", i, (long) 0);
}

SVTadc.setByte("sector", 0, (byte) 5);
SVTadc.setByte("sector", 1, (byte) 5);
SVTadc.setByte("sector", 2, (byte) 7);
SVTadc.setByte("sector", 3, (byte) 7);
SVTadc.setByte("sector", 4, (byte) 7);
SVTadc.setByte("sector", 5, (byte) 9);
SVTadc.setByte("sector", 6, (byte) 9);

SVTadc.setByte("layer", 0, (byte) 1);
SVTadc.setByte("layer", 1, (byte) 2);
SVTadc.setByte("layer", 2, (byte) 3);
SVTadc.setByte("layer", 3, (byte) 4);
SVTadc.setByte("layer", 4, (byte) 4);
SVTadc.setByte("layer", 5, (byte) 5);
SVTadc.setByte("layer", 6, (byte) 6);

SVTadc.setShort("component", 0, (short) 109);
SVTadc.setShort("component", 1, (short) 77);
SVTadc.setShort("component", 2, (short) 52);
SVTadc.setShort("component", 3, (short) 137);
SVTadc.setShort("component", 4, (short) 138);
SVTadc.setShort("component", 5, (short) 1);
SVTadc.setShort("component", 6, (short) 190);

SVTadc.setInt("ADC", 0, (int) 7);
SVTadc.setInt("ADC", 1, (int) 7);
SVTadc.setInt("ADC", 2, (int) 7);
SVTadc.setInt("ADC", 3, (int) 5);
SVTadc.setInt("ADC", 4, (int) 5);
SVTadc.setInt("ADC", 5, (int) 7);
SVTadc.setInt("ADC", 6, (int) 7);

SVTadc.setFloat("time", 0, (float) 97.0);
SVTadc.setFloat("time", 1, (float) 201.0);
SVTadc.setFloat("time", 2, (float) 78.0);
SVTadc.setFloat("time", 3, (float) 102.0);
SVTadc.setFloat("time", 4, (float) 81.0);
SVTadc.setFloat("time", 5, (float) 91.0);
SVTadc.setFloat("time", 6, (float) 205.0);

testEvent.appendBank(config);
testEvent.appendBank(SVTadc);

return testEvent;
}


public static HipoDataEvent getECSector1PhotonEvent() {
HipoDataSync writer = new HipoDataSync();
HipoDataEvent testEvent = (HipoDataEvent) writer.createEvent();
Expand Down

0 comments on commit a768d2d

Please sign in to comment.