@@ -34,40 +34,16 @@ public class Truth {
3434 long [][] recTallies ;
3535 long [] mcTallies ;
3636
37- public static void main (String [] args ) {
38- OptionParser o = new OptionParser ("trutheff" );
39- o .setRequiresInputList (true );
40- o .parse (args );
41- Truth t = new Truth (o .getInputList ().get (0 ));
42- t .add (o .getInputList ());
43- System .out .println (t .toTable ());
44- System .out .println (t .toJson ());
45- }
46-
4737 public Truth (SchemaFactory s ) {
48- init (s );
49- }
50-
51- public Truth (HipoReader r ) {
52- init (r .getSchemaFactory ());
53- }
54-
55- public Truth (String filename ) {
56- HipoReader r = new HipoReader ();
57- r .open (filename );
58- init (r .getSchemaFactory ());
59- }
60-
61- private void init (SchemaFactory schema ) {
6238 validPids = new ArrayList (NEGATIVES );
6339 validPids .addAll (POSITIVES );
6440 validPids .addAll (NEUTRALS );
6541 validPids .add (UDF );
6642 mcTallies = new long [validPids .size ()];
6743 recTallies = new long [validPids .size ()][validPids .size ()];
68- mcGenMatch = schema .getSchema ("MC::GenMatch" );
69- mcParticle = schema .getSchema ("MC::Particle" );
70- recParticle = schema .getSchema ("REC::Particle" );
44+ mcGenMatch = s .getSchema ("MC::GenMatch" );
45+ mcParticle = s .getSchema ("MC::Particle" );
46+ recParticle = s .getSchema ("REC::Particle" );
7147 }
7248
7349 /**
@@ -141,7 +117,7 @@ private TreeMap getMapping(Event e) {
141117 }
142118
143119 /**
144- * Get efficiencies as a human-readable table.
120+ * Get efficiencies as a plain, human-readable table.
145121 * @return
146122 */
147123 public String toTable () {
@@ -152,13 +128,12 @@ public String toTable() {
152128 if (validPids .size ()==i +1 ) s .append ("\n " );
153129 }
154130 for (int i =0 ; i <validPids .size (); ++i ) {
155- s .append (String .format ("%6d" ,validPids .get (i )));
131+ s .append (String .format ("\n %6d" ,validPids .get (i )));
156132 for (int j =0 ; j <validPids .size (); ++j ) {
157133 if (mcTallies [i ] > 0 )
158134 s .append (String .format ("%7.4f" ,get (validPids .get (i ),validPids .get (j ))));
159135 else
160136 s .append (String .format ("%7s" ,"-" ));
161- if (validPids .size ()==j +1 ) s .append ("\n " );
162137 }
163138 }
164139 return s .toString ();
@@ -186,4 +161,44 @@ public JsonObject toJson() {
186161 ret .add ("gens" , gens );
187162 return ret ;
188163 }
189- }
164+
165+ /**
166+ * Get efficiencies as a Markdown table.
167+ * @return
168+ */
169+ public String toMarkdown () {
170+ StringBuilder s = new StringBuilder ();
171+ s .append ("|" );
172+ for (int i =0 ; i <validPids .size (); ++i ) {
173+ s .append (String .format ("%d|" ,validPids .get (i )));
174+ if (validPids .size ()==i +1 ) s .append ("\n " );
175+ }
176+ s .append ("|" );
177+ for (int i =0 ; i <validPids .size (); ++i ) s .append (" --- |" );
178+ s .append ("\n " );
179+ for (int i =0 ; i <validPids .size (); ++i ) {
180+ s .append (String .format ("|%d|" ,validPids .get (i )));
181+ for (int j =0 ; j <validPids .size (); ++j ) {
182+ if (mcTallies [i ] > 0 )
183+ s .append (String .format ("%f|" ,get (validPids .get (i ),validPids .get (j ))));
184+ else
185+ s .append ("|" );
186+ }
187+ }
188+ return s .toString ();
189+ }
190+
191+ public static void main (String [] args ) {
192+ OptionParser o = new OptionParser ("trutheff" );
193+ o .setRequiresInputList (true );
194+ o .parse (args );
195+ HipoReader r = new HipoReader ();
196+ r .open (o .getInputList ().get (0 ));
197+ Truth t = new Truth (r .getSchemaFactory ());
198+ t .add (o .getInputList ());
199+ System .out .println (t .toTable ());
200+ System .out .println (t .toJson ());
201+ System .out .println (t .toMarkdown ());
202+ }
203+
204+ }
0 commit comments