Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

481 More features to the ATOF clustering and track matching #484

Merged
merged 19 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7a02191
refactor: generic method for clustering different types of hits, meth…
N-Plx Feb 20, 2025
9ff65b0
refactor: moving folders/packages for more generic alert features
N-Plx Feb 20, 2025
3e6381c
feat: putting back cluster path length information, now handling case…
N-Plx Feb 21, 2025
bbc0fc9
Merge branch 'development' into 481-make-atof-clustering-more-flexible
N-Plx Feb 21, 2025
4bc755d
feat: handling track-cluster matching for events with more than one t…
N-Plx Feb 22, 2025
b9e2750
Merge branch '481-make-atof-clustering-more-flexible' of https://gith…
N-Plx Feb 22, 2025
cd9acdc
feat: saving track ID in projection bank
N-Plx Feb 22, 2025
dc3ed34
feat: ignoring double barhits
N-Plx Feb 25, 2025
db708bd
feat: computing helix path length between points on the helix
N-Plx Feb 25, 2025
9a071b4
fix: correct path length definition
N-Plx Feb 25, 2025
a50ddad
Merge branch 'development' into 481-make-atof-clustering-more-flexible
N-Plx Feb 25, 2025
cf43a11
feat: computing maximal energy hit in clusters
N-Plx Feb 26, 2025
f0db0a4
feat: tdc entry id matched to hit
N-Plx Feb 26, 2025
9a2c6fe
feat: tdc and tot are filled for barhits
N-Plx Feb 26, 2025
1493d2a
Merge branch 'development' into 481-make-atof-clustering-more-flexible
N-Plx Feb 26, 2025
4aa57ae
Merge branch '481-make-atof-clustering-more-flexible' of https://gith…
N-Plx Feb 26, 2025
e1fbcb0
Merge branch 'development' into 481-make-atof-clustering-more-flexible
N-Plx Feb 28, 2025
0629273
fix: order definition
N-Plx Feb 28, 2025
d76f9e4
Merge branch '481-make-atof-clustering-more-flexible' of https://gith…
N-Plx Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,39 @@ public Vector3D getMomentumAtZ(double z) {
return new Vector3D(getPx(getB(),l),getPy(getB(),l),getPz(getB()));
}

/**
* Computes the path length between to points at radius rMin and rMax of the
* helix.
*
* @param rMin the radius of the point from which to measure.
* @param rMax the radius of the point to which to measure.
*
* helix parametrization is X(l) = xc - s*R*sin(phi0+omega*l) Y(l) = yc +
* s*R*cos(phi0+omega*l) Z(l) = z0 - l*tanL
*
* d^2 = (dX/dl)^2 + (dY/dl)^2 + (dZ/dl)^2
*
* pathlength = integral of d(l) from l(rMin) to l(rMax) pathlength =
* sqrt(R^2omega^2+tanL^2)*(l(rMax)-l(rMin))
*
* @author pilleux
*
*/
public double getPathLength(double rMin, double rMax) {

double s = (double) -KFitter.polarity * getTurningSign();

if (rMax <= rMin) {
System.out.print("Cannot compute path length, max radius smaller than min radius ! \n");
return 0;
}
double l0 = this.getLAtR(rMin);
double l1 = this.getLAtR(rMax);
double term1 = this.getOmega() * s * this.getR();
double term2 = this.getTanL();
return Math.abs((l1 - l0) * Math.sqrt(term1 * term1 + term2 * term2));
}

