From 94a699c9f23f9cda997823544a7ce2bf67cf825f Mon Sep 17 00:00:00 2001 From: Silvia Niccolai Date: Wed, 10 Jun 2026 11:51:55 -0400 Subject: [PATCH 1/7] Here we (Nilanga and Silvia) include all the recent comment to previous pull requests (PR921 and PR504), as well as the new directory structure and code naming scheme requested by Raffaella --- .../org/jlab/detector/base/DetectorType.java | 3 +- .../geant4/v2/recoil/tof/RTOFConstants.java | 51 +++ .../v2/recoil/tof/RTOFGeant4Factory.java | 144 +++++++ .../RtrkConstants.java} | 6 +- .../RtrkGeant4Factory.java} | 88 ++-- .../RtrkStripFactory.java} | 50 +-- etc/bankdefs/hipo4/rtof.json | 91 ++++ etc/bankdefs/hipo4/{recoil.json => rtrk.json} | 24 +- .../service/recoil/tof/ClusterFinder.java | 173 ++++++++ .../jlab/service/recoil/tof/HitFinder.java | 119 +++++ .../jlab/service/recoil/tof/Parameters.java | 26 ++ .../jlab/service/recoil/tof/RTOFCluster.java | 254 +++++++++++ .../org/jlab/service/recoil/tof/RTOFHit.java | 149 +++++++ .../jlab/service/recoil/tof/RTOFRawHit.java | 407 ++++++++++++++++++ .../service/recoil/tof/RecoBankWriter.java | 128 ++++++ .../RtrkCluster.java} | 38 +- .../RtrkConstants.java} | 4 +- .../{RecoilCross.java => trk/RtrkCross.java} | 27 +- .../RtrkEngine.java} | 62 +-- .../{RecoilStrip.java => trk/RtrkStrip.java} | 38 +- 20 files changed, 1713 insertions(+), 169 deletions(-) create mode 100644 common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java create mode 100644 common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java rename common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/{RecoilConstants.java => trk/RtrkConstants.java} (97%) rename common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/{RecoilGeant4Factory.java => trk/RtrkGeant4Factory.java} (71%) rename common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/{RecoilStripFactory.java => trk/RtrkStripFactory.java} (90%) create mode 100644 etc/bankdefs/hipo4/rtof.json rename etc/bankdefs/hipo4/{recoil.json => rtrk.json} (77%) create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/ClusterFinder.java create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/{RecoilCluster.java => trk/RtrkCluster.java} (84%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/{RecoilConstants.java => trk/RtrkConstants.java} (93%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/{RecoilCross.java => trk/RtrkCross.java} (72%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/{RecoilEngine.java => trk/RtrkEngine.java} (82%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/{RecoilStrip.java => trk/RtrkStrip.java} (81%) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java index 4ee7c44cf8..a07cbc2452 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java @@ -33,7 +33,8 @@ public enum DetectorType { URWT (23, "URWT"), AHDC (24, "AHDC"), ATOF (25, "ATOF"), - RECOIL (26, "RECOIL"), + RTRK (26, "RTRK"), + RTOF (27, "RTOF"), MUCAL (28, "MUCAL"), MUVT (29, "MUVT"), MURT (30, "MURT"), diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java new file mode 100644 index 0000000000..3ec69f6283 --- /dev/null +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java @@ -0,0 +1,51 @@ +package org.jlab.detector.geant4.v2.recoil.tof; + + +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.prim.Point3D; + + +public class RTOFConstants { + + public final static int NSECTORS = 2; //number of sectors + public final static int NROWS = 5; //number of rows of bars in a sector + public final static int NCOLUMNS = 63; //number of columns of bars in a sector + + public final static double LONG_BAR_LENGTH = 27.5; // cm + public final static double SHORT_BAR_LENGTH = 4; // cm + + public final static double BAR_WIDTH = 1; // cm + public final static double BAR_THICKNESS = 0.5; // cm + + public final static double HORIZONTAL_STARTING_ANGLE = 40.; + public final static double HORIZONTAL_OPENING_ANGLE = 29.; + public final static double RADIUS = 122.; // cm + + public final static double WIDTH = NCOLUMNS * BAR_WIDTH; + public final static double LENGTH = (NROWS-1) * LONG_BAR_LENGTH + SHORT_BAR_LENGTH; + public final static double THICKNESS = 0.5; // cm + + + public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) + { + + load(cp ); + return cp; + } + + /** + * Reads all the necessary constants from CCDB into static variables. + * Please use a DatabaseConstantProvider to access CCDB and load the following tables: + * @param cp a ConstantProvider that has loaded the necessary tables + */ + + public static synchronized void load( DatabaseConstantProvider cp ) + { + //WIDTH = NCOLUMNS * BAR_WIDTH; + //LENGTH = (NROWS-1) * LONG_BAR_LENGTH + SHORT_BAR_LENGTH; + //THICKNESS = 0.5; // cm + } + +} + + diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java new file mode 100644 index 0000000000..e1d238ee29 --- /dev/null +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java @@ -0,0 +1,144 @@ +package org.jlab.detector.geant4.v2.recoil.tof; + +import eu.mihosoft.vrl.v3d.Vector3d; +import org.jlab.detector.geant4.v2.Geant4Factory; +import org.jlab.detector.volume.G4World; +import org.jlab.detector.volume.G4Box; +import org.jlab.detector.volume.Geant4Basic; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; + +/** + * Generate GEANT4 volume for the RECOIL TOF detector + * + * @author Nilanga Wickramaarachchi + */ +public final class RTOFGeant4Factory extends Geant4Factory { + + private int nSectors = RTOFConstants.NSECTORS; + private int nRows = RTOFConstants.NROWS; + private int nCols = RTOFConstants.NCOLUMNS; + + public RTOFGeant4Factory( DatabaseConstantProvider cp) { + RTOFConstants.connect(cp ); + this.init(cp); + } + + public void init(DatabaseConstantProvider cp) { + + motherVolume = new G4World("root"); + + for (int isector = 0; isector < nSectors; isector++) { + Geant4Basic sectorVolume = createSector(isector, nRows, nCols); + + sectorVolume.setName("recoil_tof_sector" + (isector + 1)); + sectorVolume.setMother(motherVolume); + } + } + + + public Vector3d getCenterCoordinate(int isector) + { + int is=isector; + Vector3d vCenter = new Vector3d(0, 0, 0); + + vCenter.x = (-1+is*2)*(RTOFConstants.RADIUS)*Math.sin(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + vCenter.y = 0; + vCenter.z =RTOFConstants.RADIUS*Math.cos(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + return vCenter; + } + + + + public Geant4Basic createSector(int isector, int nRows, int nCols ) { + + double hlx = RTOFConstants.WIDTH/2+1; + double hly = RTOFConstants.LENGTH/2+1; + double hlz = RTOFConstants.THICKNESS/2+1; + + Vector3d vCenter = this.getCenterCoordinate(isector); + + Geant4Basic sectorVolume = new G4Box("recoil_tof_sector" + (isector + 1), hlx, hly, hlz); + + if(isector==0) sectorVolume.rotate("yxz",Math.toRadians((RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)),0,0); + if(isector==1) sectorVolume.rotate("yxz",Math.toRadians(-(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)),0,0); + sectorVolume.translate(vCenter.x, vCenter.y, vCenter.z); + sectorVolume.setId(isector + 1, 0, 0); + + // Bars construction + for (int row = 0; row < nRows; row++) { + for (int col = 0; col < nCols; col++) { + + Geant4Basic barVolume = this.createBar(isector, row, col); + + barVolume.setName("bar_sector" + (isector + 1) + "_row" + (row + 1) + "_column" + (col + 1)); + + barVolume.setMother(sectorVolume); + + barVolume.setId(isector + 1, row +1, col+1, 0); + } + } + + return sectorVolume; + } + + + public Geant4Basic createBar(int iSector, int iRow, int iCol) { + + int nCols = RTOFConstants.NCOLUMNS; + + double barDX = RTOFConstants.BAR_WIDTH/2; + double barDY; + + if (iRow == (nRows - 1) / 2) barDY = RTOFConstants.SHORT_BAR_LENGTH/2; + else barDY = RTOFConstants.LONG_BAR_LENGTH/2; + + double barDZ = RTOFConstants.BAR_THICKNESS/2; + + Geant4Basic barVolume = new G4Box("bar_sector" + (iSector + 1) + "_row" + (iRow + 1) + "_column" + (iCol + 1), barDX, barDY, barDZ); + + // Constants for positioning + double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position + double x_spacing = RTOFConstants.BAR_WIDTH; + double x_start = -(RTOFConstants.WIDTH - x_spacing)/2; // starting X position + double dy_long = RTOFConstants.LONG_BAR_LENGTH; + double dy_short = RTOFConstants.SHORT_BAR_LENGTH; + + //Position calculation + double z_pos = 0; + double x_pos = x_start + (iCol * x_spacing); + + double y_pos; + if(iRow < (nRows - 1) / 2) + { + y_pos = y_start + (iRow * dy_long); + } + else if (iRow == (nRows - 1) / 2) // middle row + { + y_pos = 0; + } + else + { + y_pos = y_start + (iRow -1) * dy_long + dy_short; + } + + barVolume.setPosition(x_pos, y_pos, z_pos); + + return barVolume; + } + + + + + public static void main(String[] args) { + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + + RTOFConstants.connect(cp); + + RTOFGeant4Factory factory = new RTOFGeant4Factory(cp); + + factory.getAllVolumes().forEach(volume -> { + System.out.println(volume.gemcString()); + }); + + } +} diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java similarity index 97% rename from common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilConstants.java rename to common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java index 805407434e..6e0a78e98f 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java @@ -1,13 +1,13 @@ -package org.jlab.detector.geant4.v2.recoil; +package org.jlab.detector.geant4.v2.recoil.trk; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Point3D; -public class RecoilConstants { +public class RtrkConstants { - private final static String CCDBPATH = "/geometry/recoil/"; + private final static String CCDBPATH = "/geometry/recoil/trk/"; public final static int NMAXREGIONS = 3; //max number of regions public final static int NREGIONS = 3; //number of regions diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilGeant4Factory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java similarity index 71% rename from common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilGeant4Factory.java rename to common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java index f97035e1ae..7d42c037fb 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilGeant4Factory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java @@ -1,4 +1,4 @@ -package org.jlab.detector.geant4.v2.recoil; +package org.jlab.detector.geant4.v2.recoil.trk; import eu.mihosoft.vrl.v3d.Vector3d; import org.jlab.detector.geant4.v2.Geant4Factory; @@ -16,30 +16,30 @@ import org.jlab.geometry.prim.Straight; /** - * Generate GEANT4 volume for the RECOIL detector + * Generate GEANT4 volume for the RECOIL tracker * * @author bondi, niccolai */ -public final class RecoilGeant4Factory extends Geant4Factory { +public final class RtrkGeant4Factory extends Geant4Factory { - private int nRegions = RecoilConstants.NREGIONS; - private int nSectors = RecoilConstants.NSECTORS; - private int nChambers = RecoilConstants.NCHAMBERS; + private int nRegions = RtrkConstants.NREGIONS; + private int nSectors = RtrkConstants.NSECTORS; + private int nChambers = RtrkConstants.NCHAMBERS; /** * Create the URWELL full geometry * @param cp * @param nRegions */ - public RecoilGeant4Factory( DatabaseConstantProvider cp, int nRegions) { - RecoilConstants.connect(cp ); + public RtrkGeant4Factory( DatabaseConstantProvider cp, int nRegions) { + RtrkConstants.connect(cp ); this.init(cp, nRegions); } public void init(DatabaseConstantProvider cp, int regions ) { motherVolume = new G4World("root"); - nRegions = Math.min(RecoilConstants.NMAXREGIONS, regions); + nRegions = Math.min(RtrkConstants.NMAXREGIONS, regions); for (int iregion = 0; iregion (volume.getName().contains(volName))) .findAny() @@ -295,9 +295,9 @@ public Geant4Basic getSectorVolume(int region, int sector) { public static void main(String[] args) { DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - RecoilConstants.connect(cp); + RtrkConstants.connect(cp); - RecoilGeant4Factory factory = new RecoilGeant4Factory(cp, 1); + RtrkGeant4Factory factory = new RtrkGeant4Factory(cp, 1); factory.getAllVolumes().forEach(volume -> { System.out.println(volume.gemcString()); diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilStripFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java similarity index 90% rename from common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilStripFactory.java rename to common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java index 9a4144f2a6..9158336800 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/RecoilStripFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java @@ -1,4 +1,4 @@ -package org.jlab.detector.geant4.v2.recoil; +package org.jlab.detector.geant4.v2.recoil.trk; import eu.mihosoft.vrl.v3d.Vector3d; import java.util.List; @@ -18,9 +18,9 @@ * * @author bondi, niccolai */ -public final class RecoilStripFactory { +public final class RtrkStripFactory { - private RecoilGeant4Factory factory; + private RtrkGeant4Factory factory; private IndexedList globalStrips = new IndexedList(3); private IndexedList localStrips = new IndexedList(3); private IndexedList planeStrips = new IndexedList(3); @@ -29,16 +29,16 @@ public final class RecoilStripFactory { private int nChambers; private int nLayers; - public RecoilStripFactory() { + public RtrkStripFactory() { } /** * Create the strip factory based on constants from CCDB. - * Currently constants are defined in the RecoilConstants class. + * Currently constants are defined in the RtrkConstants class. * They will be moved to CCDB when finalized). * @param cp database provide */ - public RecoilStripFactory(DatabaseConstantProvider cp) { + public RtrkStripFactory(DatabaseConstantProvider cp) { this.init(cp); } @@ -52,12 +52,12 @@ public void init(DatabaseConstantProvider cp) { /** * Create the strip factory based on constants from CCDB. - * Currently constants are defined in the URWellConstants class. + * Currently constants are defined in the RtrkConstants class. * They will be moved to CCDB when finalized). * @param cp database provide * @param regions */ - public RecoilStripFactory(DatabaseConstantProvider cp, int regions) { + public RtrkStripFactory(DatabaseConstantProvider cp, int regions) { this.init(cp, regions); } @@ -67,11 +67,11 @@ public RecoilStripFactory(DatabaseConstantProvider cp, int regions) { * @param regions */ public void init(DatabaseConstantProvider cp, int regions) { - factory = new RecoilGeant4Factory(cp, regions); - nRegions = Math.min(RecoilConstants.NMAXREGIONS, regions); - nSectors = RecoilConstants.NSECTORS; - nChambers = RecoilConstants.NCHAMBERS; - nLayers = RecoilConstants.NLAYERS; + factory = new RtrkGeant4Factory(cp, regions); + nRegions = Math.min(RtrkConstants.NMAXREGIONS, regions); + nSectors = RtrkConstants.NSECTORS; + nChambers = RtrkConstants.NCHAMBERS; + nLayers = RtrkConstants.NLAYERS; this.fillStripLists(); // this.fillPlaneLists(); } @@ -114,8 +114,8 @@ public int getNStripChamber(int ichamber, int regions) { * * number of strip in AB** */ - int nAB = (int) (2 * xHalf / RecoilConstants.PITCH); - int nAC = (int) (2 * yHalf / RecoilConstants.PITCH); + int nAB = (int) (2 * xHalf / RtrkConstants.PITCH); + int nAC = (int) (2 * yHalf / RtrkConstants.PITCH); int nStrips = nAB + nAC; @@ -190,9 +190,9 @@ private Line3d createStrip(int sector, int region, int layer, int strip) { DY = -yHalf; } // ID of the strip - int nS = (int) (DY / RecoilConstants.PITCH); + int nS = (int) (DY / RtrkConstants.PITCH); int nCStrip = nS + (cStrip - 1); - double c = nCStrip * RecoilConstants.PITCH; + double c = nCStrip * RtrkConstants.PITCH; // Take 2 points in the strip straight line. They needs to define Line object //u strips @@ -307,9 +307,9 @@ private void fillStripLists() { if ((layer) % 2 != 0) { //u strip DY = -yHalf; } - int nS = (int) (DY / RecoilConstants.PITCH); + int nS = (int) (DY / RtrkConstants.PITCH); int nCStrip = nS + (cStrip - 1); - double c = nCStrip * RecoilConstants.PITCH; + double c = nCStrip * RtrkConstants.PITCH; if (((layer) % 2 == 0 && c>-xHalf && c-yHalf && c-xHalf && c-yHalf && c + * Uses found hits information. Creates a {@link RTOFCluster} matching them. + *

+ * + * @author pilleux, Nilanga Wickramaarachchi + */ +public class ClusterFinder { + + /** + * list of clusters. + */ + private ArrayList clusters; + + /** + * Sets the list of clusters. + * + * @param clusters a {@link ArrayList} of {@link RTOFCluster}. + * + */ + public void setClusters(ArrayList clusters) { + this.clusters = clusters; + } + + /** + * Gets the list of clusters. + * + * @return a {@link ArrayList} of {@link RTOFCluster}. + * + */ + public ArrayList getClusters() { + return clusters; + } + + + /** + * Cluster hits around a given hit, based on the time and geometric + * proximity. + * + * Hits are compared based on their y difference, which + * is distance in cm and time difference. + * + * If the hit satisfies all conditions, it is marked as clustered and added + * to the cluster hit list. + * + * + * @param The type of the hit objects, which must extend + * {@link RTOFRawHit}. This allows the method to work with different types of + * hits that are subclasses of {@link RTOFRawHit} (e.g., {@link RTOFHit}). + * @param i The index from which hits are read in the list to compare + * against the current hit. + * @param hits The list of hits to be clustered, can be any subclass of + * {@link RTOFRawHit}. + * @param this_hit The hit currently being considered for clustering. + * @param sigma_y The threshold for the y-distance [cm] between the hits. + * @param sigma_t The threshold for the time difference [ns] between the + * hits. + * @param cluster_id The ID of the cluster being formed. + * @param this_cluster_hits The list that will store the clustered hits. + * This list can accept hits of type RTOFRawHit or RTOFHit. Clustered hits are + * added to this list. + * + */ + public void clusterHits(int i, ArrayList hits, RTOFRawHit this_hit, Number sigma_y, double sigma_t, int cluster_id, ArrayList this_cluster_hits) { + // Loop through less energetic clusters + for (int j = i + 1; j < hits.size(); j++) { + T other_hit = hits.get(j); + // Skip already clustered hits + if (other_hit.getIsInACluster()) { + continue; + } + // Check the distance between the hits + double delta_T = Math.abs(this_hit.getTime() - other_hit.getTime()); + //The y distance is a distance in cm + Boolean condition_y; + double delta_Y = Math.abs(this_hit.getY() - other_hit.getY()); + condition_y = (delta_Y <= sigma_y.doubleValue()); + + //If hit is within limits, it is clustered + if (condition_y) { + if (delta_T < sigma_t) { + other_hit.setIsInACluster(true); + other_hit.setAssociatedClusterIndex(cluster_id); + this_cluster_hits.add(other_hit); + } + } + } + } + + + /** + * Builds clusters in the {@link DateEvent} using hits found and stored in a + * {@link HitFinder}. + * + * @param hitfinder the {@link HitFinder} containing the hits that were + * found + * + * @param sigma_y the tolerance for clustering in y [cm] + * + * @param sigma_t the tolerance for clustering in time [ns] + * + */ + public void makeClusters(HitFinder hitfinder, double sigma_y, double sigma_t, DataEvent event) { + + //A list of clusters is built for each event + clusters.clear(); + int cluster_id = 1; + + //Getting the list of hits, they must have been ordered by energy already + ArrayList rtof_hits = hitfinder.getRTOFHits(); + + //Loop through all bar hits + for (int i_bar = 0; i_bar < rtof_hits.size(); i_bar++) { + RTOFHit this_rtof_hit = rtof_hits.get(i_bar); + //Skip hits that have already been clustered + if (this_rtof_hit.getIsInACluster()) { + continue; + } + + ArrayList this_cluster_rtof_hits = new ArrayList<>(); + this_rtof_hit.setIsInACluster(true); + this_rtof_hit.setAssociatedClusterIndex(cluster_id); + this_cluster_rtof_hits.add(this_rtof_hit); + + //Matching bar hits in clusters + clusterHits(i_bar, rtof_hits, this_rtof_hit, sigma_y, sigma_t, cluster_id, this_cluster_rtof_hits); + + RTOFCluster cluster = new RTOFCluster(this_cluster_rtof_hits, event); + clusters.add(cluster); + cluster_id++; + } + } + + /** + * Builds clusters in the {@link DataEvent} using hits found and stored in a + * {@link HitFinder}. + * + * @param event the {@link DataEvent} containing the clusters to be built + * + * @param hitfinder the {@link HitFinder} containing the hits that were + * found + * + */ + public void makeClusters(DataEvent event, HitFinder hitfinder) { + makeClusters(hitfinder, + Parameters.SIGMA_Y_CLUSTERING, + Parameters.SIGMA_T_CLUSTERING, event); + } + + /** + * Default constructor that initializes the list clusters as new empty list. + */ + public ClusterFinder() { + clusters = new ArrayList<>(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } +} diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java new file mode 100644 index 0000000000..87b8971264 --- /dev/null +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java @@ -0,0 +1,119 @@ +package org.jlab.rec.recoil.tof; + +import java.util.ArrayList; +import java.util.Collections; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; + +/** + * The {@code HitFinder} class finds hits in the recoil tof. + * + *

+ * Uses recoil tof tdc bank information + * + * Creates a {@link ArrayList} of {@link RTOFHit} for rtof hits read. + * + *

+ * + * @author pilleux, Nilanga Wickramaarachchi + */ +public class HitFinder { + + /** + * list of rtof hits + */ + private ArrayList rtofHits; + + /** + * Default constructor that initializes the list of hits as new empty lists. + */ + public HitFinder() { + this.rtofHits = new ArrayList<>(); + } + + // Getter and Setter for rtofHits + public ArrayList getRTOFHits() { + return rtofHits; + } + + public void setRTOFHits(ArrayList rtof_hits) { + this.rtofHits = rtof_hits; + } + + /** + * + * @param event the {@link DataEvent} containing hits. + * + */ + public void findHits(DataEvent event) { + //For each event a list of rtof hits is filled + this.rtofHits.clear(); + //They are read from the RTOF TDC bank + DataBank bank = event.getBank("RTOF::tdc"); + int nt = bank.rows(); // number of hits + //Hits in the bar downstream and upstream will be matched + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); + + //Looping through all hits + for (int i = 0; i < nt; i++) { + //Getting their properties + int sector = bank.getByte("sector", i); + int layer = bank.getByte("layer", i); + int component = bank.getByte("component", i); + int order = bank.getShort("order", i); + int tdc = bank.getShort("TDC", i); + int tot = bank.getShort("ToT", i); + + //Building a Hit + RTOFRawHit hit = new RTOFRawHit(sector, layer, component, order, tdc, tot); + if (hit.getEnergy() < 0.01) { + continue; //energy threshold + } + + //Sorting the hits into upstream and downstream bar hits + //Lists are built for up/down bar to match them after + if (null == hit.getType()) { + System.out.print("Undefined hit type \n"); + } else { + switch (hit.getType()) { + case "bar up" -> + hit_up.add(hit); + case "bar down" -> + hit_down.add(hit); + default -> + System.out.print("Undefined hit type \n"); + } + } + }//End loop through all hits + + //Starting loop through up hits in the bar + for (int i_up = 0; i_up < hit_up.size(); i_up++) { + RTOFRawHit this_hit_up = hit_up.get(i_up); + int countMatches = 0; + //Starting loop through down hits in the bar + for (int i_down = 0; i_down < hit_down.size(); i_down++) { + RTOFRawHit this_hit_down = hit_down.get(i_down); + //Matching the hits: if same bar and different order, they make up a rtof hit + if (this_hit_up.matchBar(this_hit_down)) { + if (countMatches > 0) { + //If the up hit was already involved in a match, do not make an additionnal match + //Chosing to ignore double matches for now because it happened for <1% of events in cosmic runs + continue; + } + RTOFHit this_rtof_hit = new RTOFHit(this_hit_down, this_hit_up); + this.rtofHits.add(this_rtof_hit); + countMatches++; + } + } + } + //Once all has been listed, hits are sorted by energy + Collections.sort(this.rtofHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } +} diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java new file mode 100644 index 0000000000..cb396207ba --- /dev/null +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java @@ -0,0 +1,26 @@ +package org.jlab.rec.recoil.tof; +import org.jlab.detector.geant4.v2.recoil.tof.RTOFConstants; + +/** + * + * @author npilleux, Nilanga Wickramaarachchi + */ +public class Parameters { + + public static final double VEFF = 20.0;//cm/ns + public static final double TDC2TIME = 0.015625;//ns per channel bin + public static final double ATT_L = 160.0;//cm + public static final double TOT2ENERGY = 1.956 * 0.5 /1000;//to MeV + + //public static double SIGMA_Y_TRACK_MATCHING_BAR = 20.0;//in cm + public static double SIGMA_Y_CLUSTERING = 4.0;//in cm + public static double SIGMA_T_CLUSTERING = 100;// in ns + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + } + +} diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java new file mode 100644 index 0000000000..68dd4cd2fe --- /dev/null +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java @@ -0,0 +1,254 @@ +package org.jlab.rec.recoil.tof; + +import java.util.ArrayList; +import org.jlab.geom.prim.Line3D; +import org.jlab.geom.prim.Point3D; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.recoil.tof.Parameters; +import org.jlab.rec.recoil.tof.RTOFRawHit; +import org.jlab.rec.recoil.tof.RTOFHit; + +/** + * The {@code RTOFCluster} represents clusters in the recoil tof + * + *

+ * Create clusters and compute their basic properties from the hits composing + * them. + *

+ * + * @author pilleux, Nilanga Wickramaarachchi + */ +public class RTOFCluster { + + /** + * list of hits in the bars. + */ + ArrayList rtofHits; + /** + * cluster properties:position [cm], time [ns], energy[MeV], + * type of the maximum hit (to set resolutions) and index and sector of the maximum hit. + */ + double x, y, z, time, energy; + String typeMaxHit; + int indexMaxHit, sectorMaxHit; + + public ArrayList getRTOFHits() { + return rtofHits; + } + + public void setRTOFHits(ArrayList rtof_hits) { + this.rtofHits = rtof_hits; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public double getZ() { + return z; + } + + public void setZ(double z) { + this.z = z; + } + + public double getTime() { + return time; + } + + public void setTime(double time) { + this.time = time; + } + + public double getEnergy() { + return energy; + } + + public void setEnergy(double energy) { + this.energy = energy; + } + + + public String getTypeMaxHit() { + return typeMaxHit; + } + + public void setTypeMaxHit(String typeMaxHit) { + this.typeMaxHit = typeMaxHit; + } + + public int getIndexMaxHit() { + return indexMaxHit; + } + + public void setIndexMaxHit(int indexMaxHit) { + this.indexMaxHit = indexMaxHit; + } + + public int getSectorMaxHit() { + return sectorMaxHit; + } + + public void setSectorMaxHit(int sectorMaxHit) { + this.sectorMaxHit = sectorMaxHit; + } + + + /** + * Compute the cluster properties. + * + * Cluster coordinates and time are defined as the coordinates and time of + * the max energy hit. + * + * TO DO: Test other choices for the definitions. + * + */ + public final void computeClusterProperties() { + this.energy = 0; + double max_energy = -1; + RTOFRawHit max_energy_hit = new RTOFRawHit(); + + for (int i_bar = 0; i_bar < this.rtofHits.size(); i_bar++) { + RTOFHit this_rtof_hit = this.rtofHits.get(i_bar); + double this_energy = this_rtof_hit.getEnergy(); + this.energy += this_energy; + if (this_energy > max_energy) { + max_energy_hit = this_rtof_hit; + max_energy = this_energy; + } + } + + this.time = max_energy_hit.getTime(); + this.x = max_energy_hit.getX(); + this.y = max_energy_hit.getY(); + this.z = max_energy_hit.getZ(); + this.typeMaxHit = max_energy_hit.getType(); + this.sectorMaxHit = max_energy_hit.getSector(); + } + + + /** + * Computes the energy deposited in the bars. + * + * @return the energy deposited in the bars. + * + */ + public double getEdepBar() { + double energy = 0; + for (int i = 0; i < this.rtofHits.size(); i++) { + RTOFRawHit this_hit = this.rtofHits.get(i); + energy += this_hit.getEnergy(); + } + return energy; + } + + /** + * Compute the cluster phi angle in radians. + * + * @return a double that is angle in radians + * + */ + public double getPhi() { + return Math.atan2(this.y, this.x); + } + + + /** + * Retrieve the hit with maximal energy in the cluster. It must have been + * computed previously. + * + * @return a RTOFRawHit that is the maximal energy hit in the cluster + * + */ + public final RTOFRawHit getMaxHit() { + if (this.typeMaxHit == null) { + System.out.print("You did not compute the maximal hit! \n"); + return null; + } + if (null == this.typeMaxHit) { + System.out.print("Unrecognized type! \n"); + return null; + } else { + switch (this.typeMaxHit) { + case "bar" -> { + return this.rtofHits.get(this.indexMaxHit); + } + default -> { + System.out.print("Unrecognized type! \n"); + return null; + } + } + } + } + + /** + * Computes the sum of TOT in the cluster. + * + * @return an int representing the summed TOT + * + */ + public int getTot() { + int tot = 0; + for (int i = 0; i < this.rtofHits.size(); i++) { + RTOFHit this_hit = this.rtofHits.get(i); + tot += this_hit.getTot(); + } + return tot; + } + + /** + * Returns the TDC of the maximal hit in the cluster. + * + * @return an int representing the TDC of the maximal hit. + * + */ + public int getTdc() { + return this.getMaxHit().getTdc(); + } + + /** + * Constructor that initializes the list of bar hits + * and computes the cluster properties. + * + * @param rtof_hits a {@link ArrayList} of {@link RTOFHit}. + * + */ + public RTOFCluster(ArrayList rtof_hits) { + this.rtofHits = rtof_hits; + this.computeClusterProperties(); + } + + /** + * Constructor that initializes the list of bar hits + * and computes the cluster properties. + * + * @param rtof_hits a {@link ArrayList} of {@link RTOFHit}. + * @param event a {@link DataEvent} with which track matching will be done. + * + */ + public RTOFCluster(ArrayList rtof_hits, DataEvent event) { + this.rtofHits = rtof_hits; + this.computeClusterProperties(); + } + + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } + +} diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java new file mode 100644 index 0000000000..fc15104086 --- /dev/null +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java @@ -0,0 +1,149 @@ +package org.jlab.rec.recoil.tof; + +import org.jlab.rec.recoil.tof.Parameters; +import org.jlab.detector.geant4.v2.recoil.tof.RTOFConstants; + +/** + * + * Represents a hit in the recoil tof bar. Extends class RTOFRawHit. Is further defined + * by the two hits upstream and downstream composing a full rtof hit. y position, + * time and energy are defined from the up/down hits. + * + * @author npilleux, Nilanga Wickramaarachchi + */ +public class RTOFHit extends RTOFRawHit { + + //A rtof hit is the combination of a downstream and upstream hits + private RTOFRawHit hitUp, hitDown; + + public RTOFRawHit getHitUp() { + return hitUp; + } + + public void setHitUp(RTOFRawHit hit_up) { + this.hitUp = hit_up; + } + + public RTOFRawHit getHitDown() { + return hitDown; + } + + public void setHitDown(RTOFRawHit hit_down) { + this.hitDown = hit_down; + } + + /** + * Computes rtof hit y local coordinate from up/downstream hit times. + * + */ + public final void computeLocalY() { + this.setLocalY(Parameters.VEFF/2. * (hitUp.getTime() - hitDown.getTime())); + } + + /** + * Computes rtof hit y coordinate in the global coordinate system. + * + */ + public final void computeGlobalY() { + double localY = this.getLocalY(); + + int nRows = RTOFConstants.NROWS; + double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position + double dy_long = RTOFConstants.LONG_BAR_LENGTH; + double dy_short = RTOFConstants.SHORT_BAR_LENGTH; + + double y_pos; // y coordinate of the center of bar wrt to the global coordinate system + if(hitUp.getRow()-1 < (nRows - 1)/2) + { + y_pos = y_start + ((hitUp.getRow()-1) * dy_long); + } + else if (hitUp.getRow()-1 == (nRows-1) / 2) // middle row + { + y_pos = 0; + } + else + { + y_pos = y_start + (hitUp.getRow()-2) * dy_long + dy_short; + } + + this.setY(y_pos + localY); + } + + + /** + * Computes rtof hit time from up/downstream hit times. + * The time is set as the time of the most energetic hit. + * It is corrected for propagation time. + * + */ + public final void computeTime() { + //We pick the most energetic signal as the timing signal + double time_at_sipm, distance_to_sipm; + if(this.hitDown.getEnergy() > this.hitUp.getEnergy()) { + time_at_sipm = this.hitDown.getTime(); + if(this.hitDown.getRow() == 3) distance_to_sipm = RTOFConstants.SHORT_BAR_LENGTH/2. - this.getLocalY(); + else distance_to_sipm = RTOFConstants.LONG_BAR_LENGTH/2. - this.getLocalY(); + } + else { + time_at_sipm = this.hitUp.getTime(); + if(this.hitUp.getRow() == 3) distance_to_sipm = RTOFConstants.SHORT_BAR_LENGTH/2. + this.getLocalY(); + else distance_to_sipm = RTOFConstants.LONG_BAR_LENGTH/2. + this.getLocalY(); + } + this.setTime(time_at_sipm - distance_to_sipm/Parameters.VEFF); + } + + /** + * Computes rtof hit energy from up/downstream hits. + * The energy of the up/downstream hits is corrected for attenuation now that y is known. + * The energy of the rtof hit is the sum of the energy of the up/downstream hits. + * + */ + public final void computeEnergy() { + this.computeLocalY(); + double distance_hit_to_sipm_up, distance_hit_to_sipm_down; + + if (hitUp.getRow() == 3) distance_hit_to_sipm_up = RTOFConstants.SHORT_BAR_LENGTH / 2. + this.getLocalY(); + else distance_hit_to_sipm_up = RTOFConstants.LONG_BAR_LENGTH / 2. + this.getLocalY(); + + if (hitDown.getRow() == 3) distance_hit_to_sipm_down = RTOFConstants.SHORT_BAR_LENGTH / 2. - this.getLocalY(); + else distance_hit_to_sipm_down = RTOFConstants.LONG_BAR_LENGTH / 2. - this.getLocalY(); + + double Edep_up = hitUp.getEnergy() * Math.exp(distance_hit_to_sipm_up / Parameters.ATT_L); + double Edep_down = hitDown.getEnergy() * Math.exp(distance_hit_to_sipm_down / Parameters.ATT_L); + this.setEnergy(Edep_up + Edep_down); + } + + public RTOFHit(RTOFRawHit hit_down, RTOFRawHit hit_up) { + boolean hits_match = hit_down.matchBar(hit_up); + if (!hits_match) { + throw new UnsupportedOperationException("Hits do not match \n"); + } + this.setType("bar"); + this.setOrder(2);//Fake order for bar hits + this.hitUp = hit_up; + this.hitDown = hit_down; + this.setSector(hit_up.getSector()); + this.setRow(hit_up.getRow()); + this.setColumn(hit_up.getColumn()); + this.setX(hit_up.getX()); + this.setZ(hit_up.getZ()); + this.computeLocalY(); + this.computeGlobalY(); + this.computeTime(); + this.computeEnergy(); + this.setTdc((hit_down.getTdc() + hit_up.getTdc())/2); + this.setTot((hit_down.getTot() + hit_up.getTot())); + } + + public RTOFHit() { + super(); + this.setType("bar"); + this.setOrder(2);//Fake order for rtof hits + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } +} diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java new file mode 100644 index 0000000000..ab88a1f023 --- /dev/null +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java @@ -0,0 +1,407 @@ +package org.jlab.rec.recoil.tof; + +import org.jlab.geom.base.*; +import org.jlab.geom.prim.Point3D; +import org.jlab.rec.recoil.tof.Parameters; +import org.jlab.detector.geant4.v2.recoil.tof.RTOFConstants; + +/** + * + * Represents a hit in the recoil tof. Stores info about the sector, row, column, + * order, TDC, ToT. Type is bar up/bar down/ bar. Stores whether + * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. + * + * @author npilleux, Nilanga Wickramaarachchi + */ +public class RTOFRawHit { + + private int sector, row, column, order; + private int tdc, tot; + private double time, energy, x, y, z, local_y; + private String type; + private boolean isInACluster; + private int associatedClusterIndex; + int idTDC; + + public int getSector() { + return sector; + } + + public void setSector(int sector) { + this.sector = sector; + } + + public int getRow() { + return row; + } + + public void setRow(int row) { + this.row = row; + } + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } + + public int getColumn() { + return column; + } + + public void setColumn(int column) { + this.column = column; + } + + public int getTdc() { + return tdc; + } + + public void setTdc(int tdc) { + this.tdc = tdc; + } + + public int getTot() { + return tot; + } + + public void setTot(int tot) { + this.tot = tot; + } + + public double getTime() { + return time; + } + + public void setTime(double time) { + this.time = time; + } + + public double getEnergy() { + return energy; + } + + public void setEnergy(double energy) { + this.energy = energy; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public double getLocalY() { + return local_y; + } + + public void setLocalY(double local_y) { + this.local_y = local_y; + } + + public double getZ() { + return z; + } + + public void setZ(double z) { + this.z = z; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public boolean getIsInACluster() { + return isInACluster; + } + + public void setIsInACluster(boolean is_in_a_cluster) { + this.isInACluster = is_in_a_cluster; + } + + public int getAssociatedClusterIndex() { + return associatedClusterIndex; + } + + public void setAssociatedClusterIndex(int index) { + this.associatedClusterIndex = index; + } + + public int getIdTDC() { + return idTDC; + } + + public void setIdTDC(int index) { + this.idTDC = index; + } + + + /** + * Assigns a type to the hit. + * + */ + public final String makeType() { + //Type of hit can be bar up, bar down or bar. + //Avoids testing components and order every time. + String itype = "undefined"; + if (this.order == 0) { + itype = "bar down"; + } else if (this.order == 1) { + itype = "bar up"; + } + this.type = itype; + return itype; + } + + /** + * Converts TDC to time (ns). Sets the hit time parameter to a raw time for + * up/down bar hits. + * + * @return 0 if the time was successfully set, or 1 if the hit type is + * unsupported. + */ + public final int convertTdcToTime() { + double tdc2time, veff, distance_to_sipm; + if (null == this.type) { + System.out.print("Null hit type, cannot convert tdc to time."); + return 1; + } else { + switch (this.type) { + case "bar up" -> { + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; + //The distance will be computed at barhit level when y information is available + distance_to_sipm = 0; + } + case "bar down" -> { + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; + //The distance will be computed at barhit level when y information is available + distance_to_sipm = 0; + } + case "bar" -> { + System.out.print("Bar hit type, cannot convert tdc to time."); + return 1; + } + default -> { + System.out.print("Undefined hit type, cannot convert tdc to time."); + return 1; + } + } + } + //Hit time. Will need implementation of offsets. + this.time = tdc2time * this.tdc - distance_to_sipm / veff; + return 0; + } + + /** + * Converts ToT to energy (MeV). Sets the hit energy parameter to a raw + * energy for up/down bar hits. + * + * @return 0 if the energy was successfully set, or 1 if the hit type is + * unsupported. + */ + public final int convertTotToEnergy() { + double tot2energy; + if (null == this.type) { + System.out.print("Null hit type, cannot convert tot to energy."); + return 1; + } else { + switch (this.type) { + case "bar up" -> { + tot2energy = Parameters.TOT2ENERGY; + //only half the information in the bar, + //the attenuation will be computed when the full hit is formed + this.energy = tot2energy * this.tot; + } + case "bar down" -> { + tot2energy = Parameters.TOT2ENERGY; + //only half the information in the bar, + //the attenuation will be computed when the full hit is formed + this.energy = tot2energy * this.tot; + } + case "bar" -> { + System.out.print("Bar hit type, cannot convert tot to energy."); + return 1; + } + default -> { + System.out.print("Undefined hit type, cannot convert tot to energy."); + return 1; + } + } + } + return 0; + } + + /** + * Calculates spatial coordinates (cm) for the hit based on row and column number of the bar within a sector. + * The row and column variables are obtained from the bank information. + * + * @return 0 if the coordinates were successfully set, or 1 if the hit type + * is undefined or unsupported. + */ + public final int calculateXYZ() { + + // Constants for positioning + int nRows = RTOFConstants.NROWS; + double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position + double x_spacing = RTOFConstants.BAR_WIDTH; + double x_start = -(RTOFConstants.WIDTH - x_spacing)/2; // starting X position + double dy_long = RTOFConstants.LONG_BAR_LENGTH; + double dy_short = RTOFConstants.SHORT_BAR_LENGTH; + + //Position calculation + double z_pos = 0; + double x_pos = x_start + ((this.column-1) * x_spacing); + + double y_pos; + if(this.row-1 < (nRows - 1) / 2) + { + y_pos = y_start + ((this.row-1) * dy_long); + } + else if (this.row-1 == (nRows - 1) / 2) // middle row + { + y_pos = 0; + } + else + { + y_pos = y_start + (this.row -2) * dy_long + dy_short; + } + + double[] localCoords = {x_pos, y_pos, z_pos}; + + // Calculate center coordinates for the sector + double sector_x = (-1+(this.sector-1)*2)*(RTOFConstants.RADIUS)*Math.sin(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + double sector_y = 0; + double sector_z = RTOFConstants.RADIUS*Math.cos(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + + // Global coordinates of the sector + double[] globalCoordsSector = {sector_x, sector_y, sector_z}; + + // Rotation angle in radians + double thetaY = 0; + + if(this.sector==1) thetaY = Math.toRadians(-(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + if(this.sector==2) thetaY = Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE); + + // Rotation matrix around the Y-axis + double[][] Ry = { + {Math.cos(thetaY), 0, Math.sin(thetaY)}, + {0, 1, 0}, + {-Math.sin(thetaY), 0, Math.cos(thetaY)} + }; + + // Rotate local coordinates + double[] rotatedCoords = new double[3]; + for (int i = 0; i < 3; i++) { + rotatedCoords[i] = Ry[i][0] * localCoords[0] + Ry[i][1] * localCoords[1] + Ry[i][2] * localCoords[2]; + } + + // Calculate global coordinates for the hit + double[] globalCoordsBar = new double[3]; + for (int i = 0; i < 3; i++) { + globalCoordsBar[i] = globalCoordsSector[i] + rotatedCoords[i]; + } + + + this.x = globalCoordsBar[0]; + this.y = globalCoordsBar[1]; + this.z = globalCoordsBar[2]; + return 0; + } + + /** + * Compares two RTOFRawHit objects to check if they match in the bar. + *
    + *
  • If the sector or row or column of the two hits do not match, the method + * returns {@code false}.
  • + *
  • If both hits are in the same SiPM (i.e., their order is the same), or + * have incorrect order, the method returns {@code false}.
  • + *
+ * If none of these conditions are violated, the method returns + * {@code true}, indicating the two hits match. + * + * @param hit2match The RTOFRawHit object to compare with the current instance. + * @return {@code true} if the hits match; {@code false} otherwise. + */ + public boolean matchBar(RTOFRawHit hit2match) { + if (this.getSector() != hit2match.getSector()) { + //Two hits in different sectors + return false; + } else if (this.getRow() != hit2match.getRow()) { + //Two hits in different rows + return false; + } else if (this.getColumn() != hit2match.getColumn()) { + //Two hits in different columns + return false; + } else if (this.getOrder() > 1 || hit2match.getOrder() > 1) { + //At least one hit has incorrect order + return false; + } else { + //Match if one is order 0 and the other is order 1 + return this.getOrder() != hit2match.getOrder(); + } + } + + /** + * Computes the azimuthal angle (phi) of the hit in rad. + * + * @return The azimuthal angle (phi) in radians, in the range [-π, π]. + */ + public double getPhi() { + return Math.atan2(this.y, this.x); + } + + /** + * Constructor for a hit in the recoil tof. Initializes the hit's sector, row, + * column, order, TDC, ToT. Sets the hit's initial state regarding + * clustering. Set up the hit's type, time, energy, and spatial coordinates. + * + * @param sector The sector of the detector where the hit occurred. + * @param row The row of the detector where the hit was detected. + * @param column The column within the row that registered the hit. + * @param order Order of the hit. + * @param tdc TDC value. + * @param tot ToT value. + * + */ + public RTOFRawHit(int sector, int row, int column, int order, int tdc, int tot) { + this.sector = sector; + this.row = row; + this.column = column; + this.order = order; + this.tdc = tdc; + this.tot = tot; + this.isInACluster = false; + + this.makeType(); + this.convertTdcToTime(); + this.convertTotToEnergy(); + this.calculateXYZ(); + } + + public RTOFRawHit() { + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } +} diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java new file mode 100644 index 0000000000..bf8b729ea1 --- /dev/null +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java @@ -0,0 +1,128 @@ +package org.jlab.rec.recoil.tof; + +import java.util.ArrayList; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.recoil.tof.RTOFCluster; +import org.jlab.rec.recoil.tof.RTOFRawHit; +import org.jlab.rec.recoil.tof.RTOFHit; + + +/** + * The {@code RecoBankWriter} writes the banks needed for the recoil tof + * reconstruction: hits and clusters info. + * + * @author pilleux, Nilanga Wickramaarachchi + */ +public class RecoBankWriter { + + /** + * Writes the bank of recoil tof hits. + * + * @param event the {@link DataEvent} in which to add the bank + * @param rtofHits the {@link ArrayList} of {@link RTOFHit} containing the rtof + * hits to be added to the bank + * + * @return {@link DataBank} the bank with all the hits read in the event. + * + */ + public static DataBank fillRTOFRawHitBank(DataEvent event, ArrayList rtofHits) { + + ArrayList hitList = new ArrayList<>(); + hitList.addAll(rtofHits); + + DataBank bank = event.createBank("RTOF::hits", hitList.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A RTOF::hits BANK!!!!!!"); + return null; + } + + for (int i = 0; i < hitList.size(); i++) { + bank.setShort("id", i, (short) (i + 1)); + bank.setShort("clusterid", i, (short) hitList.get(i).getAssociatedClusterIndex()); + bank.setByte("sector", i, (byte) hitList.get(i).getSector()); + bank.setByte("layer", i, (byte) hitList.get(i).getRow()); + bank.setByte("component", i, (byte) hitList.get(i).getColumn()); + bank.setFloat("time", i, (float) hitList.get(i).getTime()); + bank.setFloat("x", i, (float) (hitList.get(i).getX())); + bank.setFloat("y", i, (float) (hitList.get(i).getY())); + bank.setFloat("z", i, (float) (hitList.get(i).getZ())); + bank.setFloat("energy", i, (float) hitList.get(i).getEnergy()); + } + return bank; + } + + /** + * Writes the bank of rtof clusters. + * + * @param event the {@link DataEvent} in which to add the bank + * @param clusterList the {@link ArrayList} of {@link RTOFCluster} + * containing the clusters info to be added to the bank + * + * @return {@link DataBank} the bank with all the clusters built in the + * event. + * + */ + public static DataBank fillRTOFClusterBank(DataEvent event, ArrayList clusterList) { + + DataBank bank = event.createBank("RTOF::clusters", clusterList.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A RTOF::clusters BANK!!!!!!"); + return null; + } + + for (int i = 0; i < clusterList.size(); i++) { + bank.setShort("id", i, (short) (i + 1)); + bank.setShort("size", i, (short) clusterList.get(i).getRTOFHits().size()); + bank.setByte("sector", i, (byte) clusterList.get(i).getSectorMaxHit()); + bank.setFloat("time", i, (float) clusterList.get(i).getTime()); + bank.setFloat("x", i, (float) (clusterList.get(i).getX())); + bank.setFloat("y", i, (float) (clusterList.get(i).getY())); + bank.setFloat("z", i, (float) (clusterList.get(i).getZ())); + bank.setFloat("energy", i, (float) clusterList.get(i).getEnergy()); + } + return bank; + } + + + /** + * Appends the rtof banks to an event. + * + * @param event the {@link DataEvent} in which to append the banks + * @param clusterList the {@link ArrayList} of {@link RTOFCluster} + * containing the clusters info to be added to the bank + * @param rtofHits the {@link ArrayList} of {@link RTOFHit} containing the bar + * hits info to be added + * + * @return 0 if it worked, 1 if it failed + * + */ + public int appendRTOFBanks(DataEvent event, ArrayList rtofHits, ArrayList clusterList) { + + DataBank hitbank = this.fillRTOFRawHitBank(event, rtofHits); + if (hitbank != null) { + event.appendBank(hitbank); + } else { + return 1; + } + + DataBank clusterbank = fillRTOFClusterBank(event, clusterList); + if (clusterbank != null) { + event.appendBank(clusterbank); + } else { + return 1; + } + + return 0; + } + + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } + +} diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilCluster.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCluster.java similarity index 84% rename from reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilCluster.java rename to reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCluster.java index 66a6a5d914..f258307b88 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilCluster.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCluster.java @@ -1,4 +1,4 @@ -package org.jlab.service.recoil; +package org.jlab.service.recoil.trk; import java.util.ArrayList; import java.util.List; @@ -12,16 +12,16 @@ * * @author bondi, devita, niccolai */ -public class RecoilCluster extends ArrayList { +public class RtrkCluster extends ArrayList { - private DetectorDescriptor desc = new DetectorDescriptor(DetectorType.RECOIL); + private DetectorDescriptor desc = new DetectorDescriptor(DetectorType.RTRK); private int id; private Line3D clusterLine = new Line3D(); public int indexMaxStrip = -1; private byte clusterStatus = 1; - public RecoilCluster(RecoilStrip strip){ + public RtrkCluster(RtrkStrip strip){ this.desc.setSectorLayerComponent(strip.getDescriptor().getSector(), strip.getDescriptor().getLayer(), 0); this.add(strip); @@ -53,7 +53,7 @@ public int getChamber() { public double getEnergy(){ double energy = 0.0; - for(RecoilStrip strip : this){ + for(RtrkStrip strip : this){ energy += strip.getEnergy(); } return energy; @@ -61,7 +61,7 @@ public double getEnergy(){ public double getTime(){ double time = 0.0; - for(RecoilStrip strip : this){ + for(RtrkStrip strip : this){ time += strip.getTime()*strip.getEnergy(); } time /= this.getEnergy(); @@ -75,7 +75,7 @@ public double getSeedTime(){ return 0.0; } - public RecoilStrip getSeedStrip() { + public RtrkStrip getSeedStrip() { return this.get(this.indexMaxStrip); } @@ -83,8 +83,8 @@ public int getMaxStrip(){ return this.get(this.indexMaxStrip).getDescriptor().getComponent(); } - public boolean addStrip(RecoilStrip strip){ - for(RecoilStrip s : this){ + public boolean addStrip(RtrkStrip strip){ + for(RtrkStrip s : this){ if(s.isNeighbour(strip)){ this.add(strip); if(strip.getEnergy()>this.get(indexMaxStrip).getEnergy()){ @@ -99,7 +99,7 @@ public boolean addStrip(RecoilStrip strip){ public int getADC(){ int adc = 0; - for(RecoilStrip s : this){ + for(RtrkStrip s : this){ adc+= s.getADC(); } return adc; @@ -111,7 +111,7 @@ public int getADC(){ public void setClusterId(int id){ this.id = id; - for(RecoilStrip strip : this){ + for(RtrkStrip strip : this){ strip.setClusterId(id); } } @@ -155,20 +155,20 @@ public void redoClusterLine(){ } - public static List createClusters(List stripList){ + public static List createClusters(List stripList){ - List clusterList = new ArrayList<>(); + List clusterList = new ArrayList<>(); if(!stripList.isEmpty()){ for(int loop = 0; loop < stripList.size(); loop++){ //Loop over all strips boolean stripAdded = false; - for(RecoilCluster cluster : clusterList) { + for(RtrkCluster cluster : clusterList) { if(cluster.addStrip(stripList.get(loop))){ //Add adjacent strip to newly seeded peak stripAdded = true; } } if(!stripAdded){ - RecoilCluster newPeak = new RecoilCluster(stripList.get(loop)); //Non-adjacent strip seeds new peak + RtrkCluster newPeak = new RtrkCluster(stripList.get(loop)); //Non-adjacent strip seeds new peak clusterList.add(newPeak); } } @@ -180,9 +180,9 @@ public static List createClusters(List stripList){ return clusterList; } - public static List getClusters(List clusters, int sector, int layer) { - List selectedClusters = new ArrayList<>(); - for(RecoilCluster cluster : clusters) { + public static List getClusters(List clusters, int sector, int layer) { + List selectedClusters = new ArrayList<>(); + for(RtrkCluster cluster : clusters) { if(cluster.getSector()==sector && cluster.getLayer()==layer) selectedClusters.add(cluster); } @@ -196,7 +196,7 @@ public String toString(){ this.desc.getSector(),this.desc.getLayer(), this.getEnergy())); str.append(this.clusterLine.toString()); str.append("\n"); - for(RecoilStrip strip : this){ + for(RtrkStrip strip : this){ str.append("\t\t"); str.append(strip.toString()); str.append("\n"); diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilConstants.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java similarity index 93% rename from reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilConstants.java rename to reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java index eed0bb47e5..ddf55032d6 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilConstants.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java @@ -1,10 +1,10 @@ -package org.jlab.service.recoil; +package org.jlab.service.recoil.trk; /** * * @author bondi, devita,niccolai */ -public class RecoilConstants { +public class RtrkConstants { // geometry diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilCross.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java similarity index 72% rename from reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilCross.java rename to reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java index a2a2ba85e5..db98bc54c8 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilCross.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java @@ -1,4 +1,4 @@ -package org.jlab.service.recoil; +package org.jlab.service.recoil.trk; import java.util.ArrayList; import java.util.List; @@ -10,7 +10,7 @@ * recoil V-W clusters * @author devita, niccolai */ -public class RecoilCross { +public class RtrkCross { private int id; @@ -28,7 +28,8 @@ public class RecoilCross { - public RecoilCross(RecoilCluster c1, RecoilCluster c2) { + + public RtrkCross(RtrkCluster c1, RtrkCluster c2) { Vector3D dir = c1.getLine().direction().cross(c2.getLine().direction()); Plane3D plane = new Plane3D(c1.getLine().origin(), c1.getLine().direction().cross(dir)); @@ -36,7 +37,7 @@ public RecoilCross(RecoilCluster c1, RecoilCluster c2) { int nint = plane.intersectionSegment(c2.getLine(), point); if(nint==1) { this.sector = c1.getSector(); - this.region = (c1.getLayer()-1)/(RecoilConstants.NLAYER/RecoilConstants.NREGION)+1; + this.region = (c1.getLayer()-1)/(RtrkConstants.NLAYER/RtrkConstants.NREGION)+1; this.cross = point; this.energy = c1.getEnergy() + c2.getEnergy(); this.time = (c1.getTime() + c2.getTime())/2; @@ -89,20 +90,20 @@ public int getStatus() { return status; } - public static List createCrosses(List clusters) { + public static List createCrosses(List clusters) { - List crosses = new ArrayList<>(); + List crosses = new ArrayList<>(); - for(int is=0; is clustersV = RecoilCluster.getClusters(clusters, is+1, (RecoilConstants.NLAYER/RecoilConstants.NREGION)*ir+1); - List clustersW = RecoilCluster.getClusters(clusters, is+1, (RecoilConstants.NLAYER/RecoilConstants.NREGION)*ir+2); + for(int is=0; is clustersV = RtrkCluster.getClusters(clusters, is+1, (RtrkConstants.NLAYER/RtrkConstants.NREGION)*ir+1); + List clustersW = RtrkCluster.getClusters(clusters, is+1, (RtrkConstants.NLAYER/RtrkConstants.NREGION)*ir+2); - for(RecoilCluster v : clustersV) { - for(RecoilCluster w : clustersW) { + for(RtrkCluster v : clustersV) { + for(RtrkCluster w : clustersW) { if(v.getChamber()==w.getChamber()) { - RecoilCross cross = new RecoilCross(v, w); + RtrkCross cross = new RtrkCross(v, w); if(cross.point()!=null) crosses.add(cross); cross.setId(crosses.size()); } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilEngine.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java similarity index 82% rename from reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilEngine.java rename to reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java index bbb1bc8bfc..b1f3386f22 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/RecoilEngine.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java @@ -1,4 +1,4 @@ -package org.jlab.service.recoil; +package org.jlab.service.recoil.trk; import java.util.List; import java.util.Optional; @@ -8,7 +8,7 @@ import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.detector.base.DetectorType; import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.detector.geant4.v2.recoil.RecoilStripFactory; +import org.jlab.detector.geant4.v2.recoil.trk.RtrkStripFactory; import org.jlab.geom.prim.Point3D; import org.jlab.groot.data.H1F; import org.jlab.groot.fitter.DataFitter; @@ -25,14 +25,14 @@ * * @author bondi, devita, niccolai */ -public class RecoilEngine extends ReconstructionEngine { +public class RtrkEngine extends ReconstructionEngine { - public static Logger LOGGER = Logger.getLogger(RecoilEngine.class.getName()); + public static Logger LOGGER = Logger.getLogger(RtrkEngine.class.getName()); - public static RecoilStripFactory factory = new RecoilStripFactory(); + public static RtrkStripFactory factory = new RtrkStripFactory(); - public RecoilEngine() { - super("Recoil","niccolai","1.0"); + public RtrkEngine() { + super("Rtrk","niccolai","1.0"); } @Override @@ -41,11 +41,11 @@ public boolean init() { // init ConstantsManager to read constants from CCDB String variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); - factory.init(cp, RecoilConstants.NREGION); + factory.init(cp, RtrkConstants.NREGION); // register output banks for drop option - this.registerOutputBank("RECOIL::hits"); - this.registerOutputBank("RECOIL::clusters"); - this.registerOutputBank("RECOIL::crosses"); + this.registerOutputBank("RTRK::hits"); + this.registerOutputBank("RTRK::clusters"); + this.registerOutputBank("RTRK::crosses"); LOGGER.log(Level.INFO, "--> recoil is ready..."); return true; @@ -57,9 +57,9 @@ public boolean init() { @Override public boolean processDataEventUser(DataEvent event) { - List strips = RecoilStrip.getStrips(event, factory, this.getConstantsManager()); - List clusters = RecoilCluster.createClusters(strips); - List crosses = RecoilCross.createCrosses(clusters); + List strips = RtrkStrip.getStrips(event, factory, this.getConstantsManager()); + List clusters = RtrkCluster.createClusters(strips); + List crosses = RtrkCross.createCrosses(clusters); this.writeHipoBanks(event, strips, clusters, crosses); @@ -68,11 +68,11 @@ public boolean processDataEventUser(DataEvent event) { private void writeHipoBanks(DataEvent de, - List strips, - List clusters, - List crosses){ + List strips, + List clusters, + List crosses){ - DataBank bankS = de.createBank("RECOIL::hits", strips.size()); + DataBank bankS = de.createBank("RTRK::hits", strips.size()); for(int h = 0; h < strips.size(); h++){ bankS.setShort("id", h, (short) strips.get(h).getId()); bankS.setByte("sector", h, (byte) strips.get(h).getDescriptor().getSector()); @@ -84,7 +84,7 @@ private void writeHipoBanks(DataEvent de, bankS.setShort("clusterId", h, (short) strips.get(h).getClusterId()); } - DataBank bankC = de.createBank("RECOIL::clusters", clusters.size()); + DataBank bankC = de.createBank("RTRK::clusters", clusters.size()); for(int c = 0; c < clusters.size(); c++){ bankC.setShort("id", c, (short) clusters.get(c).getId()); bankC.setByte("sector", c, (byte) clusters.get(c).get(0).getDescriptor().getSector()); @@ -102,7 +102,7 @@ private void writeHipoBanks(DataEvent de, bankC.setShort("status", c, (short) clusters.get(c).getStatus()); } - DataBank bankX = de.createBank("RECOIL::crosses", crosses.size()); + DataBank bankX = de.createBank("RTRK::crosses", crosses.size()); for(int c = 0; c < crosses.size(); c++){ bankX.setShort("id", c, (short) crosses.get(c).getId()); bankX.setByte("sector", c, (byte) crosses.get(c).getSector()); @@ -153,14 +153,14 @@ public static void fitGauss(H1F histo) { public static void main (String arg[]) { - RecoilEngine engine = new RecoilEngine(); + RtrkEngine engine = new RtrkEngine(); engine.init(); String input = "/Users/devita/urwell3d.hipo"; DataGroup dg = new DataGroup(3, 2); String[] axes = {"x", "y"}; - for(int il=0; il this.desc.getSector()) return -1; if(ob.getDescriptor().getLayer() < this.desc.getLayer()) return 1; @@ -161,14 +161,14 @@ public int compareTo(Object o) { return -1; } - public static List getStrips(DataEvent event, RecoilStripFactory factory, ConstantsManager ccdb) { + public static List getStrips(DataEvent event, RtrkStripFactory factory, ConstantsManager ccdb) { - List strips = new ArrayList<>(); + List strips = new ArrayList<>(); - if(event.hasBank("RECOIL::adc")){ - RawDataBank bank = new RawDataBank("RECOIL::adc"); + if(event.hasBank("RTRK::adc")){ + RawDataBank bank = new RawDataBank("RTRK::adc"); bank.read(event); - //DataBank bank = event.getBank("RECOIL::adc"); + //DataBank bank = event.getBank("RTRK::adc"); for(int i = 0; i < bank.rows(); i++){ int sector = bank.getByte("sector", i); int layer = bank.getByte("layer", i); @@ -176,19 +176,19 @@ public static List getStrips(DataEvent event, RecoilStripFactory fa int adc = bank.getInt("ADC", i); double time = bank.getFloat("time", i); - RecoilStrip strip = new RecoilStrip(sector, layer, comp); + RtrkStrip strip = new RtrkStrip(sector, layer, comp); // strip.setTriggerPhase(triggerPhase); strip.setId(bank.trueIndex(i)+1); strip.setADC(adc); strip.setTDC((int) time); - strip.setEnergy(strip.ADC*RecoilConstants.ADCTOENERGY); - strip.setTime(strip.TDC*RecoilConstants.TDCTOTIME); + strip.setEnergy(strip.ADC*RtrkConstants.ADCTOENERGY); + strip.setTime(strip.TDC*RtrkConstants.TDCTOTIME); strip.setLine(factory.getStrip(sector, layer, comp)); strip.setChamber(factory.getChamberIndex(comp)+1); strip.setStatus(0); - if(strip.getEnergy()>RecoilConstants.THRESHOLD) strips.add(strip); + if(strip.getEnergy()>RtrkConstants.THRESHOLD) strips.add(strip); } } From f9b8ff48ba04bdf555a492903133faa8b80a1fe6 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 11 Jun 2026 09:53:14 -0400 Subject: [PATCH 2/7] fix package names, remove unused imports --- .../jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java | 3 --- .../jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java | 3 --- .../detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java | 8 -------- .../java/org/jlab/service/recoil/tof/ClusterFinder.java | 6 +----- .../main/java/org/jlab/service/recoil/tof/HitFinder.java | 2 +- .../main/java/org/jlab/service/recoil/tof/Parameters.java | 3 +-- .../java/org/jlab/service/recoil/tof/RTOFCluster.java | 8 +------- .../main/java/org/jlab/service/recoil/tof/RTOFHit.java | 3 +-- .../main/java/org/jlab/service/recoil/tof/RTOFRawHit.java | 5 +---- .../java/org/jlab/service/recoil/tof/RecoBankWriter.java | 6 +----- 10 files changed, 7 insertions(+), 40 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java index 3ec69f6283..534905fd6c 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java @@ -1,9 +1,6 @@ package org.jlab.detector.geant4.v2.recoil.tof; - import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.prim.Point3D; - public class RTOFConstants { diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java index 6e0a78e98f..45ae3c5704 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java @@ -1,9 +1,6 @@ package org.jlab.detector.geant4.v2.recoil.trk; - import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.prim.Point3D; - public class RtrkConstants { diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java index 7d42c037fb..0b61bbc992 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java @@ -2,18 +2,10 @@ import eu.mihosoft.vrl.v3d.Vector3d; import org.jlab.detector.geant4.v2.Geant4Factory; -import org.jlab.detector.volume.G4Trap; import org.jlab.detector.volume.G4World; import org.jlab.detector.volume.G4Box; -import org.jlab.detector.volume.G4Trd; import org.jlab.detector.volume.Geant4Basic; import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Plane3D; -import org.jlab.geom.prim.Vector3D; -import org.jlab.geometry.prim.Line3d; -import org.jlab.geometry.prim.Straight; /** * Generate GEANT4 volume for the RECOIL tracker diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/ClusterFinder.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/ClusterFinder.java index 930c3e447b..1463331cf2 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/ClusterFinder.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/ClusterFinder.java @@ -1,11 +1,7 @@ -package org.jlab.rec.recoil.tof; +package org.jlab.service.recoil.tof; import java.util.ArrayList; import org.jlab.io.base.DataEvent; -import org.jlab.rec.recoil.tof.Parameters; -import org.jlab.rec.recoil.tof.RTOFRawHit; -import org.jlab.rec.recoil.tof.RTOFHit; -import org.jlab.rec.recoil.tof.HitFinder; /** * The {@code ClusterFinder} class builds clusters in the recoil tof diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java index 87b8971264..67619066ed 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java @@ -1,4 +1,4 @@ -package org.jlab.rec.recoil.tof; +package org.jlab.service.recoil.tof; import java.util.ArrayList; import java.util.Collections; diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java index cb396207ba..fdb5f13979 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java @@ -1,5 +1,4 @@ -package org.jlab.rec.recoil.tof; -import org.jlab.detector.geant4.v2.recoil.tof.RTOFConstants; +package org.jlab.service.recoil.tof; /** * diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java index 68dd4cd2fe..cee0b3e877 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java @@ -1,13 +1,7 @@ -package org.jlab.rec.recoil.tof; +package org.jlab.service.recoil.tof; import java.util.ArrayList; -import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Point3D; -import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.rec.recoil.tof.Parameters; -import org.jlab.rec.recoil.tof.RTOFRawHit; -import org.jlab.rec.recoil.tof.RTOFHit; /** * The {@code RTOFCluster} represents clusters in the recoil tof diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java index fc15104086..581559d6d9 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java @@ -1,6 +1,5 @@ -package org.jlab.rec.recoil.tof; +package org.jlab.service.recoil.tof; -import org.jlab.rec.recoil.tof.Parameters; import org.jlab.detector.geant4.v2.recoil.tof.RTOFConstants; /** diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java index ab88a1f023..3998dc5674 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java @@ -1,8 +1,5 @@ -package org.jlab.rec.recoil.tof; +package org.jlab.service.recoil.tof; -import org.jlab.geom.base.*; -import org.jlab.geom.prim.Point3D; -import org.jlab.rec.recoil.tof.Parameters; import org.jlab.detector.geant4.v2.recoil.tof.RTOFConstants; /** diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java index bf8b729ea1..aa036bcc4f 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java @@ -1,12 +1,8 @@ -package org.jlab.rec.recoil.tof; +package org.jlab.service.recoil.tof; import java.util.ArrayList; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.rec.recoil.tof.RTOFCluster; -import org.jlab.rec.recoil.tof.RTOFRawHit; -import org.jlab.rec.recoil.tof.RTOFHit; - /** * The {@code RecoBankWriter} writes the banks needed for the recoil tof From 9da88bbf12b14077b244341d7f83082f74fcd9ca Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 11 Jun 2026 10:03:40 -0400 Subject: [PATCH 3/7] fix formatting, remove empty mains --- .../geant4/v2/recoil/tof/RTOFConstants.java | 13 +- .../v2/recoil/tof/RTOFGeant4Factory.java | 155 ++++--- .../geant4/v2/recoil/trk/RtrkConstants.java | 109 ++--- .../v2/recoil/trk/RtrkGeant4Factory.java | 249 ++++++----- .../v2/recoil/trk/RtrkStripFactory.java | 394 +++++++++--------- .../service/recoil/tof/ClusterFinder.java | 62 ++- .../jlab/service/recoil/tof/HitFinder.java | 24 +- .../jlab/service/recoil/tof/Parameters.java | 6 +- .../jlab/service/recoil/tof/RTOFCluster.java | 76 ++-- .../org/jlab/service/recoil/tof/RTOFHit.java | 102 +++-- .../jlab/service/recoil/tof/RTOFRawHit.java | 248 ++++++----- .../service/recoil/tof/RecoBankWriter.java | 37 +- .../jlab/service/recoil/trk/RtrkCluster.java | 55 ++- .../service/recoil/trk/RtrkConstants.java | 5 +- .../jlab/service/recoil/trk/RtrkCross.java | 23 +- .../jlab/service/recoil/trk/RtrkEngine.java | 95 ++--- .../jlab/service/recoil/trk/RtrkStrip.java | 88 ++-- 17 files changed, 824 insertions(+), 917 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java index 534905fd6c..5ef906db7b 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFConstants.java @@ -22,12 +22,10 @@ public class RTOFConstants { public final static double LENGTH = (NROWS-1) * LONG_BAR_LENGTH + SHORT_BAR_LENGTH; public final static double THICKNESS = 0.5; // cm - public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) { - - load(cp ); - return cp; + load(cp ); + return cp; } /** @@ -35,14 +33,11 @@ public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) * Please use a DatabaseConstantProvider to access CCDB and load the following tables: * @param cp a ConstantProvider that has loaded the necessary tables */ - public static synchronized void load( DatabaseConstantProvider cp ) { - //WIDTH = NCOLUMNS * BAR_WIDTH; + //WIDTH = NCOLUMNS * BAR_WIDTH; //LENGTH = (NROWS-1) * LONG_BAR_LENGTH + SHORT_BAR_LENGTH; //THICKNESS = 0.5; // cm } -} - - +} \ No newline at end of file diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java index e1d238ee29..82926db40a 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/tof/RTOFGeant4Factory.java @@ -9,7 +9,7 @@ /** * Generate GEANT4 volume for the RECOIL TOF detector - * + * * @author Nilanga Wickramaarachchi */ public final class RTOFGeant4Factory extends Geant4Factory { @@ -24,121 +24,106 @@ public RTOFGeant4Factory( DatabaseConstantProvider cp) { } public void init(DatabaseConstantProvider cp) { - motherVolume = new G4World("root"); - - for (int isector = 0; isector < nSectors; isector++) { - Geant4Basic sectorVolume = createSector(isector, nRows, nCols); - - sectorVolume.setName("recoil_tof_sector" + (isector + 1)); - sectorVolume.setMother(motherVolume); - } + for (int isector = 0; isector < nSectors; isector++) { + Geant4Basic sectorVolume = createSector(isector, nRows, nCols); + sectorVolume.setName("recoil_tof_sector" + (isector + 1)); + sectorVolume.setMother(motherVolume); + } } - - + public Vector3d getCenterCoordinate(int isector) { int is=isector; Vector3d vCenter = new Vector3d(0, 0, 0); - - vCenter.x = (-1+is*2)*(RTOFConstants.RADIUS)*Math.sin(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); - vCenter.y = 0; - vCenter.z =RTOFConstants.RADIUS*Math.cos(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + vCenter.x = (-1+is*2)*(RTOFConstants.RADIUS)*Math.sin(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + vCenter.y = 0; + vCenter.z =RTOFConstants.RADIUS*Math.cos(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); return vCenter; } - - public Geant4Basic createSector(int isector, int nRows, int nCols ) { - + double hlx = RTOFConstants.WIDTH/2+1; double hly = RTOFConstants.LENGTH/2+1; - double hlz = RTOFConstants.THICKNESS/2+1; - + double hlz = RTOFConstants.THICKNESS/2+1; + Vector3d vCenter = this.getCenterCoordinate(isector); - - Geant4Basic sectorVolume = new G4Box("recoil_tof_sector" + (isector + 1), hlx, hly, hlz); - - if(isector==0) sectorVolume.rotate("yxz",Math.toRadians((RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)),0,0); - if(isector==1) sectorVolume.rotate("yxz",Math.toRadians(-(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)),0,0); + + Geant4Basic sectorVolume = new G4Box("recoil_tof_sector" + (isector + 1), hlx, hly, hlz); + + if(isector==0) sectorVolume.rotate("yxz",Math.toRadians((RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)),0,0); + if(isector==1) sectorVolume.rotate("yxz",Math.toRadians(-(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)),0,0); sectorVolume.translate(vCenter.x, vCenter.y, vCenter.z); sectorVolume.setId(isector + 1, 0, 0); - + // Bars construction - for (int row = 0; row < nRows; row++) { - for (int col = 0; col < nCols; col++) { - - Geant4Basic barVolume = this.createBar(isector, row, col); - + for (int row = 0; row < nRows; row++) { + for (int col = 0; col < nCols; col++) { + + Geant4Basic barVolume = this.createBar(isector, row, col); + barVolume.setName("bar_sector" + (isector + 1) + "_row" + (row + 1) + "_column" + (col + 1)); - - barVolume.setMother(sectorVolume); - - barVolume.setId(isector + 1, row +1, col+1, 0); - } - } - + + barVolume.setMother(sectorVolume); + + barVolume.setId(isector + 1, row +1, col+1, 0); + } + } + return sectorVolume; } - public Geant4Basic createBar(int iSector, int iRow, int iCol) { - int nCols = RTOFConstants.NCOLUMNS; - - double barDX = RTOFConstants.BAR_WIDTH/2; - double barDY; - - if (iRow == (nRows - 1) / 2) barDY = RTOFConstants.SHORT_BAR_LENGTH/2; - else barDY = RTOFConstants.LONG_BAR_LENGTH/2; - - double barDZ = RTOFConstants.BAR_THICKNESS/2; + int nCols = RTOFConstants.NCOLUMNS; + + double barDX = RTOFConstants.BAR_WIDTH/2; + double barDY; + + if (iRow == (nRows - 1) / 2) barDY = RTOFConstants.SHORT_BAR_LENGTH/2; + else barDY = RTOFConstants.LONG_BAR_LENGTH/2; + + double barDZ = RTOFConstants.BAR_THICKNESS/2; + + Geant4Basic barVolume = new G4Box("bar_sector" + (iSector + 1) + "_row" + (iRow + 1) + "_column" + (iCol + 1), barDX, barDY, barDZ); + + // Constants for positioning + double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position + double x_spacing = RTOFConstants.BAR_WIDTH; + double x_start = -(RTOFConstants.WIDTH - x_spacing)/2; // starting X position + double dy_long = RTOFConstants.LONG_BAR_LENGTH; + double dy_short = RTOFConstants.SHORT_BAR_LENGTH; + + //Position calculation + double z_pos = 0; + double x_pos = x_start + (iCol * x_spacing); - Geant4Basic barVolume = new G4Box("bar_sector" + (iSector + 1) + "_row" + (iRow + 1) + "_column" + (iCol + 1), barDX, barDY, barDZ); - - // Constants for positioning - double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position - double x_spacing = RTOFConstants.BAR_WIDTH; - double x_start = -(RTOFConstants.WIDTH - x_spacing)/2; // starting X position - double dy_long = RTOFConstants.LONG_BAR_LENGTH; - double dy_short = RTOFConstants.SHORT_BAR_LENGTH; - - //Position calculation - double z_pos = 0; - double x_pos = x_start + (iCol * x_spacing); - double y_pos; - if(iRow < (nRows - 1) / 2) - { - y_pos = y_start + (iRow * dy_long); - } - else if (iRow == (nRows - 1) / 2) // middle row - { - y_pos = 0; - } - else - { - y_pos = y_start + (iRow -1) * dy_long + dy_short; - } - - barVolume.setPosition(x_pos, y_pos, z_pos); - - return barVolume; + if (iRow < (nRows - 1) / 2) { + y_pos = y_start + (iRow * dy_long); + } + else if (iRow == (nRows - 1) / 2) {// middle row + y_pos = 0; + } + else { + y_pos = y_start + (iRow -1) * dy_long + dy_short; + } + + barVolume.setPosition(x_pos, y_pos, z_pos); + + return barVolume; } - - - public static void main(String[] args) { DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - + RTOFConstants.connect(cp); RTOFGeant4Factory factory = new RTOFGeant4Factory(cp); - + factory.getAllVolumes().forEach(volume -> { System.out.println(volume.gemcString()); }); - - } -} + } +} \ No newline at end of file diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java index 45ae3c5704..83585b4d5f 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java @@ -1,105 +1,106 @@ package org.jlab.detector.geant4.v2.recoil.trk; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; public class RtrkConstants { - + private final static String CCDBPATH = "/geometry/recoil/trk/"; - public final static int NMAXREGIONS = 3; //max number of regions - public final static int NREGIONS = 3; //number of regions + public final static int NMAXREGIONS = 3; //max number of regions + public final static int NREGIONS = 3; //number of regions public final static int NSECTORS = 2; //number of sectors public final static int NLAYERS = 2; //number of layers public final static int NCHAMBERS = 1; //number of chambers in a sector - + public final static double HORIZONTHAL_OPENING_ANGLE = 34.; public final static double VERTICAL_OPENING_ANGLE = 50.; public final static double RADIUS[] = {33.5,55.5,79.5}; public final static double WIDTH[] = new double[NMAXREGIONS]; public final static double HEIGHT[] = new double[NMAXREGIONS]; - + public final static double THTILT = 0; // theta tilt (deg) /* public final static double XENLARGEMENT = 0.5; // cm public final static double YENLARGEMENT = 1.; // cm public final static double ZENLARGEMENT = 0.1; // cm - + // Sector geometrical parameters public final static double THOPEN = 34.; // opening angle between endplate planes (deg) public final static double THTILT = 0; // theta tilt (deg) public final static double THMIN = 4.694; // polar angle to the base of first chamber (deg) public final static double SECTORHEIGHT = 146.21; //height of each sector (cm) public final static double DX0CHAMBER0 = 5.197; // halfbase of chamber 1 (cm)*/ - + // Chamber volumes and materials (units are cm) - public final static double[] CHAMBERVOLUMESTHICKNESS = {0.0025, 0.0005,0.3, // window - 0.0025, 0.0005,0.4, // cathode - 0.0005, 0.005, 0.0005, // uRWell + DlC - 0.0005, 0.005, 0.0005, // Capacitive sharing layer1 - 0.0005, 0.005, 0.0005, // Capacitive sharing layer2 - 0.005, 0.0005,0.005, 0.005, 0.0005,0.005, 0.005, // Readout - 0.0127, 0.3, 0.0125}; // support - public final static String[] CHAMBERVOLUMESNAME = {"window_kapton", "window_Al", "window_gas", - "cathode_kapton", "cathode_Al", "cathode_gas", - "muRwell_Cu", "muRwell_kapton", "muRwell_dlc", - "capa_sharing_layer1_glue","capa_sharing_layer1_Cr","capa_sharing_layer1_kapton", - "capa_sharing_layer2_glue","capa_sharing_layer2_Cr","capa_sharing_layer2_kapton", - "readout1_glue", "readout1_Cu", "readout1_kapton", "readout2_glue", "readout2_Cu", "readout2_kapton", "readout3_glue", - "support_skin1_g10", "support_honeycomb_nomex", "support_skin2_g10"}; - - // URWELL position in the CLAS12 frame - /* public final static double TGT2DC0 = 228.078; // cm - // public final static double URWELL2DC0 = 2; // cm + public final static double[] CHAMBERVOLUMESTHICKNESS = { + 0.0025, 0.0005,0.3, // window + 0.0025, 0.0005,0.4, // cathode + 0.0005, 0.005, 0.0005, // uRWell + DlC + 0.0005, 0.005, 0.0005, // Capacitive sharing layer1 + 0.0005, 0.005, 0.0005, // Capacitive sharing layer2 + 0.005, 0.0005,0.005, 0.005, 0.0005,0.005, 0.005, // Readout + 0.0127, 0.3, 0.0125}; // support + public final static String[] CHAMBERVOLUMESNAME = { + "window_kapton", "window_Al", "window_gas", + "cathode_kapton", "cathode_Al", "cathode_gas", + "muRwell_Cu", "muRwell_kapton", "muRwell_dlc", + "capa_sharing_layer1_glue","capa_sharing_layer1_Cr","capa_sharing_layer1_kapton", + "capa_sharing_layer2_glue","capa_sharing_layer2_Cr","capa_sharing_layer2_kapton", + "readout1_glue", "readout1_Cu", "readout1_kapton", "readout2_glue", "readout2_Cu", "readout2_kapton", "readout3_glue", + "support_skin1_g10", "support_honeycomb_nomex", "support_skin2_g10"}; + + // URWELL position in the CLAS12 frame + /* public final static double TGT2DC0 = 228.078; // cm + // public final static double URWELL2DC0 = 2; // cm public final static double URWELL2DC0[] = new double[NMAXREGIONS]; public final static double DIST2TGT[] = new double[NMAXREGIONS]; - public final static double W2TGT[] = new double[NMAXREGIONS];; + public final static double W2TGT[] = new double[NMAXREGIONS];; public final static double YMIN[] = new double[NMAXREGIONS]; public final static double ZMIN[] = new double[NMAXREGIONS];*/ public final static double PITCH = 0.1 ; // cm public final static double STEREOANGLE = 90; // deg - - /* - * @return String a path to a directory in CCDB of the format {@code "/geometry/detector/"} - */ + + /* + * @return String a path to a directory in CCDB of the format {@code "/geometry/detector/"} + */ public static String getCcdbPath() { - return CCDBPATH; + return CCDBPATH; } - - /** + + /** * Loads the the necessary tables for the URWELL geometry for a given DatabaseConstantProvider. - * + * * @return DatabaseConstantProvider the same thing */ public static DatabaseConstantProvider connect( DatabaseConstantProvider cp ) { - // cp.loadTable( CCDBPATH +"RWELL"); - - load(cp ); - return cp; + // cp.loadTable( CCDBPATH +"RWELL"); + + load(cp ); + return cp; } - + /** * Reads all the necessary constants from CCDB into static variables. * Please use a DatabaseConstantProvider to access CCDB and load the following tables: * @param cp a ConstantProvider that has loaded the necessary tables */ - public static synchronized void load( DatabaseConstantProvider cp ) { - // read constants from svt table + // read constants from svt table // NREGIONS = cp.getInteger( CCDBPATH+"svt/nRegions", 0 ); - - for (int i=0; i (volume.getName().contains(volumeName))) - .findAny() - .orElse(null); + + // volumeName = "rg" + r + "_s" + s + "_r" + re + "_c" + c + "_cathode_gas"; + volumeName = "rg" + r + "_s" + s + "_c" + c + "_cathode_gas"; + return this.getAllVolumes().stream() + .filter(volume -> (volume.getName().contains(volumeName))) + .findAny() + .orElse(null); } - + /** * Returns the sector volume for the given sector number - * + * * @param sector (1-6) * @return the sector volume */ public Geant4Basic getSectorVolume(int region, int sector) { - + int r = region; int s = sector; - + String volName = "region_Rtrk_" + r + "_s" + s; return this.getAllVolumes().stream() - .filter(volume -> (volume.getName().contains(volName))) - .findAny() - .orElse(null); + .filter(volume -> (volume.getName().contains(volName))) + .findAny() + .orElse(null); } public static void main(String[] args) { DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - RtrkConstants.connect(cp); - RtrkGeant4Factory factory = new RtrkGeant4Factory(cp, 1); - factory.getAllVolumes().forEach(volume -> { System.out.println(volume.gemcString()); }); - - } + } } diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java index 9158336800..73be7ed32f 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java @@ -15,11 +15,11 @@ /** * Creates and handles the URWELL detector strips as 3D lines - * + * * @author bondi, niccolai */ public final class RtrkStripFactory { - + private RtrkGeant4Factory factory; private IndexedList globalStrips = new IndexedList(3); private IndexedList localStrips = new IndexedList(3); @@ -34,7 +34,7 @@ public RtrkStripFactory() { /** * Create the strip factory based on constants from CCDB. - * Currently constants are defined in the RtrkConstants class. + * Currently constants are defined in the RtrkConstants class. * They will be moved to CCDB when finalized). * @param cp database provide */ @@ -49,7 +49,7 @@ public RtrkStripFactory(DatabaseConstantProvider cp) { public void init(DatabaseConstantProvider cp) { this.init(cp, 1); } - + /** * Create the strip factory based on constants from CCDB. * Currently constants are defined in the RtrkConstants class. @@ -68,44 +68,44 @@ public RtrkStripFactory(DatabaseConstantProvider cp, int regions) { */ public void init(DatabaseConstantProvider cp, int regions) { factory = new RtrkGeant4Factory(cp, regions); - nRegions = Math.min(RtrkConstants.NMAXREGIONS, regions); - nSectors = RtrkConstants.NSECTORS; - nChambers = RtrkConstants.NCHAMBERS; - nLayers = RtrkConstants.NLAYERS; + nRegions = Math.min(RtrkConstants.NMAXREGIONS, regions); + nSectors = RtrkConstants.NSECTORS; + nChambers = RtrkConstants.NCHAMBERS; + nLayers = RtrkConstants.NLAYERS; this.fillStripLists(); - // this.fillPlaneLists(); + // this.fillPlaneLists(); } - + /** * Calculates the total number of strips in a sector - * + * * @return the strip number */ public int getNStripSector() { int nStrips = 0; for (int i = 0; i < nChambers; i++) { - for (int j = 0; j < nRegions; j++) { - nStrips += getNStripChamber(i,j); - } - } + for (int j = 0; j < nRegions; j++) { + nStrips += getNStripChamber(i,j); + } + } return nStrips; } - + /** * Calculates the number of strips in the given chamber - * + * * @param ichamber (0, 1, 2) * @return the strip number (1-N) */ public int getNStripChamber(int ichamber, int regions) { - - int iregion = regions; - int chamber = ichamber; + + int iregion = regions; + int chamber = ichamber; double[] dim = factory.getChamber_daughter_Dimensions(iregion,chamber); - + double yHalf = dim[1]; - double xHalf = dim[0]; - + double xHalf = dim[0]; + // C-------------D // // ------------- // // ------------- // @@ -113,56 +113,56 @@ public int getNStripChamber(int ichamber, int regions) { /** * * number of strip in AB** */ - - int nAB = (int) (2 * xHalf / RtrkConstants.PITCH); - int nAC = (int) (2 * yHalf / RtrkConstants.PITCH); - - int nStrips = nAB + nAC; - + + int nAB = (int) (2 * xHalf / RtrkConstants.PITCH); + int nAC = (int) (2 * yHalf / RtrkConstants.PITCH); + + int nStrips = nAB + nAC; + return nStrips; } - + /** * Provides the index of the chamber containing the strip with the given ID - * + * * @param strip (1 to N) * @return the chamber index (0, 1, 2) */ public int getChamberIndex(int strip) { int nStripTotal = 0; - + for(int i=0; i strip ID chamber (from 1 to getNStripChamber) int nStripTotal = 0; if (chamberIndex > 0) { for (int i = 0; i < chamberIndex; i++) { - for (int j = 0; j < nRegions; j++) { - nStripTotal += this.getNStripChamber(i,j); - } - } + for (int j = 0; j < nRegions; j++) { + nStripTotal += this.getNStripChamber(i,j); + } + } } - - //Strip ID: from 1 to getNStripChamber + + //Strip ID: from 1 to getNStripChamber int cStrip = strip - nStripTotal; return cStrip; } - + /** * Builds the given strip line in the CLAS12 frame * @param sector (1-6) @@ -171,79 +171,79 @@ private int getLocalStripId(int strip) { * @return the 3D strip line as a Line3d */ private Line3d createStrip(int sector, int region, int layer, int strip) { - + int chamberIndex = getChamberIndex(strip); int cStrip = this.getLocalStripId(strip); - + // CHAMBER reference frame // new numeration with stri ID_strip=0 crossing (0,0,0) of chamber double[] dim = factory.getChamber_daughter_Dimensions(region-1,chamberIndex); double yHalf = dim[1]; - double xHalf = dim[0]; - - double DY = -xHalf; //v strip - + double xHalf = dim[0]; + + double DY = -xHalf; //v strip + // Y coordinate of the intersection point between the x=0 and the strip line crossing for B - - if (layer % 2 != 0) { //u strip - DY = -yHalf; - } - // ID of the strip - int nS = (int) (DY / RtrkConstants.PITCH); + + if (layer % 2 != 0) { //u strip + DY = -yHalf; + } + // ID of the strip + int nS = (int) (DY / RtrkConstants.PITCH); int nCStrip = nS + (cStrip - 1); - double c = nCStrip * RtrkConstants.PITCH; - - // Take 2 points in the strip straight line. They needs to define Line object + double c = nCStrip * RtrkConstants.PITCH; + + // Take 2 points in the strip straight line. They needs to define Line object //u strips double oX = -xHalf; double oY = c; double oZ = 0; - + double eX = xHalf; double eY = c; double eZ = 0; - + if (layer % 2 == 0) { //v strips - oX = c; - oY = -yHalf; - oZ = 0; - - eX = c; - eY = yHalf; - eZ = 0; - } - - Vector3d origin = new Vector3d(oX, oY, oZ); - Vector3d end = new Vector3d(eX, eY, eZ); - + oX = c; + oY = -yHalf; + oZ = 0; + + eX = c; + eY = yHalf; + eZ = 0; + } + + Vector3d origin = new Vector3d(oX, oY, oZ); + Vector3d end = new Vector3d(eX, eY, eZ); + // Get Chamber Volume Geant4Basic chamberVolume = factory.getChamberVolume(sector, region, chamberIndex+1, layer); - - // 2 point defined before wrt the GLOBAL frame + + // 2 point defined before wrt the GLOBAL frame Vector3d globalOrigin = chamberVolume.getGlobalTransform().transform(origin); - + Vector3d globalEnd = chamberVolume.getGlobalTransform().transform(end); - + Straight line = new Line3d(globalOrigin, globalEnd); - + // CHECK intersections between line and volume chamberVolume.makeSensitive(); List Hits = chamberVolume.getIntersections(line); - + if (Hits.size() >= 1) { - - Vector3d TestOrigin = Hits.get(0).origin(); - Vector3d TestEnd = Hits.get(0).end(); - + + Vector3d TestOrigin = Hits.get(0).origin(); + Vector3d TestEnd = Hits.get(0).end(); + return new Line3d(Hits.get(0).origin(), Hits.get(0).end()); - + } else { return null; } } - - /** + + /** * Provides the given strip line in the Chamber local frame * @param region (1-2) * @param sector (1-6) @@ -251,19 +251,19 @@ private Line3d createStrip(int sector, int region, int layer, int strip) { * @param strip (1-N) * @return the 3D strip line as a Line3d */ - private Line3d getChamberStrip(int region, int sector, int chamber, int layer, int strip) { - - Line3d globalStrip = createStrip(sector, region, layer, strip); - Geant4Basic chamberVolume = factory.getChamberVolume(sector, region, chamber, layer); - - Vector3d origin = chamberVolume.getGlobalTransform().invert().transform(globalStrip.origin()); - Vector3d end = chamberVolume.getGlobalTransform().invert().transform(globalStrip.end()); - - Line3d localStrip = new Line3d(origin, end); - - return localStrip; + + Line3d globalStrip = createStrip(sector, region, layer, strip); + Geant4Basic chamberVolume = factory.getChamberVolume(sector, region, chamber, layer); + + Vector3d origin = chamberVolume.getGlobalTransform().invert().transform(globalStrip.origin()); + Vector3d end = chamberVolume.getGlobalTransform().invert().transform(globalStrip.end()); + + Line3d localStrip = new Line3d(origin, end); + + return localStrip; } + /** * Provides the given strip line in the sector local frame * @param sector (1-6) @@ -272,20 +272,18 @@ private Line3d getChamberStrip(int region, int sector, int chamber, int layer, i * @return the 3D strip line as a Line3d */ private Line3d getLocalStrip(int region, int sector, int layer, int strip) { - - + Line3d globalStrip = createStrip(sector, region, layer, strip); Geant4Basic sVolume = factory.getSectorVolume(region, sector); - + Vector3d origin = sVolume.getGlobalTransform().invert().transform(globalStrip.origin()); Vector3d end = sVolume.getGlobalTransform().invert().transform(globalStrip.end()); - + Line3d localStrip = new Line3d(origin, end); - + return localStrip; } - private void fillStripLists() { for(int ir=0; ir-xHalf && c-yHalf && c-xHalf && c-yHalf && c-xHalf && c-yHalf && c-xHalf && c-yHalf && c clusters; - + /** * Sets the list of clusters. * @@ -28,7 +28,7 @@ public class ClusterFinder { public void setClusters(ArrayList clusters) { this.clusters = clusters; } - + /** * Gets the list of clusters. * @@ -38,7 +38,7 @@ public void setClusters(ArrayList clusters) { public ArrayList getClusters() { return clusters; } - + /** * Cluster hits around a given hit, based on the time and geometric @@ -78,23 +78,23 @@ public void clusterHits(int i, ArrayList hits, RTOFRaw } // Check the distance between the hits double delta_T = Math.abs(this_hit.getTime() - other_hit.getTime()); - //The y distance is a distance in cm + //The y distance is a distance in cm Boolean condition_y; - double delta_Y = Math.abs(this_hit.getY() - other_hit.getY()); - condition_y = (delta_Y <= sigma_y.doubleValue()); - + double delta_Y = Math.abs(this_hit.getY() - other_hit.getY()); + condition_y = (delta_Y <= sigma_y.doubleValue()); + //If hit is within limits, it is clustered - if (condition_y) { - if (delta_T < sigma_t) { - other_hit.setIsInACluster(true); - other_hit.setAssociatedClusterIndex(cluster_id); - this_cluster_hits.add(other_hit); - } - } - } + if (condition_y) { + if (delta_T < sigma_t) { + other_hit.setIsInACluster(true); + other_hit.setAssociatedClusterIndex(cluster_id); + this_cluster_hits.add(other_hit); + } + } + } } - - + + /** * Builds clusters in the {@link DateEvent} using hits found and stored in a * {@link HitFinder}. @@ -108,14 +108,14 @@ public void clusterHits(int i, ArrayList hits, RTOFRaw * */ public void makeClusters(HitFinder hitfinder, double sigma_y, double sigma_t, DataEvent event) { - + //A list of clusters is built for each event clusters.clear(); int cluster_id = 1; - + //Getting the list of hits, they must have been ordered by energy already ArrayList rtof_hits = hitfinder.getRTOFHits(); - + //Loop through all bar hits for (int i_bar = 0; i_bar < rtof_hits.size(); i_bar++) { RTOFHit this_rtof_hit = rtof_hits.get(i_bar); @@ -123,21 +123,21 @@ public void makeClusters(HitFinder hitfinder, double sigma_y, double sigma_t, Da if (this_rtof_hit.getIsInACluster()) { continue; } - + ArrayList this_cluster_rtof_hits = new ArrayList<>(); this_rtof_hit.setIsInACluster(true); this_rtof_hit.setAssociatedClusterIndex(cluster_id); this_cluster_rtof_hits.add(this_rtof_hit); - + //Matching bar hits in clusters clusterHits(i_bar, rtof_hits, this_rtof_hit, sigma_y, sigma_t, cluster_id, this_cluster_rtof_hits); - + RTOFCluster cluster = new RTOFCluster(this_cluster_rtof_hits, event); clusters.add(cluster); cluster_id++; } } - + /** * Builds clusters in the {@link DataEvent} using hits found and stored in a * {@link HitFinder}. @@ -150,20 +150,14 @@ public void makeClusters(HitFinder hitfinder, double sigma_y, double sigma_t, Da */ public void makeClusters(DataEvent event, HitFinder hitfinder) { makeClusters(hitfinder, - Parameters.SIGMA_Y_CLUSTERING, - Parameters.SIGMA_T_CLUSTERING, event); + Parameters.SIGMA_Y_CLUSTERING, + Parameters.SIGMA_T_CLUSTERING, event); } - + /** * Default constructor that initializes the list clusters as new empty list. */ public ClusterFinder() { clusters = new ArrayList<>(); } - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - } } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java index 67619066ed..d79024693c 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/HitFinder.java @@ -15,31 +15,31 @@ * *

* - * @author pilleux, Nilanga Wickramaarachchi + * @author pilleux, Nilanga Wickramaarachchi */ public class HitFinder { - + /** * list of rtof hits */ private ArrayList rtofHits; - + /** * Default constructor that initializes the list of hits as new empty lists. */ public HitFinder() { this.rtofHits = new ArrayList<>(); } - + // Getter and Setter for rtofHits public ArrayList getRTOFHits() { return rtofHits; } - + public void setRTOFHits(ArrayList rtof_hits) { this.rtofHits = rtof_hits; } - + /** * * @param event the {@link DataEvent} containing hits. @@ -64,13 +64,13 @@ public void findHits(DataEvent event) { int order = bank.getShort("order", i); int tdc = bank.getShort("TDC", i); int tot = bank.getShort("ToT", i); - + //Building a Hit RTOFRawHit hit = new RTOFRawHit(sector, layer, component, order, tdc, tot); if (hit.getEnergy() < 0.01) { continue; //energy threshold } - + //Sorting the hits into upstream and downstream bar hits //Lists are built for up/down bar to match them after if (null == hit.getType()) { @@ -86,7 +86,7 @@ public void findHits(DataEvent event) { } } }//End loop through all hits - + //Starting loop through up hits in the bar for (int i_up = 0; i_up < hit_up.size(); i_up++) { RTOFRawHit this_hit_up = hit_up.get(i_up); @@ -110,10 +110,4 @@ public void findHits(DataEvent event) { //Once all has been listed, hits are sorted by energy Collections.sort(this.rtofHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - } } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java index fdb5f13979..c6b8f7f9fc 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/Parameters.java @@ -5,12 +5,12 @@ * @author npilleux, Nilanga Wickramaarachchi */ public class Parameters { - + public static final double VEFF = 20.0;//cm/ns public static final double TDC2TIME = 0.015625;//ns per channel bin public static final double ATT_L = 160.0;//cm public static final double TOT2ENERGY = 1.956 * 0.5 /1000;//to MeV - + //public static double SIGMA_Y_TRACK_MATCHING_BAR = 20.0;//in cm public static double SIGMA_Y_CLUSTERING = 4.0;//in cm public static double SIGMA_T_CLUSTERING = 100;// in ns @@ -21,5 +21,5 @@ public class Parameters { public static void main(String[] args) { // TODO code application logic here } - + } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java index cee0b3e877..a5cf256a59 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFCluster.java @@ -11,96 +11,95 @@ * them. *

* - * @author pilleux, Nilanga Wickramaarachchi + * @author pilleux, Nilanga Wickramaarachchi */ public class RTOFCluster { - + /** * list of hits in the bars. */ ArrayList rtofHits; /** - * cluster properties:position [cm], time [ns], energy[MeV], + * cluster properties:position [cm], time [ns], energy[MeV], * type of the maximum hit (to set resolutions) and index and sector of the maximum hit. */ double x, y, z, time, energy; String typeMaxHit; int indexMaxHit, sectorMaxHit; - + public ArrayList getRTOFHits() { return rtofHits; } - + public void setRTOFHits(ArrayList rtof_hits) { this.rtofHits = rtof_hits; } - + public double getX() { return x; } - + public void setX(double x) { this.x = x; } - + public double getY() { return y; } - + public void setY(double y) { this.y = y; } - + public double getZ() { return z; } - + public void setZ(double z) { this.z = z; } - + public double getTime() { return time; } - + public void setTime(double time) { this.time = time; } - + public double getEnergy() { return energy; } - + public void setEnergy(double energy) { this.energy = energy; } - - + + public String getTypeMaxHit() { return typeMaxHit; } - + public void setTypeMaxHit(String typeMaxHit) { this.typeMaxHit = typeMaxHit; } - + public int getIndexMaxHit() { return indexMaxHit; } - + public void setIndexMaxHit(int indexMaxHit) { this.indexMaxHit = indexMaxHit; } - + public int getSectorMaxHit() { return sectorMaxHit; } - + public void setSectorMaxHit(int sectorMaxHit) { this.sectorMaxHit = sectorMaxHit; } - - + /** * Compute the cluster properties. * @@ -114,7 +113,7 @@ public final void computeClusterProperties() { this.energy = 0; double max_energy = -1; RTOFRawHit max_energy_hit = new RTOFRawHit(); - + for (int i_bar = 0; i_bar < this.rtofHits.size(); i_bar++) { RTOFHit this_rtof_hit = this.rtofHits.get(i_bar); double this_energy = this_rtof_hit.getEnergy(); @@ -124,15 +123,15 @@ public final void computeClusterProperties() { max_energy = this_energy; } } - + this.time = max_energy_hit.getTime(); this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); this.typeMaxHit = max_energy_hit.getType(); - this.sectorMaxHit = max_energy_hit.getSector(); + this.sectorMaxHit = max_energy_hit.getSector(); } - + /** * Computes the energy deposited in the bars. @@ -148,7 +147,7 @@ public double getEdepBar() { } return energy; } - + /** * Compute the cluster phi angle in radians. * @@ -158,7 +157,7 @@ public double getEdepBar() { public double getPhi() { return Math.atan2(this.y, this.x); } - + /** * Retrieve the hit with maximal energy in the cluster. It must have been @@ -187,7 +186,7 @@ public final RTOFRawHit getMaxHit() { } } } - + /** * Computes the sum of TOT in the cluster. * @@ -202,7 +201,7 @@ public int getTot() { } return tot; } - + /** * Returns the TDC of the maximal hit in the cluster. * @@ -212,7 +211,7 @@ public int getTot() { public int getTdc() { return this.getMaxHit().getTdc(); } - + /** * Constructor that initializes the list of bar hits * and computes the cluster properties. @@ -224,7 +223,7 @@ public RTOFCluster(ArrayList rtof_hits) { this.rtofHits = rtof_hits; this.computeClusterProperties(); } - + /** * Constructor that initializes the list of bar hits * and computes the cluster properties. @@ -237,12 +236,5 @@ public RTOFCluster(ArrayList rtof_hits, DataEvent event) { this.rtofHits = rtof_hits; this.computeClusterProperties(); } - - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - } - + } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java index 581559d6d9..87330bc1ce 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFHit.java @@ -8,110 +8,108 @@ * by the two hits upstream and downstream composing a full rtof hit. y position, * time and energy are defined from the up/down hits. * - * @author npilleux, Nilanga Wickramaarachchi + * @author npilleux, Nilanga Wickramaarachchi */ public class RTOFHit extends RTOFRawHit { - + //A rtof hit is the combination of a downstream and upstream hits private RTOFRawHit hitUp, hitDown; - + public RTOFRawHit getHitUp() { return hitUp; } - + public void setHitUp(RTOFRawHit hit_up) { this.hitUp = hit_up; } - + public RTOFRawHit getHitDown() { return hitDown; } - + public void setHitDown(RTOFRawHit hit_down) { this.hitDown = hit_down; } - + /** * Computes rtof hit y local coordinate from up/downstream hit times. - * + * */ public final void computeLocalY() { this.setLocalY(Parameters.VEFF/2. * (hitUp.getTime() - hitDown.getTime())); } - + /** - * Computes rtof hit y coordinate in the global coordinate system. + * Computes rtof hit y coordinate in the global coordinate system. * */ public final void computeGlobalY() { - double localY = this.getLocalY(); - - int nRows = RTOFConstants.NROWS; - double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position - double dy_long = RTOFConstants.LONG_BAR_LENGTH; - double dy_short = RTOFConstants.SHORT_BAR_LENGTH; - + double localY = this.getLocalY(); + int nRows = RTOFConstants.NROWS; + double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position + double dy_long = RTOFConstants.LONG_BAR_LENGTH; + double dy_short = RTOFConstants.SHORT_BAR_LENGTH; + double y_pos; // y coordinate of the center of bar wrt to the global coordinate system - if(hitUp.getRow()-1 < (nRows - 1)/2) - { - y_pos = y_start + ((hitUp.getRow()-1) * dy_long); - } - else if (hitUp.getRow()-1 == (nRows-1) / 2) // middle row - { - y_pos = 0; - } - else - { - y_pos = y_start + (hitUp.getRow()-2) * dy_long + dy_short; - } - - this.setY(y_pos + localY); + if(hitUp.getRow()-1 < (nRows - 1)/2) + { + y_pos = y_start + ((hitUp.getRow()-1) * dy_long); + } + else if (hitUp.getRow()-1 == (nRows-1) / 2) // middle row + { + y_pos = 0; + } + else + { + y_pos = y_start + (hitUp.getRow()-2) * dy_long + dy_short; + } + + this.setY(y_pos + localY); } - /** * Computes rtof hit time from up/downstream hit times. * The time is set as the time of the most energetic hit. * It is corrected for propagation time. - * + * */ public final void computeTime() { //We pick the most energetic signal as the timing signal double time_at_sipm, distance_to_sipm; if(this.hitDown.getEnergy() > this.hitUp.getEnergy()) { time_at_sipm = this.hitDown.getTime(); - if(this.hitDown.getRow() == 3) distance_to_sipm = RTOFConstants.SHORT_BAR_LENGTH/2. - this.getLocalY(); - else distance_to_sipm = RTOFConstants.LONG_BAR_LENGTH/2. - this.getLocalY(); + if(this.hitDown.getRow() == 3) distance_to_sipm = RTOFConstants.SHORT_BAR_LENGTH/2. - this.getLocalY(); + else distance_to_sipm = RTOFConstants.LONG_BAR_LENGTH/2. - this.getLocalY(); } else { time_at_sipm = this.hitUp.getTime(); - if(this.hitUp.getRow() == 3) distance_to_sipm = RTOFConstants.SHORT_BAR_LENGTH/2. + this.getLocalY(); + if(this.hitUp.getRow() == 3) distance_to_sipm = RTOFConstants.SHORT_BAR_LENGTH/2. + this.getLocalY(); else distance_to_sipm = RTOFConstants.LONG_BAR_LENGTH/2. + this.getLocalY(); } this.setTime(time_at_sipm - distance_to_sipm/Parameters.VEFF); } - + /** * Computes rtof hit energy from up/downstream hits. * The energy of the up/downstream hits is corrected for attenuation now that y is known. * The energy of the rtof hit is the sum of the energy of the up/downstream hits. - * + * */ public final void computeEnergy() { this.computeLocalY(); double distance_hit_to_sipm_up, distance_hit_to_sipm_down; - - if (hitUp.getRow() == 3) distance_hit_to_sipm_up = RTOFConstants.SHORT_BAR_LENGTH / 2. + this.getLocalY(); - else distance_hit_to_sipm_up = RTOFConstants.LONG_BAR_LENGTH / 2. + this.getLocalY(); - - if (hitDown.getRow() == 3) distance_hit_to_sipm_down = RTOFConstants.SHORT_BAR_LENGTH / 2. - this.getLocalY(); - else distance_hit_to_sipm_down = RTOFConstants.LONG_BAR_LENGTH / 2. - this.getLocalY(); - + + if (hitUp.getRow() == 3) distance_hit_to_sipm_up = RTOFConstants.SHORT_BAR_LENGTH / 2. + this.getLocalY(); + else distance_hit_to_sipm_up = RTOFConstants.LONG_BAR_LENGTH / 2. + this.getLocalY(); + + if (hitDown.getRow() == 3) distance_hit_to_sipm_down = RTOFConstants.SHORT_BAR_LENGTH / 2. - this.getLocalY(); + else distance_hit_to_sipm_down = RTOFConstants.LONG_BAR_LENGTH / 2. - this.getLocalY(); + double Edep_up = hitUp.getEnergy() * Math.exp(distance_hit_to_sipm_up / Parameters.ATT_L); double Edep_down = hitDown.getEnergy() * Math.exp(distance_hit_to_sipm_down / Parameters.ATT_L); this.setEnergy(Edep_up + Edep_down); } - + public RTOFHit(RTOFRawHit hit_down, RTOFRawHit hit_up) { boolean hits_match = hit_down.matchBar(hit_up); if (!hits_match) { @@ -121,28 +119,22 @@ public RTOFHit(RTOFRawHit hit_down, RTOFRawHit hit_up) { this.setOrder(2);//Fake order for bar hits this.hitUp = hit_up; this.hitDown = hit_down; - this.setSector(hit_up.getSector()); + this.setSector(hit_up.getSector()); this.setRow(hit_up.getRow()); this.setColumn(hit_up.getColumn()); this.setX(hit_up.getX()); this.setZ(hit_up.getZ()); this.computeLocalY(); - this.computeGlobalY(); + this.computeGlobalY(); this.computeTime(); this.computeEnergy(); this.setTdc((hit_down.getTdc() + hit_up.getTdc())/2); this.setTot((hit_down.getTot() + hit_up.getTot())); } - + public RTOFHit() { super(); this.setType("bar"); this.setOrder(2);//Fake order for rtof hits } - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - } } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java index 3998dc5674..3feabdc5ac 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFRawHit.java @@ -8,10 +8,10 @@ * order, TDC, ToT. Type is bar up/bar down/ bar. Stores whether * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. * - * @author npilleux, Nilanga Wickramaarachchi + * @author npilleux, Nilanga Wickramaarachchi */ public class RTOFRawHit { - + private int sector, row, column, order; private int tdc, tot; private double time, energy, x, y, z, local_y; @@ -19,135 +19,166 @@ public class RTOFRawHit { private boolean isInACluster; private int associatedClusterIndex; int idTDC; - + + /** + * Constructor for a hit in the recoil tof. Initializes the hit's sector, row, + * column, order, TDC, ToT. Sets the hit's initial state regarding + * clustering. Set up the hit's type, time, energy, and spatial coordinates. + * + * @param sector The sector of the detector where the hit occurred. + * @param row The row of the detector where the hit was detected. + * @param column The column within the row that registered the hit. + * @param order Order of the hit. + * @param tdc TDC value. + * @param tot ToT value. + * + */ + public RTOFRawHit(int sector, int row, int column, int order, int tdc, int tot) { + this.sector = sector; + this.row = row; + this.column = column; + this.order = order; + this.tdc = tdc; + this.tot = tot; + this.isInACluster = false; + + this.makeType(); + this.convertTdcToTime(); + this.convertTotToEnergy(); + this.calculateXYZ(); + } + + public RTOFRawHit() { + } + public int getSector() { return sector; } - + public void setSector(int sector) { this.sector = sector; } - + public int getRow() { return row; } - + public void setRow(int row) { this.row = row; } - + public int getOrder() { return order; } - + public void setOrder(int order) { this.order = order; } - + public int getColumn() { return column; } - + public void setColumn(int column) { this.column = column; } - + public int getTdc() { return tdc; } - + public void setTdc(int tdc) { this.tdc = tdc; } - + public int getTot() { return tot; } - + public void setTot(int tot) { this.tot = tot; } - + public double getTime() { return time; } - + public void setTime(double time) { this.time = time; } - + public double getEnergy() { return energy; } - + public void setEnergy(double energy) { this.energy = energy; } - + public double getX() { return x; } - + public void setX(double x) { this.x = x; } - + public double getY() { return y; } - + public void setY(double y) { this.y = y; } - + public double getLocalY() { return local_y; } public void setLocalY(double local_y) { - this.local_y = local_y; + this.local_y = local_y; } - + public double getZ() { return z; } - + public void setZ(double z) { this.z = z; } - + public String getType() { return type; } - + public void setType(String type) { this.type = type; } - + public boolean getIsInACluster() { return isInACluster; } - + public void setIsInACluster(boolean is_in_a_cluster) { this.isInACluster = is_in_a_cluster; } - + public int getAssociatedClusterIndex() { return associatedClusterIndex; } - + public void setAssociatedClusterIndex(int index) { this.associatedClusterIndex = index; } - + public int getIdTDC() { return idTDC; } - + public void setIdTDC(int index) { this.idTDC = index; } - + /** * Assigns a type to the hit. @@ -161,11 +192,11 @@ public final String makeType() { itype = "bar down"; } else if (this.order == 1) { itype = "bar up"; - } + } this.type = itype; return itype; } - + /** * Converts TDC to time (ns). Sets the hit time parameter to a raw time for * up/down bar hits. @@ -180,7 +211,7 @@ public final int convertTdcToTime() { return 1; } else { switch (this.type) { - case "bar up" -> { + case "bar up" -> { tdc2time = Parameters.TDC2TIME; veff = Parameters.VEFF; //The distance will be computed at barhit level when y information is available @@ -206,7 +237,7 @@ public final int convertTdcToTime() { this.time = tdc2time * this.tdc - distance_to_sipm / veff; return 0; } - + /** * Converts ToT to energy (MeV). Sets the hit energy parameter to a raw * energy for up/down bar hits. @@ -221,15 +252,15 @@ public final int convertTotToEnergy() { return 1; } else { switch (this.type) { - case "bar up" -> { + case "bar up" -> { tot2energy = Parameters.TOT2ENERGY; - //only half the information in the bar, + //only half the information in the bar, //the attenuation will be computed when the full hit is formed this.energy = tot2energy * this.tot; } case "bar down" -> { tot2energy = Parameters.TOT2ENERGY; - //only half the information in the bar, + //only half the information in the bar, //the attenuation will be computed when the full hit is formed this.energy = tot2energy * this.tot; } @@ -245,7 +276,7 @@ public final int convertTotToEnergy() { } return 0; } - + /** * Calculates spatial coordinates (cm) for the hit based on row and column number of the bar within a sector. * The row and column variables are obtained from the bank information. @@ -254,75 +285,75 @@ public final int convertTotToEnergy() { * is undefined or unsupported. */ public final int calculateXYZ() { - - // Constants for positioning - int nRows = RTOFConstants.NROWS; - double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position - double x_spacing = RTOFConstants.BAR_WIDTH; - double x_start = -(RTOFConstants.WIDTH - x_spacing)/2; // starting X position - double dy_long = RTOFConstants.LONG_BAR_LENGTH; - double dy_short = RTOFConstants.SHORT_BAR_LENGTH; - - //Position calculation - double z_pos = 0; - double x_pos = x_start + ((this.column-1) * x_spacing); - + + // Constants for positioning + int nRows = RTOFConstants.NROWS; + double y_start = -(RTOFConstants.LENGTH - RTOFConstants.LONG_BAR_LENGTH)/2; // Starting Y position + double x_spacing = RTOFConstants.BAR_WIDTH; + double x_start = -(RTOFConstants.WIDTH - x_spacing)/2; // starting X position + double dy_long = RTOFConstants.LONG_BAR_LENGTH; + double dy_short = RTOFConstants.SHORT_BAR_LENGTH; + + //Position calculation + double z_pos = 0; + double x_pos = x_start + ((this.column-1) * x_spacing); + double y_pos; - if(this.row-1 < (nRows - 1) / 2) - { - y_pos = y_start + ((this.row-1) * dy_long); - } - else if (this.row-1 == (nRows - 1) / 2) // middle row - { - y_pos = 0; - } - else - { - y_pos = y_start + (this.row -2) * dy_long + dy_short; - } - - double[] localCoords = {x_pos, y_pos, z_pos}; - - // Calculate center coordinates for the sector - double sector_x = (-1+(this.sector-1)*2)*(RTOFConstants.RADIUS)*Math.sin(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); - double sector_y = 0; - double sector_z = RTOFConstants.RADIUS*Math.cos(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); - - // Global coordinates of the sector + if(this.row-1 < (nRows - 1) / 2) + { + y_pos = y_start + ((this.row-1) * dy_long); + } + else if (this.row-1 == (nRows - 1) / 2) // middle row + { + y_pos = 0; + } + else + { + y_pos = y_start + (this.row -2) * dy_long + dy_short; + } + + double[] localCoords = {x_pos, y_pos, z_pos}; + + // Calculate center coordinates for the sector + double sector_x = (-1+(this.sector-1)*2)*(RTOFConstants.RADIUS)*Math.sin(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + double sector_y = 0; + double sector_z = RTOFConstants.RADIUS*Math.cos(Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + + // Global coordinates of the sector double[] globalCoordsSector = {sector_x, sector_y, sector_z}; - - // Rotation angle in radians + + // Rotation angle in radians double thetaY = 0; - - if(this.sector==1) thetaY = Math.toRadians(-(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); - if(this.sector==2) thetaY = Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE); - + + if(this.sector==1) thetaY = Math.toRadians(-(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE)); + if(this.sector==2) thetaY = Math.toRadians(RTOFConstants.HORIZONTAL_OPENING_ANGLE/2+RTOFConstants.HORIZONTAL_STARTING_ANGLE); + // Rotation matrix around the Y-axis double[][] Ry = { {Math.cos(thetaY), 0, Math.sin(thetaY)}, {0, 1, 0}, {-Math.sin(thetaY), 0, Math.cos(thetaY)} }; - + // Rotate local coordinates double[] rotatedCoords = new double[3]; for (int i = 0; i < 3; i++) { rotatedCoords[i] = Ry[i][0] * localCoords[0] + Ry[i][1] * localCoords[1] + Ry[i][2] * localCoords[2]; } - + // Calculate global coordinates for the hit double[] globalCoordsBar = new double[3]; for (int i = 0; i < 3; i++) { globalCoordsBar[i] = globalCoordsSector[i] + rotatedCoords[i]; } - - - this.x = globalCoordsBar[0]; + + + this.x = globalCoordsBar[0]; this.y = globalCoordsBar[1]; this.z = globalCoordsBar[2]; return 0; } - + /** * Compares two RTOFRawHit objects to check if they match in the bar. *
    @@ -355,7 +386,7 @@ public boolean matchBar(RTOFRawHit hit2match) { return this.getOrder() != hit2match.getOrder(); } } - + /** * Computes the azimuthal angle (phi) of the hit in rad. * @@ -364,41 +395,4 @@ public boolean matchBar(RTOFRawHit hit2match) { public double getPhi() { return Math.atan2(this.y, this.x); } - - /** - * Constructor for a hit in the recoil tof. Initializes the hit's sector, row, - * column, order, TDC, ToT. Sets the hit's initial state regarding - * clustering. Set up the hit's type, time, energy, and spatial coordinates. - * - * @param sector The sector of the detector where the hit occurred. - * @param row The row of the detector where the hit was detected. - * @param column The column within the row that registered the hit. - * @param order Order of the hit. - * @param tdc TDC value. - * @param tot ToT value. - * - */ - public RTOFRawHit(int sector, int row, int column, int order, int tdc, int tot) { - this.sector = sector; - this.row = row; - this.column = column; - this.order = order; - this.tdc = tdc; - this.tot = tot; - this.isInACluster = false; - - this.makeType(); - this.convertTdcToTime(); - this.convertTotToEnergy(); - this.calculateXYZ(); - } - - public RTOFRawHit() { - } - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - } } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java index aa036bcc4f..1383871435 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RecoBankWriter.java @@ -11,7 +11,7 @@ * @author pilleux, Nilanga Wickramaarachchi */ public class RecoBankWriter { - + /** * Writes the bank of recoil tof hits. * @@ -23,17 +23,17 @@ public class RecoBankWriter { * */ public static DataBank fillRTOFRawHitBank(DataEvent event, ArrayList rtofHits) { - + ArrayList hitList = new ArrayList<>(); hitList.addAll(rtofHits); - + DataBank bank = event.createBank("RTOF::hits", hitList.size()); - + if (bank == null) { System.err.println("COULD NOT CREATE A RTOF::hits BANK!!!!!!"); return null; } - + for (int i = 0; i < hitList.size(); i++) { bank.setShort("id", i, (short) (i + 1)); bank.setShort("clusterid", i, (short) hitList.get(i).getAssociatedClusterIndex()); @@ -48,7 +48,7 @@ public static DataBank fillRTOFRawHitBank(DataEvent event, ArrayList rt } return bank; } - + /** * Writes the bank of rtof clusters. * @@ -61,18 +61,18 @@ public static DataBank fillRTOFRawHitBank(DataEvent event, ArrayList rt * */ public static DataBank fillRTOFClusterBank(DataEvent event, ArrayList clusterList) { - + DataBank bank = event.createBank("RTOF::clusters", clusterList.size()); - + if (bank == null) { System.err.println("COULD NOT CREATE A RTOF::clusters BANK!!!!!!"); return null; } - + for (int i = 0; i < clusterList.size(); i++) { bank.setShort("id", i, (short) (i + 1)); bank.setShort("size", i, (short) clusterList.get(i).getRTOFHits().size()); - bank.setByte("sector", i, (byte) clusterList.get(i).getSectorMaxHit()); + bank.setByte("sector", i, (byte) clusterList.get(i).getSectorMaxHit()); bank.setFloat("time", i, (float) clusterList.get(i).getTime()); bank.setFloat("x", i, (float) (clusterList.get(i).getX())); bank.setFloat("y", i, (float) (clusterList.get(i).getY())); @@ -81,8 +81,7 @@ public static DataBank fillRTOFClusterBank(DataEvent event, ArrayList rtofHits, ArrayList clusterList) { - + DataBank hitbank = this.fillRTOFRawHitBank(event, rtofHits); if (hitbank != null) { event.appendBank(hitbank); } else { return 1; } - + DataBank clusterbank = fillRTOFClusterBank(event, clusterList); if (clusterbank != null) { event.appendBank(clusterbank); } else { return 1; } - + return 0; } - - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - } - } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCluster.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCluster.java index f258307b88..8dfed856c5 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCluster.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCluster.java @@ -9,21 +9,21 @@ /** * recoil in-layer cluster - * + * * @author bondi, devita, niccolai */ public class RtrkCluster extends ArrayList { - + private DetectorDescriptor desc = new DetectorDescriptor(DetectorType.RTRK); - private int id; + private int id; private Line3D clusterLine = new Line3D(); public int indexMaxStrip = -1; private byte clusterStatus = 1; public RtrkCluster(RtrkStrip strip){ - this.desc.setSectorLayerComponent(strip.getDescriptor().getSector(), - strip.getDescriptor().getLayer(), 0); + this.desc.setSectorLayerComponent(strip.getDescriptor().getSector(), + strip.getDescriptor().getLayer(), 0); this.add(strip); this.clusterLine.copy(strip.getLine()); this.indexMaxStrip = 0; @@ -49,7 +49,7 @@ public int getChamber() { return this.get(0).getChamber(); } - public Line3D getLine() {return this.clusterLine;} + public Line3D getLine() {return this.clusterLine;} public double getEnergy(){ double energy = 0.0; @@ -72,11 +72,11 @@ public double getSeedTime(){ if(this.indexMaxStrip >= 0 && this.indexMaxStrip < this.size()){ return this.get(indexMaxStrip).getTime(); } - return 0.0; + return 0.0; } - + public RtrkStrip getSeedStrip() { - return this.get(this.indexMaxStrip); + return this.get(this.indexMaxStrip); } public int getMaxStrip(){ @@ -107,7 +107,7 @@ public int getADC(){ public void setStatus(int val) {this.clusterStatus+=val;} - public byte getStatus() {return clusterStatus;} + public byte getStatus() {return clusterStatus;} public void setClusterId(int id){ this.id = id; @@ -115,7 +115,7 @@ public void setClusterId(int id){ strip.setClusterId(id); } } - + public void redoClusterLine(){ Point3D pointOrigin = new Point3D(0.0,0.0,0.0); @@ -138,30 +138,29 @@ public void redoClusterLine(){ pointEnd.setX(pointEnd.x()+line.end().x()*le); pointEnd.setY(pointEnd.y()+line.end().y()*le); pointEnd.setZ(pointEnd.z()+line.end().z()*le); - + logSumm += le; summE += energy; } - + this.clusterLine.set( - pointOrigin.x()/logSumm, - pointOrigin.y()/logSumm, - pointOrigin.z()/logSumm, - pointEnd.x()/logSumm, - pointEnd.y()/logSumm, - pointEnd.z()/logSumm + pointOrigin.x()/logSumm, + pointOrigin.y()/logSumm, + pointOrigin.z()/logSumm, + pointEnd.x()/logSumm, + pointEnd.y()/logSumm, + pointEnd.z()/logSumm ); } - public static List createClusters(List stripList){ - + List clusterList = new ArrayList<>(); if(!stripList.isEmpty()){ - for(int loop = 0; loop < stripList.size(); loop++){ //Loop over all strips - boolean stripAdded = false; + for(int loop = 0; loop < stripList.size(); loop++){ //Loop over all strips + boolean stripAdded = false; for(RtrkCluster cluster : clusterList) { if(cluster.addStrip(stripList.get(loop))){ //Add adjacent strip to newly seeded peak stripAdded = true; @@ -178,7 +177,7 @@ public static List createClusters(List stripList){ clusterList.get(loop).redoClusterLine(); } return clusterList; - } + } public static List getClusters(List clusters, int sector, int layer) { List selectedClusters = new ArrayList<>(); @@ -192,8 +191,8 @@ public static List getClusters(List clusters, int sect @Override public String toString(){ StringBuilder str = new StringBuilder(); - str.append(String.format("----> cluster ( %3d %3d ) ENERGY = %12.5f\n", - this.desc.getSector(),this.desc.getLayer(), this.getEnergy())); + str.append(String.format("----> cluster ( %3d %3d ) ENERGY = %12.5f\n", + this.desc.getSector(),this.desc.getLayer(), this.getEnergy())); str.append(this.clusterLine.toString()); str.append("\n"); for(RtrkStrip strip : this){ @@ -204,9 +203,5 @@ public String toString(){ return str.toString(); } - - - - } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java index ddf55032d6..6eae19bbde 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java @@ -6,7 +6,6 @@ */ public class RtrkConstants { - // geometry public final static int NSECTOR = 2; public final static int NLAYER = 6; @@ -17,12 +16,12 @@ public class RtrkConstants { public final static int[] STRIPMAX = { 351, 582, 834}; // higher strip number public final static double PITCH = 0.1; // mm public final static double[] STEREO = { 0.0, 90.0 }; - + // strips public final static double THRESHOLD = 0; public final static double ADCTOENERGY = 25/1E4; // in eV, values from gemc ADC = (uRwellC.gain*1e6*tInfos.eTot/uRwellC.w_i); with gain = 10^4 and w_i = 25 eV public final static double TDCTOTIME = 1; - + // cluster public final static double COINCTIME = 100; diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java index db98bc54c8..6dd65c1f78 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java @@ -11,7 +11,7 @@ * @author devita, niccolai */ public class RtrkCross { - + private int id; private int sector; @@ -26,12 +26,9 @@ public class RtrkCross { private double time; private int status; - - - public RtrkCross(RtrkCluster c1, RtrkCluster c2) { - Vector3D dir = c1.getLine().direction().cross(c2.getLine().direction()); + Vector3D dir = c1.getLine().direction().cross(c2.getLine().direction()); Plane3D plane = new Plane3D(c1.getLine().origin(), c1.getLine().direction().cross(dir)); Point3D point = new Point3D(); int nint = plane.intersectionSegment(c2.getLine(), point); @@ -45,11 +42,11 @@ public RtrkCross(RtrkCluster c1, RtrkCluster c2) { this.cluster2 = c2.getId(); } } - + public void setId(int id) { this.id = id; } - + public int getId() { return id; } @@ -69,19 +66,19 @@ public int getChamber() { public int getCluster1() { return cluster1; } - + public int getCluster2() { return cluster2; } - + public Point3D point() { return cross; - } - + } + public double getEnergy() { return energy; } - + public double getTime() { return time; } @@ -89,7 +86,7 @@ public double getTime() { public int getStatus() { return status; } - + public static List createCrosses(List clusters) { List crosses = new ArrayList<>(); diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java index b1f3386f22..8e4c2b4559 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java @@ -22,38 +22,35 @@ /** * * recoil reconstruction engine - * + * * @author bondi, devita, niccolai */ public class RtrkEngine extends ReconstructionEngine { - + public static Logger LOGGER = Logger.getLogger(RtrkEngine.class.getName()); - + public static RtrkStripFactory factory = new RtrkStripFactory(); - + public RtrkEngine() { super("Rtrk","niccolai","1.0"); } - + @Override public boolean init() { - + // init ConstantsManager to read constants from CCDB String variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); factory.init(cp, RtrkConstants.NREGION); - // register output banks for drop option + // register output banks for drop option this.registerOutputBank("RTRK::hits"); this.registerOutputBank("RTRK::clusters"); this.registerOutputBank("RTRK::crosses"); - + LOGGER.log(Level.INFO, "--> recoil is ready..."); return true; } - - - - + @Override public boolean processDataEventUser(DataEvent event) { @@ -65,13 +62,12 @@ public boolean processDataEventUser(DataEvent event) { return true; } - - private void writeHipoBanks(DataEvent de, - List strips, - List clusters, - List crosses){ - + private void writeHipoBanks(DataEvent de, + List strips, + List clusters, + List crosses){ + DataBank bankS = de.createBank("RTRK::hits", strips.size()); for(int h = 0; h < strips.size(); h++){ bankS.setShort("id", h, (short) strips.get(h).getId()); @@ -79,12 +75,12 @@ private void writeHipoBanks(DataEvent de, bankS.setByte("layer", h, (byte) strips.get(h).getDescriptor().getLayer()); bankS.setShort("strip", h, (short) strips.get(h).getDescriptor().getComponent()); bankS.setFloat("energy", h, (float) strips.get(h).getEnergy()); - bankS.setFloat("time", h, (float) strips.get(h).getTime()); + bankS.setFloat("time", h, (float) strips.get(h).getTime()); bankS.setShort("status", h, (short) strips.get(h).getStatus()); bankS.setShort("clusterId", h, (short) strips.get(h).getClusterId()); } - DataBank bankC = de.createBank("RTRK::clusters", clusters.size()); + DataBank bankC = de.createBank("RTRK::clusters", clusters.size()); for(int c = 0; c < clusters.size(); c++){ bankC.setShort("id", c, (short) clusters.get(c).getId()); bankC.setByte("sector", c, (byte) clusters.get(c).get(0).getDescriptor().getSector()); @@ -99,10 +95,10 @@ private void writeHipoBanks(DataEvent de, bankC.setFloat("ye", c, (float) clusters.get(c).getLine().end().y()); bankC.setFloat("ze", c, (float) clusters.get(c).getLine().end().z()); bankC.setShort("size", c, (short) clusters.get(c).size()); - bankC.setShort("status", c, (short) clusters.get(c).getStatus()); - } + bankC.setShort("status", c, (short) clusters.get(c).getStatus()); + } - DataBank bankX = de.createBank("RTRK::crosses", crosses.size()); + DataBank bankX = de.createBank("RTRK::crosses", crosses.size()); for(int c = 0; c < crosses.size(); c++){ bankX.setShort("id", c, (short) crosses.get(c).getId()); bankX.setByte("sector", c, (byte) crosses.get(c).getSector()); @@ -112,13 +108,12 @@ private void writeHipoBanks(DataEvent de, bankX.setFloat("x", c, (float) crosses.get(c).point().x()); bankX.setFloat("y", c, (float) crosses.get(c).point().y()); bankX.setFloat("z", c, (float) crosses.get(c).point().z()); - bankX.setShort("cluster1", c, (short) crosses.get(c).getCluster1()); - bankX.setShort("cluster2", c, (short) crosses.get(c).getCluster2()); - bankX.setShort("status", c, (short) crosses.get(c).getStatus()); - } + bankX.setShort("cluster1", c, (short) crosses.get(c).getCluster1()); + bankX.setShort("cluster2", c, (short) crosses.get(c).getCluster2()); + bankX.setShort("status", c, (short) crosses.get(c).getStatus()); + } de.appendBanks(bankS,bankC,bankX); } - public static void fitGauss(H1F histo) { double mean = histo.getMean(); @@ -135,7 +130,7 @@ public static void fitGauss(H1F histo) { f1.setParameter(0, amp); f1.setParameter(1, mean); f1.setParameter(2, sigma); - + if(amp>5) { f1.setParLimits(0, amp*0.2, amp*1.2); f1.setParLimits(1, mean*0.5, mean*1.5); @@ -149,36 +144,36 @@ public static void fitGauss(H1F histo) { f1.setRange(mean-2.0*sigma,mean+2.0*sigma); DataFitter.fit(f1, histo, "Q"); } - } + } public static void main (String arg[]) { - + RtrkEngine engine = new RtrkEngine(); engine.init(); - + String input = "/Users/devita/urwell3d.hipo"; - + DataGroup dg = new DataGroup(3, 2); String[] axes = {"x", "y"}; for(int il=0; il getStrips(DataEvent event, RtrkStripFactory factor int comp = bank.getShort("component", i); int adc = bank.getInt("ADC", i); double time = bank.getFloat("time", i); - - RtrkStrip strip = new RtrkStrip(sector, layer, comp); -// strip.setTriggerPhase(triggerPhase); - strip.setId(bank.trueIndex(i)+1); - strip.setADC(adc); - strip.setTDC((int) time); - strip.setEnergy(strip.ADC*RtrkConstants.ADCTOENERGY); - strip.setTime(strip.TDC*RtrkConstants.TDCTOTIME); - strip.setLine(factory.getStrip(sector, layer, comp)); - strip.setChamber(factory.getChamberIndex(comp)+1); - strip.setStatus(0); + RtrkStrip strip = new RtrkStrip(sector, layer, comp); - if(strip.getEnergy()>RtrkConstants.THRESHOLD) strips.add(strip); +// strip.setTriggerPhase(triggerPhase); +strip.setId(bank.trueIndex(i)+1); +strip.setADC(adc); +strip.setTDC((int) time); +strip.setEnergy(strip.ADC*RtrkConstants.ADCTOENERGY); +strip.setTime(strip.TDC*RtrkConstants.TDCTOTIME); +strip.setLine(factory.getStrip(sector, layer, comp)); +strip.setChamber(factory.getChamberIndex(comp)+1); +strip.setStatus(0); + +if(strip.getEnergy()>RtrkConstants.THRESHOLD) strips.add(strip); } - } + } return strips; } @Override public String toString(){ StringBuilder str = new StringBuilder(); - str.append(String.format("----> strip (%3d %3d %3d) ADC/TDC %5d %5d ENERGY = %8.5f TIME = %8.5f ", - this.desc.getSector(),this.desc.getLayer(),this.desc.getComponent(), - this.ADC,this.TDC,this.getEnergy(),this.getTime())); + str.append(String.format("----> strip (%3d %3d %3d) ADC/TDC %5d %5d ENERGY = %8.5f TIME = %8.5f ", + this.desc.getSector(),this.desc.getLayer(),this.desc.getComponent(), + this.ADC,this.TDC,this.getEnergy(),this.getTime())); return str.toString(); } } From 45b88844d02015dbafdc7618d02c5f69484398fc Mon Sep 17 00:00:00 2001 From: Silvia Niccolai Date: Fri, 12 Jun 2026 10:53:57 -0400 Subject: [PATCH 4/7] Changed trk to TRK everywhere --- ...{RtrkConstants.java => RTRKConstants.java} | 2 +- ...nt4Factory.java => RTRKGeant4Factory.java} | 0 ...tripFactory.java => RTRKStripFactory.java} | 48 +++++++++---------- .../{RtrkCluster.java => RTRKCluster.java} | 34 ++++++------- ...{RtrkConstants.java => RTRKConstants.java} | 2 +- .../trk/{RtrkCross.java => RTRKCross.java} | 24 +++++----- .../trk/{RtrkEngine.java => RTRKEngine.java} | 38 +++++++-------- .../trk/{RtrkStrip.java => RTRKStrip.java} | 26 +++++----- 8 files changed, 87 insertions(+), 87 deletions(-) rename common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/{RtrkConstants.java => RTRKConstants.java} (99%) rename common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/{RtrkGeant4Factory.java => RTRKGeant4Factory.java} (100%) rename common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/{RtrkStripFactory.java => RTRKStripFactory.java} (91%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/{RtrkCluster.java => RTRKCluster.java} (87%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/{RtrkConstants.java => RTRKConstants.java} (97%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/{RtrkCross.java => RTRKCross.java} (75%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/{RtrkEngine.java => RTRKEngine.java} (90%) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/{RtrkStrip.java => RTRKStrip.java} (87%) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKConstants.java similarity index 99% rename from common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java rename to common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKConstants.java index 83585b4d5f..5df67bf460 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkConstants.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKConstants.java @@ -2,7 +2,7 @@ import org.jlab.detector.calib.utils.DatabaseConstantProvider; -public class RtrkConstants { +public class RTRKConstants { private final static String CCDBPATH = "/geometry/recoil/trk/"; diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKGeant4Factory.java similarity index 100% rename from common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkGeant4Factory.java rename to common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKGeant4Factory.java diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKStripFactory.java similarity index 91% rename from common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java rename to common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKStripFactory.java index 73be7ed32f..7368335c7e 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RtrkStripFactory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKStripFactory.java @@ -18,9 +18,9 @@ * * @author bondi, niccolai */ -public final class RtrkStripFactory { +public final class RTRKStripFactory { - private RtrkGeant4Factory factory; + private RTRKGeant4Factory factory; private IndexedList globalStrips = new IndexedList(3); private IndexedList localStrips = new IndexedList(3); private IndexedList planeStrips = new IndexedList(3); @@ -29,16 +29,16 @@ public final class RtrkStripFactory { private int nChambers; private int nLayers; - public RtrkStripFactory() { + public RTRKStripFactory() { } /** * Create the strip factory based on constants from CCDB. - * Currently constants are defined in the RtrkConstants class. + * Currently constants are defined in the RTRKConstants class. * They will be moved to CCDB when finalized). * @param cp database provide */ - public RtrkStripFactory(DatabaseConstantProvider cp) { + public RTRKStripFactory(DatabaseConstantProvider cp) { this.init(cp); } @@ -52,12 +52,12 @@ public void init(DatabaseConstantProvider cp) { /** * Create the strip factory based on constants from CCDB. - * Currently constants are defined in the RtrkConstants class. + * Currently constants are defined in the RTRKConstants class. * They will be moved to CCDB when finalized). * @param cp database provide * @param regions */ - public RtrkStripFactory(DatabaseConstantProvider cp, int regions) { + public RTRKStripFactory(DatabaseConstantProvider cp, int regions) { this.init(cp, regions); } @@ -67,11 +67,11 @@ public RtrkStripFactory(DatabaseConstantProvider cp, int regions) { * @param regions */ public void init(DatabaseConstantProvider cp, int regions) { - factory = new RtrkGeant4Factory(cp, regions); - nRegions = Math.min(RtrkConstants.NMAXREGIONS, regions); - nSectors = RtrkConstants.NSECTORS; - nChambers = RtrkConstants.NCHAMBERS; - nLayers = RtrkConstants.NLAYERS; + factory = new RTRKGeant4Factory(cp, regions); + nRegions = Math.min(RTRKConstants.NMAXREGIONS, regions); + nSectors = RTRKConstants.NSECTORS; + nChambers = RTRKConstants.NCHAMBERS; + nLayers = RTRKConstants.NLAYERS; this.fillStripLists(); // this.fillPlaneLists(); } @@ -114,8 +114,8 @@ public int getNStripChamber(int ichamber, int regions) { * * number of strip in AB** */ - int nAB = (int) (2 * xHalf / RtrkConstants.PITCH); - int nAC = (int) (2 * yHalf / RtrkConstants.PITCH); + int nAB = (int) (2 * xHalf / RTRKConstants.PITCH); + int nAC = (int) (2 * yHalf / RTRKConstants.PITCH); int nStrips = nAB + nAC; @@ -190,9 +190,9 @@ private Line3d createStrip(int sector, int region, int layer, int strip) { DY = -yHalf; } // ID of the strip - int nS = (int) (DY / RtrkConstants.PITCH); + int nS = (int) (DY / RTRKConstants.PITCH); int nCStrip = nS + (cStrip - 1); - double c = nCStrip * RtrkConstants.PITCH; + double c = nCStrip * RTRKConstants.PITCH; // Take 2 points in the strip straight line. They needs to define Line object //u strips @@ -305,9 +305,9 @@ private void fillStripLists() { if ((layer) % 2 != 0) { //u strip DY = -yHalf; } - int nS = (int) (DY / RtrkConstants.PITCH); + int nS = (int) (DY / RTRKConstants.PITCH); int nCStrip = nS + (cStrip - 1); - double c = nCStrip * RtrkConstants.PITCH; + double c = nCStrip * RTRKConstants.PITCH; if (((layer) % 2 == 0 && c>-xHalf && c-yHalf && c-xHalf && c-yHalf && c { +public class RTRKCluster extends ArrayList { private DetectorDescriptor desc = new DetectorDescriptor(DetectorType.RTRK); @@ -21,7 +21,7 @@ public class RtrkCluster extends ArrayList { public int indexMaxStrip = -1; private byte clusterStatus = 1; - public RtrkCluster(RtrkStrip strip){ + public RTRKCluster(RTRKStrip strip){ this.desc.setSectorLayerComponent(strip.getDescriptor().getSector(), strip.getDescriptor().getLayer(), 0); this.add(strip); @@ -53,7 +53,7 @@ public int getChamber() { public double getEnergy(){ double energy = 0.0; - for(RtrkStrip strip : this){ + for(RTRKStrip strip : this){ energy += strip.getEnergy(); } return energy; @@ -61,7 +61,7 @@ public double getEnergy(){ public double getTime(){ double time = 0.0; - for(RtrkStrip strip : this){ + for(RTRKStrip strip : this){ time += strip.getTime()*strip.getEnergy(); } time /= this.getEnergy(); @@ -75,7 +75,7 @@ public double getSeedTime(){ return 0.0; } - public RtrkStrip getSeedStrip() { + public RTRKStrip getSeedStrip() { return this.get(this.indexMaxStrip); } @@ -83,8 +83,8 @@ public int getMaxStrip(){ return this.get(this.indexMaxStrip).getDescriptor().getComponent(); } - public boolean addStrip(RtrkStrip strip){ - for(RtrkStrip s : this){ + public boolean addStrip(RTRKStrip strip){ + for(RTRKStrip s : this){ if(s.isNeighbour(strip)){ this.add(strip); if(strip.getEnergy()>this.get(indexMaxStrip).getEnergy()){ @@ -99,7 +99,7 @@ public boolean addStrip(RtrkStrip strip){ public int getADC(){ int adc = 0; - for(RtrkStrip s : this){ + for(RTRKStrip s : this){ adc+= s.getADC(); } return adc; @@ -111,7 +111,7 @@ public int getADC(){ public void setClusterId(int id){ this.id = id; - for(RtrkStrip strip : this){ + for(RTRKStrip strip : this){ strip.setClusterId(id); } } @@ -154,20 +154,20 @@ public void redoClusterLine(){ ); } - public static List createClusters(List stripList){ + public static List createClusters(List stripList){ - List clusterList = new ArrayList<>(); + List clusterList = new ArrayList<>(); if(!stripList.isEmpty()){ for(int loop = 0; loop < stripList.size(); loop++){ //Loop over all strips boolean stripAdded = false; - for(RtrkCluster cluster : clusterList) { + for(RTRKCluster cluster : clusterList) { if(cluster.addStrip(stripList.get(loop))){ //Add adjacent strip to newly seeded peak stripAdded = true; } } if(!stripAdded){ - RtrkCluster newPeak = new RtrkCluster(stripList.get(loop)); //Non-adjacent strip seeds new peak + RTRKCluster newPeak = new RTRKCluster(stripList.get(loop)); //Non-adjacent strip seeds new peak clusterList.add(newPeak); } } @@ -179,9 +179,9 @@ public static List createClusters(List stripList){ return clusterList; } - public static List getClusters(List clusters, int sector, int layer) { - List selectedClusters = new ArrayList<>(); - for(RtrkCluster cluster : clusters) { + public static List getClusters(List clusters, int sector, int layer) { + List selectedClusters = new ArrayList<>(); + for(RTRKCluster cluster : clusters) { if(cluster.getSector()==sector && cluster.getLayer()==layer) selectedClusters.add(cluster); } @@ -195,7 +195,7 @@ public String toString(){ this.desc.getSector(),this.desc.getLayer(), this.getEnergy())); str.append(this.clusterLine.toString()); str.append("\n"); - for(RtrkStrip strip : this){ + for(RTRKStrip strip : this){ str.append("\t\t"); str.append(strip.toString()); str.append("\n"); diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKConstants.java similarity index 97% rename from reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java rename to reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKConstants.java index 6eae19bbde..1f3cfc209c 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkConstants.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKConstants.java @@ -4,7 +4,7 @@ * * @author bondi, devita,niccolai */ -public class RtrkConstants { +public class RTRKConstants { // geometry public final static int NSECTOR = 2; diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCross.java similarity index 75% rename from reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java rename to reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCross.java index 6dd65c1f78..87498469da 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkCross.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCross.java @@ -10,7 +10,7 @@ * recoil V-W clusters * @author devita, niccolai */ -public class RtrkCross { +public class RTRKCross { private int id; @@ -26,7 +26,7 @@ public class RtrkCross { private double time; private int status; - public RtrkCross(RtrkCluster c1, RtrkCluster c2) { + public RTRKCross(RTRKCluster c1, RTRKCluster c2) { Vector3D dir = c1.getLine().direction().cross(c2.getLine().direction()); Plane3D plane = new Plane3D(c1.getLine().origin(), c1.getLine().direction().cross(dir)); @@ -34,7 +34,7 @@ public RtrkCross(RtrkCluster c1, RtrkCluster c2) { int nint = plane.intersectionSegment(c2.getLine(), point); if(nint==1) { this.sector = c1.getSector(); - this.region = (c1.getLayer()-1)/(RtrkConstants.NLAYER/RtrkConstants.NREGION)+1; + this.region = (c1.getLayer()-1)/(RTRKConstants.NLAYER/RTRKConstants.NREGION)+1; this.cross = point; this.energy = c1.getEnergy() + c2.getEnergy(); this.time = (c1.getTime() + c2.getTime())/2; @@ -87,20 +87,20 @@ public int getStatus() { return status; } - public static List createCrosses(List clusters) { + public static List createCrosses(List clusters) { - List crosses = new ArrayList<>(); + List crosses = new ArrayList<>(); - for(int is=0; is clustersV = RtrkCluster.getClusters(clusters, is+1, (RtrkConstants.NLAYER/RtrkConstants.NREGION)*ir+1); - List clustersW = RtrkCluster.getClusters(clusters, is+1, (RtrkConstants.NLAYER/RtrkConstants.NREGION)*ir+2); + for(int is=0; is clustersV = RTRKCluster.getClusters(clusters, is+1, (RTRKConstants.NLAYER/RTRKConstants.NREGION)*ir+1); + List clustersW = RTRKCluster.getClusters(clusters, is+1, (RTRKConstants.NLAYER/RTRKConstants.NREGION)*ir+2); - for(RtrkCluster v : clustersV) { - for(RtrkCluster w : clustersW) { + for(RTRKCluster v : clustersV) { + for(RTRKCluster w : clustersW) { if(v.getChamber()==w.getChamber()) { - RtrkCross cross = new RtrkCross(v, w); + RTRKCross cross = new RTRKCross(v, w); if(cross.point()!=null) crosses.add(cross); cross.setId(crosses.size()); } diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKEngine.java similarity index 90% rename from reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java rename to reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKEngine.java index 8e4c2b4559..c743d8fad0 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RtrkEngine.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKEngine.java @@ -8,7 +8,7 @@ import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.detector.base.DetectorType; import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.detector.geant4.v2.recoil.trk.RtrkStripFactory; +import org.jlab.detector.geant4.v2.recoil.trk.RTRKStripFactory; import org.jlab.geom.prim.Point3D; import org.jlab.groot.data.H1F; import org.jlab.groot.fitter.DataFitter; @@ -25,14 +25,14 @@ * * @author bondi, devita, niccolai */ -public class RtrkEngine extends ReconstructionEngine { +public class RTRKEngine extends ReconstructionEngine { - public static Logger LOGGER = Logger.getLogger(RtrkEngine.class.getName()); + public static Logger LOGGER = Logger.getLogger(RTRKEngine.class.getName()); - public static RtrkStripFactory factory = new RtrkStripFactory(); + public static RTRKStripFactory factory = new RTRKStripFactory(); - public RtrkEngine() { - super("Rtrk","niccolai","1.0"); + public RTRKEngine() { + super("RTRK","niccolai","1.0"); } @Override @@ -41,7 +41,7 @@ public boolean init() { // init ConstantsManager to read constants from CCDB String variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); - factory.init(cp, RtrkConstants.NREGION); + factory.init(cp, RTRKConstants.NREGION); // register output banks for drop option this.registerOutputBank("RTRK::hits"); this.registerOutputBank("RTRK::clusters"); @@ -54,9 +54,9 @@ public boolean init() { @Override public boolean processDataEventUser(DataEvent event) { - List strips = RtrkStrip.getStrips(event, factory, this.getConstantsManager()); - List clusters = RtrkCluster.createClusters(strips); - List crosses = RtrkCross.createCrosses(clusters); + List strips = RTRKStrip.getStrips(event, factory, this.getConstantsManager()); + List clusters = RTRKCluster.createClusters(strips); + List crosses = RTRKCross.createCrosses(clusters); this.writeHipoBanks(event, strips, clusters, crosses); @@ -64,9 +64,9 @@ public boolean processDataEventUser(DataEvent event) { } private void writeHipoBanks(DataEvent de, - List strips, - List clusters, - List crosses){ + List strips, + List clusters, + List crosses){ DataBank bankS = de.createBank("RTRK::hits", strips.size()); for(int h = 0; h < strips.size(); h++){ @@ -148,14 +148,14 @@ public static void fitGauss(H1F histo) { public static void main (String arg[]) { - RtrkEngine engine = new RtrkEngine(); + RTRKEngine engine = new RTRKEngine(); engine.init(); String input = "/Users/devita/urwell3d.hipo"; DataGroup dg = new DataGroup(3, 2); String[] axes = {"x", "y"}; - for(int il=0; il this.desc.getSector()) return -1; if(ob.getDescriptor().getLayer() < this.desc.getLayer()) return 1; @@ -159,9 +159,9 @@ public int compareTo(Object o) { return -1; } - public static List getStrips(DataEvent event, RtrkStripFactory factory, ConstantsManager ccdb) { + public static List getStrips(DataEvent event, RTRKStripFactory factory, ConstantsManager ccdb) { - List strips = new ArrayList<>(); + List strips = new ArrayList<>(); if(event.hasBank("RTRK::adc")){ RawDataBank bank = new RawDataBank("RTRK::adc"); @@ -174,19 +174,19 @@ public static List getStrips(DataEvent event, RtrkStripFactory factor int adc = bank.getInt("ADC", i); double time = bank.getFloat("time", i); - RtrkStrip strip = new RtrkStrip(sector, layer, comp); + RTRKStrip strip = new RTRKStrip(sector, layer, comp); // strip.setTriggerPhase(triggerPhase); strip.setId(bank.trueIndex(i)+1); strip.setADC(adc); strip.setTDC((int) time); -strip.setEnergy(strip.ADC*RtrkConstants.ADCTOENERGY); -strip.setTime(strip.TDC*RtrkConstants.TDCTOTIME); +strip.setEnergy(strip.ADC*RTRKConstants.ADCTOENERGY); +strip.setTime(strip.TDC*RTRKConstants.TDCTOTIME); strip.setLine(factory.getStrip(sector, layer, comp)); strip.setChamber(factory.getChamberIndex(comp)+1); strip.setStatus(0); -if(strip.getEnergy()>RtrkConstants.THRESHOLD) strips.add(strip); +if(strip.getEnergy()>RTRKConstants.THRESHOLD) strips.add(strip); } } From 0f26056e900067dc9635a135f8a44f5e2fe53a9b Mon Sep 17 00:00:00 2001 From: Silvia Niccolai Date: Fri, 12 Jun 2026 11:30:56 -0400 Subject: [PATCH 5/7] fixed bank structure and a couple of bugs following the naming changes --- .../v2/recoil/trk/RTRKGeant4Factory.java | 81 ++++++++-------- etc/bankdefs/hipo4/rtof.json | 92 ++++--------------- .../jlab/service/recoil/trk/RTRKStrip.java | 2 +- 3 files changed, 59 insertions(+), 116 deletions(-) diff --git a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKGeant4Factory.java b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKGeant4Factory.java index 2af3f96023..d4362e05d3 100644 --- a/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKGeant4Factory.java +++ b/common-tools/clas-jcsg/src/main/java/org/jlab/detector/geant4/v2/recoil/trk/RTRKGeant4Factory.java @@ -12,26 +12,26 @@ * * @author bondi, niccolai */ -public final class RtrkGeant4Factory extends Geant4Factory { +public final class RTRKGeant4Factory extends Geant4Factory { - private int nRegions = RtrkConstants.NREGIONS; - private int nSectors = RtrkConstants.NSECTORS; - private int nChambers = RtrkConstants.NCHAMBERS; + private int nRegions = RTRKConstants.NREGIONS; + private int nSectors = RTRKConstants.NSECTORS; + private int nChambers = RTRKConstants.NCHAMBERS; /** * Create the URWELL full geometry * @param cp * @param nRegions */ - public RtrkGeant4Factory( DatabaseConstantProvider cp, int nRegions) { - RtrkConstants.connect(cp ); + public RTRKGeant4Factory( DatabaseConstantProvider cp, int nRegions) { + RTRKConstants.connect(cp ); this.init(cp, nRegions); } public void init(DatabaseConstantProvider cp, int regions ) { motherVolume = new G4World("root"); - nRegions = Math.min(RtrkConstants.NMAXREGIONS, regions); + nRegions = Math.min(RTRKConstants.NMAXREGIONS, regions); for (int iregion = 0; iregion (volume.getName().contains(volName))) .findAny() @@ -285,8 +284,8 @@ public Geant4Basic getSectorVolume(int region, int sector) { public static void main(String[] args) { DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - RtrkConstants.connect(cp); - RtrkGeant4Factory factory = new RtrkGeant4Factory(cp, 1); + RTRKConstants.connect(cp); + RTRKGeant4Factory factory = new RTRKGeant4Factory(cp, 1); factory.getAllVolumes().forEach(volume -> { System.out.println(volume.gemcString()); }); diff --git a/etc/bankdefs/hipo4/rtof.json b/etc/bankdefs/hipo4/rtof.json index 48a1caa28a..a5ae1f07d2 100644 --- a/etc/bankdefs/hipo4/rtof.json +++ b/etc/bankdefs/hipo4/rtof.json @@ -5,47 +5,16 @@ "item": 21, "info": "Reconstructed RTOF hits", "entries": [ - { - "name": "id", - "type": "S", - "info": "hit id" - }, { - "name": "sector", - "type": "B", - "info": "recoil tof sector" - }, { - "name": "layer", - "type": "B", - "info": "recoil tof layer" - },{ - "name": "component", - "type": "B", - "info": "recoil tof component" - },{ - "name": "time", - "type": "F", - "info": "time in ns" - },{ - "name": "x", - "type": "F", - "info": "x position in cm" - }, { - "name": "y", - "type": "F", - "info": "y position in cm" - }, { - "name": "z", - "type": "F", - "info": "z position in cm" - },{ - "name": "energy", - "type": "F", - "info": "deposited energy in MeV" - },{ - "name": "clusterid", - "type": "S", - "info": "id of cluster to which the hit was associated" - } + {"name": "id", "type": "S", "info": "hit id"}, + {"name": "sector", "type": "B", "info": "recoil tof sector"}, + {"name": "layer", "type": "B", "info": "recoil tof layer"}, + {"name": "component", "type": "B", "info": "recoil tof component"}, + {"name": "time", "type": "F", "info": "time in ns"}, + {"name": "x", "type": "F", "info": "x position in cm"}, + {"name": "y", "type": "F", "info": "y position in cm"}, + {"name": "z", "type": "F", "info": "z position in cm"}, + {"name": "energy", "type": "F", "info": "deposited energy in MeV"}, + {"name": "clusterid", "type": "S", "info": "id of cluster to which the hit was associated"} ] },{ "name": "RTOF::clusters", @@ -53,39 +22,14 @@ "item": 22, "info": "Clusters in RTOF", "entries": [ - { - "name": "id", - "type": "S", - "info": "hit id" - }, { - "name": "size", - "type": "S", - "info": "number of hits from the bars" - },{ - "name": "sector", - "type": "B", - "info": "sector number" - },{ - "name": "time", - "type": "F", - "info": "time in ns" - },{ - "name": "x", - "type": "F", - "info": "x position in cm" - }, { - "name": "y", - "type": "F", - "info": "y position in cm" - }, { - "name": "z", - "type": "F", - "info": "z position in cm" - },{ - "name": "energy", - "type": "F", - "info": "energy in MeV" - } + {"name": "id", "type": "S", "info": "hit id"}, + {"name": "size", "type": "S", "info": "number of hits from the bars"}, + {"name": "sector", "type": "B", "info": "sector number"}, + {"name": "time", "type": "F", "info": "time in ns"}, + {"name": "x", "type": "F", "info": "x position in cm"}, + {"name": "y", "type": "F", "info": "y position in cm"}, + {"name": "z", "type": "F", "info": "z position in cm"}, + {"name": "energy", "type": "F", "info": "energy in MeV"} ] } ] diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKStrip.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKStrip.java index 717aaad032..bded0fcabc 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKStrip.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKStrip.java @@ -6,7 +6,7 @@ import org.jlab.detector.base.DetectorDescriptor; import org.jlab.detector.base.DetectorType; import org.jlab.detector.calib.utils.ConstantsManager; -import org.jlab.detector.geant4.v2.recoil.trk.RtrkStripFactory; +import org.jlab.detector.geant4.v2.recoil.trk.RTRKStripFactory; import org.jlab.geom.prim.Line3D; import org.jlab.io.base.DataEvent; From c53b310fc0c71ce2ccdf46712c0db31af39c1969 Mon Sep 17 00:00:00 2001 From: Silvia Niccolai Date: Fri, 12 Jun 2026 11:57:11 -0400 Subject: [PATCH 6/7] addressed the comment about the constants already defined in the geometry service --- .../java/org/jlab/service/recoil/trk/RTRKCluster.java | 1 + .../java/org/jlab/service/recoil/trk/RTRKCross.java | 11 ++++++----- .../java/org/jlab/service/recoil/trk/RTRKEngine.java | 7 ++++--- .../trk/{RTRKConstants.java => RTRKParameters.java} | 6 +++--- .../java/org/jlab/service/recoil/trk/RTRKStrip.java | 9 +++++---- 5 files changed, 19 insertions(+), 15 deletions(-) rename reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/{RTRKConstants.java => RTRKParameters.java} (87%) diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCluster.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCluster.java index a4cee432ca..c8c2ac152f 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCluster.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCluster.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import org.jlab.detector.geant4.v2.recoil.trk.RTRKConstants; import org.jlab.detector.base.DetectorDescriptor; import org.jlab.detector.base.DetectorType; import org.jlab.geom.prim.Line3D; diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCross.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCross.java index 87498469da..4ff69ec157 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCross.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKCross.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import org.jlab.detector.geant4.v2.recoil.trk.RTRKConstants; import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; @@ -34,7 +35,7 @@ public RTRKCross(RTRKCluster c1, RTRKCluster c2) { int nint = plane.intersectionSegment(c2.getLine(), point); if(nint==1) { this.sector = c1.getSector(); - this.region = (c1.getLayer()-1)/(RTRKConstants.NLAYER/RTRKConstants.NREGION)+1; + this.region = (c1.getLayer()-1)/(RTRKConstants.NLAYERS/RTRKConstants.NREGIONS)+1; this.cross = point; this.energy = c1.getEnergy() + c2.getEnergy(); this.time = (c1.getTime() + c2.getTime())/2; @@ -91,10 +92,10 @@ public static List createCrosses(List clusters) { List crosses = new ArrayList<>(); - for(int is=0; is clustersV = RTRKCluster.getClusters(clusters, is+1, (RTRKConstants.NLAYER/RTRKConstants.NREGION)*ir+1); - List clustersW = RTRKCluster.getClusters(clusters, is+1, (RTRKConstants.NLAYER/RTRKConstants.NREGION)*ir+2); + for(int is=0; is clustersV = RTRKCluster.getClusters(clusters, is+1, (RTRKConstants.NLAYERS/RTRKConstants.NREGIONS)*ir+1); + List clustersW = RTRKCluster.getClusters(clusters, is+1, (RTRKConstants.NLAYERS/RTRKConstants.NREGIONS)*ir+2); for(RTRKCluster v : clustersV) { for(RTRKCluster w : clustersW) { diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKEngine.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKEngine.java index c743d8fad0..e8263b3533 100644 --- a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKEngine.java +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/trk/RTRKEngine.java @@ -8,6 +8,7 @@ import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.detector.base.DetectorType; import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.detector.geant4.v2.recoil.trk.RTRKConstants; import org.jlab.detector.geant4.v2.recoil.trk.RTRKStripFactory; import org.jlab.geom.prim.Point3D; import org.jlab.groot.data.H1F; @@ -41,7 +42,7 @@ public boolean init() { // init ConstantsManager to read constants from CCDB String variationName = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, variationName); - factory.init(cp, RTRKConstants.NREGION); + factory.init(cp, RTRKConstants.NREGIONS); // register output banks for drop option this.registerOutputBank("RTRK::hits"); this.registerOutputBank("RTRK::clusters"); @@ -155,7 +156,7 @@ public static void main (String arg[]) { DataGroup dg = new DataGroup(3, 2); String[] axes = {"x", "y"}; - for(int il=0; il getStrips(DataEvent event, RTRKStripFactory factor strip.setId(bank.trueIndex(i)+1); strip.setADC(adc); strip.setTDC((int) time); -strip.setEnergy(strip.ADC*RTRKConstants.ADCTOENERGY); -strip.setTime(strip.TDC*RTRKConstants.TDCTOTIME); +strip.setEnergy(strip.ADC*RTRKParameters.ADCTOENERGY); +strip.setTime(strip.TDC*RTRKParameters.TDCTOTIME); strip.setLine(factory.getStrip(sector, layer, comp)); strip.setChamber(factory.getChamberIndex(comp)+1); strip.setStatus(0); -if(strip.getEnergy()>RTRKConstants.THRESHOLD) strips.add(strip); +if(strip.getEnergy()>RTRKParameters.THRESHOLD) strips.add(strip); } } From b6db1a353f0cab36b5df04de041d53939ddee2cd Mon Sep 17 00:00:00 2001 From: niwgit Date: Fri, 12 Jun 2026 12:28:15 -0400 Subject: [PATCH 7/7] Included engine for RTOF --- .../jlab/service/recoil/tof/RTOFEngine.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFEngine.java diff --git a/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFEngine.java b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFEngine.java new file mode 100644 index 0000000000..0bde218987 --- /dev/null +++ b/reconstruction/recoil/src/main/java/org/jlab/service/recoil/tof/RTOFEngine.java @@ -0,0 +1,82 @@ +package org.jlab.service.recoil.tof; + +import java.util.ArrayList; + +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; + +import java.util.concurrent.atomic.AtomicInteger; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.service.recoil.tof.RecoBankWriter; +import org.jlab.service.recoil.tof.RTOFCluster; +import org.jlab.service.recoil.tof.ClusterFinder; +import org.jlab.service.recoil.tof.RTOFRawHit; +import org.jlab.service.recoil.tof.RTOFHit; +import org.jlab.service.recoil.tof.HitFinder; + +/** + * Service to return reconstructed RTOF hits and clusters + * + * @author npilleux, Nilanga Wickramaarachchi + * + */ +public class RTOFEngine extends ReconstructionEngine { + + public RTOFEngine() { + super("RTOF", "Nilanga Wickramaarachchi", "1.0"); + } + + RecoBankWriter rbc; + + private final AtomicInteger run = new AtomicInteger(0); + + @Override + public boolean processDataEventUser(DataEvent event) { + + if (!event.hasBank("RUN::config")) { + return true; + } + + + //Hit finder init + HitFinder hitfinder = new HitFinder(); + hitfinder.findHits(event); + + ArrayList RTOFHits = hitfinder.getRTOFHits(); + + //Exit if hit list is empty + if (RTOFHits.isEmpty()) { + // System.out.println("No hits : "); + // event.show(); + return true; + } + + ClusterFinder clusterFinder = new ClusterFinder(); + clusterFinder.makeClusters(event,hitfinder); + ArrayList Clusters = clusterFinder.getClusters(); + + if (RTOFHits.size() != 0) { + rbc.appendRTOFBanks(event, RTOFHits, Clusters); + } + return true; + } + + @Override + public boolean init() { + rbc = new RecoBankWriter(); + + this.registerOutputBank("RTOF::hits", "RTOF::clusters"); + + return true; + } + + public static void main(String arg[]) { + } + + @Override + public void detectorChanged(int run) {} + +} +