lcsim-contrib/src/main/java/org/lcsim/contrib/SteveMagill
diff -N TrCoreDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TrCoreDriver.java 14 Feb 2012 19:22:40 -0000 1.1
@@ -0,0 +1,161 @@
+ package org.lcsim.contrib.SteveMagill;
+
+// This driver searches for track cal cluster matches for clusters very close to the track,
+// called core clusters. It starts from the position of the mip cluster and looks
+// for clusters within the same distance of the track as the mip finder. The object
+// is to find only the core of the shower without expanding into a larger volume.
+// input : tracks, calorimeter clusters, input maps from mip finder
+// output : core clusters associated to tracks
+
+import java.util.*;
+import org.lcsim.event.*;
+import org.lcsim.util.Driver;
+import org.lcsim.recon.cluster.util.*;
+import org.lcsim.util.aida.*;
+import hep.aida.*;
+import org.lcsim.spacegeom.*;
+
+public class TrCoreDriver extends Driver
+{
+ ITree tree;
+ IHistogramFactory histogramFactory;
+ IAnalysisFactory analysisFactory = IAnalysisFactory.create();
+ private AIDA aida = AIDA.defaultInstance();
+ private double _mincor;
+ private String _inclusname;
+ private String _outclusname;
+ private String _modclusname;
+ private String _tilname;
+ private String _tccname;
+ private String _intrlist;
+ private boolean trshdb = true;
+
+ public TrCoreDriver(double mincor)
+ {
+ // add arguments if needed
+ _mincor = mincor; // minimum distance to core (default 0.01)
+ }
+
+ protected void process(EventHeader event)
+ {
+ List<BasicCluster> inclus = event.get(BasicCluster.class,_inclusname);
+ // make a copy of input cluster list
+ List<BasicCluster> copyinclus = new ArrayList<BasicCluster>();
+ for (BasicCluster icl : inclus)
+ {
+ BasicCluster shclus = new BasicCluster();
+ if (icl.getSize()>0)
+ {
+ shclus.addCluster(icl);
+ copyinclus.add(shclus);
+ }
+ }
+
+ // get list of tracks to start from
+ List<Track> tracks = event.get(Track.class, _intrlist);
+ // this will be list of output core clusters
+ List<BasicCluster> trcoreclus = new ArrayList<BasicCluster>();
+ // also need a map linking coreclus to track
+ Map<Track, BasicCluster> trcoreclusmap = new HashMap<Track, BasicCluster>();
+ // Get map linking tracks to IL SpacePoints
+ Map<Track, SpacePoint> trilmap = (Map<Track, SpacePoint>) event.get(_tilname);
+
+ // loop over all tracks
+ int nclus = 0; // count number of clusters used to make cores
+ for (Track itr : tracks)
+ {
+ BasicCluster tcclus = new BasicCluster(); // only cores
+ // get associated IL coordinates from IL map
+ SpacePoint trIL = trilmap.get(itr);
+ double trxyzil = trIL.rxyz(); // rxyz of track spacepoint at IL
+// double trtheta = trIL.theta(); // track theta at IL
+// double trphi = trIL.phi(); // track phi at IL
+ double trilth = Math.atan(trIL.rxy()/trIL.z());
+ if (trilth<0) trilth+=Math.PI;
+ double trilph = Math.atan2(trIL.y(),trIL.x());
+ if (trilph<0) trilph+=2*Math.PI;
+
+ // now, find clusters very close to track - core clusters using same distance criteria as for mips
+ // this is essentially the mip finder on clusters with no density rquirement
+ int ncore = 0; // number of clusters for this track
+ double[] trcclth = new double[100];
+ double[] trcclph = new double[100];
+ double[] trcclrxyz = new double[100];
+ for (Iterator<BasicCluster> incl = copyinclus.iterator(); incl.hasNext();)
+ {
+ BasicCluster ibcl = incl.next();
+ // first, check cluster rxyz and compare to trIL rxyz, only considering if
+ // cluster rxyz>trIL rxyz - attaches clusters beyond IL
+ double[] ccpos = ibcl.getPosition();
+ double clrxyz = Math.sqrt(ccpos[0]*ccpos[0]+ccpos[1]*ccpos[1]+ccpos[2]*ccpos[2]);
+ if (trxyzil>clrxyz) continue; // don't consider this cluster, before mip
+ double ccph = Math.atan2(ccpos[1],ccpos[0]);
+ if (ccph<0) ccph+=2*Math.PI;
+ double ccr = Math.sqrt(ccpos[0]*ccpos[0]+ccpos[1]*ccpos[1]);
+ double ccth = Math.atan(ccr/ccpos[2]);
+ if (ccth<0) ccth+=Math.PI;
+ // have cluster theta and phi, now calculate distance for test
+ // uses distance of cluster to IL spacepoint
+ double dist = 999;
+ double dccth = Math.abs(trilth-ccth);
+ double dccph = Math.abs(trilph-ccph);
+ if (dccph>Math.PI) dccph = 2*Math.PI-dccph;
+ dist = Math.sqrt(dccth*dccth+dccph*dccph);
+// System.out.println(" Distance in Core Clusterer " + dist);
+ // test distance
+ if (dist<_mincor)
+ {
+ trcclth[ncore] = ccth;
+ trcclph[ncore] = ccph;
+ trcclrxyz[ncore] = clrxyz;
+ ncore++;
+ nclus++;
+ // add cluster to core, remove from cluster list
+ tcclus.addCluster(ibcl);
+ incl.remove();
+ }
+ }
+ if (tcclus.getSize()>0)
+ {
+ trcoreclus.add(tcclus);
+ trcoreclusmap.put(itr, tcclus);
+ }
+ }
+// System.out.println(" Number of clusters used for cores" + nclus);
+
+// if (trcoreclus.size()>0)
+// {
+ event.put(_outclusname,trcoreclus,BasicCluster.class,0);
+ event.put(_tccname,trcoreclusmap);
+// }
+
+ event.put(_modclusname,copyinclus,BasicCluster.class,0);
+
+ }
+
+ public void setInputTrackList(String trlist)
+ {
+ _intrlist = trlist;
+ }
+ public void setInputClusterList(String name)
+ {
+ _inclusname = name;
+ }
+ public void setModClusterList(String mname)
+ {
+ _modclusname = mname;
+ }
+ public void setOutCoreClusterList(String outclname)
+ {
+ _outclusname = outclname;
+ }
+ public void setTrackILPosMap(String tilname)
+ {
+ _tilname = tilname;
+ }
+ public void setTrackCoreClusMap(String tccname)
+ {
+ _tccname = tccname;
+ }
+}
+