lcsim-contrib/src/main/java/org/lcsim/contrib/SteveMagill
diff -N CorrScClusToRPDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CorrScClusToRPDriver.java 14 Feb 2012 19:36:23 -0000 1.1
@@ -0,0 +1,120 @@
+package org.lcsim.contrib.SteveMagill;
+
+import hep.aida.ITree;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.particle.properties.ParticlePropertyManager;
+import hep.physics.particle.properties.ParticleType;
+import java.util.*;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.base.BaseReconstructedParticle;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+import org.lcsim.recon.cluster.util.*;
+import static java.lang.Math.sqrt;
+import org.lcsim.event.ParticleID;
+import org.lcsim.event.ReconstructedParticle;
+import org.lcsim.event.base.BaseParticleID;
+
+/*
+ * SimpleClusterToReconstructedParticleExampleDriver.java
+ *
+ * Created on March 29, 2007, 1:52 PM
+ *
+ * $Id: CorrScClusToRPDriver.java,v 1.1 2012/02/14 19:36:23 magill Exp $
+ */
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class CorrScClusToRPDriver extends Driver
+{
+ private AIDA aida = AIDA.defaultInstance();
+ private ITree _tree;
+ private String _clusternames;
+ private String _allrecoparticles;
+ private double _scfactor;
+ private double _ccfactor;
+ private double _p1;
+ private double _p2;
+ private double _p3;
+ private double _p4;
+ private double _sclc;
+ private double _cclc;
+
+ /** Creates a new instance of SimpleClusterToReconstructedParticleExampleDriver */
+ public CorrScClusToRPDriver(double scfactor, double ccfactor, double p1, double p2, double p3, double p4, double sclc, double cclc)
+ {
+ _tree = aida.tree();
+ _scfactor = scfactor; // calibration factor for scint cell energy
+ _ccfactor = ccfactor; // calibration factor for ceren cell energy
+ _p1 = p1;
+ _p2 = p2;
+ _p3 = p3;
+ _p4 = p4;
+ _sclc = sclc; // correction factor for scint clusterer
+ _cclc = cclc; // correction factor for ceren clusterer
+ }
+
+ protected void process(EventHeader event)
+ {
+
+ // array of ReconstructedParticles to add to the event...
+ List<ReconstructedParticle> rpList = new ArrayList<ReconstructedParticle>();
+ Map<Long, CalorimeterHit> chmap = (Map<Long, CalorimeterHit>) event.get("ChIDMap");
+
+ // get scintillator clusters
+ List<BasicCluster> sclusters = event.get(BasicCluster.class,_clusternames);
+ for (BasicCluster sclus : sclusters)
+ {
+ double chE = 0.;
+ double ClE = _sclc*_scfactor*sclus.getEnergy();
+// aida.cloud1D("Cluster E in RP routine").fill(ClE);
+ // now loop over all hits in this cluster to get ceren energy
+ List<CalorimeterHit> clhits = sclus.getCalorimeterHits();
+ for (CalorimeterHit clhit : clhits)
+ {
+ long cid = clhit.getCellID();
+ boolean chit = chmap.containsKey(cid);
+ if (chit)
+ {
+ CalorimeterHit cchit = chmap.get(cid);
+ chE += _cclc*_ccfactor*cchit.getCorrectedEnergy();
+ }
+ }
+ double csrat = chE/ClE;
+ double cSclE = ClE/(_p1+_p2*csrat+_p3*csrat*csrat+_p4*csrat*csrat*csrat);
+ double[] pos = sclus.getPosition();
+ double norm = sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]);
+ double p = cSclE/norm;
+ Hep3Vector mom = new BasicHep3Vector(p*pos[0], p*pos[1], p*pos[2]);
+ BaseReconstructedParticle rp = new BaseReconstructedParticle(cSclE, mom);
+ rp.setMass(0.); // for now, use zero mass
+ rp.setCharge(0.); // also use zero charge
+ // so classify as photon type for now until better estimate
+ ParticleType photype = ParticlePropertyManager.getParticlePropertyProvider().get(22);
+ ParticleID id = new BaseParticleID(photype);
+ rp.addParticleID(id);
+ rp.setParticleIdUsed(id);
+ rp.addCluster(sclus);
+ rpList.add(rp);
+ }
+
+ // add the list of rps to the event...
+ event.put(_allrecoparticles,rpList, ReconstructedParticle.class,0);
+ //some simple histograms...
+// aida.cloud1D("Number of AllRecoParticles found").fill(rpList.size());
+
+ }
+
+ public void setClusterNames(String cnames)
+ {
+ _clusternames = cnames;
+ }
+ public void setRecoParticleName(String allRPname)
+ {
+ _allrecoparticles = allRPname;
+ }
+}
\ No newline at end of file