lcsim-contrib/src/main/java/org/lcsim/contrib/onoprien/vsegment/mctruth
diff -u -r1.3 -r1.4
--- MCTruthVS.java 24 Jan 2009 22:38:37 -0000 1.3
+++ MCTruthVS.java 26 Jan 2009 05:30:02 -0000 1.4
@@ -22,7 +22,7 @@
* be added to the processing chain (usually as the first driver).
*
* @author D. Onoprienko
- * @version $Id: MCTruthVS.java,v 1.3 2009/01/24 22:38:37 onoprien Exp $
+ * @version $Id: MCTruthVS.java,v 1.4 2009/01/26 05:30:02 onoprien Exp $
*/
public class MCTruthVS {
@@ -162,6 +162,16 @@
* Returns a map from MCParticles to lists of hits from the specified collections.
* Each MCParticle is mapped to a time-ordered list of hits to which it has contributed.
*
+ * @param collectionName List of names of <tt>ITrackerHit</tt> collections.
+ */
+ public HashMap<MCParticle, List<ITrackerHit>> mapByMCParticle(Collection<String> collectionNames) {
+ return mapByMCParticle(collectionNames.toArray(new String[collectionNames.size()]));
+ }
+
+ /**
+ * Returns a map from MCParticles to lists of hits from the specified collections.
+ * Each MCParticle is mapped to a time-ordered list of hits to which it has contributed.
+ *
* @param collectionName One ore more names of <tt>ITrackerHit</tt> collections.
*/
public HashMap<MCParticle, List<ITrackerHit>> mapByMCParticle(String... collectionName) {
@@ -185,8 +195,10 @@
HashMap<MCParticle, List<ITrackerHit>> outMap = new HashMap<MCParticle, List<ITrackerHit>>((int) (map.size()*1.5+1));
for (Map.Entry<MCParticle,HashSet<ITrackerHit>> entry : map.entrySet()) {
ArrayList<ITrackerHit> out = new ArrayList<ITrackerHit>(entry.getValue());
+ _mcComp = entry.getKey();
Collections.sort(out, _tCompITrHit);
- outMap.put(entry.getKey(), out);
+ outMap.put(_mcComp, out);
+ _mcComp = null;
}
return outMap;
}
@@ -215,8 +227,35 @@
private Comparator<ITrackerHit> _tCompITrHit = new Comparator<ITrackerHit>() {
public int compare(ITrackerHit hit1, ITrackerHit hit2) {
- return Double.compare(hit1.getTime(), hit2.getTime());
+ if (_mcComp == null) {
+ return Double.compare(hit1.getTime(), hit2.getTime());
+ } else {
+ SimTrackerHit sHit1 = null;
+ SimTrackerHit sHit2 = null;
+ List<SimTrackerHit> simList = getSimTrackerHits(hit1);
+ for (SimTrackerHit sHit : simList) {
+ if (sHit.getMCParticle() == _mcComp) {
+ sHit1 = sHit;
+ break;
+ }
+ }
+ simList = getSimTrackerHits(hit2);
+ for (SimTrackerHit sHit : simList) {
+ if (sHit.getMCParticle() == _mcComp) {
+ sHit2 = sHit;
+ break;
+ }
+ }
+ if (sHit1 == null) {
+ return (sHit2 == null) ? Double.compare(hit1.getTime(), hit2.getTime()) : -1;
+ } else if (sHit2 == null) {
+ return 1;
+ } else {
+ return _tCompSimTrHit.compare(sHit1, sHit2);
+ }
+ }
}
};
+ private MCParticle _mcComp;
}