33import java .util .ArrayList ;
44import java .util .Arrays ;
55import java .util .List ;
6+ import java .util .Map ;
67import java .util .TreeMap ;
78import org .jlab .jnp .hipo4 .data .Bank ;
89import org .jlab .jnp .hipo4 .data .Event ;
1516
1617/**
1718 * Efficiency matrix calculator based solely on the MC::GenMatch truth-matching
18- * bank (which is purely hit-based), and a pid assignment match in MC::Particle
19- * and REC::Particle.
19+ * bank, and a pid assignment match in MC::Particle and REC::Particle.
2020 *
2121 * @author baltzell
2222 */
@@ -188,17 +188,62 @@ public String toMarkdown() {
188188 return s .toString ();
189189 }
190190
191+ private static Map <Integer ,Float > parseEfficiencyString (String arg ) {
192+ TreeMap <Integer ,Float > m = new TreeMap <>();
193+ if (arg .contains ("," )) {
194+ for (String s : arg .split ("," ))
195+ m .putAll (parseEfficiencyString (s ));
196+ }
197+ else if (arg .contains (":" )) {
198+ String [] x = arg .split (":" );
199+ try {
200+ if (x .length == 2 ) m .put (Integer .valueOf (x [0 ]), Float .valueOf (x [1 ]));
201+ else throw new RuntimeException ("Invalid pid specification: " +arg );
202+ }
203+ catch (NumberFormatException e ) {
204+ throw new RuntimeException ("Invalid pid specification: " +arg );
205+ }
206+ }
207+ return m ;
208+ }
209+
210+ private boolean checkEfficiencies (Map <Integer ,Float > pids ) {
211+ boolean good = true ;
212+ for (int pid : pids .keySet ()) {
213+ if (get (pid , pid ) < pids .get (pid )) {
214+ System .err .println (String .format (
215+ ">>> trutheff: pid %d efficiency is %f, below %f limit" ,
216+ pid , get (pid ,pid ), pids .get (pid )));
217+ good = false ;
218+ }
219+ }
220+ return good ;
221+ }
222+
223+ /**
224+ * Efficiency cut values specificed as pid1:eff1[pid2:eff2[...]]
225+ * For example, 2212:0.9,11:0.95 is 90% for proton and 95% for electron.
226+ * @param arg
227+ * @return whether all efficiency cuts pass
228+ */
229+ public boolean checkEfficiencies (String arg ) {
230+ return checkEfficiencies (parseEfficiencyString (arg ));
231+ }
232+
191233 public static void main (String [] args ) {
192234 OptionParser o = new OptionParser ("trutheff" );
235+ o .addOption ("-e" , "" , "efficiency requirement (e.g. 321:0.9,11:0.95" );
193236 o .setRequiresInputList (true );
194237 o .parse (args );
238+ Map <Integer ,Float > pids = parseEfficiencyString (o .getOption ("-e" ).stringValue ());
195239 HipoReader r = new HipoReader ();
196240 r .open (o .getInputList ().get (0 ));
197241 Truth t = new Truth (r .getSchemaFactory ());
198242 t .add (o .getInputList ());
199- System .out .println (t .toTable ());
200- System .out .println (t .toJson ());
201243 System .out .println (t .toMarkdown ());
244+ System .out .println (t .toJson ());
245+ System .out .println (t .toTable ());
246+ if (!t .checkEfficiencies (pids )) System .exit (7 );
202247 }
203248
204249}
0 commit comments