コード例 #1
0
def count_reactions(files_to_analyze,
                    tstart,
                    only_count_reactions=None,
                    binning_in='Q2'):
    """
    Counts, how many reactions of every possible type (binned by invariant mass)
    happen in files_to_analyze starting from time tstart.

    One may limit the list of considered reactions to only_count_reactions.
    """

    intcounter = 0  # any interactions counter
    event_num = 0  # event counter

    assert ((binning_in == 'Q2') or (binning_in == 't'))

    def right_hist():
        if (binning_in == 'Q2'):
            return Hist(0., 5., 100)
        if (binning_in == 't'):
            return Hist(0., 30., 60)

    reactions = defaultdict(right_hist)

    for file_to_analyze in files_to_analyze:
        # Read input file, add Q^2 of given reactions to list: forward and backward
        bfile = open(file_to_analyze, 'rb')
        with sb.BinaryReader(file_to_analyze) as reader:
            smash_version = reader.smash_version
            #format_version = reader.format_version

            for block in reader:
                if (block['type'] == 'f'):  # end of event
                    event_num += 1
                if (block['type'] == 'i'):  # interaction
                    intcounter += 1
                    #  if (intcounter % 10000 == 0): print "interaction ", intcounter
                    time = sb.get_block_time(block)
                    if (time < tstart): continue
                    block_pdgin = np.sort(block['incoming']['pdgid'])
                    block_pdgout = np.sort(block['outgoing']['pdgid'])
                    # ignore wall crossings
                    if ((block_pdgin.size == 1) and (block_pdgout.size == 1)):
                        continue
                    # computing Mandelstam t requires 2->2 reaction
                    if ((binning_in == 't')
                            and (not ((block_pdgin.size == 2) and
                                      (block_pdgout.size == 2)))):
                        continue
                    reaction = (tuple(block_pdgin), tuple(block_pdgout))
                    if (only_count_reactions
                            and (not reaction in only_count_reactions)):
                        continue
                    if (binning_in == 'Q2'):
                        bin_variable = np.sqrt(sb.reaction_Q2(block))
                    if (binning_in == 't'):
                        bin_variable = np.abs(sb.reaction_mandelstam_t(block))
                    reactions[reaction].fill(bin_variable)
    return (reactions, event_num, smash_version)
コード例 #2
0
    def process_all(self):
        """Process all input files and output counts."""
        if self.done:
            raise RuntimeError(
                '`Process.process_all` should be called only once')
        firstfile = True
        reading_allowed = True
        # go through the list of input arguments
        for name in self.args.filename:
            # if the argument is a file, read the contents
            if os.path.isfile(name):
                with smash.BinaryReader(name) as reader:
                    # check the header for version information
                    self.smashversion = reader.smash_version
                    self.formatversion = reader.format_version
                    if firstfile:
                        smash_previous = self.smashversion
                        format_previous = self.formatversion
                        firstfile = False
                    elif (self.smashversion != smash_previous
                          or self.formatversion != format_previous):
                        if self.args.verbose:
                            print >> sout, "# Data from different versions detected!"
                            print >> sout, "# Above version from file", name
                    # loop over all data blocks in the file
                    self.process_datablocks(reader)
                self.print_unobservable_resonances()
        process_elast = "+".join(self.initial_parts)
        process_elast_gen = "+".join(
            pdgs_to_names(self.initial_pdgs, self.unify_name))

        # set up output streams
        out1 = open(self.args.output1,
                    'w') if self.args.output1 else sys.stdout
        out2 = open(self.args.output2,
                    'w') if self.args.output2 else sys.stdout
        out3 = open(self.args.output3,
                    'w') if self.args.output3 else sys.stdout
        out4 = open(self.args.output4,
                    'w') if self.args.output4 else sys.stdout
        out5 = open(self.args.output5,
                    'w') if self.args.output5 else sys.stdout
        out6 = open(self.args.output6,
                    'w') if self.args.output4 else sys.stdout
        out7 = open(self.args.output7,
                    'w') if self.args.output5 else sys.stdout

        self.print_to_file(out1, 'individual', 'elastic')
        self.print_to_file(out2, 'grouped', 'elastic')
        self.print_to_file(out3, 'final_individual', 'elastic')
        self.print_to_file(out4, 'final_grouped', 'elastic')
        self.print_to_file(out5, 'final_individual_res', 'elastic')
        self.print_to_file(out6, 'final_grouped_res', 'elastic')
        self.print_to_file(out7, 'process_type')

        self.done = True
コード例 #3
0
 def add_from_file(self, one_file):
     """ Computes bulk observables from a single SMASH output file """
     print one_file
     with sb.BinaryReader(one_file) as reader:
         self.smash_version = reader.smash_version
         block = reader.read_block()
         while block is not None:
             t = block['type']
             assert (t == 'p' or t == 'f')
             if (t == 'p'):
                 # Do not count elastic pp collisions
                 pp_elastic = block['npart'] == 2 and \
                              (block['part']['pdgid'] == 2212).all()
                 if (not pp_elastic):
                     self.add_block(block)
             block = reader.read_block()
