From e89efc2f2cae015c06c1f0c8d9ce13f69bbd2bf8 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 14 Jul 2026 10:56:51 -0400 Subject: [PATCH 1/2] rich cleanup --- .../java/org/jlab/rec/rich/Quaternion.java | 299 +++--- .../org/jlab/rec/rich/RICHCalibration.java | 731 ++++++------- .../java/org/jlab/rec/rich/RICHCluster.java | 391 +++---- .../java/org/jlab/rec/rich/RICHConstants.java | 7 +- .../java/org/jlab/rec/rich/RICHEBEngine.java | 122 ++- .../main/java/org/jlab/rec/rich/RICHEdge.java | 114 +- .../java/org/jlab/rec/rich/RICHEvent.java | 745 +++++-------- .../org/jlab/rec/rich/RICHEventBuilder.java | 641 +++++------- .../main/java/org/jlab/rec/rich/RICHHit.java | 340 ++---- .../jlab/rec/rich/RICHPMTReconstruction.java | 9 - .../org/jlab/rec/rich/RICHParameters.java | 259 +++-- .../java/org/jlab/rec/rich/RICHParticle.java | 977 ++++++++---------- .../java/org/jlab/rec/rich/RICHRayTrace.java | 509 ++++----- .../java/org/jlab/rec/rich/RICHSolution.java | 698 ++++--------- .../main/java/org/jlab/rec/rich/RICHTime.java | 77 +- .../main/java/org/jlab/rec/rich/RICHUtil.java | 37 +- .../main/java/org/jlab/rec/rich/RICHio.java | 382 +++---- 17 files changed, 2573 insertions(+), 3765 deletions(-) diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/Quaternion.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/Quaternion.java index 69b49fe48d..10807cd922 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/Quaternion.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/Quaternion.java @@ -5,107 +5,105 @@ import org.jlab.geom.prim.Vector3D; //Class created by gangel -//for the JLAB package +//for the JLAB package // -// The quaternion here is defined as: +// The quaternion here is defined as: // public class Quaternion { - //Definition of the components for the Quaternion - public double x; - public double y; - public double z; - public double w; - - public Quaternion() { - } - - public Quaternion(double angle, Vector3D rotationAxis) { - x = rotationAxis.x() * Math.sin(angle / 2); - y = rotationAxis.y() * Math.sin(angle / 2); - z = rotationAxis.z() * Math.sin(angle / 2); - w = Math.cos(angle / 2); - } - - public Quaternion(double w, double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - /** - * Set the rotation Quaternion - * @param angle the angle of rotation - * @param rotationAxis the rotation axis (normal two the vector plane) - */ - public void set(double angle, Vector3D rotationAxis) { - x = rotationAxis.x() * Math.sin(angle / 2); - y = rotationAxis.y() * Math.sin(angle / 2); - z = rotationAxis.z() * Math.sin(angle / 2); - w = Math.cos(angle / 2); - } - - public void set (double w, double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - /** - * Set the Quaternion using another one - * @param q - */ - public void set (Quaternion q) { - this.x = q.x; - this.y = q.y; - this.z = q.z; - this.w = q.w; - } - - public double getSize() { - return Math.sqrt(w * w + x * x + y * y + z * z); - } - - public void normalize() { - double sizeInv = 1 / getSize(); - x *= sizeInv; - y *= sizeInv; - z *= sizeInv; - w *= sizeInv; - } - /** - * Multiplication between two Quaternions - * @param qb the one that multiply - * @return result of the multiplication - */ - public Quaternion multiply(Quaternion qb) { - Quaternion qa = this; - Quaternion qr = new Quaternion(); - qr.w = (qa.w * qb.w) - (qa.x * qb.x) - (qa.y * qb.y) - (qa.z * qb.z); - qr.x = (qa.x * qb.w) + (qa.w * qb.x) + (qa.y * qb.z) - (qa.z * qb.y); - qr.y = (qa.y * qb.w) + (qa.w * qb.y) + (qa.z * qb.x) - (qa.x * qb.z); - qr.z = (qa.z * qb.w) + (qa.w * qb.z) + (qa.x * qb.y) - (qa.y * qb.x); - return qr; - } - - public void conjugate() { - //w = w; - x = -x; - y = -y; - z = -z; - } - - - //----------------- - public Vector3D rotate(Vector3D vector) { - //----------------- - /** - * public void rotate(Vector3D vector, Vector3D rotatedVector) { - * Implementing the Quaternion Fomula for Rotation: P' = Q.P.Q* - * @param vetor the vector 3d that needs to be rotate - * @param rotatedVector the rotated vector + //Definition of the components for the Quaternion + public double x; + public double y; + public double z; + public double w; + + public Quaternion() { + } + + public Quaternion(double angle, Vector3D rotationAxis) { + x = rotationAxis.x() * Math.sin(angle / 2); + y = rotationAxis.y() * Math.sin(angle / 2); + z = rotationAxis.z() * Math.sin(angle / 2); + w = Math.cos(angle / 2); + } + + public Quaternion(double w, double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + /** + * Set the rotation Quaternion + * @param angle the angle of rotation + * @param rotationAxis the rotation axis (normal two the vector plane) */ - + public void set(double angle, Vector3D rotationAxis) { + x = rotationAxis.x() * Math.sin(angle / 2); + y = rotationAxis.y() * Math.sin(angle / 2); + z = rotationAxis.z() * Math.sin(angle / 2); + w = Math.cos(angle / 2); + } + + public void set (double w, double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + /** + * Set the Quaternion using another one + * @param q + */ + public void set (Quaternion q) { + this.x = q.x; + this.y = q.y; + this.z = q.z; + this.w = q.w; + } + + public double getSize() { + return Math.sqrt(w * w + x * x + y * y + z * z); + } + + public void normalize() { + double sizeInv = 1 / getSize(); + x *= sizeInv; + y *= sizeInv; + z *= sizeInv; + w *= sizeInv; + } + /** + * Multiplication between two Quaternions + * @param qb the one that multiply + * @return result of the multiplication + */ + public Quaternion multiply(Quaternion qb) { + Quaternion qa = this; + Quaternion qr = new Quaternion(); + qr.w = (qa.w * qb.w) - (qa.x * qb.x) - (qa.y * qb.y) - (qa.z * qb.z); + qr.x = (qa.x * qb.w) + (qa.w * qb.x) + (qa.y * qb.z) - (qa.z * qb.y); + qr.y = (qa.y * qb.w) + (qa.w * qb.y) + (qa.z * qb.x) - (qa.x * qb.z); + qr.z = (qa.z * qb.w) + (qa.w * qb.z) + (qa.x * qb.y) - (qa.y * qb.x); + return qr; + } + + public void conjugate() { + //w = w; + x = -x; + y = -y; + z = -z; + } + + + public Vector3D rotate(Vector3D vector) { + /** + * public void rotate(Vector3D vector, Vector3D rotatedVector) { + * Implementing the Quaternion Fomula for Rotation: P' = Q.P.Q* + * @param vetor the vector 3d that needs to be rotate + * @param rotatedVector the rotated vector + */ + Vector3D rotatedVector = new Vector3D(0.,0.,0.); Quaternion quatTp1 = new Quaternion(0, vector.x(), vector.y(), vector.z()); Quaternion quatTp2 = new Quaternion(); @@ -114,81 +112,70 @@ public Vector3D rotate(Vector3D vector) { quatTp1.set(this); quatTp1.conjugate(); quatTp3 = quatTp2.multiply(quatTp1); - + rotatedVector.setX(quatTp3.x); rotatedVector.setY(quatTp3.y); rotatedVector.setZ(quatTp3.z); - + return rotatedVector; } - - - // To finish this code - public Matrix toRotation(Quaternion q1) - { - Matrix Matrice = new Matrix(3,3); - double heading =0; - double attitude =0 ; - double bank=0; - - double test = q1.x*q1.y + q1.z*q1.w; - if (test > 0.499) { // singularity at north pole - heading = 2 * Math.atan2(q1.x,q1.w); - attitude = Math.PI/2; - bank = 0; - return null; - } - if (test < -0.499) { // singularity at south pole - heading = -2 * Math.atan2(q1.x,q1.w); - attitude = - Math.PI/2; - bank = 0; - return null; - } - double sqx = q1.x*q1.x; - double sqy = q1.y*q1.y; - double sqz = q1.z*q1.z; - heading = Math.atan2(2*q1.y*q1.w-2*q1.x*q1.z , 1 - 2*sqy - 2*sqz); - attitude = Math.asin(2*test); - bank = Math.atan2(2*q1.x*q1.w-2*q1.y*q1.z , 1 - 2*sqx - 2*sqz); - - - // to finis the implementations of this effect - return Matrice; - } - - //----------------- - public double GetX() { - //----------------- + + // To finish this code + public Matrix toRotation(Quaternion q1) + { + Matrix Matrice = new Matrix(3,3); + double heading =0; + double attitude =0 ; + double bank=0; + + double test = q1.x*q1.y + q1.z*q1.w; + if (test > 0.499) { // singularity at north pole + heading = 2 * Math.atan2(q1.x,q1.w); + attitude = Math.PI/2; + bank = 0; + return null; + } + if (test < -0.499) { // singularity at south pole + heading = -2 * Math.atan2(q1.x,q1.w); + attitude = - Math.PI/2; + bank = 0; + return null; + } + double sqx = q1.x*q1.x; + double sqy = q1.y*q1.y; + double sqz = q1.z*q1.z; + heading = Math.atan2(2*q1.y*q1.w-2*q1.x*q1.z , 1 - 2*sqy - 2*sqz); + attitude = Math.asin(2*test); + bank = Math.atan2(2*q1.x*q1.w-2*q1.y*q1.z , 1 - 2*sqx - 2*sqz); + + // to finis the implementations of this effect + return Matrice; + } + + public double GetX() { + return x; } - - //----------------- - public double GetY() { - //----------------- + public double GetY() { + return y; } - - //----------------- - public double GetZ() { - //----------------- + public double GetZ() { + return z; } - - //----------------- - public double GetW() { - //----------------- - + + public double GetW() { + return w; } - - //----------------- + public void show() { - //----------------- - - System.out.format(" Quaternion axis %8.3f %8.3f %8.3f angle %8.3f (%8.3f) \n",x,y,z,w,w*57.3); + + System.out.format(" Quaternion axis %8.3f %8.3f %8.3f angle %8.3f (%8.3f) \n",x,y,z,w,w*57.3); } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCalibration.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCalibration.java index c6b430b184..00ae47b625 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCalibration.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCalibration.java @@ -5,13 +5,7 @@ import org.jlab.detector.geom.RICH.RICHLayerType; import org.jlab.detector.calib.utils.ConstantsManager; import org.jlab.utils.groups.IndexedTable; - -import org.jlab.geom.prim.Vector3D; - import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import java.io.FileReader; import java.io.BufferedReader; @@ -20,66 +14,48 @@ * @author mcontalb */ public class RICHCalibration{ - - private final static RICHGeoConstants geocost = new RICHGeoConstants(); - - private final static int NSEC = geocost.NSEC; - private final static int NLAY = geocost.NLAY; - private final static int NPMT = geocost.NPMT; - private final static int NPIX = geocost.NPIX; - private final static int NCOMPO = geocost.NCOMPO; - private final static int NWALK = geocost.NWALK; - + + private final static int NSEC = RICHGeoConstants.NSEC; + private final static int NLAY = RICHGeoConstants.NLAY; + private final static int NPMT = RICHGeoConstants.NPMT; + private final static int NPIX = RICHGeoConstants.NPIX; + private final static int NCOMPO = RICHGeoConstants.NCOMPO; + private final static int NWALK = RICHGeoConstants.NWALK; + private final static int NAERMAX = RICHGeoConstants.NAERMAX; - + private static IndexedTable richTable; - private ArrayList timewalkTables = new ArrayList(); - private ArrayList timeoffTables = new ArrayList(); - private ArrayList anglerefTables = new ArrayList(); - private ArrayList pixelTables = new ArrayList(); - private ArrayList pixstatusTables = new ArrayList(); - private ArrayList aerstatusTables = new ArrayList(); - private ArrayList mirstatusTables = new ArrayList(); - - private double D0[] = new double[NPMT]; - private double T0[] = new double[NPMT]; - private double m1[] = new double[NPMT]; - private double m2[] = new double[NPMT]; - + private ArrayList timewalkTables = new ArrayList<>(); + private ArrayList timeoffTables = new ArrayList<>(); + private ArrayList anglerefTables = new ArrayList<>(); + private ArrayList pixelTables = new ArrayList<>(); + private ArrayList pixstatusTables = new ArrayList<>(); + private ArrayList aerstatusTables = new ArrayList<>(); + private ArrayList mirstatusTables = new ArrayList<>(); + private RICHParameters richpar; - - // just for TxT file - private double pmt_timeoff[][] = new double[NPMT][NPIX]; - private double pmt_timewalk[][] = new double[NPMT][4]; - + private double aero_chele_dir[][][] = new double[4][NAERMAX][225]; private double aero_chele_lat[][][] = new double[4][NAERMAX][225]; private double aero_chele_spe[][][] = new double[4][NAERMAX][225]; private double aero_schele_dir[][][] = new double[4][NAERMAX][225]; private double aero_schele_lat[][][] = new double[4][NAERMAX][225]; private double aero_schele_spe[][][] = new double[4][NAERMAX][225]; - - - //------------------------------ - public RICHCalibration() { - //------------------------------ - } - - - //------------------------------ + + public RICHCalibration() {} + public void load_CCDB(ConstantsManager manager, int run, int ncalls, RICHGeoFactory richgeo, RICHParameters richpar){ - //------------------------------ - + int debugMode = 0; - + this.richpar = richpar; this.richTable = richgeo.get_richTable(); - + for(int irich=1; irich<=richgeo.nRICHes(); irich++){ - + int isec = find_RICHSector(irich); if(isec==0) continue; - + String time_walk = String.format("/calibration/rich/module%1d/time_walk",irich); String time_offs = String.format("/calibration/rich/module%1d/time_offset",irich); String cher_angs = String.format("/calibration/rich/module%1d/cherenkov_angle",irich); @@ -87,96 +63,92 @@ public void load_CCDB(ConstantsManager manager, int run, int ncalls, RICHGeoFact String pmts_pixe = String.format("/calibration/rich/module%1d/mapmt_pixel",irich); String stat_pmts = String.format("/calibration/rich/module%1d/status_mapmt",irich); String stat_mirr = String.format("/calibration/rich/module%1d/status_mirror",irich); - + init_CalConstantsCCDB( manager.getConstants(run, time_walk), - manager.getConstants(run, time_offs), - manager.getConstants(run, cher_angs), - manager.getConstants(run, stat_aero), - manager.getConstants(run, pmts_pixe), - manager.getConstants(run, stat_pmts), - manager.getConstants(run, stat_mirr) ); - + manager.getConstants(run, time_offs), + manager.getConstants(run, cher_angs), + manager.getConstants(run, stat_aero), + manager.getConstants(run, pmts_pixe), + manager.getConstants(run, stat_pmts), + manager.getConstants(run, stat_mirr) ); + /*if(irich==1){ - // first RICH module - init_CalConstantsCCDB( manager.getConstants(run, "/calibration/rich/module1/time_walk"), - manager.getConstants(run, "/calibration/rich/module1/time_offset"), - manager.getConstants(run, "/calibration/rich/module1/cherenkov_angle"), - manager.getConstants(run, "/calibration/rich/module1/status_aerogel"), - manager.getConstants(run, "/calibration/rich/module1/mapmt_pixel"), - manager.getConstants(run, "/calibration/rich/module1/status_mapmt"), - manager.getConstants(run, "/calibration/rich/module1/status_mirror"), irich ); + // first RICH module + init_CalConstantsCCDB( manager.getConstants(run, "/calibration/rich/module1/time_walk"), + manager.getConstants(run, "/calibration/rich/module1/time_offset"), + manager.getConstants(run, "/calibration/rich/module1/cherenkov_angle"), + manager.getConstants(run, "/calibration/rich/module1/status_aerogel"), + manager.getConstants(run, "/calibration/rich/module1/mapmt_pixel"), + manager.getConstants(run, "/calibration/rich/module1/status_mapmt"), + manager.getConstants(run, "/calibration/rich/module1/status_mirror"), irich ); }else{ - // second RICH module - init_CalConstantsCCDB( manager.getConstants(run, "/calibration/rich/module2/time_walk"), - manager.getConstants(run, "/calibration/rich/module2/time_offset"), - manager.getConstants(run, "/calibration/rich/module2/cherenkov_angle"), - manager.getConstants(run, "/calibration/rich/module2/status_aerogel"), - manager.getConstants(run, "/calibration/rich/module2/mapmt_pixel"), - manager.getConstants(run, "/calibration/rich/module2/status_mapmt"), - manager.getConstants(run, "/calibration/rich/module2/status_mirror"), irich ); + // second RICH module + init_CalConstantsCCDB( manager.getConstants(run, "/calibration/rich/module2/time_walk"), + manager.getConstants(run, "/calibration/rich/module2/time_offset"), + manager.getConstants(run, "/calibration/rich/module2/cherenkov_angle"), + manager.getConstants(run, "/calibration/rich/module2/status_aerogel"), + manager.getConstants(run, "/calibration/rich/module2/mapmt_pixel"), + manager.getConstants(run, "/calibration/rich/module2/status_mapmt"), + manager.getConstants(run, "/calibration/rich/module2/status_mirror"), irich ); }*/ - + if((debugMode>=1 || richpar.DEBUG_CAL_COST>=1) && ncalls=1 || richpar.DEBUG_CAL_COST>=1) && ncalls=1 || richpar.DEBUG_CAL_COST>=1) && ncalls=1 || richpar.DEBUG_CAL_COST>=1) && ncalls=1 || richpar.DEBUG_CAL_COST>=1) && ncalls=1 || richpar.DEBUG_CAL_COST>=1) && ncalls391) System.err.format("Exception occurred trying to pmt from '%s' \n", walk_filename); - - D0[ipmt-1] = Double.parseDouble(array[3]); - T0[ipmt-1] = Double.parseDouble(array[4]); - m1[ipmt-1] = Double.parseDouble(array[5]); - m2[ipmt-1] = Double.parseDouble(array[6]); - + + //D0[ipmt-1] = Double.parseDouble(array[3]); + //T0[ipmt-1] = Double.parseDouble(array[4]); + //m1[ipmt-1] = Double.parseDouble(array[5]); + //m2[ipmt-1] = Double.parseDouble(array[6]); } - + } catch (Exception e) { - + System.err.format("Exception occurred trying to read '%s' \n", walk_filename); e.printStackTrace(); - + } - } - - + } + + if(ifile==2){ - - /* + + /* * AEROGEL CALIBRATED OPTICS */ - + String chele_filename = new String("CALIB_DATA/aerogel_chele.txt"); - + try { - + BufferedReader bf = new BufferedReader(new FileReader(chele_filename)); - String currentLine = null; - + String currentLine; + while ( (currentLine = bf.readLine()) != null) { - + String[] array = currentLine.split(" "); int idlay = Integer.parseInt(array[1]); int iaer = Integer.parseInt(array[2]); int iqua = Integer.parseInt(array[3]); - + if((debugMode>=1 || richpar.DEBUG_CAL_COST>=1) && ncalls=1 || richpar.DEBUG_CAL_COST>=1) && ncalls=382)System.out.format("CCDB RICH TOFF ipmt %4d %8.3f (ch1) %8.3f (ch2) %8.3f (ch63) %8.3f (ch64) \n", ipmt, - -get_PixelTimeOff(isec, ipmt, 1), -get_PixelTimeOff(isec, ipmt, 2), -get_PixelTimeOff(isec, ipmt, 63), -get_PixelTimeOff(isec, ipmt, 64)); + -get_PixelTimeOff(isec, ipmt, 1), -get_PixelTimeOff(isec, ipmt, 2), -get_PixelTimeOff(isec, ipmt, 63), -get_PixelTimeOff(isec, ipmt, 64)); if(ipmt==10)System.out.format("CCDB RICH TOFF ....... \n"); if(ipmt==391)System.out.format(" \n"); } - + for(int ipmt=1; ipmt<=NPMT; ipmt++){ if(ipmt<=10 || ipmt>=382)System.out.format("CCDB RICH TWALK ipmt %4d D0 = %8.3f T0 = %8.3f m1 = %8.4f m2 = %8.4f\n", ipmt, - timewalkTables.get(irich-1).getDoubleValue("D0", isec, ipmt, 0), timewalkTables.get(irich-1).getDoubleValue("m1", isec, ipmt, 0), - timewalkTables.get(irich-1).getDoubleValue("m2", isec, ipmt, 0), timewalkTables.get(irich-1).getDoubleValue("T0", isec, ipmt, 0)); - - + timewalkTables.get(irich-1).getDoubleValue("D0", isec, ipmt, 0), timewalkTables.get(irich-1).getDoubleValue("m1", isec, ipmt, 0), + timewalkTables.get(irich-1).getDoubleValue("m2", isec, ipmt, 0), timewalkTables.get(irich-1).getDoubleValue("T0", isec, ipmt, 0)); + + if(ipmt==10)System.out.format("CCDB RICH TWALK ....... \n"); if(ipmt==391)System.out.format(" \n"); } - + } - - - //------------------------------ - public void dump_PixelConstants(int irich) { - //------------------------------ - + + + public void dump_PixelConstants(int irich) { + int isec = find_RICHSector(irich); if(isec==0) return; - + for(int ipmt=1; ipmt<=NPMT; ipmt++){ - + if(ipmt<=2 || ipmt>=390)System.out.format("CCDB PIXEL GAIN ipmt %4d %8.2f (ch1) %8.2f (ch2) %8.2f (ch63) %8.2f (ch64) \n", ipmt, - get_PixelGain(isec, ipmt, 1), get_PixelGain(isec, ipmt, 2), get_PixelGain(isec, ipmt, 63), get_PixelGain(isec, ipmt, 64)); + get_PixelGain(isec, ipmt, 1), get_PixelGain(isec, ipmt, 2), get_PixelGain(isec, ipmt, 63), get_PixelGain(isec, ipmt, 64)); if(ipmt==10)System.out.format("CCDB PIXEL GAIN ....... \n"); - + if(ipmt<=2 || ipmt>=390)System.out.format("CCDB PIXEL EFF ipmt %4d %8.2f (ch1) %8.2f (ch2) %8.2f (ch63) %8.2f (ch64) \n", ipmt, - get_PixelEff(isec, ipmt, 1), get_PixelEff(isec, ipmt, 2), get_PixelEff(isec, ipmt, 63), get_PixelEff(isec, ipmt, 64)); + get_PixelEff(isec, ipmt, 1), get_PixelEff(isec, ipmt, 2), get_PixelEff(isec, ipmt, 63), get_PixelEff(isec, ipmt, 64)); if(ipmt==10)System.out.format("CCDB PIXEL EFF ....... \n"); - + if(ipmt<=2 || ipmt>=390)System.out.format("CCDB PIXEL DARKRT ipmt %4d %8.2f (ch1) %8.2f (ch2) %8.2f (ch63) %8.2f (ch64) \n", ipmt, - get_PixelDarkRate(isec, ipmt, 1), get_PixelDarkRate(isec, ipmt, 2), get_PixelDarkRate(isec, ipmt, 63), get_PixelDarkRate(isec, ipmt, 64)); + get_PixelDarkRate(isec, ipmt, 1), get_PixelDarkRate(isec, ipmt, 2), get_PixelDarkRate(isec, ipmt, 63), get_PixelDarkRate(isec, ipmt, 64)); if(ipmt==10)System.out.format("CCDB PIXEL DARKRATE ....... \n"); - + if(ipmt<=2 || ipmt>=390)System.out.format("CCDB PIXEL MTIME ipmt %4d %8.2f (ch1) %8.2f (ch2) %8.2f (ch63) %8.2f (ch64) \n", ipmt, - get_PixelMeanTime(isec, ipmt, 1), get_PixelMeanTime(isec, ipmt, 2), get_PixelMeanTime(isec, ipmt, 63), get_PixelMeanTime(isec, ipmt, 64)); + get_PixelMeanTime(isec, ipmt, 1), get_PixelMeanTime(isec, ipmt, 2), get_PixelMeanTime(isec, ipmt, 63), get_PixelMeanTime(isec, ipmt, 64)); if(ipmt==10)System.out.format("CCDB PIXEL MTIME ....... \n"); - + if(ipmt<=2 || ipmt>=390)System.out.format("CCDB PIXEL STIME ipmt %4d %8.2f (ch1) %8.2f (ch2) %8.2f (ch63) %8.2f (ch64) \n", ipmt, - get_PixelRMSTime(isec, ipmt, 1), get_PixelRMSTime(isec, ipmt, 2), get_PixelRMSTime(isec, ipmt, 63), get_PixelRMSTime(isec, ipmt, 64)); + get_PixelRMSTime(isec, ipmt, 1), get_PixelRMSTime(isec, ipmt, 2), get_PixelRMSTime(isec, ipmt, 63), get_PixelRMSTime(isec, ipmt, 64)); if(ipmt==10)System.out.format("CCDB PIXEL STIME ....... \n"); - + if(ipmt<=2 || ipmt>=390)System.out.format("CCDB PIXEL STATUS ipmt %4d %8d (ch1) %8d (ch2) %8d (ch63) %8d (ch64) \n", ipmt, - get_PixelStatus(isec, ipmt, 1), get_PixelStatus(isec, ipmt, 2), get_PixelStatus(isec, ipmt, 63), get_PixelStatus(isec, ipmt, 64)); + get_PixelStatus(isec, ipmt, 1), get_PixelStatus(isec, ipmt, 2), get_PixelStatus(isec, ipmt, 63), get_PixelStatus(isec, ipmt, 64)); if(ipmt==10)System.out.format("CCDB PIXEL STATUS ....... \n"); - + } System.out.format(" \n"); - - + + int p_dead = 0; for(int ipmt=1; ipmt<=NPMT; ipmt++){ for(int ianode=1; ianode<=NPIX; ianode++){ if(get_PixelStatus(isec, ipmt, ianode)==2){ - System.out.format("CCDB PIXEL DEAD Sec %4d PMT %4d Anode %6d Status %6d \n",isec, ipmt, ianode, get_PixelStatus(isec, ipmt, ianode)); + System.out.format("CCDB PIXEL DEAD Sec %4d PMT %4d Anode %6d Status %6d \n",isec, ipmt, ianode, get_PixelStatus(isec, ipmt, ianode)); p_dead++; } } } - + int p_hot = 0; System.out.format(" \n"); for(int ipmt=1; ipmt<=NPMT; ipmt++){ for(int ianode=1; ianode<=NPIX; ianode++){ if(get_PixelStatus(isec, ipmt, ianode)==5){ - System.out.format("CCDB PIXEL HOT Sec %4d PMT %4d Anode %6d Status %6d \n",isec, ipmt, ianode, get_PixelStatus(isec, ipmt, ianode)); + System.out.format("CCDB PIXEL HOT Sec %4d PMT %4d Anode %6d Status %6d \n",isec, ipmt, ianode, get_PixelStatus(isec, ipmt, ianode)); p_hot++; } } } System.out.format("Pixels with bad status flag: %4d dead %4d hot \n \n",p_dead,p_hot); - + } - - - - //------------------------------ - public void dump_AeroConstants(int irich) { - //------------------------------ - + + + + public void dump_AeroConstants(int irich) { + double mrad = RICHConstants.MRAD; int isec = find_RICHSector(irich); if(isec==0) return; - + for (int ila=0; ila<4; ila++){ - for(int ico=0; icogeocost.NAERCO[ila]-3){ + for(int ico=0; icoRICHGeoConstants.NAERCO[ila]-3){ for (int iqua=0; iqua<225; iqua+=224){ - + System.out.format("CCDB RICH CHELE ila %4d itile %3d iq %4d ", 201+ila, ico+1, iqua+1); - System.out.format(" [+] %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f \n", - get_NElectron(isec, ila, ico, iqua, 0, 1), - get_ChElectron(isec, ila, ico, iqua, 0, 1)*mrad, get_SChElectron(isec, ila, ico, iqua, 0, 1)*mrad, - get_NElectron(isec, ila, ico, iqua, 1, 1), - get_ChElectron(isec, ila, ico, iqua, 1, 1)*mrad, get_SChElectron(isec, ila, ico, iqua, 1, 1)*mrad, - get_NElectron(isec, ila, ico, iqua, 2, 1), - get_ChElectron(isec, ila, ico, iqua, 2, 1)*mrad, get_SChElectron(isec, ila, ico, iqua, 2, 1)*mrad); + System.out.format(" [+] %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f \n", + get_NElectron(isec, ila, ico, iqua, 0, 1), + get_ChElectron(isec, ila, ico, iqua, 0, 1)*mrad, get_SChElectron(isec, ila, ico, iqua, 0, 1)*mrad, + get_NElectron(isec, ila, ico, iqua, 1, 1), + get_ChElectron(isec, ila, ico, iqua, 1, 1)*mrad, get_SChElectron(isec, ila, ico, iqua, 1, 1)*mrad, + get_NElectron(isec, ila, ico, iqua, 2, 1), + get_ChElectron(isec, ila, ico, iqua, 2, 1)*mrad, get_SChElectron(isec, ila, ico, iqua, 2, 1)*mrad); System.out.format(" "); - System.out.format(" [-] %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f \n", - get_NElectron(isec, ila, ico, iqua, 0, -1), - get_ChElectron(isec, ila, ico, iqua, 0, -1)*mrad, get_SChElectron(isec, ila, ico, iqua, 0, -1)*mrad, - get_NElectron(isec, ila, ico, iqua, 1, -1), - get_ChElectron(isec, ila, ico, iqua, 1, -1)*mrad, get_SChElectron(isec, ila, ico, iqua, 1, -1)*mrad, - get_NElectron(isec, ila, ico, iqua, 2, -1), - get_ChElectron(isec, ila, ico, iqua, 2, -1)*mrad, get_SChElectron(isec, ila, ico, iqua, 2, -1)*mrad); + System.out.format(" [-] %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f %5.2f %6.2f %4.2f \n", + get_NElectron(isec, ila, ico, iqua, 0, -1), + get_ChElectron(isec, ila, ico, iqua, 0, -1)*mrad, get_SChElectron(isec, ila, ico, iqua, 0, -1)*mrad, + get_NElectron(isec, ila, ico, iqua, 1, -1), + get_ChElectron(isec, ila, ico, iqua, 1, -1)*mrad, get_SChElectron(isec, ila, ico, iqua, 1, -1)*mrad, + get_NElectron(isec, ila, ico, iqua, 2, -1), + get_ChElectron(isec, ila, ico, iqua, 2, -1)*mrad, get_SChElectron(isec, ila, ico, iqua, 2, -1)*mrad); } } /*for (int iqua=0; iqua<225; iqua+=224){ - double nspe = get_NElectron(isec, ila, ico, iqua, 2, -1); - double ndir = get_NElectron(isec, ila, ico, iqua, 0, -1); - if(nspe>0 && nspe==ndir){ - System.out.format("ECCOLO ila %4d itile %3d iq %4d [%7.2f %7.2f]\n", 201+ila, ico+1, iqua+1, nspe, ndir); - } + double nspe = get_NElectron(isec, ila, ico, iqua, 2, -1); + double ndir = get_NElectron(isec, ila, ico, iqua, 0, -1); + if(nspe>0 && nspe==ndir){ + System.out.format("ECCOLO ila %4d itile %3d iq %4d [%7.2f %7.2f]\n", 201+ila, ico+1, iqua+1, nspe, ndir); + } }*/ } } System.out.format(" \n"); - + int found = 0; for (int ila=0; ila<4; ila++){ - for(int ico=0; icogeocost.NAERCO[ila]-3){ + for(int ico=0; icoRICHGeoConstants.NAERCO[ila]-3){ if(get_AeroStatus(isec, ila, ico)>0){ System.out.format("CCDB BAD AERO Sec %4d Lay %4d Compo %6d Status %6d \n",isec, ila, ico, get_AeroStatus(isec, ila, ico)); found++; @@ -478,18 +438,16 @@ public void dump_AeroConstants(int irich) { } } System.out.format("Aerogels with bad status flag: %4d \n \n",found); - + } - - - //------------------------------ - public void dump_MirrorConstants(int irich) { - //------------------------------ - + + + public void dump_MirrorConstants(int irich) { + int isec = find_RICHSector(irich); if(isec==0) return; System.out.format(" \n"); - + int found = 0; for(RICHLayerType lay: RICHLayerType.values()){ if(lay.ccdb_ila()==301){ @@ -513,19 +471,17 @@ public void dump_MirrorConstants(int irich) { } System.out.format("Mirrors with non-zero status flag %3d \n \n", found); } - - - //------------------------------ + + public double get_SChElectron(int isec, int ila, int ico, int iqua, int irefle, int icharge) { - //------------------------------ - - - if(ico<0 || ico>=geocost.NAERCO[ila]) return 0.0; + + + if(ico<0 || ico>=RICHGeoConstants.NAERCO[ila]) return 0.0; int irich = find_RICHModule(isec); if(irich==0) return 0.0; - + int irow = ico*225+iqua+1; - + double dir = 0.0; double lat = 0.0; double sphe = 0.0; @@ -539,7 +495,7 @@ public double get_SChElectron(int isec, int ila, int ico, int iqua, int irefle, lat = anglerefTables.get(irich-1).getDoubleValue("hm_sigma_lat", isec, 201+ila, irow); sphe = anglerefTables.get(irich-1).getDoubleValue("hm_sigma_sphe", isec, 201+ila, irow); } - + if(irefle==0){ if(dir>0) return dir; if(lat>0) return lat; @@ -557,114 +513,94 @@ public double get_SChElectron(int isec, int ila, int ico, int iqua, int irefle, } return 0.0; } - - - //------------------------------ - public double get_PixelGain(int isec, int ipmt, int ich) { - //------------------------------ + + + public double get_PixelGain(int isec, int ipmt, int ich) { int irich = find_RICHModule(isec); if(irich==0)return 0.0; return pixelTables.get(irich-1).getDoubleValue("gain", isec, ipmt, ich); } - - - //------------------------------ - public double get_PixelEff(int isec, int ipmt, int ich) { - //------------------------------ + + + public double get_PixelEff(int isec, int ipmt, int ich) { int irich = find_RICHModule(isec); if(irich==0)return 0.0; return pixelTables.get(irich-1).getDoubleValue("efficiency", isec, ipmt, ich); } - - - //------------------------------ - public double get_PixelDarkRate(int isec, int ipmt, int ich) { - //------------------------------ + + + public double get_PixelDarkRate(int isec, int ipmt, int ich) { int irich = find_RICHModule(isec); if(irich==0)return 0; return pixelTables.get(irich-1).getDoubleValue("darkrate", isec, ipmt, ich); } - - - //------------------------------ - public double get_PixelMeanTime(int isec, int ipmt, int ich) { - //------------------------------ + + + public double get_PixelMeanTime(int isec, int ipmt, int ich) { int irich = find_RICHModule(isec); if(irich==0)return 0.0; return pixelTables.get(irich-1).getDoubleValue("mean_t", isec, ipmt, ich); } - - - //------------------------------ - public double get_PixelRMSTime(int isec, int ipmt, int ich) { - //------------------------------ + + + public double get_PixelRMSTime(int isec, int ipmt, int ich) { int irich = find_RICHModule(isec); if(irich==0)return 0.0; return pixelTables.get(irich-1).getDoubleValue("sigma_t", isec, ipmt, ich); } - - - //------------------------------ - public int get_PixelStatus(int isec, int ipmt, int ianode) { - //------------------------------ + + + public int get_PixelStatus(int isec, int ipmt, int ianode) { int irich = find_RICHModule(isec); if(irich==0)return 0; return pixstatusTables.get(irich-1).getIntValue("status", isec, ipmt, ianode); } - - - //------------------------------ + + public int get_AeroStatus(int isec, int ila, int ico) { - //------------------------------ - + int iref_quadrant = 1; return get_AeroStatus(isec, ila, ico, iref_quadrant); - + } - - - //------------------------------ + + public int get_AeroStatus(int isec, int ila, int ico, int iqua) { - //------------------------------ - - if(ico<0 || ico>=geocost.NAERCO[ila]) return 0; + + if(ico<0 || ico>=RICHGeoConstants.NAERCO[ila]) return 0; int irich = find_RICHModule(isec); if(irich==0)return 0; - + int irow = ico*225+iqua+1; - + return aerstatusTables.get(irich-1).getIntValue("status", isec, 201+ila, irow); - + } - - - //------------------------------ + + public int get_MirrorStatus(int isec, int ila, int ico) { - //------------------------------ - + int irich = find_RICHModule(isec); if(irich==0) return 0; - + int lla = get_MisaIla(ila, ico); int cco = get_MisaIco(ila, ico); if(lla==-1 || cco==-1) return 0; - + return mirstatusTables.get(irich-1).getIntValue("status", isec, lla, cco); - + } - - - //------------------------------ + + public double get_ChElectron(int isec, int ila, int ico, int iqua, int irefle, int icharge) { - //------------------------------ - - - if(ico<0 || ico>=geocost.NAERCO[ila]) return 0.0; + + + if(ico<0 || ico>=RICHGeoConstants.NAERCO[ila]) return 0.0; int irich = find_RICHModule(isec); if(irich==0)return 0.0; - + int irow = ico*225+iqua+1; - + double dir = 0.0; double lat = 0.0; double sphe = 0.0; @@ -678,7 +614,7 @@ public double get_ChElectron(int isec, int ila, int ico, int iqua, int irefle, i lat = anglerefTables.get(irich-1).getDoubleValue("hm_mean_lat", isec, 201+ila, irow); sphe = anglerefTables.get(irich-1).getDoubleValue("hm_mean_sphe", isec, 201+ila, irow); } - + if(irefle==0){ if(dir>0) return dir; if(lat>0) return lat; @@ -696,19 +632,17 @@ public double get_ChElectron(int isec, int ila, int ico, int iqua, int irefle, i } return 0.0; } - - - //------------------------------ + + public double get_NElectron(int isec, int ila, int ico, int iqua, int irefle, int icharge) { - //------------------------------ - - - if(ico<0 || ico>=geocost.NAERCO[ila]) return 0.0; + + + if(ico<0 || ico>=RICHGeoConstants.NAERCO[ila]) return 0.0; int irich = find_RICHModule(isec); if(irich==0)return 0.0; - + int irow = ico*225+iqua+1; - + double dir = 0.0; double lat = 0.0; double sphe = 0.0; @@ -722,66 +656,57 @@ public double get_NElectron(int isec, int ila, int ico, int iqua, int irefle, in lat = anglerefTables.get(irich-1).getDoubleValue("hm_npe_lat", isec, 201+ila, irow); sphe = anglerefTables.get(irich-1).getDoubleValue("hm_npe_sphe", isec, 201+ila, irow); } - + if(irefle==0) return dir; if(irefle==1) return lat; if(irefle==2) return sphe; return 0.0; } - - - //------------------------------ + + public double get_PixelTimeOff(int isec, int ipmt, int ich){ - //------------------------------ - + int irich = find_RICHModule(isec); if(irich==0)return 0.0; - + return -1*timeoffTables.get(irich-1).getDoubleValue("offset", isec, ipmt, ich) + richpar.OFFSET_TIME; - + } - - - //------------------------------ + + public double get_PixelTimeWalk(int isec, int ipmt, int duration){ - //------------------------------ - + int irich = find_RICHModule(isec); if(irich==0)return 0.0; - - double twalk_corr = 0; + double D0 = timewalkTables.get(irich-1).getDoubleValue("D0", isec, ipmt, 0); double T0 = timewalkTables.get(irich-1).getDoubleValue("m1", isec, ipmt, 0); double m1 = timewalkTables.get(irich-1).getDoubleValue("m2", isec, ipmt, 0); double m2 = timewalkTables.get(irich-1).getDoubleValue("T0", isec, ipmt, 0); - + double f1 = m1 * duration + T0; double f1T = m1 * D0 + T0; - + double f2 = m2 * (duration - D0) + f1T; - twalk_corr = f1; + double twalk_corr = f1; if (duration > D0) twalk_corr = f2; - + return twalk_corr; } - - - //------------------------------ + + public int find_RICHModule(int isec){ - //------------------------------ - + if( richTable.hasEntry(isec,0,0)){ return richTable.getIntValue("module", isec, 0, 0); } return 0; } - - - //------------------------------ + + public int find_RICHSector(int irich){ - //------------------------------ int debugMode = 0; - + for (int isec=1; isec<=RICHGeoConstants.NSEC; isec++){ if(richTable.hasEntry(isec,0,0)){ if(debugMode>=1)System.out.format(" trovo %4d <--> %4d \n",irich, richTable.getIntValue("module", isec, 0, 0)); @@ -790,47 +715,43 @@ public int find_RICHSector(int irich){ } return 0; } - - - //------------------------------ + + public int get_MisaIla(int ila, int ico){ - //------------------------------ - + // 0 = global layer if(ila<0 || ila>RICHLayerType.values().length) return -1; - int ncompo = 0; + int ncompo; ncompo = RICHLayerType.get_Type(ila).ncompo(); if(ico<0 || ico>ncompo) return -1; - + // global RICH for(RICHLayerType lay: RICHLayerType.values()) if (lay.id() == ila) return lay.ccdb_ila(); return 0; - + } - - - //------------------------------ + + public int get_MisaIco(int ila, int ico) { - //------------------------------ - + if(ila<0 || ila>RICHLayerType.values().length) return -1; - int ncompo = 0; + int ncompo; ncompo = RICHLayerType.get_Type(ila).ncompo(); if(ico<0 || ico>ncompo) return -1; - + for(RICHLayerType lay: RICHLayerType.values()){ if (lay.id() == ila){ - + if(lay.ccdb_ila()==301){ - return lay.ccdb_ico(); + return lay.ccdb_ico(); }else{ - return ico; + return ico; } } } return 0; } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCluster.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCluster.java index 8df725059b..be4f6d588c 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCluster.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHCluster.java @@ -4,62 +4,47 @@ import org.jlab.geom.prim.Point3D; public class RICHCluster extends ArrayList { - + /** * A cluster in the RICH consists of an array of anodes in one PMT */ - + private int clusid; // cluster ID - private int signal; // pointer to the derived RICH signal + private int signal; // pointer to the derived RICH signal // constructor - // ---------------- public RICHCluster(int cluid) { - // ---------------- - this.set_id(cluid); + this.set_id(cluid); } - - // ---------------- + public int get_id() { return this.clusid; } - // ---------------- - - // ---------------- + public void set_id(int cluid) { this.clusid = cluid; } - // ---------------- - - // ---------------- + public int get_signal() { return this.signal; } - // ---------------- - - // ---------------- + public void set_signal(int signal) { this.signal = signal; } - // ---------------- - - - // ---------------- + + public int get_size() { - // ---------------- - // return number of anodes in cluster - return this.size(); + // return number of anodes in cluster + return this.size(); } - - // ---------------- + public double get_charge() { - // ---------------- - // return measured charge - double clusterEnergy = 0; - for(int i=0; imaxcharge){ - imax=i; - maxcharge=this.get(i).get_duration(); - } - } - return this.get(imax).get_anode(); + + /* int imax = 0; + double maxcharge = 0; + for(int i=0; imaxcharge){ + imax=i; + maxcharge=this.get(i).get_duration(); } - - - // ---------------- + } + return this.get(imax).get_anode(); + } + + public int get_MaxPMT() { - // ---------------- // return anode with maximum charge - - int imax = 0; - double maxcharge = 0; - for(int i=0; imaxcharge){ - imax=i; - maxcharge=this.get(i).get_duration(); - } - } - return this.get(imax).get_pmt(); + + int imax = 0; + double maxcharge = 0; + for(int i=0; imaxcharge){ + imax=i; + maxcharge=this.get(i).get_duration(); + } + } + return this.get(imax).get_pmt(); }*/ - - - // ---------------- + + public double get_time() { - // ---------------- - return this.get(0).get_Time(); + return this.get(0).get_Time(); } - - // ---------------- + public double get_rawtime() { - // ---------------- - return this.get(0).get_rawtime(); + return this.get(0).get_rawtime(); } - - - // ---------------- + + public int get_glx() { - // ---------------- // returns glx coordinate of first hit return this.get(0).get_glx(); } - - // ---------------- - public int get_gly() { - // ---------------- + + public int get_gly() { // returns gly coordinate of first hit return this.get(0).get_gly(); } - - // ---------------- + public double get_x() { - // ---------------- // returns x coordinate of first hit return this.get(0).get_x(); } - - // ---------------- - public double get_y() { - // ---------------- + + public double get_y() { // returns y coordinate of first hit return this.get(0).get_y(); } - - // ---------------- - public double get_z() { - // ---------------- + + public double get_z() { // returns z coordinate of first hit - + if(RICHConstants.COSMIC_RUN==0){ return this.get(0).get_z(); - - }else{ + + }else{ if(this.get(0).get_tile()<139){ return 0; }else{ return RICHConstants.COSMIC_TRACKING_Z; } } - } - - // ---------------- + } + public double get_wtime() { - // ---------------- - // returns charge weighted time + // returns charge weighted time double clusterEnergy = this.get_charge(); double clusterTime = 0; for(int i=0; i138){ clusz = RICHConstants.COSMIC_TRACKING_Z; } - + for(int i=0; i0){ + + if(wtot>0){ clusx /= wtot; clusy /= wtot; clusz /= wtot; - } - + } + Point3D centroid = new Point3D(clusx,clusy,clusz); - return centroid; - - } - - - // ---------------- + return centroid; + + } + + public double get_wx() { - // ---------------- // returns X coordinate of weigthed centroid return this.getCentroid().x(); } - - // ---------------- + public double get_wy() { - // ---------------- // returns Y coordinate of weigthed centroid - return this.getCentroid().y(); + return this.getCentroid().y(); } - - // ---------------- + public double get_wz() { - // ---------------- // returns Z coordinate of weigthed centroid - return this.getCentroid().z(); + return this.getCentroid().z(); } - + /* - // ---------------- public double getX2() { - // ---------------- - double clusEnergy = this.getEnergy(); - double wtot = 0; - double clusterXX = 0; - for(int i=0; i= RICHConstants.CLUSTER_MIN_SIZE && + this.get_size() >= RICHConstants.CLUSTER_MIN_SIZE && this.get_charge() >= RICHConstants.CLUSTER_MIN_CHARGE) { return true; } else { return false; } - - } - - - // ---------------- + + } + + public void merge(RICHCluster clu) { - // ---------------- - + for(int i=0; i comp "+this.get_channel()+" "+this.get_charge()+" "+ocluster.get_channel()+" "+ocluster.get_charge()); if(this.get_charge() == ocluster.get_charge())return 0; if(this.get_charge() > ocluster.get_charge()){ @@ -368,13 +307,11 @@ public int compareTo(RICHCluster ocluster) { return -1; } } - - - // ---------------- + + public void showCluster() { - // ---------------- System.out.format("Cluster ID %3d PMT %4d Siz %4d Ch %7.1f T %7.1f raw %7.1f wT %7.1f glxy %4d %4d XYZ %7.2f %7.2f %7.2f wXYZ %7.2f %7.2f %7.2f \n", - this.clusid, + this.clusid, this.get(0).get_pmt(), this.get_size(), this.get_charge(), @@ -382,11 +319,11 @@ public void showCluster() { this.get_glx(), this.get_gly(), this.get_x(), this.get_y(), this.get_z(), this.get_wx(), this.get_wy(), this.get_wz()); - for(int j = 0; j< this.size(); j++) { - System.out.format(" --> hit # %3d ID %3d idxy %3d %3d dur %4d \n", - j, this.get(j).get_id(), + for(int j = 0; j< this.size(); j++) { + System.out.format(" --> hit # %3d ID %3d idxy %3d %3d dur %4d \n", + j, this.get(j).get_id(), this.get(j).get_idx(), this.get(j).get_idy(), this.get(j).get_duration()); - } } + } } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHConstants.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHConstants.java index e571f133f2..8de35483ab 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHConstants.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHConstants.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.rec.rich; /** @@ -77,4 +72,4 @@ public class RICHConstants { public static final double MRAD = 1000.; public static final double RAD = 180./Math.PI; -} +} \ No newline at end of file diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java index faff8505dd..fbeb23a710 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java @@ -7,61 +7,59 @@ import org.jlab.detector.geom.RICH.RICHGeoFactory; public class RICHEBEngine extends ReconstructionEngine { - - private int Run = -1; + private int Ncalls = 0; - private long EBRICH_start_time; private RICHGeoFactory richgeo; private RICHTime richtime = new RICHTime(); private boolean engineDebug = false; - + public RICHEBEngine() { super("RICHEB", "mcontalb", "3.0"); } - + @Override public boolean init() { - + int debugMode = 0; if(debugMode>=1)System.out.format("I am in RICHEBEngine init \n"); - + String[] richTables = new String[]{ - "/geometry/rich/setup", - "/geometry/rich/geo_parameter", - "/geometry/rich/module1/aerogel", - "/geometry/rich/module2/aerogel", - "/geometry/rich/module1/alignment", - "/geometry/rich/module2/alignment", - "/calibration/rich/reco_flag", - "/calibration/rich/reco_parameter", - "/calibration/rich/module1/time_walk", - "/calibration/rich/module1/time_offset", - "/calibration/rich/module1/cherenkov_angle", - "/calibration/rich/module1/mapmt_pixel", - "/calibration/rich/module1/status_mirror", - "/calibration/rich/module1/status_aerogel", - "/calibration/rich/module1/status_mapmt", - "/calibration/rich/module2/time_walk", - "/calibration/rich/module2/time_offset", - "/calibration/rich/module2/cherenkov_angle", - "/calibration/rich/module2/mapmt_pixel", - "/calibration/rich/module2/status_mirror", - "/calibration/rich/module2/status_aerogel", - "/calibration/rich/module2/status_mapmt" - }; - + "/geometry/rich/setup", + "/geometry/rich/geo_parameter", + "/geometry/rich/module1/aerogel", + "/geometry/rich/module2/aerogel", + "/geometry/rich/module1/alignment", + "/geometry/rich/module2/alignment", + "/calibration/rich/reco_flag", + "/calibration/rich/reco_parameter", + "/calibration/rich/module1/time_walk", + "/calibration/rich/module1/time_offset", + "/calibration/rich/module1/cherenkov_angle", + "/calibration/rich/module1/mapmt_pixel", + "/calibration/rich/module1/status_mirror", + "/calibration/rich/module1/status_aerogel", + "/calibration/rich/module1/status_mapmt", + "/calibration/rich/module2/time_walk", + "/calibration/rich/module2/time_offset", + "/calibration/rich/module2/cherenkov_angle", + "/calibration/rich/module2/mapmt_pixel", + "/calibration/rich/module2/status_mirror", + "/calibration/rich/module2/status_aerogel", + "/calibration/rich/module2/status_mapmt" + }; + requireConstants(Arrays.asList(richTables)); - + // initialize constants manager default variation, will be then modified based on yaml settings // Get the constants for the correct variation - String engineVariation = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); + String engineVariation = Optional.ofNullable(this.getEngineConfigString("variation")).orElse("default"); this.getConstantsManager().setVariation(engineVariation); - - if(this.getEngineConfigString("debug")!=null) + + if(this.getEngineConfigString("debug")!=null) this.engineDebug = Boolean.parseBoolean(this.getEngineConfigString("debug")); - + return true; - + } @Override @@ -69,35 +67,33 @@ public void detectorChanged(int runNumber) { richgeo = new RICHGeoFactory(1, this.getConstantsManager(), runNumber, engineDebug); richtime.init_ProcessTime(); } - + @Override - // ---------------- public boolean processDataEventUser(DataEvent event) { - // ---------------- - + int debugMode = 0; - + // create instances of all event-dependent classes in processDataEventUser to avoid interferences between different threads when running in clara RICHEvent richevent = new RICHEvent(); RICHio richio = new RICHio(); RICHCalibration richcal = new RICHCalibration(); RICHParameters richpar = new RICHParameters(); - + RICHPMTReconstruction rpmt = new RICHPMTReconstruction(richevent, richgeo, richio); RICHEventBuilder reb = new RICHEventBuilder(event, richevent, richgeo, richio); - RICHRayTrace richtrace = new RICHRayTrace(richgeo, richpar); + RICHRayTrace richtrace = new RICHRayTrace(richgeo, richpar); richtime.save_ProcessTime(0, richevent); - + if(debugMode>=1){ System.out.println("---------------------------------"); System.out.println("RICH Engine call: "+Ncalls+" New Event Process "+richevent.get_EventID()); System.out.println("---------------------------------"); } - - // Initialize the CCDB information + + // Initialize the CCDB information if(debugMode>=1)System.out.println("----- Load CCDB data \n"); - int run = richevent.get_RunID(); + int run = richevent.get_RunID(); if(run>0){ richpar.load_CCDB(this.getConstantsManager(), run, Ncalls, engineDebug); richcal.load_CCDB(this.getConstantsManager(), run, Ncalls, richgeo, richpar); @@ -106,33 +102,33 @@ public boolean processDataEventUser(DataEvent event) { richcal.load_CCDB(this.getConstantsManager(), 11, Ncalls, richgeo, richpar); } Ncalls++; - + richtime.save_ProcessTime(1, richevent); - - - /* - Process RICH signals to get hits and clusters - */ + + + /* + Process RICH signals to get hits and clusters + */ if(richpar.PROCESS_RAWDATA==1){ if(debugMode>=1)System.out.println("----- Process raw data \n"); - richio.clear_LowBanks(event); + richio.clear_LowBanks(event); rpmt.process_RawData(event, richpar, richcal); richtime.save_ProcessTime(2, richevent); } - - /* - Process RICH-DC event reconstruction - */ + + /* + Process RICH-DC event reconstruction + */ if(richpar.PROCESS_DATA==1){ if(debugMode>=1)System.out.println("----- Process data \n"); - richio.clear_HighBanks(event); + richio.clear_HighBanks(event); if( !reb.process_Data(event, richpar, richcal, richtrace, richtime)) return false; richtime.save_ProcessTime(8, richevent); } - + if(richpar.DEBUG_PROC_TIME>=1) richtime.dump_ProcessTime(); - + return true; - + } } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEdge.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEdge.java index c7f3addc02..8c426546db 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEdge.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEdge.java @@ -1,14 +1,9 @@ package org.jlab.rec.rich; - - public class RICHEdge implements Comparable{ // class implements Comparable interface to allow for sorting a collection of hits by Time values - - // ---------------- + public RICHEdge(int i, int isector, int ilayer, int icomponent, int iorder, int itdc) { - // ---------------- - this.id = i; this.sector = isector; this.tile = ilayer; @@ -18,10 +13,8 @@ public RICHEdge(int i, int isector, int ilayer, int icomponent, int iorder, int this.idy = 0; this.polarity = iorder; this.tdc = itdc; - - } - - + } + private int id; // ID private int sector; // Sector private int tile; // Front-End TILE ID @@ -30,121 +23,62 @@ public RICHEdge(int i, int isector, int ilayer, int icomponent, int iorder, int private int idx; // MA-PMT idx private int idy; // MA-PMT idy private int polarity; // Edge polarity - private int tdc; // Edge TDC + private int tdc; // Edge TDC private int hit; // Hit belonging to - - - // ---------------- + public int get_id() { return id;} - // ---------------- - - // ---------------- public void set_id(int id) { this.id = id; } - // ---------------- - - // ---------------- public int get_sector() { return sector;} - // ---------------- - - // ---------------- public void set_sector(int sector) { this.sector = sector; } - // ---------------- - - // ---------------- public int get_channel() { return channel; } - // ---------------- - - // ---------------- public void set_channel(int channel) { this.channel = channel; } - // ---------------- - - // ---------------- public int get_tile() { return tile; } - // ---------------- - - - // ---------------- public void set_tile(int tile) { this.tile = tile; } - // ---------------- - - - // ---------------- public int get_polarity() { return polarity; } - // ---------------- - - - // ---------------- public void set_polarity(int polarity) { this.polarity = polarity; } - // ---------------- - - - // ---------------- public int get_tdc() { return tdc; } - // ---------------- - - - // ---------------- public void set_tdc(int tdc) { this.tdc = tdc; } - // ---------------- - - // ---------------- public int get_hit() { return hit; } - // ---------------- - - - // ---------------- public void set_hit(int hit) { this.hit = hit; } - // ---------------- - - // ---------------- public boolean pass_EdgeSelection() { - // ---------------- // a selection cut to pass the edge if(this.get_tdc() > 0) { return true; } else { return false; - } + } } - + /* - // ---------------- public int compareTo(RICHEdge oedge) { - // ---------------- - if(this.get_tile()*192+this.get_channel() == oedge.get_tile()*192+oedge.get_channel())return 0; - if(this.get_tile()*192+this.get_channel() > oedge.get_tile()*192+oedge.get_channel()){ - return 1; - }else{ - return -1; - } - }*/ - - + if(this.get_tile()*192+this.get_channel() == oedge.get_tile()*192+oedge.get_channel())return 0; + if(this.get_tile()*192+this.get_channel() > oedge.get_tile()*192+oedge.get_channel()){ + return 1; + }else{ + return -1; + } + }*/ - // ---------------- public int compareTo(RICHEdge oedge) { - // ---------------- //System.out.println(" --> comp "+this.get_channel()+" "+this.get_tdc()+" "+oedge.get_channel()+" "+oedge.get_tdc()); if(this.get_tdc() == oedge.get_tdc())return 0; if(this.get_tdc() > oedge.get_tdc()){ return 1; }else{ return -1; - } + } } - - - // ---------------- + + public void showEdge() { - // ---------------- System.out.println( - + this.get_id() + "\t" - + this.get_sector() + "\t" - + this.get_tile() + "\t" - + this.get_channel() + "\t" - + this.get_polarity() + "\t" - + this.get_tdc()); + + this.get_id() + "\t" + + this.get_sector() + "\t" + + this.get_tile() + "\t" + + this.get_channel() + "\t" + + this.get_polarity() + "\t" + + this.get_tdc()); } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEvent.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEvent.java index 7dbfc47cc9..4444c1a6f3 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEvent.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEvent.java @@ -1,270 +1,109 @@ package org.jlab.rec.rich; -import java.util.List; import java.util.ArrayList; -import java.util.Collections; - -import org.jlab.io.base.DataBank; -import org.jlab.io.base.DataEvent; - import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; - -import org.jlab.clas.pdg.PDGDatabase; import org.jlab.clas.detector.DetectorResponse; import org.jlab.detector.geom.RICH.RICHRay; import org.jlab.detector.geom.RICH.RICHGeoConstants; +/** + * A RICH Event is the collected information of the event + */ public class RICHEvent { - - /** - * A RICH Event is the collected information of the event - */ - + + private static double MRAD = 1000.; + private static double RAD = 180./Math.PI; + private int runID; private int eventID; private float eventTime; private long CPUTime; private int phase; - - private static double MRAD = 1000.; - private static double RAD = 180./Math.PI; - - private ArrayList clusters = new ArrayList(); - private ArrayList hits = new ArrayList(); - - private ArrayList resclus = new ArrayList(); - private ArrayList reshits = new ArrayList(); - private ArrayList matches = new ArrayList(); - - private ArrayList hadrons = new ArrayList(); - private ArrayList photons = new ArrayList(); - - // constructor - // ---------------- - public RICHEvent() { - // ---------------- - - } - - // ---------------- + private ArrayList clusters = new ArrayList<>(); + private ArrayList hits = new ArrayList<>(); + private ArrayList resclus = new ArrayList<>(); + private ArrayList reshits = new ArrayList<>(); + private ArrayList matches = new ArrayList<>(); + private ArrayList hadrons = new ArrayList<>(); + private ArrayList photons = new ArrayList<>(); + + public RICHEvent() {} + public void clear(){ - // ---------------- - this.clusters.clear(); this.hits.clear(); - this.hadrons.clear(); this.photons.clear(); - this.resclus.clear(); this.reshits.clear(); this.matches.clear(); - } - - - // ---------------- + public void set_RunID(int ID) { runID = ID; } - // ---------------- - - // ---------------- public void set_EventID(int ID) { eventID = ID; } - // ---------------- - - // ---------------- public void set_EventTime(float time) { eventTime = time; } - // ---------------- - - // ---------------- public void set_CPUTime(long CPUTime) { this.CPUTime = CPUTime; } - // ---------------- - - //------------------------------ public int getFTOFphase() {return phase;} - //------------------------------ - - // ---------------- public void add_Hit(RICHHit hit){ hits.add(hit); } - // ---------------- - - // ---------------- public void add_Cluster(RICHCluster cluster){ clusters.add(cluster); } - // ---------------- - - // ---------------- public void add_Photon(RICHParticle photon){ photons.add(photon); } - // ---------------- - - // ---------------- public void add_Hadron(RICHParticle hadron){ hadrons.add(hadron); } - // ---------------- - - // ---------------- public void add_ResClu(DetectorResponse resclu){ resclus.add(resclu); } - // ---------------- - - // ---------------- public void add_ResHit(DetectorResponse reshit){ reshits.add(reshit); } - // ---------------- - - // ---------------- public void add_Match(DetectorResponse match){ matches.add(match); } - // ---------------- - - // ---------------- public void add_Clusters(ArrayList res){if(res!=null) for (RICHCluster clu: res) clusters.add(clu); } - // ---------------- - - // ---------------- public void add_Hits(ArrayList res){if(res!=null) for (RICHHit hit: res) hits.add(hit); } - // ---------------- - - // ---------------- public void add_Photons(ArrayList phos){if(phos!=null) for (RICHParticle par: phos) photons.add(par); } - // ---------------- - - // ---------------- public void add_Hadron(ArrayList hads){if(hads!=null) for (RICHParticle par: hads) hadrons.add(par); } - // ---------------- - - // ---------------- public void add_ResClus(ArrayList resps){if(resps!=null) for (DetectorResponse res: resps) resclus.add(res); } - // ---------------- - - // ---------------- public void add_ResHits(ArrayList resps){if(resps!=null) for (DetectorResponse res: resps) reshits.add(res); } - // ---------------- - - // ---------------- public void add_Matches(ArrayList resps){if(resps!=null) for (DetectorResponse res: resps) matches.add(res); } - // ---------------- - - // ---------------- public int get_RunID() {return runID;} - // ---------------- - - // ---------------- public int get_EventID() {return eventID;} - // ---------------- - - // ---------------- public float get_EventTime() {return eventTime;} - // ---------------- - - // ---------------- public long get_CPUTime() {return CPUTime;} - // ---------------- - - //------------------------------ public void setFTOFphase(int phase) { this.phase = phase; } - //------------------------------ - - // ---------------- public RICHCluster get_Cluster(int i){ return clusters.get(i); } - // ---------------- - - // ---------------- public RICHHit get_Hit(int i){ return hits.get(i); } - // ---------------- - - // ---------------- public RICHParticle get_Photon(int i){ return photons.get(i); } - // ---------------- - - // ---------------- public RICHParticle get_Hadron(int i){ return hadrons.get(i); } - // ---------------- - - // ---------------- public DetectorResponse get_ResClu(int i){ return resclus.get(i); } - // ---------------- - - // ---------------- public DetectorResponse get_ResHit(int i){ return reshits.get(i); } - // ---------------- - - // ---------------- public DetectorResponse get_Match(int i){ return matches.get(i); } - // ---------------- - - // ---------------- public ArrayList get_Clusters(){ return clusters; } - // ---------------- - - // ---------------- public ArrayList get_Hits(){ return hits; } - // ---------------- - - // ---------------- public ArrayList get_Photons(){ return photons; } - // ---------------- - - // ---------------- public ArrayList get_Hadrons(){ return hadrons; } - // ---------------- - - // ---------------- public ArrayList get_ResClus(){ return resclus; } - // ---------------- - - // ---------------- public ArrayList get_ResHits(){ return reshits; } - // ---------------- - - // ---------------- public ArrayList get_Matches(){ return matches; } - // ---------------- - - // ---------------- public int get_nClu() { return clusters.size(); } - // ---------------- - - // ---------------- public int get_nHit() { return hits.size(); } - // ---------------- - - // ---------------- public int get_nHad() { return hadrons.size(); } - // ---------------- - - // ---------------- public int get_nPho() { return photons.size(); } - // ---------------- - - // ---------------- public int get_nResClu() { return resclus.size(); } - // ---------------- - - // ---------------- public int get_nResHit() { return reshits.size(); } - // ---------------- - - // ---------------- public int get_nMatch() { return matches.size(); } - // ---------------- - - - // ---------------- - public void select_Signals() { - // ---------------- - + + public void select_Signals() { + int debugMode = 0; - + int NHIT = hits.size(); int NCLU = clusters.size(); if(debugMode>=1)System.out.format("Selecting Signals (%4d HITs and %4d CLUs) \n", NHIT,NCLU); - + if(NHIT>0 || NCLU>0) { - + int nsig = 0; int one = 1; - + for(int i = 0; i < NHIT; i++){ RICHHit hit = get_Hit(i); if(hit.get_cluster()!=0)continue; - if(hit.get_xtalk()!=0) continue; + if(hit.get_xtalk()!=0) continue; if(hit.get_status()!=0 && hit.get_status()!=5)continue; hit.set_signal(one); if(debugMode>=1)System.out.format(" --> hit %3d %7.2f signal %3d \n",i,hit.get_Time(),nsig); @@ -278,48 +117,44 @@ public void select_Signals() { } } } - - - // ---------------- + + public int count_Signals() { - // ---------------- - + int debugMode = 0; - + int nsig = 0; for( RICHHit hit: hits) if(hit.get_signal()>0)nsig++; for( RICHCluster clu: clusters) if(clu.get_signal()>0) nsig++; - + return nsig; } - - - // ---------------- + + public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { - // ---------------- - + int debugMode = 0; - - if(hypo<0 || hypo>=RICHConstants.N_HYPO ) return; + + if(hypo<0 || hypo>=RICHConstants.N_HYPO ) return; if(debugMode>=1)System.out.format("Hypo %s: Ch Mean calc for reco %d \n",RICHConstants.HYPO_LUND[hypo], recotype); - + int update = 1; - while (update==1) { - + while (update==1) { + update = 0; int nea = 0; double mea = 0.0; double sea = 0.0; for( RICHParticle pho: photons) { if(pho.get_type()==hypo && pho.get_ParentIndex() == hadron.get_id()){ - - + + if(debugMode>=1)System.out.format("calc mean for photon %d ",pho.get_id()); - RICHSolution reco = new RICHSolution(); + RICHSolution reco = new RICHSolution(); if(recotype==0) reco = pho.analytic; if(recotype==1) reco = pho.traced; double etac = reco.get_EtaC(); - + if(reco.is_OK()){ if(debugMode>=1)System.out.format(" etac %7.2f \n",etac*MRAD); nea++; @@ -329,25 +164,25 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { if(debugMode>=1)System.out.format(" -> no\n"); } } - + } - + if(nea>0){ mea = mea /nea; sea = Math.sqrt( sea/nea - mea*mea ); } if(debugMode>=1)System.out.format(" mean etac %7.2f %7.2f \n",mea*MRAD,sea*MRAD); - + for( RICHParticle pho: photons) { if(pho.get_type()==hypo && pho.get_ParentIndex() == hadron.get_id()){ - - RICHSolution reco = new RICHSolution(); + + RICHSolution reco = new RICHSolution(); if(recotype==0) reco = pho.analytic; if(recotype==1) reco = pho.traced; double etac = reco.get_EtaC(); double chi = mea - 3 *sea; double cha = mea + 3 *sea; - + if(reco.is_OK() && ( etac < chi || etac > cha )) { //reco.set_OK(1); update = 1; @@ -355,10 +190,10 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { } } } - + } if(debugMode>=1)System.out.format(" Done with average \n"); - + int ndir = 0; int nlat = 0; int nspe = 0; @@ -373,21 +208,21 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { double stot = 0.0; for( RICHParticle pho: photons) { if(pho.get_type()==hypo && pho.get_ParentIndex() == hadron.get_id()){ - + RICHSolution reco = new RICHSolution(); if(recotype==0) reco = pho.analytic; if(recotype==1) reco = pho.traced; if(!reco.is_OK()) continue; - + double etac = reco.get_EtaC(); - + int irefle = reco.get_RefleType(); if(irefle<0 || irefle>2) continue; - + chtot+=etac; stot+=etac*etac; ntot++; - + if(irefle==0){ chdir+=etac; sdir+=etac*etac; @@ -405,7 +240,7 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { } } } - + if(ntot>0){ chtot = chtot /ntot; stot = Math.sqrt( stot/ntot - chtot*chtot ); @@ -422,12 +257,12 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { chspe = chspe /nspe; sspe = Math.sqrt( sspe/nspe - chspe*chspe ); } - + RICHSolution hreco = null; String sreco = null; if(recotype==0) {hreco = hadron.analytic; sreco = "ALI";} if(recotype==1) {hreco = hadron.traced; sreco = "TRA";} - + ntot = ndir+nlat+nspe; chtot = 0.0; stot = 0.0; @@ -440,9 +275,9 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { stot = 1/Math.sqrt(stot); sstot = 1/Math.sqrt(sstot); } - + int hypo_pid = RICHConstants.HYPO_LUND[hypo]; - + double madir = 0.0; double c2dir = 0.0; double ssdir = 0.0; @@ -451,16 +286,16 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { double det = Math.pow((refdir*Math.cos(chdir)),2) -1; madir = hadron.get_momentum() * hadron.get_momentum() * det; if(debugMode>=1)System.out.format(" Refdir %7.4f \n",refdir); - + ssdir = sdir/Math.sqrt(ndir-1); c2dir = Math.abs(chdir - hadron.changle(hypo_pid,0)) / ssdir; } - + hreco.set_Ndir(ndir); hreco.set_Chdir(chdir); hreco.set_RMSdir(sdir); hreco.set_Madir(madir); - + double malat = 0.0; double c2lat = 0.0; double sslat = 0.0; @@ -469,16 +304,16 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { double det = Math.pow((reflat*Math.cos(chlat)),2) -1; malat = hadron.get_momentum() * hadron.get_momentum() * det; if(debugMode>=1)System.out.format(" Reflat %7.4f \n",reflat); - + sslat = slat/Math.sqrt(nlat-1); c2lat = Math.abs(chlat - hadron.changle(hypo_pid,1)) / sslat; } - + hreco.set_Nlat(nlat); hreco.set_Chlat(chlat); hreco.set_RMSlat(slat); hreco.set_Malat(malat); - + double maspe = 0.0; double c2spe = 0.0; double ssspe = 0.0; @@ -487,16 +322,16 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { double det = Math.pow((refspe*Math.cos(chspe)),2) -1; maspe = hadron.get_momentum() * hadron.get_momentum() * det; if(debugMode>=1)System.out.format(" Refspe %7.4f \n",refspe); - + ssspe = sspe/Math.sqrt(nspe-1); c2spe = Math.abs(chspe - hadron.changle(hypo_pid,2)) / ssspe; } - + hreco.set_Nspe(nspe); hreco.set_Chspe(chspe); hreco.set_RMSspe(sspe); hreco.set_Maspe(maspe); - + double matot = 0.0; double c2tot = 0.0; if(chtot>0){ @@ -504,50 +339,48 @@ public void get_ChMean(RICHParticle hadron, int hypo, int recotype) { double det = Math.pow((reftot*Math.cos(chtot)),2) -1; matot = hadron.get_momentum() * hadron.get_momentum() * det; if(debugMode>=2)System.out.format(" Reftot %7.4f \n",reftot); - + c2tot = Math.abs(chtot - hadron.changle(hypo_pid,0)) / sstot; } - + hreco.set_Ntot(ntot); hreco.set_Chtot(chtot); hreco.set_RMStot(stot); hreco.set_Matot(matot); - + if(debugMode>=1) System.out.format("%d %s: %s %7.2f %7.2f %5d %7.4f \n", eventID, - sreco,RICHConstants.HYPO_LUND[hypo],hadron.get_momentum(),hadron.lab_theta*RAD,hadron.get_CLASpid(),hadron.refi_emission); - System.out.format("%d --> dir %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, - ndir,hadron.changle(hypo_pid,0)*MRAD,chdir*MRAD,sdir*MRAD,ssdir*MRAD,c2dir,madir); - System.out.format("%d --> lat %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, - nlat,hadron.changle(hypo_pid,1)*MRAD,chlat*MRAD,slat*MRAD,sslat*MRAD,c2lat,malat); - System.out.format("%d --> spe %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, - nspe,hadron.changle(hypo_pid,2)*MRAD,chspe*MRAD,sspe*MRAD,ssspe*MRAD,c2spe,maspe); - System.out.format("%d --> tot %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, - ntot,hadron.changle(hypo_pid,0)*MRAD,chtot*MRAD,stot*MRAD,sstot*MRAD,c2tot,matot); - + sreco,RICHConstants.HYPO_LUND[hypo],hadron.get_momentum(),hadron.lab_theta*RAD,hadron.get_CLASpid(),hadron.refi_emission); + System.out.format("%d --> dir %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, + ndir,hadron.changle(hypo_pid,0)*MRAD,chdir*MRAD,sdir*MRAD,ssdir*MRAD,c2dir,madir); + System.out.format("%d --> lat %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, + nlat,hadron.changle(hypo_pid,1)*MRAD,chlat*MRAD,slat*MRAD,sslat*MRAD,c2lat,malat); + System.out.format("%d --> spe %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, + nspe,hadron.changle(hypo_pid,2)*MRAD,chspe*MRAD,sspe*MRAD,ssspe*MRAD,c2spe,maspe); + System.out.format("%d --> tot %d %7.2f %7.2f %7.2f %7.2f %8.5f %8.5f \n",eventID, + ntot,hadron.changle(hypo_pid,0)*MRAD,chtot*MRAD,stot*MRAD,sstot*MRAD,c2tot,matot); + } - - - // ---------------- + + public void get_HypoPID(RICHParticle hadron, int recotype, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + int n_tot[] = {0, 0, 0, 0}; // photons in likelihood - int n_sig[] = {0, 0, 0, 0}; // signal photons + int n_sig[] = {0, 0, 0, 0}; // signal photons int n_bck[] = {0, 0, 0, 0}; // background photons int n_dir[] = {0, 0, 0, 0}; int n_lat[] = {0, 0, 0, 0}; int n_spe[] = {0, 0, 0, 0}; - + double n_exp[] = {0.0, 0.0, 0.0, 0.0}; double c2_sig[] = {0.0, 0.0, 0.0, 0.0}; double lh_sig[] = {0.0, 0.0, 0.0, 0.0}; double lh_ref[] = {0.0, 0.0, 0.0, 0.0}; double lh_dnn[] = {0.0, 0.0, 0.0, 0.0}; double lh_all[] = {0.0, 0.0, 0.0, 0.0}; - + double ch_sig[] = {0.0, 0.0, 0.0, 0.0}; double ch_dir[] = {0.0, 0.0, 0.0, 0.0}; double ch_lat[] = {0.0, 0.0, 0.0, 0.0}; @@ -556,46 +389,46 @@ public void get_HypoPID(RICHParticle hadron, int recotype, RICHParameters richpa double ma_dir[] = {0.0, 0.0, 0.0, 0.0}; double ma_lat[] = {0.0, 0.0, 0.0, 0.0}; double ma_spe[] = {0.0, 0.0, 0.0, 0.0}; - + double ch_had = 0.0; - + for (int hypo=0; hypo=2){ System.out.format("------------------------ \n"); System.out.format("Likelihood (PASS2) for reco %d hypo %s \n",recotype, RICHConstants.HYPO_STRING[hypo]); System.out.format("------------------------ \n"); } - + for( RICHParticle pho: photons) { if(pho.get_type()==hypo && pho.get_ParentIndex() == hadron.get_id()){ - + RICHSolution reco = pho.traced; if(recotype==0) reco = pho.analytic; - + if(!reco.is_used()){ - if(debugMode>=2)System.out.format("pho %4d %3d %3d rejected %3d %3d \n",pho.get_id(),pho.get_ParentIndex(), pho.get_HitIndex(), reco.get_OK(), reco.status()); + if(debugMode>=2)System.out.format("pho %4d %3d %3d rejected %3d %3d \n",pho.get_id(),pho.get_ParentIndex(), pho.get_HitIndex(), reco.get_OK(), reco.status()); continue; } - + double etac = reco.get_EtaC(); int irefle = reco.get_RefleType(); double Npho = hadron.nchangle(hypo_pid, irefle); double NphoEle = hadron.nchangle(11, irefle); - + double htime = pho.get_HitTime(); double t_time = pho.get_StartTime() + pho.traced.get_time(); - - if(debugMode>=2)System.out.format("pho %4d %3d %3d (%4d) %8.4f [%8.4f] %7.2f [%7.2f] %4d %7.2f %7.2f ",pho.get_id(), - pho.get_ParentIndex(), pho.get_HitIndex(), reco.get_OK(), etac*MRAD, + + if(debugMode>=2)System.out.format("pho %4d %3d %3d (%4d) %8.4f [%8.4f] %7.2f [%7.2f] %4d %7.2f %7.2f ",pho.get_id(), + pho.get_ParentIndex(), pho.get_HitIndex(), reco.get_OK(), etac*MRAD, hadron.changle(hypo_pid,irefle)*MRAD, htime, t_time, irefle, NphoEle, Npho); - + // prob for signal double prob = pho.calc_HypoYield(hadron, hypo_pid, recotype, Npho, 0); double prob_ref = pho.calc_HypoYield(hadron, hypo_pid, recotype, Npho, 1); double c2 = pho.calc_HypoC2(hadron, hypo_pid, recotype); - + // ATT: why here and not when the photon is created ? //reco.set_hypo(hypo_pid); // This is for the single photon, assig_PID does for the particle @@ -603,7 +436,7 @@ public void get_HypoPID(RICHParticle hadron, int recotype, RICHParameters richpa if(hypo==1) reco.set_PiProb(Math.log(1./prob)); if(hypo==2) reco.set_KProb(Math.log(1./prob)); if(hypo==3) reco.set_PrProb(Math.log(1./prob)); - + double refind = hadron.get_chindex(hypo_pid,irefle); double det = Math.pow((refind*Math.cos(etac)),2) -1; lh_sig[hypo] += 2*Math.log(1./prob); @@ -630,13 +463,13 @@ public void get_HypoPID(RICHParticle hadron, int recotype, RICHParameters richpa } n_tot[hypo]++; if(!reco.is_OK())n_bck[hypo]++; - if(debugMode>=2)System.out.format(" --> %10.4g %10.4g %10.4g %10.4g %10.4g %7.2f\n", + if(debugMode>=2)System.out.format(" --> %10.4g %10.4g %10.4g %10.4g %10.4g %7.2f\n", prob, prob_ref, Math.log(1./prob), Math.log(prob_ref), Math.log(prob_ref/prob),c2); - + if(debugMode>=3) pho.shortshow(); } } - + if(richpar.USE_ELECTRON_ANGLES==1){ for(int ir=0; ir0) ch_dir[hypo] = ch_dir[hypo]/n_dir[hypo]; if(n_lat[hypo]>0) ch_lat[hypo] = ch_lat[hypo]/n_lat[hypo]; if(n_spe[hypo]>0) ch_spe[hypo] = ch_spe[hypo]/n_spe[hypo]; - if(n_dir[hypo]>0 || n_lat[hypo]>0 || n_spe[hypo]>0) + if(n_dir[hypo]>0 || n_lat[hypo]>0 || n_spe[hypo]>0) ma_sig[hypo] = (ma_dir[hypo]+ma_lat[hypo]+ma_spe[hypo])/(n_dir[hypo]+n_lat[hypo]+n_spe[hypo]); - + if(debugMode>=2)System.out.format("Eve %d %7.2f raw like hypo %5d : %7.2f %4d %4d %10.4g %7.2f %7.2f %7.2f\n", eventID,hadron.get_momentum(),hypo_pid,n_exp[hypo],n_sig[hypo],n_bck[hypo],lh_sig[hypo],lh_dnn[hypo],ch_sig[hypo]*MRAD,c2_sig[hypo]); - + } - + RICHSolution hreco = hadron.traced; if(recotype==0)hreco = hadron.analytic; double newRQ = hreco.assign_HypoPID(lh_all); - + int best_hypo = -1; - int zero = 0; + int zero = 0; double bestRL = 0.0; double bestC2 = 0.0; if(hreco.get_BestH()>0){ for (int hypo=0; hypo=0){ hreco.set_BestRL(bestRL); @@ -694,7 +527,7 @@ public void get_HypoPID(RICHParticle hadron, int recotype, RICHParameters richpa hreco.set_BestCH(ch_sig[best_hypo]); hreco.set_BestNpho(n_tot[best_hypo]); hreco.set_BestMass(ma_sig[best_hypo]); - + hreco.set_Ndir(n_dir[best_hypo]); hreco.set_Nlat(n_lat[best_hypo]); hreco.set_Nspe(n_spe[best_hypo]); @@ -702,7 +535,7 @@ public void get_HypoPID(RICHParticle hadron, int recotype, RICHParameters richpa hreco.set_Chlat(ch_lat[best_hypo]); hreco.set_Chspe(ch_spe[best_hypo]); } - + if(debugMode>=1){ for (int hypo=0; hypo %10.4f %10.4g (%10.4g %7.2f)\n", - hypo_pid, hreco.get_BestH(), n_exp[hypo], n_tot[hypo], n_sig[hypo], n_bck[hypo], n_spe[hypo], - lh_sig[hypo], lh_ref[hypo], lh_dnn[hypo], lh_all[hypo], (lh_all[hypo]+lh_ref[hypo]), tmp_rl, tmp_c2); + hypo_pid, hreco.get_BestH(), n_exp[hypo], n_tot[hypo], n_sig[hypo], n_bck[hypo], n_spe[hypo], + lh_sig[hypo], lh_ref[hypo], lh_dnn[hypo], lh_all[hypo], (lh_all[hypo]+lh_ref[hypo]), tmp_rl, tmp_c2); } - + String hstri = "Traced PID"; if(recotype==0) hstri="Analytic PID"; System.out.format("%s %5d %8d P %6.2f %7.2f PID [%5d] ", @@ -726,51 +559,49 @@ public void get_HypoPID(RICHParticle hadron, int recotype, RICHParameters richpa //double c2r = 12.; //if(n_sig[best_hypo]>1) c2r = c2_sig[best_hypo]/(2*n_sig[best_hypo]); System.out.format("%5d %5d Npho %6d %6d %6d [%6.2f] Eta %7.2f [%7.2f] C2 %7.2f [%7.2f] RQ %7.3f %7.3f %4d %4d \n", - hadron.get_RICHpid(), hreco.get_secH(), + hadron.get_RICHpid(), hreco.get_secH(), n_sig[best_hypo], n_bck[best_hypo], n_spe[best_hypo], n_exp[best_hypo], ch_sig[best_hypo]*MRAD, hadron.changle(11,0)*MRAD, bestRL, bestC2, newRQ, hreco.get_ReQP(),hadron.ilay_emission, hadron.ico_emission); }else{ System.out.format("\n"); } } - + } - - - // ---------------- + + public void get_LHCbpid(RICHParticle hadron, int recotype, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + int n_sig[] = {0, 0, 0, 0}; double lh_sig[] = {0.0, 0.0, 0.0, 0.0}; double ch_sig[] = {0.0, 0.0, 0.0, 0.0}; - + double ch_had = 0.0; double FAC = 1.0; - + for (int hypo=0; hypo=1)System.out.format("Likelihood (LHCB) for reco %d hypo %s \n",recotype, RICHConstants.HYPO_STRING[hypo]); - + for( RICHParticle pho: photons) { if(pho.get_type()==hypo && pho.get_ParentIndex() == hadron.get_id()){ - + RICHSolution reco = pho.traced; if(recotype==0) reco = pho.analytic; if(!reco.is_used()) continue; - + double etac = reco.get_EtaC(); - + if(debugMode>=1)System.out.format("calc prob for photon %d %7.2f \n",pho.get_id(), etac*MRAD); - + double prob = pho.pid_LHCb(hadron, hypo_pid, recotype, 0); double prob_norm = pho.pid_LHCb(hadron, hypo_pid, recotype, 1); - + double ratiolog = Math.log(prob)/Math.log(prob_norm); - + if(hypo==0) reco.set_ElProb(ratiolog*FAC); if(hypo==1) reco.set_PiProb(ratiolog*FAC); if(hypo==2) reco.set_KProb(ratiolog*FAC); @@ -780,20 +611,20 @@ public void get_LHCbpid(RICHParticle hadron, int recotype, RICHParameters richpa ch_sig[hypo] += ratiolog*etac; n_sig[hypo]++; if(debugMode>=1)System.out.format(" --> %8.4f %8.4f %g \n", prob, prob_norm, ratiolog); - + if(debugMode>=2) pho.shortshow(); } } - + if(lh_sig[hypo]>0) ch_sig[hypo] = ch_sig[hypo]/lh_sig[hypo]; if(debugMode>=1)System.out.format("raw like hypo %2d : %4d %10.4g %7.2f \n", hypo,n_sig[hypo],lh_sig[hypo],ch_sig[hypo]*MRAD); } - + if(lh_sig[1]>0 || lh_sig[2]>0 || lh_sig[3]>0) ch_had=(ch_sig[1]*lh_sig[1] + ch_sig[2]*lh_sig[2] + ch_sig[3]*lh_sig[3])/(lh_sig[1] + lh_sig[2] + lh_sig[3]); - - + + for (int hypo=0; hypo=1)System.out.format("assign %5d %3d %3d %7.3f %7.2f \n",hreco.get_BestH(),best_hypo,sec_hypo,newRQ,bestRL); - + if(best_hypo>-1){ hreco.set_BestCH(ch_sig[best_hypo]); hreco.set_BestNpho(n_sig[best_hypo]); hreco.set_BestRL(bestRL); } if(best_hypo>-1 && debugMode>=1) - System.out.format("%s eve %8d mom %6.2f xy %7.2f %7.2f %7.2f %7.2f %8.2f %8.4f Npho %5d %10.4g %3d %10.4g %3d %10.4g --> %8.5f %7.2f %7.2f %3d %3d\n", - hstri,eventID, hadron.get_momentum(), - hadron.direct_ray.origin().x(), hadron.direct_ray.origin().y(), hadron.get_HitPos().x(), hadron.get_HitPos().y(), - hadron.changle(best_hypo,0)*MRAD, hadron.refi_emission, n_sig[best_hypo], lh_sig[best_hypo], - hreco.get_BestH()*hadron.charge(), hreco.get_Bestprob(), hreco.get_secH(), hreco.get_secprob(), - newRQ, ch_sig[best_hypo]*MRAD, ch_had*MRAD, hadron.get_CLASpid(), hadron.get_RICHpid()); - + System.out.format("%s eve %8d mom %6.2f xy %7.2f %7.2f %7.2f %7.2f %8.2f %8.4f Npho %5d %10.4g %3d %10.4g %3d %10.4g --> %8.5f %7.2f %7.2f %3d %3d\n", + hstri,eventID, hadron.get_momentum(), + hadron.direct_ray.origin().x(), hadron.direct_ray.origin().y(), hadron.get_HitPos().x(), hadron.get_HitPos().y(), + hadron.changle(best_hypo,0)*MRAD, hadron.refi_emission, n_sig[best_hypo], lh_sig[best_hypo], + hreco.get_BestH()*hadron.charge(), hreco.get_Bestprob(), hreco.get_secH(), hreco.get_secprob(), + newRQ, ch_sig[best_hypo]*MRAD, ch_had*MRAD, hadron.get_CLASpid(), hadron.get_RICHpid()); + } - - - // ---------------- + + public void get_pid(RICHParticle hadron, int recotype, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + int n_sig[] = {0, 0, 0, 0}; double lh_sig[] = {0.0, 0.0, 0.0, 0.0}; double ch_sig[] = {0.0, 0.0, 0.0, 0.0}; - + int n_bg[] = {0, 0, 0, 0}; double lh_bg[] = {0.0, 0.0, 0.0, 0.0}; double ch_bg[] = {0.0, 0.0, 0.0, 0.0}; - + double ch_had = 0.0; double FAC = 1.0; - + for (int hypo=0; hypo=1)System.out.format("Likelihood (PASS1) for reco %d hypo %s \n",recotype, RICHConstants.HYPO_STRING[hypo]); - + double prob = 0.0; for( RICHParticle pho: photons) { if(pho.get_type()==hypo && pho.get_ParentIndex() == hadron.get_id()){ - + RICHSolution reco = pho.traced; if(recotype==0) reco = pho.analytic; if(!reco.is_used()) continue; - + double etac = reco.get_EtaC(); - + if(debugMode>=1)System.out.format("calc prob for photon %d %7.2f ",pho.get_id(), etac*MRAD); - + // prob for backgound prob = pho.pid_probability(hadron, 0, recotype); if(prob-1>=richpar.PIXEL_NOMINAL_DARKRATE){ @@ -882,15 +711,15 @@ public void get_pid(RICHParticle hadron, int recotype, RICHParameters richpar) { }else{ //System.out.format(" Wrong prob for background %g \n",prob-1); } - + // prob for signal prob = pho.pid_probability(hadron, hypo_pid, recotype); - + if(hypo==0) reco.set_ElProb(Math.log(prob)*FAC); if(hypo==1) reco.set_PiProb(Math.log(prob)*FAC); if(hypo==2) reco.set_KProb(Math.log(prob)*FAC); if(hypo==3) reco.set_PrProb(Math.log(prob)*FAC); - + if(prob-1>richpar.PIXEL_NOMINAL_DARKRATE){ lh_sig[hypo] += Math.log(prob); ch_sig[hypo] += Math.log(prob)*etac; @@ -900,20 +729,20 @@ public void get_pid(RICHParticle hadron, int recotype, RICHParameters richpar) { if(debugMode>=1)System.out.format(" \n"); //System.out.format(" Wrong prob for electron %g \n",prob-1); } - + if(debugMode>=2) pho.shortshow(); } } - + if(lh_sig[hypo]>0) ch_sig[hypo] = ch_sig[hypo]/lh_sig[hypo]; if(debugMode>=1)System.out.format("raw like hypo %2d : %4d %10.4g %10.4g %7.2f \n", hypo,n_sig[hypo],lh_sig[hypo],lh_bg[hypo],ch_sig[hypo]*MRAD); } - + if(lh_sig[1]>0 || lh_sig[2]>0 || lh_sig[3]>0) ch_had=(ch_sig[1]*lh_sig[1] + ch_sig[2]*lh_sig[2] + ch_sig[3]*lh_sig[3])/(lh_sig[1] + lh_sig[2] + lh_sig[3]); - - + + for (int hypo=0; hypo=1)System.out.format("assign %5d %3d %3d %7.3f %7.2f \n",hreco.get_BestH(),best_hypo,sec_hypo,newRQ,bestRL); - + if(best_hypo>-1){ hreco.set_BestCH(ch_sig[best_hypo]); hreco.set_BestNpho(n_sig[best_hypo]); hreco.set_BestRL(bestRL); } if(best_hypo>-1 && debugMode>=1) - System.out.format("%s eve %8d mom %6.2f xy %7.2f %7.2f %7.2f %7.2f %8.2f %8.4f Npho %5d %10.4g %3d %10.4g %3d %10.4g --> %8.5f %7.2f %7.2f %3d %3d\n", - hstri,eventID, hadron.get_momentum(), - hadron.direct_ray.origin().x(), hadron.direct_ray.origin().y(), hadron.get_HitPos().x(), hadron.get_HitPos().y(), - hadron.changle(best_hypo,0)*MRAD, hadron.refi_emission, n_sig[best_hypo], lh_sig[best_hypo], - hreco.get_BestH()*hadron.charge(), hreco.get_Bestprob(), hreco.get_secH(), hreco.get_secprob(), - newRQ, ch_sig[best_hypo]*MRAD, ch_had*MRAD, hadron.get_CLASpid(), hadron.get_RICHpid()); - + System.out.format("%s eve %8d mom %6.2f xy %7.2f %7.2f %7.2f %7.2f %8.2f %8.4f Npho %5d %10.4g %3d %10.4g %3d %10.4g --> %8.5f %7.2f %7.2f %3d %3d\n", + hstri,eventID, hadron.get_momentum(), + hadron.direct_ray.origin().x(), hadron.direct_ray.origin().y(), hadron.get_HitPos().x(), hadron.get_HitPos().y(), + hadron.changle(best_hypo,0)*MRAD, hadron.refi_emission, n_sig[best_hypo], lh_sig[best_hypo], + hreco.get_BestH()*hadron.charge(), hreco.get_Bestprob(), hreco.get_secH(), hreco.get_secprob(), + newRQ, ch_sig[best_hypo]*MRAD, ch_had*MRAD, hadron.get_CLASpid(), hadron.get_RICHpid()); + } - - - // ---------------- + + public void showEvent(){ - // ---------------- - + System.out.format(" ------------------------------------ \n"); System.out.format(" RICH Event with nhad %4d and npho %4d \n",hadrons.size(),photons.size()); System.out.format(" ------------------------------------ \n"); for(int hid=0; hid %s ] [ %s --> %s ] [ %8.2f %8.2f --> %8.2f %8.2f ]\n", - hid,had.get_id(),had.get_ParentIndex(),had.get_HitIndex(), - had.lab_emission.toStringBrief(2), - had.ref_emission.toStringBrief(2), - had.get_HitPos().toStringBrief(2), had.ref_impact.toStringBrief(2), - had.lab_phi*RAD, had.lab_theta*RAD, had.ref_phi*RAD, had.ref_theta*RAD); + System.out.format(" had %3d %3d %3d %3d [ %s --> %s ] [ %s --> %s ] [ %8.2f %8.2f --> %8.2f %8.2f ]\n", + hid,had.get_id(),had.get_ParentIndex(),had.get_HitIndex(), + had.lab_emission.toStringBrief(2), + had.ref_emission.toStringBrief(2), + had.get_HitPos().toStringBrief(2), had.ref_impact.toStringBrief(2), + had.lab_phi*RAD, had.lab_theta*RAD, had.ref_phi*RAD, had.ref_theta*RAD); for(int ipho=0; ipho=2)System.out.format("Select %s photons for hadron %3d hypo %5d\n",stype,hadron.get_id(),hypo_pid); for( RICHParticle pho: photons){ - + if(!pho.is_real())continue; if(pho.get_type()!=hypo)continue; if(pho.get_ParentIndex() != hadron.get_id()) continue; - + RICHParticle had = get_Hadron( pho.get_ParentIndex() ); - + RICHSolution reco = pho.traced; if(recotype==0) { if (had.get_Status()!=1)continue; - reco = pho.analytic; + reco = pho.analytic; } - + double htime = pho.get_HitTime(); double dtime = pho.get_StartTime() + reco.get_time() - htime; if(debugMode>=2)System.out.format(" %4d --> [%7.2f + %7.2f] %7.2f --> %7.2f ",pho.get_HitIndex(),pho.get_StartTime(),reco.get_time(),htime,dtime); - + int irefle = reco.get_RefleType(); if(irefle<0 || irefle>2) continue; - + // open acceptance intervals around the given hypothesis double CHMI = had.changle(hypo_pid,irefle) - richpar.NSIGMA_CHERENKOV * had.schangle(irefle); double CHMA = had.changle(hypo_pid,irefle) + richpar.NSIGMA_CHERENKOV * had.schangle(irefle); double DTMI = pho.chtime() - richpar.NSIGMA_TIME * pho.schtime(); double DTMA = pho.chtime() + richpar.NSIGMA_TIME * pho.schtime(); - + double etaC = reco.get_EtaC(); if(debugMode>=2)System.out.format(" %4d --> %7.2f [%7.2f-%7.2f] %7.2f [%6.2f:%6.2f] ", pho.get_HitIndex(),etaC*MRAD, CHMI*MRAD, CHMA*MRAD, dtime, DTMI, DTMA); - + // select acceptable Cherenkov solution int SELE = 0; if(etaC>0 && reco.status()==0) SELE+=1; if(dtime > DTMI && dtime < DTMA) SELE+=10; if(etaC>0 && etaC>CHMI && etaC0 && etaC>CHMI && etaC DTMI && dtime < DTMA)) SELE=11; - + reco.set_OK(SELE); - + if(debugMode>=2){ if(reco.is_OK()){ System.out.format(" --> %4d (%5d %8d %8d %8d)\n", @@ -1049,21 +874,21 @@ public void select_Photons(RICHParticle hadron, int recotype, RICHParameters ric }else{ System.out.format(" --> %4d (rejected) \n",reco.get_OK()); } - } + } } } - + for (int hypo=0; hypo=1){ for( RICHParticle pho: photons) { RICHSolution reco = pho.traced; if(recotype==0)reco = pho.analytic; - + if(!reco.is_used())continue; - + System.out.format("sele pixel %4d for %s pho %4d %3d %7.2f OK %3d [%6d : %6d %6d ] %3d\n", pho.get_HitIndex(), stype, pho.get_id(), pho.get_type(), reco.get_EtaC()*MRAD, reco.get_OK(),reco.get_FirstRefle(), reco.get_RefleLayers(), reco.get_RefleCompos(), reco.status()); } - + } - + } - - // ---------------- + public void analyze_Photons(int hypo, RICHRayTrace richtrace){ - // ---------------- - + int debugMode = 0; int jj=0; for( RICHParticle photon: photons){ if(photon.get_type()==hypo){ - - System.out.format(" Analyze Photon %4d from Hadron %3d \n",jj,photon.get_ParentIndex()); + + System.out.format(" Analyze Photon %4d from Hadron %3d \n",jj,photon.get_ParentIndex()); RICHParticle richhadron = get_Hadron( photon.get_ParentIndex() ); if(debugMode>=1){ System.out.format(" --------------------------------- \n"); - System.out.format(" Analyze Photon %4d from Hadron %3d meas hit %s \n",jj,richhadron.get_id(), - photon.get_HitPos().toStringBrief(2)); + System.out.format(" Analyze Photon %4d from Hadron %3d meas hit %s \n",jj,richhadron.get_id(), + photon.get_HitPos().toStringBrief(2)); System.out.format(" --------------------------------- \n"); } if (richhadron.get_Status()==1){ @@ -1127,24 +950,22 @@ public void analyze_Photons(int hypo, RICHRayTrace richtrace){ jj++; } } - - // ---------------- + public void trace_Photons(RICHParticle hadron, int hypo, RICHRayTrace richtrace, RICHCalibration richcal){ - // ---------------- - + int debugMode = 0; - + int jj=0; if(hypo<0 || hypo>=RICHConstants.N_HYPO ) return; for( RICHParticle photon: photons){ if(photon.get_ParentIndex()==hadron.get_id() && photon.get_type()==hypo){ - + int pmt = hits.get(photon.get_HitIndex()).get_pmt(); if(debugMode>=1){ System.out.format(" --------------------------------- \n"); System.out.format(" Hypo %s: Trace Photon %4d %4d from Hadron %3d aero [%3d %3d %3d %4d] meas hit %4d %s pmt %4d \n", - RICHConstants.HYPO_LUND[hypo],jj,photon.get_id(),hadron.get_id(),photon.get_sector(), photon.ilay_emission, photon.ico_emission, - photon.iqua_emission, photon.get_HitIndex(),photon.get_HitPos().toStringBrief(2), pmt); + RICHConstants.HYPO_LUND[hypo],jj,photon.get_id(),hadron.get_id(),photon.get_sector(), photon.ilay_emission, photon.ico_emission, + photon.iqua_emission, photon.get_HitIndex(),photon.get_HitPos().toStringBrief(2), pmt); } //RICHParticle richhadron = get_Hadron( photon.get_ParentIndex() ); richtrace.find_EtaC_raytrace_steps(hadron, photon, hypo); @@ -1160,32 +981,30 @@ public void trace_Photons(RICHParticle hadron, int hypo, RICHRayTrace richtrace, jj++; } } - - - // ---------------- + + public void associate_Throws(RICHParticle hadron, int hypo, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; int match_nchi2 = 0 ; double match_chi2 = 0.0 ; - + if(hypo<0 || hypo>=RICHConstants.N_HYPO ) return; - + if(debugMode>=1)System.out.format("Associate photon with trials \n"); int jj=0; for( RICHParticle photon: photons){ if(photon.get_ParentIndex()==hadron.get_id() && photon.get_type()==hypo){ - + if(debugMode>=1)System.out.format(" Hypo %s: Look for pho id %4d xy %8.2f %8.2f time %7.2f \n", - RICHConstants.HYPO_LUND[hypo],photon.get_id(),photon.get_HitPos().x(),photon.get_HitPos().y(), photon.get_HitTime()); + RICHConstants.HYPO_LUND[hypo],photon.get_id(),photon.get_HitPos().x(),photon.get_HitPos().y(), photon.get_HitTime()); int ii=0; double distmin = 99999; for( RICHParticle trial: photons){ if(trial.get_type()==hypo+10 && trial.traced.exist()){ double dist = trial.get_HitPos().distance(photon.get_HitPos()); if(debugMode>=1)System.out.format(" --> trial %4d xy %8.2f %8.2f time %7.2f \n", trial.get_id(), - trial.get_HitPos().x(),trial.get_HitPos().y(), trial.get_HitTime()); + trial.get_HitPos().x(),trial.get_HitPos().y(), trial.get_HitTime()); if(dist < distmin){ distmin = dist; if(distmin=1)System.out.format(" --> store throw id %d xy %8.2f %8.2f time %7.2f --> dist %7.2f ch2 %7.2f tprob %8.6f %10.2f \n", - photon.trial_pho.get_id(),photon.trial_pho.get_HitPos().x(),photon.trial_pho.get_HitPos().y(), photon.trial_pho.get_HitTime(), + photon.trial_pho.get_id(),photon.trial_pho.get_HitPos().x(),photon.trial_pho.get_HitPos().y(), photon.trial_pho.get_HitTime(), distmin, (distmin/richpar.RICH_HITMATCH_RMS), tprob-1, match_chi2); } } } jj++; } - + if(match_nchi2>0)match_chi2=(match_chi2)/match_nchi2; if(debugMode>=1)System.out.format(" CHI2 %d --> %7.2f \n",match_nchi2,match_chi2); } - - // ---------------- + public void throw_Photons(RICHParticle hadron, int Nthrows, int hypo, RICHRayTrace richtrace, RICHParameters richpar, RICHCalibration richcal){ - // ---------------- - + int debugMode = 0; Vector3D vhad = hadron.direct_ray.toVector().asUnit(); - + if(hypo<0 || hypo>=RICHConstants.N_HYPO ) return; int hypo_pid = RICHConstants.HYPO_LUND[hypo]; - + int NTHE = 1; if(richpar.TRACE_NITROGEN==1 && hypo==0)NTHE=2; - + for (int ithe=0; ithe=1)System.out.format("theta %5d %5d %3d %7.2f %4d %3d %7.2f %7.2f %7.2f ", - eventID,hypo_pid,hadron.charge(),hadron.get_momentum(),hadron.ilay_emission+201,hadron.ico_emission+1, - hadron.changle(hypo_pid,0)*MRAD,hadron.changle(hypo_pid,1)*MRAD,hadron.changle(hypo_pid,2)*MRAD); + eventID,hypo_pid,hadron.charge(),hadron.get_momentum(),hadron.ilay_emission+201,hadron.ico_emission+1, + hadron.changle(hypo_pid,0)*MRAD,hadron.changle(hypo_pid,1)*MRAD,hadron.changle(hypo_pid,2)*MRAD); if(theta==0){if(debugMode>=1)System.out.format(" -> below threshold "); continue;} if(debugMode>=1)System.out.format("\n TTT %3d %3d %3d %7.2f \n",hypo,NTHE,ithe,theta*MRAD); - + // Define Cherenkov rotation Vector3D X_ONE = new Vector3D(1., 0., 0.); Vector3D vax = (vhad.cross(X_ONE)).asUnit(); Quaternion qch = new Quaternion(theta, vax); Vector3D vch = (qch.rotate(vhad)).asUnit(); - + if(debugMode>=3){ System.out.format(" --> vhad %s | %8.3f %8.3f \n", vhad.toStringBrief(2), hadron.lab_theta*RAD, hadron.lab_phi*RAD); System.out.format(" --> vax %s | %8.3f %8.3f \n", vax.toStringBrief(2), vax.theta()*RAD, vax.phi()*RAD); System.out.format(" --> vch %s | %8.3f %8.3f \n", vch.toStringBrief(2), vch.theta()*RAD, vch.phi()*RAD); - System.out.format(" --> resulting angle %8.3f %8.3f \n", vch.angle(vhad)*MRAD, vch.angle(vhad)*RAD); + System.out.format(" --> resulting angle %8.3f %8.3f \n", vch.angle(vhad)*MRAD, vch.angle(vhad)*RAD); } - + int nk=0; double dphi = 2*Math.PI/Nthrows; double cophi = -Math.PI; while (cophi=1){ + if(debugMode>=1){ System.out.println(" ------------------------------------ "); - System.out.format(" Throw photon %4d %s aero %4d %6d at the %8.3f (%8.3f, %8.3f) step %4.1f \n", - photons.size(), RICHConstants.HYPO_STRING[hypo], - hadron.ilay_emission, hadron.ico_emission, theta*MRAD, theta*RAD, cophi*RAD, fac); + System.out.format(" Throw photon %4d %s aero %4d %6d at the %8.3f (%8.3f, %8.3f) step %4.1f \n", + photons.size(), RICHConstants.HYPO_STRING[hypo], + hadron.ilay_emission, hadron.ico_emission, theta*MRAD, theta*RAD, cophi*RAD, fac); System.out.println(" ------------------------------------ "); } - + // Define Cone rotation Quaternion qco = new Quaternion(cophi, vhad); Vector3D vpho = (qco.rotate(vch)).asUnit(); double che_th = vch.angle(vhad); - if(debugMode>=3) System.out.format(" %d %8.2f --> vpho %s | %8.3f %8.3f --> %8.3f %8.3f\n", - photons.size(), cophi*RAD, vpho.toStringBrief(2), vpho.theta()*RAD, vpho.phi()*RAD, che_th*MRAD, che_th*RAD); - + if(debugMode>=3) System.out.format(" %d %8.2f --> vpho %s | %8.3f %8.3f --> %8.3f %8.3f\n", + photons.size(), cophi*RAD, vpho.toStringBrief(2), vpho.theta()*RAD, vpho.phi()*RAD, che_th*MRAD, che_th*RAD); + Point3D emission = hadron.lab_emission; if(ithe==1) { - double Lemi = 3+(cophi+Math.PI)/2./Math.PI*50.; //emission point along the trajectory in gas + double Lemi = 3+(cophi+Math.PI)/2./Math.PI*50.; //emission point along the trajectory in gas emission = new Point3D(hadron.lab_emission, vhad.multiply(Lemi)); if(debugMode>=1)System.out.format("TTT %7.2f %s \n",Lemi,emission.toStringBrief(2)); } @@ -1293,36 +1110,36 @@ public void throw_Photons(RICHParticle hadron, int Nthrows, int hypo, RICHRayTra photon.traced.set_phi(vpho.phi()); photon.traced.set_scale(fac); photon.traced.set_hypo(hypo_pid); - + ArrayList rays = richtrace.RayTrace(photon, vpho); if(rays!=null) { if(debugMode>=2) System.out.format(" Photon traced till PMT detection \n"); photon.traced.set_raytracks(rays); - + photon.set_HitPos( photon.traced.get_hit() ); photon.set_HitTime( photon.get_StartTime() + photon.traced.get_time() ); String head = String.format(" THROW %7de %3d ",eventID,photon.get_id()); if(debugMode>=1)photon.traced.dump_raytrack(head); - + // store in the event if(rays.get(rays.size()-1).is_detected()){ - - // shift (in cm) on PMT surface corresponding to one angular sigma + + // shift (in cm) on PMT surface corresponding to one angular sigma double dthe_res = richtrace.find_dthe_steps(photon); double dphi_res = richtrace.find_dphi_steps(photon); // gate (number of sigma) used in reconstruction double dthe_bin = 2 * richpar.NSIGMA_CHERENKOV; double dphi_bin = dphi/fac/photon.nominal_sChAngle(); - + photon.traced.set_dthe_res(dthe_res); photon.traced.set_dphi_res(dphi_res); photon.traced.set_dthe_bin(dthe_bin); photon.traced.set_dphi_bin(dphi_bin); - + if(debugMode>=1)System.out.format(" --> detected time %7.2f ttime %7.2f dthe (%7.2f, %7.2f) dphi (%7.2f,%7.2f)\n", photon.get_HitTime(),photon.traced.get_time(), dthe_res,dthe_bin,dphi_res,dphi_bin); - + photons.add(photon); fac=1; if(ithe==1)fac=0.2; @@ -1330,9 +1147,9 @@ public void throw_Photons(RICHParticle hadron, int Nthrows, int hypo, RICHRayTra nk++; } } - + } } } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEventBuilder.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEventBuilder.java index f12163ad6a..457cd1c6e5 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEventBuilder.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEventBuilder.java @@ -3,11 +3,8 @@ import java.util.ArrayList; import java.util.List; import java.util.HashMap; - -import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.clas.pdg.PDGDatabase; - import org.jlab.detector.base.DetectorType; import org.jlab.clas.detector.DetectorEvent; import org.jlab.clas.detector.DetectorParticle; @@ -16,107 +13,84 @@ import org.jlab.clas.detector.DetectorData; import org.jlab.clas.detector.RingCherenkovResponse; import org.jlab.io.base.DataBank; - -import org.jlab.detector.base.DetectorLayer; - import org.jlab.geom.prim.Line3D; -import org.jlab.geom.prim.Path3D; import org.jlab.geom.prim.Point3D; -import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Vector3D; - import org.jlab.clas.pdg.PhysicsConstants; import org.jlab.detector.geom.RICH.RICHGeoFactory; -import org.jlab.detector.geom.RICH.RICHGeoConstants; - public class RICHEventBuilder{ - + public int Neve = 0; - - /* - * Reconstruction classes - */ - private final DetectorType[] sharedDetectors = {DetectorType.FTOF,DetectorType.CTOF}; private RICHio richio; private RICHEvent richevent; private RICHGeoFactory richgeo; - private DetectorEvent clasevent; // temporarely only Sector 4 particles !!! - - private HashMap pindex_map = new HashMap(); - - private static double Precision = 0.00000000001; //E-11 is my threshold for defying what 0 is - private static double MRAD=1000.; + private DetectorEvent clasevent; + private HashMap pindex_map = new HashMap<>(); private static double RAD=180/Math.PI; - - // ---------------- + public RICHEventBuilder(DataEvent event, RICHEvent richeve, RICHGeoFactory richgeo, RICHio richio) { - // ---------------- - + this.richevent = richeve; this.richio = richio; this.richgeo = richgeo; - this.clasevent = new DetectorEvent(); - + this.clasevent = new DetectorEvent(); + clasevent.clear(); richevent.clear(); - + set_EventInfo(event); } - - - // ---------------- + + public boolean process_Data(DataEvent event, RICHParameters richpar, RICHCalibration richcal, RICHRayTrace richtrace, RICHTime richtime) { - // ---------------- - + int debugMode = 0; - + /* * look for RICH - DC matches */ if(debugMode>=1)System.out.format("process_DCData \n"); if(!process_DCData(event, richpar)) return false; richtime.save_ProcessTime(3, richevent); - + richio.write_RECBank(event, richevent, richpar); - + /* * create RICH particles */ if(debugMode>=1)System.out.format("process_RICHData\n"); if(!process_RICHData(event, richtrace, richpar, richcal)) return false; richtime.save_ProcessTime(4, richevent); - + /* * analytic solution (direct light only) */ if(debugMode>=1)System.out.format("analyze_Cherenkovs\n"); if(!analyze_Cherenkovs(richtrace, richpar)) return false; richtime.save_ProcessTime(5, richevent); - + /* * ray-traced solution (all photons) */ if(debugMode>=1)System.out.format("reco_Cherenkovs\n"); if(!reco_Cherenkovs(richtrace, richpar, richcal)) return false; richtime.save_ProcessTime(6, richevent); - + if(debugMode>=1)richevent.showEvent(); - + richio.write_CherenkovBanks(event, richevent, richpar); richtime.save_ProcessTime(7, richevent); - + return true; - + } - - - // ---------------- + + public boolean process_DCData(DataEvent event, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + /* Load tracks from time based tracking */ @@ -125,12 +99,12 @@ public boolean process_DCData(DataEvent event, RICHParameters richpar) { System.out.println("RICH EB: Load Tracks"); System.out.println("---------------------------------"); } - + if(!read_ForwardTracks(event)){ if(debugMode>=1)System.out.print(" no useful track in RICH sectors --> disregard RICH reco \n"); return false; } - + /* Load the cluster information */ @@ -139,7 +113,7 @@ public boolean process_DCData(DataEvent event, RICHParameters richpar) { }else{ richevent.add_ResClus( RingCherenkovResponse.readHipoEvent(event, "RICH::Cluster",DetectorType.RICH,1) ); } - + if(debugMode>=1){ if(richevent.get_nResClu()>0){ System.out.format(" ----------------------------------------- \n"); @@ -151,11 +125,11 @@ public boolean process_DCData(DataEvent event, RICHParameters richpar) { System.out.format(" ----------------------------------------- \n"); for (DetectorResponse rclu: richevent.get_ResClus()){ System.out.format("RICHEB Load Clu : --> id %4d pmt %5d ene %8.1f time %8.2f pos %s \n", - rclu.getHitIndex(),rclu.getDescriptor().getComponent(),rclu.getEnergy(),rclu.getTime(),rclu.getPosition().toStringBrief(1)); + rclu.getHitIndex(),rclu.getDescriptor().getComponent(),rclu.getEnergy(),rclu.getTime(),rclu.getPosition().toStringBrief(1)); } } } - + /* Perform the DC tracks to RICH clusters matching */ @@ -165,26 +139,24 @@ public boolean process_DCData(DataEvent event, RICHParameters richpar) { System.out.println("---------------------------------"); } process_HitMatching(richpar); - + if(clasevent.getParticles().size()>0)richevent.add_Matches(getRichResponseList()); - + return true; - + } - - - // ---------------- + + public boolean process_RICHData(DataEvent event, RICHRayTrace richtrace, RICHParameters richpar, RICHCalibration richcal) { - // ---------------- - + int debugMode = 0; - + if(debugMode>=1){ System.out.println("---------------------------------"); System.out.format(" Reco hadrons and photons with npart %d nmatches %d \n", clasevent.getParticles().size(), get_nMatch()); System.out.println("---------------------------------"); } - + /* Load the hit information */ @@ -193,7 +165,7 @@ public boolean process_RICHData(DataEvent event, RICHRayTrace richtrace, RICHPar }else{ richevent.add_ResHits( RingCherenkovResponse.readHipoEvent(event, "RICH::Hit",DetectorType.RICH,0) ); } - + if(richevent.get_nResHit()>0){ if(debugMode>=1){ System.out.format(" --------------------------------------- \n"); @@ -205,13 +177,13 @@ public boolean process_RICHData(DataEvent event, RICHRayTrace richtrace, RICHPar System.out.format(" --------------------------------------- \n"); for (DetectorResponse rhit: richevent.get_ResHits()){ System.out.format(" --> id %4d sec %3d pmt %5d ene %8.1f time %8.2f pos %8.1f %8.1f %8.1f \n", - rhit.getHitIndex(),rhit.getDescriptor().getSector(),rhit.getDescriptor().getComponent(), - rhit.getEnergy(),rhit.getTime(),rhit.getPosition().x(),rhit.getPosition().y(),rhit.getPosition().z()); + rhit.getHitIndex(),rhit.getDescriptor().getSector(),rhit.getDescriptor().getComponent(), + rhit.getEnergy(),rhit.getTime(),rhit.getPosition().x(),rhit.getPosition().y(),rhit.getPosition().z()); } } } - - if(clasevent.getParticles().size()>0){ + + if(clasevent.getParticles().size()>0){ if(find_Hadrons(richtrace, richcal, richpar)){ if(richevent.get_nResHit()>0){ if(!find_Photons(richevent.get_ResHits(), richpar, richcal)){ @@ -226,55 +198,52 @@ public boolean process_RICHData(DataEvent event, RICHRayTrace richtrace, RICHPar }else{ if(debugMode>=1)System.out.println("Found no CLAS particle in sector 4 \n"); } - + return true; - + } - - - // ---------------- + + public boolean read_ForwardTracks(DataEvent event) { - // ---------------- - + int debugMode = 0; - + if(event.hasBank("REC::Track") && event.hasBank("REC::Particle") && event.hasBank("REC::Traj")){ - + DataBank tbank = event.getBank("REC::Track"); DataBank pbank = event.getBank("REC::Particle"); DataBank rbank = event.getBank("REC::Traj"); if(debugMode>=1) System.out.format("Look for tracks after EB: REC:tk %3d REC:part %3d REC:Traj %3d \n",tbank.rows(),pbank.rows(),rbank.rows()); - + for(int i = 0 ; i < tbank.rows(); i++){ - + int itk = (int) tbank.getShort("index",i); int ipr = (int) tbank.getShort("pindex",i); int idet = (int) tbank.getByte("detector",i); int isec = (int) tbank.getByte("sector", i); - + int charge = tbank.getByte("q", i); Vector3D pvec = DetectorData.readVector(pbank, ipr, "px", "py", "pz"); Vector3D vertex = DetectorData.readVector(pbank, ipr, "vx", "vy", "vz"); int CLASpid = check_CLASpid( pbank.getInt("pid",ipr) ); - + DetectorTrack tr = new DetectorTrack(charge,pvec.mag(),i); tr.setVector(pvec.x(), pvec.y(), pvec.z()); tr.setVertex(vertex.x(), vertex.y(), vertex.z()); tr.setSector(isec); - - if(debugMode>=1){ + + if(debugMode>=1){ System.out.format(" from REC::Track %3d det %4d --> tk %4d sec %4d theta %8.2f --> part %4d pid %d \n", - i,idet,itk,tr.getSector(), pvec.theta()*RAD,ipr,CLASpid); + i,idet,itk,tr.getSector(), pvec.theta()*RAD,ipr,CLASpid); } - + /* * disregard central detector tracks */ if(idet!=6)continue; - - int ok = 0; + if(!richgeo.has_RICH(isec)) continue; - + int naero_cross = 0; int ntraj_cross = 0; double traj_path[] = {0.0, 0.0, 0.0}; @@ -289,7 +258,7 @@ public boolean read_ForwardTracks(DataEvent event) { int jlay = (int) rbank.getByte("layer",j); if (jpr==ipr && jtk==itk){ if(debugMode>=1) System.out.format("traj %3d part %3d tk %3d det %3d lay %3d ",j,jpr,jtk,jdet,jlay); - + /* * trajectory plane 42 till 5b.6.2 - 40 since 5c.7.0 - layer 36 since 6b.1.0 */ @@ -304,7 +273,7 @@ public boolean read_ForwardTracks(DataEvent event) { Vector3D vdir = new Vector3D(jcx, jcy, jcz); if(!vdir.unit()) continue; - + if(jdet==DetectorType.DC.getDetectorId() && jlay==36){ traj_cross[0] = new Line3D(jx, jy, jz, vdir.x(), vdir.y(), vdir.z()); traj_path[0] = path; @@ -325,13 +294,13 @@ public boolean read_ForwardTracks(DataEvent event) { naero_cross++; } if(debugMode>=1) System.out.format(" --> %7.2f %7.2f %7.2f | %7.2f %7.2f %7.2f -> %s | path %7.2f ", - jx,jy,jz,jcx,jcy,jcz,vdir.toStringBrief(2),path); + jx,jy,jz,jcx,jcy,jcz,vdir.toStringBrief(2),path); } - + if(debugMode>=1) System.out.format(" [%3d % 3d]\n",ntraj_cross,naero_cross); } } - + //overwrite DC3 with first AERO if present if(debugMode>=1) System.out.format(" AERO: %4d cross found \n",naero_cross); if(naero_cross>0){ @@ -346,221 +315,210 @@ public boolean read_ForwardTracks(DataEvent event) { } } } - + int detid = DetectorType.RICH.getDetectorId(); if(debugMode>=1) System.out.format(" TRAJ: %4d crosses found \n",ntraj_cross); for (int k=0; k0){ tr.addCross(traj_cross[k].origin().x(), traj_cross[k].origin().y(), traj_cross[k].origin().z(), - traj_cross[k].end().x(), traj_cross[k].end().y(), traj_cross[k].end().z() ); - tr.getTrajectory().add(new DetectorTrack.TrajectoryPoint(detid, k, traj_cross[k], (float) traj_path[k], (float) 0., (float) 0.)); + traj_cross[k].end().x(), traj_cross[k].end().y(), traj_cross[k].end().z() ); + tr.getTrajectory().add(new DetectorTrack.TrajectoryPoint(detid, k, traj_cross[k], (float) traj_path[k], (float) 0., (float) 0.)); tr.setPath(traj_path[k]); if(debugMode>=1) System.out.format(" TRAJ: store cross %4d: %3d %3d with path %7.2f \n",k,DetectorType.RICH.getDetectorId(),k,traj_path[k]); } - + } - + if(tr.getCrossCount()==0){if(debugMode>=1)System.out.format("Traj not found \n"); continue;} - + tr.setStatus(ipr); if(debugMode>=1) { - System.out.format(" Track cross N %4d first %s %s %7.2f last %s %s %7.2f path %7.2f status %3d \n \n", tr.getCrossCount(), - tr.getFirstCross().origin().toStringBrief(2), tr.getFirstCross().end().toStringBrief(2), - tr.getPathLength(DetectorType.RICH, 0), - tr.getLastCross().origin().toStringBrief(2), tr.getLastCross().end().toStringBrief(2), - tr.getPathLength(DetectorType.RICH, 1), tr.getPath(),tr.getStatus() ); + System.out.format(" Track cross N %4d first %s %s %7.2f last %s %s %7.2f path %7.2f status %3d \n \n", tr.getCrossCount(), + tr.getFirstCross().origin().toStringBrief(2), tr.getFirstCross().end().toStringBrief(2), + tr.getPathLength(DetectorType.RICH, 0), + tr.getLastCross().origin().toStringBrief(2), tr.getLastCross().end().toStringBrief(2), + tr.getPathLength(DetectorType.RICH, 1), tr.getPath(),tr.getStatus() ); } - + DetectorParticle particle = new DetectorParticle(tr); particle.setPid(CLASpid); particle.setBeta( particle.getTheoryBeta(CLASpid) ); particle.setMass( PDGDatabase.getParticleById(CLASpid).mass() ); - // ATT: FIX ME! + // ATT: FIX ME! clasevent.addParticle(particle); - + } - + }else{ - + if(event.hasBank("TimeBasedTrkg::TBTracks") && event.hasBank("TimeBasedTrkg::Trajectory") && event.hasBank("TimeBasedTrkg::TBCovMat")){ - + String trackBank = "TimeBasedTrkg::TBTracks"; String tracjBank = "TimeBasedTrkg::Trajectory"; String covBank = "TimeBasedTrkg::TBCovMat"; - if(debugMode>=1) System.out.format("Look for tracks before EB: %s %s %s \n",trackBank,tracjBank,covBank); - + if(debugMode>=1) System.out.format("Look for tracks before EB: %s %s %s \n",trackBank,tracjBank,covBank); + List tracks = DetectorData.readDetectorTracks(event, trackBank, tracjBank, covBank); - if(debugMode>=1){ + if(debugMode>=1){ for(int i = 0 ; i < tracks.size(); i++){ Line3D test = tracks.get(i).getLastCross(); System.out.format(" %d sec %d %s\n", i,tracks.get(i).getSector(),test.origin().toString()); } } - + for(int i = 0 ; i < tracks.size(); i++){ - DetectorTrack tr = tracks.get(i); + DetectorTrack tr = tracks.get(i); if(tr.getSector()==4){ tr.setStatus(i); - DetectorParticle particle = new DetectorParticle(tr); + DetectorParticle particle = new DetectorParticle(tr); particle.setPid(211); clasevent.addParticle(particle); } } - + }else{ - - if(debugMode>=1)System.out.format("No track banks: Go back\n"); + + if(debugMode>=1)System.out.format("No track banks: Go back\n"); return false; } } - + if(debugMode>=1){ System.out.format(" \n CLAS-Event PARTICLE found %3d \n",clasevent.getParticles().size()); for(int n = 0; n < clasevent.getParticles().size(); n++){ DetectorParticle p = clasevent.getParticle(n); - DetectorTrack tr = p.getTrack(); + DetectorTrack tr = p.getTrack(); show_Particle(p); - show_Track(tr); + show_Track(tr); } System.out.format(" \n"); } - - if(clasevent.getParticles().size()>0)return true; - return false; + + return !clasevent.getParticles().isEmpty(); } - - - // ---------------- + + public void process_HitMatching(RICHParameters richpar){ - // ---------------- - + int debugMode = 0; - + if(debugMode>=1){ int nc=richevent.get_nResClu(); for(int n = 0; n < nc; n++){ DetectorResponse dt = richevent.get_ResClu(n); if(debugMode>=1) System.out.format("Response n %4d %4d %s time %8.2f ene %8.2f pos %8.1f %8.1f %8.1f \n",n, - dt.getSector(), dt.getDescriptor().getType().getName(), - dt.getTime(),dt.getEnergy(),dt.getPosition().x(),dt.getPosition().y(),dt.getPosition().z()); - } + dt.getSector(), dt.getDescriptor().getType().getName(), + dt.getTime(),dt.getEnergy(),dt.getPosition().x(),dt.getPosition().y(),dt.getPosition().z()); + } } - + int np = clasevent.getParticles().size(); for(int n = 0; n < np; n++){ DetectorParticle p = this.clasevent.getParticle(n); - + if(debugMode>=1){ Line3D trajectory = p.getLastCross(); Point3D ori = trajectory.origin(); Point3D end = trajectory.end(); System.out.format("Particle n %4d itr %3d path %8.1f ori %s end %s\n", - n,p.getTrackIndex(),p.getPathLength(),ori.toStringBrief(2),end.toStringBrief(2)); + n,p.getTrackIndex(),p.getPathLength(),ori.toStringBrief(2),end.toStringBrief(2)); } - + // Matching tracks to RICH: from LastCross minimum distance in any direction Double rich_match_cut = richpar.RICH_DCMATCH_CUT; int index = p.getDetectorHit(richevent.get_ResClus(), DetectorType.RICH, -1, rich_match_cut); //int index = getDetectorHit(p, richevent.get_ResClus(), DetectorType.RICH, -1, rich_match_cut); if(index>=0){ - + DetectorResponse res = richevent.get_ResClu(index); Point3D ocross = p.getLastCross().origin(); double dz = res.getPosition().z() - ocross.z(); - if(debugMode>=1) System.out.format(" --> match found %4d par %s clu %s dz %7.2f \n", index, ocross.toStringBrief(2), res.getPosition().toStringBrief(2), dz); - - // while storing the match, calculates the matched position as middle point between track and hit + if(debugMode>=1) System.out.format(" --> match found %4d par %s clu %s dz %7.2f \n", index, ocross.toStringBrief(2), res.getPosition().toStringBrief(2), dz); + + // while storing the match, calculates the matched position as middle point between track and hit // and path (track last cross plus distance to hit) assuming the hit is downstream of last cross p.addResponse(res, true); if(dz<0){ // go backward instead of forward from LastCross double extra = p.getPathLength(res.getPosition()); res.setPath( res.getPath()-2*extra); - if(debugMode>=1) System.out.format(" --> Negative Delta z %7.2f --> correct path by %7.2 \n", dz, -2*extra); + if(debugMode>=1) System.out.format(" --> Negative Delta z %7.2f --> correct path by %7.2 \n", dz, -2*extra); } - + // Status brings the pindex of the original track to fix the hipo cross-indexes res.setAssociation(p.getTrackStatus()); } - + } if(debugMode>=1) System.out.format(" \n"); } - - // ---------------- + public void set_EventInfo(DataEvent event) { - // ---------------- - + int debugMode = 0; - + long tt = System.nanoTime(); richevent.set_CPUTime(tt); if(event.hasBank("REC::Event")==true){ DataBank bankeve = event.getBank("REC::Event"); - + float evttime = bankeve.getFloat("startTime",0); richevent.set_EventTime(evttime); - - if(debugMode>=1)System.out.format(" Create RICH Event id %8d time %8.2f \n", richevent.get_EventID(), richevent.get_EventTime()); + + if(debugMode>=1)System.out.format(" Create RICH Event id %8d time %8.2f \n", richevent.get_EventID(), richevent.get_EventTime()); } - + if(event.hasBank("RUN::config")==true){ DataBank bankrun = event.getBank("RUN::config"); richevent.set_RunID(bankrun.getInt("run",0)); richevent.set_EventID(bankrun.getInt("event",0)); - + //int phase = (int) ((bankrun.getLong("timestamp",0)%6 +1)%6) /2; int phase = (int) (bankrun.getLong("timestamp",0)%2); richevent.setFTOFphase(phase); - + if(debugMode>=1)System.out.println(" Create RICH Event id "+richevent.get_EventID()+" stamp "+bankrun.getLong("timestamp",0)+" phase "+phase); } if(debugMode>=1)System.out.println(" Create RICH Event id "+richevent.get_EventID()+" reftime"+richevent.get_CPUTime()+" "+tt); - + } - - - // ---------------- + + public int get_NClasParticle() { - // ---------------- return clasevent.getParticles().size(); } - - - // ---------------- + + public int get_nMatch() { - // ---------------- return richevent.get_nMatch(); } - - - // ---------------- + + public boolean find_Hadrons(RICHRayTrace richtrace, RICHCalibration richcal, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - - if(debugMode>=1){ + + if(debugMode>=1){ System.out.println("---------------------------------"); System.out.println("Find RICH hadrons from CLAS "+get_NClasParticle()+" particles"); System.out.println("---------------------------------"); } - + int hindex = 0; for(DetectorParticle p : clasevent.getParticles()){ - + double theta = p.vector().theta(); int CLASpid = check_CLASpid( p.getPid() ); double CLASbeta = p.getBeta(); - - if(debugMode>=1) { + + if(debugMode>=1) { System.out.format(" --> track %4d %4d %4d sec %4d ori %s P %8.2f the %8.2f time @IP %8.2f path %7.2f\n", p.getTrackIndex(),p.getTrackStatus(),CLASpid, p.getTrackSector(), p.getLastCross().origin().toStringBrief(2),p.vector().mag(),theta*RAD,richevent.get_EventTime(),p.getPathLength()); } - - DetectorResponse r = null; - DetectorResponse exr = null; + + DetectorResponse r = null; + DetectorResponse exr = null; int nr = 0; int nexr = 0; double RICHtime = 0.0; @@ -572,221 +530,211 @@ public boolean find_Hadrons(RICHRayTrace richtrace, RICHCalibration richcal, RIC RICHtime = richevent.get_EventTime() + r.getPath()/CLASbeta/(PhysicsConstants.speedOfLight()); RICHiclu = r.getHitIndex(); double TRACKtime = richevent.get_EventTime() + p.getPathLength()/CLASbeta/(PhysicsConstants.speedOfLight()); - + if(debugMode>=1)System.out.format(" --> cluster %4d hit %s path %7.2f --> rich %8.2f vs track %8.2f time\n \n",RICHiclu, - r.getPosition().toStringBrief(2), r.getPath(), r.getTime(), TRACKtime); - + r.getPosition().toStringBrief(2), r.getPath(), r.getTime(), TRACKtime); + nr++; } } - if( (nr==1) || (nr==0 && richpar.DO_MIRROR_HADS==1) ){ + if( (nr==1) || (nr==0 && richpar.DO_MIRROR_HADS==1) ){ if(debugMode>=1)System.out.format("EXTRAPOLATED with nresp %d \n",nr); exr = extrapolate_RICHResponse(p, r, richtrace); if(exr!=null) nexr++; } - + // define the response treatment in special cases if(nexr==0){if(debugMode>=1)System.out.format("No RICH intersection for particle with nresp %d and theta %8.2f \n",nr,theta*RAD); continue;} if(nr==1)Match_chi2 = 2*exr.getMatchedDistance()/richpar.RICH_HITMATCH_RMS; - + if(debugMode>=1)System.out.format(" --> intersec %4d hit %s path %7.2f --> time %8.2f chi2 %7.2f \n \n",RICHiclu, - exr.getPosition().toStringBrief(2), exr.getPath(), exr.getTime(), Match_chi2); - + exr.getPosition().toStringBrief(2), exr.getPath(), exr.getTime(), Match_chi2); + RICHParticle richhadron = new RICHParticle(hindex, p, exr, richpar); richhadron.set_StartTime(richevent.get_EventTime()); richhadron.traced.set_time(exr.getTime()); richhadron.traced.set_machi2(Match_chi2); - + //richhadron.set_HitTime(exr.getTime()); /*if(!richhadron.set_points(p.getLastCross().origin(), p.getLastCross().end(), exr.getPosition(), exr.getStatus(), richtrace) ){ - if(debugMode>=1)System.out.println(" ERROR: no MAPMT interesection found for hadron \n"); - continue; + if(debugMode>=1)System.out.println(" ERROR: no MAPMT interesection found for hadron \n"); + continue; }*/ - + if(!richhadron.find_AerogelPoints(richtrace, richcal) ) { - if(debugMode>=1)System.out.println(" ERROR: no aerogel interesection found for hadron \n"); - continue; + if(debugMode>=1)System.out.println(" ERROR: no aerogel interesection found for hadron \n"); + continue; } - + richhadron.traced.set_path((float) richhadron.get_HitPos().distance(richhadron.aero_middle)); if(debugMode>=1)System.out.format(" Timing id %3d beta %8.4f | time eve %8.2f emi %8.2f hit %8.2f at light speed %8.2f (cm/ns) \n", - CLASpid,CLASbeta,richevent.get_EventTime(),richhadron.get_StartTime(), exr.getTime(), PhysicsConstants.speedOfLight()); - + CLASpid,CLASbeta,richevent.get_EventTime(),richhadron.get_StartTime(), exr.getTime(), PhysicsConstants.speedOfLight()); + if(!richhadron.set_rotated_points() ) { - System.out.println(" ERROR: no rotation found \n"); - continue; + System.out.println(" ERROR: no rotation found \n"); + continue; } - + if(debugMode>=1){ - System.out.format(" ------------------- \n"); - System.out.format(" Hadron %4d id %4d from part %4d and clu %4d CLAS eve %7d pid %5d \n ", hindex, richhadron.get_id(), - p.getTrackStatus(), RICHiclu, richevent.get_EventID(), CLASpid); - System.out.format(" ------------------- \n"); - + System.out.format(" ------------------- \n"); + System.out.format(" Hadron %4d id %4d from part %4d and clu %4d CLAS eve %7d pid %5d \n ", hindex, richhadron.get_id(), + p.getTrackStatus(), RICHiclu, richevent.get_EventID(), CLASpid); + System.out.format(" ------------------- \n"); + richhadron.show(); Point3D crosspos = p.getLastCross().origin(); Point3D crossdir = richhadron.lab_emission; System.out.format(" track cross 1 xyz %s dir %s \n",crosspos.toStringBrief(3), crossdir.toStringBrief(3)); } - + richevent.add_Hadron(richhadron); hindex++; } - + if(debugMode==1 && hindex>1)System.out.format(" MOREHADs \n"); if(richevent.get_nHad()>0)return true; return false; - + } - - // ---------------- + public boolean find_Photons(List RichHits, RICHParameters richpar, RICHCalibration richcal){ - // ---------------- - + int debugMode = 0; if(RichHits==null) return false; - + int id = 0; for(RICHParticle richhadron : richevent.get_Hadrons()){ - - if(debugMode>=1){ + + if(debugMode>=1){ System.out.format("---------------------------------\n"); System.out.format("Find photons from hadron %3d and %6d hits \n",richhadron.get_id(), RichHits.size()); System.out.format("---------------------------------\n"); } - + for(int hypo=0; hypo=1){ - System.out.format(" ------------------- \n"); + System.out.format(" ------------------- \n"); System.out.format(" Photon id %4d from hit %4d hadron %3d and hypo %s\n", photon.get_id(), richhadron.get_id(), RichHits.get(k).getHitIndex(), RICHConstants.HYPO_STRING[hypo]); - System.out.format(" ------------------- \n"); + System.out.format(" ------------------- \n"); } - + photon.set_rotated_points(richhadron); photon.set_PixelProp(richcal); photon.set_type(hypo); int hypo_pid = RICHConstants.HYPO_LUND[hypo]; photon.traced.set_hypo(hypo_pid); - + richevent.add_Photon(photon); id++; } - + } } - + if(richevent.get_nPho()>0)return true; return false; - + } - - // ---------------- + public boolean analyze_Cherenkovs(RICHRayTrace richtrace, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + if(richpar.DO_ANALYTIC==1){ - + int hypo = 1; richevent.analyze_Photons(hypo, richtrace); //richevent.select_Photons(hypo, 0, richpar); - + for(RICHParticle richhadron : richevent.get_Hadrons()){ if (richhadron.get_Status()==1){ - //richevent.get_ChMean(richhadron, hypo, 0); - richevent.get_pid(richhadron, 0, richpar); + //richevent.get_ChMean(richhadron, hypo, 0); + richevent.get_pid(richhadron, 0, richpar); }else{ if(debugMode>=1)System.out.format(" Hadron pointing to mirror, skip analytic analysis \n"); } } - + } - + return true; - + } - - - // ---------------- + + public boolean is_WantedHypo(RICHParameters richpar, int hypo) { - // ---------------- - + if(hypo==0 && richpar.THROW_ELECTRONS==1) return true; if(hypo==1 && richpar.THROW_PIONS ==1) return true; if(hypo==2 && richpar.THROW_KAONS ==1) return true; if(hypo==3 && richpar.THROW_PROTONS ==1) return true; return false; } - - - // ---------------- + + public boolean reco_Cherenkovs(RICHRayTrace richtrace, RICHParameters richpar, RICHCalibration richcal) { - // ---------------- - + int debugMode = 0; - + int recotype = RICHRecoType.TRACED.id(); for(RICHParticle richhadron : richevent.get_Hadrons()){ - + int Ntrials = richpar.THROW_PHOTON_NUMBER; - + for (int hypo=0; hypo0)System.out.format(" Extrapolation to SPHER %s \n", extra.toStringBrief(2)); } if(extra==null) return null; - + // this extrapath is correct being calculated along the extrapolated trajectory double extrapath = extra.distance( p.getLastCross().origin() ); if(extra.z()0)System.out.format(" Take response %s path %7.2f time %7.2f\n", rpos.toStringBrief(2), exr.getPath(), exr.getTime()); - + }else{ - + exr.setPosition( extra.x(), extra.y(), extra.z() ); - exr.setMatchPosition( extra.x(), extra.y(), extra.z()); + exr.setMatchPosition( extra.x(), extra.y(), extra.z()); exr.setHitIndex( -1 ); exr.setStatus(0); double CLASbeta = p.getBeta(); exr.setTime( richevent.get_EventTime() + exr.getPath()/CLASbeta/(PhysicsConstants.speedOfLight()) ); if(debugMode>0)System.out.format(" Take extra %s path %7.2f time %7.2f\n", extra.toStringBrief(2), exr.getPath(), exr.getTime()); - + } - - + + if(debugMode>=1){ - Vector3D pos = new Vector3D(0.,0.,0.); - if(r!=null) pos = r.getPosition(); - - System.out.format("exr: status %4d imir %4d ex %s r %s exr %s L %7.2f (%7.2f + %7.2f) T %7.2f \n", - exr.getStatus(),imir,extra.toStringBrief(2), pos.toStringBrief(2), - exr.getPosition().toStringBrief(2),exr.getPath(),p.getPathLength(),extrapath,exr.getTime()); + Vector3D pos = new Vector3D(0.,0.,0.); + if(r!=null) pos = r.getPosition(); + + System.out.format("exr: status %4d imir %4d ex %s r %s exr %s L %7.2f (%7.2f + %7.2f) T %7.2f \n", + exr.getStatus(),imir,extra.toStringBrief(2), pos.toStringBrief(2), + exr.getPosition().toStringBrief(2),exr.getPath(),p.getPathLength(),extrapath,exr.getTime()); } - + return exr; } - - - // ------------- - public int check_CLASpid(int pid) { - // ------------- - /* - * force electron pid when in trouble - * (only gamma, e, pi, proton and k are allowed) - */ + + public int check_CLASpid(int pid) { + /* + * force electron pid when in trouble + * (only gamma, e, pi, proton and k are allowed) + */ + int checkpid = 0; if (Math.abs(pid)==22 || Math.abs(pid)==11 || Math.abs(pid)==211 | Math.abs(pid)==321 || Math.abs(pid)==2212) { checkpid = pid; @@ -864,12 +810,10 @@ public int check_CLASpid(int pid) { } return checkpid; } - - - // ---------------- + + public double Pi_Likelihood(double angolo) { - // ---------------- - + double mean = 0.307; double sigma= 0.004; System.out.println("Angolo: " + angolo); @@ -879,14 +823,12 @@ public double Pi_Likelihood(double angolo) { double LikeLihood= Math.log(Argomento)/Norm; //System.out.println(LikeLihood); return LikeLihood; - + } - - - // ---------------- + + public Point3D Outer_Intersection(Point3D first, Point3D second, Vector3D direction ) { - // ---------------- - + int debugMode = 0; Point3D Emissione = new Point3D(0,0,0); // Define a Vector3D as: Second point of intersection Minus first point of intersection @@ -905,76 +847,61 @@ public Point3D Outer_Intersection(Point3D first, Point3D second, Vector3D direct Emissione.setZ( first.z() ); } if(debugMode>=1){ - System.out.println("First "+first); - System.out.println("Second "+second); - System.out.println("Direction"+direction); - System.out.println("V_inter "+V_inter); - System.out.println(" prod "+V_inter.asUnit().dot(direction.asUnit())); - System.out.println("Emission "+Emissione); - } + System.out.println("First "+first); + System.out.println("Second "+second); + System.out.println("Direction"+direction); + System.out.println("V_inter "+V_inter); + System.out.println(" prod "+V_inter.asUnit().dot(direction.asUnit())); + System.out.println("Emission "+Emissione); + } return Emissione; } - - - // ---------------- + + public ArrayList getRichResponseList(){ - // ---------------- clasevent.setAssociation(); - ArrayList responses = new ArrayList(); + ArrayList responses = new ArrayList<>(); for(DetectorParticle p : clasevent.getParticles()){ for(DetectorResponse r : p.getDetectorResponses()){ - if(r.getDescriptor().getType()==DetectorType.RICH) - responses.add(r); - } - } + if(r.getDescriptor().getType()==DetectorType.RICH) + responses.add(r); + } + } return responses; } - - - // ---------------- + + public HashMap getPindexMap() { - // ---------------- - return this.pindex_map; + return this.pindex_map; } - - - // ---------------- + + public void CosmicEvent(List Hits, List Clusters) { - // ---------------- - int debugMode = 0; if(debugMode>=1) System.out.println("RICH Event Builder: Event Process "); - } - - - // ---------------- + + public void show_Particle(DetectorParticle pr) { - // ---------------- - System.out.format(" Particle pid %4d mass %9.4f beta %8.5f vert %8.2f %8.2f %8.2f mom %8.3f %8.3f %8.3f \n", pr.getPid(),pr.getMass(),pr.getBeta(), pr.vertex().x(),pr.vertex().y(),pr.vertex().z(), pr.vector().x(),pr.vector().y(),pr.vector().z()); - } - - - // ---------------- + + public void show_Track(DetectorTrack tr) { - // ---------------- - Line3D first = tr.getFirstCross(); Line3D last= tr.getLastCross(); Point3D ori = first.origin(); Point3D end = last.origin(); System.out.format(" Track id %4d %4d sec %4d path %8.1f origin %8.2f %8.2f %8.2f end %8.2f %8.2f %8.2f \n", - tr.getStatus(), - tr.getTrackIndex(), + tr.getStatus(), + tr.getTrackIndex(), tr.getSector(), tr.getPath(), ori.x(),ori.y(),ori.z(), end.x(),end.y(),end.z()); } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHHit.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHHit.java index 67ac427280..4b764ad0b1 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHHit.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHHit.java @@ -1,16 +1,11 @@ package org.jlab.rec.rich; -import org.jlab.detector.geom.RICH.RICHGeoFactory; - import org.jlab.geom.prim.Point3D; +import org.jlab.detector.geom.RICH.RICHGeoFactory; -//import org.jlab.detector.geom.RICH.RICHGeoFactory; - -// ---------------- public class RICHHit implements Comparable{ -// ---------------- // class implements Comparable interface to allow for sorting a collection of hits by Time values - + private int id = -1; // id private int sector; // Sector private int tile; // Front-End TILE ID @@ -20,52 +15,45 @@ public class RICHHit implements Comparable{ private int lead; // ID of the leading edge private int trail; // ID of the trailing edge private int signal; // pointer to the derived RICH signal - + private int idx; // anode local idx (within PMT) private int idy; // anode local idy (within PMT) private int glx; // anode global idx (onto RICH plane) private int gly; // anode global idy (onto RICH plane) - + private double x; // anode global x (within CLAS) private double y; // anode global y (within CLAS) private double z; // anode global z (within CLAS) private double time; // Hit time private double rawtime; // Hit rawtime - + private int duration; // Hit duration private int cluster; // parent cluster ID private int xtalk; // xtalk type private int status; // MA-PMT pixel status - - - // ---------------- - public RICHHit(){ - // ---------------- - } - - - // ---------------- + + public RICHHit(){} + public RICHHit(int hid, int phase, RICHEdge lead, RICHEdge trail, RICHGeoFactory richgeo, RICHCalibration richcal) { - // ---------------- - - + + int debugMode = 0; - - // Edge channel runs [1:192], Hit channel runs [0:191] + + // Edge channel runs [1:192], Hit channel runs [0:191] this.id = hid; this.sector = lead.get_sector(); this.tile = lead.get_tile(); this.pmt = richgeo.Tile2PMT(tile, lead.get_channel()); // run from 1 to 391 - this.channel = (lead.get_channel()-1)%64; + this.channel = (lead.get_channel()-1)%64; this.anode = richgeo.Maroc2Anode(channel); // run from 1 to 64 this.lead = lead.get_id(); this.trail = trail.get_id(); - + this.duration = trail.get_tdc()-lead.get_tdc(); - + double twalk_corr = richcal.get_PixelTimeWalk(sector, pmt, this.duration); double toff_corr = richcal.get_PixelTimeOff(sector, pmt, anode); - + this.status = richcal.get_PixelStatus(sector, pmt, anode); // to flag spurios hits (in not-existing sensors) coming from FPGA SEU indeuced by radiation if(this.pmt==0)this.status = 1; @@ -73,13 +61,13 @@ public RICHHit(int hid, int phase, RICHEdge lead, RICHEdge trail, RICHGeoFactory this.time = (lead.get_tdc() + phase*4 + toff_corr - twalk_corr); this.cluster = 0; this.xtalk = 0; - + if(debugMode>=2)System.out.format("Correzione time til %3d ch %6d pmt %3d anode %4d dur %5d raw %7.2f toff %7.2f twalk %7.3f --> time %7.2f \n", - this.tile, this.channel, this.pmt,this.anode,this.duration, this.rawtime, toff_corr, twalk_corr, this.time); - - if(debugMode>=2)System.out.format(" Hittime %4d %4d %8d %7.2f %7d %7.2f %7.2f %7.2f \n", hid, pmt, this.duration, this.rawtime, - phase*4, toff_corr, -twalk_corr, this.time); - + this.tile, this.channel, this.pmt,this.anode,this.duration, this.rawtime, toff_corr, twalk_corr, this.time); + + if(debugMode>=2)System.out.format(" Hittime %4d %4d %8d %7.2f %7d %7.2f %7.2f %7.2f \n", hid, pmt, this.duration, this.rawtime, + phase*4, toff_corr, -twalk_corr, this.time); + //this.glx = richgeo.get_PixelMap().get_Globalidx(pmt, anode); //this.gly = richgeo.get_PixelMap().get_Globalidy(pmt, anode); this.idx = richgeo.get_PixelMap().Anode2idx(anode); @@ -88,299 +76,201 @@ public RICHHit(int hid, int phase, RICHEdge lead, RICHEdge trail, RICHGeoFactory this.x = CesPos.x(); this.y = CesPos.y(); this.z = CesPos.z(); - - if(debugMode>=1)System.out.format(" Hit pmt %4d anode %3d --> %8.2f %8.2f %8.2f \n", pmt, anode, this.x, this.y, this.z); - - } - - - // ---------------- + + if(debugMode>=1)System.out.format(" Hit pmt %4d anode %3d --> %8.2f %8.2f %8.2f \n", pmt, anode, this.x, this.y, this.z); + + } + + public int get_id() { return id; } - // ---------------- - - // ---------------- + public void set_id(int id) { this.id = id; } - // ---------------- - - // ---------------- + public int get_sector() { return sector; } - // ---------------- - - // ---------------- + public int get_status() { return status; } - // ---------------- - - // ---------------- + public void set_sector(int sector) { this.sector = sector; } - // ---------------- - - // ---------------- + public int get_channel() { return channel; } - // ---------------- - - // ---------------- + public void set_channel(int channel) { this.channel = channel; } - // ---------------- - - // ---------------- + public int get_tile() { return tile; } - // ---------------- - - // ---------------- + public void set_tile(int tile) { this.tile = tile; } - // ---------------- - - // ---------------- + public int get_pmt() { return pmt; } - // ---------------- - - - // ---------------- + + public void set_pmt(int pmt) { this.pmt = pmt; } - // ---------------- - // ---------------- public int get_anode() { return anode; } - // ---------------- - - // ---------------- + public void set_anode(int anode) { this.anode = anode; } - // ---------------- - - // ---------------- + public int get_lead() { return lead; } - // ---------------- - - // ---------------- + public void set_lead(int lead) { this.lead = lead; } - // ---------------- - - // ---------------- + public int get_trail() { return trail; } - // ---------------- - - // ---------------- + public void set_trail(int trail) { this.trail = trail; } - // ---------------- - - // ---------------- + public int get_signal() { return signal; } - // ---------------- - - // ---------------- + public void set_signal(int signal) { this.signal = signal; } - // ---------------- - - - // ---------------- + + public int get_idx() { - // ---------------- return idx; } - - - // ---------------- + + public void set_idx(int idx) { - // ---------------- this.idx = idx; } - - - // ---------------- + + public int get_idy() { - // ---------------- return idy; } - - - // ---------------- + + public void set_idy(int idy) { - // ---------------- this.idy = idy; } - - - // ---------------- + + public int get_glx() { - // ---------------- return glx; } - - - // ---------------- + + public void set_glx(int glx) { - // ---------------- this.glx = glx; } - - - // ---------------- + + public int get_gly() { - // ---------------- return gly; } - - - // ---------------- + + public void set_gly(int gly) { - // ---------------- this.gly=gly; } - - // ---------------- + public Point3D get_Position() { - // ---------------- return new Point3D(x,y,z); } - - - // ---------------- + + public void set_Position(Point3D pos){ - // ---------------- set_Position( pos.x(), pos.y(), pos.z() ); } - - - // ---------------- + + public void set_Position(double x, double y, double z) { - // ---------------- this.x = x; this.y = y; this.z = z; } - - - // ---------------- + + public double get_x() { - // ---------------- return x; } - - - // ---------------- + + public void set_x(double x) { - // ---------------- this.x = x; } - - // ---------------- + public double get_y() { - // ---------------- return y; } - - - // ---------------- + + public void set_y(double y) { - // ---------------- this.y = y; } - - // ---------------- + public double get_z() { - // ---------------- return z; } - - // ---------------- + public void set_z(double z) { - // ---------------- this.z = z; } - - - // ---------------- + + public int get_duration() { - // ---------------- return duration; } - - - // ---------------- + + public void set_duration(int duration) { - // ---------------- this.duration = duration; } - - - // ---------------- + + public double get_Time() { - // ---------------- return time; } - - - // ---------------- + + public void set_Time(double time) { - // ---------------- this.time = time; } - - // ---------------- + public double get_rawtime() { - // ---------------- return rawtime; } - - - // ---------------- + + public void set_rawtime(int rawtime) { - // ---------------- this.rawtime = rawtime; } - - - // ---------------- + + public int get_cluster() { - // ---------------- return cluster; } - - // ---------------- + public void set_cluster(int cluster) { - // ---------------- this.cluster = cluster; } - // ---------------- public int get_xtalk() { - // ---------------- return xtalk; } - - // ---------------- + public void set_xtalk(int xtalk) { - // ---------------- this.xtalk = xtalk; } - // ---------------- public boolean passHitSelection(RICHHit hit) { - // ---------------- // a selection cut to pass the edge if(hit.get_Time() > 0) { return true; } else { return false; - } + } } - - // ---------------- + public int compareTo(RICHHit ohit) { - // ---------------- if(ohit.get_duration()==this.get_duration()) return 0; if(ohit.get_duration() > this.get_duration()){ return 1; }else{ return -1; - } + } } - - - // ---------------- + + public boolean IsinNonet(RICHHit hit, RICHHit nonet) { - // ---------------- boolean addFlag = false; double tDiff = Math.abs(hit.get_Time() - nonet.get_Time()); int xDiff = Math.abs(hit.get_idx() - nonet.get_idx()); @@ -388,32 +278,30 @@ public boolean IsinNonet(RICHHit hit, RICHHit nonet) { if(tDiff <= RICHConstants.CLUSTER_TIME_WINDOW && xDiff <= 1 && yDiff <= 1 && (xDiff + yDiff) >0) addFlag = true; return addFlag; } - - - // ---------------- + + public void showHit() { - // ---------------- System.out.format("Hit ID %3d (%3d, %3d) Sec %2d Til %4d PMT %4d Ch %4d And %3d idx %2d idy %2d glx %3d gly %3d xyz %7.2f %7.2f %7.2f clu %3d xtk %5d tim %7.1f %7.1f dur %3d \n", this.get_id(), this.get_lead(), this.get_trail(), this.get_sector(), - this.get_tile(), - this.get_pmt(), - this.get_channel(), - this.get_anode(), - this.get_idx(), - this.get_idy(), - this.get_glx(), - this.get_gly(), - this.get_x(), - this.get_y(), - this.get_z(), - this.get_cluster(), - this.get_xtalk(), - this.get_Time(), - this.get_rawtime(), + this.get_tile(), + this.get_pmt(), + this.get_channel(), + this.get_anode(), + this.get_idx(), + this.get_idy(), + this.get_glx(), + this.get_gly(), + this.get_x(), + this.get_y(), + this.get_z(), + this.get_cluster(), + this.get_xtalk(), + this.get_Time(), + this.get_rawtime(), this.get_duration()); } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHPMTReconstruction.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHPMTReconstruction.java index 31ad6280ae..ce8f8621c1 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHPMTReconstruction.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHPMTReconstruction.java @@ -2,24 +2,15 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.List; -import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; -import org.jlab.io.evio.EvioDataBank; import org.jlab.io.evio.EvioDataEvent; import org.jlab.io.hipo.HipoDataEvent; - -import javax.swing.JFrame; import org.jlab.detector.banks.RawDataBank; -import org.jlab.groot.graphics.EmbeddedCanvas; -import org.jlab.groot.data.H1F; -import org.jlab.groot.data.H2F; import org.jlab.detector.geom.RICH.RICHGeoFactory; public class RICHPMTReconstruction { - private RICHEvent richevent; private RICHGeoFactory richgeo; private RICHio richio; diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParameters.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParameters.java index 34b650249e..50a1e5d761 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParameters.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParameters.java @@ -1,27 +1,23 @@ package org.jlab.rec.rich; - import org.jlab.detector.calib.utils.ConstantsManager; import org.jlab.utils.groups.IndexedTable; -import java.io.FileReader; -import java.io.BufferedReader; - /** * * @author mcontalb */ public class RICHParameters{ - + // Default flags of RICH reconstruction parameters to be re-loaded from CCDB or TxT - + public int PROCESS_RAWDATA = 1; // Process raw data starting from RICH::tdc public int PROCESS_DATA = 1; // Process data starting from RICH::Signal (Hit-Cluster) and REC::Trajectory public int USE_SIGNAL_BANK = 0; // Use RICH::Signal Bank (vs RICH::Hit and RICH::Cluster) public int FORCE_DC_MATCH = 0; // if 1 force the hadron track to hit the cluster public int DO_ANALYTIC = 0; // if 1 calculate analytic solution - public int TRACE_PHOTONS = 1; // if 1 ray-trace phtons - + public int TRACE_PHOTONS = 1; // if 1 ray-trace phtons + public int THROW_ELECTRONS = 0; // if 1 throw photons for electron hypothesis public int THROW_PIONS = 1; // if 1 throw photons for pion hypothesis public int THROW_KAONS = 0; // if 1 throw photons for kaon hypothesis @@ -29,10 +25,10 @@ public class RICHParameters{ public int TRACE_NITROGEN = 0; // if 1 ray-trace phtoons out of nitrogen public int SAVE_PHOTONS = 0; // Store reconstructed photons in the photons bank public int SAVE_THROWS = 0; // Store throwed photons in the photons bank - + public int DO_MIRROR_HADS = 1; // if 1 reconstruct hadrons pointing to mirror public int DO_CURVED_AERO = 0; // if 1 use spherical surface of aerogel - + public int USE_ELECTRON_ANGLES = 1; // Get Cherenkov angle and rms from electrons control sample public int USE_LIKE_DELTAN = 0; // Use global normalization (expected number of photons) in likelihood public int USE_CALIBRATED_PIXELS = 1; // Get pixel properties from calibration data @@ -40,59 +36,52 @@ public class RICHParameters{ public int USE_PIXEL_EFF = 1; // Use pixel status and efficiency in the likelihood public int USE_PIXEL_TIME = 1; // Use pixel status and efficiency in the likelihood public int USE_PIXEL_BACKGR = 1; // Use pixel background in the likelihood - - public int DO_PASS2_LIKE = 1; // Adopt Likelihood of PASS2 type - public int DO_PASS1_LIKE = 0; // Adopt Likelihood of PASS1 type - public int DO_LHCB_LIKE = 0; // Adopt Likelihood of LHCB type - + + public int DO_PASS2_LIKE = 1; // Adopt Likelihood of PASS2 type + public int DO_PASS1_LIKE = 0; // Adopt Likelihood of PASS1 type + public int DO_LHCB_LIKE = 0; // Adopt Likelihood of LHCB type + public int RING_ONLY_BEST = 0; // Save only ring photons with hypothesis equal to BEST public int RING_ONLY_USED = 0; // Save only ring photons with no bad status flag - - public int DEBUG_RECO_FLAG = 0; // Number of events with debug of Reconstruction Falgs + + public int DEBUG_RECO_FLAG = 0; // Number of events with debug of Reconstruction Falgs public int DEBUG_RECO_PAR = 0; // Number of events with debug of Reconstruction Parameters public int DEBUG_CAL_COST = 0; // Number of events with debug of Calibration Constants public int DEBUG_PROC_TIME = 0; // if 1 activate the sub-process time consumption printout - + // Default values of RICH reconstruction parameters to be re-loaded from CCDB or TxT - + public double OFFSET_TIME = 0; // Offset for time matching - public double GOODHIT_FRAC = 80.; // Maximum duration (in % of local max) to flag xtalk - - public double RICH_DCMATCH_CUT = 15.; // RICH cluster matching cut with tracks + public double GOODHIT_FRAC = 80.; // Maximum duration (in % of local max) to flag xtalk + + public double RICH_DCMATCH_CUT = 15.; // RICH cluster matching cut with tracks public double THROW_ASSOCIATION_CUT = 10.; // Max distance to set initial values for tracing photons (cm) public double RICH_HITMATCH_RMS = 0.6; // RICH - particle matching chi2 reference (cm) - + public double RICH_NOMINAL_SANGLE = 6.e-3; // Expected single photon angular resolution (rad) public double NSIGMA_CHERENKOV = 5; // Number of sigmas for Cherenkov angle selection public double NSIGMA_TIME = 20; // Number of sigmas for time selection - + public int QUADRANT_NUMBER = 15; // Number of quadrants (square root of) - + public int THROW_PHOTON_NUMBER = 50; // number of photon trials for every hypothesis public double RAYTRACE_RESO_FRAC = 0.1; // Fraction of RICH equivalent resolution public int RAY_NFRONT_REFLE = 1; // Maximum number of reflectionson the front mirrros public int RAYTRACE_MAX_NSTEPS = 20; // Maximum number of steps for raytracing - + public double PIXEL_NOMINAL_STIME = 1.0; // nominal pixel time resolution public double PIXEL_NOMINAL_DARKRATE = 5.e-7; // nominal pixel background public double RICH_NOMINAL_NELE = 16; // nominal photon yield for electron - - - // ----------------- - public RICHParameters() { - // ----------------- - } - - - //------------------------------ + + public RICHParameters() {} + public void load_CCDB(ConstantsManager manager, int run, int ncalls, boolean engineDebug){ - //------------------------------ - + int debugMode = 0; - + init_FlagCCDB( manager.getConstants(run, "/calibration/rich/reco_flag"), engineDebug ); init_ParameterCCDB( manager.getConstants(run, "/calibration/rich/reco_parameter") ); - + if((debugMode>=1 || DEBUG_RECO_FLAG>=1) && ncalls=1 || DEBUG_RECO_PAR>=1) && ncalls0)System.out.format("RICHFactory: Load calibration parameters from TxT\n"); init_ParameterTxT(); - + } - + } - - - //------------------------------ + + public void init_FlagCCDB(IndexedTable flagConstants, boolean engineDebug) { - //------------------------------ - + int debugMode = 0; - - PROCESS_RAWDATA = flagConstants.getIntValue("reco_raw", 0, 0, 0); + + PROCESS_RAWDATA = flagConstants.getIntValue("reco_raw", 0, 0, 0); PROCESS_DATA = flagConstants.getIntValue("reco_data", 0, 0, 0); USE_SIGNAL_BANK = flagConstants.getIntValue("use_sig_bank", 0, 0, 0); - + FORCE_DC_MATCH = flagConstants.getIntValue("force_dc_match", 0, 0, 0); DO_ANALYTIC = flagConstants.getIntValue("do_analytic", 0, 0, 0); TRACE_PHOTONS = flagConstants.getIntValue("do_traced", 0, 0, 0); - + THROW_ELECTRONS = flagConstants.getIntValue("throw_e", 0, 0, 0); THROW_PIONS = flagConstants.getIntValue("throw_pi", 0, 0, 0); THROW_KAONS = flagConstants.getIntValue("throw_k", 0, 0, 0); @@ -141,31 +128,31 @@ public void init_FlagCCDB(IndexedTable flagConstants, boolean engineDebug) { TRACE_NITROGEN = flagConstants.getIntValue("throw_N2", 0, 0, 0); SAVE_PHOTONS = flagConstants.getIntValue("save_photons", 0, 0, 0); SAVE_THROWS = flagConstants.getIntValue("save_throws", 0, 0, 0); - + DO_MIRROR_HADS = flagConstants.getIntValue("use_spher", 0, 0, 0); DO_CURVED_AERO = flagConstants.getIntValue("do_curved", 0, 0, 0); - + USE_ELECTRON_ANGLES = flagConstants.getIntValue("use_ecalib", 0, 0, 0); - + USE_LIKE_DELTAN = flagConstants.getIntValue("like_norm", 0, 0, 0); USE_CALIBRATED_PIXELS = flagConstants.getIntValue("pixel_calib", 0, 0, 0); USE_PIXEL_GAIN = flagConstants.getIntValue("pixel_gain", 0, 0, 0); USE_PIXEL_EFF = flagConstants.getIntValue("pixel_eff", 0, 0, 0); USE_PIXEL_TIME = flagConstants.getIntValue("pixel_time", 0, 0, 0); USE_PIXEL_BACKGR = flagConstants.getIntValue("pixel_back", 0, 0, 0); - + DO_PASS1_LIKE = flagConstants.getIntValue("pass1_like", 0, 0, 0); DO_PASS2_LIKE = flagConstants.getIntValue("pass2_like", 0, 0, 0); DO_LHCB_LIKE = flagConstants.getIntValue("lhcb_like", 0, 0, 0); - + DEBUG_RECO_FLAG = flagConstants.getIntValue("debug_reco_flag", 0, 0, 0); DEBUG_RECO_PAR = flagConstants.getIntValue("debug_reco_par", 0, 0, 0); DEBUG_CAL_COST = flagConstants.getIntValue("debug_cal_const", 0, 0, 0); DEBUG_PROC_TIME = flagConstants.getIntValue("debug_CPUtime", 0, 0, 0); - + RING_ONLY_BEST = flagConstants.getIntValue("ring_only_best", 0, 0, 0); RING_ONLY_USED = flagConstants.getIntValue("ring_only_used", 0, 0, 0); - + if(!engineDebug){ if(debugMode>=1)System.out.format("RICH RECO debugging set to OFF \n"); DEBUG_RECO_FLAG = 0; @@ -173,99 +160,93 @@ public void init_FlagCCDB(IndexedTable flagConstants, boolean engineDebug) { DEBUG_CAL_COST = 0; DEBUG_PROC_TIME = 0; } - + } - - - //------------------------------ + + public void init_ParameterCCDB(IndexedTable paraConstants) { - //------------------------------ - + int debugMode = 0; - + OFFSET_TIME = paraConstants.getDoubleValue("global_time_off", 0, 0, 0); GOODHIT_FRAC = paraConstants.getDoubleValue("xtalk_frac", 0, 0, 0); - + RICH_DCMATCH_CUT = paraConstants.getDoubleValue("dc_match", 0, 0, 0); THROW_ASSOCIATION_CUT = paraConstants.getDoubleValue("trial_match", 0, 0, 0); RICH_HITMATCH_RMS = paraConstants.getDoubleValue("match_rms", 0, 0, 0); - + NSIGMA_CHERENKOV = paraConstants.getDoubleValue("nsigma_cher", 0, 0, 0); NSIGMA_TIME = paraConstants.getDoubleValue("nsigma_time", 0, 0, 0); - + QUADRANT_NUMBER = paraConstants.getIntValue("quad_number", 0, 0, 0); - + THROW_PHOTON_NUMBER = paraConstants.getIntValue("N_trials", 0, 0, 0); RAYTRACE_RESO_FRAC = paraConstants.getDoubleValue("ray_resofrac", 0, 0, 0) / 100.; RAY_NFRONT_REFLE = paraConstants.getIntValue("ray_Nfront", 0, 0, 0); RAYTRACE_MAX_NSTEPS = paraConstants.getIntValue("ray_steps", 0, 0, 0); - + RICH_NOMINAL_SANGLE = paraConstants.getDoubleValue("ref_sangle", 0, 0, 0) / 1000.; PIXEL_NOMINAL_STIME = paraConstants.getDoubleValue("ref_stime", 0, 0, 0); PIXEL_NOMINAL_DARKRATE = paraConstants.getDoubleValue("ref_darkrate", 0, 0, 0) / 1.e9; RICH_NOMINAL_NELE = paraConstants.getDoubleValue("ref_Nele", 0, 0, 0); - + } - - - //------------------------------ + + public void init_ParameterTxT() { - //------------------------------ - + /*int debugMode = 0; - + IndexedTable prova = new IndexedTable(3, "DO_ALIGNMENT/I:FORCE_DC_MATCHD"); - + try { - - BufferedReader bf = new BufferedReader(new FileReader(par_filename)); - String currentLine = null; - - while ( (currentLine = bf.readLine()) != null) { - - String[] array = currentLine.split(" "); - int isec = Integer.parseInt(array[0]); - int ila = Integer.parseInt(array[1]); - int ico = Integer.parseInt(array[2]); - String name = array[4]; - - if(name.equals("DO_ALIGNMENT") DO_ALIGNMENT = Integer.parseInt(array[2]); - String type = array[3]; - if(type.equals("I") ival = - double val = Double.parseDouble(array[5]); - - prova.addEntry(isec, ila, ico); - prova.setDoubleValue(val, "value", isec, ila, ico); - int id = parlist.valueOf(name).id(); - prova.setIntValue(id, "name", isec, ila, ico); - - double eval = prova.getDoubleValue("value", isec, ila, ico); - int etype = prova.getIntValue("name", isec, ila, ico); - - System.out.format(" PROVA Value %s %7.2f --> %4d %7.2f \n",name, val, etype, eval); - } - + + BufferedReader bf = new BufferedReader(new FileReader(par_filename)); + String currentLine = null; + + while ( (currentLine = bf.readLine()) != null) { + + String[] array = currentLine.split(" "); + int isec = Integer.parseInt(array[0]); + int ila = Integer.parseInt(array[1]); + int ico = Integer.parseInt(array[2]); + String name = array[4]; + + if(name.equals("DO_ALIGNMENT") DO_ALIGNMENT = Integer.parseInt(array[2]); + String type = array[3]; + if(type.equals("I") ival = + double val = Double.parseDouble(array[5]); + + prova.addEntry(isec, ila, ico); + prova.setDoubleValue(val, "value", isec, ila, ico); + int id = parlist.valueOf(name).id(); + prova.setIntValue(id, "name", isec, ila, ico); + + double eval = prova.getDoubleValue("value", isec, ila, ico); + int etype = prova.getIntValue("name", isec, ila, ico); + + System.out.format(" PROVA Value %s %7.2f --> %4d %7.2f \n",name, val, etype, eval); + } + } catch (Exception e) { - - System.err.format("Exception occurred trying to read '%s' \n", par_filename); - e.printStackTrace(); + + System.err.format("Exception occurred trying to read '%s' \n", par_filename); + e.printStackTrace(); }*/ - + } - - - //------------------------------ + + public void dump_RecoFlags(int run) { - //------------------------------ - + System.out.format("RICH reconstruction flags \n"); - + System.out.format("CCDB RICH PARA PROCESS_RAWDATA %9d \n", PROCESS_RAWDATA); System.out.format("CCDB RICH PARA PROCESS_DATA %9d \n", PROCESS_DATA); System.out.format("CCDB RICH PARA USE_SIGNAL_BANK %9d \n", USE_SIGNAL_BANK); System.out.format("CCDB RICH PARA FORCE_DC_MATCH %9d \n", FORCE_DC_MATCH); System.out.format("CCDB RICH PARA DO_ANALYTIC %9d \n\n", DO_ANALYTIC); - + System.out.format("CCDB RICH PARA TRACE_PHOTONS %9d \n", TRACE_PHOTONS); System.out.format("CCDB RICH PARA THROW_ELECTRONS %9d \n", THROW_ELECTRONS); System.out.format("CCDB RICH PARA THROW_PIONS %9d \n", THROW_PIONS); @@ -274,10 +255,10 @@ public void dump_RecoFlags(int run) { System.out.format("CCDB RICH PARA TRACE_NITROGEN %9d \n", TRACE_NITROGEN); System.out.format("CCDB RICH PARA SAVE_PHOTONS %9d \n", SAVE_PHOTONS); System.out.format("CCDB RICH PARA SAVE_THROWS %9d \n\n", SAVE_THROWS); - + System.out.format("CCDB RICH PARA DO_MIRROR_HADS %9d \n", DO_MIRROR_HADS); System.out.format("CCDB RICH PARA DO_CURVED_AERO %9d \n\n", DO_CURVED_AERO); - + System.out.format("CCDB RICH PARA USE_ELECTRON_ANGLES %9d \n", USE_ELECTRON_ANGLES); System.out.format("CCDB RICH PARA USE_LIKE_DELTAN %9d \n", USE_LIKE_DELTAN); System.out.format("CCDB RICH PARA USE_CALIBRATED_PIXELS %9d \n", USE_CALIBRATED_PIXELS); @@ -285,53 +266,51 @@ public void dump_RecoFlags(int run) { System.out.format("CCDB RICH PARA USE_PIXEL_EFF %9d \n", USE_PIXEL_EFF); System.out.format("CCDB RICH PARA USE_PIXEL_TIME %9d \n", USE_PIXEL_TIME); System.out.format("CCDB RICH PARA USE_PIXEL_BACKGR %9d \n\n", USE_PIXEL_BACKGR); - + System.out.format("CCDB RICH PARA DO_PASS2_LIKE %9d \n", DO_PASS2_LIKE); System.out.format("CCDB RICH PARA DO_PASS1_LIKE %9d \n", DO_PASS1_LIKE); System.out.format("CCDB RICH PARA DO_LHCB_LIKE %9d \n\n", DO_LHCB_LIKE); - + System.out.format("CCDB RICH PARA DEBUG_RECO_FLAG %9d \n", DEBUG_RECO_FLAG); System.out.format("CCDB RICH PARA DEBUG_RECO_PAR %9d \n", DEBUG_RECO_PAR); System.out.format("CCDB RICH PARA DEBUG_CAL_COST %9d \n", DEBUG_CAL_COST); System.out.format("CCDB RICH PARA DEBUG_PROC_TIME %9d \n\n", DEBUG_PROC_TIME); - + System.out.format("CCDB RICH PARA RING_ONLY_BEST %9d \n", RING_ONLY_BEST); System.out.format("CCDB RICH PARA RING_ONLY_USED %9d \n", RING_ONLY_USED); - - + + System.out.format(" \n"); } - - - //------------------------------ + + public void dump_RecoParameters(int run) { - //------------------------------ - + System.out.format("RICH reconstruction parameters \n"); - + System.out.format("CCDB RICH PARA OFFSET_TIME %9.3f (ns) \n", OFFSET_TIME); System.out.format("CCDB RICH PARA GOODHIT_FRAC %9.3f (e-2) \n\n", GOODHIT_FRAC); - + System.out.format("CCDB RICH PARA RICH_DCMATCH_CUT %9.3f (cm) \n", RICH_DCMATCH_CUT); System.out.format("CCDB RICH PARA THROW_ASSOCIATION_CUT %9.3f (cm) \n", THROW_ASSOCIATION_CUT); System.out.format("CCDB RICH PARA RICH_HITMATCH_RMS %9.3f (cm) \n\n", RICH_HITMATCH_RMS); - + System.out.format("CCDB RICH PARA NSIGMA_CHERENKOV %9.3f \n", NSIGMA_CHERENKOV); System.out.format("CCDB RICH PARA NSIGMA_TIME %9.3f \n", NSIGMA_TIME); System.out.format("CCDB RICH PARA QUADRANT_NUMBER %9d \n\n", QUADRANT_NUMBER); - + System.out.format("CCDB RICH PARA THROW_PHOTON_NUMBER %9d \n", THROW_PHOTON_NUMBER); System.out.format("CCDB RICH PARA RAYTRACE_RESO_FRAC %9.3f (e-2) \n", RAYTRACE_RESO_FRAC*100.); System.out.format("CCDB RICH PARA RAY_NFRONT_REFLE %9d \n", RAY_NFRONT_REFLE); System.out.format("CCDB RICH PARA RAYTRACE_MAX_NSTEPS %9d \n\n", RAYTRACE_MAX_NSTEPS); - + System.out.format("CCDB RICH PARA RICH_NOMINAL_SANGLE %9.3f (mrad) \n", RICH_NOMINAL_SANGLE*1e3); System.out.format("CCDB RICH PARA PIXEL_NOMINAL_STIME %9.3f (ns) \n", PIXEL_NOMINAL_STIME); System.out.format("CCDB RICH PARA PIXEL_NOMINAL_DARKRATE %9.3f (Hz) \n", PIXEL_NOMINAL_DARKRATE*1e9); System.out.format("CCDB RICH PARA RICH_NOMINAL_NELE %9.3f \n", RICH_NOMINAL_NELE); - + System.out.format(" \n"); - + } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParticle.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParticle.java index a499a420a1..4e6aa6c517 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParticle.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHParticle.java @@ -1,39 +1,22 @@ package org.jlab.rec.rich; -import org.jlab.detector.geom.RICH.RICHIntersection; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; import org.jlab.geom.prim.Vector3D; -import org.jlab.io.base.DataBank; - -import java.util.ArrayList; - -import org.jlab.io.base.DataEvent; - import org.jlab.detector.base.DetectorType; - -import org.freehep.math.minuit.FCNBase; -import org.freehep.math.minuit.FunctionMinimum; -import org.freehep.math.minuit.MnMigrad; -import org.freehep.math.minuit.MnScan; -import org.freehep.math.minuit.MnUserParameters; - import org.jlab.clas.pdg.PhysicsConstants; import org.jlab.clas.pdg.PDGDatabase; import org.jlab.clas.detector.DetectorParticle; import org.jlab.clas.detector.DetectorResponse; - -import org.jlab.detector.geom.RICH.RICHRay; import org.jlab.detector.geom.RICH.RICHIntersection; import org.jlab.detector.geom.RICH.RICHGeoConstants; - public class RICHParticle { - + /* - * A particle in the RICH consists of an array of ray lines plus particle information + * A particle in the RICH consists of an array of ray lines plus particle information */ - + private int id = -999; private int parent_index = -999; private int type = 0; @@ -42,13 +25,13 @@ public class RICHParticle { private int status = -1; private int CLASpid = -999; private int RICHpid = -999; - private double momentum = 0; - private int charge = 0; + private double momentum = 0; + private int charge = 0; //private double[][] ChAngle = new double[4][3]; //private double[] sChAngle = new double[3]; - + private RICHHit hit = new RICHHit(); - + public Point3D lab_emission = null; public int ilay_emission = -1; public int ico_emission = -1; @@ -60,13 +43,13 @@ public class RICHParticle { public double nchele_emission[] = {0.0, 0.0, 0.0}; public double lab_phi = 0.0; public double lab_theta = 0.0; - + public double pixel_gain = 0.0; public double pixel_eff = 0.0; public double pixel_mtime = 0.0; public double pixel_stime = 0.0; public double pixel_backr = 0.0; - + // rotated frame into RICH local coordinates (used for the analytic solution) public double RotAngle = 0.0; public Vector3D RotAxis = null; @@ -77,36 +60,34 @@ public class RICHParticle { public double ref_phi = 0.0; public double ref_theta = 0.0; public double EtaC_ref = 0.0; - + private double start_time = 0.0; - + public RICHSolution analytic = new RICHSolution(0); public RICHSolution traced = new RICHSolution(1); - + public RICHParticle trial_pho = null; - + public Point3D aero_entrance = new Point3D(0.,0.,9999.); public Point3D aero_exit = new Point3D(0.,0.,0.); public Point3D aero_middle = null; public Vector3D aero_normal = null; - + public Line3D direct_ray = new Line3D(0.0,0.0,0.0,0.0,0.0,0.0); public double path = 0.0; - + private final static RICHGeoConstants geocost = new RICHGeoConstants(); private RICHParameters richpar; - + private static double MRAD = geocost.MRAD; private static double RAD = geocost.RAD; - - // ------------- + public RICHParticle(int id, DetectorParticle p, DetectorResponse exr, RICHParameters richpar){ - // ------------- - /* - * RICHParticle from a CLAS charged particle for RICH reconstruction - */ + /* + * RICHParticle from a CLAS charged particle for RICH reconstruction + */ int debugMode = 0; - + this.id = id; // ATT: vedere se si puo' evitare tenendolo fuori this.parent_index = p.getTrackStatus(); @@ -114,7 +95,7 @@ public RICHParticle(int id, DetectorParticle p, DetectorResponse exr, RICHParame set_CLASpid(p.getPid()); this.sector = p.getTrackSector(); this.charge = p.getCharge(); - + // exr already account for track extrapolation at the RICH surface and possible cluster match this.hit.set_id( exr.getHitIndex() ); this.hit.set_Position( exr.getPosition().toPoint3D() ); @@ -122,10 +103,10 @@ public RICHParticle(int id, DetectorParticle p, DetectorResponse exr, RICHParame this.hit.set_sector( exr.getDescriptor().getSector() ); this.hit.set_pmt( exr.getDescriptor().getLayer() ); this.hit.set_anode( exr.getDescriptor().getComponent() ); - + this.richpar = richpar; - - this.direct_ray = p.getFirstCross(); + + this.direct_ray = p.getFirstCross(); int detid = DetectorType.RICH.getDetectorId();; this.path = p.getTrackTrajectory().get(detid,0).getPathLength(); if(richpar.FORCE_DC_MATCH==1){ @@ -135,23 +116,21 @@ public RICHParticle(int id, DetectorParticle p, DetectorResponse exr, RICHParame this.lab_phi = direct_ray.toVector().phi(); this.lab_theta = direct_ray.toVector().theta(); this.status = exr.getStatus(); - + } - - - // ------------- + + public RICHParticle(int id, RICHParticle hadron, DetectorResponse hit, Point3D point, RICHParameters richpar){ - // ------------- - /* - * RICHParticle as new particle for RICH reconstruction - */ - + /* + * RICHParticle as new particle for RICH reconstruction + */ + this.id = id; this.parent_index = hadron.get_id(); this.momentum = 1.e-6; this.CLASpid = 22; this.sector = hadron.get_sector(); - + this.start_time = hadron.get_StartTime(); if (hit!=null){ // photon from detected hit @@ -165,27 +144,25 @@ public RICHParticle(int id, RICHParticle hadron, DetectorResponse hit, Point3D p // photon from throw particle this.hit.set_Position( point ); } - + this.lab_emission = hadron.lab_emission; this.ilay_emission = hadron.ilay_emission; this.ico_emission = hadron.ico_emission; - + this.direct_ray = new Line3D(this.lab_emission, this.hit.get_Position()); this.lab_phi = direct_ray.toVector().phi(); this.lab_theta = direct_ray.toVector().theta(); - + this.richpar = richpar; - + } - - - // ------------- + + public void set_CLASpid(int pid) - // ------------- - /* - * Set the particle pid that generates the track, take piion in case of doubt - * @param int pid, the identifier of the particle (only gamma, e, pi, proton and k are allowed) - */ + /* + * Set the particle pid that generates the track, take piion in case of doubt + * @param int pid, the identifier of the particle (only gamma, e, pi, proton and k are allowed) + */ { if (Math.abs(pid)==22 || Math.abs(pid)==11 || Math.abs(pid)==211 | Math.abs(pid)==321 || Math.abs(pid)==2212) { this.CLASpid = pid; @@ -194,250 +171,192 @@ public void set_CLASpid(int pid) if(pid<0)this.CLASpid*=-1; } } - - - // ------------- + + private double get_mass(int pid) { - // ------------- - + if (Math.abs(pid)==22 || Math.abs(pid)==11 || Math.abs(pid)==211 | Math.abs(pid)==321 || Math.abs(pid)==2212) { return PDGDatabase.getParticleById(pid).mass(); }else{ return 0.0; } - + } - - + + /* - // ------------- private void set_changle() { - // ------------- // define only one Cherenkov angle depending on the pid hypothesis - int debugMode = 0; - for(int j=0; j<3; j++) { - for(int k=0 ; k<4; k++) ChAngle[k][j] = 0.0; - sChAngle[j] = 0.0; - } - - for (int iref=0; iref<3; iref++){ - if(richpar.USE_ELECTRON_ANGLES==1){ - ChAngle[0][iref] = calibrated_ChAngle(11, iref); // expected angle for electron - ChAngle[1][iref] = calibrated_ChAngle(211, iref); // pion - ChAngle[2][iref] = calibrated_ChAngle(321, iref); // kaon - ChAngle[3][iref] = calibrated_ChAngle(2212, iref); // proton - - sChAngle[iref] = calibrated_sChAngle(iref); // expected angle for electron - - }else{ - - ChAngle[0][iref] = nominal_ChAngle(11); // expected angle for electron - ChAngle[1][iref] = nominal_ChAngle(211); // pion - ChAngle[2][iref] = nominal_ChAngle(321); // kaon - ChAngle[3][iref] = nominal_ChAngle(2212); // proton - - sChAngle[iref] = nominal_sChAngle(); // expected angle for electron - } - } - - if(debugMode>=1) { - System.out.format(" Create RICH particle mom %8.2f \n",momentum); - for(int ir=0; ir<3; ir++) System.out.format(" --> Refle %3d pr %7.2f k %7.2f pi %7.2f e %7.2f --> limi %7.2f %7.2f res %7.2f\n",ir, - ChAngle[3][ir]*MRAD,ChAngle[2][ir]*MRAD,ChAngle[1][ir]*MRAD,ChAngle[0][ir]*MRAD,min_changle(ir)*MRAD,max_changle(ir)*MRAD,sChAngle[ir]*MRAD); - } - - - if(debugMode>=1) { - System.out.format(" ============================= \n"); - dump_ChAngle(); - System.out.format(" ============================= \n"); - } + int debugMode = 0; + for(int j=0; j<3; j++) { + for(int k=0 ; k<4; k++) ChAngle[k][j] = 0.0; + sChAngle[j] = 0.0; + } + + for (int iref=0; iref<3; iref++){ + if(richpar.USE_ELECTRON_ANGLES==1){ + ChAngle[0][iref] = calibrated_ChAngle(11, iref); // expected angle for electron + ChAngle[1][iref] = calibrated_ChAngle(211, iref); // pion + ChAngle[2][iref] = calibrated_ChAngle(321, iref); // kaon + ChAngle[3][iref] = calibrated_ChAngle(2212, iref); // proton + + sChAngle[iref] = calibrated_sChAngle(iref); // expected angle for electron + + }else{ + + ChAngle[0][iref] = nominal_ChAngle(11); // expected angle for electron + ChAngle[1][iref] = nominal_ChAngle(211); // pion + ChAngle[2][iref] = nominal_ChAngle(321); // kaon + ChAngle[3][iref] = nominal_ChAngle(2212); // proton + + sChAngle[iref] = nominal_sChAngle(); // expected angle for electron + } + } + + if(debugMode>=1) { + System.out.format(" Create RICH particle mom %8.2f \n",momentum); + for(int ir=0; ir<3; ir++) System.out.format(" --> Refle %3d pr %7.2f k %7.2f pi %7.2f e %7.2f --> limi %7.2f %7.2f res %7.2f\n",ir, + ChAngle[3][ir]*MRAD,ChAngle[2][ir]*MRAD,ChAngle[1][ir]*MRAD,ChAngle[0][ir]*MRAD,min_changle(ir)*MRAD,max_changle(ir)*MRAD,sChAngle[ir]*MRAD); + } + + + if(debugMode>=1) { + System.out.format(" ============================= \n"); + dump_ChAngle(); + System.out.format(" ============================= \n"); + } }*/ - - - // ------------- - public double changle(int pid, int iref) { - // ------------- + + public double changle(int pid, int iref) { + if(richpar.USE_ELECTRON_ANGLES==1) return calibrated_ChAngle(pid, iref); return nominal_ChAngle(pid); - + } - - - // ------------- - public double schangle(int iref) { - // ------------- + + public double schangle(int iref) { + if(richpar.USE_ELECTRON_ANGLES==1) return calibrated_sChAngle(iref); return nominal_sChAngle(); - + } - - - // ------------- - public double nchangle(int pid, int iref) { - // ------------- + + public double nchangle(int pid, int iref) { + if(richpar.USE_ELECTRON_ANGLES==1) return calibrated_nChAngle(pid, iref); return nominal_nChAngle(pid); - + } - - - // ------------- + + public double chgain() { - // ------------- - + if(richpar.USE_CALIBRATED_PIXELS==1) return pixel_gain; return RICHConstants.PIXEL_NOMINAL_GAIN; - + } - - - // ------------- + + public double chbackgr() { - // ------------- - + int debugMode = 0; - + if(debugMode>=1)System.out.format("Pixel back %7.2f %7.2f (1e-9)\n",pixel_backr*1e9,richpar.PIXEL_NOMINAL_DARKRATE*1e9); if(richpar.USE_CALIBRATED_PIXELS==1 && pixel_backr>0) return pixel_backr; return richpar.PIXEL_NOMINAL_DARKRATE; - + } - - - // ------------- + + public double cheff() { - // ------------- - + if(richpar.USE_CALIBRATED_PIXELS==1) return pixel_eff; return RICHConstants.PIXEL_NOMINAL_EFF; - + } - - - // ------------- + + public double chtime() { - // ------------- - + if(richpar.USE_CALIBRATED_PIXELS==1) return pixel_mtime; return RICHConstants.PIXEL_NOMINAL_TIME; - + } - - - // ------------- + + public double schtime() { - // ------------- - + if(richpar.USE_CALIBRATED_PIXELS==1) return pixel_stime; return richpar.PIXEL_NOMINAL_STIME; - + } - - - // ------------- - public double get_chindex(int hypo_pid, int irefle) { - // ------------- + + public double get_chindex(int hypo_pid, int irefle) { + return 1./get_beta(hypo_pid)/Math.cos(changle(hypo_pid,irefle)); - + } - - - // ------------- - private void dump_ChAngle() { - // ------------- + + private void dump_ChAngle() { + for( int ir=0; ir-1; ip--){ - + int pid = RICHConstants.HYPO_LUND[ip]; System.out.format(" %s %7.2f ",RICHConstants.HYPO_STRING[ip],changle(pid,ir)*MRAD); } System.out.format(" --> limi %7.2f %7.2f res %7.2f\n",min_changle(ir)*MRAD, max_changle(ir)*MRAD, schangle(ir)*MRAD ); - + } } - - - // ------------- + + public int get_id() {return id;} - // ------------- - - // ------------- + public int get_ParentIndex() {return parent_index;} - // ------------- - - // ------------- + public int get_HitIndex() {return hit.get_id();} - // ------------- - - // ------------- + public int get_type() {return type;} - // ------------- - - // ------------- + public boolean is_throw() {if(get_type()>10)return true; return false;} - // ------------- - - // ------------- + public boolean is_real() {if(get_type()<10)return true; return false;} - // ------------- - - // ------------- + public int get_recofound() {return recofound;} - // ------------- - - // ------------- + public int get_Status() {return status;} - // ------------- - - // ------------- + public int get_CLASpid() {return CLASpid;} - // ------------- - - // ------------- + public int get_RICHpid() {return RICHpid;} - // ------------- - - // ------------- + public double get_StartTime() {return start_time;} - // ------------- - - // ------------- + public double get_HitTime() {return hit.get_Time();} - // ------------- - - // ------------- + public int get_HitSector() {return hit.get_sector();} - // ------------- - - // ------------- + public int get_HitPMT() {return hit.get_pmt();} - // ------------- - - // ------------- + public int get_HitAnode() {return hit.get_anode();} - // ------------- - - // ------------- + //public double get_changle(int ipar, int irefle) { return ChAngle[ipar][irefle]; } - // ------------- - - // ------------- - public double get_beta(int pid) { - // ------------- - // return the beta depending on the given pid hypothesis and particle momentum + public double get_beta(int pid) { + // return the beta depending on the given pid hypothesis and particle momentum + // no need to calculate anything for photons if(pid==22)return 1.0; - + if (Math.abs(pid)==11 || Math.abs(pid)==211 | Math.abs(pid)==321 || Math.abs(pid)==2212) { double mass = get_mass(pid); if (this.momentum==0 && mass==0) return 0.0; @@ -445,267 +364,211 @@ public double get_beta(int pid) { }else{ return 0.0; } - + } - - - // ---------------- + + public double max_changle(int irefle) { - // ---------------- - + for(int ip=0 ; ip0)return changle(pid,irefle) + richpar.NSIGMA_CHERENKOV * schangle(irefle); } return 0.0; } - - + + /* - // ---------------- public double maxChAngle(int irefle) { - // ---------------- - - for(int k=0 ; k<4; k++) if(ChAngle[k][irefle]>0)return ChAngle[k][irefle] + 3*sChAngle[irefle]; - return 0.0; + + for(int k=0 ; k<4; k++) if(ChAngle[k][irefle]>0)return ChAngle[k][irefle] + 3*sChAngle[irefle]; + return 0.0; }*/ - - - // ---------------- + + public double min_changle(int irefle) { - // ---------------- - + for(int ip=RICHConstants.N_HYPO-1 ; ip>-1; ip--) { int pid = RICHConstants.HYPO_LUND[ip]; if(changle(pid,irefle)>0)return Math.max( RICHConstants.RICH_MIN_CHANGLE, changle(pid,irefle) - richpar.NSIGMA_CHERENKOV * schangle(irefle)); } return 0.0; } - - + + /* - // ---------------- public double minChAngle(int irefle) { - // ---------------- - // calculate the minimum Cherenlov angle compatible with the momentum - - for(int k=3 ; k>=0; k--) if(ChAngle[k][irefle]>0) return Math.max(RICHConstants.RICH_MIN_CHANGLE, ChAngle[k][irefle] - 3*sChAngle[irefle]); - return 0.0; + // calculate the minimum Cherenlov angle compatible with the momentum + + for(int k=3 ; k>=0; k--) if(ChAngle[k][irefle]>0) return Math.max(RICHConstants.RICH_MIN_CHANGLE, ChAngle[k][irefle] - 3*sChAngle[irefle]); + return 0.0; }*/ - - - // ---------------- + + public double nominal_sChAngle(){ - // ---------------- - + return richpar.RICH_NOMINAL_SANGLE; } - - - // ---------------- + + public double nominal_ChAngle(int pid){ - // ---------------- - // calculate the cherenkov angle from the aerogel - // nominal refractive index for the four accepted - // particle hypothesis - + // calculate the cherenkov angle from the aerogel + // nominal refractive index for the four accepted + // particle hypothesis + int debugMode = 0; - + int ok = 0; for (int ip=0; ip0) arg = 1.0/beta/refi_emission; if(debugMode>=1) System.out.format(" Nominal Ch Angle %8.4f beta %8.4f n %7.3f arg %8.4f\n",get_mass(pid),beta,refi_emission, Math.acos(arg)*MRAD); - + if(arg>0.0 && arg<1.0) return Math.acos(arg); return 0.0; } - - - // ---------------- + + public double nominal_nChAngle(int pid){ - // ---------------- - + int debugMode = 0; - + int ok = 0; for (int ip=0; ip=1) System.out.format(" Expected N photo PID %5d Ne %7.2f r %7.2f --> n %7.3f \n",pid,nele,ratio,nele*ratio); - + return nele*ratio; } - - - // ---------------- + + public double calibrated_sChAngle(int irefle){ - // ---------------- - + return schele_emission[irefle]; } - - - // ---------------- + + public double calibrated_ChAngle(int pid, int irefle){ - // ---------------- - // recalculate the expected Cherenkov angle - // for the given particle hypothesis starting - // from the electron measured values - + // recalculate the expected Cherenkov angle + // for the given particle hypothesis starting + // from the electron measured values + int debugMode = 0; - + int ok = 0; for (int ip=0; ipRICHConstants.N_PATH) return 0.0; - + double beta = get_beta(pid); double cose = Math.cos(chele_emission[irefle]); - + double arg = 0.0; if(beta>0) arg = 1.0/beta*cose; if(debugMode>=1) System.out.format(" Calibrated Ch Angle %7.2f %8.4f beta %8.4f n %7.3f arg %8.4f [%4d %4d]\n", - chele_emission[irefle]*MRAD,get_mass(pid),beta,refi_emission, Math.acos(arg)*MRAD, ilay_emission, ico_emission); - + chele_emission[irefle]*MRAD,get_mass(pid),beta,refi_emission, Math.acos(arg)*MRAD, ilay_emission, ico_emission); + if(arg>0.0 && arg<1.0) return Math.acos(arg); return 0.0; } - - - // ---------------- + + public double calibrated_nChAngle(int pid, int irefle){ - // ---------------- - // recalculate the expected Cherenkov photon yield - // for the given particle hypothesis starting - // from the electron measured values - + // recalculate the expected Cherenkov photon yield + // for the given particle hypothesis starting + // from the electron measured values + int debugMode = 0; - + int ok = 0; for (int ip=0; ipRICHConstants.N_PATH) return 0.0; - + if(changle(11,0)==0)return 0.0; double ratio = Math.pow(Math.sin(changle(pid,0)),2)/Math.pow(Math.sin(changle(11,0)),2); double nele = nchele_emission[irefle]; - + if(debugMode>=1) System.out.format(" Expected N photo PID %5d Ne %7.2f r %7.2f --> n %7.3f \n",pid,nele,ratio,nele*ratio); - + return nele*ratio; } - - - // ---------------- + + public void set_id(int id) { this.id=id;} - // ---------------- - - // ---------------- + public void set_HitIndex(int hit_id) { this.hit.set_id(hit_id);} - // ---------------- - - // ---------------- + public void set_parent_index(int parent_id) { this.parent_index=parent_id;} - // ---------------- - - // ---------------- + public void set_type(int type) { this.type=type; } - // ---------------- - - // ---------------- + public void set_recofound(int recof) { this.recofound=recof; } - // ---------------- - - // ---------------- + public void set_Status(int sta) { this.status = sta; } - // ---------------- - - // ---------------- + public void set_sector(int sector) { this.sector=sector; } - // ---------------- - - // ---------------- + public int get_sector() { return this.sector; } - // ---------------- - - // ---------------- + public void set_momentum(double momentum) { this.momentum=momentum; } - // ---------------- - - // ---------------- + public double get_momentum() { return this.momentum; } - // ---------------- - - // ---------------- + public int charge() { return this.charge; } - // ---------------- - - // ---------------- + public void set_HitPos( Point3D impa){ this.hit.set_Position(impa); } - // ---------------- - - // ---------------- + public Point3D get_HitPos(){ return this.hit.get_Position(); } - // ---------------- - - // ---------------- + public void set_StartTime(double time){ this.start_time = time; } - // ---------------- - - // ---------------- + public void set_HitTime(double time){ this.hit.set_Time(time); } - // ---------------- - - // ------------- + public void set_RICHpid(int hpid){ - // ------------- RICHpid = hpid; if(this.CLASpid<0)RICHpid*=-1; } - - // ---------------- + public void set_PixelProp(RICHCalibration richcal){ - // ---------------- - + int debugMode = 0; - + int isec = hit.get_sector(); int ipmt = hit.get_pmt(); int ich = hit.get_anode(); - + pixel_gain = richcal.get_PixelGain(isec, ipmt, ich); pixel_eff = richcal.get_PixelEff(isec, ipmt, ich); pixel_mtime = richcal.get_PixelMeanTime(isec, ipmt, ich); pixel_stime = richcal.get_PixelRMSTime(isec, ipmt, ich); pixel_backr = richcal.get_PixelDarkRate(isec, ipmt, ich)*1e-9; - - if(debugMode>=1) System.out.format("Photon pixel %4d %4d %4d --> %7.2f %7.2f %7.2f %7.2f %7.3f (e-9) \n",hit.get_id(), ipmt-1, ich-1, + + if(debugMode>=1) System.out.format("Photon pixel %4d %4d %4d --> %7.2f %7.2f %7.2f %7.2f %7.3f (e-9) \n",hit.get_id(), ipmt-1, ich-1, pixel_gain, pixel_eff, pixel_mtime, pixel_stime, pixel_backr*1e9); - + } - - - // ---------------- + + public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richcal){ - // ---------------- - /* - * Search for the intersection points on the aerogel along forward trajectory - * Take the first (in z) with track pointing inside as Entrance - * Take the last (in z) with track pointing outside as Exit - */ - + /* + * Search for the intersection points on the aerogel along forward trajectory + * Take the first (in z) with track pointing inside as Entrance + * Take the last (in z) with track pointing outside as Exit + */ + int debugMode = 0; boolean found_exit = false; boolean found_entrance = false; RICHIntersection compo = null; - - if(debugMode>=1){ + + if(debugMode>=1){ if(debugMode>=3) System.out.println(" \n RICHParticle::set_aerogel_points \n"); System.out.format(" from ray %s \n",direct_ray.origin().toStringBrief(2)); if(debugMode>=3) System.out.println(" Look for intersection with layer 201 \n"); @@ -714,7 +577,7 @@ public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richca if(debugMode>=1 && entrance!=null) System.out.format(" B1 entrance %4d %6d %s \n",entrance.get_layer(),entrance.get_component(), entrance.get_pos().toStringBrief(2)); RICHIntersection exit = richtrace.get_Layer(sector, "AEROGEL_2CM_B1").find_Exit(direct_ray, -1); if(debugMode>=1 && exit!=null) System.out.format(" B1 exit %4d %6d %s \n",exit.get_layer(),exit.get_component(), exit.get_pos().toStringBrief(2)); - + if(entrance==null || exit==null){ if(debugMode>=3) System.out.println(" Look for intersection with layer 202 \n"); entrance = richtrace.get_Layer(sector, "AEROGEL_2CM_B2").find_Entrance(direct_ray, -1); @@ -722,7 +585,7 @@ public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richca exit = richtrace.get_Layer(sector, "AEROGEL_2CM_B2").find_Exit(direct_ray, -1); if(debugMode>=1 && exit!=null) System.out.format(" B2 exit %4d %6d %s \n",exit.get_layer(),exit.get_component(), exit.get_pos().toStringBrief(2)); } - + if(entrance==null || exit==null){ if(debugMode>=3) System.out.println(" Look for intersection with layer 203/204 \n"); entrance = richtrace.get_Layer(sector, "AEROGEL_3CM_L2").find_Entrance(direct_ray, -1); @@ -730,18 +593,18 @@ public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richca exit = richtrace.get_Layer(sector, "AEROGEL_3CM_L1").find_Exit(direct_ray, -1); if(debugMode>=1 && exit!=null) System.out.format(" B3 exit %4d %6d %s \n",exit.get_layer(),exit.get_component(), exit.get_pos().toStringBrief(2)); } - + if(entrance==null || exit==null){ if(debugMode>=1)System.out.format(" No intersection with aerogel plane found \n"); return false; } - + aero_entrance = entrance.get_pos(); aero_exit = exit.get_pos(); aero_normal = exit.get_normal(); - + /* - * Take point at 3/4 of path inside aerrogel + * Take point at 3/4 of path inside aerrogel */ Point3D amiddle = aero_exit.midpoint(aero_entrance); aero_middle = aero_exit.midpoint(amiddle); @@ -751,10 +614,10 @@ public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richca ico_emission = exit.get_component(); ico_entrance = entrance.get_component(); refi_emission = richtrace.get_Component(sector, ilay_emission,ico_emission).get_index(); - + int Nqua = richpar.QUADRANT_NUMBER; iqua_emission = richtrace.get_Layer(sector, ilay_emission).get_Quadrant(Nqua, ico_emission, exit.get_pos()); - + if(debugMode>=1){ System.out.format(" AERO lay %3d ico %3d qua %3d \n",ilay_emission,ico_emission,iqua_emission); if(entrance.get_layer()!=ilay_emission || entrance.get_component()!=ico_emission) @@ -762,10 +625,10 @@ public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richca } // perform photon reconstruction, to be saved in RICH::Ring /*if(richcal.get_AeroStatus(sector, ilay_emission, ico_emission)>0){ - if(debugMode>=1)System.out.format(" AERO bad status: disregard \n"); - return false; + if(debugMode>=1)System.out.format(" AERO bad status: disregard \n"); + return false; }*/ - + if(richpar.USE_ELECTRON_ANGLES==1){ for(int iref=0; iref<3; iref++){ chele_emission[iref] = richcal.get_ChElectron(sector, ilay_emission, ico_emission, iqua_emission, iref, charge); @@ -775,17 +638,17 @@ public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richca ilay_emission, ico_emission, iref, chele_emission[iref]*MRAD,nchele_emission[iref]); } } - + //set_changle(); - + Vector3D Z_ONE = new Vector3D(0., 0., 1); RotAxis = aero_normal.cross(Z_ONE).asUnit(); RotAngle = aero_normal.angle(Z_ONE); - + double dist = aero_middle.distance(direct_ray.origin()); if(aero_middle.z()-direct_ray.origin().z()<0) dist*=-1; start_time += (path + dist)/get_beta(CLASpid)/(PhysicsConstants.speedOfLight()); - + if(debugMode>=3){ System.out.println(" AERO entrance %s "+aero_entrance.toStringBrief(2)); System.out.println(" AERO middle %s "+aero_middle.toStringBrief(2)); @@ -795,153 +658,143 @@ public boolean find_AerogelPoints(RICHRayTrace richtrace, RICHCalibration richca System.out.println(" AERO compo "+ico_emission); System.out.println(" AERO refi "+refi_emission); } - + return true; } - - - // ---------------- + + public void set_rotated_points(RICHParticle hadron){ - // ---------------- - + this.reference = hadron.reference; Quaternion q = new Quaternion(hadron.RotAngle, hadron.RotAxis); - + this.ref_emission = q.rotate(this.lab_emission.vectorFrom(this.reference)).toPoint3D(); this.ref_impact = q.rotate(this.hit.get_Position().vectorFrom(this.reference)).toPoint3D(); - + this.ref_phi = ref_impact.toVector3D().phi(); this.ref_theta = ref_impact.toVector3D().theta(); this.ref_proj = hadron.ref_proj; - + this.EtaC_ref = calc_EtaC(hadron, this.ref_theta); - + } - - - // ---------------- + + public boolean set_rotated_points() { - // ---------------- - + int debugMode = 0; if(lab_emission==null)return false; - + if(debugMode>=2) System.out.println(" \n RICHParticle::set_rotated_points \n"); - + // define an arbitrary reference point, here taken to be the photon emission point reference = lab_emission; - + // Define the rotation from aerogel normal to the z axis Quaternion q = new Quaternion(RotAngle, RotAxis.asUnit()); - + // rotate into the new reference system ref_emission = q.rotate( lab_emission.vectorFrom(reference)).toPoint3D(); ref_impact = q.rotate( hit.get_Position().vectorFrom(reference)).toPoint3D(); - + ref_proj = new Point3D(ref_emission.x(), ref_emission.y(), ref_impact.z()-ref_emission.z()); - + this.ref_phi = ref_impact.toVector3D().phi(); this.ref_theta = ref_impact.toVector3D().theta(); - + if(debugMode>=2){ System.out.format(" --> Track projection (P_PCP) %s ",ref_proj.toStringBrief(2)); System.out.format(" --> Track impact (P_P) %s ",ref_impact.toStringBrief(2)); System.out.format(" --> Track angles %8.2f %8.2f \n", this.ref_theta*57.3, this.ref_phi*57.3); } - + return true; } - - - // ---------------- + + public double calc_EtaC (RICHParticle hadron, double theta) { - // ---------------- // direct tracing without aerogel refraction - + double Theta_P = hadron.ref_theta; double Phi_P = hadron.ref_phi; - + double Cos_EtaC = Math.sin(Theta_P)* Math.sin(theta)*Math.cos(this.ref_phi-Phi_P)+Math.cos(Theta_P)*Math.cos(theta); - + return Math.acos(Cos_EtaC); - + } - - - // ---------------- + + public double time_probability(double testtime, int recotype) { - // ---------------- - /* - * calculate probability for a given time hypothesis - */ + /* + * calculate probability for a given time hypothesis + */ int debugMode = 0; - + RICHSolution reco = new RICHSolution(); if(recotype==0) reco = analytic; if(recotype==1) reco = traced; - + // timing probability double meant = start_time + reco.get_time(); double sigmat = richpar.PIXEL_NOMINAL_STIME; - + double funt = 0.0; double dfunt = 1; - + if(meant>0){ funt = Math.exp((-0.5)*Math.pow((testtime - meant)/sigmat, 2) )/ (sigmat*Math.sqrt(2* Math.PI)); } double prob = funt*dfunt; double back = richpar.PIXEL_NOMINAL_DARKRATE*richpar.NSIGMA_TIME*richpar.PIXEL_NOMINAL_STIME; - + if(debugMode>=1)if(prob>back)System.out.format( - "TIM prob meant %8.3f time %8.3f --> %g %g \n", - meant,testtime,funt*dfunt,Math.log(prob)); + "TIM prob meant %8.3f time %8.3f --> %g %g \n", + meant,testtime,funt*dfunt,Math.log(prob)); return prob; - + } - - // ---------------- + public double pid_probability(RICHParticle hadron, int hypo_pid, int recotype) { - // ---------------- - /* - * calculate probability for a given pid hypothesis - * based on the particle momentum and RICH resolution - * at the moment, equal photon generation and particle - * flux is assumed, actually close to Cherenkov threshold - * the photon yiled decreases and pions outnumber koans. - */ - + /* + * calculate probability for a given pid hypothesis + * based on the particle momentum and RICH resolution + * at the moment, equal photon generation and particle + * flux is assumed, actually close to Cherenkov threshold + * the photon yiled decreases and pions outnumber koans. + */ + int debugMode = 0; RICHSolution reco = new RICHSolution(); if(recotype==0) reco = analytic; if(recotype==1) reco = traced; - + double func = 0.0; double dfunc = 1e-3; - + double funt = 0.0; double dfunt = 1; - + double mean = 0.0; double sigma = 0.0; double recot = 0.0; double meant = 0.0; double sigmat = 0.0; - + int pixel_flag = 0; if(pixel_flag==0){ - + // angle probability - + int irefle = reco.get_RefleType(); if(irefle>=0 && irefle<=2){ mean=hadron.changle(hypo_pid, irefle); sigma = hadron.schangle(irefle); } - + if(mean>0 && sigma>0){ func = Math.exp((-0.5)*Math.pow((reco.get_EtaC() - mean)/sigma, 2) )/ (sigma*Math.sqrt(2* Math.PI)); } @@ -950,64 +803,62 @@ public double pid_probability(RICHParticle hadron, int hypo_pid, int recotype) { recot = start_time + reco.get_time(); meant = pixel_mtime; sigmat = pixel_stime; - + if(recot>0 && sigmat>0){ funt = Math.exp((-0.5)*Math.pow((hit.get_Time() - recot - meant)/sigmat, 2) )/ (sigmat*Math.sqrt(2* Math.PI)); } } - + double back = richpar.PIXEL_NOMINAL_DARKRATE*richpar.NSIGMA_TIME*richpar.PIXEL_NOMINAL_STIME; double prob = 1 + pixel_eff *func*dfunc*funt*dfunt + back; - + if(debugMode>=1)System.out.format( - "PID prob %4d mean %7.2f etaC %7.2f sigma %7.2f meant %7.2f (%7.2f + %7.2f) time %7.2f sigmat %7.2f eff %7.2f --> %10.4g %10.4g %8.4f e-3\n",hypo_pid, - mean*MRAD,reco.get_EtaC()*MRAD,sigma*MRAD,recot+meant,recot,meant,hit.get_Time(),sigmat,pixel_eff,func*dfunc,funt*dfunt,Math.log(prob)*1e3); + "PID prob %4d mean %7.2f etaC %7.2f sigma %7.2f meant %7.2f (%7.2f + %7.2f) time %7.2f sigmat %7.2f eff %7.2f --> %10.4g %10.4g %8.4f e-3\n",hypo_pid, + mean*MRAD,reco.get_EtaC()*MRAD,sigma*MRAD,recot+meant,recot,meant,hit.get_Time(),sigmat,pixel_eff,func*dfunc,funt*dfunt,Math.log(prob)*1e3); return prob; - + } - - - // ---------------- + + public double pid_LHCb(RICHParticle hadron, int hypo_pid, int recotype, int inorma) { - // ---------------- - /* - * calculate probability for a given pid hypothesis - * based on the particle momentum and RICH resolution - * at the moment, equal photon generation and particle - * flux is assumed, actually close to Cherenkov threshold - * the photon yiled decreases and pions outnumber koans. - */ - + /* + * calculate probability for a given pid hypothesis + * based on the particle momentum and RICH resolution + * at the moment, equal photon generation and particle + * flux is assumed, actually close to Cherenkov threshold + * the photon yiled decreases and pions outnumber koans. + */ + int debugMode = 0; RICHSolution reco = new RICHSolution(); if(recotype==0) reco = analytic; if(recotype==1) reco = traced; - + double func = 0.0; double dfunc = 1; - + double funt = 0.0; double dfunt = 1; - + double mean = 0.0; double sigma = 0.0; double recot = 0.0; double meant = 0.0; double sigmat = 0.0; - + int pixel_flag = 0; if(pixel_flag==0){ - + // angle probability - + int irefle = reco.get_RefleType(); if(irefle>=0 && irefle<=2){ mean=hadron.changle(hypo_pid, irefle); sigma = hadron.schangle(irefle); } - - if(reco.get_EtaC()>0 && sigma>0){ + + if(reco.get_EtaC()>0 && sigma>0){ // non-zero reconstruction and reference values exist (mean=0 below threshold) func = Math.exp((-0.5)*Math.pow((reco.get_EtaC() - mean)/sigma, 2) )/ (sigma*Math.sqrt(2* Math.PI)); } @@ -1017,9 +868,9 @@ public double pid_LHCb(RICHParticle hadron, int hypo_pid, int recotype, int inor recot = start_time + reco.get_time(); meant = pixel_mtime; sigmat = pixel_stime; - + if(recot>0 && sigmat>0){ - // non-zero reconstruction and reference values exist + // non-zero reconstruction and reference values exist funt = Math.exp((-0.5)*Math.pow((hit.get_Time() - recot - meant)/sigmat, 2) )/ (sigmat*Math.sqrt(2* Math.PI)); } if(inorma==1)funt = 1. / (sigmat*Math.sqrt(2* Math.PI)); @@ -1027,40 +878,38 @@ public double pid_LHCb(RICHParticle hadron, int hypo_pid, int recotype, int inor } double back = richpar.PIXEL_NOMINAL_DARKRATE*richpar.NSIGMA_TIME*richpar.PIXEL_NOMINAL_STIME; double prob = 1 + pixel_eff *func*dfunc*funt*dfunt + back; - + if(debugMode>=1)System.out.format( - "PID prob %4d mean %7.2f etaC %7.2f sigma %7.2f meant %7.2f (%7.2f + %7.2f) time %7.2f sigmat %7.2f eff %7.2f --> %10.4g %10.4g %8.4f\n",hypo_pid, - mean*MRAD,reco.get_EtaC()*MRAD,sigma*MRAD,recot+meant,recot,meant,hit.get_Time(),sigmat,pixel_eff,func*dfunc,funt*dfunt,prob); + "PID prob %4d mean %7.2f etaC %7.2f sigma %7.2f meant %7.2f (%7.2f + %7.2f) time %7.2f sigmat %7.2f eff %7.2f --> %10.4g %10.4g %8.4f\n",hypo_pid, + mean*MRAD,reco.get_EtaC()*MRAD,sigma*MRAD,recot+meant,recot,meant,hit.get_Time(),sigmat,pixel_eff,func*dfunc,funt*dfunt,prob); return prob; - + } - - // ---------------- + public double calc_HypoYield(RICHParticle hadron, int hypo_pid, int recotype, double Npho, int iref) { - // ---------------- - /* - * calculate probability for a given pid hypothesis - * based on the particle momentum and RICH resolution; - * it uses the expected number of photons, the expected - * background; iref = 1 forces a right hypothesis - */ - + /* + * calculate probability for a given pid hypothesis + * based on the particle momentum and RICH resolution; + * it uses the expected number of photons, the expected + * background; iref = 1 forces a right hypothesis + */ + int debugMode = 0; RICHSolution reco = new RICHSolution(); if(recotype==0) reco = analytic; if(recotype==1) reco = traced; - + // angle probability double mean = 0.0; double sigma = 0.0; - + int irefle = reco.get_RefleType(); if(irefle>=0 && irefle<=2){ mean = hadron.changle(hypo_pid, irefle); sigma = hadron.schangle(irefle); } - + double ftheta = 0.0; // fraction rad mrad (consistent with normalization) double dtheta = reco.get_dthe_pixel()*nominal_sChAngle()*MRAD; @@ -1071,12 +920,12 @@ public double calc_HypoYield(RICHParticle hadron, int hypo_pid, int recotype, do ftheta = 1./(sigma*MRAD*Math.sqrt(2* Math.PI)); } } - + // timing probability double recot = start_time + reco.get_time(); double meant = chtime(); double sigmat = schtime(); - + double ftime = 0.0; double dtime = 1.0; if(recot>0 && sigmat>0){ @@ -1086,121 +935,115 @@ public double calc_HypoYield(RICHParticle hadron, int hypo_pid, int recotype, do ftime = 1./(sigmat*Math.sqrt(2* Math.PI)); } } - + // background probability double backgr = 0.0; double dphi = reco.get_dphi_pixel()*nominal_sChAngle()/(2*Math.PI); //double dphi = 1.; - + if (reco.get_dphi_pixel()>0 && dphi!=1){ double dpixel = reco.get_dphi_pixel()*nominal_sChAngle()/(2*Math.PI); backgr = chbackgr() * dphi/dpixel * 2*richpar.NSIGMA_TIME*sigmat; }else{ backgr = chbackgr() * 2*richpar.NSIGMA_TIME*sigmat; } - + double prob = Npho * ftheta*dtheta * dphi; - - if(richpar.USE_PIXEL_TIME==1) prob *= ftime*dtime; - if(richpar.USE_PIXEL_EFF==1) prob *= cheff(); - - if(richpar.USE_PIXEL_BACKGR==1) prob += backgr; - + + if(richpar.USE_PIXEL_TIME==1) prob *= ftime*dtime; + if(richpar.USE_PIXEL_EFF==1) prob *= cheff(); + + if(richpar.USE_PIXEL_BACKGR==1) prob += backgr; + if(debugMode>=1 && iref==0){ System.out.format("\n HYPO %4d %4d %3d: A %6.2f (%6.2f, %5.2f) ", hit.get_id(),hypo_pid,irefle,reco.get_EtaC()*MRAD,mean*MRAD,sigma*MRAD); //System.out.format(" T %6.2f (%6.2f, %5.2f) E %5.2f B %8.4g", // hit.get_Time(),recot+meant,sigmat,pixel_eff,backgr); - //System.out.format("--> %5.1f %10.4g %10.4g %10.4g --> %8.4g \n", + //System.out.format("--> %5.1f %10.4g %10.4g %10.4g --> %8.4g \n", // Npho,ftheta*dtheta,dphi,ftime*dtime,prob); System.out.format(" T %6.2f (%6.2f, %5.2f) ", hit.get_Time(),recot+meant,sigmat); - System.out.format("--> %5.1f %10.4g %10.4g %10.4g %10.4g %10.4g %10.4g --> %8.4g \n\n", + System.out.format("--> %5.1f %10.4g %10.4g %10.4g %10.4g %10.4g %10.4g --> %8.4g \n\n", Npho,ftheta,dtheta,dphi,ftime,dtime,backgr,prob); } return prob; - + } - - // ---------------- + public double calc_HypoC2(RICHParticle hadron, int hypo_pid, int recotype) { - // ---------------- - /* - * calculate chi2 for a given pid hypothesis - * based on angle and time of RICH resolution; - */ - + /* + * calculate chi2 for a given pid hypothesis + * based on angle and time of RICH resolution; + */ + int debugMode = 0; RICHSolution reco = new RICHSolution(); if(recotype==0) reco = analytic; if(recotype==1) reco = traced; - + // angle probability double mean = 0.0; double sigma = 0.0; - + int irefle = reco.get_RefleType(); if(irefle>=0 && irefle<=2){ mean = hadron.changle(hypo_pid, irefle); sigma = hadron.schangle(irefle); } - + double ftheta = Math.pow((reco.get_EtaC()- mean)/sigma, 2); - + // timing probability double recot = start_time + reco.get_time(); double meant = chtime(); double sigmat = schtime(); - + double ftime = Math.pow((hit.get_Time() - recot - meant)/sigmat, 2); - + double prob = ftheta + ftime; //if(prob>12)prob=12.; - + if(debugMode>=1){ System.out.format("HYPO %4d %4d %3d: A %6.2f (%6.2f, %5.2f) ", hit.get_id(),hypo_pid,irefle,reco.get_EtaC()*MRAD,mean*MRAD,sigma*MRAD); System.out.format(" T %6.2f (%6.2f, %5.2f) ", hit.get_Time(),recot+meant,sigmat); - System.out.format("--> %10.4g %10.4g --> %10.4g \n", + System.out.format("--> %10.4g %10.4g --> %10.4g \n", ftheta,ftime,prob); } return prob; - + } - - + + /* - // ---------------- public double set_likelihood(double etaC) { - // ---------------- - - double pi = probability(211, etaC) - double k = probability(211, etaC) - double pr = probability(211, etaC) - - pi_like = Math.log(pi/(pi+k+pr)); - k_like = Math.log(k/(pi+k+pr)); - pr_like = Math.log(pr/(pi+k+pr)); - + + double pi = probability(211, etaC) + double k = probability(211, etaC) + double pr = probability(211, etaC) + + pi_like = Math.log(pi/(pi+k+pr)); + k_like = Math.log(k/(pi+k+pr)); + pr_like = Math.log(pr/(pi+k+pr)); + } */ - - - // ---------------- + + public void show() { - // ---------------- - + Vector3D ref_direction = ref_impact.vectorFrom(ref_emission).asUnit(); Vector3D ori_emission = lab_emission.vectorFrom(reference); Vector3D ori_impact = hit.get_Position().vectorFrom(reference); - + System.out.format(" PART info pid %d mass %8.5f mom %g \n", CLASpid, get_mass(CLASpid), momentum); - + for(int ir=0; ir %s \n", ori_impact.toStringBrief(1), ref_impact.toStringBrief(1)); System.out.format(" projection --> %s \n", ref_proj.toStringBrief(1)); System.out.println(" "); - + } - - // ---------------- + public void shortshow() { - // ---------------- - + Vector3D ref_direction = ref_impact.vectorFrom(ref_emission).asUnit(); Vector3D ori_emission = lab_emission.vectorFrom(reference); Vector3D ori_impact = hit.get_Position().vectorFrom(reference); - + System.out.format(" PART id %4d type %4d pid %4d mass %8.5f mom %g \n", id, type, CLASpid, get_mass(CLASpid), momentum); System.out.println(" "); System.out.format(" TRACK direction %s theta %8.2f phi %8.2f \n", direct_ray.toVector().toStringBrief(2), lab_theta*RAD, lab_phi*RAD); System.out.format(" emission %s time %8.2f \n", lab_emission.toStringBrief(2), start_time); System.out.format(" impact %s time track %8.2f vs hit %8.2f \n", hit.get_Position().toStringBrief(2), traced.get_time(), hit.get_Time()); System.out.println(" "); - + } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHRayTrace.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHRayTrace.java index d54182452a..bf764a2cf8 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHRayTrace.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHRayTrace.java @@ -7,176 +7,149 @@ import org.jlab.detector.geom.RICH.RICHGeoConstants; import org.jlab.detector.geom.RICH.RICHGeoFactory; import java.util.ArrayList; -import java.util.List; - -import org.jlab.detector.calib.utils.ConstantsManager; -import org.jlab.detector.geant4.v2.RICHGeant4Factory; -import org.jlab.detector.volume.G4Stl; -import org.jlab.detector.volume.G4Box; - import org.jlab.geom.prim.Vector3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Plane3D; import org.jlab.geom.prim.Point3D; - import org.freehep.math.minuit.FCNBase; import org.freehep.math.minuit.FunctionMinimum; import org.freehep.math.minuit.MnMigrad; -import org.freehep.math.minuit.MnScan; import org.freehep.math.minuit.MnUserParameters; - import org.jlab.clas.pdg.PhysicsConstants; - /** * * @author mcontalb */ public class RICHRayTrace{ - + private final static RICHGeoConstants geocost = new RICHGeoConstants(); - + private RICHGeoFactory richgeo; private RICHParameters richpar; - + private static final double RAD = RICHConstants.RAD; private static final double MRAD = RICHConstants.MRAD; - - - //------------------------------ + + public RICHRayTrace() { - //------------------------------ } - - - //------------------------------ + + public RICHRayTrace(RICHGeoFactory richgeo, RICHParameters richpar){ - //------------------------------ - + this.richgeo = richgeo; this.richpar = richpar; - + } - - - //------------------------------ + + public RICHLayer get_Layer(int isec, String slay){ - //------------------------------ - + return richgeo.get_Layer(isec, slay); - + } - - - //------------------------------ - public RICHLayer get_Layer(int isec, int ilay){ - //------------------------------ - + + + public RICHLayer get_Layer(int isec, int ilay){ + return richgeo.get_Layer(isec, ilay); - + } - - - //------------------------------ - public RICHComponent get_Component(int isec, int ilay, int ico){ - //------------------------------ - + + + public RICHComponent get_Component(int isec, int ilay, int ico){ + return richgeo.get_Layer(isec, ilay).get(ico); - + } - - - // ---------------- + + public Vector3D Reflection(Vector3D vector1, Vector3D normal) { - // ---------------- - + int debugMode = 0; Vector3D vin = vector1.asUnit(); Vector3D vnorm = normal.asUnit(); - - double cosI = vin.dot(vnorm); + + double cosI = vin.dot(vnorm); if(debugMode>=1)System.out.format("Vector in %s vnorm %s cosI %7.3f \n ",vin.toStringBrief(3),vnorm.toStringBrief(3),cosI); if (cosI > 0) { if(debugMode>=1)System.out.format("Mirror normal parallel to impinging ray %7.3f \n",cosI); vnorm.scale(-1.0); } - + double refle = 2*(vin.dot(vnorm)); Vector3D vout = vin.sub(vnorm.multiply(refle)); - + if(debugMode>=1){ System.out.format("Mirror normal %s\n",normal.toStringBrief(3)); System.out.format("Reflected versor %s\n", vout.asUnit().toStringBrief(3)); } - + return vout.asUnit(); } - - // ---------------- + public Vector3D Transmission2(Vector3D vector1, Vector3D normal, double n_1, double n_2) { - // ---------------- - + int debugMode = 0; double rn = n_1 / n_2; - + Vector3D vin = vector1.asUnit(); Vector3D vnorm = normal.asUnit(); - - double cosI = vin.dot(vnorm); + + double cosI = vin.dot(vnorm); if(debugMode>=1)System.out.format("Vector in %s vnorm %s cosI %7.3f \n ",vin.toStringBrief(3),vnorm.toStringBrief(3),cosI); if (cosI < 0) { if(debugMode>=1)System.out.format("Mirror normal parallel to impinging ray %7.3f \n",cosI); vnorm.scale(-1.0); } if(debugMode>=1)System.out.format("Vector in %s vnorm %s cosI %7.3f \n ",vin.toStringBrief(3),vnorm.toStringBrief(3),cosI); - + Vector3D vrot = (vnorm.cross(vin)).asUnit(); - + double angi = Math.acos(vin.dot(vnorm)) ; double ango = Math.asin( rn * Math.sin(angi)); - + Quaternion q = new Quaternion(ango, vrot); - + Vector3D vout = q.rotate(vnorm); - + if(debugMode>=1){ System.out.format(" vin %s \n", vin.toStringBrief(3)); - System.out.format(" vnorm %s \n", vnorm.toStringBrief(3)); + System.out.format(" vnorm %s \n", vnorm.toStringBrief(3)); System.out.format(" angles %7.3f %7.3f \n",angi*57.3, ango*57.3); - System.out.format(" vout %s \n", vout.toStringBrief(3)); + System.out.format(" vout %s \n", vout.toStringBrief(3)); } - + return vout; - + } - - // ---------------- + public RICHRay OpticalRotation(RICHRay rayin, RICHIntersection intersection) { - // ---------------- - + int debugMode = 0; Point3D vori = rayin.origin(); Vector3D inVersor = rayin.direction().asUnit(); Vector3D newVersor = new Vector3D(0.0, 0.0, 0.0); RICHRay rayout = null; int type = 0; - + if(debugMode>=1)System.out.format("Ray for %3d %3d %3d \n",intersection.get_sector(), intersection.get_layer(), intersection.get_component()); RICHLayer layer = richgeo.get_Layer(intersection.get_sector(), intersection.get_layer()); - + if(layer.is_optical()==true){ - + if(debugMode>=1)System.out.format("Ray rotation at Optical compo %3d %3d xyz %s \n", intersection.get_layer(), intersection.get_component(), vori.toStringBrief(2)); Vector3D vnorm = intersection.get_normal(); if(vnorm != null ){ if(layer.is_mirror()==true){ - + newVersor = Reflection(inVersor, vnorm); type=10000+intersection.get_layer()*100+intersection.get_component()+1; if(debugMode>=1)System.out.format(" Reflection at mirror surface norm %s \n", vnorm.toStringBrief(3)); - + }else{ - + newVersor = Transmission2(inVersor, vnorm, intersection.get_nin(), intersection.get_nout()); type=20000+intersection.get_layer()*100+intersection.get_component()+1; if(debugMode>=1){ @@ -187,103 +160,99 @@ public RICHRay OpticalRotation(RICHRay rayin, RICHIntersection intersection) { } } } - - if(debugMode>=1)System.out.format(" Versor in %s --> out %s \n",inVersor.toStringBrief(3), newVersor.toStringBrief(3)); + + if(debugMode>=1)System.out.format(" Versor in %s --> out %s \n",inVersor.toStringBrief(3), newVersor.toStringBrief(3)); } - + rayout = new RICHRay(vori, newVersor.multiply(200)); rayout.set_type(type); return rayout; - + } - - // ---------------- + public ArrayList RayTrace(RICHParticle photon, Vector3D vlab) { - // ---------------- - + int debugMode = 0; - + RICHLayer layer = get_Layer(photon.get_sector(), photon.ilay_emission); if(debugMode>=1)System.out.format("Raytrace gets refractive index from CCDB database %8.5f \n",layer.get(photon.ico_emission).get_index()); return RayTrace(photon, vlab, layer.get(photon.ico_emission).get_index()); - + } - - - // ---------------- + + public ArrayList RayTrace(RICHParticle photon, Vector3D vlab, double naero) { - // ---------------- - // return the hit position on the PMT plane of a photon emitted at emission with direction vlab - + // return the hit position on the PMT plane of a photon emitted at emission with direction vlab + int debugMode = 0; ArrayList raytracks = new ArrayList(); - + int orilay = photon.ilay_emission; int orico = photon.ico_emission; int isec = photon.get_sector(); Point3D emi = photon.lab_emission; Vector3D vdir = vlab; - + RICHRay lastray = new RICHRay(emi, vdir.multiply(200)); if(debugMode>=1) { System.out.format(" --------------------------- \n"); - System.out.format("Raytrace photon ori %s olay %3d oco %3d dir %s \n",emi.toStringBrief(2),orilay,orico,vdir.toStringBrief(3)); + System.out.format("Raytrace photon ori %s olay %3d oco %3d dir %s \n",emi.toStringBrief(2),orilay,orico,vdir.toStringBrief(3)); System.out.format(" --------------------------- \n"); } - + RICHLayer layer = get_Layer(isec, orilay); if(layer==null)return null; - + RICHIntersection first_intersection = null; if(richpar.DO_CURVED_AERO==1){ first_intersection = layer.find_ExitCurved(lastray.asLine3D(), orico); }else{ first_intersection = layer.find_Exit(lastray.asLine3D(), orico); } - if(first_intersection==null)return null; - + if(first_intersection==null)return null; + if(debugMode>=1){ System.out.format(" first inter : "); first_intersection.showIntersection(); } - + Point3D new_pos = first_intersection.get_pos(); RICHRay oriray = new RICHRay(emi, new_pos); - + /* rewrite the refractive index to be consistent with photon theta - only valid for initial aerogel - the rest of components take ref index from CCDB database + only valid for initial aerogel + the rest of components take ref index from CCDB database */ //oriray.set_refind(layer.get(orico).get_index()); first_intersection.set_nin((float) naero); oriray.set_refind(naero); raytracks.add(oriray); - + RICHRay rayin = new RICHRay(new_pos, oriray.direction().multiply(200)); lastray = OpticalRotation(rayin, first_intersection); lastray.set_refind(geocost.RICH_AIR_INDEX); RICHIntersection last_intersection = first_intersection; - + if(debugMode>=1){ System.out.format(" add first ray : "); oriray.showRay(); System.out.format(" get rotated ray : "); lastray.showRay(); } - + int jj = 1; int front_nrefl = 0; boolean detected = false; boolean lost = false; while( detected == false && lost == false && raytracks.size()<10){ - + Point3D last_ori = lastray.origin(); Point3D new_hit = null; RICHIntersection new_intersection = null; if(debugMode>=1)System.out.format(" ray-tracking step %d \n",jj); - + if(last_intersection.get_layer()<4){ - + // planar mirrors RICHIntersection test_intersection = get_Layer(isec, "MIRROR_BOTTOM").find_Entrance(lastray.asLine3D(), -1); if(test_intersection==null)test_intersection = get_Layer(isec, "MIRROR_LEFT_L1").find_Entrance(lastray.asLine3D(), -1); @@ -300,7 +269,7 @@ public ArrayList RayTrace(RICHParticle photon, Vector3D vlab, double na }else{ if(debugMode>=1)System.out.format(" no lateral mirror intersection \n"); } - + // shperical mirrors if(lastray.direction().costheta()>0){ test_intersection = get_Layer(isec, "MIRROR_SPHERE").find_EntranceCurved(lastray.asLine3D(), -1); @@ -311,22 +280,22 @@ public ArrayList RayTrace(RICHParticle photon, Vector3D vlab, double na test_intersection.showIntersection(); } //if(test_intersection.get_pos().distance(last_ori)>RICHConstants.PHOTON_DISTMIN_TRACING){ - if(new_intersection==null || (new_intersection!=null && test_intersection.get_pos().z()=1)System.out.format(" no sphere intersection \n"); } - + RICHIntersection pmt_inter = get_Layer(isec, "MAPMT").find_Entrance(lastray.asLine3D(), -1); if(pmt_inter!=null) { - Point3D test_hit = pmt_inter.get_pos(); + Point3D test_hit = pmt_inter.get_pos(); //if(test_hit.distance(last_ori)>RICHConstants.PHOTON_DISTMIN_TRACING){ - new_hit=test_hit; - if(debugMode>=1)System.out.format(" test PMT : Hit %s \n",new_hit.toStringBrief(2)); + new_hit=test_hit; + if(debugMode>=1)System.out.format(" test PMT : Hit %s \n",new_hit.toStringBrief(2)); //}else{ - //if(debugMode>=1)System.out.format(" too far PMT plane intersection \n"); + //if(debugMode>=1)System.out.format(" too far PMT plane intersection \n"); //} }else{ if(debugMode>=1)System.out.format(" no PMT plane intersection \n"); @@ -339,16 +308,16 @@ public ArrayList RayTrace(RICHParticle photon, Vector3D vlab, double na System.out.format(" test front (z %7.2f, step %7.2f) : ",last_ori.z(), test_intersection.get_pos().distance(last_ori)); test_intersection.showIntersection(); } - //if(test_intersection.get_pos().distance(last_ori)>RICHConstants.PHOTON_DISTMIN_TRACING)new_intersection = test_intersection; + //if(test_intersection.get_pos().distance(last_ori)>RICHConstants.PHOTON_DISTMIN_TRACING)new_intersection = test_intersection; new_intersection = test_intersection; front_nrefl++; }else{ if(debugMode>=1)System.out.format(" no front mirror intersection \n"); } } - + } - + if(new_hit!=null){ if(new_intersection==null || new_hit.distance(last_ori) <= new_intersection.get_pos().distance(last_ori)) { detected=true; @@ -356,16 +325,16 @@ public ArrayList RayTrace(RICHParticle photon, Vector3D vlab, double na } } if(front_nrefl>richpar.RAY_NFRONT_REFLE){ - lost = true; + lost = true; new_hit=new_intersection.get_pos(); if(debugMode>=1)System.out.format(" double front reflection: stop at front %s \n",new_hit.toStringBrief(2)); } if(new_hit==null && new_intersection==null){ - lost = true; + lost = true; Point3D point = new Point3D(0.0, 0.0, 0.0);; new_hit = new Point3D(lastray.end()); Plane3D plane = richgeo.toTriangle3D(get_Layer(isec, "MAPMT").get_Face(0)).plane(); - if(plane.intersection(lastray.asLine3D(), point)==1){ + if(plane.intersection(lastray.asLine3D(), point)==1){ double vers = lastray.direction().costheta(); double Delta_z = point.z()-lastray.origin().z(); if(debugMode>=1) System.out.format(" forced stop at PMT plane: Delta_z %7.3f vers %7.3f \n",Delta_z, vers); @@ -379,11 +348,11 @@ public ArrayList RayTrace(RICHParticle photon, Vector3D vlab, double na if(debugMode>=1) System.out.format(" no hit on PMT plane: take last ray end %s \n", new_hit.toStringBrief(2)); } } - + if(lost || detected){ if(debugMode>=1 && lost) System.out.format("LOST! stop ray-tracing \n"); if(debugMode>=1 && detected) System.out.format("DETECTED! stop ray-tracing \n"); - + RICHRay newray = new RICHRay(last_ori, new_hit); newray.set_type(lastray.get_type()); newray.set_refind((float) geocost.RICH_AIR_INDEX); @@ -393,49 +362,47 @@ public ArrayList RayTrace(RICHParticle photon, Vector3D vlab, double na System.out.format(" --> Add last ray (%7.4f) : ", geocost.RICH_AIR_INDEX); newray.showRay(); } - + }else{ - + RICHRay newray = new RICHRay(last_ori, new_intersection.get_pos()); newray.set_refind(new_intersection.get_nin()); newray.set_type(lastray.get_type()); raytracks.add(newray); - + // new ray starting at intersection, to be rotated rayin = new RICHRay(new_intersection.get_pos(), newray.direction().multiply(200)); lastray = OpticalRotation(rayin, new_intersection); lastray.set_refind(new_intersection.get_nout()); - + if(debugMode>=1){ System.out.format(" --> Add new ray (%7.4f) : ",new_intersection.get_nin()); newray.showRay(); System.out.format(" --> Get rotated ray (%7.4f) : ",new_intersection.get_nout()); lastray.showRay(); } - + } jj++; - + } - + if(debugMode>=1) System.out.format(" --------------------------- \n"); //if(detected==true)return raytracks; return raytracks; //return null; - } - - - // ---------------- + } + + public void find_EtaC_raytrace_migrad(RICHParticle hadron, RICHParticle photon) { - // ---------------- - + int debugMode = 0; double n_a = geocost.RICH_AIR_INDEX; - + double Phi_ini = photon.trial_pho.lab_phi; double Theta_ini = photon.trial_pho.lab_theta; if(Phi_ini!=0 && Theta_ini!=0) { - + double Theta_P = hadron.lab_theta; double Phi_P = hadron.lab_phi; double start_EtaC=Math.sin(Theta_P)* Math.sin(Theta_ini)*Math.cos(Phi_ini-Phi_P)+Math.cos(Theta_P)*Math.cos(Theta_ini); @@ -444,7 +411,7 @@ public void find_EtaC_raytrace_migrad(RICHParticle hadron, RICHParticle photon) System.out.format(" Hadron phi %8.2f theta %8.2f \n ", Phi_P*RAD, Theta_P*RAD); System.out.format(" Photon initial phi %8.2f theta %8.2f EtaC %10.4f \n ", Phi_ini*RAD, Theta_ini*RAD, start_EtaC*MRAD); } - + // Minimizing function FCNBase myFunction = new FCNBase() { public double valueOf(double[] par) { @@ -452,21 +419,21 @@ public double valueOf(double[] par) { double theta = par[0]; double phi = par[1]; Vector3D vpho = new Vector3D( Math.sin(theta)*Math.cos(phi), Math.sin(theta)*Math.sin(phi), Math.cos(theta)); - ArrayList rays = RayTrace(photon, vpho); + ArrayList rays = RayTrace(photon, vpho); double Function = 999; Point3D pmt_hit = new Point3D(0.0, 0.0, 0.0); if(rays!=null){ pmt_hit = rays.get(rays.size()-1).end(); Function = pmt_hit.distance(photon.get_HitPos()); } - - if(debugMode>=0)System.out.format(" ==> %8.2f %8.2f | %s vs %s --> %10.4f \n", - theta*RAD, phi*RAD, pmt_hit.toStringBrief(2), - photon.get_HitPos().toStringBrief(2), Function); + + if(debugMode>=0)System.out.format(" ==> %8.2f %8.2f | %s vs %s --> %10.4f \n", + theta*RAD, phi*RAD, pmt_hit.toStringBrief(2), + photon.get_HitPos().toStringBrief(2), Function); return Function; } }; - + if(debugMode>=0)System.out.format(" Start minimization %8.2f %8.2f | %8.2f %8.2f \n",Theta_P*RAD, Phi_P*RAD, Theta_ini*RAD, Phi_ini*RAD); MnUserParameters myParameters = new MnUserParameters(); myParameters.add("Theta",Theta_ini, 0.01); @@ -474,64 +441,62 @@ public double valueOf(double[] par) { MnMigrad migrad = new MnMigrad(myFunction, myParameters); FunctionMinimum min = migrad.minimize(); if(debugMode>=0){ - System.out.format(" --> Minimum value %g found using %d calls: result is %8.2f %8.2f\n", - min.fval(), min.nfcn(), min.userParameters().value(0)*RAD, min.userParameters().value(1)*RAD); + System.out.format(" --> Minimum value %g found using %d calls: result is %8.2f %8.2f\n", + min.fval(), min.nfcn(), min.userParameters().value(0)*RAD, min.userParameters().value(1)*RAD); } double Theta_Min = min.userParameters().value(0); double Phi_Min = min.userParameters().value(1); - + int CLASpid = photon.get_CLASpid(); double n_tile = 1/(hadron.get_beta(CLASpid)*(Math.sin(Theta_P)* Math.sin(Theta_Min)*Math.cos(Phi_Min-Phi_P)+Math.cos(Theta_P)*Math.cos(Theta_Min))); double arg = Math.pow(n_a, 2)-Math.pow(n_tile, 2)*Math.pow(Math.sin(Theta_Min), 2); double Denominator = 1e-4; if(arg>0) Denominator = Math.sqrt(arg); - + double Cos_EtaC=Math.sin(Theta_P)* Math.sin(Theta_Min)*Math.cos(Phi_Min-Phi_P)+Math.cos(Theta_P)*Math.cos(Theta_Min); - + photon.traced.set_theta((float) Theta_Min); photon.traced.set_phi((float) Phi_Min); photon.traced.set_aeron((float) n_tile); photon.traced.set_EtaC((float) Math.acos(Cos_EtaC)); - + Vector3D vmin = new Vector3D( Math.sin(Theta_Min)*Math.cos(Phi_Min), Math.sin(Theta_Min)*Math.sin(Phi_Min), Math.cos(Theta_Min)); ArrayList raysmin = RayTrace(photon, vmin); if(raysmin!=null)photon.traced.set_raytracks(raysmin); - + if(debugMode>=1){ photon.traced.show_raytrack(); - System.out.format("#### ETAC ref %8.4f min %8.4f path %8.2f time %8.2f \n", photon.EtaC_ref*MRAD, - photon.traced.get_EtaC()*MRAD, photon.traced.get_raypath(), photon.traced.get_raytime()); + System.out.format("#### ETAC ref %8.4f min %8.4f path %8.2f time %8.2f \n", photon.EtaC_ref*MRAD, + photon.traced.get_EtaC()*MRAD, photon.traced.get_raypath(), photon.traced.get_raytime()); } - + }else{ if(debugMode>=0) System.out.format("Missing starting values from trial photon\n"); } - + } - - - // ---------------- + + public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, int hypo) { - // ---------------- - + int debugMode = 0; - + if(hypo<0 || hypo>=RICHConstants.N_HYPO ) return; double n_a = geocost.RICH_AIR_INDEX; int hypo_pid = RICHConstants.HYPO_LUND[hypo]; - + if(photon.trial_pho==null){ if(debugMode>=1) System.out.format(" Missing starting values from trial photon\n"); return; } - + double Theta_P = hadron.lab_theta; double Phi_P = hadron.lab_phi; if(debugMode>=1) { System.out.format(" Hadron phi %8.2f theta %8.2f \n", Phi_P*RAD, Theta_P*RAD); System.out.format(" Measured hit %s \n",photon.get_HitPos().toStringBrief(2)); } - + // taking starting point (from most closed throws) double phi_min = photon.trial_pho.lab_phi; double the_min = photon.trial_pho.lab_theta; @@ -539,38 +504,38 @@ public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, i double dthe_min = 0; Point3D pmt_min = photon.trial_pho.get_HitPos(); int nrefle_min = photon.trial_pho.traced.get_nrefle(); - ArrayList rays_min = new ArrayList(); + ArrayList rays_min = new ArrayList(); rays_min = photon.trial_pho.traced.get_raytracks(); - + Vector3D vec_dist = photon.get_HitPos().vectorFrom(pmt_min); // ATT: this takes the projection on the z plane. Equivalent but unnecessary. double dist = Math.sqrt(vec_dist.x()*vec_dist.x()+vec_dist.y()*vec_dist.y()); double Cos_EtaC = Math.sin(Theta_P)* Math.sin(the_min)*Math.cos(phi_min-Phi_P)+Math.cos(Theta_P)*Math.cos(the_min); double EtaCmin = 0.0; if(Math.abs(Cos_EtaC)<1.)EtaCmin = Math.acos(Cos_EtaC); - + int ntrials = 0; if(debugMode>=1)System.out.format("check %7.2f [%7.2f %7.2f %7.2f --> %7.2f] : %4d [%4d] \n ",dist, - photon.nominal_sChAngle(), RICHConstants.GAP_NOMINAL_SIZE, richpar.RAYTRACE_RESO_FRAC, - photon.nominal_sChAngle()*RICHConstants.GAP_NOMINAL_SIZE*richpar.RAYTRACE_RESO_FRAC,ntrials,richpar.RAYTRACE_MAX_NSTEPS); - while (dist > photon.nominal_sChAngle()*RICHConstants.GAP_NOMINAL_SIZE*richpar.RAYTRACE_RESO_FRAC && ntrials=1){ - System.out.format(" Attempt %d with the %7.1f (%7.2f) phi %7.2f EtaC %7.2f\n",ntrials, the_min*MRAD, the_min*RAD, phi_min*RAD, EtaCmin*MRAD); + photon.nominal_sChAngle(), RICHConstants.GAP_NOMINAL_SIZE, richpar.RAYTRACE_RESO_FRAC, + photon.nominal_sChAngle()*RICHConstants.GAP_NOMINAL_SIZE*richpar.RAYTRACE_RESO_FRAC,ntrials,richpar.RAYTRACE_MAX_NSTEPS); + while (dist > photon.nominal_sChAngle()*RICHConstants.GAP_NOMINAL_SIZE*richpar.RAYTRACE_RESO_FRAC && ntrials=1){ + System.out.format(" Attempt %d with the %7.1f (%7.2f) phi %7.2f EtaC %7.2f\n",ntrials, the_min*MRAD, the_min*RAD, phi_min*RAD, EtaCmin*MRAD); System.out.format(" --> (nrfl %2d) pos %s dist %7.4f (x %7.4f y %7.4f) \n", nrefle_min, pmt_min.toStringBrief(2), dist, vec_dist.x(), vec_dist.y()); } double dthe = 0.0; double dphi = 0.0; - + for (int nthe=1; nthe<=4; nthe++){ double theta_dthe = the_min + photon.nominal_sChAngle()/nthe; Vector3D vpho_dthe = new Vector3D( Math.sin(theta_dthe)*Math.cos(phi_min), Math.sin(theta_dthe)*Math.sin(phi_min), Math.cos(theta_dthe)); double naero = 1/(hadron.get_beta(hypo_pid)*(Math.sin(Theta_P)* Math.sin(theta_dthe)*Math.cos(phi_min-Phi_P)+Math.cos(Theta_P)*Math.cos(theta_dthe))); - + ArrayList rays_dthe = RayTrace(photon, vpho_dthe, naero); if(rays_dthe!=null && rays_dthe.get(rays_dthe.size()-1).is_detected()){ int nrefle_dthe = get_Nrefle(rays_dthe); - if(debugMode>=1) System.out.format(" test %2d the %7.1f nrfl %2d vs %2d ",nthe, theta_dthe*MRAD, nrefle_dthe, nrefle_min); + if(debugMode>=1) System.out.format(" test %2d the %7.1f nrfl %2d vs %2d ",nthe, theta_dthe*MRAD, nrefle_dthe, nrefle_min); if(nrefle_dthe==nrefle_min){ Point3D pmt_dthe = rays_dthe.get(rays_dthe.size()-1).end(); Vector3D vers_dthe = pmt_dthe.vectorFrom(pmt_min); @@ -579,7 +544,7 @@ public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, i // theta step for minimization dthe = (vec_dist.x()*vers_dthe.x() + vec_dist.y()*vers_dthe.y()) / (vers_dthe.x()*vers_dthe.x() + vers_dthe.y()*vers_dthe.y()) * photon.nominal_sChAngle(); if(debugMode>=1) { - System.out.format(" --> dthe pos %s delta %7.1f (%8.2f %8.2f) %7.2f \n", + System.out.format(" --> dthe pos %s delta %7.1f (%8.2f %8.2f) %7.2f \n", pmt_dthe.toStringBrief(2), dthe*MRAD, vers_dthe.x(), vers_dthe.y(),dthe_min); dump_raytrack("TTTT",rays_dthe); } @@ -589,16 +554,16 @@ public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, i } } } - + for (int nphi=1; nphi<=4; nphi++){ double phi_dphi = phi_min + photon.nominal_sChAngle()/nphi; Vector3D vpho_dphi = new Vector3D( Math.sin(the_min)*Math.cos(phi_dphi), Math.sin(the_min)*Math.sin(phi_dphi), Math.cos(the_min)); double naero = 1/(hadron.get_beta(hypo_pid)*(Math.sin(Theta_P)* Math.sin(the_min)*Math.cos(phi_dphi-Phi_P)+Math.cos(Theta_P)*Math.cos(the_min))); - + ArrayList rays_dphi = RayTrace(photon, vpho_dphi, naero); if(rays_dphi!=null && rays_dphi.get(rays_dphi.size()-1).is_detected()){ int nrefle_dphi = get_Nrefle(rays_dphi); - if(debugMode>=1) System.out.format(" test %2d phi %7.2f nrfl %2d vs %2d ",nphi, phi_dphi*RAD, nrefle_dphi, nrefle_min); + if(debugMode>=1) System.out.format(" test %2d phi %7.2f nrfl %2d vs %2d ",nphi, phi_dphi*RAD, nrefle_dphi, nrefle_min); if(nrefle_dphi==nrefle_min){ Point3D pmt_dphi = rays_dphi.get(rays_dphi.size()-1).end(); Vector3D vers_dphi = (pmt_dphi.vectorFrom(pmt_min)); @@ -607,7 +572,7 @@ public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, i // phi step for minimization dphi = (vec_dist.x()*vers_dphi.x() + vec_dist.y()*vers_dphi.y()) / (vers_dphi.x()*vers_dphi.x() + vers_dphi.y()*vers_dphi.y()) * photon.nominal_sChAngle(); if(debugMode>=1) { - System.out.format(" --> dphi pos %s delta %7.2f (%8.2f %8.2f) %7.2f \n", + System.out.format(" --> dphi pos %s delta %7.2f (%8.2f %8.2f) %7.2f \n", pmt_dphi.toStringBrief(2), dphi*RAD, vers_dphi.x(), vers_dphi.y(),dphi_min); dump_raytrack("TTTT",rays_dphi); } @@ -617,21 +582,21 @@ public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, i } } } - - if(dthe!=0 && dphi!=0){ + + if(dthe!=0 && dphi!=0){ int found = 0; for (int nn=1; nn<=4; nn++){ double the_new = the_min + dthe/nn; double phi_new = phi_min + dphi/nn; if(debugMode>=1) System.out.format(" do step nn %3d the %7.1f phi %7.2f (from %7.1f %7.2f) \n",nn,the_new*MRAD,phi_new*RAD,the_min*MRAD,phi_min*RAD); - + Vector3D vpho_min = new Vector3D( Math.sin(the_new)*Math.cos(phi_new), Math.sin(the_new)*Math.sin(phi_new), Math.cos(the_new)); double naero = 1/(hadron.get_beta(hypo_pid)*(Math.sin(Theta_P)* Math.sin(the_new)*Math.cos(phi_new-Phi_P)+Math.cos(Theta_P)*Math.cos(the_new))); - + rays_min = RayTrace(photon, vpho_min, naero); if(rays_min!=null && rays_min.get(rays_min.size()-1).is_detected()){ int nrefle_new = get_Nrefle(rays_min); - if(debugMode>=1) System.out.format(" test %2d the %7.1f phi %7.2f nrfl %2d vs %2d ",nn, the_new*MRAD, phi_new*RAD, nrefle_new, nrefle_min); + if(debugMode>=1) System.out.format(" test %2d the %7.1f phi %7.2f nrfl %2d vs %2d ",nn, the_new*MRAD, phi_new*RAD, nrefle_new, nrefle_min); if(nrefle_new==nrefle_min){ the_min = the_new; phi_min = phi_new; @@ -655,27 +620,27 @@ public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, i } } if(found==0){ - if(debugMode>=1) System.out.format(" No Raytrace solution; give up \n"); - return; + if(debugMode>=1) System.out.format(" No Raytrace solution; give up \n"); + return; } }else{ if(debugMode>=1) System.out.format(" No Raytrace solution; give up \n"); return; } - + ntrials++; } - + if(dist < photon.nominal_sChAngle()*RICHConstants.GAP_NOMINAL_SIZE){ - + if(debugMode>=1){ - System.out.format(" --> Matched value found using %d calls: result is %8.2f %8.2f matched hit %s dist %7.3f \n", - ntrials, the_min*MRAD, phi_min*RAD, pmt_min.toStringBrief(2), dist); + System.out.format(" --> Matched value found using %d calls: result is %8.2f %8.2f matched hit %s dist %7.3f \n", + ntrials, the_min*MRAD, phi_min*RAD, pmt_min.toStringBrief(2), dist); } - + int CLASpid = photon.get_CLASpid(); double n_tile = 1/(hadron.get_beta(hypo_pid)*(Math.sin(Theta_P)* Math.sin(the_min)*Math.cos(phi_min-Phi_P)+Math.cos(Theta_P)*Math.cos(the_min))); - + photon.traced.set_theta((float) the_min); photon.traced.set_phi((float) phi_min); photon.traced.set_dthe_res((float) dthe_min); @@ -685,32 +650,30 @@ public void find_EtaC_raytrace_steps(RICHParticle hadron, RICHParticle photon, i photon.traced.set_aeron((float) n_tile); photon.traced.set_EtaC((float) EtaCmin); photon.traced.set_raytracks(rays_min); - + if(debugMode>=1){ photon.traced.show_raytrack(); - System.out.format("#### ETAC %s TRA min %8.4f ttime %8.2f dthe (%7.2f, %7.2f) dphi (%7.2f, %7.2f) \n", - RICHConstants.HYPO_LUND[hypo], photon.traced.get_EtaC()*MRAD, photon.traced.get_time(), + System.out.format("#### ETAC %s TRA min %8.4f ttime %8.2f dthe (%7.2f, %7.2f) dphi (%7.2f, %7.2f) \n", + RICHConstants.HYPO_LUND[hypo], photon.traced.get_EtaC()*MRAD, photon.traced.get_time(), photon.traced.get_dthe_res(), photon.traced.get_dthe_bin(), photon.traced.get_dphi_res(), photon.traced.get_dphi_bin()); } } - + } - - - // ---------------- + + public double find_dthe_steps(RICHParticle photon) { - // ---------------- - + int debugMode = 0; - + double pho_phi = photon.traced.get_phi(); Point3D pho_hit = photon.traced.get_hit(); int pho_nrefle = photon.traced.get_Nrefle(); - + if(debugMode>=1)System.out.format("Find_dthe %7.2f %7.2f %s ", photon.traced.get_theta()*MRAD,photon.nominal_sChAngle()*MRAD,pho_hit.toStringBrief(2)); - + double dthe_res = RICHConstants.TRACE_NOMINAL_DTHE; for (int nthe=1; nthe<=4; nthe++){ double theta_dthe = photon.traced.get_theta() + photon.nominal_sChAngle()/nthe; @@ -718,9 +681,9 @@ public double find_dthe_steps(RICHParticle photon) { ArrayList rays_dthe = RayTrace(photon, vpho_dthe); if(rays_dthe!=null){ int nrefle_dthe = get_Nrefle(rays_dthe); - if(debugMode>=1) System.out.format(" --> test %2d the %7.1f nrfl %2d vs %2d ",nthe, - theta_dthe*MRAD, nrefle_dthe, pho_nrefle); - + if(debugMode>=1) System.out.format(" --> test %2d the %7.1f nrfl %2d vs %2d ",nthe, + theta_dthe*MRAD, nrefle_dthe, pho_nrefle); + if(nrefle_dthe==pho_nrefle){ Point3D pmt_dthe = rays_dthe.get(rays_dthe.size()-1).end(); dthe_res = pmt_dthe.distance(pho_hit)*nthe; @@ -731,25 +694,23 @@ public double find_dthe_steps(RICHParticle photon) { } } } - + return dthe_res; - + } - - - // ---------------- + + public double find_dphi_steps(RICHParticle photon) { - // ---------------- - + int debugMode = 0; - + double pho_the = photon.traced.get_theta(); Point3D pho_hit = photon.traced.get_hit(); int pho_nrefle = photon.traced.get_Nrefle(); - + if(debugMode>=1)System.out.format("Find_dphi %7.2f %7.2f %s ", photon.traced.get_phi()*MRAD,photon.nominal_sChAngle()*MRAD,pho_hit.toStringBrief(2)); - + double dphi_res = RICHConstants.TRACE_NOMINAL_DPHI; for (int nphi=1; nphi<=4; nphi++){ double phi_dphi = photon.traced.get_phi() + photon.nominal_sChAngle()/nphi; @@ -759,7 +720,7 @@ public double find_dphi_steps(RICHParticle photon) { int nrefle_dphi = get_Nrefle(rays_dphi); if(debugMode>=1) System.out.format(" --> test %2d phi %7.1f nrfl %2d vs %2d ",nphi, phi_dphi*MRAD, nrefle_dphi, pho_nrefle); - + if(nrefle_dphi==pho_nrefle){ Point3D pmt_dphi = rays_dphi.get(rays_dphi.size()-1).end(); dphi_res = pmt_dphi.distance(pho_hit)*nphi; @@ -770,31 +731,29 @@ public double find_dphi_steps(RICHParticle photon) { } } } - + return dphi_res; - + } - - - // ---------------- + + public void find_EtaC_analytic_migrad (RICHParticle hadron, RICHParticle photon) { - // ---------------- - + int debugMode = 0; double n_a = geocost.RICH_AIR_INDEX; - + // The following definition should be read by the geometry // ATT: mismatch con la definizione di emission a 3/4 dell'aerogel // ATT: L deve essere calcolato con il coseno double T_r = geocost.AERO_REF_THICKNESS*geocost.CM; double L = T_r/2.; // middle point is Thickness double T_g = hadron.ref_impact.z()-hadron.ref_emission.z()-L; - + Vector3D vec_b = photon.ref_impact.vectorFrom(hadron.ref_proj); double radius = vec_b.mag(); if(debugMode>=1)System.out.println(" T_g "+T_g+" T_r "+T_r+" L "+L+" R "+radius); if(radius >=-1 ) { - + // Starting values double Phi = photon.ref_phi; double Theta_ini = photon.ref_theta; @@ -805,8 +764,8 @@ public void find_EtaC_analytic_migrad (RICHParticle hadron, RICHParticle photon) System.out.format(" Hadron phi %8.2f initial Theta %8.2f \n ", Phi_P*RAD, Theta_P*RAD); System.out.format(" Photon radius %8.2f phi %8.2f Theta %8.2f EtaC %10.4f \n ", radius, Phi*RAD, Theta_ini*RAD, photon.EtaC_ref*MRAD); } - - // Minimizing function + + // Minimizing function int CLASpid = photon.get_CLASpid(); FCNBase myFunction = new FCNBase() { public double valueOf(double[] par) { @@ -817,14 +776,14 @@ public double valueOf(double[] par) { double arg = Math.pow(n_a, 2)-Math.pow(n_tile, 2)*Math.pow(Math.sin(Theta), 2); double Denominator = 1e-4; if(arg>0) Denominator = Math.sqrt(arg); - + double Fun = (T_r -L) * Math.tan(Theta)+T_g* (n_tile * Math.sin(Theta))/Denominator; double Function = Math.pow(radius - Fun, 2); if(debugMode>=1)System.out.format(" ==> %8.2f %8.2f | %8.2f %8.2f | %9.3f %10.4f \n",Theta_P*RAD, Phi_P*RAD, Theta*RAD, Phi*RAD, nn_tile, Function); return Function; } }; - + if(debugMode>=1)System.out.format(" Start minimization %8.2f %8.2f | %8.2f %8.2f \n",Theta_P*RAD, Phi_P*RAD, Theta_ini*RAD, Phi*RAD); MnUserParameters myParameters = new MnUserParameters(); myParameters.add("Theta",Theta_ini, 0.01); @@ -836,49 +795,43 @@ public double valueOf(double[] par) { double Theta_Min = min.userParameters().value(0); photon.analytic.set_theta((float) Theta_Min); photon.analytic.set_phi((float) Phi); - + double Cos_EtaC = Math.sin(Theta_P)* Math.sin(Theta_Min)*Math.cos(Phi-Phi_P)+Math.cos(Theta_P)*Math.cos(Theta_Min); - + double n_tile = 1/(hadron.get_beta(CLASpid)*Cos_EtaC); double arg = Math.pow(n_a, 2)-Math.pow(n_tile, 2)*Math.pow(Math.sin(Theta_Min), 2); double Denominator = 1e-4; if(arg>0) Denominator = Math.sqrt(arg); - + double migrad_path = ((T_r -L)/Math.cos(Theta_Min) + (T_g*n_a/Denominator) ); double migrad_time = ( ((T_r -L)/Math.cos(Theta_Min)/n_tile) + (T_g*n_a/Denominator) )/PhysicsConstants.speedOfLight(); - + photon.analytic.set_time((float) migrad_time); photon.analytic.set_path((float) migrad_path); photon.analytic.set_aeron((float) n_tile); photon.analytic.set_EtaC((float) Math.acos(Cos_EtaC) ); - + if(debugMode>=1){ System.out.format("#### ETAC ALY ref %8.4f min %8.4f path %8.2f time %8.2f \n", photon.EtaC_ref*MRAD, photon.analytic.get_EtaC()*MRAD, photon.analytic.get_path(), photon.analytic.get_time()); } - + } } - - // ---------------- + public Point3D find_IntersectionSpheMirror(int isec, Line3D ray){ - // ---------------- - + return richgeo.find_IntersectionSpheMirror(isec, ray); - + } - - // ---------------- + public Point3D find_IntersectionMAPMT(int isec, Line3D ray){ - // ---------------- - + return richgeo.find_IntersectionMAPMT(isec, ray); } - - - // ---------------- + + public int get_Nrefle(ArrayList rays) { - // ---------------- - + int nrfl=0; for (RICHRay ray : rays) { int refe = (int) ray.get_type()/10000; @@ -886,12 +839,10 @@ public int get_Nrefle(ArrayList rays) { } return nrfl; } - - - // ---------------- + + public void dump_raytrack(String head, ArrayList raytracks) { - // ---------------- - + int ii=0; for(RICHRay ray: raytracks){ if(head!=null){ @@ -902,14 +853,12 @@ public void dump_raytrack(String head, ArrayList raytracks) { ii++; } } - - - // ---------------- + + public int get_RefleLayers(ArrayList raytracks) { - // ---------------- - + int debugMode = 0; - + int relay = 0 ; if(raytracks.size()<=2) return relay; for(int i=2; i raytracks) { } } return relay; - + } - - // ---------------- + public int get_RefleCompos(ArrayList raytracks) { - // ---------------- - + int recompo = 0 ; if(raytracks.size()<=2) return recompo; for(int i=2; i raytracks) { recompo += off*icompo; } return recompo; - + } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHSolution.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHSolution.java index e756d82667..630779a008 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHSolution.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHSolution.java @@ -5,61 +5,49 @@ import java.util.Arrays; import org.jlab.detector.geom.RICH.RICHRay; -import org.jlab.detector.geom.RICH.RICHGeoConstants; import org.jlab.geom.prim.Point3D; -// ---------------- public class RICHSolution { -// ---------------- - + private int debugMode = 0; - private static double MRAD = RICHGeoConstants.MRAD; - - - // ---------------- - public RICHSolution(){ - // ---------------- - } - - // ---------------- + + public RICHSolution(){} + public RICHSolution(int type) { - // ---------------- - this.type = type; this.raytracks.clear(); - - } - + } + private int type; // Solution type private int OK = -1; // Solution exists and has been selected as good for the given hypothesis private int hypo = 0; // Particle ID hypothesis (LUND) private int status = 0; // Flag solutions with a bad-status mirror - + private double EtaC = 0.0; // Cherenkov angle private double aeron = 0.0; // Aerogel refrative index - private double theta = 0.0; // Laboratory theta - private double phi = 0.0; // Laboratory phi + private double theta = 0.0; // Laboratory theta + private double phi = 0.0; // Laboratory phi private double dthe_res = 0.0; // Shift over MAPMT surface corresponding to 1 nominal sigma in theta private double dphi_res = 0.0; // Shift over MAPMT surface corresponding to 1 nominal sigma in phi private double dthe_bin = 0.0; // Rescaled factor to the likelihood theta bin private double dphi_bin = 0.0; // Rescaled factor to the likelihood phi bin private double scale = 0.0; // Laboratory scale private double path = 0.0; // Path within the RICH - private int nrefle = 0; // Number of photon reflections + private int nrefle = 0; // Number of photon reflections private int nrefra = 0; // Number of photon refractions private double time = 0.0; // Transit time within the RICH (solution dependent) private double machi2 = 0.0; // chi2 of the hit vs trajectory extrapolation (distance/resolution) private Point3D hit = new Point3D(0,0,0); // Impact point of photon on the PMT - - private ArrayList raytracks = new ArrayList(); // Detailed path of the photon - + + private ArrayList raytracks = new ArrayList<>(); // Detailed path of the photon + private double elprob = 0.0; // Cherenkov probability for electron private double piprob = 0.0; // Cherenkov probability for pion private double kprob = 0.0; // Cherenkov probability for kaon private double prprob = 0.0; // Cherenkov probability for proton private double bgprob = 0.0; // Cherenkov probability for background - + private int ndir = 0; // Number of direct photons private double chdir = 0.0; // Mean Cherenkov angle for direct photons private double sdir = 0.0; // RMS Cherenkov angle for direct photons @@ -72,11 +60,11 @@ public RICHSolution(int type) { private double chspe = 0.0; // Mean Cherenkov angle for photons reflected by ssperical mirrors private double sspe = 0.0; // RMS Cherenkov angle for photons reflected by ssperical mirrors private double maspe = 0.0; // Mean equivalent mass for photons reflected by ssperical mirrors - private int ntot = 0; // Number of all photons - private double chtot = 0.0; // Mean Cherenkov angle for all photons - private double stot = 0.0; // RMS Cherenkov angle for all photons - private double matot = 0.0; // Mean equivalent mass for all photons - + private int ntot = 0; // Number of all photons + private double chtot = 0.0; // Mean Cherenkov angle for all photons + private double stot = 0.0; // RMS Cherenkov angle for all photons + private double matot = 0.0; // Mean equivalent mass for all photons + private double bestprob = 0.0; // best Cherenkov probability for hadron ID private double secprob = 0.0; // second best Cherenkov probability for hadron ID private int bestH = 0; // best Cherenkov probability for hadron ID @@ -87,29 +75,19 @@ public RICHSolution(int type) { private double bestRL = 0.0; // Likelihood ratio for best PID assignment private double bestc2 = 0.0; // Chi2 for best PID assignment private double bestNp = 0.0; // Number of photons used for best PID assignment - private double bestMass = 0.0; // Measured mass for best PID assignment - - - // ---------------- + private double bestMass = 0.0; // Measured mass for best PID assignment + + public int get_type() { return type; } - // ---------------- - - // ---------------- + public int get_OK() { return OK; } - // ---------------- - - // ---------------- + // good for the current hypo (111) or other (+1000) - public boolean is_used() { if(OK>110)return true; return false;} - // ---------------- - - // ---------------- - public boolean is_OK() { if(OK==111)return true; return false;} - // ---------------- - - // ---------------- - public int get_hypo(int charge) { - // ---------------- + public boolean is_used() { return OK>110;} + + public boolean is_OK() { return OK==111;} + + public int get_hypo(int charge) { int hypo_ch = hypo; if(hypo_ch==11){ if(charge==1)hypo_ch*=-1; @@ -118,63 +96,35 @@ public int get_hypo(int charge) { } return hypo_ch; } - - // ---------------- + public int get_hypo() { return hypo; } - // ---------------- - - // ---------------- + public double get_EtaC() { return EtaC; } - // ---------------- - - // ---------------- + public double get_aeron() { return aeron; } - // ---------------- - - // ---------------- + public double get_theta() { return theta; } - // ---------------- - - // ---------------- + public double get_phi() { return phi; } - // ---------------- - - // ---------------- + public double get_dthe_res() { return dthe_res; } - // ---------------- - - // ---------------- + public double get_dphi_res() { return dphi_res; } - // ---------------- - - // ---------------- + public double get_dthe_bin() { return dthe_bin; } - // ---------------- - - // ---------------- + public double get_dphi_bin() { return dphi_bin; } - // ---------------- - - // ---------------- + public double get_scale() { return scale; } - // ---------------- - - // ---------------- + public double get_path() { return path; } - // ---------------- - - // ---------------- + public double get_time() { return time; } - // ---------------- - - // ---------------- + public double get_machi2() { return machi2; } - // ---------------- - - // ---------------- + public double get_raypath() { - // ---------------- - + double rpath = 0.0; for (RICHRay ray : raytracks) { rpath = rpath + ray.direction().mag(); @@ -182,13 +132,10 @@ public double get_raypath() { } return (double) rpath; } - - // ---------------- + public double get_raytime() { - // ---------------- - + double time = 0; - int ii=0; for (RICHRay ray : raytracks) { double dtime = ray.direction().mag()/PhysicsConstants.speedOfLight()*ray.get_refind(); time = time + (double) dtime; @@ -196,15 +143,13 @@ public double get_raytime() { } return time; } - - - // ---------------- + + public int get_RefleLayers() { - // ---------------- - // return a coded flag with the layer sequence alongt the photon path - + // return a coded flag with the layer sequence alongt the photon path + int debugMode = 0; - + int relay = 0 ; if(raytracks.size()<=2) return relay; for(int i=2; i0)System.out.format("No raytrace solution \n"); return false; @@ -292,21 +230,17 @@ public boolean exist(){ } return true; } - - - // ---------------- + + public int status(){ return status; } - // ---------------- - // ---------------- public void set_status(int isec, int lai, int ico, int iqua, RICHCalibration richcal) { - // ---------------- - // record if there is a bad-status mirror on the photon path - + // record if there is a bad-status mirror on the photon path + int debugMode = 0; - + if(!exist()) return; - if(richcal.get_AeroStatus(isec, lai, ico, iqua)>0){status=1; return;} + if(richcal.get_AeroStatus(isec, lai, ico, iqua)>0){status=1; return;} if(raytracks.size()>2){ for(int i=2; i2) return raytracks.get(2).get_type(); return 0; - + } - - // ---------------- + public int get_RefleType() { - // ---------------- - + int ifirst = get_FirstRefle(); int ilay = (int) (ifirst-10000)/100; if(ifirst<10000){ @@ -350,15 +280,13 @@ public int get_RefleType() { return 1; } } - + } - - // ---------------- + public int get_Nrefle() { - // ---------------- - + int debugMode = 0; - + if(debugMode==1)System.out.format("RICHSolution::get_Nrefle \n"); int nrfl=0; int ira=0; @@ -370,11 +298,9 @@ public int get_Nrefle() { } return nrfl; } - - // ---------------- + public int get_Nrefra() { - // ---------------- - + int nrfr=0; for (RICHRay ray : raytracks) { int refa = (int) ray.get_type()/10000; @@ -382,118 +308,62 @@ public int get_Nrefra() { } return nrfr; } - - // ---------------- + public int get_nrefle() { return nrefle; } - // ---------------- - - // ---------------- + public int get_nrefra() { return nrefra; } - // ---------------- - - // ------------- + public int get_nrays() { return raytracks.size(); } - // ------------- - - // ---------------- + public RICHRay get_ray(int i){ return this.raytracks.get(i); } - // ---------------- - - // ------------- + public RICHRay get_lastray() { return raytracks.get(raytracks.size()-1); } - // ------------- - - // ---------------- + public Point3D get_hit() { return hit; } - // ---------------- - - // ---------------- + public double get_ElProb() { return elprob; } - // ---------------- - - // ---------------- + public double get_PiProb() { return piprob; } - // ---------------- - - // ---------------- + public double get_KProb() { return kprob; } - // ---------------- - - // ---------------- + public double get_PrProb() { return prprob; } - // ---------------- - - // ---------------- + public double get_BgProb() { return bgprob; } - // ---------------- - - // ---------------- + public int get_Ndir() { return ndir; } - // ---------------- - - // ---------------- + public double get_Chdir() { return chdir; } - // ---------------- - - // ---------------- + public double get_RMSdir() { return sdir; } - // ---------------- - - // ---------------- + public double get_Madir() { return madir; } - // ---------------- - - // ---------------- + public int get_Nlat() { return nlat; } - // ---------------- - - // ---------------- + public double get_Chlat() { return chlat; } - // ---------------- - - // ---------------- + public double get_RMSlat() { return slat; } - // ---------------- - - // ---------------- + public double get_Malat() { return malat; } - // ---------------- - - // ---------------- + public int get_Nspe() { return nspe; } - // ---------------- - - // ---------------- + public double get_Chspe() { return chspe; } - // ---------------- - - // ---------------- + public double get_RMSspe() { return sspe; } - // ---------------- - - // ---------------- + public double get_Maspe() { return maspe; } - // ---------------- - - // ---------------- + public int get_Ntot() { return ntot; } - // ---------------- - - // ---------------- + public double get_Chtot() { return chtot; } - // ---------------- - - // ---------------- + public double get_RMStot() { return stot; } - // ---------------- - - // ---------------- + public double get_Matot() { return matot; } - // ---------------- - - // ---------------- - public int get_BestH(int charge) { - // ---------------- + + public int get_BestH(int charge) { int hypo_pid_ch = bestH; if(hypo_pid_ch==11){ if(charge==1)hypo_pid_ch*=-1; @@ -502,67 +372,41 @@ public int get_BestH(int charge) { } return hypo_pid_ch; } - - // ---------------- + public int get_BestH() { return bestH; } - // ---------------- - - // ---------------- + public void set_BestH(int bestH) { this.bestH = bestH;} - // ---------------- - - // ---------------- + public double get_BestCH() { return bestch; } - // ---------------- - - // ---------------- + public double get_BestRL() { return bestRL; } - // ---------------- - - // ---------------- + public double get_BestC2() { return bestc2; } - // ---------------- - - // ---------------- + public double get_BestNpho() { return bestNp; } - // ---------------- - - // ---------------- + public double get_BestMass() { return bestMass; } - // ---------------- - - // ---------------- + public int get_secH() { return secH; } - // ---------------- - - // ---------------- + public double get_Bestprob() { return bestprob; } - // ---------------- - - // ---------------- + public double get_secprob() { return secprob; } - // ---------------- - - // ---------------- + public double get_RQP() { return R_QP; } - // ---------------- - - // ---------------- + public double get_ReQP() { return Re_QP; } - // ---------------- - - // ---------------- + public double assign_LHCbPID(double lh[]) { - // ---------------- - + int debugMode = 0; - + set_ElProb(lh[0]); set_PiProb(lh[1]); set_KProb(lh[2]); set_PrProb(lh[3]); if(debugMode==1)System.out.format(" assign (LHCB) %10.4g [%10.4g %10.4g %10.4g] --> ",lh[0],lh[1],lh[2],lh[3]); - + int ibest=-1; double lhtest=0.0; for(int i=1; i<4; i++){ @@ -571,12 +415,12 @@ public double assign_LHCbPID(double lh[]) { ibest=i; } } - + int isec=-1; if(ibest>=0){ bestprob = lh[ibest]; bestH = RICHConstants.HYPO_LUND[ibest]; - + double test = 0.0; for(int i=1; i<4; i++){ if(i!=ibest && lh[i]>test){ @@ -592,7 +436,7 @@ public double assign_LHCbPID(double lh[]) { R_QP = 1.0; } } - + if(elprob>0){ if(piprob>0){ //ATT: pass2 works with only hadrons PID to not geenrate confusion. @@ -608,25 +452,23 @@ public double assign_LHCbPID(double lh[]) { bestH=RICHConstants.HYPO_LUND[0]; } } - + if(debugMode==1)System.out.format(" --> %5d (%10.4g) %5d (%10.4g) %8.4f %8.4f \n",bestH,bestprob,secH,secprob,R_QP,Re_QP); - + return R_QP; } - - - // ---------------- + + public double assign_HypoPID(double lh[]) { - // ---------------- - + int debugMode = 0; - + set_ElProb(lh[0]); set_PiProb(lh[1]); set_KProb(lh[2]); set_PrProb(lh[3]); if(debugMode==1)System.out.format(" assign (PASS2) %10.4g [%10.4g %10.4g %10.4g] --> ",lh[0],lh[1],lh[2],lh[3]); - + int ibest=-1; double lhtest=999.0; for(int i=1; i<4; i++){ @@ -635,12 +477,12 @@ public double assign_HypoPID(double lh[]) { ibest=i; } } - + int isec=-1; if(ibest>=0){ bestprob = lh[ibest]; bestH = RICHConstants.HYPO_LUND[ibest]; - + double test = 999.0; for(int i=1; i<4; i++){ if(i!=ibest && lh[i]>0 && lh[i]0){ if(piprob>0){ //ATT: pass2 works with only hadrons PID to not geenrate confusion. @@ -672,40 +514,38 @@ public double assign_HypoPID(double lh[]) { bestH=RICHConstants.HYPO_LUND[0]; } } - + if(debugMode==1)System.out.format(" --> %5d (%10.4g) %5d (%10.4g) %8.4f %8.4f \n",bestH,bestprob,secH,secprob,R_QP,Re_QP); - + return R_QP; } - - - // ---------------- + + public double assign_PID(double lh[]) { - // ---------------- - + int debugMode = 0; - + set_ElProb(lh[0]); set_PiProb(lh[1]); set_KProb(lh[2]); set_PrProb(lh[3]); if(debugMode==1)System.out.format(" assign (PASS1) %10.4g [%10.4g %10.4g %10.4g] --> ",lh[0],lh[1],lh[2],lh[3]); - + double likeh[] = {lh[1], lh[2], lh[3]}; Arrays.sort(likeh); bestprob = likeh[2]; secprob = likeh[1]; - + if(bestprob>0){ double likehr[] = {lh[1], lh[2], lh[3]}; for (int i=0; i<3; i++){ int hypo_pid = RICHConstants.HYPO_LUND[i+1]; if(Math.abs(bestprob-likehr[i])<1e-6) bestH=hypo_pid; - if(Math.abs(secprob-likehr[i])<1e-6) secH=hypo_pid; + if(Math.abs(secprob-likehr[i])<1e-6) secH=hypo_pid; } R_QP = 1-secprob/bestprob; } - + if(elprob>0){ if(piprob>0){ //ATT: pass2 works with only hadrons PID to not geenrate confusion. @@ -718,93 +558,53 @@ public double assign_PID(double lh[]) { } } if(debugMode==1)System.out.format(" --> %5d (%10.4g) %5d (%10.4g) %8.4f %8.4f \n",bestH,bestprob,secH,secprob,R_QP,Re_QP); - + return R_QP; } - - - // ---------------- + + public void set_type(int type) { this.type = type; } - // ---------------- - - // ---------------- + public void set_OK(int ok) { this.OK = ok; } - // ---------------- - - // ---------------- + public void set_hypo(int hypo) { this.hypo = hypo; } - // ---------------- - - // ---------------- + public void set_EtaC(double EtaC) { this.EtaC = EtaC; } - // ---------------- - - // ---------------- + public void set_aeron(double aeron) { this.aeron = aeron; } - // ---------------- - - // ---------------- + public void set_theta(double theta) { this.theta = theta; } - // ---------------- - - // ---------------- + public void set_phi(double phi) { this.phi = phi; } - // ---------------- - - // ---------------- + public void set_dthe_res(double dthe_res) { this.dthe_res = dthe_res; } - // ---------------- - - // ---------------- + public void set_dthe_bin(double dthe_bin) { this.dthe_bin = dthe_bin; } - // ---------------- - - // ---------------- + public void set_dphi_res(double dphi_res) { this.dphi_res = dphi_res; } - // ---------------- - - // ---------------- + public void set_dphi_bin(double dphi_bin) { this.dphi_bin = dphi_bin; } - // ---------------- - - // ---------------- + public void set_scale(double scale) { this.scale = scale; } - // ---------------- - - // ---------------- + public void set_path(double path) { this.path = path; } - // ---------------- - - // ---------------- + public void set_time(double time) { this.time = time; } - // ---------------- - - // ---------------- + public void set_machi2(double machi2) { this.machi2 = machi2; } - // ---------------- - - // ---------------- + public void set_nrefle(int nrefle) { this.nrefle = nrefle; } - // ---------------- - - // ---------------- + public void set_nrefra(int nrefra) { this.nrefra = nrefra; } - // ---------------- - - // ---------------- + public void add_ray(RICHRay ray) {this.raytracks.add(ray);} - // ---------------- - - // ---------------- + public ArrayList get_raytracks() {return this.raytracks;} - // ---------------- - - // ---------------- + public void set_raytracks(ArrayList rays){ - // ---------------- - + int debugMode = 0; - + //ATT: Vedere se puo' succedere if(rays==null){if(debugMode>=1)System.out.format("No RAYTRACE solution\n"); return;} for (RICHRay ray: rays){ @@ -816,141 +616,79 @@ public void set_raytracks(ArrayList rays){ this.nrefle = this.get_Nrefle(); this.nrefra = this.get_Nrefra(); } - - // ---------------- + public void set_hit(Point3D hit) { this.hit = hit; } - // ---------------- - - // ---------------- + public void set_ElProb(double elprob) { this.elprob = elprob; } - // ---------------- - - // ---------------- + public void set_PiProb(double piprob) { this.piprob = piprob; } - // ---------------- - - // ---------------- + public void set_KProb(double kprob) { this.kprob = kprob; } - // ---------------- - - // ---------------- + public void set_PrProb(double prprob) { this.prprob = prprob; } - // ---------------- - - // ---------------- + public void set_BgProb(double bgprob) { this.bgprob = bgprob; } - // ---------------- - - // ---------------- + public void set_Ndir(int ndir) { this.ndir = ndir; } - // ---------------- - - // ---------------- + public void set_Chdir(double chdir) { this.chdir = chdir; } - // ---------------- - - // ---------------- + public void set_RMSdir(double sdir) { this.sdir = sdir; } - // ---------------- - - // ---------------- + public void set_Madir(double madir) { this.madir = madir; } - // ---------------- - - // ---------------- + public void set_Nlat(int nlat) { this.nlat= nlat; } - // ---------------- - - // ---------------- + public void set_Chlat(double chlat) { this.chlat= chlat; } - // ---------------- - - // ---------------- + public void set_RMSlat(double slat) { this.slat= slat; } - // ---------------- - - // ---------------- + public void set_Malat(double malat) { this.malat = malat; } - // ---------------- - - // ---------------- + public void set_Nspe(int nspe) { this.nspe= nspe; } - // ---------------- - - // ---------------- + public void set_Chspe(double chspe) { this.chspe= chspe; } - // ---------------- - - // ---------------- + public void set_RMSspe(double sspe) { this.sspe= sspe; } - // ---------------- - - // ---------------- + public void set_Maspe(double maspe) { this.maspe = maspe; } - // ---------------- - - // ---------------- + public void set_Ntot(int ntot) { this.ntot= ntot; } - // ---------------- - - // ---------------- + public void set_Chtot(double chtot) { this.chtot= chtot; } - // ---------------- - - // ---------------- + public void set_RMStot(double stot) { this.stot= stot; } - // ---------------- - - // ---------------- + public void set_Matot(double matot) { this.matot = matot; } - // ---------------- - - // ---------------- + public void set_BestCH(double bestch) { this.bestch = bestch; } - // ---------------- - - // ---------------- + public void set_BestRL(double bestRL) { this.bestRL = bestRL; } - // ---------------- - - // ---------------- + public void set_BestC2(double bestc2) { this.bestc2 = bestc2; } - // ---------------- - - // ---------------- + public void set_BestNpho(double bestNp) { this.bestNp = bestNp; } - // ---------------- - - // ---------------- + public void set_BestMass(double bestMass) { this.bestMass = bestMass; } - // ---------------- - - // ---------------- + public double get_dthe_pixel(){ if(dthe_res>0) return RICHConstants.PIXEL_NOMINAL_SIZE/dthe_res; return 1.0;} - // ---------------- - - // ---------------- + public double get_dphi_pixel(){ if(dphi_res>0) return RICHConstants.PIXEL_NOMINAL_SIZE/dphi_res; return 1.0;} - // ---------------- - - // ---------------- + public double get_EqPixelNumber(){ - // ---------------- - + int debugMode = 0; double dthe_delta = dthe_res*dthe_bin; double dphi_delta = dphi_res*dphi_bin; double solid = dthe_delta/RICHConstants.PIXEL_NOMINAL_SIZE*dphi_delta/RICHConstants.PIXEL_NOMINAL_SIZE; - + if(debugMode>=1)System.out.format(" Eq Pixel %7.2f %7.2f (%7.2f) --> %8.4f \n",dthe_delta,dphi_delta,RICHConstants.PIXEL_NOMINAL_SIZE,solid); return solid; } - - // ---------------- + public void show_raytrack() { - // ---------------- - + int ii=0; for(RICHRay ray: raytracks){ System.out.format(" %d",ii); @@ -958,12 +696,10 @@ public void show_raytrack() { ii++; } } - - - // ---------------- + + public void dump_raytrack(String head) { - // ---------------- - + int ii=0; for(RICHRay ray: raytracks){ if(head!=null){ @@ -975,13 +711,11 @@ public void dump_raytrack(String head) { } } - - // ---------------- + public void showSolution() { - // ---------------- System.out.format("SOL type %3d EtaC %8.3f n %6.4f the %7.3f phi %7.3f hit %s path %6.1f time %6.2f nrfl %2d nfr %2d pel %7.5f pi %7.5g k %7.5g pr %7.5g bg %7.5g \n", - get_type(), get_EtaC(), get_aeron(), get_theta(), get_phi(), get_hit().toStringBrief(2), get_path(), get_time(), get_nrefle(), get_nrefra(), - get_ElProb(), get_PiProb(), get_KProb(), get_PrProb(), get_BgProb()); + get_type(), get_EtaC(), get_aeron(), get_theta(), get_phi(), get_hit().toStringBrief(2), get_path(), get_time(), get_nrefle(), get_nrefra(), + get_ElProb(), get_PiProb(), get_KProb(), get_PrProb(), get_BgProb()); } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHTime.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHTime.java index e90fac881e..9da4c50b26 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHTime.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHTime.java @@ -4,70 +4,57 @@ * @author mcontalb */ public class RICHTime{ - + private final static int NTIME = 10; private long RICH_START_TIME = (long) 0; private double richprocess_time[] = new double[NTIME]; private int richprocess_ntimes[] = new int[NTIME]; - - private double SHOW_PROGRESS_INTERVAL = 1.e9; // as default, do not print anything - - - - //------------------------------ + // as default, do not print anything + public RICHTime() { - //------------------------------ } - - - // ---------------- + + public void init_ProcessTime(){ - // ---------------- - + int debugMode = 0; - + for(int i=0; i-1 && iphase-1){ // time = (richprocess_time[i]/richprocess_ntimes[i]-richprocess_time[found]/richprocess_ntimes[found]); //}else{ - time = richprocess_time[i]/richprocess_ntimes[i]; + time = richprocess_time[i]/richprocess_ntimes[i]; //} tot += time; System.out.format(" PHASE %3d: %s %12.4f average over %6d time %10.4f ms \n", i, str[i], richprocess_time[i], richprocess_ntimes[i], time); @@ -87,15 +74,15 @@ public void dump_ProcessTime(){ } double zero = 0.0 ; System.out.format(" TOTAL : %s %12.4f average over %6d time %10.4f ms \n", seve, zero, richprocess_ntimes[0], tot); - + /*for(int i=NTIME-1; i>-1; i--){ - double time = 0.0; - if(richprocess_ntimes[i]>0){ - time = richprocess_time[i]/richprocess_ntimes[i]; - System.out.format(" PHASE %3d: TOTAL average over %6d time %10.4f ms \n", NTIME, richprocess_ntimes[i], time); - break; - } + double time = 0.0; + if(richprocess_ntimes[i]>0){ + time = richprocess_time[i]/richprocess_ntimes[i]; + System.out.format(" PHASE %3d: TOTAL average over %6d time %10.4f ms \n", NTIME, richprocess_ntimes[i], time); + break; + } }*/ } - + } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHUtil.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHUtil.java index 55587f169b..9f8b69d62a 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHUtil.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHUtil.java @@ -3,27 +3,18 @@ import eu.mihosoft.vrl.v3d.Vector3d; import eu.mihosoft.vrl.v3d.Vertex; import org.jlab.geometry.prim.Line3d; - import org.jlab.geom.prim.Vector3D; import org.jlab.geom.prim.Line3D; import org.jlab.geom.prim.Point3D; - /** * @author mcontalb */ public class RICHUtil{ + public RICHUtil() {} - //------------------------------ - public RICHUtil() { - //------------------------------ - } - - - //------------------------------ public String toString(Vector3d vec, int qua) { - //------------------------------ if(qua==2)return String.format("%8.2f %8.2f %8.2f", vec.x, vec.y, vec.z); if(qua==3)return String.format("%8.3f %8.3f %8.3f", vec.x, vec.y, vec.z); if(qua==4)return String.format("%8.4f %8.4f %8.4f", vec.x, vec.y, vec.z); @@ -32,100 +23,74 @@ public String toString(Vector3d vec, int qua) { } - //------------------------------ public String toString(Vector3d vec) { - //------------------------------ return String.format("%8.3f %8.3f %8.3f", vec.x, vec.y, vec.z); } - //------------------------------ public String toString(Vector3D vec) { - //------------------------------ return String.format("%8.3f %8.3f %8.3f", vec.x(), vec.y(), vec.z()); } - //------------------------------ public String toString(Point3D vec) { - //------------------------------ return String.format("%7.2f %7.2f %7.2f", vec.x(), vec.y(), vec.z()); } - //------------------------------ public Vector3D toVector3D(Vector3d vin) { - //------------------------------ Vector3D vout = new Vector3D(vin.x, vin.y, vin.z); return vout; } - //------------------------------ public Vector3D toVector3D(Point3D pin) { - //------------------------------ Vector3D vout = new Vector3D(pin.x(), pin.y(), pin.z()); return vout; } - //------------------------------ public Vector3d toVector3d(Vertex ver) {return new Vector3d(ver.pos.x, ver.pos.y, ver.pos.z); } - //------------------------------ - //------------------------------ public Vector3d toVector3d(Vector3D vin) { - //------------------------------ Vector3d vout = new Vector3d(vin.x(), vin.y(), vin.z()); return vout; } - //------------------------------ public Vector3d toVector3d(Point3D pin) { - //------------------------------ Vector3d vout = new Vector3d(pin.x(), pin.y(), pin.z()); return vout; } - //------------------------------ public Point3D toPoint3D(Vertex vin) { - //------------------------------ Point3D pout = new Point3D(vin.pos.x, vin.pos.y, vin.pos.z); return pout; } - //------------------------------ public Point3D toPoint3D(Vector3D vin) { - //------------------------------ Point3D pout = new Point3D(vin.x(), vin.y(), vin.z()); return pout; } - //------------------------------ public Point3D toPoint3D(Vector3d vin) { - //------------------------------ if(vin==null) return null; Point3D pout = new Point3D(vin.x, vin.y, vin.z); return pout; } - //------------------------------ public Line3d toLine3d(Line3D lin) { - //------------------------------ Line3d lout = new Line3d(toVector3d(lin.origin()), toVector3d(lin.end())); return lout; } - //------------------------------ public Line3D toLine3D(Line3d lin) { - //------------------------------ Line3D lout = new Line3D(toPoint3D(lin.origin()), toPoint3D(lin.end())); return lout; } diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHio.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHio.java index 8a78e00e7e..ab65def3ac 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHio.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHio.java @@ -1,36 +1,22 @@ package org.jlab.rec.rich; import java.util.List; -import java.util.ArrayList; -import java.util.Collections; - import org.jlab.io.base.DataBank; import org.jlab.io.base.DataEvent; import org.jlab.clas.detector.DetectorResponse; - import org.jlab.detector.geom.RICH.RICHGeoConstants; public class RICHio { - - /* - * RICH i/o - */ + private static double MRAD = RICHGeoConstants.MRAD; - private static double RAD = RICHGeoConstants.RAD; - - // constructor - // ---------------- - public RICHio() { - // ---------------- - - } - - // ---------------- + private static double RAD = RICHGeoConstants.RAD; + + public RICHio() {} + public void clear_LowBanks(DataEvent event) { - // ---------------- - + int debugMode = 0; - + // remove previous version of low-level banks from the event if(event.hasBank("RICH::hits")){ event.removeBank("RICH::hits"); @@ -53,12 +39,10 @@ public void clear_LowBanks(DataEvent event) { if(debugMode==1)System.out.format("Remove RICH::Signal from event \n"); } } - - - // ---------------- + + public void clear_HighBanks(DataEvent event) { - // ---------------- - + int debugMode = 0; // remove previous version of high-level banks from the event @@ -82,7 +66,7 @@ public void clear_HighBanks(DataEvent event) { event.removeBank("RICH::hadCher"); if(debugMode==1)System.out.format("Remove RICH::hadCher from event \n"); } - + if(event.hasBank("RICH::Response")){ event.removeBank("RICH::Response"); if(debugMode==1)System.out.format("Remove RICH::Response from event \n"); @@ -104,69 +88,61 @@ public void clear_HighBanks(DataEvent event) { if(debugMode==1)System.out.format("Remove RICH::Particle from event \n"); } } - - - // ---------------- + + public void write_PMTBanks(DataEvent event, RICHEvent richevent) { - // ---------------- - + if(richevent.get_nHit()>0)write_HitBank(event, richevent); - + if(richevent.get_nClu()>0)write_ClusterBank(event, richevent); - + //ATT: pass2 //if(richevent.get_nHit()>0 || richevent.get_nClu()>0) - // write_SignalBank(event, richevent); - + // write_SignalBank(event, richevent); + } - - - // ---------------- + + public void write_RECBank(DataEvent event, RICHEvent richevent, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + int NMAT = richevent.get_nMatch(); if(debugMode>=1)System.out.format("Creating Bank for %5d Matches \n", NMAT); - + if(NMAT>0){ - + String richBank = "RICH::Response"; DataBank bankRich = get_ResponseBank(richevent.get_Matches(), event, richBank, richpar); if(bankRich!=null)event.appendBanks(bankRich); - + } - + } - - - // ---------------- + + public void write_CherenkovBanks(DataEvent event, RICHEvent richevent, RICHParameters richpar) { - // ---------------- - + //ATT: Pass2 if(richevent.get_nHad()>0)write_HadronBank(event, richevent); - + if(richevent.get_nPho()>0)write_PhotonBank(event, richevent, richpar); - + if(richevent.get_nPho()>0)write_RingBank(event, richevent, richpar); - + if(richevent.get_nHad()>0)write_ParticleBank(event, richevent, richpar); - + } - - - // ---------------- + + private void write_HitBank(DataEvent event, RICHEvent richevent) { - // ---------------- - + int debugMode = 0; - + int NHIT = richevent.get_nHit(); if(debugMode>=1)System.out.format("Creating Bank for %5d Hits \n", NHIT); - + if(NHIT>0) { if(debugMode>=2)System.out.println(" --> Creating the RICH::Hit Bank "); DataBank bankHits = event.createBank("RICH::Hit", NHIT); @@ -174,11 +150,11 @@ private void write_HitBank(DataEvent event, RICHEvent richevent) { System.out.println("ERROR CREATING BANK : RICH::Hit"); return; } - + for(int i = 0; i < NHIT; i++){ - + RICHHit hit = richevent.get_Hit(i); - + bankHits.setShort("id", i, (short) hit.get_id()); bankHits.setShort("sector", i, (short) hit.get_sector()); bankHits.setShort("tile", i, (short) hit.get_tile()); @@ -193,23 +169,21 @@ private void write_HitBank(DataEvent event, RICHEvent richevent) { bankHits.setShort("xtalk", i, (short) hit.get_xtalk()); bankHits.setShort("status", i, (short) hit.get_status()); bankHits.setShort("duration",i, (short) hit.get_duration()); - if(debugMode>=1)System.out.format(" hit %3d id %3d [%3d %4d %4d] %3d %3d %5d \n", i, hit.get_id(), + if(debugMode>=1)System.out.format(" hit %3d id %3d [%3d %4d %4d] %3d %3d %5d \n", i, hit.get_id(), hit.get_sector(), hit.get_pmt(),hit.get_anode(),hit.get_status(),hit.get_cluster(),hit.get_xtalk()); } event.appendBanks(bankHits); } - + } - - // ---------------- + private void write_ClusterBank(DataEvent event, RICHEvent richevent) { - // ---------------- - + int debugMode = 0; - + int NCLU = richevent.get_nClu(); if(debugMode>=1)System.out.format("Creating Bank for %5d Clusters \n", NCLU); - + if(NCLU>0) { if(debugMode>=2)System.out.println(" --> Creating the RICH::Cluster Bank "); DataBank bankCluster = event.createBank("RICH::Cluster", NCLU); @@ -217,11 +191,11 @@ private void write_ClusterBank(DataEvent event, RICHEvent richevent) { System.out.println("ERROR CREATING BANK : RICH::Cluster"); return; } - + for(int i = 0; i < NCLU; i++){ - + RICHCluster clu = richevent.get_Cluster(i); - + bankCluster.setShort("id", i, (short) clu.get_id()); bankCluster.setShort("size", i, (short) clu.get_size()); bankCluster.setShort("sector", i, (short) clu.get(0).get_sector()); @@ -241,38 +215,36 @@ private void write_ClusterBank(DataEvent event, RICHEvent richevent) { event.appendBanks(bankCluster); } } - - - // ---------------- + + private void write_SignalBank(DataEvent event, RICHEvent richevent) { - // ---------------- - + int debugMode = 0; - + int NHIT = richevent.get_nHit(); int NCLU = richevent.get_nClu(); if(debugMode>=1)System.out.format("Creating Bank for Signals (%4d HITs and %4d CLUs) \n", NHIT,NCLU); - + if(NHIT>0 || NCLU>0) { - + int nsig = richevent.count_Signals(); - + if(debugMode>=1)System.out.format(" --> Creating the RICH::Signal Bank for NHIT,NCLU (%5d,%5d) --> %5d \n",NHIT,NCLU,nsig); DataBank bankSignal = event.createBank("RICH::Signal", nsig); if(bankSignal==null){ System.out.println("ERROR CREATING BANK : RICH::Signal"); return; } - + int one = 1; int ientry = 0; for(int i=0; i < NHIT; i++){ - + RICHHit hit = richevent.get_Hit(i); if(debugMode>=1)System.out.format(" hit %3d %5d (%3d %3d %5d) %7.2f",i,hit.get_id(),hit.get_status(),hit.get_cluster(),hit.get_xtalk(),hit.get_Time()); - + if(ientry0){ - + bankSignal.setShort("id", ientry, (short) ientry); bankSignal.setShort("hindex", ientry, (short) hit.get_id()); bankSignal.setShort("sector", ientry, (short) hit.get_sector()); @@ -286,22 +258,22 @@ private void write_SignalBank(DataEvent event, RICHEvent richevent) { bankSignal.setFloat("time", ientry, (float) hit.get_Time()); bankSignal.setFloat("rawtime", ientry, (float) hit.get_rawtime()); bankSignal.setFloat("charge" , ientry, (float) hit.get_duration()); - + if(debugMode>=1)System.out.format(" --> sig %4d %5d %7.2f \n",ientry, hit.get_id(), (float) hit.get_duration()); ientry++; }else{ if(debugMode>=1)System.out.format(" \n"); } - + } - + for(int j=0; j < NCLU; j++){ - + RICHCluster clu = richevent.get_Cluster(j); if(debugMode>=1)System.out.format(" clu %3d %5d %7.2f ",j,clu.get_id(),clu.get_time()); - + if(ientry0){ - + int imax = clu.get_iMax(); bankSignal.setShort("id", ientry, (short) ientry); bankSignal.setShort("hindex", ientry, (short) clu.get_id()); @@ -316,25 +288,23 @@ private void write_SignalBank(DataEvent event, RICHEvent richevent) { bankSignal.setFloat("time", ientry, (float) clu.get_time()); bankSignal.setFloat("rawtime", ientry, (float) clu.get_rawtime()); bankSignal.setFloat("charge", ientry, (float) clu.get_charge()); - + if(debugMode>=1)System.out.format(" --> clu %4d %5d %7.2f \n",ientry,clu.get_size(),clu.get_charge()); ientry++; }else{ if(debugMode>=1)System.out.format("\n"); } - + } event.appendBanks(bankSignal); } } - - - // ---------------- + + public void write_HadronBank(DataEvent event, RICHEvent richevent) { - // ---------------- - + int debugMode = 0; - + int NHAD = richevent.get_nHad(); if(debugMode>=1)System.out.format("Creating Bank for %5d Hadrons \n", NHAD); @@ -345,16 +315,16 @@ public void write_HadronBank(DataEvent event, RICHEvent richevent) { System.out.println("ERROR CREATING BANK : RICH::Hadron"); return; } - + for(int i = 0; i < NHAD; i++){ - + RICHParticle had = richevent.get_Hadron(i); - + bankHads.setShort("id", i, (short) had.get_id()); bankHads.setShort("hindex", i, (short) had.get_HitIndex()); bankHads.setByte("pindex", i, (byte) had.get_ParentIndex()); bankHads.setByte("sector", i, (byte) had.get_sector()); - + bankHads.setFloat("traced_the", i, (float) had.lab_theta); bankHads.setFloat("traced_phi", i, (float) had.lab_phi); bankHads.setFloat("traced_hitx", i, (float) had.get_HitPos().x()); @@ -363,36 +333,34 @@ public void write_HadronBank(DataEvent event, RICHEvent richevent) { bankHads.setFloat("traced_time", i, (float) had.traced.get_time()); bankHads.setFloat("traced_path", i, (float) had.traced.get_path()); bankHads.setFloat("traced_mchi2", i, (float) had.traced.get_machi2()); - + bankHads.setShort("traced_ilay", i, (short) had.ilay_emission); bankHads.setShort("traced_ico", i, (short) had.ico_emission); bankHads.setFloat("traced_emix", i, (float) had.lab_emission.x()); bankHads.setFloat("traced_emiy", i, (float) had.lab_emission.y()); bankHads.setFloat("traced_emiz", i, (float) had.lab_emission.z()); - + bankHads.setFloat("etaC_dir", i, (float) had.changle(11,0)); bankHads.setFloat("etaC_lat", i, (float) had.changle(11,1)); bankHads.setFloat("etaC_sphe", i, (float) had.changle(11,2)); bankHads.setFloat("etaC_rms", i, (float) had.schangle(0)); if(debugMode>0)System.out.format(" part %4d %4d %4d %5d %5d %7.2f %7.2f \n", had.get_id(),had.get_HitIndex(),had.get_ParentIndex(),had.ilay_emission,had.ico_emission,had.traced.get_time(),had.traced.get_machi2()); - + } event.appendBanks(bankHads); } - + } - - - // ---------------- + + public void write_ParticleBank(DataEvent event, RICHEvent richevent, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + int NHAD = richevent.get_nHad(); if(debugMode>=1)System.out.format("Creating Bank for %5d RICH Particles \n", NHAD); - + if(NHAD>0) { if(debugMode>=1)System.out.println(" --> Creating the RICH::Particle Bank "); DataBank bankPart = event.createBank("RICH::Particle", NHAD); @@ -400,36 +368,36 @@ public void write_ParticleBank(DataEvent event, RICHEvent richevent, RICHParamet System.out.println("ERROR CREATING BANK : RICH::Particle"); return; } - + for(int i = 0; i < NHAD; i++){ - + RICHParticle had = richevent.get_Hadron(i); double dT_max = richpar.PIXEL_NOMINAL_STIME*3; - + if(debugMode>0)System.out.format(" part %4d %4d %4d %5d %5d %5d %5d \n", had.get_id(),had.get_HitIndex(),had.get_ParentIndex(),had.ilay_emission,had.ico_emission,had.ico_entrance,had.traced.get_BestH()); - + if(had.get_id()>255)continue; if(had.get_HitIndex()>255)continue; if(had.get_ParentIndex()>255)continue; if(had.ilay_emission>255)continue; if(had.ico_emission>255)continue; if(had.ico_entrance>255)continue; - + if(debugMode>0)System.out.format(" RICHio %7.2f %7.2f %5d %7.2f %9.4f %9.4f %7.2f %7.2f %7.2f\n",had.min_changle(0)*MRAD,had.max_changle(0)*MRAD, - had.traced.get_BestH(),had.traced.get_RQP(),had.traced.get_ElProb(),had.traced.get_PiProb(),had.traced.get_BestCH(), - had.traced.get_BestC2(),had.traced.get_BestRL() ); - + had.traced.get_BestH(),had.traced.get_RQP(),had.traced.get_ElProb(),had.traced.get_PiProb(),had.traced.get_BestCH(), + had.traced.get_BestC2(),had.traced.get_BestRL() ); + bankPart.setByte("id", i ,(byte) had.get_id()); bankPart.setShort("hindex", i, (short) had.get_HitIndex()); bankPart.setByte("pindex", i, (byte) had.get_ParentIndex()); - + bankPart.setByte("emilay", i, (byte) had.ilay_emission); bankPart.setByte("emico", i, (byte) had.ico_emission); bankPart.setByte("enico", i, (byte) had.ico_entrance); bankPart.setShort("emqua", i, (short) had.iqua_emission); bankPart.setFloat("mchi2", i, (float) had.traced.get_machi2()); - + bankPart.setShort("best_PID", i, (short) had.traced.get_BestH(had.charge())); bankPart.setFloat("RQ", i, (float) had.traced.get_RQP()); bankPart.setFloat("ReQ", i, (float) had.traced.get_ReQP()); @@ -437,7 +405,7 @@ public void write_ParticleBank(DataEvent event, RICHEvent richevent, RICHParamet bankPart.setFloat("pi_logl", i, (float) had.traced.get_PiProb()); bankPart.setFloat("k_logl", i, (float) had.traced.get_KProb()); bankPart.setFloat("pr_logl", i, (float) had.traced.get_PrProb()); - + bankPart.setFloat("best_ch", i, (float) had.traced.get_BestCH()); bankPart.setFloat("best_c2", i, (float) had.traced.get_BestC2()); bankPart.setFloat("best_RL", i, (float) had.traced.get_BestRL()); @@ -446,23 +414,21 @@ public void write_ParticleBank(DataEvent event, RICHEvent richevent, RICHParamet } event.appendBanks(bankPart); } - + } - - - // ---------------- + + public void write_RingBank(DataEvent event, RICHEvent richevent, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + int NPHO = richevent.get_nPho(); if(debugMode>=1)System.out.format("Creating Ring Bank from %5d Photons\n", NPHO); if(NPHO!=0) { - + int Nring = 0; - + for(int i = 0; i < NPHO; i++){ RICHParticle pho = richevent.get_Photon(i); RICHParticle had = richevent.get_Hadron( pho.get_ParentIndex() ); @@ -472,39 +438,39 @@ public void write_RingBank(DataEvent event, RICHEvent richevent, RICHParameters if(richpar.RING_ONLY_BEST==1 && hypo_pid!=had.traced.get_BestH(had.charge()))continue; if(pho.traced.get_OK()>=110) Nring++; } - + if(debugMode>=1)System.out.format(" --> Creating the RICH::Ring Bank for Npho %5d Nring %5d \n",NPHO,Nring); DataBank bankRing = event.createBank("RICH::Ring", Nring); if(bankRing==null){ System.out.println("ERROR CREATING BANK : RICH::Ring"); return; } - + /*if(debugMode>=1)System.out.format(" --> Creating the RICH::reference Bank for Npho %5d Nref %5d \n",NPHO,Nring); DataBank bankRefe = event.createBank("RICH::reference", Nring); if(bankRefe==null){ - System.out.println("ERROR CREATING BANK : RICH::reference"); - return; + System.out.println("ERROR CREATING BANK : RICH::reference"); + return; }*/ - - + + int ientry = 0; for(int i = 0; i < NPHO; i++){ - + RICHParticle pho = richevent.get_Photon(i); RICHParticle had = richevent.get_Hadron( pho.get_ParentIndex() ); int pmt = pho.get_HitPMT(); - + double a_time = pho.get_StartTime() + pho.analytic.get_time(); double t_time = pho.get_StartTime() + pho.traced.get_time(); - + double a_etaC = pho.analytic.get_EtaC(); double t_etaC = pho.traced.get_EtaC(); int hypo_pid = pho.traced.get_hypo(had.charge()); - + if(!pho.is_real())continue; if(debugMode>=1)System.out.format(" phot %3d (%3d %3d) pmt %4d [%6d] ok %6d ",i,pho.get_ParentIndex(),had.get_ParentIndex(),pmt,pho.traced.get_RefleLayers(),pho.traced.get_OK()); - + // skip no real Cherenkov solution boolean reject=false; if(richpar.RING_ONLY_USED==1 && !pho.traced.is_used())reject=true; @@ -514,131 +480,129 @@ public void write_RingBank(DataEvent event, RICHEvent richevent, RICHParameters double htime = pho.get_HitTime(); int use = pho.traced.get_OK(); if(use>=1000)use=-1*(use-1000); - + if(had.get_ParentIndex()<255 && pho.get_HitAnode()<255 && pho.traced.get_nrefle()<255){ - + //bankRing.setShort("id", ientry, (short) pho.get_id()); bankRing.setShort("id", ientry, (short) ientry); bankRing.setShort("hindex", ientry, (short) pho.get_HitIndex()); bankRing.setByte( "pindex", ientry, (byte) had.get_ParentIndex()); - + bankRing.setByte( "sector", ientry, (byte) pho.get_HitSector()); bankRing.setShort("pmt", ientry, (short) pho.get_HitPMT()); bankRing.setByte( "anode", ientry, (byte) pho.get_HitAnode()); bankRing.setFloat("dtime", ientry, (float) (htime-t_time)); - + bankRing.setInt( "hypo", ientry, (int) hypo_pid); bankRing.setFloat("etaC", ientry, (float) t_etaC ); - + double prob = pho.traced.get_ElProb(); if(Math.abs(hypo_pid)==211) prob = pho.traced.get_PiProb(); if(Math.abs(hypo_pid)==321) prob = pho.traced.get_KProb(); if(Math.abs(hypo_pid)==2212) prob = pho.traced.get_PrProb(); bankRing.setFloat("prob", ientry, (float) prob); - + bankRing.setByte("use", ientry, (byte) use); bankRing.setInt("layers", ientry, (int) pho.traced.get_RefleLayers()); bankRing.setInt("compos", ientry, (int) pho.traced.get_RefleCompos()); - + double dangle = pho.traced.get_dphi_pixel()*pho.traced.get_dthe_pixel(); bankRing.setFloat("dangle", ientry, (float) dangle); - + /*bankRefe.setShort("id", ientry, (short) pho.get_id()); bankRefe.setShort("hindex", ientry, (short) pho.get_HitIndex()); bankRefe.setByte( "pindex", ientry, (byte) had.get_ParentIndex()); - + bankRefe.setFloat("path", ientry, (float) pho.traced.get_path()); bankRefe.setFloat("time", ientry, (float) t_time ); bankRefe.setFloat("stime", ientry, (float) pho.schtime()); bankRefe.setFloat("hittime", ientry, (float) htime); - + bankRefe.setFloat("eff", ientry, (float) pho.cheff()); bankRefe.setFloat("back", ientry, (float) pho.chbackgr()); - + bankRefe.setFloat("etac_ref", ientry, (float) had.changle(hypo_pid,irefle)); bankRefe.setFloat("etac_rms", ientry, (float) had.schangle(irefle));*/ - + if(debugMode>=1)System.out.format(" --> ring %3d %5d %7.2f %7.2f (%3d) %7.2f %7.2f \n", ientry,hypo_pid,t_time,t_etaC*MRAD,use,htime-t_time,prob); ientry++; }else{ if(debugMode>=1)System.out.format(" \n"); } - + }else{ if(debugMode>=1)System.out.format(" \n"); } - + } event.appendBanks(bankRing); //event.appendBanks(bankRefe); } } - - - // ---------------- + + public void write_PhotonBank(DataEvent event, RICHEvent richevent, RICHParameters richpar) { - // ---------------- - + int debugMode = 0; - + int NPHO = richevent.get_nPho(); if(debugMode>=1)System.out.format("Creating Bank for %5d Photons \n", NPHO); if(NPHO!=0) { - + int Nrow = 0; for(int i = 0; i < NPHO; i++){ RICHParticle pho = richevent.get_Photon(i); if((pho.is_real() && richpar.SAVE_PHOTONS==1) || (!pho.is_real() && richpar.SAVE_THROWS==1))Nrow++; } - + if(debugMode>=1)System.out.format(" --> Creating the RICH::Photon Bank for Npho %4d Nrow %4d \n",NPHO,Nrow); DataBank bankPhos = event.createBank("RICH::Photon", Nrow); if(bankPhos==null){ System.out.println("ERROR CREATING BANK : RICH::Photon"); return; } - + int ientry = 0; - + for(int i = 0; i < NPHO; i++){ - + RICHParticle pho = richevent.get_Photon(i); RICHParticle had = richevent.get_Hadron( pho.get_ParentIndex() ); int hypo_pid = pho.traced.get_hypo(had.charge()); if(debugMode>=1)System.out.format(" phot %3d (%3d %3d) %3d %5d ",i,pho.get_ParentIndex(),had.get_ParentIndex(),pho.get_type(),hypo_pid); int use = pho.traced.get_OK(); if(use>=1000)use=-1*(use-1000); - + if((pho.is_real() && richpar.SAVE_PHOTONS==1) || (!pho.is_real() && richpar.SAVE_THROWS==1)){ if(ientry=1)System.out.format(" %4d --> %4d %4d ", pho.get_id(),ientry,pho.get_HitIndex()); if(pho.traced.exist()){ - + bankPhos.setFloat("traced_the", ientry,(float) pho.traced.get_theta()); bankPhos.setFloat("traced_phi", ientry,(float) pho.traced.get_phi()); bankPhos.setFloat("traced_hitx", ientry,(float) pho.traced.get_hit().x()); @@ -651,50 +615,48 @@ public void write_PhotonBank(DataEvent event, RICHEvent richevent, RICHParameter bankPhos.setShort("traced_1rfl", ientry,(short) pho.traced.get_FirstRefle()); bankPhos.setInt("traced_layers", ientry,(int) pho.traced.get_RefleLayers()); bankPhos.setInt("traced_compos", ientry,(int) pho.traced.get_RefleCompos()); - + bankPhos.setFloat("traced_etaC", ientry,(float) pho.traced.get_EtaC()); bankPhos.setFloat("traced_aeron", ientry,(float) pho.traced.get_aeron()); bankPhos.setFloat("traced_dthe", ientry,(float) pho.traced.get_dthe_pixel()); bankPhos.setFloat("traced_dphi", ientry,(float) pho.traced.get_dphi_pixel()); - + double prob = pho.traced.get_ElProb(); if(Math.abs(hypo_pid)==211) prob = pho.traced.get_PiProb(); if(Math.abs(hypo_pid)==321) prob = pho.traced.get_KProb(); if(Math.abs(hypo_pid)==2212) prob = pho.traced.get_PrProb(); bankPhos.setFloat("prob", ientry, (float) prob); - + if(debugMode>=1)System.out.format(" --> %4d %7.2f [%7.2f] %7.2f [%7.2f] --> (%5d) %7.2f %6d \n", irefle,pho.traced.get_EtaC()*MRAD,had.changle(hypo_pid,irefle)*MRAD, htime,pho.get_StartTime()+pho.traced.get_time(),pho.traced.get_OK(),prob,hypo_pid); }else{ if(debugMode>=1)System.out.format(" --> no traced \n"); } - + ientry++; - - }else{ - if(debugMode>=1)System.out.format(" \n"); - } - }else{ + + }else{ + if(debugMode>=1)System.out.format(" \n"); + } + }else{ if(debugMode>=1)System.out.format(" \n"); - } + } } event.appendBanks(bankPhos); } - + } - - // ---------------- + public DataBank get_ResponseBank(List responses, DataEvent event, String bank_name, RICHParameters richpar){ - // ---------------- - + int debugMode = 0; if(debugMode>=1)System.out.format("Saving match in RICH::Response bank Nmatches %5d \n",responses.size()); DataBank bank = event.createBank(bank_name, responses.size()); for(int row = 0; row < responses.size(); row++){ DetectorResponse r = (DetectorResponse) responses.get(row); - + bank.setShort("index", row, (short) r.getHitIndex()); bank.setShort("pindex", row, (short) r.getAssociation()); bank.setByte("detector", row, (byte) r.getDescriptor().getType().getDetectorId()); @@ -710,19 +672,19 @@ public DataBank get_ResponseBank(List responses, DataEvent eve bank.setFloat("time", row, (float) r.getTime()); bank.setFloat("energy", row, (float) r.getEnergy()); float chi2 = (float) (2*Math.sqrt(Math.pow(r.getMatchedPosition().x()-r.getPosition().x(),2)+ - Math.pow(r.getMatchedPosition().y()-r.getPosition().y(),2)+ - Math.pow(r.getMatchedPosition().z()-r.getPosition().z(),2))/richpar.RICH_HITMATCH_RMS); + Math.pow(r.getMatchedPosition().y()-r.getPosition().y(),2)+ + Math.pow(r.getMatchedPosition().z()-r.getPosition().z(),2))/richpar.RICH_HITMATCH_RMS); bank.setFloat("chi2", row, (float) chi2); - + if(debugMode>=1)System.out.format("RICH::Response id %3d hit %6.1f %6.1f %6.1f tk %6.1f %6.1f %6.1f chi2 %8.3f \n", - r.getHitIndex(), - r.getPosition().x(),r.getPosition().y(),r.getPosition().z(), - r.getPosition().x()+(r.getMatchedPosition().x()-r.getPosition().x())*2, - r.getPosition().y()+(r.getMatchedPosition().y()-r.getPosition().y())*2, - r.getPosition().z()+(r.getMatchedPosition().z()-r.getPosition().z())*2,chi2); + r.getHitIndex(), + r.getPosition().x(),r.getPosition().y(),r.getPosition().z(), + r.getPosition().x()+(r.getMatchedPosition().x()-r.getPosition().x())*2, + r.getPosition().y()+(r.getMatchedPosition().y()-r.getPosition().y())*2, + r.getPosition().z()+(r.getMatchedPosition().z()-r.getPosition().z())*2,chi2); } return bank; } - - + + } From fd59c142c971a791dc5a3e7155e358137d82176c Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Tue, 14 Jul 2026 11:05:05 -0400 Subject: [PATCH 2/2] unify comment format --- .../src/main/java/org/jlab/rec/rich/RICHEBEngine.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java index fbeb23a710..1a4966279c 100644 --- a/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java +++ b/reconstruction/rich/src/main/java/org/jlab/rec/rich/RICHEBEngine.java @@ -106,9 +106,7 @@ public boolean processDataEventUser(DataEvent event) { richtime.save_ProcessTime(1, richevent); - /* - Process RICH signals to get hits and clusters - */ + // Process RICH signals to get hits and clusters if(richpar.PROCESS_RAWDATA==1){ if(debugMode>=1)System.out.println("----- Process raw data \n"); richio.clear_LowBanks(event); @@ -116,9 +114,7 @@ public boolean processDataEventUser(DataEvent event) { richtime.save_ProcessTime(2, richevent); } - /* - Process RICH-DC event reconstruction - */ + // Process RICH-DC event reconstruction if(richpar.PROCESS_DATA==1){ if(debugMode>=1)System.out.println("----- Process data \n"); richio.clear_HighBanks(event);