Esempio n. 1
0
 def boostCovarianceMatrix(self):
   """
   Boosts the covariance matrix adjusting the compoents of the covariance matrix
   according to the rules of the boost.
   """   
   boosted_cov_matrix = MyEditableCovarianceMatrix()
   order = ["x", "y", "z", "px", "py", "pz", "E"]
   for e1 in order:
     for e2 in order:
       boosted_cov_matrix.setCovarianceElement(e1,e2,self.boostCovElement(e1,e2))
   return boosted_cov_matrix
header.append("number_trials")
header.append("det_ref_cov_matrix")
header.append("det_cov_matrix")
header.append("log_emittance")
print ",".join(header)
step = args.step #Only calculate once all particles are present.
in_loop = True
with open(args.list_of_directories) as f:
  directories = [line.rstrip() for line in f]

trials_step_size = 10
last_trials_step = int(math.floor(len(directories)/trials_step_size))
for i in range(1,last_trials_step):
  number_trials = i*trials_step_size
  trial_dirs = random.sample(directories,number_trials)
  sum_covariance_matrix = MyEditableCovarianceMatrix()
  mean_phase_volume=Phase6DVolume(mass=mass_of_macroparticle)
  for directory in trial_dirs:
    cov_matrix = MyEditableCovarianceMatrix()
    cov_matrix.readCovarianceMatrix(os.path.join(directory,str(args.step)+"_cov_matrix.txt"))
    sum_covariance_matrix.cov_matrix += cov_matrix.cov_matrix
    mean_phase_volume.injectFile(os.path.join(directory,str(args.step)+"_mean.txt"),mass=mass_of_macroparticle)
  sum_covariance_matrix.cov_matrix = sum_covariance_matrix.cov_matrix/len(mean_phase_volume)
  #sum_covariance_matrix.printCovarianceMatrix()
  det_cov_matrix = sum_covariance_matrix.getSubDeterminant()
  ref_cov_matrix = mean_phase_volume.getCovarianceMatrix()
  det_ref_cov_matrix = ref_cov_matrix.getSubDeterminant()
  #ref_cov_matrix.printCovarianceMatrix()
  log_emittance = np.log10(det_ref_cov_matrix) + (args.number_of_particles-1)*np.log10(det_cov_matrix)
  output = []
  output.append(number_trials)
Esempio n. 3
0
mass_of_macroparticle = args.number_of_electrons_per_macroparticle*mass_of_electron

scaling_factor_for_x_mean = 1e8
scaling_factor_for_p_mean = 1e4

header = []
header.append("time")
header.append("det_ref_cov_matrix")
header.append("det_cov_matrix")
header.append("log_emittance")
print ",".join(header)
step = 100 #Only calculate once all particles are present.
in_loop = True
while in_loop is True:
  output = []
  sum_covariance_matrix = MyEditableCovarianceMatrix()
  mean_phase_volume=Phase6DVolume(mass=mass_of_macroparticle)
  with open(args.list_of_directories) as f:
    initialized = False
    for directory in f:
      directory = directory.rstrip()
      if not initialized:
        cosy_output = CosyOutput()
        cosy_output.injectFile(os.path.join(directory,"screen.txt"))
        row_numbers = cosy_output.getRowNumbersWithKeyValuePair("step number",step,comparison = 'eq')
        if row_numbers == []:
          in_loop = False
          break
        time = float(cosy_output.returnTableValue("time",row_numbers[0]))
        output.append(time)
        initialized = True