From ca09bc64cc6bbeb0ffc686bd0bc7589d981c06f5 Mon Sep 17 00:00:00 2001 From: N-Plx Date: Mon, 13 Jan 2025 10:51:29 -0600 Subject: [PATCH 01/20] 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 000000000..ce2d3d181 --- /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/20] 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 ce2d3d181..322eb8bf1 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 000000000..202f943a4 --- /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/20] 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 000000000..eb0e55caa --- /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/20] 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 000000000..931d43ff8 --- /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 000000000..22ae7ecf9 --- /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 322eb8bf1..20ebc190c 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 202f943a4..0317d17d1 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/20] 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 000000000..9ccbbe26d --- /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 000000000..feb790fd2 --- /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/20] 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 931d43ff8..102b61b6c 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 20ebc190c..17ceecbef 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 0317d17d1..5365b3255 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/20] 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 eb0e55caa..345a0afa1 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/20] 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 22ae7ecf9..9830e4615 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/20] 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 7c125eb9c..f7cf6b16a 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/20] 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 f7cf6b16a..c614e9218 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 9ccbbe26d..cae3e33f6 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 feb790fd2..652bbfa0c 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/20] 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 c614e9218..e616780db 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 cae3e33f6..aaec5d3b6 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 652bbfa0c..bd0b11103 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/20] 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 102b61b6c..76e441c7e 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 9830e4615..b6f50b496 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 17ceecbef..d5bbf0ae0 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 5365b3255..8d2e0d5c9 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 aaec5d3b6..5138d1508 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 bd0b11103..f8e2b3c8c 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/20] 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 f8e2b3c8c..cca125510 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 000000000..d76a38d9e --- /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/20] 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 d5bbf0ae0..ef5889f8e 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 8d2e0d5c9..9c1428cba 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/20] 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 d76a38d9e..89c7cce60 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/20] 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 ef5889f8e..77b23dad4 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 9c1428cba..b71a03b86 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 c8d784cc2..adece8494 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/20] 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 e616780db..ea6f4e251 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/20] 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 000000000..94479d937 --- /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/20] 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 76e441c7e..55b31eb9f 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 b6f50b496..c0ed07c9c 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/20] 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 55b31eb9f..87c895082 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 c0ed07c9c..28e6af5ce 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 77b23dad4..88d0a4e16 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 b71a03b86..3edae6bd5 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 adece8494..8f33db7f6 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 cca125510..90d5936b8 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 94479d937..c87040d17 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 89c7cce60..2c15a5200 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 {