@Override
public String toString() {
String s = String.format(" drho=%.4f phi0=%.4f radius=%.4f z0=%.4f tanL=%.4f B=%.4f\n", this._d0, this._phi0, this._R, this._z0, this._tanL, this._B);
Expand Down
16 changes: 14 additions & 2 deletions etc/bankdefs/hipo4/alert.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
"info": "Track Projections to ATOF",
"entries": [
{
"name": "id",
"type": "S",
"info": "projection id"
},{
"name": "trackID",
"type": "S",
"info": "id of the track that was projected"
}, {
"name": "x_at_bar",
"type": "F",
"info": "x position at atof bar (middle surface) in mm"
}, {
},{
"name": "y_at_bar",
"type": "F",
"info": "y position at atof bar (middle surface) in mm"
Expand Down Expand Up @@ -91,7 +99,7 @@
"info": "deposited energy in MeV"
},{
"name": "clusterid",
"type": "I",
"type": "S",
"info": "id of cluster to which the hit was associated"
}
]
Expand Down Expand Up @@ -141,6 +149,10 @@
"name": "inpathlength",
"type": "F",
"info": "path length inside the detector in mm"
},{
"name": "projID",
"type": "S",
"info": "id of the projected track matched. it is -1 if a straight track was assigned."
}
]
},{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jlab.rec.atof.trackMatch;
package org.jlab.rec.alert.projections;

import org.jlab.geom.prim.Point3D;

Expand Down Expand Up @@ -42,6 +42,8 @@ public class TrackProjection {
*/
Float wedgeInPathLength;

int trackID;


/**
* Default constructor that initializes the intersection points and path lengths to {@code NaN}.
Expand Down Expand Up @@ -165,6 +167,14 @@ public void setWedgeInPathLength(Float WedgeInPathLength) {
this.wedgeInPathLength = WedgeInPathLength;
}

public void setTrackID(int trackID) {
this.trackID = trackID;
}

public int getTrackID() {
return trackID;
}

/**
* testing purposes.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jlab.rec.atof.trackMatch;
package org.jlab.rec.alert.projections;

import java.util.ArrayList;

import org.jlab.io.base.DataBank;
import org.jlab.io.base.DataEvent;
import org.jlab.clas.tracking.trackrep.Helix;
Expand Down Expand Up @@ -30,7 +29,7 @@ public class TrackProjector {
* projections of tracks.
*/
private ArrayList<TrackProjection> projections;

/**
* solenoid magnitude
*/
Expand All @@ -54,8 +53,8 @@ public TrackProjector() {
public ArrayList<TrackProjection> getProjections() {
return projections;
}
/**

/**
* Gets the solenoid magnitude
*
* @return solenoid magnitude
Expand All @@ -72,8 +71,8 @@ public Double getB() {
public void setProjections(ArrayList<TrackProjection> Projections) {
this.projections = Projections;
}
/**

/**
* Sets the solenoid magnitude.
*
* @param B a double.
Expand All @@ -91,9 +90,7 @@ public void setB(Double B) {
public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) {

projections.clear();

String track_bank_name = "AHDC::Track";

if (event == null) { // check if there is an event
//System.out.print(" no event \n");
} else if (event.hasBank(track_bank_name) == false) {
Expand All @@ -104,13 +101,13 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb)
int nt = bank.rows(); // number of tracks
TrackProjection projection = new TrackProjection();
for (int i = 0; i < nt; i++) {

double x = bank.getFloat("x", i);
double y = bank.getFloat("y", i);
double z = bank.getFloat("z", i);
double px = bank.getFloat("px", i);
double py = bank.getFloat("py", i);
double pz = bank.getFloat("pz", i);
int id = nt + 1;//To be replaced by track id if it is added to the out bank

int q = -1; //need the charge sign from tracking

Expand All @@ -120,34 +117,36 @@ public void projectTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb)
double yb = 0;

//momenta must be in GeV for the helix class
Helix helix = new Helix(x, y, z, px/1000., py/1000., pz/1000., q, b, xb, yb, units);
Helix helix = new Helix(x, y, z, px / 1000., py / 1000., pz / 1000., q, b, xb, yb, units);

//Intersection points with the middle of the bar or wedge
projection.setBarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS));
projection.setWedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS));

double rVertex = Math.sqrt(x * x + y * y);

//Path length to the middle of the bar or wedge
projection.setBarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS)));
projection.setWedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS)));

projection.setBarPathLength((float) helix.getPathLength(rVertex, Parameters.BAR_MIDDLE_RADIUS));
projection.setWedgePathLength((float) helix.getPathLength(rVertex, Parameters.WEDGE_MIDDLE_RADIUS));
//Path length from the inner radius to the middle radius
projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength());
projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength());
projection.setBarInPathLength((float) helix.getPathLength(Parameters.BAR_INNER_RADIUS, Parameters.BAR_MIDDLE_RADIUS));
projection.setWedgeInPathLength((float) helix.getPathLength(Parameters.WEDGE_INNER_RADIUS, Parameters.WEDGE_MIDDLE_RADIUS));
projection.setTrackID(id);
projections.add(projection);
}

}
}

/**
* Projects the MC particles onto the atof using a {@link Helix}
* model.
* Projects the MC particles onto the atof using a {@link Helix} model.
*
* @param event the {@link DataEvent} containing track data to be projected.
*/
public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccdb) {

projections.clear();

String track_bank_name = "MC::Particle";
if (event == null) { // check if there is an event
//System.out.print(" no event \n");
Expand All @@ -158,7 +157,6 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd
DataBank bank = event.getBank(track_bank_name);
int nt = bank.rows(); // number of tracks
TrackProjection projection = new TrackProjection();
DataBank outputBank = event.createBank("ALERT::Projections", nt);

for (int i = 0; i < nt; i++) {

Expand All @@ -168,15 +166,14 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd
double px = bank.getFloat("px", i);
double py = bank.getFloat("py", i);
double pz = bank.getFloat("pz", i);

int id = bank.getShort("id", i);
//Put everything in MM
x = x * 10;
y = y * 10;
z = z * 10;

x = x*10;
y = y*10;
z = z*10;
Units units = Units.MM;

Units units = Units.MM;

int q = -1; //need the charge sign from tracking

double xb = 0;
Expand All @@ -186,24 +183,25 @@ public void projectMCTracks(DataEvent event) {//, CalibrationConstantsLoader ccd
Helix helix = new Helix(x, y, z, px, py, pz, q, b, xb, yb, units);

//Intersection points with the middle of the bar or wedge
projection.setBarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS));
projection.setBarIntersect(helix.getHelixPointAtR(Parameters.BAR_MIDDLE_RADIUS));
projection.setWedgeIntersect(helix.getHelixPointAtR(Parameters.WEDGE_MIDDLE_RADIUS));

//Path length to the middle of the bar or wedge
double rVertex = Math.sqrt(x * x + y * y);

projection.setBarPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_INNER_RADIUS)));
projection.setWedgePathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_INNER_RADIUS)));

