Print

Print


Commit in lcsim-contrib/src/main/java/org/lcsim/contrib/Partridge/TextFileToStdhep on MAIN
GenerateMuons.java+55added 1.1
TextFileToStdhep.java+95-861.2 -> 1.3
+150-86
1 added + 1 modified, total 2 files
Minor updates

lcsim-contrib/src/main/java/org/lcsim/contrib/Partridge/TextFileToStdhep
GenerateMuons.java added at 1.1
diff -N GenerateMuons.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ GenerateMuons.java	20 Feb 2009 22:49:53 -0000	1.1
@@ -0,0 +1,55 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.lcsim.contrib.Partridge.TextFileToStdhep;
+
+import hep.io.stdhep.StdhepEvent;
+import hep.io.stdhep.StdhepWriter;
+import java.io.IOException;
+import java.util.Random;
+
+/**
+ *
+ * @author partridge
+ */
+public class GenerateMuons{
+
+    public static void main(String[] args) throws IOException {
+        Random generator = new Random();
+
+        int nwrit = 100;
+        StdhepWriter sw = new StdhepWriter("c:\\muons.slcio", "Single muons",
+                "Single muons", nwrit);
+        sw.setCompatibilityMode(false);
+        for (int icross = 0; icross < nwrit; icross++) {
+            double p = 100.;
+            double m = 0.105658;
+            double theta = (178. * generator.nextDouble() + 1.) * Math.PI / 180.;
+            double phi = 2. * Math.PI * generator.nextDouble();
+            int nevhep = icross;
+            int nhep = 1;
+            int isthep[] = new int[2];
+            isthep[0] = 1;
+            int idhep[] = new int[2];
+            idhep[0] = 13;
+            if (generator.nextDouble() > 0.5) idhep[0] = -13;
+            int jmohep[] = new int[2];
+            for (int i=0; i<2; i++) jmohep[i] = 0;
+            int jdahep[] = new int[2];
+            for (int i=0; i<2; i++) jdahep[i] = 0;
+            double phep[] = new double[5];
+            phep[0] = p * Math.sin(theta) * Math.cos(phi);
+            phep[1] = p * Math.sin(theta) * Math.sin(phi);
+            phep[2] = p * Math.cos(theta);
+            phep[3] = Math.sqrt(p*p + m*m);
+            phep[4] = m;
+            double vhep[] = new double[4];
+            for (int i=0; i<4; i++) vhep[i] = 0.;
+            StdhepEvent ev = new StdhepEvent(nevhep, nhep, isthep, idhep, jmohep, jdahep, phep, vhep);
+            sw.writeRecord(ev);
+        }
+        sw.close();
+    }
+}
\ No newline at end of file

lcsim-contrib/src/main/java/org/lcsim/contrib/Partridge/TextFileToStdhep
TextFileToStdhep.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- TextFileToStdhep.java	17 Jan 2009 01:40:09 -0000	1.2
+++ TextFileToStdhep.java	20 Feb 2009 22:49:53 -0000	1.3
@@ -29,99 +29,108 @@
 //            throw new RuntimeException("Invalid number of arguments");
 //        }
 //        String file = args[0];
-        String file = "c:/StdHepWriter/Minbias_14TeV_1E33_1404bunches_10";
-        String infile = file+".txt";
-        String outfile = file+".stdhep";
+        for (int i = 0; i < 10; i++) {
+            for (int j = 0; j < 10; j++) {
+                int k = 0;
+                if (i == 0 && j == 0) k = 1;
+                String file = "c:/StdHepWriter/Minbias_14TeV_1E33_1404bunches_100evts" + k + i + j;
+                String infile = file + ".txt";
+                String outfile = file + ".stdhep";
+                process(infile, outfile);
+            }
+        }
+    }
 
+    private static void process(String infile, String outfile) throws IOException {
 //        try {
-            FileReader fr = new FileReader(infile);
-            StreamTokenizer tok = new StreamTokenizer(fr);
-            tok.resetSyntax();
-            tok.wordChars(33, 255);
-            tok.parseNumbers();
-            tok.whitespaceChars(0, ' ');
-            tok.eolIsSignificant(true);
-            List<Double> beg = getNumbersInLine(tok);
-            if (beg.size() != 7) {
-                throw new RuntimeException("Unexpected entry in begin run record");
+        FileReader fr = new FileReader(infile);
+        StreamTokenizer tok = new StreamTokenizer(fr);
+        tok.resetSyntax();
+        tok.wordChars(33, 255);
+        tok.parseNumbers();
+        tok.whitespaceChars(0, ' ');
+        tok.eolIsSignificant(true);
+        List<Double> beg = getNumbersInLine(tok);
+        if (beg.size() != 7) {
+            throw new RuntimeException("Unexpected entry in begin run record");
+        }
+        int nreq = beg.get(0).intValue();
+        int ngen = beg.get(1).intValue();
+        int nwrit = beg.get(2).intValue();
+        float ecm = beg.get(3).floatValue();
+        float xsec = beg.get(4).floatValue();
+        double rn1 = beg.get(5);
+        double rn2 = beg.get(6);
+        StdhepWriter sw = new StdhepWriter(outfile, "Imported Stdhep Events",
+                "From file " + infile, nwrit);
+        sw.setCompatibilityMode(false);
+        StdhepBeginRun sb = new StdhepBeginRun(nreq, ngen, nwrit, ecm, xsec, rn1, rn2);
+        sw.writeRecord(sb);
+        for (int icross = 0; icross < nwrit; icross++) {
+            List<Double> nums = getNumbersInLine(tok);
+            if (nums.size() != 2) {
+                throw new RuntimeException("Unexpected entry for number of particles");
             }
-            int nreq = beg.get(0).intValue();
-            int ngen = beg.get(1).intValue();
-            int nwrit = beg.get(2).intValue();
-            float ecm = beg.get(3).floatValue();
-            float xsec = beg.get(4).floatValue();
-            double rn1 = beg.get(5);
-            double rn2 = beg.get(6);
-            StdhepWriter sw = new StdhepWriter(outfile, "Imported Stdhep Events",
-                    "From file " + infile, nwrit);
-            sw.setCompatibilityMode(false);
-            StdhepBeginRun sb = new StdhepBeginRun(nreq, ngen, nwrit, ecm, xsec, rn1, rn2);
-            sw.writeRecord(sb);
-            for (int icross = 0; icross < nwrit; icross++) {
-                List<Double> nums = getNumbersInLine(tok);
-                if (nums.size() != 2) {
-                    throw new RuntimeException("Unexpected entry for number of particles");
+            int nevhep = nums.get(0).intValue();
+            int nhep = nums.get(1).intValue();
+            System.out.println("Number of particles for event " + nevhep + ": " + nhep);
+            int isthep[] = new int[nhep];
+            int idhep[] = new int[nhep];
+            int jmohep[] = new int[2 * nhep];
+            int jdahep[] = new int[2 * nhep];
+            double phep[] = new double[5 * nhep];
+            double vhep[] = new double[4 * nhep];
+            for (int i = 0; i < nhep; i++) {
+                List<Double> vals = getNumbersInLine(tok);
+                if (vals.size() != 16) {
+                    throw new RuntimeException("Unexpected entry for a particle");
                 }
-                int nevhep = nums.get(0).intValue();
-                int nhep = nums.get(1).intValue();
-                System.out.println("Number of particles for event " + nevhep + ": " + nhep);
-                int isthep[] = new int[nhep];
-                int idhep[] = new int[nhep];
-                int jmohep[] = new int[2 * nhep];
-                int jdahep[] = new int[2 * nhep];
-                double phep[] = new double[5 * nhep];
-                double vhep[] = new double[4 * nhep];
-                for (int i = 0; i < nhep; i++) {
-                    List<Double> vals = getNumbersInLine(tok);
-                    if (vals.size() != 16) {
-                        throw new RuntimeException("Unexpected entry for a particle");
-                    }
-                    int ip = vals.get(0).intValue();
-                    if (ip != i + 1) {
-                        throw new RuntimeException("Particle numbering mismatch");
-                    }
-                    isthep[i] = vals.get(1).intValue();
-                    idhep[i] = vals.get(2).intValue();
-                    jmohep[2 * i] = vals.get(3).intValue();
-                    jmohep[2 * i + 1] = vals.get(4).intValue();
-                    jdahep[2 * i] = vals.get(5).intValue();
-                    jdahep[2 * i + 1] = vals.get(6).intValue();
-                    for (int j = 0; j < 5; j++) {
-                        phep[5 * i + j] = vals.get(j + 7);
-                    }
-                    for (int j = 0; j < 4; j++) {
-                        vhep[4 * i + j] = vals.get(j + 12);
-                    }
-
-                    if (i == 0 || i == nhep - 1) {
-                        System.out.println(ip + " st: " + isthep[i] + " id: " + idhep[i] +
-                                " jmo: " + jmohep[2 * i] + " " + jmohep[2 * i + 1] +
-                                " jda: " + jdahep[2 * i] + " " + jdahep[2 * i + 1]);
-                        System.out.println("p: " + phep[5 * i] + " " + phep[5 * i + 1] + " " +
-                                phep[5 * i + 2] + " " + phep[5 * i + 3] + " " + phep[5 * i + 4]);
-                        System.out.println("v: " + vhep[4 * i] + " " + vhep[4 * i + 1] + " " +
-                                vhep[4 * i + 2] + " " + vhep[4 * i + 3]);
-                    }
+                int ip = vals.get(0).intValue();
+                if (ip != i + 1) {
+                    throw new RuntimeException("Particle numbering mismatch");
                 }
-                StdhepEvent ev = new StdhepEvent(nevhep, nhep, isthep, idhep, jmohep, jdahep, phep, vhep);
-                sw.writeRecord(ev);
-            }
-            List<Double> end = getNumbersInLine(tok);
-            if (end.size() != 7) {
-                throw new RuntimeException("Unexpected entry in begin run record");
+                isthep[i] = vals.get(1).intValue();
+                idhep[i] = vals.get(2).intValue();
+                jmohep[2 * i] = vals.get(3).intValue();
+                jmohep[2 * i + 1] = vals.get(4).intValue();
+                jdahep[2 * i] = vals.get(5).intValue();
+                jdahep[2 * i + 1] = vals.get(6).intValue();
+                for (int j = 0; j < 5; j++) {
+                    phep[5 * i + j] = vals.get(j + 7);
+                }
+                for (int j = 0; j < 4; j++) {
+                    vhep[4 * i + j] = vals.get(j + 12);
+                }
+
+//                    if (i == 0 || i == nhep - 1) {
+//                        System.out.println(ip + " st: " + isthep[i] + " id: " + idhep[i] +
+//                                " jmo: " + jmohep[2 * i] + " " + jmohep[2 * i + 1] +
+//                                " jda: " + jdahep[2 * i] + " " + jdahep[2 * i + 1]);
+//                        System.out.println("p: " + phep[5 * i] + " " + phep[5 * i + 1] + " " +
+//                                phep[5 * i + 2] + " " + phep[5 * i + 3] + " " + phep[5 * i + 4]);
+//                        System.out.println("v: " + vhep[4 * i] + " " + vhep[4 * i + 1] + " " +
+//                                vhep[4 * i + 2] + " " + vhep[4 * i + 3]);
+//                    }
             }
-            int nreqe = end.get(0).intValue();
-            int ngene = end.get(1).intValue();
-            int nwrite = end.get(2).intValue();
-            float ecme = end.get(3).floatValue();
-            float xsece = end.get(4).floatValue();
-            double rn1e = end.get(5);
-            double rn2e = end.get(6);
-            StdhepEndRun se = new StdhepEndRun(nreqe, ngene, nwrite, ecme, xsece, rn1e, rn2e);
-            sw.writeRecord(se);
+            StdhepEvent ev = new StdhepEvent(nevhep, nhep, isthep, idhep, jmohep, jdahep, phep, vhep);
+            sw.writeRecord(ev);
+        }
+        List<Double> end = getNumbersInLine(tok);
+        if (end.size() != 7) {
+            throw new RuntimeException("Unexpected entry in begin run record");
+        }
+        int nreqe = end.get(0).intValue();
+        int ngene = end.get(1).intValue();
+        int nwrite = end.get(2).intValue();
+        float ecme = end.get(3).floatValue();
+        float xsece = end.get(4).floatValue();
+        double rn1e = end.get(5);
+        double rn2e = end.get(6);
+        StdhepEndRun se = new StdhepEndRun(nreqe, ngene, nwrite, ecme, xsece, rn1e, rn2e);
+        sw.writeRecord(se);
 
-            sw.close();
-            fr.close();
+        sw.close();
+        fr.close();
 //        } catch (IOException e) {
 //            System.out.println("Error opening " + infile);
 //        }
CVSspam 0.2.8