From 87011e4bb28ec82619b4fced0fb6e14c98d3c29a Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Thu, 15 Feb 2024 20:10:08 -0500 Subject: [PATCH 01/51] Changed the data bank to process the hits in AHDCEngine: It should have been AHDC::adc (since corresponding HitReader also uses this bank), it was AHDC::tdc. --- .../alert/src/main/java/org/jlab/rec/service/AHDCEngine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index a1a992d699..2bed94d9f2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -69,7 +69,8 @@ public boolean processDataEvent(DataEvent event) { magfield = 50 * magfieldfactor; - if (event.hasBank("AHDC::tdc")) { + //if (event.hasBank("AHDC::tdc")) { + if (event.hasBank("AHDC::adc")) { // I) Read raw hit HitReader hitRead = new HitReader(event, simulation); From 10559cd61af948a27b46b57ae0c902a2f016eb87 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Thu, 29 Feb 2024 12:21:33 -0500 Subject: [PATCH 02/51] reversed the change in AHDCEngine. --- .../alert/src/main/java/org/jlab/rec/service/AHDCEngine.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index 2bed94d9f2..5870cf9e5d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -69,8 +69,8 @@ public boolean processDataEvent(DataEvent event) { magfield = 50 * magfieldfactor; - //if (event.hasBank("AHDC::tdc")) { - if (event.hasBank("AHDC::adc")) { + if (event.hasBank("AHDC::tdc")) { + //if (event.hasBank("AHDC::adc")) { // I) Read raw hit HitReader hitRead = new HitReader(event, simulation); From 08cd67520e413ee07c2b6a5fb7e4896113d94e16 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 22 Apr 2024 15:06:34 -0400 Subject: [PATCH 03/51] Reverted (again???) the hit type to be read in AHDC reconstruction from TDC to ADC. --- .../alert/src/main/java/org/jlab/rec/service/AHDCEngine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index f7597d4ca0..97e2d65f5e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -69,7 +69,8 @@ public boolean processDataEvent(DataEvent event) { magfield = 50 * magfieldfactor; - if (event.hasBank("AHDC::tdc")) { + //if (event.hasBank("AHDC::tdc")) { + if (event.hasBank("AHDC::adc")) { // I) Read raw hit HitReader hitRead = new HitReader(event, simulation); From 10f0972dddf85dcd590b91c44f2bb0a813d17a66 Mon Sep 17 00:00:00 2001 From: mpaolone Date: Tue, 23 Apr 2024 07:55:55 -0600 Subject: [PATCH 04/51] changed AHDC bank back to ADC only --- etc/bankdefs/hipo4/data.json | 13 ------------- .../main/java/org/jlab/rec/service/AHDCEngine.java | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/etc/bankdefs/hipo4/data.json b/etc/bankdefs/hipo4/data.json index a1ef21a083..5ea2d74fbd 100644 --- a/etc/bankdefs/hipo4/data.json +++ b/etc/bankdefs/hipo4/data.json @@ -14,19 +14,6 @@ { "name":"ped" , "type":"S", "info":"pedestal from pulse analysis"} ] }, - { - "name" : "AHDC::tdc", - "group": 22400, - "item" : 12, - "info": "TDC bank for the ALERT Wire Chamber", - "entries":[ - { "name":"sector" , "type":"B", "info":"sector 1"}, - { "name":"layer" , "type":"B", "info":"layer 1-5"}, - { "name":"component" , "type":"S", "info":"wire number"}, - { "name":"order" , "type":"B", "info":"Stereo angle 0 - in, 1 - out"}, - { "name":"TDC" , "type":"I", "info":"TDC value"} - ] - }, { "name" : "BMT::adc", "group": 20100, diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index a1a992d699..b1c1791c2e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -69,7 +69,7 @@ public boolean processDataEvent(DataEvent event) { magfield = 50 * magfieldfactor; - if (event.hasBank("AHDC::tdc")) { + if (event.hasBank("AHDC::adc")) { // I) Read raw hit HitReader hitRead = new HitReader(event, simulation); From 9440e2117748923e6e45964c7f3a753667f3b7c4 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:19:16 -0400 Subject: [PATCH 05/51] remove redundant checks --- .../org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java index 4057a9b678..f544ee06d5 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java @@ -60,7 +60,6 @@ public AlertTOFDetector createDetectorLocal(ConstantProvider cp) { @Override public AlertTOFSector createSector(ConstantProvider cp, int sectorId) { - if (!(0 <= sectorId && sectorId < nsectors)) throw new IllegalArgumentException("Error: invalid sector=" + sectorId); AlertTOFSector sector = new AlertTOFSector(sectorId); for (int superlayerId = 0; superlayerId < nsuperl; superlayerId++) sector.addSuperlayer(createSuperlayer(cp, sectorId, superlayerId)); @@ -69,8 +68,6 @@ public AlertTOFSector createSector(ConstantProvider cp, int sectorId) { @Override public AlertTOFSuperlayer createSuperlayer(ConstantProvider cp, int sectorId, int superlayerId) { - if (!(0 <= sectorId && sectorId < nsectors)) throw new IllegalArgumentException("Error: invalid sector=" + sectorId); - if (!(0 <= superlayerId && superlayerId < nsuperl)) throw new IllegalArgumentException("Error: invalid superlayer=" + superlayerId); AlertTOFSuperlayer superlayer = new AlertTOFSuperlayer(sectorId, superlayerId); if (superlayerId == 0) { From c95e068e819339323fbc4ddcb03010000eea3162 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:19:56 -0400 Subject: [PATCH 06/51] remove unused objects --- .../org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java index f544ee06d5..269f6c8f81 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java @@ -107,8 +107,6 @@ public AlertTOFLayer createLayer(ConstantProvider cp, int sectorId, int superlay AlertTOFLayer layer = new AlertTOFLayer(sectorId, superlayerId, layerId); - List planes = new ArrayList<>(); - double len_b = layerId * pad_z + layerId * gap_pad_z; // back paddle plan double len_f = len_b + pad_z; // front paddle plan double Rl = R0; @@ -152,7 +150,6 @@ public AlertTOFLayer createLayer(ConstantProvider cp, int sectorId, int superlay Plane3D plane = new Plane3D(0, Rl, 0, 0, 1, 0); plane.rotateZ(sectorId * openAng_sector_rad - Math.toRadians(90)); - planes.add(plane); return layer; } From 11d695436c95a3b0e131fa7aa54bd93629e43d2a Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:20:29 -0400 Subject: [PATCH 07/51] cleanup --- .../geom/detector/alert/ATOF/AlertTOFFactory.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java index 269f6c8f81..bde7b251ec 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java @@ -1,11 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -//package clas12vis; - package org.jlab.geom.detector.alert.ATOF; import org.jlab.geom.base.ConstantProvider; @@ -16,9 +8,6 @@ import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Transformation3D; -import java.util.ArrayList; -import java.util.List; - /** * @author viktoriya * this is the latest ATOF geometry class to be used in reco. and in GEMC simulations! From 3420bb97c4c247c079dc5479f161f5a799f79848 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:30:34 -0400 Subject: [PATCH 08/51] leave internal indexing at zero, output at 1 --- .../org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java index bde7b251ec..7354fd4673 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java @@ -49,7 +49,7 @@ public AlertTOFDetector createDetectorLocal(ConstantProvider cp) { @Override public AlertTOFSector createSector(ConstantProvider cp, int sectorId) { - AlertTOFSector sector = new AlertTOFSector(sectorId); + AlertTOFSector sector = new AlertTOFSector(sectorId+1); for (int superlayerId = 0; superlayerId < nsuperl; superlayerId++) sector.addSuperlayer(createSuperlayer(cp, sectorId, superlayerId)); return sector; @@ -57,7 +57,7 @@ public AlertTOFSector createSector(ConstantProvider cp, int sectorId) { @Override public AlertTOFSuperlayer createSuperlayer(ConstantProvider cp, int sectorId, int superlayerId) { - AlertTOFSuperlayer superlayer = new AlertTOFSuperlayer(sectorId, superlayerId); + AlertTOFSuperlayer superlayer = new AlertTOFSuperlayer(sectorId+1, superlayerId+1); if (superlayerId == 0) { int nlayers0 = 1; @@ -94,7 +94,7 @@ public AlertTOFLayer createLayer(ConstantProvider cp, int sectorId, int superlay double gap_pad_z = 0.3d; // mm, gap between paddles in z - AlertTOFLayer layer = new AlertTOFLayer(sectorId, superlayerId, layerId); + AlertTOFLayer layer = new AlertTOFLayer(sectorId+1, superlayerId+1, layerId+1); double len_b = layerId * pad_z + layerId * gap_pad_z; // back paddle plan double len_f = len_b + pad_z; // front paddle plan From d6fd779cdd8702d72c3cc6a4e52a7564f45b35cf Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:37:33 -0400 Subject: [PATCH 09/51] cleanup --- .../org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java index 9679141708..cc4acf9b98 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package org.jlab.geom.detector.alert.AHDC; import org.jlab.geom.base.ConstantProvider; From 46e33d0a7e707c8468cce7052f66ec58723507eb Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:38:07 -0400 Subject: [PATCH 10/51] remove redundant checks --- .../java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java index cc4acf9b98..1beef65287 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java @@ -54,7 +54,6 @@ public AlertDCDetector createDetectorLocal(ConstantProvider cp) { @Override public AlertDCSector createSector(ConstantProvider cp, int sectorId) { - if (!(0 <= sectorId && sectorId < nsectors)) throw new IllegalArgumentException("Error: invalid sector=" + sectorId); AlertDCSector sector = new AlertDCSector(sectorId); for (int superlayerId = 0; superlayerId < nsuperl; superlayerId++) sector.addSuperlayer(createSuperlayer(cp, sectorId, superlayerId)); @@ -64,8 +63,6 @@ public AlertDCSector createSector(ConstantProvider cp, int sectorId) { @Override public AlertDCSuperlayer createSuperlayer(ConstantProvider cp, int sectorId, int superlayerId) { - if (!(0 <= sectorId && sectorId < nsectors)) throw new IllegalArgumentException("Error: invalid sector=" + sectorId); - if (!(0 <= superlayerId && superlayerId < nsuperl)) throw new IllegalArgumentException("Error: invalid superlayer=" + superlayerId); AlertDCSuperlayer superlayer = new AlertDCSuperlayer(sectorId, superlayerId); for (int layerId = 0; layerId < nlayers; layerId++) From 268c239bd202090e9095d03d52487c69505b7cad Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:40:47 -0400 Subject: [PATCH 11/51] leave internal indexing from zero, output from 1 --- .../org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java index 1beef65287..0a9bd13026 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java @@ -54,7 +54,7 @@ public AlertDCDetector createDetectorLocal(ConstantProvider cp) { @Override public AlertDCSector createSector(ConstantProvider cp, int sectorId) { - AlertDCSector sector = new AlertDCSector(sectorId); + AlertDCSector sector = new AlertDCSector(sectorId+1); for (int superlayerId = 0; superlayerId < nsuperl; superlayerId++) sector.addSuperlayer(createSuperlayer(cp, sectorId, superlayerId)); return sector; @@ -63,7 +63,7 @@ public AlertDCSector createSector(ConstantProvider cp, int sectorId) { @Override public AlertDCSuperlayer createSuperlayer(ConstantProvider cp, int sectorId, int superlayerId) { - AlertDCSuperlayer superlayer = new AlertDCSuperlayer(sectorId, superlayerId); + AlertDCSuperlayer superlayer = new AlertDCSuperlayer(sectorId+1, superlayerId+1); for (int layerId = 0; layerId < nlayers; layerId++) superlayer.addLayer(createLayer(cp, sectorId, superlayerId, layerId)); @@ -77,7 +77,7 @@ public AlertDCLayer createLayer(ConstantProvider cp, int sectorId, int superlaye if (!(0 <= superlayerId && superlayerId < nsuperl)) throw new IllegalArgumentException("Error: invalid superlayer=" + superlayerId); if (!(0 <= layerId && layerId < nlayers)) throw new IllegalArgumentException("Error: invalid layer=" + layerId); - AlertDCLayer layer = new AlertDCLayer(sectorId, superlayerId, layerId); + AlertDCLayer layer = new AlertDCLayer(sectorId+1, superlayerId+1, layerId+1); // Load constants AHDC // Length in Z mm! @@ -213,7 +213,7 @@ public AlertDCLayer createLayer(ConstantProvider cp, int sectorId, int superlaye // not possible to add directly PrismaticComponent class because it is an ABSTRACT // a new class should be created: public class NewClassWire extends PrismaticComponent {...} // 5 top points & 5 bottom points with convexe shape. Concave shape is not supported. - AlertDCWire wire = new AlertDCWire(wireId, wireLine, firstF, secondF); + AlertDCWire wire = new AlertDCWire(wireId+1, wireLine, firstF, secondF); // Add wire object to the list layer.addComponent(wire); } From 4a9647f93966e6055bda4d2ac7601953c45095a5 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 22 May 2024 17:49:54 -0400 Subject: [PATCH 12/51] simplicy logic --- .../java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java index e28a16b3a2..3603c890b8 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java @@ -57,10 +57,10 @@ public void findPreCluster(List AHDC_hits) { hit.setUse(true); int expected_wire_plus = hit.getWireId() + 1; int expected_wire_minus = hit.getWireId() - 1; - if (hit.getWireId() - 1 == 0) { + if (hit.getWireId() == 1) { expected_wire_minus = hit.getNbOfWires(); } - if (hit.getWireId() + 1 == hit.getNbOfWires() + 1) { + if (hit.getWireId() == hit.getNbOfWires() ) { expected_wire_plus = 1; } From 481795d55d2d257cdfa3381041d9ff9fa4d15bd6 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 23 May 2024 10:43:31 -0400 Subject: [PATCH 13/51] use s/l/c/o indexing starting from 1 (and stop changing wire number internally to start from zero) (this requires removing a manual +1 offset for wire number in a perl script in GEMC) --- .../org/jlab/rec/ahdc/Cluster/Cluster.java | 4 +++- .../jlab/rec/ahdc/Cluster/ClusterFinder.java | 8 +++---- .../org/jlab/rec/ahdc/KalmanFilter/Hit.java | 22 +++++++++---------- .../rec/ahdc/PreCluster/PreClusterFinder.java | 16 +++++++------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java index 6d90337e05..14325fb99e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java @@ -27,7 +27,9 @@ public Cluster(PreCluster precluster, PreCluster other_precluster) { _PreClusters_list.add(precluster); _PreClusters_list.add(other_precluster); this._Radius = (precluster.get_Radius() + other_precluster.get_Radius()) / 2; - this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(20) * Math.pow(-1, precluster.get_Super_layer()) - Math.toRadians(20) * Math.pow(-1, other_precluster.get_Super_layer()))) * 300 - 150; + + this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(20) * Math.pow(-1, precluster.get_Super_layer()-1) - Math.toRadians(20) * Math.pow(-1, other_precluster.get_Super_layer()-1))) * 300 - 150; + double x1 = -precluster.get_Radius() * Math.sin(precluster.get_Phi()); double y1 = -precluster.get_Radius() * Math.cos(precluster.get_Phi()); double x2 = -other_precluster.get_Radius() * Math.sin(other_precluster.get_Phi()); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java index a8db6bd9f7..e8033525e5 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java @@ -16,7 +16,7 @@ private void find_associate_cluster(PreCluster precluster, List AHDC if (precluster.get_Super_layer() == super_layer && precluster.get_Layer() == layer && !precluster.is_Used()) { ArrayList possible_precluster_list = new ArrayList<>(); - double phi_mean = precluster.get_Phi() + 0.1 * Math.pow(-1, precluster.get_Super_layer()); + double phi_mean = precluster.get_Phi() + 0.1 * Math.pow(-1, precluster.get_Super_layer()-1); double x = -precluster.get_Radius() * Math.sin(phi_mean); double y = -precluster.get_Radius() * Math.cos(phi_mean); for (PreCluster other_precluster : AHDC_precluster_list) { @@ -67,10 +67,10 @@ public void findCluster(List AHDC_precluster_list) { // Collections.sort(AHDC_precluster_list); for (PreCluster precluster : AHDC_precluster_list) { - find_associate_cluster(precluster, AHDC_precluster_list, window, minimal_distance, 0, 0, 1); find_associate_cluster(precluster, AHDC_precluster_list, window, minimal_distance, 1, 1, 2); - find_associate_cluster(precluster, AHDC_precluster_list, window, minimal_distance, 2, 1, 3); - find_associate_cluster(precluster, AHDC_precluster_list, window, minimal_distance, 3, 1, 4); + find_associate_cluster(precluster, AHDC_precluster_list, window, minimal_distance, 2, 2, 3); + find_associate_cluster(precluster, AHDC_precluster_list, window, minimal_distance, 3, 2, 4); + find_associate_cluster(precluster, AHDC_precluster_list, window, minimal_distance, 4, 2, 5); } for (Cluster cluster : _list_with_maybe_same_cluster) { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index a56f7b4661..c2a547c575 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -23,7 +23,7 @@ public class Hit implements Comparable { public Hit(int superLayer, int layer, int wire, int numWire, double r, double doca) { this.superLayer = superLayer; this.layer = layer; - this.wire = wire - 1; + this.wire = wire; this.r = r; this.doca = doca; this.numWires = numWire; @@ -51,35 +51,35 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do Plane3D rPlane = new Plane3D(p2, n2); switch (this.superLayer) { - case 0: + case 1: numWires = 47.0; R_layer = 32.0; break; - case 1: + case 2: numWires = 56.0; R_layer = 38.0; break; - case 2: + case 3: numWires = 72.0; R_layer = 48.0; break; - case 3: + case 4: numWires = 87.0; R_layer = 58.0; break; - case 4: + case 5: numWires = 99.0; R_layer = 68.0; break; } - R_layer = R_layer + DR_layer * this.layer; + R_layer = R_layer + DR_layer * (this.layer-1); double alphaW_layer = Math.toRadians(round / (numWires)); - double wx = -R_layer * Math.sin(alphaW_layer * this.wire); - double wy = -R_layer * Math.cos(alphaW_layer * this.wire); + double wx = -R_layer * Math.sin(alphaW_layer * (this.wire-1)); + double wy = -R_layer * Math.cos(alphaW_layer * (this.wire-1)); - double wx_end = -R_layer * Math.sin(alphaW_layer * this.wire + thster * (Math.pow(-1, this.superLayer))); - double wy_end = -R_layer * Math.cos(alphaW_layer * this.wire + thster * (Math.pow(-1, this.superLayer))); + double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1))); + double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1))); Line3D line = new Line3D(wx, wy, -150, wx_end, wy_end, zl/2); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java index 3603c890b8..f991da5d2b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java @@ -23,21 +23,21 @@ private void fill_list(List AHDC_hits, ArrayList sxlx, int super_layer public void findPreCluster(List AHDC_hits) { ArrayList s0l0 = new ArrayList(); - fill_list(AHDC_hits, s0l0, 0, 0); + fill_list(AHDC_hits, s0l0, 1, 1); ArrayList s1l0 = new ArrayList(); - fill_list(AHDC_hits, s1l0, 1, 0); + fill_list(AHDC_hits, s1l0, 2, 1); ArrayList s1l1 = new ArrayList(); - fill_list(AHDC_hits, s1l1, 1, 1); + fill_list(AHDC_hits, s1l1, 3, 2); ArrayList s2l0 = new ArrayList(); - fill_list(AHDC_hits, s2l0, 2, 0); + fill_list(AHDC_hits, s2l0, 4, 1); ArrayList s2l1 = new ArrayList(); - fill_list(AHDC_hits, s2l1, 2, 1); + fill_list(AHDC_hits, s2l1, 5, 2); ArrayList s3l0 = new ArrayList(); - fill_list(AHDC_hits, s3l0, 3, 0); + fill_list(AHDC_hits, s3l0, 6, 1); ArrayList s3l1 = new ArrayList(); - fill_list(AHDC_hits, s3l1, 3, 1); + fill_list(AHDC_hits, s3l1, 7, 2); ArrayList s4l0 = new ArrayList(); - fill_list(AHDC_hits, s4l0, 4, 0); + fill_list(AHDC_hits, s4l0, 8, 1); ArrayList> all_super_layer = new ArrayList<>(); all_super_layer.add(s0l0); From 2e86a6604f869c968d4d856cb8ecb89bd495107f Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Tue, 18 Jun 2024 08:38:24 -0400 Subject: [PATCH 14/51] fixed a merge error that slipped through the cracks. --- .../alert/src/main/java/org/jlab/rec/service/AHDCEngine.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index aced0fffea..9f42708e70 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -69,10 +69,6 @@ public boolean processDataEvent(DataEvent event) { magfield = 50 * magfieldfactor; -<<<<<<< HEAD -======= - //if (event.hasBank("AHDC::tdc")) { ->>>>>>> 04571a19be467d9b85ef3e9ffa8b94078aa7b944 if (event.hasBank("AHDC::adc")) { // I) Read raw hit HitReader hitRead = new HitReader(event, simulation); From 85dbe45d6b77ee799b13571f5bda62e5e0e86169 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 8 Jul 2024 23:35:47 -0400 Subject: [PATCH 15/51] Modified the reference layer index for the "OtherCluster" in the PreCluster pairing routine in AHDC ClusterFinder --- .../main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java | 4 +++- .../src/main/java/org/jlab/rec/service/AHDCEngine.java | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java index e8033525e5..7a1421815a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/ClusterFinder.java @@ -13,6 +13,7 @@ public class ClusterFinder { public ClusterFinder() {} private void find_associate_cluster(PreCluster precluster, List AHDC_precluster_list, int window, int minimal_distance, int super_layer, int layer, int associate_super_layer) { + //System.out.println(" precluster superlayer " + precluster.get_Super_layer() + " ref superlayer " + super_layer + " layer " + precluster.get_Layer() + " ref " + layer); if (precluster.get_Super_layer() == super_layer && precluster.get_Layer() == layer && !precluster.is_Used()) { ArrayList possible_precluster_list = new ArrayList<>(); @@ -20,7 +21,8 @@ private void find_associate_cluster(PreCluster precluster, List AHDC double x = -precluster.get_Radius() * Math.sin(phi_mean); double y = -precluster.get_Radius() * Math.cos(phi_mean); for (PreCluster other_precluster : AHDC_precluster_list) { - if (other_precluster.get_Super_layer() == associate_super_layer && other_precluster.get_Layer() == 0 && !other_precluster.is_Used()) { + //System.out.println(" othercluster superlayer " + other_precluster.get_Super_layer() + " ref " + associate_super_layer + " layer " + other_precluster.get_Layer() + " ref 1 now"); + if (other_precluster.get_Super_layer() == associate_super_layer && other_precluster.get_Layer() == 1 && !other_precluster.is_Used()) { double x_start = x - window; double x_end = x + window; double y_start = y - window; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index 9f42708e70..bca4ed604c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -75,17 +75,20 @@ public boolean processDataEvent(DataEvent event) { ArrayList AHDC_Hits = hitRead.get_AHDCHits(); ArrayList TrueAHDC_Hits = hitRead.get_TrueAHDCHits(); - + //System.out.println("AHDC_Hits size " + AHDC_Hits.size()); + // II) Create PreCluster PreClusterFinder preclusterfinder = new PreClusterFinder(); preclusterfinder.findPreCluster(AHDC_Hits); ArrayList AHDC_PreClusters = preclusterfinder.get_AHDCPreClusters(); + //System.out.println("AHDC_PreClusters size " + AHDC_PreClusters.size()); // III) Create Cluster ClusterFinder clusterfinder = new ClusterFinder(); clusterfinder.findCluster(AHDC_PreClusters); ArrayList AHDC_Clusters = clusterfinder.get_AHDCClusters(); - + //System.out.println("AHDC_Clusters size " + AHDC_Clusters.size()); + // IV) Track Finder ArrayList AHDC_Tracks = new ArrayList<>(); if (findingMethod.equals("distance")) { From e14c4641d1c8cf202a9c7707918b92c4a7548e1c Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Tue, 9 Jul 2024 00:46:31 -0400 Subject: [PATCH 16/51] Modified the hardcoded lookup superlayer/layer indices to fill the per-layer list of hits in AHDC PreCluster Modified the hardcoded lookup superlayer indices to obtain the geometry parameters to calculate x, y. --- .../src/main/java/org/jlab/rec/ahdc/Hit/Hit.java | 14 +++++++------- .../jlab/rec/ahdc/PreCluster/PreClusterFinder.java | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java index aeb429bbed..8a235279dc 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java @@ -31,31 +31,31 @@ private void wirePosition() { double numWires = 32.0; double R_layer = 47.0; - + switch (this.superLayerId) { - case 0: + case 1: numWires = 47.0; R_layer = 32.0; break; - case 1: + case 2: numWires = 56.0; R_layer = 38.0; break; - case 2: + case 3: numWires = 72.0; R_layer = 48.0; break; - case 3: + case 4: numWires = 87.0; R_layer = 58.0; break; - case 4: + case 5: numWires = 99.0; R_layer = 68.0; break; } - R_layer = R_layer + DR_layer * this.layerId; + R_layer = R_layer + DR_layer * (this.layerId-1); double alphaW_layer = Math.toRadians(round / (numWires)); double wx = -R_layer * Math.sin(alphaW_layer * this.wireId); double wy = -R_layer * Math.cos(alphaW_layer * this.wireId); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java index f991da5d2b..40bb33e7bc 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java @@ -27,17 +27,17 @@ public void findPreCluster(List AHDC_hits) { ArrayList s1l0 = new ArrayList(); fill_list(AHDC_hits, s1l0, 2, 1); ArrayList s1l1 = new ArrayList(); - fill_list(AHDC_hits, s1l1, 3, 2); + fill_list(AHDC_hits, s1l1, 2, 2); ArrayList s2l0 = new ArrayList(); - fill_list(AHDC_hits, s2l0, 4, 1); + fill_list(AHDC_hits, s2l0, 3, 1); ArrayList s2l1 = new ArrayList(); - fill_list(AHDC_hits, s2l1, 5, 2); + fill_list(AHDC_hits, s2l1, 3, 2); ArrayList s3l0 = new ArrayList(); - fill_list(AHDC_hits, s3l0, 6, 1); + fill_list(AHDC_hits, s3l0, 4, 1); ArrayList s3l1 = new ArrayList(); - fill_list(AHDC_hits, s3l1, 7, 2); + fill_list(AHDC_hits, s3l1, 4, 2); ArrayList s4l0 = new ArrayList(); - fill_list(AHDC_hits, s4l0, 8, 1); + fill_list(AHDC_hits, s4l0, 5, 1); ArrayList> all_super_layer = new ArrayList<>(); all_super_layer.add(s0l0); From 06b8f90cc117b86e6f816a0c4504c8cba42c4ecc Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Wed, 17 Jul 2024 14:23:49 -0400 Subject: [PATCH 17/51] Declared upfront the hardcoded variables for cluster z calculation in Cluster.java --- .../src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java index 14325fb99e..a882a160a0 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java @@ -10,6 +10,10 @@ */ public class Cluster { + private double _StereoAngle = 20.0; + private double _DeltaZ = 300.0; + private double _Zoffset = 178.0; + private double _Radius; private double _Phi; private double _Z; @@ -28,7 +32,7 @@ public Cluster(PreCluster precluster, PreCluster other_precluster) { _PreClusters_list.add(other_precluster); this._Radius = (precluster.get_Radius() + other_precluster.get_Radius()) / 2; - this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(20) * Math.pow(-1, precluster.get_Super_layer()-1) - Math.toRadians(20) * Math.pow(-1, other_precluster.get_Super_layer()-1))) * 300 - 150; + this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(_StereoAngle) * Math.pow(-1, precluster.get_Super_layer()-1) - Math.toRadians(_StereoAngle) * Math.pow(-1, other_precluster.get_Super_layer()-1))) * _DeltaZ - _Zoffset; double x1 = -precluster.get_Radius() * Math.sin(precluster.get_Phi()); double y1 = -precluster.get_Radius() * Math.cos(precluster.get_Phi()); From 230b1b12abbbe961d6374e72cde01fd14c39f24d Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 16 Sep 2024 14:44:22 -0400 Subject: [PATCH 18/51] Added printouts to debug kalman filter. --- .../org/jlab/rec/ahdc/Cluster/Cluster.java | 2 +- .../rec/ahdc/KalmanFilter/KalmanFilter.java | 48 ++++++++++++------- .../rec/ahdc/KalmanFilter/MaterialMap.java | 14 +++--- .../java/org/jlab/rec/service/AHDCEngine.java | 2 + 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java index a882a160a0..2497164999 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java @@ -12,7 +12,7 @@ public class Cluster { private double _StereoAngle = 20.0; private double _DeltaZ = 300.0; - private double _Zoffset = 178.0; + private double _Zoffset = 150.0; private double _Radius; private double _Phi; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index e3de4248dc..e24fddb84b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -37,11 +37,15 @@ private void propagation(ArrayList tracks, DataEvent event) { try { //If simulation read MC::Particle Bank ------------------------------------------------ DataBank bankParticle = event.getBank("MC::Particle"); + double vxmc = bankParticle.getFloat("vx", 0); + double vymc = bankParticle.getFloat("vy", 0); double vzmc = bankParticle.getFloat("vz", 0); double pxmc = bankParticle.getFloat("px", 0); double pymc = bankParticle.getFloat("py", 0); double pzmc = bankParticle.getFloat("pz", 0); - + double p_mc = java.lang.Math.sqrt(pxmc*pxmc+pymc*pymc+pzmc*pzmc); + //System.out.println("MC track: vz: " + vzmc*10 + " px: " + pxmc*1000 + " py: " + pymc*1000 + " pz: " + pzmc*1000 + "; p = " + p_mc*1000);//convert p to MeV, v to mm + ArrayList sim_hits = new ArrayList<>(); sim_hits.add(new Point3D(0, 0, vzmc)); @@ -56,6 +60,7 @@ private void propagation(ArrayList tracks, DataEvent event) { } } + /* Writer hitsWriter = new FileWriter("hits.dat"); for (Point3D p : sim_hits) { @@ -82,14 +87,17 @@ private void propagation(ArrayList tracks, DataEvent event) { final double px0 = tracks.get(0).get_px(); final double py0 = tracks.get(0).get_py(); final double pz0 = tracks.get(0).get_pz(); + final double p_init = java.lang.Math.sqrt(px0*px0+py0*py0+pz0*pz0); double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; - // System.out.println("y = " + Arrays.toString(y)); + //double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; + //System.out.println("y = " + x0 + ", " + y0 + ", " + z0 + ", " + px0 + ", " + py0 + ", " + pz0 + "; p = " + p_init); // Initialization hit // System.out.println("tracks = " + tracks); ArrayList AHDC_hits = tracks.get(0).getHits(); ArrayList KF_hits = new ArrayList<>(); for (org.jlab.rec.ahdc.Hit.Hit AHDC_hit : AHDC_hits) { + //System.out.println("Superlayer = " + AHDC_hit.getSuperLayerId() + ", Layer " + AHDC_hit.getLayerId() + ", Wire " + AHDC_hit.getWireId() + ", Nwires " + AHDC_hit.getNbOfWires() + ", Radius " + AHDC_hit.getRadius() + ", DOCA " + AHDC_hit.getDoca()); Hit hit = new Hit(AHDC_hit.getSuperLayerId(), AHDC_hit.getLayerId(), AHDC_hit.getWireId(), AHDC_hit.getNbOfWires(), AHDC_hit.getRadius(), AHDC_hit.getDoca()); // Do delete hit with same radius @@ -125,7 +133,7 @@ private void propagation(ArrayList tracks, DataEvent event) { // Initialization of the Kalman Fitter RealVector initialStateEstimate = new ArrayRealVector(stepper.y); - RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{10.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 10.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 10.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); + RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{100.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 100.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 100.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); KFitter kFitter = new KFitter(initialStateEstimate, initialErrorCovariance, stepper, propagator); @@ -153,24 +161,28 @@ private void propagation(ArrayList tracks, DataEvent event) { for (int k = 0; k < 1; k++) { - // System.out.println("--------- ForWard propagation !! ---------"); + //System.out.println("--------- ForWard propagation !! ---------"); for (Indicator indicator : forwardIndicators) { kFitter.predict(indicator); + //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { + //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); kFitter.correct(indicator); + //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } - // System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } - // System.out.println("--------- BackWard propagation !! ---------"); + //System.out.println("--------- BackWard propagation !! ---------"); for (Indicator indicator : backwardIndicators) { kFitter.predict(indicator); + //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { + //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); kFitter.correct(indicator); + //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } - // System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } } @@ -187,7 +199,7 @@ private void propagation(ArrayList tracks, DataEvent event) { RealVector x_out = kFitter.getStateEstimationVector(); tracks.get(0).setPositionAndMomentumForKF(x_out); - + //System.out.println("y_final = " + x_out + " p_final = " + kFitter.getMomentum()); } catch (Exception e) { // e.printStackTrace(); } @@ -200,18 +212,18 @@ private HashMap materialGeneration() { String name_De = "deuteriumGas"; double thickness_De = 1; - double density_De = 0.0009; // 9.37E-4; + double density_De = 9.37E-4;// 5.5 atm double ZoverA_De = 0.496499; - double X0_De = 0; + double X0_De = 1.3445E+5; // I guess X0 is not even used??? double IeV_De = 19.2; org.jlab.clas.tracking.kalmanfilter.Material deuteriumGas = new org.jlab.clas.tracking.kalmanfilter.Material(name_De, thickness_De, density_De, ZoverA_De, X0_De, IeV_De, units); - String name_Bo = "BONuS12Gas"; + String name_Bo = "BONuS12Gas";//80% He, 20% CO2 double thickness_Bo = 1; double density_Bo = 4.9778E-4; double ZoverA_Bo = 0.49989; - double X0_Bo = 0; + double X0_Bo = 4.5761E+4; double IeV_Bo = 73.8871; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); @@ -219,8 +231,8 @@ private HashMap materialGeneration() { String name_My = "Mylar"; double thickness_My = 1; double density_My = 1.4; - double ZoverA_My = 0.501363; - double X0_My = 0; + double ZoverA_My = 0.52037; + double X0_My = 28.54; double IeV_My = 78.7; org.jlab.clas.tracking.kalmanfilter.Material Mylar = new org.jlab.clas.tracking.kalmanfilter.Material(name_My, thickness_My, density_My, ZoverA_My, X0_My, IeV_My, units); @@ -228,8 +240,8 @@ private HashMap materialGeneration() { String name_Ka = "Kapton"; double thickness_Ka = 1; double density_Ka = 1.42; - double ZoverA_Ka = 0.500722; - double X0_Ka = 0; + double ZoverA_Ka = 0.51264; + double X0_Ka = 28.57; double IeV_Ka = 79.6; org.jlab.clas.tracking.kalmanfilter.Material Kapton = new org.jlab.clas.tracking.kalmanfilter.Material(name_Ka, thickness_Ka, density_Ka, ZoverA_Ka, X0_Ka, IeV_Ka, units); @@ -247,7 +259,7 @@ private HashMap materialGeneration() { ArrayList forwardIndicators(ArrayList hitArrayList, HashMap materialHashMap) { ArrayList forwardIndicators = new ArrayList<>(); forwardIndicators.add(new Indicator(3.0, 0.2, null, true, materialHashMap.get("deuteriumGas"))); - forwardIndicators.add(new Indicator(3.063, 0.001, null, true, materialHashMap.get("Kapton"))); + forwardIndicators.add(new Indicator(3.060, 0.001, null, true, materialHashMap.get("Kapton"))); for (Hit hit : hitArrayList) { forwardIndicators.add(new Indicator(hit.r(), 0.1, hit, true, materialHashMap.get("BONuS12Gas"))); } @@ -259,7 +271,7 @@ ArrayList backwardIndicators(ArrayList hitArrayList, HashMap= 0; i--) { backwardIndicators.add(new Indicator(hitArrayList.get(i).r(), 0.1, hitArrayList.get(i), false, materialHashMap.get("BONuS12Gas"))); } - backwardIndicators.add(new Indicator(3.063, 1, null, false, materialHashMap.get("BONuS12Gas"))); + backwardIndicators.add(new Indicator(3.060, 1, null, false, materialHashMap.get("BONuS12Gas"))); backwardIndicators.add(new Indicator(3.0, 0.001, null, false, materialHashMap.get("Kapton"))); Hit hit = new Hit_beam(0, 0, 0, 0, 0, 0, 0, 0); backwardIndicators.add(new Indicator(0.0, 0.2, hit, false, materialHashMap.get("deuteriumGas"))); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java index ac3e5eee36..53a20e6a67 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java @@ -14,16 +14,16 @@ public static HashMap generateMaterials() { double thickness_De = 1; double density_De = 9.37E-4; double ZoverA_De = 0.496499; - double X0_De = 0; + double X0_De = 1.3445E+5; double IeV_De = 19.2; org.jlab.clas.tracking.kalmanfilter.Material deuteriumGas = new org.jlab.clas.tracking.kalmanfilter.Material(name_De, thickness_De, density_De, ZoverA_De, X0_De, IeV_De, units); - String name_Bo = "BONuS12Gas"; + String name_Bo = "BONuS12Gas";//80% He, 20% CO2 double thickness_Bo = 1; double density_Bo = 4.9778E-4; double ZoverA_Bo = 0.49989; - double X0_Bo = 0; + double X0_Bo = 4.5761E+4; double IeV_Bo = 73.8871; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); @@ -31,8 +31,8 @@ public static HashMap generateMaterials() { String name_My = "Mylar"; double thickness_My = 1; double density_My = 1.4; - double ZoverA_My = 0.501363; - double X0_My = 0; + double ZoverA_My = 0.52037; + double X0_My = 28.54; double IeV_My = 78.7; org.jlab.clas.tracking.kalmanfilter.Material Mylar = new org.jlab.clas.tracking.kalmanfilter.Material(name_My, thickness_My, density_My, ZoverA_My, X0_My, IeV_My, units); @@ -40,8 +40,8 @@ public static HashMap generateMaterials() { String name_Ka = "Kapton"; double thickness_Ka = 1; double density_Ka = 1.42; - double ZoverA_Ka = 0.500722; - double X0_Ka = 0; + double ZoverA_Ka = 0.51264; + double X0_Ka = 28.57; double IeV_Ka = 79.6; org.jlab.clas.tracking.kalmanfilter.Material Kapton = new org.jlab.clas.tracking.kalmanfilter.Material(name_Ka, thickness_Ka, density_Ka, ZoverA_Ka, X0_Ka, IeV_Ka, units); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index bca4ed604c..a15ff89e0a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -93,11 +93,13 @@ public boolean processDataEvent(DataEvent event) { ArrayList AHDC_Tracks = new ArrayList<>(); if (findingMethod.equals("distance")) { // IV) a) Distance method + //System.out.println("using distance"); Distance distance = new Distance(); distance.find_track(AHDC_Clusters); AHDC_Tracks = distance.get_AHDCTracks(); } else if (findingMethod.equals("hough")) { // IV) b) Hough Transform method + //System.out.println("using hough"); HoughTransform houghtransform = new HoughTransform(); houghtransform.find_tracks(AHDC_Clusters); AHDC_Tracks = houghtransform.get_AHDCTracks(); From abbb742512373cb2a4264b6282cc243a6a3bd0b3 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Tue, 17 Sep 2024 09:28:21 -0400 Subject: [PATCH 19/51] Revert "Merge branch 'development' of github.com:efuchey/coatjava into development" This reverts commit 62544e761c946da12186b3e6416eccebd4f6c915, reversing changes made to 66afda9a051074af17212c28d1556886a3226d86. --- .../org/jlab/rec/ahdc/Cluster/Cluster.java | 6 +-- .../rec/ahdc/KalmanFilter/KalmanFilter.java | 48 +++++++------------ .../rec/ahdc/KalmanFilter/MaterialMap.java | 14 +++--- .../java/org/jlab/rec/service/AHDCEngine.java | 2 - 4 files changed, 26 insertions(+), 44 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java index 2497164999..14325fb99e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java @@ -10,10 +10,6 @@ */ public class Cluster { - private double _StereoAngle = 20.0; - private double _DeltaZ = 300.0; - private double _Zoffset = 150.0; - private double _Radius; private double _Phi; private double _Z; @@ -32,7 +28,7 @@ public Cluster(PreCluster precluster, PreCluster other_precluster) { _PreClusters_list.add(other_precluster); this._Radius = (precluster.get_Radius() + other_precluster.get_Radius()) / 2; - this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(_StereoAngle) * Math.pow(-1, precluster.get_Super_layer()-1) - Math.toRadians(_StereoAngle) * Math.pow(-1, other_precluster.get_Super_layer()-1))) * _DeltaZ - _Zoffset; + this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(20) * Math.pow(-1, precluster.get_Super_layer()-1) - Math.toRadians(20) * Math.pow(-1, other_precluster.get_Super_layer()-1))) * 300 - 150; double x1 = -precluster.get_Radius() * Math.sin(precluster.get_Phi()); double y1 = -precluster.get_Radius() * Math.cos(precluster.get_Phi()); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index e24fddb84b..e3de4248dc 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -37,15 +37,11 @@ private void propagation(ArrayList tracks, DataEvent event) { try { //If simulation read MC::Particle Bank ------------------------------------------------ DataBank bankParticle = event.getBank("MC::Particle"); - double vxmc = bankParticle.getFloat("vx", 0); - double vymc = bankParticle.getFloat("vy", 0); double vzmc = bankParticle.getFloat("vz", 0); double pxmc = bankParticle.getFloat("px", 0); double pymc = bankParticle.getFloat("py", 0); double pzmc = bankParticle.getFloat("pz", 0); - double p_mc = java.lang.Math.sqrt(pxmc*pxmc+pymc*pymc+pzmc*pzmc); - //System.out.println("MC track: vz: " + vzmc*10 + " px: " + pxmc*1000 + " py: " + pymc*1000 + " pz: " + pzmc*1000 + "; p = " + p_mc*1000);//convert p to MeV, v to mm - + ArrayList sim_hits = new ArrayList<>(); sim_hits.add(new Point3D(0, 0, vzmc)); @@ -60,7 +56,6 @@ private void propagation(ArrayList tracks, DataEvent event) { } } - /* Writer hitsWriter = new FileWriter("hits.dat"); for (Point3D p : sim_hits) { @@ -87,17 +82,14 @@ private void propagation(ArrayList tracks, DataEvent event) { final double px0 = tracks.get(0).get_px(); final double py0 = tracks.get(0).get_py(); final double pz0 = tracks.get(0).get_pz(); - final double p_init = java.lang.Math.sqrt(px0*px0+py0*py0+pz0*pz0); double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; - //double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; - //System.out.println("y = " + x0 + ", " + y0 + ", " + z0 + ", " + px0 + ", " + py0 + ", " + pz0 + "; p = " + p_init); + // System.out.println("y = " + Arrays.toString(y)); // Initialization hit // System.out.println("tracks = " + tracks); ArrayList AHDC_hits = tracks.get(0).getHits(); ArrayList KF_hits = new ArrayList<>(); for (org.jlab.rec.ahdc.Hit.Hit AHDC_hit : AHDC_hits) { - //System.out.println("Superlayer = " + AHDC_hit.getSuperLayerId() + ", Layer " + AHDC_hit.getLayerId() + ", Wire " + AHDC_hit.getWireId() + ", Nwires " + AHDC_hit.getNbOfWires() + ", Radius " + AHDC_hit.getRadius() + ", DOCA " + AHDC_hit.getDoca()); Hit hit = new Hit(AHDC_hit.getSuperLayerId(), AHDC_hit.getLayerId(), AHDC_hit.getWireId(), AHDC_hit.getNbOfWires(), AHDC_hit.getRadius(), AHDC_hit.getDoca()); // Do delete hit with same radius @@ -133,7 +125,7 @@ private void propagation(ArrayList tracks, DataEvent event) { // Initialization of the Kalman Fitter RealVector initialStateEstimate = new ArrayRealVector(stepper.y); - RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{100.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 100.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 100.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); + RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{10.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 10.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 10.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); KFitter kFitter = new KFitter(initialStateEstimate, initialErrorCovariance, stepper, propagator); @@ -161,28 +153,24 @@ private void propagation(ArrayList tracks, DataEvent event) { for (int k = 0; k < 1; k++) { - //System.out.println("--------- ForWard propagation !! ---------"); + // System.out.println("--------- ForWard propagation !! ---------"); for (Indicator indicator : forwardIndicators) { kFitter.predict(indicator); - //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { - //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); kFitter.correct(indicator); - //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } + // System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } - //System.out.println("--------- BackWard propagation !! ---------"); + // System.out.println("--------- BackWard propagation !! ---------"); for (Indicator indicator : backwardIndicators) { kFitter.predict(indicator); - //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { - //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); kFitter.correct(indicator); - //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } + // System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } } @@ -199,7 +187,7 @@ private void propagation(ArrayList tracks, DataEvent event) { RealVector x_out = kFitter.getStateEstimationVector(); tracks.get(0).setPositionAndMomentumForKF(x_out); - //System.out.println("y_final = " + x_out + " p_final = " + kFitter.getMomentum()); + } catch (Exception e) { // e.printStackTrace(); } @@ -212,18 +200,18 @@ private HashMap materialGeneration() { String name_De = "deuteriumGas"; double thickness_De = 1; - double density_De = 9.37E-4;// 5.5 atm + double density_De = 0.0009; // 9.37E-4; double ZoverA_De = 0.496499; - double X0_De = 1.3445E+5; // I guess X0 is not even used??? + double X0_De = 0; double IeV_De = 19.2; org.jlab.clas.tracking.kalmanfilter.Material deuteriumGas = new org.jlab.clas.tracking.kalmanfilter.Material(name_De, thickness_De, density_De, ZoverA_De, X0_De, IeV_De, units); - String name_Bo = "BONuS12Gas";//80% He, 20% CO2 + String name_Bo = "BONuS12Gas"; double thickness_Bo = 1; double density_Bo = 4.9778E-4; double ZoverA_Bo = 0.49989; - double X0_Bo = 4.5761E+4; + double X0_Bo = 0; double IeV_Bo = 73.8871; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); @@ -231,8 +219,8 @@ private HashMap materialGeneration() { String name_My = "Mylar"; double thickness_My = 1; double density_My = 1.4; - double ZoverA_My = 0.52037; - double X0_My = 28.54; + double ZoverA_My = 0.501363; + double X0_My = 0; double IeV_My = 78.7; org.jlab.clas.tracking.kalmanfilter.Material Mylar = new org.jlab.clas.tracking.kalmanfilter.Material(name_My, thickness_My, density_My, ZoverA_My, X0_My, IeV_My, units); @@ -240,8 +228,8 @@ private HashMap materialGeneration() { String name_Ka = "Kapton"; double thickness_Ka = 1; double density_Ka = 1.42; - double ZoverA_Ka = 0.51264; - double X0_Ka = 28.57; + double ZoverA_Ka = 0.500722; + double X0_Ka = 0; double IeV_Ka = 79.6; org.jlab.clas.tracking.kalmanfilter.Material Kapton = new org.jlab.clas.tracking.kalmanfilter.Material(name_Ka, thickness_Ka, density_Ka, ZoverA_Ka, X0_Ka, IeV_Ka, units); @@ -259,7 +247,7 @@ private HashMap materialGeneration() { ArrayList forwardIndicators(ArrayList hitArrayList, HashMap materialHashMap) { ArrayList forwardIndicators = new ArrayList<>(); forwardIndicators.add(new Indicator(3.0, 0.2, null, true, materialHashMap.get("deuteriumGas"))); - forwardIndicators.add(new Indicator(3.060, 0.001, null, true, materialHashMap.get("Kapton"))); + forwardIndicators.add(new Indicator(3.063, 0.001, null, true, materialHashMap.get("Kapton"))); for (Hit hit : hitArrayList) { forwardIndicators.add(new Indicator(hit.r(), 0.1, hit, true, materialHashMap.get("BONuS12Gas"))); } @@ -271,7 +259,7 @@ ArrayList backwardIndicators(ArrayList hitArrayList, HashMap= 0; i--) { backwardIndicators.add(new Indicator(hitArrayList.get(i).r(), 0.1, hitArrayList.get(i), false, materialHashMap.get("BONuS12Gas"))); } - backwardIndicators.add(new Indicator(3.060, 1, null, false, materialHashMap.get("BONuS12Gas"))); + backwardIndicators.add(new Indicator(3.063, 1, null, false, materialHashMap.get("BONuS12Gas"))); backwardIndicators.add(new Indicator(3.0, 0.001, null, false, materialHashMap.get("Kapton"))); Hit hit = new Hit_beam(0, 0, 0, 0, 0, 0, 0, 0); backwardIndicators.add(new Indicator(0.0, 0.2, hit, false, materialHashMap.get("deuteriumGas"))); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java index 53a20e6a67..ac3e5eee36 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java @@ -14,16 +14,16 @@ public static HashMap generateMaterials() { double thickness_De = 1; double density_De = 9.37E-4; double ZoverA_De = 0.496499; - double X0_De = 1.3445E+5; + double X0_De = 0; double IeV_De = 19.2; org.jlab.clas.tracking.kalmanfilter.Material deuteriumGas = new org.jlab.clas.tracking.kalmanfilter.Material(name_De, thickness_De, density_De, ZoverA_De, X0_De, IeV_De, units); - String name_Bo = "BONuS12Gas";//80% He, 20% CO2 + String name_Bo = "BONuS12Gas"; double thickness_Bo = 1; double density_Bo = 4.9778E-4; double ZoverA_Bo = 0.49989; - double X0_Bo = 4.5761E+4; + double X0_Bo = 0; double IeV_Bo = 73.8871; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); @@ -31,8 +31,8 @@ public static HashMap generateMaterials() { String name_My = "Mylar"; double thickness_My = 1; double density_My = 1.4; - double ZoverA_My = 0.52037; - double X0_My = 28.54; + double ZoverA_My = 0.501363; + double X0_My = 0; double IeV_My = 78.7; org.jlab.clas.tracking.kalmanfilter.Material Mylar = new org.jlab.clas.tracking.kalmanfilter.Material(name_My, thickness_My, density_My, ZoverA_My, X0_My, IeV_My, units); @@ -40,8 +40,8 @@ public static HashMap generateMaterials() { String name_Ka = "Kapton"; double thickness_Ka = 1; double density_Ka = 1.42; - double ZoverA_Ka = 0.51264; - double X0_Ka = 28.57; + double ZoverA_Ka = 0.500722; + double X0_Ka = 0; double IeV_Ka = 79.6; org.jlab.clas.tracking.kalmanfilter.Material Kapton = new org.jlab.clas.tracking.kalmanfilter.Material(name_Ka, thickness_Ka, density_Ka, ZoverA_Ka, X0_Ka, IeV_Ka, units); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index a15ff89e0a..bca4ed604c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -93,13 +93,11 @@ public boolean processDataEvent(DataEvent event) { ArrayList AHDC_Tracks = new ArrayList<>(); if (findingMethod.equals("distance")) { // IV) a) Distance method - //System.out.println("using distance"); Distance distance = new Distance(); distance.find_track(AHDC_Clusters); AHDC_Tracks = distance.get_AHDCTracks(); } else if (findingMethod.equals("hough")) { // IV) b) Hough Transform method - //System.out.println("using hough"); HoughTransform houghtransform = new HoughTransform(); houghtransform.find_tracks(AHDC_Clusters); AHDC_Tracks = houghtransform.get_AHDCTracks(); From c9f73b085f55872f5a0cbee0ba1a78d01bfad080 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Tue, 17 Sep 2024 09:31:36 -0400 Subject: [PATCH 20/51] Reapply "Merge branch 'development' of github.com:efuchey/coatjava into development" This reverts commit abbb742512373cb2a4264b6282cc243a6a3bd0b3. --- .../org/jlab/rec/ahdc/Cluster/Cluster.java | 6 ++- .../rec/ahdc/KalmanFilter/KalmanFilter.java | 48 ++++++++++++------- .../rec/ahdc/KalmanFilter/MaterialMap.java | 14 +++--- .../java/org/jlab/rec/service/AHDCEngine.java | 2 + 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java index 14325fb99e..2497164999 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Cluster/Cluster.java @@ -10,6 +10,10 @@ */ public class Cluster { + private double _StereoAngle = 20.0; + private double _DeltaZ = 300.0; + private double _Zoffset = 150.0; + private double _Radius; private double _Phi; private double _Z; @@ -28,7 +32,7 @@ public Cluster(PreCluster precluster, PreCluster other_precluster) { _PreClusters_list.add(other_precluster); this._Radius = (precluster.get_Radius() + other_precluster.get_Radius()) / 2; - this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(20) * Math.pow(-1, precluster.get_Super_layer()-1) - Math.toRadians(20) * Math.pow(-1, other_precluster.get_Super_layer()-1))) * 300 - 150; + this._Z = ((other_precluster.get_Phi() - precluster.get_Phi()) / (Math.toRadians(_StereoAngle) * Math.pow(-1, precluster.get_Super_layer()-1) - Math.toRadians(_StereoAngle) * Math.pow(-1, other_precluster.get_Super_layer()-1))) * _DeltaZ - _Zoffset; double x1 = -precluster.get_Radius() * Math.sin(precluster.get_Phi()); double y1 = -precluster.get_Radius() * Math.cos(precluster.get_Phi()); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index e3de4248dc..e24fddb84b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -37,11 +37,15 @@ private void propagation(ArrayList tracks, DataEvent event) { try { //If simulation read MC::Particle Bank ------------------------------------------------ DataBank bankParticle = event.getBank("MC::Particle"); + double vxmc = bankParticle.getFloat("vx", 0); + double vymc = bankParticle.getFloat("vy", 0); double vzmc = bankParticle.getFloat("vz", 0); double pxmc = bankParticle.getFloat("px", 0); double pymc = bankParticle.getFloat("py", 0); double pzmc = bankParticle.getFloat("pz", 0); - + double p_mc = java.lang.Math.sqrt(pxmc*pxmc+pymc*pymc+pzmc*pzmc); + //System.out.println("MC track: vz: " + vzmc*10 + " px: " + pxmc*1000 + " py: " + pymc*1000 + " pz: " + pzmc*1000 + "; p = " + p_mc*1000);//convert p to MeV, v to mm + ArrayList sim_hits = new ArrayList<>(); sim_hits.add(new Point3D(0, 0, vzmc)); @@ -56,6 +60,7 @@ private void propagation(ArrayList tracks, DataEvent event) { } } + /* Writer hitsWriter = new FileWriter("hits.dat"); for (Point3D p : sim_hits) { @@ -82,14 +87,17 @@ private void propagation(ArrayList tracks, DataEvent event) { final double px0 = tracks.get(0).get_px(); final double py0 = tracks.get(0).get_py(); final double pz0 = tracks.get(0).get_pz(); + final double p_init = java.lang.Math.sqrt(px0*px0+py0*py0+pz0*pz0); double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; - // System.out.println("y = " + Arrays.toString(y)); + //double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; + //System.out.println("y = " + x0 + ", " + y0 + ", " + z0 + ", " + px0 + ", " + py0 + ", " + pz0 + "; p = " + p_init); // Initialization hit // System.out.println("tracks = " + tracks); ArrayList AHDC_hits = tracks.get(0).getHits(); ArrayList KF_hits = new ArrayList<>(); for (org.jlab.rec.ahdc.Hit.Hit AHDC_hit : AHDC_hits) { + //System.out.println("Superlayer = " + AHDC_hit.getSuperLayerId() + ", Layer " + AHDC_hit.getLayerId() + ", Wire " + AHDC_hit.getWireId() + ", Nwires " + AHDC_hit.getNbOfWires() + ", Radius " + AHDC_hit.getRadius() + ", DOCA " + AHDC_hit.getDoca()); Hit hit = new Hit(AHDC_hit.getSuperLayerId(), AHDC_hit.getLayerId(), AHDC_hit.getWireId(), AHDC_hit.getNbOfWires(), AHDC_hit.getRadius(), AHDC_hit.getDoca()); // Do delete hit with same radius @@ -125,7 +133,7 @@ private void propagation(ArrayList tracks, DataEvent event) { // Initialization of the Kalman Fitter RealVector initialStateEstimate = new ArrayRealVector(stepper.y); - RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{10.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 10.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 10.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); + RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{100.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 100.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 100.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); KFitter kFitter = new KFitter(initialStateEstimate, initialErrorCovariance, stepper, propagator); @@ -153,24 +161,28 @@ private void propagation(ArrayList tracks, DataEvent event) { for (int k = 0; k < 1; k++) { - // System.out.println("--------- ForWard propagation !! ---------"); + //System.out.println("--------- ForWard propagation !! ---------"); for (Indicator indicator : forwardIndicators) { kFitter.predict(indicator); + //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { + //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); kFitter.correct(indicator); + //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } - // System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } - // System.out.println("--------- BackWard propagation !! ---------"); + //System.out.println("--------- BackWard propagation !! ---------"); for (Indicator indicator : backwardIndicators) { kFitter.predict(indicator); + //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { + //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); kFitter.correct(indicator); + //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } - // System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } } @@ -187,7 +199,7 @@ private void propagation(ArrayList tracks, DataEvent event) { RealVector x_out = kFitter.getStateEstimationVector(); tracks.get(0).setPositionAndMomentumForKF(x_out); - + //System.out.println("y_final = " + x_out + " p_final = " + kFitter.getMomentum()); } catch (Exception e) { // e.printStackTrace(); } @@ -200,18 +212,18 @@ private HashMap materialGeneration() { String name_De = "deuteriumGas"; double thickness_De = 1; - double density_De = 0.0009; // 9.37E-4; + double density_De = 9.37E-4;// 5.5 atm double ZoverA_De = 0.496499; - double X0_De = 0; + double X0_De = 1.3445E+5; // I guess X0 is not even used??? double IeV_De = 19.2; org.jlab.clas.tracking.kalmanfilter.Material deuteriumGas = new org.jlab.clas.tracking.kalmanfilter.Material(name_De, thickness_De, density_De, ZoverA_De, X0_De, IeV_De, units); - String name_Bo = "BONuS12Gas"; + String name_Bo = "BONuS12Gas";//80% He, 20% CO2 double thickness_Bo = 1; double density_Bo = 4.9778E-4; double ZoverA_Bo = 0.49989; - double X0_Bo = 0; + double X0_Bo = 4.5761E+4; double IeV_Bo = 73.8871; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); @@ -219,8 +231,8 @@ private HashMap materialGeneration() { String name_My = "Mylar"; double thickness_My = 1; double density_My = 1.4; - double ZoverA_My = 0.501363; - double X0_My = 0; + double ZoverA_My = 0.52037; + double X0_My = 28.54; double IeV_My = 78.7; org.jlab.clas.tracking.kalmanfilter.Material Mylar = new org.jlab.clas.tracking.kalmanfilter.Material(name_My, thickness_My, density_My, ZoverA_My, X0_My, IeV_My, units); @@ -228,8 +240,8 @@ private HashMap materialGeneration() { String name_Ka = "Kapton"; double thickness_Ka = 1; double density_Ka = 1.42; - double ZoverA_Ka = 0.500722; - double X0_Ka = 0; + double ZoverA_Ka = 0.51264; + double X0_Ka = 28.57; double IeV_Ka = 79.6; org.jlab.clas.tracking.kalmanfilter.Material Kapton = new org.jlab.clas.tracking.kalmanfilter.Material(name_Ka, thickness_Ka, density_Ka, ZoverA_Ka, X0_Ka, IeV_Ka, units); @@ -247,7 +259,7 @@ private HashMap materialGeneration() { ArrayList forwardIndicators(ArrayList hitArrayList, HashMap materialHashMap) { ArrayList forwardIndicators = new ArrayList<>(); forwardIndicators.add(new Indicator(3.0, 0.2, null, true, materialHashMap.get("deuteriumGas"))); - forwardIndicators.add(new Indicator(3.063, 0.001, null, true, materialHashMap.get("Kapton"))); + forwardIndicators.add(new Indicator(3.060, 0.001, null, true, materialHashMap.get("Kapton"))); for (Hit hit : hitArrayList) { forwardIndicators.add(new Indicator(hit.r(), 0.1, hit, true, materialHashMap.get("BONuS12Gas"))); } @@ -259,7 +271,7 @@ ArrayList backwardIndicators(ArrayList hitArrayList, HashMap= 0; i--) { backwardIndicators.add(new Indicator(hitArrayList.get(i).r(), 0.1, hitArrayList.get(i), false, materialHashMap.get("BONuS12Gas"))); } - backwardIndicators.add(new Indicator(3.063, 1, null, false, materialHashMap.get("BONuS12Gas"))); + backwardIndicators.add(new Indicator(3.060, 1, null, false, materialHashMap.get("BONuS12Gas"))); backwardIndicators.add(new Indicator(3.0, 0.001, null, false, materialHashMap.get("Kapton"))); Hit hit = new Hit_beam(0, 0, 0, 0, 0, 0, 0, 0); backwardIndicators.add(new Indicator(0.0, 0.2, hit, false, materialHashMap.get("deuteriumGas"))); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java index ac3e5eee36..53a20e6a67 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java @@ -14,16 +14,16 @@ public static HashMap generateMaterials() { double thickness_De = 1; double density_De = 9.37E-4; double ZoverA_De = 0.496499; - double X0_De = 0; + double X0_De = 1.3445E+5; double IeV_De = 19.2; org.jlab.clas.tracking.kalmanfilter.Material deuteriumGas = new org.jlab.clas.tracking.kalmanfilter.Material(name_De, thickness_De, density_De, ZoverA_De, X0_De, IeV_De, units); - String name_Bo = "BONuS12Gas"; + String name_Bo = "BONuS12Gas";//80% He, 20% CO2 double thickness_Bo = 1; double density_Bo = 4.9778E-4; double ZoverA_Bo = 0.49989; - double X0_Bo = 0; + double X0_Bo = 4.5761E+4; double IeV_Bo = 73.8871; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); @@ -31,8 +31,8 @@ public static HashMap generateMaterials() { String name_My = "Mylar"; double thickness_My = 1; double density_My = 1.4; - double ZoverA_My = 0.501363; - double X0_My = 0; + double ZoverA_My = 0.52037; + double X0_My = 28.54; double IeV_My = 78.7; org.jlab.clas.tracking.kalmanfilter.Material Mylar = new org.jlab.clas.tracking.kalmanfilter.Material(name_My, thickness_My, density_My, ZoverA_My, X0_My, IeV_My, units); @@ -40,8 +40,8 @@ public static HashMap generateMaterials() { String name_Ka = "Kapton"; double thickness_Ka = 1; double density_Ka = 1.42; - double ZoverA_Ka = 0.500722; - double X0_Ka = 0; + double ZoverA_Ka = 0.51264; + double X0_Ka = 28.57; double IeV_Ka = 79.6; org.jlab.clas.tracking.kalmanfilter.Material Kapton = new org.jlab.clas.tracking.kalmanfilter.Material(name_Ka, thickness_Ka, density_Ka, ZoverA_Ka, X0_Ka, IeV_Ka, units); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index bca4ed604c..a15ff89e0a 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -93,11 +93,13 @@ public boolean processDataEvent(DataEvent event) { ArrayList AHDC_Tracks = new ArrayList<>(); if (findingMethod.equals("distance")) { // IV) a) Distance method + //System.out.println("using distance"); Distance distance = new Distance(); distance.find_track(AHDC_Clusters); AHDC_Tracks = distance.get_AHDCTracks(); } else if (findingMethod.equals("hough")) { // IV) b) Hough Transform method + //System.out.println("using hough"); HoughTransform houghtransform = new HoughTransform(); houghtransform.find_tracks(AHDC_Clusters); AHDC_Tracks = houghtransform.get_AHDCTracks(); From 8a5ba10e8106472239749335c847eefe3a2c8789 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Tue, 17 Sep 2024 17:15:31 -0400 Subject: [PATCH 21/51] Adjusted the AHDC gas parameters in alert KalmanFilter.java --- .../java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index e24fddb84b..9712872d02 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -221,10 +221,10 @@ private HashMap materialGeneration() { String name_Bo = "BONuS12Gas";//80% He, 20% CO2 double thickness_Bo = 1; - double density_Bo = 4.9778E-4; - double ZoverA_Bo = 0.49989; - double X0_Bo = 4.5761E+4; - double IeV_Bo = 73.8871; + double density_Bo = 1.39735E-3; + double ZoverA_Bo = 0.49983; + double X0_Bo = 3.69401E+4; + double IeV_Bo = 73.5338; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); From 09cad74bf8f9d0a7b48660daa5730fcd307f59c4 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Sun, 6 Oct 2024 23:17:08 -0400 Subject: [PATCH 22/51] Completed commit 3420bb9 by modifying output index of atof paddle starting at 1 instead of 0 --- .../java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java index 7354fd4673..6fb2f19e2e 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java @@ -120,7 +120,7 @@ public AlertTOFLayer createLayer(ConstantProvider cp, int sectorId, int superlay Point3D p5 = new Point3D(dR / 2, -widthTl / 2, len_b); Point3D p6 = new Point3D(dR / 2, widthTl / 2, len_b); Point3D p7 = new Point3D(-dR / 2, widthBl / 2, len_b); - ScintillatorPaddle Paddle = new ScintillatorPaddle(sectorId * 4 + padId, p0, p1, p2, p3, p4, p5, p6, p7); + ScintillatorPaddle Paddle = new ScintillatorPaddle(sectorId * 4 + padId+1, p0, p1, p2, p3, p4, p5, p6, p7); double openAng_sector_deg = npaddles * openAng_pad_deg; Paddle.rotateZ(Math.toRadians(padId * openAng_pad_deg + sectorId * openAng_sector_deg)); From a8e69c456c7afe338dbfe73791956d412b61d034 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Tue, 8 Oct 2024 15:07:57 -0400 Subject: [PATCH 23/51] Added comments about units quantities. --- .../java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java | 1 + .../org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java | 3 +++ .../org/jlab/rec/ahdc/KalmanFilter/Propagator.java | 2 ++ .../org/jlab/rec/ahdc/KalmanFilter/RungeKutta4.java | 12 +++++++----- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java index b94d9478ba..cb45c9ac7d 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java @@ -14,6 +14,7 @@ public class KFitter { public final Stepper stepper; private final Propagator propagator; public double chi2 = 0; + // masses/energies in MeV private final double electron_mass_c2 = PhysicsConstants.massElectron() * 1000; private final double proton_mass_c2 = PhysicsConstants.massProton() * 1000; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index 27eae0e250..b8d3b8aad4 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -27,6 +27,7 @@ * - flag for target material * - error px0 use MC !! Bad !! FIX IT FAST */ +// masses/energies should be in MeV; distances should be in mm public class KalmanFilter { @@ -259,6 +260,7 @@ private HashMap materialGeneration() { ArrayList forwardIndicators(ArrayList hitArrayList, HashMap materialHashMap) { ArrayList forwardIndicators = new ArrayList<>(); + //R, h, defined in mm! forwardIndicators.add(new Indicator(3.0, 0.2, null, true, materialHashMap.get("deuteriumGas"))); forwardIndicators.add(new Indicator(3.060, 0.001, null, true, materialHashMap.get("Kapton"))); for (Hit hit : hitArrayList) { @@ -269,6 +271,7 @@ ArrayList forwardIndicators(ArrayList hitArrayList, HashMap backwardIndicators(ArrayList hitArrayList, HashMap materialHashMap) { ArrayList backwardIndicators = new ArrayList<>(); + //R, h, defined in mm! for (int i = hitArrayList.size() - 2; i >= 0; i--) { backwardIndicators.add(new Indicator(hitArrayList.get(i).r(), 0.1, hitArrayList.get(i), false, materialHashMap.get("BONuS12Gas"))); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Propagator.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Propagator.java index b3757f8c30..8064c250d7 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Propagator.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Propagator.java @@ -9,6 +9,8 @@ import java.io.Writer; import java.util.Arrays; +// All distances here should be in mm. +// Do all those hardcoded values even make sense??? public class Propagator { private final RungeKutta4 RK4; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/RungeKutta4.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/RungeKutta4.java index 7154d1d945..8830b959e0 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/RungeKutta4.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/RungeKutta4.java @@ -121,19 +121,21 @@ private double[] f(double[] y) { } } + // This uses MeV and cm private void energyLoss( double[] yIn, double h, org.jlab.clas.tracking.kalmanfilter.Material material) { - double mass = particle.mass() * 1000; + double mass = particle.mass() * 1000; //particle mass defined in GeV, converted to MeV - h /= 10; // cm + h /= 10; // h defined in mm, converted to cm double mom = Math.sqrt(yIn[3] * yIn[3] + yIn[4] * yIn[4] + yIn[5] * yIn[5]); double E = Math.sqrt(mom * mom + mass * mass); - - double dedx = material.getEloss(mom/1000, mass/1000) * 1000; + //material::getEloss(double p, double m) uses GeV and cm + //see common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/kalmanfilter/Material.java + double dedx = material.getEloss(mom/1000, mass/1000) * 1000;//Momentum, mass input in GeV, output in GeV/cm, converted to MeV/cm double DeltaE = dedx * h; stepper.dEdx += DeltaE; - + double mom_prim; if (this.stepper.direction) mom_prim = Math.sqrt((E - DeltaE) * (E - DeltaE) - mass * mass); else mom_prim = Math.sqrt((E + DeltaE) * (E + DeltaE) - mass * mass); From 2b39ea932c4b67672e78c80e8db3439b855970fc Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Oct 2024 12:08:23 -0400 Subject: [PATCH 24/51] export BMT waveform --- .../jlab/detector/decode/CLASDecoder4.java | 43 +++++++++++++++++++ etc/bankdefs/hipo4/data.json | 19 ++++++++ 2 files changed, 62 insertions(+) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index 0796b64e00..97361f69bf 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -244,6 +244,37 @@ public List getEntriesSCALER(DetectorType type, return scaler; } + public void exportWaveforms() { + for ( DetectorDataDgtz x : dataList) { + if (x.getDescriptor().getType() == DetectorType.BMT) { + for (int i=0; i 0) { + for (int j=0; j a = this.getEntriesADC(type); + Bank b = new Bank(schemaFactory.getSchema(name), a.size()); + for (int i=0; i adcDGTZ = this.getEntriesADC(type); @@ -393,6 +424,9 @@ public Event getDataEvent(){ Event event = new Event(); + String[] wfBankNames = new String[]{"BMT::wf"}; + DetectorType[] wfBankTypes = new DetectorType[]{DetectorType.BMT}; + String[] adcBankNames = new String[]{"FTOF::adc","ECAL::adc","FTCAL::adc","FTHODO::adc","FTTRK::adc", "HTCC::adc","BST::adc","CTOF::adc","CND::adc","LTCC::adc","BMT::adc", "FMT::adc","HEL::adc","RF::adc","BAND::adc","RASTER::adc"}; @@ -413,6 +447,15 @@ public Event getDataEvent(){ } } + for(int i = 0; i < wfBankTypes.length; i++){ + Bank wfBank = getDataBankWF(wfBankNames[i],wfBankTypes[i]); + if(wfBank!=null){ + if(wfBank.getRows()>0){ + event.write(wfBank); + } + } + } + for(int i = 0; i < tdcBankTypes.length; i++){ Bank tdcBank = getDataBankTDC(tdcBankNames[i],tdcBankTypes[i]); if(tdcBank!=null){ diff --git a/etc/bankdefs/hipo4/data.json b/etc/bankdefs/hipo4/data.json index a1ef21a083..9124e59713 100644 --- a/etc/bankdefs/hipo4/data.json +++ b/etc/bankdefs/hipo4/data.json @@ -44,6 +44,25 @@ { "name":"timestamp" , "type":"L", "info":"timestamp"} ] }, + { + "name" : "BMT::wf", + "group": 20100, + "item" : 12, + "info": "WF bank for the Barrel MicroMegas Tracker", + "entries":[ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer (1-6)"}, + { "name":"component" , "type":"S", "info":"strips"}, + { "name":"order" , "type":"B", "info":"order: 0 - ADCL , 1 - ADCR"}, + { "name":"timestamp" , "type":"L", "info":"timestamp"}, + { "name":"s1" , "type":"S", "info":"sample #1"}, + { "name":"s2" , "type":"S", "info":"sample #2"}, + { "name":"s3" , "type":"S", "info":"sample #3"}, + { "name":"s4" , "type":"S", "info":"sample #4"}, + { "name":"s5" , "type":"S", "info":"sample #5"}, + { "name":"s6" , "type":"S", "info":"sample #6"} + ] + }, { "name" : "BST::adc", "group": 20200, From fb5a235079546d3ac591e6474f7f2f5854f4e7a7 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Oct 2024 15:34:14 -0400 Subject: [PATCH 25/51] cleanup --- .../org/jlab/detector/decode/CLASDecoder4.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index 97361f69bf..dc76e567b0 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -244,21 +244,6 @@ public List getEntriesSCALER(DetectorType type, return scaler; } - public void exportWaveforms() { - for ( DetectorDataDgtz x : dataList) { - if (x.getDescriptor().getType() == DetectorType.BMT) { - for (int i=0; i 0) { - for (int j=0; j a = this.getEntriesADC(type); Bank b = new Bank(schemaFactory.getSchema(name), a.size()); From f8226e57f6919fe1674b4d5390e6a7a89e9cbbd8 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 21 Oct 2024 16:54:03 -0400 Subject: [PATCH 26/51] Fixed the calculation of the hit wire position in Hit/Hit.java and KalmanFilter/Hit.java Fixed the gas composition in MaterialMap; Added some comments in KalmanFilter.java --- .../main/java/org/jlab/rec/ahdc/Hit/Hit.java | 4 +- .../org/jlab/rec/ahdc/KalmanFilter/Hit.java | 43 +++++++++++-------- .../rec/ahdc/KalmanFilter/KalmanFilter.java | 5 ++- .../rec/ahdc/KalmanFilter/MaterialMap.java | 8 ++-- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java index 8a235279dc..4d8d97cb2c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java @@ -57,8 +57,8 @@ private void wirePosition() { R_layer = R_layer + DR_layer * (this.layerId-1); double alphaW_layer = Math.toRadians(round / (numWires)); - double wx = -R_layer * Math.sin(alphaW_layer * this.wireId); - double wy = -R_layer * Math.cos(alphaW_layer * this.wireId); + double wx = -R_layer * Math.sin(alphaW_layer * this.wireId-1); + double wy = -R_layer * Math.cos(alphaW_layer * this.wireId-1); this.nbOfWires = (int) numWires; this.phi = Math.atan2(wy, wx); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index c2a547c575..145a6a0ce1 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -20,6 +20,9 @@ public class Hit implements Comparable { private final double numWires; private final Line3D line3D; + // Comparison with: common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/AHDC/AlertDCFactory.java + // here, SuperLayer, Layer, Wire, start from 1 + // in AlertDCFactory, same variables start from 1 public Hit(int superLayer, int layer, int wire, int numWire, double r, double doca) { this.superLayer = superLayer; this.layer = layer; @@ -28,29 +31,29 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do this.doca = doca; this.numWires = numWire; - final double DR_layer = 4.0; - final double round = 360.0; - final double thster = Math.toRadians(20.0); - final double zl = 300.0; + final double DR_layer = 4.0;//OK + final double round = 360.0;//OK + final double thster = Math.toRadians(20.0);//OK + final double zl = 300.0;//OK double numWires = 32.0; double R_layer = 47.0; - double zoff1 = 0.0d; - double zoff2 = 300.0d; + double zoff1 = 0.0d;//OK + double zoff2 = 300.0d;//OK Point3D p1 = new Point3D(R_layer, 0, zoff1); Vector3D n1 = new Vector3D(0, 0, 1); //n1.rotateY(-thopen); //n1.rotateZ(thtilt); - Plane3D lPlane = new Plane3D(p1, n1); + Plane3D lPlane = new Plane3D(p1, n1);//OK Point3D p2 = new Point3D(R_layer, 0, zoff2); Vector3D n2 = new Vector3D(0, 0, 1); //n2.rotateY(thopen); //n2.rotateZ(thtilt); - Plane3D rPlane = new Plane3D(p2, n2); + Plane3D rPlane = new Plane3D(p2, n2);//OK - switch (this.superLayer) { + switch (this.superLayer) {//OK case 1: numWires = 47.0; R_layer = 32.0; @@ -73,23 +76,27 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do break; } - R_layer = R_layer + DR_layer * (this.layer-1); - double alphaW_layer = Math.toRadians(round / (numWires)); - double wx = -R_layer * Math.sin(alphaW_layer * (this.wire-1)); - double wy = -R_layer * Math.cos(alphaW_layer * (this.wire-1)); + R_layer = R_layer + DR_layer * (this.layer-1);//OK + double alphaW_layer = Math.toRadians(round / (numWires));//OK + double wx = -R_layer * Math.sin(alphaW_layer * (this.wire-1));//OK + double wy = -R_layer * Math.cos(alphaW_layer * (this.wire-1));//OK - double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1))); - double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1))); - - Line3D line = new Line3D(wx, wy, -150, wx_end, wy_end, zl/2); + double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK + double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK + Line3D line = new Line3D(wx, wy, 0, wx_end, wy_end, zl);//apparent inconsistency: -150, zl/2, instead of 0, zl? + //Temporary note: if I understand the following well, it *does* lead to a position inconsistency between this code and the factory code Point3D lPoint = new Point3D(); Point3D rPoint = new Point3D(); lPlane.intersection(line, lPoint); rPlane.intersection(line, rPoint); + lPoint.setZ(-zl/2); + rPoint.setZ(zl/2); + //lPoint.show(); + //rPoint.show(); // All wire go from left to right Line3D wireLine = new Line3D(lPoint, rPoint); - + //wireLine.show(); this.line3D = wireLine; } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index b8d3b8aad4..2a52ef49db 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -91,6 +91,7 @@ private void propagation(ArrayList tracks, DataEvent event) { final double p_init = java.lang.Math.sqrt(px0*px0+py0*py0+pz0*pz0); double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; //System.out.println("y = " + x0 + ", " + y0 + ", " + z0 + ", " + px0 + ", " + py0 + ", " + pz0 + "; p = " + p_init); + // EPAF: *the line below is for TEST ONLY!!!* //double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; //System.out.println("y = " + vxmc + ", " + vymc + ", " + vzmc + ", " + pxmc + ", " + pymc + ", " + pzmc + "; p = " + java.lang.Math.sqrt(pxmc*pxmc+pymc*pymc+pzmc*pzmc)); @@ -170,7 +171,7 @@ private void propagation(ArrayList tracks, DataEvent event) { //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); - kFitter.correct(indicator); + kFitter.correct(indicator); //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } } @@ -182,7 +183,7 @@ private void propagation(ArrayList tracks, DataEvent event) { //System.out.println("indicator R " + indicator.R + " h " + indicator.h + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); if (indicator.haveAHit()) { //System.out.println("Superlayer = " + indicator.hit.getSuperLayer() + ", Layer " + indicator.hit.getLayer() + ", Wire " + indicator.hit.getWire() + ", Nwires " + indicator.hit.getNumWires() + ", Radius " + indicator.hit.getR() + ", DOCA " + indicator.hit.getDoca()); - kFitter.correct(indicator); + kFitter.correct(indicator); //System.out.println("y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum()); } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java index 53a20e6a67..cfc0ff6495 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/MaterialMap.java @@ -21,10 +21,10 @@ public static HashMap generateMaterials() { String name_Bo = "BONuS12Gas";//80% He, 20% CO2 double thickness_Bo = 1; - double density_Bo = 4.9778E-4; - double ZoverA_Bo = 0.49989; - double X0_Bo = 4.5761E+4; - double IeV_Bo = 73.8871; + double density_Bo = 1.39735E-3; + double ZoverA_Bo = 0.49983; + double X0_Bo = 3.69401E+4; + double IeV_Bo = 73.5338; org.jlab.clas.tracking.kalmanfilter.Material BONuS12 = new org.jlab.clas.tracking.kalmanfilter.Material(name_Bo, thickness_Bo, density_Bo, ZoverA_Bo, X0_Bo, IeV_Bo, units); From ebea5315c2ca14ca4508fc698e49f657d38f796c Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Oct 2024 17:36:00 -0400 Subject: [PATCH 27/51] add NamedEntry --- .../org/jlab/utils/groups/IndexedTable.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java index 2c4bb9a5db..05ad447e52 100644 --- a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java +++ b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java @@ -145,7 +145,11 @@ public double getDoubleValue(String item, int... index){ } return 0; } - + + public NamedEntry getNamedEntry(int... index) { + return new NamedEntry(entries.getItem(index), entryNames); + } + public IndexedList getList(){ return this.entries; } @@ -295,7 +299,7 @@ public Object getValueAt(int row, int column) { } return trow.getValue(column-ic).toString(); } - + public class RowConstraint { public int COLUMN = 0; @@ -377,4 +381,21 @@ public void setSize(int size){ } } } + + public static class NamedEntry extends IndexedEntry { + + Map entryNames = new HashMap<>(); + + public NamedEntry(IndexedEntry entry, List names) { + super(entry.getSize()); + for (int i=0; i Date: Mon, 21 Oct 2024 17:43:47 -0400 Subject: [PATCH 28/51] Apparently, changing the wire indexing was not desirable, at least for Hit/Hit.java --- .../alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java | 4 ++-- .../main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java | 10 +++++----- .../org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java index 4d8d97cb2c..8a235279dc 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java @@ -57,8 +57,8 @@ private void wirePosition() { R_layer = R_layer + DR_layer * (this.layerId-1); double alphaW_layer = Math.toRadians(round / (numWires)); - double wx = -R_layer * Math.sin(alphaW_layer * this.wireId-1); - double wy = -R_layer * Math.cos(alphaW_layer * this.wireId-1); + double wx = -R_layer * Math.sin(alphaW_layer * this.wireId); + double wy = -R_layer * Math.cos(alphaW_layer * this.wireId); this.nbOfWires = (int) numWires; this.phi = Math.atan2(wy, wx); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index 145a6a0ce1..d6fa3e6e39 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -78,11 +78,11 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do R_layer = R_layer + DR_layer * (this.layer-1);//OK double alphaW_layer = Math.toRadians(round / (numWires));//OK - double wx = -R_layer * Math.sin(alphaW_layer * (this.wire-1));//OK - double wy = -R_layer * Math.cos(alphaW_layer * (this.wire-1));//OK + double wx = -R_layer * Math.sin(alphaW_layer * (this.wire));//OK + double wy = -R_layer * Math.cos(alphaW_layer * (this.wire));//OK - double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK - double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK + double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire) + thster * (Math.pow(-1, this.superLayer-1)));//OK + double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire) + thster * (Math.pow(-1, this.superLayer-1)));//OK Line3D line = new Line3D(wx, wy, 0, wx_end, wy_end, zl);//apparent inconsistency: -150, zl/2, instead of 0, zl? //Temporary note: if I understand the following well, it *does* lead to a position inconsistency between this code and the factory code @@ -105,7 +105,7 @@ public RealVector get_Vector() { } public RealMatrix get_MeasurementNoise() { - return new Array2DRowRealMatrix(new double[][]{{10}}); + return new Array2DRowRealMatrix(new double[][]{{10.0}});//in cm... 10 cm is probably too much. } public double doca() { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index 2a52ef49db..2caef20609 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -136,6 +136,7 @@ private void propagation(ArrayList tracks, DataEvent event) { // Initialization of the Kalman Fitter RealVector initialStateEstimate = new ArrayRealVector(stepper.y); + //first 3 lines in cm^2; last 3 lines in MeV^2 RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{100.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 100.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 100.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); KFitter kFitter = new KFitter(initialStateEstimate, initialErrorCovariance, stepper, propagator); From b2eff249a7b332ce4bf468bba4bf86ef04530d69 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Oct 2024 18:02:50 -0400 Subject: [PATCH 29/51] refactor --- .../org/jlab/utils/groups/IndexedTable.java | 16 -------------- .../org/jlab/utils/groups/NamedEntry.java | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 common-tools/clas-utils/src/main/java/org/jlab/utils/groups/NamedEntry.java diff --git a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java index 05ad447e52..bb8dec696c 100644 --- a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java +++ b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java @@ -382,20 +382,4 @@ public void setSize(int size){ } } - public static class NamedEntry extends IndexedEntry { - - Map entryNames = new HashMap<>(); - - public NamedEntry(IndexedEntry entry, List names) { - super(entry.getSize()); - for (int i=0; i entryNames = new HashMap<>(); + + public NamedEntry(IndexedTable.IndexedEntry entry, List names) { + super(entry.getSize()); + for (int i=0; i Date: Mon, 21 Oct 2024 18:03:06 -0400 Subject: [PATCH 30/51] add bank link --- etc/bankdefs/hipo4/data.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etc/bankdefs/hipo4/data.json b/etc/bankdefs/hipo4/data.json index 9124e59713..d1850bb1cd 100644 --- a/etc/bankdefs/hipo4/data.json +++ b/etc/bankdefs/hipo4/data.json @@ -41,7 +41,8 @@ { "name":"time" , "type":"F", "info":"time from pulse fit"}, { "name":"ped" , "type":"S", "info":"pedestal from pulse analysis"}, { "name":"integral" , "type":"I", "info":"ADC integral (sum over the pulse)"}, - { "name":"timestamp" , "type":"L", "info":"timestamp"} + { "name":"timestamp" , "type":"L", "info":"timestamp"}, + { "name":"id" , "type":"S", "info":"link to BMT::wf"} ] }, { From 27a4c218d693b7a0c2de2af9b6feace8e2804867 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 21 Oct 2024 18:08:05 -0400 Subject: [PATCH 31/51] refactor --- .../jlab/detector/pulse/HipoExtractor.java | 97 +++++++++++++++++++ .../org/jlab/detector/pulse/IExtractor.java | 10 ++ .../java/org/jlab/detector/pulse/Mode1.java | 38 ++++++++ .../java/org/jlab/detector/pulse/Pulse.java | 31 ++++++ 4 files changed, 176 insertions(+) create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/IExtractor.java create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java new file mode 100644 index 0000000000..35681e101e --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java @@ -0,0 +1,97 @@ + +package org.jlab.detector.pulse; + +import java.util.ArrayList; +import java.util.List; +import org.jlab.io.base.DataBank; +import org.jlab.jnp.hipo4.data.Bank; +import org.jlab.utils.groups.NamedEntry; + +public abstract class HipoExtractor implements IExtractor { + + public static final void copyIndices(Bank src, Bank dest, int isrc, int idest) { + dest.putShort("sector", idest, src.getShort("sector",isrc)); + dest.putShort("layer", idest, src.getShort("layer",isrc)); + dest.putShort("component", idest, src.getShort("component",isrc)); + dest.putShort("order", idest, src.getShort("order",isrc)); + dest.putShort("index", idest, (short)isrc); + } + + public static final void copyIndices(DataBank src, DataBank dest, int isrc, int idest) { + dest.setShort("sector", idest, src.getShort("sector",isrc)); + dest.setShort("layer", idest, src.getShort("layer",isrc)); + dest.setShort("component", idest, src.getShort("component",isrc)); + dest.setShort("order", idest, src.getShort("order",isrc)); + dest.setShort("index", idest, (short)isrc); + } + + public final List getPulses(NamedEntry pars, DataBank bank) { + List pulses = new ArrayList<>(); + for (int i=0; i getPulses(NamedEntry pars, Bank bank) { + List pulses = new ArrayList<>(); + for (int i=0; i 0) { + List pulses = getPulses(pars, src); + dest.reset(); + dest.setRows(pulses.size()); + for (int i=0; i 0) { + List pulses = getPulses(pars, src); + dest.reset(); + dest.allocate(pulses.size()); + for (int i=0; i 0) { + Bank adc = new Bank(schema.getSchema(pars.adcBankName)); + update(pars, wf, adc); + event.remove(schema.getSchema(pars.adcBankName)); + if (adc.getRows() > 0) event.write(adc); + } + } + + public final void update(NamedEntry pars, DataEvent event) { + DataBank wf = event.getBank(pars.wfBankName); + if (wf.rows() > 0) { + DataBank adc = event.getBank(pars.adcBankName); + update(pars, wf, adc); + event.removeBank(pars.adcBankName); + if (adc.rows() > 0) event.appendBank(adc); + } + } +*/ +} \ No newline at end of file diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/IExtractor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/IExtractor.java new file mode 100644 index 0000000000..bfa765d84e --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/IExtractor.java @@ -0,0 +1,10 @@ +package org.jlab.detector.pulse; + +import java.util.List; +import org.jlab.utils.groups.NamedEntry; + +public interface IExtractor { + + public List extract(NamedEntry pars, int id, short... samples); + +} diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java new file mode 100644 index 0000000000..7c015abf5e --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java @@ -0,0 +1,38 @@ +package org.jlab.detector.pulse; + +import java.util.ArrayList; +import java.util.List; +import org.jlab.utils.groups.NamedEntry; + +public class Mode1 extends HipoExtractor { + + @Override + public List extract(NamedEntry entry, int id, short... samples) { + + // Retrive the extraction parameters from a CCDB table: + double ped = entry.getValue("ped").doubleValue(); + double tet = entry.getValue("tet").doubleValue(); + int nsa = entry.getValue("nsa").intValue(); + int nsb = entry.getValue("nsb").intValue(); + + // Perform the extraction algorithm: + List pulses = new ArrayList<>(); + for (int i=0; i ped+tet) { + int n = 0; + float integral = 0; + for (int j=i-nsb; j<=i+nsa; ++j) { + if (j<0) continue; + if (j>=samples.length) continue; + integral += samples[j]; + n++; + } + integral -= n * ped; + pulses.add(new Pulse(integral, i, 0x0, id)); + i += nsa; + } + } + return pulses; + } + +} diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java new file mode 100644 index 0000000000..53539b5b1e --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java @@ -0,0 +1,31 @@ +package org.jlab.detector.pulse; + +import org.jlab.detector.base.DetectorDescriptor; + +public class Pulse { + + public DetectorDescriptor descriptor; + public long timestamp; + public float integral; + public float time; + public long flags; + public int id; + + public Pulse(DetectorDescriptor d) { + this.descriptor = d; + } + + public Pulse(float integral, float time, long flags, int id) { + this.integral = integral; + this.time = time; + this.flags = flags; + this.id = id; + } + + @Override + public String toString() { + return String.format("org.jlab.detector.Pulse: integral=%f time=%f flags=%d id=%d", + integral, time, flags, id); + } + +} \ No newline at end of file From d1e0e959a0ce5c79658c5334a6514a2b8c710112 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 24 Oct 2024 14:53:56 -0400 Subject: [PATCH 32/51] preserve index --- .../org/jlab/utils/groups/IndexedTable.java | 4 +-- .../org/jlab/utils/groups/NamedEntry.java | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java index bb8dec696c..a0865613f4 100644 --- a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java +++ b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java @@ -65,7 +65,7 @@ public void setPrecision(Integer precision){ str.append("f"); this.precisionFormat = str.toString(); } - + public boolean hasEntry(int... index){ return this.entries.hasItem(index); } @@ -147,7 +147,7 @@ public double getDoubleValue(String item, int... index){ } public NamedEntry getNamedEntry(int... index) { - return new NamedEntry(entries.getItem(index), entryNames); + return NamedEntry.create(entries.getItem(index), entryNames, index); } public IndexedList getList(){ diff --git a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/NamedEntry.java b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/NamedEntry.java index 7611fe6a6e..b221ad99ef 100644 --- a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/NamedEntry.java +++ b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/NamedEntry.java @@ -3,20 +3,32 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jlab.utils.groups.IndexedTable.IndexedEntry; -public class NamedEntry extends IndexedTable.IndexedEntry { +/** + * IndexedEntry wrapper for names and indices. + */ +public class NamedEntry { - Map entryNames = new HashMap<>(); + IndexedEntry entry; + Map names = new HashMap<>(); + int[] index; - public NamedEntry(IndexedTable.IndexedEntry entry, List names) { - super(entry.getSize()); + public static NamedEntry create(IndexedEntry entry, List names, int... index) { + NamedEntry e = new NamedEntry(); for (int i=0; i Date: Thu, 24 Oct 2024 14:54:11 -0400 Subject: [PATCH 33/51] tested, cleaned up --- .../detector/base/DetectorDescriptor.java | 8 + .../jlab/detector/decode/CLASDecoder4.java | 17 +- .../jlab/detector/pulse/ExampleExtractor.java | 54 +++++ .../jlab/detector/pulse/HipoExtractor.java | 189 +++++++++++------- .../java/org/jlab/detector/pulse/Mode1.java | 38 ---- .../java/org/jlab/detector/pulse/Pulse.java | 13 +- .../jlab/clas/reco/ReconstructionEngine.java | 4 + .../clas/service/PulseExtractorEngine.java | 41 ++++ 8 files changed, 248 insertions(+), 116 deletions(-) create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ExampleExtractor.java delete mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java create mode 100644 common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java index 81d12615df..058916d69c 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java @@ -64,6 +64,14 @@ public void setOrder(int order){ } } + public int[] getCSC() { + return new int[]{hw_CRATE,hw_SLOT,hw_CHANNEL}; + } + + public int[] getSLCO() { + return new int[]{dt_SECTOR,dt_LAYER,dt_COMPONENT,dt_ORDER}; + } + public DetectorType getType(){ return this.detectorType;} public final void setType(DetectorType type){ diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index dc76e567b0..2c939a1f87 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -14,6 +14,7 @@ import org.jlab.detector.helicity.HelicityBit; import org.jlab.detector.helicity.HelicitySequence; import org.jlab.detector.helicity.HelicityState; +import org.jlab.detector.pulse.ExampleExtractor; import org.jlab.logging.DefaultLogger; @@ -47,6 +48,7 @@ public class CLASDecoder4 { private boolean isRunNumberFixed = false; private int decoderDebugMode = 0; private SchemaFactory schemaFactory = new SchemaFactory(); + private ExampleExtractor mode3 = new ExampleExtractor(); public CLASDecoder4(boolean development){ codaDecoder = new CodaEventDecoder(); @@ -244,6 +246,10 @@ public List getEntriesSCALER(DetectorType type, return scaler; } + public void extractPulses(Event event) { + mode3.update(6, null, event, schemaFactory, "BMT::wf", "BMT::adc"); + } + public Bank getDataBankWF(String name, DetectorType type) { List a = this.getEntriesADC(type); Bank b = new Bank(schemaFactory.getSchema(name), a.size()); @@ -434,10 +440,8 @@ public Event getDataEvent(){ for(int i = 0; i < wfBankTypes.length; i++){ Bank wfBank = getDataBankWF(wfBankNames[i],wfBankTypes[i]); - if(wfBank!=null){ - if(wfBank.getRows()>0){ - event.write(wfBank); - } + if(wfBank!=null && wfBank.getRows()>0){ + event.write(wfBank); } } @@ -799,7 +803,9 @@ public static void main(String[] args){ decodedEvent.read(rawScaler); decodedEvent.read(rawRunConf); decodedEvent.read(helicityAdc); - + + decoder.extractPulses(decodedEvent); + helicityReadings.add(HelicityState.createFromFadcBank(helicityAdc, rawRunConf, decoder.detectorDecoder.scalerManager)); @@ -841,4 +847,5 @@ public static void main(String[] args){ writer.close(); } + } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ExampleExtractor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ExampleExtractor.java new file mode 100644 index 0000000000..cbf6a320ec --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ExampleExtractor.java @@ -0,0 +1,54 @@ +package org.jlab.detector.pulse; + +import java.util.ArrayList; +import java.util.List; +import org.jlab.utils.groups.NamedEntry; + +public class ExampleExtractor extends HipoExtractor { + + // Fixed extraction parameters: + final double ped = 2000; + final double tet = 2000; + final int nsa = 30; + final int nsb = 5; + + /** + * @param pars CCDB row + * @param id link to row in source bank + * @param samples ADC samples + * @return extracted pulses + */ + @Override + public List extract(NamedEntry pars, int id, short... samples) { + + List pulses = null; + + /* + // Retrive extraction parameters from a CCDB table: + double ped = pars.getValue("ped").doubleValue(); + double tet = pars.getValue("tet").doubleValue(); + int nsa = pars.getValue("nsa").intValue(); + int nsb = pars.getValue("nsb").intValue(); + */ + + // Perform the extraction: + for (int i=0; i ped+tet) { + int n = 0; + float integral = 0; + for (int j=i-nsb; j<=i+nsa; ++j) { + if (j<0) continue; + if (j>=samples.length) break; + integral += samples[j]; + n++; + } + integral -= n * ped; + if (pulses == null) pulses = new ArrayList<>(); + pulses.add(new Pulse(integral, i, 0x0, id)); + i += nsa; + } + } + return pulses; + } + +} diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java index 35681e101e..cff36fe313 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java @@ -4,94 +4,147 @@ import java.util.ArrayList; import java.util.List; import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; import org.jlab.jnp.hipo4.data.Bank; -import org.jlab.utils.groups.NamedEntry; +import org.jlab.jnp.hipo4.data.Event; +import org.jlab.jnp.hipo4.data.SchemaFactory; +import org.jlab.utils.groups.IndexedTable; +/** + * For now, a place to store standard waveform/pulse HIPO manipulations. + * No bounds checking for number of samples. + */ public abstract class HipoExtractor implements IExtractor { - public static final void copyIndices(Bank src, Bank dest, int isrc, int idest) { - dest.putShort("sector", idest, src.getShort("sector",isrc)); - dest.putShort("layer", idest, src.getShort("layer",isrc)); - dest.putShort("component", idest, src.getShort("component",isrc)); - dest.putShort("order", idest, src.getShort("order",isrc)); - dest.putShort("index", idest, (short)isrc); - } - - public static final void copyIndices(DataBank src, DataBank dest, int isrc, int idest) { - dest.setShort("sector", idest, src.getShort("sector",isrc)); - dest.setShort("layer", idest, src.getShort("layer",isrc)); - dest.setShort("component", idest, src.getShort("component",isrc)); - dest.setShort("order", idest, src.getShort("order",isrc)); - dest.setShort("index", idest, (short)isrc); - } - - public final List getPulses(NamedEntry pars, DataBank bank) { - List pulses = new ArrayList<>(); - for (int i=0; i 0) { + Bank adc = new Bank(schema.getSchema(adcBankName)); + update(n, it, wf, adc); + event.remove(schema.getSchema(adcBankName)); + if (adc.getRows() > 0) event.write(adc); } - return pulses; } - public final List getPulses(NamedEntry pars, Bank bank) { - List pulses = new ArrayList<>(); - for (int i=0; i 0) { + event.removeBank(adcBankName); + List pulses = getPulses(n, it, wf); + if (pulses != null && !pulses.isEmpty()) { + DataBank adc = event.createBank(adcBankName, pulses.size()); + for (int i=0; i 0) { - List pulses = getPulses(pars, src); + List pulses = getPulses(n, it, src); dest.reset(); - dest.setRows(pulses.size()); - for (int i=0; i 0) { - List pulses = getPulses(pars, src); - dest.reset(); - dest.allocate(pulses.size()); - for (int i=0; i getPulses(int n, IndexedTable it, DataBank wfBank) { + List pulses = null; + short[] samples = new short[n]; + for (int i=0; i p = it==null ? extract(null, i, samples) : + extract(it.getNamedEntry(getIndices(wfBank,i)), i, samples); + if (p!=null && !p.isEmpty()) { + if (pulses == null) pulses = new ArrayList<>(); + pulses.addAll(p); } } + return pulses; } -/* - public final void update(NamedEntry pars, Event event, SchemaFactory schema) { - Bank wf = new Bank(schema.getSchema(pars.wfBankName)); - event.read(wf); - if (wf.getRows() > 0) { - Bank adc = new Bank(schema.getSchema(pars.adcBankName)); - update(pars, wf, adc); - event.remove(schema.getSchema(pars.adcBankName)); - if (adc.getRows() > 0) event.write(adc); - } - } - public final void update(NamedEntry pars, DataEvent event) { - DataBank wf = event.getBank(pars.wfBankName); - if (wf.rows() > 0) { - DataBank adc = event.getBank(pars.adcBankName); - update(pars, wf, adc); - event.removeBank(pars.adcBankName); - if (adc.rows() > 0) event.appendBank(adc); + private List getPulses(int n, IndexedTable it, Bank wfBank) { + List pulses = null; + short[] samples = new short[n]; + for (int i=0; i(); + pulses.addAll(p); + } } + return pulses; } -*/ + } \ No newline at end of file diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java deleted file mode 100644 index 7c015abf5e..0000000000 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode1.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jlab.detector.pulse; - -import java.util.ArrayList; -import java.util.List; -import org.jlab.utils.groups.NamedEntry; - -public class Mode1 extends HipoExtractor { - - @Override - public List extract(NamedEntry entry, int id, short... samples) { - - // Retrive the extraction parameters from a CCDB table: - double ped = entry.getValue("ped").doubleValue(); - double tet = entry.getValue("tet").doubleValue(); - int nsa = entry.getValue("nsa").intValue(); - int nsb = entry.getValue("nsb").intValue(); - - // Perform the extraction algorithm: - List pulses = new ArrayList<>(); - for (int i=0; i ped+tet) { - int n = 0; - float integral = 0; - for (int j=i-nsb; j<=i+nsa; ++j) { - if (j<0) continue; - if (j>=samples.length) continue; - integral += samples[j]; - n++; - } - integral -= n * ped; - pulses.add(new Pulse(integral, i, 0x0, id)); - i += nsa; - } - } - return pulses; - } - -} diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java index 53539b5b1e..6e69255448 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java @@ -11,10 +11,13 @@ public class Pulse { public long flags; public int id; - public Pulse(DetectorDescriptor d) { - this.descriptor = d; - } - + /** + * Units are the same as the raw units of the samples. + * @param integral pulse integral, pedestal-subtracted + * @param time pulse time + * @param flags user flags + * @param id link to row in source bank + */ public Pulse(float integral, float time, long flags, int id) { this.integral = integral; this.time = time; @@ -24,7 +27,7 @@ public Pulse(float integral, float time, long flags, int id) { @Override public String toString() { - return String.format("org.jlab.detector.Pulse: integral=%f time=%f flags=%d id=%d", + return String.format("pulse: integral=%f time=%f flags=%d id=%d", integral, time, flags, id); } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java index 79b4fc6f1d..cce8c4301b 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java @@ -96,6 +96,10 @@ public void registerOutputBank(String... bankName) { } } + protected SchemaFactory getSchemaFactory() { + return this.engineDictionary; + } + protected RawBank getRawBankReader(String bankName) { return new RawDataBank(bankName, this.rawBankOrders); } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java new file mode 100644 index 0000000000..0ca7ce86ce --- /dev/null +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java @@ -0,0 +1,41 @@ +package org.jlab.clas.service; + +import org.jlab.clas.reco.ReconstructionEngine; +import org.jlab.detector.pulse.ExampleExtractor; +import org.jlab.io.base.DataEvent; + +public class PulseExtractorEngine extends ReconstructionEngine { + + ExampleExtractor basic = new ExampleExtractor(); + + public PulseExtractorEngine() { + super("PULSE", "baltzell", "0.0"); + } + + @Override + public boolean init() { + // If using a CCDB table, must register it here: + //requireConstants("/daq/config/ahdc"); + return true; + } + + @Override + public boolean processDataEvent(DataEvent event) { + + // No CCDB table, hardcoded parameters in the extractor: + basic.update(6, null, event, "BMT::wf", "BMT::adc"); + + /* + // Requiring a CCDB table: + DataBank runConfig = event.getBank("RUN::config"); + if (runConfig.rows()>0) { + IndexedTable it = getConstantsManager().getConstants( + runConfig.getInt("run", 0), "/daq/config/ahdc"); + basic.update(136, it, event, "AHDC::wf", "AHDC::adc"); + } + */ + + return true; + } + +} From 05b21086e169072676f58468e086c26e9ccc180c Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 24 Oct 2024 17:32:00 -0400 Subject: [PATCH 34/51] cleanup, add a mode-7 --- .../jlab/detector/decode/CLASDecoder4.java | 4 +- .../{ExampleExtractor.java => Mode3.java} | 19 ++++++++-- .../java/org/jlab/detector/pulse/Mode7.java | 38 +++++++++++++++++++ .../java/org/jlab/detector/pulse/Pulse.java | 1 + .../clas/service/PulseExtractorEngine.java | 4 +- 5 files changed, 58 insertions(+), 8 deletions(-) rename common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/{ExampleExtractor.java => Mode3.java} (70%) create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode7.java diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index 2c939a1f87..b7a935565b 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -14,7 +14,7 @@ import org.jlab.detector.helicity.HelicityBit; import org.jlab.detector.helicity.HelicitySequence; import org.jlab.detector.helicity.HelicityState; -import org.jlab.detector.pulse.ExampleExtractor; +import org.jlab.detector.pulse.Mode3; import org.jlab.logging.DefaultLogger; @@ -48,7 +48,7 @@ public class CLASDecoder4 { private boolean isRunNumberFixed = false; private int decoderDebugMode = 0; private SchemaFactory schemaFactory = new SchemaFactory(); - private ExampleExtractor mode3 = new ExampleExtractor(); + private Mode3 mode3 = new Mode3(); public CLASDecoder4(boolean development){ codaDecoder = new CodaEventDecoder(); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ExampleExtractor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode3.java similarity index 70% rename from common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ExampleExtractor.java rename to common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode3.java index cbf6a320ec..058d94e126 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ExampleExtractor.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode3.java @@ -4,7 +4,12 @@ import java.util.List; import org.jlab.utils.groups.NamedEntry; -public class ExampleExtractor extends HipoExtractor { +/** + * Similar to FADC250 Mode-3 pulse extraction. + * + * @author baltzell + */ +public class Mode3 extends HipoExtractor { // Fixed extraction parameters: final double ped = 2000; @@ -32,10 +37,12 @@ public List extract(NamedEntry pars, int id, short... samples) { */ // Perform the extraction: - for (int i=0; i ped+tet) { + for (int i=0; i ped+tet && samples[i+1] > samples[i]) { int n = 0; float integral = 0; + // Integrate the pulse: for (int j=i-nsb; j<=i+nsa; ++j) { if (j<0) continue; if (j>=samples.length) break; @@ -43,8 +50,12 @@ public List extract(NamedEntry pars, int id, short... samples) { n++; } integral -= n * ped; + Pulse p = new Pulse(integral, i, 0x0, id); + p.pedestal = (float)(ped); + // Add the new pulse to the list: if (pulses == null) pulses = new ArrayList<>(); - pulses.add(new Pulse(integral, i, 0x0, id)); + pulses.add(p); + // Add a holdoff time before next possible pulse: i += nsa; } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode7.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode7.java new file mode 100644 index 0000000000..aafdf25a40 --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Mode7.java @@ -0,0 +1,38 @@ +package org.jlab.detector.pulse; + +import java.util.List; +import org.jlab.utils.groups.NamedEntry; + +/** + * Similar to a Mode-7 FADC250 pulse extraction + * @author baltzell + */ +public class Mode7 extends Mode3 { + + /** + * @param t0 threshold-crossing sample index + * @param ped pedestal (for calculating pulse half-height) + * @param samples + * @return pulse time + */ + private static float calculateTime(int t0, float ped, short... samples) { + for (int j=t0+1; j extract(NamedEntry pars, int id, short... samples) { + List pulses = super.extract(pars, id, samples); + for (Pulse p : pulses) + p.time = calculateTime((int)p.time, p.pedestal, samples); + return pulses; + } + +} diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java index 6e69255448..1adf719d43 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java @@ -8,6 +8,7 @@ public class Pulse { public long timestamp; public float integral; public float time; + public float pedestal; public long flags; public int id; diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java index 0ca7ce86ce..1bc79c85fe 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java @@ -1,12 +1,12 @@ package org.jlab.clas.service; import org.jlab.clas.reco.ReconstructionEngine; -import org.jlab.detector.pulse.ExampleExtractor; +import org.jlab.detector.pulse.Mode3; import org.jlab.io.base.DataEvent; public class PulseExtractorEngine extends ReconstructionEngine { - ExampleExtractor basic = new ExampleExtractor(); + Mode3 basic = new Mode3(); public PulseExtractorEngine() { super("PULSE", "baltzell", "0.0"); From 39a126ec4c09b417b42d238e502ae4a00fa49c4a Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Thu, 24 Oct 2024 17:58:01 -0400 Subject: [PATCH 35/51] docs, examples --- .../jlab/detector/pulse/HipoExtractor.java | 42 ++++++++++++------- .../java/org/jlab/detector/pulse/Mode3.java | 2 +- .../java/org/jlab/detector/pulse/Mode7.java | 3 +- .../java/org/jlab/detector/pulse/Pulse.java | 3 ++ .../clas/service/PulseExtractorEngine.java | 13 +++++- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java index cff36fe313..fba8012e45 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/HipoExtractor.java @@ -11,8 +11,17 @@ import org.jlab.utils.groups.IndexedTable; /** - * For now, a place to store standard waveform/pulse HIPO manipulations. - * No bounds checking for number of samples. + * For now, a place to store standard boilerplate for waveform/pulse HIPO + * manipulations. No bounds checking regarding number of samples. + * + * Here an IndexedTable object from CCDB is used to pass initialization parameters + * to the extractor. If that object is null, the @{link org.jlab.detector.pulse.IExtractor.extract} + * method should know what to do, e.g., hardcoded, channel-independent parameters. + * + * FIXME: Passing the #samples around is obviously bad, and there's probably a + * few non-horrible ways that can be addressed without changing bank format. + * + * @author baltzell */ public abstract class HipoExtractor implements IExtractor { @@ -36,6 +45,7 @@ public void update(int n, IndexedTable it, Event event, SchemaFactory schema, St } /** + * This could be overriden, e.g., for non-standard ADC banks. * @param n number of samples in readout * @param it CCDB table containing extraction initialization parameters * @param event the event to modify @@ -60,22 +70,22 @@ public void update(int n, IndexedTable it, DataEvent event, String wfBankName, S } /** - * - * @param n - * @param it - * @param src - * @param dest + * This could be overriden, e.g., for non-standard ADC banks. + * @param n number of samples in readout + * @param it CCDB table containing extraction initialization parameters + * @param wfBank input waveform bank + * @param adcBank output ADC bank */ - protected void update(int n, IndexedTable it, Bank src, Bank dest) { - if (src.getRows() > 0) { - List pulses = getPulses(n, it, src); - dest.reset(); - dest.setRows(pulses!=null ? pulses.size() : 0); + protected void update(int n, IndexedTable it, Bank wfBank, Bank adcBank) { + if (wfBank.getRows() > 0) { + List pulses = getPulses(n, it, wfBank); + adcBank.reset(); + adcBank.setRows(pulses!=null ? pulses.size() : 0); if (pulses!=null && !pulses.isEmpty()) { for (int i=0; i getPulses(int n, IndexedTable it, Bank wfBank) { for (int i=0; i Date: Mon, 28 Oct 2024 13:38:31 -0400 Subject: [PATCH 36/51] Verified and updated the calculations of the wire ends positions. A few printouts are still left in. --- .../main/java/org/jlab/rec/ahdc/Hit/Hit.java | 8 ++++-- .../org/jlab/rec/ahdc/KalmanFilter/Hit.java | 25 +++++++++++-------- .../jlab/rec/ahdc/KalmanFilter/KFitter.java | 10 +++++++- .../rec/ahdc/KalmanFilter/KalmanFilter.java | 4 +-- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java index 8a235279dc..f73701103f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java @@ -3,6 +3,7 @@ public class Hit implements Comparable { + private final double thster = Math.toRadians(20.0); private final int id; private final int superLayerId; private final int layerId; @@ -57,9 +58,12 @@ private void wirePosition() { R_layer = R_layer + DR_layer * (this.layerId-1); double alphaW_layer = Math.toRadians(round / (numWires)); - double wx = -R_layer * Math.sin(alphaW_layer * this.wireId); - double wy = -R_layer * Math.cos(alphaW_layer * this.wireId); + //should it be at z = 0? in which case, we need to account for the positive or negative stereo angle... + double wx = -R_layer * Math.sin(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1))); + double wy = -R_layer * Math.cos(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1))); + System.out.println(" superlayer " + this.superLayerId + " layer " + this.layerId + " wire " + this.wireId + " R_layer " + R_layer + " wx " + wx + " wy " + wy); + this.nbOfWires = (int) numWires; this.phi = Math.atan2(wy, wx); this.radius = R_layer; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index d6fa3e6e39..7b475e508e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -39,8 +39,8 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do double numWires = 32.0; double R_layer = 47.0; - double zoff1 = 0.0d;//OK - double zoff2 = 300.0d;//OK + double zoff1 = -zl/2;//OK + double zoff2 = +zl/2;//OK Point3D p1 = new Point3D(R_layer, 0, zoff1); Vector3D n1 = new Vector3D(0, 0, 1); //n1.rotateY(-thopen); @@ -76,24 +76,27 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do break; } + R_layer = R_layer + DR_layer * (this.layer-1);//OK double alphaW_layer = Math.toRadians(round / (numWires));//OK - double wx = -R_layer * Math.sin(alphaW_layer * (this.wire));//OK - double wy = -R_layer * Math.cos(alphaW_layer * (this.wire));//OK + double wx = -R_layer * Math.sin(alphaW_layer * (this.wire-1));//OK + double wy = -R_layer * Math.cos(alphaW_layer * (this.wire-1));//OK - double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire) + thster * (Math.pow(-1, this.superLayer-1)));//OK - double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire) + thster * (Math.pow(-1, this.superLayer-1)));//OK + double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK + double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK - Line3D line = new Line3D(wx, wy, 0, wx_end, wy_end, zl);//apparent inconsistency: -150, zl/2, instead of 0, zl? + System.out.println(" superlayer " + this.superLayer + " layer " + this.layer + " wire " + this.wire + " wx " + wx + " wy " + wy + " wx_end " + wx_end + " wy_end " + wy_end); + + Line3D line = new Line3D(wx, wy, -zl/2, wx_end, wy_end, zl/2);//apparent inconsistency: -150, zl/2, instead of 0, zl? //Temporary note: if I understand the following well, it *does* lead to a position inconsistency between this code and the factory code Point3D lPoint = new Point3D(); Point3D rPoint = new Point3D(); lPlane.intersection(line, lPoint); rPlane.intersection(line, rPoint); - lPoint.setZ(-zl/2); - rPoint.setZ(zl/2); - //lPoint.show(); - //rPoint.show(); + //lPoint.setZ(-zl/2); + //rPoint.setZ(zl/2); + lPoint.show(); + rPoint.show(); // All wire go from left to right Line3D wireLine = new Line3D(lPoint, rPoint); //wireLine.show(); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java index cb45c9ac7d..0008738825 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java @@ -73,6 +73,8 @@ public void predict(Indicator indicator) throws Exception { } public void correct(Indicator indicator) { + System.out.println(" state before: (" + stateEstimation.getEntry(0) + ", " + stateEstimation.getEntry(1) + ", " + stateEstimation.getEntry(2) + ", " + stateEstimation.getEntry(3) + ", " + stateEstimation.getEntry(4) + ", " + stateEstimation.getEntry(5) + ");" ); + System.out.println(" state radius before: " + Math.sqrt( Math.pow(stateEstimation.getEntry(0), 2) + Math.pow(stateEstimation.getEntry(1), 2) ) ); RealVector z; RealMatrix measurementNoise; RealMatrix measurementMatrix; @@ -94,8 +96,12 @@ public void correct(Indicator indicator) { h = h(stateEstimation, indicator); z = indicator.hit.get_Vector(); + System.out.println(" distance " + h.getEntry(0) + " hit R " + indicator.hit.getR() + " hit wire " + indicator.hit.getWire() + " hit doca " + indicator.hit.getDoca()); + } + /* + // EPAF: trying to not modify the trajectory for tests... RealMatrix measurementMatrixT = measurementMatrix.transpose(); // S = H * P(k) * H' + R @@ -116,7 +122,9 @@ public void correct(Indicator indicator) { // Numerically more stable !! RealMatrix tmpMatrix = identity.subtract(kalmanGain.multiply(measurementMatrix)); errorCovariance = tmpMatrix.multiply(errorCovariance.multiply(tmpMatrix.transpose())).add(kalmanGain.multiply(measurementNoise.multiply(kalmanGain.transpose()))); - + */ + + //System.out.println(" state after: (" + stateEstimation.getEntry(0) + ", " + stateEstimation.getEntry(1) + ", " + stateEstimation.getEntry(2) + ", " + stateEstimation.getEntry(3) + ", " + stateEstimation.getEntry(4) + ", " + stateEstimation.getEntry(5) + ");" ); // Give back to the stepper the new stateEstimation stepper.y = stateEstimation.toArray(); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index 2caef20609..ac476a43b2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -89,10 +89,10 @@ private void propagation(ArrayList tracks, DataEvent event) { final double py0 = tracks.get(0).get_py(); final double pz0 = tracks.get(0).get_pz(); final double p_init = java.lang.Math.sqrt(px0*px0+py0*py0+pz0*pz0); - double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; + //double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; //System.out.println("y = " + x0 + ", " + y0 + ", " + z0 + ", " + px0 + ", " + py0 + ", " + pz0 + "; p = " + p_init); // EPAF: *the line below is for TEST ONLY!!!* - //double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; + double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; //System.out.println("y = " + vxmc + ", " + vymc + ", " + vzmc + ", " + pxmc + ", " + pymc + ", " + pzmc + "; p = " + java.lang.Math.sqrt(pxmc*pxmc+pymc*pymc+pzmc*pzmc)); // Initialization hit From 2b4f081699e4564d92108908619c5f32621a4484 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 28 Oct 2024 17:19:47 -0400 Subject: [PATCH 37/51] Fixed B field direction in Kalman filter (anywhere else that it's wrong?) --- .../src/main/java/org/jlab/rec/ahdc/Hit/Hit.java | 2 +- .../java/org/jlab/rec/ahdc/KalmanFilter/Hit.java | 13 ++++++++----- .../org/jlab/rec/ahdc/KalmanFilter/KFitter.java | 8 +++----- .../jlab/rec/ahdc/KalmanFilter/KalmanFilter.java | 6 +++--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java index f73701103f..df9da417cf 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java @@ -62,7 +62,7 @@ private void wirePosition() { double wx = -R_layer * Math.sin(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1))); double wy = -R_layer * Math.cos(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1))); - System.out.println(" superlayer " + this.superLayerId + " layer " + this.layerId + " wire " + this.wireId + " R_layer " + R_layer + " wx " + wx + " wy " + wy); + //System.out.println(" superlayer " + this.superLayerId + " layer " + this.layerId + " wire " + this.wireId + " R_layer " + R_layer + " wx " + wx + " wy " + wy); this.nbOfWires = (int) numWires; this.phi = Math.atan2(wy, wx); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index 7b475e508e..d0a8c9023b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -85,18 +85,17 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK - System.out.println(" superlayer " + this.superLayer + " layer " + this.layer + " wire " + this.wire + " wx " + wx + " wy " + wy + " wx_end " + wx_end + " wy_end " + wy_end); + //System.out.println(" superlayer " + this.superLayer + " layer " + this.layer + " wire " + this.wire + " wx " + wx + " wy " + wy + " wx_end " + wx_end + " wy_end " + wy_end); - Line3D line = new Line3D(wx, wy, -zl/2, wx_end, wy_end, zl/2);//apparent inconsistency: -150, zl/2, instead of 0, zl? - //Temporary note: if I understand the following well, it *does* lead to a position inconsistency between this code and the factory code + Line3D line = new Line3D(wx, wy, -zl/2, wx_end, wy_end, zl/2); Point3D lPoint = new Point3D(); Point3D rPoint = new Point3D(); lPlane.intersection(line, lPoint); rPlane.intersection(line, rPoint); //lPoint.setZ(-zl/2); //rPoint.setZ(zl/2); - lPoint.show(); - rPoint.show(); + //lPoint.show(); + //rPoint.show(); // All wire go from left to right Line3D wireLine = new Line3D(lPoint, rPoint); //wireLine.show(); @@ -120,6 +119,10 @@ public double doca() { public Line3D line() {return line3D;} public double distance(Point3D point3D) { + //System.out.println("Calculating distance: "); + //this.line3D.show(); + //point3D.show(); + //System.out.println(" d = " + this.line3D.distance(point3D).length()); return this.line3D.distance(point3D).length(); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java index 0008738825..78b796f7cc 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java @@ -73,8 +73,8 @@ public void predict(Indicator indicator) throws Exception { } public void correct(Indicator indicator) { - System.out.println(" state before: (" + stateEstimation.getEntry(0) + ", " + stateEstimation.getEntry(1) + ", " + stateEstimation.getEntry(2) + ", " + stateEstimation.getEntry(3) + ", " + stateEstimation.getEntry(4) + ", " + stateEstimation.getEntry(5) + ");" ); - System.out.println(" state radius before: " + Math.sqrt( Math.pow(stateEstimation.getEntry(0), 2) + Math.pow(stateEstimation.getEntry(1), 2) ) ); + //System.out.println(" state before: (" + stateEstimation.getEntry(0) + ", " + stateEstimation.getEntry(1) + ", " + stateEstimation.getEntry(2) + ", " + stateEstimation.getEntry(3) + ", " + stateEstimation.getEntry(4) + ", " + stateEstimation.getEntry(5) + ");" ); + //System.out.println(" state radius before: " + Math.sqrt( Math.pow(stateEstimation.getEntry(0), 2) + Math.pow(stateEstimation.getEntry(1), 2) ) ); RealVector z; RealMatrix measurementNoise; RealMatrix measurementMatrix; @@ -96,11 +96,10 @@ public void correct(Indicator indicator) { h = h(stateEstimation, indicator); z = indicator.hit.get_Vector(); - System.out.println(" distance " + h.getEntry(0) + " hit R " + indicator.hit.getR() + " hit wire " + indicator.hit.getWire() + " hit doca " + indicator.hit.getDoca()); + //System.out.println(" distance " + h.getEntry(0) + " hit R " + indicator.hit.getR() + " hit wire " + indicator.hit.getWire() + " hit doca " + indicator.hit.getDoca()); } - /* // EPAF: trying to not modify the trajectory for tests... RealMatrix measurementMatrixT = measurementMatrix.transpose(); @@ -122,7 +121,6 @@ public void correct(Indicator indicator) { // Numerically more stable !! RealMatrix tmpMatrix = identity.subtract(kalmanGain.multiply(measurementMatrix)); errorCovariance = tmpMatrix.multiply(errorCovariance.multiply(tmpMatrix.transpose())).add(kalmanGain.multiply(measurementNoise.multiply(kalmanGain.transpose()))); - */ //System.out.println(" state after: (" + stateEstimation.getEntry(0) + ", " + stateEstimation.getEntry(1) + ", " + stateEstimation.getEntry(2) + ", " + stateEstimation.getEntry(3) + ", " + stateEstimation.getEntry(4) + ", " + stateEstimation.getEntry(5) + ");" ); // Give back to the stepper the new stateEstimation diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index ac476a43b2..6daeb38417 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -72,7 +72,7 @@ private void propagation(ArrayList tracks, DataEvent event) { // Initialization --------------------------------------------------------------------- - final double magfield = -50; + final double magfield = +50; final PDGParticle proton = PDGDatabase.getParticleById(2212); final int numberOfVariables = 6; final double tesla = 0.001; @@ -89,10 +89,10 @@ private void propagation(ArrayList tracks, DataEvent event) { final double py0 = tracks.get(0).get_py(); final double pz0 = tracks.get(0).get_pz(); final double p_init = java.lang.Math.sqrt(px0*px0+py0*py0+pz0*pz0); - //double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; + double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; //System.out.println("y = " + x0 + ", " + y0 + ", " + z0 + ", " + px0 + ", " + py0 + ", " + pz0 + "; p = " + p_init); // EPAF: *the line below is for TEST ONLY!!!* - double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; + //double[] y = new double[]{vxmc, vymc, vzmc, pxmc, pymc, pzmc}; //System.out.println("y = " + vxmc + ", " + vymc + ", " + vzmc + ", " + pxmc + ", " + pymc + ", " + pzmc + "; p = " + java.lang.Math.sqrt(pxmc*pxmc+pymc*pymc+pzmc*pzmc)); // Initialization hit From 2d513b944305a185bc8cd31a77c833ce65a3a8e5 Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Wed, 6 Nov 2024 04:40:43 -0500 Subject: [PATCH 38/51] Implementation of a new mode of extraction Creation of ModeAHDC.java --- .../org/jlab/detector/pulse/ModeAHDC.java | 243 ++++++++++++++++++ .../java/org/jlab/detector/pulse/Pulse.java | 10 +- 2 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java new file mode 100644 index 0000000000..d0df869579 --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -0,0 +1,243 @@ +package org.jlab.detector.pulse; + +import java.util.List; +import java.util.ArrayList; +import org.jlab.utils.groups.NamedEntry; + + +/** + * A new extraction method dedicated to the AHDC signal waveform + * + * Some blocks of code are inspired by MVTFitter.java + * + * @author ftouchte + */ +public class ModeAHDC extends HipoExtractor { + + // Settings parameters (they can be initialised by a CCDB) + public float samplingTime; + public int sparseSample; + public short adcOffset; + public long timeStamp; + public float fineTimeStampResolution; + public static final short ADC_LIMIT = 4095; // 2^12-1 + public float amplitudeFractionCFA; + public int binDelayCFD; + public float fractionCFD; + + // Calculation intermediaries + private int binMax; //Bin of the max ADC over the pulse + private int binOffset; //Offset due to sparse sample + private float adcMax; //Max value of ADC over the pulse (fitted) + private float timeMax; //Time of the max ADC over the pulse (fitted) + private float integral; //Sum of ADCs over the pulse (not fitted) + private long timestamp; + + private short[] samplesCorr; //Waveform after offset (pedestal) correction + private int binNumber; //Number of bins in one waveform + + private float timeRiseCFA; // moment when the signal reaches a Constant Fraction of its Amplitude uphill (fitted) + private float timeFallCFA; // moment when the signal reaches a Constant Fraction of its Amplitude downhill (fitted) + private float timeOverThresholdCFA; // is equal to (timeFallCFA - timeRiseCFA) + private float timeCFD; // time extracted using the Constant Fraction Discriminator (CFD) algorithm (fitted) + + /** + * This method extracts relevant informations from the digitized signal + * (the samples) and store them in a Pulse + * + * @param pars CCDB row + * @param id link to row in source bank + * @param samples ADC samples + */ + @Override + public List extract(NamedEntry pars, int id, short... samples){ + waveformCorrection(samples,adcOffset,samplingTime,sparseSample); + fitAverage(samplingTime); + computeTimeAtConstantFractionAmplitude(samplingTime,amplitudeFractionCFA); + computeTimeUsingConstantFractionDiscriminator(samplingTime,fractionCFD,binDelayCFD); + fineTimeStampCorrection(timeStamp,fineTimeStampResolution); + // output + Pulse pulse = new Pulse(); + pulse.adcMax = adcMax; + pulse.time = timeMax; + pulse.timestamp = timestamp; + pulse.integral = integral; + pulse.timeRiseCFA = timeRiseCFA; + pulse.timeFallCFA = timeFallCFA; + pulse.timeOverThresholdCFA = timeOverThresholdCFA; + pulse.timeCFD = timeCFD; + //pulse.binMax = binMax; + //pulse.binOffset = binOffset; + pulse.pedestal = adcOffset; + List output = new ArrayList<>(); + output.add(pulse); + return output; + } + + /** + * This method subtracts the pedestal (noise) from samples and stores it in : samplesCorr + * It also computes a first value for : adcMax, binMax, timeMax and integral + * This code is inspired by the one of MVTFitter.java + * @param samples ADC samples + * @param adcOffset pedestal or noise level + * @param samplingTime time between two adc bins + * @param sparseSample used to define binOffset + */ + private void waveformCorrection(short[] samples, short adcOffset, float samplingTime, int sparseSample){ + binNumber = samples.length; + binMax = 0; + adcMax = (short) (samples[0] - adcOffset); + integral = 0; + samplesCorr = new short[binNumber]; + for (int bin = 0; bin < binNumber; bin++){ + samplesCorr[bin] = (short) (samples[bin] - adcOffset); + if (adcMax < samplesCorr[bin]){ + adcMax = samplesCorr[bin]; + binMax = bin; + } + integral += samplesCorr[bin]; + } + /** + * If adcMax == ADC_LIMIT, that means there is saturation + * In that case, binMax is the middle of the first plateau + * This convention can be changed + */ + if ((short) adcMax == ADC_LIMIT) { + int binMax2 = binMax; + for (int bin = binMax; bin < binNumber; bin++){ + if (samplesCorr[bin] == ADC_LIMIT) { + binMax2 = bin; + } + else { + break; + } + } + binMax = (binMax + binMax2)/2; + } + binOffset = sparseSample*binMax; + timeMax = (binMax + binOffset)*samplingTime; + } + + /** + * This method gives a more precise value of the max of the waveform by computing the average of five points around the binMax + * It is an alternative to fitParabolic() + * The suitability of one of these fits can be the subject of a study + * Remark : This method updates adcMax but doesn't change timeMax + * @param samplingTime time between 2 ADC bins + */ + private void fitAverage(float samplingTime){ + if ((binMax - 2 >= 0) && (binMax + 2 <= binNumber - 1)){ + adcMax = 0; + for (int bin = binMax - 2; bin <= binMax + 2; bin++){ + adcMax += samplesCorr[bin]; + } + adcMax = adcMax/5; + } + } + + /** + * Fit the max of the pulse using parabolic fit, this method updates the timeMax and adcMax values + * @param samplingTime time between 2 ADC bins + */ + private void fitParabolic(float samplingTime) { + + } + + /** + * From MVTFitter.java + * Make fine timestamp correction (using dream (=electronic chip) clock) + * @param timeStamp timing informations (used to make fine corrections) + * @param fineTimeStampResolution precision of dream clock (usually 8) + */ + private void fineTimeStampCorrection (long timeStamp, float fineTimeStampResolution) { + this.timestamp = timeStamp; + String binaryTimeStamp = Long.toBinaryString(timeStamp); //get 64 bit timestamp in binary format + if (binaryTimeStamp.length()>=3){ + byte fineTimeStamp = Byte.parseByte(binaryTimeStamp.substring(binaryTimeStamp.length()-3,binaryTimeStamp.length()),2); //fineTimeStamp : keep and convert last 3 bits of binary timestamp + timeMax += (float) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection + // Question : I wonder if I have to do the same thing of all time quantities that the extract() methods compute. + } + } + + /** + * This method determines the moment when the signal reaches a Constant Fraction of its Amplitude (i.e fraction*adcMax) + * It fills the attributs : timeRiseCFA, timeFallCFA, timeOverThresholdCFA + * @param samplingTime time between 2 ADC bins + * @param amplitudeFraction amplitude fraction between 0 and 1 + */ + private void computeTimeAtConstantFractionAmplitude(float samplingTime, float amplitudeFractionCFA){ + float threshold = amplitudeFractionCFA*adcMax; + // timeRiseCFA + int binRise = 0; + for (int bin = 0; bin < binMax; bin++){ + if (samplesCorr[bin] < threshold) + binRise = bin; // last pass below threshold and before adcMax + } // at this stage : binRise < timeRiseCFA/samplingTime <= binRise + 1 // timeRiseCFA is determined by assuming a linear fit between binRise and binRise + 1 + float slopeRise = 0; + if (binRise + 1 <= binNumber-1) + slopeRise = samplesCorr[binRise+1] - samplesCorr[binRise]; + float fittedBinRise = (slopeRise == 0) ? binRise : binRise + (threshold - samplesCorr[binRise])/slopeRise; + timeRiseCFA = (fittedBinRise + binOffset)*samplingTime; // binOffset is determined in wavefromCorrection() // must be the same for all time ? // or must be defined using fittedBinRise*sparseSample + + // timeFallCFA + int binFall = binMax; + for (int bin = binMax; bin < binNumber; bin++){ + if (samplesCorr[bin] > threshold){ + binFall = bin; + } + else { + binFall = bin; + break; // first pass below the threshold + } + } // at this stage : binFall - 1 <= timeRiseCFA/samplingTime < binFall // timeFallCFA is determined by assuming a linear fit between binFall - 1 and binFall + float slopeFall = 0; + if (binFall - 1 >= 0) + slopeFall = samplesCorr[binFall] - samplesCorr[binFall-1]; + float fittedBinFall = (slopeFall == 0) ? binFall : binFall + (threshold - samplesCorr[binFall-1])/slopeFall; + timeFallCFA = (fittedBinFall + binOffset)*samplingTime; + + // timeOverThreshold + timeOverThresholdCFA = timeFallCFA - timeRiseCFA; + } + + /** + * This methods extracts a time using the Constant Fraction Discriminator (CFD) algorithm + * It fills the attribut : timeCFD + * @param samplingTime time between 2 ADC bins + * @param fractionCFD CFD fraction parameter between 0 and 1 + * @param binDelayCFD CFD delay parameter + */ + private void computeTimeUsingConstantFractionDiscriminator(float samplingTime, float fractionCFD, int binDelayCFD){ + float[] signal = new float[binNumber]; + // signal generation + for (int bin = 0; bin < binNumber; bin++){ + signal[bin] = (1 - fractionCFD)*samplesCorr[bin]; // we fill it with a fraction of the original signal + if (bin < binNumber - binDelayCFD) + signal[bin] += -1*fractionCFD*samplesCorr[bin + binDelayCFD]; // we advance and invert a complementary fraction of the original signal and superimpose it to the previous signal + } + // determine the two humps + int binHumpSup = 0; + int binHumpInf = 0; + for (int bin = 0; bin < binNumber; bin++){ + if (signal[bin] > signal[binHumpSup]) + binHumpSup = bin; + } + for (int bin = 0; bin < binHumpSup; bin++){ // this loop has been added to be sure : binHumpInf < binHumpSup + if (signal[bin] < signal[binHumpInf]) + binHumpInf = bin; + } + // research for zero + int binZero = 0; + for (int bin = binHumpInf; bin <= binHumpSup; bin++){ + if (signal[bin] < 0) + binZero = bin; // last pass below zero + } // at this stage : binZero < timeCFD/samplingTime <= binZero + 1 // timeCFD is determined by assuming a linear fit between binZero and binZero + 1 + float slopeCFD = 0; + if (binZero + 1 <= binNumber) + slopeCFD = signal[binZero+1] - signal[binZero]; + float fittedBinZero = (slopeCFD == 0) ? binZero : binZero + (0 - signal[binZero])/slopeCFD; + timeCFD = (fittedBinZero + binOffset)*samplingTime; + + } + +} diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java index 36592136f5..9874b3ad7f 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java @@ -15,6 +15,12 @@ public class Pulse { public long flags; public int id; + public float adcMax; + public float timeRiseCFA; + public float timeFallCFA; + public float timeOverThresholdCFA; + public float timeCFD; + /** * Units are the same as the raw units of the samples. * @param integral pulse integral, pedestal-subtracted @@ -29,10 +35,12 @@ public Pulse(float integral, float time, long flags, int id) { this.id = id; } + public Pulse(){} + @Override public String toString() { return String.format("pulse: integral=%f time=%f flags=%d id=%d", integral, time, flags, id); } -} \ No newline at end of file +} From 65395cbeade4c0b3e774d97f311af701f0a038f0 Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Fri, 8 Nov 2024 09:52:56 -0500 Subject: [PATCH 39/51] Update time calculations in ModeAHDC.java --- .../main/java/org/jlab/detector/pulse/ModeAHDC.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java index d0df869579..1301ca1248 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -97,15 +97,15 @@ private void waveformCorrection(short[] samples, short adcOffset, float sampling } integral += samplesCorr[bin]; } - /** - * If adcMax == ADC_LIMIT, that means there is saturation + /* + * If adcMax + adcOffset == ADC_LIMIT, that means there is saturation * In that case, binMax is the middle of the first plateau * This convention can be changed */ - if ((short) adcMax == ADC_LIMIT) { + if ((short) adcMax + adcOffset == ADC_LIMIT) { int binMax2 = binMax; for (int bin = binMax; bin < binNumber; bin++){ - if (samplesCorr[bin] == ADC_LIMIT) { + if (samplesCorr[bin] + adcOffset == ADC_LIMIT) { binMax2 = bin; } else { @@ -193,7 +193,7 @@ private void computeTimeAtConstantFractionAmplitude(float samplingTime, float am float slopeFall = 0; if (binFall - 1 >= 0) slopeFall = samplesCorr[binFall] - samplesCorr[binFall-1]; - float fittedBinFall = (slopeFall == 0) ? binFall : binFall + (threshold - samplesCorr[binFall-1])/slopeFall; + float fittedBinFall = (slopeFall == 0) ? binFall : binFall-1 + (threshold - samplesCorr[binFall-1])/slopeFall; timeFallCFA = (fittedBinFall + binOffset)*samplingTime; // timeOverThreshold From 5f6d07c8eb17a09a4af7c0412bcabd27c77394a0 Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Mon, 18 Nov 2024 06:28:29 -0500 Subject: [PATCH 40/51] Reduce indentation --- .../org/jlab/detector/pulse/ModeAHDC.java | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java index 1301ca1248..f473866513 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -126,13 +126,13 @@ private void waveformCorrection(short[] samples, short adcOffset, float sampling * @param samplingTime time between 2 ADC bins */ private void fitAverage(float samplingTime){ - if ((binMax - 2 >= 0) && (binMax + 2 <= binNumber - 1)){ - adcMax = 0; - for (int bin = binMax - 2; bin <= binMax + 2; bin++){ - adcMax += samplesCorr[bin]; - } - adcMax = adcMax/5; + if ((binMax - 2 >= 0) && (binMax + 2 <= binNumber - 1)){ + adcMax = 0; + for (int bin = binMax - 2; bin <= binMax + 2; bin++){ + adcMax += samplesCorr[bin]; } + adcMax = adcMax/5; + } } /** @@ -150,13 +150,13 @@ private void fitParabolic(float samplingTime) { * @param fineTimeStampResolution precision of dream clock (usually 8) */ private void fineTimeStampCorrection (long timeStamp, float fineTimeStampResolution) { - this.timestamp = timeStamp; - String binaryTimeStamp = Long.toBinaryString(timeStamp); //get 64 bit timestamp in binary format - if (binaryTimeStamp.length()>=3){ - byte fineTimeStamp = Byte.parseByte(binaryTimeStamp.substring(binaryTimeStamp.length()-3,binaryTimeStamp.length()),2); //fineTimeStamp : keep and convert last 3 bits of binary timestamp - timeMax += (float) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection - // Question : I wonder if I have to do the same thing of all time quantities that the extract() methods compute. - } + this.timestamp = timeStamp; + String binaryTimeStamp = Long.toBinaryString(timeStamp); //get 64 bit timestamp in binary format + if (binaryTimeStamp.length()>=3){ + byte fineTimeStamp = Byte.parseByte(binaryTimeStamp.substring(binaryTimeStamp.length()-3,binaryTimeStamp.length()),2); //fineTimeStamp : keep and convert last 3 bits of binary timestamp + timeMax += (float) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection + // Question : I wonder if I have to do the same thing of all time quantities that the extract() methods compute. + } } /** @@ -166,38 +166,38 @@ private void fineTimeStampCorrection (long timeStamp, float fineTimeStampResolut * @param amplitudeFraction amplitude fraction between 0 and 1 */ private void computeTimeAtConstantFractionAmplitude(float samplingTime, float amplitudeFractionCFA){ - float threshold = amplitudeFractionCFA*adcMax; - // timeRiseCFA - int binRise = 0; - for (int bin = 0; bin < binMax; bin++){ - if (samplesCorr[bin] < threshold) - binRise = bin; // last pass below threshold and before adcMax - } // at this stage : binRise < timeRiseCFA/samplingTime <= binRise + 1 // timeRiseCFA is determined by assuming a linear fit between binRise and binRise + 1 - float slopeRise = 0; - if (binRise + 1 <= binNumber-1) - slopeRise = samplesCorr[binRise+1] - samplesCorr[binRise]; - float fittedBinRise = (slopeRise == 0) ? binRise : binRise + (threshold - samplesCorr[binRise])/slopeRise; - timeRiseCFA = (fittedBinRise + binOffset)*samplingTime; // binOffset is determined in wavefromCorrection() // must be the same for all time ? // or must be defined using fittedBinRise*sparseSample - - // timeFallCFA - int binFall = binMax; - for (int bin = binMax; bin < binNumber; bin++){ - if (samplesCorr[bin] > threshold){ - binFall = bin; - } - else { - binFall = bin; - break; // first pass below the threshold - } - } // at this stage : binFall - 1 <= timeRiseCFA/samplingTime < binFall // timeFallCFA is determined by assuming a linear fit between binFall - 1 and binFall - float slopeFall = 0; - if (binFall - 1 >= 0) - slopeFall = samplesCorr[binFall] - samplesCorr[binFall-1]; - float fittedBinFall = (slopeFall == 0) ? binFall : binFall-1 + (threshold - samplesCorr[binFall-1])/slopeFall; - timeFallCFA = (fittedBinFall + binOffset)*samplingTime; - - // timeOverThreshold - timeOverThresholdCFA = timeFallCFA - timeRiseCFA; + float threshold = amplitudeFractionCFA*adcMax; + // timeRiseCFA + int binRise = 0; + for (int bin = 0; bin < binMax; bin++){ + if (samplesCorr[bin] < threshold) + binRise = bin; // last pass below threshold and before adcMax + } // at this stage : binRise < timeRiseCFA/samplingTime <= binRise + 1 // timeRiseCFA is determined by assuming a linear fit between binRise and binRise + 1 + float slopeRise = 0; + if (binRise + 1 <= binNumber-1) + slopeRise = samplesCorr[binRise+1] - samplesCorr[binRise]; + float fittedBinRise = (slopeRise == 0) ? binRise : binRise + (threshold - samplesCorr[binRise])/slopeRise; + timeRiseCFA = (fittedBinRise + binOffset)*samplingTime; // binOffset is determined in wavefromCorrection() // must be the same for all time ? // or must be defined using fittedBinRise*sparseSample + + // timeFallCFA + int binFall = binMax; + for (int bin = binMax; bin < binNumber; bin++){ + if (samplesCorr[bin] > threshold){ + binFall = bin; + } + else { + binFall = bin; + break; // first pass below the threshold + } + } // at this stage : binFall - 1 <= timeRiseCFA/samplingTime < binFall // timeFallCFA is determined by assuming a linear fit between binFall - 1 and binFall + float slopeFall = 0; + if (binFall - 1 >= 0) + slopeFall = samplesCorr[binFall] - samplesCorr[binFall-1]; + float fittedBinFall = (slopeFall == 0) ? binFall : binFall-1 + (threshold - samplesCorr[binFall-1])/slopeFall; + timeFallCFA = (fittedBinFall + binOffset)*samplingTime; + + // timeOverThreshold + timeOverThresholdCFA = timeFallCFA - timeRiseCFA; } /** @@ -208,35 +208,35 @@ private void computeTimeAtConstantFractionAmplitude(float samplingTime, float am * @param binDelayCFD CFD delay parameter */ private void computeTimeUsingConstantFractionDiscriminator(float samplingTime, float fractionCFD, int binDelayCFD){ - float[] signal = new float[binNumber]; - // signal generation - for (int bin = 0; bin < binNumber; bin++){ - signal[bin] = (1 - fractionCFD)*samplesCorr[bin]; // we fill it with a fraction of the original signal - if (bin < binNumber - binDelayCFD) - signal[bin] += -1*fractionCFD*samplesCorr[bin + binDelayCFD]; // we advance and invert a complementary fraction of the original signal and superimpose it to the previous signal - } - // determine the two humps - int binHumpSup = 0; - int binHumpInf = 0; - for (int bin = 0; bin < binNumber; bin++){ - if (signal[bin] > signal[binHumpSup]) - binHumpSup = bin; - } - for (int bin = 0; bin < binHumpSup; bin++){ // this loop has been added to be sure : binHumpInf < binHumpSup - if (signal[bin] < signal[binHumpInf]) - binHumpInf = bin; - } - // research for zero - int binZero = 0; - for (int bin = binHumpInf; bin <= binHumpSup; bin++){ - if (signal[bin] < 0) - binZero = bin; // last pass below zero - } // at this stage : binZero < timeCFD/samplingTime <= binZero + 1 // timeCFD is determined by assuming a linear fit between binZero and binZero + 1 - float slopeCFD = 0; - if (binZero + 1 <= binNumber) - slopeCFD = signal[binZero+1] - signal[binZero]; - float fittedBinZero = (slopeCFD == 0) ? binZero : binZero + (0 - signal[binZero])/slopeCFD; - timeCFD = (fittedBinZero + binOffset)*samplingTime; + float[] signal = new float[binNumber]; + // signal generation + for (int bin = 0; bin < binNumber; bin++){ + signal[bin] = (1 - fractionCFD)*samplesCorr[bin]; // we fill it with a fraction of the original signal + if (bin < binNumber - binDelayCFD) + signal[bin] += -1*fractionCFD*samplesCorr[bin + binDelayCFD]; // we advance and invert a complementary fraction of the original signal and superimpose it to the previous signal + } + // determine the two humps + int binHumpSup = 0; + int binHumpInf = 0; + for (int bin = 0; bin < binNumber; bin++){ + if (signal[bin] > signal[binHumpSup]) + binHumpSup = bin; + } + for (int bin = 0; bin < binHumpSup; bin++){ // this loop has been added to be sure : binHumpInf < binHumpSup + if (signal[bin] < signal[binHumpInf]) + binHumpInf = bin; + } + // research for zero + int binZero = 0; + for (int bin = binHumpInf; bin <= binHumpSup; bin++){ + if (signal[bin] < 0) + binZero = bin; // last pass below zero + } // at this stage : binZero < timeCFD/samplingTime <= binZero + 1 // timeCFD is determined by assuming a linear fit between binZero and binZero + 1 + float slopeCFD = 0; + if (binZero + 1 <= binNumber) + slopeCFD = signal[binZero+1] - signal[binZero]; + float fittedBinZero = (slopeCFD == 0) ? binZero : binZero + (0 - signal[binZero])/slopeCFD; + timeCFD = (fittedBinZero + binOffset)*samplingTime; } From 4dd148fc3b0e546adc0707d831f57a06f36f5b05 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 2 Dec 2024 09:52:57 -0500 Subject: [PATCH 41/51] * Fixed the magnetic field direction and the calculation of the wire end points; * Adjusted the initial covariance matrix parameters; * Added methods n KFitter and Hit to set better measurement and noise matrices for hits; *** For debugging purposes only: *** * Added a method to reconstruct that tracks gathering all hits, and sets the track parameters as follows: px = 150.0*sin(atan2(y_w0, x_w0)), py = 150.0*cos(atan2(y_w0, x_w0)) set with x_w0, y_w0 origin of first wire hit; x, y, z = 0, pz = 0; => only good for MC with no background; * commented out the track finding method and using the method described above. --- .../main/java/org/jlab/rec/ahdc/Hit/Hit.java | 2 +- .../org/jlab/rec/ahdc/KalmanFilter/Hit.java | 28 +++++- .../jlab/rec/ahdc/KalmanFilter/KFitter.java | 89 ++++++++++++++----- .../rec/ahdc/KalmanFilter/KalmanFilter.java | 17 ++-- .../java/org/jlab/rec/ahdc/Track/Track.java | 15 ++++ .../java/org/jlab/rec/service/AHDCEngine.java | 65 +++++++------- 6 files changed, 154 insertions(+), 62 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java index df9da417cf..511bc5807e 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java @@ -61,7 +61,7 @@ private void wirePosition() { //should it be at z = 0? in which case, we need to account for the positive or negative stereo angle... double wx = -R_layer * Math.sin(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1))); double wy = -R_layer * Math.cos(alphaW_layer * (this.wireId-1) + 0.5*thster * (Math.pow(-1, this.superLayerId-1))); - + //System.out.println(" superlayer " + this.superLayerId + " layer " + this.layerId + " wire " + this.wireId + " R_layer " + R_layer + " wx " + wx + " wy " + wy); this.nbOfWires = (int) numWires; diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index d0a8c9023b..773011b0e2 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -17,6 +17,7 @@ public class Hit implements Comparable { private final int wire; private final double r; private final double doca; + private final double adc; private final double numWires; private final Line3D line3D; @@ -30,7 +31,8 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do this.r = r; this.doca = doca; this.numWires = numWire; - + this.adc = 0;//placeholder + final double DR_layer = 4.0;//OK final double round = 360.0;//OK final double thster = Math.toRadians(20.0);//OK @@ -102,12 +104,28 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do this.line3D = wireLine; } + public RealVector get_Vector_simple() { + return new ArrayRealVector(new double[]{this.doca}); + } + public RealVector get_Vector() { return new ArrayRealVector(new double[]{this.doca}); } - public RealMatrix get_MeasurementNoise() { - return new Array2DRowRealMatrix(new double[][]{{10.0}});//in cm... 10 cm is probably too much. + public RealMatrix get_MeasurementNoise_simple() { + return new Array2DRowRealMatrix(new double[][]{{0.01}}); + } + + public RealMatrix get_MeasurementNoise() { + final double costhster = Math.cos(thster); + final double sinthster = Math.cos(thster); + //dR = 0.1m dphi = pi dz = L/2 + Array2DRowRealMatrix wire_noise = new Array2DRowRealMatrix(new double[][]{{0.1, 0.0, 0.0}, {0.0, Math.atan(0.1/this.r), 0.0}, {0.0, 0.0, 150.0}});//uncertainty matrix in wire coordinates + Array2DRowRealMatrix stereo_rotation = new Array2DRowRealMatrix(new double[][]{{1, 0.0, 0.0}, {0, costhster, -sinthster}, {0, sinthster, costhster}});//rotation of wire + wire_noise.multiply(stereo_rotation); + + return wire_noise.multiply(wire_noise); + // } public double doca() { @@ -165,6 +183,10 @@ public double getDoca() { return doca; } + public double getADC() { + return adc; + } + public Line3D getLine3D() { return line3D; } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java index 78b796f7cc..ca821cb675 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java @@ -58,7 +58,7 @@ public void predict(Indicator indicator) throws Exception { double dE = Math.abs(stepper.dEdx); double K = 0.000307075; - double sigma2_dE = indicator.material.getDensity() * K * indicator.material.getZoverA() / beta2 * tmax * s / 10 * (1.0 - beta2 / 2) * 1000 * 1000; + double sigma2_dE = indicator.material.getDensity() * K * indicator.material.getZoverA() / beta2 * tmax * s / 10 * (1.0 - beta2 / 2) * 1000 * 1000;//in MeV^2 double dp_prim_ddE = (E + dE) / Math.sqrt((E + dE) * (E + dE) - mass * mass); double sigma2_px = Math.pow(px / p, 2) * Math.pow(dp_prim_ddE, 2) * sigma2_dE; double sigma2_py = Math.pow(py / p, 2) * Math.pow(dp_prim_ddE, 2) * sigma2_dE; @@ -83,29 +83,30 @@ public void correct(Indicator indicator) { measurementNoise = new Array2DRowRealMatrix( new double[][]{ - {9.00, 0.0000, 0.0000}, - {0.00, 1e10, 0.0000}, - {0.00, 0.0000, 1e10} - }); - measurementMatrix = H_beam(stateEstimation); - h = h_beam(stateEstimation); - z = indicator.hit.get_Vector_beam(); + // {9.00, 0.0000, 0.0000}, + // {0.00, 1e10, 0.0000}, + // {0.00, 0.0000, 1e10} + {0.09, 0.0000, 0.0000}, + {0.00, 1.e10, 0.0000}, + {0.00, 0.0000, 1.e10} + });//3x3 + measurementMatrix = H_beam(stateEstimation);//6x3 + h = h_beam(stateEstimation);//3x1 + z = indicator.hit.get_Vector_beam();//0! } else { - measurementNoise = indicator.hit.get_MeasurementNoise(); - measurementMatrix = H(stateEstimation, indicator); - h = h(stateEstimation, indicator); - z = indicator.hit.get_Vector(); + measurementNoise = indicator.hit.get_MeasurementNoise_simple();//1x1 + measurementMatrix = H_simple(stateEstimation, indicator);//6x1 + h = h(stateEstimation, indicator);//1x1 + z = indicator.hit.get_Vector();//1x1 //System.out.println(" distance " + h.getEntry(0) + " hit R " + indicator.hit.getR() + " hit wire " + indicator.hit.getWire() + " hit doca " + indicator.hit.getDoca()); } - - // EPAF: trying to not modify the trajectory for tests... RealMatrix measurementMatrixT = measurementMatrix.transpose(); // S = H * P(k) * H' + R RealMatrix S = measurementMatrix.multiply(errorCovariance).multiply(measurementMatrixT).add(measurementNoise); - + // Inn = z(k) - h(xHat(k)-) RealVector innovation = z.subtract(h); @@ -167,11 +168,58 @@ private RealMatrix F(Indicator indicator, Stepper stepper1) throws Exception { private RealVector h(RealVector x, Indicator indicator) { double d = indicator.hit.distance(new Point3D(x.getEntry(0), x.getEntry(1), x.getEntry(2))); + //As per my understanding: d -> r distance from wire; phi, z unknown + return MatrixUtils.createRealVector(new double[]{d});//would need to have this 3x3 + } + + private RealMatrix H(RealVector x, Indicator indicator) { + + // As per my understanding: ddocadx,y,z -> = dr/dx,y,z, etc + // dphi/dx + double xx = x.getEntry(0);//(indicator.hit.getline3D().origin().x()+indicator.hit.getline3D().end().x())*0.5; + double yy = x.getEntry(1);//(indicator.hit.getline3D().origin().y()+indicator.hit.getline3D().end().y())*0.5; + + double drdx = (xx) / (Math.hypot(xx, yy)); + double drdy = (yy) / (Math.hypot(xx, yy)); + double drdz = 0.0; + double drdpx = 0.0; + double drdpy = 0.0; + double drdpz = 0.0; + + double dphidx = -(yy) / (xx * xx + yy * yy); + double dphidy = (xx) / (xx * xx + yy * yy); + double dphidz = 0.0; + double dphidpx = 0.0; + double dphidpy = 0.0; + double dphidpz = 0.0; - return MatrixUtils.createRealVector(new double[]{d}); + double dzdx = 0.0; + double dzdy = 0.0; + double dzdz = 1.0; + double dzdpx = 0.0; + double dzdpy = 0.0; + double dzdpz = 0.0; + + return MatrixUtils.createRealMatrix( + new double[][]{ + {drdx, drdy, drdz, drdpx, drdpy, drdpz}, + {dphidx, dphidy, dphidz, dphidpx, dphidpy, dphidpz}, + {dzdx, dzdy, dzdz, dzdpx, dzdpy, dzdpz} + }); + // double ddocadx = subfunctionH(x, indicator, 0); + // double ddocady = subfunctionH(x, indicator, 1); + // double ddocadz = subfunctionH(x, indicator, 2); + // double ddocadpx = subfunctionH(x, indicator, 3); + // double ddocadpy = subfunctionH(x, indicator, 4); + // double ddocadpz = subfunctionH(x, indicator, 5); + + // return MatrixUtils.createRealMatrix(new double[][]{ + // {ddocadx, ddocady, ddocadz, ddocadpx, ddocadpy, ddocadpz}, + // {0, 0, 0, 0, 0, 0, 0}, + // {0, 0, 0, 0, 0, 0, 0}}); } - private RealMatrix H(RealVector x, Indicator indicator) { + private RealMatrix H_simple(RealVector x, Indicator indicator) { double ddocadx = subfunctionH(x, indicator, 0); double ddocady = subfunctionH(x, indicator, 1); @@ -179,10 +227,11 @@ private RealMatrix H(RealVector x, Indicator indicator) { double ddocadpx = subfunctionH(x, indicator, 3); double ddocadpy = subfunctionH(x, indicator, 4); double ddocadpz = subfunctionH(x, indicator, 5); - - + + // As per my understanding: ddocadx,y,z -> = dr/dx,y,z, etc + // dphi/dx return MatrixUtils.createRealMatrix(new double[][]{ - {ddocadx, ddocady, ddocadz, ddocadpx, ddocadpy, ddocadpz}}); + {ddocadx, ddocady, ddocadz, ddocadpx, ddocadpy, ddocadpz}}); } double subfunctionH(RealVector x, Indicator indicator, int i) { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index 6daeb38417..e6834a6105 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -85,8 +85,10 @@ private void propagation(ArrayList tracks, DataEvent event) { final double x0 = 0.0; final double y0 = 0.0; final double z0 = tracks.get(0).get_Z0(); - final double px0 = tracks.get(0).get_px(); - final double py0 = tracks.get(0).get_py(); + //final + double px0 = tracks.get(0).get_px(); + //final + double py0 = tracks.get(0).get_py(); final double pz0 = tracks.get(0).get_pz(); final double p_init = java.lang.Math.sqrt(px0*px0+py0*py0+pz0*pz0); double[] y = new double[]{x0, y0, z0, px0, py0, pz0}; @@ -96,7 +98,7 @@ private void propagation(ArrayList tracks, DataEvent event) { //System.out.println("y = " + vxmc + ", " + vymc + ", " + vzmc + ", " + pxmc + ", " + pymc + ", " + pzmc + "; p = " + java.lang.Math.sqrt(pxmc*pxmc+pymc*pymc+pzmc*pzmc)); // Initialization hit - // System.out.println("tracks = " + tracks); + //System.out.println("tracks = " + tracks); ArrayList AHDC_hits = tracks.get(0).getHits(); ArrayList KF_hits = new ArrayList<>(); for (org.jlab.rec.ahdc.Hit.Hit AHDC_hit : AHDC_hits) { @@ -113,7 +115,8 @@ private void propagation(ArrayList tracks, DataEvent event) { // if (!aleardyHaveR) KF_hits.add(hit); } - + + /* Writer hitsWiresWriter = new FileWriter("hits_wires.dat"); for (Hit h : KF_hits) { @@ -137,8 +140,8 @@ private void propagation(ArrayList tracks, DataEvent event) { // Initialization of the Kalman Fitter RealVector initialStateEstimate = new ArrayRealVector(stepper.y); //first 3 lines in cm^2; last 3 lines in MeV^2 - RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{100.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 100.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 100.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1000.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1000.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 1000.0}}); - + RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{1.00, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 1.00, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 25.0, 0.0, 0.0, 25.0}, {0.0, 0.0, 0.0, 1.00, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1.00, 0.0}, {0.0, 0.0, 25.0, 0.0, 0.0, 25.0}}); + KFitter kFitter = new KFitter(initialStateEstimate, initialErrorCovariance, stepper, propagator); /* @@ -163,7 +166,7 @@ private void propagation(ArrayList tracks, DataEvent event) { */ - for (int k = 0; k < 1; k++) { + for (int k = 0; k < 10; k++) { //System.out.println("--------- ForWard propagation !! ---------"); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Track/Track.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Track/Track.java index aa11e12d42..10d2351ab6 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Track/Track.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Track/Track.java @@ -40,6 +40,21 @@ public Track(List clusters) { generateHitList(); } + public Track(ArrayList hitslist) { + hits.addAll(hitslist); + this.x0 = 0.0; + this.y0 = 0.0; + this.z0 = 0.0; + double p = 150.0;//MeV/c + //take first hit. + Hit hit = hitslist.get(0); + double phi = Math.atan2(hit.getX(), hit.getY()); + //hitslist. + this.px0 = p*Math.sin(phi); + this.py0 = p*Math.cos(phi); + this.pz0 = 0.0; + } + public void setPositionAndMomentum(HelixFitObject helixFitObject) { this.x0 = helixFitObject.get_X0(); this.y0 = helixFitObject.get_Y0(); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index a15ff89e0a..c63ef35705 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -91,37 +91,40 @@ public boolean processDataEvent(DataEvent event) { // IV) Track Finder ArrayList AHDC_Tracks = new ArrayList<>(); - if (findingMethod.equals("distance")) { - // IV) a) Distance method - //System.out.println("using distance"); - Distance distance = new Distance(); - distance.find_track(AHDC_Clusters); - AHDC_Tracks = distance.get_AHDCTracks(); - } else if (findingMethod.equals("hough")) { - // IV) b) Hough Transform method - //System.out.println("using hough"); - HoughTransform houghtransform = new HoughTransform(); - houghtransform.find_tracks(AHDC_Clusters); - AHDC_Tracks = houghtransform.get_AHDCTracks(); - } - - // V) Global fit - for (Track track : AHDC_Tracks) { - int nbOfPoints = track.get_Clusters().size(); - - double[][] szPos = new double[nbOfPoints][3]; - - int j = 0; - for (Cluster cluster : track.get_Clusters()) { - szPos[j][0] = cluster.get_X(); - szPos[j][1] = cluster.get_Y(); - szPos[j][2] = cluster.get_Z(); - j++; - } - - HelixFitJava h = new HelixFitJava(); - track.setPositionAndMomentum(h.HelixFit(nbOfPoints, szPos, 1)); - } + // if (findingMethod.equals("distance")) { + // // IV) a) Distance method + // //System.out.println("using distance"); + // Distance distance = new Distance(); + // distance.find_track(AHDC_Clusters); + // AHDC_Tracks = distance.get_AHDCTracks(); + // } else if (findingMethod.equals("hough")) { + // // IV) b) Hough Transform method + // //System.out.println("using hough"); + // HoughTransform houghtransform = new HoughTransform(); + // houghtransform.find_tracks(AHDC_Clusters); + // AHDC_Tracks = houghtransform.get_AHDCTracks(); + // } + + //Temporary track method ONLY for MC with no background; + AHDC_Tracks.add(new Track(AHDC_Hits)); + + // // V) Global fit + // for (Track track : AHDC_Tracks) { + // int nbOfPoints = track.get_Clusters().size(); + + // double[][] szPos = new double[nbOfPoints][3]; + + // int j = 0; + // for (Cluster cluster : track.get_Clusters()) { + // szPos[j][0] = cluster.get_X(); + // szPos[j][1] = cluster.get_Y(); + // szPos[j][2] = cluster.get_Z(); + // j++; + // } + + // HelixFitJava h = new HelixFitJava(); + // track.setPositionAndMomentum(h.HelixFit(nbOfPoints, szPos, 1)); + // } // VI) Kalman Filter // System.out.println("AHDC_Tracks = " + AHDC_Tracks); From 4143a259727f92539c5f1e242ca5cb074fc30074 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Tue, 3 Dec 2024 13:54:30 -0500 Subject: [PATCH 42/51] Added additional functions called "getMeasurementNoise_simple", "getVector_simple" for Hit, and "H_simple", "h_simple" for KFitter to return the preexisting matrix emasurements; new matrix measurements have been implemented in the methods "getMeasurementNoise", "getVector", "H" and "h". Added new memebers "adc" and "phi" for the hit for measured ADC and wire phi position at z = 0 respectively. --- .../org/jlab/rec/ahdc/KalmanFilter/Hit.java | 28 +++++++++++-------- .../jlab/rec/ahdc/KalmanFilter/KFitter.java | 26 ++++++++++++----- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index 773011b0e2..3394bd71ae 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -16,6 +16,7 @@ public class Hit implements Comparable { private final int layer; private final int wire; private final double r; + private final double phi; private final double doca; private final double adc; private final double numWires; @@ -88,7 +89,8 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK //System.out.println(" superlayer " + this.superLayer + " layer " + this.layer + " wire " + this.wire + " wx " + wx + " wy " + wy + " wx_end " + wx_end + " wy_end " + wy_end); - + this.phi = Math.atan2( (wy+wy_end)*0.5, (wx+wx_end)*0.5 ); + Line3D line = new Line3D(wx, wy, -zl/2, wx_end, wy_end, zl/2); Point3D lPoint = new Point3D(); Point3D rPoint = new Point3D(); @@ -103,37 +105,41 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do //wireLine.show(); this.line3D = wireLine; } - - public RealVector get_Vector_simple() { - return new ArrayRealVector(new double[]{this.doca}); - } - + public RealVector get_Vector() { - return new ArrayRealVector(new double[]{this.doca}); + RealVector wire_meas = new ArrayRealVector(new double[]{this.r(), this.phi(), 0}); + //Array2DRowRealMatrix stereo_rotation = new Array2DRowRealMatrix(new double[][]{{1, 0.0, 0.0}, {0, costhster, -sinthster}, {0, sinthster, costhster}});//rotation of wire: needed? + return wire_meas;//.multiply(stereo_rotation); } - public RealMatrix get_MeasurementNoise_simple() { - return new Array2DRowRealMatrix(new double[][]{{0.01}}); + public RealVector get_Vector_simple() { + return new ArrayRealVector(new double[]{this.doca}); } public RealMatrix get_MeasurementNoise() { final double costhster = Math.cos(thster); final double sinthster = Math.cos(thster); //dR = 0.1m dphi = pi dz = L/2 - Array2DRowRealMatrix wire_noise = new Array2DRowRealMatrix(new double[][]{{0.1, 0.0, 0.0}, {0.0, Math.atan(0.1/this.r), 0.0}, {0.0, 0.0, 150.0}});//uncertainty matrix in wire coordinates + Array2DRowRealMatrix wire_noise = new Array2DRowRealMatrix(new double[][]{{0.1, 0.0, 0.0}, {0.0, Math.atan(0.1/this.r), 0.0}, {0.0, 0.0, 150.0/costhster}});//uncertainty matrix in wire coordinates Array2DRowRealMatrix stereo_rotation = new Array2DRowRealMatrix(new double[][]{{1, 0.0, 0.0}, {0, costhster, -sinthster}, {0, sinthster, costhster}});//rotation of wire wire_noise.multiply(stereo_rotation); return wire_noise.multiply(wire_noise); - // + // } + public RealMatrix get_MeasurementNoise_simple() { + return new Array2DRowRealMatrix(new double[][]{{0.01}}); + } + public double doca() { return doca; } public double r() {return r;} + public double phi() {return phi;} + public Line3D line() {return line3D;} public double distance(Point3D point3D) { diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java index ca821cb675..83001e35f4 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java @@ -95,9 +95,14 @@ public void correct(Indicator indicator) { z = indicator.hit.get_Vector_beam();//0! } else { measurementNoise = indicator.hit.get_MeasurementNoise_simple();//1x1 - measurementMatrix = H_simple(stateEstimation, indicator);//6x1 - h = h(stateEstimation, indicator);//1x1 - z = indicator.hit.get_Vector();//1x1 + measurementMatrix = H_simple(stateEstimation, indicator);//6x1 + h = h_simple(stateEstimation, indicator);//1x1 + z = indicator.hit.get_Vector_simple();//1x1 + + // measurementNoise = indicator.hit.get_MeasurementNoise();//3x3 + // measurementMatrix = H(stateEstimation, indicator);//6x3 + // h = h(stateEstimation, indicator);//3x1 + // z = indicator.hit.get_Vector();//3x1 //System.out.println(" distance " + h.getEntry(0) + " hit R " + indicator.hit.getR() + " hit wire " + indicator.hit.getWire() + " hit doca " + indicator.hit.getDoca()); @@ -106,7 +111,7 @@ public void correct(Indicator indicator) { // S = H * P(k) * H' + R RealMatrix S = measurementMatrix.multiply(errorCovariance).multiply(measurementMatrixT).add(measurementNoise); - + // Inn = z(k) - h(xHat(k)-) RealVector innovation = z.subtract(h); @@ -166,6 +171,14 @@ private RealMatrix F(Indicator indicator, Stepper stepper1) throws Exception { } private RealVector h(RealVector x, Indicator indicator) { + //double d = indicator.hit.distance(new Point3D(x.getEntry(0), x.getEntry(1), x.getEntry(2))); + //As per my understanding: d -> r distance from wire; phi, z unknown + double xx = x.getEntry(0);//(indicator.hit.getline3D().origin().x()+indicator.hit.getline3D().end().x())*0.5; + double yy = x.getEntry(1);//(indicator.hit.getline3D().origin().y()+indicator.hit.getline3D().end().y())*0.5; + return MatrixUtils.createRealVector(new double[]{Math.hypot(xx, yy), Math.atan2(yy, xx), x.getEntry(2)}); + } + + private RealVector h_simple(RealVector x, Indicator indicator) { double d = indicator.hit.distance(new Point3D(x.getEntry(0), x.getEntry(1), x.getEntry(2))); //As per my understanding: d -> r distance from wire; phi, z unknown @@ -176,8 +189,8 @@ private RealMatrix H(RealVector x, Indicator indicator) { // As per my understanding: ddocadx,y,z -> = dr/dx,y,z, etc // dphi/dx - double xx = x.getEntry(0);//(indicator.hit.getline3D().origin().x()+indicator.hit.getline3D().end().x())*0.5; - double yy = x.getEntry(1);//(indicator.hit.getline3D().origin().y()+indicator.hit.getline3D().end().y())*0.5; + double xx = x.getEntry(0);//(indicator.hit.getline3D().origin().x()+indicator.hit.getline3D().end().x())*0.5; + double yy = x.getEntry(1);//(indicator.hit.getline3D().origin().y()+indicator.hit.getline3D().end().y())*0.5; double drdx = (xx) / (Math.hypot(xx, yy)); double drdy = (yy) / (Math.hypot(xx, yy)); @@ -229,7 +242,6 @@ private RealMatrix H_simple(RealVector x, Indicator indicator) { double ddocadpz = subfunctionH(x, indicator, 5); // As per my understanding: ddocadx,y,z -> = dr/dx,y,z, etc - // dphi/dx return MatrixUtils.createRealMatrix(new double[][]{ {ddocadx, ddocady, ddocadz, ddocadpx, ddocadpy, ddocadpz}}); } From 5dd9fe4ac121d29df32633c06aefcbeace3e7fb6 Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 9 Dec 2024 10:34:56 -0500 Subject: [PATCH 43/51] Duplicated the measurement matrices functions: one in cylindrical system, one to minimize track distance. Added functions to calculate phi for hit as a function of z and to calculate the hit "sign" i.e. the side of the wire the track passes. --- .../org/jlab/rec/ahdc/KalmanFilter/Hit.java | 30 +++++++-- .../jlab/rec/ahdc/KalmanFilter/KFitter.java | 63 ++++++++++--------- .../rec/ahdc/KalmanFilter/KalmanFilter.java | 19 +++++- 3 files changed, 76 insertions(+), 36 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java index 3394bd71ae..fa4d1dc477 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/Hit.java @@ -12,6 +12,7 @@ public class Hit implements Comparable { private final double thster = Math.toRadians(20.0); + private final double zl = 300.0;//OK private final int superLayer; private final int layer; private final int wire; @@ -37,7 +38,6 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do final double DR_layer = 4.0;//OK final double round = 360.0;//OK final double thster = Math.toRadians(20.0);//OK - final double zl = 300.0;//OK double numWires = 32.0; double R_layer = 47.0; @@ -88,9 +88,9 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do double wx_end = -R_layer * Math.sin(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK double wy_end = -R_layer * Math.cos(alphaW_layer * (this.wire-1) + thster * (Math.pow(-1, this.superLayer-1)));//OK - //System.out.println(" superlayer " + this.superLayer + " layer " + this.layer + " wire " + this.wire + " wx " + wx + " wy " + wy + " wx_end " + wx_end + " wy_end " + wy_end); this.phi = Math.atan2( (wy+wy_end)*0.5, (wx+wx_end)*0.5 ); - + //System.out.println(" superlayer " + this.superLayer + " layer " + this.layer + " wire " + this.wire + " wx " + wx + " wy " + wy + " wx_end " + wx_end + " wy_end " + wy_end + " phi " + this.phi); + Line3D line = new Line3D(wx, wy, -zl/2, wx_end, wy_end, zl/2); Point3D lPoint = new Point3D(); Point3D rPoint = new Point3D(); @@ -106,16 +106,26 @@ public Hit(int superLayer, int layer, int wire, int numWire, double r, double do this.line3D = wireLine; } - public RealVector get_Vector() { + //hit measurement vector in cylindrical coordinates: r, phi, z + public RealVector get_Vector() { + // final double costhster = Math.cos(thster); + // final double sinthster = Math.cos(thster); RealVector wire_meas = new ArrayRealVector(new double[]{this.r(), this.phi(), 0}); - //Array2DRowRealMatrix stereo_rotation = new Array2DRowRealMatrix(new double[][]{{1, 0.0, 0.0}, {0, costhster, -sinthster}, {0, sinthster, costhster}});//rotation of wire: needed? + // Array2DRowRealMatrix stereo_rotation = new Array2DRowRealMatrix(new double[][]{{1, 0.0, 0.0}, {0, costhster, -sinthster}, {0, sinthster, costhster}});//rotation of wire: needed? return wire_meas;//.multiply(stereo_rotation); } + //hit measurement vector in 1 dimension: minimize distance - doca public RealVector get_Vector_simple() { return new ArrayRealVector(new double[]{this.doca}); } + //hit measurement vector in 1 dimension: minimize distance - doca - adds hit "sign" + public RealVector get_Vector_sign(int sign) { + // Attempt: multiply doca by sign + return new ArrayRealVector(new double[]{sign*this.doca}); + } + public RealMatrix get_MeasurementNoise() { final double costhster = Math.cos(thster); final double sinthster = Math.cos(thster); @@ -138,7 +148,15 @@ public double doca() { public double r() {return r;} - public double phi() {return phi;} + public double phi() {return phi;}//at z = 0; + + public double phi(double z) { + // double x_0 = r*sin(phi); + // double y_0 = r*cos(phi); + double x_z = r*Math.sin( phi + thster * z/(zl*0.5) * (Math.pow(-1, this.superLayer-1)) ); + double y_z = r*Math.cos( phi + thster * z/(zl*0.5) * (Math.pow(-1, this.superLayer-1)) ); + return Math.atan2(x_z, y_z); + } public Line3D line() {return line3D;} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java index 83001e35f4..3feddf5b27 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KFitter.java @@ -75,7 +75,7 @@ public void predict(Indicator indicator) throws Exception { public void correct(Indicator indicator) { //System.out.println(" state before: (" + stateEstimation.getEntry(0) + ", " + stateEstimation.getEntry(1) + ", " + stateEstimation.getEntry(2) + ", " + stateEstimation.getEntry(3) + ", " + stateEstimation.getEntry(4) + ", " + stateEstimation.getEntry(5) + ");" ); //System.out.println(" state radius before: " + Math.sqrt( Math.pow(stateEstimation.getEntry(0), 2) + Math.pow(stateEstimation.getEntry(1), 2) ) ); - RealVector z; + RealVector z, z_plus, z_minus; RealMatrix measurementNoise; RealMatrix measurementMatrix; RealVector h; @@ -96,7 +96,7 @@ public void correct(Indicator indicator) { } else { measurementNoise = indicator.hit.get_MeasurementNoise_simple();//1x1 measurementMatrix = H_simple(stateEstimation, indicator);//6x1 - h = h_simple(stateEstimation, indicator);//1x1 + h = h_simple(stateEstimation, indicator);//.multiply(wire_sign_mat(indicator));//1x1 z = indicator.hit.get_Vector_simple();//1x1 // measurementNoise = indicator.hit.get_MeasurementNoise();//3x3 @@ -104,14 +104,14 @@ public void correct(Indicator indicator) { // h = h(stateEstimation, indicator);//3x1 // z = indicator.hit.get_Vector();//3x1 - //System.out.println(" distance " + h.getEntry(0) + " hit R " + indicator.hit.getR() + " hit wire " + indicator.hit.getWire() + " hit doca " + indicator.hit.getDoca()); - + //System.out.println(" h: r " + h.getEntry(0) + " phi " + h.getEntry(1) + " h z " + h.getEntry(2) + " z: r " + z.getEntry(0) + " phi " + z.getEntry(1) + " z " + z.getEntry(2) ); + } RealMatrix measurementMatrixT = measurementMatrix.transpose(); // S = H * P(k) * H' + R RealMatrix S = measurementMatrix.multiply(errorCovariance).multiply(measurementMatrixT).add(measurementNoise); - + // Inn = z(k) - h(xHat(k)-) RealVector innovation = z.subtract(h); @@ -133,6 +133,25 @@ public void correct(Indicator indicator) { stepper.y = stateEstimation.toArray(); } + public double residual(Indicator indicator) { + double d = indicator.hit.distance( new Point3D( stateEstimation.getEntry(0), stateEstimation.getEntry(1), stateEstimation.getEntry(2) ) ); + return indicator.hit.doca()-d; + } + + public double wire_sign(Indicator indicator) {//let's decide: positive when (phi state - phi wire) > 0 + double phi_state = Math.atan2(stateEstimation.getEntry(1), stateEstimation.getEntry(0)); + double phi_wire = indicator.hit.phi(stateEstimation.getEntry(2)); + //System.out.println(" phi state " + phi_state + " phi wire " + phi_wire);// + " phi state alt? " + Math.atan2(stateEstimation.getEntry(1), stateEstimation.getEntry(0))); + return (phi_state-phi_wire)/Math.abs(phi_state-phi_wire) ; + } + + // public RealMatrix wire_sign_mat(Indicator indicator) {//let's decide: positive when (phi state - phi wire) > 0 + // double phi_state = Math.atan2(stateEstimation.getEntry(1), stateEstimation.getEntry(0)); + // double phi_wire = indicator.hit.phi(stateEstimation.getEntry(2)); + // System.out.println(" phi state " + phi_state + " phi wire " + phi_wire);// + " phi state alt? " + Math.atan2(stateEstimation.getEntry(1), stateEstimation.getEntry(0))); + // return MatrixUtils.createRealMatrix(new double[][]{{(phi_state-phi_wire)/Math.abs(phi_state-phi_wire)}}); + // } + private RealMatrix F(Indicator indicator, Stepper stepper1) throws Exception { double[] dfdx = subfunctionF(indicator, stepper1, 0); @@ -170,27 +189,25 @@ private RealMatrix F(Indicator indicator, Stepper stepper1) throws Exception { return new double[]{dxdi, dydi, dzdi, dpxdi, dpydi, dpzdi}; } + //measurement matrix in cylindrical coordinates: r, phi, z private RealVector h(RealVector x, Indicator indicator) { - //double d = indicator.hit.distance(new Point3D(x.getEntry(0), x.getEntry(1), x.getEntry(2))); - //As per my understanding: d -> r distance from wire; phi, z unknown - double xx = x.getEntry(0);//(indicator.hit.getline3D().origin().x()+indicator.hit.getline3D().end().x())*0.5; - double yy = x.getEntry(1);//(indicator.hit.getline3D().origin().y()+indicator.hit.getline3D().end().y())*0.5; + //As per my understanding: d -> r wire; phi -> phi wire, z unconstrained + double xx = x.getEntry(0); + double yy = x.getEntry(1); return MatrixUtils.createRealVector(new double[]{Math.hypot(xx, yy), Math.atan2(yy, xx), x.getEntry(2)}); } + //measurement matrix in 1 dimension: minimize distance - doca private RealVector h_simple(RealVector x, Indicator indicator) { - double d = indicator.hit.distance(new Point3D(x.getEntry(0), x.getEntry(1), x.getEntry(2))); - //As per my understanding: d -> r distance from wire; phi, z unknown return MatrixUtils.createRealVector(new double[]{d});//would need to have this 3x3 } + //measurement noise matrix in cylindrical coordinates: r, phi, z private RealMatrix H(RealVector x, Indicator indicator) { - - // As per my understanding: ddocadx,y,z -> = dr/dx,y,z, etc // dphi/dx - double xx = x.getEntry(0);//(indicator.hit.getline3D().origin().x()+indicator.hit.getline3D().end().x())*0.5; - double yy = x.getEntry(1);//(indicator.hit.getline3D().origin().y()+indicator.hit.getline3D().end().y())*0.5; + double xx = x.getEntry(0); + double yy = x.getEntry(1); double drdx = (xx) / (Math.hypot(xx, yy)); double drdy = (yy) / (Math.hypot(xx, yy)); @@ -219,19 +236,9 @@ private RealMatrix H(RealVector x, Indicator indicator) { {dphidx, dphidy, dphidz, dphidpx, dphidpy, dphidpz}, {dzdx, dzdy, dzdz, dzdpx, dzdpy, dzdpz} }); - // double ddocadx = subfunctionH(x, indicator, 0); - // double ddocady = subfunctionH(x, indicator, 1); - // double ddocadz = subfunctionH(x, indicator, 2); - // double ddocadpx = subfunctionH(x, indicator, 3); - // double ddocadpy = subfunctionH(x, indicator, 4); - // double ddocadpz = subfunctionH(x, indicator, 5); - - // return MatrixUtils.createRealMatrix(new double[][]{ - // {ddocadx, ddocady, ddocadz, ddocadpx, ddocadpy, ddocadpz}, - // {0, 0, 0, 0, 0, 0, 0}, - // {0, 0, 0, 0, 0, 0, 0}}); } + //measurement matrix in 1 dimension: minimize distance - doca private RealMatrix H_simple(RealVector x, Indicator indicator) { double ddocadx = subfunctionH(x, indicator, 0); @@ -254,8 +261,8 @@ private RealMatrix H_simple(RealVector x, Indicator indicator) { x_plus.setEntry(i, x_plus.getEntry(i) + h); x_minus.setEntry(i, x_minus.getEntry(i) - h); - double doca_plus = h(x_plus, indicator).getEntry(0); - double doca_minus = h(x_minus, indicator).getEntry(0); + double doca_plus = h_simple(x_plus, indicator).getEntry(0); + double doca_minus = h_simple(x_minus, indicator).getEntry(0); return (doca_plus - doca_minus) / (2 * h); } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java index e6834a6105..2cd0bc5593 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/KalmanFilter/KalmanFilter.java @@ -140,7 +140,7 @@ private void propagation(ArrayList tracks, DataEvent event) { // Initialization of the Kalman Fitter RealVector initialStateEstimate = new ArrayRealVector(stepper.y); //first 3 lines in cm^2; last 3 lines in MeV^2 - RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{1.00, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 1.00, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 25.0, 0.0, 0.0, 25.0}, {0.0, 0.0, 0.0, 1.00, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1.00, 0.0}, {0.0, 0.0, 25.0, 0.0, 0.0, 25.0}}); + RealMatrix initialErrorCovariance = MatrixUtils.createRealMatrix(new double[][]{{1.00, 0.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 1.00, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 25.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.00, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1.00, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, 25.0}}); KFitter kFitter = new KFitter(initialStateEstimate, initialErrorCovariance, stepper, propagator); @@ -165,7 +165,14 @@ private void propagation(ArrayList tracks, DataEvent event) { writer_back.close(); */ - + //Print out hit residuals *before* fit: + // for (Indicator indicator : forwardIndicators) { + // kFitter.predict(indicator); + // if (indicator.haveAHit()) { + // System.out.println(" Pre-fit: indicator R " + indicator.R + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum() + " residual: " + kFitter.residual(indicator) + " sign " + kFitter.wire_sign(indicator) ); + // } + // } + for (int k = 0; k < 10; k++) { //System.out.println("--------- ForWard propagation !! ---------"); @@ -193,6 +200,14 @@ private void propagation(ArrayList tracks, DataEvent event) { } } + // //Print out residuals *after* fit: + // for (Indicator indicator : forwardIndicators) { + // kFitter.predict(indicator); + // if (indicator.haveAHit()) { + // System.out.println(" Post-fit: indicator R " + indicator.R + "; y = " + kFitter.getStateEstimationVector() + " p = " + kFitter.getMomentum() + " residual: " + kFitter.residual(indicator) + " sign " + kFitter.wire_sign(indicator) ); + // } + // } + /* Writer writer_last = new FileWriter("track_last.dat"); for (Indicator indicator : forwardIndicators) { From 0723c1554dcc2004b186e5d1312ee45c07d140aa Mon Sep 17 00:00:00 2001 From: Eric Fuchey Date: Mon, 9 Dec 2024 10:41:53 -0500 Subject: [PATCH 44/51] For pull request only: commented out the line in AHDCEngine that gathers all hits to make a track candidate and uncommented the track finding code. --- .../java/org/jlab/rec/service/AHDCEngine.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index c63ef35705..2ccf99b1ae 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -91,40 +91,40 @@ public boolean processDataEvent(DataEvent event) { // IV) Track Finder ArrayList AHDC_Tracks = new ArrayList<>(); - // if (findingMethod.equals("distance")) { - // // IV) a) Distance method - // //System.out.println("using distance"); - // Distance distance = new Distance(); - // distance.find_track(AHDC_Clusters); - // AHDC_Tracks = distance.get_AHDCTracks(); - // } else if (findingMethod.equals("hough")) { - // // IV) b) Hough Transform method - // //System.out.println("using hough"); - // HoughTransform houghtransform = new HoughTransform(); - // houghtransform.find_tracks(AHDC_Clusters); - // AHDC_Tracks = houghtransform.get_AHDCTracks(); - // } + if (findingMethod.equals("distance")) { + // IV) a) Distance method + //System.out.println("using distance"); + Distance distance = new Distance(); + distance.find_track(AHDC_Clusters); + AHDC_Tracks = distance.get_AHDCTracks(); + } else if (findingMethod.equals("hough")) { + // IV) b) Hough Transform method + //System.out.println("using hough"); + HoughTransform houghtransform = new HoughTransform(); + houghtransform.find_tracks(AHDC_Clusters); + AHDC_Tracks = houghtransform.get_AHDCTracks(); + } //Temporary track method ONLY for MC with no background; - AHDC_Tracks.add(new Track(AHDC_Hits)); + //AHDC_Tracks.add(new Track(AHDC_Hits)); - // // V) Global fit - // for (Track track : AHDC_Tracks) { - // int nbOfPoints = track.get_Clusters().size(); + // V) Global fit + for (Track track : AHDC_Tracks) { + int nbOfPoints = track.get_Clusters().size(); - // double[][] szPos = new double[nbOfPoints][3]; + double[][] szPos = new double[nbOfPoints][3]; - // int j = 0; - // for (Cluster cluster : track.get_Clusters()) { - // szPos[j][0] = cluster.get_X(); - // szPos[j][1] = cluster.get_Y(); - // szPos[j][2] = cluster.get_Z(); - // j++; - // } + int j = 0; + for (Cluster cluster : track.get_Clusters()) { + szPos[j][0] = cluster.get_X(); + szPos[j][1] = cluster.get_Y(); + szPos[j][2] = cluster.get_Z(); + j++; + } - // HelixFitJava h = new HelixFitJava(); - // track.setPositionAndMomentum(h.HelixFit(nbOfPoints, szPos, 1)); - // } + HelixFitJava h = new HelixFitJava(); + track.setPositionAndMomentum(h.HelixFit(nbOfPoints, szPos, 1)); + } // VI) Kalman Filter // System.out.println("AHDC_Tracks = " + AHDC_Tracks); From 3867efe10b392c1e630c6b65f5f77028a01ed881 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 10 Dec 2024 17:49:03 -0500 Subject: [PATCH 45/51] fix bad merge conflict --- .../src/main/java/org/jlab/detector/decode/CLASDecoder4.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index 5419e1a1c0..3d979fe545 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -443,6 +443,7 @@ public Event getDataEvent(){ Event event = new Event(); String[] wfBankNames = new String[]{"AHDC::wf"}; + DetectorType[] wfBankTypes = new DetectorType[]{DetectorType.AHDC}; String[] adcBankNames = new String[]{"FTOF::adc","ECAL::adc","FTCAL::adc", "FTHODO::adc", "FTTRK::adc", "HTCC::adc","BST::adc","CTOF::adc", From 5636a1a47f26781cb23f5f1cd751de9d3f50f895 Mon Sep 17 00:00:00 2001 From: Michael Paolone Date: Thu, 12 Dec 2024 11:35:09 -0700 Subject: [PATCH 46/51] changed ModeAHDC to be dumber and threadsafe, changed PreClusterFinder to not loop 12 more times than needed --- .../org/jlab/detector/pulse/ModeAHDC.java | 396 +++++++++--------- .../rec/ahdc/PreCluster/PreClusterFinder.java | 43 +- 2 files changed, 218 insertions(+), 221 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java index f473866513..2d4aa03c02 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -2,6 +2,8 @@ import java.util.List; import java.util.ArrayList; + +import net.jcip.annotations.GuardedBy; import org.jlab.utils.groups.NamedEntry; @@ -14,33 +16,7 @@ */ public class ModeAHDC extends HipoExtractor { - // Settings parameters (they can be initialised by a CCDB) - public float samplingTime; - public int sparseSample; - public short adcOffset; - public long timeStamp; - public float fineTimeStampResolution; public static final short ADC_LIMIT = 4095; // 2^12-1 - public float amplitudeFractionCFA; - public int binDelayCFD; - public float fractionCFD; - - // Calculation intermediaries - private int binMax; //Bin of the max ADC over the pulse - private int binOffset; //Offset due to sparse sample - private float adcMax; //Max value of ADC over the pulse (fitted) - private float timeMax; //Time of the max ADC over the pulse (fitted) - private float integral; //Sum of ADCs over the pulse (not fitted) - private long timestamp; - - private short[] samplesCorr; //Waveform after offset (pedestal) correction - private int binNumber; //Number of bins in one waveform - - private float timeRiseCFA; // moment when the signal reaches a Constant Fraction of its Amplitude uphill (fitted) - private float timeFallCFA; // moment when the signal reaches a Constant Fraction of its Amplitude downhill (fitted) - private float timeOverThresholdCFA; // is equal to (timeFallCFA - timeRiseCFA) - private float timeCFD; // time extracted using the Constant Fraction Discriminator (CFD) algorithm (fitted) - /** * This method extracts relevant informations from the digitized signal * (the samples) and store them in a Pulse @@ -51,11 +27,209 @@ public class ModeAHDC extends HipoExtractor { */ @Override public List extract(NamedEntry pars, int id, short... samples){ - waveformCorrection(samples,adcOffset,samplingTime,sparseSample); - fitAverage(samplingTime); - computeTimeAtConstantFractionAmplitude(samplingTime,amplitudeFractionCFA); - computeTimeUsingConstantFractionDiscriminator(samplingTime,fractionCFD,binDelayCFD); - fineTimeStampCorrection(timeStamp,fineTimeStampResolution); + // Settings parameters (they can be initialised by a CCDB) + float samplingTime = 0; + int sparseSample = 0; + short adcOffset = 0; + long timeStamp = 0; + float fineTimeStampResolution = 0; + + float amplitudeFractionCFA = 0; + int binDelayCFD = 0; + float fractionCFD = 0; + + // Calculation intermediaries + int binMax = 0; //Bin of the max ADC over the pulse + int binOffset = 0; //Offset due to sparse sample + float adcMax = 0; //Max value of ADC over the pulse (fitted) + float timeMax =0; //Time of the max ADC over the pulse (fitted) + float integral = 0; //Sum of ADCs over the pulse (not fitted) + long timestamp = 0; + + short[] samplesCorr; //Waveform after offset (pedestal) correction + int binNumber = 0; //Number of bins in one waveform + + float timeRiseCFA = 0; // moment when the signal reaches a Constant Fraction of its Amplitude uphill (fitted) + float timeFallCFA = 0; // moment when the signal reaches a Constant Fraction of its Amplitude downhill (fitted) + float timeOverThresholdCFA = 0; // is equal to (timeFallCFA - timeRiseCFA) + float timeCFD =0 ; // time extracted using the Constant Fraction Discriminator (CFD) algorithm (fitted) + /// ///////////////////////// + // Begin waveform correction + /// //////////////////////// + //waveformCorrection(samples,adcOffset,samplingTime,sparseSample, binMax, adcMax, integral, samplesCorr[], binOffset, timeMax); + /** + * This method subtracts the pedestal (noise) from samples and stores it in : samplesCorr + * It also computes a first value for : adcMax, binMax, timeMax and integral + * This code is inspired by the one of MVTFitter.java + * @param samples ADC samples + * @param adcOffset pedestal or noise level + * @param samplingTime time between two adc bins + * @param sparseSample used to define binOffset + */ + //private void waveformCorrection(short[] samples, short adcOffset, float samplingTime, int sparseSample, int binMax, int adcMax, int integral, short samplesCorr[], int binOffset, int timeMax){ + binNumber = samples.length; + binMax = 0; + adcMax = (short) (samples[0] - adcOffset); + integral = 0; + samplesCorr = new short[binNumber]; + for (int bin = 0; bin < binNumber; bin++){ + samplesCorr[bin] = (short) (samples[bin] - adcOffset); + if (adcMax < samplesCorr[bin]){ + adcMax = samplesCorr[bin]; + binMax = bin; + } + integral += samplesCorr[bin]; + } + /* + * If adcMax + adcOffset == ADC_LIMIT, that means there is saturation + * In that case, binMax is the middle of the first plateau + * This convention can be changed + */ + if ((short) adcMax + adcOffset == ADC_LIMIT) { + int binMax2 = binMax; + for (int bin = binMax; bin < binNumber; bin++){ + if (samplesCorr[bin] + adcOffset == ADC_LIMIT) { + binMax2 = bin; + } + else { + break; + } + } + binMax = (binMax + binMax2)/2; + } + binOffset = sparseSample*binMax; + timeMax = (binMax + binOffset)*samplingTime; + //} + + /// ///////////////////////// + // Begin fit average + /// //////////////////////// + + //fitAverage(samplingTime); + /** + * This method gives a more precise value of the max of the waveform by computing the average of five points around the binMax + * It is an alternative to fitParabolic() + * The suitability of one of these fits can be the subject of a study + * Remark : This method updates adcMax but doesn't change timeMax + * @param samplingTime time between 2 ADC bins + */ + //private void fitAverage(float samplingTime){ + if ((binMax - 2 >= 0) && (binMax + 2 <= binNumber - 1)){ + adcMax = 0; + for (int bin = binMax - 2; bin <= binMax + 2; bin++){ + adcMax += samplesCorr[bin]; + } + adcMax = adcMax/5; + } + //} + + /// ///////////////////////// + // Begin computeTimeAtConstantFractionAmplitude + /// //////////////////////// + //computeTimeAtConstantFractionAmplitude(samplingTime,amplitudeFractionCFA); + /** + * This method determines the moment when the signal reaches a Constant Fraction of its Amplitude (i.e fraction*adcMax) + * It fills the attributs : timeRiseCFA, timeFallCFA, timeOverThresholdCFA + * @param samplingTime time between 2 ADC bins + * @param amplitudeFraction amplitude fraction between 0 and 1 + */ + //private void computeTimeAtConstantFractionAmplitude(float samplingTime, float amplitudeFractionCFA){ + float threshold = amplitudeFractionCFA*adcMax; + // timeRiseCFA + int binRise = 0; + for (int bin = 0; bin < binMax; bin++){ + if (samplesCorr[bin] < threshold) + binRise = bin; // last pass below threshold and before adcMax + } // at this stage : binRise < timeRiseCFA/samplingTime <= binRise + 1 // timeRiseCFA is determined by assuming a linear fit between binRise and binRise + 1 + float slopeRise = 0; + if (binRise + 1 <= binNumber-1) + slopeRise = samplesCorr[binRise+1] - samplesCorr[binRise]; + float fittedBinRise = (slopeRise == 0) ? binRise : binRise + (threshold - samplesCorr[binRise])/slopeRise; + timeRiseCFA = (fittedBinRise + binOffset)*samplingTime; // binOffset is determined in wavefromCorrection() // must be the same for all time ? // or must be defined using fittedBinRise*sparseSample + + // timeFallCFA + int binFall = binMax; + for (int bin = binMax; bin < binNumber; bin++){ + if (samplesCorr[bin] > threshold){ + binFall = bin; + } + else { + binFall = bin; + break; // first pass below the threshold + } + } // at this stage : binFall - 1 <= timeRiseCFA/samplingTime < binFall // timeFallCFA is determined by assuming a linear fit between binFall - 1 and binFall + float slopeFall = 0; + if (binFall - 1 >= 0) + slopeFall = samplesCorr[binFall] - samplesCorr[binFall-1]; + float fittedBinFall = (slopeFall == 0) ? binFall : binFall-1 + (threshold - samplesCorr[binFall-1])/slopeFall; + timeFallCFA = (fittedBinFall + binOffset)*samplingTime; + + // timeOverThreshold + timeOverThresholdCFA = timeFallCFA - timeRiseCFA; + //} + /// ///////////////////////// + // Begin computeTimeUsingConstantFractionDiscriminator + /// //////////////////////// + //computeTimeUsingConstantFractionDiscriminator(samplingTime,fractionCFD,binDelayCFD); + /** + * This methods extracts a time using the Constant Fraction Discriminator (CFD) algorithm + * It fills the attribut : timeCFD + * @param samplingTime time between 2 ADC bins + * @param fractionCFD CFD fraction parameter between 0 and 1 + * @param binDelayCFD CFD delay parameter + */ + //private void computeTimeUsingConstantFractionDiscriminator(float samplingTime, float fractionCFD, int binDelayCFD){ + float[] signal = new float[binNumber]; + // signal generation + for (int bin = 0; bin < binNumber; bin++){ + signal[bin] = (1 - fractionCFD)*samplesCorr[bin]; // we fill it with a fraction of the original signal + if (bin < binNumber - binDelayCFD) + signal[bin] += -1*fractionCFD*samplesCorr[bin + binDelayCFD]; // we advance and invert a complementary fraction of the original signal and superimpose it to the previous signal + } + // determine the two humps + int binHumpSup = 0; + int binHumpInf = 0; + for (int bin = 0; bin < binNumber; bin++){ + if (signal[bin] > signal[binHumpSup]) + binHumpSup = bin; + } + for (int bin = 0; bin < binHumpSup; bin++){ // this loop has been added to be sure : binHumpInf < binHumpSup + if (signal[bin] < signal[binHumpInf]) + binHumpInf = bin; + } + // research for zero + int binZero = 0; + for (int bin = binHumpInf; bin <= binHumpSup; bin++){ + if (signal[bin] < 0) + binZero = bin; // last pass below zero + } // at this stage : binZero < timeCFD/samplingTime <= binZero + 1 // timeCFD is determined by assuming a linear fit between binZero and binZero + 1 + float slopeCFD = 0; + if (binZero + 1 <= binNumber) + slopeCFD = signal[binZero+1] - signal[binZero]; + float fittedBinZero = (slopeCFD == 0) ? binZero : binZero + (0 - signal[binZero])/slopeCFD; + timeCFD = (fittedBinZero + binOffset)*samplingTime; + + //} + + /// ///////////////////////// + // Begin fineTimeStampCorrection + /// //////////////////////// + //fineTimeStampCorrection(timeStamp,fineTimeStampResolution); + /** + * From MVTFitter.java + * Make fine timestamp correction (using dream (=electronic chip) clock) + * @param timeStamp timing informations (used to make fine corrections) + * @param fineTimeStampResolution precision of dream clock (usually 8) + */ + //private void fineTimeStampCorrection (long timeStamp, float fineTimeStampResolution) { + //this.timestamp = timeStamp; + String binaryTimeStamp = Long.toBinaryString(timeStamp); //get 64 bit timestamp in binary format + if (binaryTimeStamp.length()>=3){ + byte fineTimeStamp = Byte.parseByte(binaryTimeStamp.substring(binaryTimeStamp.length()-3,binaryTimeStamp.length()),2); //fineTimeStamp : keep and convert last 3 bits of binary timestamp + timeMax += (float) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection + // Question : I wonder if I have to do the same thing of all time quantities that the extract() methods compute. + } + //} // output Pulse pulse = new Pulse(); pulse.adcMax = adcMax; @@ -73,68 +247,6 @@ public List extract(NamedEntry pars, int id, short... samples){ output.add(pulse); return output; } - - /** - * This method subtracts the pedestal (noise) from samples and stores it in : samplesCorr - * It also computes a first value for : adcMax, binMax, timeMax and integral - * This code is inspired by the one of MVTFitter.java - * @param samples ADC samples - * @param adcOffset pedestal or noise level - * @param samplingTime time between two adc bins - * @param sparseSample used to define binOffset - */ - private void waveformCorrection(short[] samples, short adcOffset, float samplingTime, int sparseSample){ - binNumber = samples.length; - binMax = 0; - adcMax = (short) (samples[0] - adcOffset); - integral = 0; - samplesCorr = new short[binNumber]; - for (int bin = 0; bin < binNumber; bin++){ - samplesCorr[bin] = (short) (samples[bin] - adcOffset); - if (adcMax < samplesCorr[bin]){ - adcMax = samplesCorr[bin]; - binMax = bin; - } - integral += samplesCorr[bin]; - } - /* - * If adcMax + adcOffset == ADC_LIMIT, that means there is saturation - * In that case, binMax is the middle of the first plateau - * This convention can be changed - */ - if ((short) adcMax + adcOffset == ADC_LIMIT) { - int binMax2 = binMax; - for (int bin = binMax; bin < binNumber; bin++){ - if (samplesCorr[bin] + adcOffset == ADC_LIMIT) { - binMax2 = bin; - } - else { - break; - } - } - binMax = (binMax + binMax2)/2; - } - binOffset = sparseSample*binMax; - timeMax = (binMax + binOffset)*samplingTime; - } - - /** - * This method gives a more precise value of the max of the waveform by computing the average of five points around the binMax - * It is an alternative to fitParabolic() - * The suitability of one of these fits can be the subject of a study - * Remark : This method updates adcMax but doesn't change timeMax - * @param samplingTime time between 2 ADC bins - */ - private void fitAverage(float samplingTime){ - if ((binMax - 2 >= 0) && (binMax + 2 <= binNumber - 1)){ - adcMax = 0; - for (int bin = binMax - 2; bin <= binMax + 2; bin++){ - adcMax += samplesCorr[bin]; - } - adcMax = adcMax/5; - } - } - /** * Fit the max of the pulse using parabolic fit, this method updates the timeMax and adcMax values * @param samplingTime time between 2 ADC bins @@ -142,102 +254,4 @@ private void fitAverage(float samplingTime){ private void fitParabolic(float samplingTime) { } - - /** - * From MVTFitter.java - * Make fine timestamp correction (using dream (=electronic chip) clock) - * @param timeStamp timing informations (used to make fine corrections) - * @param fineTimeStampResolution precision of dream clock (usually 8) - */ - private void fineTimeStampCorrection (long timeStamp, float fineTimeStampResolution) { - this.timestamp = timeStamp; - String binaryTimeStamp = Long.toBinaryString(timeStamp); //get 64 bit timestamp in binary format - if (binaryTimeStamp.length()>=3){ - byte fineTimeStamp = Byte.parseByte(binaryTimeStamp.substring(binaryTimeStamp.length()-3,binaryTimeStamp.length()),2); //fineTimeStamp : keep and convert last 3 bits of binary timestamp - timeMax += (float) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection - // Question : I wonder if I have to do the same thing of all time quantities that the extract() methods compute. - } - } - - /** - * This method determines the moment when the signal reaches a Constant Fraction of its Amplitude (i.e fraction*adcMax) - * It fills the attributs : timeRiseCFA, timeFallCFA, timeOverThresholdCFA - * @param samplingTime time between 2 ADC bins - * @param amplitudeFraction amplitude fraction between 0 and 1 - */ - private void computeTimeAtConstantFractionAmplitude(float samplingTime, float amplitudeFractionCFA){ - float threshold = amplitudeFractionCFA*adcMax; - // timeRiseCFA - int binRise = 0; - for (int bin = 0; bin < binMax; bin++){ - if (samplesCorr[bin] < threshold) - binRise = bin; // last pass below threshold and before adcMax - } // at this stage : binRise < timeRiseCFA/samplingTime <= binRise + 1 // timeRiseCFA is determined by assuming a linear fit between binRise and binRise + 1 - float slopeRise = 0; - if (binRise + 1 <= binNumber-1) - slopeRise = samplesCorr[binRise+1] - samplesCorr[binRise]; - float fittedBinRise = (slopeRise == 0) ? binRise : binRise + (threshold - samplesCorr[binRise])/slopeRise; - timeRiseCFA = (fittedBinRise + binOffset)*samplingTime; // binOffset is determined in wavefromCorrection() // must be the same for all time ? // or must be defined using fittedBinRise*sparseSample - - // timeFallCFA - int binFall = binMax; - for (int bin = binMax; bin < binNumber; bin++){ - if (samplesCorr[bin] > threshold){ - binFall = bin; - } - else { - binFall = bin; - break; // first pass below the threshold - } - } // at this stage : binFall - 1 <= timeRiseCFA/samplingTime < binFall // timeFallCFA is determined by assuming a linear fit between binFall - 1 and binFall - float slopeFall = 0; - if (binFall - 1 >= 0) - slopeFall = samplesCorr[binFall] - samplesCorr[binFall-1]; - float fittedBinFall = (slopeFall == 0) ? binFall : binFall-1 + (threshold - samplesCorr[binFall-1])/slopeFall; - timeFallCFA = (fittedBinFall + binOffset)*samplingTime; - - // timeOverThreshold - timeOverThresholdCFA = timeFallCFA - timeRiseCFA; - } - - /** - * This methods extracts a time using the Constant Fraction Discriminator (CFD) algorithm - * It fills the attribut : timeCFD - * @param samplingTime time between 2 ADC bins - * @param fractionCFD CFD fraction parameter between 0 and 1 - * @param binDelayCFD CFD delay parameter - */ - private void computeTimeUsingConstantFractionDiscriminator(float samplingTime, float fractionCFD, int binDelayCFD){ - float[] signal = new float[binNumber]; - // signal generation - for (int bin = 0; bin < binNumber; bin++){ - signal[bin] = (1 - fractionCFD)*samplesCorr[bin]; // we fill it with a fraction of the original signal - if (bin < binNumber - binDelayCFD) - signal[bin] += -1*fractionCFD*samplesCorr[bin + binDelayCFD]; // we advance and invert a complementary fraction of the original signal and superimpose it to the previous signal - } - // determine the two humps - int binHumpSup = 0; - int binHumpInf = 0; - for (int bin = 0; bin < binNumber; bin++){ - if (signal[bin] > signal[binHumpSup]) - binHumpSup = bin; - } - for (int bin = 0; bin < binHumpSup; bin++){ // this loop has been added to be sure : binHumpInf < binHumpSup - if (signal[bin] < signal[binHumpInf]) - binHumpInf = bin; - } - // research for zero - int binZero = 0; - for (int bin = binHumpInf; bin <= binHumpSup; bin++){ - if (signal[bin] < 0) - binZero = bin; // last pass below zero - } // at this stage : binZero < timeCFD/samplingTime <= binZero + 1 // timeCFD is determined by assuming a linear fit between binZero and binZero + 1 - float slopeCFD = 0; - if (binZero + 1 <= binNumber) - slopeCFD = signal[binZero+1] - signal[binZero]; - float fittedBinZero = (slopeCFD == 0) ? binZero : binZero + (0 - signal[binZero])/slopeCFD; - timeCFD = (fittedBinZero + binOffset)*samplingTime; - - } - } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java index 40bb33e7bc..ab5b692603 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/PreCluster/PreClusterFinder.java @@ -12,42 +12,25 @@ public class PreClusterFinder { public PreClusterFinder() { _AHDCPreClusters = new ArrayList<>(); } - - private void fill_list(List AHDC_hits, ArrayList sxlx, int super_layer, int layer) { - for (Hit hit : AHDC_hits) { - if (hit.getSuperLayerId() == super_layer && hit.getLayerId() == layer) { - sxlx.add(hit); + + private void fill_list(List AHDC_hits, ArrayList> all_super_layer){ + int nsuper_layers = 8; + int super_layers[] = {1,2,2,3,3,4,4,5}; + int layers[] = {1,1,2,1,2,1,2,1}; + for(int i = 0; i < nsuper_layers; i++){ + ArrayList sxlx = new ArrayList<>(); + for (Hit hit : AHDC_hits) { + if (hit.getSuperLayerId() == super_layers[i] && hit.getLayerId() == layers[i]) { + sxlx.add(hit); + } } + all_super_layer.add(sxlx); } } public void findPreCluster(List AHDC_hits) { - ArrayList s0l0 = new ArrayList(); - fill_list(AHDC_hits, s0l0, 1, 1); - ArrayList s1l0 = new ArrayList(); - fill_list(AHDC_hits, s1l0, 2, 1); - ArrayList s1l1 = new ArrayList(); - fill_list(AHDC_hits, s1l1, 2, 2); - ArrayList s2l0 = new ArrayList(); - fill_list(AHDC_hits, s2l0, 3, 1); - ArrayList s2l1 = new ArrayList(); - fill_list(AHDC_hits, s2l1, 3, 2); - ArrayList s3l0 = new ArrayList(); - fill_list(AHDC_hits, s3l0, 4, 1); - ArrayList s3l1 = new ArrayList(); - fill_list(AHDC_hits, s3l1, 4, 2); - ArrayList s4l0 = new ArrayList(); - fill_list(AHDC_hits, s4l0, 5, 1); - ArrayList> all_super_layer = new ArrayList<>(); - all_super_layer.add(s0l0); - all_super_layer.add(s1l0); - all_super_layer.add(s1l1); - all_super_layer.add(s2l0); - all_super_layer.add(s2l1); - all_super_layer.add(s3l0); - all_super_layer.add(s3l1); - all_super_layer.add(s4l0); + fill_list(AHDC_hits,all_super_layer); for (ArrayList sxlx : all_super_layer) { for (Hit hit : sxlx) { From d6adcd863dd51dda3bed277b692bff4d1340a707 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 13 Dec 2024 11:40:13 -0500 Subject: [PATCH 47/51] AHDC::wf must be defined --- etc/bankdefs/hipo4/data.json | 41 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/etc/bankdefs/hipo4/data.json b/etc/bankdefs/hipo4/data.json index cde3f796d1..7a8ea61519 100644 --- a/etc/bankdefs/hipo4/data.json +++ b/etc/bankdefs/hipo4/data.json @@ -1,4 +1,23 @@ [ + { + "name" : "AHDC::wf", + "group": 22400, + "item" : 10, + "info": "Waveform bank for the AHDC", + "entries":[ + { "name":"sector" , "type":"B", "info":"sector"}, + { "name":"layer" , "type":"B", "info":"layer (1-6)"}, + { "name":"component" , "type":"S", "info":"strips"}, + { "name":"order" , "type":"B", "info":"order: 0 - ADCL , 1 - ADCR"}, + { "name":"timestamp" , "type":"L", "info":"timestamp"}, + { "name":"s1" , "type":"S", "info":"sample #1"}, + { "name":"s2" , "type":"S", "info":"sample #2"}, + { "name":"s3" , "type":"S", "info":"sample #3"}, + { "name":"s4" , "type":"S", "info":"sample #4"}, + { "name":"s5" , "type":"S", "info":"sample #5"}, + { "name":"s6" , "type":"S", "info":"sample #6"} + ] + }, { "name" : "AHDC::adc", "group": 22400, @@ -42,27 +61,7 @@ { "name":"time" , "type":"F", "info":"time from pulse fit"}, { "name":"ped" , "type":"S", "info":"pedestal from pulse analysis"}, { "name":"integral" , "type":"I", "info":"ADC integral (sum over the pulse)"}, - { "name":"timestamp" , "type":"L", "info":"timestamp"}, - { "name":"id" , "type":"S", "info":"link to BMT::wf"} - ] - }, - { - "name" : "BMT::wf", - "group": 20100, - "item" : 12, - "info": "WF bank for the Barrel MicroMegas Tracker", - "entries":[ - { "name":"sector" , "type":"B", "info":"sector"}, - { "name":"layer" , "type":"B", "info":"layer (1-6)"}, - { "name":"component" , "type":"S", "info":"strips"}, - { "name":"order" , "type":"B", "info":"order: 0 - ADCL , 1 - ADCR"}, - { "name":"timestamp" , "type":"L", "info":"timestamp"}, - { "name":"s1" , "type":"S", "info":"sample #1"}, - { "name":"s2" , "type":"S", "info":"sample #2"}, - { "name":"s3" , "type":"S", "info":"sample #3"}, - { "name":"s4" , "type":"S", "info":"sample #4"}, - { "name":"s5" , "type":"S", "info":"sample #5"}, - { "name":"s6" , "type":"S", "info":"sample #6"} + { "name":"timestamp" , "type":"L", "info":"timestamp"} ] }, { From 0bd410828924a640ec458ee6435bb763b8895c7e Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Fri, 13 Dec 2024 11:41:53 -0500 Subject: [PATCH 48/51] actually use the new ahdc pulse extractor --- .../main/java/org/jlab/detector/decode/CLASDecoder4.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java index 3d979fe545..17fee2548b 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java @@ -14,7 +14,7 @@ import org.jlab.detector.helicity.HelicityBit; import org.jlab.detector.helicity.HelicitySequence; import org.jlab.detector.helicity.HelicityState; -import org.jlab.detector.pulse.Mode3; +import org.jlab.detector.pulse.ModeAHDC; import org.jlab.logging.DefaultLogger; @@ -47,8 +47,8 @@ public class CLASDecoder4 { private HipoDataEvent hipoEvent = null; private boolean isRunNumberFixed = false; private int decoderDebugMode = 0; - private SchemaFactory schemaFactory = new SchemaFactory(); - private Mode3 mode3 = new Mode3(); + private SchemaFactory schemaFactory = new SchemaFactory(); + private ModeAHDC ahdcExtractor = new ModeAHDC(); public CLASDecoder4(boolean development){ codaDecoder = new CodaEventDecoder(); @@ -248,7 +248,7 @@ public List getEntriesSCALER(DetectorType type, } public void extractPulses(Event event) { - mode3.update(6, null, event, schemaFactory, "AHDC::wf", "AHDC::adc"); + ahdcExtractor.update(6, null, event, schemaFactory, "AHDC::wf", "AHDC::adc"); } public Bank getDataBankWF(String name, DetectorType type) { From 35213138e37303ab1b9faacceb4e060642742c42 Mon Sep 17 00:00:00 2001 From: Mathieu Ouillon Date: Mon, 16 Dec 2024 10:53:36 -0500 Subject: [PATCH 49/51] Add AI for ALERT trackfinding Use DeepJavaLibrary to load a PyTorch model. Create a new bank AHDC_AI::Prediction. --- etc/bankdefs/hipo4/alert.json | 21 ++- etc/bankdefs/util/bankSplit.py | 2 +- parent/pom.xml | 12 ++ reconstruction/alert/pom.xml | 11 ++ .../org/jlab/rec/ahdc/AI/AIPrediction.java | 37 ++++++ .../org/jlab/rec/ahdc/AI/PreClustering.java | 110 ++++++++++++++++ .../rec/ahdc/AI/PreclusterSuperlayer.java | 46 +++++++ .../jlab/rec/ahdc/AI/TrackConstruction.java | 106 ++++++++++++++++ .../org/jlab/rec/ahdc/AI/TrackPrediction.java | 74 +++++++++++ .../java/org/jlab/rec/ahdc/AI/model/model.pt | Bin 0 -> 30224 bytes .../jlab/rec/ahdc/Banks/RecoBankWriter.java | 26 ++++ .../main/java/org/jlab/rec/ahdc/Hit/Hit.java | 2 + .../java/org/jlab/rec/service/AHDCEngine.java | 120 +++++++++++++++--- 13 files changed, 550 insertions(+), 17 deletions(-) create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/AIPrediction.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreClustering.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreclusterSuperlayer.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackConstruction.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackPrediction.java create mode 100644 reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/model/model.pt diff --git a/etc/bankdefs/hipo4/alert.json b/etc/bankdefs/hipo4/alert.json index 586ca188f8..7c125eb9cc 100644 --- a/etc/bankdefs/hipo4/alert.json +++ b/etc/bankdefs/hipo4/alert.json @@ -159,5 +159,24 @@ "info": "pz in MeV" } ] -} +}, + { + "name": "AHDC_AI::Prediction", + "group": 23000, + "item": 30, + "info": "Prediction given by AI", + "entries": [ + {"name": "X1", "type": "F", "info": "X1 position of the 1th superprecluster (mm)"}, + {"name": "Y1", "type": "F", "info": "Y1 position of the 1th superprecluster (mm)"}, + {"name": "X2", "type": "F", "info": "X2 position of the 2nd superprecluster (mm)"}, + {"name": "Y2", "type": "F", "info": "Y2 position of the 2nd superprecluster (mm)"}, + {"name": "X3", "type": "F", "info": "X3 position of the 3rd superprecluster (mm)"}, + {"name": "Y3", "type": "F", "info": "Y3 position of the 3rd superprecluster (mm)"}, + {"name": "X4", "type": "F", "info": "X4 position of the 4th superprecluster (mm)"}, + {"name": "Y4", "type": "F", "info": "Y4 position of the 4th superprecluster (mm)"}, + {"name": "X5", "type": "F", "info": "X5 position of the 5th superprecluster (mm)"}, + {"name": "Y5", "type": "F", "info": "Y5 position of the 5th superprecluster (mm)"}, + {"name": "Pred", "type": "F", "info": "Prediction of the model: 0 mean bad track; 1 mean good track"} + ] + } ] diff --git a/etc/bankdefs/util/bankSplit.py b/etc/bankdefs/util/bankSplit.py index b8f5e9da0f..7d93505028 100755 --- a/etc/bankdefs/util/bankSplit.py +++ b/etc/bankdefs/util/bankSplit.py @@ -65,7 +65,7 @@ def create(dirname, banklist): raster = ["RASTER::position"] rich = ["RICH::tdc","RICH::Ring","RICH::Particle"] rtpc = ["RTPC::hits","RTPC::tracks","RTPC::KFtracks"] -alert = ["AHDC::Track", "AHDC::MC", "AHDC::Hits", "AHDC::PreClusters", "AHDC::Clusters", "AHDC::KFTrack"] +alert = ["AHDC::Track", "AHDC::MC", "AHDC::Hits", "AHDC::PreClusters", "AHDC::Clusters", "AHDC::KFTrack", "AHDC_AI::Prediction"] dets = band + raster + rich + rtpc + alert # additions for the calibration schema: diff --git a/parent/pom.xml b/parent/pom.xml index 99495aa728..833507a2cc 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -46,6 +46,18 @@ 0.8.12 + + ai.djl + model-zoo + 0.30.0 + compile + + + ai.djl.pytorch + pytorch-model-zoo + 0.30.0 + + diff --git a/reconstruction/alert/pom.xml b/reconstruction/alert/pom.xml index 4d7f9502a5..0029fb4bfa 100644 --- a/reconstruction/alert/pom.xml +++ b/reconstruction/alert/pom.xml @@ -40,6 +40,17 @@ 11.0.5-SNAPSHOT compile + + ai.djl + model-zoo + 0.30.0 + compile + + + ai.djl.pytorch + pytorch-model-zoo + 0.30.0 + diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/AIPrediction.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/AIPrediction.java new file mode 100644 index 0000000000..1e800c6cf6 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/AIPrediction.java @@ -0,0 +1,37 @@ +package org.jlab.rec.ahdc.AI; + +import java.util.ArrayList; + +import ai.djl.MalformedModelException; +import ai.djl.inference.Predictor; +import ai.djl.repository.zoo.ModelNotFoundException; +import ai.djl.repository.zoo.ZooModel; +import ai.djl.translate.TranslateException; + +import java.io.IOException; + +public class AIPrediction { + + + public AIPrediction() throws ModelNotFoundException, MalformedModelException, IOException { + } + + public ArrayList prediction(ArrayList> tracks, ZooModel model) throws TranslateException { + ArrayList result = new ArrayList<>(); + for (ArrayList track : tracks) { + float[] a = new float[]{(float) track.get(0).getX(), (float) track.get(0).getY(), + (float) track.get(1).getX(), (float) track.get(1).getY(), + (float) track.get(2).getX(), (float) track.get(2).getY(), + (float) track.get(3).getX(), (float) track.get(3).getY(), + (float) track.get(4).getX(), (float) track.get(4).getY(), + }; + + Predictor my_predictor = model.newPredictor(); + result.add(new TrackPrediction(my_predictor.predict(a), track)); + } + + return result; + } + + +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreClustering.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreClustering.java new file mode 100644 index 0000000000..17cb3f365f --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreClustering.java @@ -0,0 +1,110 @@ +package org.jlab.rec.ahdc.AI; + +import org.jlab.rec.ahdc.Hit.Hit; +import org.jlab.rec.ahdc.PreCluster.PreCluster; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +public class PreClustering { + + private ArrayList fill(List hits, int super_layer, int layer) { + + ArrayList result = new ArrayList<>(); + for (Hit hit : hits) { + if (hit.getSuperLayerId() == super_layer && hit.getLayerId() == layer) result.add(hit); + } + return result; + } + + public ArrayList find_preclusters_for_AI(List AHDC_hits) { + ArrayList preclusters = new ArrayList<>(); + + ArrayList s1l1 = fill(AHDC_hits, 1, 1); + ArrayList s2l1 = fill(AHDC_hits, 2, 1); + ArrayList s2l2 = fill(AHDC_hits, 2, 2); + ArrayList s3l1 = fill(AHDC_hits, 3, 1); + ArrayList s3l2 = fill(AHDC_hits, 3, 2); + ArrayList s4l1 = fill(AHDC_hits, 4, 1); + ArrayList s4l2 = fill(AHDC_hits, 4, 2); + ArrayList s5l1 = fill(AHDC_hits, 5, 1); + + // Sort hits of each layers by phi: + s1l1.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + s2l1.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + s2l2.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + s3l1.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + s3l2.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + s4l1.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + s4l2.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + s5l1.sort(new Comparator() {@Override public int compare(Hit a1, Hit a2) {return Double.compare(a1.getPhi(), a2.getPhi());}}); + + ArrayList> all_super_layer = new ArrayList<>(Arrays.asList(s1l1, s2l1, s2l2, s3l1, s3l2, s4l1, s4l2, s5l1)); + + for (ArrayList p : all_super_layer) { + for (Hit hit : p) { + hit.setUse(false); + } + } + + for (ArrayList p : all_super_layer) { + for (Hit hit : p) { + if (hit.is_NoUsed()) { + ArrayList temp = new ArrayList<>(); + temp.add(hit); + hit.setUse(true); + + boolean has_next = true; + while (has_next) { + has_next = false; + for (Hit hit1 : p) { + if (hit1.is_NoUsed() && (hit1.getWireId() == temp.get(temp.size() - 1).getWireId() + 1 || hit1.getWireId() == temp.get(temp.size() - 1).getWireId() - 1)) { + temp.add(hit1); + hit1.setUse(true); + has_next = true; + break; + } + } + } + if (!temp.isEmpty()) preclusters.add(new PreCluster(temp)); + } + } + } + return preclusters; + } + + public ArrayList merge_preclusters(ArrayList preclusters) { + double distance_max = 8.0; + + ArrayList superpreclusters = new ArrayList<>(); + for (PreCluster precluster : preclusters) { + if (!precluster.is_Used()) { + ArrayList tmp = new ArrayList<>(); + tmp.add(precluster); + precluster.set_Used(true); + for (PreCluster other : preclusters) { + if (precluster.get_hits_list().get(precluster.get_hits_list().size() - 1).getSuperLayerId() == other.get_hits_list().get(other.get_hits_list().size() - 1).getSuperLayerId() && precluster.get_hits_list().get(precluster.get_hits_list().size() - 1).getLayerId() != other.get_hits_list().get(other.get_hits_list().size() - 1).getLayerId() && !other.is_Used()) { + double dx = precluster.get_X() - other.get_X(); + double dy = precluster.get_Y() - other.get_Y(); + double distance = Math.sqrt(dx * dx + dy * dy); + + if (distance < distance_max) { + other.set_Used(true); + tmp.add(other); + } + } + } + + if (!tmp.isEmpty()) superpreclusters.add(new PreclusterSuperlayer(tmp)); + } + } + + return superpreclusters; + } + + + + +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreclusterSuperlayer.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreclusterSuperlayer.java new file mode 100644 index 0000000000..ecab32728c --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/PreclusterSuperlayer.java @@ -0,0 +1,46 @@ +package org.jlab.rec.ahdc.AI; + +import org.jlab.rec.ahdc.Hit.Hit; +import org.jlab.rec.ahdc.PreCluster.PreCluster; + +import java.util.ArrayList; + +public class PreclusterSuperlayer { + private final double x; + private final double y; + private ArrayList preclusters = new ArrayList<>(); + + + ; public PreclusterSuperlayer(ArrayList preclusters_) { + this.preclusters = preclusters_; + double x_ = 0; + double y_ = 0; + + for (PreCluster p : this.preclusters) { + x_ += p.get_X(); + y_ += p.get_Y(); + } + this.x = x_ / this.preclusters.size(); + this.y = y_ / this.preclusters.size(); + + + + } + + public ArrayList getPreclusters() { + return preclusters; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + + public String toString() { + return "PreCluster{" + "X: " + this.x + " Y: " + this.y + " phi: " + Math.atan2(this.y, this.x) + "}\n"; + } +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackConstruction.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackConstruction.java new file mode 100644 index 0000000000..dce5414001 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackConstruction.java @@ -0,0 +1,106 @@ +package org.jlab.rec.ahdc.AI; + +import org.jlab.rec.ahdc.Hit.Hit; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.*; + +public class TrackConstruction { + public TrackConstruction() {} + + private double mod(double x, double y) { + + if (0. == y) return x; + + double m = x - y * Math.floor(x / y); + // handle boundary cases resulted from floating-point cut off: + if (y > 0) { // modulo range: [0..y) + if (m >= y) return 0; // Mod(-1e-16 , 360. ): m= 360. + if (m < 0) { + if (y + m == y) return 0; // just in case... + else return y + m; // Mod(106.81415022205296 , _TWO_PI ): m= -1.421e-14 + } + } else { // modulo range: (y..0] + if (m <= y) return 0; // Mod(1e-16 , -360. ): m= -360. + if (m > 0) { + if (y + m == y) return 0; // just in case... + else return y + m; // Mod(-106.81415022205296, -_TWO_PI): m= 1.421e-14 + } + } + + return m; + } + + private double warp_zero_two_pi(double angle) { return mod(angle, 2. * Math.PI); } + + private boolean angle_in_range(double angle, double lower, double upper) { return warp_zero_two_pi(angle - lower) <= warp_zero_two_pi(upper - lower); } + + + public ArrayList> get_all_possible_track(ArrayList preclusterSuperlayers) { + + // Get seeds to start the track finding algorithm + ArrayList seeds = new ArrayList<>(); + for (PreclusterSuperlayer precluster : preclusterSuperlayers) { + if (precluster.getPreclusters().get(0).get_hits_list().get(0).getSuperLayerId() == 1) seeds.add(precluster); + } + seeds.sort(new Comparator() { + @Override + public int compare(PreclusterSuperlayer a1, PreclusterSuperlayer a2) { + return Double.compare(Math.atan2(a1.getY(), a1.getX()), Math.atan2(a2.getY(), a2.getX())); + } + }); + // System.out.println("seeds: " + seeds); + + // Get all possible tracks ---------------------------------------------------------------- + double max_angle = Math.toRadians(60); + + ArrayList> all_combinations = new ArrayList<>(); + for (PreclusterSuperlayer seed : seeds) { + double phi_seed = warp_zero_two_pi(Math.atan2(seed.getY(), seed.getX())); + + ArrayList track = new ArrayList<>(); + for (PreclusterSuperlayer p : preclusterSuperlayers) { + double phi_p = warp_zero_two_pi(Math.atan2(p.getY(), p.getX())); + if (angle_in_range(phi_p, phi_seed - max_angle, phi_seed + max_angle)) track.add(p); + } + // System.out.println("track: " + track.size()); + + ArrayList> combinations = new ArrayList<>(List.of(new ArrayList<>(List.of(seed)))); + // System.out.println("combinations: " + combinations); + + for (int i = 1; i < 5; ++i) { + ArrayList> new_combinations = new ArrayList<>(); + for (ArrayList combination : combinations) { + + for (PreclusterSuperlayer precluster : track) { + if (precluster.getPreclusters().get(0).get_hits_list().get(0).getSuperLayerId() == seed.getPreclusters().get(0).get_hits_list().get(0).getSuperLayerId() + i) { + // System.out.printf("Good Precluster x: %.2f, y: %.2f, r: %.2f%n", precluster.getX(), precluster.getY(), Math.hypot(precluster.getX(), precluster.getY())); + // System.out.println("combination: " + combination); + + ArrayList new_combination = new ArrayList<>(combination); + new_combination.add(precluster); + // System.out.println("new_combination: " + new_combination); + new_combinations.add(new_combination); + } + } + for (ArrayList c : new_combinations) { + // System.out.println("c.size: " + c.size() + ", c: " + c); + } + + } + combinations = new_combinations; + if (combinations.size() > 10000) break; + } + for (ArrayList combination : combinations) { + if (combination.size() == 5) { + all_combinations.add(combination); + } + } + } + + return all_combinations; + } + +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackPrediction.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackPrediction.java new file mode 100644 index 0000000000..7ea5bd7712 --- /dev/null +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/TrackPrediction.java @@ -0,0 +1,74 @@ +package org.jlab.rec.ahdc.AI; + +import org.jlab.rec.ahdc.Cluster.Cluster; +import org.jlab.rec.ahdc.PreCluster.PreCluster; + +import java.util.ArrayList; + +public class TrackPrediction { + + private float prediction; + private final ArrayList superpreclusters; + private final ArrayList preclusters = new ArrayList<>(); + private ArrayList clusters = new ArrayList<>(); + + public TrackPrediction(float prediction, ArrayList superpreclusters_) { + this.prediction = prediction; + this.superpreclusters = superpreclusters_; + + for (PreclusterSuperlayer p : this.superpreclusters) { + if (p.getPreclusters() != null) + this.preclusters.addAll(p.getPreclusters()); + } + + // Generate the clusters + for (PreCluster p : this.preclusters) { + if (p.get_Super_layer() == 1) { + for (PreCluster other : this.preclusters) { + if (other.get_Super_layer() == 2 && other.get_Layer() == 1) + clusters.add(new Cluster(p, other)); + } + } + + if (p.get_Super_layer() == 2 && p.get_Layer() == 2) { + for (PreCluster other : this.preclusters) { + if (other.get_Super_layer() == 3 && other.get_Layer() == 1) + clusters.add(new Cluster(p, other)); + } + } + + if (p.get_Super_layer() == 3 && p.get_Layer() == 2) { + for (PreCluster other : this.preclusters) { + if (other.get_Super_layer() == 4 && other.get_Layer() == 1) + clusters.add(new Cluster(p, other)); + } + } + + if (p.get_Super_layer() == 4 && p.get_Layer() == 2) { + for (PreCluster other : this.preclusters) { + if (other.get_Super_layer() == 5 && other.get_Layer() == 1) + clusters.add(new Cluster(p, other)); + } + } + + + } + + } + + public float getPrediction() { + return prediction; + } + + public ArrayList getSuperpreclusters() { + return superpreclusters; + } + + public ArrayList getPreclusters() { + return preclusters; + } + + public ArrayList getClusters() { + return clusters; + } +} diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/model/model.pt b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/model/model.pt new file mode 100644 index 0000000000000000000000000000000000000000..73e665c231471d0c33a6997e75a35efc43eb3d5a GIT binary patch literal 30224 zcmeFZc|4Wf{{L^5xezjwdCWZRYwZjXLWatid7fp61~Y|_v5+#8lFYHMwUZ19kwk+s zlc7P#?5FPg+~>aUb57^n=ks}d9=|`n9*^r`WAC-r>wT^3{d!*SwJyhXiAe|u_Us|} zhc5;KIsz|mKTlf^Yfo0Lz-$-1m=JL>e*farXTW=cUsqRm5eqR;RRa! z*Lvxu=WqGZ2c}11A1MJ?8{a~-3>nb7oaMl_?k3Ds|AZ!NQy^=r@jy@A2AH21!Lc8u zgoKsMRf5~KQ6R}7 z4tid>2K#SZLY@*|f%3NHh}X{BA^pcf`ohWLZ_T8sCi`yeN)u;pyK2u5IhnGr_Fpo{B;3n@BbENA0Y(! zm_)Eoo=)X~C;`qpei;ohK~Z`pM#z>K3tIvTn?|NlWRuSc>Zrzn^Hk-C$w5(g;yMP2 znaD$|szt$Dwi=xK-Y*FKz826$`wkr>N`_oSkCB$;YfTl?>cH4I8&S#92HNTz*mr(Y zO;`ym+-%53b+3}(pBL>zRxwV1qLvH-{Sc(cX$LncRSXIzv*1v)51=Q}1WvB&u)@&{ z_(w^>sBT*5WN!@$t|`ObjY&Y!X#mJB65{V>F~K;$L|9IB84LqD;6mVo@`iGNi`QLX z&%7~Q4&?{i`|sfFYA=E399bYdSRM{8%78IiS7;Sr1+T#cgx043c&BHA(PIhV=JPyI zlfHxA2#A81_0Qbjaetb6{{5XCxUdewlUTIA=(Vva?&*Ogy4*{Y@KlH(uOmtO# z0%0nnK$99Hk-Q8npnY{1fAedL3X>%@h?!19&ShA`7YGre^js29F7v~!CsQC+!4jGm zQsUVnMS!px5ole=28X(LFXU7S#{4HnDeHPS!(X#>}e{K(TZ=8nD^IL&!K?tt; zTOM+~AsXsODf6Z@~D z4LRm;UHmZ+AUq88)oI{-HznLTG60tEszCO%e&ih_deCvP7YTOB0zs^Hhz18EJa~W; z5PxBUZ$-pb!afOa&s?`#Shx(SkZcV0A`xWgIF0g(a-ot` z^RVe$E-*Z106hdY&@=w4=+_Y+lqYi=QcGzf#g=)^L+>sq(5Vd-lZZ7 zdlFIEG$F*vI|9RFPzk03xp4V@N}%e|IoNFf1VMrc&}t_QkWe>-zBVfWZeMkgjB@}# zuFHca;M&ppZhqwJ(vHfx&$d87I0vj>e~6sAVT~sjVS>Stag7IfY+%@ZDzued15rOm zgC={?!E=--;??GX-sVU`ocJlQysCxZ=3)w{a%V%&mTCZGg%Y$AQG-j>2O+L38}eAs z0`-0DV336lq^VjXH#KzOSq?IM>svvzMBM~+7;ytR0b&T7wIMtp9f{P1X@G!Kar9_X z5x7PfjdpB=qhf*;7#9DhXk*zs9AWoWJe6B2*i$5dsH_RY5ab|e{YsCs$}&O&t^(*- z9Era-QG`n!m_$z5GvHI&o51;#kC4~$#c;o|E4c4CfQz~1ga(l@g1F0Tpw5H?XyhcL zHCeB4MF-76j9L;(e(DkGMyCS`O{rkc@Hy1Q_6y4J!VCJji$FqqOw&Zb z7GmC80d|Ng5M?tAuBylsWL^vgk$4sGMaCT^5T1oqGB<$h>1&YhU3!z)3tzyQG7U~0 z*@JpY6eC$U87)-W3vXyl4W}s3pQn=f#ly8YGa+ zjs!>>Qz1tlJb>ByHfZe8LioY*DoD%Q1EgotkP!wg$p69&bKF<}hN_=~J~K4v{IlCo zi}fp#bIBS|-=+Yjjy53snhf$RZw$wlwhgi`>!HJlGE6b5!W5PHA#;z+VZ~EjM0Z9R zMl`n~N0u^>2S!z(FzW%3eSQRB_w}GQ92)3dJO%`Xr2<0-1(Xvs1GSVa@b)7X8FKAL-`w3so{}5E z{4;_GRo4;p__;Qu@%VGJq96iYv2lZLWZ9^s+6T<#`5X|M>kQuxszA@rmtp#cL==t^ z1L^C{;3IA?#@~((YQMXMe%$*67+gFHN>!#Xk-cY-QBGs1(RKhcyeezJZvNnr9F6m_?4%zj>2Iw0)p?y&-@kp zPy9+oQ%&Ws_|>2NE7kxD^QAE`Y$Oeq2AUx48A@QXdmE`ZQUJb`oIypdHeq6gLO^wD z7o^K71w1uGuq%igI5Nj$&Lpuy%A+NibbD>sJLrqvHqAu8^TK}rM-Kn3|H}SF|JC++ zgr*PYA%~0Y00UJns%l6Dp1{E78fG;7|x~} z&w8L&xFI0TaY1XsgrV@@8>EoX6NV4G!|_ZjBgT<^7?ODwkjMM7X>lbTJ+aFq$_)b8 zd&~t;;{^papv(y#%&iAHc0z#6APH3TzQPb(H;4TTT)>C2tC}5-aFI_BUdrivI$bAX|s_Z(_mSv;e3T*?_*d z+=(cdL;*3ETj1*q5iI89ftTiGz{QiL@bEcua7X?gJVBg;5e(ErtXTIUtZLGrz%2uc zG)|#CPZKenMF*;k0AW}nB3)_&x0&$BVHGjJ?9K|{H9_PH zyaSn}l29)^DrtQGye+Fs4Qaa0P1v z+aOwaOXDbd>|zY4wOmEams3#ho0WhpYA?7LYYOB2_XGKBJBZp5V!Y^(8f+0~2kA1R z;LSTupim7Efmf4g01YGlWpoC(9b}2@nXE;pii^M)W(RplO9!uG+ z!xft7>EL?1=&^eWlYkW;GuT;4!PVqHM~@s&fEJ7jc)Q6AKv;HJMd3p#d=79ZpTJ9y z<-h_&B72+WTzHZ4Sz;6+cnIF|4b95v8F~ zP`3UOsg8UJjbnOY4D&4*xyFKT!JI`MAM?S^Spm#3ZgKQEdmfCp6bCKOqCsxWM-^A* zDfIJb5LPhuJ|^r*4dC#R0!1oIh}9cPtoMhr$nB8;l_&aLP%a1U(SL_QJ2Ek{09>DL z0+iwqY!v7Ln5GrPW|9+*Sr8){T3g_1m@2SbU&4i8+u)N&#Q5~ISSU_a2$+Xskyhu+ zAW(u7PG?zT@8IKM@t!pBY?uj@*mwa!x3OG{$M;lVEWLWL5EZ9&g zJbs|xA8+T^s^mfW4zh`JV$eW<6f~MAqEzI>*xMT%c!PQ( zTu~Vxwrj-)4Wi@2FG{i?T2-vDpyygsuZuI_WN1M6U&SJw@ntYnR{@^keh&x*yCbk+KG9ysTydaLrvu#}#bA-IqCFEt?W= z6nz4I`>+Vi30#qYhdY?0jy;H&P9ZX>-w9IHs=-+0OLRz*5`A^r26Gy1e9!N z03YujVCYT`!nb0uWi&^CJXbiXlL5elVh`BnVt_7$2FM4*3NgwKSJ67|1&1Hi0wLTw zhUB&|IKf>61<2~5W33TXosI$a&$%JLy%11w2v>O(9fA#8Jqj(a;((;{0Pr>$0XCOI zp@?HB=kUXkw^}N&*$=EWqVrN)?${N3bqF zj~YBa+W1Tqsb#xPrUYCPIF3T{Q{sr`Fqd}`qMxxrs z#b9ArEa-m!6=D7y4%1sL@CsBOKr`bba)l@xjI`LJPn>8#dD|j7moNl7G&6vw%wuqH zDh9|LIJnCxF>t`d0tT!^VNxz`APq+82t(;ba7QQ_Sv%hkuMZ@`AaZ9gn5qc&_vC?5 zSy`l9iv_Bi--3!YN_f^j4RGwM5%@x=3{D8d0HSnq&?0bErK*_|36$mlkB{#GkCkGe zWET(Yo(#uPO{gJz0uKO!L&fj`zbRyBiD<$adV$E-cQBWNKVv8~^^wP=Mc_&@F%(p& zz)fa-Mwt|{fT`d$^s{FTXgu$UY#yybO=#ZXIJ!=QXP<&V`cN6DGP+1 zfXuA~py5IZ;{#3sQlly)ukk#*m_-a3!$^Sy?aXCiRF+y=6b)eF2xc!arNych5N zTmjaJYl6oG+<;I_1V7TO49X-jfhM8_J4Hg!hk*p)U@0z^Murtn73($n;spzx7|mzv#dA%6fRa7q_5#Y6_O%ogtnwk^vuR zY>f3PbOi)A+Mvc+2y|-ztUeE|8=Wh))?wP_6qMV%V zNEng5wY9&upS_EwXKJvpTD(>qlb^9AEo|}B}9Eke@b5h;qVJWrr(zu z{rzlRyJ2!P>>!+ufH)-;{j!uTCDe{{D_$ zzQn)l>PMFnUS1NrYm)&Uj%Or(eG{eTFK?#wCHdZ)3*luKBK-h6UsBV3yDfRRdO6zq zS^GJ91X!Q(-|fqn>}PG-dwcos4s=(Av7>K*qnE#{tp}wq`QIBhCERWFknf(KHS$ZJ zl*fK_P3cSVBM7^dDuN(KS7#T0UrPI5v{(oDyLz0V+#Q@ ze<58;T|)m$_V(T$9**|@uHIf}C=L7^9Q_;}G+ga>Pt9IoBYz{`eWu^1kDaUS8DDyr z-A-MoU1)wtl=5Y8q19#FZIbavle-P>Hs|uor}qCAWF{AepGCrUx933H@4ZtRIUYMf z>C620Nba5@mLFY7`yTjN8^1(T!uoHM&ePV**~8KL&~Nc&{m~}n--hpUz=c*XnQ(XH zY`+A9ad+&DzZ*Tf%O9o6_;UOzmGd8^a{VTi+lAw2!~DC{e;BINui|G_aUhTbQg>d)M{o|}x{*!hkUzObte7{UEKR)n> z3mo}PJ8)6?*(m?6ozmFV+0)zAfzlWI2eF5DuXEMiLrvnlQASKb1*P3o`2F~9T8z6J zQT}l!iZp@XA5F`CcRPyY-x7ee1Ep8h#Q!?@_eRw?a1Y zEem;rUWcDWtmc{2u|m5f1J*{u+fj^9`o7tR1`0ABWRFbb)6yR>o^c*+d_~BuUnuKm zcjb~#Signpn^&)~$Bq2ntp&Nw~&!bEwG-X9G%BN@ZYntU}zLFyiXYU@@ znU{&a77<9CFFbJ8yNzBT>x2U*-o5Vf*JE*=()P!KJ9cOqM~r(q+)l6BJKba#mpWHx z6DdJh-eDK|jXU<(jC9RmR($(yv~B>-dfI`zZ+F=#tyqP5K{po$Oz81BQV0 zzc>XF4!c(7Z2bc-nEu7d2qQ9O+3jA_z(`Nk#QK!B$x&-#6C-VXEo&21wPQzo2~2nY zO5jTv?MtLf@T*h0x%x|3`?%V>dpJ`5;+3vm{vNJpc72Rk$V$l3-$<80mmt=c z`AXb_i4I#bmYZpH6Yi_%h4HWX?Y9d%Iz#5L+<6E6lpKh&CfEaS--L1G?3atXLnZoB zPE~X_zvZYQRL_w)(c9Cppvw1AOT)1E^XV>9kv-Mwam016)(Og^GFQSIV!kezI{KQn zKjvJK(W*CRYj{z@^?k0K*LkQ`x*NIWpGHrWK={9n-tQ+2|9=+8*332UH}Z__=}RY* zmb_jUy9PF4yQ;))s$b=4X%s)ZAn!odW=*Dc^?FwPu{iql7q7y-hMeYC1;0spY!GW2 zRgIq(GCwSB6DBVVzl~;oLJ;g}ji(uo7ZzJzMqc6E4ypcjVEcA`?b=#NL;aV&t#glV zbJu!YCS8hT%^~EXckVD|jmc5s`pV5gFTgPU^eTJlWsiq!*=NVM(Yv|E{2tFJJ_MGJ zYB)V9ZwwI3OTlriHCOB;^CeFB9`a!^cG_?)6$n(b)_HWhuk`uS$McnSE#nukAK%#R z+cIKOmv%`~2pl zQcTFb=5gb@Vk_$Ox)^R-4ZDSsch}La@tF;^q;>Ih+Kl^L4$gP#YlFVBIcwFoQurU| zRVy#2sCxeZCunG1Ojc`tAwOJPpXby@MoULtpG)TBgs7prgR?g(`rYa+tm?-DyX3E2 zQ0Vs@SMig?BpOHXa!nW;7pU(PF(cGsO6&KzPi4s$Blh}xl=X?nEPFSL=rrH~N1 zpL1d#g;5#(I`8@ep9qhk6$WF*H&bXb@yNAHX?)L_GJD63iawh!Pup5b+>s2v%1L98 zSqt=dt;vWz>{^*l^(OJ3k=2unx8qFaYtAVfX)teO>DD}Rk~%=RY^)(>HtV3?nDauG z^3ezCE3&C|eIF)B+nJuaY!$K9x}R@&vk+*W8qs?FqPMjc7rcG-WJ~u~%K&RP^MMhz zBZ1akpUwyxdE)&Pat>dott?(XR>)O81TU}XHtG+&%rg1b82j!N?YPclp@W3Z zDoc3{RzbN^lPo*buzRpSf8BIYMPe){-$GwcwD zSf9(*p|f9O=Hwf{&Z~O`t(!RMEpwioG2Z{h{Zi(Rf-#P#HG6+0(br=qg_t~7P z-F!otcTYBxXJB&qZl}V2-uj0`?qcucBeyq^UaCrhcps9)NB7TTXaz_3a){XUTMj5v zP1{iPw2(IJ$sCck3@`Vg$rx3B8#Bs&?;Hc=!G+4=eo}|{M-H7fA0T9sl)n_ zhgf2sp>b^mSC2i~k*7zAu3W}y#jicTA91B)gZUhu+H0 zTs>bCB^vi?LjR71CT^36CoD+JSC8>34MC&kQ|9U>x2Jy2y4uH-Cii#t>Fjw)(?`~s zA!Rx`wm|h%4oCT=cx|gGKf=Clo=hR&+L=6``n#f;naz{&A4!j^G2J784>oc(YNg!I zYbrHA$II1Upc%EMX*j;r-?c$Eu@Y>pwPZk5c~EX@|G~WpXIr(-ZhfSo%MuXG(mYuF z;Xv^h)&6;neuu~YfibQjz5W;TUFGc>6(22KJz0Cp-KtuEUnF`yvA2-tPFFiCWpg^X ztg*foo;yn)Re9&Nx%c5~1%i**co6@9>I+@nd&Fu^AE~*YGIheZ@CHhg-Q?l*s>@O4 zsdT1eMv;WBxUOY}DN~bJotU4QgV{_~Z`DJ`W`l}IhCRsp?MoCSTlqUR#uFdh*(mjd z4#bR&^3F1^(`38cOgt7MPwmihMEO{3ldHCg=z~Pbn9FO2_IbAB3BNl{ynS+CS_= zli5(~x5Ev4l{ zKE++3dCoUIQCd8w*C%%B)4kxGCapQc2f92=-^|z!W@IC$ zc;qW#IKFH~bIV0LyG;noMHle-OF#{=@#?S)V~}A8S&|94rQm7Px5mwLUqbF*u=+sf z_^ggY_h`F@X?lsu_t~hC{VaTBmw6(7W#oT;n{xQSj{5JX;$MybZ~RkO5>o6OQuLw6 z|Dl*JjOA6239$H_<=H`K)UJ>?>Vu=_*-2l8QKTzd)1Kh+o}d|io1bmK`N{tVB?GyBM^JWvpuAOW+?g}ak_%dUa_Tap&mNqJSkva`tY|ttK1%L>&d_g05V4R*x#`@RTpyD+DYq}8 z*w+83ppfoFd+@Cn7OecATap)5*%h^A%9c!1G)BBpkC+XD6prN+LA|haf z(+p5H(!cuA-DcHN^3bw+hR|zgTg$HD>$&T)Yw(4_W`=0&?Z*Pafo{3(_ir7)r;4pv|1dh6)zKI6wA`Huq!xwX%@V@CQr=Fub#Mn%r#L= z?{x0qges@f{9&07O0O4qM~4=fUadY0H_zfs3RGE`QnWpycJodBlh~c06sKYF6{VBb zXW7ntz9C&MIr@!PkoH2fU!+u88A18$XC`YDZ7WuOiUpI8XJ30Pn@^i=opu$JdwI$- z`q=f(kR)utaWD~n?=0V;ZOo8bb(KmEi@l%tl*xAMnhy9aW3;cci z7?e%NM%#QpGm#Fm2CpuvdpR$f0JfK${$V#6>&_p3+=UOEWYd8ZCv9>|Z73}Br07=e zkGww;#;IJPR*^bqG57wCOf4~!>A|%+*U$Cn{oX-j7ltZH1V1>+eY=qp;qqb{By(eu_ZK1PA|GD*t;4<_80D{kwENaQvzM<3r!`_v(<&-plTM zt3-S0llm#myk`9i^v2UuAAahO(s`K9CTOvefXGM~^?ZK(?Osb{m)xQY9l<4LBl8E9 zP8to-;}$pd2R5t=@)?beQkh=Uup^F6fNhr;9(*PLkRW*VYh5TVjr;Q0eL}V%C%V%$ zwlQ6OZx&Sd1qf>Nmuo+{V`U;gp>wt*uvzy0DK@S!|1!~%2nD9oijIBzDn6~e47}u5 zmNhb$>vyL`!4=c+aa&2OJZkMdN#)#@1zE7dhD?mX_n10UFhxGuP1K}BKf_850@D9M zOn;xO2?@+wGv~bCYB09nkkz*MmUX({BI|S*&86kn??i7$Lya+2e{6X@%1F2uZqOgxN)L)W#NBD2$)s;(1Jka1V{*(soxv^`3oy*3 zhR>^Ny-e;FuUcCj4Qv-NuJev=)<@lrgmj3%NlYh6fgHixx!C?AdKMS!E$Q}QT59_;nS(jJAPi0TDvz%%~))V%c*(PEtUQ8X~w>fe9!1F0&&ip zG9O42+9;otoe)4K6+dp0Q%fFaJBCYcOIdPZnRKrg$OPedu_daTWY2k}S2nv|=oe7T zu3vYs_KHhg^@-cFoWa|X`_)R`S6PqEM5L#KtXMJHvq*g7>VAz#gjI%>{!N);cg6{C z*;(->SA}KS=q>K*S24o+-@ripM6GmHTw}ol~cQ}|8b9*b3EkSQu~GV3WX(@19#wSMz7)E z{cY)wo)_S&wFXYu-eu#vD!9ej2kqj@SIdRZyzrNexBJ-7$CDF&=FYKUmRdK@=PZ@N z!akNQiDO4oS0@7k*r^+ieA}ODUht}mI8nG_{7Ps}Y2lNzb;E8iwFu*70=(Zp{Ivb% z$m|If>~!)4RfWeR*+-nLyXO2vDG>_4t$k@d1frd}mzV55FIYqm*hzW`It;FtHr>6y z?q;hXH*qSQy6naEWv|bViPjE%Zf`YZT2ZH?Y~`e2A^30wy>fHECtb>Arw^-C!NaVl zN!Q4mq_Bm@lyqf>SX8`oeTJLoB=HXQiSIg3M!t<)$}2q7YPIQqd%3Pbp`89r0Bh<% z_XYN6QR+B>);WHM)%99wMgm8A(rwN(6_vw%q@k&{w<#`%Ti&=^ zLe|TkrPba`WUiqbd=BGna4WS#qomi>pX|nw>E7U)1c_VmGxUuK6}QS=NUhWd`)K?b zhSkbvTay zH>I*qDcdnYi{oyqq5fd@#DP=O6|Otgk2q6o4NKT%9Jd3&hnV;Ni5lKm?m=R z@yUp@wz?AGL7f7w_bJ~Wp?NEa5IoU+%SgJ}U@0KLv3k0_OjySz?i8fo5PJ13HCKH4$-REN4vUuF#jHK5{fAzc#0s@{7*roFtC!Uo ziRGD$RIHiwU2GRqbZbl5dYokcGJ8TvHP;|s@KV&Gl*zHevsY#v3dNE?vi+IAbJqFR z@^<+<@gMlRq@$VfH~!9Y=>G@)&itqR-GNwCPaasb(C%XU9e;EFBY$UXDyjUAzY{m* zWPZ=z7=!KI{Qgh*n{;ub>+k%n*z%pf8Fu;m$S!|R`oyY`69@0B3QLZQXFiYwS1*(Z2-kHzI8M+T^(3LFGvkzwN~pEhk-HyI>Tx&M z$-bR6!+RfUUXHuYm)|nbyEC-Ny5`%-PLtX_#z$$I_57%fkLAtA16M-qpHo|=Q7dI! zDp9JE4fZ{qN*+8>iF6lEyVS==**|4-SV$+Xl|@(=0$+FgK8lM1_1-B-)_>sdyZ?&6 zJ*%)qf8+0?Tl&A_?^vwwKj-i381Y~EJ9M_O$>G2x*F0Yz;Sc_PZTOwPDIe^Nse4U- zE;}!O2bm$j3VQ@6T`CJ*=&VmW&vxe_#;}>bLCv0X-mV#cg#huljJ6aU3_6Loa&)5- ztJGYy>L2m``o+@v+e7xQ7AZwq!MMOY7lTK_iZt>$;nhC0KT455AbfuV<=}|2So1D~ z*N@1*4R>sy618!?aqhDR-+N;BuaT|$#1iB~ug`JaPMp{%==@QGOwfmIT(hhQPw)aA(n&%lbGZ5N^${(yl>vj zN$OkZ7|=iev?C?Zc>t^}G@TnP6Zp7AOYr5GCKYpC!X8PV)mIhjG^3*?3Hch=n_F&W zu`g=5BWgU~cEW+-ZNHv0o>aOn%`pVT8GTW0&x%+^y0pS{n6wf@2wXO#)>z zR&~3ZM`~?pCnNGUyb4KlQQ^2H2+zJ?&rU2&2-&eKVoT5uhBDKKH4vXKCfwd z%Pb@Qbo#hMN2M3lkcYaH&3T!<30*Hd9E{RR3wvVn*y;|bz_zdpt*EH>lf-j*E`+bb z2+i{!?-+!F^Q)gfV9b5lr{lfr>gAPJH@bUHtv29Sj&s_uQQqX0~`6-G3#V~)Ekd| zOex)pH1*PAChq_|3wxVKez2AGc2W5FwvG0 z743U-zrCqK`NP_|q)YzhnDCLfL;CiSCU;K>9CX|l@QyI@kWBNnDA|(@S}j6cO^DKx z_L6a)_3Aa@uoK53x@O&~iv||tdf?milHO6qeXO49$yU?V^ZEW+oF*azSIH|dS1<*4 z*Z0}<*(9~)#0-_6ynR>RMK=3N-Qc46id^Ic>{pNBbm!hrq*C5fpU8NN!+ej}XScfK zt9J+(67-!^TKd)%b{;P;t@Zx72{C7bAH|jo z4R3kIy=6WNANkh>QN>o_p7%8S&DzqZ`?zFeo_y82*m5w_@&RTyv&+sg$V_!oxg6j7 z^lWrw3uGsL;l41vB$>}eHRx=((mpeI2h!55N0F61r&_09ul0$z^NQ!PUYuT&A^UajD)vW4cPS$R24V$tXc}4KE-r*wkKJ7EC`t9_^4)>&+otpi%{MQmgmXdQk8l=2#2eGwA(~$1`Fkoxf+MD|3EKFLty099TKLIAeRjc#-TL|AxBO4_NLxAg_4v4Yb&9#Wgt%xPyl^`-T0!$J zS0VKYPU_F)9V+@qr|>=DMLg=dk2I$}GNd>IYM8W?th`g4EpIdxZ$0BoIOr;Q{n~(Y zk*Z2h&P&nqSO*@(+>;uHx4G#pD8{12ACSBg&Ms^f+1xAVb90G+PtwNR1EZFZTlcQoEzILzCYl5sl)I;PoGNp?qrk#s3|@ ze?KX|w~C+h`;yLp4AL*E7gS8_WVVPf9+1BCCSuUzh?C8xBRAvqvIiY$LWbHm?y3i| zs%+07Mt);=IpUa-X;^OY$8BC*nj9bR{~BE7VD{44+S9Wl=z{{=u;k3(@ZBqt*plI8 z15PCErAV`vZqHTcA;m41hdHWgUk)WieRXAYAQmv0#cg8Tq3R$P@^)5vzradP zvbVyVzDJ|m{=qXw6+^N2x#rgmOlM1lDAp7ADtby%ebMY7{hF$Su?#@lwvtW;<~zJM z2&u~v#OufNc+;pqb>}6~YjL^Bna_R@+f7vT?zvDnS4ekuO%30kH@!ppd-H2MJ5xZTH|i5DdubVYD9$WqCK z|6;PmLhb8PuL{@gsX9w;a$^mbKv~s`R(BR%Q}p^H-3Hjs+303Bm|M`;#kRLtW$a-x z8Y~Z4NbL8h&ElwEsOvs-WsCcpNB3^&-J4&^o6$Z}$d;Blj;D0&oLK8#N;&Pjea|=K zpODbxbHWz0#p!v|w^H#pMMRPXYj-Q|gI!^6wd+IdxM&mgeM5_wwR5Z*nsX%GUIdW4Z}-%FqFwlm>@oTHR3RHzorB@cz87Yl zWM{8v%lH^dPnh!NPIWw=XbslmoVePuyO|)jU|51aQQSMZ_7v@l=Swa%Z(J4HDMabl z-$HG0aacPmpnhoD^unlTS95*m9T@dKK1XqBe z@087bOmR#LtxVM*KQ?1?Io4gP*@DqhbYeT6?!k?glEqh*E4PR@3o9oP-s0_A(f3A+ zp1WHKG)Q$vD6a%p#*^;I6D{@n?)ST4`QB_RFuhE?@*(S!AiYR@cl((O!^CF}(Y22# z<_Nt`J#vncX+(Btw}$>mNs*3ugjehle*^WY5fRJCxk?g+5rMZ6Z+yrzMkVfq6$N~3 zuD*Jn?oKxylUC)S*PD(Np{2?xpOQp&cK2?P@A*L3-|>IT?=t_M-|ZDzR!G<)@89U$ ztHWDToM_^3?%YA*n}$-0ApSzoC*^_1=zBu$+zyw~M;ZG@NmsCM0!n$_ z-iR|y6OuX0VqzR=*LK|aQFz-p*Q+SpI1Z7wqjT^-H4`1 z#!Z^COW$u1e-Gl>G~wB%{{Y}s|C&wy?*3+<273_8hw@t8@*YhkuXLfpJ4Eci*)BWr5(ffd}rdcjlWFQ&v(gn_W1`S~K3| zidKajWr`SgJ;GQ-$$LMY`}9zX?#PWQZSy;i=nRR!Y118Eq*pjX`2G`<%GnLf>%8MS zVKNh;yx&MMew;oxIv@3N%A8&>p8)~_7q)t@uj+(>m%#zUWZb5nWh|~Wazkfd| zzjum%!|x}bEgicjJA9q?n&XpizZ7pySMR?b{v|W~xI^*O?mrmO;18&y9d?~xE%+N1LGPJ1f#I{8E=_YL*M@@BVE-MJ z`yXzfuzaTd!0uD~#mZ@{V_88y-;9ddNDV6Xn2m?I%RuCdPxmq_9WWifl0uCA@XGJ% zCPp*{Cr2%Q@A6(*ngU{FRVB@f*T{9yB10l9wJ_J?Jn^K|_fyS=G8ycA7ul=d$v&f4 zv^$AWTGh? zzjm)R9JcJ=?Dh=KV(;0T_o|O%E#Q8q^HF(Sy4xqb=flN4$J{*SE^%sYcysSYqxgW@~B zXKy<$dj1~YpP7Eg_fs87-|;>1&-gCBi|@7H@m(ar{X4!-{R!XaCN>WI5#Q~nzT>;= zFZeF-1K%fq#do>i@I7UDhrP7uL!V21zgHr|Nxr2A7vj&ah6=jA9Jae@zZ_jJMgCr* zdY%5Fq~BQYDIo^0riF`Hw);fI}UPjysRZQXj{ayoIRprT3Z@>OlyryCkwo9?Gz-bA(y>C|P)jEDPKzuM4IZF7*! zJ(PYMW#Pm2@u8Jz__<2TjF%7So@p&|RMx$-U=2rJue;`94LP0! zX{F!F zxgGCfann)kJ-c}@`}3_3%N?!~`V&G6Y(q5+{a#IB+=3+LJ)=MXS6E;>N z!92x>_G#n&)eiJUFJ*-YDb%~x4QDzTW}cb(tiDW%yr!{lL4Q%~R!RRD1<9!>Uskq4 zH&pt7u%O{I$Dutk3<=st?W51hCM@26ld67G4ZD9mI_Wx*X)9mHoeFsi^WoFu^G~gU zSvmCg<@L#vyb1tMC3H$Ys1_M<1dntcnK$0jXvSdG zy#w$Bc{o~p(cNQeYx1I-nY}2yK$YZCm-+BK6b_Q zX#Sx=%w^GMd3a~CiH+K;O6wWLte+pI>(1PC-D_5R{;uGwi0VF0e%S>|k8^TaJ<=7J zr0r|hwR61}**G6ebWR?KIa6eI^P1GD(}yD?Oxr~Nzsbmadn&OYF57;2z2M)79d_ND z?A`XKeJ!oHpl;$ZHSWUn3+r2jQ_k{v<^<*3s#Rn^U^rFNcZ#;Y_%`6m8Ls_-wV;(V zrxsuT8Ti>Z>h&fSC9M~U(%S3xbk)r>a=)9lSwoD`S4d|EU*FV~vjf*(RX=-S@}#W3 z>=juSmsIL1V`j6@WGK0BFw-zt+s+*{?_RUd;w6_rt4rq2e;lX68blwbFY;KE{5vc$eWUpD;PC5ZD}TRL z{(ALLSypVkp=eO5_UqVh92q|+u)4Qz)Op+PA}>-sqmVa6{hL`;&=z?M;j^bcioe=r zx@FbV_wSEAnouOHb1~tsM#bl**L=Iae{zni{u5$0Yn^RDyu4;irMT_9SC!HGmOuG@ zfiovRa{B&MnT-kl;=iq<_N=}erfA&xwfPdi>Z)xEnddJ2bHVJ{_xkfC2Y_QR{Rba^ zV2L?#dvawp*St2pn3nVhkrjM;2R|1`#x;mPRIQMVYYczLwTEr}Vd)QQdsxFC=I&s7 z?{J*s?%iMci5m7z=dSHP?YzU{PSmW|y`}A&OmytQBMWKQT#jBPVgTNhwDKLt0K6Hv zY&S$L+mVI|a5B-x-}inIxKZcmt-n{-)uMCmjM66xx8Jon~rcYqEHv-PQevq!(Y~4{FomXZsQQL{?qp zbNurImnJM!OS4@zAswruS2PFC~fAbx7^-uVR=qeTOF3kGkzQ4&Hu#k*_s~X^!H5 z;hp*qCVp;s9U|8DZN|r}{nNre>*VEtZ?f#sUv*- z?YngZb(X9P|9VSy`OPd->%7~!vlFF$JHER)OZWVw`(8=+G>)+a9+J@$aSk~8J)%od zBx_RC;-%knCvi%-*w(bOj*h<%qw#m(M!pRXb#y>wKSks38(!J9A&x@jU|r@cbO`Hby<Ltuz*jXFaVyB1FWyX$H%Y%&x{EyWQUv`0XsgX z6Zi2k9N^<)I8!4yfd=>hcj8Ao=2gZPa zPXR|YKmk}VU>abAZUFMJ+o%Ry;KF8rF}eZB=b)k*uz(wz0Ve1MARj!6YCr&RT{)%~ zfU$xa3&MR;`Cn6t1VuNBnj|w^F zBO2N0K0!XR!yLt?Uj%Hz*j$e|8hN?54~qS4_9WVmh)=A`#8LgH{Eh`y6=*0BW3b106zA zcoVQ0x9^c>yiwzPNdSp%z>&{Ev)t%DN1hu)jdM#Nmn5I#u@$$kk!O`q>G2uS2n0XY_vfvrL)&_tul_#pxoX%HHy4>Wqju&xxs2adA tracks) { return bank; } + + public DataBank fillAIPrediction(DataEvent event, ArrayList predictions) { + + DataBank bank = event.createBank("AHDC_AI::Prediction", predictions.size()); + + int row = 0; + + for (TrackPrediction track : predictions) { + bank.setFloat("X1", row, (float) track.getSuperpreclusters().get(0).getX()); + bank.setFloat("Y1", row, (float) track.getSuperpreclusters().get(0).getY()); + bank.setFloat("X2", row, (float) track.getSuperpreclusters().get(1).getX()); + bank.setFloat("Y2", row, (float) track.getSuperpreclusters().get(1).getY()); + bank.setFloat("X3", row, (float) track.getSuperpreclusters().get(2).getX()); + bank.setFloat("Y3", row, (float) track.getSuperpreclusters().get(2).getY()); + bank.setFloat("X4", row, (float) track.getSuperpreclusters().get(3).getX()); + bank.setFloat("Y4", row, (float) track.getSuperpreclusters().get(3).getY()); + bank.setFloat("X5", row, (float) track.getSuperpreclusters().get(4).getX()); + bank.setFloat("Y5", row, (float) track.getSuperpreclusters().get(4).getY()); + + bank.setFloat("Pred", row, track.getPrediction()); + row++; + } + + return bank; + } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java index 511bc5807e..6ee4bab6a0 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/Hit.java @@ -128,4 +128,6 @@ public double getX() { public double getY() { return y; } + + public double getPhi() {return phi;} } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java index 2ccf99b1ae..ed27d104e9 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/service/AHDCEngine.java @@ -1,11 +1,29 @@ package org.jlab.rec.service; +import ai.djl.MalformedModelException; +import ai.djl.ndarray.NDArray; +import ai.djl.ndarray.NDList; +import ai.djl.ndarray.NDManager; +import ai.djl.ndarray.types.Shape; +import ai.djl.repository.zoo.Criteria; +import ai.djl.repository.zoo.ModelNotFoundException; +import ai.djl.repository.zoo.ZooModel; +import ai.djl.training.util.ProgressBar; +import ai.djl.translate.TranslateException; +import ai.djl.translate.Translator; +import ai.djl.translate.TranslatorContext; import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.clas.tracking.kalmanfilter.Material; import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.io.hipo.HipoDataSource; import org.jlab.io.hipo.HipoDataSync; +import org.jlab.jnp.hipo4.data.SchemaFactory; +import org.jlab.rec.ahdc.AI.AIPrediction; +import org.jlab.rec.ahdc.AI.PreClustering; +import org.jlab.rec.ahdc.AI.PreclusterSuperlayer; +import org.jlab.rec.ahdc.AI.TrackConstruction; +import org.jlab.rec.ahdc.AI.TrackPrediction; import org.jlab.rec.ahdc.Banks.RecoBankWriter; import org.jlab.rec.ahdc.Cluster.Cluster; import org.jlab.rec.ahdc.Cluster.ClusterFinder; @@ -22,14 +40,17 @@ import org.jlab.rec.ahdc.Track.Track; import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.*; public class AHDCEngine extends ReconstructionEngine { private boolean simulation; + private boolean use_AI_for_trackfinding; private String findingMethod; private HashMap materialMap; + private ZooModel model; public AHDCEngine() { super("ALERT", "ouillon", "1.0.1"); @@ -39,11 +60,42 @@ public AHDCEngine() { public boolean init() { simulation = false; findingMethod = "distance"; + use_AI_for_trackfinding = true; if (materialMap == null) { materialMap = MaterialMap.generateMaterials(); } + Translator my_translator = new Translator() { + @Override + public Float processOutput(TranslatorContext translatorContext, NDList ndList) throws Exception { + return ndList.get(0).getFloat(); + } + + @Override + public NDList processInput(TranslatorContext translatorContext, float[] floats) throws Exception { + NDManager manager = NDManager.newBaseManager(); + NDArray samples = manager.zeros(new Shape(floats.length)); + samples.set(floats); + return new NDList(samples); + } + }; + + Criteria my_model = Criteria.builder().setTypes(float[].class, Float.class) + .optModelPath(Paths.get(System.getenv("CLAS12DIR") + "/../reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/model/")) + .optEngine("PyTorch") + .optTranslator(my_translator) + .optProgress(new ProgressBar()) + .build(); + + + try { + model = my_model.loadModel(); + } catch (IOException | ModelNotFoundException | MalformedModelException e) { + throw new RuntimeException(e); + } + + return true; } @@ -78,11 +130,14 @@ public boolean processDataEvent(DataEvent event) { //System.out.println("AHDC_Hits size " + AHDC_Hits.size()); // II) Create PreCluster + ArrayList AHDC_PreClusters = new ArrayList<>(); PreClusterFinder preclusterfinder = new PreClusterFinder(); preclusterfinder.findPreCluster(AHDC_Hits); - ArrayList AHDC_PreClusters = preclusterfinder.get_AHDCPreClusters(); + AHDC_PreClusters = preclusterfinder.get_AHDCPreClusters(); //System.out.println("AHDC_PreClusters size " + AHDC_PreClusters.size()); + + // III) Create Cluster ClusterFinder clusterfinder = new ClusterFinder(); clusterfinder.findCluster(AHDC_PreClusters); @@ -91,19 +146,52 @@ public boolean processDataEvent(DataEvent event) { // IV) Track Finder ArrayList AHDC_Tracks = new ArrayList<>(); - if (findingMethod.equals("distance")) { - // IV) a) Distance method - //System.out.println("using distance"); - Distance distance = new Distance(); - distance.find_track(AHDC_Clusters); - AHDC_Tracks = distance.get_AHDCTracks(); - } else if (findingMethod.equals("hough")) { - // IV) b) Hough Transform method - //System.out.println("using hough"); - HoughTransform houghtransform = new HoughTransform(); - houghtransform.find_tracks(AHDC_Clusters); - AHDC_Tracks = houghtransform.get_AHDCTracks(); + ArrayList predictions = new ArrayList<>(); + + if (use_AI_for_trackfinding == false) { + if (findingMethod.equals("distance")) { + // IV) a) Distance method + //System.out.println("using distance"); + Distance distance = new Distance(); + distance.find_track(AHDC_Clusters); + AHDC_Tracks = distance.get_AHDCTracks(); + } else if (findingMethod.equals("hough")) { + // IV) b) Hough Transform method + //System.out.println("using hough"); + HoughTransform houghtransform = new HoughTransform(); + houghtransform.find_tracks(AHDC_Clusters); + AHDC_Tracks = houghtransform.get_AHDCTracks(); + } + } + else { + // AI --------------------------------------------------------------------------------- + AHDC_Hits.sort(new Comparator() { + @Override + public int compare(Hit a1, Hit a2) { + return Double.compare(a1.getRadius(), a2.getRadius()); + } + }); + PreClustering preClustering = new PreClustering(); + ArrayList preClustersAI = preClustering.find_preclusters_for_AI(AHDC_Hits); + ArrayList preclusterSuperlayers = preClustering.merge_preclusters(preClustersAI); + TrackConstruction trackConstruction = new TrackConstruction(); + ArrayList> tracks = trackConstruction.get_all_possible_track(preclusterSuperlayers); + + + try { + AIPrediction aiPrediction = new AIPrediction(); + predictions = aiPrediction.prediction(tracks, model); + } catch (ModelNotFoundException | MalformedModelException | IOException | TranslateException e) { + throw new RuntimeException(e); + } + + for (TrackPrediction t : predictions) { + if (t.getPrediction() > 0.5) + AHDC_Tracks.add(new Track(t.getClusters())); + } } + // ------------------------------------------------------------------------------------ + //Temporary track method ONLY for MC with no background; //AHDC_Tracks.add(new Track(AHDC_Hits)); @@ -138,12 +226,14 @@ public boolean processDataEvent(DataEvent event) { DataBank recoClusterBank = writer.fillClustersBank(event, AHDC_Clusters); DataBank recoTracksBank = writer.fillAHDCTrackBank(event, AHDC_Tracks); DataBank recoKFTracksBank = writer.fillAHDCKFTrackBank(event, AHDC_Tracks); + DataBank AIPredictionBanks = writer.fillAIPrediction(event, predictions); event.appendBank(recoHitsBank); event.appendBank(recoPreClusterBank); event.appendBank(recoClusterBank); event.appendBank(recoTracksBank); event.appendBank(recoKFTracksBank); + event.appendBank(AIPredictionBanks); if (simulation) { DataBank recoMCBank = writer.fillAHDCMCTrackBank(event); From bd001db854a0ad8aaddaeaec07156930fece8cc7 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Mon, 16 Dec 2024 13:40:16 -0500 Subject: [PATCH 50/51] Revert "leave internal indexing at zero, output at 1" This reverts commit 3420bb97c4c247c079dc5479f161f5a799f79848. --- .../org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java index 6fb2f19e2e..ba4cd181be 100644 --- a/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java +++ b/common-tools/clas-geometry/src/main/java/org/jlab/geom/detector/alert/ATOF/AlertTOFFactory.java @@ -49,7 +49,7 @@ public AlertTOFDetector createDetectorLocal(ConstantProvider cp) { @Override public AlertTOFSector createSector(ConstantProvider cp, int sectorId) { - AlertTOFSector sector = new AlertTOFSector(sectorId+1); + AlertTOFSector sector = new AlertTOFSector(sectorId); for (int superlayerId = 0; superlayerId < nsuperl; superlayerId++) sector.addSuperlayer(createSuperlayer(cp, sectorId, superlayerId)); return sector; @@ -57,7 +57,7 @@ public AlertTOFSector createSector(ConstantProvider cp, int sectorId) { @Override public AlertTOFSuperlayer createSuperlayer(ConstantProvider cp, int sectorId, int superlayerId) { - AlertTOFSuperlayer superlayer = new AlertTOFSuperlayer(sectorId+1, superlayerId+1); + AlertTOFSuperlayer superlayer = new AlertTOFSuperlayer(sectorId, superlayerId); if (superlayerId == 0) { int nlayers0 = 1; @@ -94,7 +94,7 @@ public AlertTOFLayer createLayer(ConstantProvider cp, int sectorId, int superlay double gap_pad_z = 0.3d; // mm, gap between paddles in z - AlertTOFLayer layer = new AlertTOFLayer(sectorId+1, superlayerId+1, layerId+1); + AlertTOFLayer layer = new AlertTOFLayer(sectorId, superlayerId, layerId); double len_b = layerId * pad_z + layerId * gap_pad_z; // back paddle plan double len_f = len_b + pad_z; // front paddle plan From c251ca3b694a84010a60c8165e28f9fdef1297d1 Mon Sep 17 00:00:00 2001 From: Whitney Armstrong Date: Thu, 2 Jan 2025 12:21:59 -0600 Subject: [PATCH 51/51] Better names for constant fraction variables - https://github.com/JeffersonLab/coatjava/pull/378#discussion_r1871880348 --- .../org/jlab/detector/pulse/ModeAHDC.java | 39 ++++++++++--------- .../java/org/jlab/detector/pulse/Pulse.java | 8 ++-- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java index 2d4aa03c02..d01b1b3e36 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -49,10 +49,10 @@ public List extract(NamedEntry pars, int id, short... samples){ short[] samplesCorr; //Waveform after offset (pedestal) correction int binNumber = 0; //Number of bins in one waveform - float timeRiseCFA = 0; // moment when the signal reaches a Constant Fraction of its Amplitude uphill (fitted) - float timeFallCFA = 0; // moment when the signal reaches a Constant Fraction of its Amplitude downhill (fitted) - float timeOverThresholdCFA = 0; // is equal to (timeFallCFA - timeRiseCFA) - float timeCFD =0 ; // time extracted using the Constant Fraction Discriminator (CFD) algorithm (fitted) + float leadingEdgeTime = 0; // moment when the signal reaches a Constant Fraction of its Amplitude uphill (fitted) + float trailingEdgeTime = 0; // moment when the signal reaches a Constant Fraction of its Amplitude downhill (fitted) + float timeOverThreshold = 0; // is equal to (timeFallCFA - timeRiseCFA) + float constantFractionTime ; // time extracted using the Constant Fraction Discriminator (CFD) algorithm (fitted) /// ///////////////////////// // Begin waveform correction /// //////////////////////// @@ -129,25 +129,26 @@ public List extract(NamedEntry pars, int id, short... samples){ //computeTimeAtConstantFractionAmplitude(samplingTime,amplitudeFractionCFA); /** * This method determines the moment when the signal reaches a Constant Fraction of its Amplitude (i.e fraction*adcMax) - * It fills the attributs : timeRiseCFA, timeFallCFA, timeOverThresholdCFA + * It fills the attributs : leadingEdgeTime trailingEdgeTime, timeOverThreshold + * * @param samplingTime time between 2 ADC bins * @param amplitudeFraction amplitude fraction between 0 and 1 */ //private void computeTimeAtConstantFractionAmplitude(float samplingTime, float amplitudeFractionCFA){ float threshold = amplitudeFractionCFA*adcMax; - // timeRiseCFA + // leadingEdgeTime int binRise = 0; for (int bin = 0; bin < binMax; bin++){ if (samplesCorr[bin] < threshold) binRise = bin; // last pass below threshold and before adcMax - } // at this stage : binRise < timeRiseCFA/samplingTime <= binRise + 1 // timeRiseCFA is determined by assuming a linear fit between binRise and binRise + 1 + } // at this stage : binRise < leadingEdgeTime/samplingTime <= binRise + 1 // leadingEdgeTime is determined by assuming a linear fit between binRise and binRise + 1 float slopeRise = 0; if (binRise + 1 <= binNumber-1) slopeRise = samplesCorr[binRise+1] - samplesCorr[binRise]; float fittedBinRise = (slopeRise == 0) ? binRise : binRise + (threshold - samplesCorr[binRise])/slopeRise; - timeRiseCFA = (fittedBinRise + binOffset)*samplingTime; // binOffset is determined in wavefromCorrection() // must be the same for all time ? // or must be defined using fittedBinRise*sparseSample + leadingEdgeTime = (fittedBinRise + binOffset)*samplingTime; // binOffset is determined in wavefromCorrection() // must be the same for all time ? // or must be defined using fittedBinRise*sparseSample - // timeFallCFA + // trailingEdgeTime int binFall = binMax; for (int bin = binMax; bin < binNumber; bin++){ if (samplesCorr[bin] > threshold){ @@ -157,15 +158,15 @@ public List extract(NamedEntry pars, int id, short... samples){ binFall = bin; break; // first pass below the threshold } - } // at this stage : binFall - 1 <= timeRiseCFA/samplingTime < binFall // timeFallCFA is determined by assuming a linear fit between binFall - 1 and binFall + } // at this stage : binFall - 1 <= timeRiseCFA/samplingTime < binFall // trailingEdgeTime is determined by assuming a linear fit between binFall - 1 and binFall float slopeFall = 0; if (binFall - 1 >= 0) slopeFall = samplesCorr[binFall] - samplesCorr[binFall-1]; float fittedBinFall = (slopeFall == 0) ? binFall : binFall-1 + (threshold - samplesCorr[binFall-1])/slopeFall; - timeFallCFA = (fittedBinFall + binOffset)*samplingTime; + trailingEdgeTime = (fittedBinFall + binOffset)*samplingTime; // timeOverThreshold - timeOverThresholdCFA = timeFallCFA - timeRiseCFA; + timeOverThreshold = trailingEdgeTime - leadingEdgeTime; //} /// ///////////////////////// // Begin computeTimeUsingConstantFractionDiscriminator @@ -173,7 +174,7 @@ public List extract(NamedEntry pars, int id, short... samples){ //computeTimeUsingConstantFractionDiscriminator(samplingTime,fractionCFD,binDelayCFD); /** * This methods extracts a time using the Constant Fraction Discriminator (CFD) algorithm - * It fills the attribut : timeCFD + * It fills the attribut : constantFractionTime * @param samplingTime time between 2 ADC bins * @param fractionCFD CFD fraction parameter between 0 and 1 * @param binDelayCFD CFD delay parameter @@ -202,12 +203,12 @@ public List extract(NamedEntry pars, int id, short... samples){ for (int bin = binHumpInf; bin <= binHumpSup; bin++){ if (signal[bin] < 0) binZero = bin; // last pass below zero - } // at this stage : binZero < timeCFD/samplingTime <= binZero + 1 // timeCFD is determined by assuming a linear fit between binZero and binZero + 1 + } // at this stage : binZero < constantFractionTime/samplingTime <= binZero + 1 // constantFractionTime is determined by assuming a linear fit between binZero and binZero + 1 float slopeCFD = 0; if (binZero + 1 <= binNumber) slopeCFD = signal[binZero+1] - signal[binZero]; float fittedBinZero = (slopeCFD == 0) ? binZero : binZero + (0 - signal[binZero])/slopeCFD; - timeCFD = (fittedBinZero + binOffset)*samplingTime; + constantFractionTime = (fittedBinZero + binOffset)*samplingTime; //} @@ -236,10 +237,10 @@ public List extract(NamedEntry pars, int id, short... samples){ pulse.time = timeMax; pulse.timestamp = timestamp; pulse.integral = integral; - pulse.timeRiseCFA = timeRiseCFA; - pulse.timeFallCFA = timeFallCFA; - pulse.timeOverThresholdCFA = timeOverThresholdCFA; - pulse.timeCFD = timeCFD; + pulse.leadingEdgeTime = leadingEdgeTime ; + pulse.trailingEdgeTime = trailingEdgeTime; + pulse.timeOverThreshold = timeOverThreshold; + pulse.constantFractionTime = constantFractionTime; //pulse.binMax = binMax; //pulse.binOffset = binOffset; pulse.pedestal = adcOffset; diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java index 9874b3ad7f..310381cc54 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/Pulse.java @@ -16,10 +16,10 @@ public class Pulse { public int id; public float adcMax; - public float timeRiseCFA; - public float timeFallCFA; - public float timeOverThresholdCFA; - public float timeCFD; + public float leadingEdgeTime ; + public float trailingEdgeTime; + public float timeOverThreshold; + public float constantFractionTime; /** * Units are the same as the raw units of the samples.