From d4f1936c62312a49ace7efe470ab72deeb2bf698 Mon Sep 17 00:00:00 2001 From: Nathan Harrison Date: Mon, 30 Jul 2018 14:20:41 -0400 Subject: [PATCH] Added code to count/compare gen and rec particles --- release-validation-1/.gitignore | 9 ++ release-validation-1/README.md | 6 ++ release-validation-1/pom.xml | 32 +++++++ .../java/org/jlab/c12val/ParticleCounter.java | 92 +++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 release-validation-1/.gitignore create mode 100644 release-validation-1/pom.xml create mode 100644 release-validation-1/src/main/java/org/jlab/c12val/ParticleCounter.java diff --git a/release-validation-1/.gitignore b/release-validation-1/.gitignore new file mode 100644 index 0000000..cf88d6e --- /dev/null +++ b/release-validation-1/.gitignore @@ -0,0 +1,9 @@ +11gev_sidis_250.dat +11gev_sidis_250b.dat +cook.clara +files.list +install-claracre-clas.sh +myclara +*.evio +*.hipo +target diff --git a/release-validation-1/README.md b/release-validation-1/README.md index 164a20d..42b2410 100644 --- a/release-validation-1/README.md +++ b/release-validation-1/README.md @@ -7,6 +7,7 @@ sudo docker run -it -v $PWD/:/jlab/workdir/shared --rm jeffersonlab/clas12tags:4 * From the docker container, run GEMC: ``` gemc clas12.gcard -INPUT_GEN_FILE="LUND, shared/11gev_sidis_500.dat" -USE_GUI=0 -N=500 -PRINT_EVENT=20 -RUNNO=11 -OUTPUT="evio, shared/out.evio" +exit # exit docker, do the remaining steps from your normal shell ``` * Tip: divide up the lund file and run several instances of GEMC: ``` @@ -44,3 +45,8 @@ echo "exit" >> cook.clara $CLARA_HOME/bin/clara-shell cook.clara ``` +## Analysis +``` +mvn install +mvn exec:java -Dexec.mainClass="org.jlab.c12val.ParticleCounter" +``` diff --git a/release-validation-1/pom.xml b/release-validation-1/pom.xml new file mode 100644 index 0000000..8d152f1 --- /dev/null +++ b/release-validation-1/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + org.jlab.c12val + rv1 + 1.0-SNAPSHOT + jar + + + + clas12maven + https://clasweb.jlab.org/clas12maven + + + + + + org.jlab.coat + coat-libs + 5.1-SNAPSHOT + + + + + 1.8 + 1.8 + + + diff --git a/release-validation-1/src/main/java/org/jlab/c12val/ParticleCounter.java b/release-validation-1/src/main/java/org/jlab/c12val/ParticleCounter.java new file mode 100644 index 0000000..656769c --- /dev/null +++ b/release-validation-1/src/main/java/org/jlab/c12val/ParticleCounter.java @@ -0,0 +1,92 @@ +package org.jlab.c12val; + +import org.jlab.io.base.DataBank; +import org.jlab.io.base.DataEvent; +import org.jlab.io.hipo.HipoDataSource; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; + +public class ParticleCounter { + + public ArrayList pids, genCounts, recCounts; + public static final HashMap chargeOfPid = new HashMap(); + static { + chargeOfPid.put(11, -1); + chargeOfPid.put(-11, 1); + chargeOfPid.put(211, 1); + chargeOfPid.put(-211, -1); + chargeOfPid.put(2212, 1); + chargeOfPid.put(321, 1); + chargeOfPid.put(-321, -1); + chargeOfPid.put(22, 0); + chargeOfPid.put(2112, 0); + } + + + public ParticleCounter(int... pids) { + this.pids = new ArrayList<>(); + for(int pid : pids) this.pids.add(pid); + this.genCounts = new ArrayList(Collections.nCopies(this.pids.size(), 0)); + this.recCounts = new ArrayList(Collections.nCopies(this.pids.size(), 0)); + } + + + public void processEvent(DataEvent event) { + DataBank genBank, recBank; + if(event.hasBank("MC::Particle")) genBank = event.getBank("MC::Particle"); + else genBank = null; + if(event.hasBank("REC::Particle")) recBank = event.getBank("REC::Particle"); + else recBank = null; + if(genBank != null) processGenRecBanks(genBank, recBank); + } + + + public void processGenRecBanks(DataBank genBank, DataBank recBank) { + for(int i = 0; i < genBank.rows(); i++) { + int pid = genBank.getInt("pid", i); + if(pids.contains(pid)) { + int ipid = pids.indexOf(pid); + genCounts.set(ipid, genCounts.get(ipid) + 1); + Integer charge = chargeOfPid.get(pid); + if(recBank != null && recBank.rows() > 0) processRecBank(recBank, pid, charge, genBank.getFloat("px", i), genBank.getFloat("py", i), genBank.getFloat("pz", i)); + } + } + } + + + public void processRecBank(DataBank recBank, int gpid, Integer gq, double gpx, double gpy, double gpz) { + for(int i = 0; i < recBank.rows(); i++) { + byte rq = recBank.getByte("charge", i); + float rpx = recBank.getFloat("px", i); + float rpy = recBank.getFloat("py", i); + float rpz = recBank.getFloat("pz", i); + int ipid = pids.indexOf(gpid); + if(gq == null || gq == rq) { + if(Math.abs(gpx - rpx) < 0.2 && Math.abs(gpy - rpy) < 0.2 && Math.abs(gpz - rpz) < 0.2) recCounts.set(ipid, recCounts.get(ipid) + 1); + } + } + } + + + public void printResults() { + System.out.printf("%-7s %-7s %-7s %n", "pid", "#gen", "#rec"); + for(int i = 0; i < pids.size(); i++) { + System.out.printf("%-7d %-7d %-7d %n", pids.get(i), genCounts.get(i), recCounts.get(i)); + } + } + + + public static void main(String[] args) { + ParticleCounter pcounter = new ParticleCounter(11, 211, -211, 2212, 321, 22, 2112); + HipoDataSource reader = new HipoDataSource(); + reader.open("out_out.hipo"); + while(reader.hasEvent()) { + DataEvent event = reader.getNextEvent(); + pcounter.processEvent(event); + } + pcounter.printResults(); + } + +}