Skip to content

Commit 2898e31

Browse files
author
Matthew Solt
committed
updating tuple maker and truth matching
1 parent 439b49d commit 2898e31

5 files changed

Lines changed: 515 additions & 212 deletions

File tree

analysis/src/main/java/org/hps/analysis/MC/MCFullDetectorTruth.java

Lines changed: 155 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.lcsim.event.SimCalorimeterHit;
1616
import org.lcsim.event.SimTrackerHit;
1717
import org.lcsim.geometry.FieldMap;
18-
import org.lcsim.geometry.IDDecoder;
1918
import org.lcsim.util.swim.Trajectory;
2019

2120
/**
@@ -66,10 +65,24 @@ public static Map<MCParticle, List<SimCalorimeterHit>> BuildCalHitMap(List<SimCa
6665
return calHitMap;
6766
}
6867

69-
public static String trackHitLayer(IDDecoder trackerDecoder,SimTrackerHit hit) {
68+
public static String trackHitLayer(SimTrackerHit hit) {
7069
String layer = Integer.toString( (int) hit.getLayer());
7170
double y = hit.getPositionVec().y();
7271
String volume = "";
72+
//boolean isTop = ((HpsSiSensor) ((SimTrackerHit) hit.getDetectorElement()).getDetectorElement()).isTopLayer();
73+
//if(isTop) volume = "t";
74+
if(y > 0) volume = "t";
75+
else volume = "b";
76+
String prefix = "L" + layer + volume;
77+
return prefix;
78+
}
79+
80+
public static String trackHitLayer_1(SimTrackerHit hit) {
81+
String layer = Integer.toString( (int) hit.getLayer() - 1);
82+
double y = hit.getPositionVec().y();
83+
String volume = "";
84+
//boolean isTop = ((HpsSiSensor) ((SimTrackerHit) hit.getDetectorElement()).getDetectorElement()).isTopLayer();
85+
//if(isTop) volume = "t";
7386
if(y > 0) volume = "t";
7487
else volume = "b";
7588
String prefix = "L" + layer + volume;
@@ -180,7 +193,7 @@ public static String MCParticleType(MCParticle p, List<MCParticle> particles, do
180193
return "";
181194
}
182195

183-
public static Hep3Vector extrapolateTrackPosition(Hep3Vector startPosition, Hep3Vector startMomentum, double endPositionZ, double stepSize, FieldMap fieldMap, double q) {
196+
/*public static Hep3Vector extrapolateTrackPosition(Hep3Vector startPosition, Hep3Vector startMomentum, double endPositionZ, double stepSize, FieldMap fieldMap, double q) {
184197
185198
// Start by transforming detector vectors into tracking frame
186199
Hep3Vector currentPosition = CoordinateTransformations.transformVectorToTracking(startPosition);
@@ -220,8 +233,7 @@ public static Hep3Vector extrapolateTrackPosition(Hep3Vector startPosition, Hep3
220233
// update the extrapolated position.
221234
//if(CoordinateTransformations.transformVectorToTracking(startPosition).x() > currentPosition.x()){
222235
if(currentMomentum.x() < 0){
223-
//System.out.println("Extrapolation is going backwards! Break loop! Z = " + currentPosition.x());
224-
break;
236+
return null;
225237
}
226238
currentPosition = trajectory.getPointAtDistance(stepSize);
227239
@@ -281,8 +293,7 @@ public static Hep3Vector extrapolateTrackMomentum(Hep3Vector startPosition, Hep3
281293
282294
//if(CoordinateTransformations.transformVectorToTracking(startPosition).x() > currentPosition.x()){
283295
if(currentMomentum.x() < 0){
284-
//System.out.println("Extrapolation is going backwards! Break loop! Z = " + currentPosition.x());
285-
break;
296+
return null;
286297
}
287298
288299
// Using the new trajectory, extrapolated the track by a step and
@@ -305,7 +316,7 @@ public static Hep3Vector extrapolateTrackMomentum(Hep3Vector startPosition, Hep3
305316
306317
// Transform vector back to detector frame
307318
return CoordinateTransformations.transformVectorToDetector(currentMomentum);
308-
}
319+
}*/
309320

