diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/physics/TestEvent.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/physics/TestEvent.java index 5414ab64a5..de2a465184 100644 --- a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/physics/TestEvent.java +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/physics/TestEvent.java @@ -1,9 +1,13 @@ package org.jlab.analysis.physics; +import org.jlab.detector.base.DetectorType; import org.jlab.io.hipo.HipoDataEvent; import org.jlab.jnp.hipo4.data.Bank; import org.jlab.jnp.hipo4.data.Event; import org.jlab.jnp.hipo4.data.SchemaFactory; +import org.jlab.jnp.hipo4.io.HipoReader; +import org.jlab.jnp.hipo4.io.HipoWriterSorted; +import org.jlab.utils.CLASResources; /** * @@ -11,11 +15,48 @@ */ public class TestEvent { + public static void main(String args[]) { + write(); + //getDCSector1ElectronEvent(0).show(); + } + + public static HipoDataEvent get(DetectorType t) { + HipoReader reader = new HipoReader(); + String dir = CLASResources.getResourcePath("etc/data/test"); + String stub = t.getName().toLowerCase(); + reader.open(String.format("%s/%s.hipo",dir,stub)); + Event e = new Event(); + reader.getEvent(e, 0); + return new HipoDataEvent(e,reader.getSchemaFactory()); + } + + private static void write() { + SchemaFactory sf = new SchemaFactory(); + sf.initFromDirectory(CLASResources.getResourcePath("etc/bankdefs/hipo4")); + write( "dc.hipo",getDCSector1ElectronEvent(sf).getHipoEvent()); + write( "cvt.hipo",getCVTTestEvent(sf).getHipoEvent()); + write( "ecal.hipo",getECSector1PhotonEvent(sf).getHipoEvent()); + } + + private static void write(String path, Event e) { + try (HipoWriterSorted writer = new HipoWriterSorted()) { + writer.setCompressionType(2); + writer.getSchemaFactory().initFromDirectory(CLASResources.getResourcePath("etc/bankdefs/hipo4")); + writer.open(path); + writer.addEvent(e); + } + } + + public static HipoDataEvent getDCSector1ElectronEvent(int event) { + HipoReader reader = new HipoReader(); + reader.open(CLASResources.getResourcePath("etc/data/test/dc.hipo")); + Event e = new Event(); + reader.getEvent(e, event); + return new HipoDataEvent(e,reader.getSchemaFactory()); + } public static HipoDataEvent getDCSector1ElectronEvent(SchemaFactory schemaFactory) { - Event testEvent = new Event(); - - + Event testEvent = new Event(); // this event is based on a gemc event with // one generated electron with p=2.5, th=25, ph=0 @@ -276,7 +317,6 @@ public static HipoDataEvent getCVTTestEvent(SchemaFactory schemaFactory) { return hipoEvent; } - public static HipoDataEvent getECSector1PhotonEvent(SchemaFactory schemaFactory) { Event testEvent = new Event(); Bank config = new Bank(schemaFactory.getSchema("RUN::config"), 1); diff --git a/etc/data/test/cvt.hipo b/etc/data/test/cvt.hipo new file mode 100644 index 0000000000..0d09ce7d14 Binary files /dev/null and b/etc/data/test/cvt.hipo differ diff --git a/etc/data/test/dc.hipo b/etc/data/test/dc.hipo new file mode 100644 index 0000000000..93de64c10d Binary files /dev/null and b/etc/data/test/dc.hipo differ diff --git a/etc/data/test/ecal.hipo b/etc/data/test/ecal.hipo new file mode 100644 index 0000000000..b0f09ae9fa Binary files /dev/null and b/etc/data/test/ecal.hipo differ diff --git a/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java b/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java index fc795f1d92..3ceee43152 100644 --- a/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java +++ b/reconstruction/cvt/src/test/java/org/jlab/rec/cvt/services/CVTReconstructionTest.java @@ -11,6 +11,7 @@ import org.jlab.analysis.physics.TestEvent; import org.jlab.analysis.math.ClasMath; import org.jlab.clas.swimtools.MagFieldsEngine; +import org.jlab.detector.base.DetectorType; import org.jlab.jnp.hipo4.data.SchemaFactory; import org.jlab.logging.DefaultLogger; import org.jlab.utils.CLASResources; @@ -42,7 +43,7 @@ public void testCVTReconstruction() { SchemaFactory schemaFactory = new SchemaFactory(); schemaFactory.initFromDirectory(dir); - DataEvent testEvent = TestEvent.getCVTTestEvent(schemaFactory); + DataEvent testEvent = TestEvent.get(DetectorType.CVT); MagFieldsEngine enf = new MagFieldsEngine(); enf.init(); diff --git a/reconstruction/dc/src/test/java/org/jlab/service/dc/DCReconstructionTest.java b/reconstruction/dc/src/test/java/org/jlab/service/dc/DCReconstructionTest.java index 0954c9cd3a..cfcf56a608 100644 --- a/reconstruction/dc/src/test/java/org/jlab/service/dc/DCReconstructionTest.java +++ b/reconstruction/dc/src/test/java/org/jlab/service/dc/DCReconstructionTest.java @@ -10,10 +10,9 @@ import org.jlab.analysis.math.ClasMath; import org.jlab.clas.swimtools.MagFieldsEngine; -import org.jlab.jnp.hipo4.data.SchemaFactory; +import org.jlab.detector.base.DetectorType; import org.jlab.logging.DefaultLogger; import org.jlab.utils.CLASResources; -import org.jlab.utils.system.ClasUtilsFile; /** * @@ -29,19 +28,15 @@ public void testDCReconstruction() { System.setProperty("CLAS12DIR", "../../"); String mapDir = CLASResources.getResourcePath("etc")+"/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields(mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat","Symm_solenoid_r601_phi1_z1201_13June2018.dat"); - } - catch (Exception e) { - e.printStackTrace(); - } - - String dir = ClasUtilsFile.getResourceDir("CLAS12DIR", "etc/bankdefs/hipo4"); - SchemaFactory schemaFactory = new SchemaFactory(); - schemaFactory.initFromDirectory(dir); + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat","Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } + catch (Exception e) { + e.printStackTrace(); + } - DataEvent testEvent = TestEvent.getDCSector1ElectronEvent(schemaFactory); + DataEvent testEvent = TestEvent.get(DetectorType.DC); MagFieldsEngine enf = new MagFieldsEngine(); enf.init(); @@ -72,7 +67,6 @@ public void testDCReconstruction() { if(testEvent.hasBank("TimeBasedTrkg::TBTracks")) { testEvent.getBank("TimeBasedTrkg::TBTracks").show(); } - assertEquals(testEvent.hasBank("TimeBasedTrkg::TBTracks"), true); assertEquals(testEvent.getBank("TimeBasedTrkg::TBTracks").rows(), 1); @@ -90,7 +84,6 @@ public void testDCReconstruction() { assertEquals(testEvent.getBank("TimeBasedTrkg::TBTracks").getFloat("Vtx0_z", 0) < 0.885, true); assertEquals(testEvent.getBank("TimeBasedTrkg::TBTracks").getFloat("Vtx0_z", 0) > -0.0753, true); - //Region 1 assertEquals(ClasMath.isWithinXPercent(155, testEvent.getBank("TimeBasedTrkg::TBCrosses").getFloat("x", 0), 4.02), true); assertEquals(testEvent.getBank("TimeBasedTrkg::TBCrosses").getFloat("y", 0 ) < 9.25, true); @@ -106,7 +99,6 @@ public void testDCReconstruction() { assertEquals(ClasMath.isWithinXPercent(127, testEvent.getBank("TimeBasedTrkg::TBCrosses").getFloat("x", 2), -11.0), true); assertEquals(testEvent.getBank("TimeBasedTrkg::TBCrosses").getFloat("y", 2 ) < 17.96, true); assertEquals(testEvent.getBank("TimeBasedTrkg::TBCrosses").getFloat("y", 2 ) > -23.66, true); - } diff --git a/reconstruction/eb/src/test/java/org/jlab/service/eb/EBReconstructionTest.java b/reconstruction/eb/src/test/java/org/jlab/service/eb/EBReconstructionTest.java index 44296527ce..31be0690c9 100644 --- a/reconstruction/eb/src/test/java/org/jlab/service/eb/EBReconstructionTest.java +++ b/reconstruction/eb/src/test/java/org/jlab/service/eb/EBReconstructionTest.java @@ -7,6 +7,7 @@ import org.jlab.analysis.math.ClasMath; import org.jlab.clas.swimtools.MagFieldsEngine; import cnuphys.magfield.MagneticFields; +import org.jlab.detector.base.DetectorType; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; @@ -116,7 +117,7 @@ public void testEBReconstruction() { SchemaFactory schemaFactory = new SchemaFactory(); schemaFactory.initFromDirectory(dir); - DataEvent photonEvent = TestEvent.getECSector1PhotonEvent(schemaFactory); + DataEvent photonEvent = TestEvent.get(DetectorType.ECAL); processAllEngines(photonEvent); assertEquals(photonEvent.hasBank("RECHB::Event"), true); assertEquals(photonEvent.hasBank("RECHB::Particle"), true); @@ -132,7 +133,7 @@ public void testEBReconstruction() { assertEquals(photonEvent.getBank("RECHB::Particle").getFloat("py", 0) < 0.15, true); assertEquals(ClasMath.isWithinXPercent(25.0, photonEvent.getBank("RECHB::Particle").getFloat("pz", 0), 2.266), true); - DataEvent electronEvent = TestEvent.getDCSector1ElectronEvent(schemaFactory); + DataEvent electronEvent = TestEvent.get(DetectorType.DC); processAllEngines(electronEvent); assertEquals(electronEvent.hasBank("REC::Event"), true); assertEquals(electronEvent.hasBank("REC::Particle"), true); diff --git a/reconstruction/ec/src/test/java/org/jlab/service/ec/ECReconstructionTest.java b/reconstruction/ec/src/test/java/org/jlab/service/ec/ECReconstructionTest.java index 9294001a21..dafea5922f 100644 --- a/reconstruction/ec/src/test/java/org/jlab/service/ec/ECReconstructionTest.java +++ b/reconstruction/ec/src/test/java/org/jlab/service/ec/ECReconstructionTest.java @@ -6,6 +6,7 @@ import org.jlab.io.base.DataEvent; import org.jlab.analysis.physics.TestEvent; +import org.jlab.detector.base.DetectorType; import org.jlab.jnp.hipo4.data.SchemaFactory; import org.jlab.logging.DefaultLogger; import org.jlab.utils.system.ClasUtilsFile; @@ -26,7 +27,7 @@ public void testECReconstruction() { SchemaFactory schemaFactory = new SchemaFactory(); schemaFactory.initFromDirectory(dir); - DataEvent testEvent = TestEvent.getECSector1PhotonEvent(schemaFactory); + DataEvent testEvent = TestEvent.get(DetectorType.ECAL); ECEngine engineEC = new ECEngine(); engineEC.init();