hps-java/src/main/java/org/lcsim/hps/recon/particle
diff -u -r1.5 -r1.6
--- ReconParticleDriver.java 12 Apr 2013 17:25:07 -0000 1.5
+++ ReconParticleDriver.java 15 Apr 2013 07:14:32 -0000 1.6
@@ -14,17 +14,12 @@
import org.lcsim.event.ReconstructedParticle;
import org.lcsim.event.Track;
import org.lcsim.event.base.BaseReconstructedParticle;
-import org.lcsim.fit.helicaltrack.HelicalTrackFit;
-import org.lcsim.recon.tracking.seedtracker.SeedCandidate;
-import org.lcsim.recon.tracking.seedtracker.SeedTrack;
+import org.lcsim.geometry.Detector;
import org.lcsim.util.Driver;
//--- hps-java ---//
import org.lcsim.hps.recon.ecal.HPSEcalCluster;
import org.lcsim.hps.recon.tracking.SvtTrackExtrapolator;
-import org.lcsim.hps.recon.vertexing.BilliorTrack;
-import org.lcsim.hps.recon.vertexing.BilliorVertex;
-import org.lcsim.hps.recon.vertexing.BilliorVertexer;
/**
* Driver that matches SVT Tracks and Ecal Clusters and creates
@@ -32,24 +27,20 @@
*
* @author Mathew Graham <[log in to unmask]>
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: ReconParticleDriver.java,v 1.5 2013/04/12 17:25:07 omoreno Exp $
+ * @version $Id: ReconParticleDriver.java,v 1.6 2013/04/15 07:14:32 omoreno Exp $
*/
-public class ReconParticleDriver extends Driver {
+public abstract class ReconParticleDriver extends Driver {
SvtTrackExtrapolator extrapolator = new SvtTrackExtrapolator();
-
- // List to contained all tracks which have been matched in an event
- List<Track> matchedTracks;
- List<HPSEcalCluster> matchedClusters;
-
+
// Flags
boolean debug = false;
// Reconstructed particle collections
List<ReconstructedParticle> reconParticles;
- List<ReconstructedParticle> aprimeCands;
- List<ReconstructedParticle> aprimeCandsCon;
- List<ReconstructedParticle> aprimeCandsTarget;
+ List<ReconstructedParticle> candidates;
+ List<ReconstructedParticle> candidatesBeamCon;
+ List<ReconstructedParticle> candidatesTargetCon;
List<ReconstructedParticle> electrons;
List<ReconstructedParticle> positrons;
@@ -57,13 +48,16 @@
String ecalClustersCollectionName = "EcalClusters";
String tracksCollectionName = "MatchedTracks";
String finalStateParticlesCollectionName = "FinalStateParticles";
- String aprimeCandidatesName = "APrimeUnconstrained";
- String aprimeCandidatesConstrainedName = "APrimeBeamspotConstrained";
- String aprimeCandidatesTargetName = "APrimeTargetConstrained";
+ String candidatesCollectionName = null;
+ String candidatesBeamConCollectionName = null;
+ String candidatesTargetConCollectionName = null;
+ String vertexCandidatesCollectionName = null;
+ String vertexBeamConsCandidatesName = null;
// The beamsize array is in the tracking frame
double[] beamsize = {0.001, 0.2, 0.02};
double maxTrackClusterDistance = 1000; // [mm]
+ double bField;
// flipSign is a kludge...
@@ -105,14 +99,19 @@
public void setBeamSigmaY(double sigma_y) {
beamsize[2] = sigma_y;
}
+
+
+ @Override
+ protected void detectorChanged(Detector detector){
+
+ Hep3Vector ip = new BasicHep3Vector(0., 0., 1.);
+ bField = detector.getFieldMap().getField(ip).y();
+ if(bField < 0) flipSign = -1;
+
+ }
public void process(EventHeader event) {
- // Set the sign of the variable flipSign (See above for details)
- Hep3Vector IP = new BasicHep3Vector(0., 0., 1.);
- double bfield = event.getDetector().getFieldMap().getField(IP).y();
- if (bfield < 0) flipSign = -1;
-
// If the event does not have Ecal clusters, skip the event
if (!event.hasCollection(HPSEcalCluster.class, ecalClustersCollectionName)) return;
@@ -121,37 +120,59 @@
if(clusters.isEmpty()) return;
this.printDebug("Number of Ecal clusters: " + clusters.size());
-
// Get the tracks in the event
List<Track> tracks = event.get(Track.class, tracksCollectionName);
this.printDebug("Number of Tracks: " + tracks.size());
-
-
- // Instantiate the list of matched tracks and clusters. This list
- // will be used to check if a track has already been previously matched
- matchedTracks = new ArrayList<Track>();
- matchedClusters = new ArrayList<HPSEcalCluster>();
-
- reconParticles = new ArrayList<ReconstructedParticle>();
- aprimeCands = new ArrayList<ReconstructedParticle>();
- aprimeCandsCon = new ArrayList<ReconstructedParticle>();
- aprimeCandsTarget = new ArrayList<ReconstructedParticle>();
- electrons = new ArrayList<ReconstructedParticle>();
- positrons = new ArrayList<ReconstructedParticle>();
+ reconParticles = new ArrayList<ReconstructedParticle>();
+ electrons = new ArrayList<ReconstructedParticle>();
+ positrons = new ArrayList<ReconstructedParticle>();
+ candidates = new ArrayList<ReconstructedParticle>();
+ candidatesBeamCon = new ArrayList<ReconstructedParticle>();
+ candidatesTargetCon = new ArrayList<ReconstructedParticle>();
// If there are clusters and tracks in the event, try to match them
// to each other
- if (!tracks.isEmpty() && !clusters.isEmpty()) {
+ if (!tracks.isEmpty() && !clusters.isEmpty()) this.matchTracksToClusters(clusters, tracks);
- // Loop over all Ecal clusters in the event
- HPSEcalCluster matchedCluster = null;
+ // Put all the reconstructed particles in the event
+ event.put(finalStateParticlesCollectionName, reconParticles, ReconstructedParticle.class, 0);
+
+ // Vertex electron and positron candidates
+ vertexParticles(electrons, positrons);
+
+ // If the list exist, put the vertexed candidates into the event
+ if(candidatesCollectionName != null)
+ event.put(candidatesCollectionName, candidates, ReconstructedParticle.class, 0);
+ if(candidatesBeamConCollectionName != null)
+ event.put(candidatesBeamConCollectionName, candidatesBeamCon, ReconstructedParticle.class, 0);
+ if(candidatesTargetConCollectionName != null)
+ event.put(candidatesTargetConCollectionName, candidatesTargetCon, ReconstructedParticle.class, 0);
+ }
+
+ /**
+ *
+ */
+ abstract void vertexParticles(List<ReconstructedParticle> electrons, List<ReconstructedParticle> positrons);
+
+ /**
+ *
+ */
+ private void matchTracksToClusters(List<HPSEcalCluster> clusters, List<Track> tracks){
+
+ // Instantiate the list of matched tracks and clusters. This list
+ // will be used to check if a track has already been previously matched
+ List<Track> matchedTracks = new ArrayList<Track>();
+ List<HPSEcalCluster> matchedClusters = new ArrayList<HPSEcalCluster>();
+
+ // Loop over all clusters
+ HPSEcalCluster matchedCluster = null;
for(HPSEcalCluster cluster : clusters){
-
+
// If the cluster has already been matched to a track, continue
// on to the next cluster
if(matchedClusters.contains(cluster)) continue;
- matchedCluster = cluster;
+ matchedCluster = cluster;
// Get the Ecal cluster position
Hep3Vector clusterPos = new BasicHep3Vector(cluster.getPosition());
@@ -162,7 +183,7 @@
double rMax = Double.MAX_VALUE;
// Loop over all tracks in the event
for(Track track : tracks){
-
+
// Check if the track has already been matched to another cluster
if(matchedTracks.contains(track)){
this.printDebug("Track has already been matched");
@@ -194,8 +215,9 @@
matchedTrack = track;
matchedTrackPosition = trkPosAtShowerMax;
}
- }
-
+ }
+
+
// If a matching track isn't found, continue to the next cluster
// in the event. This will occur when a track is found to have
// NaN coordinate values as explained above or when the distance
@@ -209,13 +231,22 @@
// Check if the track is a closer match to any other cluster in
// the event
for(HPSEcalCluster ecalCluster : clusters){
+
+ // Skip the current cluster and any other cluster that has
+ // been matched already
if(ecalCluster.equals(cluster) || matchedClusters.contains(ecalCluster)) continue;
+ // Get the Ecal cluster position
Hep3Vector ecalClusterPos = new BasicHep3Vector(ecalCluster.getPosition());
this.printDebug("Ecal cluster position: " + ecalClusterPos.toString());
+
+ // Get the position of the track at the Ecal cluster shower max
extrapolator.setTrack(matchedTrack);
Hep3Vector trkPosAtShowerMax = extrapolator.extrapolateTrack(ecalClusterPos.z());
this.printDebug("Track position at shower max: " + trkPosAtShowerMax.toString());
+
+ // Get the distance between the track and the cluster position
+ // and check if the track has a better cluster match
double r = VecOp.sub(trkPosAtShowerMax, ecalClusterPos).magnitude();
if(r < rMax && r <= maxTrackClusterDistance){
rMax = r;
@@ -235,15 +266,14 @@
particle.addCluster(matchedCluster);
particle.addTrack(matchedTrack);
reconParticles.add(particle);
-
+
// Add the particle to either the collection of possible
// electrons or positrons
if(matchedTrack.getCharge()*flipSign > 0) positrons.add(particle);
else electrons.add(particle);
-
- }
- }
-
+
+ }
+
// After iterating through all tracks, if there still
// exist some clusters in the list then assign them
// to their own reconstructed particles
@@ -254,70 +284,14 @@
reconParticles.add(particle);
}
}
-
- // Put all the reconstructed particles in the event
- event.put(finalStateParticlesCollectionName, reconParticles, ReconstructedParticle.class, 0);
-
- BilliorVertexer vtxfitter = new BilliorVertexer(bfield);
- vtxfitter.doBeamSpotConstraint(false);
- vtxfitter.setBeamSize(beamsize);
-
- BilliorVertexer vtxfitterCon = new BilliorVertexer(bfield);
- vtxfitterCon.doBeamSpotConstraint(true);
- vtxfitterCon.setBeamSize(beamsize);
-
- BilliorVertexer vtxfitterTarget = new BilliorVertexer(bfield);
- vtxfitterTarget.doTargetConstraint(true);
- vtxfitterTarget.setBeamSize(beamsize);
-
- for (ReconstructedParticle pos : positrons) {
- for (ReconstructedParticle ele : electrons) {
- SeedTrack eleTrack=(SeedTrack) ele.getTracks().get(0);
- SeedTrack posTrack=(SeedTrack) pos.getTracks().get(0);
- BilliorTrack btEle = getBilliorTrack( eleTrack);
- BilliorTrack btPos = getBilliorTrack( posTrack);
- List<BilliorTrack> btlist = new ArrayList<BilliorTrack>();
- btlist.add(btEle);
- btlist.add(btPos);
- BilliorVertex vtxfit = vtxfitter.fitVertex(btlist);
- BilliorVertex vtxfitCon = vtxfitterCon.fitVertex(btlist);
- BilliorVertex vtxfitTarget = vtxfitterTarget.fitVertex(btlist);
-
- BaseReconstructedParticle apCand = new BaseReconstructedParticle();
- apCand.setStartVertex(vtxfit);
- apCand.addParticle(ele);
- apCand.addParticle(pos);
- aprimeCands.add(apCand);
-
- BaseReconstructedParticle apCandCon = new BaseReconstructedParticle();
- apCandCon.setStartVertex(vtxfitCon);
- apCandCon.addParticle(ele);
- apCandCon.addParticle(pos);
- aprimeCandsCon.add(apCandCon);
-
- BaseReconstructedParticle apCandTarget = new BaseReconstructedParticle();
- apCandTarget.setStartVertex(vtxfitTarget);
- apCandTarget.addParticle(ele);
- apCandTarget.addParticle(pos);
- aprimeCandsTarget.add(apCandTarget);
- }
- }
-
- event.put(aprimeCandidatesConstrainedName, aprimeCandsCon, ReconstructedParticle.class, 0);
- event.put(aprimeCandidatesTargetName, aprimeCandsTarget, ReconstructedParticle.class, 0);
- event.put(aprimeCandidatesName, aprimeCands, ReconstructedParticle.class, 0);
-
}
-
+
+ /**
+ *
+ * @param debugMessage
+ */
private void printDebug(String debugMessage){
if(debug)
System.out.println(this.getClass().getSimpleName() + ": " + debugMessage);
}
-
- private BilliorTrack getBilliorTrack(SeedTrack st) {
- SeedTrack stEle = (SeedTrack) st;
- SeedCandidate seedEle = stEle.getSeedCandidate();
- HelicalTrackFit htEle = seedEle.getHelix();
- return new BilliorTrack(htEle);
- }
}