def validateMomenta(self, jet, tolerance=.01): """ Checks if the jetmomentum is the sum of the constituent momenta. """ v = TLorentzVector(0, 0, 0, 0) for comp in jet.constituents.values(): for ptc in comp: v += ptc.p4() ret = True if abs(jet.pt() - v.Pt()) > tolerance: print 'pt unequal: ', jet.pt() - v.Pt() ret = False if abs(jet.theta() - v.Theta()) > tolerance: print 'theta unequal: ', jet.theta() - v.Theta() ret = False if abs(jet.eta() - v.Eta()) > tolerance: print 'eta unequal', jet.eta() - v.Eta() ret = False if abs(jet.phi() - v.Phi()) > tolerance: print 'phi unequal: ', jet.phi() - v.Phi() ret = False if abs(jet.m() - v.M()) > tolerance: print 'mass unequal: ', jet.m() - v.M() ret = False return ret
def print_vec(self, vec): print "theta vec:", TMath.Pi() - vec.Theta() print return print "pxyz:", vec.Px(), vec.Py(), vec.Pz() print "en, phi:", vec.E(), vec.Phi() print v3 = vec.Vect() print "vxyz:", v3.x(), v3.y(), v3.z() print "theta v3: ", TMath.Pi() - v3.Theta() print theta_add = 1e-5 v3.SetTheta(v3.Theta() - theta_add) print "vxyz:", v3.x(), v3.y(), v3.z() print "theta v3: ", TMath.Pi() - v3.Theta() print vec2 = TLorentzVector(vec) vec3 = TLorentzVector(vec) vec.SetVect(v3) print "theta vec:", TMath.Pi() - vec.Theta() print "pxyz:", vec.Px(), vec.Py(), vec.Pz() print "en, phi:", vec.E(), vec.Phi() print vec2.SetTheta(vec2.Theta() - theta_add) print "theta vec:", TMath.Pi() - vec2.Theta() print "pxyz:", vec2.Px(), vec2.Py(), vec2.Pz() print "en, phi:", vec2.E(), vec2.Phi() print print "Delta theta, en, phi", vec3.Theta() - vec.Theta(), vec3.E( ) - vec.E(), vec3.Phi() - vec.Phi() print "Delta theta, en, phi", vec3.Theta() - vec2.Theta(), vec3.E( ) - vec2.E(), vec3.Phi() - vec2.Phi()
def fixMiss(self): self.fillUnknowns() miss = TLorentzVector(0., 0., 0., 1.) for i in range(5): miss -= TLorentzVector(self.x[i]*self.beta[i]*sin(self.theta[i])*cos(self.phi[i]), \ self.x[i]*self.beta[i]*sin(self.theta[i])*sin(self.phi[i]), \ self.x[i]*self.beta[i]*cos(self.theta[i]), \ self.x[i]) self.alpha[5] = miss.E() self.alpha[6] = miss.P() / miss.E() self.alpha[7] = miss.Theta() self.alpha[8] = miss.Phi() self.fillUnknowns() self.fillConstraints(False)
print("(pred[event][index + 2]) should be phi", (pred[event][index + 2])) print("test M!", tau_lorentz.M()) print("test!", tau_lorentz.Pt()) print("test Eta", tau_lorentz.Eta()) print("test Phi", tau_lorentz.Phi()) tofill['tau_pt'] = tau_lorentz.Pt() tofill['tau_eta'] = tau_lorentz.Eta() tofill['tau_phi'] = tau_lorentz.Phi() tofill['tau_mass'] = tau_lorentz.M() print("poodle tau_lorentz.M()", tau_lorentz.M()) print("tau_lorentz.Pt()", tau_lorentz.Pt()) print("tau_lorentz.Eta()", tau_lorentz.Eta()) print("tau_lorentz.Phi()", tau_lorentz.Phi()) print("tau_lorentz.Theta()", tau_lorentz.Theta()) #begin unrotation for index in range(0, tau_to_unrotate_info.shape[1], 3): almost_in_lab_frame_tau_lorentz = unrotateFromLeadPtPiInVisTauMomPointsAlongZFramePointsAlongNegX( (tau_to_unrotate_info_to_use[event][index]), tau_lorentz) print(" poodle almost_in_lab_frame_tau_lorentz.M() is:", almost_in_lab_frame_tau_lorentz.M()) lab_frame_tau_lorentz = unrotateFromVisTauMomPointsAlongZAxis( (tau_to_unrotate_info_to_use[event][index + 1]), (tau_to_unrotate_info_to_use[event][index + 2]), almost_in_lab_frame_tau_lorentz) print("poodle lab_frame_tau_lorentz.M() is:", lab_frame_tau_lorentz.M()) almost_in_lab_frame_tau_lorentz_no_neutrino = unrotateFromLeadPtPiInVisTauMomPointsAlongZFramePointsAlongNegX( (tau_to_unrotate_info_to_use[event][index]),
tmp_unrotated_Py = tmp_unrotated_PxPyPz_vec[1] tmp_unrotated_Pz = tmp_unrotated_PxPyPz_vec[2] Global_4vec = ROOT.TLorentzVector() Global_4vec.SetPxPyPzE(tmp_unrotated_Px, tmp_unrotated_Py, tmp_unrotated_Pz, tmp_E) return Global_4vec ##### test ##### v = TLorentzVector() v.SetPxPyPzE(-3.6740152498, -2.79192430698, 21.6557548444, 22.1777103583) print "Px,Py,Pz,E,M:", v.Px(), v.Py(), v.Pz(), v.E(), v.M() print "tau_orig_theta, tau_orig_phi:", v.Theta(), v.Phi() tau_orig_theta_test = v.Theta() tau_orig_phi_test = v.Phi() toPrint = rotateToVisTauMomPointsInEtaEqualsZero(tau_orig_theta_test, tau_orig_phi_test, v) # print toPrint newPx = toPrint.Px() newPy = toPrint.Py() newPz = toPrint.Pz() newE = toPrint.E() newM = toPrint.M() newTheta = toPrint.Theta() newPhi = toPrint.Phi()
def PruneGenr8File(fname_in, fname_out, E_GAMMA_VARY, MIN_VAL, MAX_VAL, NACCEPTED, MAX_EVENTS, verbose=False): # print "input genr8 file: " + fname_in # print "output file: " + fname_out counter = 1 line1_out = "" #Run and event info line2_out = "1 1 0.000000\n" #Gamma ID info line3_out = "" #Gamma P4 info for line in open(fname_in, 'r'): if (NACCEPTED >= MAX_EVENTS): # print "Done generating this point!" break if (counter % 11 == 1): #Event info value_in_line = 1 run = "" event = "" for value in line.split(): if (value_in_line == 1): run = value if (value_in_line == 2): event = value if (verbose and value_in_line == 1): print "Run " + value if (verbose and value_in_line == 2): print "Event " + value if (verbose and value_in_line == 3): print "NParticles " + value value_in_line += 1 # line1_out = run + " " + event + " " + "1\n" line1_out = run + " " + str(NACCEPTED + 1) + " " + "1\n" if (counter % 11 == 2): #Gamma1 info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 if (counter % 11 == 3): #Gamma1 p4 value_in_line = 1 p4_string = line.split() p4_gam1 = TLorentzVector(float(p4_string[1]), float(p4_string[2]), float(p4_string[3]), float(p4_string[4])) for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 if (counter % 11 == 4): #Gamma2 info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 if (counter % 11 == 5): #Gamma2 p4 value_in_line = 1 p4_string = line.split() p4_gam2 = TLorentzVector(float(p4_string[1]), float(p4_string[2]), float(p4_string[3]), float(p4_string[4])) for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 if (counter % 11 == 6): #Pi+ info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 if (counter % 11 == 7): #Pi+ p4 value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 if (counter % 11 == 8): #Pi- info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 if (counter % 11 == 9): #Pi- p4 value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 if (counter % 11 == 10): #proton info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 if (counter % 11 == 0): #proton p4 value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 #Finished with this event. Check if one of the two photons passes cuts. #If so, save event and increment NACCEPTED if (verbose): print "Cut on energy? " + str(E_GAMMA_VARY) print "Cut on theta? " + str(not E_GAMMA_VARY) print "Min value: " + str(MIN_VAL) print "Max value: " + str(MAX_VAL) print "Gamma1 energy: " + str(p4_gam1.E()) print "Gamma2 energy: " + str(p4_gam2.E()) GAMMA1_PASSES = False if (E_GAMMA_VARY and MIN_VAL < p4_gam1.E() and p4_gam1.E() < MAX_VAL and p4_gam2.E() > E_SPECTATOR_MIN): GAMMA1_PASSES = True if (not E_GAMMA_VARY and MIN_VAL < p4_gam1.Theta() * 180 / 3.14159 and p4_gam1.Theta() * 180 / 3.14159 < MAX_VAL): GAMMA1_PASSES = True if (verbose and GAMMA1_PASSES): print "Gamma1 passes: " print "Min value: " + str(MIN_VAL) print "Max value: " + str(MAX_VAL) print "Gamma1 energy: " + str(p4_gam1.E()) if (GAMMA1_PASSES): with open(fname_out, "a") as myfile: line3_out = " 0 " + str(p4_gam1.Px()) + " " + str( p4_gam1.Py()) + " " + str(p4_gam1.Pz()) + " " + str( p4_gam1.E()) + "\n" myfile.write(line1_out) myfile.write(line2_out) myfile.write(line3_out) NACCEPTED += 1 GAMMA2_PASSES = False if (E_GAMMA_VARY and MIN_VAL < p4_gam2.E() and p4_gam2.E() < MAX_VAL and p4_gam1.E() > E_SPECTATOR_MIN): GAMMA2_PASSES = True if (not E_GAMMA_VARY and MIN_VAL < p4_gam2.Theta() * 180 / 3.14159 and p4_gam2.Theta() * 180 / 3.14159 < MAX_VAL): GAMMA2_PASSES = True if (verbose and GAMMA2_PASSES): print "Gamma2 passes: " print "Min value: " + str(MIN_VAL) print "Max value: " + str(MAX_VAL) print "Gamma2 energy: " + str(p4_gam2.E()) if (GAMMA2_PASSES): with open(fname_out, "a") as myfile: line3_out = " 0 " + str(p4_gam2.Px()) + " " + str( p4_gam2.Py()) + " " + str(p4_gam2.Pz()) + " " + str( p4_gam2.E()) + "\n" myfile.write(line1_out) myfile.write(line2_out) myfile.write(line3_out) NACCEPTED += 1 if (verbose): print "\n" # with open(fname_out, "a") as myfile: # myfile.write(line1_out) # myfile.write(line2_out) counter += 1 # if(counter>200): break return NACCEPTED
m1 = pdg.GetParticle(int(g1line[3])).Mass() m2 = pdg.GetParticle(int(g2line[3])).Mass() v0 = TLorentzVector(g0d[0], g0d[1], g0d[2], sqrt(g0d[0]**2 + g0d[1]**2 + g0d[2]**2 + m0**2)) v1 = TLorentzVector(g1d[0], g1d[1], g1d[2], sqrt(g1d[0]**2 + g1d[1]**2 + g1d[2]**2 + m1**2)) v2 = TLorentzVector(g2d[0], g2d[1], g2d[2], sqrt(g2d[0]**2 + g2d[1]**2 + g2d[2]**2 + m2**2)) m = v1 + v2 h1.Fill(m0) h0.Fill(m.M()) #v0 = TVector3( g0d[0], g0d[1], g0d[2] ) #v1 = TVector3( g1d[0], g1d[1], g1d[2] ) h2t.Fill(degrees(v1.Theta()), degrees(v2.Theta())) h2p.Fill(degrees(v1.Phi()), degrees(v2.Phi())) i += int(line[0]) + 1 c0 = TCanvas() h1.Draw() h0.SetLineColor(2) h0.Draw("same") c1 = TCanvas("theta", "theta") h2t.Draw("colz") c2 = TCanvas("phi", "phi") h2p.Draw("colz")