Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. import hep.aida.*;
  2. import java.util.Random;
  3. import hep.aida.*;
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7.  
  8. public class photons
  9. {
  10.    static StringTokenizer st;
  11.  
  12.    public static void main(String[] args) throws IOException
  13.    {
  14.  
  15.      Integer np = 53;
  16.      Double lambda[]     = new Double[53];
  17.      Double delta[]         = new Double[52];
  18.      Double probability[] = new Double[53];
  19.  
  20.       // Create factories
  21.       IAnalysisFactory  analysisFactory = IAnalysisFactory.create();
  22.       ITreeFactory      treeFactory = analysisFactory.createTreeFactory();
  23.       ITree                tree = treeFactory.create();
  24.       IPlotter             plotter = analysisFactory.createPlotterFactory().create("Fit.java Plot");
  25.       IHistogramFactory histogramFactory = analysisFactory.createHistogramFactory(tree);
  26.       IFunctionFactory  functionFactory = analysisFactory.createFunctionFactory(tree);
  27.       IFitFactory          fitFactory = analysisFactory.createFitFactory();    
  28.       IDataPointSetFactory dpsf   = analysisFactory.createDataPointSetFactory(tree);
  29.  
  30.       IDataPointSet dataPointSet = dpsf.create("dataPointSet","Showing relation between wavelength and photomultiplier efficiency",2);
  31.       // create data point set ; still empty
  32.  
  33.       try {
  34.         BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Dawnimus\\Desktop\\data\\xp3422.txt"));    // read input file
  35.         int i= 0;
  36.         while ( true ){
  37.           String line = in.readLine();                          // copy full line to string
  38.           if (line==null) break;                                // abort loop if line is empty
  39.           System.out.println( line );
  40.           st = new StringTokenizer(line);                       // break line into tokens
  41.           Double x  = Double.parseDouble(st.nextToken());      
  42.           Double y  = Double.parseDouble(st.nextToken()) * (0.34 /  89.400);  // convert into quantum efficiency              
  43.           System.out.println("(x,y)  "+  x + "  " + y );
  44.           lambda[i] = x;
  45.           probability[i] = y;
  46.           if (i > 0){ delta[i-1] = lambda[i] - lambda[i-1];};
  47.           IDataPoint dp = dataPointSet.addPoint();   // add one data point to set
  48.           dp.coordinate(0).setValue(x);
  49.           dp.coordinate(1).setValue(y);
  50.           dp.coordinate(1).setErrorPlus(0.0);
  51.           dp.coordinate(1).setErrorMinus(0.0);
  52.           i++;
  53.           }
  54.        }
  55.        catch (IOException e){System.out.println( e ); }      
  56.        
  57.      
  58.       Double alpha = 1.0 / 137.0 ;
  59.       Double dNdz = 0. ;  
  60.       Double a=0. ;
  61.       Double twopi = 8. * Math.atan(1.0);
  62.       Double deg2rad = 360. / twopi;  
  63.       Double theta = 50.0 * deg2rad;
  64.       for (int i = 0; i < np - 1; i++ ) {
  65.           a = alpha * Math.pow(Math.sin(theta),2) * twopi *  Math.pow(lambda[i],-2) * delta[i] * 1e+9 ;
  66.           dNdz = dNdz + a * probability[i] ;
  67.            }
  68.  
  69.         System.out.println("dNdz  [1/m] : " + dNdz  );
  70.  
  71.  
  72.        plotter.region(0).plot(dataPointSet);          // request plot
  73.        plotter.show();   // show plot
  74.      
  75.        tree.close();
  76.      
  77.    }
  78. }
  79. \end{lstlisting}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement