lcsim-contrib/src/main/java/org/lcsim/contrib/SteveMagill
diff -N CorrScClusDriver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CorrScClusDriver.java 14 Feb 2012 19:18:40 -0000 1.1
@@ -0,0 +1,114 @@
+package org.lcsim.contrib.SteveMagill;
+
+import hep.aida.ITree;
+import java.util.*;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+import org.lcsim.recon.cluster.util.*;
+
+public class CorrScClusDriver extends Driver
+{
+ private AIDA aida = AIDA.defaultInstance();
+ private ITree _tree;
+ private String _inclusters;
+ private String _outclusters;
+ private String _chidm;
+ private double _scfactor;
+ private double _ccfactor;
+ private double _p1;
+ private double _p2;
+ private double _p3;
+ private double _p4;
+ private double _sclc;
+ private double _cclc;
+ private boolean _cscdb = true;
+
+ /** Creates a new instance of SimpleClusterToReconstructedParticleExampleDriver */
+ public CorrScClusDriver(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 - applied to hadron clusters
+ _cclc = cclc; // correction factor for ceren clusterer
+ }
+
+ protected void process(EventHeader event)
+ {
+
+ // get map of cerenkov hit and hit ID from event
+ Map<Long, CalorimeterHit> chmap = (Map<Long, CalorimeterHit>) event.get(_chidm);
+
+ // make new corrected cluster list
+ List<BasicCluster> cclusters = new ArrayList<BasicCluster>();
+
+ // get scintillator clusters from event
+ List<BasicCluster> sclusters = event.get(BasicCluster.class,_inclusters);
+ double sClEsum = 0.;
+ double cClEsum = 0.;
+ for (BasicCluster sclus : sclusters)
+ {
+ BasicCluster cclus = new BasicCluster();
+ cclus.addCluster(sclus);
+ double chE = 0.;
+ double ClE = _scfactor*sclus.getEnergy();
+ sClEsum += _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 += _ccfactor*cchit.getCorrectedEnergy();
+ }
+ }
+ double csrat = chE/ClE;
+ if (csrat>1.) csrat = 1.;
+// System.out.println(" CS Ratio " + csrat);
+ if (csrat<0.98)
+ {
+ _sclc = 1.05; // use 1.09 for CCAL02 and NN clusterer
+ } else
+ {
+ _sclc = 1.05; // use 1.05 for CCAL02 and NN clusterer
+ }
+ double cSclE = _sclc*ClE/(_p1+_p2*csrat+_p3*csrat*csrat+_p4*csrat*csrat*csrat);
+ cClEsum += _sclc*ClE/(_p1+_p2*csrat+_p3*csrat*csrat+_p4*csrat*csrat*csrat);
+ if (_cscdb) aida.cloud1D("C over S per Cluster").fill(csrat);
+ if (_cscdb) aida.cloud1D("CS Polynomial Correction Factor per Cluster").fill(_p1+_p2*csrat+_p3*csrat*csrat+_p4*csrat*csrat*csrat);
+
+ cclus.setEnergy(cSclE);
+ cclusters.add(cclus);
+ }
+
+ if (_cscdb) aida.cloud1D("Uncorr Scintillator Clus ESum").fill(sClEsum);
+ if (_cscdb) aida.cloud1D("CS Corrected Scintillator Clus Esum").fill(cClEsum);
+
+ // add the new cluster list to the event
+ event.put(_outclusters, cclusters, BasicCluster.class,0);
+
+ }
+
+ public void setInputClusterNames(String cname)
+ {
+ _inclusters = cname;
+ }
+ public void setOutputClusterNames(String outcname)
+ {
+ _outclusters = outcname;
+ }
+ public void setCHIDMapName(String chidm)
+ {
+ _chidm = chidm;
+ }
+}
\ No newline at end of file