diff --git a/.gitignore b/.gitignore index a41c2f4f8f..591c854639 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +# installed: +/coatjava +/myLocalMvnRepo +target + *.class *lundfiles*.dat @@ -10,4 +15,16 @@ *.ear # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* \ No newline at end of file +hs_err_pid* + +# editor tmp files: +*.swp +*~ + +# ide stuff: +*.iml +.idea + +# no log files: +*.log + diff --git a/build-coatjava.sh b/build-coatjava.sh index 885f25e562..1697aa7bb6 100755 --- a/build-coatjava.sh +++ b/build-coatjava.sh @@ -1,7 +1,7 @@ #!/bin/bash +mkdir -p coatjava rm -f coatjava/lib/clas/jcsg-0.3.2.jar -mkdir coatjava cp -r bin coatjava/ cp -r etc coatjava/ mkdir -p coatjava/lib/clas diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java index e1f2121e72..8286ce7d84 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorType.java @@ -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.detector.base; /** @@ -36,6 +31,11 @@ public enum DetectorType { SC (114, "SC"), CC (115, "CC"), SVT (220, "SVT"); + + // FIXME add layer conventions here, e.g.: + // (or maybe they are defined somewhere else?) + // FTOF2/1A/1B = 0/1/2 + // PCAL/Inner/Outer = 1/4/7 private final int detectorId; private final String detectorName; diff --git a/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PhysicsConstants.java b/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PhysicsConstants.java index 256a992d26..e6f418ab23 100644 --- a/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PhysicsConstants.java +++ b/common-tools/clas-physics/src/main/java/org/jlab/clas/pdg/PhysicsConstants.java @@ -25,7 +25,7 @@ public static double massNeutron(){ } public static double massElectron(){ - return 0.0005; + return 0.000511; } public static double massPionCharged(){ diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CalorimeterResponse.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CalorimeterResponse.java index 789864ae68..fc2ff87429 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CalorimeterResponse.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CalorimeterResponse.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.clas.detector; import java.util.ArrayList; @@ -17,19 +12,17 @@ * @author jnewton */ public class CalorimeterResponse extends DetectorResponse { - - + public CalorimeterResponse(){ super(); } - + public CalorimeterResponse(int sector, int layer, int component){ this.getDescriptor().setSectorLayerComponent(sector, layer, component); } - - + public static List readHipoEvent(DataEvent event, - String bankName, DetectorType type){ + String bankName, DetectorType type){ List responseList = new ArrayList(); if(event.hasBank(bankName)==true){ DataBank bank = event.getBank(bankName); @@ -49,10 +42,8 @@ public static List readHipoEvent(DataEvent event, responseList.add(response); } } - return responseList; } - } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CherenkovResponse.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CherenkovResponse.java index 8fccf39ac1..1349fd7ae5 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CherenkovResponse.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/CherenkovResponse.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.clas.detector; import java.util.ArrayList; @@ -22,50 +17,49 @@ * @author gavalian */ public class CherenkovResponse { - - private double hitTime = 0.0; - private double hitTheta = 0.0; - private double hitPhi = 0.0; - private int hitNphe = 0; - private double hitDeltaPhi = 0.0; + + private double hitTime = 0.0; + private double hitTheta = 0.0; + private double hitPhi = 0.0; + private double hitNphe = 0; + private double hitDeltaPhi = 0.0; private double hitDeltaTheta = 0.0; - private int association = -1; - private int hitIndex = -1; - + private int hitIndex = -1; + private int association = -1; + private DetectorType cherenkovType = DetectorType.HTCC; private Point3D hitPosition = new Point3D(); - //private Sphere3D private DetectorDescriptor desc = new DetectorDescriptor(); - + public CherenkovResponse(double theta, double phi, double dtheta, double dphi){ hitTheta = theta; hitPhi = phi; hitDeltaTheta = dtheta; hitDeltaPhi = dphi; } - + public CherenkovResponse setTime(double time) { hitTime = time; return this;} - public CherenkovResponse setEnergy(int energy) { hitNphe = energy; return this;} + public CherenkovResponse setEnergy(double energy) { hitNphe = energy; return this;} public void setAssociation(int assoc) {this.association = assoc;} public void setHitIndex(int index){this.hitIndex = index;} - + public double getTime(){ return hitTime;} public int getHitIndex(){return hitIndex;} - public int getEnergy(){ return hitNphe;} + public double getEnergy(){ return hitNphe;} public double getTheta() {return this.hitTheta;} public double getPhi() {return this.hitPhi;} public double getDeltaTheta(){ return this.hitDeltaTheta;} public double getDeltaPhi() {return this.hitDeltaPhi;} public int getAssociation() {return this.association;} - + public Point3D getHitPosition(){ return this.hitPosition; } - + public void setHitPosition(double x, double y, double z){ this.hitPosition.set(x, y, z); } - + public Point3D getIntersection(Line3D line){ Vector3D vec = new Vector3D(this.hitPosition.x(),this.hitPosition.y(),this.hitPosition.z()); vec.unit(); @@ -74,23 +68,15 @@ public Point3D getIntersection(Line3D line){ plane.intersection(line, intersect); return intersect; } - + public boolean match(Line3D particletrack){ Point3D intersection = this.getIntersection(particletrack); Vector3D vecRec = intersection.toVector3D(); Vector3D vecHit = this.hitPosition.toVector3D(); - //System.out.println(particletrack); - //System.out.println(this.hitPosition); -// System.out.println("Calculated Theta Difference (Degrees)" + Math.abs(vecHit.theta()-vecRec.theta())*57.2958); -// System.out.println("Expected Theta Difference (Degrees)" + this.hitDeltaTheta*57.2958); -// System.out.println(" "); -// System.out.println("Calculated Phi Difference (Degrees)" + Math.abs(vecHit.phi()-vecRec.phi())*57.2958); -// System.out.println("Expected Phi Difference (Degrees)" + this.hitDeltaPhi*57.2958); -// System.out.println(" "); - -//System.out.println(Math.abs(vecHit.theta()-vecRec.theta())*57.2958 + " " + -// Math.abs(vecHit.phi()-vecRec.phi())*57.2958); - + // FIXME: + // 1. remove hardcoded constant (10 degrees) + // 2. either use both dphi and dtheta from detector bank (only + // exists for HTCC), or get both from CCDB return (Math.abs(vecHit.theta()-vecRec.theta())<10.0/57.2958 && Math.abs(vecHit.phi()-vecRec.phi()) readHipoEvent(DataEvent event, - String bankName, DetectorType type){ + String bankName, DetectorType type){ List responseList = new ArrayList(); if(event.hasBank(bankName)==true){ DataBank bank = event.getBank(bankName); int nrows = bank.rows(); for(int row = 0; row < nrows; row++){ - int nphe = bank.getInt("nphe", row); - double theta = bank.getFloat("theta", row); - double dtheta = bank.getFloat("dtheta",row); - double phi = bank.getFloat("phi",row); - double dphi = bank.getFloat("dphi",row); + double x = bank.getFloat("x",row); double y = bank.getFloat("y",row); double z = bank.getFloat("z",row); double time = bank.getFloat("time",row); - CherenkovResponse che = new CherenkovResponse(theta,phi,dtheta,dphi); - che.setHitPosition(x, y, z); - //System.out.println(che.getHitPosition()); - //System.out.println("hello there is cherenkov"); - che.setHitIndex(row); - che.setEnergy(nphe); - che.setTime(time); - che.setCherenkovType(DetectorType.HTCC); + + // FIXME: unify LTCC/HTCC detector banks + // Here we have to treat them differently: + // 1. nphe really shouldn't be an integer + // 2. either add dtheta/dphi to LTCC, or ignore HTCC's and use CCDB for both + // 3. HTCC provides both x/y/z and theta/phi, while LTCC provides only x/y/z. + // The current convention in EB is to use only x/y/z, while theta/phi is + // just propogated. + + double nphe,theta=0,phi=0,dtheta=0,dphi=0; + + if (type==DetectorType.HTCC) { + nphe = (double)bank.getInt("nphe", row); + dtheta = bank.getFloat("dtheta",row); + dphi = bank.getFloat("dphi",row); + theta = bank.getFloat("theta", row); + phi = bank.getFloat("phi",row); + } + + else if (type==DetectorType.LTCC) { + nphe = bank.getFloat("nphe", row); + // Hardcode some dtheta/dphi values for now (for matching): + dtheta = 10*3.14159/180; + dphi = 10*3.14159/180; + // Fill theta/phi: + // Not yet. + } + + else { + throw new RuntimeException( + "CherenkovResponse::readHipoEvent: invalid DetectorType: "+type); + } + + CherenkovResponse che = new CherenkovResponse(theta,phi,dtheta,dphi); + che.setHitPosition(x, y, z); + che.setHitIndex(row); + che.setEnergy(nphe); + che.setTime(time); + che.setCherenkovType(type); responseList.add(che); } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.java index 90724d112b..a6f2d4436c 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorData.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.clas.detector; import java.util.ArrayList; @@ -27,7 +22,6 @@ public class DetectorData { */ public static List readDetectorResponses(DataEvent event, String bank_name){ List responses = new ArrayList(); - //System.out.println(" RESPONESE BANK EXISTS = " + event.hasBank(bank_name)); if(event.hasBank(bank_name)==true){ DataBank bank = event.getBank(bank_name); @@ -200,7 +194,6 @@ public static DataBank getCalorimeterResponseBank(List respons DataBank bank = event.createBank(bank_name, responses.size()); for(int row = 0; row < responses.size(); row++){ DetectorResponse r = 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()); @@ -229,7 +222,7 @@ public static DataBank getCalorimeterResponseBank(List respons return bank; } - public static DataBank getScintillatorResponseBank(List responses, DataEvent event, String bank_name){ + public static DataBank getScintillatorResponseBank(List responses, DataEvent event, String bank_name){ DataBank bank = event.createBank(bank_name, responses.size()); for(int row = 0; row < responses.size(); row++){ DetectorResponse r = responses.get(row); @@ -253,7 +246,7 @@ public static DataBank getScintillatorResponseBank(List respon return bank; } - public static DataBank getCherenkovResponseBank(List responses, DataEvent event, String bank_name){ + public static DataBank getCherenkovResponseBank(List responses, DataEvent event, String bank_name){ DataBank bank = event.createBank(bank_name, responses.size()); for(int row = 0; row < responses.size(); row++){ CherenkovResponse c = responses.get(row); @@ -275,83 +268,115 @@ public static DataBank getCherenkovResponseBank(List response return bank; } - public static DataBank getForwardTaggerBank(List responses, DataEvent event, String bank_name){ - DataBank bank = event.createBank(bank_name, responses.size()); - for(int row = 0; row < responses.size(); row++){ - TaggerResponse ft = responses.get(row); - bank.setShort("index", row, (short) 0); - bank.setShort("pindex", row, (short) 0); - bank.setShort("size", row, (short) 0); - bank.setFloat("x", row, (float) 0.0); - bank.setFloat("y", row, (float) 0.0); - bank.setFloat("z", row, (float) 0.0); - bank.setFloat("dx", row, (float) 0.0); - bank.setFloat("dy", row, (float) 0.0); - bank.setFloat("radius", row, (float) 0.0); - bank.setFloat("path", row, (float) 0.0); - bank.setFloat("time", row, (float) 0.0); - bank.setInt("energy", row, (int) 0.0); - bank.setFloat("chi2", row, (float) 0.0); + public static DataBank getForwardTaggerBank(List particles, DataEvent event, String bank_name, int rows){ + DataBank bank = event.createBank(bank_name, rows); + int row = 0; + for(int i = 0; i < particles.size(); i++){ + // FIXME: + // 1. remove this hardcoded constant 100, instead use DetectorType class + // 2. use REC::Particle.detector for identifying detector, NOT "status" + if(particles.get(i).getStatus()==100) { + DetectorParticle p = particles.get(i); + bank.setShort("index", row, (short) p.getTaggerIndex()); + bank.setShort("pindex", row, (short) i); + bank.setShort("size", row, (short) p.getTaggerSize()); + bank.setFloat("x", row, (float) p.getTaggerPosition().x()); + bank.setFloat("y", row, (float) p.getTaggerPosition().y()); + bank.setFloat("z", row, (float) p.getTaggerPosition().z()); + bank.setFloat("dx", row, (float) p.getTaggerPositionWidth().x()); + bank.setFloat("dy", row, (float) p.getTaggerPositionWidth().y()); + bank.setFloat("radius", row, (float) p.getTaggerRadius()); + bank.setFloat("path", row, (float) 0.0); + bank.setFloat("time", row, (float) p.getTaggerTime()); + bank.setInt("energy", row, (int) p.getTaggerEnergy()); + bank.setFloat("chi2", row, (float) 0.0); + row = row + 1; + } } return bank; } - public static DataBank getEventBank(DetectorEvent detectorEvent, DataEvent event, String bank_name){ + public static DataBank getEventBank(DetectorEvent detectorEvent, DataEvent event, String bank_name){ DataBank bank = event.createBank(bank_name, 1); - bank.setInt("NRUN", 0, detectorEvent.getEventHeader().getRun()); - bank.setInt("NEVENT", 0, detectorEvent.getEventHeader().getEvent()); - bank.setInt("TRG", 0, detectorEvent.getEventHeader().getTrigger()); - bank.setFloat("STTime", 0, (float) detectorEvent.getEventHeader().getStartTime()); - bank.setFloat("RFTime", 0, (float) detectorEvent.getEventHeader().getRfTime()); + bank.setInt("NRUN", 0, detectorEvent.getEventHeader().getRun()); + bank.setInt("NEVENT", 0, detectorEvent.getEventHeader().getEvent()); + bank.setInt("TRG", 0, detectorEvent.getEventHeader().getTrigger()); + bank.setFloat("STTime", 0, (float) detectorEvent.getEventHeader().getStartTime()); + bank.setFloat("RFTime", 0, (float) detectorEvent.getEventHeader().getRfTime()); return bank; } - public static DataBank getCrossBank(List particles, DataEvent event, String bank_name) { - DataBank bank = event.createBank(bank_name, particles.size()); - for(int row = 0 ; row < particles.size(); row++){ - DetectorParticle p = particles.get(row); - bank.setShort("pindex", row, (short) row); - bank.setFloat("c_x", row, (float) p.getCross().x()); - bank.setFloat("c_y", row, (float) p.getCross().y()); - bank.setFloat("c_z", row, (float) p.getCross().z()); - bank.setFloat("c_ux", row, (float) p.getCrossDir().x()); - bank.setFloat("c_uy", row, (float) p.getCrossDir().y()); - bank.setFloat("c_uz", row, (float) p.getCrossDir().z()); - - } - return bank; - } + public static DataBank getTracksBank(List particles, DataEvent event, String bank_name, int rows) { + DataBank bank = event.createBank(bank_name, rows); + int row = 0; + for(int i = 0 ; i < particles.size(); i++) { + DetectorParticle p = particles.get(i); + // FIXME: is this supposed to work for CVT too? + if(p.getTrackDetector()==DetectorType.DC.getDetectorId()) { + bank.setShort("index", row, (short) p.getTrackIndex()); + bank.setShort("pindex", row, (short) i); + bank.setByte("detector", row, (byte) p.getTrackDetector()); + bank.setByte("q", row, (byte) p.getCharge()); + bank.setFloat("chi2", row, (float) p.getChi2()); + bank.setShort("NDF", row, (short) p.getNDF()); + bank.setFloat("px_nomm", row, (float) p.vector().x()); + bank.setFloat("py_nomm", row, (float) p.vector().y()); + bank.setFloat("pz_nomm", row, (float) p.vector().z()); + bank.setFloat("vx_nomm", row, (float) p.vertex().x()); + bank.setFloat("vy_nomm", row, (float) p.vertex().y()); + bank.setFloat("vz_nomm", row, (float) p.vertex().z()); + row = row + 1; + } + } + return bank; + } + + public static DataBank getCrossBank(List particles, DataEvent event, String bank_name) { + DataBank bank = event.createBank(bank_name, particles.size()); + for(int row = 0 ; row < particles.size(); row++){ + DetectorParticle p = particles.get(row); + bank.setShort("pindex", row, (short) row); + bank.setFloat("c_x", row, (float) p.getCross().x()); + bank.setFloat("c_y", row, (float) p.getCross().y()); + bank.setFloat("c_z", row, (float) p.getCross().z()); + bank.setFloat("c_ux", row, (float) p.getCrossDir().x()); + bank.setFloat("c_uy", row, (float) p.getCrossDir().y()); + bank.setFloat("c_uz", row, (float) p.getCrossDir().z()); + + } + return bank; + } public static List readTBCovMat(DataEvent event, String bank_name) { List covMat = new ArrayList(); - if(event.hasBank(bank_name)==true){ - DataBank bank = event.getBank(bank_name); - int nrows = bank.rows(); - for(int row = 0; row < nrows; row++){ - double[] covariance = new double[15]; - covariance[0] = bank.getFloat("C11", row); - covariance[1] = bank.getFloat("C12", row); - covariance[2] = bank.getFloat("C13", row); - covariance[3] = bank.getFloat("C14", row); - covariance[4] = bank.getFloat("C15", row); - covariance[5] = bank.getFloat("C22", row); - covariance[6] = bank.getFloat("C23", row); - covariance[7] = bank.getFloat("C24", row); - covariance[8] = bank.getFloat("C25", row); - covariance[9] = bank.getFloat("C33", row); - covariance[10] = bank.getFloat("C34", row); - covariance[11] = bank.getFloat("C35", row); - covariance[12] = bank.getFloat("C44", row); - covariance[13] = bank.getFloat("C45", row); - covariance[14] = bank.getFloat("C55", row); - covMat.add(covariance); - } - } + if(event.hasBank(bank_name)==true){ + DataBank bank = event.getBank(bank_name); + int nrows = bank.rows(); + for(int row = 0; row < nrows; row++){ + double[] covariance = new double[15]; + covariance[0] = bank.getFloat("C11", row); + covariance[1] = bank.getFloat("C12", row); + covariance[2] = bank.getFloat("C13", row); + covariance[3] = bank.getFloat("C14", row); + covariance[4] = bank.getFloat("C15", row); + covariance[5] = bank.getFloat("C22", row); + covariance[6] = bank.getFloat("C23", row); + covariance[7] = bank.getFloat("C24", row); + covariance[8] = bank.getFloat("C25", row); + covariance[9] = bank.getFloat("C33", row); + covariance[10] = bank.getFloat("C34", row); + covariance[11] = bank.getFloat("C35", row); + covariance[12] = bank.getFloat("C44", row); + covariance[13] = bank.getFloat("C45", row); + covariance[14] = bank.getFloat("C55", row); + covMat.add(covariance); + } + } return covMat; } - public static DataBank getTBCovMatBank(List particles, DataEvent event, String bank_name) { + public static DataBank getTBCovMatBank(List particles, DataEvent event, String bank_name) { DataBank bank = event.createBank(bank_name, particles.size()); for(int row = 0; row < particles.size(); row++){ DetectorParticle p = particles.get(row); @@ -387,26 +412,31 @@ public static List readDetectorTracks(DataEvent event, String ba if(event.hasBank(bank_name)==true){ DataBank bank = event.getBank(bank_name); int nrows = bank.rows(); - + for(int row = 0; row < nrows; row++){ int charge = bank.getByte("q", row); - //System.out.println("DC charge " + bank.getByte("q",row)); Vector3D pvec = DetectorData.readVector(bank, row, "p0_x", "p0_y", "p0_z"); Vector3D vertex = DetectorData.readVector(bank, row, "Vtx0_x", "Vtx0_y", "Vtx0_z"); - - DetectorTrack track = new DetectorTrack(charge,pvec.mag()); + + DetectorTrack track = new DetectorTrack(charge,pvec.mag(), (row)); track.setVector(pvec.x(), pvec.y(), pvec.z()); track.setVertex(vertex.x(), vertex.y(), vertex.z()); track.setPath(bank.getFloat("pathlength", row)); - + Vector3D lc_vec = DetectorData.readVector(bank, row, "c1_x", "c1_y", "c1_z"); Vector3D lc_dir = DetectorData.readVector(bank, row, "c1_ux", "c1_uy", "c1_uz"); - + Vector3D hc_vec = DetectorData.readVector(bank, row, "c3_x", "c3_y", "c3_z"); Vector3D hc_dir = DetectorData.readVector(bank, row, "c3_ux", "c3_uy", "c3_uz"); track.addCross(lc_vec.x(), lc_vec.y(), lc_vec.z(), lc_dir.x(), lc_dir.y(), lc_dir.z()); track.addCross(hc_vec.x(), hc_vec.y(), hc_vec.z(), hc_dir.x(), hc_dir.y(), hc_dir.z()); - + + track.setNDF(bank.getInt("ndf",row)); + track.setchi2(bank.getFloat("chi2",row)); + track.setStatus(bank.getInt("status",row)); + + track.setDetectorID(DetectorType.DC.getDetectorId()); + tracks.add(track); } } @@ -414,71 +444,48 @@ public static List readDetectorTracks(DataEvent event, String ba } - public static List readCentralDetectorTracks(DataEvent event, String bank_name){ - List tracks = new ArrayList(); - if(event.hasBank(bank_name)==true){ - DataBank bank = event.getBank(bank_name); - int nrows = bank.rows(); - - for(int row = 0; row < nrows; row++){ - int charge = bank.getInt("q", row); - double p = bank.getFloat("p",row); - double pt = bank.getFloat("pt",row); - double phi0 = bank.getFloat("phi0",row); - double tandip = bank.getFloat("tandip", row); - double z0 = bank.getFloat("z0", row); - double d0 = bank.getFloat("d0", row); - - double pz = pt*tandip; - double py = pt*Math.sin(phi0); - double px = pt*Math.cos(phi0); - - double vx = d0*Math.cos(phi0); - double vy = d0*Math.sin(phi0); - - DetectorTrack track = new DetectorTrack(charge,p); - track.setVector(px, py, pz); - track.setVertex(vx, vy, z0); - track.setPath(bank.getFloat("pathlength", row)); - - //track.addCTOFPoint(x,y,z); - //System.out.println("track intersect is..." + trackIntersect); - Vector3D hc_vec = DetectorData.readVector(bank, row, "c_x", "c_y", "c_z"); - Vector3D hc_dir = DetectorData.readVector(bank, row, "c_ux", "c_uy", "c_uz"); - track.addCross(hc_vec.x(), hc_vec.y(), hc_vec.z(), hc_dir.x(), hc_dir.y(), hc_dir.z()); - - tracks.add(track); - } - } - return tracks; - } - - public static List readTaggerTracks(DataEvent event, String bank_name){ + public static List readCentralDetectorTracks(DataEvent event, String bank_name){ List tracks = new ArrayList(); if(event.hasBank(bank_name)==true){ DataBank bank = event.getBank(bank_name); int nrows = bank.rows(); - + for(int row = 0; row < nrows; row++){ - int charge = bank.getInt("q", row); - float cx = bank.getFloat("c_x", row); - float cy = bank.getFloat("c_y" , row); - float cz = bank.getFloat("c_z", row); - float energy = bank.getFloat("energy", row); - - Vector3D pvec = new Vector3D(cx*energy,cy*energy,cz*energy); - - DetectorTrack track = new DetectorTrack(charge,pvec.mag()); - track.setVertex(0.0, 0.0, 0.0); - track.setVector(cx*energy, cy*energy, cz*energy); - track.setTime(bank.getFloat("time", row)); - track.setID(bank.getInt("id",row)); - - tracks.add(track); + int charge = bank.getInt("q", row); + double p = bank.getFloat("p",row); + double pt = bank.getFloat("pt",row); + double phi0 = bank.getFloat("phi0",row); + double tandip = bank.getFloat("tandip", row); + double z0 = bank.getFloat("z0", row); + double d0 = bank.getFloat("d0", row); + + double pz = pt*tandip; + double py = pt*Math.sin(phi0); + double px = pt*Math.cos(phi0); + + double vx = d0*Math.cos(phi0); + double vy = d0*Math.sin(phi0); + + DetectorTrack track = new DetectorTrack(charge,p); + track.setVector(px, py, pz); + track.setVertex(vx, vy, z0); + track.setPath(bank.getFloat("pathlength", row)); + + //track.addCTOFPoint(x,y,z); + Vector3D hc_vec = DetectorData.readVector(bank, row, "c_x", "c_y", "c_z"); + Vector3D hc_dir = DetectorData.readVector(bank, row, "c_ux", "c_uy", "c_uz"); + track.addCross(hc_vec.x(), hc_vec.y(), hc_vec.z(), hc_dir.x(), hc_dir.y(), hc_dir.z()); + + // FIXME: define a convetion on DetectorType for central tracks + track.setDetectorID(DetectorType.SVT.getDetectorId()); + + tracks.add(track); } } return tracks; } + + } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorEvent.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorEvent.java index 9cfc409f53..a5f2067512 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorEvent.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorEvent.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.clas.detector; import java.util.ArrayList; @@ -13,7 +8,6 @@ import org.jlab.io.base.DataEvent; - /** * * @author gavalian @@ -25,16 +19,10 @@ public class DetectorEvent { private PhysicsEvent reconstructedEvent = new PhysicsEvent(); private DetectorHeader eventHeader = new DetectorHeader(); -// private double RF_OFFSET = 0.0; -// private double RF_BUNCH = 2.004; -// private int RF_SHIFT = 800; - - public DetectorEvent(){ } - public static DetectorEvent readDetectorEvent(DataEvent event){ return DetectorData.readDetectorEvent(event); } @@ -62,7 +50,6 @@ public DetectorParticle matchedParticle(Particle p){ int index = -1; for(int i = 0; i < particleList.size();i++){ if(p.charge()==particleList.get(i).getCharge()){ - //System.out.println("index = " + i + " compare = " + particleList.get(i).compare(p.vector().vect())); if(particleList.get(i).compare(p.vector().vect())3){ - sf = 0.0004*p + 0.2738; - } - return sf; - } + + public double ParametrizedSF() { + double sf = 0.0; + double p = this.vector().mag(); + if (p <= 3) { + sf = -0.0035*pow(p,4) + 0.0271*pow(p,3) - 0.077*pow(p,2) + 0.0985*pow(p,1) + 0.2241; + } + else { + sf = 0.0004*p + 0.2738; + } + return sf; + } public double ParametrizedSigma(){ - double p = this.vector().mag(); - double sigma = 0.02468*pow(p,-0.51); - - return sigma; - - } - - public double getTheoryBeta(int id){ + double p = this.vector().mag(); + double sigma = 0.02468*pow(p,-0.51); + return sigma; + } + */ + + public double getTheoryBeta(int id){ double beta = 0.0; double p = detectorTrack.getVector().mag(); + //double mass = PDGDatabase.getParticleById(id); // map lookup if(id==11 || id==-11){ - beta = p/sqrt(p*p + 0.00051*0.00051); - //beta = 1.0; - //System.out.println("Beta is " + beta); + beta = p/sqrt(p*p + pow(PhysicsConstants.massElectron(),2));//0.00051*0.00051); } - if(id==-211 || id==211){ - beta = p/sqrt(p*p + 0.13957*0.13957); + else if(id==-211 || id==211){ + beta = p/sqrt(p*p + pow(PhysicsConstants.massPionCharged(),2));//0.13957*0.13957); } - if(id==2212 || id==-2212){ - beta = p/sqrt(p*p + 0.938*0.938); - //System.out.println("Beta is " + beta); + else if(id==2212 || id==-2212){ + beta = p/sqrt(p*p + pow(PhysicsConstants.massProton(),2));//0.938*0.938); } - if(id==-321 || id==321){ - beta = p/sqrt(p*p + 0.493667*0.493667); + else if(id==-321 || id==321){ + beta = p/sqrt(p*p + pow(PhysicsConstants.massKaonCharged(),2));//0.493667*0.493667); } return beta; } - - public int getNphe(DetectorType type){ - int nphe = 0; - for(CherenkovResponse c : this.cherenkovStore){ - if(c.getCherenkovType()==type){ - nphe = c.getEnergy(); - } - } - return nphe; - } - - public double getVertexTime(DetectorType type, int layer){ - double vertex_time = this.getTime(type,layer) - this.getPathLength(type, layer)/(this.getTheoryBeta(this.getPid())*29.9792); - return vertex_time; - } - + + public double getNphe(DetectorType type){ + double nphe = 0; + for(CherenkovResponse c : this.cherenkovStore){ + if(c.getCherenkovType()==type){ + nphe = c.getEnergy(); + } + } + return nphe; + } + + public double getVertexTime(DetectorType type, int layer){ + double vertex_time = this.getTime(type,layer) - this.getPathLength(type, layer)/(this.getTheoryBeta(this.getPid())*29.9792); + return vertex_time; + } + public double getVertexTime(DetectorType type, int layer, int pid){ - double vertex_time = this.getTime(type,layer) - this.getPathLength(type, layer)/(this.getTheoryBeta(pid)*29.9792); - return vertex_time; - } - - public int getCherenkovSignal(List cherenkovs, DetectorType type){ - - int bestIndex = -1; - if(cherenkovs.size()>0){ - // System.out.println("There are here???"); - for(int loop = 0; loop < cherenkovs.size(); loop++) { - if(cherenkovs.get(loop).getCherenkovType()==type){ - boolean matchtruth = cherenkovs.get(loop).match(this.detectorTrack.getFirstCross()); - //System.out.println(matchtruth); - if(matchtruth==true){ - bestIndex = loop; - } - } - } - } - return bestIndex; - } - - public double getTime(DetectorType type, int layer) { - DetectorResponse response = this.getHit(type,layer); - if(response==null) return -1.0; + double vertex_time = this.getTime(type,layer) - this.getPathLength(type, layer)/(this.getTheoryBeta(pid)*29.9792); + return vertex_time; + } + + public int getCherenkovSignal(List cherenkovs, DetectorType type){ + + // choose cross based on detector type: + Line3D cross; + if (type==DetectorType.HTCC) + cross=this.detectorTrack.getFirstCross(); + else if (type==DetectorType.LTCC) + cross=this.detectorTrack.getLastCross(); + else throw new RuntimeException( + "DetectorParticle:getCheckr5noSignal: invalid type: "+type); + + // find the best match: + int bestIndex = -1; + if(cherenkovs.size()>0){ + for(int loop = 0; loop < cherenkovs.size(); loop++) { + if(cherenkovs.get(loop).getCherenkovType()==type){ + boolean matchtruth = cherenkovs.get(loop).match(cross); + if(matchtruth==true){ + bestIndex = loop; + // FIXME keep the first match! + break; + } + } + } + } + return bestIndex; + } + + public double getTime(DetectorType type, int layer) { + DetectorResponse response = this.getHit(type,layer); + if(response==null) return -1.0; return response.getTime(); } - + public double getPathLength(DetectorType type, int layer){ DetectorResponse response = this.getHit(type,layer); if(response==null) return -1.0; @@ -819,7 +795,7 @@ public int getSoftwareTriggerScore() { public int compareTo(Object o) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorResponse.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorResponse.java index 4943c3d6b0..7f897e05ea 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorResponse.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorResponse.java @@ -1,11 +1,5 @@ -/* - * 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.clas.detector; - import java.util.ArrayList; import java.util.List; import org.jlab.clas.physics.Vector3; @@ -25,21 +19,19 @@ public class DetectorResponse { private DetectorDescriptor descriptor = new DetectorDescriptor(); - private Vector3D hitPosition = new Vector3D(); - //private Point3D hitPosition = new Vector3(); - private Vector3D hitPositionMatched = new Vector3D(); + private Vector3D hitPosition = new Vector3D(); + //private Point3D hitPosition = new Vector3(); + private Vector3D hitPositionMatched = new Vector3D(); private Double detectorTime = 0.0; private Double detectorEnergy = 0.0; private Double particlePath = 0.0; private int association = -1; - private int hitIndex = -1; + private int hitIndex = -1; public DetectorResponse(){ super(); } - - public DetectorResponse(int sector, int layer, int component){ descriptor.setSectorLayerComponent(sector, layer, component); } @@ -127,8 +119,6 @@ public static List readHipoEvent(DataEvent event, } return responseList; } - - /** * Reads a HIPO event, constructs list of detector responses then returns only diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorTrack.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorTrack.java index 11de4640e3..179b661b60 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorTrack.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorTrack.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.clas.detector; import java.util.ArrayList; @@ -18,22 +13,24 @@ */ public class DetectorTrack { + private int trackAssociation = -1; + private int trackIndex = -1; private int trackCharge = 0; - private double trackMom = 0.0; - private double trackPath = 0.0; - private double taggerTime = 0.0; - private int taggerID = 0; - private Vector3D trackEnd = new Vector3D(); + private double trackMom = 0.0; + private double trackPath = 0.0; + private double taggerTime = 0.0; + private int taggerID = 0; + private double trackchi2 = 0.0; + private int ndf = 0; + private int trackStatus = 0; + private int trackDetectorID = -1; + private Vector3D trackEnd = new Vector3D(); private Vector3 trackP = new Vector3(); private Vector3 trackVertex = new Vector3(); // private Point3D trackIntersect = new Point3D(); - - private double variable1 = 0.0; - private int variable2 = -1; - - + private List trackCrosses = new ArrayList(); // private List ctofIntersects = new ArrayList(); @@ -42,15 +39,18 @@ public class DetectorTrack { public DetectorTrack(int charge){ this.trackCharge = charge; } - - public double getVariable1() { - return variable1; - } + public DetectorTrack(int charge, double mom){ this.trackMom = mom; this.trackCharge = charge; } + + public DetectorTrack(int charge, double mom, int index){ + this.trackMom = mom; + this.trackCharge = charge; + this.trackIndex = index; + } // public DetectorTrack(int charge, double mom, Point3D ctofintersect){ // this.trackMom = mom; @@ -116,20 +116,24 @@ public DetectorTrack setTrackEnd(double x, double y, double z){ return this; } -// public void setTrackIntersect(Point3D inter) { -// this.trackIntersect = inter; -// } - -// public Point3D getTrackIntersect() { -// return this.ctofIntersects.get(0); -// } + public void setNDF(int x) {this.ndf = x;} + public void setStatus(int x) {this.trackStatus = x;} + public void setchi2(double x) {this.trackchi2 = x;} + public void setAssociation(int x) {this.trackAssociation = x;} + public void setDetectorID(int id) {this.trackDetectorID = id;} public int getCharge() { return trackCharge;} - public double getP() { return trackP.mag();} + public int getNDF() {return ndf;} + public int getStatus() {return trackStatus;} + public double getchi2() {return trackchi2;} + public double getP() { return trackP.mag();} + public int getID() {return this.taggerID;} public double getPath() { return trackPath;} public Vector3 getVector() { return this.trackP;} public Vector3 getVertex() { return this.trackVertex;} public Vector3D getTrackEnd() { return trackEnd;} + public int getAssociation() {return trackAssociation;} + public int getDetectorID() {return trackDetectorID;} public void addCross(double x, double y, double z, @@ -158,6 +162,10 @@ public Line3D getFirstCross(){ return trackCrosses.get(0); } + public int getTrackIndex() { + return this.trackIndex; + } + public Line3D getLastCross(){ return this.trackCrosses.get(this.trackCrosses.size()-1); } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/ScintillatorResponse.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/ScintillatorResponse.java index 35dd1d8649..5c700a1bb3 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/ScintillatorResponse.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/ScintillatorResponse.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.clas.detector; import java.util.ArrayList; @@ -18,7 +13,6 @@ */ public class ScintillatorResponse extends DetectorResponse { - public ScintillatorResponse(){ super(); } @@ -27,7 +21,6 @@ public ScintillatorResponse(int sector, int layer, int component){ this.getDescriptor().setSectorLayerComponent(sector, layer, component); } - public static List readHipoEvent(DataEvent event, String bankName, DetectorType type){ List responseList = new ArrayList(); @@ -50,9 +43,7 @@ public static List readHipoEvent(DataEvent event, responseList.add(response); } } - return responseList; } - } diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/TaggerResponse.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/TaggerResponse.java index 001d9c53cb..41cf928e07 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/TaggerResponse.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/TaggerResponse.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.clas.detector; import java.util.ArrayList; @@ -23,25 +18,37 @@ */ public class TaggerResponse { - private double hitTime = 0.0; + + + + private double hitTime = 0.0; private int hitID = -1; - private int hitCharge = -1; - private double hitEnergy = 0.0; - private int association = -1; + private int hitSize = -1; + private double hitRadius = 0.0; + private double hitEnergy = 0.0; + private int association = -1; + private int hitIndex = -1; + private DetectorDescriptor descriptor = new DetectorDescriptor(); private Vector3D hitMomentum = new Vector3D(); - - public TaggerResponse setTime(double time) { hitTime = time; return this;} + private Point3D hitPosition = new Point3D(); + private Point3D hitWidth = new Point3D(); + public void setID(int id){ hitID = id;} - public void setCharge(int q){hitCharge = q;} + public void setTime(double time) {hitTime = time;} + public void setSize(int q){hitSize = q;} public void setEnergy(double energy) { hitEnergy = energy;} public void setAssociation(int assoc) {this.association = assoc;} + public void setHitIndex(int index) {this.hitIndex = index;} + public void setRadius(double r) {hitRadius = r;} - public int getCharge(){return hitCharge;} + public int getSize(){return hitSize;} public int getID(){return hitID;} public double getTime(){ return hitTime;} public double getEnergy(){ return hitEnergy;} public int getAssociation() {return this.association;} + public int getHitIndex() {return this.hitIndex;} + public double getRadius() {return this.hitRadius;} public Vector3D getMomentum(){ return this.hitMomentum; @@ -51,29 +58,48 @@ public void setMomentum(double px, double py, double pz){ this.hitMomentum.setXYZ(px, py, pz); } - + public Point3D getPosition(){ + return this.hitPosition; + } + + public void setPosition(double x, double y, double z){ + this.hitPosition.set(x, y, z); + } + + public Point3D getPositionWidth(){ + return this.hitPosition; + } + public void setPositionWidth(double x, double y, double z){ + this.hitWidth.set(x, y, z); + } + public static List readHipoEvent(DataEvent event, - String bankName){ + String bankName, DetectorType type){ List responseList = new ArrayList(); if(event.hasBank(bankName)==true){ DataBank bank = event.getBank(bankName); int nrows = bank.rows(); for(int row = 0; row < nrows; row++){ int id = bank.getInt("id", row); - int charge = bank.getInt("charge", row); - float cx = bank.getFloat("cx",row); - float cy = bank.getFloat("cy",row); - float cz = bank.getFloat("cz",row); - float time = bank.getFloat("time",row); - float energy = bank.getFloat("energy",row); - TaggerResponse ft = new TaggerResponse(); - ft.setCharge(charge); - ft.setID(id); - ft.setEnergy(energy); - ft.setTime(time); - ft.setMomentum(cx*energy, cy*energy, cz*energy); - //System.out.println("FT Energy " + energy); + int size = bank.getInt("size", row); + double x = bank.getFloat("x",row); + double y = bank.getFloat("y",row); + double z = bank.getFloat("z",row); + double dx = bank.getFloat("widthX",row); + double dy = bank.getFloat("widthY",row); + double radius = bank.getFloat("radius", row); + double time = bank.getFloat("time",row); + double energy = bank.getFloat("energy",row); + TaggerResponse ft = new TaggerResponse(); + + ft.setSize(size); + ft.setID(id); + ft.setEnergy(energy); + ft.setRadius(radius); + ft.setTime(time); + ft.setHitIndex(row); + ft.setPosition(x, y, z); responseList.add(ft); } } diff --git a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ParticleReconstruction.java b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ParticleReconstruction.java index 7aba7c991a..7a90fed29f 100644 --- a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ParticleReconstruction.java +++ b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ParticleReconstruction.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.monitor.eb; import org.jlab.clas.pdg.PDGDatabase; diff --git a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReactionAnalysis.java b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReactionAnalysis.java index fdf037dfa8..0fd5be8fc4 100644 --- a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReactionAnalysis.java +++ b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReactionAnalysis.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.monitor.eb; import org.jlab.clas.physics.EventFilter; diff --git a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReconstructionMonitor.java b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReconstructionMonitor.java index 0cc7fe56ec..c0a3c882de 100644 --- a/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReconstructionMonitor.java +++ b/reconstruction/eb/src/main/java/org/jlab/monitor/eb/ReconstructionMonitor.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.monitor.eb; import java.util.ArrayList; diff --git a/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBCCDBConstants.java b/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBCCDBConstants.java new file mode 100644 index 0000000000..257819131b --- /dev/null +++ b/reconstruction/eb/src/main/java/org/jlab/rec/eb/EBCCDBConstants.java @@ -0,0 +1,220 @@ +package org.jlab.rec.eb; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + +import org.jlab.detector.calib.utils.ConstantsManager; +import org.jlab.utils.groups.IndexedTable; +import org.jlab.geom.prim.Vector3D; + +public class EBCCDBConstants { + + public static boolean LOADED = false; + + public static final String ebTablePrefix="/calibration/eb/"; + + public static final String[] ebTableNames={ + "electron_sf", + "photon_sf", + "neutron_beta", + "pid", + "ecal_matching", + "ftof_matching", + "ctof_matching", + "cnd_matching", + "htcc_matching", + "ltcc_matching" + }; + + public static final String[] otherTableNames={ + "/geometry/target", + "/calibration/rf/offset" + }; + + public static List getAllTableNames() { + List ret=new ArrayList (); + for (String ss : ebTableNames) ret.add(ebTablePrefix+ss); + for (String ss : otherTableNames) ret.add(ss); + return ret; + } + + private static Map tables = new HashMap(); + private static Map dbDoubles = new HashMap(); + private static Map dbIntegers = new HashMap(); + private static Map dbVector3Ds = new HashMap(); + private static Map dbArrays = new HashMap(); + + static EBDatabaseConstantProvider DBP = new EBDatabaseConstantProvider(10,"default"); + + // fill maps: + public static synchronized void setDouble(EBCCDBEnum key,Double value) { + dbDoubles.put(key,value); + } + public static synchronized void setVector3D(EBCCDBEnum key,Vector3D value) { + dbVector3Ds.put(key,value); + } + public static synchronized void setInteger(EBCCDBEnum key,int value) { + dbIntegers.put(key,value); + } + public static synchronized void setArray(EBCCDBEnum key,Double[] value) { + dbArrays.put(key,value); + } + + // read maps: + public static synchronized double getDouble(EBCCDBEnum key) { + if (!dbDoubles.containsKey(key)) + throw new RuntimeException("Missing Double Key: "+key); + return dbDoubles.get(key); + } + public static synchronized Vector3D getVector3D(EBCCDBEnum key) { + if (!dbVector3Ds.containsKey(key)) + throw new RuntimeException("Missing Vector3D Key: "+key); + return dbVector3Ds.get(key); + } + public static synchronized int getInteger(EBCCDBEnum key) { + if (!dbIntegers.containsKey(key)) + throw new RuntimeException("Missing Integer Key: "+key); + return dbIntegers.get(key); + } + public static synchronized Double[] getArray(EBCCDBEnum key) { + if (!dbArrays.containsKey(key)) + throw new RuntimeException("Missing Integer Key: "+key); + return dbArrays.get(key); + } + + // read ccdb tables: + private static synchronized void loadTable( + int run, + ConstantsManager manager, + String fullTableName) { + tables.put(fullTableName,manager.getConstants(run,fullTableName)); + } + private static synchronized void loadEbTable( + int run, + ConstantsManager manager, + String shortTableName) { + tables.put(shortTableName,manager.getConstants(run,ebTablePrefix+shortTableName)); + } + + // read ccdb values, fill maps: + private static synchronized void loadDouble( + EBCCDBEnum key, + String tableName, + String columnName, + int sector,int layer,int component) { + double value=tables.get(tableName).getDoubleValue(columnName,sector,layer,component); + setDouble(key,value); + } + private static synchronized void loadInteger( + EBCCDBEnum key, + String tableName, + String columnName, + int sector,int layer,int component) { + int value=tables.get(tableName).getIntValue(columnName,sector,layer,component); + setInteger(key,value); + } + private static synchronized void loadVector3D( + EBCCDBEnum key, + String tableName, + String colName1, String colName2, String colName3, + int sector,int layer,int component) { + double val1=tables.get(tableName).getDoubleValue(colName1,sector,layer,component); + double val2=tables.get(tableName).getDoubleValue(colName2,sector,layer,component); + double val3=tables.get(tableName).getDoubleValue(colName3,sector,layer,component); + setVector3D(key,new Vector3D(val1,val2,val3)); + } + private static synchronized void loadArray( + EBCCDBEnum key, + String tableName, + String[] colNames, + int sector,int layer,int component) { + Double vals[]=new Double[colNames.length]; + for (int ii=0; ii integerContainer=new HashMap(); + private HashMap doubleContainer=new HashMap(); + + EBDatabaseConstantProvider() { super(); } + EBDatabaseConstantProvider(int run, String var) { super(run,var); } + + int createIntegers (String table,int key) { + final int len=this.length(table); + Integer vals[]=new Integer[len]; + for (int ii=0; ii0){ - DetectorParticle trigger = event.getParticle(0); + + // abort, rely on default init of DetectorEvent: + if (event.getParticles().size() <= 0) return; + + // first particle is designated as the "trigger" particle: + // TODO: reference the code that actually does the sorting + DetectorParticle trigger = event.getParticle(0); + + // priority is to identify a trigger time: + boolean foundTriggerTime=false; + double startTime=-1000; + + // electron/positron is trigger particle: + if (trigger.getPid()==11 || trigger.getPid()==-11) { + + trigger.setBeta(1.0); + trigger.setMass(PhysicsConstants.massElectron()); + + double time = 0.0; + double path = 0.0; + + // TODO: get these hardcoded FTOF "layer" 1/2/3 constants out of here. + // Should be from DetectorType instead, and similarly for for ECAL/PCAL's 1/4/7 (e.g. in EBCCDB) - //System.out.println(" trigger pid = " + trigger.getPid()); - if(trigger.getPid()==11 || trigger.getPid()==-11){ - trigger.setBeta(1.0); - trigger.setMass(0.0005); - - double time = 0.0; - double path = 0.0; - - if(trigger.hasHit(DetectorType.FTOF, 1)==true){ - //System.out.println("There is a FTOF1A hit!!!"); - time = trigger.getTime(DetectorType.FTOF, 1); - path = trigger.getPathLength(DetectorType.FTOF, 1); - } - - if(trigger.hasHit(DetectorType.FTOF, 2)==true){ - //System.out.println("There is a FTOF1B hit!!!"); - time = trigger.getTime(DetectorType.FTOF, 2); - path = trigger.getPathLength(DetectorType.FTOF, 2); - } + // prefer FTOF Panel 1B: + if (trigger.hasHit(DetectorType.FTOF, 2)==true){ + time = trigger.getTime(DetectorType.FTOF, 2); + path = trigger.getPathLength(DetectorType.FTOF, 2); + foundTriggerTime = true; + } + + // else use FTOF Panel 1A: + else if (trigger.hasHit(DetectorType.FTOF, 1)==true){ + time = trigger.getTime(DetectorType.FTOF, 1); + path = trigger.getPathLength(DetectorType.FTOF, 1); + foundTriggerTime = true; + } - double tof = path/EBConstants.SPEED_OF_LIGHT; + // set startTime based on FTOF: + if (foundTriggerTime) { + double tof = path/PhysicsConstants.speedOfLight(); double start_time = time - tof; - double deltatr = - start_time + event.getEventHeader().getRfTime() /* - (trigger.vertex().z() - - (EBConstants.TARGET_POSITION))/(EBConstants.SPEED_OF_LIGHT)*/ - + (EBConstants.RF_LARGE_INTEGER+0.5)*EBConstants.RF_BUCKET_LENGTH + EBConstants.RF_OFFSET; + double deltatr = - start_time + event.getEventHeader().getRfTime() + + (EBConstants.RF_LARGE_INTEGER+0.5)*EBConstants.RF_BUCKET_LENGTH + EBConstants.RF_OFFSET; + //double deltatr = - start_time + event.getEventHeader().getRfTime() /* - (trigger.vertex().z() + // - (EBConstants.TARGET_POSITION))/(PhysicsConstants.speedOfLight())*/ + // + (EBConstants.RF_LARGE_INTEGER+0.5)*EBConstants.RF_BUCKET_LENGTH + EBConstants.RF_OFFSET; double rfcorr = deltatr%EBConstants.RF_BUCKET_LENGTH - EBConstants.RF_BUCKET_LENGTH/2;//RF correction term - event.getEventHeader().setStartTime(start_time + rfcorr); - //System.out.println(event.getEventHeader().getRfTime() - start_time); - //System.out.println(rfcorr + " " + (124.25- time + tof)); - //System.out.println(" TIME = " + tof + " time from TOF = " + time); - //System.out.println(" PATH = " + path + " " ); - //System.out.println(" SET START TIME = " + start_time + " ACTUAL TIME = " + event.getEventHeader().getStartTime()); - - //System.out.println(start_time - event.getEventHeader().getRfTime()); - - this.assignMasses(event); - this.assignPids(event); - - + startTime = start_time + rfcorr; } - - if(trigger.getPid()==0 || trigger.getPid()==22) { - - event.getEventHeader().setStartTime(124.25); - this.assignMasses(event); - this.assignPids(event); - - } - } + + // neutral is trigger particle: + else if (trigger.getPid()==0 || trigger.getPid()==22) { + trigger.setBeta(1.0); + trigger.setMass(0.0); + // TODO: implement full neutral trigger start time + //startTime = EBConstants.GEMC_STARTTIME; + //foundTriggerTime=true; + } + + // trigger particle is unkown: + else { + } + + // we found event start time, so set it and do pid: + if (foundTriggerTime) { + event.getEventHeader().setStartTime(startTime); + this.assignMasses(event); + this.assignPids(event); + } + } - - + + public void assignMasses(DetectorEvent event){ - + int np = event.getParticles().size(); - //System.out.println("======================= ANALYSIS"); for(int i = 1; i < np; i++) { DetectorParticle p = event.getParticle(i); double start_time = event.getEventHeader().getStartTime(); double beta = 0.0; double mass = 0.0; - + if(p.hasHit(DetectorType.FTOF, 1)==true){ - //System.out.println("1A"); beta = p.getBeta(DetectorType.FTOF,1, start_time); mass = p.getMass2(DetectorType.FTOF,1, start_time); p.setBeta(beta); - - //System.out.println(String.format("PARTICLE %3d (Layer 1) p = %8.3f beta = %8.3f mass2 = %8.3f", - // i,p.vector().mag(),beta,mass)); } if(p.hasHit(DetectorType.FTOF, 2)==true){ - //System.out.println("1B"); beta = p.getBeta(DetectorType.FTOF, 2,start_time); mass = p.getMass2(DetectorType.FTOF, 2,start_time); p.setBeta(beta); - //System.out.println(String.format("PARTICLE %3d (Layer 2) p = %8.3f beta = %8.3f mass2 = %8.3f", - // i,p.vector().mag(),beta,mass)); } if(p.hasHit(DetectorType.CTOF, 0)==true){ -// //System.out.println("CTOF"); beta = p.getBeta(DetectorType.CTOF ,start_time); mass = p.getMass2(DetectorType.CTOF,start_time); p.setBeta(beta); -// //System.out.println(String.format("PARTICLE %3d (Layer 2) p = %8.3f beta = %8.3f mass2 = %8.3f", -// // i,p.vector().mag(),beta,mass)); } - //System.out.println("----------------"); - - - - //p.getBeta(DetectorType.BST, start_time) } } - + public void assignPids(DetectorEvent event) { int np = event.getParticles().size(); PIDHypothesis pidHyp = new PIDHypothesis(); @@ -134,12 +133,10 @@ public void assignPids(DetectorEvent event) { if(p.getCharge()==0) break; if(p.getCharge()>0){ for(int b = 0; b < this.pidPositive.length; b++){ - //System.out.println(this.pidPositive[b]); pidHyp.setEvent(event); pidHyp.PIDMatch(p, this.pidPositive[b]); //pidHyp.PIDQuality(p,this.pidPositive[b],event); } - //p.setPid(pidHyp.get(0).getPid()); } else { for(int b = 0; b < this.pidNegative.length; b++){ @@ -148,51 +145,44 @@ public void assignPids(DetectorEvent event) { //pidHyp.PIDQuality(p, this.pidNegative[b],event); } //Collections.sort(pidHyp); - // System.out.println(pidHyp.get(0).getPid()); //p.setPid(pidHyp.get(0).getPid()); } - //System.out.println(" "); } } - -public class PIDHypothesis { - + + public class PIDHypothesis { + private int theoryPID = -1; private double PIDquality = 0.0; private DetectorEvent event; - - - + public PIDHypothesis() { - - } - + + } + public void setEvent(DetectorEvent e) {event = e;} - + public void PIDMatch(DetectorParticle p, int pid) { - + double beta = p.getTheoryBeta(pid); double vertex_index = optimalVertexTime(p); - + int pidCandidate = pid; boolean vertexCheck = (abs(pid)==211 && vertex_index==1 && p.getBeta()>0.0) || - (abs(pid)==2212 && vertex_index==0 && p.getBeta()>0.0) || - (abs(pid)==321 && vertex_index==2 && p.getBeta()>0.0); + (abs(pid)==2212 && vertex_index==0 && p.getBeta()>0.0) || + (abs(pid)==321 && vertex_index==2 && p.getBeta()>0.0); boolean sfCheck = p.getEnergyFraction(DetectorType.EC)>EBConstants.ECAL_SAMPLINGFRACTION_CUT; boolean htccSignalCheck = p.getNphe(DetectorType.HTCC)>EBConstants.HTCC_NPHE_CUT; boolean ltccSignalCheck = p.getNphe(DetectorType.LTCC)>EBConstants.LTCC_NPHE_CUT; boolean htccPionThreshold = p.vector().mag()>EBConstants.HTCC_PION_THRESHOLD; boolean ltccPionThreshold = p.vector().mag()EBConstants.LTCC_LOWER_PION_THRESHOLD; - -// System.out.println(sfCheck + " " + htccSignalCheck); - + && p.vector().mag()>EBConstants.LTCC_LOWER_PION_THRESHOLD; + switch(abs(pid)) { case 11: if(htccSignalCheck==true && sfCheck==true){ - //System.out.println("Positron detected"); this.finalizePID(p, pid); break; } @@ -205,22 +195,22 @@ public void PIDMatch(DetectorParticle p, int pid) { && htccPionThreshold==true) { this.finalizePID(p, pid); break; - } + } if(vertexCheck==false && htccSignalCheck==true && sfCheck==false && htccPionThreshold==true) { this.finalizePID(p, pid); break; - } + } if(vertexCheck==true && ltccSignalCheck==true && sfCheck==false && ltccPionThreshold==true) { this.finalizePID(p, pid); break; - } + } if(vertexCheck==false && ltccSignalCheck==true && sfCheck==false && ltccPionThreshold==true) { this.finalizePID(p, pid); break; - } + } case 321: if(vertexCheck==true && sfCheck==false && htccSignalCheck==false){ this.finalizePID(p, pid); @@ -234,39 +224,39 @@ public void PIDMatch(DetectorParticle p, int pid) { } } - + public int optimalVertexTime(DetectorParticle p) { int vertex_index = 0; HashMap vertexDiffs = new HashMap(); double vertex_time_hypothesis = 0.0; double event_start_time = event.getEventHeader().getStartTime(); - + if(p.hasHit(DetectorType.FTOF,1)==true) { - vertexDiffs.put(0,abs(p.getVertexTime(DetectorType.FTOF, 1, 2212)-event_start_time)); - vertexDiffs.put(1,abs(p.getVertexTime(DetectorType.FTOF, 1, 211)-event_start_time)); - vertexDiffs.put(2,abs(p.getVertexTime(DetectorType.FTOF, 1, 321)-event_start_time)); + vertexDiffs.put(0,abs(p.getVertexTime(DetectorType.FTOF, 1, 2212)-event_start_time)); + vertexDiffs.put(1,abs(p.getVertexTime(DetectorType.FTOF, 1, 211)-event_start_time)); + vertexDiffs.put(2,abs(p.getVertexTime(DetectorType.FTOF, 1, 321)-event_start_time)); } - + if(p.hasHit(DetectorType.FTOF,2)==true) { - vertexDiffs.put(0,abs(p.getVertexTime(DetectorType.FTOF, 2, 2212)-event_start_time)); - vertexDiffs.put(1,abs(p.getVertexTime(DetectorType.FTOF, 2, 211)-event_start_time)); - vertexDiffs.put(2,abs(p.getVertexTime(DetectorType.FTOF, 2, 321)-event_start_time)); + vertexDiffs.put(0,abs(p.getVertexTime(DetectorType.FTOF, 2, 2212)-event_start_time)); + vertexDiffs.put(1,abs(p.getVertexTime(DetectorType.FTOF, 2, 211)-event_start_time)); + vertexDiffs.put(2,abs(p.getVertexTime(DetectorType.FTOF, 2, 321)-event_start_time)); } - + if(vertexDiffs.size()>0) { - double min = vertexDiffs.get(0); + double min = vertexDiffs.get(0); - for (int i = 0; i <= 2; i++) { - if (vertexDiffs.get(i) < min) { - min = vertexDiffs.get(i); - vertex_index = i; + for (int i = 0; i <= 2; i++) { + if (vertexDiffs.get(i) < min) { + min = vertexDiffs.get(i); + vertex_index = i; + } } } - } return vertex_index; } - - + + public double PIDQuality(DetectorParticle p, int pid, DetectorEvent event) { double delta_t = abs(p.getVertexTime(DetectorType.FTOF, 2, pid)-event.getEventHeader().getStartTime()); double sigma = 0.08; @@ -274,21 +264,16 @@ public double PIDQuality(DetectorParticle p, int pid, DetectorEvent event) { return q; } - + public void finalizePID(DetectorParticle p, int pid) { - p.setPid(pid); - theoryPID = pid; - PIDquality = this.PIDQuality(p, pid, event); - p.setPidQuality(PIDquality); + p.setPid(pid); + theoryPID = pid; + PIDquality = this.PIDQuality(p, pid, event); + p.setPidQuality(PIDquality); } - - - - } - } diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java index bd77c85468..92504fd6c4 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBEngine.java @@ -1,11 +1,6 @@ -/* - * 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.service.eb; - +import java.util.Arrays; import java.util.List; import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.io.base.DataEvent; @@ -13,6 +8,8 @@ import org.jlab.detector.base.DetectorType; import org.jlab.io.base.DataBank; import org.jlab.clas.detector.CherenkovResponse; +import org.jlab.rec.eb.EBCCDBConstants; +import org.jlab.rec.eb.EBCCDBEnum; /** * @@ -30,12 +27,13 @@ public class EBEngine extends ReconstructionEngine { String crossBank = null; String matrixBank = null; String trackType = null; + String ftBank = null; public EBEngine(String name){ super(name,"gavalian","1.0"); initBankNames(); } - + public void initBankNames() { //Initialize bank names } @@ -53,9 +51,9 @@ public boolean processDataEvent(DataEvent de) { List responseCTOF = ScintillatorResponse.readHipoEvent(de, "CTOF::hits", DetectorType.CTOF); List responseHTCC = CherenkovResponse.readHipoEvent(de,"HTCC::rec",DetectorType.HTCC); - List responseLTCC = CherenkovResponse.readHipoEvent(de,"LTCC::rec",DetectorType.LTCC); + List responseLTCC = CherenkovResponse.readHipoEvent(de,"LTCC::clusters",DetectorType.LTCC); - List trackFT = TaggerResponse.readHipoEvent(de, "FT::particles"); + List trackFT = TaggerResponse.readHipoEvent(de, "FTCAL::clusters", DetectorType.FTCAL); eb.addDetectorResponses(responseFTOF); eb.addDetectorResponses(responseCTOF); @@ -63,52 +61,36 @@ public boolean processDataEvent(DataEvent de) { eb.addCherenkovResponses(responseHTCC); eb.addCherenkovResponses(responseLTCC); - - - // Add tracks List tracks = DetectorData.readDetectorTracks(de, trackType); - eb.addTracks(tracks); + eb.addForwardTracks(tracks); List ctracks = DetectorData.readCentralDetectorTracks(de, "CVTRec::Tracks"); - eb.addTracks(ctracks); - - + eb.addCentralTracks(ctracks); + // Process tracks: eb.processHitMatching(); eb.addTaggerTracks(trackFT); - eb.processNeutralTracks(); + eb.processNeutralTracks(); + eb.assignTrigger(); + // Process RF: EBRadioFrequency rf = new EBRadioFrequency(); eb.getEvent().getEventHeader().setRfTime(rf.getTime(de)+EBConstants.RF_OFFSET); - //eb.getEvent().setRfTime(rf); - - //System.out.println(eb.getEvent().toString()); - - -// for(int i = 0; i < eb.getEvent().getParticles().size(); i++) { -// System.out.println("Particle " + i); -// for(int j = 0 ; j < eb.getEvent().getParticles().get(i).getDetectorResponses().size() ; j++){ -// System.out.println("Point " + eb.getEvent().getParticles().get(i).getDetectorResponses().get(j).getMatchedDistance()); -// } -// } - + // Do PID etc: EBAnalyzer analyzer = new EBAnalyzer(); - //System.out.println("analyzing"); analyzer.processEvent(eb.getEvent()); - - - //System.out.println(eb.getEvent().toString()); - - - + // create REC:detector banks: if(eb.getEvent().getParticles().size()>0){ + DataBank bankP = DetectorData.getDetectorParticleBank(eb.getEvent().getParticles(), de, particleBank); de.appendBanks(bankP); + DataBank bankEve = DetectorData.getEventBank(eb.getEvent(), de, eventBank); de.appendBanks(bankEve); + List calorimeters = eb.getEvent().getCalorimeterResponseList(); if(calorimeterBank!=null && calorimeters.size()>0) { DataBank bankCal = DetectorData.getCalorimeterResponseBank(calorimeters, de, calorimeterBank); @@ -124,6 +106,17 @@ public boolean processDataEvent(DataEvent de) { DataBank bankChe = DetectorData.getCherenkovResponseBank(cherenkovs, de, cherenkovBank); de.appendBanks(bankChe); } + + if (ftBank!=null && trackFT.size()>0) { + DataBank bankForwardTagger = DetectorData.getForwardTaggerBank(eb.getEvent().getParticles(), de, trackBank, trackFT.size()); + de.appendBanks(bankForwardTagger); + } + + if (trackBank!=null && tracks.size()>0) { + DataBank bankTrack = DetectorData.getTracksBank(eb.getEvent().getParticles(), de, trackBank, tracks.size()); + de.appendBanks(bankTrack); + } + if(matrixBank!=null) { DataBank bankMat = DetectorData.getTBCovMatBank(eb.getEvent().getParticles(), de, matrixBank); de.appendBanks(bankMat); @@ -157,6 +150,10 @@ public void setCherenkovBank(String cherenkovBank) { public void setTrackBank(String trackBank) { this.trackBank = trackBank; } + + public void setFTBank(String ftBank) { + this.ftBank = ftBank; + } public void setCrossBank(String crossBank) { this.crossBank = crossBank; @@ -170,6 +167,17 @@ public void setTrackType(String trackType) { @Override public boolean init() { + + // load EB constants from CCDB: + requireConstants(EBCCDBConstants.getAllTableNames()); + this.getConstantsManager().setVariation("default"); + // FIXME: check run number in processDataEvent, reload from CCDB if changed. + // For now we just use hard-coded run number: + EBCCDBConstants.load(10,this.getConstantsManager()); + + // Example of retrieveing values from EBCCDBConstants: + //Double[] t=EBCCDBConstants.getArray(EBCCDBEnum.ELEC_SF); + System.out.println("[EB::] --> event builder is ready...."); return true; } diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBHBEngine.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBHBEngine.java index fccf3d7cb3..ba260fbec8 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBHBEngine.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBHBEngine.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.service.eb; @@ -27,6 +22,7 @@ public void initBankNames() { this.setTrackBank("RECHB::Track"); this.setCrossBank("RECHB::TrackCross"); this.setTrackType("HitBasedTrkg::HBTracks"); + this.setFTBank("RECHB::ForwardTagger"); } } diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBRadioFrequency.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBRadioFrequency.java index 62cd9a8c98..e629333094 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBRadioFrequency.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBRadioFrequency.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.service.eb; import java.util.ArrayList; diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBTBEngine.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBTBEngine.java index 9d6847f553..e4e1c59a22 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBTBEngine.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBTBEngine.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.service.eb; @@ -27,6 +22,7 @@ public void initBankNames() { this.setTrackBank("REC::Track"); this.setCrossBank("REC::TrackCross"); this.setTrackType("TimeBasedTrkg::TBTracks"); + this.setFTBank("REC::ForwardTagger"); } } diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBio.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBio.java index 59a65112e3..b4796ec7a6 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EBio.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EBio.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.service.eb; import java.util.ArrayList; @@ -89,7 +84,7 @@ public static List readTracks(DataEvent event, int type){ bank.getDouble("c1_uy", i), bank.getDouble("c1_uz", i) ); - // System.out.println(p.getLowerCross()); + // System.out.println(p.getLowerCross()); p.setPath(bank.getDouble("pathlength", i)); p.setCharge(bank.getInt("q", i)); dpList.add(p); @@ -132,8 +127,6 @@ public static List readCentralTracks(DataEvent event){ public static boolean isTimeBased(DataEvent de){ boolean tb = false; - //System.out.println(" HAS BANK = " + de.hasBank("TimeBasedTrkg::TBHits") - //+ " HB = " + de.hasBank("HitBasedTrkg::HBTracks")); if(de.hasBank("TimeBasedTrkg::TBHits")==true){ //de.show(); return true; @@ -223,42 +216,35 @@ public static DataBank writeResponses(List responses, int type } return bank; } - + public static DataBank writeCherenkovResponses(List responses, int type ) { - String bankName = "EVENTHB::particle"; - + String bankName = "EVENTHB::particle"; + switch (type){ case 1 : bankName = "EVENTHB::cherenkov"; break; case 2 : bankName = "EVENTTB::cherenkov"; break; default: break; } EvioDataBank bank = EvioFactory.createBank(bankName, responses.size()); - for(int i = 0; i < responses.size();i++){ + for(int i = 0; i < responses.size();i++){ bank.setInt("pindex", i,responses.get(i).getAssociation()); bank.setInt("index", i,i); - bank.setFloat("X", i, (float) responses.get(i).getHitPosition().x()); bank.setFloat("Y", i, (float) responses.get(i).getHitPosition().y()); bank.setFloat("Z", i, (float) responses.get(i).getHitPosition().z()); - - bank.setFloat("time", i, (float) responses.get(i).getTime()); bank.setFloat("nphe", i, (float) responses.get(i).getEnergy()); - } return bank; } - - public static DataBank writeTrigger(DetectorEvent event){ - String bankName = "Trigger::info"; - + public static DataBank writeTrigger(DetectorEvent event){ + String bankName = "Trigger::info"; EvioDataBank bank = EvioFactory.createBank(bankName, 1); //bank.setDouble("starttime", 0, event.getEventTrigger().getStartTime()); //bank.setDouble("vertextime",0, event.getEventTrigger().getVertexTime()); //bank.setDouble("rftime", 0, event.getEventTrigger().getRFTime()); //bank.setInt("id",0,event.getEventTrigger().getTriggerID()); - return bank; } @@ -267,7 +253,6 @@ public static List readECAL(DataEvent event){ if(event.hasBank("ECDetector::clusters")==true){ EvioDataBank bank = (EvioDataBank) event.getBank("ECDetector::clusters"); int nrows = bank.rows(); - //System.out.println("*************************\n\n\n\n ECAL " + nrows); for(int i = 0; i < nrows; i++){ int sector = bank.getInt("sector", i); int layer = bank.getInt("layer", i); @@ -275,16 +260,13 @@ public static List readECAL(DataEvent event){ resp.getDescriptor().setType(DetectorType.EC); resp.getDescriptor().setSectorLayerComponent(sector, layer, 0); resp.setPosition( - bank.getDouble("X", i),bank.getDouble("Y", i), - bank.getDouble("Z", i) - ); - resp.setTime(bank.getDouble("time", i)); - resp.setEnergy(bank.getDouble("energy", i)); - - ecal.add(resp); + bank.getDouble("X", i),bank.getDouble("Y", i), + bank.getDouble("Z", i) + ); + resp.setTime(bank.getDouble("time", i)); + resp.setEnergy(bank.getDouble("energy", i)); + ecal.add(resp); } - } else { - //System.out.println("\n\n\n\n NO ECAL"); } return ecal; } @@ -308,7 +290,6 @@ public static List readFTOF(DataEvent event){ ); resp.setTime(bank.getFloat("time", i)); resp.setEnergy(bank.getFloat("energy", i)); - ftof.add(resp); } } @@ -331,17 +312,14 @@ public static List readHTCC(DataEvent event) { double x = bank.getDouble("x",i); double y = bank.getDouble("y",i); double z = bank.getDouble("z",i); - // System.out.println(bank.getFloat("x")); double time = bank.getFloat("time",i); - // System.out.println("nphe" + nphe); - CherenkovResponse che = new CherenkovResponse(theta,phi,dtheta,dphi); - che.setHitPosition(x, y, z); - che.setEnergy(nphe); - che.setTime(time); - che.setCherenkovType(DetectorType.HTCC); - // System.out.println(che.getHitPosition()); - htcc.add(che); - + CherenkovResponse che = new CherenkovResponse(theta,phi,dtheta,dphi); + che.setHitPosition(x, y, z); + che.setEnergy(nphe); + che.setTime(time); + che.setCherenkovType(DetectorType.HTCC); + htcc.add(che); + } } return htcc; diff --git a/reconstruction/eb/src/main/java/org/jlab/service/eb/EventBuilder.java b/reconstruction/eb/src/main/java/org/jlab/service/eb/EventBuilder.java index b53df668ee..2b6a6fb8e5 100644 --- a/reconstruction/eb/src/main/java/org/jlab/service/eb/EventBuilder.java +++ b/reconstruction/eb/src/main/java/org/jlab/service/eb/EventBuilder.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.service.eb; import static java.lang.Math.abs; @@ -18,6 +13,7 @@ import org.jlab.clas.detector.CherenkovResponse; import org.jlab.clas.detector.ScintillatorResponse; import org.jlab.clas.detector.TaggerResponse; +import org.jlab.clas.physics.Vector3; import org.jlab.geom.prim.Vector3D; /** @@ -25,17 +21,17 @@ * @author gavalian */ public class EventBuilder { - + private DetectorEvent detectorEvent = new DetectorEvent(); private List detectorResponses = new ArrayList(); private List cherenkovResponses = new ArrayList(); private List taggerResponses = new ArrayList(); private int[] TriggerList = new int[]{11,-11,0}; - + public EventBuilder(){ - + } - + public void initEvent() { detectorEvent.clear(); } @@ -47,7 +43,7 @@ public void initEvent(DetectorHeader head) { public void addDetectorResponses(List responses){ detectorResponses.addAll(responses); } - + public void addCherenkovResponses(List responses){ cherenkovResponses.addAll(responses); } @@ -61,35 +57,28 @@ public void addTaggerResponses(List responses){ * and added to the detector event. * @param tracks */ - //public void addTracks(List tracks){ - - - public void addTracks(List tracks) { + public void addForwardTracks(List tracks) { //for(DetectorTrack track : tracks){ for(int i = 0 ; i < tracks.size(); i++){ DetectorParticle particle = new DetectorParticle(tracks.get(i)); + //particle.setStatus(1); detectorEvent.addParticle(particle); } } - /* - public void addTBTracks(List tracks, List covMatrices) { - detectorEvent.clear(); + public void addCentralTracks(List tracks) { //for(DetectorTrack track : tracks){ for(int i = 0 ; i < tracks.size(); i++){ - DetectorParticle particle = new DetectorParticle(tracks.get(i), covMatrices.get(i)); + DetectorParticle particle = new DetectorParticle(tracks.get(i)); detectorEvent.addParticle(particle); } - - }*/ + } public void addTaggerTracks(List taggers) { //for(DetectorTrack track : tracks){ for(int i = 0 ; i < taggers.size(); i++){ - int charge = taggers.get(i).getCharge(); - int id = taggers.get(i).getID(); - Vector3D momentum = taggers.get(i).getMomentum(); - DetectorParticle particle = new DetectorParticle(id,charge,momentum.x(),momentum.y(),momentum.z()); + DetectorParticle particle = new DetectorParticle(taggers.get(i)); + particle.setStatus(100); detectorEvent.addParticle(particle); } } @@ -104,31 +93,26 @@ public void processHitMatching(){ //List responseFTOF1A = DetectorResponse.getListByLayer(detectorResponses, DetectorType.FTOF, 1); //List responseFTOF1B = DetectorResponse.getListByLayer(detectorResponses, DetectorType.FTOF, 2); - //System.out.println("Detector response store size = " + this.detectorResponses.size()); int np = detectorEvent.getParticles().size(); - //System.out.println("Number of Particles = " + np); for(int n = 0; n < np; n++){ DetectorParticle p = this.detectorEvent.getParticle(n); double quality = 0.0; + /** * Matching tracks to FTOF layer 1A detector. Added to the particle and association is * set with a particle needed. */ - - - int index = p.getDetectorHit(this.detectorResponses, DetectorType.FTOF, 1, EBConstants.FTOF_MATCHING_1A); - //System.out.println("index FTOF-1A = " + index); if(index>=0){ p.addResponse(detectorResponses.get(index), true); detectorResponses.get(index).setAssociation(n); } + /** * Matching tracks to FTOF layer 1B detector. Added to the particle and association is */ index = p.getDetectorHit(this.detectorResponses, DetectorType.FTOF, 2, EBConstants.FTOF_MATCHING_1B); - //System.out.println("index FTOF-1B = " + index); if(index>=0){ p.addResponse(detectorResponses.get(index), true); detectorResponses.get(index).setAssociation(n); @@ -138,34 +122,33 @@ public void processHitMatching(){ * Matching tracks to FTOF layer 2 detector. Added to the particle and association is */ index = p.getDetectorHit(this.detectorResponses, DetectorType.FTOF, 3, EBConstants.FTOF_MATCHING_2); - //System.out.println("index FTOF-1B = " + index); if(index>=0){ p.addResponse(detectorResponses.get(index), true); detectorResponses.get(index).setAssociation(n); } + /** * Matching tracks to CTOF detector. Added to the particle and association is */ index = p.getDetectorHit(this.detectorResponses, DetectorType.CTOF, 0, EBConstants.CTOF_Matching); -// //System.out.println("index CTOF = " + index); if(index>=0){ p.addResponse(detectorResponses.get(index), true); detectorResponses.get(index).setAssociation(n); } + /** * Matching tracks to PCAL (first layer of ECAL) and adding to the particle if reasonable match * is found, and proper association is set. */ - index = p.getDetectorHit(this.detectorResponses, DetectorType.EC, 1, EBConstants.PCAL_MATCHING); - if(index>=0){ p.addResponse(detectorResponses.get(index), true); detectorResponses.get(index).setAssociation(n); //quality = p.getDetectorHitQuality(detectorResponses, index, EBConstants.PCAL_hitRes); //detectorResponses.get(index).setHitQuality(quality); } - + + // Matching tracks to EC Inner: index = p.getDetectorHit(this.detectorResponses, DetectorType.EC, 4, EBConstants.ECIN_MATCHING); if(index>=0){ p.addResponse(detectorResponses.get(index), true); @@ -174,6 +157,7 @@ public void processHitMatching(){ //detectorResponses.get(index).setHitQuality(quality); } + // Matching tracks to EC Outer: index = p.getDetectorHit(this.detectorResponses, DetectorType.EC, 7, EBConstants.ECOUT_MATCHING); if(index>=0){ p.addResponse(detectorResponses.get(index), true); @@ -181,15 +165,16 @@ public void processHitMatching(){ //quality = p.getDetectorHitQuality(detectorResponses, index, EBConstants.ECOUT_hitRes); //detectorResponses.get(index).setHitQuality(quality); } - + + // Matching tracks to HTCC: index = p.getCherenkovSignal(this.cherenkovResponses,DetectorType.HTCC); - //System.out.println("HTCC Matching Index " + index); //double = p.getCherenkovSignalQuality() if(index>=0){ p.addCherenkovResponse(cherenkovResponses.get(index)); cherenkovResponses.get(index).setAssociation(n); } + // Matching tracks to LTCC: index = p.getCherenkovSignal(this.cherenkovResponses,DetectorType.LTCC); //double = p.getCherenkovSignalQuality() if(index>=0){ @@ -201,25 +186,31 @@ public void processHitMatching(){ } public void processNeutralTracks(){ - + + // get all unmatched calorimeter responses: + List responsesPCAL = this.getUnmatchedResponses(detectorResponses, DetectorType.EC, 1); + List responsesECIN = this.getUnmatchedResponses(detectorResponses, DetectorType.EC, 4); + List responsesECOUT = this.getUnmatchedResponses(detectorResponses, DetectorType.EC, 7); + + // FIXME: is this really 1/2/3, or should it really be 1/2/0: + // Critical to use DetectorType for this, instead of hardcoded constants everywhere. + List responsesFTOF1A = this.getUnmatchedResponses(detectorResponses, DetectorType.FTOF, 1); + List responsesFTOF1B = this.getUnmatchedResponses(detectorResponses, DetectorType.FTOF, 2); + List responsesFTOF2 = this.getUnmatchedResponses(detectorResponses, DetectorType.FTOF, 3); - - List responsesPCAL = this.getUnmatchedResponses((List) detectorResponses, DetectorType.EC, 1); - + // setup the empty list of neutral particles: List particles = new ArrayList(); - + + // add a new neutral particle for each unmatched PCAL response: + // TODO: Neutrals should not require any ECAL layer, but just one. for(DetectorResponse r : responsesPCAL){ DetectorParticle p = DetectorParticle.createNeutral(r); particles.add(p); } - List responsesECIN = this.getUnmatchedResponses(detectorResponses, DetectorType.EC, 4); - List responsesECOUT = this.getUnmatchedResponses(detectorResponses, DetectorType.EC, 7); - List responsesFTOF1A = this.getUnmatchedResponses(detectorResponses, DetectorType.FTOF, 1); - List responsesFTOF1B = this.getUnmatchedResponses(detectorResponses, DetectorType.FTOF, 2); - List responsesFTOF2 = this.getUnmatchedResponses(detectorResponses, DetectorType.FTOF, 3); - + for(int i = 0; i < particles.size(); i++){ DetectorParticle p = particles.get(i); + // FIXME: again, layer idices should be gotten from DetectorType int index = p.getDetectorHit(responsesECIN, DetectorType.EC, 4, EBConstants.ECIN_MATCHING); if(index>=0){ p.addResponse(responsesECIN.get(index), true); responsesECIN.get(index).setAssociation(i);} index = p.getDetectorHit(responsesECOUT, DetectorType.EC, 7, EBConstants.ECOUT_MATCHING); @@ -242,13 +233,12 @@ public void processNeutralTracks(){ pz*energy/EBConstants.ECAL_SAMPLINGFRACTION); int calorimeter_count = responsesPCAL.size() + responsesECIN.size() + responsesECOUT.size(); int scintillator_count = responsesFTOF1A.size() + responsesFTOF1B.size() + responsesFTOF2.size(); - if(calorimeter_count>1 && scintillator_count==0){ + if(calorimeter_count>0 && scintillator_count==0){ detectorEvent.addParticle(p); } } detectorEvent.setAssociation(); - //System.out.println(" PCAL RESPONSES = " + responsesPCAL.size()); } public List getUnmatchedResponses(List list, DetectorType type, int layer){ @@ -277,155 +267,151 @@ public void assignTrigger() { int i = 0; boolean hasTrigger=false; while(hasTrigger==false) { - - if(TriggerList[i]==11){ - ElectronTriggerOption electron = new ElectronTriggerOption(); - hasTrigger = electron.assignSoftwareTrigger(detectorEvent); - } - if(TriggerList[i]==-11){ - PositronTriggerOption positron = new PositronTriggerOption(); - hasTrigger= positron.assignSoftwareTrigger(detectorEvent); - } - if(TriggerList[i]==-211){ - NegPionTriggerOption negpion = new NegPionTriggerOption(); - hasTrigger = negpion.assignSoftwareTrigger(detectorEvent); - } - if(TriggerList[i]==211){ - PosPionTriggerOption pospion = new PosPionTriggerOption(); - hasTrigger = pospion.assignSoftwareTrigger(detectorEvent); - } - if(TriggerList[i]==0){ - hasTrigger = true; - } - - - i = i + 1; + + if(TriggerList[i]==11){ + ElectronTriggerOption electron = new ElectronTriggerOption(); + hasTrigger = electron.assignSoftwareTrigger(detectorEvent); + } + if(TriggerList[i]==-11){ + PositronTriggerOption positron = new PositronTriggerOption(); + hasTrigger= positron.assignSoftwareTrigger(detectorEvent); + } + if(TriggerList[i]==-211){ + NegPionTriggerOption negpion = new NegPionTriggerOption(); + hasTrigger = negpion.assignSoftwareTrigger(detectorEvent); + } + if(TriggerList[i]==211){ + PosPionTriggerOption pospion = new PosPionTriggerOption(); + hasTrigger = pospion.assignSoftwareTrigger(detectorEvent); + } + if(TriggerList[i]==0){ + hasTrigger = true; + } + + + i = i + 1; } } - - public DetectorEvent getEvent(){return this.detectorEvent;} - + public void show(){ int np = this.detectorEvent.getParticles().size(); System.out.println(">>>>>>>>> DETECTOR EVENT WITH PARTICLE COUNT # " + np); System.out.println(this.detectorEvent.toString()); - /* - for(int n = 0; n < np; n++){ - System.out.println(detectorEvent.getParticle(n)); - }*/ + //for(int n = 0; n < np; n++){ + // System.out.println(detectorEvent.getParticle(n)); + //} } } - class TriggerOptions { - - public int id; - public int score_requirement; - public int charge; - - TriggerOptions() { - initID(); - } - - public void initID() { - //Initialize parameters - } - - public void setID(int pid) { - this.id = pid; - } - - public void setScoreRequirement(int sc) { - this.score_requirement = sc; - } - - public void setCharge(int ch) { - this.charge = ch; - } - - public boolean assignSoftwareTrigger(DetectorEvent event) { - boolean flag = false; - int npart = event.getParticles().size(); - for(int i = 0; i < npart; i++){ - DetectorParticle p = event.getParticle(i); - if(p.getSoftwareTriggerScore()>=this.score_requirement) { //Possible Electron - //System.out.println("The requirements is " + this.score_requirement); - if(this.charge==p.getCharge()){ - p.setPid(this.id); - } - - - } - } - - int index = -1; - double best_p = 0.0; - for(int i = 0; i < npart; i++){ - if(event.getParticle(i).getPid()==this.id){ - if(event.getParticle(i).vector().mag()>best_p){ //Sorting the Momentum - best_p = event.getParticle(i).vector().mag(); - index = i; - } +class TriggerOptions { + + public int id; + public int score_requirement; + public int charge; + + TriggerOptions() { + initID(); + } + + public void initID() { + //Initialize parameters + } + + public void setID(int pid) { + this.id = pid; + } + + public void setScoreRequirement(int sc) { + this.score_requirement = sc; + } + + public void setCharge(int ch) { + this.charge = ch; + } + + public boolean assignSoftwareTrigger(DetectorEvent event) { + boolean flag = false; + int npart = event.getParticles().size(); + for(int i = 0; i < npart; i++){ + DetectorParticle p = event.getParticle(i); + if(p.getSoftwareTriggerScore()>=this.score_requirement) { //Possible Electron + //System.out.println("The requirements is " + this.score_requirement); + if(this.charge==p.getCharge()){ + p.setPid(this.id); } } - - if(index>0){ - event.moveUp(index); - if(event.getParticle(0).getPid()==this.id){ - flag = true; - } - } - + } - return flag; + + int index = -1; + double best_p = 0.0; + for(int i = 0; i < npart; i++){ + if(event.getParticle(i).getPid()==this.id){ + if(event.getParticle(i).vector().mag()>best_p){ //Sorting the Momentum + best_p = event.getParticle(i).vector().mag(); + index = i; + } } + } + if(index>0){ + event.moveUp(index); + if(event.getParticle(0).getPid()==this.id){ + flag = true; + } } - class ElectronTriggerOption extends TriggerOptions { - - @Override - public void initID() { - this.setID(11); - this.setScoreRequirement(110); - this.setCharge(-1); - } - - } - - class PositronTriggerOption extends TriggerOptions { - - @Override - public void initID() { - this.setID(-11); - this.setScoreRequirement(110); - this.setCharge(1); - } - - } - - class NegPionTriggerOption extends TriggerOptions { - - @Override - public void initID() { - this.setID(-211); - this.setScoreRequirement(10); - this.setCharge(-1); - } - - } - - class PosPionTriggerOption extends TriggerOptions { - - @Override - public void initID() { - this.setID(211); - this.setScoreRequirement(10); - this.setCharge(1); - } - - } + + return flag; + } + +} + +class ElectronTriggerOption extends TriggerOptions { + + @Override + public void initID() { + this.setID(11); + this.setScoreRequirement(110); + this.setCharge(-1); + } + +} + +class PositronTriggerOption extends TriggerOptions { + + @Override + public void initID() { + this.setID(-11); + this.setScoreRequirement(110); + this.setCharge(1); + } + +} + +class NegPionTriggerOption extends TriggerOptions { + + @Override + public void initID() { + this.setID(-211); + this.setScoreRequirement(10); + this.setCharge(-1); + } + +} + +class PosPionTriggerOption extends TriggerOptions { + + @Override + public void initID() { + this.setID(211); + this.setScoreRequirement(10); + this.setCharge(1); + } + +} diff --git a/validation/advanced-tests/.gitignore b/validation/advanced-tests/.gitignore new file mode 100644 index 0000000000..b038532423 --- /dev/null +++ b/validation/advanced-tests/.gitignore @@ -0,0 +1,11 @@ +/clara_installation +/cook.clara +/files.list +/*.hipo +/*.evio +/*.evio.tar.gz +/*.evio.gz +/*.hipo.gz +/*.hipo +/coatjava-local.tar.gz + diff --git a/validation/advanced-tests/run-eb-tests.sh b/validation/advanced-tests/run-eb-tests.sh new file mode 100755 index 0000000000..94cbb6b124 --- /dev/null +++ b/validation/advanced-tests/run-eb-tests.sh @@ -0,0 +1,100 @@ +#!/bin/sh -f + +# coatjava must already be built at ../../coatjava/ + +# if first argument is -t, only run the test, +# don't redownload dependencies, don't run reconstruction. +runTestOnly=0 +if [ "$1" = "-t" ] +then + runTestOnly=1 +fi + +# last argument is input file stub: +webFileStub="${@: -1}" +case $webFileStub in + electronproton) + ;; + electronkaon) + ;; + electronpion) + ;; + *) + echo Invalid input evio file: $webFileStub + exit 1 +esac + +# set up environment +CLARA_HOME=$PWD/clara_installation/ ; export CLARA_HOME + +# Do NOT use whatever clas12 libraries come with CLARA for testing: +#COAT=$CLARA_HOME/plugins/clas12/ + +# Use the ones in this clas12 build for testing: +COAT=../../coatjava + +classPath="$COAT/lib/services/*:$COAT/lib/clas/*:$COAT/lib/utils/*:../lib/*:src/" + +webDir=http://clasweb.jlab.org/clas12offline/distribution/coatjava/validation_files/eb/v0/ + + +# compile test codes before anything else: +javac -cp $classPath src/eb/EBTwoTrackTest.java +if [ $? != 0 ] ; then echo "EBTwoTrackTest compilation failure" ; exit 1 ; fi + +# download and setup dependencies, run reconstruction: +if [ $runTestOnly -eq 0 ] +then + # tar the local coatjava build so it can be installed with clara + cd ../.. + tar -zcvf coatjava-local.tar.gz coatjava + mv coatjava-local.tar.gz validation/advanced-tests/ + cd - + + # install clara + if ! [ -d clara_installation ] + then + wget --no-check-certificate https://claraweb.jlab.org/clara/_downloads/install-claracre-clas.sh + chmod +x install-claracre-clas.sh + ./install-claracre-clas.sh -l local + if [ $? != 0 ] ; then echo "clara installation error" ; exit 1 ; fi + rm install-claracre-clas.sh + fi + + # download test files + if ! [ -e ${webFileStub}.evio.gz ] + then + wget --no-check-certificate $webDir/${webFileStub}.evio.gz + if [ $? != 0 ] ; then echo "wget validation files failure" ; exit 1 ; fi + gunzip -f ${webFileStub}.evio.gz + fi + + rm -f ${webFileStub}.hipo + rm -f out_${webFileStub}.hipo + + # convert to hipo + $COAT/bin/evio2hipo -o ${webFileStub}.hipo ${webFileStub}.evio + + # run reconstruction without clara + ../../coatjava/bin/notsouseful-util -i ${webFileStub}.hipo -o out_${webFileStub}.hipo -c 2 + + # run reconstruction with clara + #echo "set inputDir $PWD/" > cook.clara + #echo "set outputDir $PWD/" >> cook.clara + #echo "set threads 7" >> cook.clara + #echo "set javaMemory 2" >> cook.clara + #echo "set session s_cook" >> cook.clara + #echo "set description d_cook" >> cook.clara + #ls ${webFileStub}.hipo > files.list + #echo "set fileList $PWD/files.list" >> cook.clara + #echo "run local" >> cook.clara + #echo "exit" >> cook.clara + #$CLARA_HOME/bin/clara-shell cook.clara +fi + +# run KppTracking junit tests +java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath -DINPUTFILE=out_${webFileStub}.hipo org.junit.runner.JUnitCore eb.EBTwoTrackTest +if [ $? != 0 ] ; then echo "EBTwoTrackTest unit test failure" ; exit 1 ; else echo "EBTwoTrackTest passed unit tests" ; fi + +exit 0 + diff --git a/validation/advanced-tests/src/eb/EBTwoTrackTest.java b/validation/advanced-tests/src/eb/EBTwoTrackTest.java new file mode 100644 index 0000000000..8fec3b0c63 --- /dev/null +++ b/validation/advanced-tests/src/eb/EBTwoTrackTest.java @@ -0,0 +1,251 @@ +package eb; + +import java.io.File; +import org.junit.Test; +import static org.junit.Assert.*; + +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; + +import org.jlab.analysis.math.ClasMath; + +/** + * + * Analyze EB efficiencies based on Joseph's two-particle (e-X) FD events. + * Need to write a more general purpose one based on MC::Particle bank. + * + * @author baltzell + */ +public class EBTwoTrackTest { + + static final boolean debug=false; + + // these correspond to Joseph's two-particle event generater: + static final int electronSector=1; + static final int hadronSector=3; + + int nNegTrackEvents = 0; + int nTwoTrackEvents = 0; + int nEvents = 0; + int epCount = 0; + int eCount = 0; + int eposCount = 0; + int epiCount = 0; + int ekCount = 0; + int nMisid = 0; + int nMissing = 0; + int nElectronsSector[]={0,0,0,0,0,0}; + int nHadronsSector[]={0,0,0,0,0,0}; + int hadronPDG; + + @Test + public void main() { + String fileName=System.getProperty("INPUTFILE"); + File file = new File(fileName); + if (!file.exists() || file.isDirectory()) { + System.err.println("Cannot find input file."); + assertEquals(false, true); + } + + if (fileName.indexOf("proton")>=0) hadronPDG=2212; + else if (fileName.indexOf("pion")>0) hadronPDG=211; + else if (fileName.indexOf("kaon")>0) hadronPDG=321; + else { + System.err.println("Cannot find particle type in filename."); + assertEquals(false, true); + } + processFile(fileName); + checkResults(); + } + + private void checkResults() { + + final double twoTrackFrac = (double)nTwoTrackEvents / nEvents; + + final double eEff = (double)eCount / nNegTrackEvents; + final double pEff = (double)epCount / eposCount; + final double piEff = (double)epiCount / eposCount; + final double kEff = (double)ekCount / eposCount; + + final double epEff = (double)epCount / nTwoTrackEvents; + final double epiEff = (double)epiCount / nTwoTrackEvents; + final double ekEff = (double)ekCount / nTwoTrackEvents; + + System.out.println("\n#############################################################"); + System.out.println(String.format("\n# Events = %d",nEvents)); + System.out.print("\nElectrons Sectors: "); + for (int k=0; k<6; k++) System.out.print(String.format(" %4d",nElectronsSector[k])); + System.out.print("\nHadrons Sectors: "); + for (int k=0; k<6; k++) System.out.print(String.format(" %4d",nHadronsSector[k])); + System.out.println("\n"); + System.out.println(String.format("2-Track Frac = %.3f\n",twoTrackFrac)); + System.out.println(String.format("eEff = %.3f",eEff)); + System.out.println(String.format("pEff = %.3f",pEff)); + System.out.println(String.format("piEff = %.3f",piEff)); + System.out.println(String.format("kEff = %.3f\n",kEff)); + System.out.println(String.format("epEff = %.3f",epEff)); + System.out.println(String.format("epiEff = %.3f",epiEff)); + System.out.println(String.format("ekEff = %.3f\n",ekEff)); + System.out.println(String.format("misid = %.3f",(float)nMisid/eposCount)); + System.out.println(String.format("missing = %.3f",(float)nMissing/eposCount)); + System.out.println("\n#############################################################"); + + // some global efficiency tests: + assertEquals(eEff>0.9,true); + if (hadronPDG==2212) assertEquals(pEff>0.77,true); + else if (hadronPDG==321) assertEquals(kEff>0.42,true); + else if (hadronPDG==211) assertEquals(piEff>0.75,true); + } + + private void processFile(String fileName) { + + HipoDataSource reader = new HipoDataSource(); + reader.open(fileName); + + while (reader.hasEvent()) { + + nEvents++; + + DataEvent event = reader.getNextEvent(); + + // get banks: + DataBank trkBank=null,tofBank=null,htccBank=null,ltccBank=null; + DataBank recBank=null,mcBank=null,cheBank=null,rectrkBank=null;; + + if (event.hasBank("FTOF::clusters")) + tofBank=event.getBank("FTOF::clusters"); + if (event.hasBank("TimeBasedTrkg::TBTracks")) + trkBank = event.getBank("TimeBasedTrkg::TBTracks"); + if(event.hasBank("REC::Particle")) + recBank = event.getBank("REC::Particle"); + if(event.hasBank("MC::Particle")) + mcBank = event.getBank("MC::Particle"); + if(event.hasBank("REC::Cherenkov")) + cheBank = event.getBank("REC::Cherenkov"); + if (event.hasBank("LTCC::clusters")) + ltccBank = event.getBank("LTCC::clusters"); + if (event.hasBank("HTCC::rec")) + htccBank = event.getBank("HTCC::rec"); + if (event.hasBank("REC::Track")) + rectrkBank = event.getBank("REC::Track"); + + //if (mcBank!=null) mcBank.show(); + + // no tracking bank, discard event: + if (trkBank==null) continue; + + //if (rectrkBank!=null) rectrkBank.show(); + +/* + if (cheBank!=null) { + for (int ii=0; ii0) nPosTracks++; + else if (trkBank.getInt("q",ii)<0) nPosTracks++; + } + } + + // no possible electron tracks, discard event: + if (nNegTracks==0) continue; + + nNegTrackEvents++; + if (nPosTracks>0) nTwoTrackEvents++; + + boolean foundElectron = false; + boolean foundHadron = false; + boolean foundProton = false; + boolean foundKaon = false; + boolean foundPion = false; + + // check particle bank: + if (recBank!=null) { + for(int ii = 0; ii < recBank.rows(); ii++) { + + final byte charge = recBank.getByte("charge", ii); + final int pid = recBank.getInt("pid", ii); + final double px=recBank.getFloat("px",ii); + final double py=recBank.getFloat("py",ii); + final int sector = ClasMath.getSectorFromPhi(Math.atan2(py,px)); + + if (pid==11 && sector==electronSector) { + if (!foundElectron) nElectronsSector[sector-1]++; + foundElectron=true; + } + else if (sector==hadronSector) { + if (Math.abs(pid)==hadronPDG) { + if (!foundHadron) nHadronsSector[sector-1]++; + foundHadron=true; + } + if (pid==2212) foundProton=true; + else if (Math.abs(pid)==211) foundPion=true; + else if (Math.abs(pid)==321) foundKaon=true; + } + + } + } + + // pid counting: + if (foundElectron) { + + eCount++; + + if (nPosTracks>0) { + + eposCount++; + + if (foundProton) epCount++; + if (foundKaon) ekCount++; + if (foundPion) epiCount++; + + // FIXME + if ( (hadronPDG==2212 && !foundProton) || + (hadronPDG==321 && !foundKaon) || + (hadronPDG==211 && !foundPion) ) { + + if (hadronPDG==2212 && (foundPion || foundKaon)) nMisid++; + else if (hadronPDG==321 && (foundProton || foundPion)) nMisid++; + else if (hadronPDG==211 && (foundProton || foundKaon)) nMisid++; + else { + nMissing++; + if (debug) { + recBank.show(); + tofBank.show(); + } + } + } + } + } + + // CVT tracks could make this happen: + //if (foundProton && nPosTracks==0) { + // System.err.println("WHAT"); + //} + } + reader.close(); + } + +} diff --git a/validation/advanced-tests/src/eb/simplePidTest.groovy b/validation/advanced-tests/src/eb/simplePidTest.groovy new file mode 100644 index 0000000000..823ba110c7 --- /dev/null +++ b/validation/advanced-tests/src/eb/simplePidTest.groovy @@ -0,0 +1,153 @@ +import java.util.ArrayList; +import org.jlab.groot.data.H1F; +import org.jlab.groot.data.H2F; +import org.jlab.groot.math.F1D; +import org.jlab.groot.ui.TCanvas; +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; +import org.jlab.clas.physics.LorentzVector; +import org.jlab.groot.ui.TCanvas; +import org.jlab.groot.data.GraphErrors; +import org.jlab.geom.prim.Point3D; +import org.jlab.geom.prim.Vector3D; +import org.jlab.clas.detector.DetectorParticle; + + +HipoDataSource reader = new HipoDataSource(); +reader.open(args[0]); + + +int dc_electron_total = 0; +int eb_electron_total = 0; + +int dc_hadron_total = 0; +int eb_hadron_total = 0; + + +thelist = fillInvariantMassData(reader); +if(thelist.size()==4) { +dc_electron_total = dc_electron_total + thelist.get(0); +eb_electron_total = eb_electron_total + thelist.get(1); +dc_hadron_total = dc_hadron_total + thelist.get(2); +eb_hadron_total = eb_hadron_total + thelist.get(3); +} + + + +System.out.println("Generated electrons " + dc_electron_total); +System.out.println("Reconstructed electrons " + eb_electron_total); +System.out.println("Generated hadrons " + dc_hadron_total); +System.out.println("Reconstructed hadrons " + eb_hadron_total); + + +List fillInvariantMassData(HipoDataSource read) { + +List list = new ArrayList<>(); +int generated_electron = 0; +int reconstructed_electron = 0; +int generated_hadron = 0; +int reconstructed_hadron = 0; + + +while(read.hasEvent()) +{ + + DataEvent event = read.getNextEvent(); + + ArrayList eb_electrons = new ArrayList<>(); + ArrayList eb_hadrons = new ArrayList<>(); + + ArrayList electrons = new ArrayList<>(); + ArrayList hadrons = new ArrayList<>(); + + + + if(event.hasBank("REC::Particle")) + { + DataBank bank = event.getBank("REC::Particle"); + for(int k = 0; k < bank.rows(); k++) + { + int charge = bank.getInt("charge", k); + int pid = bank.getInt("pid", k); + float px = bank.getFloat("px", k); + float py = bank.getFloat("py", k); + float pz = bank.getFloat("pz", k); + float beta = bank.getFloat("beta", k ); + Vector3D vec = new Vector3D(px,py,pz); + double theta = vec.theta()*57.2958; + double phi = vec.phi()*57.2958; + double energy; + + if(pid==11) { + energy = Math.sqrt(px*px + py*py + pz*pz + 0.0005*0.0005); + eb_electrons.add(new LorentzVector(px, py, pz, energy)); + } + + + if(pid==2212) { + energy = Math.sqrt(px*px + py*py + pz*pz + 0.938*0.938); + eb_hadrons.add(new LorentzVector(px, py, pz, energy)); + } + + if(charge<0) { + energy = Math.sqrt(px*px + py*py + pz*pz + 0.0005*0.0005); + electrons.add(new LorentzVector(px, py, pz, energy)); + } + + + if(charge>0) { + energy = Math.sqrt(px*px + py*py + pz*pz + 0.938*0.938); + hadrons.add(new LorentzVector(px, py, pz, energy)); + } + + + + }//end of for loop + + + + }//end of if (REC::Particle) loop + + + + +//++++++++++++++++++++++Efficiency Analysis++++++++++++++++++++++++++++++++++++++++++ + + + +if(electrons.size()>0){ + generated_electron = generated_electron + 1; + } + + +if(eb_electrons.size()>0) { + reconstructed_electron = reconstructed_electron + 1; +} + +if(hadrons.size()>0){ + generated_hadron = generated_hadron + 1; + } + + +if(eb_hadrons.size()>0) { + reconstructed_hadron = reconstructed_hadron + 1; +} + + +} + + + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +if(generated_electron>0 && reconstructed_electron>0) { +list.add(generated_electron); +list.add(reconstructed_electron); +list.add(generated_hadron); +list.add(reconstructed_hadron); +} +return list; +} + diff --git a/validation/unit-tests/run-unit-test.sh b/validation/unit-tests/run-unit-test.sh new file mode 100755 index 0000000000..b26b2ab6bc --- /dev/null +++ b/validation/unit-tests/run-unit-test.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +pathToTest=$1 +testName=${pathToTest##*/} +testName=${testName%.java} +package=`head -1 $pathToTest | awk '{print$2}' | sed 's/;//'` + +# coatjava must already be built at ../../coatjava/ +COAT="../../coatjava/" +classPath="$COAT/lib/services/*:$COAT/lib/clas/*:$COAT/lib/utils/*:../lib/*:src/" + +# compile the test: +javac -cp $classPath $pathToTest +if [ $? != 0 ] ; then echo "$testName compilation failure" ; exit 1 ; fi + +# run the test: +java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath org.junit.runner.JUnitCore $package.$testName +if [ $? != 0 ] ; then echo "$package unit test failure" ; exit 1 ; else echo "$package passed unit tests" ; fi + diff --git a/validation/unit-tests/run-unit-tests.sh b/validation/unit-tests/run-unit-tests.sh index 06d44921f8..affab42439 100755 --- a/validation/unit-tests/run-unit-tests.sh +++ b/validation/unit-tests/run-unit-tests.sh @@ -23,6 +23,10 @@ if [ $? != 0 ] ; then echo "CVTReconstructionTest compilation failure" ; exit 1 javac -cp $classPath src/ec/ECReconstructionTest.java if [ $? != 0 ] ; then echo "ECReconstructionTest compilation failure" ; exit 1 ; fi +javac -cp $classPath src/eb/EBReconstructionTest.java +if [ $? != 0 ] ; then echo "EBReconstructionTest compilation failure" ; exit 1 ; fi + + # run dc junit tests java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath org.junit.runner.JUnitCore dc.DCReconstructionTest @@ -36,6 +40,12 @@ if [ $? != 0 ] ; then echo "cvt unit test failure" ; exit 1 ; else echo "cvt pas java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath org.junit.runner.JUnitCore ec.ECReconstructionTest if [ $? != 0 ] ; then echo "ec unit test failure" ; exit 1 ; else echo "ec passed unit tests" ; fi +# run eb junit tests +java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath org.junit.runner.JUnitCore eb.EBReconstructionTest +if [ $? != 0 ] ; then echo "eb unit test failure" ; exit 1 ; else echo "eb passed unit tests" ; fi + # run event generator #java -DCLAS12DIR="$COAT" -Xmx1536m -Xms1024m -cp $classPath events.RandomEventGenerator + + diff --git a/validation/unit-tests/src/eb/EBReconstructionTest.java b/validation/unit-tests/src/eb/EBReconstructionTest.java new file mode 100644 index 0000000000..77b69f8a30 --- /dev/null +++ b/validation/unit-tests/src/eb/EBReconstructionTest.java @@ -0,0 +1,114 @@ +package eb; + +import org.junit.Test; +import static org.junit.Assert.*; + +import events.TestEvent; + +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.service.dc.DCHBEngine; +import org.jlab.service.dc.DCTBEngine; +import org.jlab.service.ec.ECEngine; +import org.jlab.service.ftof.FTOFEngine; +import org.jlab.service.htcc.HTCCReconstructionService; +import org.jlab.service.ltcc.LTCCEngine; +import org.jlab.service.eb.EBHBEngine; +import org.jlab.service.eb.EBTBEngine; + +/** + * + * @author nbaltzell + */ +public class EBReconstructionTest { + + public void processAllEngines(DataEvent ev) { + + DCHBEngine engineDCHB = new DCHBEngine(); + engineDCHB.init(); + engineDCHB.processDataEvent(ev); + + DCTBEngine engineDCTB = new DCTBEngine(); + engineDCTB.init(); + engineDCTB.processDataEvent(ev); + + ECEngine engineEC = new ECEngine(); + engineEC.init(); + engineEC.processDataEvent(ev); + + FTOFEngine engineFTOF = new FTOFEngine(); + engineFTOF.init(); + engineFTOF.processDataEvent(ev); + + HTCCReconstructionService engineHTCC = new HTCCReconstructionService(); + engineHTCC.init(); + engineHTCC.processDataEvent(ev); + + LTCCEngine engineLTCC = new LTCCEngine(); + engineLTCC.init(); + engineLTCC.processDataEvent(ev); + + EBHBEngine engineEBHB = new EBHBEngine(); + engineEBHB.init(); + engineEBHB.processDataEvent(ev); + + EBTBEngine engineEBTB = new EBTBEngine(); + engineEBTB.init(); + engineEBTB.processDataEvent(ev); + + ev.show(); + } + + /** + * + * Check that index references are within valid range + * + * bankNameFrom - bank containing the index + * bankNameTo - bank to which the index refers + * idxVarName - name of the index variable + * + */ + public boolean hasValidRefs(DataEvent ev, + String bankNameFrom, + String bankNameTo, + String idxVarName) { + DataBank bFrom=ev.getBank(bankNameFrom); + DataBank bTo=ev.getBank(bankNameTo); + for (int ii=0; ii=bTo.rows() || ref<0) { + bFrom.show(); + bTo.show(); + System.err.println(String.format( + "\bnhasValidRefs: failed on (%s0>%s) %d->%d\n", + bankNameFrom,bankNameTo,ii,ref)); + return false; + } + } + return true; + } + + @Test + public void testEBReconstruction() { + + DataEvent photonEvent = TestEvent.getECSector1PhotonEvent(); + processAllEngines(photonEvent); + assertEquals(photonEvent.hasBank("RECHB::Event"), true); + assertEquals(photonEvent.hasBank("RECHB::Particle"), true); + assertEquals(photonEvent.hasBank("RECHB::Calorimeter"), true); + assertEquals(photonEvent.hasBank("REC::Event"), true); + assertEquals(photonEvent.hasBank("REC::Particle"), true); + assertEquals(photonEvent.hasBank("REC::Calorimeter"), true); + assertEquals(hasValidRefs(photonEvent,"REC::Calorimeter","REC::Particle","pindex"),true); + + DataEvent electronEvent = TestEvent.getDCSector1ElectronEvent(); + processAllEngines(electronEvent); + assertEquals(electronEvent.hasBank("REC::Event"), true); + assertEquals(electronEvent.hasBank("REC::Particle"), true); + assertEquals(electronEvent.hasBank("REC::Track"), true); + assertEquals(hasValidRefs(photonEvent,"REC::Track","TimeBasedTrkg::TBTracks","index"),true); + //assertEquals(electronEvent.hasBank("REC::Cherenkov"), true); + //assertEquals(electronEvent.hasBank("REC::Scintillator"), true); + + } +}