Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #484 from JeffersonLab/eb-traj
Browse files Browse the repository at this point in the history
EB/common-tools updates
  • Loading branch information
raffaelladevita authored Mar 2, 2020
2 parents 32fd941 + 842e5e0 commit 169a12b
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -382,12 +383,24 @@ public static DataBank getTracksBank(List<DetectorParticle> particles, DataEvent

public static DataBank getTrajectoriesBank(List<DetectorParticle> particles, DataEvent event, String bank_name) {

Map <Integer,List<Integer>> 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);

Expand All @@ -397,6 +410,9 @@ public static DataBank getTrajectoriesBank(List<DetectorParticle> 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);
Expand Down Expand Up @@ -643,7 +659,7 @@ public static List<DetectorParticle> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -408,7 +408,7 @@ public void setStatus(double minNpheHtcc,double minNpheLtcc) {
public int getDetectorHit(List<DetectorResponse> hitList, DetectorType type,
int detectorLayer,
double distanceThreshold){

Line3D trajectory = this.detectorTrack.getLastCross();
Point3D hitPoint = new Point3D();
double minimumDistance = 500.0;
Expand Down Expand Up @@ -471,11 +471,9 @@ public double getDetectorHitQuality(List<DetectorResponse> 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){
Expand All @@ -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<DetectorResponse> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DetectorResponse> 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<DetectorResponse> 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;
}
}
8 changes: 4 additions & 4 deletions etc/bankdefs/hipo4/event.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"}
]
},
Expand Down Expand Up @@ -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)"}
]
},
Expand Down
3 changes: 3 additions & 0 deletions etc/bankdefs/util/bankSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,9 +72,9 @@ public void addFTIndices(List<Map<DetectorType, Integer>> ftindex) {
public void addTracks(List<DetectorTrack> 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)));
}
}

Expand Down Expand Up @@ -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));
}

}
Expand Down

0 comments on commit 169a12b

Please sign in to comment.