From ca09bc64cc6bbeb0ffc686bd0bc7589d981c06f5 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 13 Jan 2025 10:51:29 -0600 Subject: [PATCH 01/82] Definition of atof hits --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java new file mode 100644 index 0000000000..ce2d3d181a --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -0,0 +1,238 @@ +package org.jlab.rec.atof.Hit; + +import org.jlab.geom.base.*; +import org.jlab.geom.detector.alert.ATOF.*; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.prim.Point3D; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; + +/** + * + * @author npilleux + */ +public class AtofHit { + + private int sector, layer, component, order; + private int TDC, ToT; + private double time, energy, x, y, z; + private String type; + + public int getSector() { + return sector; + } + + public void setSector(int sector) { + this.sector = sector; + } + + public int getLayer() { + return layer; + } + + public void setLayer(int layer) { + this.layer = layer; + } + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } + + public int getComponent() { + return component; + } + + public void setComponent(int component) { + this.component = component; + } + + 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 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 String makeType(){ + String type = "undefined"; + if(this.component == 10 && this.order==0) type = "bar down"; + else if(this.component == 10 && this.order==1) type = "bar up"; + else if(this.component < 10) type = "wedge"; + this.type = type; + return type; + } + + public int TDC_to_time() + { + double some_conversion = 0; + if(this.type == "wedge") + { + some_conversion = 10;//read calib constants here + } + else if(this.type == "bar up") + { + some_conversion = 10; + } + else if(this.type == "bar down") + { + some_conversion = 10; + } + else + { + return 0; + } + this.time = some_conversion * this.TDC; + return 1; + } + + public int ToT_to_energy() + { + double some_conversion = 0; + if(this.type == "wedge") + { + some_conversion = 10;//read calib constants here + } + else if(this.type == "bar up") + { + some_conversion = 10; + } + else if(this.type == "bar down") + { + some_conversion = 10; + } + else + { + return 0; + } + this.energy = some_conversion * this.ToT; + return 1; + } + + public int slc_to_xyz(Detector atof) + { + int sl = 999; + if(this.type == "wedge") sl = 1; + else if(this.type == "bar up" || this.type == "bar down") sl = 0; + else return 0; + + Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); + Point3D midpoint = comp.getMidpoint(); + this.x = midpoint.x(); + this.y = midpoint.y(); + this.z = midpoint.z(); + return 1; + } + + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) + { + this.sector = sector; + this.layer = layer; + this.component = component; + this.order = order; + this.TDC = tdc; + this.ToT = tot; + + this.makeType(); + int is_ok = this.TDC_to_time(); + if(is_ok==1) is_ok = this.ToT_to_energy(); + if(is_ok==1) is_ok = this.slc_to_xyz(atof); + } + + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + DataBank bank = event.getBank("ATOF::tdc"); + int nt = bank.rows(); // number of tracks + + for (int i = 0; i < nt; i++) { + int sector = bank.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + System.out.print(hit.getX() + "\n"); + } + } + } +} + From f21f8c1d0845e587759d47eea5dda9b7db158352 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 13 Jan 2025 11:59:02 -0600 Subject: [PATCH 02/82] Definition of bar hits --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 10 +- .../java/org/jlab/rec/atof/Hit/BarHit.java | 179 ++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index ce2d3d181a..322eb8bf1f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -185,6 +185,15 @@ public int slc_to_xyz(Detector atof) return 1; } + public boolean barmatch(AtofHit hit2match) + { + if(this.getSector() != hit2match.getSector()) return false; //System.out.print("Two hits in different sectors \n"); + else if(this.getLayer() != hit2match.getLayer()) return false; //System.out.print("Two hits in different layers \n"); + else if(this.getComponent() != 10 || hit2match.getComponent() != 10) return false; //System.out.print("At least one hit is not in the bar \n"); + else if(this.getOrder() == hit2match.getOrder()) return false; //System.out.print("Two hits in same SiPM \n"); + else return true; + } + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { this.sector = sector; @@ -200,7 +209,6 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot if(is_ok==1) is_ok = this.slc_to_xyz(atof); } - /** * @param args the command line arguments */ diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java new file mode 100644 index 0000000000..202f943a4a --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -0,0 +1,179 @@ +package org.jlab.rec.atof.Hit; + +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import java.util.ArrayList; + +/** + * + * @author npilleux + */ +public class BarHit { + + //A bar hit is the combination of a downstream and upstream hits + private AtofHit hit_up, hit_down; + private double x,y,z, time, energy; + int sector, layer; + + public AtofHit getHitUp() { + return hit_up; + } + + public void setHitUp(AtofHit hit_up) { + this.hit_up = hit_up; + } + + public AtofHit getHitDown() { + return hit_down; + } + + public void setHitDown(AtofHit hit_down) { + this.hit_down = hit_down; + } + + 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 void computeZ() { + double some_calibration = 10; //Here read the calibration DB + this.z = some_calibration * (hit_up.getTime() - hit_down.getTime()); + } + + public void computeTime() { + double some_calibration = 10; //Here read the calibration DB + this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime())/2.); + } + + public void computeEnergy() { + this.energy = (hit_up.getEnergy() + hit_down.getEnergy()); + } + + 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 int getSector() { + return sector; + } + + public void setSector(int sector) { + this.sector = sector; + } + + public int getLayer() { + return layer; + } + + public void setLayer(int layer) { + this.layer = layer; + } + + public BarHit(AtofHit hit_down, AtofHit hit_up) + { + boolean hits_match = hit_down.barmatch(hit_up); + if(!hits_match) throw new UnsupportedOperationException("Hits do not match \n"); + + this.hit_up = hit_up; + this.hit_down = hit_down; + this.layer = hit_up.getLayer(); + this.sector = hit_up.getSector(); + this.x = hit_up.getX(); + this.y = hit_up.getY(); + this.computeZ(); + this.computeTime(); + this.computeEnergy(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + DataBank bank = event.getBank("ATOF::tdc"); + int nt = bank.rows(); // number of tracks + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); + ArrayList hit_wedge = new ArrayList<>(); + for (int i = 0; i < nt; i++) { + int sector = bank.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + 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); + case "wedge" -> hit_wedge.add(hit); + default -> System.out.print("Undefined hit type \n"); + } + } + ArrayList bar_hits = new ArrayList(); + for(int i_up=0; i_up Date: Mon, 13 Jan 2025 13:40:03 -0600 Subject: [PATCH 03/82] Building hit lists --- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java new file mode 100644 index 0000000000..eb0e55caa3 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -0,0 +1,106 @@ +package org.jlab.rec.atof.Hit; + +import java.util.ArrayList; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +/** + * + * @author npilleux + */ +public class HitFinder { + + private ArrayList bar_hits; + private ArrayList wedge_hits; + + public HitFinder() + { + this.bar_hits = new ArrayList<>(); + this.wedge_hits = new ArrayList<>(); + } + + // Getter and Setter for bar_hits + public ArrayList getBarHits() { + return bar_hits; + } + + public void setBarHits(ArrayList bar_hits) { + this.bar_hits = bar_hits; + } + + // Getter and Setter for wedge_hits + public ArrayList getWedgeHits() { + return wedge_hits; + } + + public void setWedgeHits(ArrayList wedge_hits) { + this.wedge_hits = wedge_hits; + } + + public void FindHits(DataEvent event, Detector atof) { + + DataBank bank = event.getBank("ATOF::tdc"); + int nt = bank.rows(); // number of hits + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); + + for (int i = 0; i < nt; i++) { + int sector = bank.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + 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); + case "wedge" -> this.wedge_hits.add(hit); + default -> System.out.print("Undefined hit type \n"); + } + } + for(int i_up=0; i_up Date: Mon, 13 Jan 2025 14:55:24 -0600 Subject: [PATCH 04/82] First clustering, to be revisited --- .../jlab/rec/atof/Cluster/AtofCluster.java | 127 +++++++++++++++++ .../jlab/rec/atof/Cluster/ClusterFinder.java | 133 ++++++++++++++++++ .../java/org/jlab/rec/atof/Hit/AtofHit.java | 19 +++ .../java/org/jlab/rec/atof/Hit/BarHit.java | 18 +++ 4 files changed, 297 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java new file mode 100644 index 0000000000..931d43ff8c --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -0,0 +1,127 @@ +package org.jlab.rec.atof.Cluster; + +import java.util.ArrayList; +import org.jlab.rec.atof.Hit.AtofHit; +import org.jlab.rec.atof.Hit.BarHit; + +/** + * + * @author npilleux + */ +public class AtofCluster { + + ArrayList bar_hits; + ArrayList wedge_hits; + double x,y,z,time,energy; + + public ArrayList getBarHits() { + return bar_hits; + } + + public void setBarHits(ArrayList bar_hits) { + this.bar_hits = bar_hits; + } + + public ArrayList getWedgeHits() { + return wedge_hits; + } + + public void setWedgeHits(ArrayList wedge_hits) { + this.wedge_hits = wedge_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; + } + + //Cluster coordinates and time are defined as the coordinates and time of the max energy hit + //Can be changed later + public void computeClusterProperties() { + this.energy=0; + double max_energy = -1; + AtofHit max_energy_hit = new AtofHit(); + BarHit max_energy_barhit = new BarHit(); + + for(int i_wedge = 0; i_wedgemax_energy){max_energy_hit = this_wedge_hit; max_energy = this_energy;} + } + + for(int i_bar = 0; i_barmax_energy){max_energy_barhit = this_bar_hit; max_energy = this_energy;} + } + + if(max_energy_hit.getEnergy() > max_energy_barhit.getEnergy()) + { + this.time = max_energy_hit.getTime(); + this.x = max_energy_hit.getX(); + this.y = max_energy_hit.getY(); + this.z = max_energy_hit.getZ(); + } + else + { + this.time = max_energy_barhit.getTime(); + this.x = max_energy_barhit.getX(); + this.y = max_energy_barhit.getY(); + this.z = max_energy_barhit.getZ(); + } + + } + + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) + { + this.bar_hits = bar_hits; + this.wedge_hits = wedge_hits; + this.computeClusterProperties(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } + +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java new file mode 100644 index 0000000000..22ae7ecf93 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -0,0 +1,133 @@ +package org.jlab.rec.atof.Cluster; + +import java.util.ArrayList; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.Hit.AtofHit; +import org.jlab.rec.atof.Hit.BarHit; +import org.jlab.rec.atof.Hit.HitFinder; + +/** + * + * @author npilleux + */ +public class ClusterFinder { + + private ArrayList clusters; + + public void MakeClusters(HitFinder hitfinder) { + + ArrayList wedge_hits = hitfinder.getWedgeHits(); + ArrayList bar_hits = hitfinder.getBarHits(); + + double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future + double sigma_Z = 2.0;//wedge length. to be read from DB in the future + double sigma_T = 10;//timing resolution to be read from DB in the future + + + for(int i_wedge = 0; i_wedge this_cluster_wedge_hits = new ArrayList<>(); + ArrayList this_cluster_bar_hits = new ArrayList<>(); + + this_wedge_hit.setIs_in_a_cluster(true); + this_cluster_wedge_hits.add(this_wedge_hit); + + + //Check if other wedge hits should be clustered + for(int j_wedge = 0; j_wedge this_cluster_wedge_hits = new ArrayList(); + ArrayList this_cluster_bar_hits = new ArrayList(); + this_cluster_bar_hits.add(this_bar_hit); + AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); + clusters.add(cluster); + } + } + + public ClusterFinder() + { + clusters = new ArrayList(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + HitFinder hitfinder = new HitFinder(); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + hitfinder.FindHits(event, atof); + ClusterFinder clusterfinder = new ClusterFinder(); + clusterfinder.MakeClusters(hitfinder); + + } + } + +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 322eb8bf1f..20ebc190c4 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -18,6 +18,7 @@ public class AtofHit { private int TDC, ToT; private double time, energy, x, y, z; private String type; + private boolean is_in_a_cluster; public int getSector() { return sector; @@ -114,6 +115,14 @@ public String getType() { public void setType(String type) { this.type = type; } + + public boolean getIs_in_a_cluster() { + return is_in_a_cluster; + } + + public void setIs_in_a_cluster(boolean is_in_a_cluster) { + this.is_in_a_cluster = is_in_a_cluster; + } public String makeType(){ String type = "undefined"; @@ -194,6 +203,11 @@ public boolean barmatch(AtofHit hit2match) else return true; } + public double getPhi() + { + return Math.atan2(this.y, this.x); + } + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { this.sector = sector; @@ -202,12 +216,17 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.order = order; this.TDC = tdc; this.ToT = tot; + this.is_in_a_cluster = false; this.makeType(); int is_ok = this.TDC_to_time(); if(is_ok==1) is_ok = this.ToT_to_energy(); if(is_ok==1) is_ok = this.slc_to_xyz(atof); } + + public AtofHit() + { + } /** * @param args the command line arguments diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 202f943a4a..0317d17d13 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -18,6 +18,7 @@ public class BarHit { private AtofHit hit_up, hit_down; private double x,y,z, time, energy; int sector, layer; + private boolean is_in_a_cluster; public AtofHit getHitUp() { return hit_up; @@ -105,6 +106,19 @@ public void setLayer(int layer) { this.layer = layer; } + public boolean getIs_in_a_cluster() { + return is_in_a_cluster; + } + + public void setIs_in_a_cluster(boolean is_in_a_cluster) { + this.is_in_a_cluster = is_in_a_cluster; + } + + public double getPhi() + { + return Math.atan2(this.y, this.x); + } + public BarHit(AtofHit hit_down, AtofHit hit_up) { boolean hits_match = hit_down.barmatch(hit_up); @@ -121,6 +135,10 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) this.computeEnergy(); } + public BarHit() + { + } + /** * @param args the command line arguments */ From 49d70a72393df063846a1e581523b0cc0514a409 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 13 Jan 2025 15:01:27 -0600 Subject: [PATCH 05/82] ahdc track projection --- .../rec/atof/TrackMatch/TrackProjection.java | 124 +++++++++++ .../rec/atof/TrackMatch/TrackProjector.java | 196 ++++++++++++++++++ 2 files changed, 320 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java new file mode 100644 index 0000000000..9ccbbe26dd --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -0,0 +1,124 @@ +package org.jlab.rec.atof.TrackMatch; + +import org.jlab.geom.prim.Point3D; + +/** + * The {@code TrackProjection} class holds ahdc track information relevant for atof analysis + * i.e projected to the inner surfaces of the bar and wedges + * @author pilleux + */ + +public class TrackProjection { + + /** + * Intersection point of the track with the inner surface of the bar. + */ + private Point3D _BarIntersect = new Point3D(); + + /** + * Intersection point of the track with the inner surface of the wedges. + */ + private Point3D _WedgeIntersect = new Point3D(); + + /** + * Path length of the track from the DOCA to the beam line + * to the inner surface of the bar. + */ + Float _BarPathLength; + + /** + * Path length of the track from the DOCA to the beam line + * to the inner surface of the wedges. + */ + Float _WedgePathLength; + + /** + * Default constructor that initializes the intersection points and path lengths to {@code NaN}. + */ + public TrackProjection() { + _BarIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + _WedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + _BarPathLength = Float.NaN; + _WedgePathLength = Float.NaN; + } + + /** + * Gets the intersection point of the track with the inner surface of the bar. + * + * @return {@link Point3D} bar's intersection point. + */ + public Point3D get_BarIntersect() { + return _BarIntersect; + } + + /** + * Gets the intersection point of the track with the inner surface of the wedges. + * + * @return {@link Point3D} wedge's intersection point. + */ + public Point3D get_WedgeIntersect() { + return _WedgeIntersect; + } + + /** + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * + * @return {@code Float} path length to the bar's inner surface. + */ + public Float get_BarPathLength() { + return _BarPathLength; + } + + /** + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * + * @return {@code Float} path length to the wedge's inner surface. + */ + public Float get_WedgePathLength() { + return _WedgePathLength; + } + + /** + * Sets the intersection point of the track with the inner surface of the bar. + * + * @param BarIntersect {@link Point3D} intersection with the bar. + */ + public void set_BarIntersect(Point3D BarIntersect) { + this._BarIntersect = BarIntersect; + } + + /** + * Sets the intersection point of the track with the inner surface of the wedges. + * + * @param WedgeIntersect {@link Point3D} intersection with the wedge. + */ + public void set_WedgeIntersect(Point3D WedgeIntersect) { + this._WedgeIntersect = WedgeIntersect; + } + + /** + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * + * @param BarPathLength {@code Float} path length to the bar inner surface. + */ + public void set_BarPathLength(Float BarPathLength) { + this._BarPathLength = BarPathLength; + } + + /** + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * + * @param WedgePathLength {@code Float} path length to the wedge inner surface. + */ + public void set_WedgePathLength(Float WedgePathLength) { + this._WedgePathLength = WedgePathLength; + } + + /** + * testing purposes. + * + * @param arg command-line arguments. + */ + public static void main(String arg[]) { + } +} \ No newline at end of file diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java new file mode 100644 index 0000000000..feb790fd28 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -0,0 +1,196 @@ +package org.jlab.rec.atof.TrackMatch; + +import java.util.ArrayList; +import java.util.List; + +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.clas.tracking.trackrep.Helix; +import org.jlab.clas.tracking.kalmanfilter.Units; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.clas.swimtools.Swim; +import org.jlab.utils.CLASResources; +import cnuphys.magfield.MagneticFields; + +/** + * The {@code TrackProjector} class projects ahdc tracks to the inner surfaces + * of the bar and wedges of the atof + * + *

+ * Uses ahdc track bank information (for now position, momentum) Creates a + * {@link TrackProjection} for each track. + *

+ * + *

+ * TO DO: - replace hardcoded values with database values. - magnetic field ? + * use swimmer tools? - charge ? + *

+ * + * @author pilleux + */ +public class TrackProjector { + + /** + * projections of tracks. + */ + private List Projections; + + /** + * solenoid magnitude + */ + private Double B; + + /** + * Default constructor that initializes the list of projections as new empty + * list and the magnetic field to 5T. + */ + public TrackProjector() { + Projections = new ArrayList(); + B = 5.0; + } + + /** + * Gets the list of track projections. + * + * @return a {@link List} of {@link TrackProjection} objects representing + * the projections. + */ + public List getProjections() { + return Projections; + } + + /** + * Gets the solenoid magnitude + * + * @return solenoid magnitude + */ + public Double getB() { + return B; + } + + /** + * Sets the list of track projections. + * + * @param Projections a {@link List} of {@link TrackProjection}. + */ + public void setProjections(List Projections) { + this.Projections = Projections; + } + + /** + * Sets the solenoid magnitude. + * + * @param B a double. + */ + public void setB(Double B) { + this.B = B; + } + + /** + * Projects the ahdc tracks in the event onto the atof using a {@link Helix} + * model. + * + * @param event the {@link DataEvent} containing track data to be projected. + */ + public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { + + Projections.clear(); + + double bar_innerradius = 77; //NEEDS TO BE REPLACED WITH DB CONSTANTS something like ccdb.INNERRADIUS[0] + double wedge_innerradius = 80; + + String track_bank_name = "AHDC::Track"; + + if (event == null) { // check if there is an event + //System.out.print(" no event"); + } else if (event.hasBank(track_bank_name) == false) { + // check if there are ahdc tracks in the event + //System.out.print("no tracks"); + } else { + DataBank bank = event.getBank(track_bank_name); + + int nt = bank.rows(); // number of tracks + TrackProjection projection = new TrackProjection(); + DataBank outputBank = event.createBank("AHDC::Projections", nt); + + for (int i = 0; i < nt; i++) { + + double x = bank.getFloat("x", i); + double y = bank.getFloat("y", i); + double z = bank.getFloat("z", i); + double px = bank.getFloat("px", i); + double py = bank.getFloat("py", i); + double pz = bank.getFloat("pz", i); + + int q = 1; //this has to be changed, we need the charge info from tracking + + Units units = Units.MM; //can be MM or CM. + + double xb = 0; + double yb = 0; + + Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + + projection.set_BarIntersect(helix.getHelixPointAtR(bar_innerradius)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_innerradius)); + + projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); + projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); + + Projections.add(projection); + fill_out_bank(outputBank, projection, i); + } + event.appendBank(outputBank); + } + } + + public static void fill_out_bank(DataBank outputBank, TrackProjection projection, int i) { + outputBank.setFloat("x_at_bar", i, (float) projection.get_BarIntersect().x()); + outputBank.setFloat("y_at_bar", i, (float) projection.get_BarIntersect().y()); + outputBank.setFloat("z_at_bar", i, (float) projection.get_BarIntersect().z()); + outputBank.setFloat("L_at_bar", i, (float) projection.get_BarPathLength()); + outputBank.setFloat("x_at_wedge", i, (float) projection.get_WedgeIntersect().x()); + outputBank.setFloat("y_at_wedge", i, (float) projection.get_WedgeIntersect().y()); + outputBank.setFloat("z_at_wedge", i, (float) projection.get_WedgeIntersect().z()); + outputBank.setFloat("L_at_wedge", i, (float) projection.get_WedgePathLength()); + } + + public static void main(String arg[]) { + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + double B = Math.abs(b[2]); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(B); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/test_updated_2.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + + projector.ProjectTracks(event); + //event.getBank("AHDC::Projections").show(); + } + + System.out.print("Read " + event_number + " events"); + } +} \ No newline at end of file From 8b2f35b8465b65ccb6434f0e36926449eb32e255 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:41:58 -0600 Subject: [PATCH 06/82] Path length --- .../jlab/rec/atof/Cluster/AtofCluster.java | 16 + .../java/org/jlab/rec/atof/Hit/AtofHit.java | 319 ++++++++++++------ .../java/org/jlab/rec/atof/Hit/BarHit.java | 36 ++ 3 files changed, 273 insertions(+), 98 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 931d43ff8c..102b61b6c3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -13,6 +13,7 @@ public class AtofCluster { ArrayList bar_hits; ArrayList wedge_hits; double x,y,z,time,energy; + double path_length; public ArrayList getBarHits() { return bar_hits; @@ -70,6 +71,14 @@ public void setEnergy(double energy) { this.energy = energy; } + public double getpath_length() { + return path_length; + } + + public void setpath_length(double path_length) { + this.path_length = path_length; + } + //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later public void computeClusterProperties() { @@ -100,6 +109,7 @@ public void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); + this.path_length = max_energy_hit.getpath_length(); } else { @@ -107,10 +117,16 @@ public void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); + this.path_length = max_energy_barhit.getpath_length(); } } + public double getPhi() + { + return Math.atan2(this.y, this.x); + } + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { this.bar_hits = bar_hits; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 20ebc190c4..17ceecbef2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -1,5 +1,6 @@ package org.jlab.rec.atof.Hit; +import java.util.List; import org.jlab.geom.base.*; import org.jlab.geom.detector.alert.ATOF.*; import org.jlab.detector.calib.utils.DatabaseConstantProvider; @@ -7,11 +8,21 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.TrackMatch.TrackProjection; +import org.jlab.rec.atof.TrackMatch.TrackProjector; /** - * + * + * Represents a hit in the atof. + * Stores info about the sector, layer, component, order, TDC, ToT. + * Type is wedge/bar up/bar down + * Spatial coordinates are computed from atof detector object using the geometry service + * Stores whether the hit is part of a cluster. + * Calculates time, energy based on TDC/ToT. + * * @author npilleux */ + public class AtofHit { private int sector, layer, component, order; @@ -19,6 +30,7 @@ public class AtofHit { private double time, energy, x, y, z; private String type; private boolean is_in_a_cluster; + private double path_length; public int getSector() { return sector; @@ -35,7 +47,7 @@ public int getLayer() { public void setLayer(int layer) { this.layer = layer; } - + public int getOrder() { return order; } @@ -51,7 +63,7 @@ public int getComponent() { public void setComponent(int component) { this.component = component; } - + public int getTDC() { return TDC; } @@ -67,7 +79,7 @@ public int getToT() { public void setToT(int tot) { this.ToT = tot; } - + public double getTime() { return time; } @@ -107,7 +119,7 @@ public double getZ() { public void setZ(double z) { this.z = z; } - + public String getType() { return type; } @@ -115,7 +127,7 @@ public String getType() { public void setType(String type) { this.type = type; } - + public boolean getIs_in_a_cluster() { return is_in_a_cluster; } @@ -124,109 +136,221 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - public String makeType(){ - String type = "undefined"; - if(this.component == 10 && this.order==0) type = "bar down"; - else if(this.component == 10 && this.order==1) type = "bar up"; - else if(this.component < 10) type = "wedge"; - this.type = type; - return type; + public double getpath_length() { + return path_length; } - - public int TDC_to_time() - { - double some_conversion = 0; - if(this.type == "wedge") - { - some_conversion = 10;//read calib constants here - } - else if(this.type == "bar up") - { - some_conversion = 10; - } - else if(this.type == "bar down") - { - some_conversion = 10; - } - else - { - return 0; - } - this.time = some_conversion * this.TDC; - return 1; + + public void setpath_length(double path_length) { + this.path_length = path_length; } - public int ToT_to_energy() - { - double some_conversion = 0; - if(this.type == "wedge") - { - some_conversion = 10;//read calib constants here - } - else if(this.type == "bar up") - { - some_conversion = 10; - } - else if(this.type == "bar down") - { - some_conversion = 10; - } - else - { - return 0; - } - this.energy = some_conversion * this.ToT; - return 1; + public int compute_module_index(){ + //Index ranging 0 to 60 for each wedge+bar module + return 4*this.sector + this.layer; } - - public int slc_to_xyz(Detector atof) - { + + public final String makeType() { + String itype = "undefined"; + if (this.component == 10 && this.order == 0) { + itype = "bar down"; + } else if (this.component == 10 && this.order == 1) { + itype = "bar up"; + } else if (this.component < 10) { + itype = "wedge"; + } + this.type = itype; + return itype; + } + + public final int TDC_to_time() { + double some_conversion = 0; + if (null == this.type) { + return 1; + } else { + switch (this.type) { + case "wedge" -> + some_conversion = 10;//read calib constants here + case "bar up" -> + some_conversion = 10; + case "bar down" -> + some_conversion = 10; + default -> { + return 1; + } + } + } + this.time = some_conversion * this.TDC; + return 0; + } + + public final int ToT_to_energy() { + double some_conversion = 0; + if (null == this.type) { + return 1; + } else { + switch (this.type) { + case "wedge" -> + some_conversion = 10;//read calib constants here + case "bar up" -> + some_conversion = 10; + case "bar down" -> + some_conversion = 10; + default -> { + return 1; + } + } + } + this.energy = some_conversion * this.ToT; + return 0; + } + + /** + * Calculates spatial coordinates for the hit based on associated + * detector component. Retrieves the midpoint of the atof component + * to assign the corresponding x, y, z coordinates to the hit. + * + * + * @param atof The Detector object representing the atof. + * @return 0 if the coordinates were successfully set, or 1 if the hit type + * is undefined or unsupported. + */ + public final int slc_to_xyz(Detector atof) { int sl = 999; - if(this.type == "wedge") sl = 1; - else if(this.type == "bar up" || this.type == "bar down") sl = 0; - else return 0; + if (null == this.type) { + return 1; + } else { + switch (this.type) { + case "wedge" -> + sl = 1; + case "bar up", "bar down" -> + sl = 0; + default -> { + return 1; + } + } + } Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); this.x = midpoint.x(); this.y = midpoint.y(); this.z = midpoint.z(); - return 1; + return 0; } - - public boolean barmatch(AtofHit hit2match) - { - if(this.getSector() != hit2match.getSector()) return false; //System.out.print("Two hits in different sectors \n"); - else if(this.getLayer() != hit2match.getLayer()) return false; //System.out.print("Two hits in different layers \n"); - else if(this.getComponent() != 10 || hit2match.getComponent() != 10) return false; //System.out.print("At least one hit is not in the bar \n"); - else if(this.getOrder() == hit2match.getOrder()) return false; //System.out.print("Two hits in same SiPM \n"); - else return true; + + /** + * Compares two AtofHit objects to check if they match in the bar. + *
    + *
  • If the sector or layer of the two hits do not match, the method + * returns {@code false}.
  • + *
  • If either hit is not in the bar (component must be 10), the method + * returns {@code false}.
  • + *
  • If both hits are in the same SiPM (i.e., their order is the same), + * 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 AtofHit object to compare with the current instance. + * @return {@code true} if the hits match; {@code false} otherwise. + */ + public boolean barmatch(AtofHit hit2match) { + if (this.getSector() != hit2match.getSector()) { + return false; //System.out.print("Two hits in different sectors \n"); + } else if (this.getLayer() != hit2match.getLayer()) { + return false; //System.out.print("Two hits in different layers \n"); + } else if (this.getComponent() != 10 || hit2match.getComponent() != 10) { + return false; //System.out.print("At least one hit is not in the bar \n"); + } else { + return this.getOrder() != hit2match.getOrder(); //System.out.print("Two hits in same SiPM \n"); + } } - - public double getPhi() - { + + /** + * Returns the azimuthal angle (phi) of the hit. + * + * @return The azimuthal angle (phi) in radians, in the range [-π, π]. + */ + public double getPhi() { return Math.atan2(this.y, this.x); } - - public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) - { - this.sector = sector; - this.layer = layer; - this.component = component; - this.order = order; - this.TDC = tdc; - this.ToT = tot; - this.is_in_a_cluster = false; - - this.makeType(); - int is_ok = this.TDC_to_time(); - if(is_ok==1) is_ok = this.ToT_to_energy(); - if(is_ok==1) is_ok = this.slc_to_xyz(atof); - } - - public AtofHit() - { - } + + /** + * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * component, 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 layer The layer of the detector where the hit was detected. + * @param component The component within the layer that registered the hit. + * @param order Order of the hit. + * @param tdc TDC value. + * @param tot ToT velue. + * @param atof Detector object representing the atof, used to calculate + * spatial coordinates. + */ + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { + this.sector = sector; + this.layer = layer; + this.component = component; + this.order = order; + this.TDC = tdc; + this.ToT = tot; + this.is_in_a_cluster = false; + + this.makeType(); + int is_ok = this.TDC_to_time(); + if (is_ok != 1) { + is_ok = this.ToT_to_energy(); + } + if (is_ok != 1) { + is_ok = this.slc_to_xyz(atof); + } + } + + /** + * Matches the current track with ahdc tracks projections. Calculates the + * match by comparing the hit's azimuthal angle and longitudinal position + * (z) with the track projection. If a match is found within defined + * tolerances for phi and z, the path length of the matched hit is updated. + * + * @param track_projector The TrackProjector object that provides a list of + * TrackProjections. + * + */ + public void MatchTrack(TrackProjector track_projector) { + double sigma_phi = 10; + double sigma_z = 10; + List Projections = track_projector.getProjections(); + for (int i_track = 0; i_track < Projections.size(); i_track++) { + Point3D projection_point = new Point3D(); + if (null == this.getType()) { + System.out.print("Impossible to match track and hitm hit type is undefined \n"); + } else { + switch (this.getType()) { + case "wedge" -> + projection_point = Projections.get(i_track).get_WedgeIntersect(); + case "bar up", "bar down" -> + projection_point = Projections.get(i_track).get_BarIntersect(); + default -> + System.out.print("Impossible to match track and hitm hit type is undefined \n"); + } + } + + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { + if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { + if ("wedge".equals(this.getType())) { + this.setpath_length(Projections.get(i_track).get_WedgePathLength()); + } else { + this.setpath_length(Projections.get(i_track).get_BarPathLength()); + } + } + } + } + } + + public AtofHit() { + } /** * @param args the command line arguments @@ -236,7 +360,7 @@ public static void main(String[] args) { AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); - + //Input to be read String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; HipoDataSource reader = new HipoDataSource(); @@ -248,7 +372,7 @@ public static void main(String[] args) { event_number++; DataBank bank = event.getBank("ATOF::tdc"); int nt = bank.rows(); // number of tracks - + for (int i = 0; i < nt; i++) { int sector = bank.getInt("sector", i); int layer = bank.getInt("layer", i); @@ -258,8 +382,7 @@ public static void main(String[] args) { int tot = bank.getInt("ToT", i); AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); System.out.print(hit.getX() + "\n"); - } + } } } } - diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 0317d17d13..5365b3255d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -7,6 +7,10 @@ import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; import java.util.ArrayList; +import java.util.List; +import org.jlab.geom.prim.Point3D; +import org.jlab.rec.atof.TrackMatch.TrackProjection; +import org.jlab.rec.atof.TrackMatch.TrackProjector; /** * @@ -19,6 +23,7 @@ public class BarHit { private double x,y,z, time, energy; int sector, layer; private boolean is_in_a_cluster; + private double path_length; public AtofHit getHitUp() { return hit_up; @@ -114,11 +119,42 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } + public double getpath_length() { + return path_length; + } + + public void setpath_length(double path_length) { + this.path_length = path_length; + } + public double getPhi() { return Math.atan2(this.y, this.x); } + public int compute_module_index(){ + //Index ranging 0 to 60 for each wedge+bar module + return 4*this.sector + this.layer; + } + + public void MatchTrack(TrackProjector track_projector) + { + double sigma_phi = 10; + double sigma_z = 10; + List Projections = track_projector.getProjections(); + for(int i_track = 0; i_track < Projections.size(); i_track++) + { + Point3D projection_point = Projections.get(i_track).get_BarIntersect(); + if(Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) + { + if(Math.abs(this.getZ() - projection_point.z()) < sigma_z) + { + this.setpath_length(Projections.get(i_track).get_BarPathLength()); + } + } + } + } + public BarHit(AtofHit hit_down, AtofHit hit_up) { boolean hits_match = hit_down.barmatch(hit_up); From 40a9109f31bf14cc85e1a0a6aa4c5142cf149987 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:43:19 -0600 Subject: [PATCH 07/82] Hits sorted by energy --- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index eb0e55caa3..345a0afa1e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -1,12 +1,17 @@ package org.jlab.rec.atof.Hit; +import cnuphys.magfield.MagneticFields; import java.util.ArrayList; +import java.util.Collections; +import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.utils.CLASResources; /** * * @author npilleux @@ -40,42 +45,62 @@ public void setWedgeHits(ArrayList wedge_hits) { this.wedge_hits = wedge_hits; } - public void FindHits(DataEvent event, Detector atof) { + public void FindHits(DataEvent event, Detector atof, TrackProjector track_projector) { + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank DataBank bank = event.getBank("ATOF::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.getInt("sector", i); int layer = bank.getInt("layer", i); int component = bank.getInt("component", i); int order = bank.getInt("order", i); int tdc = bank.getInt("TDC", i); int tot = bank.getInt("ToT", i); + //Building a Hit AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if(hit.getEnergy() < 0.1 )continue; //energy threshold + //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed 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); - case "wedge" -> this.wedge_hits.add(hit); + case "wedge" -> {hit.MatchTrack(track_projector); this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); } @@ -83,24 +108,49 @@ else switch (hit.getType()) { * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here + + //Building ALERT geometry AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + double B = Math.abs(b[2]); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(B); + + //Hit finder init + HitFinder hitfinder = new HitFinder(); //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - - HitFinder hitfinder = new HitFinder(); int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; - hitfinder.FindHits(event, atof); + + projector.ProjectTracks(event); + hitfinder.FindHits(event, atof, projector); } + + System.out.print("Read " + event_number + " events"); } } \ No newline at end of file From 00fb57c2a2c997f8b8f54a6fd82683f4b393bbbd Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:44:10 -0600 Subject: [PATCH 08/82] Some more clustering algo, resolutions need to be set --- .../jlab/rec/atof/Cluster/ClusterFinder.java | 230 +++++++++++++----- 1 file changed, 163 insertions(+), 67 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 22ae7ecf93..9830e4615b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -1,6 +1,8 @@ package org.jlab.rec.atof.Cluster; +import cnuphys.magfield.MagneticFields; import java.util.ArrayList; +import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -9,6 +11,8 @@ import org.jlab.rec.atof.Hit.AtofHit; import org.jlab.rec.atof.Hit.BarHit; import org.jlab.rec.atof.Hit.HitFinder; +import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.utils.CLASResources; /** * @@ -18,91 +22,165 @@ public class ClusterFinder { private ArrayList clusters; + public void setClusters(ArrayList clusters) { + this.clusters = clusters; + } + + public ArrayList getClusters() { + return clusters; + } + public void MakeClusters(HitFinder hitfinder) { + //A list of clusters is built for each event + clusters.clear(); + + //Getting the list of hits, they must have been ordered by energy already ArrayList wedge_hits = hitfinder.getWedgeHits(); ArrayList bar_hits = hitfinder.getBarHits(); - + double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future - double sigma_Z = 2.0;//wedge length. to be read from DB in the future - double sigma_T = 10;//timing resolution to be read from DB in the future - - - for(int i_wedge = 0; i_wedge this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); + //Indicate that this hit now is in a cluster this_wedge_hit.setIs_in_a_cluster(true); + //And store it this_cluster_wedge_hits.add(this_wedge_hit); - - - //Check if other wedge hits should be clustered - for(int j_wedge = 0; j_wedge 30) { + delta_module = 60 - delta_module; + } + int delta_component = Math.abs(this_wedge_hit.getComponent() - other_wedge_hit.getComponent()); + //Later we could use z and phi threshold + //double delta_Phi = Math.abs(this_wedge_hit.getPhi() - other_wedge_hit.getPhi()); + //double delta_Z = Math.abs(this_wedge_hit.getZ() - other_wedge_hit.getZ()); + //Time matching + double delta_T = Math.abs(this_wedge_hit.getTime() - other_wedge_hit.getTime()); + + if (delta_module <= sigma_module)//delta_Phi <= sigma_Phi) + { + if (delta_component <= sigma_component)//delta_Z <= sigma_Z) + { + if (delta_T < sigma_T) { + other_wedge_hit.setIs_in_a_cluster(true); + this_cluster_wedge_hits.add(other_wedge_hit); } - } - - //Check if bar hits should be clustered - for(int j_bar = 0; j_bar 30) { + delta_module = 60 - delta_module; + } + //Later we could use phi threshold + //double delta_Phi = Math.abs(this_wedge_hit.getPhi() - other_wedge_hit.getPhi()); + double delta_Z = Math.abs(this_wedge_hit.getZ() - other_bar_hit.getZ()); + //Time matching + double delta_T = Math.abs(this_wedge_hit.getTime() - other_bar_hit.getTime()); + if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) + { + if (delta_Z < sigma_Z) { + if (delta_T < sigma_T) { + other_bar_hit.setIs_in_a_cluster(true); + this_cluster_bar_hits.add(other_bar_hit); } - } + } + } + }//End loop bar hits + //After all wedge and bar hits have been grouped, build the cluster AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); + //And add it to the list of clusters clusters.add(cluster); - } + }//End loop on all wedge hits - for(int i_bar = 0; i_bar this_cluster_wedge_hits = new ArrayList(); ArrayList this_cluster_bar_hits = new ArrayList(); + this_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(this_bar_hit); + + //Loop through less energetic clusters + for (int j_bar = i_bar + 1; j_bar < bar_hits.size(); j_bar++) { + BarHit other_bar_hit = bar_hits.get(j_bar); + //Skip already clustered hits + if (other_bar_hit.getIs_in_a_cluster()) { + continue; + } + + //Check the distance between the hits + //For now we use phi module difference from what is observed in simu + int delta_module = Math.abs(this_bar_hit.compute_module_index() - other_bar_hit.compute_module_index()); + if (delta_module > 30) { + delta_module = 60 - delta_module; + } + //Later we could use phi threshold + //double delta_Phi = Math.abs(this_wedge_hit.getPhi() - other_wedge_hit.getPhi()); + double delta_Z = Math.abs(this_bar_hit.getZ() - other_bar_hit.getZ()); + //Time matching + double delta_T = Math.abs(this_bar_hit.getTime() - other_bar_hit.getTime()); + + if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) + { + if (delta_Z < sigma_Z) { + if (delta_T < sigma_T) { + other_bar_hit.setIs_in_a_cluster(true); + this_cluster_bar_hits.add(other_bar_hit); + } + } + } + } AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } } - - public ClusterFinder() - { - clusters = new ArrayList(); - } - + + public ClusterFinder() { + clusters = new ArrayList(); + } + /** * @param args the command line arguments */ @@ -111,23 +189,41 @@ public static void main(String[] args) { AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); - + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + double B = Math.abs(b[2]); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(B); + //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - + HitFinder hitfinder = new HitFinder(); int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); event_number++; - hitfinder.FindHits(event, atof); + projector.ProjectTracks(event); + hitfinder.FindHits(event, atof, projector); ClusterFinder clusterfinder = new ClusterFinder(); clusterfinder.MakeClusters(hitfinder); - } } - + } From 9bfe8cf558a5ea3a71bfdde8684afd2fada5d19f Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:44:36 -0600 Subject: [PATCH 09/82] Track projection bank def --- etc/bankdefs/hipo4/alert.json | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index 7c125eb9cc..f7cf6b16a3 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -1,5 +1,45 @@ [ { + "name": "AHDC::Projections", + "group": 23000, + "item": 31, + "info": "Track Projections to ATOF", + "entries": [ + { + "name": "x_at_bar", + "type": "F", + "info": "x position at atof bar in mm" + }, { + "name": "y_at_bar", + "type": "F", + "info": "y position at atof bar in mm" + }, { + "name": "z_at_bar", + "type": "F", + "info": "z position at atof bar in mm" + },{ + "name": "L_at_bar", + "type": "F", + "info": "path length at atof bar in mm" + },{ + "name": "x_at_wedge", + "type": "F", + "info": "x position at atof wedge in mm" + }, { + "name": "y_at_wedge", + "type": "F", + "info": "y position at atof wedge in mm" + }, { + "name": "z_at_wedge", + "type": "F", + "info": "z position at atof wedge in mm" + },{ + "name": "L_at_wedge", + "type": "F", + "info": "path length at atof wedge in mm" + } + ] + },{ "name": "AHDC::Hits", "group": 23000, "item": 23, From 6852b6412ce2b98e2cb397bf89ed8ac8bda4bb8a Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 16:21:51 -0600 Subject: [PATCH 10/82] Track projection to the middle of elements --- etc/bankdefs/hipo4/alert.json | 8 ++ .../rec/atof/TrackMatch/TrackProjection.java | 86 +++++++++++++++---- .../rec/atof/TrackMatch/TrackProjector.java | 34 +++++--- 3 files changed, 99 insertions(+), 29 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index f7cf6b16a3..c614e9218d 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -21,6 +21,10 @@ "name": "L_at_bar", "type": "F", "info": "path length at atof bar in mm" + },{ + "name": "L_in_bar", + "type": "F", + "info": "path length inside atof bar in mm" },{ "name": "x_at_wedge", "type": "F", @@ -37,6 +41,10 @@ "name": "L_at_wedge", "type": "F", "info": "path length at atof wedge in mm" + },{ + "name": "L_in_wedge", + "type": "F", + "info": "path length inside atof wedge in mm" } ] },{ diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index 9ccbbe26dd..cae3e33f63 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -4,33 +4,44 @@ /** * The {@code TrackProjection} class holds ahdc track information relevant for atof analysis - * i.e projected to the inner surfaces of the bar and wedges + * i.e projected to the middle surfaces of the bar and wedges * @author pilleux */ public class TrackProjection { /** - * Intersection point of the track with the inner surface of the bar. + * Intersection point of the track with the middle surface of the bar. */ private Point3D _BarIntersect = new Point3D(); /** - * Intersection point of the track with the inner surface of the wedges. + * Intersection point of the track with the middle surface of the wedges. */ private Point3D _WedgeIntersect = new Point3D(); /** * Path length of the track from the DOCA to the beam line - * to the inner surface of the bar. + * to the middle surface of the bar. */ Float _BarPathLength; /** * Path length of the track from the DOCA to the beam line - * to the inner surface of the wedges. + * to the middle surface of the wedges. */ Float _WedgePathLength; + + /** + * Path length inside the bar. + */ + Float _BarInPathLength; + + /** + * Path length inside the wedge. + */ + Float _WedgeInPathLength; + /** * Default constructor that initializes the intersection points and path lengths to {@code NaN}. @@ -40,10 +51,12 @@ public TrackProjection() { _WedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); _BarPathLength = Float.NaN; _WedgePathLength = Float.NaN; + _BarInPathLength = Float.NaN; + _WedgeInPathLength = Float.NaN; } /** - * Gets the intersection point of the track with the inner surface of the bar. + * Gets the intersection point of the track with the middle surface of the bar. * * @return {@link Point3D} bar's intersection point. */ @@ -52,7 +65,7 @@ public Point3D get_BarIntersect() { } /** - * Gets the intersection point of the track with the inner surface of the wedges. + * Gets the intersection point of the track with the middle surface of the wedges. * * @return {@link Point3D} wedge's intersection point. */ @@ -61,25 +74,45 @@ public Point3D get_WedgeIntersect() { } /** - * Gets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * Gets the path length of the track from the DOCA to the beam line to the middle surface of the bar. * - * @return {@code Float} path length to the bar's inner surface. + * @return {@code Float} path length to the bar's middle surface. */ public Float get_BarPathLength() { return _BarPathLength; } + + /** + * Gets the path length of the track from the the middle surface of the bar + * to its middle surface. + * + * @return {@code Float} path length inside the bar. + */ + public Float get_BarInPathLength() { + return _BarInPathLength; + } /** - * Gets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * Gets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. * - * @return {@code Float} path length to the wedge's inner surface. + * @return {@code Float} path length to the wedge's middle surface. */ public Float get_WedgePathLength() { return _WedgePathLength; } + + /** + * Gets the path length of the track from the the inner surface of the wedge + * to its middle surface. + * + * @return {@code Float} path length inside the wedge. + */ + public Float get_WedgeInPathLength() { + return _WedgeInPathLength; + } /** - * Sets the intersection point of the track with the inner surface of the bar. + * Sets the intersection point of the track with the middle surface of the bar. * * @param BarIntersect {@link Point3D} intersection with the bar. */ @@ -88,7 +121,7 @@ public void set_BarIntersect(Point3D BarIntersect) { } /** - * Sets the intersection point of the track with the inner surface of the wedges. + * Sets the intersection point of the track with the middle surface of the wedges. * * @param WedgeIntersect {@link Point3D} intersection with the wedge. */ @@ -97,22 +130,41 @@ public void set_WedgeIntersect(Point3D WedgeIntersect) { } /** - * Sets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * Sets the path length of the track from the DOCA to the beam line to the middle surface of the bar. * - * @param BarPathLength {@code Float} path length to the bar inner surface. + * @param BarPathLength {@code Float} path length to the bar middle surface. */ public void set_BarPathLength(Float BarPathLength) { this._BarPathLength = BarPathLength; } /** - * Sets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * Sets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. * - * @param WedgePathLength {@code Float} path length to the wedge inner surface. + * @param WedgePathLength {@code Float} path length to the wedge middle surface. */ public void set_WedgePathLength(Float WedgePathLength) { this._WedgePathLength = WedgePathLength; } + + /** + * Sets the path length of the track inside the bar. + * + * @param BarInPathLength {@code Float} path length inside the bar. + */ + public void set_BarInPathLength(Float BarInPathLength) { + this._BarInPathLength = BarInPathLength; + } + + /** + * Sets the path length of the track inside the wedges. + * + * @param WedgeInPathLength {@code Float} path length inside the wedge. + */ + public void set_WedgeInPathLength(Float WedgeInPathLength) { + this._WedgeInPathLength = WedgeInPathLength; + } + /** * testing purposes. diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index feb790fd28..652bbfa0c1 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -95,20 +95,23 @@ public void setB(Double B) { public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { Projections.clear(); - + //All of these are in MM double bar_innerradius = 77; //NEEDS TO BE REPLACED WITH DB CONSTANTS something like ccdb.INNERRADIUS[0] double wedge_innerradius = 80; - + double bar_thickness = 3; + double wedge_thickness = 20; + double bar_middle_radius = bar_innerradius + bar_thickness/2; + double wedge_middle_radius = wedge_innerradius + wedge_thickness/2; + String track_bank_name = "AHDC::Track"; if (event == null) { // check if there is an event - //System.out.print(" no event"); + //System.out.print(" no event \n"); } else if (event.hasBank(track_bank_name) == false) { // check if there are ahdc tracks in the event - //System.out.print("no tracks"); + //System.out.print("no tracks \n"); } else { DataBank bank = event.getBank(track_bank_name); - int nt = bank.rows(); // number of tracks TrackProjection projection = new TrackProjection(); DataBank outputBank = event.createBank("AHDC::Projections", nt); @@ -131,11 +134,17 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); - projection.set_BarIntersect(helix.getHelixPointAtR(bar_innerradius)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_innerradius)); + //Intersection points with the middle of the bar or wedge + projection.set_BarIntersect(helix.getHelixPointAtR(bar_middle_radius)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_middle_radius)); - projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); - projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); + //Path length to the middle of the bar or wedge + projection.set_BarPathLength((float) helix.getLAtR(bar_middle_radius)); + projection.set_WedgePathLength((float) helix.getLAtR(wedge_middle_radius)); + + //Path length from the inner radius to the middle radius + projection.set_BarInPathLength(projection.get_BarPathLength() - (float) helix.getLAtR(bar_innerradius)); + projection.set_WedgeInPathLength(projection.get_WedgePathLength() - (float) helix.getLAtR(wedge_innerradius)); Projections.add(projection); fill_out_bank(outputBank, projection, i); @@ -149,10 +158,12 @@ public static void fill_out_bank(DataBank outputBank, TrackProjection projection outputBank.setFloat("y_at_bar", i, (float) projection.get_BarIntersect().y()); outputBank.setFloat("z_at_bar", i, (float) projection.get_BarIntersect().z()); outputBank.setFloat("L_at_bar", i, (float) projection.get_BarPathLength()); + outputBank.setFloat("L_in_bar", i, (float) projection.get_BarInPathLength()); outputBank.setFloat("x_at_wedge", i, (float) projection.get_WedgeIntersect().x()); outputBank.setFloat("y_at_wedge", i, (float) projection.get_WedgeIntersect().y()); outputBank.setFloat("z_at_wedge", i, (float) projection.get_WedgeIntersect().z()); outputBank.setFloat("L_at_wedge", i, (float) projection.get_WedgePathLength()); + outputBank.setFloat("L_in_wedge", i, (float) projection.get_WedgeInPathLength()); } public static void main(String arg[]) { @@ -178,17 +189,16 @@ public static void main(String arg[]) { projector.setB(B); //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/test_updated_2.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); event_number++; projector.ProjectTracks(event); - //event.getBank("AHDC::Projections").show(); + event.getBank("AHDC::Projections").show(); } System.out.print("Read " + event_number + " events"); From 4b9ad5169a0ac24646cdf66dd26a22469001f3a5 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 16:35:04 -0600 Subject: [PATCH 11/82] Track projection surfaces redefinition --- etc/bankdefs/hipo4/alert.json | 16 +++++++-------- .../rec/atof/TrackMatch/TrackProjection.java | 20 +++++++++---------- .../rec/atof/TrackMatch/TrackProjector.java | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index c614e9218d..e616780db4 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -8,19 +8,19 @@ { "name": "x_at_bar", "type": "F", - "info": "x position at atof bar in mm" + "info": "x position at atof bar (middle surface) in mm" }, { "name": "y_at_bar", "type": "F", - "info": "y position at atof bar in mm" + "info": "y position at atof bar (middle surface) in mm" }, { "name": "z_at_bar", "type": "F", - "info": "z position at atof bar in mm" + "info": "z position at atof bar (middle surface) in mm" },{ "name": "L_at_bar", "type": "F", - "info": "path length at atof bar in mm" + "info": "path length at atof bar (inner surface) in mm" },{ "name": "L_in_bar", "type": "F", @@ -28,19 +28,19 @@ },{ "name": "x_at_wedge", "type": "F", - "info": "x position at atof wedge in mm" + "info": "x position at atof wedge (middle surface) in mm" }, { "name": "y_at_wedge", "type": "F", - "info": "y position at atof wedge in mm" + "info": "y position at atof wedge (middle surface) in mm" }, { "name": "z_at_wedge", "type": "F", - "info": "z position at atof wedge in mm" + "info": "z position at atof wedge (middle surface) in mm" },{ "name": "L_at_wedge", "type": "F", - "info": "path length at atof wedge in mm" + "info": "path length at atof wedge (inner surface) in mm" },{ "name": "L_in_wedge", "type": "F", diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index cae3e33f63..aaec5d3b64 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -4,7 +4,7 @@ /** * The {@code TrackProjection} class holds ahdc track information relevant for atof analysis - * i.e projected to the middle surfaces of the bar and wedges + * i.e projected to the surfaces of the bar and wedges * @author pilleux */ @@ -22,13 +22,13 @@ public class TrackProjection { /** * Path length of the track from the DOCA to the beam line - * to the middle surface of the bar. + * to the entrance surface of the bar. */ Float _BarPathLength; /** * Path length of the track from the DOCA to the beam line - * to the middle surface of the wedges. + * to the entrance surface of the wedges. */ Float _WedgePathLength; @@ -74,7 +74,7 @@ public Point3D get_WedgeIntersect() { } /** - * Gets the path length of the track from the DOCA to the beam line to the middle surface of the bar. + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the bar. * * @return {@code Float} path length to the bar's middle surface. */ @@ -83,7 +83,7 @@ public Float get_BarPathLength() { } /** - * Gets the path length of the track from the the middle surface of the bar + * Gets the path length of the track from the inner surface of the bar * to its middle surface. * * @return {@code Float} path length inside the bar. @@ -93,7 +93,7 @@ public Float get_BarInPathLength() { } /** - * Gets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. * * @return {@code Float} path length to the wedge's middle surface. */ @@ -130,18 +130,18 @@ public void set_WedgeIntersect(Point3D WedgeIntersect) { } /** - * Sets the path length of the track from the DOCA to the beam line to the middle surface of the bar. + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the bar. * - * @param BarPathLength {@code Float} path length to the bar middle surface. + * @param BarPathLength {@code Float} path length to the bar inner surface. */ public void set_BarPathLength(Float BarPathLength) { this._BarPathLength = BarPathLength; } /** - * Sets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. * - * @param WedgePathLength {@code Float} path length to the wedge middle surface. + * @param WedgePathLength {@code Float} path length to the wedge inner surface. */ public void set_WedgePathLength(Float WedgePathLength) { this._WedgePathLength = WedgePathLength; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index 652bbfa0c1..bd0b111035 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -139,12 +139,12 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_middle_radius)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) helix.getLAtR(bar_middle_radius)); - projection.set_WedgePathLength((float) helix.getLAtR(wedge_middle_radius)); + projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); + projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength(projection.get_BarPathLength() - (float) helix.getLAtR(bar_innerradius)); - projection.set_WedgeInPathLength(projection.get_WedgePathLength() - (float) helix.getLAtR(wedge_innerradius)); + projection.set_BarInPathLength((float) helix.getLAtR(bar_middle_radius) - projection.get_BarPathLength()); + projection.set_WedgeInPathLength((float) helix.getLAtR(wedge_middle_radius) - projection.get_WedgePathLength()); Projections.add(projection); fill_out_bank(outputBank, projection, i); From ccd62bd07baed21661afefaaac455c08219dc003 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 16 Jan 2025 10:07:22 -0600 Subject: [PATCH 12/82] Some naming conventions --- .../jlab/rec/atof/Cluster/AtofCluster.java | 16 +-- .../jlab/rec/atof/Cluster/ClusterFinder.java | 16 +-- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 132 ++++++++++++------ .../java/org/jlab/rec/atof/Hit/BarHit.java | 20 +-- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 10 +- .../rec/atof/TrackMatch/TrackProjection.java | 2 +- .../rec/atof/TrackMatch/TrackProjector.java | 2 +- 7 files changed, 126 insertions(+), 72 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 102b61b6c3..76e441c7ed 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -1,8 +1,8 @@ -package org.jlab.rec.atof.Cluster; +package org.jlab.rec.atof.cluster; import java.util.ArrayList; -import org.jlab.rec.atof.Hit.AtofHit; -import org.jlab.rec.atof.Hit.BarHit; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; /** * @@ -71,17 +71,17 @@ public void setEnergy(double energy) { this.energy = energy; } - public double getpath_length() { + public double getPath_length() { return path_length; } - public void setpath_length(double path_length) { + public void setPath_length(double path_length) { this.path_length = path_length; } //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later - public void computeClusterProperties() { + public final void computeClusterProperties() { this.energy=0; double max_energy = -1; AtofHit max_energy_hit = new AtofHit(); @@ -109,7 +109,7 @@ public void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); - this.path_length = max_energy_hit.getpath_length(); + this.path_length = max_energy_hit.getPath_length(); } else { @@ -117,7 +117,7 @@ public void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); - this.path_length = max_energy_barhit.getpath_length(); + this.path_length = max_energy_barhit.getPath_length(); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 9830e4615b..b6f50b496c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.Cluster; +package org.jlab.rec.atof.cluster; import cnuphys.magfield.MagneticFields; import java.util.ArrayList; @@ -8,10 +8,10 @@ import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import org.jlab.rec.atof.Hit.AtofHit; -import org.jlab.rec.atof.Hit.BarHit; -import org.jlab.rec.atof.Hit.HitFinder; -import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.hit.HitFinder; +import org.jlab.rec.atof.trackMatch.TrackProjector; import org.jlab.utils.CLASResources; /** @@ -71,7 +71,7 @@ public void MakeClusters(HitFinder hitfinder) { } //Check the distance between the hits //For now we use phi module and z component differences from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.compute_module_index() - other_wedge_hit.compute_module_index()); + int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_wedge_hit.computeModule_index()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -103,7 +103,7 @@ public void MakeClusters(HitFinder hitfinder) { } //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.compute_module_index() - other_bar_hit.compute_module_index()); + int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_bar_hit.computeModule_index()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -152,7 +152,7 @@ public void MakeClusters(HitFinder hitfinder) { //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_bar_hit.compute_module_index() - other_bar_hit.compute_module_index()); + int delta_module = Math.abs(this_bar_hit.computeModule_index() - other_bar_hit.computeModule_index()); if (delta_module > 30) { delta_module = 60 - delta_module; } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 17ceecbef2..d5bbf0ae01 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.Hit; +package org.jlab.rec.atof.hit; import java.util.List; import org.jlab.geom.base.*; @@ -8,21 +8,18 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import org.jlab.rec.atof.TrackMatch.TrackProjection; -import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.rec.atof.trackMatch.TrackProjection; +import org.jlab.rec.atof.trackMatch.TrackProjector; /** - * - * Represents a hit in the atof. - * Stores info about the sector, layer, component, order, TDC, ToT. - * Type is wedge/bar up/bar down - * Spatial coordinates are computed from atof detector object using the geometry service - * Stores whether the hit is part of a cluster. - * Calculates time, energy based on TDC/ToT. - * + * + * Represents a hit in the atof. Stores info about the sector, layer, component, + * order, TDC, ToT. Type is wedge/bar up/bar down Spatial coordinates are + * computed from atof detector object using the geometry service Stores whether + * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. + * * @author npilleux */ - public class AtofHit { private int sector, layer, component, order; @@ -30,7 +27,7 @@ public class AtofHit { private double time, energy, x, y, z; private String type; private boolean is_in_a_cluster; - private double path_length; + private double path_length, inpath_length; public int getSector() { return sector; @@ -136,17 +133,25 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - public double getpath_length() { + public double getPath_length() { return path_length; } - public void setpath_length(double path_length) { + public void setPath_length(double path_length) { this.path_length = path_length; } - - public int compute_module_index(){ + + public double getInpath_length() { + return inpath_length; + } + + public void setInpath_length(double inpath_length) { + this.inpath_length = inpath_length; + } + + public int computeModule_index() { //Index ranging 0 to 60 for each wedge+bar module - return 4*this.sector + this.layer; + return 4 * this.sector + this.layer; } public final String makeType() { @@ -164,50 +169,65 @@ public final String makeType() { public final int TDC_to_time() { double some_conversion = 0; + double veff = 1; if (null == this.type) { return 1; } else { switch (this.type) { - case "wedge" -> + case "wedge" -> { + some_conversion = 10;//read calib constants here + veff = 1; + } + case "bar up" -> { + some_conversion = 10;//read calib constants here + veff = 1; + } + case "bar down" -> { some_conversion = 10;//read calib constants here - case "bar up" -> - some_conversion = 10; - case "bar down" -> - some_conversion = 10; + veff = 1; + } default -> { return 1; } } } - this.time = some_conversion * this.TDC; + //Time at the inner surface + this.time = some_conversion * this.TDC - this.inpath_length / veff; return 0; } public final int ToT_to_energy() { double some_conversion = 0; + double att_L = 1; if (null == this.type) { return 1; } else { switch (this.type) { - case "wedge" -> + case "wedge" -> { + some_conversion = 10;//read calib constants here + att_L = 10; + } + case "bar up" -> { + some_conversion = 10;//read calib constants here + att_L = 10; + } + case "bar down" -> { some_conversion = 10;//read calib constants here - case "bar up" -> - some_conversion = 10; - case "bar down" -> - some_conversion = 10; + att_L = 10; + } default -> { return 1; } } } - this.energy = some_conversion * this.ToT; + this.energy = some_conversion * this.ToT * Math.exp(this.inpath_length / att_L); return 0; } /** - * Calculates spatial coordinates for the hit based on associated - * detector component. Retrieves the midpoint of the atof component - * to assign the corresponding x, y, z coordinates to the hit. + * Calculates spatial coordinates for the hit based on associated detector + * component. Retrieves the midpoint of the atof component to assign the + * corresponding x, y, z coordinates to the hit. * * * @param atof The Detector object representing the atof. @@ -229,7 +249,6 @@ public final int slc_to_xyz(Detector atof) { } } } - Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); this.x = midpoint.x(); @@ -254,7 +273,7 @@ public final int slc_to_xyz(Detector atof) { * @param hit2match The AtofHit object to compare with the current instance. * @return {@code true} if the hits match; {@code false} otherwise. */ - public boolean barmatch(AtofHit hit2match) { + public boolean matchBar(AtofHit hit2match) { if (this.getSector() != hit2match.getSector()) { return false; //System.out.print("Two hits in different sectors \n"); } else if (this.getLayer() != hit2match.getLayer()) { @@ -285,7 +304,7 @@ public double getPhi() { * @param component The component within the layer that registered the hit. * @param order Order of the hit. * @param tdc TDC value. - * @param tot ToT velue. + * @param tot ToT value. * @param atof Detector object representing the atof, used to calculate * spatial coordinates. */ @@ -308,6 +327,41 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot } } + /** + * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * component, 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 layer The layer of the detector where the hit was detected. + * @param component The component within the layer that registered the hit. + * @param order Order of the hit. + * @param tdc TDC value. + * @param tot ToT value. + * @param atof Detector object representing the atof, used to calculate + * @param track_projector TrackProjector object with ahdc tracks to be + * matched to the hit. + */ + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof, TrackProjector track_projector) { + this.sector = sector; + this.layer = layer; + this.component = component; + this.order = order; + this.TDC = tdc; + this.ToT = tot; + this.is_in_a_cluster = false; + + //First the type needs to be set + this.makeType(); + //From it the coordinates can be computed + this.slc_to_xyz(atof); + //From them tracks can be matched + this.matchTrack(track_projector); + //And energy and time can then be computed + this.ToT_to_energy(); + this.TDC_to_time(); + } + /** * Matches the current track with ahdc tracks projections. Calculates the * match by comparing the hit's azimuthal angle and longitudinal position @@ -318,7 +372,7 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * TrackProjections. * */ - public void MatchTrack(TrackProjector track_projector) { + public final void matchTrack(TrackProjector track_projector) { double sigma_phi = 10; double sigma_z = 10; List Projections = track_projector.getProjections(); @@ -340,9 +394,9 @@ public void MatchTrack(TrackProjector track_projector) { if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { - this.setpath_length(Projections.get(i_track).get_WedgePathLength()); + this.setPath_length(Projections.get(i_track).get_WedgePathLength()); } else { - this.setpath_length(Projections.get(i_track).get_BarPathLength()); + this.setPath_length(Projections.get(i_track).get_BarPathLength()); } } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 5365b3255d..8d2e0d5c96 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.Hit; +package org.jlab.rec.atof.hit; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; @@ -9,8 +9,8 @@ import java.util.ArrayList; import java.util.List; import org.jlab.geom.prim.Point3D; -import org.jlab.rec.atof.TrackMatch.TrackProjection; -import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.rec.atof.trackMatch.TrackProjection; +import org.jlab.rec.atof.trackMatch.TrackProjector; /** * @@ -119,11 +119,11 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - public double getpath_length() { + public double getPath_length() { return path_length; } - public void setpath_length(double path_length) { + public void setPath_length(double path_length) { this.path_length = path_length; } @@ -132,12 +132,12 @@ public double getPhi() return Math.atan2(this.y, this.x); } - public int compute_module_index(){ + public int computeModule_index(){ //Index ranging 0 to 60 for each wedge+bar module return 4*this.sector + this.layer; } - public void MatchTrack(TrackProjector track_projector) + public void matchTrack(TrackProjector track_projector) { double sigma_phi = 10; double sigma_z = 10; @@ -149,7 +149,7 @@ public void MatchTrack(TrackProjector track_projector) { if(Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - this.setpath_length(Projections.get(i_track).get_BarPathLength()); + this.setPath_length(Projections.get(i_track).get_BarPathLength()); } } } @@ -157,7 +157,7 @@ public void MatchTrack(TrackProjector track_projector) public BarHit(AtofHit hit_down, AtofHit hit_up) { - boolean hits_match = hit_down.barmatch(hit_up); + boolean hits_match = hit_down.matchBar(hit_up); if(!hits_match) throw new UnsupportedOperationException("Hits do not match \n"); this.hit_up = hit_up; @@ -221,7 +221,7 @@ else switch (hit.getType()) { for(int i_down=0; i_down hit_up.add(hit); case "bar down" -> hit_down.add(hit); - case "wedge" -> {hit.MatchTrack(track_projector); this.wedge_hits.add(hit);} + case "wedge" -> {hit.matchTrack(track_projector); this.wedge_hits.add(hit);} default -> System.out.print("Undefined hit type \n"); } }//End loop through all hits @@ -89,11 +89,11 @@ else switch (hit.getType()) { { AtofHit this_hit_down = hit_down.get(i_down); //Matching the hits: if same module and different order, they make up a bar hit - if(this_hit_up.barmatch(this_hit_down)) + if(this_hit_up.matchBar(this_hit_down)) { //Bar hits are matched to ahdc tracks and listed BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - this_bar_hit.MatchTrack(track_projector); + this_bar_hit.matchTrack(track_projector); this.bar_hits.add(this_bar_hit); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index aaec5d3b64..5138d15083 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.TrackMatch; +package org.jlab.rec.atof.trackMatch; import org.jlab.geom.prim.Point3D; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index bd0b111035..f8e2b3c8c0 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.TrackMatch; +package org.jlab.rec.atof.trackMatch; import java.util.ArrayList; import java.util.List; From 32dd3028dc72f2b6698e8edc7fafcdff942678b8 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 09:44:52 -0600 Subject: [PATCH 13/82] Handling parameters + method for testing --- .../rec/atof/TrackMatch/TrackProjector.java | 88 +++++++++++++++---- .../jlab/rec/atof/constants/Parameters.java | 44 ++++++++++ 2 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index f8e2b3c8c0..cca125510c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -11,6 +11,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.utils.CLASResources; import cnuphys.magfield.MagneticFields; +import org.jlab.rec.atof.constants.Parameters; /** * The {@code TrackProjector} class projects ahdc tracks to the inner surfaces @@ -95,13 +96,6 @@ public void setB(Double B) { public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { Projections.clear(); - //All of these are in MM - double bar_innerradius = 77; //NEEDS TO BE REPLACED WITH DB CONSTANTS something like ccdb.INNERRADIUS[0] - double wedge_innerradius = 80; - double bar_thickness = 3; - double wedge_thickness = 20; - double bar_middle_radius = bar_innerradius + bar_thickness/2; - double wedge_middle_radius = wedge_innerradius + wedge_thickness/2; String track_bank_name = "AHDC::Track"; @@ -125,27 +119,91 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) double py = bank.getFloat("py", i); double pz = bank.getFloat("pz", i); - int q = 1; //this has to be changed, we need the charge info from tracking + int q = 1; //need the charge sign from tracking Units units = Units.MM; //can be MM or CM. double xb = 0; double yb = 0; - Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + //momenta must be in GeV for the helix class + Helix helix = new Helix(x, y, z, px/1000., py/1000., pz/1000., q, B, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(bar_middle_radius)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_middle_radius)); + projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); - projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); + projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) helix.getLAtR(bar_middle_radius) - projection.get_BarPathLength()); - projection.set_WedgeInPathLength((float) helix.getLAtR(wedge_middle_radius) - projection.get_WedgePathLength()); + projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); + projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); + Projections.add(projection); + fill_out_bank(outputBank, projection, i); + } + event.appendBank(outputBank); + } + } + + /** + * Projects the MC particles onto the atof using a {@link Helix} + * model. + * + * @param event the {@link DataEvent} containing track data to be projected. + */ + public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { + + Projections.clear(); + + String track_bank_name = "MC::Particle"; + if (event == null) { // check if there is an event + //System.out.print(" no event \n"); + } else if (event.hasBank(track_bank_name) == false) { + // check if there are ahdc tracks in the event + //System.out.print("no tracks \n"); + } else { + DataBank bank = event.getBank(track_bank_name); + int nt = bank.rows(); // number of tracks + TrackProjection projection = new TrackProjection(); + DataBank outputBank = event.createBank("AHDC::Projections", nt); + + for (int i = 0; i < nt; i++) { + + double x = bank.getFloat("vx", i); + double y = bank.getFloat("vy", i); + double z = bank.getFloat("vz", i); + double px = bank.getFloat("px", i); + double py = bank.getFloat("py", i); + double pz = bank.getFloat("pz", i); + + //Put everything in MM + x = x*10; + y = y*10; + z = z*10; + Units units = Units.MM; + + int q = 1; //need the charge sign from tracking + + double xb = 0; + double yb = 0; + + //momenta must be in GeV for the helix class + Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + + //Intersection points with the middle of the bar or wedge + projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); + + //Path length to the middle of the bar or wedge + projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); + + //Path length from the inner radius to the middle radius + projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); + projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); Projections.add(projection); fill_out_bank(outputBank, projection, i); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java new file mode 100644 index 0000000000..d76a38d9e2 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -0,0 +1,44 @@ +package org.jlab.rec.atof.constants; + +/** + * + * @author npilleux + */ +public class Parameters { + + Parameters() { + } + + //In millimiters + public static final double BAR_INNER_RADIUS = 77; + public static final double WEDGE_INNER_RADIUS = 80; + public static final double BAR_THICKNESS = 3; + public static final double WEDGE_THICKNESS = 20; + public static final double BAR_MIDDLE_RADIUS = BAR_INNER_RADIUS + BAR_THICKNESS / 2; + public static final double WEDGE_MIDDLE_RADIUS = WEDGE_INNER_RADIUS + WEDGE_THICKNESS / 2; + + + public static final double VEFF = 200.0;//mm/ns + public static final double TDC2TIME = 0.015625;//ns per channel bin + public static final double ATT_L = 1600.0;//mm + public static final double TOT2ENERGY_BAR = 1.956 * 0.3;//MeV? To be checked. + public static final double TOT2ENERGY_WEDGE = 1.956 * 2.0;//MeV? To be checked. + + public static double LENGTH_ATOF = 279.7; //detector length in mm + + public static double SIGMA_PHI_TRACK_MATCHING_BAR = 180 * Math.PI/180.;//in rad + public static double SIGMA_PHI_TRACK_MATCHING_WEDGE = 180 * Math.PI/180.;//in rad + + public static double SIGMA_Z_TRACK_MATCHING_BAR = 150;//in mm + public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 150;//in mm + + public static double SIGMA_PHI_CLUSTERING = 6;//in deg + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + } + +} From 584db56fc817af51f1ed889a099e3cc7050048a0 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 09:48:20 -0600 Subject: [PATCH 14/82] Handling parameters + bank input --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 107 ++++++++--- .../java/org/jlab/rec/atof/Hit/BarHit.java | 170 ++++++++++-------- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 59 ++++++ 3 files changed, 233 insertions(+), 103 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index d5bbf0ae01..ef5889f8ef 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -8,6 +8,7 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.trackMatch.TrackProjection; import org.jlab.rec.atof.trackMatch.TrackProjector; @@ -168,23 +169,23 @@ public final String makeType() { } public final int TDC_to_time() { - double some_conversion = 0; + double tdc2time = 1; double veff = 1; if (null == this.type) { return 1; } else { switch (this.type) { case "wedge" -> { - some_conversion = 10;//read calib constants here - veff = 1; + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; } case "bar up" -> { - some_conversion = 10;//read calib constants here - veff = 1; + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; } case "bar down" -> { - some_conversion = 10;//read calib constants here - veff = 1; + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; } default -> { return 1; @@ -192,35 +193,35 @@ public final int TDC_to_time() { } } //Time at the inner surface - this.time = some_conversion * this.TDC - this.inpath_length / veff; + this.time = tdc2time * this.TDC - this.inpath_length / veff; return 0; } public final int ToT_to_energy() { - double some_conversion = 0; + double tot2energy = 1; double att_L = 1; if (null == this.type) { return 1; } else { switch (this.type) { case "wedge" -> { - some_conversion = 10;//read calib constants here - att_L = 10; + tot2energy = Parameters.TOT2ENERGY_WEDGE; + att_L = Parameters.ATT_L; } case "bar up" -> { - some_conversion = 10;//read calib constants here - att_L = 10; + tot2energy = Parameters.TOT2ENERGY_WEDGE; + att_L = Parameters.ATT_L; } case "bar down" -> { - some_conversion = 10;//read calib constants here - att_L = 10; + tot2energy = Parameters.TOT2ENERGY_BAR; + att_L = Parameters.ATT_L; } default -> { return 1; } } } - this.energy = some_conversion * this.ToT * Math.exp(this.inpath_length / att_L); + this.energy = tot2energy * this.ToT * Math.exp(this.inpath_length / att_L); return 0; } @@ -251,9 +252,11 @@ public final int slc_to_xyz(Detector atof) { } Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); - this.x = midpoint.x(); - this.y = midpoint.y(); - this.z = midpoint.z(); + + //coordinates centered at the center of the atof in mm + this.x = midpoint.x() - Parameters.LENGTH_ATOF / 2.; + this.y = midpoint.y() - Parameters.LENGTH_ATOF / 2.; + this.z = midpoint.z() - Parameters.LENGTH_ATOF / 2.; return 0; } @@ -373,24 +376,31 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * */ public final void matchTrack(TrackProjector track_projector) { - double sigma_phi = 10; - double sigma_z = 10; + double sigma_phi = 0; + double sigma_z = 0; + List Projections = track_projector.getProjections(); for (int i_track = 0; i_track < Projections.size(); i_track++) { Point3D projection_point = new Point3D(); if (null == this.getType()) { - System.out.print("Impossible to match track and hitm hit type is undefined \n"); + System.out.print("Impossible to match track and hit; hit type is null \n"); } else { switch (this.getType()) { - case "wedge" -> + case "wedge" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; projection_point = Projections.get(i_track).get_WedgeIntersect(); - case "bar up", "bar down" -> + } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; projection_point = Projections.get(i_track).get_BarIntersect(); + } default -> - System.out.print("Impossible to match track and hitm hit type is undefined \n"); + System.out.print("Impossible to match track and hit; hit type is undefined \n"); } } - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { @@ -403,6 +413,51 @@ public final void matchTrack(TrackProjector track_projector) { } } + public void matchTrack(DataBank track_bank) { + int nt = track_bank.rows(); // number of tracks + double sigma_phi = 0; + double sigma_z = 0; + + //Looping through all tracks + for (int i = 0; i < nt; i++) { + + Float xt = null,yt = null,zt=null,path = null; + + if (null == this.getType()) { + System.out.print("Impossible to match track and hit; hit type is null \n"); + } else { + switch (this.getType()) { + case "wedge" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; + xt = track_bank.getFloat("x_at_wedge", i); + yt = track_bank.getFloat("y_at_wedge", i); + zt = track_bank.getFloat("z_at_wedge", i); + path = track_bank.getFloat("L_at_wedge", i); + } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; + xt = track_bank.getFloat("x_at_bar", i); + yt = track_bank.getFloat("y_at_bar", i); + zt = track_bank.getFloat("z_at_bar", i); + path = track_bank.getFloat("L_at_bar", i); + } + default -> + System.out.print("Impossible to match track and hit; hit type is undefined \n"); + } + } + Point3D projection_point = new Point3D(xt, yt, zt); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { + if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { + this.setPath_length(path); + } + } + } + + } + public AtofHit() { } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 8d2e0d5c96..9c1428cbae 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.trackMatch.TrackProjection; import org.jlab.rec.atof.trackMatch.TrackProjector; @@ -17,14 +18,14 @@ * @author npilleux */ public class BarHit { - + //A bar hit is the combination of a downstream and upstream hits private AtofHit hit_up, hit_down; - private double x,y,z, time, energy; + private double x, y, z, time, energy; int sector, layer; private boolean is_in_a_cluster; private double path_length; - + public AtofHit getHitUp() { return hit_up; } @@ -64,18 +65,18 @@ public double getZ() { public void setZ(double z) { this.z = z; } - - public void computeZ() { + + public final void computeZ() { double some_calibration = 10; //Here read the calibration DB this.z = some_calibration * (hit_up.getTime() - hit_down.getTime()); } - - public void computeTime() { + + public final void computeTime() { double some_calibration = 10; //Here read the calibration DB - this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime())/2.); + this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.); } - - public void computeEnergy() { + + public final void computeEnergy() { this.energy = (hit_up.getEnergy() + hit_down.getEnergy()); } @@ -110,7 +111,7 @@ public int getLayer() { public void setLayer(int layer) { this.layer = layer; } - + public boolean getIs_in_a_cluster() { return is_in_a_cluster; } @@ -118,7 +119,7 @@ public boolean getIs_in_a_cluster() { public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - + public double getPath_length() { return path_length; } @@ -126,64 +127,75 @@ public double getPath_length() { public void setPath_length(double path_length) { this.path_length = path_length; } - - public double getPhi() - { + + public double getPhi() { return Math.atan2(this.y, this.x); } - - public int computeModule_index(){ + + public int computeModule_index() { //Index ranging 0 to 60 for each wedge+bar module - return 4*this.sector + this.layer; + return 4 * this.sector + this.layer; } - - public void matchTrack(TrackProjector track_projector) - { - double sigma_phi = 10; - double sigma_z = 10; + + public void matchTrack(TrackProjector track_projector) { List Projections = track_projector.getProjections(); - for(int i_track = 0; i_track < Projections.size(); i_track++) - { - Point3D projection_point = Projections.get(i_track).get_BarIntersect(); - if(Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) - { - if(Math.abs(this.getZ() - projection_point.z()) < sigma_z) - { - this.setPath_length(Projections.get(i_track).get_BarPathLength()); - } - } + for (int i_track = 0; i_track < Projections.size(); i_track++) { + Point3D projection_point = Projections.get(i_track).get_BarIntersect(); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { + if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { + this.setPath_length(Projections.get(i_track).get_BarPathLength()); + } } } - - public BarHit(AtofHit hit_down, AtofHit hit_up) - { - boolean hits_match = hit_down.matchBar(hit_up); - if(!hits_match) throw new UnsupportedOperationException("Hits do not match \n"); - - this.hit_up = hit_up; - this.hit_down = hit_down; - this.layer = hit_up.getLayer(); - this.sector = hit_up.getSector(); - this.x = hit_up.getX(); - this.y = hit_up.getY(); - this.computeZ(); - this.computeTime(); - this.computeEnergy(); - } - - public BarHit() - { - } - + } + + public void matchTrack(DataBank track_bank) { + int nt = track_bank.rows(); // number of tracks + //Looping through all tracks + for (int i = 0; i < nt; i++) { + //Getting their properties + Float xt = track_bank.getFloat("x_at_bar", i); + Float yt = track_bank.getFloat("y_at_bar", i); + Float zt = track_bank.getFloat("z_at_bar", i); + Float path = track_bank.getFloat("L_at_bar", i); + Point3D projection_point = new Point3D(xt, yt, zt); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { + if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { + this.setPath_length(path); + } + } + } + } + + public BarHit(AtofHit hit_down, AtofHit hit_up) { + boolean hits_match = hit_down.matchBar(hit_up); + if (!hits_match) { + throw new UnsupportedOperationException("Hits do not match \n"); + } + + this.hit_up = hit_up; + this.hit_down = hit_down; + this.layer = hit_up.getLayer(); + this.sector = hit_up.getSector(); + this.x = hit_up.getX(); + this.y = hit_up.getY(); + this.computeZ(); + this.computeTime(); + this.computeEnergy(); + } + + public BarHit() { + } + /** * @param args the command line arguments */ - public static void main(String[] args) { + public static void main(String[] args) { // TODO code application logic here AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); - + //Input to be read String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; HipoDataSource reader = new HipoDataSource(); @@ -195,9 +207,9 @@ public static void main(String[] args) { event_number++; DataBank bank = event.getBank("ATOF::tdc"); int nt = bank.rows(); // number of tracks - ArrayList hit_up = new ArrayList<>(); - ArrayList hit_down = new ArrayList<>(); - ArrayList hit_wedge = new ArrayList<>(); + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); + ArrayList hit_wedge = new ArrayList<>(); for (int i = 0; i < nt; i++) { int sector = bank.getInt("sector", i); int layer = bank.getInt("layer", i); @@ -206,28 +218,32 @@ public static void main(String[] args) { int tdc = bank.getInt("TDC", i); int tot = bank.getInt("ToT", i); AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - 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); - case "wedge" -> hit_wedge.add(hit); - default -> System.out.print("Undefined hit type \n"); + 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); + case "wedge" -> + hit_wedge.add(hit); + default -> + System.out.print("Undefined hit type \n"); + } } } - ArrayList bar_hits = new ArrayList(); - for(int i_up=0; i_up bar_hits = new ArrayList(); + for (int i_up = 0; i_up < hit_up.size(); i_up++) { AtofHit this_hit_up = hit_up.get(i_up); - for(int i_down=0; i_down Double.compare(hit1.getEnergy(), hit2.getEnergy())); } + public void FindHits(DataEvent event, Detector atof) { + + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank + DataBank bank_atof_hits = event.getBank("ATOF::tdc"); + DataBank bank_track = event.getBank("AHDC::Projection"); + int nt = bank_atof_hits.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_atof_hits.getInt("sector", i); + int layer = bank_atof_hits.getInt("layer", i); + int component = bank_atof_hits.getInt("component", i); + int order = bank_atof_hits.getInt("order", i); + int tdc = bank_atof_hits.getInt("TDC", i); + int tot = bank_atof_hits.getInt("ToT", i); + //Building a Hit + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if(hit.getEnergy() < 0.1 )continue; //energy threshold + //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed + 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); + case "wedge" -> {hit.matchTrack(bank_track); this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + } + /** * @param args the command line arguments From 5b652eaf428d4d7d414ef64b4d43108e252a1481 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:11:19 -0600 Subject: [PATCH 15/82] Correcting conversion to MeV --- .../main/java/org/jlab/rec/atof/constants/Parameters.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java index d76a38d9e2..89c7cce60e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -21,16 +21,16 @@ public class Parameters { public static final double VEFF = 200.0;//mm/ns public static final double TDC2TIME = 0.015625;//ns per channel bin public static final double ATT_L = 1600.0;//mm - public static final double TOT2ENERGY_BAR = 1.956 * 0.3;//MeV? To be checked. - public static final double TOT2ENERGY_WEDGE = 1.956 * 2.0;//MeV? To be checked. + public static final double TOT2ENERGY_BAR = 1.956 * 0.3 /1000;//to MeV + public static final double TOT2ENERGY_WEDGE = 1.956 * 2.0 /1000;//to MeV public static double LENGTH_ATOF = 279.7; //detector length in mm public static double SIGMA_PHI_TRACK_MATCHING_BAR = 180 * Math.PI/180.;//in rad public static double SIGMA_PHI_TRACK_MATCHING_WEDGE = 180 * Math.PI/180.;//in rad - public static double SIGMA_Z_TRACK_MATCHING_BAR = 150;//in mm - public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 150;//in mm + public static double SIGMA_Z_TRACK_MATCHING_BAR = 200;//in mm + public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 200;//in mm public static double SIGMA_PHI_CLUSTERING = 6;//in deg From 02c89e0622c1e24bd6687cd8f922def4a99916e2 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:12:21 -0600 Subject: [PATCH 16/82] Refactoring BarHit definition, now inherits from AtofHit --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 117 ++++--- .../java/org/jlab/rec/atof/Hit/BarHit.java | 149 ++------ .../java/org/jlab/rec/atof/Hit/HitFinder.java | 325 +++++++++++------- 3 files changed, 294 insertions(+), 297 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index ef5889f8ef..77b23dad4d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -15,7 +15,7 @@ /** * * Represents a hit in the atof. Stores info about the sector, layer, component, - * order, TDC, ToT. Type is wedge/bar up/bar down Spatial coordinates are + * order, TDC, ToT. Type is wedge/bar up/bar down/ bar Spatial coordinates are * computed from atof detector object using the geometry service Stores whether * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. * @@ -187,6 +187,10 @@ public final int TDC_to_time() { tdc2time = Parameters.TDC2TIME; veff = Parameters.VEFF; } + case "bar" -> { + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; + } default -> { return 1; } @@ -199,29 +203,34 @@ public final int TDC_to_time() { public final int ToT_to_energy() { double tot2energy = 1; - double att_L = 1; if (null == this.type) { return 1; } else { switch (this.type) { case "wedge" -> { tot2energy = Parameters.TOT2ENERGY_WEDGE; - att_L = Parameters.ATT_L; + //For now hits are considered in the middle of the wedge + //And the SiPM on top + double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS/2.; + this.energy = tot2energy * this.ToT * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); } case "bar up" -> { - tot2energy = Parameters.TOT2ENERGY_WEDGE; - att_L = Parameters.ATT_L; + tot2energy = Parameters.TOT2ENERGY_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_BAR; - att_L = Parameters.ATT_L; - } + //only half the information in the bar, + //the attenuation will be computed when the full hit is formed + this.energy = tot2energy * this.ToT; + } default -> { return 1; } } } - this.energy = tot2energy * this.ToT * Math.exp(this.inpath_length / att_L); return 0; } @@ -243,7 +252,7 @@ public final int slc_to_xyz(Detector atof) { switch (this.type) { case "wedge" -> sl = 1; - case "bar up", "bar down" -> + case "bar up", "bar down", "bar" -> sl = 0; default -> { return 1; @@ -283,6 +292,8 @@ public boolean matchBar(AtofHit hit2match) { return false; //System.out.print("Two hits in different layers \n"); } else if (this.getComponent() != 10 || hit2match.getComponent() != 10) { return false; //System.out.print("At least one hit is not in the bar \n"); + } else if (this.getOrder() > 1 || hit2match.getComponent() > 1) { + return false; //System.out.print("At least one hit is not a downstram or upstream hit. It may be a full bar hit. \n"); } else { return this.getOrder() != hit2match.getOrder(); //System.out.print("Two hits in same SiPM \n"); } @@ -413,49 +424,65 @@ public final void matchTrack(TrackProjector track_projector) { } } - public void matchTrack(DataBank track_bank) { - int nt = track_bank.rows(); // number of tracks - double sigma_phi = 0; - double sigma_z = 0; + public int matchTrack(DataEvent event) { - //Looping through all tracks - for (int i = 0; i < nt; i++) { + String track_bank_name = "AHDC::Projections"; + if (event == null) { // check if there is an event + //System.out.print(" no event \n"); + return 1; + } else if (event.hasBank(track_bank_name) == false) { + return 1; + // check if there are ahdc tracks in the event + //System.out.print("no tracks \n"); + } else { + DataBank track_bank = event.getBank(track_bank_name); + int nt = track_bank.rows(); // number of tracks + double sigma_phi = 0; + double sigma_z = 0; - Float xt = null,yt = null,zt=null,path = null; - - if (null == this.getType()) { - System.out.print("Impossible to match track and hit; hit type is null \n"); - } else { - switch (this.getType()) { - case "wedge" -> { - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; - xt = track_bank.getFloat("x_at_wedge", i); - yt = track_bank.getFloat("y_at_wedge", i); - zt = track_bank.getFloat("z_at_wedge", i); - path = track_bank.getFloat("L_at_wedge", i); - } - case "bar up", "bar down" -> { - System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; - xt = track_bank.getFloat("x_at_bar", i); - yt = track_bank.getFloat("y_at_bar", i); - zt = track_bank.getFloat("z_at_bar", i); - path = track_bank.getFloat("L_at_bar", i); + //Looping through all tracks + for (int i = 0; i < nt; i++) { + + Float xt = null, yt = null, zt = null, path = null, inpath = null; + + if (null == this.getType()) { + System.out.print("Impossible to match track and hit; hit type is null \n"); + } else { + switch (this.getType()) { + case "wedge" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; + xt = track_bank.getFloat("x_at_wedge", i); + yt = track_bank.getFloat("y_at_wedge", i); + zt = track_bank.getFloat("z_at_wedge", i); + path = track_bank.getFloat("L_at_wedge", i); + inpath = track_bank.getFloat("L_in_wedge", i); + } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; + xt = track_bank.getFloat("x_at_bar", i); + yt = track_bank.getFloat("y_at_bar", i); + zt = track_bank.getFloat("z_at_bar", i); + path = track_bank.getFloat("L_at_bar", i); + inpath = track_bank.getFloat("L_in_bar", i); + } + default -> + System.out.print("Impossible to match track and hit; hit type is undefined \n"); } - default -> - System.out.print("Impossible to match track and hit; hit type is undefined \n"); } - } - Point3D projection_point = new Point3D(xt, yt, zt); - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { - if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - this.setPath_length(path); + Point3D projection_point = new Point3D(xt, yt, zt); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { + if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { + System.out.print("PASSED CUTS \n"); + this.setPath_length(path); + this.setInpath_length(inpath); + } } } } - + return 0; } public AtofHit() { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 9c1428cbae..b71a03b86b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -7,24 +7,20 @@ import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; import java.util.ArrayList; -import java.util.List; -import org.jlab.geom.prim.Point3D; import org.jlab.rec.atof.constants.Parameters; -import org.jlab.rec.atof.trackMatch.TrackProjection; -import org.jlab.rec.atof.trackMatch.TrackProjector; /** + * + * Represents a hit in the atof bar. Extends class AtofHit. Is further defined + * by the two hits upstream and downstream composing a full bar hit. z position, + * time and energy are defined from the up/down hits * * @author npilleux */ -public class BarHit { +public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits private AtofHit hit_up, hit_down; - private double x, y, z, time, energy; - int sector, layer; - private boolean is_in_a_cluster; - private double path_length; public AtofHit getHitUp() { return hit_up; @@ -42,129 +38,23 @@ public void setHitDown(AtofHit hit_down) { this.hit_down = hit_down; } - 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 final void computeZ() { double some_calibration = 10; //Here read the calibration DB - this.z = some_calibration * (hit_up.getTime() - hit_down.getTime()); + this.setZ(some_calibration * (hit_up.getTime() - hit_down.getTime())); } public final void computeTime() { double some_calibration = 10; //Here read the calibration DB - this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.); + this.setTime(some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.)); } public final void computeEnergy() { - this.energy = (hit_up.getEnergy() + hit_down.getEnergy()); - } - - 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 int getSector() { - return sector; - } - - public void setSector(int sector) { - this.sector = sector; - } - - public int getLayer() { - return layer; - } - - public void setLayer(int layer) { - this.layer = layer; - } - - public boolean getIs_in_a_cluster() { - return is_in_a_cluster; - } - - public void setIs_in_a_cluster(boolean is_in_a_cluster) { - this.is_in_a_cluster = is_in_a_cluster; - } - - public double getPath_length() { - return path_length; - } - - public void setPath_length(double path_length) { - this.path_length = path_length; - } - - public double getPhi() { - return Math.atan2(this.y, this.x); - } - - public int computeModule_index() { - //Index ranging 0 to 60 for each wedge+bar module - return 4 * this.sector + this.layer; - } - - public void matchTrack(TrackProjector track_projector) { - List Projections = track_projector.getProjections(); - for (int i_track = 0; i_track < Projections.size(); i_track++) { - Point3D projection_point = Projections.get(i_track).get_BarIntersect(); - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { - if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { - this.setPath_length(Projections.get(i_track).get_BarPathLength()); - } - } - } - } - - public void matchTrack(DataBank track_bank) { - int nt = track_bank.rows(); // number of tracks - //Looping through all tracks - for (int i = 0; i < nt; i++) { - //Getting their properties - Float xt = track_bank.getFloat("x_at_bar", i); - Float yt = track_bank.getFloat("y_at_bar", i); - Float zt = track_bank.getFloat("z_at_bar", i); - Float path = track_bank.getFloat("L_at_bar", i); - Point3D projection_point = new Point3D(xt, yt, zt); - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { - if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { - this.setPath_length(path); - } - } - } + this.computeZ(); + double distance_hit_to_sipm_up = Parameters.LENGTH_ATOF / 2. + this.getZ(); + double distance_hit_to_sipm_down = Parameters.LENGTH_ATOF / 2. - this.getZ(); + double Edep_up = hit_up.getEnergy() * Math.exp(distance_hit_to_sipm_up / Parameters.ATT_L); + double Edep_down = hit_down.getEnergy() * Math.exp(distance_hit_to_sipm_down / Parameters.ATT_L); + this.setEnergy(Edep_up + Edep_down); } public BarHit(AtofHit hit_down, AtofHit hit_up) { @@ -172,13 +62,14 @@ public BarHit(AtofHit hit_down, AtofHit 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.hit_up = hit_up; this.hit_down = hit_down; - this.layer = hit_up.getLayer(); - this.sector = hit_up.getSector(); - this.x = hit_up.getX(); - this.y = hit_up.getY(); + this.setLayer(hit_up.getLayer()); + this.setSector(hit_up.getSector()); + this.setX(hit_up.getX()); + this.setY(hit_up.getY()); this.computeZ(); this.computeTime(); this.computeEnergy(); @@ -233,7 +124,7 @@ public static void main(String[] args) { } } } - ArrayList bar_hits = new ArrayList(); + ArrayList bar_hits = new ArrayList<>(); for (int i_up = 0; i_up < hit_up.size(); i_up++) { AtofHit this_hit_up = hit_up.get(i_up); for (int i_down = 0; i_down < hit_down.size(); i_down++) { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index c8d784cc27..adece84948 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -3,30 +3,34 @@ import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.Collections; +import javax.swing.JFrame; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.groot.data.H1F; +import org.jlab.groot.graphics.EmbeddedCanvas; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofHitBank; import org.jlab.rec.atof.trackMatch.TrackProjector; import org.jlab.utils.CLASResources; + /** * * @author npilleux */ public class HitFinder { - + private ArrayList bar_hits; private ArrayList wedge_hits; - - public HitFinder() - { - this.bar_hits = new ArrayList<>(); - this.wedge_hits = new ArrayList<>(); - } - + + public HitFinder() { + this.bar_hits = new ArrayList<>(); + this.wedge_hits = new ArrayList<>(); + } + // Getter and Setter for bar_hits public ArrayList getBarHits() { return bar_hits; @@ -44,130 +48,147 @@ public ArrayList getWedgeHits() { public void setWedgeHits(ArrayList wedge_hits) { this.wedge_hits = wedge_hits; } - + public void FindHits(DataEvent event, Detector atof, TrackProjector track_projector) { - //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); - //They are read from the ATOF TDC bank - DataBank bank = event.getBank("ATOF::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.getInt("sector", i); - int layer = bank.getInt("layer", i); - int component = bank.getInt("component", i); - int order = bank.getInt("order", i); - int tdc = bank.getInt("TDC", i); - int tot = bank.getInt("ToT", i); - //Building a Hit - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if(hit.getEnergy() < 0.1 )continue; //energy threshold - //Sorting the hits into wedge, upstream and downstream bar hits - //Lists are built for up/down bar to match them after - //Wedge hits are mayched to ahdc tracks and listed - 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); - case "wedge" -> {hit.matchTrack(track_projector); this.wedge_hits.add(hit);} - default -> System.out.print("Undefined hit type \n"); + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank + DataBank bank = event.getBank("ATOF::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.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + //Building a Hit + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if (hit.getEnergy() < 0.1) { + continue; //energy threshold + } //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed + 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); + case "wedge" -> { + hit.matchTrack(track_projector); + this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); } - + //Once all has been listed, hits are sorted by energy + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + } + public void FindHits(DataEvent event, Detector atof) { - //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); - //They are read from the ATOF TDC bank - DataBank bank_atof_hits = event.getBank("ATOF::tdc"); - DataBank bank_track = event.getBank("AHDC::Projection"); - int nt = bank_atof_hits.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_atof_hits.getInt("sector", i); - int layer = bank_atof_hits.getInt("layer", i); - int component = bank_atof_hits.getInt("component", i); - int order = bank_atof_hits.getInt("order", i); - int tdc = bank_atof_hits.getInt("TDC", i); - int tot = bank_atof_hits.getInt("ToT", i); - //Building a Hit - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if(hit.getEnergy() < 0.1 )continue; //energy threshold - //Sorting the hits into wedge, upstream and downstream bar hits - //Lists are built for up/down bar to match them after - //Wedge hits are mayched to ahdc tracks and listed - 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); - case "wedge" -> {hit.matchTrack(bank_track); this.wedge_hits.add(hit);} - default -> System.out.print("Undefined hit type \n"); + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank + DataBank bank_atof_hits = event.getBank("ATOF::tdc"); + int nt = bank_atof_hits.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_atof_hits.getInt("sector", i); + int layer = bank_atof_hits.getInt("layer", i); + int component = bank_atof_hits.getInt("component", i); + int order = bank_atof_hits.getInt("order", i); + int tdc = bank_atof_hits.getInt("TDC", i); + int tot = bank_atof_hits.getInt("ToT", i); + //Building a Hit + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if (hit.getEnergy() < 0.1) { + continue; //energy threshold + } //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed + 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); + case "wedge" -> { + hit.matchTrack(event); + this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); } - + //Once all has been listed, hits are sorted by energy + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + ArrayList allhits = new ArrayList<>();; + allhits.addAll(this.wedge_hits); + allhits.addAll(this.bar_hits); + DataBank hitbank = fillAtofHitBank(event, allhits); + event.appendBank(hitbank); + } /** * @param args the command line arguments */ public static void main(String[] args) { - + //Building ALERT geometry AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); @@ -190,26 +211,84 @@ public static void main(String[] args) { //Track Projector Initialisation with B field TrackProjector projector = new TrackProjector(); projector.setB(B); - + //Hit finder init HitFinder hitfinder = new HitFinder(); - + //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/updated_updated_rec_more_protons_50_to_650.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); + H1F h_delta_energy = new H1F("Energy", "Energy", 100, -10, 10); + h_delta_energy.setTitleX("delta energy [GeV]"); + int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - projector.ProjectTracks(event); - hitfinder.FindHits(event, atof, projector); + hitfinder.FindHits(event, atof); + DataBank MC_True = event.getBank("MC::True"); + DataBank tdc = event.getBank("ATOF::tdc"); + DataBank hits = event.getBank("ATOF::hits"); + double totEdep = 0; + + for (int i = 0; i < MC_True.rows(); i++) { + + if (MC_True.getByte("detector", i) != 24) { + continue; + } + Float true_energy = MC_True.getFloat("avgT", i); + if (true_energy < 5) { + continue; + } + System.out.print(true_energy + " TRUE \n"); + double min_diff = 9999.; + double energy_at_min = 9999.; + + for (int j = 0; j < hits.rows(); j++) { + Float hit_energy = hits.getFloat("time", j); + Float diff = true_energy - hit_energy; + if (diff < min_diff) { + min_diff = diff; + energy_at_min = true_energy; + } + } + System.out.print("ICI " + energy_at_min + " " + true_energy + " \n"); + h_delta_energy.fill(min_diff / energy_at_min); } + System.out.print("------------------- \n"); + } + + System.out.print ( + + "Read " + event_number + " events"); + JFrame frame = new JFrame("Raster"); + + frame.setSize ( + + 2500,800); + EmbeddedCanvas canvas = new EmbeddedCanvas(); + + canvas.divide ( + + + 3,2); + canvas.cd ( + + + 3); canvas.draw (h_delta_energy); + + frame.add (canvas); + + frame.setLocationRelativeTo ( + + + null); + frame.setVisible ( + - System.out.print("Read " + event_number + " events"); +true); } } - \ No newline at end of file From bd04a6e00cbf99482042e903aa1fa86224b940a3 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:13:03 -0600 Subject: [PATCH 17/82] ATOF hit bank --- etc/bankdefs/hipo4/alert.json | 58 +++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index e616780db4..ea6f4e251b 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -4,7 +4,7 @@ "group": 23000, "item": 31, "info": "Track Projections to ATOF", - "entries": [ + "entries": [ { "name": "x_at_bar", "type": "F", @@ -20,7 +20,7 @@ },{ "name": "L_at_bar", "type": "F", - "info": "path length at atof bar (inner surface) in mm" + "info": "path length at atof bar (inner surface) in mm" },{ "name": "L_in_bar", "type": "F", @@ -28,7 +28,7 @@ },{ "name": "x_at_wedge", "type": "F", - "info": "x position at atof wedge (middle surface) in mm" + "info": "x position at atof wedge (middle surface) in mm" }, { "name": "y_at_wedge", "type": "F", @@ -48,6 +48,58 @@ } ] },{ + "name": "ATOF::hits", + "group": 22500, + "item": 21, + "info": "Hits in ATOF", + "entries": [ + { + "name": "id", + "type": "S", + "info": "hit id" + }, { + "name": "sector", + "type": "I", + "info": "atof sector" + }, { + "name": "layer", + "type": "I", + "info": "atof layer" + },{ + "name": "component", + "type": "I", + "info": "atof component" + },{ + "name": "time", + "type": "F", + "info": "time in ns" + },{ + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + },{ + "name": "energy", + "type": "F", + "info": "deposited energy in MeV" + },{ + "name": "inlength", + "type": "F", + "info": "path length inside the detector (from entrance to hit) in mm" + },{ + "name": "pathlength", + "type": "F", + "info": "path length to the hit in mm" + } + ] + },{ "name": "AHDC::Hits", "group": 23000, "item": 23, From 1cdd48456d36ea33713bba9064696af8ccc7b9a2 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:18:14 -0600 Subject: [PATCH 18/82] ATOF bank writer --- .../jlab/rec/atof/banks/RecoBankWriter.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java new file mode 100644 index 0000000000..94479d9379 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -0,0 +1,53 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template + */ +package org.jlab.rec.atof.banks; + +import java.util.ArrayList; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.atof.hit.AtofHit; + +/** + * + * @author npilleux + */ +public class RecoBankWriter { + + // write useful information in the bank + public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitlist) { + + DataBank bank = event.createBank("ATOF::hits", hitlist.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + return null; + } + + for(int i =0; i< hitlist.size(); i++) { + bank.setShort("id",i, (short)(i+1)); + bank.setInt("sector",i, (int) hitlist.get(i).getSector()); + bank.setInt("layer",i, (int) hitlist.get(i).getLayer()); + bank.setInt("component",i, (int) hitlist.get(i).getComponent()); + //bank.setShort("trkID",i, (short) hitlist.get(i).get_AssociatedTrkId()); + //bank.setShort("clusterid", i, (short) hitlist.get(i).get_AssociatedClusterID()); + 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()); + bank.setFloat("inlength",i, (float) (hitlist.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (hitlist.get(i).getPath_length())); + } + return bank; + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + } + +} From 83686184ddf7e9556b86cfac3a8c59833dd12a52 Mon Sep 17 00:00:00 2001 From: Churamani Paudel Date: Tue, 21 Jan 2025 15:25:41 -0500 Subject: [PATCH 19/82] viewed clustering logic --- .../main/java/org/jlab/rec/atof/Cluster/AtofCluster.java | 3 ++- .../java/org/jlab/rec/atof/Cluster/ClusterFinder.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 76e441c7ed..55b31eb9fb 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -1,5 +1,4 @@ package org.jlab.rec.atof.cluster; - import java.util.ArrayList; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; @@ -8,6 +7,8 @@ * * @author npilleux */ + + public class AtofCluster { ArrayList bar_hits; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index b6f50b496c..c0ed07c9c9 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -42,7 +42,14 @@ public void MakeClusters(HitFinder hitfinder) { double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future double sigma_Z = 6000;//to be read from DB in the future double sigma_T = 1000;//timing resolution to be read from DB in the future - int sigma_module = 1; //hits are always within +-1 phi module of the most energetic + + /* + double sigma_Phi = loadParameterFromDB("SIGMA_PHI"); + double sigma_Z = loadParameterFromDB("SIGMA_Z"); + double sigma_T = loadParameterFromDB("SIGMA_T"); + */ + + int sigma_module = 1; //hits are always within +-1 phi module of the most energetic int sigma_component = 1;//hits are always within +-1 z component of the most energetic //Looping through wedge hits first From a803cc3b953df1892cac34b4108c399ecaf6637d Mon Sep 17 00:00:00 2001 From: Churamani Paudel Date: Wed, 22 Jan 2025 12:02:03 -0500 Subject: [PATCH 20/82] will work on this branch --- .../org/jlab/rec/atof/Cluster/AtofCluster.java | 3 ++- .../org/jlab/rec/atof/Cluster/ClusterFinder.java | 11 +++-------- .../main/java/org/jlab/rec/atof/Hit/AtofHit.java | 4 +++- .../main/java/org/jlab/rec/atof/Hit/BarHit.java | 4 ++-- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 2 +- .../jlab/rec/atof/TrackMatch/TrackProjector.java | 15 ++++++++++----- .../org/jlab/rec/atof/banks/RecoBankWriter.java | 2 +- .../org/jlab/rec/atof/constants/Parameters.java | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 55b31eb9fb..87c8950823 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -5,7 +5,7 @@ /** * - * @author npilleux + * @authors npilleux, churaman */ @@ -82,6 +82,7 @@ public void setPath_length(double path_length) { //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later + public final void computeClusterProperties() { this.energy=0; double max_energy = -1; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index c0ed07c9c9..28e6af5cec 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -16,8 +16,9 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ + public class ClusterFinder { private ArrayList clusters; @@ -42,16 +43,10 @@ public void MakeClusters(HitFinder hitfinder) { double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future double sigma_Z = 6000;//to be read from DB in the future double sigma_T = 1000;//timing resolution to be read from DB in the future - - /* - double sigma_Phi = loadParameterFromDB("SIGMA_PHI"); - double sigma_Z = loadParameterFromDB("SIGMA_Z"); - double sigma_T = loadParameterFromDB("SIGMA_T"); - */ - int sigma_module = 1; //hits are always within +-1 phi module of the most energetic int sigma_component = 1;//hits are always within +-1 z component of the most energetic + //Looping through wedge hits first for (int i_wedge = 0; i_wedge < wedge_hits.size(); i_wedge++) { AtofHit this_wedge_hit = wedge_hits.get(i_wedge); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 77b23dad4d..88d0a4e164 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -19,7 +19,7 @@ * computed from atof detector object using the geometry service Stores whether * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. * - * @author npilleux + * @authors npilleux, churaman */ public class AtofHit { @@ -285,6 +285,7 @@ public final int slc_to_xyz(Detector atof) { * @param hit2match The AtofHit object to compare with the current instance. * @return {@code true} if the hits match; {@code false} otherwise. */ + public boolean matchBar(AtofHit hit2match) { if (this.getSector() != hit2match.getSector()) { return false; //System.out.print("Two hits in different sectors \n"); @@ -386,6 +387,7 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * TrackProjections. * */ + public final void matchTrack(TrackProjector track_projector) { double sigma_phi = 0; double sigma_z = 0; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index b71a03b86b..3edae6bd58 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,5 +1,4 @@ package org.jlab.rec.atof.hit; - import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -15,8 +14,9 @@ * by the two hits upstream and downstream composing a full bar hit. z position, * time and energy are defined from the up/down hits * - * @author npilleux + * @authors npilleux,churaman */ + public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index adece84948..8f33db7f6d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -19,7 +19,7 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ public class HitFinder { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index cca125510c..90d5936b89 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -180,10 +180,12 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd double pz = bank.getFloat("pz", i); //Put everything in MM + x = x*10; y = y*10; z = z*10; - Units units = Units.MM; + + Units units = Units.MM; int q = 1; //need the charge sign from tracking @@ -194,15 +196,18 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + + projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + + projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); + + projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); Projections.add(projection); fill_out_bank(outputBank, projection, i); @@ -261,4 +266,4 @@ public static void main(String arg[]) { System.out.print("Read " + event_number + " events"); } -} \ No newline at end of file +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 94479d9379..c87040d17e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -11,7 +11,7 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ public class RecoBankWriter { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java index 89c7cce60e..2c15a5200b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -2,7 +2,7 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ public class Parameters { From d80672f632101a3e231e2c76406672a4e3e37542 Mon Sep 17 00:00:00 2001 From: Churamani Paudel Date: Thu, 23 Jan 2025 12:25:04 -0500 Subject: [PATCH 21/82] proximity checks for ClusterFinder::improved logic --- .../jlab/rec/atof/Cluster/ClusterFinder.java | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 28e6af5cec..0b70675e50 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -229,3 +229,202 @@ public static void main(String[] args) { } } + + + + +/* +// Exhibits more modular approach, and parameters/thresholds for clustering +// +package org.jlab.rec.atof.cluster; + +import cnuphys.magfield.MagneticFields; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.hit.HitFinder; +import org.jlab.rec.atof.trackMatch.TrackProjector; +import org.jlab.utils.CLASResources; + + +// @authors npilleux, churaman + +public class ClusterFinder { + + private static final Logger logger = Logger.getLogger(ClusterFinder.class.getName()); + private List clusters; +//can be replaced with actual values + private final double sigmaPhi = 6.0; // Angle opening of a layer + private final double sigmaZ = 6000.0; // Z threshold in mm + private final double sigmaT = 1000.0; // Timing resolution in ns + private final int sigmaModule = 1; // Module proximity threshold + private final int sigmaComponent = 1; // Component proximity threshold + + public ClusterFinder() { + this.clusters = new ArrayList<>(); + } + + public List getClusters() { + return clusters; + } + + public void setClusters(List clusters) { + this.clusters = clusters; + } + + public void makeClusters(HitFinder hitFinder) { + clusters.clear(); + List wedgeHits = hitFinder.getWedgeHits(); + List barHits = hitFinder.getBarHits(); + + clusterWedgeHits(wedgeHits, barHits); + clusterRemainingBarHits(barHits); + + logger.info("Clustering completed: " + clusters.size() + " clusters formed."); + } + + private void clusterWedgeHits(List wedgeHits, List barHits) { + for (int i = 0; i < wedgeHits.size(); i++) { + AtofHit primaryHit = wedgeHits.get(i); + if (primaryHit.getIs_in_a_cluster()) continue; + + List clusterWedgeHits = new ArrayList<>(); + List clusterBarHits = new ArrayList<>(); + + primaryHit.setIs_in_a_cluster(true); + clusterWedgeHits.add(primaryHit); + + addNearbyWedgeHits(primaryHit, wedgeHits, clusterWedgeHits); + addNearbyBarHits(primaryHit, barHits, clusterBarHits); + + clusters.add(new AtofCluster(clusterBarHits, clusterWedgeHits)); + } + } + + private void addNearbyWedgeHits(AtofHit primaryHit, List wedgeHits, List clusterWedgeHits) { + for (AtofHit hit : wedgeHits) { + if (hit.getIs_in_a_cluster()) continue; + + if (isHitInProximity(primaryHit, hit)) { + hit.setIs_in_a_cluster(true); + clusterWedgeHits.add(hit); + } + } + } + + private void addNearbyBarHits(AtofHit primaryHit, List barHits, List clusterBarHits) { + for (BarHit hit : barHits) { + if (hit.getIs_in_a_cluster()) continue; + + if (isHitInProximity(primaryHit, hit)) { + hit.setIs_in_a_cluster(true); + clusterBarHits.add(hit); + } + } + } + + private void clusterRemainingBarHits(List barHits) { + for (int i = 0; i < barHits.size(); i++) { + BarHit primaryHit = barHits.get(i); + if (primaryHit.getIs_in_a_cluster()) continue; + + List clusterBarHits = new ArrayList<>(); + primaryHit.setIs_in_a_cluster(true); + clusterBarHits.add(primaryHit); + + for (int j = i + 1; j < barHits.size(); j++) { + BarHit secondaryHit = barHits.get(j); + if (secondaryHit.getIs_in_a_cluster()) continue; + + if (isHitInProximity(primaryHit, secondaryHit)) { + secondaryHit.setIs_in_a_cluster(true); + clusterBarHits.add(secondaryHit); + } + } + + clusters.add(new AtofCluster(clusterBarHits, new ArrayList<>())); + } + } + +private boolean isHitInProximity(AtofHit hit1, AtofHit hit2) { + // Check if both hits are wedge hits + if (!"wedge".equals(hit1.getType()) || !"wedge".equals(hit2.getType())) { + return false; // Return false if either hit is not a wedge + } + + int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); + deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; + + int deltaComponent = Math.abs(hit1.getComponent() - hit2.getComponent()); + double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); + + return deltaModule <= sigmaModule && deltaComponent <= sigmaComponent && deltaT < sigmaT; +} + +private boolean isHitInProximity(AtofHit hit1, BarHit hit2) { + // Ensures that the AtofHit is of type "wedge" + if (!"wedge".equals(hit1.getType())) { + return false; + } + + // Computes module difference with circular boundary handling + int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); + deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; + + // Computes spatial and temporal proximity + double deltaZ = Math.abs(hit1.getZ() - hit2.getZ()); + double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); + + // Returns true if all proximity conditions are satisfied + return deltaModule <= sigmaModule && deltaZ < sigmaZ && deltaT < sigmaT; +} + + + public static void main(String[] args) { + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields( + mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", + "Symm_solenoid_r601_phi1_z1201_13June2018.dat" + ); + } catch (Exception e) { + logger.severe("Error initializing magnetic fields: " + e.getMessage()); + } + + TrackProjector projector = new TrackProjector(); + projector.setB(new Swim().BfieldLab(0, 0, 0, new float[3])[2]); + + String inputFile = "/path/to/input.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(inputFile); + + HitFinder hitFinder = new HitFinder(); + + while (reader.hasEvent()) { + DataEvent event = reader.getNextEvent(); + projector.ProjectTracks(event); + hitFinder.FindHits(event, atof, projector); + + ClusterFinder clusterFinder = new ClusterFinder(); + clusterFinder.makeClusters(hitFinder); + + logger.info("Processed event with " + clusterFinder.getClusters().size() + " clusters."); + } + } +} +*/ + From 2f5b3987f8c23d1bd14e9cfee1f6be041336f6d5 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 23 Jan 2025 11:29:24 -0600 Subject: [PATCH 22/82] Fixing conversions tdc/tot to time/energy and cleanup --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 127 +++++++++--------- 1 file changed, 67 insertions(+), 60 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 88d0a4e164..02e32eec52 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -19,7 +19,7 @@ * computed from atof detector object using the geometry service Stores whether * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. * - * @authors npilleux, churaman + * @author npilleux */ public class AtofHit { @@ -156,6 +156,8 @@ public int computeModule_index() { } public final String makeType() { + //Type of hit can be wedge, bar up, bar down or bar. + //Avoids testing components and order every time. String itype = "undefined"; if (this.component == 10 && this.order == 0) { itype = "bar down"; @@ -168,42 +170,66 @@ public final String makeType() { return itype; } + /** + * Converts TDC to time (ns). Sets the hit time parameter to a raw time for + * up/down bar hits or to the time corrected for the propagation for wedge + * hits. + * + * @return 0 if the time was successfully set, or 1 if the hit type is + * unsupported. + */ public final int TDC_to_time() { - double tdc2time = 1; - double veff = 1; + 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 "wedge" -> { tdc2time = Parameters.TDC2TIME; veff = Parameters.VEFF; + //Wedge hits are placed at the center of wedges and sipm at their top + distance_to_sipm = Parameters.WEDGE_THICKNESS / 2.; } case "bar up" -> { tdc2time = Parameters.TDC2TIME; veff = Parameters.VEFF; + //The distance will be computed at barhit level when z 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 z information is available + distance_to_sipm = 0; } case "bar" -> { - tdc2time = Parameters.TDC2TIME; - veff = Parameters.VEFF; + 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; } } } - //Time at the inner surface - this.time = tdc2time * this.TDC - this.inpath_length / veff; + //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 or to the energy corrected for the + * attenuation for wedge hits. + * + * @return 0 if the energy was successfully set, or 1 if the hit type is + * unsupported. + */ public final int ToT_to_energy() { - double tot2energy = 1; + double tot2energy; if (null == this.type) { + System.out.print("Null hit type, cannot convert tot to energy."); return 1; } else { switch (this.type) { @@ -211,7 +237,7 @@ public final int ToT_to_energy() { tot2energy = Parameters.TOT2ENERGY_WEDGE; //For now hits are considered in the middle of the wedge //And the SiPM on top - double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS/2.; + double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS / 2.; this.energy = tot2energy * this.ToT * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); } case "bar up" -> { @@ -225,8 +251,13 @@ public final int ToT_to_energy() { //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; } } @@ -237,7 +268,7 @@ public final int ToT_to_energy() { /** * Calculates spatial coordinates for the hit based on associated detector * component. Retrieves the midpoint of the atof component to assign the - * corresponding x, y, z coordinates to the hit. + * corresponding x, y, z coordinates to the hit (mm). * * * @param atof The Detector object representing the atof. @@ -245,7 +276,7 @@ public final int ToT_to_energy() { * is undefined or unsupported. */ public final int slc_to_xyz(Detector atof) { - int sl = 999; + int sl; if (null == this.type) { return 1; } else { @@ -261,10 +292,11 @@ public final int slc_to_xyz(Detector atof) { } Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); - - //coordinates centered at the center of the atof in mm - this.x = midpoint.x() - Parameters.LENGTH_ATOF / 2.; - this.y = midpoint.y() - Parameters.LENGTH_ATOF / 2.; + //Midpoints defined in the system were z=0 is the upstream end of the atof + //Translation to the system were z=0 is the center of the atof + //Units are mm + this.x = midpoint.x(); + this.y = midpoint.y(); this.z = midpoint.z() - Parameters.LENGTH_ATOF / 2.; return 0; } @@ -277,7 +309,7 @@ public final int slc_to_xyz(Detector atof) { *
  • If either hit is not in the bar (component must be 10), the method * returns {@code false}.
  • *
  • If both hits are in the same SiPM (i.e., their order is the same), - * the method returns {@code false}.
  • + * 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. @@ -285,23 +317,27 @@ public final int slc_to_xyz(Detector atof) { * @param hit2match The AtofHit object to compare with the current instance. * @return {@code true} if the hits match; {@code false} otherwise. */ - public boolean matchBar(AtofHit hit2match) { if (this.getSector() != hit2match.getSector()) { - return false; //System.out.print("Two hits in different sectors \n"); + //Two hits in different sectors + return false; } else if (this.getLayer() != hit2match.getLayer()) { - return false; //System.out.print("Two hits in different layers \n"); + //Two hits in different layers + return false; } else if (this.getComponent() != 10 || hit2match.getComponent() != 10) { - return false; //System.out.print("At least one hit is not in the bar \n"); - } else if (this.getOrder() > 1 || hit2match.getComponent() > 1) { - return false; //System.out.print("At least one hit is not a downstram or upstream hit. It may be a full bar hit. \n"); + //At least one hit not in the bar + return false; + } else if (this.getOrder() > 1 || hit2match.getOrder() > 1) { + //At least one hit has incorrect order + return false; } else { - return this.getOrder() != hit2match.getOrder(); //System.out.print("Two hits in same SiPM \n"); + //Match if one is order 0 and the other is order 1 + return this.getOrder() != hit2match.getOrder(); } } /** - * Returns the azimuthal angle (phi) of the hit. + * Computes the azimuthal angle (phi) of the hit in rad. * * @return The azimuthal angle (phi) in radians, in the range [-π, π]. */ @@ -310,7 +346,7 @@ public double getPhi() { } /** - * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * Constructor for a hit in the atof. Initializes the hit's sector, layer, * component, order, TDC, ToT. Sets the hit's initial state regarding * clustering. Set up the hit's type, time, energy, and spatial coordinates. * @@ -343,7 +379,7 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot } /** - * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * Constructor for a hit in the atof. Initializes the hit's sector, layer, * component, order, TDC, ToT. Sets the hit's initial state regarding * clustering. Set up the hit's type, time, energy, and spatial coordinates. * @@ -387,7 +423,6 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * TrackProjections. * */ - public final void matchTrack(TrackProjector track_projector) { double sigma_phi = 0; double sigma_z = 0; @@ -446,7 +481,6 @@ public int matchTrack(DataEvent event) { for (int i = 0; i < nt; i++) { Float xt = null, yt = null, zt = null, path = null, inpath = null; - if (null == this.getType()) { System.out.print("Impossible to match track and hit; hit type is null \n"); } else { @@ -460,8 +494,7 @@ public int matchTrack(DataEvent event) { path = track_bank.getFloat("L_at_wedge", i); inpath = track_bank.getFloat("L_in_wedge", i); } - case "bar up", "bar down" -> { - System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + case "bar" -> { sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; xt = track_bank.getFloat("x_at_bar", i); @@ -470,6 +503,9 @@ public int matchTrack(DataEvent event) { path = track_bank.getFloat("L_at_bar", i); inpath = track_bank.getFloat("L_in_bar", i); } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + } default -> System.out.print("Impossible to match track and hit; hit type is undefined \n"); } @@ -477,7 +513,6 @@ public int matchTrack(DataEvent event) { Point3D projection_point = new Point3D(xt, yt, zt); if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - System.out.print("PASSED CUTS \n"); this.setPath_length(path); this.setInpath_length(inpath); } @@ -494,33 +529,5 @@ public AtofHit() { * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - DataBank bank = event.getBank("ATOF::tdc"); - int nt = bank.rows(); // number of tracks - - for (int i = 0; i < nt; i++) { - int sector = bank.getInt("sector", i); - int layer = bank.getInt("layer", i); - int component = bank.getInt("component", i); - int order = bank.getInt("order", i); - int tdc = bank.getInt("TDC", i); - int tot = bank.getInt("ToT", i); - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - System.out.print(hit.getX() + "\n"); - } - } } } From 13e72f990c499b7078f4635719677d2ae69371ed Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 23 Jan 2025 11:43:42 -0600 Subject: [PATCH 23/82] Fixing time/energy computation and some cleanup --- .../java/org/jlab/rec/atof/Hit/BarHit.java | 97 +++++++------------ 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 3edae6bd58..8b13a978ca 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,4 +1,5 @@ package org.jlab.rec.atof.hit; + import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -12,11 +13,10 @@ * * Represents a hit in the atof bar. Extends class AtofHit. Is further defined * by the two hits upstream and downstream composing a full bar hit. z position, - * time and energy are defined from the up/down hits + * time and energy are defined from the up/down hits. * - * @authors npilleux,churaman + * @author npilleux */ - public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits @@ -38,16 +38,40 @@ public void setHitDown(AtofHit hit_down) { this.hit_down = hit_down; } + /** + * Computes bar hit z coordinate from up/downstream hit times. + * + */ public final void computeZ() { - double some_calibration = 10; //Here read the calibration DB - this.setZ(some_calibration * (hit_up.getTime() - hit_down.getTime())); + this.setZ(Parameters.VEFF/2. * (hit_up.getTime() - hit_down.getTime())); } + /** + * Computes bar 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() { - double some_calibration = 10; //Here read the calibration DB - this.setTime(some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.)); + //We pick the most energetic signal as the timing signal + double time_at_sipm, distance_to_sipm; + if(this.hit_down.getEnergy() > this.hit_up.getEnergy()) { + time_at_sipm = this.hit_down.getTime(); + distance_to_sipm = Parameters.LENGTH_ATOF/2. - this.getZ(); + } + else { + time_at_sipm = this.hit_up.getTime(); + distance_to_sipm = Parameters.LENGTH_ATOF/2. + this.getZ(); + } + this.setTime(time_at_sipm - distance_to_sipm/Parameters.VEFF); } + /** + * Computes bar hit energy from up/downstream hits. + * The energy of the up/downstream hits is corrected for attenuation now that z is known. + * The energy of the bar hit is the sum of the energy of the up/downstream hits. + * + */ public final void computeEnergy() { this.computeZ(); double distance_hit_to_sipm_up = Parameters.LENGTH_ATOF / 2. + this.getZ(); @@ -68,6 +92,7 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { this.hit_down = hit_down; this.setLayer(hit_up.getLayer()); this.setSector(hit_up.getSector()); + this.setComponent(10); this.setX(hit_up.getX()); this.setY(hit_up.getY()); this.computeZ(); @@ -76,65 +101,15 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { } public BarHit() { + super(); // Call AtofHit constructor + //Sets some parameters to make a bar type hit + this.setType("bar"); + this.setOrder(2); } /** * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - DataBank bank = event.getBank("ATOF::tdc"); - int nt = bank.rows(); // number of tracks - ArrayList hit_up = new ArrayList<>(); - ArrayList hit_down = new ArrayList<>(); - ArrayList hit_wedge = new ArrayList<>(); - for (int i = 0; i < nt; i++) { - int sector = bank.getInt("sector", i); - int layer = bank.getInt("layer", i); - int component = bank.getInt("component", i); - int order = bank.getInt("order", i); - int tdc = bank.getInt("TDC", i); - int tot = bank.getInt("ToT", i); - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - 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); - case "wedge" -> - hit_wedge.add(hit); - default -> - System.out.print("Undefined hit type \n"); - } - } - } - ArrayList bar_hits = new ArrayList<>(); - for (int i_up = 0; i_up < hit_up.size(); i_up++) { - AtofHit this_hit_up = hit_up.get(i_up); - for (int i_down = 0; i_down < hit_down.size(); i_down++) { - AtofHit this_hit_down = hit_down.get(i_down); - if (this_hit_up.matchBar(this_hit_down)) { - BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - bar_hits.add(this_bar_hit); - } - } - } - } } } From 8343ce8e530c75a6f1f70602273812fd7d5844da Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 23 Jan 2025 11:46:14 -0600 Subject: [PATCH 24/82] Fixing energy sorting and some cleanup --- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 121 ++---------------- 1 file changed, 10 insertions(+), 111 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index 8f33db7f6d..c875f67635 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -19,7 +19,7 @@ /** * - * @authors npilleux,churaman + * @author npilleux */ public class HitFinder { @@ -71,9 +71,10 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec int tot = bank.getInt("ToT", i); //Building a Hit AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if (hit.getEnergy() < 0.1) { + if (hit.getEnergy() < 0.01) { continue; //energy threshold - } //Sorting the hits into wedge, upstream and downstream bar hits + } + //Sorting the hits into wedge, upstream and downstream bar hits //Lists are built for up/down bar to match them after //Wedge hits are mayched to ahdc tracks and listed if (null == hit.getType()) { @@ -110,8 +111,8 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } public void FindHits(DataEvent event, Detector atof) { @@ -136,7 +137,7 @@ public void FindHits(DataEvent event, Detector atof) { int tot = bank_atof_hits.getInt("ToT", i); //Building a Hit AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if (hit.getEnergy() < 0.1) { + if (hit.getEnergy() < 0.01) { continue; //energy threshold } //Sorting the hits into wedge, upstream and downstream bar hits //Lists are built for up/down bar to match them after @@ -175,9 +176,9 @@ public void FindHits(DataEvent event, Detector atof) { } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); - ArrayList allhits = new ArrayList<>();; + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + ArrayList allhits = new ArrayList<>(); allhits.addAll(this.wedge_hits); allhits.addAll(this.bar_hits); DataBank hitbank = fillAtofHitBank(event, allhits); @@ -188,107 +189,5 @@ public void FindHits(DataEvent event, Detector atof) { * @param args the command line arguments */ public static void main(String[] args) { - - //Building ALERT geometry - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //READING MAG FIELD MAP - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields(mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); - } catch (Exception e) { - e.printStackTrace(); - } - float[] b = new float[3]; - Swim swimmer = new Swim(); - swimmer.BfieldLab(0, 0, 0, b); - double B = Math.abs(b[2]); - - //Track Projector Initialisation with B field - TrackProjector projector = new TrackProjector(); - projector.setB(B); - - //Hit finder init - HitFinder hitfinder = new HitFinder(); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/updated_updated_rec_more_protons_50_to_650.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - H1F h_delta_energy = new H1F("Energy", "Energy", 100, -10, 10); - h_delta_energy.setTitleX("delta energy [GeV]"); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - projector.ProjectTracks(event); - hitfinder.FindHits(event, atof); - DataBank MC_True = event.getBank("MC::True"); - DataBank tdc = event.getBank("ATOF::tdc"); - DataBank hits = event.getBank("ATOF::hits"); - double totEdep = 0; - - for (int i = 0; i < MC_True.rows(); i++) { - - if (MC_True.getByte("detector", i) != 24) { - continue; - } - Float true_energy = MC_True.getFloat("avgT", i); - if (true_energy < 5) { - continue; - } - System.out.print(true_energy + " TRUE \n"); - double min_diff = 9999.; - double energy_at_min = 9999.; - - for (int j = 0; j < hits.rows(); j++) { - Float hit_energy = hits.getFloat("time", j); - Float diff = true_energy - hit_energy; - if (diff < min_diff) { - min_diff = diff; - energy_at_min = true_energy; - } - } - System.out.print("ICI " + energy_at_min + " " + true_energy + " \n"); - h_delta_energy.fill(min_diff / energy_at_min); - } - System.out.print("------------------- \n"); - } - - System.out.print ( - - "Read " + event_number + " events"); - JFrame frame = new JFrame("Raster"); - - frame.setSize ( - - 2500,800); - EmbeddedCanvas canvas = new EmbeddedCanvas(); - - canvas.divide ( - - - 3,2); - canvas.cd ( - - - 3); canvas.draw (h_delta_energy); - - frame.add (canvas); - - frame.setLocationRelativeTo ( - - - null); - frame.setVisible ( - - -true); } } From 16fb0791c6372deee728aed2b412b3f76d2c8547 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:37:28 -0600 Subject: [PATCH 25/82] handling clustering parameters --- .../jlab/rec/atof/Cluster/ClusterFinder.java | 297 ++---------------- .../jlab/rec/atof/constants/Parameters.java | 17 +- 2 files changed, 38 insertions(+), 276 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 0b70675e50..fba46b565c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -2,12 +2,19 @@ import cnuphys.magfield.MagneticFields; import java.util.ArrayList; +import javax.swing.JFrame; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.groot.data.H1F; +import org.jlab.groot.data.H2F; +import org.jlab.groot.graphics.EmbeddedCanvas; +import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofClusterBank; +import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; @@ -16,22 +23,21 @@ /** * - * @authors npilleux,churaman + * @author npilleux */ - public class ClusterFinder { private ArrayList clusters; - + public void setClusters(ArrayList clusters) { this.clusters = clusters; } - + public ArrayList getClusters() { return clusters; } - public void MakeClusters(HitFinder hitfinder) { + public void makeClusters(DataEvent event, HitFinder hitfinder) { //A list of clusters is built for each event clusters.clear(); @@ -40,13 +46,6 @@ public void MakeClusters(HitFinder hitfinder) { ArrayList wedge_hits = hitfinder.getWedgeHits(); ArrayList bar_hits = hitfinder.getBarHits(); - double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future - double sigma_Z = 6000;//to be read from DB in the future - double sigma_T = 1000;//timing resolution to be read from DB in the future - int sigma_module = 1; //hits are always within +-1 phi module of the most energetic - int sigma_component = 1;//hits are always within +-1 z component of the most energetic - - //Looping through wedge hits first for (int i_wedge = 0; i_wedge < wedge_hits.size(); i_wedge++) { AtofHit this_wedge_hit = wedge_hits.get(i_wedge); @@ -54,6 +53,7 @@ public void MakeClusters(HitFinder hitfinder) { if (this_wedge_hit.getIs_in_a_cluster()) { continue; } + //Holding onto the hits composing the cluster ArrayList this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); @@ -84,11 +84,10 @@ public void MakeClusters(HitFinder hitfinder) { //Time matching double delta_T = Math.abs(this_wedge_hit.getTime() - other_wedge_hit.getTime()); - if (delta_module <= sigma_module)//delta_Phi <= sigma_Phi) - { - if (delta_component <= sigma_component)//delta_Z <= sigma_Z) + if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { + if (delta_component <= Parameters.SIGMA_COMPONENT_CLUSTERING)//delta_Z <= sigma_Z) { - if (delta_T < sigma_T) { + if (delta_T < Parameters.SIGMA_T_CLUSTERING) { other_wedge_hit.setIs_in_a_cluster(true); this_cluster_wedge_hits.add(other_wedge_hit); } @@ -114,22 +113,21 @@ public void MakeClusters(HitFinder hitfinder) { double delta_Z = Math.abs(this_wedge_hit.getZ() - other_bar_hit.getZ()); //Time matching double delta_T = Math.abs(this_wedge_hit.getTime() - other_bar_hit.getTime()); - if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) - { - if (delta_Z < sigma_Z) { - if (delta_T < sigma_T) { + if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { + if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { + if (delta_T < Parameters.SIGMA_T_CLUSTERING) { other_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(other_bar_hit); } } } }//End loop bar hits + //After all wedge and bar hits have been grouped, build the cluster AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); //And add it to the list of clusters clusters.add(cluster); }//End loop on all wedge hits - //Now make clusters from bar hits that are not associated with wedge hits //Loop through all bar hits for (int i_bar = 0; i_bar < bar_hits.size(); i_bar++) { @@ -139,11 +137,11 @@ public void MakeClusters(HitFinder hitfinder) { continue; } - ArrayList this_cluster_wedge_hits = new ArrayList(); - ArrayList this_cluster_bar_hits = new ArrayList(); + ArrayList this_cluster_wedge_hits = new ArrayList<>(); + ArrayList this_cluster_bar_hits = new ArrayList<>(); this_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(this_bar_hit); - + //Loop through less energetic clusters for (int j_bar = i_bar + 1; j_bar < bar_hits.size(); j_bar++) { BarHit other_bar_hit = bar_hits.get(j_bar); @@ -151,7 +149,7 @@ public void MakeClusters(HitFinder hitfinder) { if (other_bar_hit.getIs_in_a_cluster()) { continue; } - + //Check the distance between the hits //For now we use phi module difference from what is observed in simu int delta_module = Math.abs(this_bar_hit.computeModule_index() - other_bar_hit.computeModule_index()); @@ -164,10 +162,9 @@ public void MakeClusters(HitFinder hitfinder) { //Time matching double delta_T = Math.abs(this_bar_hit.getTime() - other_bar_hit.getTime()); - if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) - { - if (delta_Z < sigma_Z) { - if (delta_T < sigma_T) { + if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { + if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { + if (delta_T < Parameters.SIGMA_T_CLUSTERING) { other_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(other_bar_hit); } @@ -177,254 +174,18 @@ public void MakeClusters(HitFinder hitfinder) { AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } + DataBank clusterbank = fillAtofClusterBank(event, clusters); + event.appendBank(clusterbank); } public ClusterFinder() { - clusters = new ArrayList(); + clusters = new ArrayList<>(); } /** * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //READING MAG FIELD MAP - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields(mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); - } catch (Exception e) { - e.printStackTrace(); - } - float[] b = new float[3]; - Swim swimmer = new Swim(); - swimmer.BfieldLab(0, 0, 0, b); - double B = Math.abs(b[2]); - - //Track Projector Initialisation with B field - TrackProjector projector = new TrackProjector(); - projector.setB(B); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - HitFinder hitfinder = new HitFinder(); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - projector.ProjectTracks(event); - hitfinder.FindHits(event, atof, projector); - ClusterFinder clusterfinder = new ClusterFinder(); - clusterfinder.MakeClusters(hitfinder); - } - } - -} - - - - -/* -// Exhibits more modular approach, and parameters/thresholds for clustering -// -package org.jlab.rec.atof.cluster; - -import cnuphys.magfield.MagneticFields; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; -import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; -import org.jlab.rec.atof.hit.AtofHit; -import org.jlab.rec.atof.hit.BarHit; -import org.jlab.rec.atof.hit.HitFinder; -import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; - - -// @authors npilleux, churaman - -public class ClusterFinder { - - private static final Logger logger = Logger.getLogger(ClusterFinder.class.getName()); - private List clusters; -//can be replaced with actual values - private final double sigmaPhi = 6.0; // Angle opening of a layer - private final double sigmaZ = 6000.0; // Z threshold in mm - private final double sigmaT = 1000.0; // Timing resolution in ns - private final int sigmaModule = 1; // Module proximity threshold - private final int sigmaComponent = 1; // Component proximity threshold - - public ClusterFinder() { - this.clusters = new ArrayList<>(); } - public List getClusters() { - return clusters; - } - - public void setClusters(List clusters) { - this.clusters = clusters; - } - - public void makeClusters(HitFinder hitFinder) { - clusters.clear(); - List wedgeHits = hitFinder.getWedgeHits(); - List barHits = hitFinder.getBarHits(); - - clusterWedgeHits(wedgeHits, barHits); - clusterRemainingBarHits(barHits); - - logger.info("Clustering completed: " + clusters.size() + " clusters formed."); - } - - private void clusterWedgeHits(List wedgeHits, List barHits) { - for (int i = 0; i < wedgeHits.size(); i++) { - AtofHit primaryHit = wedgeHits.get(i); - if (primaryHit.getIs_in_a_cluster()) continue; - - List clusterWedgeHits = new ArrayList<>(); - List clusterBarHits = new ArrayList<>(); - - primaryHit.setIs_in_a_cluster(true); - clusterWedgeHits.add(primaryHit); - - addNearbyWedgeHits(primaryHit, wedgeHits, clusterWedgeHits); - addNearbyBarHits(primaryHit, barHits, clusterBarHits); - - clusters.add(new AtofCluster(clusterBarHits, clusterWedgeHits)); - } - } - - private void addNearbyWedgeHits(AtofHit primaryHit, List wedgeHits, List clusterWedgeHits) { - for (AtofHit hit : wedgeHits) { - if (hit.getIs_in_a_cluster()) continue; - - if (isHitInProximity(primaryHit, hit)) { - hit.setIs_in_a_cluster(true); - clusterWedgeHits.add(hit); - } - } - } - - private void addNearbyBarHits(AtofHit primaryHit, List barHits, List clusterBarHits) { - for (BarHit hit : barHits) { - if (hit.getIs_in_a_cluster()) continue; - - if (isHitInProximity(primaryHit, hit)) { - hit.setIs_in_a_cluster(true); - clusterBarHits.add(hit); - } - } - } - - private void clusterRemainingBarHits(List barHits) { - for (int i = 0; i < barHits.size(); i++) { - BarHit primaryHit = barHits.get(i); - if (primaryHit.getIs_in_a_cluster()) continue; - - List clusterBarHits = new ArrayList<>(); - primaryHit.setIs_in_a_cluster(true); - clusterBarHits.add(primaryHit); - - for (int j = i + 1; j < barHits.size(); j++) { - BarHit secondaryHit = barHits.get(j); - if (secondaryHit.getIs_in_a_cluster()) continue; - - if (isHitInProximity(primaryHit, secondaryHit)) { - secondaryHit.setIs_in_a_cluster(true); - clusterBarHits.add(secondaryHit); - } - } - - clusters.add(new AtofCluster(clusterBarHits, new ArrayList<>())); - } - } - -private boolean isHitInProximity(AtofHit hit1, AtofHit hit2) { - // Check if both hits are wedge hits - if (!"wedge".equals(hit1.getType()) || !"wedge".equals(hit2.getType())) { - return false; // Return false if either hit is not a wedge - } - - int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); - deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; - - int deltaComponent = Math.abs(hit1.getComponent() - hit2.getComponent()); - double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); - - return deltaModule <= sigmaModule && deltaComponent <= sigmaComponent && deltaT < sigmaT; -} - -private boolean isHitInProximity(AtofHit hit1, BarHit hit2) { - // Ensures that the AtofHit is of type "wedge" - if (!"wedge".equals(hit1.getType())) { - return false; - } - - // Computes module difference with circular boundary handling - int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); - deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; - - // Computes spatial and temporal proximity - double deltaZ = Math.abs(hit1.getZ() - hit2.getZ()); - double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); - - // Returns true if all proximity conditions are satisfied - return deltaModule <= sigmaModule && deltaZ < sigmaZ && deltaT < sigmaT; -} - - - public static void main(String[] args) { - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields( - mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", - "Symm_solenoid_r601_phi1_z1201_13June2018.dat" - ); - } catch (Exception e) { - logger.severe("Error initializing magnetic fields: " + e.getMessage()); - } - - TrackProjector projector = new TrackProjector(); - projector.setB(new Swim().BfieldLab(0, 0, 0, new float[3])[2]); - - String inputFile = "/path/to/input.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(inputFile); - - HitFinder hitFinder = new HitFinder(); - - while (reader.hasEvent()) { - DataEvent event = reader.getNextEvent(); - projector.ProjectTracks(event); - hitFinder.FindHits(event, atof, projector); - - ClusterFinder clusterFinder = new ClusterFinder(); - clusterFinder.makeClusters(hitFinder); - - logger.info("Processed event with " + clusterFinder.getClusters().size() + " clusters."); - } - } } -*/ - diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java index 2c15a5200b..9a5868f82a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -2,18 +2,15 @@ /** * - * @authors npilleux,churaman + * @author npilleux */ public class Parameters { - Parameters() { - } - //In millimiters - public static final double BAR_INNER_RADIUS = 77; - public static final double WEDGE_INNER_RADIUS = 80; - public static final double BAR_THICKNESS = 3; - public static final double WEDGE_THICKNESS = 20; + public static final double BAR_INNER_RADIUS = 77;//mm + public static final double WEDGE_INNER_RADIUS = 80;//mm + public static final double BAR_THICKNESS = 3;//mm + public static final double WEDGE_THICKNESS = 20;//mm public static final double BAR_MIDDLE_RADIUS = BAR_INNER_RADIUS + BAR_THICKNESS / 2; public static final double WEDGE_MIDDLE_RADIUS = WEDGE_INNER_RADIUS + WEDGE_THICKNESS / 2; @@ -33,6 +30,10 @@ public class Parameters { public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 200;//in mm public static double SIGMA_PHI_CLUSTERING = 6;//in deg + public static double SIGMA_Z_CLUSTERING = 200;//in mm + public static double SIGMA_MODULE_CLUSTERING = 1; + public static double SIGMA_COMPONENT_CLUSTERING = 1; + public static double SIGMA_T_CLUSTERING = 100;// in ns /** * @param args the command line arguments From 91d9b111bb969740142b860fb4920f8ac98aec0a Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:38:12 -0600 Subject: [PATCH 26/82] cluster parameters definition --- .../jlab/rec/atof/Cluster/AtofCluster.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 87c8950823..b610e740ae 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -1,20 +1,19 @@ package org.jlab.rec.atof.cluster; + import java.util.ArrayList; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; /** * - * @authors npilleux, churaman + * @author npilleux */ - - public class AtofCluster { ArrayList bar_hits; ArrayList wedge_hits; double x,y,z,time,energy; - double path_length; + double path_length, inpath_length; public ArrayList getBarHits() { return bar_hits; @@ -80,9 +79,16 @@ public void setPath_length(double path_length) { this.path_length = path_length; } + public double getInpath_length() { + return inpath_length; + } + + public void setInpath_length(double inpath_length) { + this.inpath_length = inpath_length; + } + //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later - public final void computeClusterProperties() { this.energy=0; double max_energy = -1; @@ -112,6 +118,7 @@ public final void computeClusterProperties() { this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); this.path_length = max_energy_hit.getPath_length(); + this.inpath_length = max_energy_hit.getInpath_length(); } else { @@ -120,8 +127,8 @@ public final void computeClusterProperties() { this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); this.path_length = max_energy_barhit.getPath_length(); + this.inpath_length = max_energy_barhit.getInpath_length(); } - } public double getPhi() @@ -129,6 +136,11 @@ public double getPhi() return Math.atan2(this.y, this.x); } + public double getBeta() + { + return (this.path_length / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c + } + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { this.bar_hits = bar_hits; From 14a7cc6c9e00ab905a8eed3b52765bf2a1dee0fe Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:39:53 -0600 Subject: [PATCH 27/82] fix hit order --- .../alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 02e32eec52..597b082afe 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -159,9 +159,9 @@ public final String makeType() { //Type of hit can be wedge, bar up, bar down or bar. //Avoids testing components and order every time. String itype = "undefined"; - if (this.component == 10 && this.order == 0) { + if (this.component == 10 && this.order == 1) { itype = "bar down"; - } else if (this.component == 10 && this.order == 1) { + } else if (this.component == 10 && this.order == 0) { itype = "bar up"; } else if (this.component < 10) { itype = "wedge"; @@ -492,7 +492,8 @@ public int matchTrack(DataEvent event) { yt = track_bank.getFloat("y_at_wedge", i); zt = track_bank.getFloat("z_at_wedge", i); path = track_bank.getFloat("L_at_wedge", i); - inpath = track_bank.getFloat("L_in_wedge", i); + //A wedge hit traveled through the whole bar and then through a portion of the wedge + inpath = track_bank.getFloat("L_in_wedge", i) + track_bank.getFloat("L_at_wedge", i) - track_bank.getFloat("L_at_bar", i); } case "bar" -> { sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; From 9764d60bc49ccca135104a0639db0dae7bd628cb Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:41:35 -0600 Subject: [PATCH 28/82] cluster bank definition --- etc/bankdefs/hipo4/alert.json | 48 +++++++++++++++++++ .../jlab/rec/atof/banks/RecoBankWriter.java | 32 ++++++++++--- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index ea6f4e251b..775cfba259 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -99,6 +99,54 @@ "info": "path length to the hit in mm" } ] + },{ + "name": "ATOF::clusters", + "group": 22500, + "item": 22, + "info": "Clusters in ATOF", + "entries": [ + { + "name": "id", + "type": "S", + "info": "hit id" + }, { + "name": "barsize", + "type": "I", + "info": "number of hits from the bars" + }, { + "name": "wedgesize", + "type": "I", + "info": "number of hits from the wedges" + },{ + "name": "time", + "type": "F", + "info": "time in ns" + },{ + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + },{ + "name": "energy", + "type": "F", + "info": "energy in MeV" + },{ + "name": "pathlength", + "type": "F", + "info": "path length to the cluster in mm" + },{ + "name": "inpathlength", + "type": "F", + "info": "path length inside the detector in mm" + } + ] },{ "name": "AHDC::Hits", "group": 23000, diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index c87040d17e..299a50bf1f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -1,21 +1,17 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template - */ package org.jlab.rec.atof.banks; import java.util.ArrayList; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; +import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.hit.AtofHit; /** * - * @authors npilleux,churaman + * @author npilleux */ public class RecoBankWriter { - // write useful information in the bank public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitlist) { DataBank bank = event.createBank("ATOF::hits", hitlist.size()); @@ -42,6 +38,30 @@ public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitli } return bank; } + + public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterlist) { + + DataBank bank = event.createBank("ATOF::clusters", clusterlist.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + return null; + } + + for(int i =0; i< clusterlist.size(); i++) { + bank.setShort("id",i, (short)(i+1)); + bank.setInt("barsize",i, (int) clusterlist.get(i).getBarHits().size()); + bank.setInt("wedgesize",i, (int) clusterlist.get(i).getWedgeHits().size()); + 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()); + bank.setFloat("inpathlength",i, (float) (clusterlist.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (clusterlist.get(i).getPath_length())); + } + return bank; + } /** * @param args the command line arguments From 33cbb4ffaffb71b2cb9f50a0599c2be3e636d37e Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:42:19 -0600 Subject: [PATCH 29/82] charge sign fix and projection from MC Particle info --- .../rec/atof/TrackMatch/TrackProjector.java | 63 ++++++++++++++++--- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index 90d5936b89..225ebf4842 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -11,6 +11,9 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.utils.CLASResources; import cnuphys.magfield.MagneticFields; +import java.io.BufferedWriter; +import java.io.IOException; +import org.jlab.geom.prim.Point3D; import org.jlab.rec.atof.constants.Parameters; /** @@ -109,7 +112,6 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) int nt = bank.rows(); // number of tracks TrackProjection projection = new TrackProjection(); DataBank outputBank = event.createBank("AHDC::Projections", nt); - for (int i = 0; i < nt; i++) { double x = bank.getFloat("x", i); @@ -119,7 +121,7 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) double py = bank.getFloat("py", i); double pz = bank.getFloat("pz", i); - int q = 1; //need the charge sign from tracking + int q = -1; //need the charge sign from tracking Units units = Units.MM; //can be MM or CM. @@ -158,7 +160,6 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Projections.clear(); String track_bank_name = "MC::Particle"; - if (event == null) { // check if there is an event //System.out.print(" no event \n"); } else if (event.hasBank(track_bank_name) == false) { @@ -187,7 +188,7 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Units units = Units.MM; - int q = 1; //need the charge sign from tracking + int q = -1; //need the charge sign from tracking double xb = 0; double yb = 0; @@ -196,7 +197,6 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); @@ -215,6 +215,55 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd event.appendBank(outputBank); } } + + public void projectMCTracks_full_path(DataEvent event, int num_event, BufferedWriter writer) throws IOException { + + String track_bank_name = "MC::Particle"; + if (event == null) { // check if there is an event + //System.out.print(" no event \n"); + } else if (event.hasBank(track_bank_name) == false) { + // check if there are ahdc tracks in the event + //System.out.print("no tracks \n"); + } else { + DataBank bank = event.getBank(track_bank_name); + int nt = bank.rows(); // number of tracks + + for (int i = 0; i < nt; i++) { + + double x = bank.getFloat("vx", i); + double y = bank.getFloat("vy", i); + double z = bank.getFloat("vz", i); + double px = bank.getFloat("px", i); + double py = bank.getFloat("py", i); + double pz = bank.getFloat("pz", i); + + //Put everything in MM + + x = x*10; + y = y*10; + z = z*10; + + Units units = Units.MM; + + int q = -1; //need the charge sign from tracking + + double xb = 0; + double yb = 0; + + //momenta must be in GeV for the helix class + Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + + double min = 0.1; + double max = Parameters.WEDGE_INNER_RADIUS+Parameters.WEDGE_THICKNESS; + int nsteps = 20; + double step = (max-min)/nsteps; + for(double i_radius = min; i_radius Date: Mon, 3 Feb 2025 09:47:36 -0600 Subject: [PATCH 30/82] draft atof engine to be completed --- .../java/org/jlab/rec/service/ATOFEngine.java | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java new file mode 100644 index 0000000000..4f9473c830 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -0,0 +1,157 @@ +package org.jlab.rec.service; + +import cnuphys.magfield.MagneticFields; +import java.util.ArrayList; + +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.io.hipo.HipoDataSync; + +import java.util.concurrent.atomic.AtomicInteger; +import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.rec.atof.banks.RecoBankWriter; +import org.jlab.rec.atof.cluster.AtofCluster; +import org.jlab.rec.atof.cluster.ClusterFinder; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.hit.HitFinder; +import org.jlab.rec.atof.trackMatch.TrackProjector; +import org.jlab.utils.CLASResources; + +/** + * Service to return reconstructed ATOF hits and clusters + * + * @author npilleux + * + */ +public class ATOFEngine extends ReconstructionEngine { + + public ATOFEngine() { + super("ATOF", "pilleux", "1.0"); + } + + //int Run = -1; + RecoBankWriter rbc; + + private final AtomicInteger Run = new AtomicInteger(0); + private Detector ATOF; + private double B; //Magnetic field + + @Override + public boolean processDataEvent(DataEvent event) { + + if (!event.hasBank("RUN::config")) { + return true; + } + + DataBank bank = event.getBank("RUN::config"); + + // Load the constants + //------------------- + int newRun = bank.getInt("run", 0); + if (newRun == 0) { + return true; + } + + if (Run.get() == 0 || (Run.get() != 0 && Run.get() != newRun)) { + Run.set(newRun); + } + + //CalibrationConstantsLoader constantsLoader = new CalibrationConstantsLoader(newRun, this.getConstantsManager()); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(this.B); + projector.ProjectTracks(event); + + //Hit finder init + HitFinder hitfinder = new HitFinder(); + hitfinder.FindHits(event, ATOF); + + ArrayList WedgeHits = hitfinder.getWedgeHits(); + ArrayList BarHits = hitfinder.getBarHits(); + + //1) exit if halfhit list is empty + if (WedgeHits.isEmpty() && BarHits.isEmpty()) { + // System.out.println("No hits : "); + // event.show(); + return true; + } + + + ClusterFinder clusterFinder = new ClusterFinder(); + clusterFinder.makeClusters(event,hitfinder); + ArrayList clusters = clusterFinder.getClusters(); + + if (WedgeHits.size() != 0 || BarHits.size() != 0) { + //rbc.appendBanks(event, hits, cndclusters); + } + return true; + } + + @Override + public boolean init() { + rbc = new RecoBankWriter(); + + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + this.ATOF = factory.createDetectorCLAS(cp); + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + this.B = Math.abs(b[2]); + + //requireConstants(Arrays.asList(CalibrationConstantsLoader.getCndTables())); + //this.getConstantsManager().setVariation("default"); + + this.registerOutputBank("CND::hits", "CND::clusters"); + + return true; + } + + public static void main(String arg[]) { + ATOFEngine en = new ATOFEngine(); + + en.init(); + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/mixed_ions.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + //String outputFile = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/tester.hipo"; + //HipoDataSync writer = new HipoDataSync(); + //writer.open(outputFile); + + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + en.processDataEvent(event); + //writer.writeEvent(event); + } + + //writer.close(); + + //HipoDataSource sortie = new HipoDataSource(); + //sortie.open(outputFile); + + //System.out.println("Fichier de sortie : "); + //while (sortie.hasEvent()) { + + // DataEvent event = (DataEvent) sortie.getNextEvent(); + //event.show(); + //} + } + +} From 436e21c6f4a21b5867eb0529a7aec0d36698b5d1 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 6 Feb 2025 15:24:54 -0600 Subject: [PATCH 31/82] appending output banks --- .../jlab/rec/atof/banks/RecoBankWriter.java | 25 ++++++- .../java/org/jlab/rec/service/ATOFEngine.java | 71 +++++++++---------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 299a50bf1f..066a3ceea3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -5,6 +5,7 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; /** * @@ -12,7 +13,11 @@ */ public class RecoBankWriter { - public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitlist) { + public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits) { + + ArrayList hitlist = new ArrayList<>(); + hitlist.addAll(wedge_hits); + hitlist.addAll(bar_hits); DataBank bank = event.createBank("ATOF::hits", hitlist.size()); @@ -62,12 +67,28 @@ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits, ArrayList clusterlist) { + + DataBank hitbank = this.fillAtofHitBank(event, wedge_hits, bar_hits); + if (hitbank != null) { + event.appendBank(hitbank); + } + else return 1; + + DataBank clusterbank = fillAtofClusterBank(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) { - // TODO code application logic here } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java index 4f9473c830..58f40ad415 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -7,7 +7,6 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import org.jlab.io.hipo.HipoDataSync; import java.util.concurrent.atomic.AtomicInteger; import org.jlab.clas.swimtools.Swim; @@ -35,12 +34,25 @@ public ATOFEngine() { super("ATOF", "pilleux", "1.0"); } - //int Run = -1; RecoBankWriter rbc; private final AtomicInteger Run = new AtomicInteger(0); private Detector ATOF; private double B; //Magnetic field + + //Setters and getters + public void setB(double B) { + this.B = B; + } + public double getB() { + return B; + } + public void setATOF(Detector ATOF) { + this.ATOF = ATOF; + } + public Detector getATOF() { + return ATOF; + } @Override public boolean processDataEvent(DataEvent event) { @@ -76,20 +88,19 @@ public boolean processDataEvent(DataEvent event) { ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); - //1) exit if halfhit list is empty + //Exit if hit lists are empty if (WedgeHits.isEmpty() && BarHits.isEmpty()) { // System.out.println("No hits : "); // event.show(); return true; } - - + ClusterFinder clusterFinder = new ClusterFinder(); clusterFinder.makeClusters(event,hitfinder); - ArrayList clusters = clusterFinder.getClusters(); + ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - //rbc.appendBanks(event, hits, cndclusters); + rbc.appendATOFBanks(event, WedgeHits, BarHits, Clusters); } return true; } @@ -102,7 +113,18 @@ public boolean init() { DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); this.ATOF = factory.createDetectorCLAS(cp); - //READING MAG FIELD MAP + //requireConstants(Arrays.asList(CalibrationConstantsLoader.getAtofTables())); + //this.getConstantsManager().setVariation("default"); + + this.registerOutputBank("ATOF::hits", "ATOF::clusters"); + + return true; + } + + public static void main(String arg[]) { + ATOFEngine en = new ATOFEngine(); + + //READING MAG FIELD MAP System.setProperty("CLAS12DIR", "../../"); String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; try { @@ -114,44 +136,17 @@ public boolean init() { float[] b = new float[3]; Swim swimmer = new Swim(); swimmer.BfieldLab(0, 0, 0, b); - this.B = Math.abs(b[2]); - - //requireConstants(Arrays.asList(CalibrationConstantsLoader.getCndTables())); - //this.getConstantsManager().setVariation("default"); - - this.registerOutputBank("CND::hits", "CND::clusters"); - - return true; - } - - public static void main(String arg[]) { - ATOFEngine en = new ATOFEngine(); + en.setB(Math.abs(b[2])); en.init(); String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/mixed_ions.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - //String outputFile = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/tester.hipo"; - //HipoDataSync writer = new HipoDataSync(); - //writer.open(outputFile); - + while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); en.processDataEvent(event); - //writer.writeEvent(event); + event.getBank("ATOF::clusters").show(); } - - //writer.close(); - - //HipoDataSource sortie = new HipoDataSource(); - //sortie.open(outputFile); - - //System.out.println("Fichier de sortie : "); - //while (sortie.hasEvent()) { - - // DataEvent event = (DataEvent) sortie.getNextEvent(); - //event.show(); - //} } - } From 08fe9f4dfbd7d3c1cf9badc0e9470b0aacb8a0c6 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 6 Feb 2025 15:53:40 -0600 Subject: [PATCH 32/82] fix:but writing output banks --- .../main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java | 6 ++---- .../src/main/java/org/jlab/rec/atof/Hit/HitFinder.java | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index fba46b565c..d13e96b958 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -13,7 +13,6 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofClusterBank; import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; @@ -174,8 +173,8 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } - DataBank clusterbank = fillAtofClusterBank(event, clusters); - event.appendBank(clusterbank); + //DataBank clusterbank = fillAtofClusterBank(event, clusters); + //event.appendBank(clusterbank); } public ClusterFinder() { @@ -187,5 +186,4 @@ public ClusterFinder() { */ public static void main(String[] args) { } - } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index c875f67635..748ff8dfef 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -13,7 +13,6 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofHitBank; import org.jlab.rec.atof.trackMatch.TrackProjector; import org.jlab.utils.CLASResources; @@ -178,16 +177,12 @@ public void FindHits(DataEvent event, Detector atof) { //Once all has been listed, hits are sorted by energy Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - ArrayList allhits = new ArrayList<>(); - allhits.addAll(this.wedge_hits); - allhits.addAll(this.bar_hits); - DataBank hitbank = fillAtofHitBank(event, allhits); - event.appendBank(hitbank); } /** * @param args the command line arguments */ public static void main(String[] args) { + } } From 6099557a5b645fabbdaff5a540c5dfa8394488c8 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Tue, 11 Feb 2025 16:08:11 -0600 Subject: [PATCH 33/82] style: naming conventions and some cleaning --- .../jlab/rec/atof/Cluster/AtofCluster.java | 54 +++++------ .../jlab/rec/atof/Cluster/ClusterFinder.java | 15 --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 97 +++++++++---------- .../java/org/jlab/rec/atof/Hit/BarHit.java | 38 +++----- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 60 +++++------- .../jlab/rec/atof/banks/RecoBankWriter.java | 68 +++++++------ .../java/org/jlab/rec/service/ATOFEngine.java | 79 ++++----------- 7 files changed, 166 insertions(+), 245 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index b610e740ae..fd1ef4a519 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -10,25 +10,25 @@ */ public class AtofCluster { - ArrayList bar_hits; - ArrayList wedge_hits; + ArrayList barHits; + ArrayList wedgeHits; double x,y,z,time,energy; - double path_length, inpath_length; + double pathLength, inPathLength; public ArrayList getBarHits() { - return bar_hits; + return barHits; } public void setBarHits(ArrayList bar_hits) { - this.bar_hits = bar_hits; + this.barHits = bar_hits; } public ArrayList getWedgeHits() { - return wedge_hits; + return wedgeHits; } public void setWedgeHits(ArrayList wedge_hits) { - this.wedge_hits = wedge_hits; + this.wedgeHits = wedge_hits; } public double getX() { @@ -71,20 +71,20 @@ public void setEnergy(double energy) { this.energy = energy; } - public double getPath_length() { - return path_length; + public double getPathLength() { + return pathLength; } - public void setPath_length(double path_length) { - this.path_length = path_length; + public void setPathLength(double pathLength) { + this.pathLength = pathLength; } - public double getInpath_length() { - return inpath_length; + public double getInPathLength() { + return inPathLength; } - public void setInpath_length(double inpath_length) { - this.inpath_length = inpath_length; + public void setInPathLength(double inPathLength) { + this.inPathLength = inPathLength; } //Cluster coordinates and time are defined as the coordinates and time of the max energy hit @@ -95,17 +95,17 @@ public final void computeClusterProperties() { AtofHit max_energy_hit = new AtofHit(); BarHit max_energy_barhit = new BarHit(); - for(int i_wedge = 0; i_wedgemax_energy){max_energy_hit = this_wedge_hit; max_energy = this_energy;} } - for(int i_bar = 0; i_barmax_energy){max_energy_barhit = this_bar_hit; max_energy = this_energy;} @@ -117,8 +117,8 @@ public final void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); - this.path_length = max_energy_hit.getPath_length(); - this.inpath_length = max_energy_hit.getInpath_length(); + this.pathLength = max_energy_hit.getPath_length(); + this.inPathLength = max_energy_hit.getInpath_length(); } else { @@ -126,11 +126,11 @@ public final void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); - this.path_length = max_energy_barhit.getPath_length(); - this.inpath_length = max_energy_barhit.getInpath_length(); + this.pathLength = max_energy_barhit.getPath_length(); + this.inPathLength = max_energy_barhit.getInpath_length(); } } - + public double getPhi() { return Math.atan2(this.y, this.x); @@ -138,13 +138,13 @@ public double getPhi() public double getBeta() { - return (this.path_length / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c + return (this.pathLength / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c } public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { - this.bar_hits = bar_hits; - this.wedge_hits = wedge_hits; + this.barHits = bar_hits; + this.wedgeHits = wedge_hits; this.computeClusterProperties(); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index d13e96b958..3bc3df6236 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -1,24 +1,11 @@ package org.jlab.rec.atof.cluster; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; -import javax.swing.JFrame; -import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.groot.data.H1F; -import org.jlab.groot.data.H2F; -import org.jlab.groot.graphics.EmbeddedCanvas; -import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; -import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; /** * @@ -173,8 +160,6 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } - //DataBank clusterbank = fillAtofClusterBank(event, clusters); - //event.appendBank(clusterbank); } public ClusterFinder() { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 597b082afe..41de05aa21 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -2,12 +2,9 @@ import java.util.List; import org.jlab.geom.base.*; -import org.jlab.geom.detector.alert.ATOF.*; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Point3D; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.trackMatch.TrackProjection; import org.jlab.rec.atof.trackMatch.TrackProjector; @@ -24,11 +21,11 @@ public class AtofHit { private int sector, layer, component, order; - private int TDC, ToT; + private int tdc, tot; private double time, energy, x, y, z; private String type; - private boolean is_in_a_cluster; - private double path_length, inpath_length; + private boolean isInACluster; + private double pathLength, inPathLength; public int getSector() { return sector; @@ -62,20 +59,20 @@ public void setComponent(int component) { this.component = component; } - public int getTDC() { - return TDC; + public int getTdc() { + return tdc; } - public void setTDC(int tdc) { - this.TDC = tdc; + public void setTdc(int tdc) { + this.tdc = tdc; } - public int getToT() { - return ToT; + public int getTot() { + return tot; } - public void setToT(int tot) { - this.ToT = tot; + public void setTot(int tot) { + this.tot = tot; } public double getTime() { @@ -126,31 +123,31 @@ public void setType(String type) { this.type = type; } - public boolean getIs_in_a_cluster() { - return is_in_a_cluster; + public boolean getIsInACluster() { + return isInACluster; } - public void setIs_in_a_cluster(boolean is_in_a_cluster) { - this.is_in_a_cluster = is_in_a_cluster; + public void setIsInACluster(boolean is_in_a_cluster) { + this.isInACluster = is_in_a_cluster; } - public double getPath_length() { - return path_length; + public double getPathLength() { + return pathLength; } - public void setPath_length(double path_length) { - this.path_length = path_length; + public void setPathLength(double path_length) { + this.pathLength = path_length; } - public double getInpath_length() { - return inpath_length; + public double getInPathLength() { + return inPathLength; } - public void setInpath_length(double inpath_length) { - this.inpath_length = inpath_length; + public void setInPathLength(double inpath_length) { + this.inPathLength = inpath_length; } - public int computeModule_index() { + public int computeModuleIndex() { //Index ranging 0 to 60 for each wedge+bar module return 4 * this.sector + this.layer; } @@ -178,7 +175,7 @@ public final String makeType() { * @return 0 if the time was successfully set, or 1 if the hit type is * unsupported. */ - public final int TDC_to_time() { + 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."); @@ -214,7 +211,7 @@ public final int TDC_to_time() { } } //Hit time. Will need implementation of offsets. - this.time = tdc2time * this.TDC - distance_to_sipm / veff; + this.time = tdc2time * this.tdc - distance_to_sipm / veff; return 0; } @@ -226,7 +223,7 @@ public final int TDC_to_time() { * @return 0 if the energy was successfully set, or 1 if the hit type is * unsupported. */ - public final int ToT_to_energy() { + public final int convertTotToEnergy() { double tot2energy; if (null == this.type) { System.out.print("Null hit type, cannot convert tot to energy."); @@ -238,19 +235,19 @@ public final int ToT_to_energy() { //For now hits are considered in the middle of the wedge //And the SiPM on top double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS / 2.; - this.energy = tot2energy * this.ToT * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); + this.energy = tot2energy * this.tot * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); } case "bar up" -> { tot2energy = Parameters.TOT2ENERGY_BAR; //only half the information in the bar, //the attenuation will be computed when the full hit is formed - this.energy = tot2energy * this.ToT; + this.energy = tot2energy * this.tot; } case "bar down" -> { tot2energy = Parameters.TOT2ENERGY_BAR; //only half the information in the bar, //the attenuation will be computed when the full hit is formed - this.energy = tot2energy * this.ToT; + this.energy = tot2energy * this.tot; } case "bar" -> { System.out.print("Bar hit type, cannot convert tot to energy."); @@ -275,7 +272,7 @@ public final int ToT_to_energy() { * @return 0 if the coordinates were successfully set, or 1 if the hit type * is undefined or unsupported. */ - public final int slc_to_xyz(Detector atof) { + public final int convertSLCToXYZ(Detector atof) { int sl; if (null == this.type) { return 1; @@ -364,17 +361,17 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.layer = layer; this.component = component; this.order = order; - this.TDC = tdc; - this.ToT = tot; - this.is_in_a_cluster = false; + this.tdc = tdc; + this.tot = tot; + this.isInACluster = false; this.makeType(); - int is_ok = this.TDC_to_time(); + int is_ok = this.convertTdcToTime(); if (is_ok != 1) { - is_ok = this.ToT_to_energy(); + is_ok = this.convertTotToEnergy(); } if (is_ok != 1) { - is_ok = this.slc_to_xyz(atof); + is_ok = this.convertSLCToXYZ(atof); } } @@ -398,19 +395,19 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.layer = layer; this.component = component; this.order = order; - this.TDC = tdc; - this.ToT = tot; - this.is_in_a_cluster = false; + this.tdc = tdc; + this.tot = tot; + this.isInACluster = false; //First the type needs to be set this.makeType(); //From it the coordinates can be computed - this.slc_to_xyz(atof); + this.convertSLCToXYZ(atof); //From them tracks can be matched this.matchTrack(track_projector); //And energy and time can then be computed - this.ToT_to_energy(); - this.TDC_to_time(); + this.convertTotToEnergy(); + this.convertTdcToTime(); } /** @@ -452,9 +449,9 @@ public final void matchTrack(TrackProjector track_projector) { if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { - this.setPath_length(Projections.get(i_track).get_WedgePathLength()); + this.setPathLength(Projections.get(i_track).get_WedgePathLength()); } else { - this.setPath_length(Projections.get(i_track).get_BarPathLength()); + this.setPathLength(Projections.get(i_track).get_BarPathLength()); } } } @@ -514,8 +511,8 @@ public int matchTrack(DataEvent event) { Point3D projection_point = new Point3D(xt, yt, zt); if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - this.setPath_length(path); - this.setInpath_length(inpath); + this.setPathLength(path); + this.setInPathLength(inpath); } } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 8b13a978ca..7bba7a1ab2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,12 +1,5 @@ package org.jlab.rec.atof.hit; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; -import java.util.ArrayList; import org.jlab.rec.atof.constants.Parameters; /** @@ -20,22 +13,22 @@ public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits - private AtofHit hit_up, hit_down; + private AtofHit hitUp, hitDown; public AtofHit getHitUp() { - return hit_up; + return hitUp; } public void setHitUp(AtofHit hit_up) { - this.hit_up = hit_up; + this.hitUp = hit_up; } public AtofHit getHitDown() { - return hit_down; + return hitDown; } public void setHitDown(AtofHit hit_down) { - this.hit_down = hit_down; + this.hitDown = hit_down; } /** @@ -43,7 +36,7 @@ public void setHitDown(AtofHit hit_down) { * */ public final void computeZ() { - this.setZ(Parameters.VEFF/2. * (hit_up.getTime() - hit_down.getTime())); + this.setZ(Parameters.VEFF/2. * (hitUp.getTime() - hitDown.getTime())); } /** @@ -55,12 +48,12 @@ public final void computeZ() { public final void computeTime() { //We pick the most energetic signal as the timing signal double time_at_sipm, distance_to_sipm; - if(this.hit_down.getEnergy() > this.hit_up.getEnergy()) { - time_at_sipm = this.hit_down.getTime(); + if(this.hitDown.getEnergy() > this.hitUp.getEnergy()) { + time_at_sipm = this.hitDown.getTime(); distance_to_sipm = Parameters.LENGTH_ATOF/2. - this.getZ(); } else { - time_at_sipm = this.hit_up.getTime(); + time_at_sipm = this.hitUp.getTime(); distance_to_sipm = Parameters.LENGTH_ATOF/2. + this.getZ(); } this.setTime(time_at_sipm - distance_to_sipm/Parameters.VEFF); @@ -76,8 +69,8 @@ public final void computeEnergy() { this.computeZ(); double distance_hit_to_sipm_up = Parameters.LENGTH_ATOF / 2. + this.getZ(); double distance_hit_to_sipm_down = Parameters.LENGTH_ATOF / 2. - this.getZ(); - double Edep_up = hit_up.getEnergy() * Math.exp(distance_hit_to_sipm_up / Parameters.ATT_L); - double Edep_down = hit_down.getEnergy() * Math.exp(distance_hit_to_sipm_down / Parameters.ATT_L); + 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); } @@ -88,8 +81,8 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { } this.setType("bar"); this.setOrder(2);//Fake order for bar hits - this.hit_up = hit_up; - this.hit_down = hit_down; + this.hitUp = hit_up; + this.hitDown = hit_down; this.setLayer(hit_up.getLayer()); this.setSector(hit_up.getSector()); this.setComponent(10); @@ -101,10 +94,9 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { } public BarHit() { - super(); // Call AtofHit constructor - //Sets some parameters to make a bar type hit + super(); this.setType("bar"); - this.setOrder(2); + this.setOrder(2);//Fake order for bar hits } /** diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index 748ff8dfef..8f45d28217 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -1,20 +1,11 @@ package org.jlab.rec.atof.hit; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.Collections; -import javax.swing.JFrame; -import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.groot.data.H1F; -import org.jlab.groot.graphics.EmbeddedCanvas; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; /** * @@ -22,37 +13,35 @@ */ public class HitFinder { - private ArrayList bar_hits; - private ArrayList wedge_hits; + private ArrayList barHits; + private ArrayList wedgeHits; public HitFinder() { - this.bar_hits = new ArrayList<>(); - this.wedge_hits = new ArrayList<>(); + this.barHits = new ArrayList<>(); + this.wedgeHits = new ArrayList<>(); } - // Getter and Setter for bar_hits + // Getter and Setter for barHits public ArrayList getBarHits() { - return bar_hits; + return barHits; } public void setBarHits(ArrayList bar_hits) { - this.bar_hits = bar_hits; + this.barHits = bar_hits; } - // Getter and Setter for wedge_hits public ArrayList getWedgeHits() { - return wedge_hits; + return wedgeHits; } public void setWedgeHits(ArrayList wedge_hits) { - this.wedge_hits = wedge_hits; + this.wedgeHits = wedge_hits; } - public void FindHits(DataEvent event, Detector atof, TrackProjector track_projector) { - + public void findHits(DataEvent event, Detector atof, TrackProjector track_projector) { //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); + this.barHits.clear(); + this.wedgeHits.clear(); //They are read from the ATOF TDC bank DataBank bank = event.getBank("ATOF::tdc"); int nt = bank.rows(); // number of hits @@ -86,7 +75,7 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec hit_down.add(hit); case "wedge" -> { hit.matchTrack(track_projector); - this.wedge_hits.add(hit); + this.wedgeHits.add(hit); } default -> System.out.print("Undefined hit type \n"); @@ -105,20 +94,20 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec //Bar hits are matched to ahdc tracks and listed BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); this_bar_hit.matchTrack(track_projector); - this.bar_hits.add(this_bar_hit); + this.barHits.add(this_bar_hit); } } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.barHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedgeHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } - public void FindHits(DataEvent event, Detector atof) { + public void findHits(DataEvent event, Detector atof) { //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); + this.barHits.clear(); + this.wedgeHits.clear(); //They are read from the ATOF TDC bank DataBank bank_atof_hits = event.getBank("ATOF::tdc"); int nt = bank_atof_hits.rows(); // number of hits @@ -151,7 +140,7 @@ public void FindHits(DataEvent event, Detector atof) { hit_down.add(hit); case "wedge" -> { hit.matchTrack(event); - this.wedge_hits.add(hit); + this.wedgeHits.add(hit); } default -> System.out.print("Undefined hit type \n"); @@ -169,20 +158,19 @@ public void FindHits(DataEvent event, Detector atof) { if (this_hit_up.matchBar(this_hit_down)) { //Bar hits are matched to ahdc tracks and listed BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - this_bar_hit.matchTrack(event); - this.bar_hits.add(this_bar_hit); + //this_bar_hit.matchTrack(event); + this.barHits.add(this_bar_hit); } } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.barHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedgeHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } /** * @param args the command line arguments */ public static void main(String[] args) { - } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 066a3ceea3..306ecb5fa2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -13,70 +13,68 @@ */ public class RecoBankWriter { - public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits) { + public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { - ArrayList hitlist = new ArrayList<>(); - hitlist.addAll(wedge_hits); - hitlist.addAll(bar_hits); + ArrayList hitList = new ArrayList<>(); + hitList.addAll(wedgeHits); + hitList.addAll(barHits); - DataBank bank = event.createBank("ATOF::hits", hitlist.size()); + DataBank bank = event.createBank("ATOF::hits", hitList.size()); if (bank == null) { - System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + System.err.println("COULD NOT CREATE A ATOF::hits BANK!!!!!!"); return null; } - for(int i =0; i< hitlist.size(); i++) { + for(int i =0; i< hitList.size(); i++) { bank.setShort("id",i, (short)(i+1)); - bank.setInt("sector",i, (int) hitlist.get(i).getSector()); - bank.setInt("layer",i, (int) hitlist.get(i).getLayer()); - bank.setInt("component",i, (int) hitlist.get(i).getComponent()); - //bank.setShort("trkID",i, (short) hitlist.get(i).get_AssociatedTrkId()); - //bank.setShort("clusterid", i, (short) hitlist.get(i).get_AssociatedClusterID()); - 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()); - bank.setFloat("inlength",i, (float) (hitlist.get(i).getInpath_length())); - bank.setFloat("pathlength",i, (float) (hitlist.get(i).getPath_length())); + bank.setInt("sector",i, (int) hitList.get(i).getSector()); + bank.setInt("layer",i, (int) hitList.get(i).getLayer()); + bank.setInt("component",i, (int) hitList.get(i).getComponent()); + 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()); + bank.setFloat("inlength",i, (float) (hitList.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (hitList.get(i).getPath_length())); } return bank; } - public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterlist) { + public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterList) { - DataBank bank = event.createBank("ATOF::clusters", clusterlist.size()); + DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); if (bank == null) { - System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + System.err.println("COULD NOT CREATE A ATOF::clusters BANK!!!!!!"); return null; } - for(int i =0; i< clusterlist.size(); i++) { + for(int i =0; i< clusterList.size(); i++) { bank.setShort("id",i, (short)(i+1)); - bank.setInt("barsize",i, (int) clusterlist.get(i).getBarHits().size()); - bank.setInt("wedgesize",i, (int) clusterlist.get(i).getWedgeHits().size()); - 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()); - bank.setFloat("inpathlength",i, (float) (clusterlist.get(i).getInpath_length())); - bank.setFloat("pathlength",i, (float) (clusterlist.get(i).getPath_length())); + bank.setInt("barsize",i, (int) clusterList.get(i).getBarHits().size()); + bank.setInt("wedgesize",i, (int) clusterList.get(i).getWedgeHits().size()); + 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()); + bank.setFloat("inpathlength",i, (float) (clusterList.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (clusterList.get(i).getPath_length())); } return bank; } - public int appendATOFBanks(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits, ArrayList clusterlist) { + public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { - DataBank hitbank = this.fillAtofHitBank(event, wedge_hits, bar_hits); + DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); if (hitbank != null) { event.appendBank(hitbank); } else return 1; - DataBank clusterbank = fillAtofClusterBank(event, clusterlist); + DataBank clusterbank = fillAtofClusterBank(event, clusterList); if (clusterbank != null) { event.appendBank(clusterbank); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java index 58f40ad415..384a81d85f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -1,15 +1,12 @@ package org.jlab.rec.service; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import java.util.concurrent.atomic.AtomicInteger; -import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -20,38 +17,36 @@ import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; /** - * Service to return reconstructed ATOF hits and clusters + * Service to return reconstructed Atof hits and clusters * * @author npilleux * */ -public class ATOFEngine extends ReconstructionEngine { +public class AtofEngine extends ReconstructionEngine { - public ATOFEngine() { + public AtofEngine() { super("ATOF", "pilleux", "1.0"); } RecoBankWriter rbc; - private final AtomicInteger Run = new AtomicInteger(0); - private Detector ATOF; - private double B; //Magnetic field + private final AtomicInteger run = new AtomicInteger(0); + private Detector Atof; + private double b; //Magnetic field - //Setters and getters public void setB(double B) { - this.B = B; + this.b = B; } public double getB() { - return B; + return b; } - public void setATOF(Detector ATOF) { - this.ATOF = ATOF; + public void setAtof(Detector ATOF) { + this.Atof = ATOF; } - public Detector getATOF() { - return ATOF; + public Detector getAtof() { + return Atof; } @Override @@ -63,27 +58,23 @@ public boolean processDataEvent(DataEvent event) { DataBank bank = event.getBank("RUN::config"); - // Load the constants - //------------------- int newRun = bank.getInt("run", 0); if (newRun == 0) { return true; } - if (Run.get() == 0 || (Run.get() != 0 && Run.get() != newRun)) { - Run.set(newRun); + if (run.get() == 0 || (run.get() != 0 && run.get() != newRun)) { + run.set(newRun); } - //CalibrationConstantsLoader constantsLoader = new CalibrationConstantsLoader(newRun, this.getConstantsManager()); - - //Track Projector Initialisation with B field + //Track Projector Initialisation with b field TrackProjector projector = new TrackProjector(); - projector.setB(this.B); - projector.ProjectTracks(event); + projector.setB(this.b); + projector.projectTracks(event); //Hit finder init HitFinder hitfinder = new HitFinder(); - hitfinder.FindHits(event, ATOF); + hitfinder.findHits(event, Atof); ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); @@ -100,7 +91,7 @@ public boolean processDataEvent(DataEvent event) { ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - rbc.appendATOFBanks(event, WedgeHits, BarHits, Clusters); + rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters); } return true; } @@ -111,42 +102,12 @@ public boolean init() { AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - this.ATOF = factory.createDetectorCLAS(cp); - - //requireConstants(Arrays.asList(CalibrationConstantsLoader.getAtofTables())); - //this.getConstantsManager().setVariation("default"); - + this.Atof = factory.createDetectorCLAS(cp); this.registerOutputBank("ATOF::hits", "ATOF::clusters"); return true; } public static void main(String arg[]) { - ATOFEngine en = new ATOFEngine(); - - //READING MAG FIELD MAP - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields(mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); - } catch (Exception e) { - e.printStackTrace(); - } - float[] b = new float[3]; - Swim swimmer = new Swim(); - swimmer.BfieldLab(0, 0, 0, b); - en.setB(Math.abs(b[2])); - - en.init(); - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/mixed_ions.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - en.processDataEvent(event); - event.getBank("ATOF::clusters").show(); - } } } From 199c47f177f15c644fcb533587f8f98ee9f034ee Mon Sep 17 00:00:00 2001 From: N-Plx Date: Tue, 11 Feb 2025 16:10:57 -0600 Subject: [PATCH 34/82] style: fixed naming conventions and some cleaning --- .../jlab/rec/atof/Cluster/AtofCluster.java | 10 +- .../jlab/rec/atof/Cluster/ClusterFinder.java | 26 +-- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 8 +- .../rec/atof/TrackMatch/TrackProjection.java | 73 ++++---- .../rec/atof/TrackMatch/TrackProjector.java | 161 ++++-------------- .../jlab/rec/atof/banks/RecoBankWriter.java | 8 +- 6 files changed, 99 insertions(+), 187 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index fd1ef4a519..4d30ed2ac8 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -117,8 +117,8 @@ public final void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); - this.pathLength = max_energy_hit.getPath_length(); - this.inPathLength = max_energy_hit.getInpath_length(); + this.pathLength = max_energy_hit.getPathLength(); + this.inPathLength = max_energy_hit.getInPathLength(); } else { @@ -126,11 +126,11 @@ public final void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); - this.pathLength = max_energy_barhit.getPath_length(); - this.inPathLength = max_energy_barhit.getInpath_length(); + this.pathLength = max_energy_barhit.getPathLength(); + this.inPathLength = max_energy_barhit.getInPathLength(); } } - + public double getPhi() { return Math.atan2(this.y, this.x); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 3bc3df6236..1e8619b8bd 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -36,7 +36,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int i_wedge = 0; i_wedge < wedge_hits.size(); i_wedge++) { AtofHit this_wedge_hit = wedge_hits.get(i_wedge); //Make a cluster for each wedge hit that has not been previously clustered - if (this_wedge_hit.getIs_in_a_cluster()) { + if (this_wedge_hit.getIsInACluster()) { continue; } @@ -45,7 +45,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { ArrayList this_cluster_bar_hits = new ArrayList<>(); //Indicate that this hit now is in a cluster - this_wedge_hit.setIs_in_a_cluster(true); + this_wedge_hit.setIsInACluster(true); //And store it this_cluster_wedge_hits.add(this_wedge_hit); @@ -54,12 +54,12 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int j_wedge = i_wedge + 1; j_wedge < wedge_hits.size(); j_wedge++) { AtofHit other_wedge_hit = wedge_hits.get(j_wedge); //If that other hit is already involved in a cluster, skip it - if (other_wedge_hit.getIs_in_a_cluster()) { + if (other_wedge_hit.getIsInACluster()) { continue; } //Check the distance between the hits //For now we use phi module and z component differences from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_wedge_hit.computeModule_index()); + int delta_module = Math.abs(this_wedge_hit.computeModuleIndex() - other_wedge_hit.computeModuleIndex()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -74,7 +74,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { if (delta_component <= Parameters.SIGMA_COMPONENT_CLUSTERING)//delta_Z <= sigma_Z) { if (delta_T < Parameters.SIGMA_T_CLUSTERING) { - other_wedge_hit.setIs_in_a_cluster(true); + other_wedge_hit.setIsInACluster(true); this_cluster_wedge_hits.add(other_wedge_hit); } } @@ -85,12 +85,12 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int j_bar = 0; j_bar < bar_hits.size(); j_bar++) { BarHit other_bar_hit = bar_hits.get(j_bar); //Skip already clustered hits - if (other_bar_hit.getIs_in_a_cluster()) { + if (other_bar_hit.getIsInACluster()) { continue; } //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_bar_hit.computeModule_index()); + int delta_module = Math.abs(this_wedge_hit.computeModuleIndex() - other_bar_hit.computeModuleIndex()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -102,7 +102,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { if (delta_T < Parameters.SIGMA_T_CLUSTERING) { - other_bar_hit.setIs_in_a_cluster(true); + other_bar_hit.setIsInACluster(true); this_cluster_bar_hits.add(other_bar_hit); } } @@ -119,26 +119,26 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int i_bar = 0; i_bar < bar_hits.size(); i_bar++) { BarHit this_bar_hit = bar_hits.get(i_bar); //Skip hits that have already been clustered - if (this_bar_hit.getIs_in_a_cluster()) { + if (this_bar_hit.getIsInACluster()) { continue; } ArrayList this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); - this_bar_hit.setIs_in_a_cluster(true); + this_bar_hit.setIsInACluster(true); this_cluster_bar_hits.add(this_bar_hit); //Loop through less energetic clusters for (int j_bar = i_bar + 1; j_bar < bar_hits.size(); j_bar++) { BarHit other_bar_hit = bar_hits.get(j_bar); //Skip already clustered hits - if (other_bar_hit.getIs_in_a_cluster()) { + if (other_bar_hit.getIsInACluster()) { continue; } //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_bar_hit.computeModule_index() - other_bar_hit.computeModule_index()); + int delta_module = Math.abs(this_bar_hit.computeModuleIndex() - other_bar_hit.computeModuleIndex()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -151,7 +151,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { if (delta_T < Parameters.SIGMA_T_CLUSTERING) { - other_bar_hit.setIs_in_a_cluster(true); + other_bar_hit.setIsInACluster(true); this_cluster_bar_hits.add(other_bar_hit); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 41de05aa21..0ca3ff0c7a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -434,13 +434,13 @@ public final void matchTrack(TrackProjector track_projector) { case "wedge" -> { sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; - projection_point = Projections.get(i_track).get_WedgeIntersect(); + projection_point = Projections.get(i_track).getWedgeIntersect(); } case "bar up", "bar down" -> { System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; - projection_point = Projections.get(i_track).get_BarIntersect(); + projection_point = Projections.get(i_track).getBarIntersect(); } default -> System.out.print("Impossible to match track and hit; hit type is undefined \n"); @@ -449,9 +449,9 @@ public final void matchTrack(TrackProjector track_projector) { if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { - this.setPathLength(Projections.get(i_track).get_WedgePathLength()); + this.setPathLength(Projections.get(i_track).getWedgePathLength()); } else { - this.setPathLength(Projections.get(i_track).get_BarPathLength()); + this.setPathLength(Projections.get(i_track).getBarPathLength()); } } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index 5138d15083..f6da1eacf3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -13,46 +13,46 @@ public class TrackProjection { /** * Intersection point of the track with the middle surface of the bar. */ - private Point3D _BarIntersect = new Point3D(); + private Point3D barIntersect = new Point3D(); /** * Intersection point of the track with the middle surface of the wedges. */ - private Point3D _WedgeIntersect = new Point3D(); + private Point3D wedgeIntersect = new Point3D(); /** * Path length of the track from the DOCA to the beam line * to the entrance surface of the bar. */ - Float _BarPathLength; + Float barPathLength; /** * Path length of the track from the DOCA to the beam line * to the entrance surface of the wedges. */ - Float _WedgePathLength; + Float wedgePathLength; /** * Path length inside the bar. */ - Float _BarInPathLength; + Float barInPathLength; /** * Path length inside the wedge. */ - Float _WedgeInPathLength; + Float wedgeInPathLength; /** * Default constructor that initializes the intersection points and path lengths to {@code NaN}. */ public TrackProjection() { - _BarIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); - _WedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); - _BarPathLength = Float.NaN; - _WedgePathLength = Float.NaN; - _BarInPathLength = Float.NaN; - _WedgeInPathLength = Float.NaN; + barIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + wedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + barPathLength = Float.NaN; + wedgePathLength = Float.NaN; + barInPathLength = Float.NaN; + wedgeInPathLength = Float.NaN; } /** @@ -60,8 +60,8 @@ public TrackProjection() { * * @return {@link Point3D} bar's intersection point. */ - public Point3D get_BarIntersect() { - return _BarIntersect; + public Point3D getBarIntersect() { + return barIntersect; } /** @@ -69,8 +69,8 @@ public Point3D get_BarIntersect() { * * @return {@link Point3D} wedge's intersection point. */ - public Point3D get_WedgeIntersect() { - return _WedgeIntersect; + public Point3D getWedgeIntersect() { + return wedgeIntersect; } /** @@ -78,8 +78,8 @@ public Point3D get_WedgeIntersect() { * * @return {@code Float} path length to the bar's middle surface. */ - public Float get_BarPathLength() { - return _BarPathLength; + public Float getBarPathLength() { + return barPathLength; } /** @@ -88,8 +88,8 @@ public Float get_BarPathLength() { * * @return {@code Float} path length inside the bar. */ - public Float get_BarInPathLength() { - return _BarInPathLength; + public Float getBarInPathLength() { + return barInPathLength; } /** @@ -97,8 +97,8 @@ public Float get_BarInPathLength() { * * @return {@code Float} path length to the wedge's middle surface. */ - public Float get_WedgePathLength() { - return _WedgePathLength; + public Float getWedgePathLength() { + return wedgePathLength; } /** @@ -107,8 +107,8 @@ public Float get_WedgePathLength() { * * @return {@code Float} path length inside the wedge. */ - public Float get_WedgeInPathLength() { - return _WedgeInPathLength; + public Float getWedgeInPathLength() { + return wedgeInPathLength; } /** @@ -116,8 +116,8 @@ public Float get_WedgeInPathLength() { * * @param BarIntersect {@link Point3D} intersection with the bar. */ - public void set_BarIntersect(Point3D BarIntersect) { - this._BarIntersect = BarIntersect; + public void setBarIntersect(Point3D BarIntersect) { + this.barIntersect = BarIntersect; } /** @@ -125,8 +125,8 @@ public void set_BarIntersect(Point3D BarIntersect) { * * @param WedgeIntersect {@link Point3D} intersection with the wedge. */ - public void set_WedgeIntersect(Point3D WedgeIntersect) { - this._WedgeIntersect = WedgeIntersect; + public void setWedgeIntersect(Point3D WedgeIntersect) { + this.wedgeIntersect = WedgeIntersect; } /** @@ -134,8 +134,8 @@ public void set_WedgeIntersect(Point3D WedgeIntersect) { * * @param BarPathLength {@code Float} path length to the bar inner surface. */ - public void set_BarPathLength(Float BarPathLength) { - this._BarPathLength = BarPathLength; + public void setBarPathLength(Float BarPathLength) { + this.barPathLength = BarPathLength; } /** @@ -143,8 +143,8 @@ public void set_BarPathLength(Float BarPathLength) { * * @param WedgePathLength {@code Float} path length to the wedge inner surface. */ - public void set_WedgePathLength(Float WedgePathLength) { - this._WedgePathLength = WedgePathLength; + public void setWedgePathLength(Float WedgePathLength) { + this.wedgePathLength = WedgePathLength; } /** @@ -152,8 +152,8 @@ public void set_WedgePathLength(Float WedgePathLength) { * * @param BarInPathLength {@code Float} path length inside the bar. */ - public void set_BarInPathLength(Float BarInPathLength) { - this._BarInPathLength = BarInPathLength; + public void setBarInPathLength(Float BarInPathLength) { + this.barInPathLength = BarInPathLength; } /** @@ -161,10 +161,9 @@ public void set_BarInPathLength(Float BarInPathLength) { * * @param WedgeInPathLength {@code Float} path length inside the wedge. */ - public void set_WedgeInPathLength(Float WedgeInPathLength) { - this._WedgeInPathLength = WedgeInPathLength; + public void setWedgeInPathLength(Float WedgeInPathLength) { + this.wedgeInPathLength = WedgeInPathLength; } - /** * testing purposes. diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index 225ebf4842..d66040e6c8 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -7,13 +7,6 @@ import org.jlab.io.base.DataEvent; import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.clas.tracking.kalmanfilter.Units; -import org.jlab.io.hipo.HipoDataSource; -import org.jlab.clas.swimtools.Swim; -import org.jlab.utils.CLASResources; -import cnuphys.magfield.MagneticFields; -import java.io.BufferedWriter; -import java.io.IOException; -import org.jlab.geom.prim.Point3D; import org.jlab.rec.atof.constants.Parameters; /** @@ -37,20 +30,20 @@ public class TrackProjector { /** * projections of tracks. */ - private List Projections; + private List projections; /** * solenoid magnitude */ - private Double B; + private Double b; /** * Default constructor that initializes the list of projections as new empty * list and the magnetic field to 5T. */ public TrackProjector() { - Projections = new ArrayList(); - B = 5.0; + projections = new ArrayList(); + this.b = 5.0; } /** @@ -60,7 +53,7 @@ public TrackProjector() { * the projections. */ public List getProjections() { - return Projections; + return projections; } /** @@ -69,7 +62,7 @@ public List getProjections() { * @return solenoid magnitude */ public Double getB() { - return B; + return b; } /** @@ -78,7 +71,7 @@ public Double getB() { * @param Projections a {@link List} of {@link TrackProjection}. */ public void setProjections(List Projections) { - this.Projections = Projections; + this.projections = Projections; } /** @@ -87,7 +80,7 @@ public void setProjections(List Projections) { * @param B a double. */ public void setB(Double B) { - this.B = B; + this.b = B; } /** @@ -96,9 +89,9 @@ public void setB(Double B) { * * @param event the {@link DataEvent} containing track data to be projected. */ - public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { + public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { - Projections.clear(); + projections.clear(); String track_bank_name = "AHDC::Track"; @@ -129,20 +122,20 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) double yb = 0; //momenta must be in GeV for the helix class - Helix helix = new Helix(x, y, z, px/1000., py/1000., pz/1000., q, B, xb, yb, units); + Helix helix = new Helix(x, y, z, px/1000., py/1000., pz/1000., q, b, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); + projection.setBarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.setWedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); - projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); + projection.setBarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.setWedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); - projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); - Projections.add(projection); + projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); + projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); + projections.add(projection); fill_out_bank(outputBank, projection, i); } event.appendBank(outputBank); @@ -157,7 +150,7 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) */ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { - Projections.clear(); + projections.clear(); String track_bank_name = "MC::Particle"; if (event == null) { // check if there is an event @@ -194,123 +187,43 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd double yb = 0; //momenta must be in GeV for the helix class - Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + Helix helix = new Helix(x, y, z, px, py, pz, q, b, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); + projection.setBarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.setWedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); - projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); + projection.setBarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.setWedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); - projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); - Projections.add(projection); + projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); + projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); + projections.add(projection); fill_out_bank(outputBank, projection, i); } event.appendBank(outputBank); } } - public void projectMCTracks_full_path(DataEvent event, int num_event, BufferedWriter writer) throws IOException { - - String track_bank_name = "MC::Particle"; - if (event == null) { // check if there is an event - //System.out.print(" no event \n"); - } else if (event.hasBank(track_bank_name) == false) { - // check if there are ahdc tracks in the event - //System.out.print("no tracks \n"); - } else { - DataBank bank = event.getBank(track_bank_name); - int nt = bank.rows(); // number of tracks - - for (int i = 0; i < nt; i++) { - - double x = bank.getFloat("vx", i); - double y = bank.getFloat("vy", i); - double z = bank.getFloat("vz", i); - double px = bank.getFloat("px", i); - double py = bank.getFloat("py", i); - double pz = bank.getFloat("pz", i); - - //Put everything in MM - - x = x*10; - y = y*10; - z = z*10; - - Units units = Units.MM; - - int q = -1; //need the charge sign from tracking - - double xb = 0; - double yb = 0; - - //momenta must be in GeV for the helix class - Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); - - double min = 0.1; - double max = Parameters.WEDGE_INNER_RADIUS+Parameters.WEDGE_THICKNESS; - int nsteps = 20; - double step = (max-min)/nsteps; - for(double i_radius = min; i_radius wedge 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()); - bank.setFloat("inlength",i, (float) (hitList.get(i).getInpath_length())); - bank.setFloat("pathlength",i, (float) (hitList.get(i).getPath_length())); + bank.setFloat("inlength",i, (float) (hitList.get(i).getInPathLength())); + bank.setFloat("pathlength",i, (float) (hitList.get(i).getPathLength())); } return bank; } @@ -60,8 +60,8 @@ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList Date: Tue, 11 Feb 2025 16:16:26 -0600 Subject: [PATCH 35/82] fix: file name matches class name --- .../org/jlab/rec/service/{ATOFEngine.java => AtofEngine.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename reconstruction/alert/src/main/java/org/jlab/rec/service/{ATOFEngine.java => AtofEngine.java} (100%) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java rename to reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java From 70c80e5937835cbc2e210de600dfc9cf2d722b40 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Tue, 11 Feb 2025 17:03:18 -0600 Subject: [PATCH 36/82] style: some more documentation --- .../jlab/rec/atof/Cluster/AtofCluster.java | 144 +++++++++++++----- .../jlab/rec/atof/Cluster/ClusterFinder.java | 36 ++++- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 17 +++ .../java/org/jlab/rec/atof/Hit/HitFinder.java | 39 ++++- .../jlab/rec/atof/banks/RecoBankWriter.java | 42 ++++- 5 files changed, 233 insertions(+), 45 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 4d30ed2ac8..abf08bc35b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -5,16 +5,32 @@ import org.jlab.rec.atof.hit.BarHit; /** + * The {@code AtofCluster} represents clusters in the atof * - * @author npilleux + *

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

    + * + * @author pilleux */ public class AtofCluster { - + + /** + * list of hits in the bars. + */ ArrayList barHits; + /** + * list of hits in the wedges. + */ ArrayList wedgeHits; - double x,y,z,time,energy; + /** + * cluster properties:position [cm], time [ns], energy[MeV], path length + * [cm] and length through the atof [cm]. + */ + double x, y, z, time, energy; double pathLength, inPathLength; - + public ArrayList getBarHits() { return barHits; } @@ -70,7 +86,7 @@ public double getEnergy() { public void setEnergy(double energy) { this.energy = energy; } - + public double getPathLength() { return pathLength; } @@ -78,7 +94,7 @@ public double getPathLength() { public void setPathLength(double pathLength) { this.pathLength = pathLength; } - + public double getInPathLength() { return inPathLength; } @@ -86,42 +102,50 @@ public double getInPathLength() { public void setInPathLength(double inPathLength) { this.inPathLength = inPathLength; } - - //Cluster coordinates and time are defined as the coordinates and time of the max energy hit - //Can be changed later + + /** + * 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; + this.energy = 0; double max_energy = -1; AtofHit max_energy_hit = new AtofHit(); BarHit max_energy_barhit = new BarHit(); - for(int i_wedge = 0; i_wedgemax_energy){max_energy_hit = this_wedge_hit; max_energy = this_energy;} + this.energy += this_energy; + if (this_energy > max_energy) { + max_energy_hit = this_wedge_hit; + max_energy = this_energy; + } } - - for(int i_bar = 0; i_barmax_energy){max_energy_barhit = this_bar_hit; max_energy = this_energy;} + this.energy += this_energy; + if (this_energy > max_energy) { + max_energy_barhit = this_bar_hit; + max_energy = this_energy; + } } - - if(max_energy_hit.getEnergy() > max_energy_barhit.getEnergy()) - { + + if (max_energy_hit.getEnergy() > max_energy_barhit.getEnergy()) { 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.pathLength = max_energy_hit.getPathLength(); this.inPathLength = max_energy_hit.getInPathLength(); - } - else - { + } else { this.time = max_energy_barhit.getTime(); this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); @@ -130,28 +154,66 @@ public final void computeClusterProperties() { this.inPathLength = max_energy_barhit.getInPathLength(); } } - - public double getPhi() - { - return Math.atan2(this.y, this.x); + + public double getEdepWedge() { + double energy = 0; + for (int i = 0; i < this.wedgeHits.size(); i++) { + AtofHit this_hit = this.wedgeHits.get(i); + energy += this_hit.getEnergy(); + } + return energy; } - - public double getBeta() - { - return (this.pathLength / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c - } - - public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) - { - this.barHits = bar_hits; - this.wedgeHits = wedge_hits; - this.computeClusterProperties(); + + public double getEdepBar() { + double energy = 0; + for (int i = 0; i < this.barHits.size(); i++) { + AtofHit this_hit = this.barHits.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); + } + + /** + * Compute the cluster beta from the path length and time. + * + * @return a double that is beta + * + * - TO DO: Change to non-hardcoded value for c + * + */ + public double getBeta() { + //Need to change to non hardcoded value + return (this.pathLength / this.time) / (2.9979 * Math.pow(10, 2)); + } + + /** + * Constructor that initializes the list of bar hits and list of wedge hits + * and computes the cluster properties. + * + * @param bar_hits a {@link ArrayList} of {@link BarHit}. + * @param wedge_hits a {@link ArrayList} of {@link AtofHit}. + * + */ + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { + this.barHits = bar_hits; + this.wedgeHits = wedge_hits; + this.computeClusterProperties(); + } /** * @param args the command line arguments */ public static void main(String[] args) { } - + } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 1e8619b8bd..a2825dadf3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -8,21 +8,51 @@ import org.jlab.rec.atof.hit.HitFinder; /** + * The {@code ClusterFinder} class builds clusters in the atof * - * @author npilleux + *

    + * Uses found hits information. + * Creates a {@link AtofCluster} matching them. + *

    + * + * @author pilleux */ public class ClusterFinder { + /** + * list of clusters. + */ private ArrayList clusters; + /** + * Sets the list of clusters. + * + * @param clusters a {@link ArrayList} of {@link AtofCluster}. + * + */ public void setClusters(ArrayList clusters) { this.clusters = clusters; } + /** + * Gets the list of clusters. + * + * @return a {@link ArrayList} of {@link AtofCluster}. + * + */ public ArrayList getClusters() { return clusters; } + /** + * Builds clusters in the {@link DateEvent} 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) { //A list of clusters is built for each event @@ -162,6 +192,10 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { } } + /** + * Default constructor that initializes the list clusters as new empty + * list. + */ public ClusterFinder() { clusters = new ArrayList<>(); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 0ca3ff0c7a..937d9e43f6 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -147,11 +147,19 @@ public void setInPathLength(double inpath_length) { this.inPathLength = inpath_length; } + /** + * Computes the module index for the hit. + * + */ public int computeModuleIndex() { //Index ranging 0 to 60 for each wedge+bar module return 4 * this.sector + this.layer; } + /** + * Assigns a type to the hit. + * + */ public final String makeType() { //Type of hit can be wedge, bar up, bar down or bar. //Avoids testing components and order every time. @@ -458,6 +466,15 @@ public final void matchTrack(TrackProjector track_projector) { } } + /** + * Matches the current track with ahdc tracks projections that have been written to the banks. + * Calculates the match by comparing the hit's azimuthal angle and longitudinal position + * (z) with the track projection. If a match is found within defined + * tolerances for phi and z, the path length of the matched hit is updated. + * + * @param event a @link{DataEvent} in which the track projections bank has been written. + * + */ public int matchTrack(DataEvent event) { String track_bank_name = "AHDC::Projections"; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index 8f45d28217..b0f17d9669 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -8,14 +8,33 @@ import org.jlab.rec.atof.trackMatch.TrackProjector; /** + * The {@code HitFinder} class finds hits in the atof. + * + *

    + * Uses atof tdc bank information + * + * Creates a {@link ArrayList} of {@link BarHit} for bar hits read. + * Creates a {@link ArrayList} of {@link AtofHit} for wedge hits read. + * + *

    * - * @author npilleux + * @author pilleux */ public class HitFinder { + /** + * list of bar hits + */ private ArrayList barHits; + /** + * list of wedge hits + */ private ArrayList wedgeHits; + /** + * Default constructor that initializes the list of hits as new empty + * lists. + */ public HitFinder() { this.barHits = new ArrayList<>(); this.wedgeHits = new ArrayList<>(); @@ -38,6 +57,16 @@ public void setWedgeHits(ArrayList wedge_hits) { this.wedgeHits = wedge_hits; } + /** + * Find hits in the event, matches them to tracks found in the ahdc + * and build their properties. + * + * @param event the {@link DataEvent} containing hits. + * @param atof the {@link Detector} representing the atof geometry to match + * the sector/layer/component to x/y/z. + * @param track_projector the {@link TrackProjector} containing the ahdc tracks projected + * to the atof for matching. + */ public void findHits(DataEvent event, Detector atof, TrackProjector track_projector) { //For each event a list of bar hits and a list of wedge hits are filled this.barHits.clear(); @@ -103,6 +132,14 @@ public void findHits(DataEvent event, Detector atof, TrackProjector track_projec Collections.sort(this.wedgeHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } + /** + * Find hits in the event, matches them to tracks in the + * projections bank and build their properties. + * + * @param event the {@link DataEvent} containing hits and the bank with ahdc track projections. + * @param atof the {@link Detector} representing the atof geometry to match + * the sector/layer/component to x/y/z. + */ public void findHits(DataEvent event, Detector atof) { //For each event a list of bar hits and a list of wedge hits are filled diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 169283b563..f32c384136 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -8,11 +8,25 @@ import org.jlab.rec.atof.hit.BarHit; /** - * - * @author npilleux + * The {@code RecoBankWriter} writes the banks needed for the atof reconstruction: + * track projections, hits and clusters info. + * + * @author pilleux */ public class RecoBankWriter { + /** + * Writes the bank of atof hits. + * + * @param event the {@link DataEvent} in which to add the bank + * @param wedgeHits the {@link ArrayList} of {@link AtofHit} + * containing the wedge hits to be added to the bank + * @param barHits the {@link ArrayList} of {@link BarHit} + * containing the bar hits to be added to the bank + * + * @return {@link DataBank} the bank with all the hits read in the event. + * + */ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { ArrayList hitList = new ArrayList<>(); @@ -42,6 +56,16 @@ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge return bank; } + /** + * Writes the bank of atof clusters. + * + * @param event the {@link DataEvent} in which to add the bank + * @param clusterList the {@link ArrayList} of {@link AtofCluster} + * 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 fillAtofClusterBank(DataEvent event, ArrayList clusterList) { DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); @@ -66,6 +90,20 @@ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); From d04345a0cd38d0eb79c36479fae497b890616b25 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 12 Feb 2025 10:44:31 -0600 Subject: [PATCH 37/82] refactor: move writing of the projection bank --- .../rec/atof/TrackMatch/TrackProjector.java | 26 +-- .../jlab/rec/atof/banks/RecoBankWriter.java | 175 +++++++++++------- .../java/org/jlab/rec/service/AtofEngine.java | 4 +- 3 files changed, 117 insertions(+), 88 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index d66040e6c8..f3334085eb 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -1,7 +1,6 @@ package org.jlab.rec.atof.trackMatch; import java.util.ArrayList; -import java.util.List; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; @@ -30,7 +29,7 @@ public class TrackProjector { /** * projections of tracks. */ - private List projections; + private ArrayList projections; /** * solenoid magnitude @@ -52,7 +51,7 @@ public TrackProjector() { * @return a {@link List} of {@link TrackProjection} objects representing * the projections. */ - public List getProjections() { + public ArrayList getProjections() { return projections; } @@ -70,7 +69,7 @@ public Double getB() { * * @param Projections a {@link List} of {@link TrackProjection}. */ - public void setProjections(List Projections) { + public void setProjections(ArrayList Projections) { this.projections = Projections; } @@ -104,7 +103,6 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) DataBank bank = event.getBank(track_bank_name); int nt = bank.rows(); // number of tracks TrackProjection projection = new TrackProjection(); - DataBank outputBank = event.createBank("AHDC::Projections", nt); for (int i = 0; i < nt; i++) { double x = bank.getFloat("x", i); @@ -136,9 +134,7 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); projections.add(projection); - fill_out_bank(outputBank, projection, i); } - event.appendBank(outputBank); } } @@ -203,25 +199,9 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); projections.add(projection); - fill_out_bank(outputBank, projection, i); } - event.appendBank(outputBank); } } - - public static void fill_out_bank(DataBank outputBank, TrackProjection projection, int i) { - outputBank.setFloat("x_at_bar", i, (float) projection.getBarIntersect().x()); - outputBank.setFloat("y_at_bar", i, (float) projection.getBarIntersect().y()); - outputBank.setFloat("z_at_bar", i, (float) projection.getBarIntersect().z()); - outputBank.setFloat("L_at_bar", i, (float) projection.getBarPathLength()); - outputBank.setFloat("L_in_bar", i, (float) projection.getBarInPathLength()); - outputBank.setFloat("x_at_wedge", i, (float) projection.getWedgeIntersect().x()); - outputBank.setFloat("y_at_wedge", i, (float) projection.getWedgeIntersect().y()); - outputBank.setFloat("z_at_wedge", i, (float) projection.getWedgeIntersect().z()); - outputBank.setFloat("L_at_wedge", i, (float) projection.getWedgePathLength()); - outputBank.setFloat("L_in_wedge", i, (float) projection.getWedgeInPathLength()); - - } public static void main(String arg[]) { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index f32c384136..93a7d98a69 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -6,118 +6,167 @@ import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.trackMatch.TrackProjection; /** - * The {@code RecoBankWriter} writes the banks needed for the atof reconstruction: - * track projections, hits and clusters info. - * + * The {@code RecoBankWriter} writes the banks needed for the atof + * reconstruction: track projections, hits and clusters info. + * * @author pilleux */ public class RecoBankWriter { - + /** * Writes the bank of atof hits. - * + * * @param event the {@link DataEvent} in which to add the bank - * @param wedgeHits the {@link ArrayList} of {@link AtofHit} - * containing the wedge hits to be added to the bank - * @param barHits the {@link ArrayList} of {@link BarHit} - * containing the bar hits to be added to the bank - * + * @param wedgeHits the {@link ArrayList} of {@link AtofHit} containing the + * wedge hits to be added to the bank + * @param barHits the {@link ArrayList} of {@link BarHit} containing the bar + * hits to be added to the bank + * * @return {@link DataBank} the bank with all the hits read in the event. - * + * */ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { - + ArrayList hitList = new ArrayList<>(); hitList.addAll(wedgeHits); hitList.addAll(barHits); - - DataBank bank = event.createBank("ATOF::hits", hitList.size()); - + + DataBank bank = event.createBank("ATOF::hits", hitList.size()); + if (bank == null) { System.err.println("COULD NOT CREATE A ATOF::hits BANK!!!!!!"); return null; } - - for(int i =0; i< hitList.size(); i++) { - bank.setShort("id",i, (short)(i+1)); - bank.setInt("sector",i, (int) hitList.get(i).getSector()); - bank.setInt("layer",i, (int) hitList.get(i).getLayer()); - bank.setInt("component",i, (int) hitList.get(i).getComponent()); - 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()); - bank.setFloat("inlength",i, (float) (hitList.get(i).getInPathLength())); - bank.setFloat("pathlength",i, (float) (hitList.get(i).getPathLength())); + + for (int i = 0; i < hitList.size(); i++) { + bank.setShort("id", i, (short) (i + 1)); + bank.setInt("sector", i, (int) hitList.get(i).getSector()); + bank.setInt("layer", i, (int) hitList.get(i).getLayer()); + bank.setInt("component", i, (int) hitList.get(i).getComponent()); + 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()); + bank.setFloat("inlength", i, (float) (hitList.get(i).getInPathLength())); + bank.setFloat("pathlength", i, (float) (hitList.get(i).getPathLength())); } return bank; } - + /** * Writes the bank of atof clusters. - * + * * @param event the {@link DataEvent} in which to add the bank - * @param clusterList the {@link ArrayList} of {@link AtofCluster} + * @param clusterList the {@link ArrayList} of {@link AtofCluster} * containing the clusters info to be added to the bank - * - * @return {@link DataBank} the bank with all the clusters built in the event. - * + * + * @return {@link DataBank} the bank with all the clusters built in the + * event. + * */ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterList) { - - DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); - + + DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); + if (bank == null) { System.err.println("COULD NOT CREATE A ATOF::clusters BANK!!!!!!"); return null; } - - for(int i =0; i< clusterList.size(); i++) { - bank.setShort("id",i, (short)(i+1)); - bank.setInt("barsize",i, (int) clusterList.get(i).getBarHits().size()); - bank.setInt("wedgesize",i, (int) clusterList.get(i).getWedgeHits().size()); - 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()); - bank.setFloat("inpathlength",i, (float) (clusterList.get(i).getInPathLength())); - bank.setFloat("pathlength",i, (float) (clusterList.get(i).getPathLength())); + + for (int i = 0; i < clusterList.size(); i++) { + bank.setShort("id", i, (short) (i + 1)); + bank.setInt("barsize", i, (int) clusterList.get(i).getBarHits().size()); + bank.setInt("wedgesize", i, (int) clusterList.get(i).getWedgeHits().size()); + 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()); + bank.setFloat("inpathlength", i, (float) (clusterList.get(i).getInPathLength())); + bank.setFloat("pathlength", i, (float) (clusterList.get(i).getPathLength())); } return bank; } - + + /** + * Writes the bank of track projections. + * + * @param event the {@link DataEvent} in which to add the bank + * @param projections the {@link ArrayList} of {@link TrackProjection} + * containing the track projection info to be added to the bank + * + * @return {@link DataBank} the bank with all the projected tracks in the + * event. + * + */ + public static DataBank fillProjectionsBank(DataEvent event, ArrayList projections) { + + DataBank bank = event.createBank("AHDC::Projections", projections.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A AHDC::Projections BANK!!!!!!"); + return null; + } + + for (int i = 0; i < projections.size(); i++) { + TrackProjection projection = projections.get(i); + bank.setFloat("x_at_bar", i, (float) projection.getBarIntersect().x()); + bank.setFloat("y_at_bar", i, (float) projection.getBarIntersect().y()); + bank.setFloat("z_at_bar", i, (float) projection.getBarIntersect().z()); + bank.setFloat("L_at_bar", i, (float) projection.getBarPathLength()); + bank.setFloat("L_in_bar", i, (float) projection.getBarInPathLength()); + bank.setFloat("x_at_wedge", i, (float) projection.getWedgeIntersect().x()); + bank.setFloat("y_at_wedge", i, (float) projection.getWedgeIntersect().y()); + bank.setFloat("z_at_wedge", i, (float) projection.getWedgeIntersect().z()); + bank.setFloat("L_at_wedge", i, (float) projection.getWedgePathLength()); + bank.setFloat("L_in_wedge", i, (float) projection.getWedgeInPathLength()); + } + return bank; + } + /** * Appends the atof banks to an event. - * + * * @param event the {@link DataEvent} in which to append the banks - * @param clusterList the {@link ArrayList} of {@link AtofCluster} + * @param clusterList the {@link ArrayList} of {@link AtofCluster} * containing the clusters info to be added to the bank - * @param wedgeHits the {@link ArrayList} of {@link AtofHit} - * containing the wedge hits info to be added - * @param barHits the {@link ArrayList} of {@link BarHit} - * containing the bar hits info to be added - * + * @param wedgeHits the {@link ArrayList} of {@link AtofHit} containing the + * wedge hits info to be added + * @param barHits the {@link ArrayList} of {@link BarHit} containing the bar + * hits info to be added + * @param projections the {@link ArrayList} of {@link TrackProjection} containing the + * track projections info to be added + * * @return 0 if it worked, 1 if it failed - * + * */ - public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { + public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList, ArrayList projections) { + + DataBank projbank = this.fillProjectionsBank(event, projections); + if (projbank != null) { + event.appendBank(projbank); + } else { + return 1; + } DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); if (hitbank != null) { event.appendBank(hitbank); + } else { + return 1; } - else return 1; DataBank clusterbank = fillAtofClusterBank(event, clusterList); if (clusterbank != null) { event.appendBank(clusterbank); + } else { + return 1; } - else return 1; - + return 0; } @@ -126,5 +175,5 @@ public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayL */ public static void main(String[] args) { } - + } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java index 384a81d85f..ae98601b4c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java @@ -74,7 +74,7 @@ public boolean processDataEvent(DataEvent event) { //Hit finder init HitFinder hitfinder = new HitFinder(); - hitfinder.findHits(event, Atof); + hitfinder.findHits(event, Atof, projector); ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); @@ -91,7 +91,7 @@ public boolean processDataEvent(DataEvent event) { ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters); + rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters, projector.getProjections()); } return true; } From 350b6ec473b2a66de36968b57d9aa47ac2b1519b Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 13 Jan 2025 10:51:29 -0600 Subject: [PATCH 38/82] Definition of atof hits --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java new file mode 100644 index 0000000000..ce2d3d181a --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -0,0 +1,238 @@ +package org.jlab.rec.atof.Hit; + +import org.jlab.geom.base.*; +import org.jlab.geom.detector.alert.ATOF.*; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.prim.Point3D; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; + +/** + * + * @author npilleux + */ +public class AtofHit { + + private int sector, layer, component, order; + private int TDC, ToT; + private double time, energy, x, y, z; + private String type; + + public int getSector() { + return sector; + } + + public void setSector(int sector) { + this.sector = sector; + } + + public int getLayer() { + return layer; + } + + public void setLayer(int layer) { + this.layer = layer; + } + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } + + public int getComponent() { + return component; + } + + public void setComponent(int component) { + this.component = component; + } + + 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 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 String makeType(){ + String type = "undefined"; + if(this.component == 10 && this.order==0) type = "bar down"; + else if(this.component == 10 && this.order==1) type = "bar up"; + else if(this.component < 10) type = "wedge"; + this.type = type; + return type; + } + + public int TDC_to_time() + { + double some_conversion = 0; + if(this.type == "wedge") + { + some_conversion = 10;//read calib constants here + } + else if(this.type == "bar up") + { + some_conversion = 10; + } + else if(this.type == "bar down") + { + some_conversion = 10; + } + else + { + return 0; + } + this.time = some_conversion * this.TDC; + return 1; + } + + public int ToT_to_energy() + { + double some_conversion = 0; + if(this.type == "wedge") + { + some_conversion = 10;//read calib constants here + } + else if(this.type == "bar up") + { + some_conversion = 10; + } + else if(this.type == "bar down") + { + some_conversion = 10; + } + else + { + return 0; + } + this.energy = some_conversion * this.ToT; + return 1; + } + + public int slc_to_xyz(Detector atof) + { + int sl = 999; + if(this.type == "wedge") sl = 1; + else if(this.type == "bar up" || this.type == "bar down") sl = 0; + else return 0; + + Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); + Point3D midpoint = comp.getMidpoint(); + this.x = midpoint.x(); + this.y = midpoint.y(); + this.z = midpoint.z(); + return 1; + } + + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) + { + this.sector = sector; + this.layer = layer; + this.component = component; + this.order = order; + this.TDC = tdc; + this.ToT = tot; + + this.makeType(); + int is_ok = this.TDC_to_time(); + if(is_ok==1) is_ok = this.ToT_to_energy(); + if(is_ok==1) is_ok = this.slc_to_xyz(atof); + } + + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + DataBank bank = event.getBank("ATOF::tdc"); + int nt = bank.rows(); // number of tracks + + for (int i = 0; i < nt; i++) { + int sector = bank.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + System.out.print(hit.getX() + "\n"); + } + } + } +} + From 2ba808adfc2a22089a56c2c191af26d490bf264e Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 13 Jan 2025 11:59:02 -0600 Subject: [PATCH 39/82] Definition of bar hits --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 10 +- .../java/org/jlab/rec/atof/Hit/BarHit.java | 179 ++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index ce2d3d181a..322eb8bf1f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -185,6 +185,15 @@ public int slc_to_xyz(Detector atof) return 1; } + public boolean barmatch(AtofHit hit2match) + { + if(this.getSector() != hit2match.getSector()) return false; //System.out.print("Two hits in different sectors \n"); + else if(this.getLayer() != hit2match.getLayer()) return false; //System.out.print("Two hits in different layers \n"); + else if(this.getComponent() != 10 || hit2match.getComponent() != 10) return false; //System.out.print("At least one hit is not in the bar \n"); + else if(this.getOrder() == hit2match.getOrder()) return false; //System.out.print("Two hits in same SiPM \n"); + else return true; + } + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { this.sector = sector; @@ -200,7 +209,6 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot if(is_ok==1) is_ok = this.slc_to_xyz(atof); } - /** * @param args the command line arguments */ diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java new file mode 100644 index 0000000000..202f943a4a --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -0,0 +1,179 @@ +package org.jlab.rec.atof.Hit; + +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import java.util.ArrayList; + +/** + * + * @author npilleux + */ +public class BarHit { + + //A bar hit is the combination of a downstream and upstream hits + private AtofHit hit_up, hit_down; + private double x,y,z, time, energy; + int sector, layer; + + public AtofHit getHitUp() { + return hit_up; + } + + public void setHitUp(AtofHit hit_up) { + this.hit_up = hit_up; + } + + public AtofHit getHitDown() { + return hit_down; + } + + public void setHitDown(AtofHit hit_down) { + this.hit_down = hit_down; + } + + 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 void computeZ() { + double some_calibration = 10; //Here read the calibration DB + this.z = some_calibration * (hit_up.getTime() - hit_down.getTime()); + } + + public void computeTime() { + double some_calibration = 10; //Here read the calibration DB + this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime())/2.); + } + + public void computeEnergy() { + this.energy = (hit_up.getEnergy() + hit_down.getEnergy()); + } + + 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 int getSector() { + return sector; + } + + public void setSector(int sector) { + this.sector = sector; + } + + public int getLayer() { + return layer; + } + + public void setLayer(int layer) { + this.layer = layer; + } + + public BarHit(AtofHit hit_down, AtofHit hit_up) + { + boolean hits_match = hit_down.barmatch(hit_up); + if(!hits_match) throw new UnsupportedOperationException("Hits do not match \n"); + + this.hit_up = hit_up; + this.hit_down = hit_down; + this.layer = hit_up.getLayer(); + this.sector = hit_up.getSector(); + this.x = hit_up.getX(); + this.y = hit_up.getY(); + this.computeZ(); + this.computeTime(); + this.computeEnergy(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + DataBank bank = event.getBank("ATOF::tdc"); + int nt = bank.rows(); // number of tracks + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); + ArrayList hit_wedge = new ArrayList<>(); + for (int i = 0; i < nt; i++) { + int sector = bank.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + 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); + case "wedge" -> hit_wedge.add(hit); + default -> System.out.print("Undefined hit type \n"); + } + } + ArrayList bar_hits = new ArrayList(); + for(int i_up=0; i_up Date: Mon, 13 Jan 2025 13:40:03 -0600 Subject: [PATCH 40/82] Building hit lists --- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java new file mode 100644 index 0000000000..eb0e55caa3 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -0,0 +1,106 @@ +package org.jlab.rec.atof.Hit; + +import java.util.ArrayList; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +/** + * + * @author npilleux + */ +public class HitFinder { + + private ArrayList bar_hits; + private ArrayList wedge_hits; + + public HitFinder() + { + this.bar_hits = new ArrayList<>(); + this.wedge_hits = new ArrayList<>(); + } + + // Getter and Setter for bar_hits + public ArrayList getBarHits() { + return bar_hits; + } + + public void setBarHits(ArrayList bar_hits) { + this.bar_hits = bar_hits; + } + + // Getter and Setter for wedge_hits + public ArrayList getWedgeHits() { + return wedge_hits; + } + + public void setWedgeHits(ArrayList wedge_hits) { + this.wedge_hits = wedge_hits; + } + + public void FindHits(DataEvent event, Detector atof) { + + DataBank bank = event.getBank("ATOF::tdc"); + int nt = bank.rows(); // number of hits + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); + + for (int i = 0; i < nt; i++) { + int sector = bank.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + 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); + case "wedge" -> this.wedge_hits.add(hit); + default -> System.out.print("Undefined hit type \n"); + } + } + for(int i_up=0; i_up Date: Mon, 13 Jan 2025 14:55:24 -0600 Subject: [PATCH 41/82] First clustering, to be revisited --- .../jlab/rec/atof/Cluster/AtofCluster.java | 127 +++++++++++++++++ .../jlab/rec/atof/Cluster/ClusterFinder.java | 133 ++++++++++++++++++ .../java/org/jlab/rec/atof/Hit/AtofHit.java | 19 +++ .../java/org/jlab/rec/atof/Hit/BarHit.java | 18 +++ 4 files changed, 297 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java new file mode 100644 index 0000000000..931d43ff8c --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -0,0 +1,127 @@ +package org.jlab.rec.atof.Cluster; + +import java.util.ArrayList; +import org.jlab.rec.atof.Hit.AtofHit; +import org.jlab.rec.atof.Hit.BarHit; + +/** + * + * @author npilleux + */ +public class AtofCluster { + + ArrayList bar_hits; + ArrayList wedge_hits; + double x,y,z,time,energy; + + public ArrayList getBarHits() { + return bar_hits; + } + + public void setBarHits(ArrayList bar_hits) { + this.bar_hits = bar_hits; + } + + public ArrayList getWedgeHits() { + return wedge_hits; + } + + public void setWedgeHits(ArrayList wedge_hits) { + this.wedge_hits = wedge_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; + } + + //Cluster coordinates and time are defined as the coordinates and time of the max energy hit + //Can be changed later + public void computeClusterProperties() { + this.energy=0; + double max_energy = -1; + AtofHit max_energy_hit = new AtofHit(); + BarHit max_energy_barhit = new BarHit(); + + for(int i_wedge = 0; i_wedgemax_energy){max_energy_hit = this_wedge_hit; max_energy = this_energy;} + } + + for(int i_bar = 0; i_barmax_energy){max_energy_barhit = this_bar_hit; max_energy = this_energy;} + } + + if(max_energy_hit.getEnergy() > max_energy_barhit.getEnergy()) + { + this.time = max_energy_hit.getTime(); + this.x = max_energy_hit.getX(); + this.y = max_energy_hit.getY(); + this.z = max_energy_hit.getZ(); + } + else + { + this.time = max_energy_barhit.getTime(); + this.x = max_energy_barhit.getX(); + this.y = max_energy_barhit.getY(); + this.z = max_energy_barhit.getZ(); + } + + } + + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) + { + this.bar_hits = bar_hits; + this.wedge_hits = wedge_hits; + this.computeClusterProperties(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + } + +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java new file mode 100644 index 0000000000..22ae7ecf93 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -0,0 +1,133 @@ +package org.jlab.rec.atof.Cluster; + +import java.util.ArrayList; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.Hit.AtofHit; +import org.jlab.rec.atof.Hit.BarHit; +import org.jlab.rec.atof.Hit.HitFinder; + +/** + * + * @author npilleux + */ +public class ClusterFinder { + + private ArrayList clusters; + + public void MakeClusters(HitFinder hitfinder) { + + ArrayList wedge_hits = hitfinder.getWedgeHits(); + ArrayList bar_hits = hitfinder.getBarHits(); + + double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future + double sigma_Z = 2.0;//wedge length. to be read from DB in the future + double sigma_T = 10;//timing resolution to be read from DB in the future + + + for(int i_wedge = 0; i_wedge this_cluster_wedge_hits = new ArrayList<>(); + ArrayList this_cluster_bar_hits = new ArrayList<>(); + + this_wedge_hit.setIs_in_a_cluster(true); + this_cluster_wedge_hits.add(this_wedge_hit); + + + //Check if other wedge hits should be clustered + for(int j_wedge = 0; j_wedge this_cluster_wedge_hits = new ArrayList(); + ArrayList this_cluster_bar_hits = new ArrayList(); + this_cluster_bar_hits.add(this_bar_hit); + AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); + clusters.add(cluster); + } + } + + public ClusterFinder() + { + clusters = new ArrayList(); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + HitFinder hitfinder = new HitFinder(); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + hitfinder.FindHits(event, atof); + ClusterFinder clusterfinder = new ClusterFinder(); + clusterfinder.MakeClusters(hitfinder); + + } + } + +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 322eb8bf1f..20ebc190c4 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -18,6 +18,7 @@ public class AtofHit { private int TDC, ToT; private double time, energy, x, y, z; private String type; + private boolean is_in_a_cluster; public int getSector() { return sector; @@ -114,6 +115,14 @@ public String getType() { public void setType(String type) { this.type = type; } + + public boolean getIs_in_a_cluster() { + return is_in_a_cluster; + } + + public void setIs_in_a_cluster(boolean is_in_a_cluster) { + this.is_in_a_cluster = is_in_a_cluster; + } public String makeType(){ String type = "undefined"; @@ -194,6 +203,11 @@ public boolean barmatch(AtofHit hit2match) else return true; } + public double getPhi() + { + return Math.atan2(this.y, this.x); + } + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { this.sector = sector; @@ -202,12 +216,17 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.order = order; this.TDC = tdc; this.ToT = tot; + this.is_in_a_cluster = false; this.makeType(); int is_ok = this.TDC_to_time(); if(is_ok==1) is_ok = this.ToT_to_energy(); if(is_ok==1) is_ok = this.slc_to_xyz(atof); } + + public AtofHit() + { + } /** * @param args the command line arguments diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 202f943a4a..0317d17d13 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -18,6 +18,7 @@ public class BarHit { private AtofHit hit_up, hit_down; private double x,y,z, time, energy; int sector, layer; + private boolean is_in_a_cluster; public AtofHit getHitUp() { return hit_up; @@ -105,6 +106,19 @@ public void setLayer(int layer) { this.layer = layer; } + public boolean getIs_in_a_cluster() { + return is_in_a_cluster; + } + + public void setIs_in_a_cluster(boolean is_in_a_cluster) { + this.is_in_a_cluster = is_in_a_cluster; + } + + public double getPhi() + { + return Math.atan2(this.y, this.x); + } + public BarHit(AtofHit hit_down, AtofHit hit_up) { boolean hits_match = hit_down.barmatch(hit_up); @@ -121,6 +135,10 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) this.computeEnergy(); } + public BarHit() + { + } + /** * @param args the command line arguments */ From ddd47bd53ae660a8c0d7bf3d5cf5c7b4d602b80a Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 13 Jan 2025 15:01:27 -0600 Subject: [PATCH 42/82] ahdc track projection --- .../rec/atof/TrackMatch/TrackProjection.java | 124 +++++++++++ .../rec/atof/TrackMatch/TrackProjector.java | 196 ++++++++++++++++++ 2 files changed, 320 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java new file mode 100644 index 0000000000..9ccbbe26dd --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -0,0 +1,124 @@ +package org.jlab.rec.atof.TrackMatch; + +import org.jlab.geom.prim.Point3D; + +/** + * The {@code TrackProjection} class holds ahdc track information relevant for atof analysis + * i.e projected to the inner surfaces of the bar and wedges + * @author pilleux + */ + +public class TrackProjection { + + /** + * Intersection point of the track with the inner surface of the bar. + */ + private Point3D _BarIntersect = new Point3D(); + + /** + * Intersection point of the track with the inner surface of the wedges. + */ + private Point3D _WedgeIntersect = new Point3D(); + + /** + * Path length of the track from the DOCA to the beam line + * to the inner surface of the bar. + */ + Float _BarPathLength; + + /** + * Path length of the track from the DOCA to the beam line + * to the inner surface of the wedges. + */ + Float _WedgePathLength; + + /** + * Default constructor that initializes the intersection points and path lengths to {@code NaN}. + */ + public TrackProjection() { + _BarIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + _WedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + _BarPathLength = Float.NaN; + _WedgePathLength = Float.NaN; + } + + /** + * Gets the intersection point of the track with the inner surface of the bar. + * + * @return {@link Point3D} bar's intersection point. + */ + public Point3D get_BarIntersect() { + return _BarIntersect; + } + + /** + * Gets the intersection point of the track with the inner surface of the wedges. + * + * @return {@link Point3D} wedge's intersection point. + */ + public Point3D get_WedgeIntersect() { + return _WedgeIntersect; + } + + /** + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * + * @return {@code Float} path length to the bar's inner surface. + */ + public Float get_BarPathLength() { + return _BarPathLength; + } + + /** + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * + * @return {@code Float} path length to the wedge's inner surface. + */ + public Float get_WedgePathLength() { + return _WedgePathLength; + } + + /** + * Sets the intersection point of the track with the inner surface of the bar. + * + * @param BarIntersect {@link Point3D} intersection with the bar. + */ + public void set_BarIntersect(Point3D BarIntersect) { + this._BarIntersect = BarIntersect; + } + + /** + * Sets the intersection point of the track with the inner surface of the wedges. + * + * @param WedgeIntersect {@link Point3D} intersection with the wedge. + */ + public void set_WedgeIntersect(Point3D WedgeIntersect) { + this._WedgeIntersect = WedgeIntersect; + } + + /** + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * + * @param BarPathLength {@code Float} path length to the bar inner surface. + */ + public void set_BarPathLength(Float BarPathLength) { + this._BarPathLength = BarPathLength; + } + + /** + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * + * @param WedgePathLength {@code Float} path length to the wedge inner surface. + */ + public void set_WedgePathLength(Float WedgePathLength) { + this._WedgePathLength = WedgePathLength; + } + + /** + * testing purposes. + * + * @param arg command-line arguments. + */ + public static void main(String arg[]) { + } +} \ No newline at end of file diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java new file mode 100644 index 0000000000..feb790fd28 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -0,0 +1,196 @@ +package org.jlab.rec.atof.TrackMatch; + +import java.util.ArrayList; +import java.util.List; + +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.clas.tracking.trackrep.Helix; +import org.jlab.clas.tracking.kalmanfilter.Units; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.clas.swimtools.Swim; +import org.jlab.utils.CLASResources; +import cnuphys.magfield.MagneticFields; + +/** + * The {@code TrackProjector} class projects ahdc tracks to the inner surfaces + * of the bar and wedges of the atof + * + *

    + * Uses ahdc track bank information (for now position, momentum) Creates a + * {@link TrackProjection} for each track. + *

    + * + *

    + * TO DO: - replace hardcoded values with database values. - magnetic field ? + * use swimmer tools? - charge ? + *

    + * + * @author pilleux + */ +public class TrackProjector { + + /** + * projections of tracks. + */ + private List Projections; + + /** + * solenoid magnitude + */ + private Double B; + + /** + * Default constructor that initializes the list of projections as new empty + * list and the magnetic field to 5T. + */ + public TrackProjector() { + Projections = new ArrayList(); + B = 5.0; + } + + /** + * Gets the list of track projections. + * + * @return a {@link List} of {@link TrackProjection} objects representing + * the projections. + */ + public List getProjections() { + return Projections; + } + + /** + * Gets the solenoid magnitude + * + * @return solenoid magnitude + */ + public Double getB() { + return B; + } + + /** + * Sets the list of track projections. + * + * @param Projections a {@link List} of {@link TrackProjection}. + */ + public void setProjections(List Projections) { + this.Projections = Projections; + } + + /** + * Sets the solenoid magnitude. + * + * @param B a double. + */ + public void setB(Double B) { + this.B = B; + } + + /** + * Projects the ahdc tracks in the event onto the atof using a {@link Helix} + * model. + * + * @param event the {@link DataEvent} containing track data to be projected. + */ + public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { + + Projections.clear(); + + double bar_innerradius = 77; //NEEDS TO BE REPLACED WITH DB CONSTANTS something like ccdb.INNERRADIUS[0] + double wedge_innerradius = 80; + + String track_bank_name = "AHDC::Track"; + + if (event == null) { // check if there is an event + //System.out.print(" no event"); + } else if (event.hasBank(track_bank_name) == false) { + // check if there are ahdc tracks in the event + //System.out.print("no tracks"); + } else { + DataBank bank = event.getBank(track_bank_name); + + int nt = bank.rows(); // number of tracks + TrackProjection projection = new TrackProjection(); + DataBank outputBank = event.createBank("AHDC::Projections", nt); + + for (int i = 0; i < nt; i++) { + + double x = bank.getFloat("x", i); + double y = bank.getFloat("y", i); + double z = bank.getFloat("z", i); + double px = bank.getFloat("px", i); + double py = bank.getFloat("py", i); + double pz = bank.getFloat("pz", i); + + int q = 1; //this has to be changed, we need the charge info from tracking + + Units units = Units.MM; //can be MM or CM. + + double xb = 0; + double yb = 0; + + Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + + projection.set_BarIntersect(helix.getHelixPointAtR(bar_innerradius)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_innerradius)); + + projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); + projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); + + Projections.add(projection); + fill_out_bank(outputBank, projection, i); + } + event.appendBank(outputBank); + } + } + + public static void fill_out_bank(DataBank outputBank, TrackProjection projection, int i) { + outputBank.setFloat("x_at_bar", i, (float) projection.get_BarIntersect().x()); + outputBank.setFloat("y_at_bar", i, (float) projection.get_BarIntersect().y()); + outputBank.setFloat("z_at_bar", i, (float) projection.get_BarIntersect().z()); + outputBank.setFloat("L_at_bar", i, (float) projection.get_BarPathLength()); + outputBank.setFloat("x_at_wedge", i, (float) projection.get_WedgeIntersect().x()); + outputBank.setFloat("y_at_wedge", i, (float) projection.get_WedgeIntersect().y()); + outputBank.setFloat("z_at_wedge", i, (float) projection.get_WedgeIntersect().z()); + outputBank.setFloat("L_at_wedge", i, (float) projection.get_WedgePathLength()); + } + + public static void main(String arg[]) { + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + double B = Math.abs(b[2]); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(B); + + //Input to be read + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/test_updated_2.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + + int event_number = 0; + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; + + projector.ProjectTracks(event); + //event.getBank("AHDC::Projections").show(); + } + + System.out.print("Read " + event_number + " events"); + } +} \ No newline at end of file From d5913b1d1d3237423e135d03454a9a4695fdddd9 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:41:58 -0600 Subject: [PATCH 43/82] Path length --- .../jlab/rec/atof/Cluster/AtofCluster.java | 16 + .../java/org/jlab/rec/atof/Hit/AtofHit.java | 319 ++++++++++++------ .../java/org/jlab/rec/atof/Hit/BarHit.java | 36 ++ 3 files changed, 273 insertions(+), 98 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 931d43ff8c..102b61b6c3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -13,6 +13,7 @@ public class AtofCluster { ArrayList bar_hits; ArrayList wedge_hits; double x,y,z,time,energy; + double path_length; public ArrayList getBarHits() { return bar_hits; @@ -70,6 +71,14 @@ public void setEnergy(double energy) { this.energy = energy; } + public double getpath_length() { + return path_length; + } + + public void setpath_length(double path_length) { + this.path_length = path_length; + } + //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later public void computeClusterProperties() { @@ -100,6 +109,7 @@ public void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); + this.path_length = max_energy_hit.getpath_length(); } else { @@ -107,10 +117,16 @@ public void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); + this.path_length = max_energy_barhit.getpath_length(); } } + public double getPhi() + { + return Math.atan2(this.y, this.x); + } + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { this.bar_hits = bar_hits; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 20ebc190c4..17ceecbef2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -1,5 +1,6 @@ package org.jlab.rec.atof.Hit; +import java.util.List; import org.jlab.geom.base.*; import org.jlab.geom.detector.alert.ATOF.*; import org.jlab.detector.calib.utils.DatabaseConstantProvider; @@ -7,11 +8,21 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.TrackMatch.TrackProjection; +import org.jlab.rec.atof.TrackMatch.TrackProjector; /** - * + * + * Represents a hit in the atof. + * Stores info about the sector, layer, component, order, TDC, ToT. + * Type is wedge/bar up/bar down + * Spatial coordinates are computed from atof detector object using the geometry service + * Stores whether the hit is part of a cluster. + * Calculates time, energy based on TDC/ToT. + * * @author npilleux */ + public class AtofHit { private int sector, layer, component, order; @@ -19,6 +30,7 @@ public class AtofHit { private double time, energy, x, y, z; private String type; private boolean is_in_a_cluster; + private double path_length; public int getSector() { return sector; @@ -35,7 +47,7 @@ public int getLayer() { public void setLayer(int layer) { this.layer = layer; } - + public int getOrder() { return order; } @@ -51,7 +63,7 @@ public int getComponent() { public void setComponent(int component) { this.component = component; } - + public int getTDC() { return TDC; } @@ -67,7 +79,7 @@ public int getToT() { public void setToT(int tot) { this.ToT = tot; } - + public double getTime() { return time; } @@ -107,7 +119,7 @@ public double getZ() { public void setZ(double z) { this.z = z; } - + public String getType() { return type; } @@ -115,7 +127,7 @@ public String getType() { public void setType(String type) { this.type = type; } - + public boolean getIs_in_a_cluster() { return is_in_a_cluster; } @@ -124,109 +136,221 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - public String makeType(){ - String type = "undefined"; - if(this.component == 10 && this.order==0) type = "bar down"; - else if(this.component == 10 && this.order==1) type = "bar up"; - else if(this.component < 10) type = "wedge"; - this.type = type; - return type; + public double getpath_length() { + return path_length; } - - public int TDC_to_time() - { - double some_conversion = 0; - if(this.type == "wedge") - { - some_conversion = 10;//read calib constants here - } - else if(this.type == "bar up") - { - some_conversion = 10; - } - else if(this.type == "bar down") - { - some_conversion = 10; - } - else - { - return 0; - } - this.time = some_conversion * this.TDC; - return 1; + + public void setpath_length(double path_length) { + this.path_length = path_length; } - public int ToT_to_energy() - { - double some_conversion = 0; - if(this.type == "wedge") - { - some_conversion = 10;//read calib constants here - } - else if(this.type == "bar up") - { - some_conversion = 10; - } - else if(this.type == "bar down") - { - some_conversion = 10; - } - else - { - return 0; - } - this.energy = some_conversion * this.ToT; - return 1; + public int compute_module_index(){ + //Index ranging 0 to 60 for each wedge+bar module + return 4*this.sector + this.layer; } - - public int slc_to_xyz(Detector atof) - { + + public final String makeType() { + String itype = "undefined"; + if (this.component == 10 && this.order == 0) { + itype = "bar down"; + } else if (this.component == 10 && this.order == 1) { + itype = "bar up"; + } else if (this.component < 10) { + itype = "wedge"; + } + this.type = itype; + return itype; + } + + public final int TDC_to_time() { + double some_conversion = 0; + if (null == this.type) { + return 1; + } else { + switch (this.type) { + case "wedge" -> + some_conversion = 10;//read calib constants here + case "bar up" -> + some_conversion = 10; + case "bar down" -> + some_conversion = 10; + default -> { + return 1; + } + } + } + this.time = some_conversion * this.TDC; + return 0; + } + + public final int ToT_to_energy() { + double some_conversion = 0; + if (null == this.type) { + return 1; + } else { + switch (this.type) { + case "wedge" -> + some_conversion = 10;//read calib constants here + case "bar up" -> + some_conversion = 10; + case "bar down" -> + some_conversion = 10; + default -> { + return 1; + } + } + } + this.energy = some_conversion * this.ToT; + return 0; + } + + /** + * Calculates spatial coordinates for the hit based on associated + * detector component. Retrieves the midpoint of the atof component + * to assign the corresponding x, y, z coordinates to the hit. + * + * + * @param atof The Detector object representing the atof. + * @return 0 if the coordinates were successfully set, or 1 if the hit type + * is undefined or unsupported. + */ + public final int slc_to_xyz(Detector atof) { int sl = 999; - if(this.type == "wedge") sl = 1; - else if(this.type == "bar up" || this.type == "bar down") sl = 0; - else return 0; + if (null == this.type) { + return 1; + } else { + switch (this.type) { + case "wedge" -> + sl = 1; + case "bar up", "bar down" -> + sl = 0; + default -> { + return 1; + } + } + } Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); this.x = midpoint.x(); this.y = midpoint.y(); this.z = midpoint.z(); - return 1; + return 0; } - - public boolean barmatch(AtofHit hit2match) - { - if(this.getSector() != hit2match.getSector()) return false; //System.out.print("Two hits in different sectors \n"); - else if(this.getLayer() != hit2match.getLayer()) return false; //System.out.print("Two hits in different layers \n"); - else if(this.getComponent() != 10 || hit2match.getComponent() != 10) return false; //System.out.print("At least one hit is not in the bar \n"); - else if(this.getOrder() == hit2match.getOrder()) return false; //System.out.print("Two hits in same SiPM \n"); - else return true; + + /** + * Compares two AtofHit objects to check if they match in the bar. + *
      + *
    • If the sector or layer of the two hits do not match, the method + * returns {@code false}.
    • + *
    • If either hit is not in the bar (component must be 10), the method + * returns {@code false}.
    • + *
    • If both hits are in the same SiPM (i.e., their order is the same), + * 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 AtofHit object to compare with the current instance. + * @return {@code true} if the hits match; {@code false} otherwise. + */ + public boolean barmatch(AtofHit hit2match) { + if (this.getSector() != hit2match.getSector()) { + return false; //System.out.print("Two hits in different sectors \n"); + } else if (this.getLayer() != hit2match.getLayer()) { + return false; //System.out.print("Two hits in different layers \n"); + } else if (this.getComponent() != 10 || hit2match.getComponent() != 10) { + return false; //System.out.print("At least one hit is not in the bar \n"); + } else { + return this.getOrder() != hit2match.getOrder(); //System.out.print("Two hits in same SiPM \n"); + } } - - public double getPhi() - { + + /** + * Returns the azimuthal angle (phi) of the hit. + * + * @return The azimuthal angle (phi) in radians, in the range [-π, π]. + */ + public double getPhi() { return Math.atan2(this.y, this.x); } - - public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) - { - this.sector = sector; - this.layer = layer; - this.component = component; - this.order = order; - this.TDC = tdc; - this.ToT = tot; - this.is_in_a_cluster = false; - - this.makeType(); - int is_ok = this.TDC_to_time(); - if(is_ok==1) is_ok = this.ToT_to_energy(); - if(is_ok==1) is_ok = this.slc_to_xyz(atof); - } - - public AtofHit() - { - } + + /** + * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * component, 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 layer The layer of the detector where the hit was detected. + * @param component The component within the layer that registered the hit. + * @param order Order of the hit. + * @param tdc TDC value. + * @param tot ToT velue. + * @param atof Detector object representing the atof, used to calculate + * spatial coordinates. + */ + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { + this.sector = sector; + this.layer = layer; + this.component = component; + this.order = order; + this.TDC = tdc; + this.ToT = tot; + this.is_in_a_cluster = false; + + this.makeType(); + int is_ok = this.TDC_to_time(); + if (is_ok != 1) { + is_ok = this.ToT_to_energy(); + } + if (is_ok != 1) { + is_ok = this.slc_to_xyz(atof); + } + } + + /** + * Matches the current track with ahdc tracks projections. Calculates the + * match by comparing the hit's azimuthal angle and longitudinal position + * (z) with the track projection. If a match is found within defined + * tolerances for phi and z, the path length of the matched hit is updated. + * + * @param track_projector The TrackProjector object that provides a list of + * TrackProjections. + * + */ + public void MatchTrack(TrackProjector track_projector) { + double sigma_phi = 10; + double sigma_z = 10; + List Projections = track_projector.getProjections(); + for (int i_track = 0; i_track < Projections.size(); i_track++) { + Point3D projection_point = new Point3D(); + if (null == this.getType()) { + System.out.print("Impossible to match track and hitm hit type is undefined \n"); + } else { + switch (this.getType()) { + case "wedge" -> + projection_point = Projections.get(i_track).get_WedgeIntersect(); + case "bar up", "bar down" -> + projection_point = Projections.get(i_track).get_BarIntersect(); + default -> + System.out.print("Impossible to match track and hitm hit type is undefined \n"); + } + } + + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { + if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { + if ("wedge".equals(this.getType())) { + this.setpath_length(Projections.get(i_track).get_WedgePathLength()); + } else { + this.setpath_length(Projections.get(i_track).get_BarPathLength()); + } + } + } + } + } + + public AtofHit() { + } /** * @param args the command line arguments @@ -236,7 +360,7 @@ public static void main(String[] args) { AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); - + //Input to be read String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; HipoDataSource reader = new HipoDataSource(); @@ -248,7 +372,7 @@ public static void main(String[] args) { event_number++; DataBank bank = event.getBank("ATOF::tdc"); int nt = bank.rows(); // number of tracks - + for (int i = 0; i < nt; i++) { int sector = bank.getInt("sector", i); int layer = bank.getInt("layer", i); @@ -258,8 +382,7 @@ public static void main(String[] args) { int tot = bank.getInt("ToT", i); AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); System.out.print(hit.getX() + "\n"); - } + } } } } - diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 0317d17d13..5365b3255d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -7,6 +7,10 @@ import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; import java.util.ArrayList; +import java.util.List; +import org.jlab.geom.prim.Point3D; +import org.jlab.rec.atof.TrackMatch.TrackProjection; +import org.jlab.rec.atof.TrackMatch.TrackProjector; /** * @@ -19,6 +23,7 @@ public class BarHit { private double x,y,z, time, energy; int sector, layer; private boolean is_in_a_cluster; + private double path_length; public AtofHit getHitUp() { return hit_up; @@ -114,11 +119,42 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } + public double getpath_length() { + return path_length; + } + + public void setpath_length(double path_length) { + this.path_length = path_length; + } + public double getPhi() { return Math.atan2(this.y, this.x); } + public int compute_module_index(){ + //Index ranging 0 to 60 for each wedge+bar module + return 4*this.sector + this.layer; + } + + public void MatchTrack(TrackProjector track_projector) + { + double sigma_phi = 10; + double sigma_z = 10; + List Projections = track_projector.getProjections(); + for(int i_track = 0; i_track < Projections.size(); i_track++) + { + Point3D projection_point = Projections.get(i_track).get_BarIntersect(); + if(Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) + { + if(Math.abs(this.getZ() - projection_point.z()) < sigma_z) + { + this.setpath_length(Projections.get(i_track).get_BarPathLength()); + } + } + } + } + public BarHit(AtofHit hit_down, AtofHit hit_up) { boolean hits_match = hit_down.barmatch(hit_up); From bddc2c09ceed9ef1662d19d426735860ba3cc71f Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:43:19 -0600 Subject: [PATCH 44/82] Hits sorted by energy --- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index eb0e55caa3..345a0afa1e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -1,12 +1,17 @@ package org.jlab.rec.atof.Hit; +import cnuphys.magfield.MagneticFields; import java.util.ArrayList; +import java.util.Collections; +import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.utils.CLASResources; /** * * @author npilleux @@ -40,42 +45,62 @@ public void setWedgeHits(ArrayList wedge_hits) { this.wedge_hits = wedge_hits; } - public void FindHits(DataEvent event, Detector atof) { + public void FindHits(DataEvent event, Detector atof, TrackProjector track_projector) { + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank DataBank bank = event.getBank("ATOF::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.getInt("sector", i); int layer = bank.getInt("layer", i); int component = bank.getInt("component", i); int order = bank.getInt("order", i); int tdc = bank.getInt("TDC", i); int tot = bank.getInt("ToT", i); + //Building a Hit AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if(hit.getEnergy() < 0.1 )continue; //energy threshold + //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed 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); - case "wedge" -> this.wedge_hits.add(hit); + case "wedge" -> {hit.MatchTrack(track_projector); this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); } @@ -83,24 +108,49 @@ else switch (hit.getType()) { * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here + + //Building ALERT geometry AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + double B = Math.abs(b[2]); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(B); + + //Hit finder init + HitFinder hitfinder = new HitFinder(); //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - - HitFinder hitfinder = new HitFinder(); int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); + event_number++; - hitfinder.FindHits(event, atof); + + projector.ProjectTracks(event); + hitfinder.FindHits(event, atof, projector); } + + System.out.print("Read " + event_number + " events"); } } \ No newline at end of file From 41f0648ffa40c0622513df99680d963e3435e42b Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:44:10 -0600 Subject: [PATCH 45/82] Some more clustering algo, resolutions need to be set --- .../jlab/rec/atof/Cluster/ClusterFinder.java | 230 +++++++++++++----- 1 file changed, 163 insertions(+), 67 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 22ae7ecf93..9830e4615b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -1,6 +1,8 @@ package org.jlab.rec.atof.Cluster; +import cnuphys.magfield.MagneticFields; import java.util.ArrayList; +import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -9,6 +11,8 @@ import org.jlab.rec.atof.Hit.AtofHit; import org.jlab.rec.atof.Hit.BarHit; import org.jlab.rec.atof.Hit.HitFinder; +import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.utils.CLASResources; /** * @@ -18,91 +22,165 @@ public class ClusterFinder { private ArrayList clusters; + public void setClusters(ArrayList clusters) { + this.clusters = clusters; + } + + public ArrayList getClusters() { + return clusters; + } + public void MakeClusters(HitFinder hitfinder) { + //A list of clusters is built for each event + clusters.clear(); + + //Getting the list of hits, they must have been ordered by energy already ArrayList wedge_hits = hitfinder.getWedgeHits(); ArrayList bar_hits = hitfinder.getBarHits(); - + double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future - double sigma_Z = 2.0;//wedge length. to be read from DB in the future - double sigma_T = 10;//timing resolution to be read from DB in the future - - - for(int i_wedge = 0; i_wedge this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); + //Indicate that this hit now is in a cluster this_wedge_hit.setIs_in_a_cluster(true); + //And store it this_cluster_wedge_hits.add(this_wedge_hit); - - - //Check if other wedge hits should be clustered - for(int j_wedge = 0; j_wedge 30) { + delta_module = 60 - delta_module; + } + int delta_component = Math.abs(this_wedge_hit.getComponent() - other_wedge_hit.getComponent()); + //Later we could use z and phi threshold + //double delta_Phi = Math.abs(this_wedge_hit.getPhi() - other_wedge_hit.getPhi()); + //double delta_Z = Math.abs(this_wedge_hit.getZ() - other_wedge_hit.getZ()); + //Time matching + double delta_T = Math.abs(this_wedge_hit.getTime() - other_wedge_hit.getTime()); + + if (delta_module <= sigma_module)//delta_Phi <= sigma_Phi) + { + if (delta_component <= sigma_component)//delta_Z <= sigma_Z) + { + if (delta_T < sigma_T) { + other_wedge_hit.setIs_in_a_cluster(true); + this_cluster_wedge_hits.add(other_wedge_hit); } - } - - //Check if bar hits should be clustered - for(int j_bar = 0; j_bar 30) { + delta_module = 60 - delta_module; + } + //Later we could use phi threshold + //double delta_Phi = Math.abs(this_wedge_hit.getPhi() - other_wedge_hit.getPhi()); + double delta_Z = Math.abs(this_wedge_hit.getZ() - other_bar_hit.getZ()); + //Time matching + double delta_T = Math.abs(this_wedge_hit.getTime() - other_bar_hit.getTime()); + if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) + { + if (delta_Z < sigma_Z) { + if (delta_T < sigma_T) { + other_bar_hit.setIs_in_a_cluster(true); + this_cluster_bar_hits.add(other_bar_hit); } - } + } + } + }//End loop bar hits + //After all wedge and bar hits have been grouped, build the cluster AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); + //And add it to the list of clusters clusters.add(cluster); - } + }//End loop on all wedge hits - for(int i_bar = 0; i_bar this_cluster_wedge_hits = new ArrayList(); ArrayList this_cluster_bar_hits = new ArrayList(); + this_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(this_bar_hit); + + //Loop through less energetic clusters + for (int j_bar = i_bar + 1; j_bar < bar_hits.size(); j_bar++) { + BarHit other_bar_hit = bar_hits.get(j_bar); + //Skip already clustered hits + if (other_bar_hit.getIs_in_a_cluster()) { + continue; + } + + //Check the distance between the hits + //For now we use phi module difference from what is observed in simu + int delta_module = Math.abs(this_bar_hit.compute_module_index() - other_bar_hit.compute_module_index()); + if (delta_module > 30) { + delta_module = 60 - delta_module; + } + //Later we could use phi threshold + //double delta_Phi = Math.abs(this_wedge_hit.getPhi() - other_wedge_hit.getPhi()); + double delta_Z = Math.abs(this_bar_hit.getZ() - other_bar_hit.getZ()); + //Time matching + double delta_T = Math.abs(this_bar_hit.getTime() - other_bar_hit.getTime()); + + if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) + { + if (delta_Z < sigma_Z) { + if (delta_T < sigma_T) { + other_bar_hit.setIs_in_a_cluster(true); + this_cluster_bar_hits.add(other_bar_hit); + } + } + } + } AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } } - - public ClusterFinder() - { - clusters = new ArrayList(); - } - + + public ClusterFinder() { + clusters = new ArrayList(); + } + /** * @param args the command line arguments */ @@ -111,23 +189,41 @@ public static void main(String[] args) { AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); - + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + double B = Math.abs(b[2]); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(B); + //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - + HitFinder hitfinder = new HitFinder(); int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); event_number++; - hitfinder.FindHits(event, atof); + projector.ProjectTracks(event); + hitfinder.FindHits(event, atof, projector); ClusterFinder clusterfinder = new ClusterFinder(); clusterfinder.MakeClusters(hitfinder); - } } - + } From 88ffc5fd996d77d50a44c6e75723cd1c56bfa31a Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 14:44:36 -0600 Subject: [PATCH 46/82] Track projection bank def --- etc/bankdefs/hipo4/alert.json | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index 7c125eb9cc..f7cf6b16a3 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -1,5 +1,45 @@ [ { + "name": "AHDC::Projections", + "group": 23000, + "item": 31, + "info": "Track Projections to ATOF", + "entries": [ + { + "name": "x_at_bar", + "type": "F", + "info": "x position at atof bar in mm" + }, { + "name": "y_at_bar", + "type": "F", + "info": "y position at atof bar in mm" + }, { + "name": "z_at_bar", + "type": "F", + "info": "z position at atof bar in mm" + },{ + "name": "L_at_bar", + "type": "F", + "info": "path length at atof bar in mm" + },{ + "name": "x_at_wedge", + "type": "F", + "info": "x position at atof wedge in mm" + }, { + "name": "y_at_wedge", + "type": "F", + "info": "y position at atof wedge in mm" + }, { + "name": "z_at_wedge", + "type": "F", + "info": "z position at atof wedge in mm" + },{ + "name": "L_at_wedge", + "type": "F", + "info": "path length at atof wedge in mm" + } + ] + },{ "name": "AHDC::Hits", "group": 23000, "item": 23, From e6d874f6f99d155602dbab024385a432d89315b4 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 16:21:51 -0600 Subject: [PATCH 47/82] Track projection to the middle of elements --- etc/bankdefs/hipo4/alert.json | 8 ++ .../rec/atof/TrackMatch/TrackProjection.java | 86 +++++++++++++++---- .../rec/atof/TrackMatch/TrackProjector.java | 34 +++++--- 3 files changed, 99 insertions(+), 29 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index f7cf6b16a3..c614e9218d 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -21,6 +21,10 @@ "name": "L_at_bar", "type": "F", "info": "path length at atof bar in mm" + },{ + "name": "L_in_bar", + "type": "F", + "info": "path length inside atof bar in mm" },{ "name": "x_at_wedge", "type": "F", @@ -37,6 +41,10 @@ "name": "L_at_wedge", "type": "F", "info": "path length at atof wedge in mm" + },{ + "name": "L_in_wedge", + "type": "F", + "info": "path length inside atof wedge in mm" } ] },{ diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index 9ccbbe26dd..cae3e33f63 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -4,33 +4,44 @@ /** * The {@code TrackProjection} class holds ahdc track information relevant for atof analysis - * i.e projected to the inner surfaces of the bar and wedges + * i.e projected to the middle surfaces of the bar and wedges * @author pilleux */ public class TrackProjection { /** - * Intersection point of the track with the inner surface of the bar. + * Intersection point of the track with the middle surface of the bar. */ private Point3D _BarIntersect = new Point3D(); /** - * Intersection point of the track with the inner surface of the wedges. + * Intersection point of the track with the middle surface of the wedges. */ private Point3D _WedgeIntersect = new Point3D(); /** * Path length of the track from the DOCA to the beam line - * to the inner surface of the bar. + * to the middle surface of the bar. */ Float _BarPathLength; /** * Path length of the track from the DOCA to the beam line - * to the inner surface of the wedges. + * to the middle surface of the wedges. */ Float _WedgePathLength; + + /** + * Path length inside the bar. + */ + Float _BarInPathLength; + + /** + * Path length inside the wedge. + */ + Float _WedgeInPathLength; + /** * Default constructor that initializes the intersection points and path lengths to {@code NaN}. @@ -40,10 +51,12 @@ public TrackProjection() { _WedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); _BarPathLength = Float.NaN; _WedgePathLength = Float.NaN; + _BarInPathLength = Float.NaN; + _WedgeInPathLength = Float.NaN; } /** - * Gets the intersection point of the track with the inner surface of the bar. + * Gets the intersection point of the track with the middle surface of the bar. * * @return {@link Point3D} bar's intersection point. */ @@ -52,7 +65,7 @@ public Point3D get_BarIntersect() { } /** - * Gets the intersection point of the track with the inner surface of the wedges. + * Gets the intersection point of the track with the middle surface of the wedges. * * @return {@link Point3D} wedge's intersection point. */ @@ -61,25 +74,45 @@ public Point3D get_WedgeIntersect() { } /** - * Gets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * Gets the path length of the track from the DOCA to the beam line to the middle surface of the bar. * - * @return {@code Float} path length to the bar's inner surface. + * @return {@code Float} path length to the bar's middle surface. */ public Float get_BarPathLength() { return _BarPathLength; } + + /** + * Gets the path length of the track from the the middle surface of the bar + * to its middle surface. + * + * @return {@code Float} path length inside the bar. + */ + public Float get_BarInPathLength() { + return _BarInPathLength; + } /** - * Gets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * Gets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. * - * @return {@code Float} path length to the wedge's inner surface. + * @return {@code Float} path length to the wedge's middle surface. */ public Float get_WedgePathLength() { return _WedgePathLength; } + + /** + * Gets the path length of the track from the the inner surface of the wedge + * to its middle surface. + * + * @return {@code Float} path length inside the wedge. + */ + public Float get_WedgeInPathLength() { + return _WedgeInPathLength; + } /** - * Sets the intersection point of the track with the inner surface of the bar. + * Sets the intersection point of the track with the middle surface of the bar. * * @param BarIntersect {@link Point3D} intersection with the bar. */ @@ -88,7 +121,7 @@ public void set_BarIntersect(Point3D BarIntersect) { } /** - * Sets the intersection point of the track with the inner surface of the wedges. + * Sets the intersection point of the track with the middle surface of the wedges. * * @param WedgeIntersect {@link Point3D} intersection with the wedge. */ @@ -97,22 +130,41 @@ public void set_WedgeIntersect(Point3D WedgeIntersect) { } /** - * Sets the path length of the track from the DOCA to the beam line to the inner surface of the bar. + * Sets the path length of the track from the DOCA to the beam line to the middle surface of the bar. * - * @param BarPathLength {@code Float} path length to the bar inner surface. + * @param BarPathLength {@code Float} path length to the bar middle surface. */ public void set_BarPathLength(Float BarPathLength) { this._BarPathLength = BarPathLength; } /** - * Sets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. + * Sets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. * - * @param WedgePathLength {@code Float} path length to the wedge inner surface. + * @param WedgePathLength {@code Float} path length to the wedge middle surface. */ public void set_WedgePathLength(Float WedgePathLength) { this._WedgePathLength = WedgePathLength; } + + /** + * Sets the path length of the track inside the bar. + * + * @param BarInPathLength {@code Float} path length inside the bar. + */ + public void set_BarInPathLength(Float BarInPathLength) { + this._BarInPathLength = BarInPathLength; + } + + /** + * Sets the path length of the track inside the wedges. + * + * @param WedgeInPathLength {@code Float} path length inside the wedge. + */ + public void set_WedgeInPathLength(Float WedgeInPathLength) { + this._WedgeInPathLength = WedgeInPathLength; + } + /** * testing purposes. diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index feb790fd28..652bbfa0c1 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -95,20 +95,23 @@ public void setB(Double B) { public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { Projections.clear(); - + //All of these are in MM double bar_innerradius = 77; //NEEDS TO BE REPLACED WITH DB CONSTANTS something like ccdb.INNERRADIUS[0] double wedge_innerradius = 80; - + double bar_thickness = 3; + double wedge_thickness = 20; + double bar_middle_radius = bar_innerradius + bar_thickness/2; + double wedge_middle_radius = wedge_innerradius + wedge_thickness/2; + String track_bank_name = "AHDC::Track"; if (event == null) { // check if there is an event - //System.out.print(" no event"); + //System.out.print(" no event \n"); } else if (event.hasBank(track_bank_name) == false) { // check if there are ahdc tracks in the event - //System.out.print("no tracks"); + //System.out.print("no tracks \n"); } else { DataBank bank = event.getBank(track_bank_name); - int nt = bank.rows(); // number of tracks TrackProjection projection = new TrackProjection(); DataBank outputBank = event.createBank("AHDC::Projections", nt); @@ -131,11 +134,17 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); - projection.set_BarIntersect(helix.getHelixPointAtR(bar_innerradius)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_innerradius)); + //Intersection points with the middle of the bar or wedge + projection.set_BarIntersect(helix.getHelixPointAtR(bar_middle_radius)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_middle_radius)); - projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); - projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); + //Path length to the middle of the bar or wedge + projection.set_BarPathLength((float) helix.getLAtR(bar_middle_radius)); + projection.set_WedgePathLength((float) helix.getLAtR(wedge_middle_radius)); + + //Path length from the inner radius to the middle radius + projection.set_BarInPathLength(projection.get_BarPathLength() - (float) helix.getLAtR(bar_innerradius)); + projection.set_WedgeInPathLength(projection.get_WedgePathLength() - (float) helix.getLAtR(wedge_innerradius)); Projections.add(projection); fill_out_bank(outputBank, projection, i); @@ -149,10 +158,12 @@ public static void fill_out_bank(DataBank outputBank, TrackProjection projection outputBank.setFloat("y_at_bar", i, (float) projection.get_BarIntersect().y()); outputBank.setFloat("z_at_bar", i, (float) projection.get_BarIntersect().z()); outputBank.setFloat("L_at_bar", i, (float) projection.get_BarPathLength()); + outputBank.setFloat("L_in_bar", i, (float) projection.get_BarInPathLength()); outputBank.setFloat("x_at_wedge", i, (float) projection.get_WedgeIntersect().x()); outputBank.setFloat("y_at_wedge", i, (float) projection.get_WedgeIntersect().y()); outputBank.setFloat("z_at_wedge", i, (float) projection.get_WedgeIntersect().z()); outputBank.setFloat("L_at_wedge", i, (float) projection.get_WedgePathLength()); + outputBank.setFloat("L_in_wedge", i, (float) projection.get_WedgeInPathLength()); } public static void main(String arg[]) { @@ -178,17 +189,16 @@ public static void main(String arg[]) { projector.setB(B); //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/test_updated_2.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); event_number++; projector.ProjectTracks(event); - //event.getBank("AHDC::Projections").show(); + event.getBank("AHDC::Projections").show(); } System.out.print("Read " + event_number + " events"); From 0596da4638df8b49c8ba00f638954119a8a0db3f Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 15 Jan 2025 16:35:04 -0600 Subject: [PATCH 48/82] Track projection surfaces redefinition --- etc/bankdefs/hipo4/alert.json | 16 +++++++-------- .../rec/atof/TrackMatch/TrackProjection.java | 20 +++++++++---------- .../rec/atof/TrackMatch/TrackProjector.java | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index c614e9218d..e616780db4 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -8,19 +8,19 @@ { "name": "x_at_bar", "type": "F", - "info": "x position at atof bar in mm" + "info": "x position at atof bar (middle surface) in mm" }, { "name": "y_at_bar", "type": "F", - "info": "y position at atof bar in mm" + "info": "y position at atof bar (middle surface) in mm" }, { "name": "z_at_bar", "type": "F", - "info": "z position at atof bar in mm" + "info": "z position at atof bar (middle surface) in mm" },{ "name": "L_at_bar", "type": "F", - "info": "path length at atof bar in mm" + "info": "path length at atof bar (inner surface) in mm" },{ "name": "L_in_bar", "type": "F", @@ -28,19 +28,19 @@ },{ "name": "x_at_wedge", "type": "F", - "info": "x position at atof wedge in mm" + "info": "x position at atof wedge (middle surface) in mm" }, { "name": "y_at_wedge", "type": "F", - "info": "y position at atof wedge in mm" + "info": "y position at atof wedge (middle surface) in mm" }, { "name": "z_at_wedge", "type": "F", - "info": "z position at atof wedge in mm" + "info": "z position at atof wedge (middle surface) in mm" },{ "name": "L_at_wedge", "type": "F", - "info": "path length at atof wedge in mm" + "info": "path length at atof wedge (inner surface) in mm" },{ "name": "L_in_wedge", "type": "F", diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index cae3e33f63..aaec5d3b64 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -4,7 +4,7 @@ /** * The {@code TrackProjection} class holds ahdc track information relevant for atof analysis - * i.e projected to the middle surfaces of the bar and wedges + * i.e projected to the surfaces of the bar and wedges * @author pilleux */ @@ -22,13 +22,13 @@ public class TrackProjection { /** * Path length of the track from the DOCA to the beam line - * to the middle surface of the bar. + * to the entrance surface of the bar. */ Float _BarPathLength; /** * Path length of the track from the DOCA to the beam line - * to the middle surface of the wedges. + * to the entrance surface of the wedges. */ Float _WedgePathLength; @@ -74,7 +74,7 @@ public Point3D get_WedgeIntersect() { } /** - * Gets the path length of the track from the DOCA to the beam line to the middle surface of the bar. + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the bar. * * @return {@code Float} path length to the bar's middle surface. */ @@ -83,7 +83,7 @@ public Float get_BarPathLength() { } /** - * Gets the path length of the track from the the middle surface of the bar + * Gets the path length of the track from the inner surface of the bar * to its middle surface. * * @return {@code Float} path length inside the bar. @@ -93,7 +93,7 @@ public Float get_BarInPathLength() { } /** - * Gets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. + * Gets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. * * @return {@code Float} path length to the wedge's middle surface. */ @@ -130,18 +130,18 @@ public void set_WedgeIntersect(Point3D WedgeIntersect) { } /** - * Sets the path length of the track from the DOCA to the beam line to the middle surface of the bar. + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the bar. * - * @param BarPathLength {@code Float} path length to the bar middle surface. + * @param BarPathLength {@code Float} path length to the bar inner surface. */ public void set_BarPathLength(Float BarPathLength) { this._BarPathLength = BarPathLength; } /** - * Sets the path length of the track from the DOCA to the beam line to the middle surface of the wedges. + * Sets the path length of the track from the DOCA to the beam line to the inner surface of the wedges. * - * @param WedgePathLength {@code Float} path length to the wedge middle surface. + * @param WedgePathLength {@code Float} path length to the wedge inner surface. */ public void set_WedgePathLength(Float WedgePathLength) { this._WedgePathLength = WedgePathLength; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index 652bbfa0c1..bd0b111035 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -139,12 +139,12 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_middle_radius)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) helix.getLAtR(bar_middle_radius)); - projection.set_WedgePathLength((float) helix.getLAtR(wedge_middle_radius)); + projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); + projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength(projection.get_BarPathLength() - (float) helix.getLAtR(bar_innerradius)); - projection.set_WedgeInPathLength(projection.get_WedgePathLength() - (float) helix.getLAtR(wedge_innerradius)); + projection.set_BarInPathLength((float) helix.getLAtR(bar_middle_radius) - projection.get_BarPathLength()); + projection.set_WedgeInPathLength((float) helix.getLAtR(wedge_middle_radius) - projection.get_WedgePathLength()); Projections.add(projection); fill_out_bank(outputBank, projection, i); From e812ba5083db16fd7076a001909a47779a95fea4 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 16 Jan 2025 10:07:22 -0600 Subject: [PATCH 49/82] Some naming conventions --- .../jlab/rec/atof/Cluster/AtofCluster.java | 16 +-- .../jlab/rec/atof/Cluster/ClusterFinder.java | 16 +-- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 132 ++++++++++++------ .../java/org/jlab/rec/atof/Hit/BarHit.java | 20 +-- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 10 +- .../rec/atof/TrackMatch/TrackProjection.java | 2 +- .../rec/atof/TrackMatch/TrackProjector.java | 2 +- 7 files changed, 126 insertions(+), 72 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 102b61b6c3..76e441c7ed 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -1,8 +1,8 @@ -package org.jlab.rec.atof.Cluster; +package org.jlab.rec.atof.cluster; import java.util.ArrayList; -import org.jlab.rec.atof.Hit.AtofHit; -import org.jlab.rec.atof.Hit.BarHit; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; /** * @@ -71,17 +71,17 @@ public void setEnergy(double energy) { this.energy = energy; } - public double getpath_length() { + public double getPath_length() { return path_length; } - public void setpath_length(double path_length) { + public void setPath_length(double path_length) { this.path_length = path_length; } //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later - public void computeClusterProperties() { + public final void computeClusterProperties() { this.energy=0; double max_energy = -1; AtofHit max_energy_hit = new AtofHit(); @@ -109,7 +109,7 @@ public void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); - this.path_length = max_energy_hit.getpath_length(); + this.path_length = max_energy_hit.getPath_length(); } else { @@ -117,7 +117,7 @@ public void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); - this.path_length = max_energy_barhit.getpath_length(); + this.path_length = max_energy_barhit.getPath_length(); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 9830e4615b..b6f50b496c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.Cluster; +package org.jlab.rec.atof.cluster; import cnuphys.magfield.MagneticFields; import java.util.ArrayList; @@ -8,10 +8,10 @@ import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import org.jlab.rec.atof.Hit.AtofHit; -import org.jlab.rec.atof.Hit.BarHit; -import org.jlab.rec.atof.Hit.HitFinder; -import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.hit.HitFinder; +import org.jlab.rec.atof.trackMatch.TrackProjector; import org.jlab.utils.CLASResources; /** @@ -71,7 +71,7 @@ public void MakeClusters(HitFinder hitfinder) { } //Check the distance between the hits //For now we use phi module and z component differences from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.compute_module_index() - other_wedge_hit.compute_module_index()); + int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_wedge_hit.computeModule_index()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -103,7 +103,7 @@ public void MakeClusters(HitFinder hitfinder) { } //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.compute_module_index() - other_bar_hit.compute_module_index()); + int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_bar_hit.computeModule_index()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -152,7 +152,7 @@ public void MakeClusters(HitFinder hitfinder) { //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_bar_hit.compute_module_index() - other_bar_hit.compute_module_index()); + int delta_module = Math.abs(this_bar_hit.computeModule_index() - other_bar_hit.computeModule_index()); if (delta_module > 30) { delta_module = 60 - delta_module; } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 17ceecbef2..d5bbf0ae01 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.Hit; +package org.jlab.rec.atof.hit; import java.util.List; import org.jlab.geom.base.*; @@ -8,21 +8,18 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import org.jlab.rec.atof.TrackMatch.TrackProjection; -import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.rec.atof.trackMatch.TrackProjection; +import org.jlab.rec.atof.trackMatch.TrackProjector; /** - * - * Represents a hit in the atof. - * Stores info about the sector, layer, component, order, TDC, ToT. - * Type is wedge/bar up/bar down - * Spatial coordinates are computed from atof detector object using the geometry service - * Stores whether the hit is part of a cluster. - * Calculates time, energy based on TDC/ToT. - * + * + * Represents a hit in the atof. Stores info about the sector, layer, component, + * order, TDC, ToT. Type is wedge/bar up/bar down Spatial coordinates are + * computed from atof detector object using the geometry service Stores whether + * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. + * * @author npilleux */ - public class AtofHit { private int sector, layer, component, order; @@ -30,7 +27,7 @@ public class AtofHit { private double time, energy, x, y, z; private String type; private boolean is_in_a_cluster; - private double path_length; + private double path_length, inpath_length; public int getSector() { return sector; @@ -136,17 +133,25 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - public double getpath_length() { + public double getPath_length() { return path_length; } - public void setpath_length(double path_length) { + public void setPath_length(double path_length) { this.path_length = path_length; } - - public int compute_module_index(){ + + public double getInpath_length() { + return inpath_length; + } + + public void setInpath_length(double inpath_length) { + this.inpath_length = inpath_length; + } + + public int computeModule_index() { //Index ranging 0 to 60 for each wedge+bar module - return 4*this.sector + this.layer; + return 4 * this.sector + this.layer; } public final String makeType() { @@ -164,50 +169,65 @@ public final String makeType() { public final int TDC_to_time() { double some_conversion = 0; + double veff = 1; if (null == this.type) { return 1; } else { switch (this.type) { - case "wedge" -> + case "wedge" -> { + some_conversion = 10;//read calib constants here + veff = 1; + } + case "bar up" -> { + some_conversion = 10;//read calib constants here + veff = 1; + } + case "bar down" -> { some_conversion = 10;//read calib constants here - case "bar up" -> - some_conversion = 10; - case "bar down" -> - some_conversion = 10; + veff = 1; + } default -> { return 1; } } } - this.time = some_conversion * this.TDC; + //Time at the inner surface + this.time = some_conversion * this.TDC - this.inpath_length / veff; return 0; } public final int ToT_to_energy() { double some_conversion = 0; + double att_L = 1; if (null == this.type) { return 1; } else { switch (this.type) { - case "wedge" -> + case "wedge" -> { + some_conversion = 10;//read calib constants here + att_L = 10; + } + case "bar up" -> { + some_conversion = 10;//read calib constants here + att_L = 10; + } + case "bar down" -> { some_conversion = 10;//read calib constants here - case "bar up" -> - some_conversion = 10; - case "bar down" -> - some_conversion = 10; + att_L = 10; + } default -> { return 1; } } } - this.energy = some_conversion * this.ToT; + this.energy = some_conversion * this.ToT * Math.exp(this.inpath_length / att_L); return 0; } /** - * Calculates spatial coordinates for the hit based on associated - * detector component. Retrieves the midpoint of the atof component - * to assign the corresponding x, y, z coordinates to the hit. + * Calculates spatial coordinates for the hit based on associated detector + * component. Retrieves the midpoint of the atof component to assign the + * corresponding x, y, z coordinates to the hit. * * * @param atof The Detector object representing the atof. @@ -229,7 +249,6 @@ public final int slc_to_xyz(Detector atof) { } } } - Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); this.x = midpoint.x(); @@ -254,7 +273,7 @@ public final int slc_to_xyz(Detector atof) { * @param hit2match The AtofHit object to compare with the current instance. * @return {@code true} if the hits match; {@code false} otherwise. */ - public boolean barmatch(AtofHit hit2match) { + public boolean matchBar(AtofHit hit2match) { if (this.getSector() != hit2match.getSector()) { return false; //System.out.print("Two hits in different sectors \n"); } else if (this.getLayer() != hit2match.getLayer()) { @@ -285,7 +304,7 @@ public double getPhi() { * @param component The component within the layer that registered the hit. * @param order Order of the hit. * @param tdc TDC value. - * @param tot ToT velue. + * @param tot ToT value. * @param atof Detector object representing the atof, used to calculate * spatial coordinates. */ @@ -308,6 +327,41 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot } } + /** + * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * component, 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 layer The layer of the detector where the hit was detected. + * @param component The component within the layer that registered the hit. + * @param order Order of the hit. + * @param tdc TDC value. + * @param tot ToT value. + * @param atof Detector object representing the atof, used to calculate + * @param track_projector TrackProjector object with ahdc tracks to be + * matched to the hit. + */ + public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof, TrackProjector track_projector) { + this.sector = sector; + this.layer = layer; + this.component = component; + this.order = order; + this.TDC = tdc; + this.ToT = tot; + this.is_in_a_cluster = false; + + //First the type needs to be set + this.makeType(); + //From it the coordinates can be computed + this.slc_to_xyz(atof); + //From them tracks can be matched + this.matchTrack(track_projector); + //And energy and time can then be computed + this.ToT_to_energy(); + this.TDC_to_time(); + } + /** * Matches the current track with ahdc tracks projections. Calculates the * match by comparing the hit's azimuthal angle and longitudinal position @@ -318,7 +372,7 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * TrackProjections. * */ - public void MatchTrack(TrackProjector track_projector) { + public final void matchTrack(TrackProjector track_projector) { double sigma_phi = 10; double sigma_z = 10; List Projections = track_projector.getProjections(); @@ -340,9 +394,9 @@ public void MatchTrack(TrackProjector track_projector) { if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { - this.setpath_length(Projections.get(i_track).get_WedgePathLength()); + this.setPath_length(Projections.get(i_track).get_WedgePathLength()); } else { - this.setpath_length(Projections.get(i_track).get_BarPathLength()); + this.setPath_length(Projections.get(i_track).get_BarPathLength()); } } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 5365b3255d..8d2e0d5c96 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.Hit; +package org.jlab.rec.atof.hit; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; @@ -9,8 +9,8 @@ import java.util.ArrayList; import java.util.List; import org.jlab.geom.prim.Point3D; -import org.jlab.rec.atof.TrackMatch.TrackProjection; -import org.jlab.rec.atof.TrackMatch.TrackProjector; +import org.jlab.rec.atof.trackMatch.TrackProjection; +import org.jlab.rec.atof.trackMatch.TrackProjector; /** * @@ -119,11 +119,11 @@ public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - public double getpath_length() { + public double getPath_length() { return path_length; } - public void setpath_length(double path_length) { + public void setPath_length(double path_length) { this.path_length = path_length; } @@ -132,12 +132,12 @@ public double getPhi() return Math.atan2(this.y, this.x); } - public int compute_module_index(){ + public int computeModule_index(){ //Index ranging 0 to 60 for each wedge+bar module return 4*this.sector + this.layer; } - public void MatchTrack(TrackProjector track_projector) + public void matchTrack(TrackProjector track_projector) { double sigma_phi = 10; double sigma_z = 10; @@ -149,7 +149,7 @@ public void MatchTrack(TrackProjector track_projector) { if(Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - this.setpath_length(Projections.get(i_track).get_BarPathLength()); + this.setPath_length(Projections.get(i_track).get_BarPathLength()); } } } @@ -157,7 +157,7 @@ public void MatchTrack(TrackProjector track_projector) public BarHit(AtofHit hit_down, AtofHit hit_up) { - boolean hits_match = hit_down.barmatch(hit_up); + boolean hits_match = hit_down.matchBar(hit_up); if(!hits_match) throw new UnsupportedOperationException("Hits do not match \n"); this.hit_up = hit_up; @@ -221,7 +221,7 @@ else switch (hit.getType()) { for(int i_down=0; i_down hit_up.add(hit); case "bar down" -> hit_down.add(hit); - case "wedge" -> {hit.MatchTrack(track_projector); this.wedge_hits.add(hit);} + case "wedge" -> {hit.matchTrack(track_projector); this.wedge_hits.add(hit);} default -> System.out.print("Undefined hit type \n"); } }//End loop through all hits @@ -89,11 +89,11 @@ else switch (hit.getType()) { { AtofHit this_hit_down = hit_down.get(i_down); //Matching the hits: if same module and different order, they make up a bar hit - if(this_hit_up.barmatch(this_hit_down)) + if(this_hit_up.matchBar(this_hit_down)) { //Bar hits are matched to ahdc tracks and listed BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - this_bar_hit.MatchTrack(track_projector); + this_bar_hit.matchTrack(track_projector); this.bar_hits.add(this_bar_hit); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index aaec5d3b64..5138d15083 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.TrackMatch; +package org.jlab.rec.atof.trackMatch; import org.jlab.geom.prim.Point3D; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index bd0b111035..f8e2b3c8c0 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -1,4 +1,4 @@ -package org.jlab.rec.atof.TrackMatch; +package org.jlab.rec.atof.trackMatch; import java.util.ArrayList; import java.util.List; From 5a0500609a86a47f7c29a4a9829e26c5566932a6 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 09:44:52 -0600 Subject: [PATCH 50/82] Handling parameters + method for testing --- .../rec/atof/TrackMatch/TrackProjector.java | 88 +++++++++++++++---- .../jlab/rec/atof/constants/Parameters.java | 44 ++++++++++ 2 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index f8e2b3c8c0..cca125510c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -11,6 +11,7 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.utils.CLASResources; import cnuphys.magfield.MagneticFields; +import org.jlab.rec.atof.constants.Parameters; /** * The {@code TrackProjector} class projects ahdc tracks to the inner surfaces @@ -95,13 +96,6 @@ public void setB(Double B) { public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { Projections.clear(); - //All of these are in MM - double bar_innerradius = 77; //NEEDS TO BE REPLACED WITH DB CONSTANTS something like ccdb.INNERRADIUS[0] - double wedge_innerradius = 80; - double bar_thickness = 3; - double wedge_thickness = 20; - double bar_middle_radius = bar_innerradius + bar_thickness/2; - double wedge_middle_radius = wedge_innerradius + wedge_thickness/2; String track_bank_name = "AHDC::Track"; @@ -125,27 +119,91 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) double py = bank.getFloat("py", i); double pz = bank.getFloat("pz", i); - int q = 1; //this has to be changed, we need the charge info from tracking + int q = 1; //need the charge sign from tracking Units units = Units.MM; //can be MM or CM. double xb = 0; double yb = 0; - Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + //momenta must be in GeV for the helix class + Helix helix = new Helix(x, y, z, px/1000., py/1000., pz/1000., q, B, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(bar_middle_radius)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(wedge_middle_radius)); + projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) helix.getLAtR(bar_innerradius)); - projection.set_WedgePathLength((float) helix.getLAtR(wedge_innerradius)); + projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) helix.getLAtR(bar_middle_radius) - projection.get_BarPathLength()); - projection.set_WedgeInPathLength((float) helix.getLAtR(wedge_middle_radius) - projection.get_WedgePathLength()); + projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); + projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); + Projections.add(projection); + fill_out_bank(outputBank, projection, i); + } + event.appendBank(outputBank); + } + } + + /** + * Projects the MC particles onto the atof using a {@link Helix} + * model. + * + * @param event the {@link DataEvent} containing track data to be projected. + */ + public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { + + Projections.clear(); + + String track_bank_name = "MC::Particle"; + if (event == null) { // check if there is an event + //System.out.print(" no event \n"); + } else if (event.hasBank(track_bank_name) == false) { + // check if there are ahdc tracks in the event + //System.out.print("no tracks \n"); + } else { + DataBank bank = event.getBank(track_bank_name); + int nt = bank.rows(); // number of tracks + TrackProjection projection = new TrackProjection(); + DataBank outputBank = event.createBank("AHDC::Projections", nt); + + for (int i = 0; i < nt; i++) { + + double x = bank.getFloat("vx", i); + double y = bank.getFloat("vy", i); + double z = bank.getFloat("vz", i); + double px = bank.getFloat("px", i); + double py = bank.getFloat("py", i); + double pz = bank.getFloat("pz", i); + + //Put everything in MM + x = x*10; + y = y*10; + z = z*10; + Units units = Units.MM; + + int q = 1; //need the charge sign from tracking + + double xb = 0; + double yb = 0; + + //momenta must be in GeV for the helix class + Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + + //Intersection points with the middle of the bar or wedge + projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); + + //Path length to the middle of the bar or wedge + projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); + + //Path length from the inner radius to the middle radius + projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); + projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); Projections.add(projection); fill_out_bank(outputBank, projection, i); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java new file mode 100644 index 0000000000..d76a38d9e2 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -0,0 +1,44 @@ +package org.jlab.rec.atof.constants; + +/** + * + * @author npilleux + */ +public class Parameters { + + Parameters() { + } + + //In millimiters + public static final double BAR_INNER_RADIUS = 77; + public static final double WEDGE_INNER_RADIUS = 80; + public static final double BAR_THICKNESS = 3; + public static final double WEDGE_THICKNESS = 20; + public static final double BAR_MIDDLE_RADIUS = BAR_INNER_RADIUS + BAR_THICKNESS / 2; + public static final double WEDGE_MIDDLE_RADIUS = WEDGE_INNER_RADIUS + WEDGE_THICKNESS / 2; + + + public static final double VEFF = 200.0;//mm/ns + public static final double TDC2TIME = 0.015625;//ns per channel bin + public static final double ATT_L = 1600.0;//mm + public static final double TOT2ENERGY_BAR = 1.956 * 0.3;//MeV? To be checked. + public static final double TOT2ENERGY_WEDGE = 1.956 * 2.0;//MeV? To be checked. + + public static double LENGTH_ATOF = 279.7; //detector length in mm + + public static double SIGMA_PHI_TRACK_MATCHING_BAR = 180 * Math.PI/180.;//in rad + public static double SIGMA_PHI_TRACK_MATCHING_WEDGE = 180 * Math.PI/180.;//in rad + + public static double SIGMA_Z_TRACK_MATCHING_BAR = 150;//in mm + public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 150;//in mm + + public static double SIGMA_PHI_CLUSTERING = 6;//in deg + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + } + +} From f0a181744d6c6e488957b71b751a278a6835cfb6 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 09:48:20 -0600 Subject: [PATCH 51/82] Handling parameters + bank input --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 107 ++++++++--- .../java/org/jlab/rec/atof/Hit/BarHit.java | 170 ++++++++++-------- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 59 ++++++ 3 files changed, 233 insertions(+), 103 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index d5bbf0ae01..ef5889f8ef 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -8,6 +8,7 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.trackMatch.TrackProjection; import org.jlab.rec.atof.trackMatch.TrackProjector; @@ -168,23 +169,23 @@ public final String makeType() { } public final int TDC_to_time() { - double some_conversion = 0; + double tdc2time = 1; double veff = 1; if (null == this.type) { return 1; } else { switch (this.type) { case "wedge" -> { - some_conversion = 10;//read calib constants here - veff = 1; + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; } case "bar up" -> { - some_conversion = 10;//read calib constants here - veff = 1; + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; } case "bar down" -> { - some_conversion = 10;//read calib constants here - veff = 1; + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; } default -> { return 1; @@ -192,35 +193,35 @@ public final int TDC_to_time() { } } //Time at the inner surface - this.time = some_conversion * this.TDC - this.inpath_length / veff; + this.time = tdc2time * this.TDC - this.inpath_length / veff; return 0; } public final int ToT_to_energy() { - double some_conversion = 0; + double tot2energy = 1; double att_L = 1; if (null == this.type) { return 1; } else { switch (this.type) { case "wedge" -> { - some_conversion = 10;//read calib constants here - att_L = 10; + tot2energy = Parameters.TOT2ENERGY_WEDGE; + att_L = Parameters.ATT_L; } case "bar up" -> { - some_conversion = 10;//read calib constants here - att_L = 10; + tot2energy = Parameters.TOT2ENERGY_WEDGE; + att_L = Parameters.ATT_L; } case "bar down" -> { - some_conversion = 10;//read calib constants here - att_L = 10; + tot2energy = Parameters.TOT2ENERGY_BAR; + att_L = Parameters.ATT_L; } default -> { return 1; } } } - this.energy = some_conversion * this.ToT * Math.exp(this.inpath_length / att_L); + this.energy = tot2energy * this.ToT * Math.exp(this.inpath_length / att_L); return 0; } @@ -251,9 +252,11 @@ public final int slc_to_xyz(Detector atof) { } Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); - this.x = midpoint.x(); - this.y = midpoint.y(); - this.z = midpoint.z(); + + //coordinates centered at the center of the atof in mm + this.x = midpoint.x() - Parameters.LENGTH_ATOF / 2.; + this.y = midpoint.y() - Parameters.LENGTH_ATOF / 2.; + this.z = midpoint.z() - Parameters.LENGTH_ATOF / 2.; return 0; } @@ -373,24 +376,31 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * */ public final void matchTrack(TrackProjector track_projector) { - double sigma_phi = 10; - double sigma_z = 10; + double sigma_phi = 0; + double sigma_z = 0; + List Projections = track_projector.getProjections(); for (int i_track = 0; i_track < Projections.size(); i_track++) { Point3D projection_point = new Point3D(); if (null == this.getType()) { - System.out.print("Impossible to match track and hitm hit type is undefined \n"); + System.out.print("Impossible to match track and hit; hit type is null \n"); } else { switch (this.getType()) { - case "wedge" -> + case "wedge" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; projection_point = Projections.get(i_track).get_WedgeIntersect(); - case "bar up", "bar down" -> + } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; projection_point = Projections.get(i_track).get_BarIntersect(); + } default -> - System.out.print("Impossible to match track and hitm hit type is undefined \n"); + System.out.print("Impossible to match track and hit; hit type is undefined \n"); } } - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { @@ -403,6 +413,51 @@ public final void matchTrack(TrackProjector track_projector) { } } + public void matchTrack(DataBank track_bank) { + int nt = track_bank.rows(); // number of tracks + double sigma_phi = 0; + double sigma_z = 0; + + //Looping through all tracks + for (int i = 0; i < nt; i++) { + + Float xt = null,yt = null,zt=null,path = null; + + if (null == this.getType()) { + System.out.print("Impossible to match track and hit; hit type is null \n"); + } else { + switch (this.getType()) { + case "wedge" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; + xt = track_bank.getFloat("x_at_wedge", i); + yt = track_bank.getFloat("y_at_wedge", i); + zt = track_bank.getFloat("z_at_wedge", i); + path = track_bank.getFloat("L_at_wedge", i); + } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; + xt = track_bank.getFloat("x_at_bar", i); + yt = track_bank.getFloat("y_at_bar", i); + zt = track_bank.getFloat("z_at_bar", i); + path = track_bank.getFloat("L_at_bar", i); + } + default -> + System.out.print("Impossible to match track and hit; hit type is undefined \n"); + } + } + Point3D projection_point = new Point3D(xt, yt, zt); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { + if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { + this.setPath_length(path); + } + } + } + + } + public AtofHit() { } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 8d2e0d5c96..9c1428cbae 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; import org.jlab.geom.prim.Point3D; +import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.trackMatch.TrackProjection; import org.jlab.rec.atof.trackMatch.TrackProjector; @@ -17,14 +18,14 @@ * @author npilleux */ public class BarHit { - + //A bar hit is the combination of a downstream and upstream hits private AtofHit hit_up, hit_down; - private double x,y,z, time, energy; + private double x, y, z, time, energy; int sector, layer; private boolean is_in_a_cluster; private double path_length; - + public AtofHit getHitUp() { return hit_up; } @@ -64,18 +65,18 @@ public double getZ() { public void setZ(double z) { this.z = z; } - - public void computeZ() { + + public final void computeZ() { double some_calibration = 10; //Here read the calibration DB this.z = some_calibration * (hit_up.getTime() - hit_down.getTime()); } - - public void computeTime() { + + public final void computeTime() { double some_calibration = 10; //Here read the calibration DB - this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime())/2.); + this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.); } - - public void computeEnergy() { + + public final void computeEnergy() { this.energy = (hit_up.getEnergy() + hit_down.getEnergy()); } @@ -110,7 +111,7 @@ public int getLayer() { public void setLayer(int layer) { this.layer = layer; } - + public boolean getIs_in_a_cluster() { return is_in_a_cluster; } @@ -118,7 +119,7 @@ public boolean getIs_in_a_cluster() { public void setIs_in_a_cluster(boolean is_in_a_cluster) { this.is_in_a_cluster = is_in_a_cluster; } - + public double getPath_length() { return path_length; } @@ -126,64 +127,75 @@ public double getPath_length() { public void setPath_length(double path_length) { this.path_length = path_length; } - - public double getPhi() - { + + public double getPhi() { return Math.atan2(this.y, this.x); } - - public int computeModule_index(){ + + public int computeModule_index() { //Index ranging 0 to 60 for each wedge+bar module - return 4*this.sector + this.layer; + return 4 * this.sector + this.layer; } - - public void matchTrack(TrackProjector track_projector) - { - double sigma_phi = 10; - double sigma_z = 10; + + public void matchTrack(TrackProjector track_projector) { List Projections = track_projector.getProjections(); - for(int i_track = 0; i_track < Projections.size(); i_track++) - { - Point3D projection_point = Projections.get(i_track).get_BarIntersect(); - if(Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) - { - if(Math.abs(this.getZ() - projection_point.z()) < sigma_z) - { - this.setPath_length(Projections.get(i_track).get_BarPathLength()); - } - } + for (int i_track = 0; i_track < Projections.size(); i_track++) { + Point3D projection_point = Projections.get(i_track).get_BarIntersect(); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { + if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { + this.setPath_length(Projections.get(i_track).get_BarPathLength()); + } } } - - public BarHit(AtofHit hit_down, AtofHit hit_up) - { - boolean hits_match = hit_down.matchBar(hit_up); - if(!hits_match) throw new UnsupportedOperationException("Hits do not match \n"); - - this.hit_up = hit_up; - this.hit_down = hit_down; - this.layer = hit_up.getLayer(); - this.sector = hit_up.getSector(); - this.x = hit_up.getX(); - this.y = hit_up.getY(); - this.computeZ(); - this.computeTime(); - this.computeEnergy(); - } - - public BarHit() - { - } - + } + + public void matchTrack(DataBank track_bank) { + int nt = track_bank.rows(); // number of tracks + //Looping through all tracks + for (int i = 0; i < nt; i++) { + //Getting their properties + Float xt = track_bank.getFloat("x_at_bar", i); + Float yt = track_bank.getFloat("y_at_bar", i); + Float zt = track_bank.getFloat("z_at_bar", i); + Float path = track_bank.getFloat("L_at_bar", i); + Point3D projection_point = new Point3D(xt, yt, zt); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { + if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { + this.setPath_length(path); + } + } + } + } + + public BarHit(AtofHit hit_down, AtofHit hit_up) { + boolean hits_match = hit_down.matchBar(hit_up); + if (!hits_match) { + throw new UnsupportedOperationException("Hits do not match \n"); + } + + this.hit_up = hit_up; + this.hit_down = hit_down; + this.layer = hit_up.getLayer(); + this.sector = hit_up.getSector(); + this.x = hit_up.getX(); + this.y = hit_up.getY(); + this.computeZ(); + this.computeTime(); + this.computeEnergy(); + } + + public BarHit() { + } + /** * @param args the command line arguments */ - public static void main(String[] args) { + public static void main(String[] args) { // TODO code application logic here AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); Detector atof = factory.createDetectorCLAS(cp); - + //Input to be read String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; HipoDataSource reader = new HipoDataSource(); @@ -195,9 +207,9 @@ public static void main(String[] args) { event_number++; DataBank bank = event.getBank("ATOF::tdc"); int nt = bank.rows(); // number of tracks - ArrayList hit_up = new ArrayList<>(); - ArrayList hit_down = new ArrayList<>(); - ArrayList hit_wedge = new ArrayList<>(); + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); + ArrayList hit_wedge = new ArrayList<>(); for (int i = 0; i < nt; i++) { int sector = bank.getInt("sector", i); int layer = bank.getInt("layer", i); @@ -206,28 +218,32 @@ public static void main(String[] args) { int tdc = bank.getInt("TDC", i); int tot = bank.getInt("ToT", i); AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - 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); - case "wedge" -> hit_wedge.add(hit); - default -> System.out.print("Undefined hit type \n"); + 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); + case "wedge" -> + hit_wedge.add(hit); + default -> + System.out.print("Undefined hit type \n"); + } } } - ArrayList bar_hits = new ArrayList(); - for(int i_up=0; i_up bar_hits = new ArrayList(); + for (int i_up = 0; i_up < hit_up.size(); i_up++) { AtofHit this_hit_up = hit_up.get(i_up); - for(int i_down=0; i_down Double.compare(hit1.getEnergy(), hit2.getEnergy())); } + public void FindHits(DataEvent event, Detector atof) { + + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank + DataBank bank_atof_hits = event.getBank("ATOF::tdc"); + DataBank bank_track = event.getBank("AHDC::Projection"); + int nt = bank_atof_hits.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_atof_hits.getInt("sector", i); + int layer = bank_atof_hits.getInt("layer", i); + int component = bank_atof_hits.getInt("component", i); + int order = bank_atof_hits.getInt("order", i); + int tdc = bank_atof_hits.getInt("TDC", i); + int tot = bank_atof_hits.getInt("ToT", i); + //Building a Hit + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if(hit.getEnergy() < 0.1 )continue; //energy threshold + //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed + 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); + case "wedge" -> {hit.matchTrack(bank_track); this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + } + /** * @param args the command line arguments From 8003196a38ee5cafe38685bbb1ad4e5ba7104600 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:11:19 -0600 Subject: [PATCH 52/82] Correcting conversion to MeV --- .../main/java/org/jlab/rec/atof/constants/Parameters.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java index d76a38d9e2..89c7cce60e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -21,16 +21,16 @@ public class Parameters { public static final double VEFF = 200.0;//mm/ns public static final double TDC2TIME = 0.015625;//ns per channel bin public static final double ATT_L = 1600.0;//mm - public static final double TOT2ENERGY_BAR = 1.956 * 0.3;//MeV? To be checked. - public static final double TOT2ENERGY_WEDGE = 1.956 * 2.0;//MeV? To be checked. + public static final double TOT2ENERGY_BAR = 1.956 * 0.3 /1000;//to MeV + public static final double TOT2ENERGY_WEDGE = 1.956 * 2.0 /1000;//to MeV public static double LENGTH_ATOF = 279.7; //detector length in mm public static double SIGMA_PHI_TRACK_MATCHING_BAR = 180 * Math.PI/180.;//in rad public static double SIGMA_PHI_TRACK_MATCHING_WEDGE = 180 * Math.PI/180.;//in rad - public static double SIGMA_Z_TRACK_MATCHING_BAR = 150;//in mm - public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 150;//in mm + public static double SIGMA_Z_TRACK_MATCHING_BAR = 200;//in mm + public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 200;//in mm public static double SIGMA_PHI_CLUSTERING = 6;//in deg From f624514dcb01ab3bac4e6f1e3027afd484e971a4 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:12:21 -0600 Subject: [PATCH 53/82] Refactoring BarHit definition, now inherits from AtofHit --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 117 ++++--- .../java/org/jlab/rec/atof/Hit/BarHit.java | 149 ++------ .../java/org/jlab/rec/atof/Hit/HitFinder.java | 325 +++++++++++------- 3 files changed, 294 insertions(+), 297 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index ef5889f8ef..77b23dad4d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -15,7 +15,7 @@ /** * * Represents a hit in the atof. Stores info about the sector, layer, component, - * order, TDC, ToT. Type is wedge/bar up/bar down Spatial coordinates are + * order, TDC, ToT. Type is wedge/bar up/bar down/ bar Spatial coordinates are * computed from atof detector object using the geometry service Stores whether * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. * @@ -187,6 +187,10 @@ public final int TDC_to_time() { tdc2time = Parameters.TDC2TIME; veff = Parameters.VEFF; } + case "bar" -> { + tdc2time = Parameters.TDC2TIME; + veff = Parameters.VEFF; + } default -> { return 1; } @@ -199,29 +203,34 @@ public final int TDC_to_time() { public final int ToT_to_energy() { double tot2energy = 1; - double att_L = 1; if (null == this.type) { return 1; } else { switch (this.type) { case "wedge" -> { tot2energy = Parameters.TOT2ENERGY_WEDGE; - att_L = Parameters.ATT_L; + //For now hits are considered in the middle of the wedge + //And the SiPM on top + double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS/2.; + this.energy = tot2energy * this.ToT * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); } case "bar up" -> { - tot2energy = Parameters.TOT2ENERGY_WEDGE; - att_L = Parameters.ATT_L; + tot2energy = Parameters.TOT2ENERGY_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_BAR; - att_L = Parameters.ATT_L; - } + //only half the information in the bar, + //the attenuation will be computed when the full hit is formed + this.energy = tot2energy * this.ToT; + } default -> { return 1; } } } - this.energy = tot2energy * this.ToT * Math.exp(this.inpath_length / att_L); return 0; } @@ -243,7 +252,7 @@ public final int slc_to_xyz(Detector atof) { switch (this.type) { case "wedge" -> sl = 1; - case "bar up", "bar down" -> + case "bar up", "bar down", "bar" -> sl = 0; default -> { return 1; @@ -283,6 +292,8 @@ public boolean matchBar(AtofHit hit2match) { return false; //System.out.print("Two hits in different layers \n"); } else if (this.getComponent() != 10 || hit2match.getComponent() != 10) { return false; //System.out.print("At least one hit is not in the bar \n"); + } else if (this.getOrder() > 1 || hit2match.getComponent() > 1) { + return false; //System.out.print("At least one hit is not a downstram or upstream hit. It may be a full bar hit. \n"); } else { return this.getOrder() != hit2match.getOrder(); //System.out.print("Two hits in same SiPM \n"); } @@ -413,49 +424,65 @@ public final void matchTrack(TrackProjector track_projector) { } } - public void matchTrack(DataBank track_bank) { - int nt = track_bank.rows(); // number of tracks - double sigma_phi = 0; - double sigma_z = 0; + public int matchTrack(DataEvent event) { - //Looping through all tracks - for (int i = 0; i < nt; i++) { + String track_bank_name = "AHDC::Projections"; + if (event == null) { // check if there is an event + //System.out.print(" no event \n"); + return 1; + } else if (event.hasBank(track_bank_name) == false) { + return 1; + // check if there are ahdc tracks in the event + //System.out.print("no tracks \n"); + } else { + DataBank track_bank = event.getBank(track_bank_name); + int nt = track_bank.rows(); // number of tracks + double sigma_phi = 0; + double sigma_z = 0; - Float xt = null,yt = null,zt=null,path = null; - - if (null == this.getType()) { - System.out.print("Impossible to match track and hit; hit type is null \n"); - } else { - switch (this.getType()) { - case "wedge" -> { - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; - xt = track_bank.getFloat("x_at_wedge", i); - yt = track_bank.getFloat("y_at_wedge", i); - zt = track_bank.getFloat("z_at_wedge", i); - path = track_bank.getFloat("L_at_wedge", i); - } - case "bar up", "bar down" -> { - System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; - xt = track_bank.getFloat("x_at_bar", i); - yt = track_bank.getFloat("y_at_bar", i); - zt = track_bank.getFloat("z_at_bar", i); - path = track_bank.getFloat("L_at_bar", i); + //Looping through all tracks + for (int i = 0; i < nt; i++) { + + Float xt = null, yt = null, zt = null, path = null, inpath = null; + + if (null == this.getType()) { + System.out.print("Impossible to match track and hit; hit type is null \n"); + } else { + switch (this.getType()) { + case "wedge" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; + xt = track_bank.getFloat("x_at_wedge", i); + yt = track_bank.getFloat("y_at_wedge", i); + zt = track_bank.getFloat("z_at_wedge", i); + path = track_bank.getFloat("L_at_wedge", i); + inpath = track_bank.getFloat("L_in_wedge", i); + } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; + xt = track_bank.getFloat("x_at_bar", i); + yt = track_bank.getFloat("y_at_bar", i); + zt = track_bank.getFloat("z_at_bar", i); + path = track_bank.getFloat("L_at_bar", i); + inpath = track_bank.getFloat("L_in_bar", i); + } + default -> + System.out.print("Impossible to match track and hit; hit type is undefined \n"); } - default -> - System.out.print("Impossible to match track and hit; hit type is undefined \n"); } - } - Point3D projection_point = new Point3D(xt, yt, zt); - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { - if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - this.setPath_length(path); + Point3D projection_point = new Point3D(xt, yt, zt); + if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { + if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { + System.out.print("PASSED CUTS \n"); + this.setPath_length(path); + this.setInpath_length(inpath); + } } } } - + return 0; } public AtofHit() { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 9c1428cbae..b71a03b86b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -7,24 +7,20 @@ import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; import java.util.ArrayList; -import java.util.List; -import org.jlab.geom.prim.Point3D; import org.jlab.rec.atof.constants.Parameters; -import org.jlab.rec.atof.trackMatch.TrackProjection; -import org.jlab.rec.atof.trackMatch.TrackProjector; /** + * + * Represents a hit in the atof bar. Extends class AtofHit. Is further defined + * by the two hits upstream and downstream composing a full bar hit. z position, + * time and energy are defined from the up/down hits * * @author npilleux */ -public class BarHit { +public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits private AtofHit hit_up, hit_down; - private double x, y, z, time, energy; - int sector, layer; - private boolean is_in_a_cluster; - private double path_length; public AtofHit getHitUp() { return hit_up; @@ -42,129 +38,23 @@ public void setHitDown(AtofHit hit_down) { this.hit_down = hit_down; } - 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 final void computeZ() { double some_calibration = 10; //Here read the calibration DB - this.z = some_calibration * (hit_up.getTime() - hit_down.getTime()); + this.setZ(some_calibration * (hit_up.getTime() - hit_down.getTime())); } public final void computeTime() { double some_calibration = 10; //Here read the calibration DB - this.time = some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.); + this.setTime(some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.)); } public final void computeEnergy() { - this.energy = (hit_up.getEnergy() + hit_down.getEnergy()); - } - - 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 int getSector() { - return sector; - } - - public void setSector(int sector) { - this.sector = sector; - } - - public int getLayer() { - return layer; - } - - public void setLayer(int layer) { - this.layer = layer; - } - - public boolean getIs_in_a_cluster() { - return is_in_a_cluster; - } - - public void setIs_in_a_cluster(boolean is_in_a_cluster) { - this.is_in_a_cluster = is_in_a_cluster; - } - - public double getPath_length() { - return path_length; - } - - public void setPath_length(double path_length) { - this.path_length = path_length; - } - - public double getPhi() { - return Math.atan2(this.y, this.x); - } - - public int computeModule_index() { - //Index ranging 0 to 60 for each wedge+bar module - return 4 * this.sector + this.layer; - } - - public void matchTrack(TrackProjector track_projector) { - List Projections = track_projector.getProjections(); - for (int i_track = 0; i_track < Projections.size(); i_track++) { - Point3D projection_point = Projections.get(i_track).get_BarIntersect(); - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { - if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { - this.setPath_length(Projections.get(i_track).get_BarPathLength()); - } - } - } - } - - public void matchTrack(DataBank track_bank) { - int nt = track_bank.rows(); // number of tracks - //Looping through all tracks - for (int i = 0; i < nt; i++) { - //Getting their properties - Float xt = track_bank.getFloat("x_at_bar", i); - Float yt = track_bank.getFloat("y_at_bar", i); - Float zt = track_bank.getFloat("z_at_bar", i); - Float path = track_bank.getFloat("L_at_bar", i); - Point3D projection_point = new Point3D(xt, yt, zt); - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < Parameters.SIGMA_PHI_TRACK_MATCHING_BAR) { - if (Math.abs(this.getZ() - projection_point.z()) < Parameters.SIGMA_Z_TRACK_MATCHING_BAR) { - this.setPath_length(path); - } - } - } + this.computeZ(); + double distance_hit_to_sipm_up = Parameters.LENGTH_ATOF / 2. + this.getZ(); + double distance_hit_to_sipm_down = Parameters.LENGTH_ATOF / 2. - this.getZ(); + double Edep_up = hit_up.getEnergy() * Math.exp(distance_hit_to_sipm_up / Parameters.ATT_L); + double Edep_down = hit_down.getEnergy() * Math.exp(distance_hit_to_sipm_down / Parameters.ATT_L); + this.setEnergy(Edep_up + Edep_down); } public BarHit(AtofHit hit_down, AtofHit hit_up) { @@ -172,13 +62,14 @@ public BarHit(AtofHit hit_down, AtofHit 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.hit_up = hit_up; this.hit_down = hit_down; - this.layer = hit_up.getLayer(); - this.sector = hit_up.getSector(); - this.x = hit_up.getX(); - this.y = hit_up.getY(); + this.setLayer(hit_up.getLayer()); + this.setSector(hit_up.getSector()); + this.setX(hit_up.getX()); + this.setY(hit_up.getY()); this.computeZ(); this.computeTime(); this.computeEnergy(); @@ -233,7 +124,7 @@ public static void main(String[] args) { } } } - ArrayList bar_hits = new ArrayList(); + ArrayList bar_hits = new ArrayList<>(); for (int i_up = 0; i_up < hit_up.size(); i_up++) { AtofHit this_hit_up = hit_up.get(i_up); for (int i_down = 0; i_down < hit_down.size(); i_down++) { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index c8d784cc27..adece84948 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -3,30 +3,34 @@ import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.Collections; +import javax.swing.JFrame; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.groot.data.H1F; +import org.jlab.groot.graphics.EmbeddedCanvas; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofHitBank; import org.jlab.rec.atof.trackMatch.TrackProjector; import org.jlab.utils.CLASResources; + /** * * @author npilleux */ public class HitFinder { - + private ArrayList bar_hits; private ArrayList wedge_hits; - - public HitFinder() - { - this.bar_hits = new ArrayList<>(); - this.wedge_hits = new ArrayList<>(); - } - + + public HitFinder() { + this.bar_hits = new ArrayList<>(); + this.wedge_hits = new ArrayList<>(); + } + // Getter and Setter for bar_hits public ArrayList getBarHits() { return bar_hits; @@ -44,130 +48,147 @@ public ArrayList getWedgeHits() { public void setWedgeHits(ArrayList wedge_hits) { this.wedge_hits = wedge_hits; } - + public void FindHits(DataEvent event, Detector atof, TrackProjector track_projector) { - //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); - //They are read from the ATOF TDC bank - DataBank bank = event.getBank("ATOF::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.getInt("sector", i); - int layer = bank.getInt("layer", i); - int component = bank.getInt("component", i); - int order = bank.getInt("order", i); - int tdc = bank.getInt("TDC", i); - int tot = bank.getInt("ToT", i); - //Building a Hit - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if(hit.getEnergy() < 0.1 )continue; //energy threshold - //Sorting the hits into wedge, upstream and downstream bar hits - //Lists are built for up/down bar to match them after - //Wedge hits are mayched to ahdc tracks and listed - 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); - case "wedge" -> {hit.matchTrack(track_projector); this.wedge_hits.add(hit);} - default -> System.out.print("Undefined hit type \n"); + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank + DataBank bank = event.getBank("ATOF::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.getInt("sector", i); + int layer = bank.getInt("layer", i); + int component = bank.getInt("component", i); + int order = bank.getInt("order", i); + int tdc = bank.getInt("TDC", i); + int tot = bank.getInt("ToT", i); + //Building a Hit + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if (hit.getEnergy() < 0.1) { + continue; //energy threshold + } //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed + 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); + case "wedge" -> { + hit.matchTrack(track_projector); + this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); } - + //Once all has been listed, hits are sorted by energy + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + } + public void FindHits(DataEvent event, Detector atof) { - //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); - //They are read from the ATOF TDC bank - DataBank bank_atof_hits = event.getBank("ATOF::tdc"); - DataBank bank_track = event.getBank("AHDC::Projection"); - int nt = bank_atof_hits.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_atof_hits.getInt("sector", i); - int layer = bank_atof_hits.getInt("layer", i); - int component = bank_atof_hits.getInt("component", i); - int order = bank_atof_hits.getInt("order", i); - int tdc = bank_atof_hits.getInt("TDC", i); - int tot = bank_atof_hits.getInt("ToT", i); - //Building a Hit - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if(hit.getEnergy() < 0.1 )continue; //energy threshold - //Sorting the hits into wedge, upstream and downstream bar hits - //Lists are built for up/down bar to match them after - //Wedge hits are mayched to ahdc tracks and listed - 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); - case "wedge" -> {hit.matchTrack(bank_track); this.wedge_hits.add(hit);} - default -> System.out.print("Undefined hit type \n"); + //For each event a list of bar hits and a list of wedge hits are filled + this.bar_hits.clear(); + this.wedge_hits.clear(); + //They are read from the ATOF TDC bank + DataBank bank_atof_hits = event.getBank("ATOF::tdc"); + int nt = bank_atof_hits.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_atof_hits.getInt("sector", i); + int layer = bank_atof_hits.getInt("layer", i); + int component = bank_atof_hits.getInt("component", i); + int order = bank_atof_hits.getInt("order", i); + int tdc = bank_atof_hits.getInt("TDC", i); + int tot = bank_atof_hits.getInt("ToT", i); + //Building a Hit + AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + if (hit.getEnergy() < 0.1) { + continue; //energy threshold + } //Sorting the hits into wedge, upstream and downstream bar hits + //Lists are built for up/down bar to match them after + //Wedge hits are mayched to ahdc tracks and listed + 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); + case "wedge" -> { + hit.matchTrack(event); + this.wedge_hits.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 Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); } - + //Once all has been listed, hits are sorted by energy + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + ArrayList allhits = new ArrayList<>();; + allhits.addAll(this.wedge_hits); + allhits.addAll(this.bar_hits); + DataBank hitbank = fillAtofHitBank(event, allhits); + event.appendBank(hitbank); + } /** * @param args the command line arguments */ public static void main(String[] args) { - + //Building ALERT geometry AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); @@ -190,26 +211,84 @@ public static void main(String[] args) { //Track Projector Initialisation with B field TrackProjector projector = new TrackProjector(); projector.setB(B); - + //Hit finder init HitFinder hitfinder = new HitFinder(); - + //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/updated_updated_rec_more_protons_50_to_650.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); + H1F h_delta_energy = new H1F("Energy", "Energy", 100, -10, 10); + h_delta_energy.setTitleX("delta energy [GeV]"); + int event_number = 0; while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - projector.ProjectTracks(event); - hitfinder.FindHits(event, atof, projector); + hitfinder.FindHits(event, atof); + DataBank MC_True = event.getBank("MC::True"); + DataBank tdc = event.getBank("ATOF::tdc"); + DataBank hits = event.getBank("ATOF::hits"); + double totEdep = 0; + + for (int i = 0; i < MC_True.rows(); i++) { + + if (MC_True.getByte("detector", i) != 24) { + continue; + } + Float true_energy = MC_True.getFloat("avgT", i); + if (true_energy < 5) { + continue; + } + System.out.print(true_energy + " TRUE \n"); + double min_diff = 9999.; + double energy_at_min = 9999.; + + for (int j = 0; j < hits.rows(); j++) { + Float hit_energy = hits.getFloat("time", j); + Float diff = true_energy - hit_energy; + if (diff < min_diff) { + min_diff = diff; + energy_at_min = true_energy; + } + } + System.out.print("ICI " + energy_at_min + " " + true_energy + " \n"); + h_delta_energy.fill(min_diff / energy_at_min); } + System.out.print("------------------- \n"); + } + + System.out.print ( + + "Read " + event_number + " events"); + JFrame frame = new JFrame("Raster"); + + frame.setSize ( + + 2500,800); + EmbeddedCanvas canvas = new EmbeddedCanvas(); + + canvas.divide ( + + + 3,2); + canvas.cd ( + + + 3); canvas.draw (h_delta_energy); + + frame.add (canvas); + + frame.setLocationRelativeTo ( + + + null); + frame.setVisible ( + - System.out.print("Read " + event_number + " events"); +true); } } - \ No newline at end of file From 06cf9857dd380dc327ac9b4a86b885da6df55ddd Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:13:03 -0600 Subject: [PATCH 54/82] ATOF hit bank --- etc/bankdefs/hipo4/alert.json | 58 +++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index e616780db4..ea6f4e251b 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -4,7 +4,7 @@ "group": 23000, "item": 31, "info": "Track Projections to ATOF", - "entries": [ + "entries": [ { "name": "x_at_bar", "type": "F", @@ -20,7 +20,7 @@ },{ "name": "L_at_bar", "type": "F", - "info": "path length at atof bar (inner surface) in mm" + "info": "path length at atof bar (inner surface) in mm" },{ "name": "L_in_bar", "type": "F", @@ -28,7 +28,7 @@ },{ "name": "x_at_wedge", "type": "F", - "info": "x position at atof wedge (middle surface) in mm" + "info": "x position at atof wedge (middle surface) in mm" }, { "name": "y_at_wedge", "type": "F", @@ -48,6 +48,58 @@ } ] },{ + "name": "ATOF::hits", + "group": 22500, + "item": 21, + "info": "Hits in ATOF", + "entries": [ + { + "name": "id", + "type": "S", + "info": "hit id" + }, { + "name": "sector", + "type": "I", + "info": "atof sector" + }, { + "name": "layer", + "type": "I", + "info": "atof layer" + },{ + "name": "component", + "type": "I", + "info": "atof component" + },{ + "name": "time", + "type": "F", + "info": "time in ns" + },{ + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + },{ + "name": "energy", + "type": "F", + "info": "deposited energy in MeV" + },{ + "name": "inlength", + "type": "F", + "info": "path length inside the detector (from entrance to hit) in mm" + },{ + "name": "pathlength", + "type": "F", + "info": "path length to the hit in mm" + } + ] + },{ "name": "AHDC::Hits", "group": 23000, "item": 23, From 61ea386124d8cbd68ea97ec99845513297cd60a8 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Fri, 17 Jan 2025 16:18:14 -0600 Subject: [PATCH 55/82] ATOF bank writer --- .../jlab/rec/atof/banks/RecoBankWriter.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java new file mode 100644 index 0000000000..94479d9379 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -0,0 +1,53 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template + */ +package org.jlab.rec.atof.banks; + +import java.util.ArrayList; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.atof.hit.AtofHit; + +/** + * + * @author npilleux + */ +public class RecoBankWriter { + + // write useful information in the bank + public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitlist) { + + DataBank bank = event.createBank("ATOF::hits", hitlist.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + return null; + } + + for(int i =0; i< hitlist.size(); i++) { + bank.setShort("id",i, (short)(i+1)); + bank.setInt("sector",i, (int) hitlist.get(i).getSector()); + bank.setInt("layer",i, (int) hitlist.get(i).getLayer()); + bank.setInt("component",i, (int) hitlist.get(i).getComponent()); + //bank.setShort("trkID",i, (short) hitlist.get(i).get_AssociatedTrkId()); + //bank.setShort("clusterid", i, (short) hitlist.get(i).get_AssociatedClusterID()); + 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()); + bank.setFloat("inlength",i, (float) (hitlist.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (hitlist.get(i).getPath_length())); + } + return bank; + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + } + +} From 81d4c643fcc3635df70e8755db7f2f21d0bae83f Mon Sep 17 00:00:00 2001 From: Churamani Paudel Date: Tue, 21 Jan 2025 15:25:41 -0500 Subject: [PATCH 56/82] viewed clustering logic --- .../main/java/org/jlab/rec/atof/Cluster/AtofCluster.java | 3 ++- .../java/org/jlab/rec/atof/Cluster/ClusterFinder.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 76e441c7ed..55b31eb9fb 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -1,5 +1,4 @@ package org.jlab.rec.atof.cluster; - import java.util.ArrayList; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; @@ -8,6 +7,8 @@ * * @author npilleux */ + + public class AtofCluster { ArrayList bar_hits; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index b6f50b496c..c0ed07c9c9 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -42,7 +42,14 @@ public void MakeClusters(HitFinder hitfinder) { double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future double sigma_Z = 6000;//to be read from DB in the future double sigma_T = 1000;//timing resolution to be read from DB in the future - int sigma_module = 1; //hits are always within +-1 phi module of the most energetic + + /* + double sigma_Phi = loadParameterFromDB("SIGMA_PHI"); + double sigma_Z = loadParameterFromDB("SIGMA_Z"); + double sigma_T = loadParameterFromDB("SIGMA_T"); + */ + + int sigma_module = 1; //hits are always within +-1 phi module of the most energetic int sigma_component = 1;//hits are always within +-1 z component of the most energetic //Looping through wedge hits first From 80c743bf0644608391783cdbe918e6cef942575b Mon Sep 17 00:00:00 2001 From: Churamani Paudel Date: Wed, 22 Jan 2025 12:02:03 -0500 Subject: [PATCH 57/82] will work on this branch --- .../org/jlab/rec/atof/Cluster/AtofCluster.java | 3 ++- .../org/jlab/rec/atof/Cluster/ClusterFinder.java | 11 +++-------- .../main/java/org/jlab/rec/atof/Hit/AtofHit.java | 4 +++- .../main/java/org/jlab/rec/atof/Hit/BarHit.java | 4 ++-- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 2 +- .../jlab/rec/atof/TrackMatch/TrackProjector.java | 15 ++++++++++----- .../org/jlab/rec/atof/banks/RecoBankWriter.java | 2 +- .../org/jlab/rec/atof/constants/Parameters.java | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 55b31eb9fb..87c8950823 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -5,7 +5,7 @@ /** * - * @author npilleux + * @authors npilleux, churaman */ @@ -82,6 +82,7 @@ public void setPath_length(double path_length) { //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later + public final void computeClusterProperties() { this.energy=0; double max_energy = -1; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index c0ed07c9c9..28e6af5cec 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -16,8 +16,9 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ + public class ClusterFinder { private ArrayList clusters; @@ -42,16 +43,10 @@ public void MakeClusters(HitFinder hitfinder) { double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future double sigma_Z = 6000;//to be read from DB in the future double sigma_T = 1000;//timing resolution to be read from DB in the future - - /* - double sigma_Phi = loadParameterFromDB("SIGMA_PHI"); - double sigma_Z = loadParameterFromDB("SIGMA_Z"); - double sigma_T = loadParameterFromDB("SIGMA_T"); - */ - int sigma_module = 1; //hits are always within +-1 phi module of the most energetic int sigma_component = 1;//hits are always within +-1 z component of the most energetic + //Looping through wedge hits first for (int i_wedge = 0; i_wedge < wedge_hits.size(); i_wedge++) { AtofHit this_wedge_hit = wedge_hits.get(i_wedge); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 77b23dad4d..88d0a4e164 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -19,7 +19,7 @@ * computed from atof detector object using the geometry service Stores whether * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. * - * @author npilleux + * @authors npilleux, churaman */ public class AtofHit { @@ -285,6 +285,7 @@ public final int slc_to_xyz(Detector atof) { * @param hit2match The AtofHit object to compare with the current instance. * @return {@code true} if the hits match; {@code false} otherwise. */ + public boolean matchBar(AtofHit hit2match) { if (this.getSector() != hit2match.getSector()) { return false; //System.out.print("Two hits in different sectors \n"); @@ -386,6 +387,7 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * TrackProjections. * */ + public final void matchTrack(TrackProjector track_projector) { double sigma_phi = 0; double sigma_z = 0; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index b71a03b86b..3edae6bd58 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,5 +1,4 @@ package org.jlab.rec.atof.hit; - import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -15,8 +14,9 @@ * by the two hits upstream and downstream composing a full bar hit. z position, * time and energy are defined from the up/down hits * - * @author npilleux + * @authors npilleux,churaman */ + public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index adece84948..8f33db7f6d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -19,7 +19,7 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ public class HitFinder { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index cca125510c..90d5936b89 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -180,10 +180,12 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd double pz = bank.getFloat("pz", i); //Put everything in MM + x = x*10; y = y*10; z = z*10; - Units units = Units.MM; + + Units units = Units.MM; int q = 1; //need the charge sign from tracking @@ -194,15 +196,18 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + + projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + + projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); + + projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); Projections.add(projection); fill_out_bank(outputBank, projection, i); @@ -261,4 +266,4 @@ public static void main(String arg[]) { System.out.print("Read " + event_number + " events"); } -} \ No newline at end of file +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 94479d9379..c87040d17e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -11,7 +11,7 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ public class RecoBankWriter { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java index 89c7cce60e..2c15a5200b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -2,7 +2,7 @@ /** * - * @author npilleux + * @authors npilleux,churaman */ public class Parameters { From 4d51e5e01c2997ea0ea123e27f1875b986fc76be Mon Sep 17 00:00:00 2001 From: Churamani Paudel Date: Thu, 23 Jan 2025 12:25:04 -0500 Subject: [PATCH 58/82] proximity checks for ClusterFinder::improved logic --- .../jlab/rec/atof/Cluster/ClusterFinder.java | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 28e6af5cec..0b70675e50 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -229,3 +229,202 @@ public static void main(String[] args) { } } + + + + +/* +// Exhibits more modular approach, and parameters/thresholds for clustering +// +package org.jlab.rec.atof.cluster; + +import cnuphys.magfield.MagneticFields; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.hit.HitFinder; +import org.jlab.rec.atof.trackMatch.TrackProjector; +import org.jlab.utils.CLASResources; + + +// @authors npilleux, churaman + +public class ClusterFinder { + + private static final Logger logger = Logger.getLogger(ClusterFinder.class.getName()); + private List clusters; +//can be replaced with actual values + private final double sigmaPhi = 6.0; // Angle opening of a layer + private final double sigmaZ = 6000.0; // Z threshold in mm + private final double sigmaT = 1000.0; // Timing resolution in ns + private final int sigmaModule = 1; // Module proximity threshold + private final int sigmaComponent = 1; // Component proximity threshold + + public ClusterFinder() { + this.clusters = new ArrayList<>(); + } + + public List getClusters() { + return clusters; + } + + public void setClusters(List clusters) { + this.clusters = clusters; + } + + public void makeClusters(HitFinder hitFinder) { + clusters.clear(); + List wedgeHits = hitFinder.getWedgeHits(); + List barHits = hitFinder.getBarHits(); + + clusterWedgeHits(wedgeHits, barHits); + clusterRemainingBarHits(barHits); + + logger.info("Clustering completed: " + clusters.size() + " clusters formed."); + } + + private void clusterWedgeHits(List wedgeHits, List barHits) { + for (int i = 0; i < wedgeHits.size(); i++) { + AtofHit primaryHit = wedgeHits.get(i); + if (primaryHit.getIs_in_a_cluster()) continue; + + List clusterWedgeHits = new ArrayList<>(); + List clusterBarHits = new ArrayList<>(); + + primaryHit.setIs_in_a_cluster(true); + clusterWedgeHits.add(primaryHit); + + addNearbyWedgeHits(primaryHit, wedgeHits, clusterWedgeHits); + addNearbyBarHits(primaryHit, barHits, clusterBarHits); + + clusters.add(new AtofCluster(clusterBarHits, clusterWedgeHits)); + } + } + + private void addNearbyWedgeHits(AtofHit primaryHit, List wedgeHits, List clusterWedgeHits) { + for (AtofHit hit : wedgeHits) { + if (hit.getIs_in_a_cluster()) continue; + + if (isHitInProximity(primaryHit, hit)) { + hit.setIs_in_a_cluster(true); + clusterWedgeHits.add(hit); + } + } + } + + private void addNearbyBarHits(AtofHit primaryHit, List barHits, List clusterBarHits) { + for (BarHit hit : barHits) { + if (hit.getIs_in_a_cluster()) continue; + + if (isHitInProximity(primaryHit, hit)) { + hit.setIs_in_a_cluster(true); + clusterBarHits.add(hit); + } + } + } + + private void clusterRemainingBarHits(List barHits) { + for (int i = 0; i < barHits.size(); i++) { + BarHit primaryHit = barHits.get(i); + if (primaryHit.getIs_in_a_cluster()) continue; + + List clusterBarHits = new ArrayList<>(); + primaryHit.setIs_in_a_cluster(true); + clusterBarHits.add(primaryHit); + + for (int j = i + 1; j < barHits.size(); j++) { + BarHit secondaryHit = barHits.get(j); + if (secondaryHit.getIs_in_a_cluster()) continue; + + if (isHitInProximity(primaryHit, secondaryHit)) { + secondaryHit.setIs_in_a_cluster(true); + clusterBarHits.add(secondaryHit); + } + } + + clusters.add(new AtofCluster(clusterBarHits, new ArrayList<>())); + } + } + +private boolean isHitInProximity(AtofHit hit1, AtofHit hit2) { + // Check if both hits are wedge hits + if (!"wedge".equals(hit1.getType()) || !"wedge".equals(hit2.getType())) { + return false; // Return false if either hit is not a wedge + } + + int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); + deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; + + int deltaComponent = Math.abs(hit1.getComponent() - hit2.getComponent()); + double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); + + return deltaModule <= sigmaModule && deltaComponent <= sigmaComponent && deltaT < sigmaT; +} + +private boolean isHitInProximity(AtofHit hit1, BarHit hit2) { + // Ensures that the AtofHit is of type "wedge" + if (!"wedge".equals(hit1.getType())) { + return false; + } + + // Computes module difference with circular boundary handling + int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); + deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; + + // Computes spatial and temporal proximity + double deltaZ = Math.abs(hit1.getZ() - hit2.getZ()); + double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); + + // Returns true if all proximity conditions are satisfied + return deltaModule <= sigmaModule && deltaZ < sigmaZ && deltaT < sigmaT; +} + + + public static void main(String[] args) { + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + Detector atof = factory.createDetectorCLAS(cp); + + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields( + mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", + "Symm_solenoid_r601_phi1_z1201_13June2018.dat" + ); + } catch (Exception e) { + logger.severe("Error initializing magnetic fields: " + e.getMessage()); + } + + TrackProjector projector = new TrackProjector(); + projector.setB(new Swim().BfieldLab(0, 0, 0, new float[3])[2]); + + String inputFile = "/path/to/input.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(inputFile); + + HitFinder hitFinder = new HitFinder(); + + while (reader.hasEvent()) { + DataEvent event = reader.getNextEvent(); + projector.ProjectTracks(event); + hitFinder.FindHits(event, atof, projector); + + ClusterFinder clusterFinder = new ClusterFinder(); + clusterFinder.makeClusters(hitFinder); + + logger.info("Processed event with " + clusterFinder.getClusters().size() + " clusters."); + } + } +} +*/ + From aa853436d6dd3f1cbbdf5879ad739e6cd96145a4 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 23 Jan 2025 11:29:24 -0600 Subject: [PATCH 59/82] Fixing conversions tdc/tot to time/energy and cleanup --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 127 +++++++++--------- 1 file changed, 67 insertions(+), 60 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 88d0a4e164..02e32eec52 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -19,7 +19,7 @@ * computed from atof detector object using the geometry service Stores whether * the hit is part of a cluster. Calculates time, energy based on TDC/ToT. * - * @authors npilleux, churaman + * @author npilleux */ public class AtofHit { @@ -156,6 +156,8 @@ public int computeModule_index() { } public final String makeType() { + //Type of hit can be wedge, bar up, bar down or bar. + //Avoids testing components and order every time. String itype = "undefined"; if (this.component == 10 && this.order == 0) { itype = "bar down"; @@ -168,42 +170,66 @@ public final String makeType() { return itype; } + /** + * Converts TDC to time (ns). Sets the hit time parameter to a raw time for + * up/down bar hits or to the time corrected for the propagation for wedge + * hits. + * + * @return 0 if the time was successfully set, or 1 if the hit type is + * unsupported. + */ public final int TDC_to_time() { - double tdc2time = 1; - double veff = 1; + 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 "wedge" -> { tdc2time = Parameters.TDC2TIME; veff = Parameters.VEFF; + //Wedge hits are placed at the center of wedges and sipm at their top + distance_to_sipm = Parameters.WEDGE_THICKNESS / 2.; } case "bar up" -> { tdc2time = Parameters.TDC2TIME; veff = Parameters.VEFF; + //The distance will be computed at barhit level when z 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 z information is available + distance_to_sipm = 0; } case "bar" -> { - tdc2time = Parameters.TDC2TIME; - veff = Parameters.VEFF; + 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; } } } - //Time at the inner surface - this.time = tdc2time * this.TDC - this.inpath_length / veff; + //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 or to the energy corrected for the + * attenuation for wedge hits. + * + * @return 0 if the energy was successfully set, or 1 if the hit type is + * unsupported. + */ public final int ToT_to_energy() { - double tot2energy = 1; + double tot2energy; if (null == this.type) { + System.out.print("Null hit type, cannot convert tot to energy."); return 1; } else { switch (this.type) { @@ -211,7 +237,7 @@ public final int ToT_to_energy() { tot2energy = Parameters.TOT2ENERGY_WEDGE; //For now hits are considered in the middle of the wedge //And the SiPM on top - double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS/2.; + double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS / 2.; this.energy = tot2energy * this.ToT * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); } case "bar up" -> { @@ -225,8 +251,13 @@ public final int ToT_to_energy() { //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; } } @@ -237,7 +268,7 @@ public final int ToT_to_energy() { /** * Calculates spatial coordinates for the hit based on associated detector * component. Retrieves the midpoint of the atof component to assign the - * corresponding x, y, z coordinates to the hit. + * corresponding x, y, z coordinates to the hit (mm). * * * @param atof The Detector object representing the atof. @@ -245,7 +276,7 @@ public final int ToT_to_energy() { * is undefined or unsupported. */ public final int slc_to_xyz(Detector atof) { - int sl = 999; + int sl; if (null == this.type) { return 1; } else { @@ -261,10 +292,11 @@ public final int slc_to_xyz(Detector atof) { } Component comp = atof.getSector(this.sector).getSuperlayer(sl).getLayer(this.layer).getComponent(this.component); Point3D midpoint = comp.getMidpoint(); - - //coordinates centered at the center of the atof in mm - this.x = midpoint.x() - Parameters.LENGTH_ATOF / 2.; - this.y = midpoint.y() - Parameters.LENGTH_ATOF / 2.; + //Midpoints defined in the system were z=0 is the upstream end of the atof + //Translation to the system were z=0 is the center of the atof + //Units are mm + this.x = midpoint.x(); + this.y = midpoint.y(); this.z = midpoint.z() - Parameters.LENGTH_ATOF / 2.; return 0; } @@ -277,7 +309,7 @@ public final int slc_to_xyz(Detector atof) { *
  • If either hit is not in the bar (component must be 10), the method * returns {@code false}.
  • *
  • If both hits are in the same SiPM (i.e., their order is the same), - * the method returns {@code false}.
  • + * 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. @@ -285,23 +317,27 @@ public final int slc_to_xyz(Detector atof) { * @param hit2match The AtofHit object to compare with the current instance. * @return {@code true} if the hits match; {@code false} otherwise. */ - public boolean matchBar(AtofHit hit2match) { if (this.getSector() != hit2match.getSector()) { - return false; //System.out.print("Two hits in different sectors \n"); + //Two hits in different sectors + return false; } else if (this.getLayer() != hit2match.getLayer()) { - return false; //System.out.print("Two hits in different layers \n"); + //Two hits in different layers + return false; } else if (this.getComponent() != 10 || hit2match.getComponent() != 10) { - return false; //System.out.print("At least one hit is not in the bar \n"); - } else if (this.getOrder() > 1 || hit2match.getComponent() > 1) { - return false; //System.out.print("At least one hit is not a downstram or upstream hit. It may be a full bar hit. \n"); + //At least one hit not in the bar + return false; + } else if (this.getOrder() > 1 || hit2match.getOrder() > 1) { + //At least one hit has incorrect order + return false; } else { - return this.getOrder() != hit2match.getOrder(); //System.out.print("Two hits in same SiPM \n"); + //Match if one is order 0 and the other is order 1 + return this.getOrder() != hit2match.getOrder(); } } /** - * Returns the azimuthal angle (phi) of the hit. + * Computes the azimuthal angle (phi) of the hit in rad. * * @return The azimuthal angle (phi) in radians, in the range [-π, π]. */ @@ -310,7 +346,7 @@ public double getPhi() { } /** - * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * Constructor for a hit in the atof. Initializes the hit's sector, layer, * component, order, TDC, ToT. Sets the hit's initial state regarding * clustering. Set up the hit's type, time, energy, and spatial coordinates. * @@ -343,7 +379,7 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot } /** - * Constructor for a fit in the atof. Initializes the hit's sector, layer, + * Constructor for a hit in the atof. Initializes the hit's sector, layer, * component, order, TDC, ToT. Sets the hit's initial state regarding * clustering. Set up the hit's type, time, energy, and spatial coordinates. * @@ -387,7 +423,6 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot * TrackProjections. * */ - public final void matchTrack(TrackProjector track_projector) { double sigma_phi = 0; double sigma_z = 0; @@ -446,7 +481,6 @@ public int matchTrack(DataEvent event) { for (int i = 0; i < nt; i++) { Float xt = null, yt = null, zt = null, path = null, inpath = null; - if (null == this.getType()) { System.out.print("Impossible to match track and hit; hit type is null \n"); } else { @@ -460,8 +494,7 @@ public int matchTrack(DataEvent event) { path = track_bank.getFloat("L_at_wedge", i); inpath = track_bank.getFloat("L_in_wedge", i); } - case "bar up", "bar down" -> { - System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + case "bar" -> { sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; xt = track_bank.getFloat("x_at_bar", i); @@ -470,6 +503,9 @@ public int matchTrack(DataEvent event) { path = track_bank.getFloat("L_at_bar", i); inpath = track_bank.getFloat("L_in_bar", i); } + case "bar up", "bar down" -> { + System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); + } default -> System.out.print("Impossible to match track and hit; hit type is undefined \n"); } @@ -477,7 +513,6 @@ public int matchTrack(DataEvent event) { Point3D projection_point = new Point3D(xt, yt, zt); if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - System.out.print("PASSED CUTS \n"); this.setPath_length(path); this.setInpath_length(inpath); } @@ -494,33 +529,5 @@ public AtofHit() { * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - DataBank bank = event.getBank("ATOF::tdc"); - int nt = bank.rows(); // number of tracks - - for (int i = 0; i < nt; i++) { - int sector = bank.getInt("sector", i); - int layer = bank.getInt("layer", i); - int component = bank.getInt("component", i); - int order = bank.getInt("order", i); - int tdc = bank.getInt("TDC", i); - int tot = bank.getInt("ToT", i); - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - System.out.print(hit.getX() + "\n"); - } - } } } From 786488bb7db019333edbd6e6d05afb6e32872f84 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 23 Jan 2025 11:43:42 -0600 Subject: [PATCH 60/82] Fixing time/energy computation and some cleanup --- .../java/org/jlab/rec/atof/Hit/BarHit.java | 97 +++++++------------ 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 3edae6bd58..8b13a978ca 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,4 +1,5 @@ package org.jlab.rec.atof.hit; + import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -12,11 +13,10 @@ * * Represents a hit in the atof bar. Extends class AtofHit. Is further defined * by the two hits upstream and downstream composing a full bar hit. z position, - * time and energy are defined from the up/down hits + * time and energy are defined from the up/down hits. * - * @authors npilleux,churaman + * @author npilleux */ - public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits @@ -38,16 +38,40 @@ public void setHitDown(AtofHit hit_down) { this.hit_down = hit_down; } + /** + * Computes bar hit z coordinate from up/downstream hit times. + * + */ public final void computeZ() { - double some_calibration = 10; //Here read the calibration DB - this.setZ(some_calibration * (hit_up.getTime() - hit_down.getTime())); + this.setZ(Parameters.VEFF/2. * (hit_up.getTime() - hit_down.getTime())); } + /** + * Computes bar 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() { - double some_calibration = 10; //Here read the calibration DB - this.setTime(some_calibration + ((hit_up.getTime() + hit_down.getTime()) / 2.)); + //We pick the most energetic signal as the timing signal + double time_at_sipm, distance_to_sipm; + if(this.hit_down.getEnergy() > this.hit_up.getEnergy()) { + time_at_sipm = this.hit_down.getTime(); + distance_to_sipm = Parameters.LENGTH_ATOF/2. - this.getZ(); + } + else { + time_at_sipm = this.hit_up.getTime(); + distance_to_sipm = Parameters.LENGTH_ATOF/2. + this.getZ(); + } + this.setTime(time_at_sipm - distance_to_sipm/Parameters.VEFF); } + /** + * Computes bar hit energy from up/downstream hits. + * The energy of the up/downstream hits is corrected for attenuation now that z is known. + * The energy of the bar hit is the sum of the energy of the up/downstream hits. + * + */ public final void computeEnergy() { this.computeZ(); double distance_hit_to_sipm_up = Parameters.LENGTH_ATOF / 2. + this.getZ(); @@ -68,6 +92,7 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { this.hit_down = hit_down; this.setLayer(hit_up.getLayer()); this.setSector(hit_up.getSector()); + this.setComponent(10); this.setX(hit_up.getX()); this.setY(hit_up.getY()); this.computeZ(); @@ -76,65 +101,15 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { } public BarHit() { + super(); // Call AtofHit constructor + //Sets some parameters to make a bar type hit + this.setType("bar"); + this.setOrder(2); } /** * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/test_tdc_atof.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - DataBank bank = event.getBank("ATOF::tdc"); - int nt = bank.rows(); // number of tracks - ArrayList hit_up = new ArrayList<>(); - ArrayList hit_down = new ArrayList<>(); - ArrayList hit_wedge = new ArrayList<>(); - for (int i = 0; i < nt; i++) { - int sector = bank.getInt("sector", i); - int layer = bank.getInt("layer", i); - int component = bank.getInt("component", i); - int order = bank.getInt("order", i); - int tdc = bank.getInt("TDC", i); - int tot = bank.getInt("ToT", i); - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - 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); - case "wedge" -> - hit_wedge.add(hit); - default -> - System.out.print("Undefined hit type \n"); - } - } - } - ArrayList bar_hits = new ArrayList<>(); - for (int i_up = 0; i_up < hit_up.size(); i_up++) { - AtofHit this_hit_up = hit_up.get(i_up); - for (int i_down = 0; i_down < hit_down.size(); i_down++) { - AtofHit this_hit_down = hit_down.get(i_down); - if (this_hit_up.matchBar(this_hit_down)) { - BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - bar_hits.add(this_bar_hit); - } - } - } - } } } From 57d922859c8531cfb1a06c1a6c547345c9a55c18 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 23 Jan 2025 11:46:14 -0600 Subject: [PATCH 61/82] Fixing energy sorting and some cleanup --- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 121 ++---------------- 1 file changed, 10 insertions(+), 111 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index 8f33db7f6d..c875f67635 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -19,7 +19,7 @@ /** * - * @authors npilleux,churaman + * @author npilleux */ public class HitFinder { @@ -71,9 +71,10 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec int tot = bank.getInt("ToT", i); //Building a Hit AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if (hit.getEnergy() < 0.1) { + if (hit.getEnergy() < 0.01) { continue; //energy threshold - } //Sorting the hits into wedge, upstream and downstream bar hits + } + //Sorting the hits into wedge, upstream and downstream bar hits //Lists are built for up/down bar to match them after //Wedge hits are mayched to ahdc tracks and listed if (null == hit.getType()) { @@ -110,8 +111,8 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } public void FindHits(DataEvent event, Detector atof) { @@ -136,7 +137,7 @@ public void FindHits(DataEvent event, Detector atof) { int tot = bank_atof_hits.getInt("ToT", i); //Building a Hit AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if (hit.getEnergy() < 0.1) { + if (hit.getEnergy() < 0.01) { continue; //energy threshold } //Sorting the hits into wedge, upstream and downstream bar hits //Lists are built for up/down bar to match them after @@ -175,9 +176,9 @@ public void FindHits(DataEvent event, Detector atof) { } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit1.getEnergy(), hit2.getEnergy())); - ArrayList allhits = new ArrayList<>();; + Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + ArrayList allhits = new ArrayList<>(); allhits.addAll(this.wedge_hits); allhits.addAll(this.bar_hits); DataBank hitbank = fillAtofHitBank(event, allhits); @@ -188,107 +189,5 @@ public void FindHits(DataEvent event, Detector atof) { * @param args the command line arguments */ public static void main(String[] args) { - - //Building ALERT geometry - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //READING MAG FIELD MAP - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields(mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); - } catch (Exception e) { - e.printStackTrace(); - } - float[] b = new float[3]; - Swim swimmer = new Swim(); - swimmer.BfieldLab(0, 0, 0, b); - double B = Math.abs(b[2]); - - //Track Projector Initialisation with B field - TrackProjector projector = new TrackProjector(); - projector.setB(B); - - //Hit finder init - HitFinder hitfinder = new HitFinder(); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/updated_updated_rec_more_protons_50_to_650.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - H1F h_delta_energy = new H1F("Energy", "Energy", 100, -10, 10); - h_delta_energy.setTitleX("delta energy [GeV]"); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - projector.ProjectTracks(event); - hitfinder.FindHits(event, atof); - DataBank MC_True = event.getBank("MC::True"); - DataBank tdc = event.getBank("ATOF::tdc"); - DataBank hits = event.getBank("ATOF::hits"); - double totEdep = 0; - - for (int i = 0; i < MC_True.rows(); i++) { - - if (MC_True.getByte("detector", i) != 24) { - continue; - } - Float true_energy = MC_True.getFloat("avgT", i); - if (true_energy < 5) { - continue; - } - System.out.print(true_energy + " TRUE \n"); - double min_diff = 9999.; - double energy_at_min = 9999.; - - for (int j = 0; j < hits.rows(); j++) { - Float hit_energy = hits.getFloat("time", j); - Float diff = true_energy - hit_energy; - if (diff < min_diff) { - min_diff = diff; - energy_at_min = true_energy; - } - } - System.out.print("ICI " + energy_at_min + " " + true_energy + " \n"); - h_delta_energy.fill(min_diff / energy_at_min); - } - System.out.print("------------------- \n"); - } - - System.out.print ( - - "Read " + event_number + " events"); - JFrame frame = new JFrame("Raster"); - - frame.setSize ( - - 2500,800); - EmbeddedCanvas canvas = new EmbeddedCanvas(); - - canvas.divide ( - - - 3,2); - canvas.cd ( - - - 3); canvas.draw (h_delta_energy); - - frame.add (canvas); - - frame.setLocationRelativeTo ( - - - null); - frame.setVisible ( - - -true); } } From 146ec823417ed6749e804c13e54024a34e7f3111 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:37:28 -0600 Subject: [PATCH 62/82] handling clustering parameters --- .../jlab/rec/atof/Cluster/ClusterFinder.java | 297 ++---------------- .../jlab/rec/atof/constants/Parameters.java | 17 +- 2 files changed, 38 insertions(+), 276 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 0b70675e50..fba46b565c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -2,12 +2,19 @@ import cnuphys.magfield.MagneticFields; import java.util.ArrayList; +import javax.swing.JFrame; import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.groot.data.H1F; +import org.jlab.groot.data.H2F; +import org.jlab.groot.graphics.EmbeddedCanvas; +import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; +import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofClusterBank; +import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; @@ -16,22 +23,21 @@ /** * - * @authors npilleux,churaman + * @author npilleux */ - public class ClusterFinder { private ArrayList clusters; - + public void setClusters(ArrayList clusters) { this.clusters = clusters; } - + public ArrayList getClusters() { return clusters; } - public void MakeClusters(HitFinder hitfinder) { + public void makeClusters(DataEvent event, HitFinder hitfinder) { //A list of clusters is built for each event clusters.clear(); @@ -40,13 +46,6 @@ public void MakeClusters(HitFinder hitfinder) { ArrayList wedge_hits = hitfinder.getWedgeHits(); ArrayList bar_hits = hitfinder.getBarHits(); - double sigma_Phi = 6.0; //angle opening of a layer. to be read from DB in the future - double sigma_Z = 6000;//to be read from DB in the future - double sigma_T = 1000;//timing resolution to be read from DB in the future - int sigma_module = 1; //hits are always within +-1 phi module of the most energetic - int sigma_component = 1;//hits are always within +-1 z component of the most energetic - - //Looping through wedge hits first for (int i_wedge = 0; i_wedge < wedge_hits.size(); i_wedge++) { AtofHit this_wedge_hit = wedge_hits.get(i_wedge); @@ -54,6 +53,7 @@ public void MakeClusters(HitFinder hitfinder) { if (this_wedge_hit.getIs_in_a_cluster()) { continue; } + //Holding onto the hits composing the cluster ArrayList this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); @@ -84,11 +84,10 @@ public void MakeClusters(HitFinder hitfinder) { //Time matching double delta_T = Math.abs(this_wedge_hit.getTime() - other_wedge_hit.getTime()); - if (delta_module <= sigma_module)//delta_Phi <= sigma_Phi) - { - if (delta_component <= sigma_component)//delta_Z <= sigma_Z) + if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { + if (delta_component <= Parameters.SIGMA_COMPONENT_CLUSTERING)//delta_Z <= sigma_Z) { - if (delta_T < sigma_T) { + if (delta_T < Parameters.SIGMA_T_CLUSTERING) { other_wedge_hit.setIs_in_a_cluster(true); this_cluster_wedge_hits.add(other_wedge_hit); } @@ -114,22 +113,21 @@ public void MakeClusters(HitFinder hitfinder) { double delta_Z = Math.abs(this_wedge_hit.getZ() - other_bar_hit.getZ()); //Time matching double delta_T = Math.abs(this_wedge_hit.getTime() - other_bar_hit.getTime()); - if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) - { - if (delta_Z < sigma_Z) { - if (delta_T < sigma_T) { + if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { + if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { + if (delta_T < Parameters.SIGMA_T_CLUSTERING) { other_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(other_bar_hit); } } } }//End loop bar hits + //After all wedge and bar hits have been grouped, build the cluster AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); //And add it to the list of clusters clusters.add(cluster); }//End loop on all wedge hits - //Now make clusters from bar hits that are not associated with wedge hits //Loop through all bar hits for (int i_bar = 0; i_bar < bar_hits.size(); i_bar++) { @@ -139,11 +137,11 @@ public void MakeClusters(HitFinder hitfinder) { continue; } - ArrayList this_cluster_wedge_hits = new ArrayList(); - ArrayList this_cluster_bar_hits = new ArrayList(); + ArrayList this_cluster_wedge_hits = new ArrayList<>(); + ArrayList this_cluster_bar_hits = new ArrayList<>(); this_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(this_bar_hit); - + //Loop through less energetic clusters for (int j_bar = i_bar + 1; j_bar < bar_hits.size(); j_bar++) { BarHit other_bar_hit = bar_hits.get(j_bar); @@ -151,7 +149,7 @@ public void MakeClusters(HitFinder hitfinder) { if (other_bar_hit.getIs_in_a_cluster()) { continue; } - + //Check the distance between the hits //For now we use phi module difference from what is observed in simu int delta_module = Math.abs(this_bar_hit.computeModule_index() - other_bar_hit.computeModule_index()); @@ -164,10 +162,9 @@ public void MakeClusters(HitFinder hitfinder) { //Time matching double delta_T = Math.abs(this_bar_hit.getTime() - other_bar_hit.getTime()); - if (delta_module <= sigma_module)//delta_Phi < sigma_Phi) - { - if (delta_Z < sigma_Z) { - if (delta_T < sigma_T) { + if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { + if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { + if (delta_T < Parameters.SIGMA_T_CLUSTERING) { other_bar_hit.setIs_in_a_cluster(true); this_cluster_bar_hits.add(other_bar_hit); } @@ -177,254 +174,18 @@ public void MakeClusters(HitFinder hitfinder) { AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } + DataBank clusterbank = fillAtofClusterBank(event, clusters); + event.appendBank(clusterbank); } public ClusterFinder() { - clusters = new ArrayList(); + clusters = new ArrayList<>(); } /** * @param args the command line arguments */ public static void main(String[] args) { - // TODO code application logic here - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - //READING MAG FIELD MAP - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields(mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); - } catch (Exception e) { - e.printStackTrace(); - } - float[] b = new float[3]; - Swim swimmer = new Swim(); - swimmer.BfieldLab(0, 0, 0, b); - double B = Math.abs(b[2]); - - //Track Projector Initialisation with B field - TrackProjector projector = new TrackProjector(); - projector.setB(B); - - //Input to be read - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/update_protons_to_test_with_tracks.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - HitFinder hitfinder = new HitFinder(); - - int event_number = 0; - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - event_number++; - projector.ProjectTracks(event); - hitfinder.FindHits(event, atof, projector); - ClusterFinder clusterfinder = new ClusterFinder(); - clusterfinder.MakeClusters(hitfinder); - } - } - -} - - - - -/* -// Exhibits more modular approach, and parameters/thresholds for clustering -// -package org.jlab.rec.atof.cluster; - -import cnuphys.magfield.MagneticFields; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; -import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; -import org.jlab.rec.atof.hit.AtofHit; -import org.jlab.rec.atof.hit.BarHit; -import org.jlab.rec.atof.hit.HitFinder; -import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; - - -// @authors npilleux, churaman - -public class ClusterFinder { - - private static final Logger logger = Logger.getLogger(ClusterFinder.class.getName()); - private List clusters; -//can be replaced with actual values - private final double sigmaPhi = 6.0; // Angle opening of a layer - private final double sigmaZ = 6000.0; // Z threshold in mm - private final double sigmaT = 1000.0; // Timing resolution in ns - private final int sigmaModule = 1; // Module proximity threshold - private final int sigmaComponent = 1; // Component proximity threshold - - public ClusterFinder() { - this.clusters = new ArrayList<>(); } - public List getClusters() { - return clusters; - } - - public void setClusters(List clusters) { - this.clusters = clusters; - } - - public void makeClusters(HitFinder hitFinder) { - clusters.clear(); - List wedgeHits = hitFinder.getWedgeHits(); - List barHits = hitFinder.getBarHits(); - - clusterWedgeHits(wedgeHits, barHits); - clusterRemainingBarHits(barHits); - - logger.info("Clustering completed: " + clusters.size() + " clusters formed."); - } - - private void clusterWedgeHits(List wedgeHits, List barHits) { - for (int i = 0; i < wedgeHits.size(); i++) { - AtofHit primaryHit = wedgeHits.get(i); - if (primaryHit.getIs_in_a_cluster()) continue; - - List clusterWedgeHits = new ArrayList<>(); - List clusterBarHits = new ArrayList<>(); - - primaryHit.setIs_in_a_cluster(true); - clusterWedgeHits.add(primaryHit); - - addNearbyWedgeHits(primaryHit, wedgeHits, clusterWedgeHits); - addNearbyBarHits(primaryHit, barHits, clusterBarHits); - - clusters.add(new AtofCluster(clusterBarHits, clusterWedgeHits)); - } - } - - private void addNearbyWedgeHits(AtofHit primaryHit, List wedgeHits, List clusterWedgeHits) { - for (AtofHit hit : wedgeHits) { - if (hit.getIs_in_a_cluster()) continue; - - if (isHitInProximity(primaryHit, hit)) { - hit.setIs_in_a_cluster(true); - clusterWedgeHits.add(hit); - } - } - } - - private void addNearbyBarHits(AtofHit primaryHit, List barHits, List clusterBarHits) { - for (BarHit hit : barHits) { - if (hit.getIs_in_a_cluster()) continue; - - if (isHitInProximity(primaryHit, hit)) { - hit.setIs_in_a_cluster(true); - clusterBarHits.add(hit); - } - } - } - - private void clusterRemainingBarHits(List barHits) { - for (int i = 0; i < barHits.size(); i++) { - BarHit primaryHit = barHits.get(i); - if (primaryHit.getIs_in_a_cluster()) continue; - - List clusterBarHits = new ArrayList<>(); - primaryHit.setIs_in_a_cluster(true); - clusterBarHits.add(primaryHit); - - for (int j = i + 1; j < barHits.size(); j++) { - BarHit secondaryHit = barHits.get(j); - if (secondaryHit.getIs_in_a_cluster()) continue; - - if (isHitInProximity(primaryHit, secondaryHit)) { - secondaryHit.setIs_in_a_cluster(true); - clusterBarHits.add(secondaryHit); - } - } - - clusters.add(new AtofCluster(clusterBarHits, new ArrayList<>())); - } - } - -private boolean isHitInProximity(AtofHit hit1, AtofHit hit2) { - // Check if both hits are wedge hits - if (!"wedge".equals(hit1.getType()) || !"wedge".equals(hit2.getType())) { - return false; // Return false if either hit is not a wedge - } - - int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); - deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; - - int deltaComponent = Math.abs(hit1.getComponent() - hit2.getComponent()); - double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); - - return deltaModule <= sigmaModule && deltaComponent <= sigmaComponent && deltaT < sigmaT; -} - -private boolean isHitInProximity(AtofHit hit1, BarHit hit2) { - // Ensures that the AtofHit is of type "wedge" - if (!"wedge".equals(hit1.getType())) { - return false; - } - - // Computes module difference with circular boundary handling - int deltaModule = Math.abs(hit1.computeModule_index() - hit2.computeModule_index()); - deltaModule = deltaModule > 30 ? 60 - deltaModule : deltaModule; - - // Computes spatial and temporal proximity - double deltaZ = Math.abs(hit1.getZ() - hit2.getZ()); - double deltaT = Math.abs(hit1.getTime() - hit2.getTime()); - - // Returns true if all proximity conditions are satisfied - return deltaModule <= sigmaModule && deltaZ < sigmaZ && deltaT < sigmaT; -} - - - public static void main(String[] args) { - AlertTOFFactory factory = new AlertTOFFactory(); - DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - Detector atof = factory.createDetectorCLAS(cp); - - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields( - mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", - "Symm_solenoid_r601_phi1_z1201_13June2018.dat" - ); - } catch (Exception e) { - logger.severe("Error initializing magnetic fields: " + e.getMessage()); - } - - TrackProjector projector = new TrackProjector(); - projector.setB(new Swim().BfieldLab(0, 0, 0, new float[3])[2]); - - String inputFile = "/path/to/input.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(inputFile); - - HitFinder hitFinder = new HitFinder(); - - while (reader.hasEvent()) { - DataEvent event = reader.getNextEvent(); - projector.ProjectTracks(event); - hitFinder.FindHits(event, atof, projector); - - ClusterFinder clusterFinder = new ClusterFinder(); - clusterFinder.makeClusters(hitFinder); - - logger.info("Processed event with " + clusterFinder.getClusters().size() + " clusters."); - } - } } -*/ - diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java index 2c15a5200b..9a5868f82a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/constants/Parameters.java @@ -2,18 +2,15 @@ /** * - * @authors npilleux,churaman + * @author npilleux */ public class Parameters { - Parameters() { - } - //In millimiters - public static final double BAR_INNER_RADIUS = 77; - public static final double WEDGE_INNER_RADIUS = 80; - public static final double BAR_THICKNESS = 3; - public static final double WEDGE_THICKNESS = 20; + public static final double BAR_INNER_RADIUS = 77;//mm + public static final double WEDGE_INNER_RADIUS = 80;//mm + public static final double BAR_THICKNESS = 3;//mm + public static final double WEDGE_THICKNESS = 20;//mm public static final double BAR_MIDDLE_RADIUS = BAR_INNER_RADIUS + BAR_THICKNESS / 2; public static final double WEDGE_MIDDLE_RADIUS = WEDGE_INNER_RADIUS + WEDGE_THICKNESS / 2; @@ -33,6 +30,10 @@ public class Parameters { public static double SIGMA_Z_TRACK_MATCHING_WEDGE = 200;//in mm public static double SIGMA_PHI_CLUSTERING = 6;//in deg + public static double SIGMA_Z_CLUSTERING = 200;//in mm + public static double SIGMA_MODULE_CLUSTERING = 1; + public static double SIGMA_COMPONENT_CLUSTERING = 1; + public static double SIGMA_T_CLUSTERING = 100;// in ns /** * @param args the command line arguments From 4ab2fc035b5775bb84ec3c99264d41a3d8fce86c Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:38:12 -0600 Subject: [PATCH 63/82] cluster parameters definition --- .../jlab/rec/atof/Cluster/AtofCluster.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 87c8950823..b610e740ae 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -1,20 +1,19 @@ package org.jlab.rec.atof.cluster; + import java.util.ArrayList; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; /** * - * @authors npilleux, churaman + * @author npilleux */ - - public class AtofCluster { ArrayList bar_hits; ArrayList wedge_hits; double x,y,z,time,energy; - double path_length; + double path_length, inpath_length; public ArrayList getBarHits() { return bar_hits; @@ -80,9 +79,16 @@ public void setPath_length(double path_length) { this.path_length = path_length; } + public double getInpath_length() { + return inpath_length; + } + + public void setInpath_length(double inpath_length) { + this.inpath_length = inpath_length; + } + //Cluster coordinates and time are defined as the coordinates and time of the max energy hit //Can be changed later - public final void computeClusterProperties() { this.energy=0; double max_energy = -1; @@ -112,6 +118,7 @@ public final void computeClusterProperties() { this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); this.path_length = max_energy_hit.getPath_length(); + this.inpath_length = max_energy_hit.getInpath_length(); } else { @@ -120,8 +127,8 @@ public final void computeClusterProperties() { this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); this.path_length = max_energy_barhit.getPath_length(); + this.inpath_length = max_energy_barhit.getInpath_length(); } - } public double getPhi() @@ -129,6 +136,11 @@ public double getPhi() return Math.atan2(this.y, this.x); } + public double getBeta() + { + return (this.path_length / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c + } + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { this.bar_hits = bar_hits; From dce50ef0c1cc4946cfbd2be2856dda7b6da7385c Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:39:53 -0600 Subject: [PATCH 64/82] fix hit order --- .../alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 02e32eec52..597b082afe 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -159,9 +159,9 @@ public final String makeType() { //Type of hit can be wedge, bar up, bar down or bar. //Avoids testing components and order every time. String itype = "undefined"; - if (this.component == 10 && this.order == 0) { + if (this.component == 10 && this.order == 1) { itype = "bar down"; - } else if (this.component == 10 && this.order == 1) { + } else if (this.component == 10 && this.order == 0) { itype = "bar up"; } else if (this.component < 10) { itype = "wedge"; @@ -492,7 +492,8 @@ public int matchTrack(DataEvent event) { yt = track_bank.getFloat("y_at_wedge", i); zt = track_bank.getFloat("z_at_wedge", i); path = track_bank.getFloat("L_at_wedge", i); - inpath = track_bank.getFloat("L_in_wedge", i); + //A wedge hit traveled through the whole bar and then through a portion of the wedge + inpath = track_bank.getFloat("L_in_wedge", i) + track_bank.getFloat("L_at_wedge", i) - track_bank.getFloat("L_at_bar", i); } case "bar" -> { sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; From 21934c1165c73661185973e372eb53af316940fb Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:41:35 -0600 Subject: [PATCH 65/82] cluster bank definition --- etc/bankdefs/hipo4/alert.json | 48 +++++++++++++++++++ .../jlab/rec/atof/banks/RecoBankWriter.java | 32 ++++++++++--- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index ea6f4e251b..775cfba259 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -99,6 +99,54 @@ "info": "path length to the hit in mm" } ] + },{ + "name": "ATOF::clusters", + "group": 22500, + "item": 22, + "info": "Clusters in ATOF", + "entries": [ + { + "name": "id", + "type": "S", + "info": "hit id" + }, { + "name": "barsize", + "type": "I", + "info": "number of hits from the bars" + }, { + "name": "wedgesize", + "type": "I", + "info": "number of hits from the wedges" + },{ + "name": "time", + "type": "F", + "info": "time in ns" + },{ + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + },{ + "name": "energy", + "type": "F", + "info": "energy in MeV" + },{ + "name": "pathlength", + "type": "F", + "info": "path length to the cluster in mm" + },{ + "name": "inpathlength", + "type": "F", + "info": "path length inside the detector in mm" + } + ] },{ "name": "AHDC::Hits", "group": 23000, diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index c87040d17e..299a50bf1f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -1,21 +1,17 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template - */ package org.jlab.rec.atof.banks; import java.util.ArrayList; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; +import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.hit.AtofHit; /** * - * @authors npilleux,churaman + * @author npilleux */ public class RecoBankWriter { - // write useful information in the bank public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitlist) { DataBank bank = event.createBank("ATOF::hits", hitlist.size()); @@ -42,6 +38,30 @@ public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitli } return bank; } + + public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterlist) { + + DataBank bank = event.createBank("ATOF::clusters", clusterlist.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + return null; + } + + for(int i =0; i< clusterlist.size(); i++) { + bank.setShort("id",i, (short)(i+1)); + bank.setInt("barsize",i, (int) clusterlist.get(i).getBarHits().size()); + bank.setInt("wedgesize",i, (int) clusterlist.get(i).getWedgeHits().size()); + 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()); + bank.setFloat("inpathlength",i, (float) (clusterlist.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (clusterlist.get(i).getPath_length())); + } + return bank; + } /** * @param args the command line arguments From 74ab5887d6addfc207dee7b3df4ac89c12d73ec9 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 3 Feb 2025 09:42:19 -0600 Subject: [PATCH 66/82] charge sign fix and projection from MC Particle info --- .../rec/atof/TrackMatch/TrackProjector.java | 63 ++++++++++++++++--- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index 90d5936b89..225ebf4842 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -11,6 +11,9 @@ import org.jlab.clas.swimtools.Swim; import org.jlab.utils.CLASResources; import cnuphys.magfield.MagneticFields; +import java.io.BufferedWriter; +import java.io.IOException; +import org.jlab.geom.prim.Point3D; import org.jlab.rec.atof.constants.Parameters; /** @@ -109,7 +112,6 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) int nt = bank.rows(); // number of tracks TrackProjection projection = new TrackProjection(); DataBank outputBank = event.createBank("AHDC::Projections", nt); - for (int i = 0; i < nt; i++) { double x = bank.getFloat("x", i); @@ -119,7 +121,7 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) double py = bank.getFloat("py", i); double pz = bank.getFloat("pz", i); - int q = 1; //need the charge sign from tracking + int q = -1; //need the charge sign from tracking Units units = Units.MM; //can be MM or CM. @@ -158,7 +160,6 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Projections.clear(); String track_bank_name = "MC::Particle"; - if (event == null) { // check if there is an event //System.out.print(" no event \n"); } else if (event.hasBank(track_bank_name) == false) { @@ -187,7 +188,7 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Units units = Units.MM; - int q = 1; //need the charge sign from tracking + int q = -1; //need the charge sign from tracking double xb = 0; double yb = 0; @@ -196,7 +197,6 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); @@ -215,6 +215,55 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd event.appendBank(outputBank); } } + + public void projectMCTracks_full_path(DataEvent event, int num_event, BufferedWriter writer) throws IOException { + + String track_bank_name = "MC::Particle"; + if (event == null) { // check if there is an event + //System.out.print(" no event \n"); + } else if (event.hasBank(track_bank_name) == false) { + // check if there are ahdc tracks in the event + //System.out.print("no tracks \n"); + } else { + DataBank bank = event.getBank(track_bank_name); + int nt = bank.rows(); // number of tracks + + for (int i = 0; i < nt; i++) { + + double x = bank.getFloat("vx", i); + double y = bank.getFloat("vy", i); + double z = bank.getFloat("vz", i); + double px = bank.getFloat("px", i); + double py = bank.getFloat("py", i); + double pz = bank.getFloat("pz", i); + + //Put everything in MM + + x = x*10; + y = y*10; + z = z*10; + + Units units = Units.MM; + + int q = -1; //need the charge sign from tracking + + double xb = 0; + double yb = 0; + + //momenta must be in GeV for the helix class + Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + + double min = 0.1; + double max = Parameters.WEDGE_INNER_RADIUS+Parameters.WEDGE_THICKNESS; + int nsteps = 20; + double step = (max-min)/nsteps; + for(double i_radius = min; i_radius Date: Mon, 3 Feb 2025 09:47:36 -0600 Subject: [PATCH 67/82] draft atof engine to be completed --- .../java/org/jlab/rec/service/ATOFEngine.java | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java new file mode 100644 index 0000000000..4f9473c830 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -0,0 +1,157 @@ +package org.jlab.rec.service; + +import cnuphys.magfield.MagneticFields; +import java.util.ArrayList; + +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.io.hipo.HipoDataSync; + +import java.util.concurrent.atomic.AtomicInteger; +import org.jlab.clas.swimtools.Swim; +import org.jlab.detector.calib.utils.DatabaseConstantProvider; +import org.jlab.geom.base.Detector; +import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.rec.atof.banks.RecoBankWriter; +import org.jlab.rec.atof.cluster.AtofCluster; +import org.jlab.rec.atof.cluster.ClusterFinder; +import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.hit.HitFinder; +import org.jlab.rec.atof.trackMatch.TrackProjector; +import org.jlab.utils.CLASResources; + +/** + * Service to return reconstructed ATOF hits and clusters + * + * @author npilleux + * + */ +public class ATOFEngine extends ReconstructionEngine { + + public ATOFEngine() { + super("ATOF", "pilleux", "1.0"); + } + + //int Run = -1; + RecoBankWriter rbc; + + private final AtomicInteger Run = new AtomicInteger(0); + private Detector ATOF; + private double B; //Magnetic field + + @Override + public boolean processDataEvent(DataEvent event) { + + if (!event.hasBank("RUN::config")) { + return true; + } + + DataBank bank = event.getBank("RUN::config"); + + // Load the constants + //------------------- + int newRun = bank.getInt("run", 0); + if (newRun == 0) { + return true; + } + + if (Run.get() == 0 || (Run.get() != 0 && Run.get() != newRun)) { + Run.set(newRun); + } + + //CalibrationConstantsLoader constantsLoader = new CalibrationConstantsLoader(newRun, this.getConstantsManager()); + + //Track Projector Initialisation with B field + TrackProjector projector = new TrackProjector(); + projector.setB(this.B); + projector.ProjectTracks(event); + + //Hit finder init + HitFinder hitfinder = new HitFinder(); + hitfinder.FindHits(event, ATOF); + + ArrayList WedgeHits = hitfinder.getWedgeHits(); + ArrayList BarHits = hitfinder.getBarHits(); + + //1) exit if halfhit list is empty + if (WedgeHits.isEmpty() && BarHits.isEmpty()) { + // System.out.println("No hits : "); + // event.show(); + return true; + } + + + ClusterFinder clusterFinder = new ClusterFinder(); + clusterFinder.makeClusters(event,hitfinder); + ArrayList clusters = clusterFinder.getClusters(); + + if (WedgeHits.size() != 0 || BarHits.size() != 0) { + //rbc.appendBanks(event, hits, cndclusters); + } + return true; + } + + @Override + public boolean init() { + rbc = new RecoBankWriter(); + + AlertTOFFactory factory = new AlertTOFFactory(); + DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); + this.ATOF = factory.createDetectorCLAS(cp); + + //READING MAG FIELD MAP + System.setProperty("CLAS12DIR", "../../"); + String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; + try { + MagneticFields.getInstance().initializeMagneticFields(mapDir, + "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); + } catch (Exception e) { + e.printStackTrace(); + } + float[] b = new float[3]; + Swim swimmer = new Swim(); + swimmer.BfieldLab(0, 0, 0, b); + this.B = Math.abs(b[2]); + + //requireConstants(Arrays.asList(CalibrationConstantsLoader.getCndTables())); + //this.getConstantsManager().setVariation("default"); + + this.registerOutputBank("CND::hits", "CND::clusters"); + + return true; + } + + public static void main(String arg[]) { + ATOFEngine en = new ATOFEngine(); + + en.init(); + String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/mixed_ions.hipo"; + HipoDataSource reader = new HipoDataSource(); + reader.open(input); + //String outputFile = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/tester.hipo"; + //HipoDataSync writer = new HipoDataSync(); + //writer.open(outputFile); + + while (reader.hasEvent()) { + DataEvent event = (DataEvent) reader.getNextEvent(); + en.processDataEvent(event); + //writer.writeEvent(event); + } + + //writer.close(); + + //HipoDataSource sortie = new HipoDataSource(); + //sortie.open(outputFile); + + //System.out.println("Fichier de sortie : "); + //while (sortie.hasEvent()) { + + // DataEvent event = (DataEvent) sortie.getNextEvent(); + //event.show(); + //} + } + +} From de817c4c4939766b3da2a8f79ecbc2894226b08e Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 6 Feb 2025 15:24:54 -0600 Subject: [PATCH 68/82] appending output banks --- .../jlab/rec/atof/banks/RecoBankWriter.java | 25 ++++++- .../java/org/jlab/rec/service/ATOFEngine.java | 71 +++++++++---------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 299a50bf1f..066a3ceea3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -5,6 +5,7 @@ import org.jlab.io.base.DataEvent; import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.BarHit; /** * @@ -12,7 +13,11 @@ */ public class RecoBankWriter { - public static DataBank fillAtofHitBank(DataEvent event, ArrayList hitlist) { + public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits) { + + ArrayList hitlist = new ArrayList<>(); + hitlist.addAll(wedge_hits); + hitlist.addAll(bar_hits); DataBank bank = event.createBank("ATOF::hits", hitlist.size()); @@ -62,12 +67,28 @@ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits, ArrayList clusterlist) { + + DataBank hitbank = this.fillAtofHitBank(event, wedge_hits, bar_hits); + if (hitbank != null) { + event.appendBank(hitbank); + } + else return 1; + + DataBank clusterbank = fillAtofClusterBank(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) { - // TODO code application logic here } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java index 4f9473c830..58f40ad415 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -7,7 +7,6 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import org.jlab.io.hipo.HipoDataSync; import java.util.concurrent.atomic.AtomicInteger; import org.jlab.clas.swimtools.Swim; @@ -35,12 +34,25 @@ public ATOFEngine() { super("ATOF", "pilleux", "1.0"); } - //int Run = -1; RecoBankWriter rbc; private final AtomicInteger Run = new AtomicInteger(0); private Detector ATOF; private double B; //Magnetic field + + //Setters and getters + public void setB(double B) { + this.B = B; + } + public double getB() { + return B; + } + public void setATOF(Detector ATOF) { + this.ATOF = ATOF; + } + public Detector getATOF() { + return ATOF; + } @Override public boolean processDataEvent(DataEvent event) { @@ -76,20 +88,19 @@ public boolean processDataEvent(DataEvent event) { ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); - //1) exit if halfhit list is empty + //Exit if hit lists are empty if (WedgeHits.isEmpty() && BarHits.isEmpty()) { // System.out.println("No hits : "); // event.show(); return true; } - - + ClusterFinder clusterFinder = new ClusterFinder(); clusterFinder.makeClusters(event,hitfinder); - ArrayList clusters = clusterFinder.getClusters(); + ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - //rbc.appendBanks(event, hits, cndclusters); + rbc.appendATOFBanks(event, WedgeHits, BarHits, Clusters); } return true; } @@ -102,7 +113,18 @@ public boolean init() { DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); this.ATOF = factory.createDetectorCLAS(cp); - //READING MAG FIELD MAP + //requireConstants(Arrays.asList(CalibrationConstantsLoader.getAtofTables())); + //this.getConstantsManager().setVariation("default"); + + this.registerOutputBank("ATOF::hits", "ATOF::clusters"); + + return true; + } + + public static void main(String arg[]) { + ATOFEngine en = new ATOFEngine(); + + //READING MAG FIELD MAP System.setProperty("CLAS12DIR", "../../"); String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; try { @@ -114,44 +136,17 @@ public boolean init() { float[] b = new float[3]; Swim swimmer = new Swim(); swimmer.BfieldLab(0, 0, 0, b); - this.B = Math.abs(b[2]); - - //requireConstants(Arrays.asList(CalibrationConstantsLoader.getCndTables())); - //this.getConstantsManager().setVariation("default"); - - this.registerOutputBank("CND::hits", "CND::clusters"); - - return true; - } - - public static void main(String arg[]) { - ATOFEngine en = new ATOFEngine(); + en.setB(Math.abs(b[2])); en.init(); String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/mixed_ions.hipo"; HipoDataSource reader = new HipoDataSource(); reader.open(input); - //String outputFile = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/tester.hipo"; - //HipoDataSync writer = new HipoDataSync(); - //writer.open(outputFile); - + while (reader.hasEvent()) { DataEvent event = (DataEvent) reader.getNextEvent(); en.processDataEvent(event); - //writer.writeEvent(event); + event.getBank("ATOF::clusters").show(); } - - //writer.close(); - - //HipoDataSource sortie = new HipoDataSource(); - //sortie.open(outputFile); - - //System.out.println("Fichier de sortie : "); - //while (sortie.hasEvent()) { - - // DataEvent event = (DataEvent) sortie.getNextEvent(); - //event.show(); - //} } - } From c94715f669bda1d28979d6fc1492bbfd5a4df508 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Thu, 6 Feb 2025 15:53:40 -0600 Subject: [PATCH 69/82] fix:but writing output banks --- .../main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java | 6 ++---- .../src/main/java/org/jlab/rec/atof/Hit/HitFinder.java | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index fba46b565c..d13e96b958 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -13,7 +13,6 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofClusterBank; import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; @@ -174,8 +173,8 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } - DataBank clusterbank = fillAtofClusterBank(event, clusters); - event.appendBank(clusterbank); + //DataBank clusterbank = fillAtofClusterBank(event, clusters); + //event.appendBank(clusterbank); } public ClusterFinder() { @@ -187,5 +186,4 @@ public ClusterFinder() { */ public static void main(String[] args) { } - } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index c875f67635..748ff8dfef 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -13,7 +13,6 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; -import static org.jlab.rec.atof.banks.RecoBankWriter.fillAtofHitBank; import org.jlab.rec.atof.trackMatch.TrackProjector; import org.jlab.utils.CLASResources; @@ -178,16 +177,12 @@ public void FindHits(DataEvent event, Detector atof) { //Once all has been listed, hits are sorted by energy Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - ArrayList allhits = new ArrayList<>(); - allhits.addAll(this.wedge_hits); - allhits.addAll(this.bar_hits); - DataBank hitbank = fillAtofHitBank(event, allhits); - event.appendBank(hitbank); } /** * @param args the command line arguments */ public static void main(String[] args) { + } } From 05ac12b0812401918ea18836335dc739108c2647 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Tue, 11 Feb 2025 16:08:11 -0600 Subject: [PATCH 70/82] style: naming conventions and some cleaning --- .../jlab/rec/atof/Cluster/AtofCluster.java | 54 +++++------ .../jlab/rec/atof/Cluster/ClusterFinder.java | 15 --- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 97 +++++++++---------- .../java/org/jlab/rec/atof/Hit/BarHit.java | 38 +++----- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 60 +++++------- .../jlab/rec/atof/banks/RecoBankWriter.java | 68 +++++++------ .../java/org/jlab/rec/service/ATOFEngine.java | 79 ++++----------- 7 files changed, 166 insertions(+), 245 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index b610e740ae..fd1ef4a519 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -10,25 +10,25 @@ */ public class AtofCluster { - ArrayList bar_hits; - ArrayList wedge_hits; + ArrayList barHits; + ArrayList wedgeHits; double x,y,z,time,energy; - double path_length, inpath_length; + double pathLength, inPathLength; public ArrayList getBarHits() { - return bar_hits; + return barHits; } public void setBarHits(ArrayList bar_hits) { - this.bar_hits = bar_hits; + this.barHits = bar_hits; } public ArrayList getWedgeHits() { - return wedge_hits; + return wedgeHits; } public void setWedgeHits(ArrayList wedge_hits) { - this.wedge_hits = wedge_hits; + this.wedgeHits = wedge_hits; } public double getX() { @@ -71,20 +71,20 @@ public void setEnergy(double energy) { this.energy = energy; } - public double getPath_length() { - return path_length; + public double getPathLength() { + return pathLength; } - public void setPath_length(double path_length) { - this.path_length = path_length; + public void setPathLength(double pathLength) { + this.pathLength = pathLength; } - public double getInpath_length() { - return inpath_length; + public double getInPathLength() { + return inPathLength; } - public void setInpath_length(double inpath_length) { - this.inpath_length = inpath_length; + public void setInPathLength(double inPathLength) { + this.inPathLength = inPathLength; } //Cluster coordinates and time are defined as the coordinates and time of the max energy hit @@ -95,17 +95,17 @@ public final void computeClusterProperties() { AtofHit max_energy_hit = new AtofHit(); BarHit max_energy_barhit = new BarHit(); - for(int i_wedge = 0; i_wedgemax_energy){max_energy_hit = this_wedge_hit; max_energy = this_energy;} } - for(int i_bar = 0; i_barmax_energy){max_energy_barhit = this_bar_hit; max_energy = this_energy;} @@ -117,8 +117,8 @@ public final void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); - this.path_length = max_energy_hit.getPath_length(); - this.inpath_length = max_energy_hit.getInpath_length(); + this.pathLength = max_energy_hit.getPath_length(); + this.inPathLength = max_energy_hit.getInpath_length(); } else { @@ -126,11 +126,11 @@ public final void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); - this.path_length = max_energy_barhit.getPath_length(); - this.inpath_length = max_energy_barhit.getInpath_length(); + this.pathLength = max_energy_barhit.getPath_length(); + this.inPathLength = max_energy_barhit.getInpath_length(); } } - + public double getPhi() { return Math.atan2(this.y, this.x); @@ -138,13 +138,13 @@ public double getPhi() public double getBeta() { - return (this.path_length / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c + return (this.pathLength / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c } public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { - this.bar_hits = bar_hits; - this.wedge_hits = wedge_hits; + this.barHits = bar_hits; + this.wedgeHits = wedge_hits; this.computeClusterProperties(); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index d13e96b958..3bc3df6236 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -1,24 +1,11 @@ package org.jlab.rec.atof.cluster; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; -import javax.swing.JFrame; -import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.groot.data.H1F; -import org.jlab.groot.data.H2F; -import org.jlab.groot.graphics.EmbeddedCanvas; -import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; -import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; /** * @@ -173,8 +160,6 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); clusters.add(cluster); } - //DataBank clusterbank = fillAtofClusterBank(event, clusters); - //event.appendBank(clusterbank); } public ClusterFinder() { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 597b082afe..41de05aa21 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -2,12 +2,9 @@ import java.util.List; import org.jlab.geom.base.*; -import org.jlab.geom.detector.alert.ATOF.*; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.prim.Point3D; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.trackMatch.TrackProjection; import org.jlab.rec.atof.trackMatch.TrackProjector; @@ -24,11 +21,11 @@ public class AtofHit { private int sector, layer, component, order; - private int TDC, ToT; + private int tdc, tot; private double time, energy, x, y, z; private String type; - private boolean is_in_a_cluster; - private double path_length, inpath_length; + private boolean isInACluster; + private double pathLength, inPathLength; public int getSector() { return sector; @@ -62,20 +59,20 @@ public void setComponent(int component) { this.component = component; } - public int getTDC() { - return TDC; + public int getTdc() { + return tdc; } - public void setTDC(int tdc) { - this.TDC = tdc; + public void setTdc(int tdc) { + this.tdc = tdc; } - public int getToT() { - return ToT; + public int getTot() { + return tot; } - public void setToT(int tot) { - this.ToT = tot; + public void setTot(int tot) { + this.tot = tot; } public double getTime() { @@ -126,31 +123,31 @@ public void setType(String type) { this.type = type; } - public boolean getIs_in_a_cluster() { - return is_in_a_cluster; + public boolean getIsInACluster() { + return isInACluster; } - public void setIs_in_a_cluster(boolean is_in_a_cluster) { - this.is_in_a_cluster = is_in_a_cluster; + public void setIsInACluster(boolean is_in_a_cluster) { + this.isInACluster = is_in_a_cluster; } - public double getPath_length() { - return path_length; + public double getPathLength() { + return pathLength; } - public void setPath_length(double path_length) { - this.path_length = path_length; + public void setPathLength(double path_length) { + this.pathLength = path_length; } - public double getInpath_length() { - return inpath_length; + public double getInPathLength() { + return inPathLength; } - public void setInpath_length(double inpath_length) { - this.inpath_length = inpath_length; + public void setInPathLength(double inpath_length) { + this.inPathLength = inpath_length; } - public int computeModule_index() { + public int computeModuleIndex() { //Index ranging 0 to 60 for each wedge+bar module return 4 * this.sector + this.layer; } @@ -178,7 +175,7 @@ public final String makeType() { * @return 0 if the time was successfully set, or 1 if the hit type is * unsupported. */ - public final int TDC_to_time() { + 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."); @@ -214,7 +211,7 @@ public final int TDC_to_time() { } } //Hit time. Will need implementation of offsets. - this.time = tdc2time * this.TDC - distance_to_sipm / veff; + this.time = tdc2time * this.tdc - distance_to_sipm / veff; return 0; } @@ -226,7 +223,7 @@ public final int TDC_to_time() { * @return 0 if the energy was successfully set, or 1 if the hit type is * unsupported. */ - public final int ToT_to_energy() { + public final int convertTotToEnergy() { double tot2energy; if (null == this.type) { System.out.print("Null hit type, cannot convert tot to energy."); @@ -238,19 +235,19 @@ public final int ToT_to_energy() { //For now hits are considered in the middle of the wedge //And the SiPM on top double distance_hit_to_sipm = Parameters.WEDGE_THICKNESS / 2.; - this.energy = tot2energy * this.ToT * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); + this.energy = tot2energy * this.tot * Math.exp(distance_hit_to_sipm / Parameters.ATT_L); } case "bar up" -> { tot2energy = Parameters.TOT2ENERGY_BAR; //only half the information in the bar, //the attenuation will be computed when the full hit is formed - this.energy = tot2energy * this.ToT; + this.energy = tot2energy * this.tot; } case "bar down" -> { tot2energy = Parameters.TOT2ENERGY_BAR; //only half the information in the bar, //the attenuation will be computed when the full hit is formed - this.energy = tot2energy * this.ToT; + this.energy = tot2energy * this.tot; } case "bar" -> { System.out.print("Bar hit type, cannot convert tot to energy."); @@ -275,7 +272,7 @@ public final int ToT_to_energy() { * @return 0 if the coordinates were successfully set, or 1 if the hit type * is undefined or unsupported. */ - public final int slc_to_xyz(Detector atof) { + public final int convertSLCToXYZ(Detector atof) { int sl; if (null == this.type) { return 1; @@ -364,17 +361,17 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.layer = layer; this.component = component; this.order = order; - this.TDC = tdc; - this.ToT = tot; - this.is_in_a_cluster = false; + this.tdc = tdc; + this.tot = tot; + this.isInACluster = false; this.makeType(); - int is_ok = this.TDC_to_time(); + int is_ok = this.convertTdcToTime(); if (is_ok != 1) { - is_ok = this.ToT_to_energy(); + is_ok = this.convertTotToEnergy(); } if (is_ok != 1) { - is_ok = this.slc_to_xyz(atof); + is_ok = this.convertSLCToXYZ(atof); } } @@ -398,19 +395,19 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.layer = layer; this.component = component; this.order = order; - this.TDC = tdc; - this.ToT = tot; - this.is_in_a_cluster = false; + this.tdc = tdc; + this.tot = tot; + this.isInACluster = false; //First the type needs to be set this.makeType(); //From it the coordinates can be computed - this.slc_to_xyz(atof); + this.convertSLCToXYZ(atof); //From them tracks can be matched this.matchTrack(track_projector); //And energy and time can then be computed - this.ToT_to_energy(); - this.TDC_to_time(); + this.convertTotToEnergy(); + this.convertTdcToTime(); } /** @@ -452,9 +449,9 @@ public final void matchTrack(TrackProjector track_projector) { if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { - this.setPath_length(Projections.get(i_track).get_WedgePathLength()); + this.setPathLength(Projections.get(i_track).get_WedgePathLength()); } else { - this.setPath_length(Projections.get(i_track).get_BarPathLength()); + this.setPathLength(Projections.get(i_track).get_BarPathLength()); } } } @@ -514,8 +511,8 @@ public int matchTrack(DataEvent event) { Point3D projection_point = new Point3D(xt, yt, zt); if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - this.setPath_length(path); - this.setInpath_length(inpath); + this.setPathLength(path); + this.setInPathLength(inpath); } } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java index 8b13a978ca..7bba7a1ab2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java @@ -1,12 +1,5 @@ package org.jlab.rec.atof.hit; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; -import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; -import java.util.ArrayList; import org.jlab.rec.atof.constants.Parameters; /** @@ -20,22 +13,22 @@ public class BarHit extends AtofHit { //A bar hit is the combination of a downstream and upstream hits - private AtofHit hit_up, hit_down; + private AtofHit hitUp, hitDown; public AtofHit getHitUp() { - return hit_up; + return hitUp; } public void setHitUp(AtofHit hit_up) { - this.hit_up = hit_up; + this.hitUp = hit_up; } public AtofHit getHitDown() { - return hit_down; + return hitDown; } public void setHitDown(AtofHit hit_down) { - this.hit_down = hit_down; + this.hitDown = hit_down; } /** @@ -43,7 +36,7 @@ public void setHitDown(AtofHit hit_down) { * */ public final void computeZ() { - this.setZ(Parameters.VEFF/2. * (hit_up.getTime() - hit_down.getTime())); + this.setZ(Parameters.VEFF/2. * (hitUp.getTime() - hitDown.getTime())); } /** @@ -55,12 +48,12 @@ public final void computeZ() { public final void computeTime() { //We pick the most energetic signal as the timing signal double time_at_sipm, distance_to_sipm; - if(this.hit_down.getEnergy() > this.hit_up.getEnergy()) { - time_at_sipm = this.hit_down.getTime(); + if(this.hitDown.getEnergy() > this.hitUp.getEnergy()) { + time_at_sipm = this.hitDown.getTime(); distance_to_sipm = Parameters.LENGTH_ATOF/2. - this.getZ(); } else { - time_at_sipm = this.hit_up.getTime(); + time_at_sipm = this.hitUp.getTime(); distance_to_sipm = Parameters.LENGTH_ATOF/2. + this.getZ(); } this.setTime(time_at_sipm - distance_to_sipm/Parameters.VEFF); @@ -76,8 +69,8 @@ public final void computeEnergy() { this.computeZ(); double distance_hit_to_sipm_up = Parameters.LENGTH_ATOF / 2. + this.getZ(); double distance_hit_to_sipm_down = Parameters.LENGTH_ATOF / 2. - this.getZ(); - double Edep_up = hit_up.getEnergy() * Math.exp(distance_hit_to_sipm_up / Parameters.ATT_L); - double Edep_down = hit_down.getEnergy() * Math.exp(distance_hit_to_sipm_down / Parameters.ATT_L); + 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); } @@ -88,8 +81,8 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { } this.setType("bar"); this.setOrder(2);//Fake order for bar hits - this.hit_up = hit_up; - this.hit_down = hit_down; + this.hitUp = hit_up; + this.hitDown = hit_down; this.setLayer(hit_up.getLayer()); this.setSector(hit_up.getSector()); this.setComponent(10); @@ -101,10 +94,9 @@ public BarHit(AtofHit hit_down, AtofHit hit_up) { } public BarHit() { - super(); // Call AtofHit constructor - //Sets some parameters to make a bar type hit + super(); this.setType("bar"); - this.setOrder(2); + this.setOrder(2);//Fake order for bar hits } /** diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index 748ff8dfef..8f45d28217 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -1,20 +1,11 @@ package org.jlab.rec.atof.hit; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import java.util.Collections; -import javax.swing.JFrame; -import org.jlab.clas.swimtools.Swim; -import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; -import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; -import org.jlab.groot.data.H1F; -import org.jlab.groot.graphics.EmbeddedCanvas; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; /** * @@ -22,37 +13,35 @@ */ public class HitFinder { - private ArrayList bar_hits; - private ArrayList wedge_hits; + private ArrayList barHits; + private ArrayList wedgeHits; public HitFinder() { - this.bar_hits = new ArrayList<>(); - this.wedge_hits = new ArrayList<>(); + this.barHits = new ArrayList<>(); + this.wedgeHits = new ArrayList<>(); } - // Getter and Setter for bar_hits + // Getter and Setter for barHits public ArrayList getBarHits() { - return bar_hits; + return barHits; } public void setBarHits(ArrayList bar_hits) { - this.bar_hits = bar_hits; + this.barHits = bar_hits; } - // Getter and Setter for wedge_hits public ArrayList getWedgeHits() { - return wedge_hits; + return wedgeHits; } public void setWedgeHits(ArrayList wedge_hits) { - this.wedge_hits = wedge_hits; + this.wedgeHits = wedge_hits; } - public void FindHits(DataEvent event, Detector atof, TrackProjector track_projector) { - + public void findHits(DataEvent event, Detector atof, TrackProjector track_projector) { //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); + this.barHits.clear(); + this.wedgeHits.clear(); //They are read from the ATOF TDC bank DataBank bank = event.getBank("ATOF::tdc"); int nt = bank.rows(); // number of hits @@ -86,7 +75,7 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec hit_down.add(hit); case "wedge" -> { hit.matchTrack(track_projector); - this.wedge_hits.add(hit); + this.wedgeHits.add(hit); } default -> System.out.print("Undefined hit type \n"); @@ -105,20 +94,20 @@ public void FindHits(DataEvent event, Detector atof, TrackProjector track_projec //Bar hits are matched to ahdc tracks and listed BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); this_bar_hit.matchTrack(track_projector); - this.bar_hits.add(this_bar_hit); + this.barHits.add(this_bar_hit); } } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.barHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedgeHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } - public void FindHits(DataEvent event, Detector atof) { + public void findHits(DataEvent event, Detector atof) { //For each event a list of bar hits and a list of wedge hits are filled - this.bar_hits.clear(); - this.wedge_hits.clear(); + this.barHits.clear(); + this.wedgeHits.clear(); //They are read from the ATOF TDC bank DataBank bank_atof_hits = event.getBank("ATOF::tdc"); int nt = bank_atof_hits.rows(); // number of hits @@ -151,7 +140,7 @@ public void FindHits(DataEvent event, Detector atof) { hit_down.add(hit); case "wedge" -> { hit.matchTrack(event); - this.wedge_hits.add(hit); + this.wedgeHits.add(hit); } default -> System.out.print("Undefined hit type \n"); @@ -169,20 +158,19 @@ public void FindHits(DataEvent event, Detector atof) { if (this_hit_up.matchBar(this_hit_down)) { //Bar hits are matched to ahdc tracks and listed BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - this_bar_hit.matchTrack(event); - this.bar_hits.add(this_bar_hit); + //this_bar_hit.matchTrack(event); + this.barHits.add(this_bar_hit); } } } //Once all has been listed, hits are sorted by energy - Collections.sort(this.bar_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - Collections.sort(this.wedge_hits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.barHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); + Collections.sort(this.wedgeHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } /** * @param args the command line arguments */ public static void main(String[] args) { - } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 066a3ceea3..306ecb5fa2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -13,70 +13,68 @@ */ public class RecoBankWriter { - public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits) { + public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { - ArrayList hitlist = new ArrayList<>(); - hitlist.addAll(wedge_hits); - hitlist.addAll(bar_hits); + ArrayList hitList = new ArrayList<>(); + hitList.addAll(wedgeHits); + hitList.addAll(barHits); - DataBank bank = event.createBank("ATOF::hits", hitlist.size()); + DataBank bank = event.createBank("ATOF::hits", hitList.size()); if (bank == null) { - System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + System.err.println("COULD NOT CREATE A ATOF::hits BANK!!!!!!"); return null; } - for(int i =0; i< hitlist.size(); i++) { + for(int i =0; i< hitList.size(); i++) { bank.setShort("id",i, (short)(i+1)); - bank.setInt("sector",i, (int) hitlist.get(i).getSector()); - bank.setInt("layer",i, (int) hitlist.get(i).getLayer()); - bank.setInt("component",i, (int) hitlist.get(i).getComponent()); - //bank.setShort("trkID",i, (short) hitlist.get(i).get_AssociatedTrkId()); - //bank.setShort("clusterid", i, (short) hitlist.get(i).get_AssociatedClusterID()); - 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()); - bank.setFloat("inlength",i, (float) (hitlist.get(i).getInpath_length())); - bank.setFloat("pathlength",i, (float) (hitlist.get(i).getPath_length())); + bank.setInt("sector",i, (int) hitList.get(i).getSector()); + bank.setInt("layer",i, (int) hitList.get(i).getLayer()); + bank.setInt("component",i, (int) hitList.get(i).getComponent()); + 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()); + bank.setFloat("inlength",i, (float) (hitList.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (hitList.get(i).getPath_length())); } return bank; } - public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterlist) { + public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterList) { - DataBank bank = event.createBank("ATOF::clusters", clusterlist.size()); + DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); if (bank == null) { - System.err.println("COULD NOT CREATE A ATOF::Hits BANK!!!!!!"); + System.err.println("COULD NOT CREATE A ATOF::clusters BANK!!!!!!"); return null; } - for(int i =0; i< clusterlist.size(); i++) { + for(int i =0; i< clusterList.size(); i++) { bank.setShort("id",i, (short)(i+1)); - bank.setInt("barsize",i, (int) clusterlist.get(i).getBarHits().size()); - bank.setInt("wedgesize",i, (int) clusterlist.get(i).getWedgeHits().size()); - 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()); - bank.setFloat("inpathlength",i, (float) (clusterlist.get(i).getInpath_length())); - bank.setFloat("pathlength",i, (float) (clusterlist.get(i).getPath_length())); + bank.setInt("barsize",i, (int) clusterList.get(i).getBarHits().size()); + bank.setInt("wedgesize",i, (int) clusterList.get(i).getWedgeHits().size()); + 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()); + bank.setFloat("inpathlength",i, (float) (clusterList.get(i).getInpath_length())); + bank.setFloat("pathlength",i, (float) (clusterList.get(i).getPath_length())); } return bank; } - public int appendATOFBanks(DataEvent event, ArrayList wedge_hits, ArrayList bar_hits, ArrayList clusterlist) { + public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { - DataBank hitbank = this.fillAtofHitBank(event, wedge_hits, bar_hits); + DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); if (hitbank != null) { event.appendBank(hitbank); } else return 1; - DataBank clusterbank = fillAtofClusterBank(event, clusterlist); + DataBank clusterbank = fillAtofClusterBank(event, clusterList); if (clusterbank != null) { event.appendBank(clusterbank); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java index 58f40ad415..384a81d85f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -1,15 +1,12 @@ package org.jlab.rec.service; -import cnuphys.magfield.MagneticFields; import java.util.ArrayList; import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.hipo.HipoDataSource; import java.util.concurrent.atomic.AtomicInteger; -import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -20,38 +17,36 @@ import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; import org.jlab.rec.atof.trackMatch.TrackProjector; -import org.jlab.utils.CLASResources; /** - * Service to return reconstructed ATOF hits and clusters + * Service to return reconstructed Atof hits and clusters * * @author npilleux * */ -public class ATOFEngine extends ReconstructionEngine { +public class AtofEngine extends ReconstructionEngine { - public ATOFEngine() { + public AtofEngine() { super("ATOF", "pilleux", "1.0"); } RecoBankWriter rbc; - private final AtomicInteger Run = new AtomicInteger(0); - private Detector ATOF; - private double B; //Magnetic field + private final AtomicInteger run = new AtomicInteger(0); + private Detector Atof; + private double b; //Magnetic field - //Setters and getters public void setB(double B) { - this.B = B; + this.b = B; } public double getB() { - return B; + return b; } - public void setATOF(Detector ATOF) { - this.ATOF = ATOF; + public void setAtof(Detector ATOF) { + this.Atof = ATOF; } - public Detector getATOF() { - return ATOF; + public Detector getAtof() { + return Atof; } @Override @@ -63,27 +58,23 @@ public boolean processDataEvent(DataEvent event) { DataBank bank = event.getBank("RUN::config"); - // Load the constants - //------------------- int newRun = bank.getInt("run", 0); if (newRun == 0) { return true; } - if (Run.get() == 0 || (Run.get() != 0 && Run.get() != newRun)) { - Run.set(newRun); + if (run.get() == 0 || (run.get() != 0 && run.get() != newRun)) { + run.set(newRun); } - //CalibrationConstantsLoader constantsLoader = new CalibrationConstantsLoader(newRun, this.getConstantsManager()); - - //Track Projector Initialisation with B field + //Track Projector Initialisation with b field TrackProjector projector = new TrackProjector(); - projector.setB(this.B); - projector.ProjectTracks(event); + projector.setB(this.b); + projector.projectTracks(event); //Hit finder init HitFinder hitfinder = new HitFinder(); - hitfinder.FindHits(event, ATOF); + hitfinder.findHits(event, Atof); ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); @@ -100,7 +91,7 @@ public boolean processDataEvent(DataEvent event) { ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - rbc.appendATOFBanks(event, WedgeHits, BarHits, Clusters); + rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters); } return true; } @@ -111,42 +102,12 @@ public boolean init() { AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - this.ATOF = factory.createDetectorCLAS(cp); - - //requireConstants(Arrays.asList(CalibrationConstantsLoader.getAtofTables())); - //this.getConstantsManager().setVariation("default"); - + this.Atof = factory.createDetectorCLAS(cp); this.registerOutputBank("ATOF::hits", "ATOF::clusters"); return true; } public static void main(String arg[]) { - ATOFEngine en = new ATOFEngine(); - - //READING MAG FIELD MAP - System.setProperty("CLAS12DIR", "../../"); - String mapDir = CLASResources.getResourcePath("etc") + "/data/magfield"; - try { - MagneticFields.getInstance().initializeMagneticFields(mapDir, - "Symm_torus_r2501_phi16_z251_24Apr2018.dat", "Symm_solenoid_r601_phi1_z1201_13June2018.dat"); - } catch (Exception e) { - e.printStackTrace(); - } - float[] b = new float[3]; - Swim swimmer = new Swim(); - swimmer.BfieldLab(0, 0, 0, b); - en.setB(Math.abs(b[2])); - - en.init(); - String input = "/Users/npilleux/Desktop/alert/atof-reconstruction/coatjava/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/mixed_ions.hipo"; - HipoDataSource reader = new HipoDataSource(); - reader.open(input); - - while (reader.hasEvent()) { - DataEvent event = (DataEvent) reader.getNextEvent(); - en.processDataEvent(event); - event.getBank("ATOF::clusters").show(); - } } } From 21c956e211fbe277f242503e06d5ec77783e82e9 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Tue, 11 Feb 2025 16:10:57 -0600 Subject: [PATCH 71/82] style: fixed naming conventions and some cleaning --- .../jlab/rec/atof/Cluster/AtofCluster.java | 10 +- .../jlab/rec/atof/Cluster/ClusterFinder.java | 26 +-- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 8 +- .../rec/atof/TrackMatch/TrackProjection.java | 73 ++++---- .../rec/atof/TrackMatch/TrackProjector.java | 161 ++++-------------- .../jlab/rec/atof/banks/RecoBankWriter.java | 8 +- 6 files changed, 99 insertions(+), 187 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index fd1ef4a519..4d30ed2ac8 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -117,8 +117,8 @@ public final void computeClusterProperties() { this.x = max_energy_hit.getX(); this.y = max_energy_hit.getY(); this.z = max_energy_hit.getZ(); - this.pathLength = max_energy_hit.getPath_length(); - this.inPathLength = max_energy_hit.getInpath_length(); + this.pathLength = max_energy_hit.getPathLength(); + this.inPathLength = max_energy_hit.getInPathLength(); } else { @@ -126,11 +126,11 @@ public final void computeClusterProperties() { this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); this.z = max_energy_barhit.getZ(); - this.pathLength = max_energy_barhit.getPath_length(); - this.inPathLength = max_energy_barhit.getInpath_length(); + this.pathLength = max_energy_barhit.getPathLength(); + this.inPathLength = max_energy_barhit.getInPathLength(); } } - + public double getPhi() { return Math.atan2(this.y, this.x); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 3bc3df6236..1e8619b8bd 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -36,7 +36,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int i_wedge = 0; i_wedge < wedge_hits.size(); i_wedge++) { AtofHit this_wedge_hit = wedge_hits.get(i_wedge); //Make a cluster for each wedge hit that has not been previously clustered - if (this_wedge_hit.getIs_in_a_cluster()) { + if (this_wedge_hit.getIsInACluster()) { continue; } @@ -45,7 +45,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { ArrayList this_cluster_bar_hits = new ArrayList<>(); //Indicate that this hit now is in a cluster - this_wedge_hit.setIs_in_a_cluster(true); + this_wedge_hit.setIsInACluster(true); //And store it this_cluster_wedge_hits.add(this_wedge_hit); @@ -54,12 +54,12 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int j_wedge = i_wedge + 1; j_wedge < wedge_hits.size(); j_wedge++) { AtofHit other_wedge_hit = wedge_hits.get(j_wedge); //If that other hit is already involved in a cluster, skip it - if (other_wedge_hit.getIs_in_a_cluster()) { + if (other_wedge_hit.getIsInACluster()) { continue; } //Check the distance between the hits //For now we use phi module and z component differences from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_wedge_hit.computeModule_index()); + int delta_module = Math.abs(this_wedge_hit.computeModuleIndex() - other_wedge_hit.computeModuleIndex()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -74,7 +74,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { if (delta_component <= Parameters.SIGMA_COMPONENT_CLUSTERING)//delta_Z <= sigma_Z) { if (delta_T < Parameters.SIGMA_T_CLUSTERING) { - other_wedge_hit.setIs_in_a_cluster(true); + other_wedge_hit.setIsInACluster(true); this_cluster_wedge_hits.add(other_wedge_hit); } } @@ -85,12 +85,12 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int j_bar = 0; j_bar < bar_hits.size(); j_bar++) { BarHit other_bar_hit = bar_hits.get(j_bar); //Skip already clustered hits - if (other_bar_hit.getIs_in_a_cluster()) { + if (other_bar_hit.getIsInACluster()) { continue; } //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_wedge_hit.computeModule_index() - other_bar_hit.computeModule_index()); + int delta_module = Math.abs(this_wedge_hit.computeModuleIndex() - other_bar_hit.computeModuleIndex()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -102,7 +102,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { if (delta_T < Parameters.SIGMA_T_CLUSTERING) { - other_bar_hit.setIs_in_a_cluster(true); + other_bar_hit.setIsInACluster(true); this_cluster_bar_hits.add(other_bar_hit); } } @@ -119,26 +119,26 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { for (int i_bar = 0; i_bar < bar_hits.size(); i_bar++) { BarHit this_bar_hit = bar_hits.get(i_bar); //Skip hits that have already been clustered - if (this_bar_hit.getIs_in_a_cluster()) { + if (this_bar_hit.getIsInACluster()) { continue; } ArrayList this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); - this_bar_hit.setIs_in_a_cluster(true); + this_bar_hit.setIsInACluster(true); this_cluster_bar_hits.add(this_bar_hit); //Loop through less energetic clusters for (int j_bar = i_bar + 1; j_bar < bar_hits.size(); j_bar++) { BarHit other_bar_hit = bar_hits.get(j_bar); //Skip already clustered hits - if (other_bar_hit.getIs_in_a_cluster()) { + if (other_bar_hit.getIsInACluster()) { continue; } //Check the distance between the hits //For now we use phi module difference from what is observed in simu - int delta_module = Math.abs(this_bar_hit.computeModule_index() - other_bar_hit.computeModule_index()); + int delta_module = Math.abs(this_bar_hit.computeModuleIndex() - other_bar_hit.computeModuleIndex()); if (delta_module > 30) { delta_module = 60 - delta_module; } @@ -151,7 +151,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { if (delta_module <= Parameters.SIGMA_MODULE_CLUSTERING) { if (delta_Z < Parameters.SIGMA_Z_CLUSTERING) { if (delta_T < Parameters.SIGMA_T_CLUSTERING) { - other_bar_hit.setIs_in_a_cluster(true); + other_bar_hit.setIsInACluster(true); this_cluster_bar_hits.add(other_bar_hit); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 41de05aa21..0ca3ff0c7a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -434,13 +434,13 @@ public final void matchTrack(TrackProjector track_projector) { case "wedge" -> { sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; - projection_point = Projections.get(i_track).get_WedgeIntersect(); + projection_point = Projections.get(i_track).getWedgeIntersect(); } case "bar up", "bar down" -> { System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; - projection_point = Projections.get(i_track).get_BarIntersect(); + projection_point = Projections.get(i_track).getBarIntersect(); } default -> System.out.print("Impossible to match track and hit; hit type is undefined \n"); @@ -449,9 +449,9 @@ public final void matchTrack(TrackProjector track_projector) { if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { if ("wedge".equals(this.getType())) { - this.setPathLength(Projections.get(i_track).get_WedgePathLength()); + this.setPathLength(Projections.get(i_track).getWedgePathLength()); } else { - this.setPathLength(Projections.get(i_track).get_BarPathLength()); + this.setPathLength(Projections.get(i_track).getBarPathLength()); } } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java index 5138d15083..f6da1eacf3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java @@ -13,46 +13,46 @@ public class TrackProjection { /** * Intersection point of the track with the middle surface of the bar. */ - private Point3D _BarIntersect = new Point3D(); + private Point3D barIntersect = new Point3D(); /** * Intersection point of the track with the middle surface of the wedges. */ - private Point3D _WedgeIntersect = new Point3D(); + private Point3D wedgeIntersect = new Point3D(); /** * Path length of the track from the DOCA to the beam line * to the entrance surface of the bar. */ - Float _BarPathLength; + Float barPathLength; /** * Path length of the track from the DOCA to the beam line * to the entrance surface of the wedges. */ - Float _WedgePathLength; + Float wedgePathLength; /** * Path length inside the bar. */ - Float _BarInPathLength; + Float barInPathLength; /** * Path length inside the wedge. */ - Float _WedgeInPathLength; + Float wedgeInPathLength; /** * Default constructor that initializes the intersection points and path lengths to {@code NaN}. */ public TrackProjection() { - _BarIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); - _WedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); - _BarPathLength = Float.NaN; - _WedgePathLength = Float.NaN; - _BarInPathLength = Float.NaN; - _WedgeInPathLength = Float.NaN; + barIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + wedgeIntersect = new Point3D(Double.NaN, Double.NaN, Double.NaN); + barPathLength = Float.NaN; + wedgePathLength = Float.NaN; + barInPathLength = Float.NaN; + wedgeInPathLength = Float.NaN; } /** @@ -60,8 +60,8 @@ public TrackProjection() { * * @return {@link Point3D} bar's intersection point. */ - public Point3D get_BarIntersect() { - return _BarIntersect; + public Point3D getBarIntersect() { + return barIntersect; } /** @@ -69,8 +69,8 @@ public Point3D get_BarIntersect() { * * @return {@link Point3D} wedge's intersection point. */ - public Point3D get_WedgeIntersect() { - return _WedgeIntersect; + public Point3D getWedgeIntersect() { + return wedgeIntersect; } /** @@ -78,8 +78,8 @@ public Point3D get_WedgeIntersect() { * * @return {@code Float} path length to the bar's middle surface. */ - public Float get_BarPathLength() { - return _BarPathLength; + public Float getBarPathLength() { + return barPathLength; } /** @@ -88,8 +88,8 @@ public Float get_BarPathLength() { * * @return {@code Float} path length inside the bar. */ - public Float get_BarInPathLength() { - return _BarInPathLength; + public Float getBarInPathLength() { + return barInPathLength; } /** @@ -97,8 +97,8 @@ public Float get_BarInPathLength() { * * @return {@code Float} path length to the wedge's middle surface. */ - public Float get_WedgePathLength() { - return _WedgePathLength; + public Float getWedgePathLength() { + return wedgePathLength; } /** @@ -107,8 +107,8 @@ public Float get_WedgePathLength() { * * @return {@code Float} path length inside the wedge. */ - public Float get_WedgeInPathLength() { - return _WedgeInPathLength; + public Float getWedgeInPathLength() { + return wedgeInPathLength; } /** @@ -116,8 +116,8 @@ public Float get_WedgeInPathLength() { * * @param BarIntersect {@link Point3D} intersection with the bar. */ - public void set_BarIntersect(Point3D BarIntersect) { - this._BarIntersect = BarIntersect; + public void setBarIntersect(Point3D BarIntersect) { + this.barIntersect = BarIntersect; } /** @@ -125,8 +125,8 @@ public void set_BarIntersect(Point3D BarIntersect) { * * @param WedgeIntersect {@link Point3D} intersection with the wedge. */ - public void set_WedgeIntersect(Point3D WedgeIntersect) { - this._WedgeIntersect = WedgeIntersect; + public void setWedgeIntersect(Point3D WedgeIntersect) { + this.wedgeIntersect = WedgeIntersect; } /** @@ -134,8 +134,8 @@ public void set_WedgeIntersect(Point3D WedgeIntersect) { * * @param BarPathLength {@code Float} path length to the bar inner surface. */ - public void set_BarPathLength(Float BarPathLength) { - this._BarPathLength = BarPathLength; + public void setBarPathLength(Float BarPathLength) { + this.barPathLength = BarPathLength; } /** @@ -143,8 +143,8 @@ public void set_BarPathLength(Float BarPathLength) { * * @param WedgePathLength {@code Float} path length to the wedge inner surface. */ - public void set_WedgePathLength(Float WedgePathLength) { - this._WedgePathLength = WedgePathLength; + public void setWedgePathLength(Float WedgePathLength) { + this.wedgePathLength = WedgePathLength; } /** @@ -152,8 +152,8 @@ public void set_WedgePathLength(Float WedgePathLength) { * * @param BarInPathLength {@code Float} path length inside the bar. */ - public void set_BarInPathLength(Float BarInPathLength) { - this._BarInPathLength = BarInPathLength; + public void setBarInPathLength(Float BarInPathLength) { + this.barInPathLength = BarInPathLength; } /** @@ -161,10 +161,9 @@ public void set_BarInPathLength(Float BarInPathLength) { * * @param WedgeInPathLength {@code Float} path length inside the wedge. */ - public void set_WedgeInPathLength(Float WedgeInPathLength) { - this._WedgeInPathLength = WedgeInPathLength; + public void setWedgeInPathLength(Float WedgeInPathLength) { + this.wedgeInPathLength = WedgeInPathLength; } - /** * testing purposes. diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index 225ebf4842..d66040e6c8 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -7,13 +7,6 @@ import org.jlab.io.base.DataEvent; import org.jlab.clas.tracking.trackrep.Helix; import org.jlab.clas.tracking.kalmanfilter.Units; -import org.jlab.io.hipo.HipoDataSource; -import org.jlab.clas.swimtools.Swim; -import org.jlab.utils.CLASResources; -import cnuphys.magfield.MagneticFields; -import java.io.BufferedWriter; -import java.io.IOException; -import org.jlab.geom.prim.Point3D; import org.jlab.rec.atof.constants.Parameters; /** @@ -37,20 +30,20 @@ public class TrackProjector { /** * projections of tracks. */ - private List Projections; + private List projections; /** * solenoid magnitude */ - private Double B; + private Double b; /** * Default constructor that initializes the list of projections as new empty * list and the magnetic field to 5T. */ public TrackProjector() { - Projections = new ArrayList(); - B = 5.0; + projections = new ArrayList(); + this.b = 5.0; } /** @@ -60,7 +53,7 @@ public TrackProjector() { * the projections. */ public List getProjections() { - return Projections; + return projections; } /** @@ -69,7 +62,7 @@ public List getProjections() { * @return solenoid magnitude */ public Double getB() { - return B; + return b; } /** @@ -78,7 +71,7 @@ public Double getB() { * @param Projections a {@link List} of {@link TrackProjection}. */ public void setProjections(List Projections) { - this.Projections = Projections; + this.projections = Projections; } /** @@ -87,7 +80,7 @@ public void setProjections(List Projections) { * @param B a double. */ public void setB(Double B) { - this.B = B; + this.b = B; } /** @@ -96,9 +89,9 @@ public void setB(Double B) { * * @param event the {@link DataEvent} containing track data to be projected. */ - public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { + public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { - Projections.clear(); + projections.clear(); String track_bank_name = "AHDC::Track"; @@ -129,20 +122,20 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) double yb = 0; //momenta must be in GeV for the helix class - Helix helix = new Helix(x, y, z, px/1000., py/1000., pz/1000., q, B, xb, yb, units); + Helix helix = new Helix(x, y, z, px/1000., py/1000., pz/1000., q, b, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); + projection.setBarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.setWedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); - projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); + projection.setBarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.setWedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); - projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); - Projections.add(projection); + projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); + projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); + projections.add(projection); fill_out_bank(outputBank, projection, i); } event.appendBank(outputBank); @@ -157,7 +150,7 @@ public void ProjectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) */ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) { - Projections.clear(); + projections.clear(); String track_bank_name = "MC::Particle"; if (event == null) { // check if there is an event @@ -194,123 +187,43 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd double yb = 0; //momenta must be in GeV for the helix class - Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); + Helix helix = new Helix(x, y, z, px, py, pz, q, b, xb, yb, units); //Intersection points with the middle of the bar or wedge - projection.set_BarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); - projection.set_WedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); + projection.setBarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS)); + projection.setWedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS)); //Path length to the middle of the bar or wedge - projection.set_BarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); - projection.set_WedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); + projection.setBarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS))); + projection.setWedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS))); //Path length from the inner radius to the middle radius - projection.set_BarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.get_BarPathLength()); - projection.set_WedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.get_WedgePathLength()); - Projections.add(projection); + projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); + projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); + projections.add(projection); fill_out_bank(outputBank, projection, i); } event.appendBank(outputBank); } } - public void projectMCTracks_full_path(DataEvent event, int num_event, BufferedWriter writer) throws IOException { - - String track_bank_name = "MC::Particle"; - if (event == null) { // check if there is an event - //System.out.print(" no event \n"); - } else if (event.hasBank(track_bank_name) == false) { - // check if there are ahdc tracks in the event - //System.out.print("no tracks \n"); - } else { - DataBank bank = event.getBank(track_bank_name); - int nt = bank.rows(); // number of tracks - - for (int i = 0; i < nt; i++) { - - double x = bank.getFloat("vx", i); - double y = bank.getFloat("vy", i); - double z = bank.getFloat("vz", i); - double px = bank.getFloat("px", i); - double py = bank.getFloat("py", i); - double pz = bank.getFloat("pz", i); - - //Put everything in MM - - x = x*10; - y = y*10; - z = z*10; - - Units units = Units.MM; - - int q = -1; //need the charge sign from tracking - - double xb = 0; - double yb = 0; - - //momenta must be in GeV for the helix class - Helix helix = new Helix(x, y, z, px, py, pz, q, B, xb, yb, units); - - double min = 0.1; - double max = Parameters.WEDGE_INNER_RADIUS+Parameters.WEDGE_THICKNESS; - int nsteps = 20; - double step = (max-min)/nsteps; - for(double i_radius = min; i_radius wedge 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()); - bank.setFloat("inlength",i, (float) (hitList.get(i).getInpath_length())); - bank.setFloat("pathlength",i, (float) (hitList.get(i).getPath_length())); + bank.setFloat("inlength",i, (float) (hitList.get(i).getInPathLength())); + bank.setFloat("pathlength",i, (float) (hitList.get(i).getPathLength())); } return bank; } @@ -60,8 +60,8 @@ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList Date: Tue, 11 Feb 2025 16:16:26 -0600 Subject: [PATCH 72/82] fix: file name matches class name --- .../org/jlab/rec/service/{ATOFEngine.java => AtofEngine.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename reconstruction/alert/src/main/java/org/jlab/rec/service/{ATOFEngine.java => AtofEngine.java} (100%) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java rename to reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java From cb272a975796187a7260a3b81794a9ac3da5f87d Mon Sep 17 00:00:00 2001 From: N-Plx Date: Tue, 11 Feb 2025 17:03:18 -0600 Subject: [PATCH 73/82] style: some more documentation --- .../jlab/rec/atof/Cluster/AtofCluster.java | 144 +++++++++++++----- .../jlab/rec/atof/Cluster/ClusterFinder.java | 36 ++++- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 17 +++ .../java/org/jlab/rec/atof/Hit/HitFinder.java | 39 ++++- .../jlab/rec/atof/banks/RecoBankWriter.java | 42 ++++- 5 files changed, 233 insertions(+), 45 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index 4d30ed2ac8..abf08bc35b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -5,16 +5,32 @@ import org.jlab.rec.atof.hit.BarHit; /** + * The {@code AtofCluster} represents clusters in the atof * - * @author npilleux + *

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

    + * + * @author pilleux */ public class AtofCluster { - + + /** + * list of hits in the bars. + */ ArrayList barHits; + /** + * list of hits in the wedges. + */ ArrayList wedgeHits; - double x,y,z,time,energy; + /** + * cluster properties:position [cm], time [ns], energy[MeV], path length + * [cm] and length through the atof [cm]. + */ + double x, y, z, time, energy; double pathLength, inPathLength; - + public ArrayList getBarHits() { return barHits; } @@ -70,7 +86,7 @@ public double getEnergy() { public void setEnergy(double energy) { this.energy = energy; } - + public double getPathLength() { return pathLength; } @@ -78,7 +94,7 @@ public double getPathLength() { public void setPathLength(double pathLength) { this.pathLength = pathLength; } - + public double getInPathLength() { return inPathLength; } @@ -86,42 +102,50 @@ public double getInPathLength() { public void setInPathLength(double inPathLength) { this.inPathLength = inPathLength; } - - //Cluster coordinates and time are defined as the coordinates and time of the max energy hit - //Can be changed later + + /** + * 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; + this.energy = 0; double max_energy = -1; AtofHit max_energy_hit = new AtofHit(); BarHit max_energy_barhit = new BarHit(); - for(int i_wedge = 0; i_wedgemax_energy){max_energy_hit = this_wedge_hit; max_energy = this_energy;} + this.energy += this_energy; + if (this_energy > max_energy) { + max_energy_hit = this_wedge_hit; + max_energy = this_energy; + } } - - for(int i_bar = 0; i_barmax_energy){max_energy_barhit = this_bar_hit; max_energy = this_energy;} + this.energy += this_energy; + if (this_energy > max_energy) { + max_energy_barhit = this_bar_hit; + max_energy = this_energy; + } } - - if(max_energy_hit.getEnergy() > max_energy_barhit.getEnergy()) - { + + if (max_energy_hit.getEnergy() > max_energy_barhit.getEnergy()) { 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.pathLength = max_energy_hit.getPathLength(); this.inPathLength = max_energy_hit.getInPathLength(); - } - else - { + } else { this.time = max_energy_barhit.getTime(); this.x = max_energy_barhit.getX(); this.y = max_energy_barhit.getY(); @@ -130,28 +154,66 @@ public final void computeClusterProperties() { this.inPathLength = max_energy_barhit.getInPathLength(); } } - - public double getPhi() - { - return Math.atan2(this.y, this.x); + + public double getEdepWedge() { + double energy = 0; + for (int i = 0; i < this.wedgeHits.size(); i++) { + AtofHit this_hit = this.wedgeHits.get(i); + energy += this_hit.getEnergy(); + } + return energy; } - - public double getBeta() - { - return (this.pathLength / this.time) / (2.9979 * Math.pow(10, 2));//to do: Change to non-hardcoded value for c - } - - public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) - { - this.barHits = bar_hits; - this.wedgeHits = wedge_hits; - this.computeClusterProperties(); + + public double getEdepBar() { + double energy = 0; + for (int i = 0; i < this.barHits.size(); i++) { + AtofHit this_hit = this.barHits.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); + } + + /** + * Compute the cluster beta from the path length and time. + * + * @return a double that is beta + * + * - TO DO: Change to non-hardcoded value for c + * + */ + public double getBeta() { + //Need to change to non hardcoded value + return (this.pathLength / this.time) / (2.9979 * Math.pow(10, 2)); + } + + /** + * Constructor that initializes the list of bar hits and list of wedge hits + * and computes the cluster properties. + * + * @param bar_hits a {@link ArrayList} of {@link BarHit}. + * @param wedge_hits a {@link ArrayList} of {@link AtofHit}. + * + */ + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { + this.barHits = bar_hits; + this.wedgeHits = wedge_hits; + this.computeClusterProperties(); + } /** * @param args the command line arguments */ public static void main(String[] args) { } - + } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index 1e8619b8bd..a2825dadf3 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -8,21 +8,51 @@ import org.jlab.rec.atof.hit.HitFinder; /** + * The {@code ClusterFinder} class builds clusters in the atof * - * @author npilleux + *

    + * Uses found hits information. + * Creates a {@link AtofCluster} matching them. + *

    + * + * @author pilleux */ public class ClusterFinder { + /** + * list of clusters. + */ private ArrayList clusters; + /** + * Sets the list of clusters. + * + * @param clusters a {@link ArrayList} of {@link AtofCluster}. + * + */ public void setClusters(ArrayList clusters) { this.clusters = clusters; } + /** + * Gets the list of clusters. + * + * @return a {@link ArrayList} of {@link AtofCluster}. + * + */ public ArrayList getClusters() { return clusters; } + /** + * Builds clusters in the {@link DateEvent} 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) { //A list of clusters is built for each event @@ -162,6 +192,10 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { } } + /** + * Default constructor that initializes the list clusters as new empty + * list. + */ public ClusterFinder() { clusters = new ArrayList<>(); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 0ca3ff0c7a..937d9e43f6 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -147,11 +147,19 @@ public void setInPathLength(double inpath_length) { this.inPathLength = inpath_length; } + /** + * Computes the module index for the hit. + * + */ public int computeModuleIndex() { //Index ranging 0 to 60 for each wedge+bar module return 4 * this.sector + this.layer; } + /** + * Assigns a type to the hit. + * + */ public final String makeType() { //Type of hit can be wedge, bar up, bar down or bar. //Avoids testing components and order every time. @@ -458,6 +466,15 @@ public final void matchTrack(TrackProjector track_projector) { } } + /** + * Matches the current track with ahdc tracks projections that have been written to the banks. + * Calculates the match by comparing the hit's azimuthal angle and longitudinal position + * (z) with the track projection. If a match is found within defined + * tolerances for phi and z, the path length of the matched hit is updated. + * + * @param event a @link{DataEvent} in which the track projections bank has been written. + * + */ public int matchTrack(DataEvent event) { String track_bank_name = "AHDC::Projections"; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index 8f45d28217..b0f17d9669 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -8,14 +8,33 @@ import org.jlab.rec.atof.trackMatch.TrackProjector; /** + * The {@code HitFinder} class finds hits in the atof. + * + *

    + * Uses atof tdc bank information + * + * Creates a {@link ArrayList} of {@link BarHit} for bar hits read. + * Creates a {@link ArrayList} of {@link AtofHit} for wedge hits read. + * + *

    * - * @author npilleux + * @author pilleux */ public class HitFinder { + /** + * list of bar hits + */ private ArrayList barHits; + /** + * list of wedge hits + */ private ArrayList wedgeHits; + /** + * Default constructor that initializes the list of hits as new empty + * lists. + */ public HitFinder() { this.barHits = new ArrayList<>(); this.wedgeHits = new ArrayList<>(); @@ -38,6 +57,16 @@ public void setWedgeHits(ArrayList wedge_hits) { this.wedgeHits = wedge_hits; } + /** + * Find hits in the event, matches them to tracks found in the ahdc + * and build their properties. + * + * @param event the {@link DataEvent} containing hits. + * @param atof the {@link Detector} representing the atof geometry to match + * the sector/layer/component to x/y/z. + * @param track_projector the {@link TrackProjector} containing the ahdc tracks projected + * to the atof for matching. + */ public void findHits(DataEvent event, Detector atof, TrackProjector track_projector) { //For each event a list of bar hits and a list of wedge hits are filled this.barHits.clear(); @@ -103,6 +132,14 @@ public void findHits(DataEvent event, Detector atof, TrackProjector track_projec Collections.sort(this.wedgeHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); } + /** + * Find hits in the event, matches them to tracks in the + * projections bank and build their properties. + * + * @param event the {@link DataEvent} containing hits and the bank with ahdc track projections. + * @param atof the {@link Detector} representing the atof geometry to match + * the sector/layer/component to x/y/z. + */ public void findHits(DataEvent event, Detector atof) { //For each event a list of bar hits and a list of wedge hits are filled diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 169283b563..f32c384136 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -8,11 +8,25 @@ import org.jlab.rec.atof.hit.BarHit; /** - * - * @author npilleux + * The {@code RecoBankWriter} writes the banks needed for the atof reconstruction: + * track projections, hits and clusters info. + * + * @author pilleux */ public class RecoBankWriter { + /** + * Writes the bank of atof hits. + * + * @param event the {@link DataEvent} in which to add the bank + * @param wedgeHits the {@link ArrayList} of {@link AtofHit} + * containing the wedge hits to be added to the bank + * @param barHits the {@link ArrayList} of {@link BarHit} + * containing the bar hits to be added to the bank + * + * @return {@link DataBank} the bank with all the hits read in the event. + * + */ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { ArrayList hitList = new ArrayList<>(); @@ -42,6 +56,16 @@ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge return bank; } + /** + * Writes the bank of atof clusters. + * + * @param event the {@link DataEvent} in which to add the bank + * @param clusterList the {@link ArrayList} of {@link AtofCluster} + * 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 fillAtofClusterBank(DataEvent event, ArrayList clusterList) { DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); @@ -66,6 +90,20 @@ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); From 5bb27b3a98589d78b8053fdca2664c6730994689 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Wed, 12 Feb 2025 10:44:31 -0600 Subject: [PATCH 74/82] refactor: move writing of the projection bank --- .../rec/atof/TrackMatch/TrackProjector.java | 26 +-- .../jlab/rec/atof/banks/RecoBankWriter.java | 175 +++++++++++------- .../java/org/jlab/rec/service/AtofEngine.java | 4 +- 3 files changed, 117 insertions(+), 88 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java index d66040e6c8..f3334085eb 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java @@ -1,7 +1,6 @@ package org.jlab.rec.atof.trackMatch; import java.util.ArrayList; -import java.util.List; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; @@ -30,7 +29,7 @@ public class TrackProjector { /** * projections of tracks. */ - private List projections; + private ArrayList projections; /** * solenoid magnitude @@ -52,7 +51,7 @@ public TrackProjector() { * @return a {@link List} of {@link TrackProjection} objects representing * the projections. */ - public List getProjections() { + public ArrayList getProjections() { return projections; } @@ -70,7 +69,7 @@ public Double getB() { * * @param Projections a {@link List} of {@link TrackProjection}. */ - public void setProjections(List Projections) { + public void setProjections(ArrayList Projections) { this.projections = Projections; } @@ -104,7 +103,6 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) DataBank bank = event.getBank(track_bank_name); int nt = bank.rows(); // number of tracks TrackProjection projection = new TrackProjection(); - DataBank outputBank = event.createBank("AHDC::Projections", nt); for (int i = 0; i < nt; i++) { double x = bank.getFloat("x", i); @@ -136,9 +134,7 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); projections.add(projection); - fill_out_bank(outputBank, projection, i); } - event.appendBank(outputBank); } } @@ -203,25 +199,9 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength()); projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength()); projections.add(projection); - fill_out_bank(outputBank, projection, i); } - event.appendBank(outputBank); } } - - public static void fill_out_bank(DataBank outputBank, TrackProjection projection, int i) { - outputBank.setFloat("x_at_bar", i, (float) projection.getBarIntersect().x()); - outputBank.setFloat("y_at_bar", i, (float) projection.getBarIntersect().y()); - outputBank.setFloat("z_at_bar", i, (float) projection.getBarIntersect().z()); - outputBank.setFloat("L_at_bar", i, (float) projection.getBarPathLength()); - outputBank.setFloat("L_in_bar", i, (float) projection.getBarInPathLength()); - outputBank.setFloat("x_at_wedge", i, (float) projection.getWedgeIntersect().x()); - outputBank.setFloat("y_at_wedge", i, (float) projection.getWedgeIntersect().y()); - outputBank.setFloat("z_at_wedge", i, (float) projection.getWedgeIntersect().z()); - outputBank.setFloat("L_at_wedge", i, (float) projection.getWedgePathLength()); - outputBank.setFloat("L_in_wedge", i, (float) projection.getWedgeInPathLength()); - - } public static void main(String arg[]) { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index f32c384136..93a7d98a69 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -6,118 +6,167 @@ import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; +import org.jlab.rec.atof.trackMatch.TrackProjection; /** - * The {@code RecoBankWriter} writes the banks needed for the atof reconstruction: - * track projections, hits and clusters info. - * + * The {@code RecoBankWriter} writes the banks needed for the atof + * reconstruction: track projections, hits and clusters info. + * * @author pilleux */ public class RecoBankWriter { - + /** * Writes the bank of atof hits. - * + * * @param event the {@link DataEvent} in which to add the bank - * @param wedgeHits the {@link ArrayList} of {@link AtofHit} - * containing the wedge hits to be added to the bank - * @param barHits the {@link ArrayList} of {@link BarHit} - * containing the bar hits to be added to the bank - * + * @param wedgeHits the {@link ArrayList} of {@link AtofHit} containing the + * wedge hits to be added to the bank + * @param barHits the {@link ArrayList} of {@link BarHit} containing the bar + * hits to be added to the bank + * * @return {@link DataBank} the bank with all the hits read in the event. - * + * */ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { - + ArrayList hitList = new ArrayList<>(); hitList.addAll(wedgeHits); hitList.addAll(barHits); - - DataBank bank = event.createBank("ATOF::hits", hitList.size()); - + + DataBank bank = event.createBank("ATOF::hits", hitList.size()); + if (bank == null) { System.err.println("COULD NOT CREATE A ATOF::hits BANK!!!!!!"); return null; } - - for(int i =0; i< hitList.size(); i++) { - bank.setShort("id",i, (short)(i+1)); - bank.setInt("sector",i, (int) hitList.get(i).getSector()); - bank.setInt("layer",i, (int) hitList.get(i).getLayer()); - bank.setInt("component",i, (int) hitList.get(i).getComponent()); - 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()); - bank.setFloat("inlength",i, (float) (hitList.get(i).getInPathLength())); - bank.setFloat("pathlength",i, (float) (hitList.get(i).getPathLength())); + + for (int i = 0; i < hitList.size(); i++) { + bank.setShort("id", i, (short) (i + 1)); + bank.setInt("sector", i, (int) hitList.get(i).getSector()); + bank.setInt("layer", i, (int) hitList.get(i).getLayer()); + bank.setInt("component", i, (int) hitList.get(i).getComponent()); + 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()); + bank.setFloat("inlength", i, (float) (hitList.get(i).getInPathLength())); + bank.setFloat("pathlength", i, (float) (hitList.get(i).getPathLength())); } return bank; } - + /** * Writes the bank of atof clusters. - * + * * @param event the {@link DataEvent} in which to add the bank - * @param clusterList the {@link ArrayList} of {@link AtofCluster} + * @param clusterList the {@link ArrayList} of {@link AtofCluster} * containing the clusters info to be added to the bank - * - * @return {@link DataBank} the bank with all the clusters built in the event. - * + * + * @return {@link DataBank} the bank with all the clusters built in the + * event. + * */ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList clusterList) { - - DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); - + + DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); + if (bank == null) { System.err.println("COULD NOT CREATE A ATOF::clusters BANK!!!!!!"); return null; } - - for(int i =0; i< clusterList.size(); i++) { - bank.setShort("id",i, (short)(i+1)); - bank.setInt("barsize",i, (int) clusterList.get(i).getBarHits().size()); - bank.setInt("wedgesize",i, (int) clusterList.get(i).getWedgeHits().size()); - 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()); - bank.setFloat("inpathlength",i, (float) (clusterList.get(i).getInPathLength())); - bank.setFloat("pathlength",i, (float) (clusterList.get(i).getPathLength())); + + for (int i = 0; i < clusterList.size(); i++) { + bank.setShort("id", i, (short) (i + 1)); + bank.setInt("barsize", i, (int) clusterList.get(i).getBarHits().size()); + bank.setInt("wedgesize", i, (int) clusterList.get(i).getWedgeHits().size()); + 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()); + bank.setFloat("inpathlength", i, (float) (clusterList.get(i).getInPathLength())); + bank.setFloat("pathlength", i, (float) (clusterList.get(i).getPathLength())); } return bank; } - + + /** + * Writes the bank of track projections. + * + * @param event the {@link DataEvent} in which to add the bank + * @param projections the {@link ArrayList} of {@link TrackProjection} + * containing the track projection info to be added to the bank + * + * @return {@link DataBank} the bank with all the projected tracks in the + * event. + * + */ + public static DataBank fillProjectionsBank(DataEvent event, ArrayList projections) { + + DataBank bank = event.createBank("AHDC::Projections", projections.size()); + + if (bank == null) { + System.err.println("COULD NOT CREATE A AHDC::Projections BANK!!!!!!"); + return null; + } + + for (int i = 0; i < projections.size(); i++) { + TrackProjection projection = projections.get(i); + bank.setFloat("x_at_bar", i, (float) projection.getBarIntersect().x()); + bank.setFloat("y_at_bar", i, (float) projection.getBarIntersect().y()); + bank.setFloat("z_at_bar", i, (float) projection.getBarIntersect().z()); + bank.setFloat("L_at_bar", i, (float) projection.getBarPathLength()); + bank.setFloat("L_in_bar", i, (float) projection.getBarInPathLength()); + bank.setFloat("x_at_wedge", i, (float) projection.getWedgeIntersect().x()); + bank.setFloat("y_at_wedge", i, (float) projection.getWedgeIntersect().y()); + bank.setFloat("z_at_wedge", i, (float) projection.getWedgeIntersect().z()); + bank.setFloat("L_at_wedge", i, (float) projection.getWedgePathLength()); + bank.setFloat("L_in_wedge", i, (float) projection.getWedgeInPathLength()); + } + return bank; + } + /** * Appends the atof banks to an event. - * + * * @param event the {@link DataEvent} in which to append the banks - * @param clusterList the {@link ArrayList} of {@link AtofCluster} + * @param clusterList the {@link ArrayList} of {@link AtofCluster} * containing the clusters info to be added to the bank - * @param wedgeHits the {@link ArrayList} of {@link AtofHit} - * containing the wedge hits info to be added - * @param barHits the {@link ArrayList} of {@link BarHit} - * containing the bar hits info to be added - * + * @param wedgeHits the {@link ArrayList} of {@link AtofHit} containing the + * wedge hits info to be added + * @param barHits the {@link ArrayList} of {@link BarHit} containing the bar + * hits info to be added + * @param projections the {@link ArrayList} of {@link TrackProjection} containing the + * track projections info to be added + * * @return 0 if it worked, 1 if it failed - * + * */ - public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { + public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList, ArrayList projections) { + + DataBank projbank = this.fillProjectionsBank(event, projections); + if (projbank != null) { + event.appendBank(projbank); + } else { + return 1; + } DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); if (hitbank != null) { event.appendBank(hitbank); + } else { + return 1; } - else return 1; DataBank clusterbank = fillAtofClusterBank(event, clusterList); if (clusterbank != null) { event.appendBank(clusterbank); + } else { + return 1; } - else return 1; - + return 0; } @@ -126,5 +175,5 @@ public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayL */ public static void main(String[] args) { } - + } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java index 384a81d85f..ae98601b4c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java @@ -74,7 +74,7 @@ public boolean processDataEvent(DataEvent event) { //Hit finder init HitFinder hitfinder = new HitFinder(); - hitfinder.findHits(event, Atof); + hitfinder.findHits(event, Atof, projector); ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); @@ -91,7 +91,7 @@ public boolean processDataEvent(DataEvent event) { ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters); + rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters, projector.getProjections()); } return true; } From a337e06560efb37af662556aa700b91b4bca451a Mon Sep 17 00:00:00 2001 From: N-Plx Date: Sat, 15 Feb 2025 12:25:04 -0500 Subject: [PATCH 75/82] refactor: move track matching from hit to cluster level --- .../jlab/rec/atof/Cluster/AtofCluster.java | 123 ++++++++++-- .../jlab/rec/atof/Cluster/ClusterFinder.java | 4 +- .../java/org/jlab/rec/atof/Hit/AtofHit.java | 188 +----------------- .../java/org/jlab/rec/atof/Hit/HitFinder.java | 80 +------- .../jlab/rec/atof/banks/RecoBankWriter.java | 34 ++-- .../java/org/jlab/rec/service/AtofEngine.java | 8 +- 6 files changed, 140 insertions(+), 297 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java index abf08bc35b..2e7cc2d5fa 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java @@ -1,6 +1,10 @@ package org.jlab.rec.atof.cluster; import java.util.ArrayList; +import org.jlab.geom.prim.Point3D; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.rec.atof.constants.Parameters; import org.jlab.rec.atof.hit.AtofHit; import org.jlab.rec.atof.hit.BarHit; @@ -26,10 +30,12 @@ public class AtofCluster { ArrayList wedgeHits; /** * cluster properties:position [cm], time [ns], energy[MeV], path length - * [cm] and length through the atof [cm]. + * [cm] and length through the atof [cm], type of the maximum hit (to set + * resolutions). */ double x, y, z, time, energy; double pathLength, inPathLength; + String typeMaxHit; public ArrayList getBarHits() { return barHits; @@ -102,7 +108,15 @@ public double getInPathLength() { public void setInPathLength(double inPathLength) { this.inPathLength = inPathLength; } + + public String getTypeMaxHit() { + return typeMaxHit; + } + public void setTypeMaxHit(String typeMaxHit) { + this.typeMaxHit = typeMaxHit; + } + /** * Compute the cluster properties. * @@ -116,7 +130,6 @@ public final void computeClusterProperties() { this.energy = 0; double max_energy = -1; AtofHit max_energy_hit = new AtofHit(); - BarHit max_energy_barhit = new BarHit(); for (int i_wedge = 0; i_wedge < this.wedgeHits.size(); i_wedge++) { AtofHit this_wedge_hit = this.wedgeHits.get(i_wedge); @@ -133,26 +146,87 @@ public final void computeClusterProperties() { double this_energy = this_bar_hit.getEnergy(); this.energy += this_energy; if (this_energy > max_energy) { - max_energy_barhit = this_bar_hit; + max_energy_hit = this_bar_hit; max_energy = this_energy; } } - - if (max_energy_hit.getEnergy() > max_energy_barhit.getEnergy()) { - 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.pathLength = max_energy_hit.getPathLength(); - this.inPathLength = max_energy_hit.getInPathLength(); + + 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(); + } + + /** + * Matches the current track with ahdc tracks projections that have been written to the banks. + * Calculates the match by comparing the hit's azimuthal angle and longitudinal position + * (z) with the track projection. If a match is found within defined + * tolerances for phi and z, the path length of the matched hit is updated. + * + * @param event a @link{DataEvent} in which the track projections bank has been written. + * + */ + public int matchTrack(DataEvent event) { + String track_bank_name = "AHDC::Projections"; + if (event == null) { // check if there is an event + //System.out.print(" no event \n"); + return 1; + } else if (event.hasBank(track_bank_name) == false) { + // check if there are ahdc tracks in the event + //System.out.print("no tracks \n"); + return 1; } else { - this.time = max_energy_barhit.getTime(); - this.x = max_energy_barhit.getX(); - this.y = max_energy_barhit.getY(); - this.z = max_energy_barhit.getZ(); - this.pathLength = max_energy_barhit.getPathLength(); - this.inPathLength = max_energy_barhit.getInPathLength(); + DataBank track_bank = event.getBank(track_bank_name); + int nt = track_bank.rows(); // number of tracks + double sigma_phi = 0; + double sigma_z = 0; + + //Looping through all tracks + for (int i = 0; i < nt; i++) { + Float xt = null, yt = null, zt = null, path = null, inpath = null; + if (null == this.getTypeMaxHit()) { + System.out.print("Impossible to match track and hit; hit type is null \n"); + } else { + switch (this.getTypeMaxHit()) { + case "wedge" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; + xt = track_bank.getFloat("x_at_wedge", i); + yt = track_bank.getFloat("y_at_wedge", i); + zt = track_bank.getFloat("z_at_wedge", i); + path = track_bank.getFloat("L_at_wedge", i); + //A wedge hit traveled through the whole bar and then through a portion of the wedge + inpath = track_bank.getFloat("L_in_wedge", i) + track_bank.getFloat("L_at_wedge", i) - track_bank.getFloat("L_at_bar", i); + } + case "bar" -> { + sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; + sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; + xt = track_bank.getFloat("x_at_bar", i); + yt = track_bank.getFloat("y_at_bar", i); + zt = track_bank.getFloat("z_at_bar", i); + path = track_bank.getFloat("L_at_bar", i); + inpath = track_bank.getFloat("L_in_bar", i); + } + case "bar up", "bar down" -> { + System.out.print("Impossible to match track and hit; hit type is a single up or down bar hit. \n"); + } + default -> + System.out.print("Impossible to match track and hit; hit type is undefined \n"); + } + } + Point3D projection_point = new Point3D(xt, yt, zt); + double delta_phi = Math.abs(this.getPhi() - projection_point.toVector3D().phi()); + if(delta_phi > Math.PI) delta_phi = Math.PI - delta_phi; + if (delta_phi < sigma_phi) { + if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { + this.setPathLength(path); + this.setInPathLength(inpath); + } + } + } } + return 0; } public double getEdepWedge() { @@ -209,6 +283,21 @@ public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { this.wedgeHits = wedge_hits; this.computeClusterProperties(); } + + /** + * Constructor that initializes the list of bar hits and list of wedge hits + * and computes the cluster properties. + * + * @param bar_hits a {@link ArrayList} of {@link BarHit}. + * @param wedge_hits a {@link ArrayList} of {@link AtofHit}. + * + */ + public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits, DataEvent event) { + this.barHits = bar_hits; + this.wedgeHits = wedge_hits; + this.computeClusterProperties(); + this.matchTrack(event); + } /** * @param args the command line arguments diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java index a2825dadf3..271e9a094a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java @@ -140,7 +140,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { }//End loop bar hits //After all wedge and bar hits have been grouped, build the cluster - AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); + AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits, event); //And add it to the list of clusters clusters.add(cluster); }//End loop on all wedge hits @@ -187,7 +187,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { } } } - AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits); + AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits, event); clusters.add(cluster); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java index 937d9e43f6..28a69fbd8b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java @@ -1,13 +1,8 @@ package org.jlab.rec.atof.hit; -import java.util.List; import org.jlab.geom.base.*; import org.jlab.geom.prim.Point3D; -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataEvent; import org.jlab.rec.atof.constants.Parameters; -import org.jlab.rec.atof.trackMatch.TrackProjection; -import org.jlab.rec.atof.trackMatch.TrackProjector; /** * @@ -25,7 +20,6 @@ public class AtofHit { private double time, energy, x, y, z; private String type; private boolean isInACluster; - private double pathLength, inPathLength; public int getSector() { return sector; @@ -131,22 +125,6 @@ public void setIsInACluster(boolean is_in_a_cluster) { this.isInACluster = is_in_a_cluster; } - public double getPathLength() { - return pathLength; - } - - public void setPathLength(double path_length) { - this.pathLength = path_length; - } - - public double getInPathLength() { - return inPathLength; - } - - public void setInPathLength(double inpath_length) { - this.inPathLength = inpath_length; - } - /** * Computes the module index for the hit. * @@ -374,172 +352,14 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.isInACluster = false; this.makeType(); - int is_ok = this.convertTdcToTime(); - if (is_ok != 1) { - is_ok = this.convertTotToEnergy(); - } - if (is_ok != 1) { - is_ok = this.convertSLCToXYZ(atof); - } - } - - /** - * Constructor for a hit in the atof. Initializes the hit's sector, layer, - * component, 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 layer The layer of the detector where the hit was detected. - * @param component The component within the layer that registered the hit. - * @param order Order of the hit. - * @param tdc TDC value. - * @param tot ToT value. - * @param atof Detector object representing the atof, used to calculate - * @param track_projector TrackProjector object with ahdc tracks to be - * matched to the hit. - */ - public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof, TrackProjector track_projector) { - this.sector = sector; - this.layer = layer; - this.component = component; - this.order = order; - this.tdc = tdc; - this.tot = tot; - this.isInACluster = false; - - //First the type needs to be set - this.makeType(); - //From it the coordinates can be computed - this.convertSLCToXYZ(atof); - //From them tracks can be matched - this.matchTrack(track_projector); - //And energy and time can then be computed - this.convertTotToEnergy(); this.convertTdcToTime(); + this.convertTotToEnergy(); + this.convertSLCToXYZ(atof); } - /** - * Matches the current track with ahdc tracks projections. Calculates the - * match by comparing the hit's azimuthal angle and longitudinal position - * (z) with the track projection. If a match is found within defined - * tolerances for phi and z, the path length of the matched hit is updated. - * - * @param track_projector The TrackProjector object that provides a list of - * TrackProjections. - * - */ - public final void matchTrack(TrackProjector track_projector) { - double sigma_phi = 0; - double sigma_z = 0; - - List Projections = track_projector.getProjections(); - for (int i_track = 0; i_track < Projections.size(); i_track++) { - Point3D projection_point = new Point3D(); - if (null == this.getType()) { - System.out.print("Impossible to match track and hit; hit type is null \n"); - } else { - switch (this.getType()) { - case "wedge" -> { - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; - projection_point = Projections.get(i_track).getWedgeIntersect(); - } - case "bar up", "bar down" -> { - System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; - projection_point = Projections.get(i_track).getBarIntersect(); - } - default -> - System.out.print("Impossible to match track and hit; hit type is undefined \n"); - } - } - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { - if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - if ("wedge".equals(this.getType())) { - this.setPathLength(Projections.get(i_track).getWedgePathLength()); - } else { - this.setPathLength(Projections.get(i_track).getBarPathLength()); - } - } - } - } - } - - /** - * Matches the current track with ahdc tracks projections that have been written to the banks. - * Calculates the match by comparing the hit's azimuthal angle and longitudinal position - * (z) with the track projection. If a match is found within defined - * tolerances for phi and z, the path length of the matched hit is updated. - * - * @param event a @link{DataEvent} in which the track projections bank has been written. - * - */ - public int matchTrack(DataEvent event) { - - String track_bank_name = "AHDC::Projections"; - if (event == null) { // check if there is an event - //System.out.print(" no event \n"); - return 1; - } else if (event.hasBank(track_bank_name) == false) { - return 1; - // check if there are ahdc tracks in the event - //System.out.print("no tracks \n"); - } else { - DataBank track_bank = event.getBank(track_bank_name); - int nt = track_bank.rows(); // number of tracks - double sigma_phi = 0; - double sigma_z = 0; - - //Looping through all tracks - for (int i = 0; i < nt; i++) { - - Float xt = null, yt = null, zt = null, path = null, inpath = null; - if (null == this.getType()) { - System.out.print("Impossible to match track and hit; hit type is null \n"); - } else { - switch (this.getType()) { - case "wedge" -> { - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_WEDGE; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_WEDGE; - xt = track_bank.getFloat("x_at_wedge", i); - yt = track_bank.getFloat("y_at_wedge", i); - zt = track_bank.getFloat("z_at_wedge", i); - path = track_bank.getFloat("L_at_wedge", i); - //A wedge hit traveled through the whole bar and then through a portion of the wedge - inpath = track_bank.getFloat("L_in_wedge", i) + track_bank.getFloat("L_at_wedge", i) - track_bank.getFloat("L_at_bar", i); - } - case "bar" -> { - sigma_phi = Parameters.SIGMA_PHI_TRACK_MATCHING_BAR; - sigma_z = Parameters.SIGMA_Z_TRACK_MATCHING_BAR; - xt = track_bank.getFloat("x_at_bar", i); - yt = track_bank.getFloat("y_at_bar", i); - zt = track_bank.getFloat("z_at_bar", i); - path = track_bank.getFloat("L_at_bar", i); - inpath = track_bank.getFloat("L_in_bar", i); - } - case "bar up", "bar down" -> { - System.out.print("WARNING : YOU ARE MATCHING A TRACK TO A SINGLE HIT IN THE BAR. \n"); - } - default -> - System.out.print("Impossible to match track and hit; hit type is undefined \n"); - } - } - Point3D projection_point = new Point3D(xt, yt, zt); - if (Math.abs(this.getPhi() - projection_point.toVector3D().phi()) < sigma_phi) { - if (Math.abs(this.getZ() - projection_point.z()) < sigma_z) { - this.setPathLength(path); - this.setInPathLength(inpath); - } - } - } - } - return 0; - } - - public AtofHit() { + public AtofHit(){ } - + /** * @param args the command line arguments */ diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java index b0f17d9669..83bc3c5012 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java @@ -5,7 +5,6 @@ import org.jlab.geom.base.Detector; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.rec.atof.trackMatch.TrackProjector; /** * The {@code HitFinder} class finds hits in the atof. @@ -64,10 +63,8 @@ public void setWedgeHits(ArrayList wedge_hits) { * @param event the {@link DataEvent} containing hits. * @param atof the {@link Detector} representing the atof geometry to match * the sector/layer/component to x/y/z. - * @param track_projector the {@link TrackProjector} containing the ahdc tracks projected - * to the atof for matching. */ - public void findHits(DataEvent event, Detector atof, TrackProjector track_projector) { + public void findHits(DataEvent event, Detector atof) { //For each event a list of bar hits and a list of wedge hits are filled this.barHits.clear(); this.wedgeHits.clear(); @@ -103,80 +100,6 @@ public void findHits(DataEvent event, Detector atof, TrackProjector track_projec case "bar down" -> hit_down.add(hit); case "wedge" -> { - hit.matchTrack(track_projector); - this.wedgeHits.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++) { - AtofHit this_hit_up = hit_up.get(i_up); - //Starting loop through down hits in the bar - for (int i_down = 0; i_down < hit_down.size(); i_down++) { - AtofHit this_hit_down = hit_down.get(i_down); - //Matching the hits: if same module and different order, they make up a bar hit - if (this_hit_up.matchBar(this_hit_down)) { - //Bar hits are matched to ahdc tracks and listed - BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - this_bar_hit.matchTrack(track_projector); - this.barHits.add(this_bar_hit); - } - } - } - //Once all has been listed, hits are sorted by energy - Collections.sort(this.barHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - Collections.sort(this.wedgeHits, (hit1, hit2) -> Double.compare(hit2.getEnergy(), hit1.getEnergy())); - } - - /** - * Find hits in the event, matches them to tracks in the - * projections bank and build their properties. - * - * @param event the {@link DataEvent} containing hits and the bank with ahdc track projections. - * @param atof the {@link Detector} representing the atof geometry to match - * the sector/layer/component to x/y/z. - */ - public void findHits(DataEvent event, Detector atof) { - - //For each event a list of bar hits and a list of wedge hits are filled - this.barHits.clear(); - this.wedgeHits.clear(); - //They are read from the ATOF TDC bank - DataBank bank_atof_hits = event.getBank("ATOF::tdc"); - int nt = bank_atof_hits.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_atof_hits.getInt("sector", i); - int layer = bank_atof_hits.getInt("layer", i); - int component = bank_atof_hits.getInt("component", i); - int order = bank_atof_hits.getInt("order", i); - int tdc = bank_atof_hits.getInt("TDC", i); - int tot = bank_atof_hits.getInt("ToT", i); - //Building a Hit - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); - if (hit.getEnergy() < 0.01) { - continue; //energy threshold - } //Sorting the hits into wedge, upstream and downstream bar hits - //Lists are built for up/down bar to match them after - //Wedge hits are mayched to ahdc tracks and listed - 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); - case "wedge" -> { - hit.matchTrack(event); this.wedgeHits.add(hit); } default -> @@ -195,7 +118,6 @@ public void findHits(DataEvent event, Detector atof) { if (this_hit_up.matchBar(this_hit_down)) { //Bar hits are matched to ahdc tracks and listed BarHit this_bar_hit = new BarHit(this_hit_up, this_hit_down); - //this_bar_hit.matchTrack(event); this.barHits.add(this_bar_hit); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 93a7d98a69..8bb4b16b02 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -51,8 +51,6 @@ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge 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()); - bank.setFloat("inlength", i, (float) (hitList.get(i).getInPathLength())); - bank.setFloat("pathlength", i, (float) (hitList.get(i).getPathLength())); } return bank; } @@ -138,21 +136,12 @@ public static DataBank fillProjectionsBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList, ArrayList projections) { + public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { - DataBank projbank = this.fillProjectionsBank(event, projections); - if (projbank != null) { - event.appendBank(projbank); - } else { - return 1; - } - DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); if (hitbank != null) { event.appendBank(hitbank); @@ -169,6 +158,27 @@ public int appendAtofBanks(DataEvent event, ArrayList wedgeHits, ArrayL return 0; } + + /** + * Appends the alert match banks to an event. + * + * @param event the {@link DataEvent} in which to append the banks + * @param projections the {@link ArrayList} of {@link TrackProjection} containing the + * track projections info to be added + * + * @return 0 if it worked, 1 if it failed + * + */ + public int appendMatchBanks(DataEvent event, ArrayList projections) { + + DataBank projbank = this.fillProjectionsBank(event, projections); + if (projbank != null) { + event.appendBank(projbank); + } else { + return 1; + } + return 0; + } /** * @param args the command line arguments diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java index ae98601b4c..10ba876cfd 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java @@ -10,6 +10,7 @@ import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; +import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.banks.RecoBankWriter; import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.cluster.ClusterFinder; @@ -71,10 +72,10 @@ public boolean processDataEvent(DataEvent event) { TrackProjector projector = new TrackProjector(); projector.setB(this.b); projector.projectTracks(event); - + rbc.appendMatchBanks(event, projector.getProjections()); //Hit finder init HitFinder hitfinder = new HitFinder(); - hitfinder.findHits(event, Atof, projector); + hitfinder.findHits(event, Atof); ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); @@ -91,7 +92,7 @@ public boolean processDataEvent(DataEvent event) { ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters, projector.getProjections()); + rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters); } return true; } @@ -109,5 +110,6 @@ public boolean init() { } public static void main(String arg[]) { + } } From c5376fd378d25c49dcd3ad5d68461d1f9fee10e7 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Sat, 15 Feb 2025 16:13:15 -0500 Subject: [PATCH 76/82] refactor: changing paths --- .../java/org/jlab/rec/atof/{Cluster => cluster}/AtofCluster.java | 0 .../org/jlab/rec/atof/{Cluster => cluster}/ClusterFinder.java | 0 .../src/main/java/org/jlab/rec/atof/{Hit => hit}/AtofHit.java | 0 .../src/main/java/org/jlab/rec/atof/{Hit => hit}/BarHit.java | 0 .../src/main/java/org/jlab/rec/atof/{Hit => hit}/HitFinder.java | 0 .../jlab/rec/atof/{TrackMatch => trackMatch}/TrackProjection.java | 0 .../jlab/rec/atof/{TrackMatch => trackMatch}/TrackProjector.java | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/{Cluster => cluster}/AtofCluster.java (100%) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/{Cluster => cluster}/ClusterFinder.java (100%) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/{Hit => hit}/AtofHit.java (100%) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/{Hit => hit}/BarHit.java (100%) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/{Hit => hit}/HitFinder.java (100%) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/{TrackMatch => trackMatch}/TrackProjection.java (100%) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/{TrackMatch => trackMatch}/TrackProjector.java (100%) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/AtofCluster.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/AtofCluster.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/AtofCluster.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ClusterFinder.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/Cluster/ClusterFinder.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ClusterFinder.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/AtofHit.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/AtofHit.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/AtofHit.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/BarHit.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/BarHit.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/BarHit.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/HitFinder.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/Hit/HitFinder.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/HitFinder.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/trackMatch/TrackProjection.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjection.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/trackMatch/TrackProjection.java diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/trackMatch/TrackProjector.java similarity index 100% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/TrackMatch/TrackProjector.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/trackMatch/TrackProjector.java From 17dd519222692f36141590ba4798939ccb729e3f Mon Sep 17 00:00:00 2001 From: N-Plx Date: Sat, 15 Feb 2025 16:31:36 -0500 Subject: [PATCH 77/82] feat: reading magnetic field using swimmer tools --- .../main/java/org/jlab/rec/service/AtofEngine.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java index 10ba876cfd..a7e2164837 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java @@ -7,6 +7,7 @@ import org.jlab.io.base.DataEvent; import java.util.concurrent.atomic.AtomicInteger; +import org.jlab.clas.swimtools.Swim; import org.jlab.detector.calib.utils.DatabaseConstantProvider; import org.jlab.geom.base.Detector; import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; @@ -67,8 +68,15 @@ public boolean processDataEvent(DataEvent event) { if (run.get() == 0 || (run.get() != 0 && run.get() != newRun)) { run.set(newRun); } - + + //Do we need to read the event vx,vy,vz? + //If not, this part can be moved in the initialization of the engine. + double eventVx=0,eventVy=0,eventVz=0; //They should be in CM //Track Projector Initialisation with b field + Swim swim = new Swim(); + float magField[] = new float[3]; + swim.BfieldLab(eventVx, eventVy, eventVz, magField); + this.b = Math.sqrt(Math.pow(magField[0],2) + Math.pow(magField[1],2) + Math.pow(magField[2],2)); TrackProjector projector = new TrackProjector(); projector.setB(this.b); projector.projectTracks(event); @@ -110,6 +118,4 @@ public boolean init() { } public static void main(String arg[]) { - - } } From 014847f81386769775ad40de55616392be9dffe2 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Sat, 15 Feb 2025 16:38:14 -0500 Subject: [PATCH 78/82] fix: missing closing bracket --- .../alert/src/main/java/org/jlab/rec/service/AtofEngine.java | 1 + 1 file changed, 1 insertion(+) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java index a7e2164837..f18d4c3177 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java @@ -118,4 +118,5 @@ public boolean init() { } public static void main(String arg[]) { + } } From 1f4c469855a559d116d8e8960774591a95de0a74 Mon Sep 17 00:00:00 2001 From: Whitney Armstrong Date: Mon, 17 Feb 2025 15:01:44 -0600 Subject: [PATCH 79/82] Renamed things to use ATOF instead of Atof --- etc/bankdefs/hipo4/alert.json | 648 +++++++++--------- .../jlab/rec/atof/banks/RecoBankWriter.java | 30 +- .../{AtofCluster.java => ATOFCluster.java} | 28 +- .../jlab/rec/atof/cluster/ClusterFinder.java | 28 +- .../atof/hit/{AtofHit.java => ATOFHit.java} | 12 +- .../java/org/jlab/rec/atof/hit/BarHit.java | 16 +- .../java/org/jlab/rec/atof/hit/HitFinder.java | 18 +- .../{AtofEngine.java => ATOFEngine.java} | 8 +- 8 files changed, 389 insertions(+), 399 deletions(-) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/{AtofCluster.java => ATOFCluster.java} (91%) rename reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/{AtofHit.java => ATOFHit.java} (97%) rename reconstruction/alert/src/main/java/org/jlab/rec/service/{AtofEngine.java => ATOFEngine.java} (95%) diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index 775cfba259..5701d1ac61 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -1,330 +1,322 @@ [ - { - "name": "AHDC::Projections", - "group": 23000, - "item": 31, - "info": "Track Projections to ATOF", - "entries": [ - { - "name": "x_at_bar", - "type": "F", - "info": "x position at atof bar (middle surface) in mm" - }, { - "name": "y_at_bar", - "type": "F", - "info": "y position at atof bar (middle surface) in mm" - }, { - "name": "z_at_bar", - "type": "F", - "info": "z position at atof bar (middle surface) in mm" - },{ - "name": "L_at_bar", - "type": "F", - "info": "path length at atof bar (inner surface) in mm" - },{ - "name": "L_in_bar", - "type": "F", - "info": "path length inside atof bar in mm" - },{ - "name": "x_at_wedge", - "type": "F", - "info": "x position at atof wedge (middle surface) in mm" - }, { - "name": "y_at_wedge", - "type": "F", - "info": "y position at atof wedge (middle surface) in mm" - }, { - "name": "z_at_wedge", - "type": "F", - "info": "z position at atof wedge (middle surface) in mm" - },{ - "name": "L_at_wedge", - "type": "F", - "info": "path length at atof wedge (inner surface) in mm" - },{ - "name": "L_in_wedge", - "type": "F", - "info": "path length inside atof wedge in mm" - } - ] - },{ - "name": "ATOF::hits", - "group": 22500, - "item": 21, - "info": "Hits in ATOF", - "entries": [ - { - "name": "id", - "type": "S", - "info": "hit id" - }, { - "name": "sector", - "type": "I", - "info": "atof sector" - }, { - "name": "layer", - "type": "I", - "info": "atof layer" - },{ - "name": "component", - "type": "I", - "info": "atof component" - },{ - "name": "time", - "type": "F", - "info": "time in ns" - },{ - "name": "x", - "type": "F", - "info": "x position in mm" - }, { - "name": "y", - "type": "F", - "info": "y position in mm" - }, { - "name": "z", - "type": "F", - "info": "z position in mm" - },{ - "name": "energy", - "type": "F", - "info": "deposited energy in MeV" - },{ - "name": "inlength", - "type": "F", - "info": "path length inside the detector (from entrance to hit) in mm" - },{ - "name": "pathlength", - "type": "F", - "info": "path length to the hit in mm" - } - ] - },{ - "name": "ATOF::clusters", - "group": 22500, - "item": 22, - "info": "Clusters in ATOF", - "entries": [ - { - "name": "id", - "type": "S", - "info": "hit id" - }, { - "name": "barsize", - "type": "I", - "info": "number of hits from the bars" - }, { - "name": "wedgesize", - "type": "I", - "info": "number of hits from the wedges" - },{ - "name": "time", - "type": "F", - "info": "time in ns" - },{ - "name": "x", - "type": "F", - "info": "x position in mm" - }, { - "name": "y", - "type": "F", - "info": "y position in mm" - }, { - "name": "z", - "type": "F", - "info": "z position in mm" - },{ - "name": "energy", - "type": "F", - "info": "energy in MeV" - },{ - "name": "pathlength", - "type": "F", - "info": "path length to the cluster in mm" - },{ - "name": "inpathlength", - "type": "F", - "info": "path length inside the detector in mm" - } - ] - },{ - "name": "AHDC::Hits", - "group": 23000, - "item": 23, - "info": "Raw Hits", - "entries": [ - { - "name": "ID", - "type": "S", - "info": "hit id" - }, { - "name": "layer", - "type": "B", - "info": "layer number" - }, { - "name": "superlayer", - "type": "B", - "info": "superlayer number" - }, { - "name": "wire", - "type": "I", - "info": "wire number" - }, { - "name": "Doca", - "type": "D", - "info": "distance od closest approch (mm)" - } - ] - }, { - "name": "AHDC::PreClusters", - "group": 23000, - "item": 24, - "info": "Pre Clusters info", - "entries": [ - { - "name": "X", - "type": "F", - "info": "X info (mm)" - }, { - "name": "Y", - "type": "F", - "info": "Y info (mm)" - } - ] -}, { - "name": "AHDC::Clusters", - "group": 23000, - "item": 25, - "info": "Clusters info", - "entries": [ - { - "name": "X", - "type": "F", - "info": "X info (mm)" - }, { - "name": "Y", - "type": "F", - "info": "Y info (mm)" - }, { - "name": "Z", - "type": "F", - "info": "Z info (mm)" - } - ] -}, { - "name": "AHDC::Track", - "group": 23000, - "item": 21, - "info": "Reco Tracks", - "entries": [ - { - "name": "x", - "type": "F", - "info": "x position in mm" - }, { - "name": "y", - "type": "F", - "info": "y position in mm" - }, { - "name": "z", - "type": "F", - "info": "z position in mm" - }, { - "name": "px", - "type": "F", - "info": "px in MeV" - }, { - "name": "py", - "type": "F", - "info": "py in MeV" - }, { - "name": "pz", - "type": "F", - "info": "pz in MeV" - } - ] -}, { - "name": "AHDC::KFTrack", - "group": 23000, - "item": 26, - "info": "Reco Kalman Filter Tracks", - "entries": [ - { - "name": "x", - "type": "F", - "info": "x position in mm" - }, { - "name": "y", - "type": "F", - "info": "y position in mm" - }, { - "name": "z", - "type": "F", - "info": "z position in mm" - }, { - "name": "px", - "type": "F", - "info": "px in MeV" - }, { - "name": "py", - "type": "F", - "info": "py in MeV" - }, { - "name": "pz", - "type": "F", - "info": "pz in MeV" - } - ] -}, { - "name": "AHDC::MC", - "group": 23000, - "item": 22, - "info": "MC Tracks", - "entries": [ - { - "name": "x", - "type": "F", - "info": "x position in mm" - }, { - "name": "y", - "type": "F", - "info": "y position in mm" - }, { - "name": "z", - "type": "F", - "info": "z position in mm" - }, { - "name": "px", - "type": "F", - "info": "px in MeV" - }, { - "name": "py", - "type": "F", - "info": "py in MeV" - }, { - "name": "pz", - "type": "F", - "info": "pz in MeV" - } - ] -}, - { - "name": "AHDC_AI::Prediction", - "group": 23000, - "item": 30, - "info": "Prediction given by AI", - "entries": [ - {"name": "X1", "type": "F", "info": "X1 position of the 1th superprecluster (mm)"}, - {"name": "Y1", "type": "F", "info": "Y1 position of the 1th superprecluster (mm)"}, - {"name": "X2", "type": "F", "info": "X2 position of the 2nd superprecluster (mm)"}, - {"name": "Y2", "type": "F", "info": "Y2 position of the 2nd superprecluster (mm)"}, - {"name": "X3", "type": "F", "info": "X3 position of the 3rd superprecluster (mm)"}, - {"name": "Y3", "type": "F", "info": "Y3 position of the 3rd superprecluster (mm)"}, - {"name": "X4", "type": "F", "info": "X4 position of the 4th superprecluster (mm)"}, - {"name": "Y4", "type": "F", "info": "Y4 position of the 4th superprecluster (mm)"}, - {"name": "X5", "type": "F", "info": "X5 position of the 5th superprecluster (mm)"}, - {"name": "Y5", "type": "F", "info": "Y5 position of the 5th superprecluster (mm)"}, - {"name": "Pred", "type": "F", "info": "Prediction of the model: 0 mean bad track; 1 mean good track"} - ] - } + { + "name": "ALERT::Projections", + "group": 23000, + "item": 31, + "info": "Track Projections to ATOF", + "entries": [ + { + "name": "x_at_bar", + "type": "F", + "info": "x position at atof bar (middle surface) in mm" + }, { + "name": "y_at_bar", + "type": "F", + "info": "y position at atof bar (middle surface) in mm" + }, { + "name": "z_at_bar", + "type": "F", + "info": "z position at atof bar (middle surface) in mm" + },{ + "name": "L_at_bar", + "type": "F", + "info": "path length at atof bar (inner surface) in mm" + },{ + "name": "L_in_bar", + "type": "F", + "info": "path length inside atof bar in mm" + },{ + "name": "x_at_wedge", + "type": "F", + "info": "x position at atof wedge (middle surface) in mm" + }, { + "name": "y_at_wedge", + "type": "F", + "info": "y position at atof wedge (middle surface) in mm" + }, { + "name": "z_at_wedge", + "type": "F", + "info": "z position at atof wedge (middle surface) in mm" + },{ + "name": "L_at_wedge", + "type": "F", + "info": "path length at atof wedge (inner surface) in mm" + },{ + "name": "L_in_wedge", + "type": "F", + "info": "path length inside atof wedge in mm" + } + ] + },{ + "name": "ATOF::hits", + "group": 22500, + "item": 21, + "info": "Reconstructed ATOF hits", + "entries": [ + { + "name": "id", + "type": "S", + "info": "hit id" + }, { + "name": "sector", + "type": "I", + "info": "atof sector" + }, { + "name": "layer", + "type": "I", + "info": "atof layer" + },{ + "name": "component", + "type": "I", + "info": "atof component" + },{ + "name": "time", + "type": "F", + "info": "time in ns" + },{ + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + },{ + "name": "energy", + "type": "F", + "info": "deposited energy in MeV" + } + ] + },{ + "name": "ATOF::clusters", + "group": 22500, + "item": 22, + "info": "Clusters in ATOF", + "entries": [ + { + "name": "id", + "type": "S", + "info": "hit id" + }, { + "name": "N_bar", + "type": "I", + "info": "number of hits from the bars" + }, { + "name": "N_wedge", + "type": "I", + "info": "number of hits from the wedges" + },{ + "name": "time", + "type": "F", + "info": "time in ns" + },{ + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + },{ + "name": "energy", + "type": "F", + "info": "energy in MeV" + },{ + "name": "pathlength", + "type": "F", + "info": "path length to the cluster in mm" + },{ + "name": "inpathlength", + "type": "F", + "info": "path length inside the detector in mm" + } + ] + },{ + "name": "AHDC::Hits", + "group": 23000, + "item": 23, + "info": "Raw Hits", + "entries": [ + { + "name": "ID", + "type": "S", + "info": "hit id" + }, { + "name": "layer", + "type": "B", + "info": "layer number" + }, { + "name": "superlayer", + "type": "B", + "info": "superlayer number" + }, { + "name": "wire", + "type": "I", + "info": "wire number" + }, { + "name": "Doca", + "type": "D", + "info": "distance od closest approch (mm)" + } + ] + }, { + "name": "AHDC::PreClusters", + "group": 23000, + "item": 24, + "info": "Pre Clusters info", + "entries": [ + { + "name": "X", + "type": "F", + "info": "X info (mm)" + }, { + "name": "Y", + "type": "F", + "info": "Y info (mm)" + } + ] + }, { + "name": "AHDC::Clusters", + "group": 23000, + "item": 25, + "info": "Clusters info", + "entries": [ + { + "name": "X", + "type": "F", + "info": "X info (mm)" + }, { + "name": "Y", + "type": "F", + "info": "Y info (mm)" + }, { + "name": "Z", + "type": "F", + "info": "Z info (mm)" + } + ] + }, { + "name": "AHDC::Track", + "group": 23000, + "item": 21, + "info": "Reco Tracks", + "entries": [ + { + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + }, { + "name": "px", + "type": "F", + "info": "px in MeV" + }, { + "name": "py", + "type": "F", + "info": "py in MeV" + }, { + "name": "pz", + "type": "F", + "info": "pz in MeV" + } + ] + }, { + "name": "AHDC::KFTrack", + "group": 23000, + "item": 26, + "info": "Reco Kalman Filter Tracks", + "entries": [ + { + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + }, { + "name": "px", + "type": "F", + "info": "px in MeV" + }, { + "name": "py", + "type": "F", + "info": "py in MeV" + }, { + "name": "pz", + "type": "F", + "info": "pz in MeV" + } + ] + }, { + "name": "AHDC::MC", + "group": 23000, + "item": 22, + "info": "MC Tracks", + "entries": [ + { + "name": "x", + "type": "F", + "info": "x position in mm" + }, { + "name": "y", + "type": "F", + "info": "y position in mm" + }, { + "name": "z", + "type": "F", + "info": "z position in mm" + }, { + "name": "px", + "type": "F", + "info": "px in MeV" + }, { + "name": "py", + "type": "F", + "info": "py in MeV" + }, { + "name": "pz", + "type": "F", + "info": "pz in MeV" + } + ] + }, + { + "name": "AHDC_AI::Prediction", + "group": 23000, + "item": 30, + "info": "Prediction given by AI", + "entries": [ + {"name": "X1", "type": "F", "info": "X1 position of the 1th superprecluster (mm)"}, + {"name": "Y1", "type": "F", "info": "Y1 position of the 1th superprecluster (mm)"}, + {"name": "X2", "type": "F", "info": "X2 position of the 2nd superprecluster (mm)"}, + {"name": "Y2", "type": "F", "info": "Y2 position of the 2nd superprecluster (mm)"}, + {"name": "X3", "type": "F", "info": "X3 position of the 3rd superprecluster (mm)"}, + {"name": "Y3", "type": "F", "info": "Y3 position of the 3rd superprecluster (mm)"}, + {"name": "X4", "type": "F", "info": "X4 position of the 4th superprecluster (mm)"}, + {"name": "Y4", "type": "F", "info": "Y4 position of the 4th superprecluster (mm)"}, + {"name": "X5", "type": "F", "info": "X5 position of the 5th superprecluster (mm)"}, + {"name": "Y5", "type": "F", "info": "Y5 position of the 5th superprecluster (mm)"}, + {"name": "Pred", "type": "F", "info": "Prediction of the model: 0 mean bad track; 1 mean good track"} + ] + } ] diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 8bb4b16b02..06a4398351 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -3,8 +3,8 @@ import java.util.ArrayList; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.rec.atof.cluster.AtofCluster; -import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.cluster.ATOFCluster; +import org.jlab.rec.atof.hit.ATOFHit; import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.trackMatch.TrackProjection; @@ -20,7 +20,7 @@ public class RecoBankWriter { * Writes the bank of atof hits. * * @param event the {@link DataEvent} in which to add the bank - * @param wedgeHits the {@link ArrayList} of {@link AtofHit} containing the + * @param wedgeHits the {@link ArrayList} of {@link ATOFHit} containing the * wedge hits to be added to the bank * @param barHits the {@link ArrayList} of {@link BarHit} containing the bar * hits to be added to the bank @@ -28,9 +28,9 @@ public class RecoBankWriter { * @return {@link DataBank} the bank with all the hits read in the event. * */ - public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { + public static DataBank fillATOFHitBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits) { - ArrayList hitList = new ArrayList<>(); + ArrayList hitList = new ArrayList<>(); hitList.addAll(wedgeHits); hitList.addAll(barHits); @@ -59,14 +59,14 @@ public static DataBank fillAtofHitBank(DataEvent event, ArrayList wedge * Writes the bank of atof clusters. * * @param event the {@link DataEvent} in which to add the bank - * @param clusterList the {@link ArrayList} of {@link AtofCluster} + * @param clusterList the {@link ArrayList} of {@link ATOFCluster} * 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 fillAtofClusterBank(DataEvent event, ArrayList clusterList) { + public static DataBank fillATOFClusterBank(DataEvent event, ArrayList clusterList) { DataBank bank = event.createBank("ATOF::clusters", clusterList.size()); @@ -77,15 +77,13 @@ public static DataBank fillAtofClusterBank(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { + public int appendATOFBanks(DataEvent event, ArrayList wedgeHits, ArrayList barHits, ArrayList clusterList) { - DataBank hitbank = this.fillAtofHitBank(event, wedgeHits, barHits); + DataBank hitbank = this.fillATOFHitBank(event, wedgeHits, barHits); if (hitbank != null) { event.appendBank(hitbank); } else { return 1; } - DataBank clusterbank = fillAtofClusterBank(event, clusterList); + DataBank clusterbank = fillATOFClusterBank(event, clusterList); if (clusterbank != null) { event.appendBank(clusterbank); } else { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/AtofCluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ATOFCluster.java similarity index 91% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/AtofCluster.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ATOFCluster.java index 2e7cc2d5fa..8433e8554c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/AtofCluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ATOFCluster.java @@ -5,11 +5,11 @@ import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.rec.atof.constants.Parameters; -import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.ATOFHit; import org.jlab.rec.atof.hit.BarHit; /** - * The {@code AtofCluster} represents clusters in the atof + * The {@code ATOFCluster} represents clusters in the atof * *

    * Create clusters and compute their basic properties from the hits composing @@ -18,7 +18,7 @@ * * @author pilleux */ -public class AtofCluster { +public class ATOFCluster { /** * list of hits in the bars. @@ -27,7 +27,7 @@ public class AtofCluster { /** * list of hits in the wedges. */ - ArrayList wedgeHits; + ArrayList wedgeHits; /** * cluster properties:position [cm], time [ns], energy[MeV], path length * [cm] and length through the atof [cm], type of the maximum hit (to set @@ -45,11 +45,11 @@ public void setBarHits(ArrayList bar_hits) { this.barHits = bar_hits; } - public ArrayList getWedgeHits() { + public ArrayList getWedgeHits() { return wedgeHits; } - public void setWedgeHits(ArrayList wedge_hits) { + public void setWedgeHits(ArrayList wedge_hits) { this.wedgeHits = wedge_hits; } @@ -129,10 +129,10 @@ public void setTypeMaxHit(String typeMaxHit) { public final void computeClusterProperties() { this.energy = 0; double max_energy = -1; - AtofHit max_energy_hit = new AtofHit(); + ATOFHit max_energy_hit = new ATOFHit(); for (int i_wedge = 0; i_wedge < this.wedgeHits.size(); i_wedge++) { - AtofHit this_wedge_hit = this.wedgeHits.get(i_wedge); + ATOFHit this_wedge_hit = this.wedgeHits.get(i_wedge); double this_energy = this_wedge_hit.getEnergy(); this.energy += this_energy; if (this_energy > max_energy) { @@ -232,7 +232,7 @@ public int matchTrack(DataEvent event) { public double getEdepWedge() { double energy = 0; for (int i = 0; i < this.wedgeHits.size(); i++) { - AtofHit this_hit = this.wedgeHits.get(i); + ATOFHit this_hit = this.wedgeHits.get(i); energy += this_hit.getEnergy(); } return energy; @@ -241,7 +241,7 @@ public double getEdepWedge() { public double getEdepBar() { double energy = 0; for (int i = 0; i < this.barHits.size(); i++) { - AtofHit this_hit = this.barHits.get(i); + ATOFHit this_hit = this.barHits.get(i); energy += this_hit.getEnergy(); } return energy; @@ -275,10 +275,10 @@ public double getBeta() { * and computes the cluster properties. * * @param bar_hits a {@link ArrayList} of {@link BarHit}. - * @param wedge_hits a {@link ArrayList} of {@link AtofHit}. + * @param wedge_hits a {@link ArrayList} of {@link ATOFHit}. * */ - public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { + public ATOFCluster(ArrayList bar_hits, ArrayList wedge_hits) { this.barHits = bar_hits; this.wedgeHits = wedge_hits; this.computeClusterProperties(); @@ -289,10 +289,10 @@ public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits) { * and computes the cluster properties. * * @param bar_hits a {@link ArrayList} of {@link BarHit}. - * @param wedge_hits a {@link ArrayList} of {@link AtofHit}. + * @param wedge_hits a {@link ArrayList} of {@link ATOFHit}. * */ - public AtofCluster(ArrayList bar_hits, ArrayList wedge_hits, DataEvent event) { + public ATOFCluster(ArrayList bar_hits, ArrayList wedge_hits, DataEvent event) { this.barHits = bar_hits; this.wedgeHits = wedge_hits; this.computeClusterProperties(); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ClusterFinder.java index 271e9a094a..19cabb1f3d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/cluster/ClusterFinder.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import org.jlab.io.base.DataEvent; import org.jlab.rec.atof.constants.Parameters; -import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.ATOFHit; import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; @@ -12,7 +12,7 @@ * *

    * Uses found hits information. - * Creates a {@link AtofCluster} matching them. + * Creates a {@link ATOFCluster} matching them. *

    * * @author pilleux @@ -22,25 +22,25 @@ public class ClusterFinder { /** * list of clusters. */ - private ArrayList clusters; + private ArrayList clusters; /** * Sets the list of clusters. * - * @param clusters a {@link ArrayList} of {@link AtofCluster}. + * @param clusters a {@link ArrayList} of {@link ATOFCluster}. * */ - public void setClusters(ArrayList clusters) { + public void setClusters(ArrayList clusters) { this.clusters = clusters; } /** * Gets the list of clusters. * - * @return a {@link ArrayList} of {@link AtofCluster}. + * @return a {@link ArrayList} of {@link ATOFCluster}. * */ - public ArrayList getClusters() { + public ArrayList getClusters() { return clusters; } @@ -59,19 +59,19 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { clusters.clear(); //Getting the list of hits, they must have been ordered by energy already - ArrayList wedge_hits = hitfinder.getWedgeHits(); + ArrayList wedge_hits = hitfinder.getWedgeHits(); ArrayList bar_hits = hitfinder.getBarHits(); //Looping through wedge hits first for (int i_wedge = 0; i_wedge < wedge_hits.size(); i_wedge++) { - AtofHit this_wedge_hit = wedge_hits.get(i_wedge); + ATOFHit this_wedge_hit = wedge_hits.get(i_wedge); //Make a cluster for each wedge hit that has not been previously clustered if (this_wedge_hit.getIsInACluster()) { continue; } //Holding onto the hits composing the cluster - ArrayList this_cluster_wedge_hits = new ArrayList<>(); + ArrayList this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); //Indicate that this hit now is in a cluster @@ -82,7 +82,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { //Check if other wedge hits should be clustered with the current one //Start from the index of the current one and look at less energetic hits for (int j_wedge = i_wedge + 1; j_wedge < wedge_hits.size(); j_wedge++) { - AtofHit other_wedge_hit = wedge_hits.get(j_wedge); + ATOFHit other_wedge_hit = wedge_hits.get(j_wedge); //If that other hit is already involved in a cluster, skip it if (other_wedge_hit.getIsInACluster()) { continue; @@ -140,7 +140,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { }//End loop bar hits //After all wedge and bar hits have been grouped, build the cluster - AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits, event); + ATOFCluster cluster = new ATOFCluster(this_cluster_bar_hits, this_cluster_wedge_hits, event); //And add it to the list of clusters clusters.add(cluster); }//End loop on all wedge hits @@ -153,7 +153,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { continue; } - ArrayList this_cluster_wedge_hits = new ArrayList<>(); + ArrayList this_cluster_wedge_hits = new ArrayList<>(); ArrayList this_cluster_bar_hits = new ArrayList<>(); this_bar_hit.setIsInACluster(true); this_cluster_bar_hits.add(this_bar_hit); @@ -187,7 +187,7 @@ public void makeClusters(DataEvent event, HitFinder hitfinder) { } } } - AtofCluster cluster = new AtofCluster(this_cluster_bar_hits, this_cluster_wedge_hits, event); + ATOFCluster cluster = new ATOFCluster(this_cluster_bar_hits, this_cluster_wedge_hits, event); clusters.add(cluster); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/AtofHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/ATOFHit.java similarity index 97% rename from reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/AtofHit.java rename to reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/ATOFHit.java index 28a69fbd8b..c0ffadd359 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/AtofHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/ATOFHit.java @@ -13,7 +13,7 @@ * * @author npilleux */ -public class AtofHit { +public class ATOFHit { private int sector, layer, component, order; private int tdc, tot; @@ -285,7 +285,7 @@ public final int convertSLCToXYZ(Detector atof) { } /** - * Compares two AtofHit objects to check if they match in the bar. + * Compares two ATOFHit objects to check if they match in the bar. *
      *
    • If the sector or layer of the two hits do not match, the method * returns {@code false}.
    • @@ -297,10 +297,10 @@ public final int convertSLCToXYZ(Detector atof) { * If none of these conditions are violated, the method returns * {@code true}, indicating the two hits match. * - * @param hit2match The AtofHit object to compare with the current instance. + * @param hit2match The ATOFHit object to compare with the current instance. * @return {@code true} if the hits match; {@code false} otherwise. */ - public boolean matchBar(AtofHit hit2match) { + public boolean matchBar(ATOFHit hit2match) { if (this.getSector() != hit2match.getSector()) { //Two hits in different sectors return false; @@ -342,7 +342,7 @@ public double getPhi() { * @param atof Detector object representing the atof, used to calculate * spatial coordinates. */ - public AtofHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { + public ATOFHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) { this.sector = sector; this.layer = layer; this.component = component; @@ -357,7 +357,7 @@ public AtofHit(int sector, int layer, int component, int order, int tdc, int tot this.convertSLCToXYZ(atof); } - public AtofHit(){ + public ATOFHit(){ } /** diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/BarHit.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/BarHit.java index 7bba7a1ab2..bbd8fd5316 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/BarHit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/BarHit.java @@ -4,30 +4,30 @@ /** * - * Represents a hit in the atof bar. Extends class AtofHit. Is further defined + * Represents a hit in the atof bar. Extends class ATOFHit. Is further defined * by the two hits upstream and downstream composing a full bar hit. z position, * time and energy are defined from the up/down hits. * * @author npilleux */ -public class BarHit extends AtofHit { +public class BarHit extends ATOFHit { //A bar hit is the combination of a downstream and upstream hits - private AtofHit hitUp, hitDown; + private ATOFHit hitUp, hitDown; - public AtofHit getHitUp() { + public ATOFHit getHitUp() { return hitUp; } - public void setHitUp(AtofHit hit_up) { + public void setHitUp(ATOFHit hit_up) { this.hitUp = hit_up; } - public AtofHit getHitDown() { + public ATOFHit getHitDown() { return hitDown; } - public void setHitDown(AtofHit hit_down) { + public void setHitDown(ATOFHit hit_down) { this.hitDown = hit_down; } @@ -74,7 +74,7 @@ public final void computeEnergy() { this.setEnergy(Edep_up + Edep_down); } - public BarHit(AtofHit hit_down, AtofHit hit_up) { + public BarHit(ATOFHit hit_down, ATOFHit hit_up) { boolean hits_match = hit_down.matchBar(hit_up); if (!hits_match) { throw new UnsupportedOperationException("Hits do not match \n"); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/HitFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/HitFinder.java index 83bc3c5012..4a9592cb21 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/HitFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/HitFinder.java @@ -13,7 +13,7 @@ * Uses atof tdc bank information * * Creates a {@link ArrayList} of {@link BarHit} for bar hits read. - * Creates a {@link ArrayList} of {@link AtofHit} for wedge hits read. + * Creates a {@link ArrayList} of {@link ATOFHit} for wedge hits read. * *

      * @@ -28,7 +28,7 @@ public class HitFinder { /** * list of wedge hits */ - private ArrayList wedgeHits; + private ArrayList wedgeHits; /** * Default constructor that initializes the list of hits as new empty @@ -48,11 +48,11 @@ public void setBarHits(ArrayList bar_hits) { this.barHits = bar_hits; } - public ArrayList getWedgeHits() { + public ArrayList getWedgeHits() { return wedgeHits; } - public void setWedgeHits(ArrayList wedge_hits) { + public void setWedgeHits(ArrayList wedge_hits) { this.wedgeHits = wedge_hits; } @@ -72,8 +72,8 @@ public void findHits(DataEvent event, Detector atof) { DataBank bank = event.getBank("ATOF::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<>(); + ArrayList hit_up = new ArrayList<>(); + ArrayList hit_down = new ArrayList<>(); //Looping through all hits for (int i = 0; i < nt; i++) { //Getting their properties @@ -84,7 +84,7 @@ public void findHits(DataEvent event, Detector atof) { int tdc = bank.getInt("TDC", i); int tot = bank.getInt("ToT", i); //Building a Hit - AtofHit hit = new AtofHit(sector, layer, component, order, tdc, tot, atof); + ATOFHit hit = new ATOFHit(sector, layer, component, order, tdc, tot, atof); if (hit.getEnergy() < 0.01) { continue; //energy threshold } @@ -110,10 +110,10 @@ public void findHits(DataEvent event, Detector atof) { //Starting loop through up hits in the bar for (int i_up = 0; i_up < hit_up.size(); i_up++) { - AtofHit this_hit_up = hit_up.get(i_up); + ATOFHit this_hit_up = hit_up.get(i_up); //Starting loop through down hits in the bar for (int i_down = 0; i_down < hit_down.size(); i_down++) { - AtofHit this_hit_down = hit_down.get(i_down); + ATOFHit this_hit_down = hit_down.get(i_down); //Matching the hits: if same module and different order, they make up a bar hit if (this_hit_up.matchBar(this_hit_down)) { //Bar hits are matched to ahdc tracks and listed diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java similarity index 95% rename from reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java rename to reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java index f18d4c3177..4b32f792e9 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AtofEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -15,7 +15,7 @@ import org.jlab.rec.atof.banks.RecoBankWriter; import org.jlab.rec.atof.cluster.AtofCluster; import org.jlab.rec.atof.cluster.ClusterFinder; -import org.jlab.rec.atof.hit.AtofHit; +import org.jlab.rec.atof.hit.ATOFHit; import org.jlab.rec.atof.hit.BarHit; import org.jlab.rec.atof.hit.HitFinder; import org.jlab.rec.atof.trackMatch.TrackProjector; @@ -26,9 +26,9 @@ * @author npilleux * */ -public class AtofEngine extends ReconstructionEngine { +public class ATOFEngine extends ReconstructionEngine { - public AtofEngine() { + public ATOFEngine() { super("ATOF", "pilleux", "1.0"); } @@ -85,7 +85,7 @@ public boolean processDataEvent(DataEvent event) { HitFinder hitfinder = new HitFinder(); hitfinder.findHits(event, Atof); - ArrayList WedgeHits = hitfinder.getWedgeHits(); + ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); //Exit if hit lists are empty From 3cd22c166c4efb3c1df773d25ea0dbfbdc52c5ae Mon Sep 17 00:00:00 2001 From: Whitney Armstrong Date: Mon, 17 Feb 2025 15:06:04 -0600 Subject: [PATCH 80/82] More name changes --- .../java/org/jlab/rec/service/ATOFEngine.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java index 4b32f792e9..117af7ba61 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/ATOFEngine.java @@ -13,7 +13,7 @@ import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory; import org.jlab.io.hipo.HipoDataSource; import org.jlab.rec.atof.banks.RecoBankWriter; -import org.jlab.rec.atof.cluster.AtofCluster; +import org.jlab.rec.atof.cluster.ATOFCluster; import org.jlab.rec.atof.cluster.ClusterFinder; import org.jlab.rec.atof.hit.ATOFHit; import org.jlab.rec.atof.hit.BarHit; @@ -21,7 +21,7 @@ import org.jlab.rec.atof.trackMatch.TrackProjector; /** - * Service to return reconstructed Atof hits and clusters + * Service to return reconstructed ATOF hits and clusters * * @author npilleux * @@ -35,7 +35,7 @@ public ATOFEngine() { RecoBankWriter rbc; private final AtomicInteger run = new AtomicInteger(0); - private Detector Atof; + private Detector ATOF; private double b; //Magnetic field public void setB(double B) { @@ -44,11 +44,11 @@ public void setB(double B) { public double getB() { return b; } - public void setAtof(Detector ATOF) { - this.Atof = ATOF; + public void setATOF(Detector ATOF) { + this.ATOF = ATOF; } - public Detector getAtof() { - return Atof; + public Detector getATOF() { + return ATOF; } @Override @@ -83,7 +83,7 @@ public boolean processDataEvent(DataEvent event) { rbc.appendMatchBanks(event, projector.getProjections()); //Hit finder init HitFinder hitfinder = new HitFinder(); - hitfinder.findHits(event, Atof); + hitfinder.findHits(event, ATOF); ArrayList WedgeHits = hitfinder.getWedgeHits(); ArrayList BarHits = hitfinder.getBarHits(); @@ -97,10 +97,10 @@ public boolean processDataEvent(DataEvent event) { ClusterFinder clusterFinder = new ClusterFinder(); clusterFinder.makeClusters(event,hitfinder); - ArrayList Clusters = clusterFinder.getClusters(); + ArrayList Clusters = clusterFinder.getClusters(); if (WedgeHits.size() != 0 || BarHits.size() != 0) { - rbc.appendAtofBanks(event, WedgeHits, BarHits, Clusters); + rbc.appendATOFBanks(event, WedgeHits, BarHits, Clusters); } return true; } @@ -111,7 +111,7 @@ public boolean init() { AlertTOFFactory factory = new AlertTOFFactory(); DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default"); - this.Atof = factory.createDetectorCLAS(cp); + this.ATOF = factory.createDetectorCLAS(cp); this.registerOutputBank("ATOF::hits", "ATOF::clusters"); return true; From 4e6c911341df12400a5a91297826b1dc4c8bf0df Mon Sep 17 00:00:00 2001 From: Whitney Armstrong Date: Mon, 17 Feb 2025 15:08:06 -0600 Subject: [PATCH 81/82] Missed bank name change. --- .../src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index 06a4398351..bacbf0de57 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -101,7 +101,7 @@ public static DataBank fillATOFClusterBank(DataEvent event, ArrayList projections) { - DataBank bank = event.createBank("AHDC::Projections", projections.size()); + DataBank bank = event.createBank("ALERT::Projections", projections.size()); if (bank == null) { System.err.println("COULD NOT CREATE A AHDC::Projections BANK!!!!!!"); From e83adc9ed1dee9bd3043aa0dad238fc00ec206da Mon Sep 17 00:00:00 2001 From: Whitney Armstrong Date: Mon, 17 Feb 2025 15:21:02 -0600 Subject: [PATCH 82/82] Missed AHDC -> ALERT Projections --- .../src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java | 2 +- .../src/main/java/org/jlab/rec/atof/cluster/ATOFCluster.java | 2 +- .../main/java/org/jlab/rec/atof/trackMatch/TrackProjector.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java index bacbf0de57..b619956f7e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/atof/banks/RecoBankWriter.java @@ -104,7 +104,7 @@ public static DataBank fillProjectionsBank(DataEvent event, ArrayList