コード例 #4
0
def count_elastic_scat(file_to_analyze, t_start):
    with sb.BinaryReader(file_to_analyze) as reader:
        smash_version = reader.smash_version
        format_version = reader.format_version
        elastic = 0
        for block in reader:
            if (block['type'] == 'f'):  # end of event
                event_num = block['nevent'] + 1
                # print "finished analyzing event ", event_num
            if (block['type'] == 'i'
                    and sb.is_elastic22(block)):  # 2->2 el. scatt.
                time = sb.get_block_time(block)
                if (time > t_start): elastic += 1
    return {
        'smash_ver': smash_version,
        'ev_num': event_num,
        'elast_coll': elastic
    }
コード例 #5
0
def get_multiplicity(file_to_analyze):
    """
        Compute number of particles against time in the file file_to_analyze
        for every particle in a pdg_list.
    """
    time = np.zeros(max_tcounter)
    mul = np.zeros((max_tcounter, total_pdgs))
    mul_sqr = np.zeros((max_tcounter, total_pdgs))
    event_num = 0
    tcounter = 0
    with sb.BinaryReader(file_to_analyze) as reader:
        smash_version = reader.smash_version
        #format_version = reader.format_version
        for block in reader:
            if (block['type'] == 'f'):  # end of event
                event_num += 1
                blocks_per_event = tcounter
                tcounter = 0
            if (block['type'] == 'i'):  # interaction
                print 'Error: there should be no interactions in this file!'
                sys.exit(1)
            if (block['type'] == 'p'):  # particles
                if (event_num == 0):
                    time[tcounter] = sb.get_block_time(block)
                for i in np.arange(total_pdgs):
                    part_num = sb.count_pdg_in_block(block, pdg_list[i])
                    mul[tcounter, i] += part_num
                    mul_sqr[tcounter, i] += part_num * part_num
                tcounter += 1
    return {
        'smash_version': smash_version,
        'nevents': event_num,
        'blocks_per_event': blocks_per_event,
        'time': time,
        'mul': mul,
        'mul_sqr': mul_sqr
    }
コード例 #6
0
hist_pt_omega = np.zeros((nbins_pt + 2, max(omega_channels.values()) + 1))

hist_y = np.zeros((nbins_y + 2, n_channels))
hist_y_0_150 = np.zeros((nbins_y + 2, n_channels))
hist_y_150_470 = np.zeros((nbins_y + 2, n_channels))
hist_y_470_700 = np.zeros((nbins_y + 2, n_channels))
hist_y_700 = np.zeros((nbins_y + 2, n_channels))
hist_y_rho = np.zeros((nbins_y + 2, max(rho_channels.values()) + 1))
hist_y_omega = np.zeros((nbins_y + 2, max(omega_channels.values()) + 1))

### ACTUAL ANALYSIS ###
unknown_ch = []
unknown_rho_ch = []
unknown_omega_ch = []

with sbs.BinaryReader(args.data_file) as reader:

    # save smash version number to extra data file
    smash_version = reader.smash_version
    with open("other.version.dat", "w") as out:
        out.write("smash_version: ")
        out.write(smash_version + "\n")

    for block in reader:

        if block["type"] == 'f':
            num_events = block["nevent"]
        if block["type"] == 'p':
            sys.exit(
                "Error: Found particle block in dilepton binary collision output."
            )
コード例 #7
0
import sys
import numpy as np
import smash_basic_scripts as sb

arg = sys.argv
file_to_analyze = arg[1]
output_file = arg[2]
pdg_string = arg[3]
tstart = float(arg[4])

pdg_list = map(int, pdg_string.split(','))
N_pdgs = len(pdg_list)

with sb.BinaryReader(file_to_analyze) as reader:
    smash_version = reader.smash_version
    format_version = reader.format_version

    # Set histgram binnings
    Ebins = np.linspace(0.0, 5., 101)

    # Prepare empty lists of histograms
    Ehist = []
    for i in xrange(N_pdgs):
        h, bins = np.histogram([], bins=Ebins)
        Ehist.append(h)

    # Read file and fill histograms
    for block in reader:
        if (block['type'] == 'p'):
            time = sb.get_block_time(block)
            if (time > tstart):
コード例 #8
0
ファイル: yields.py プロジェクト: vks/smash-analysis
ntestparticles = d['General']['Testparticles']

for edir in sorted(os.listdir(".")):    # loop over energies
    if path.isdir(edir) and (edir != "CMakeFiles"):
        datadir = path.join(path.abspath(edir), "data")
        count_with_error = defaultdict(Average)  # total count of processes with the initial pdgs
        pt_total = defaultdict(Average)  # average transverse momentum
        nevent = 0
        for rdir in os.listdir(path.abspath(datadir)):  # loop over runs
            rdir = path.join(path.abspath(datadir), rdir)
            if path.isdir(rdir):
                #print rdir
                name = path.join(rdir, "particles_binary.bin")
                # if the argument is a file, read the contents
                if (path.isfile(name)):
                    with smash.BinaryReader(name) as reader:
                        # check the header for version information
                        smashversion = reader.smash_version
                        formatversion = reader.format_version
                        if firstfile:
                            print "#version", smashversion, "format", formatversion, "analysis", smash.analysis_version_string()
                            firstfile = False
                        # loop over all data blocks in the file
                        for datablock in reader:
                            if datablock['type'] == 'p':
                                nevent += 1
                                # count particles and calculate transverse momentum
                                pt_event = defaultdict(Average)
                                count = defaultdict(int)
                                for particle in datablock['part']:
                                    i = particle['pdgid']