#!/bin/python from sys import argv from numpy import append, savetxt, shape, array, newaxis, zeros, arange from Modules.Read import ReadEnergy, ReadTime, ReadExtraFile, ReadProfile from Modules.Read import ReadMomentumAngle, ReadPositionAngle, resultDirectory from Modules.Spectrum import spectrum from Modules.Map import computeMap, isotrop from Modules.Angle import angle_vs_energy from Modules.Timing import timing from Modules.Constants import degre def InProgress(i,Nmax): print " ", (i*100)/Nmax, "% done" if shape(argv)[0] < 2: print "not enough arguments (at least 1)" exit() #=============================================================================# PowerSpectrum=[1,1.5,2,2.5] for fileId in argv[1:]: print "#=============================================================================#" print "# Analysis of", fileId print "#=============================================================================#" # read files print "# 1. Reading data" time = ReadTime(fileId) energy = ReadEnergy(fileId) weightini, generation, theta_arrival, Esource = ReadExtraFile(fileId,[2,3,4,5]) nbPhotonsEmitted=ReadProfile(fileId,[3]) Gen_contrib = [] Gen_cont = zeros((int(max(generation))+1)) Source = [] Spectrum = [] Angle_Energy = [] Timing = [] print "# 2. Computing powerlaw spectrum" for powerlaw_index in PowerSpectrum: # apply source spectrum weight_source = (Esource/min(Esource))**(1-powerlaw_index) weight = weightini* weight_source #=============================================================================# # GENERATION CONTRIBUTION #=============================================================================# NbTotEvents = sum(weight) if Gen_contrib==[]: Gen_contrib = arange(0,max(generation)+1,1)[:,newaxis] for gen in list(set(generation)): Gen_cont[int(gen)] = sum(weight[generation==gen])/NbTotEvents *100 Gen_contrib = append(Gen_contrib,Gen_cont[:,newaxis],axis=1) #=============================================================================# # SPECTRUM (SOURCE AND MEASURED) #=============================================================================# nbBins = 50 # draw source spectrum Es=array(list(set(Esource))) Ws= (Es/min(Es))**(1-powerlaw_index) Es,Fs = spectrum(Es,Ws,nbBins=nbBins) Es=Es[:,newaxis] Fs=Fs[:,newaxis] if Source==[]: Source = Es Source = append(Source,Fs,axis=1) else: Source = append(Source,Fs,axis=1) # primary gamma-rays contribution and full spectrum ener,flux,flux_0 = spectrum(energy,weight,generation,nbBins) ener=ener[:,newaxis] flux=flux[:,newaxis] flux_0=flux_0[:,newaxis] if Spectrum==[]: Spectrum = ener Spectrum = append(Spectrum,flux,axis=1) Spectrum = append(Spectrum,flux_0,axis=1) else: Spectrum = append(Spectrum,flux,axis=1) Spectrum = append(Spectrum,flux_0,axis=1) #=============================================================================# # TIME DISTRIBUTION AND TIME DELAY VERSUS ANGLE #=============================================================================# nbBins = 100 delta_t,dNdt = timing(time,weight,nbBins) delta_t=delta_t[:,newaxis] dNdt=dNdt[:,newaxis] if Timing==[]: Timing = delta_t Timing = append(Timing,dNdt,axis=1) else: Timing = append(Timing,dNdt,axis=1) InProgress(PowerSpectrum.index(powerlaw_index)+1,shape(PowerSpectrum)[0]) #=============================================================================# # IMAGING, RADIAL DISTRIBUTION AND ANGLE VERSUS ENERGY #=============================================================================# print "# 3. compute images and radial distribution" powerlaw_index = 2 Elim = 1e-1 # GeV thetalim = 20 # degre nbBins = 100 Radial = [] thetaDir,phiDir = ReadMomentumAngle(fileId)*degre thetaPos,phiPos = ReadPositionAngle(fileId)*degre theta = thetaDir - thetaPos phi = phiDir -phiPos # apply source spectrum weight_source = (Esource/min(Esource))**(1-powerlaw_index) weight = weightini* weight_source # apply selection cond=(energy>Elim) #& (abs(theta)