Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:11

0001 #!/usr/bin/env python
0002 
0003 from __future__ import print_function
0004 import os
0005 import sys
0006 import math
0007 import numpy
0008 import matplotlib.pyplot as plt
0009 import numpy as np
0010 from matplotlib import colors
0011 
0012 ptLSB = 0.25;
0013 etaLSB = 0.0043633231;
0014 phiLSB = 0.0043633231;
0015 hwJets = []
0016 emJets = []
0017 hwData = []
0018 emData = []
0019 hwDataNoZ = []
0020 emDataNoZ = []
0021 nHw = 0
0022 nEm = 0
0023 nEv = 5000
0024 nEvNoZ = 0
0025 
0026 
0027 for hwRx in range(0,70):
0028     with open("datFull/" + str(hwRx) + "/tx_summary.txt", "r") as inFile:
0029         frameIt = -1
0030         for line in inFile:
0031             if('1v' in line):
0032                 frameIt += 1
0033                 if frameIt < 20:
0034                     continue
0035                 if hwRx == 0 and frameIt < 33:
0036                     continue
0037                 linkData = line.split('1v')
0038                 for wordIt in range(1,25):
0039                     word = linkData[wordIt].replace(' ','').replace('\n','')
0040                     if int(word, 16) & 0xffff:
0041                         jet = word[8:]
0042                         hwJets.append([(int(jet,16)&0xffff)*ptLSB, 
0043                                          ((((int(jet,16)>>24)&0xff)*19)+9)*etaLSB,
0044                                          ((((int(jet,16)>>16)&0xff)*20)+10)*phiLSB])
0045                     if (int(word, 16)>>32) & 0xffff:
0046                         jet = word[:8]
0047                         hwJets.append([(int(jet,16)&0xffff)*ptLSB, 
0048                                          ((((int(jet,16)>>24)&0xff)*19)+9)*etaLSB,
0049                                          ((((int(jet,16)>>16)&0xff)*20)+10)*phiLSB])
0050                 if (frameIt%13) == 6:
0051                     if(nHw>=nEv):
0052                         break
0053                     nHw+=1
0054                     if len(hwJets)==0:
0055                         hwJets.append([0,0,0])
0056                     hwData.append(hwJets)
0057                     del hwJets
0058                     hwJets = []
0059 
0060 
0061 with open("emuout.txt", "r") as inFile:
0062     for line in inFile:
0063         if " " in line:
0064             if(nEm>=nEv):
0065                 break
0066             nEm+=1
0067             if len(emJets)>0:
0068                 emData.append(emJets)
0069             del emJets
0070             emJets = []
0071         else:
0072             jet = [float(line.split("\t")[0]),
0073                    float(line.split("\t")[1]),
0074                    float(line.split("\t")[2])]
0075             emJets.append(jet)
0076 
0077 
0078 nDiff = 0
0079 
0080 for evIt in range(0,nEv):
0081     if len(hwData[evIt]) != len(emData[evIt]):
0082         nDiff+=1
0083         continue
0084     goodJet=0
0085     for hwJet in hwData[evIt]:
0086         for emJet in emData[evIt]:
0087             if hwJet[0] == emJet[0]:
0088                 if (hwJet[1]-emJet[1])<0.01:
0089                     if (hwJet[2]-emJet[2])<0.01:
0090                         goodJet+=1
0091     if goodJet < len(hwData[evIt]):
0092         nDiff+=1
0093 
0094 
0095 print("\n\nnEvent = " + str(nEv) + "\nnDiff = " + str(nDiff) + "\nGood events = " + str((1-float(nDiff)/float(nEv))*100) + "%")
0096         
0097 
0098 
0099 print("\n\n=====================================================================================")
0100 print("\t\tFirmware Events: " + str(nHw) + "\t\t" + "Emulator Events: " + str(nEm))
0101 print("=====================================================================================")
0102 print("\t\tpT\t" + "eta\t" + "phi\t\t" + "pT\t" + "eta\t" + "phi\t")
0103 print("=====================================================================================")
0104 
0105 
0106 for evIt in range(0,nEv):
0107     if hwData[evIt][0][0] > 0:
0108         hwDataNoZ.append(hwData[evIt])
0109     if emData[evIt][0][0] > 0:
0110         emDataNoZ.append(emData[evIt])
0111     nEvNoZ+=1
0112 
0113 
0114 for evIt in range(0,nEv):
0115     if hwData[evIt][0][0] ==0 and emData[evIt][0][0] == 0:
0116         continue
0117     jetCount=0
0118     jetDiff = len(hwData[evIt]) - len(emData[evIt])
0119     print("")
0120     if jetDiff==0:
0121         for jetIt in range(len(hwData[evIt])):
0122             print(str(evIt) + "\t\t" + str(hwData[evIt][jetIt][0]) + "\t" + str(hwData[evIt][jetIt][1])[:4] + "\t" + str(hwData[evIt][jetIt][2])[:4] + "\t\t" +
0123                   str(emData[evIt][jetIt][0]) + "\t" + str(emData[evIt][jetIt][1])[:4] + "\t" + str(emData[evIt][jetIt][2])[:4])
0124     if jetDiff>0:
0125         for jetIt in range(len(hwData[evIt])):
0126             jetCount+=1
0127             if jetCount > len(emData[evIt]):
0128                 emData[evIt].append([0,0,0])
0129             print(str(evIt) + "\t\t" + str(hwData[evIt][jetIt][0]) + "\t" + str(hwData[evIt][jetIt][1])[:4] + "\t" + str(hwData[evIt][jetIt][2])[:4]  + "\t\t" +
0130                   str(emData[evIt][jetIt][0]) + "\t" + str(emData[evIt][jetIt][1])[:4] + "\t" + str(emData[evIt][jetIt][2])[:4])
0131     if jetDiff<0:
0132         for jetIt in range(len(emData[evIt])):
0133             jetCount+=1
0134             if jetCount > len(hwData[evIt]):
0135                 hwData[evIt].append([0,0,0])
0136             print(str(evIt) + "\t\t" + str(hwData[evIt][jetIt][0]) + "\t" + str(hwData[evIt][jetIt][1])[:4] + "\t" + str(hwData[evIt][jetIt][2])[:4]  + "\t\t" +
0137                   str(emData[evIt][jetIt][0]) + "\t" + str(emData[evIt][jetIt][1])[:4] + "\t" + str(emData[evIt][jetIt][2])[:4])
0138         
0139 
0140 
0141 
0142 fig, axs =   plt.subplots(2,3, figsize=(20, 10), gridspec_kw={'height_ratios': [3, 1]})
0143 
0144 fig.patch.set_facecolor( '#ffffff')
0145 
0146 
0147 nPtHw,  bPtHw  = np.histogram([jet[0] for event in hwDataNoZ for jet in event], bins=50, range=(0,200))
0148 nEtaHw, bEtaHw = np.histogram([jet[1] for event in hwDataNoZ for jet in event], bins=18, range=(0,1.5))
0149 nPhiHw, bPhiHw = np.histogram([jet[2] for event in hwDataNoZ for jet in event], bins=8,  range=(0,0.7))
0150 
0151 meansPt  = [0.5*(bPtHw[i]  + bPtHw[i+1])  for i in range(len(nPtHw))]
0152 meansEta = [0.5*(bEtaHw[i] + bEtaHw[i+1]) for i in range(len(nEtaHw))]
0153 meansPhi = [0.5*(bPhiHw[i] + bPhiHw[i+1]) for i in range(len(nPhiHw))]
0154 
0155 nPtEm  = axs[0,0].hist([jet[0] for event in emDataNoZ for jet in event], bins=50, range=(0,200), histtype='bar', linewidth=1.5, label='Emulator', color='#929591', zorder=0)[0]
0156 nEtaEm = axs[0,1].hist([jet[1] for event in emDataNoZ for jet in event], bins=18, range=(0,1.5), histtype='bar', linewidth=1.5, label='Emulator', color='#929591', zorder=0)[0]
0157 nPhiEm = axs[0,2].hist([jet[2] for event in emDataNoZ for jet in event], bins=8,  range=(0,0.7), histtype='bar', linewidth=1.5, label='Emulator', color='#929591', zorder=0)[0]
0158 
0159 axs[0,0].scatter(meansPt,  nPtHw,  label='Firmware', c='#000000', linewidths=0.5, s=25, marker='+')
0160 axs[0,1].scatter(meansEta, nEtaHw, label='Firmware', c='#000000', linewidths=0.5, s=25, marker='+')
0161 axs[0,2].scatter(meansPhi, nPhiHw, label='Firmware', c='#000000', linewidths=0.5, s=25, marker='+')
0162 
0163 
0164 axs[1,0].scatter(meansPt,  [(hw/em) for hw,em in zip(nPtHw,nPtEm)] ,  c='#000000', linewidths=0.5, s=15, zorder=1)
0165 axs[1,1].scatter(meansEta, [(hw/em) for hw,em in zip(nEtaHw,nEtaEm)], c='#000000', linewidths=0.5, s=15, zorder=1)
0166 axs[1,2].scatter(meansPhi, [(hw/em) for hw,em in zip(nPhiHw,nPhiEm)], c='#000000', linewidths=0.5, s=15, zorder=1)
0167 
0168 axs[1,0].axhline(y=1, linewidth=1, linestyle='--', c='#929591')
0169 axs[1,1].axhline(y=1, linewidth=1, linestyle='--', c='#929591')
0170 axs[1,2].axhline(y=1, linewidth=1, linestyle='--', c='#929591')
0171 
0172 axs[1,0].set(ylim=(0.5,1.5))
0173 axs[1,1].set(ylim=(0.5,1.5))
0174 axs[1,2].set(ylim=(0.5,1.5))
0175 
0176 axs[0,0].set(ylabel="Events")
0177 axs[1,0].set(ylabel="FW / EMU")
0178 
0179 axs[0,0].legend(prop={'size': 10})
0180 axs[0,1].legend(prop={'size': 10})
0181 axs[0,2].legend(prop={'size': 10})
0182 
0183 ymaxPt  = max(np.concatenate([nPtHw,nPtEm]))
0184 ymaxEta = max(np.concatenate([nEtaHw,nEtaEm]))
0185 ymaxPhi = max(np.concatenate([nPhiHw,nPhiEm]))
0186 
0187 axs[0,0].set(xlim=(0,200))
0188 axs[0,1].set(xlim=(0,1.5))
0189 axs[0,2].set(xlim=(0,0.7))
0190 
0191 axs[0,0].set(ylim=(0,ymaxPt +(0.05*ymaxPt)))
0192 axs[0,1].set(ylim=(0,ymaxEta+(0.05*ymaxEta)))
0193 axs[0,2].set(ylim=(0,ymaxPhi+(0.05*ymaxPhi)))
0194 
0195 axs[0,0].set(xlabel="Jet $p_T$ (GeV)")
0196 axs[0,1].set(xlabel="Jet $\eta$")
0197 axs[0,2].set(xlabel="Jet $\phi$")
0198 
0199 plt.savefig('ttbarPU200_3900.pdf', bbox_inches='tight')