示例#1
0
文件: fwGTT.py 项目: Chriisbrown/GTT
def fwFastHisto(event, ret_all=False, weight='pt',fwpt=True):
  ''' Return the index and weight of the maximum bin '''
  bins = range(TrackWord_config['HWUz0']['nbins'])
  z0 = []

  for i in range(len(event["z0"])):
    z = toHWU('Z0',event["z0"][i])
    if np.signbit(z[1]):
      z0.append(-z[0]*8 - int(z[0]/2) + int(z[1]/8) + int(z[1]/64) + 128 )  #fw estimate
    else:
      z0.append( z[0]*8 + int(z[0]/2) + int(z[1]/8) + int(z[1]/64) + 128 )    #fw estimate

  if fwpt:
    weight = event["fwPt"]
  else:
    weight = [toHWU( "Pt",p) for p in event[ "pt"]]
  h, b = np.histogram(z0, bins=bins, weights=weight)

  if ret_all:
    return b, h
  return (b[h.argmax()]), h.max()
示例#2
0
文件: fwGTT.py 项目: Chriisbrown/GTT
def fwInvRLUT(event):
  pt_array = []
  
  with open('ComponentTest/InvRtest/InvRarrays.npy', 'rb') as f:
    new_InvR = np.load(f)

    new_IntOut = np.load(f)
    new_FracOut = np.load(f)
    for i in range(len(event["pt"])):
      invr = toHWU("InvR",event["InvR"].iloc[i])
      idx = (np.abs(new_InvR - invr)).argmin()
      pt_array.append(int((new_IntOut[idx]*2**18 + new_FracOut[idx])/2**18))

  

  event["fwPt"] = pt_array
示例#3
0
文件: fwGTT.py 项目: Chriisbrown/GTT
def fwTrackSelection(event,fwpt=True):

    purity_cut = []
    for i in range(len(event["pt"])):
      if fwpt:
        pt = event["fwPt"][i]
      else:
        pt = toHWU("Pt",event["pt"][i])

      chi = toHWU("Chi2rz",event["chi2rz"][i])  + toHWU("Chi2rphi",event["chi2rphi"][i])
        
      if ( pt >= 128
          and (event["nstub"][i]  >= 4 ) 
          and (toHWU("Bendchi2",event["bendchi2"][i]) < 3) 
          and (chi <= 16 )
          and (toHWU("Chi2rz",event["chi2rz"][i]) <= 9 )
          and (toHWU("Chi2rphi",event["chi2rphi"][i]) <= 9 ) ):
          purity_cut.append(i)

    new_event = dict(list([(key,event[key][purity_cut].reset_index(drop=True)) for key in event.keys()]))
    
    return new_event
示例#4
0

def costoHWU(t, fracnbins):

    fracnbins = fracnbins
    tmin = 0
    tmax = 1

    x = tmax if t > tmax else t
    x = tmin if t < tmin else x
    # Get the bin index
    x = (x - tmin) / ((tmax - tmin) / fracnbins)
    return round(x)


cos_LUT = [costoHWU(np.cos(i), lut_precision) for i in phi_iterator]
sin_LUT = [costoHWU(np.sin(i), lut_precision) for i in phi_iterator]

f = open("TrigLUT.txt", "w")
for i in range(len(phi_iterator)):

    f.write("(" + str(int(cos_LUT[i])) + "," + str(int(sin_LUT[i])) + "),\n")

f.close()

f2 = open("ShiftLUT.txt", "w")
for i in range(0, 9):
    f2.write("(" + str(i * 2 * toHWU("Phi", -1.026 + np.pi / 9)) + "),\n")

f2.close()
示例#5
0
import numpy as np
from Formats import TrackWord_config
from Formats import toHWU, HWUto
import util

tanl = np.linspace(0, 7, 2**16)
#eta = np.linspace(-2.5,2.5,2**20)
etagrid = np.zeros([2**3, 2**12], dtype=np.int32)

eta = []

for tanl_i in tanl:
    eta_i = -np.log(np.tan(0.5 * np.arctan(1 / abs(tanl_i))))

    tanl_int, tanl_frac = toHWU("TanL", tanl_i)

    try:
        eta_i = int(toHWU("HWUeta", eta_i))
    except ValueError:
        eta_i = 0
    eta.append(eta_i)
    etagrid[int(tanl_int)][tanl_frac] = eta_i

f = open("TanLUT.txt", "w")
for i in range((2**12)):
    f.write("(")
    line = [(str(etagrid[j][i]) + ",") for j in range(2**3)]
    line[-1] = line[-1][:-1]
    [f.write(l) for l in line]
    f.write("),\n")
示例#6
0
文件: fwGTT.py 项目: Chriisbrown/GTT
def fwInvR(event):
  pt_array = []
  for i in range(len(event["pt"])):
    pt_array.append(2*math.modf(350286/toHWU("InvR",event["InvR"].iloc[i]))[1])
  event["fwPt"] = pt_array
