Advertisement
Guest User

Untitled

a guest
May 1st, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. class Main2
  4. {
  5. static BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in));
  6. static PrintWriter screen = new PrintWriter (System.out,true);
  7.  
  8. public static void main (String [] args) throws FileNotFoundException, IOException, NullPointerException
  9. {
  10. BufferedReader reader = new BufferedReader(new FileReader("Combined4mu.csv"));
  11. List<String> lines = new ArrayList<>();
  12. String line = null;
  13. String [] event = new String [20]; //Array to hold elements of each event line
  14. screen.println("Please enter the name of the file");
  15. String name = keyboard.readLine();
  16. String filename = name+".csv";
  17. FileWriter file1 = new FileWriter(filename);
  18. PrintWriter outputFile = new PrintWriter(file1);
  19.  
  20. screen.println("\nPlease enter the Density in gcm^-3");
  21. double rho = new Double (keyboard.readLine()).doubleValue();
  22. screen.println("\nPlease enter the Atomic Mass in u");
  23. double A = new Double (keyboard.readLine()).doubleValue();
  24. screen.println("\nPlease enter the Proton Number");
  25. int Z = Integer.parseInt(keyboard.readLine());
  26. screen.println("\nPlease enter the Thickness of the Solenoid in cm");
  27. double t = new Double (keyboard.readLine());
  28. screen.println("\nPlease enter the Number of Detectors");
  29. int det = Integer.parseInt(keyboard.readLine());
  30. screen.println("\nPlease enter the Resolution of the Detectors in Microns");
  31. double res = new Double (keyboard.readLine()).doubleValue()*0.000001;
  32. screen.println("\nWhat would you like to do? \n1)Export Muon Positions \n2)Export Invariant Mass \nPlease enter number");
  33. int ans = Integer.parseInt(keyboard.readLine());
  34.  
  35. double [] position=new double [3];
  36. double [][] Hit = new double [det][2];
  37. double [] linestats = new double [2];
  38. double [] xarray = new double [det];
  39. double [] yarray = new double [det];
  40. double xback;
  41. double yback;
  42. int j=0;
  43. double [] E = new double [4];
  44. double [] px = new double [4];
  45. double [] py = new double [4];
  46. double [] pz = new double [4];
  47. screen.println("\n\nLoading.... please wait");
  48.  
  49. while ((line = reader.readLine()) != null) //event loop
  50. {
  51. lines.add(line);
  52. String delimiter = ",";
  53. event = line.split(",");
  54. for (int q = 0; q<=3; q++) //muon number loop
  55. {
  56. PolarConvert PolarConst = new PolarConvert( event[5*q+1], event[5*q+2], event[5*q+3], event[5*q+4]);
  57. IronTrack IronConst = new IronTrack(PolarConst.pT(),PolarConst.delta(),PolarConst.bigPhi(),PolarConst.q(),rho,A,Z);
  58.  
  59. double exitX = PolarConst.exitX();
  60. double exitY = PolarConst.exitY();
  61.  
  62. for (int r=0;r<=2;r++) //loop to fill position array
  63. {
  64. position[r] = IronConst.newPos(exitX,exitY)[r];
  65. }
  66.  
  67. for (int d=0;d<=(det-1);d++) //detector loop
  68. {
  69. for (int s=0;s<=1;s++)
  70. {
  71. Hit[d][s]=IronConst.detector(position[0],position[1],position[2],(d*0.1+2.3),res)[s];
  72.  
  73. }
  74. xarray[d]=Hit[d][0];
  75. yarray[d]=Hit[d][1];
  76.  
  77. }
  78.  
  79. JLineFit JLConst = new JLineFit (xarray,yarray,det);
  80. linestats[0] = JLConst.getJLine()[0]; //grad
  81. linestats[1] = JLConst.getJLine()[1]; //intercept
  82.  
  83. BacktoB BackConst = new BacktoB (linestats[0], linestats[1], 1.2, xarray[0], yarray [0]);
  84. xback = BackConst.getcoordinates()[0];
  85. yback = BackConst.getcoordinates()[1];
  86. ReversePC RevConst = new ReversePC (xback,yback,linestats[0],PolarConst.pZ());//,PolarConst.delta());
  87. E[q]=RevConst.getE();
  88. px[q]=RevConst.back_px();
  89. py[q]=RevConst.back_py();
  90. pz[q]=PolarConst.pZ();
  91.  
  92. if (ans < 2)
  93. {
  94. outputFile.println(Hit[0][0]+","+Hit[0][1]+","+Hit[1][0]+","+Hit[1][1]+","+Hit[2][0]+","+Hit[2][1]+","+xback+","+yback);
  95. }
  96. //screen.println(RevConst.back_pT());
  97. //outputFile.println(RevConst.back_pT()+","+PolarConst.pT());
  98.  
  99. }
  100. INVMASS MassConst = new INVMASS (E,px,py,pz);
  101. if (ans > 1)
  102. {
  103. outputFile.println(MassConst.getMASS());
  104. }
  105. }
  106. j++;
  107. outputFile.close();
  108. screen.println("\n\nFinished,"+name+" is ready to view");
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement