Print

Print


Commit in lcsim/src/org/lcsim/recon/cheater on MAIN
RemoveMultipleHelicalTrackHitsCheater.java+33-91.1 -> 1.2
Also clean up the LCRelations when removing a hit

lcsim/src/org/lcsim/recon/cheater
RemoveMultipleHelicalTrackHitsCheater.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- RemoveMultipleHelicalTrackHitsCheater.java	19 Jul 2012 11:51:39 -0000	1.1
+++ RemoveMultipleHelicalTrackHitsCheater.java	20 Jul 2012 17:46:35 -0000	1.2
@@ -12,6 +12,7 @@
 
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.EventHeader.LCMetaData;
+import org.lcsim.event.LCRelation;
 import org.lcsim.event.MCParticle;
 import org.lcsim.event.RelationalTable;
 import org.lcsim.event.RelationalTable.Mode;
@@ -34,10 +35,14 @@
 public class RemoveMultipleHelicalTrackHitsCheater extends Driver {
 	
 	protected String trackHitCollection;
+	protected String trackHitRelations;
+	protected String trackMCRelations;
 	protected double coneAngle;
 	
 	public RemoveMultipleHelicalTrackHitsCheater() {
 		trackHitCollection = "HelicalTrackHits";
+		trackHitRelations = "HelicalTrackHitRelations";
+		trackMCRelations = "HelicalTrackMCRelations";
 		coneAngle = Math.PI/18.;
 	}
 	
@@ -45,6 +50,14 @@
 		this.trackHitCollection = trackHitCollection;
 	}
 	
+	public void setTrackHitRelations(String trackHitRelations) {
+		this.trackHitRelations = trackHitRelations;
+	}
+	
+	public void setTrackMCRelations(String trackMCRelations) {
+		this.trackMCRelations = trackMCRelations;
+	}
+	
 	/**
 	 * Sets the minimum angle between a first hit and a secondary hit in layer. If inside the cone the secondary hit will be removed.
 	 * @param coneAngle
@@ -55,8 +68,22 @@
 	
 	@Override
 	protected void process(EventHeader event) {
-		// get the collection of HelicalTrackHits
+		// get the collection of HelicalTrackHits and all its LCRelations
 		List<HelicalTrackHit> trackHits = event.get(HelicalTrackHit.class, trackHitCollection);
+		List<LCRelation> hitRelations = event.get(LCRelation.class, trackHitRelations);
+		List<LCRelation> mcRelations = event.get(LCRelation.class, trackMCRelations);
+		
+		// map to store the LCRelations connecting each hit with its simulated hits
+		RelationalTable<HelicalTrackHit, LCRelation> hitToHitRelationMap = new BaseRelationalTable<HelicalTrackHit, LCRelation>(Mode.MANY_TO_MANY, Weighting.UNWEIGHTED);
+		for (LCRelation relation : hitRelations) {
+			hitToHitRelationMap.add((HelicalTrackHit) relation.getFrom(), relation);
+		}
+		
+		// map to store the LCRelations connecting each hit with its mc particles
+		RelationalTable<HelicalTrackHit, LCRelation> hitToMCRelationMap = new BaseRelationalTable<HelicalTrackHit, LCRelation>(Mode.MANY_TO_MANY, Weighting.UNWEIGHTED);
+		for (LCRelation relation : mcRelations) {
+			hitToMCRelationMap.add((HelicalTrackHit) relation.getFrom(), relation);
+		}
 		
 		// map to store a map of particle to hit relations for each layer.
 		Map<String, RelationalTable<HelicalTrackHit, MCParticle>> layerToHitsToParticleMap = new HashMap<String, RelationalTable<HelicalTrackHit,MCParticle>>();
@@ -92,7 +119,6 @@
 			
 			// lists to store which hits to keep and which to remove
 			List<HelicalTrackHit> processedHits = new ArrayList<HelicalTrackHit>();
-			List<HelicalTrackHit> removeHits = new ArrayList<HelicalTrackHit>();
 			for (MCParticle particle : layerToParticleMap.get(identifier)) {
 				
 				// we just have a single hit from a particle: nothing to do
@@ -105,23 +131,21 @@
 					Hep3Vector v1 = hit.getCorrectedPosition();
 					processedHits.add(hit);
 					for (HelicalTrackHit otherHit : particleHits) {
-						if (removeHits.contains(otherHit) || processedHits.contains(otherHit)) continue;
+						if (!trackHits.contains(otherHit) || processedHits.contains(otherHit)) continue;
 						Hep3Vector v12 = VecOp.sub(otherHit.getCorrectedPosition(), v1);
 						
 						// calculate angle of the direction of the second hit with respect to the line-of-sight from IP to the first hit
 						double deltaPhi = Math.acos(VecOp.dot(v1, v12)/(v1.magnitude()*v12.magnitude()));
 						if (Math.abs(deltaPhi) < coneAngle) {
-							removeHits.add(otherHit);
+							// remove the hit and all relations pointing to it
+							trackHits.remove(otherHit);
+							hitRelations.removeAll(hitToHitRelationMap.allFrom(otherHit));
+							mcRelations.removeAll(hitToMCRelationMap.allFrom(otherHit));
 						}
 					}
 				}
 			}
-			trackHits.removeAll(removeHits);
 		}
-		LCMetaData meta = event.getMetaData(trackHits);
-		
-		// replace the collection
-		event.put(trackHitCollection, trackHits, HelicalTrackHit.class, meta.getFlags());
 	}
 	
 	/**
CVSspam 0.2.12


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