diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBConstants.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBConstants.java index 2372350831..429be436b2 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBConstants.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/calib/utils/RCDBConstants.java @@ -70,7 +70,7 @@ public Long getLong(String key) { } public Time getTime(String key) { if (data.containsKey(key)) { - if (data.get(key).getValue() instanceof Double) { + if (data.get(key).getValue() instanceof Time) { return (Time) data.get(key).getValue(); } } 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 51020f8904..33b0c005ba 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,6 +1,7 @@ package org.jlab.clas.detector; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -382,12 +383,24 @@ public static DataBank getTracksBank(List particles, DataEvent public static DataBank getTrajectoriesBank(List particles, DataEvent event, String bank_name) { + Map > ignore=new HashMap<>(); + //ignore.put(DetectorType.TARGET.getDetectorId(),Arrays.asList(1,2)); + //ignore.put(DetectorType.CVT.getDetectorId(),Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12)); + //ignore.put(DetectorType.DC.getDetectorId(),Arrays.asList(6,12,18,24,30,36)); + DataBank bank=null; if (bank_name!=null) { int nrows = 0; for(int i = 0 ; i < particles.size(); i++) { - nrows += particles.get(i).getTrackTrajectory().size(); + DetectorTrack.Trajectory traj = particles.get(i).getTrackTrajectory(); + for (int detId : traj.getDetectors()) { + for (int layId : traj.getLayers(detId)) { + if (!ignore.containsKey(detId) || !ignore.get(detId).contains(layId)) { + nrows++; + } + } + } } bank = event.createBank(bank_name, nrows); @@ -397,6 +410,9 @@ public static DataBank getTrajectoriesBank(List particles, Dat DetectorTrack.Trajectory traj = p.getTrackTrajectory(); for (int detId : traj.getDetectors()) { for (int layId : traj.getLayers(detId)) { + if (ignore.containsKey(detId) && ignore.get(detId).contains(layId)) { + continue; + } bank.setShort("index", row, (short) p.getTrackIndex()); bank.setShort("pindex", row, (short) i); bank.setByte("detector", row, (byte) detId); @@ -643,7 +659,7 @@ public static List readForwardTaggerParticles(DataEvent event track.setDetectorID(DetectorType.FTCAL.getDetectorId()); // FIXME: FT not in trajectory bank - DetectorParticlePOCA particle = new DetectorParticlePOCA(track); + DetectorParticle particle = new DetectorParticle(track); int pid = 0; if (charge==0) pid = 22; diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorParticle.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorParticle.java index 961656eeed..34adab688f 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorParticle.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorParticle.java @@ -4,7 +4,6 @@ import static java.lang.Math.sqrt; import java.util.ArrayList; import java.util.List; -import org.jlab.clas.detector.DetectorTrack.TrajectoryPoint; import org.jlab.clas.physics.Particle; import org.jlab.clas.physics.Vector3; @@ -129,13 +128,11 @@ public void clear(){ public void addResponse(DetectorResponse res, boolean match){ this.responseStore.add(res); if(match==true){ - TrajectoryPoint tp=this.detectorTrack.getTrajectoryPoint(res.getDescriptor()); - if (tp!=null) { - res.getMatchedPosition().setXYZ(tp.getCross().origin().x(), - tp.getCross().origin().y(), - tp.getCross().origin().z()); - res.setPath(tp.getPathLength()); - } + Line3D distance = this.getDistance(res); + res.getMatchedPosition().setXYZ( + distance.midpoint().x(), + distance.midpoint().y(),distance.midpoint().z()); + res.setPath(this.getPathLength(res.getPosition())); } } @@ -385,15 +382,18 @@ public double getEnergy(DetectorType type, int layer){ return energy; } - public double getPathLength(DetectorType type,int layId) { - return this.detectorTrack.getPathLength(type,layId); - } + public double getPathLength(DetectorType type, int layer){ + DetectorResponse response = this.getHit(type,layer); + if(response==null) return -1.0; + return this.getPathLength(response.getPosition()); + } public double getBeta(DetectorType type, int layer, double startTime){ DetectorResponse response = this.getHit(type,layer); if(response==null) return -1.0; - final double cpath = this.detectorTrack.getPathLength(type,layer); - final double ctime = response.getTime() - startTime; - return cpath/ctime/PhysicsConstants.speedOfLight(); + double cpath = this.getPathLength(response.getPosition()); + double ctime = response.getTime() - startTime; + double beta = cpath/ctime/PhysicsConstants.speedOfLight(); + return beta; } public void setStatus(double minNpheHtcc,double minNpheLtcc) { @@ -408,7 +408,7 @@ public void setStatus(double minNpheHtcc,double minNpheLtcc) { public int getDetectorHit(List hitList, DetectorType type, int detectorLayer, double distanceThreshold){ - + Line3D trajectory = this.detectorTrack.getLastCross(); Point3D hitPoint = new Point3D(); double minimumDistance = 500.0; @@ -471,11 +471,9 @@ public double getDetectorHitQuality(List hitList, int index, } public Line3D getDistance(DetectorResponse response){ - TrajectoryPoint tp=detectorTrack.getTrajectoryPoint(response.getDescriptor()); - if (tp!=null) { - return new Line3D(tp.getCross().origin(), response.getPosition().toPoint3D()); - } - return null; + Line3D cross = this.detectorTrack.getLastCross(); + Line3D dist = cross.distanceRay(response.getPosition().toPoint3D()); + return dist; } public double getTheoryBeta(int id){ @@ -498,21 +496,38 @@ public double getNphe(DetectorType type){ } public double getVertexTime(DetectorType type, int layer){ - return this.getVertexTime(type,layer,this.getPid()); + double vertex_time = this.getTime(type,layer) - + this.getPathLength(type, layer) / + (this.getTheoryBeta(this.getPid())*PhysicsConstants.speedOfLight()); + return vertex_time; } - + public double getVertexTime(DetectorType type, int layer, int pid){ - return this.getTime(type,layer) - - this.getPathLength(type, layer) / - (this.getTheoryBeta(pid)*PhysicsConstants.speedOfLight()); + double vertex_time = -9999; + if(type==DetectorType.CTOF) { + DetectorResponse res = this.getHit(type); + vertex_time = this.getTime(type) - res.getPath()/ + (this.getTheoryBeta(pid)*PhysicsConstants.speedOfLight()); + } + else { + vertex_time = this.getTime(type,layer) - + this.getPathLength(type, layer) / + (this.getTheoryBeta(pid)*PhysicsConstants.speedOfLight()); + } + return vertex_time; } public int getCherenkovSignal(List responses, DetectorType type){ - TrajectoryPoint tp=detectorTrack.getTrajectoryPoint(type.getDetectorId(), 1); - if (tp==null) return -1; - Line3D cross=tp.getCross(); - + 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; double bestConeAngle = Double.POSITIVE_INFINITY; diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorParticleTraj.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorParticleTraj.java new file mode 100644 index 0000000000..1991fc8561 --- /dev/null +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/detector/DetectorParticleTraj.java @@ -0,0 +1,117 @@ +package org.jlab.clas.detector; + +import java.util.List; +import org.jlab.clas.detector.DetectorTrack.TrajectoryPoint; +import org.jlab.geom.prim.Line3D; +import org.jlab.detector.base.DetectorType; +import org.jlab.clas.pdg.PhysicsConstants; + +/** + * Override methods to use new tracking trajectory surfaces. + * (Currently unavailable for hit-based tracking.) + * + */ +public class DetectorParticleTraj extends DetectorParticle { + + public DetectorParticleTraj(DetectorTrack track){ + super(track); + } + + @Override + public int getDetectorHit(List hitList, DetectorType type, + int detectorLayer, + double distanceThreshold){ + + // Protect against odd tracks that don't have trajectory intersection: + if (detectorLayer<1) { + if (!detectorTrack.getTrajectory().hasDetector(type.getDetectorId())) { + return -1; + } + } + else if (detectorTrack.getTrajectoryPoint(type.getDetectorId(),detectorLayer)==null) { + return -1; + } + + // FIXME: replace with trajectory-based matching: + return super.getDetectorHit(hitList, type, detectorLayer, distanceThreshold); + } + + @Override + public double getPathLength(DetectorType type,int layId) { + return this.detectorTrack.getPathLength(type,layId); + } + + @Override + public double getBeta(DetectorType type, int layer, double startTime){ + DetectorResponse response = this.getHit(type,layer); + if(response==null) return -1.0; + final double cpath = this.detectorTrack.getPathLength(type,layer); + final double ctime = response.getTime() - startTime; + return cpath/ctime/PhysicsConstants.speedOfLight(); + } + + @Override + public double getVertexTime(DetectorType type, int layer){ + return this.getVertexTime(type,layer,this.getPid()); + } + + @Override + public double getVertexTime(DetectorType type, int layer, int pid){ + return this.getTime(type,layer) - + this.getPathLength(type, layer) / + (this.getTheoryBeta(pid)*PhysicsConstants.speedOfLight()); + } + + @Override + public Line3D getDistance(DetectorResponse response){ + TrajectoryPoint tp=detectorTrack.getTrajectoryPoint(response.getDescriptor()); + if (tp!=null) { + return new Line3D(tp.getCross().origin(), response.getPosition().toPoint3D()); + } + return null; + } + + @Override + public void addResponse(DetectorResponse res, boolean match){ + this.responseStore.add(res); + if(match==true){ + TrajectoryPoint tp=this.detectorTrack.getTrajectoryPoint(res.getDescriptor()); + if (tp!=null) { + res.getMatchedPosition().setXYZ(tp.getCross().origin().x(), + tp.getCross().origin().y(), + tp.getCross().origin().z()); + res.setPath(tp.getPathLength()); + } + } + } + + @Override + public int getCherenkovSignal(List responses, DetectorType type){ + + TrajectoryPoint tp=detectorTrack.getTrajectoryPoint(type.getDetectorId(), 1); + if (tp==null) return -1; + Line3D cross=tp.getCross(); + + // find the best match: + int bestIndex = -1; + double bestConeAngle = Double.POSITIVE_INFINITY; + if(responses.size()>0){ + for(int loop = 0; loop < responses.size(); loop++) { + if (responses.get(loop).getDescriptor().getType() != type) continue; + if (responses.get(loop).getAssociation()>=0) continue; + CherenkovResponse cher = (CherenkovResponse)responses.get(loop); + // FIXME: use normalized distance/angle instead of box cut? + // unify with non-Cherenkov? + CherenkovResponse.TrackResidual tres = cher.getTrackResidual(cross); + if (Math.abs(tres.getDeltaTheta()) < cher.getDeltaTheta() && + Math.abs(tres.getDeltaPhi()) < cher.getDeltaPhi()) { + if (tres.getConeAngle() < bestConeAngle) { + bestIndex = loop; + bestConeAngle = tres.getConeAngle(); + } + } + } + } + return bestIndex; + } +} diff --git a/etc/bankdefs/hipo4/event.json b/etc/bankdefs/hipo4/event.json index 3f9bb2f827..b338e0a6f7 100644 --- a/etc/bankdefs/hipo4/event.json +++ b/etc/bankdefs/hipo4/event.json @@ -11,8 +11,8 @@ {"name":"liveTime", "type":"D", "info":"Lifetime"}, {"name":"startTime", "type":"F", "info":"Event Start Time (ns)"}, {"name":"RFTime", "type":"F", "info":"RF Time (ns)"}, - {"name":"helicity", "type":"B", "info":"Helicity of Event (0 or 1, else undefined), with HWP-correction"}, - {"name":"helicityRaw","type":"B", "info":"Helicity of Event (0 or 1, else undefined)"}, + {"name":"helicity", "type":"B", "info":"Helicity of Event (+/-1, else undefined), with HWP-correction"}, + {"name":"helicityRaw","type":"B", "info":"Helicity of Event (+/-1, else undefined)"}, {"name":"procTime", "type":"F", "info":"Event Processing Time (UNIX Time = seconds)"} ] }, @@ -192,8 +192,8 @@ {"name":"liveTime", "type":"D", "info":"Lifetime"}, {"name":"startTime", "type":"F", "info":"Event Start Time (ns)"}, {"name":"RFTime", "type":"F", "info":"RF Time (ns)"}, - {"name":"helicity", "type":"B", "info":"Helicity of Event (0 or 1, else undefined), with HWP-correction"}, - {"name":"helicityRaw","type":"B", "info":"Helicity of Event (0 or 1, else undefined)"}, + {"name":"helicity", "type":"B", "info":"Helicity of Event (+/-1, else undefined), with HWP-correction"}, + {"name":"helicityRaw","type":"B", "info":"Helicity of Event (+/-1, else undefined)"}, {"name":"procTime", "type":"F", "info":"Event Processing Time (UNIX Time = seconds)"} ] }, diff --git a/etc/bankdefs/util/bankSplit.py b/etc/bankdefs/util/bankSplit.py index e3cd979cf2..aa9fe261c0 100644 --- a/etc/bankdefs/util/bankSplit.py +++ b/etc/bankdefs/util/bankSplit.py @@ -52,8 +52,11 @@ def createdirandlinks(dirname, banklist): dst = ["RUN::config","RAW::epics","RAW::scaler","REC::Event","REC::Particle","REC::Calorimeter","REC::Cherenkov","REC::CovMat","REC::ForwardTagger","REC::Scintillator","REC::Track","REC::Traj","RECFT::Event","RECFT::Particle","RICH::tdc","RICH::ringCher","RICH::hadCher","RUN::scaler","HEL::flip","HEL::online","MC::Event","MC::Header","MC::Lund","MC::Particle","MC::True"] calibration = ["BAND::adc","BAND::tdc","BAND::hits","CND::adc","CND::hits","CND::tdc","CTOF::adc","CTOF::hits","CTOF::tdc","CVTRec::Tracks","ECAL::adc","ECAL::calib","ECAL::clusters","ECAL::peaks","ECAL::tdc","FT::particles","FTCAL::adc","FTCAL::clusters","FTCAL::hits","FTHODO::adc","FTHODO::clusters","FTHODO::hits","FTOF::adc","FTOF::hits","FTOF::tdc","HEL::flip","HEL::online","HTCC::adc","HTCC::rec","LTCC::adc","LTCC::clusters","MC::Event","MC::Header","MC::Lund","MC::Particle","MC::True","RAW::epics","RAW::scaler","REC::Calorimeter","REC::Cherenkov","REC::CovMat","REC::Event","REC::ForwardTagger","REC::Particle","REC::Scintillator","REC::Track","REC::Traj","RECFT::Event","RECFT::Particle","RF::adc","RF::tdc","RICH::tdc","RICH::hits","RICH::hadCher","RICH::hadrons","RICH::photons","RUN::config","RUN::rf","RUN::scaler","RUN::trigger","TimeBasedTrkg::TBCrosses","TimeBasedTrkg::TBHits","TimeBasedTrkg::TBSegments","TimeBasedTrkg::TBSegmentTrajectory","TimeBasedTrkg::TBTracks","TimeBasedTrkg::Trajectory"] monitoring = ["BAND::adc","BAND::tdc","BAND::hits","BMT::adc","BMTRec::Clusters","BMTRec::Crosses","BMTRec::Hits","BMTRec::LayerEffs","BST::adc","BSTRec::Clusters","BSTRec::Crosses","BSTRec::Hits","BSTRec::LayerEffs","CND::adc","CND::clusters","CND::hits","CND::tdc","CTOF::adc","CTOF::hits","CTOF::tdc","CVTRec::Tracks","CVTRec::Trajectory","ECAL::adc","ECAL::calib","ECAL::clusters","ECAL::hits","ECAL::peaks","ECAL::tdc","FT::particles","FTCAL::adc","FTCAL::clusters","FTCAL::hits","FTHODO::adc","FTHODO::clusters","FTHODO::hits","FTOF::adc","FTOF::hits","FTOF::tdc","HEL::adc","HEL::flip","HEL::online","HitBasedTrkg::HBTracks","HTCC::adc","HTCC::rec","LTCC::adc","LTCC::clusters","MC::Event","MC::Header","MC::Lund","MC::Particle","MC::True","RAW::epics","RAW::scaler","RAW::vtp","REC::Calorimeter","REC::Cherenkov","REC::CovMat","REC::Event","REC::ForwardTagger","REC::Particle","REC::Scintillator","REC::Track","REC::Traj","RECFT::Event","RECFT::Particle","RECHB::Calorimeter","RECHB::Cherenkov","RECHB::Event","RECHB::ForwardTagger","RECHB::Particle","RECHB::Scintillator","RECHB::Track","RF::adc","RF::tdc","RICH::tdc","RICH::hits","RICH::hadrons","RICH::photons","RUN::config","RUN::rf","RUN::scaler","RUN::trigger","TimeBasedTrkg::TBCrosses","TimeBasedTrkg::TBHits","TimeBasedTrkg::TBSegments","TimeBasedTrkg::TBSegmentTrajectory","TimeBasedTrkg::TBTracks","TimeBasedTrkg::Trajectory"] +ebrerun=list(dst) +ebrerun.extend(["FTOF::hits","TimeBasedTrkg::TBTracks","TimeBasedTrkg::Trajectory","TimeBasedTrkg::TBCovMat","HitBasedTrkg::HBTracks","FTOF::hbhits","ECAL::clusters","CTOF::hits","CND::clusters","HTCC::rec","LTCC::clusters","ECAL::moments","CVTRec::Tracks","CVTRec::Trajectory","FT::particles","FTCAL::clusters","FTHODO::clusters","RUN:rf"]) createdirandlinks("dst/", dst) createdirandlinks("calibration/", calibration) createdirandlinks("monitoring/", monitoring) +#createdirandlinks("ebrerun/", ebrerun) 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 220c49f4ad..5147c83e87 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 @@ -14,7 +14,7 @@ import org.jlab.clas.detector.DetectorHeader; import org.jlab.clas.detector.DetectorEvent; import org.jlab.clas.detector.DetectorParticle; -import org.jlab.clas.detector.DetectorParticlePOCA; +import org.jlab.clas.detector.DetectorParticleTraj; import org.jlab.clas.detector.DetectorResponse; import org.jlab.clas.detector.DetectorTrack; import org.jlab.clas.detector.TaggerResponse; @@ -72,9 +72,9 @@ public void addFTIndices(List> ftindex) { public void addTracks(List tracks) { for(int i = 0 ; i < tracks.size(); i++){ if (this.usePOCA) - detectorEvent.addParticle(new DetectorParticlePOCA(tracks.get(i))); - else detectorEvent.addParticle(new DetectorParticle(tracks.get(i))); + else + detectorEvent.addParticle(new DetectorParticleTraj(tracks.get(i))); } } @@ -144,8 +144,8 @@ public void processHitMatching(){ // only match with CTOF/CND if it's a central track: else if (p.getTrackDetectorID()==DetectorType.CVT.getDetectorId()) { // NOTE: Should we do 2-d matching in cylindrical coordinates for CD? - findMatchingHit(n,p,detectorResponses,DetectorType.CTOF,0, ccdb.getDouble(EBCCDBEnum.CTOF_DZ)); - findMatchingHit(n,p,detectorResponses,DetectorType.CND, 0, ccdb.getDouble(EBCCDBEnum.CND_DZ)); + findMatchingHit(n,p,detectorResponses,DetectorType.CTOF,1, ccdb.getDouble(EBCCDBEnum.CTOF_DZ)); + findMatchingHit(n,p,detectorResponses,DetectorType.CND,-1, ccdb.getDouble(EBCCDBEnum.CND_DZ)); } }