def reconstruct_track( self, track, pdgid, parent_ids, clusters=None ): # cluster argument does not ever seem to be used at present '''construct a charged hadron from the track ''' if self.locked[track.uniqueid]: return vertex = track.path.points['vertex'] pdgid = pdgid * track.charge mass, charge = particle_data[pdgid] p4 = TLorentzVector() p4.SetVectM(track.p3(), mass) particle = Particle(p4, vertex, charge, pdgid, len(self.particles), subtype='r') #todo fix this so it picks up smeared track points (need to propagagte smeared track) particle.set_track( track) #refer to existing track rather than make a new one self.locked[track.uniqueid] = True pdebugger.info(str('Made {} from {}'.format(particle, track))) self.insert_particle(parent_ids, particle) return particle
def test_ip_many(self): npoints = 100 radii = np.linspace(0.1, 0.2, npoints) angles = np.linspace(0, math.pi, npoints) momenta = np.linspace(200, 500, npoints) mass = 0.5 field = 1e-5 origin = TVector3(0, 0, 0) for radius, angle, momentum in zip(radii, angles, momenta): ip_pos = TVector3(math.cos(angle), math.sin(angle), 0) ip_pos *= radius smom = TVector3(math.cos(angle - math.pi / 2.), math.sin(angle - math.pi / 2.), 0) smom *= momentum p4 = TLorentzVector() p4.SetVectM(smom, mass) helix_vertex = copy.deepcopy(ip_pos) delta = copy.deepcopy(smom.Unit()) delta *= radius helix_vertex += delta helix = Helix(field, 1., p4, helix_vertex) ip_mine = helix.compute_IP_2(origin, smom) ip_nic = compute_IP(helix, origin, smom) ip_luc = helix.compute_IP(origin, smom) nplaces = 8 self.assertAlmostEqual(abs(ip_luc), radius, places=nplaces) #COLIN in the following, I modify Nic's minimization args # so that they work, and to reach Lucas' precision # it works with nplaces = 5 though. self.assertAlmostEqual(abs(ip_mine), radius, places=nplaces)
def test_layerfan(self): c1 = Cluster(10, TVector3(1, 0, 0), 1., 'ecal_in') c2 = Cluster(20, TVector3(1, 0, 0), 1., 'hcal_in') p3 = c1.position.Unit()*100. p4 = TLorentzVector() p4.SetVectM(p3, 1.) path = StraightLine(p4, TVector3(0,0,0)) charge = 1. tr = Track(p3, charge, path) tr.path.points['ecal_in'] = c1.position tr.path.points['hcal_in'] = c2.position elems = [c1, c2, tr] for ele in elems: link_type, link_ok, distance = ruler(ele, ele) if ele!=tr: self.assertTrue(link_ok) elif ele==tr: self.assertFalse(link_ok) #ecal hcal no longer linked to match c++ so have adjusted test accordingly link_type, link_ok, distance = ruler(c2, c1) self.assertFalse(link_ok) self.assertEqual(link_type, None) link_type, link_ok, distance = ruler(tr, c1) self.assertTrue(link_ok) link_type, link_ok, distance = ruler(tr, c2) self.assertTrue(link_ok)
def process(self, event): ptcs = getattr(event, self.cfg_ana.particles) sump3 = TVector3() charge = 0 sume = 0 for ptc in ptcs: sump3 += ptc.p3() charge += ptc.q() p4 = TLorentzVector() p4.SetVectM(-sump3, 0) missing = Particle(0, charge, p4) setattr(event, self.instance_label, missing)
def reconstruct_track(self, track, clusters = None): # cluster argument does not ever seem to be used at present '''construct a charged hadron from the track ''' vertex = track.path.points['vertex'] pdg_id = 211 * track.charge mass, charge = particle_data[pdg_id] p4 = TLorentzVector() p4.SetVectM(track.p3, mass) particle = Particle(p4, vertex, charge, pdg_id, Identifier.PFOBJECTTYPE.RECPARTICLE) particle.set_path(track.path) particle.clusters = clusters self.locked[track.uniqueid] = True pdebugger.info(str('Made {} from {}'.format(particle, track))) return particle
def test_ip_many(self): npoints = 100 scale = 1e-6 radii = np.linspace(0.1 * scale, 0.2 * scale, npoints) angles = np.linspace(0, math.pi, npoints) momenta = np.linspace(200, 500, npoints) mass = 0.5 field = 1e-5 origin = TVector3(0, 0, 0) for radius, angle, momentum in zip(radii, angles, momenta): ip_pos = TVector3(math.cos(angle), math.sin(angle), 0) ip_pos *= radius p3 = TVector3(math.cos(angle - math.pi / 2.), math.sin(angle - math.pi / 2.), 0) p3 *= momentum p4 = TLorentzVector() p4.SetVectM(p3, mass) helix_vertex = copy.deepcopy(ip_pos) delta = copy.deepcopy(p3.Unit()) delta *= radius helix_vertex += delta helix = Helix(field, 1., p4, helix_vertex) # jet direction is 0.1 radians away from particle direction # to obtain a positivive IP sign jet_dir = copy.deepcopy(p3).Unit() jet_dir.RotateZ(0.1) ip_nic = compute_IP(helix, origin, jet_dir) ip_obj = ImpactParameter(helix, origin, jet_dir) verbose = False places = 8 if verbose: print '-' * 50 print math.cos(angle), math.sin(angle), radius print 'obj', ip_obj.value, '({})'.format( abs(ip_obj.value) - radius) print 'nic', ip_nic, '({})'.format(abs(ip_nic) - radius) else: self.assertAlmostEqual(abs(ip_obj.value), radius, places=places) #COLIN->NIC: Nicolo's minimization does not give the right result # could be that it only works for very small distances? # can be tested by uncommenting the following line and # running this test file self.assertAlmostEqual(abs(ip_nic), radius, places=places)
def monojet(pdgids, theta, phi, pstar, jetenergy, vertex=None): particles = [] if vertex is None: vertex = TVector3(0., 0., 0.) jetp4star = TLorentzVector() for pdgid in pdgids[:-1]: mass, charge = particle_data[pdgid] phistar = random.uniform(-math.pi, math.pi) thetastar = random.uniform(-math.pi, math.pi) sint = math.sin(thetastar) cost = math.cos(thetastar) sinp = math.sin(phistar) cosp = math.cos(phistar) pz = pstar * cost px = pstar * sint * cosp py = pstar * sint * sinp p4 = TLorentzVector() p4.SetXYZM(px, py, pz, mass) jetp4star += p4 particles.append(Particle(p4, vertex, charge, pdgid)) pdgid = pdgids[-1] mass, charge = particle_data[pdgid] p4 = TLorentzVector() p4.SetVectM(-jetp4star.Vect(), mass) particles.append(Particle(p4, vertex, charge, pdgid)) jetp4star += p4 #boosting to lab gamma = jetenergy / jetp4star.M() beta = math.sqrt(1 - 1 / gamma**2) boostvec = TVector3( math.sin(theta) * math.cos(phi), math.sin(theta) * math.sin(phi), math.cos(theta)) boostvec *= beta boosted_particles = [] jetp4 = LorentzVector() for ptc in particles: bp4 = LorentzVector(ptc.p4()) bp4.Boost(boostvec) jetp4 += bp4 boosted_particles.append( Particle(bp4, ptc.vertex, ptc.q(), ptc.pdgid())) # print jetp4.M(), jetp4.E() return boosted_particles
def analyze(): BEAM = 4.81726 # Beam energy in GeV MASS_P = 0.93827203 # Mass in GeV MASS_E = 0.000511 # Mass in GeV MASS_PIP = 0.13957018 # Mass in GeV fin = "511_lab_E_PIP_data.csv.gz" fout = "MissingMass.root" # TODO: Create the histograms you want to fill # Load chain from branch lab OutputFile = TFile(fout, "RECREATE") #Create 4 vectors for the scattered electron e_mu_prime_3 = TVector3() e_mu_prime = TLorentzVector() # TODO: Create 4 vectors for the scattered pion data = pd.read_csv(fin, sep=',') data['e_px'] = data['e_p'] * data['e_cx'] data['e_py'] = data['e_p'] * data['e_cy'] data['e_pz'] = data['e_p'] * data['e_cz'] for event in data.itertuples(): e_mu_prime_3.SetXYZ(event.e_px, event.e_py, event.e_pz) e_mu_prime.SetVectM(e_mu_prime_3, MASS_E) # print(e_mu_prime.E()) #TODO: Calculate missing mass using the functions you created above # and fill the histogram. #end stuff OutputFile.cd() # TODO: # Fit the missing mass peak. # Hint: Get everything else working first. # Then try some of the fits we used in previous labs. #TODO: Write the histograms into the file #hist.Write() OutputFile.Close()
def analyze(): BEAM = 4.81726 # Beam energy in GeV MASS_P = 0.93827203 # Mass in GeV MASS_E = 0.000511 # Mass in GeV fin = "511_lab_E_data.csv.gz" fout = "WvsQ2.root" # TODO: Create the histograms you want to fill # Load chain from branch lab OutputFile = TFile(fout, "RECREATE") #Create 4 vectors for the scattered electron e_mu_prime_3 = TVector3() e_mu_prime = TLorentzVector() data = pd.read_csv(fin, sep=',') data['px'] = data['p'] * data['cx'] data['py'] = data['p'] * data['cy'] data['pz'] = data['p'] * data['cz'] for event in data.itertuples(): # We setup the scattered electron by first setting the momentum 3 vector e_mu_prime_3.SetXYZ(event.px, event.py, event.pz) # And then adding a mass to the 3 vector # ROOT will calculate the proper energy for # the 4 vector for us this way. # Check out (https://root.cern.ch/doc/master/classTLorentzVector.html) # for reference e_mu_prime.SetVectM(e_mu_prime_3, MASS_E) #print(e_mu_prime.E()) #TODO: Calculate W and Q^2 using the functions you created above and fill the histograms. #end stuff OutputFile.cd() #TODO: Write the histograms into the file #hist.Write() OutputFile.Close()
def test_many(self): nzeds = 100 masses = np.linspace(80, 100, nzeds) boosts = np.linspace(1, 50, nzeds) thetas = np.linspace(1, math.pi, nzeds) for mass, boost, theta in zip(masses, boosts, thetas): energy = mass / 2. ptc1 = Particle(11, -1, TLorentzVector(0, energy, 0, energy)) ptc2 = Particle(11, 1, TLorentzVector(0, -energy, 0, energy)) resonance = Resonance(ptc1, ptc2, 23) p3_lab = TVector3() p3_lab.SetMagThetaPhi(boost, theta, 0.1) p4_lab = TLorentzVector() p4_lab.SetVectM(p3_lab, mass) bp4 = copy.deepcopy(resonance.p4()) boost_vector = p4_lab.BoostVector() bp4.Boost(boost_vector) places = 8 self.assertAlmostEqual(bp4.Vect().Mag(), boost, places) self.assertAlmostEqual(bp4.M(), mass, places) resonance.boost(boost_vector) self.assertAlmostEqual(bp4.E(), resonance.e(), places)
def test_layerfan(self): c1 = Cluster(10, TVector3(1, 0, 0), 1., 'ecal_in') c2 = Cluster(20, TVector3(1, 0, 0), 1., 'hcal_in') p3 = c1.position.Unit() * 100. p4 = TLorentzVector() p4.SetVectM(p3, 1.) path = StraightLine(p4, TVector3(0, 0, 0)) charge = 1. tr = Track(p3, charge, path) tr.path.points['ecal_in'] = c1.position tr.path.points['hcal_in'] = c2.position elems = [c1, c2, tr] for ele in elems: link_type, link_ok, distance = ruler(ele, ele) if ele != tr: self.assertTrue(link_ok) elif ele == tr: self.assertFalse(link_ok) for ele1, ele2 in itertools.combinations(elems, 2): link_type, link_ok, distance = ruler(ele1, ele2) self.assertTrue(link_ok) link_type, link_ok, distance = ruler(c2, c1) self.assertEqual(link_type, ('ecal_in', 'hcal_in'))
def fvec(_px, _py, _pz, _mass): """Returns four vector given the momentum in each direction and mass of the particle.""" _vec = TVector3(_px, _py, _pz) _4vec = TLorentzVector() _4vec.SetVectM(_vec, _mass) return _4vec
def makeRooDataSet(type, infile_name, outfile_name, tree_name, nevents): """ Make RooDataSets from TTrees""" inputfile = TFile.Open(infile_name, "READ") print "Importing tree" tree = TTree() inputfile.GetObject(tree_name, tree) #get the tree from the data file #define variables for the RooDataSet m_mumu = RooRealVar("m_mumu", "m_mumu", 0.0, 4.0) y_mumu = RooRealVar("y_mumu", "y_mumu", 0.0, 2.0) pt_mumu = RooRealVar("pt_mumu", "pt_mumu", 0.0, 260.0) eta_gamma = RooRealVar("eta_gamma", "eta_gamma", -3.5, 3.5) pt_gamma = RooRealVar("pt_gamma", "pt_gamma", 0.0, 100.0) m_gamma = RooRealVar("m_gamma", "m_gamma", -0.1, 0.1) m_chi_rf1S = RooRealVar("m_chi_rf1S", "m_chi_rf1S", 0.0, 7.0) m_chi_rf2S = RooRealVar("m_chi_rf2S", "m_chi_rf2S", -1.0, 1.0) Qvalue = RooRealVar("Qvalue", "Q", -15., 15.) ctpv = RooRealVar("ctpv", "ctpv", -1.0, 3.5) ctpv_error = RooRealVar("ctpv_err", "ctpv_err", -1.0, 1.0) pi0_abs_mass = RooRealVar("pi0_abs_mass", "pi0_abs_mass", 0.0, 2.2) psi1S_nsigma = RooRealVar("psi1S_nsigma", "psi1S_nsigma", 0.0, 1.0) psi2S_nsigma = RooRealVar("psi2S_nsigma", "psi2S_nsigma", 0.0, 1.0) psi3S_nsigma = RooRealVar("psi3S_nsigma", "psi3S_nsigma", 0.0, 1.0) rho_conv = RooRealVar("rho_conv", "rho_conv", 0.0, 70.0) dz = RooRealVar("dz", "dz", -1.0, 1.0) probFit1S = RooRealVar('probFit1S', 'probFit1S', 0, 1) probFit2S = RooRealVar('probFit2S', 'probFit2S', 0, 1) probFit3S = RooRealVar('probFit3S', 'probFit3S', 0, 1) dataArgSet = RooArgSet(m_mumu, y_mumu, pt_mumu, eta_gamma, pt_gamma, m_gamma, m_chi_rf1S) dataArgSet.add(m_chi_rf2S) dataArgSet.add(Qvalue) dataArgSet.add(ctpv) dataArgSet.add(ctpv_error) dataArgSet.add(pi0_abs_mass) dataArgSet.add(psi1S_nsigma) dataArgSet.add(psi2S_nsigma) dataArgSet.add(rho_conv) dataArgSet.add(dz) dataArgSet.add(probFit1S) dataArgSet.add(probFit2S) dataArgSet.add(probFit3S) print "Creating DataSet" dataSet = RooDataSet("chicds", "Chic RooDataSet", dataArgSet) entries = tree.GetEntries() print entries if nevents is not 0: entries = nevents for ientry in range(0, entries): tree.GetEntry(ientry) # unfort ntuples are slightly different for chic and chib if applyscale: if usekinfit: spatial = tree.rf1S_photon_p4.Vect() spatial *= (1 / escale) corr_photon_p4 = TLorentzVector() #corr_photon_p4.SetVectM(spatial,tree.rf1S_photon_p4.M()) corr_photon_p4.SetVectM(spatial, 0) corr_chi_p4 = tree.rf1S_dimuon_p4 + corr_photon_p4 else: spatial = tree.photon_p4.Vect() spatial *= (1 / escale) corr_photon_p4 = TLorentzVector() corr_photon_p4.SetVectM(spatial, tree.photon_p4.M()) corr_chi_p4 = tree.dimuon_p4 + corr_photon_p4 else: corr_chi_p4 = tree.chi_p4 if type == 'chic': m_mumu.setVal(tree.dimuon_p4.M()) y_mumu.setVal(tree.dimuon_p4.Rapidity()) pt_mumu.setVal(tree.dimuon_p4.Pt()) eta_gamma.setVal(tree.photon_p4.Eta()) pt_gamma.setVal(tree.photon_p4.Pt()) m_gamma.setVal(tree.photon_p4.M()) m_chi_rf1S.setVal(tree.rf1S_chi_p4.M()) m_chi_rf1S.setVal(tree.rf2S_chi_p4.M()) if usekinfit: Qvalue.setVal(corr_chi_p4.M()) else: Qvalue.setVal((corr_chi_p4).M() - tree.dimuon_p4.M()) print 'corr value ', corr_chi_p4.M() #Qvalue.setVal((tree.chi_p4).M()**2 - tree.dimuon_p4.M()**2) psi1S_nsigma.setVal(tree.psi1S_nsigma) psi2S_nsigma.setVal(tree.psi2S_nsigma) psi3S_nsigma.setVal(0) elif type == 'chib': m_mumu.setVal(tree.dimuon_p4.M()) y_mumu.setVal(tree.dimuon_p4.Rapidity()) pt_mumu.setVal(tree.dimuon_p4.Pt()) eta_gamma.setVal(tree.photon_p4.Eta()) pt_gamma.setVal(tree.photon_p4.Pt()) m_chi_rf1S.setVal(tree.rf1S_chi_p4.M()) m_chi_rf2S.setVal(tree.rf2S_chi_p4.M()) if usekinfit: Qvalue.setVal(corr_chi_p4.M()) else: Qvalue.setVal(corr_chi_p4.M() - tree.dimuon_p4.M()) psi1S_nsigma.setVal(tree.Y1S_nsigma) psi2S_nsigma.setVal(tree.Y2S_nsigma) psi3S_nsigma.setVal(tree.Y3S_nsigma) probFit1S.setVal(tree.probFit1S) probFit2S.setVal(tree.probFit2S) probFit3S.setVal(tree.probFit3S) ctpv.setVal(tree.ctpv) ctpv_error.setVal(tree.ctpv_error) pi0_abs_mass.setVal(tree.pi0_abs_mass) rho_conv.setVal(tree.conv_vertex) dz.setVal(tree.dz) if selectchi1: if (tree.chic_pdgId == 20443): dataSet.add(dataArgSet) else: dataSet.add(dataArgSet) outfile = TFile(outfile_name, 'recreate') dataSet.Write()
elif len(lin_list) == 6: if lin_list[0] == "1": v1_gen.SetXYZ(float(lin_list[3]), float(lin_list[4]), float(lin_list[5])) elif lin_list[0] == "2": v2_gen.SetXYZ(float(lin_list[3]), float(lin_list[4]), float(lin_list[5])) elif lin_list[0] == "3": v3_found = 1 v3_gen.SetXYZ(float(lin_list[3]), float(lin_list[4]), float(lin_list[5])) lin = fil.readline() lin_list = lin.split(None) p4g.SetVectM(p3g, 0.0) p4targ.SetXYZT(0, 0, 0, m_proton) p4L.SetVectM(p3L, m_lam) p4k.SetVectM(p3k, m_kplus) p4p.SetVectM(p3p, m_proton) p4mu.SetVectM(p3mu, m_muon) p4nu = p4g + p4targ - p4k - p4p - p4mu p3nu = p4nu.Vect() p4tot_i = p4g + p4targ p4tot_f = p4k + p4p + p4mu + p4nu if v3_found == 0: v3_gen = v2_gen outfeats.append(p3g.Mag())