Skip to content

Commit

Permalink
move all to event files
Browse files Browse the repository at this point in the history
  • Loading branch information
baltzell committed Jan 21, 2025
1 parent f55accb commit 841537b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;
Expand All @@ -15,19 +16,36 @@
public class TestEvent {

public static void main(String args[]) {
//writeDCSector1ElectronEvent();
getDCSector1ElectronEvent(0).show();
write();
//getDCSector1ElectronEvent(0).show();
}

public static void writeDCSector1ElectronEvent(String path) {
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);
HipoDataEvent e = getDCSector1ElectronEvent(writer.getSchemaFactory());
writer.addEvent(e.getHipoEvent());
writer.addEvent(e);
}
}
}

public static HipoDataEvent getDCSector1ElectronEvent(int event) {
HipoReader reader = new HipoReader();
Expand Down Expand Up @@ -299,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);
Expand Down
Binary file added etc/data/test/cvt.hipo
Binary file not shown.
Binary file added etc/data/test/ecal.hipo
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jlab.analysis.math.ClasMath;

import org.jlab.clas.swimtools.MagFieldsEngine;
import org.jlab.detector.base.DetectorType;
import org.jlab.logging.DefaultLogger;
import org.jlab.utils.CLASResources;

Expand All @@ -35,7 +36,7 @@ public void testDCReconstruction() {
e.printStackTrace();
}

DataEvent testEvent = TestEvent.getDCSector1ElectronEvent(0);
DataEvent testEvent = TestEvent.get(DetectorType.DC);

MagFieldsEngine enf = new MagFieldsEngine();
enf.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 841537b

Please sign in to comment.