Esempio n. 1
0
class EventGenerator:
    EVENT_TIME_DURATION = 50.e3  # ns, 50 us per event

    def __init__(self, filename, exclude_noise, save_plot, max_spill_count):
        self.filename = filename
        self.exclude_noise = exclude_noise
        self.save_plot = save_plot
        self.data_dir = os.path.dirname(self.filename)
        if not self.data_dir:
            self.data_dir = '.'
        self.file_basename = os.path.basename(self.filename)
        self.max_spill_count = max_spill_count

        self.pdg = TDatabasePDG()
        self.delta_x = 1.4  # mm
        self.delta_y = 8.6  # mm
        self.delta_z = 0.  # mm
        # self.delta_x = 1375.9  # mm
        # self.delta_y = -67.5  # mm
        # self.delta_z = -14617.4  # mm
        self.angle_rotation_y_axis = -0.349 * pi / 180.  # rad

    def rotate_y_axis(self, z, x):
        # angle > 0 if the coordinate system rotates counterclockwise
        # angle < 0 if the coordinate system rotates clockwise
        z_prime = cos(self.angle_rotation_y_axis) * z + sin(
            self.angle_rotation_y_axis) * x
        x_prime = -sin(self.angle_rotation_y_axis) * z + cos(
            self.angle_rotation_y_axis) * x
        return z_prime, x_prime

    def translate(self, x, y, z):
        return x + self.delta_x, y + self.delta_y, z + self.delta_z

    def run(self):
        particles = []
        particle_count = 0
        spill_count = 0

        f_beam = TFile(self.filename)
        spills = [key.GetName() for key in gDirectory.GetListOfKeys()]
        for spill in spills:
            spill_count += 1
            if self.max_spill_count and spill_count > self.max_spill_count:
                spill_count -= 1
                break
            print('spill = {}'.format(spill))

            for track in f_beam.Get(spill):
                particle_count += 1
                pass_all = track.TrackPresenttof_us and \
                    track.TrackPresentwire_chamber_1_detector and \
                    track.TrackPresentwire_chamber_2_detector and \
                    track.TrackPresentwire_chamber_3_detector and \
                    track.TrackPresentwire_chamber_4_detector and \
                    track.TrackPresentcherenkov and \
                    track.TrackPresenttof_ds and \
                    track.TrackPresentnova

                is_noise = not pass_all
                if self.exclude_noise and is_noise is True:
                    continue

                pdg_id = int(track.PDGidnova)
                x, y, z = self.translate(track.xnova, track.ynova,
                                         track.znova)  # mm
                # z, x = self.rotate_y_axis(z, x)
                t = track.tnova  # s

                px = track.Pxnova  # MeV
                py = track.Pynova  # MeV
                pz = track.Pznova  # MeV
                # pz, px = self.rotate_y_axis(pz, px)

                px /= 1000.  # GeV
                py /= 1000.  # GeV
                pz /= 1000.  # GeV
                x /= 10.  # cm
                y /= 10.  # cm
                z /= 10.  # cm
                t *= 1.e9  # ns

                mass = self.pdg.GetParticle(pdg_id).Mass()
                energy = (mass**2 + px**2 + py**2 + pz**2)**0.5
                particle = [
                    is_noise, 1, pdg_id, 0, 0, 0, 0, px, py, pz, energy, mass,
                    x, y, z, t
                ]

                particles.append(particle)
                particle_count += 1
                if particle_count % 1e6 == 0:
                    print('particle_count = {}'.format(particle_count))

        print('spill_count = {}'.format(spill_count))
        f_beam.Close()

        particles = sorted(particles, key=lambda p: p[-1])
        events = []
        event_end_time = 0.
        event_start_time = 0.
        event_particles = []
        for particle in particles:
            is_noise = particle[0]
            time = particle[-1]  # time
            if time > event_end_time:
                if event_particles:
                    events.append(event_particles)
                    event_particles = []
                if not is_noise:
                    particle[-1] = 0.
                    event_particles = [particle]
                    event_start_time = time
                    event_end_time = time + EventGenerator.EVENT_TIME_DURATION  # ns
            else:
                particle[-1] -= event_start_time
                event_particles.append(particle)
        if event_particles:
            events.append(event_particles)

        txt_filename = 'text_gen.{}{}.txt'.format(
            self.file_basename, '.exclude_noise' if self.exclude_noise else '')
        with open('{}/{}'.format(self.data_dir, txt_filename), 'w') as f_txt:
            for event in events:
                f_txt.write('0 {}\n'.format(len(event)))
                for particle in event:
                    f_txt.write(' '.join(map(str, particle[1:])) + '\n')

        if self.save_plot:
            self.make_plot(events)

    def make_plot(self, events):
        f_det = TFile(
            '{}/text_gen.{}{}.root'.format(
                self.data_dir, self.file_basename,
                '.exclude_noise' if self.exclude_noise else ''), 'RECREATE')
        multiple_particle_event_count = 0
        h_count = TH1D('h_count', 'h_count', 100, -0.5, 99.5)
        h_timing = TH1D('h_timing', 'h_timing', 5000, 0., 50.e3)  # ns
        h_xy = TH2D('h_xy', 'h_xy', 600, -150, 150, 600, -150, 150)  # cm
        h_z = TH1D('h_z', 'h_z', 500, -1, 1)  # cm
        for i, event in enumerate(events):
            h_count.Fill(len(event))
            if len(event) > 1:
                multiple_particle_event_count += 1

            for particle in event:
                h_timing.Fill(particle[-1])
                is_noise = particle[0]
                if is_noise:
                    continue
                x = particle[-4]
                y = particle[-3]
                z = particle[-2]
                h_xy.Fill(x, y)
                h_z.Fill(z)

        print('len(events) = {}'.format(len(events)))
        print('multiple_particle_event_count = {}'.format(
            multiple_particle_event_count))
        h_count.Write('h_particle_count_per_event')
        h_timing.Write('h_timing')
        h_xy.Write('h_xy')
        h_z.Write('h_z')
        f_det.Close()