310321
public static double deltaThetaX(Hep3Vector p1, Hep3Vector p2){
311322
double theta1 = p1.x()/p1.z();
@@ -318,4 +329,140 @@ public static double deltaThetaY(Hep3Vector p1, Hep3Vector p2){
318329
double theta2 = p2.y()/p2.z();
319330
return theta2 - theta1;
320331
}
332+
333+
public static Hep3Vector extrapolateTrackMomentum(Hep3Vector endPosition, Hep3Vector endMomentum, Hep3Vector startPosition, double stepSize, FieldMap fieldMap, double q) {
334+
if(endPosition == null || endMomentum == null || startPosition == null) return null;
335+
// Start by transforming detector vectors into tracking frame
336+
Hep3Vector currentPosition = CoordinateTransformations.transformVectorToTracking(endPosition);
337+
Hep3Vector currentMomentum = VecOp.neg(CoordinateTransformations.transformVectorToTracking(endMomentum));
338+
double startPositionZ = startPosition.z();
339+
340+
//System.out.println(currentPosition.x() + " " + currentPosition.y() + " " + currentPosition.z() + " ");
341+
342+
// Retrieve the y component of the bfield in the middle of detector
343+
double bFieldY = fieldMap.getField(new BasicHep3Vector(0, 0, 500.0)).y();
344+
345+
// HACK: LCSim doesn't deal well with negative fields so they are
346+
// turned to positive for tracking purposes. As a result,
347+
// the charge calculated using the B-field, will be wrong
348+
// when the field is negative and needs to be flipped.
349+
if (bFieldY < 0)
350+
q = q * (-1);
351+
352+
// Swim the track through the B-field until the end point is reached.
353+
// The position of the track will be incremented according to the step
354+
// size up to ~90% of the final position. At this point, a finer
355+
// track size will be used.
356+
boolean stepSizeChange = false;
357+
while (currentPosition.x() > startPositionZ) {
358+
// The field map coordinates are in the detector frame so the
359+
// extrapolated track position needs to be transformed from the
360+
// track frame to detector.
361+
Hep3Vector currentPositionDet = CoordinateTransformations.transformVectorToDetector(currentPosition);
362+
363+
// Get the field at the current position along the track.
364+
bFieldY = fieldMap.getField(currentPositionDet).y();
365+
366+
// Get a trajectory (Helix or Line objects) created with the
367+
// track parameters at the current position.
368+
Trajectory trajectory = TrackUtils.getTrajectory(currentMomentum, new org.lcsim.spacegeom.SpacePoint(currentPosition), q, bFieldY);
369+
370+
// Using the new trajectory, extrapolated the track by a step and
371+
// update the extrapolated position.
372+
//if(CoordinateTransformations.transformVectorToTracking(startPosition).x() > currentPosition.x()){
373+
if(currentMomentum.x() > 0){
374+
//System.out.println("Track is going Forwards!");
375+
return null;
376+
}
377+
currentPosition = trajectory.getPointAtDistance(stepSize);
378+
379+
// Calculate the momentum vector at the new position. This will
380+
// be used when creating the trajectory that will be used to
381+
// extrapolate the track in the next iteration.
382+
currentMomentum = VecOp.mult(currentMomentum.magnitude(), trajectory.getUnitTangentAtLength(stepSize));
383+
384+
//System.out.println("Position " + CoordinateTransformations.transformVectorToDetector(currentPosition) + " Momentum " + CoordinateTransformations.transformVectorToDetector(currentMomentum) + " startPositionZ " + startPositionZ);
385+
386+
//System.out.println(currentPosition.x() + " " + currentPosition.y() + " " + currentPosition.z() + " ");
387+
388+
// If the position of the track along X (or z in the detector frame)
389+
// is at 90% of the total distance, reduce the step size.
390+
if (currentPosition.x() / startPositionZ > .80 && !stepSizeChange) {
391+
stepSize /= 10;
392+
//System.out.println("Changing step size: " + stepSize);
393+
stepSizeChange = true;
394+
}
395+
}
396+
397+
// Transform vector back to detector frame
398+
return CoordinateTransformations.transformVectorToDetector(currentMomentum);
399+
}
400+
401+
public static Hep3Vector extrapolateTrackPosition(Hep3Vector endPosition, Hep3Vector endMomentum, Hep3Vector startPosition, double stepSize, FieldMap fieldMap, double q) {
402+
if(endPosition == null || endMomentum == null || startPosition == null) return null;
403+
// Start by transforming detector vectors into tracking frame
404+
Hep3Vector currentPosition = CoordinateTransformations.transformVectorToTracking(endPosition);
405+
Hep3Vector currentMomentum = VecOp.neg(CoordinateTransformations.transformVectorToTracking(endMomentum));
406+
double startPositionZ = startPosition.z();
407+
408+
//System.out.println(currentPosition.x() + " " + currentPosition.y() + " " + currentPosition.z() + " ");
409+
410+
// Retrieve the y component of the bfield in the middle of detector
411+
double bFieldY = fieldMap.getField(new BasicHep3Vector(0, 0, 500.0)).y();
412+
413+
// HACK: LCSim doesn't deal well with negative fields so they are
414+
// turned to positive for tracking purposes. As a result,
415+
// the charge calculated using the B-field, will be wrong
416+
// when the field is negative and needs to be flipped.
417+
if (bFieldY < 0)
418+
q = q * (-1);
419+
420+
// Swim the track through the B-field until the end point is reached.
421+
// The position of the track will be incremented according to the step
422+
// size up to ~90% of the final position. At this point, a finer
423+
// track size will be used.
424+
boolean stepSizeChange = false;
425+
while (currentPosition.x() > startPositionZ) {
426+
// The field map coordinates are in the detector frame so the
427+
// extrapolated track position needs to be transformed from the
428+
// track frame to detector.
429+
Hep3Vector currentPositionDet = CoordinateTransformations.transformVectorToDetector(currentPosition);
430+
431+
// Get the field at the current position along the track.
432+
bFieldY = fieldMap.getField(currentPositionDet).y();
433+
434+
// Get a trajectory (Helix or Line objects) created with the
435+
// track parameters at the current position.
436+
Trajectory trajectory = TrackUtils.getTrajectory(currentMomentum, new org.lcsim.spacegeom.SpacePoint(currentPosition), q, bFieldY);
437+
438+
// Using the new trajectory, extrapolated the track by a step and
439+
// update the extrapolated position.
440+
//if(CoordinateTransformations.transformVectorToTracking(startPosition).x() > currentPosition.x()){
441+
if(currentMomentum.x() > 0){
442+
//System.out.println("Track is going Forwards!");
443+
return null;
444+
}
445+
currentPosition = trajectory.getPointAtDistance(stepSize);
446+
447+
// Calculate the momentum vector at the new position. This will
448+
// be used when creating the trajectory that will be used to
449+
// extrapolate the track in the next iteration.
450+
currentMomentum = VecOp.mult(currentMomentum.magnitude(), trajectory.getUnitTangentAtLength(stepSize));
451+
452+
//System.out.println(currentPosition.x() + " " + currentPosition.y() + " " + currentPosition.z() + " ");
453+
454+
// If the position of the track along X (or z in the detector frame)
455+
// is at 90% of the total distance, reduce the step size.
456+
if (currentPosition.x() / startPositionZ > .80 && !stepSizeChange) {
457+
stepSize /= 10;
458+
//System.out.println("Changing step size: " + stepSize);
459+
stepSizeChange = true;
460+
}
461+
}
462+
463+
// Transform vector back to detector frame
464+
return CoordinateTransformations.transformVectorToDetector(currentPosition);
465+
}
466+
467+
321468
}

analysis/src/main/java/org/hps/analysis/MC/TrackTruthMatching.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void doAnalysis(Track trk, RelationalTable hittomc){
8484
if (mcmap.containsKey(mcp))
8585
mchits = mcmap.get(mcp);
8686
mchits++;
87-
//System.out.println("mchits " + mchits);
87+
//System.out.println("mcp " + mcp + " ID " + mcp.getPDGID() + " mchits " + mchits);
8888

8989
mcmap.put(mcp, mchits);
9090
}

analysis/src/main/java/org/hps/analysis/tuple/FullTruthTupleDriver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ protected void setupVariables() {
1111
tupleVariables.clear();
1212
addEventVariables();
1313
addFullMCTridentVariables();
14+
addFullMCWabVariables();
1415
}
1516

1617
protected void addEventVariables() {
@@ -23,6 +24,7 @@ public void process(EventHeader event) {
2324

2425
fillTruthEventVariables(event);
2526
fillMCFullTruthVariables(event);
27+
fillMCWabVariables(event);
2628

2729
if (tupleWriter != null) {
2830
writeTuple();

analysis/src/main/java/org/hps/analysis/tuple/TridentTupleDriver.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ protected void setupVariables() {
4444
addParticleVariables("ele");
4545
addParticleVariables("pos");
4646
if(getFullTruth){
47-
addFullTruthVertextVariables();
47+
addFullTruthVertexVariables();
4848
}
4949
String[] newVars = new String[]{"minPositiveIso/D", "minNegativeIso/D", "minIso/D"};
5050
tupleVariables.addAll(Arrays.asList(newVars));
5151
if (getMC) {
52-
addFullMCTridentVariables();
53-
addFullMCWabVariables();
52+
addMCTridentVariables();
5453
}
5554
}
5655

@@ -119,8 +118,6 @@ public void process(EventHeader event) {
119118

120119
if (getMC) {
121120
fillMCTridentVariables(event);
122-
fillMCWabVariables(event);
123-
fillMCFullTruthVariables(event);
124121
}
125122

126123
if (getFullTruth){

0 commit comments

Comments
 (0)