示例#7
0
文件: fwGTT.py 项目: Chriisbrown/GTT
def fwTrackToVertex(event,vertex):
    in_window = []
    TanLUTf = open("TanLUT.txt")
    TanLUTlines = TanLUTf.readlines()
    bin_width = 30/(2**8-1)
    
    for i in range(len(event["eta"])):
        tanl_int,tanl_frac = toHWU("TanL",event["TanL"][i])
        temp_str = TanLUTlines[int(tanl_frac)].split(",")[int(tanl_int)]

        if temp_str[0] == '(':
          eta = int(temp_str[1:])
        elif temp_str[-1] == ')':
          eta = int(temp_str[:-1])
        else:
          eta = int(temp_str)

        z0 = toHWU('Z0',event["z0"][i])
        if np.signbit(z0[1]):
          HWUz =  -z0[0]*8 - int(z0[0]/2) + int(z0[1]/8) + int(z0[1]/64) + 128   #fw estimate
        else:
          HWUz = z0[0]*8 + int(z0[0]/2) + int(z0[1]/8) + int(z0[1]/64) + 128    #fw estimate

        #HWUz = round(sign*(abs(z0[0]*255/(30)) + z0[1]*255/(63*30)) + 255/2)  #true fw
        bin_width = 30/(2**8-1)
        
        if ( eta>= toHWU("HWUeta",0)  and eta< toHWU("HWUeta",0.7) ): 
          DeltaZ = int(0.4/bin_width)
        elif (  eta >= toHWU("HWUeta",0.7)  and eta< toHWU("HWUeta",1.0) ):  
          DeltaZ = int(0.6/bin_width)

        elif ( eta >= toHWU("HWUeta",1.0)  and eta< toHWU("HWUeta",1.2) ):  
          DeltaZ = int(0.76/bin_width)

        elif ( eta >= toHWU("HWUeta",1.2) and eta< toHWU("HWUeta",1.6) ): 
          DeltaZ = int(1.0/bin_width)

        elif ( eta >= toHWU("HWUeta",1.6)  and eta < toHWU("HWUeta",2.0)  ):  
          DeltaZ = int(1.7/bin_width)

        elif ( eta >= toHWU("HWUeta",2.0)  and eta <= toHWU("HWUeta",2.4)  ):
          DeltaZ = int(2.2/bin_width)
        if ( abs(HWUz - toHWU('HWUz0',vertex)) <= DeltaZ):
            in_window.append(i)

    new_event = dict(list([(key,event[key][in_window].reset_index(drop=True)) for key in event.keys()]))

    return new_event
示例#8
0
文件: fwGTT.py 项目: Chriisbrown/GTT
def fwTrackMET(event,fwpt=True,Cordic=True):
  shiftLUTf = open("ShiftLUT.txt")
  shiftLUTlines = shiftLUTf.readlines()

  TrigLUTf = open("TrigLUT.txt")
  TrigLUTlines = TrigLUTf.readlines()

  sumpx_sectors = np.zeros([9])
  sumpy_sectors = np.zeros([9])

  for i in range(len(event["phi"])):
    for sector in range(0,9):
      if event["phiSector"][i] == sector:
        if fwpt:
          pt = event["fwPt"][i]
        else:
          pt = toHWU("Pt",event["pt"][i])/2**6
        
        shift = int(shiftLUTlines[event["phiSector"][i]][1:-3])
        phi = toHWU("Phi",event["Sector_Phi"][i]) + shift
        phi = phi -(2**11)/2

        if phi < 0:
            phi = phi + 2*np.pi/hwu_binsize
        elif phi > 2*np.pi/hwu_binsize:
            phi = phi - 2*np.pi/hwu_binsize  

        if (phi >= 0  and phi < int(np.pi/(2*hwu_binsize))):
            TrigLUT = TrigLUTlines[int(phi)].split(',')
            sumpx_sectors[sector] += int(pt*int(TrigLUT[0][1:])/lut_precision)
            sumpy_sectors[sector] += int(pt*int(TrigLUT[1][:-1])/lut_precision)
        elif (phi >= int(np.pi/(2*hwu_binsize))  and phi < int(np.pi/(hwu_binsize))):
            TrigLUT = TrigLUTlines[int(phi-np.pi/(2*hwu_binsize))].split(',')
            sumpx_sectors[sector] -= int(pt*int(TrigLUT[1][:-1])/lut_precision)
            sumpy_sectors[sector] += int(pt*int(TrigLUT[0][1:])/lut_precision)
        elif (phi >= int(np.pi/(hwu_binsize) )  and phi < int(3*np.pi/(2*hwu_binsize))):
            TrigLUT = TrigLUTlines[int(phi-np.pi/(hwu_binsize))].split(',')
            sumpx_sectors[sector] -= int(pt*int(TrigLUT[0][1:])/lut_precision)
            sumpy_sectors[sector] -= int(pt*int(TrigLUT[1][:-1])/lut_precision)
        elif (phi >= int(3*np.pi/(2*hwu_binsize) )  and phi < int(2*np.pi/(hwu_binsize))):
            TrigLUT = TrigLUTlines[int(phi-3*np.pi/(2*hwu_binsize) )].split(',')
            sumpx_sectors[sector] += int(pt*int(TrigLUT[1][:-1])/lut_precision)
            sumpy_sectors[sector] -= int(pt*int(TrigLUT[0][1:])/lut_precision)

  sumpx = np.sum(sumpx_sectors)
  sumpy = np.sum(sumpy_sectors)

  if Cordic:
    MET_phi,MET = fwCordicSqrt(int(sumpx),int(sumpy),4)
    MET_phi = MET_phi*2*np.pi/2304
    MET = MET/2**6

  else:
    MET = int(np.sqrt(sumpx*sumpx+sumpy*sumpy))/2**6
    MET_phi = np.arctan2(sumpy,sumpx)

    if MET_phi > 0:
      MET_phi -= np.pi
    elif MET_phi <= 0:
      MET_phi += np.pi

  return MET,MET_phi