hps-java/src/main/java/org/lcsim/hps/recon/ecal
diff -N TestRunRateAnalysis.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ TestRunRateAnalysis.java 21 Jun 2012 18:54:55 -0000 1.1
@@ -0,0 +1,131 @@
+package org.lcsim.hps.recon.ecal;
+
+import hep.aida.IHistogram2D;
+import java.util.List;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.EventHeader;
+import org.lcsim.event.MCParticle;
+import org.lcsim.event.util.ParticleTypeClassifier;
+import org.lcsim.util.Driver;
+import org.lcsim.util.aida.AIDA;
+
+/**
+ * Reads clusters and makes trigger decision using opposite quadrant criterion.
+ * Prints triggers to file if file path specified.
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: TestRunRateAnalysis.java,v 1.1 2012/06/21 18:54:55 meeg Exp $
+ */
+public class TestRunRateAnalysis extends Driver {
+
+ AIDA aida = AIDA.defaultInstance();
+ IHistogram2D eClusterVsP, photonEClusterVsP, electronEClusterVsP, positronEClusterVsP;
+ IHistogram2D eVsP, photonEVsP, electronEVsP, positronEVsP;
+ private String clusterCollectionName;
+ private String hitCollectionName = "EcalHits";
+ int nTriggers;
+ private double clusterEnergyLow = 10; //
+ int deadtimelessTriggerCount;
+ int[] triggersY = new int[5];
+
+ public TestRunRateAnalysis() {
+ }
+
+ @Override
+ public void startOfData() {
+ deadtimelessTriggerCount = 0;
+
+ eClusterVsP = aida.histogram2D("All Cluster E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+ photonEClusterVsP = aida.histogram2D("Photon Cluster E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+ electronEClusterVsP = aida.histogram2D("Electron Cluster E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+ positronEClusterVsP = aida.histogram2D("Positron Cluster E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+
+ eVsP = aida.histogram2D("All E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+ photonEVsP = aida.histogram2D("Photon E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+ electronEVsP = aida.histogram2D("Electron E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+ positronEVsP = aida.histogram2D("Positron E vs. Pz", 100, 0.0, 2000.0, 100, 0.0, 2000.0);
+ }
+
+ public void setClusterEnergyLow(double clusterEnergyLow) {
+ this.clusterEnergyLow = clusterEnergyLow;
+ }
+
+ public void setClusterCollectionName(String clusterCollectionName) {
+ this.clusterCollectionName = clusterCollectionName;
+ }
+
+ public void process(EventHeader event) {
+ //System.out.println(this.getClass().getCanonicalName() + " - process");
+
+ // MCParticles
+ List<MCParticle> mcparticles = event.get(MCParticle.class).get(0);
+
+// if (mcparticles.size() != 1) {
+// throw new RuntimeException("expected exactly 1 MCParticle");
+// }
+ if (mcparticles.isEmpty()) {
+ return;
+ }
+// MCParticle particle = mcparticles.get(0);
+
+ // Get the list of raw ECal hits.
+ List<HPSEcalCluster> clusters = event.get(HPSEcalCluster.class, clusterCollectionName);
+ if (clusters == null) {
+ throw new RuntimeException("Event is missing ECal clusters collection!");
+ }
+
+ boolean trigger = false;
+
+ for (HPSEcalCluster cluster : clusters) {
+ if (cluster.getEnergy() > clusterEnergyLow && cluster.getSeedHit().getIdentifierFieldValue("ix") < 0) {
+// if (cluster.getEnergy() > clusterEnergyLow && cluster.getSeedHit().getIdentifierFieldValue("iy")>0 && cluster.getSeedHit().getIdentifierFieldValue("ix")<0) {
+ triggersY[Math.abs(cluster.getSeedHit().getIdentifierFieldValue("iy")) - 1]++;
+ if (Math.abs(cluster.getSeedHit().getIdentifierFieldValue("iy")) > 1) {
+ trigger = true;
+ }
+ }
+ if (cluster.getSeedHit().getIdentifierFieldValue("ix") < 0 && Math.abs(cluster.getSeedHit().getIdentifierFieldValue("iy")) > 1) {
+ for (MCParticle particle : mcparticles) {
+ if (ParticleTypeClassifier.isElectron(particle.getPDGID())) {
+ electronEClusterVsP.fill(1000.0 * particle.getPZ(), 1000.0 * cluster.getEnergy());
+ } else if (ParticleTypeClassifier.isPositron(particle.getPDGID())) {
+ positronEClusterVsP.fill(1000.0 * particle.getPZ(), 1000.0 * cluster.getEnergy());
+ } else if (ParticleTypeClassifier.isPhoton(particle.getPDGID())) {
+ photonEClusterVsP.fill(1000.0 * particle.getPZ(), 1000.0 * cluster.getEnergy());
+ }
+ eClusterVsP.fill(1000.0 * particle.getPZ(), 1000.0 * cluster.getEnergy());
+ }
+ }
+ }
+ if (trigger) {
+ deadtimelessTriggerCount++;
+ }
+
+ List<CalorimeterHit> hits = event.get(CalorimeterHit.class, hitCollectionName);
+ if (hits == null) {
+ throw new RuntimeException("Event is missing ECal hits collection!");
+ }
+ double totalE = 0;
+ for (CalorimeterHit hit : hits) {
+ totalE += hit.getRawEnergy();
+ }
+
+ for (MCParticle particle : mcparticles) {
+ if (ParticleTypeClassifier.isElectron(particle.getPDGID())) {
+ electronEVsP.fill(1000.0 * particle.getPZ(), 1000.0 * totalE);
+ } else if (ParticleTypeClassifier.isPositron(particle.getPDGID())) {
+ positronEVsP.fill(1000.0 * particle.getPZ(), 1000.0 * totalE);
+ } else if (ParticleTypeClassifier.isPhoton(particle.getPDGID())) {
+ photonEVsP.fill(1000.0 * particle.getPZ(), 1000.0 * totalE);
+ }
+ eVsP.fill(1000.0 * particle.getPZ(), 1000.0 * totalE);
+ }
+ }
+
+ @Override
+ public void endOfData() {
+ System.out.printf("Trigger count without dead time: %d\n", deadtimelessTriggerCount);
+ System.out.format("Triggers vs. Y: %d\t%d\t%d\t%d\t%d, total %d\n", triggersY[0], triggersY[1], triggersY[2], triggersY[3], triggersY[4], deadtimelessTriggerCount);
+ super.endOfData();
+ }
+}
\ No newline at end of file