diff --git a/common-tools/clas-analysis/src/main/java/org/jlab/analysis/nabo/Efficiency.java b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/nabo/Efficiency.java new file mode 100644 index 000000000..2958045ce --- /dev/null +++ b/common-tools/clas-analysis/src/main/java/org/jlab/analysis/nabo/Efficiency.java @@ -0,0 +1,124 @@ +package org.jlab.analysis.nabo; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.TreeMap; +import java.util.stream.IntStream; +import org.jlab.jnp.hipo4.data.Bank; +import org.jlab.jnp.hipo4.data.Event; +import org.jlab.jnp.hipo4.data.Schema; +import org.jlab.jnp.hipo4.data.SchemaFactory; +import org.jlab.jnp.hipo4.io.HipoReader; + +public class Efficiency { + + static final List NEGATIVES = Arrays.asList(11, -211, -321, -2212); + static final List POSITIVES = Arrays.asList(11, 211, 321, 2212); + static final List NEUTRALS = Arrays.asList(22, 2112); + static List PIDS; + + Schema mcGenMatch; + Schema mcParticle; + Schema recParticle; + int[][] caches; + + public static void main(String[] args) { + Efficiency e = new Efficiency(args); + System.out.println(e); + } + + private void init(SchemaFactory schema) { + PIDS = new ArrayList(NEGATIVES); + PIDS.addAll(POSITIVES); + PIDS.addAll(NEUTRALS); + caches = new int[PIDS.size()][PIDS.size()]; + mcGenMatch = schema.getSchema("MC::GenMatch"); + mcParticle = schema.getSchema("MC::Particle"); + recParticle = schema.getSchema("REC::Particle"); + } + + public Efficiency(SchemaFactory schema) { + init(schema); + } + + public Efficiency(String... filenames) { + HipoReader r = new HipoReader(); + r.open(filenames[0]); + init(r.getSchemaFactory()); + r.close(); + add(filenames); + } + + public float get(int mc, int rec) { + long sum = IntStream.of(caches[PIDS.indexOf(mc)]).sum(); + return sum>0 ? caches[PIDS.indexOf(mc)][PIDS.indexOf(rec)]/sum : 0; + } + + public float get(int pid) { + return get(pid,pid); + } + + @Override + public String toString() { + StringBuilder s = new StringBuilder(); + s.append(" "); + for (int i=0; i good = getMapping(e); + for (short row=0; row m = new TreeMap<>(); + for (int row=0; row