lcsim-contrib/src/main/java/org/lcsim/contrib/SteveMagill
diff -N SChClLinkDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SChClLinkDriver.java 12 Aug 2009 18:32:31 -0000 1.1
@@ -0,0 +1,113 @@
+package org.lcsim.contrib.SteveMagill;
+
+import java.util.*;
+import org.lcsim.event.*;
+import org.lcsim.util.Driver;
+import org.lcsim.recon.cluster.util.*;
+import org.lcsim.util.aida.AIDA;
+import hep.aida.ITree;
+
+public class SChClLinkDriver extends Driver
+{
+ private AIDA aida = AIDA.defaultInstance();
+ private double _clldis;
+ private int _ofrac;
+ private boolean linkD = true;
+ private String _sclusname;
+ private String _chclusname;
+ private String _olmapname;
+
+ public SChClLinkDriver(double clldis, int ofrac)
+ {
+ _clldis = clldis;
+ _ofrac = ofrac;
+ }
+
+ protected void process(EventHeader event)
+ {
+ super.process(event); // executes all added drivers
+
+ // loop over all Scin clusters
+ Map<BasicCluster, BasicCluster> schmap = new HashMap<BasicCluster, BasicCluster>();
+ int nlink = 0;
+ try
+ {
+ List<BasicCluster> Sclusters = event.get(BasicCluster.class,_sclusname);
+// System.out.println("Number of S Clus" + Sclusters.size());
+ for (BasicCluster sclus : Sclusters)
+ {
+ double ecp[] = sclus.getPosition();
+ double ecpx = ecp[0];
+ double ecpy = ecp[1];
+ double ecpz = ecp[2];
+ double ecR = Math.sqrt(ecpx*ecpx+ecpy*ecpy);
+ double eclth = Math.atan(ecR/ecpz);
+ if (eclth<0) eclth+=Math.PI;
+ double eclph = Math.atan2(ecpy,ecpx);
+ if (eclph<0) eclph+=2*Math.PI;
+ if (linkD) aida.cloud1D("Theta of S Clusters").fill(eclth);
+ if (linkD) aida.cloud1D("Phi of S Clusters").fill(eclph);
+
+ // now check with ch clusters to make links
+ try
+ {
+ List<BasicCluster> CHclusters = event.get(BasicCluster.class,_chclusname);
+// for (BasicCluster hadclus : HADclusters)
+ for (Iterator<BasicCluster> chcl = CHclusters.iterator(); chcl.hasNext();)
+ {
+ BasicCluster ihcl = chcl.next();
+ double hcp[] = ihcl.getPosition();
+ double hcpx = hcp[0];
+ double hcpy = hcp[1];
+ double hcpz = hcp[2];
+ double hcR = Math.sqrt(hcpx*hcpx+hcpy*hcpy);
+ double hclth = Math.atan(hcR/hcpz);
+ if (hclth<0) hclth+=Math.PI;
+ double hclph = Math.atan2(hcpy,hcpx);
+ if (hclph<0) hclph+=2*Math.PI;
+ if (linkD) aida.cloud1D("Theta of CH Clusters").fill(hclth);
+ if (linkD) aida.cloud1D("Phi of CH Clusters").fill(hclph);
+ // calculate distance in theta phi
+ double dccth = Math.abs(eclth-hclth);
+ double dccph = Math.abs(eclph-hclph);
+ if (dccph>Math.PI) dccph = 2*Math.PI-dccph;
+ double dist = Math.sqrt(dccth*dccth+dccph*dccph);
+ if (linkD) aida.cloud1D("Distance between S and CH clusters").fill(dist);
+ // test for distance and merge if close, removing merged hadclusters from list
+ if (dist<_clldis)
+ {
+ schmap.put(sclus, ihcl);
+ nlink++;
+ }
+ } // end of had cluster loop
+ }
+ catch (java.lang.IllegalArgumentException ex)
+ {
+ System.out.println("No CH clusters in link");
+ }
+ } // end of S cluster loop
+ }
+ catch (java.lang.IllegalArgumentException ex)
+ {
+ System.out.println("No S clusters in link");
+ }
+ aida.cloud1D("Number of S C cluster links").fill(nlink);
+ event.put(_olmapname,schmap);
+
+ } // end of event loop
+
+ public void setInputScinClusterName(String sclname)
+ {
+ _sclusname = sclname;
+ }
+ public void setInputCherClusterName(String chclname)
+ {
+ _chclusname = chclname;
+ }
+ public void setOutputLinkMapName(String olmapname)
+ {
+ _olmapname = olmapname;
+ }
+
+}
+