|
| 1 | +package org.jlab.rec.cvt.banks; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import org.junit.BeforeClass; |
| 5 | +import org.junit.Test; |
| 6 | +import static org.junit.Assert.*; |
| 7 | + |
| 8 | +import org.jlab.detector.banks.RawBank.OrderType; |
| 9 | +import org.jlab.detector.base.DetectorType; |
| 10 | +import org.jlab.io.base.DataBank; |
| 11 | +import org.jlab.io.base.DataEvent; |
| 12 | +import org.jlab.io.hipo.HipoDataSync; |
| 13 | +import org.jlab.rec.cvt.bmt.BMTType; |
| 14 | +import org.jlab.rec.cvt.cluster.Cluster; |
| 15 | +import org.jlab.rec.cvt.hit.Hit; |
| 16 | +import org.jlab.rec.cvt.services.CVTEngine; |
| 17 | +import org.jlab.utils.groups.IndexedTable; |
| 18 | + |
| 19 | +public class BSTHitReaderTest { |
| 20 | + |
| 21 | + private static final int NOMINAL = OrderType.NOMINAL.getTypeId(); |
| 22 | + private static final int BACKGROUND = OrderType.BGADDED_NOMINAL.getTypeId(); |
| 23 | + private static final int REMOVED = OrderType.BGREMOVED.getTypeId(); |
| 24 | + private static HipoDataSync events; |
| 25 | + |
| 26 | + @BeforeClass |
| 27 | + public static void initializeGeometry() { |
| 28 | + assertNotNull("Source libexec/env.sh before running the test", System.getenv("CLAS12DIR")); |
| 29 | + CVTEngine engine = new CVTEngine(); |
| 30 | + assertTrue(engine.init()); |
| 31 | + engine.detectorChanged(11); |
| 32 | + events = new HipoDataSync(); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void leadingOrderFilteredRowPreservesOriginalIds() { |
| 37 | + assertHitReferences(new int[]{REMOVED, NOMINAL, BACKGROUND}, |
| 38 | + new int[]{2, 3, 4}, new int[]{2, 3}); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void interiorOrderFilteredRowPreservesOriginalIds() { |
| 43 | + assertHitReferences(new int[]{NOMINAL, REMOVED, NOMINAL}, |
| 44 | + new int[]{2, 3, 4}, new int[]{1, 3}); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void unfilteredRowsKeepTheirIds() { |
| 49 | + assertHitReferences(new int[]{NOMINAL, NOMINAL, BACKGROUND}, |
| 50 | + new int[]{2, 3, 4}, new int[]{1, 2, 3}); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void timingRowDoesNotRenumberTheFollowingHit() { |
| 55 | + assertHitReferences(new int[]{NOMINAL, NOMINAL}, |
| 56 | + new int[]{-1, 3}, new int[]{2}); |
| 57 | + } |
| 58 | + |
| 59 | + private static void assertHitReferences(int[] orders, int[] adcs, int[] expectedRawRows) { |
| 60 | + DataEvent event = events.createEvent(); |
| 61 | + DataBank raw = event.createBank("BST::adc", orders.length); |
| 62 | + IndexedTable status = new IndexedTable(3, "status/I"); |
| 63 | + for (int row = 0; row < orders.length; row++) { |
| 64 | + int strip = adcs[row] < 0 ? 1 : 10 + row; |
| 65 | + raw.setByte("sector", row, (byte) 1); |
| 66 | + raw.setByte("layer", row, (byte) 1); |
| 67 | + raw.setShort("component", row, (short) strip); |
| 68 | + raw.setInt("ADC", row, adcs[row]); |
| 69 | + raw.setByte("order", row, (byte) orders[row]); |
| 70 | + raw.setFloat("time", row, 10 + row); |
| 71 | + status.addEntry(1, 1, strip); |
| 72 | + status.setIntValue(0, "status", 1, 1, strip); |
| 73 | + } |
| 74 | + event.appendBank(raw); |
| 75 | + IndexedTable adcStatus = new IndexedTable(3, "adcstatus/I"); |
| 76 | + adcStatus.addEntry(0, 0, 0); |
| 77 | + adcStatus.setIntValue(0, "adcstatus", 0, 0, 0); |
| 78 | + |
| 79 | + HitReader reader = new HitReader(); |
| 80 | + reader.fetch_SVTHits(event, -1, -1, status, adcStatus); |
| 81 | + List<Hit> hits = reader.getSVTHits(); |
| 82 | + assertEquals(expectedRawRows.length, hits.size()); |
| 83 | + |
| 84 | + // Assemble one synthetic cluster to check the bank writer's references. |
| 85 | + Cluster cluster = new Cluster(DetectorType.BST, BMTType.UNDEFINED, 1, 1, 1); |
| 86 | + cluster.addAll(hits); |
| 87 | + cluster.calc_CentroidParams(); |
| 88 | + DataBank hitBank = RecoBankWriter.fillSVTHitBank(event, hits, "BST::Hits"); |
| 89 | + DataBank clusterBank = RecoBankWriter.fillSVTClusterBank(event, |
| 90 | + List.of(cluster), "BST::Clusters"); |
| 91 | + assertNotNull(hitBank); |
| 92 | + assertNotNull(clusterBank); |
| 93 | + assertEquals(expectedRawRows.length, hitBank.rows()); |
| 94 | + assertEquals(1, clusterBank.rows()); |
| 95 | + assertEquals(expectedRawRows.length, clusterBank.getShort("size", 0)); |
| 96 | + for (int index = 0; index < expectedRawRows.length; index++) { |
| 97 | + int rawRow = expectedRawRows[index] - 1; |
| 98 | + // The physical strip independently identifies its original ADC row. |
| 99 | + assertEquals(raw.getShort("component", rawRow), hits.get(index).getStrip().getStrip()); |
| 100 | + assertEquals("Hit ID must reference the original ADC row", |
| 101 | + expectedRawRows[index], hits.get(index).getId()); |
| 102 | + assertEquals(expectedRawRows[index], hitBank.getShort("ID", index)); |
| 103 | + assertEquals("Cluster reference must use the original ADC row ID", |
| 104 | + expectedRawRows[index], clusterBank.getShort("Hit" + (index + 1) + "_ID", 0)); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments