Commit in hps-java/src/main/java/org/lcsim/hps/recon/tracking on MAIN | |||
DataTrackerFakeHitDriver.java | +154 | -41 | 1.5 -> 1.6 |
Changed SimTrackerHit creation so that the start and end points of the hit lie within the sensor volume; Work in progress ...
diff -u -r1.5 -r1.6 --- DataTrackerFakeHitDriver.java 15 Nov 2012 02:49:06 -0000 1.5 +++ DataTrackerFakeHitDriver.java 19 Nov 2012 22:11:11 -0000 1.6 @@ -11,10 +11,14 @@
import hep.physics.vec.VecOp; import java.util.*; import org.lcsim.detector.IDetectorElement;
-import org.lcsim.detector.IReadout;
import org.lcsim.detector.ITransform3D;
+import org.lcsim.detector.ITranslation3D;
import org.lcsim.detector.Transform3D;
+import org.lcsim.detector.Translation3D;
import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.solids.Box; +import org.lcsim.detector.solids.Inside; +import org.lcsim.detector.solids.Polygon3D;
import org.lcsim.detector.tracker.silicon.*; import org.lcsim.event.EventHeader; import org.lcsim.event.MCParticle;
@@ -26,11 +30,8 @@
import org.lcsim.fit.helicaltrack.HelicalTrackHit; import org.lcsim.fit.helicaltrack.HelixUtils; import org.lcsim.fit.helicaltrack.HitIdentifier;
-import org.lcsim.fit.helicaltrack.HitUtils;
import org.lcsim.geometry.Detector; import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
-import org.lcsim.hps.recon.tracking.apv25.SvtReadout; -import org.lcsim.hps.users.omoreno.SimpleSvtTrigger;
import org.lcsim.hps.users.phansson.WTrack; import org.lcsim.hps.users.phansson.WTrackUtils; import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHit;
@@ -39,7 +40,6 @@
import org.lcsim.recon.tracking.digitization.sisim.TrackerHitType.CoordinateSystem; import org.lcsim.util.Driver; import org.lcsim.util.aida.AIDA;
-import org.lcsim.util.lcio.LCIOUtil;
/** *
@@ -57,6 +57,7 @@
TrackerHitType trackerType = new TrackerHitType(TrackerHitType.CoordinateSystem.GLOBAL, TrackerHitType.MeasurementType.STRIP_1D); CoordinateSystem coordinate_system = trackerType.getCoordinateSystem(); private HitIdentifier _ID = new HitIdentifier();
+ private EventHeader.LCMetaData metaData = null;
private boolean _doHth = false; boolean createSimTrackerHits = false;
@@ -191,7 +192,8 @@
*/ @Override public void process(EventHeader event) {
-
+ +
// Obtain the tracks from the event if(!event.hasCollection(HpsHelicalTrackFit.class, trackCollectionName)){ this.printDebug("No HpsHelicalTrackFits were found, skipping event");
@@ -209,24 +211,18 @@
} else if(createSimTrackerHits){ this.printDebug("Creating SimTrackerHits..."); simHits = new ArrayList<SimTrackerHit>();
+ metaData = event.getMetaData(event.get(SimTrackerHit.class, "TrackerHits"));
} else { // Create StripHit1Ds by default this.printDebug("Creating StripHit1D..."); stripHits1D = new ArrayList<SiTrackerHit>(); }
- - /*// Make new lists for output. - List<SiTrackerHit> stripHits1D = new ArrayList<SiTrackerHit>(); - List<HelicalTrackHit> hths = new ArrayList<HelicalTrackHit>(); */
if(debug) System.out.println(this.getClass().getSimpleName() + ": Add hits for " + tracks.size() + " tracks (" + this.trackCollectionName + ")"); for(HpsHelicalTrackFit helix : tracks) { if(debug) System.out.println(this.getClass().getSimpleName() + ": trying to add hits for this track");
- //List<SiTrackerHit> stripHits1D_for_track = new ArrayList<SiTrackerHit>(); - //List<HelicalTrackHit> hths_for_track = new ArrayList<HelicalTrackHit>(); -
// Get the MC Particle associated with this track MCParticle mcParticle = helix.getMCParticle();
@@ -263,22 +259,14 @@
continue; }
- // Get the sensor position along the z direction - double zposition = sensor.getGeometry().getPosition().z(); - - // Get the position where the sensor and track intercept
+ // Get the position where the sensor and track intercept (Maybe this should go + // inside the method makeSimTrackerHit since it's the only method that uses it
Hep3Vector trackPosAtSensor = this.getHelixPlaneIntercept(sensor, wtrack);
+ this.printDebug("The track/plane intercept at " + trackPosAtSensor.toString());
- - if(debug) { - System.out.printf("%s: track/plane intercept at %s\n",this.getClass().getSimpleName(),trackPosAtSensor.toString(),zposition); - } -
// Check if the track lies within the sensor boolean isHit = trackUtils.sensorContainsTrack(trackPosAtSensor, sensor);
- -
if(isHit) { if(debug) System.out.println(this.getClass().getSimpleName() + ": make a tracker hit and add to this sensor"); if(SvtUtils.getInstance().isTopLayer(sensor)) {
@@ -293,10 +281,8 @@
hths.add(this.makeHelicalTrackHit(sensor, wtrack)); } else if(createSimTrackerHits){ // Create a SimTrackerHit at the intersect between a track and a sensor
- simHits.add(this.makeSimTrackerHit(sensor, trackPosAtSensor, mcParticle));
+ simHits.add(this.makeSimTrackerHit(metaData, sensor, trackPosAtSensor, mcParticle, wtrack));
} else {
- - this.printDebug("Creating a SimTrackerHit at position: " + trackPosAtSensor);
stripHits1D.add(this.makeTrackerHit(sensor, wtrack)); } } else {
@@ -544,7 +530,7 @@
/* * Weird way of getting the org location by creating a fake raw tracker hit...must be simpler way? */
- List<RawTrackerHit> rth_cluster = this.makeRawTrackerFakeHit(sensor);
+ List<RawTrackerHit> rth_cluster = this.makeRawTrackerFakeHit(sensor);
if(rth_cluster.size()!=1) { System.out.println(this.getClass().getSimpleName() + ": the fake raw tracker hit cluster is different than one!? " + rth_cluster.size() ); System.exit(1);
@@ -583,7 +569,7 @@
Hep3Vector h = new BasicHep3Vector(_bfield.x(),_bfield.y(),Math.abs(_bfield.z())); h = VecOp.unit(h); Hep3Vector position = wutils.getHelixAndPlaneIntercept(wtrack, _orgloc, eta, h);
- if(debug) {
+ if(debug) {
HelicalTrackFit htf = wtrack._htf; List<Double> s = HelixUtils.PathToXPlane(htf, position.x(), 0, 0); Hep3Vector posOnHelix = HelixUtils.PointOnHelix(htf, s.get(0));
@@ -657,31 +643,158 @@
/** * Create a SimTrackerHit and add it to the corresponding readout *
+ * @param metaData : meta data associated with the SimTrackerHit collection
* @param sensor : sensor on which the hit will be created on
- * @param trkPositionAtSensor : the position at which the SimTrackerHit will be created at
+ * @param trkPositionAtSensor : the position of a track at a sensor plane
* @param particle : MC particle associated with the track containing the hit * @return SimTrackerHit */
- private SimTrackerHit makeSimTrackerHit(SiSensor sensor, Hep3Vector trkPositionAtSensor, MCParticle particle){ - Hep3Vector trkPositionAtSensorDet = VecOp.mult(VecOp.inverse(detToTrk),trkPositionAtSensor); - if(this.debug) { - System.out.printf("%s: makeSimTrackerHit for sensor %s at position %s in JLab coord (from %s) for MCp pvec=%s \n",this.getClass().getSimpleName(),sensor.getName(),trkPositionAtSensorDet.toString(),trkPositionAtSensor.toString(),particle.getMomentum().toString()); -
+ private SimTrackerHit makeSimTrackerHit(EventHeader.LCMetaData metaData, SiSensor sensor, Hep3Vector trkPositionAtSensor, MCParticle particle, WTrack wtrack){ + + // Transform the position of the SimTrackerHit to the detector coordinates + // TODO: Fix the extrapolator so that it returns the position in the detector frame + //Hep3Vector trkPositionAtSensorDet = VecOp.mult(VecOp.inverse(detToTrk),trkPositionAtSensor); + //this.printDebug("The helix and sensor intercept at: " + trkPositionAtSensorDet.toString()); + + // Sensor to tracking frame transformation + ITransform3D localToGlobal = sensor.getGeometry().getLocalToGlobal(); + // Tracking frame to sensor transformation + ITransform3D globalToSensor = sensor.getGeometry().getGlobalToLocal(); + + // Get the sensor position + Hep3Vector sensorPosition = sensor.getGeometry().getPosition(); + this.printDebug("Sensor position: " + sensorPosition.toString()); + // Transform the sensor position to the tracking frame + Hep3Vector transformedSensorPosition = globalToSensor.transformed(sensorPosition); + this.printDebug("Transformed sensor position: " + transformedSensorPosition.toString()); + + // Get the solid representing a sensor + Box sensorSolid = (Box) sensor.getGeometry().getLogicalVolume().getSolid(); + // Get the solid faces + Polygon3D pSide = sensorSolid.getFacesNormalTo(new BasicHep3Vector(0,0,1)).get(0); + this.printDebug("p Side: " + pSide.toString()); + Polygon3D nSide = sensorSolid.getFacesNormalTo(new BasicHep3Vector(0,0,-1)).get(0); + this.printDebug("n Side: " + pSide.toString()); + + // Translate to the sensor face (p side) + ITranslation3D translateToPSide = new Translation3D(VecOp.mult(-pSide.getDistance(), pSide.getNormal())); + this.printDebug("pSide Translation vector: " + translateToPSide.getTranslationVector().toString()); + + // Translate to the p side of the sensor + Hep3Vector pSidePosition = translateToPSide.translated(transformedSensorPosition); + this.printDebug("Translated sensor position at p side: " + pSidePosition.toString()); + // Transform the sensor position to the tracking coordinates + localToGlobal.transform(pSidePosition); + this.printDebug("Translated sensor position at p side in tracking coordinates: " + pSidePosition.toString()); + // Check if the point lies inside of the sensor + if(sensor.getGeometry().inside(pSidePosition) == Inside.OUTSIDE){ + throw new RuntimeException("Position of p side face does not lie within the sensor volume!"); + } else { + this.printDebug("p side position lies within the sensor volume"); + } + + // Find the interception between the p side face and the track + Hep3Vector h = new BasicHep3Vector(_bfield.x(),_bfield.y(),Math.abs(_bfield.z())); + h = VecOp.unit(h); + // Transform the sensor position to the lcsim coordinates + pSidePosition = VecOp.mult(detToTrk, pSidePosition); + this.printDebug("p side position in lcsim coordinates: " + pSidePosition.toString()); + //Hep3Vector pSideInter = wutils.getHelixAndPlaneIntercept(wtrack, pSidePosition, VecOp.unit(pSidePosition), h); + Hep3Vector eta = this.getPlaneUnitVector(sensor); + Hep3Vector pSideInter = wutils.getHelixAndPlaneIntercept(wtrack, pSidePosition, eta , h); + this.printDebug("Intersection between track and p side: " + pSideInter.toString()); + // Transform back to the JLab coordinates + pSideInter = VecOp.mult(VecOp.inverse(detToTrk), pSideInter); + this.printDebug("Intersection trasnformed to the JLab coordinates: " + pSideInter.toString()); + if(sensor.getGeometry().inside(pSideInter) == Inside.OUTSIDE){ + throw new RuntimeException("Position of p side/track intercept does not lie within the sensor volume!"); + } else { + this.printDebug("p side/track intercept lies within the sensor volume");
}
+ + // Translate to the sensor n side + ITranslation3D translateToNSide = new Translation3D(VecOp.mult(-nSide.getDistance(), nSide.getNormal())); + this.printDebug("n side Translation vector: " + translateToNSide.getTranslationVector().toString()); + + // Translate to the n side of the sensor + Hep3Vector nSidePosition = translateToNSide.translated(transformedSensorPosition); + this.printDebug("Translated sensor position at n side: " + nSidePosition.toString()); + // Transform the sensor position to the tracking coordinates + localToGlobal.transform(nSidePosition); + this.printDebug("Translated sensor position at n side in tracking coordinates: " + nSidePosition.toString()); + // Check if the point lies inside of the sensor + if(sensor.getGeometry().inside(nSidePosition) == Inside.OUTSIDE){ + throw new RuntimeException("Position of n side face does not lie within the sensor volume!"); + } else { + this.printDebug("n side position lies within the sensor volume"); + } + + // Find the interception between the p side face and the track + // Transform the sensor position to the lcsim coordinates + nSidePosition = VecOp.mult(detToTrk, nSidePosition); + this.printDebug("n side position in lcsim coordinates: " + nSidePosition.toString()); + //Hep3Vector pSideInter = wutils.getHelixAndPlaneIntercept(wtrack, pSidePosition, VecOp.unit(pSidePosition), h); + Hep3Vector nSideInter = wutils.getHelixAndPlaneIntercept(wtrack, nSidePosition, eta , h); + this.printDebug("Intersection between track and n side: " + nSideInter.toString()); + // Transform back to the JLab coordinates + nSideInter = VecOp.mult(VecOp.inverse(detToTrk), nSideInter); + this.printDebug("Intersection trasnfored to the JLab coordinates: " + nSideInter.toString()); + if(sensor.getGeometry().inside(nSideInter) == Inside.OUTSIDE){ + throw new RuntimeException("Position of n side/track intercept does not lie within the sensor volume!"); + } else { + this.printDebug("n side/track intercept lies within the sensor volume"); + } + + // Find the midpoint between a straight line connecting the p side and n side intercepts + Hep3Vector trkPositionAtSensorDet = VecOp.add(nSideInter, pSideInter); + trkPositionAtSensorDet = VecOp.mult(.5, trkPositionAtSensorDet); + this.printDebug("Hit will be placed at position: " + trkPositionAtSensorDet.toString()); + if(sensor.getGeometry().inside(trkPositionAtSensorDet) == Inside.OUTSIDE){ + throw new RuntimeException("Midpoint does not lie within the sensor volume!"); + } else { + this.printDebug("midpoint lies within the sensor volume"); + } + + // Find the length of the line. For now, this is the path length + // Note: The small delta parameter is to avoid ending up outside of the sensor + double pathLength = VecOp.sub(nSideInter, pSideInter).magnitude() - .01; + this.printDebug("The path length is: " + pathLength); + + /* DEBUG + Hep3Vector midpoint = new BasicHep3Vector(trkPositionAtSensorDet.v()); + Hep3Vector direction = VecOp.unit(new BasicHep3Vector(particle.getMomentum().v())); + Hep3Vector half_length = VecOp.mult(pathLength/2.0,direction); + + Hep3Vector endPoint = VecOp.add(midpoint,half_length); + this.printDebug("The end point is at position: " + endPoint.toString()); + + Hep3Vector startPoint = VecOp.add(midpoint,VecOp.mult(-1.0,half_length)); + this.printDebug("The start point is at position: " + startPoint.toString()); + + if(sensor.getGeometry().inside(endPoint) == Inside.OUTSIDE){ + throw new RuntimeException("Position of end point does not lie within the sensor volume!"); + } else { + this.printDebug("end point lies within the sensor volume"); + } + + if(sensor.getGeometry().inside(startPoint) == Inside.OUTSIDE){ + throw new RuntimeException("Position start point does not lie within the sensor volume!"); + } else { + this.printDebug("Start point lies within the sensor volume"); + } */ +
double dEdx = 24000/* MIP */*DopedSilicon.ENERGY_EHPAIR; double[] momentum = particle.getMomentum().v();
- double pathLength = 0;
+ this.printDebug("Particle Momentum: " + particle.getMomentum().toString());
double time = 0; int cellID = (int) TrackerHitUtils.makeSimTrackerHitId(sensor).getValue();
- // Create a new SimTrackerHit - SimTrackerHit simHit = new BaseSimTrackerHit(trkPositionAtSensorDet.v(), dEdx, momentum, pathLength, time, cellID, particle, null, sensor);
+ + SimTrackerHit simHit = new BaseSimTrackerHit(trkPositionAtSensorDet.v(), dEdx, momentum, pathLength, time, cellID, particle, metaData, sensor);
// Add it to the sensor readout
- sensor.getReadout().addHit(simHit);
+ // sensor.getReadout().addHit(simHit);
return simHit; }
- -
//private SymmetricMatrix getCovariance() { private SymmetricMatrix getCovariance(List<RawTrackerHit> cluster, SiSensorElectrodes electrodes) { SymmetricMatrix covariance = new SymmetricMatrix(3);
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1