//Path length to the middle of the bar or wedge
projection.setBarPathLength((float) helix.getPathLength(rVertex, Parameters.BAR_MIDDLE_RADIUS));
projection.setWedgePathLength((float) helix.getPathLength(rVertex, Parameters.WEDGE_MIDDLE_RADIUS));
//Path length from the inner radius to the middle radius
projection.setBarInPathLength((float) helix.getPathLength(Parameters.BAR_INNER_RADIUS, Parameters.BAR_MIDDLE_RADIUS));
projection.setWedgeInPathLength((float) helix.getPathLength(Parameters.WEDGE_INNER_RADIUS, Parameters.WEDGE_MIDDLE_RADIUS));

projection.setBarInPathLength((float) Math.abs(helix.getLAtR(Parameters.BAR_MIDDLE_RADIUS)) - projection.getBarPathLength());
projection.setWedgeInPathLength((float) Math.abs(helix.getLAtR(Parameters.WEDGE_MIDDLE_RADIUS)) - projection.getWedgePathLength());
projection.setTrackID(id);
projections.add(projection);
}
}
}

public static void main(String arg[]) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.jlab.rec.atof.cluster.ATOFCluster;
import org.jlab.rec.atof.hit.ATOFHit;
import org.jlab.rec.atof.hit.BarHit;
import org.jlab.rec.atof.trackMatch.TrackProjection;
import org.jlab.rec.alert.projections.TrackProjection;

/**
* The {@code RecoBankWriter} writes the banks needed for the atof
Expand Down Expand Up @@ -43,7 +43,7 @@ public static DataBank fillATOFHitBank(DataEvent event, ArrayList<ATOFHit> wedge

for (int i = 0; i < hitList.size(); i++) {
bank.setShort("id", i, (short) (i + 1));
bank.setInt("clusterid", i, (int) hitList.get(i).getAssociatedClusterIndex());
bank.setShort("clusterid", i, (short) hitList.get(i).getAssociatedClusterIndex());
bank.setInt("sector", i, (int) hitList.get(i).getSector());
bank.setInt("layer", i, (int) hitList.get(i).getLayer());
bank.setInt("component", i, (int) hitList.get(i).getComponent());
Expand Down Expand Up @@ -85,6 +85,9 @@ public static DataBank fillATOFClusterBank(DataEvent event, ArrayList<ATOFCluste
bank.setFloat("y", i, (float) (clusterList.get(i).getY()));
bank.setFloat("z", i, (float) (clusterList.get(i).getZ()));
bank.setFloat("energy", i, (float) clusterList.get(i).getEnergy());
bank.setFloat("inpathlength",i, (float) (clusterList.get(i).getInPathLength()));
bank.setFloat("pathlength",i, (float) (clusterList.get(i).getPathLength()));
bank.setShort("projID", i, (short) (clusterList.get(i).getIProj()));
}
return bank;
}
Expand All @@ -108,9 +111,10 @@ public static DataBank fillProjectionsBank(DataEvent event, ArrayList<TrackProje
System.err.println("COULD NOT CREATE A ALERT::Projections BANK!!!!!!");
return null;
}

for (int i = 0; i < projections.size(); i++) {
TrackProjection projection = projections.get(i);
bank.setShort("id", i, (short) (i + 1));
bank.setShort("trackID", i, (short) projection.getTrackID());
bank.setFloat("x_at_bar", i, (float) projection.getBarIntersect().x());
bank.setFloat("y_at_bar", i, (float) projection.getBarIntersect().y());
bank.setFloat("z_at_bar", i, (float) projection.getBarIntersect().z());
Expand Down
Loading