Esempio n. 2
0
"""
# all the not useful fields will be filled with 99

from ROOT import TGenPhaseSpace, TLorentzVector, TDatabasePDG, TMath, TVector3

import math
from random import random as rndm
from array import array
from random import gauss

dbpdg = TDatabasePDG()

# chose motherParticle
PDGmother = 3122
MotherMass = dbpdg.GetParticle(PDGmother).Mass()

# chose daughters
PDGs = [2212, -211]
DaughterMass = [dbpdg.GetParticle(i).Mass() for i in PDGs]

# Settings
# ========

NEVENTS = 50000
BeamPolarization = -1  # not useful

# generate flat in ranges of P, theta, phi
PMin = 0.5
PMax = 2.0
Esempio n. 3
0
# result_0.1Bn_ecut_0.5.root         	1E8 with Ecut > 0.5 GeV
Yandex = False  # False
Yandex2 = False  # summer 2015 production, 10B, Ecut>10GeV, Mo/W/ target
Yandex3 = True  # spring 2016 production, 10B, Ecut>10GeV, Mo/W/ target, record start of track
afterHadronAbsorber = False
JPsi = False  # True
MoTarget = False
Tau = False

import ROOT, os
from array import array
from ROOT import TDatabasePDG, TMath, gDirectory
from rootUtils import *

pdg = TDatabasePDG()
mu = pdg.GetParticle(13)
Mmu = mu.Mass()
Mmu2 = Mmu * Mmu

if Yandex:
    stats = {5.: [1E9, 1E9], 0.5: [1E8]}
    files = {
        5.: [
            '$SHIPSOFT/data/result_1Bn_ecut_5.root',
            '$SHIPSOFT/data/result_1Bn_ecut_5-v02.root'
        ],
        0.5: ['$SHIPSOFT/data/result_0.1Bn_ecut_0.5.root']
    }
    fnew = 'pythia8_Geant4_total_Yandex.root'
if Yandex2:
    stats = {10.: [1E10]}
Esempio n. 4
0
import enum
from ROOT import TDatabasePDG

db = TDatabasePDG()
db.GetParticle(0)  # initialize list
all_particles = list(db.ParticleList())
data = {p.GetName(): p.PdgCode() for p in all_particles}
ParticleID = enum.IntEnum('ParticleID', data)


def main():
    for pid in ParticleID:
        print(
            f"{pid.__class__.__name__}({pid.value}) == {pid.__class__.__name__}['{pid.name}']"
        )


if __name__ == "__main__":
    main()
Esempio n. 5
0
h2p = TH2F("phi", "", 180, -180, 180, 180, -180, 180)

i = 0
while i < len(content):

    line = content[i].strip().split()
    if len(line) == 10:
        g0line = content[i + 1].strip().split()
        g1line = content[i + 2].strip().split()
        g2line = content[i + 3].strip().split()

        g0d = [float(a) for a in g0line[6:9]]
        g1d = [float(a) for a in g1line[6:9]]
        g2d = [float(a) for a in g2line[6:9]]

        m0 = pdg.GetParticle(int(g0line[3])).Mass()
        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] )
Esempio n. 6
0
      1=active

"""
# all the not useful fields will be filled with 99

from ROOT import TGenPhaseSpace, TLorentzVector, TVector3, TDatabasePDG, TMath

import math
from random import random as rndm
from array import array

dbpdg = TDatabasePDG()

#  motherParticle
PDGmother = 223
MotherMass = dbpdg.GetParticle(PDGmother).Mass()

#  daughters
PDGs = [211, -211, 111]
DaughterMass = [dbpdg.GetParticle(i).Mass() for i in PDGs]

# decay pi0
gPDGs = [22, 22]
gMasses = [dbpdg.GetParticle(i).Mass() for i in gPDGs]

# Exclusive collision Settings
# ============================

BeamPolarization = -1  # not useful

BeamEnergy = 10.6
Esempio n. 7
0
from ROOT import TGenPhaseSpace, TLorentzVector, TVector3, TDatabasePDG, TMath, TH2F

import math
from random import random as rndm
from array import array

dbpdg = TDatabasePDG()

# Exclusive collision Settings
# ============================

BeamPolarization = -1  # not useful

BeamEnergy = 6.5
TargetMass = dbpdg.GetParticle(2212).Mass()

beam = TLorentzVector(0, 0, BeamEnergy, BeamEnergy)
target = TLorentzVector(0, 0, 0, TargetMass)
CME = beam + target

FSPDGs = [11, 2212]
FSMasses = [dbpdg.GetParticle(i).Mass() for i in FSPDGs]

# electron polar angle cuts
ThetaMin = math.radians(4.0)
ThetaMax = math.radians(40.0)

# proton polar angle cuts
PThetaMin = math.radians(35.0)
PThetaMax = math.radians(120.0)