Skip to content

Commit

Permalink
clock added to pyfile
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Ulrich committed Feb 6, 2025
1 parent 896f918 commit f8a7f95
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions neuland/util/neuland_add_random_hitpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math
import random
from enum import Enum
from scipy.signal import square

import ROOT

Expand All @@ -18,6 +19,8 @@ class Mode(Enum):
UNIFORM = 1
## Generate value according to distribution of a cosine function.
COSINE = 2
## Generate value according to distribution of a clock function.
CLOCK = 3


class ParValueSet:
Expand Down Expand Up @@ -64,6 +67,13 @@ def set(
self.period = period
self.err = err

def set_clock(self, **kwargs):
"""Set all random generator parameter with the clock distribution.
@param kwargs Key-value pairs passed to set() member function
"""
self.set(Mode.CLOCK, **kwargs)

def set_cos(self, **kwargs):
"""Set all random generator parameter with the cosine distribution.
Expand Down Expand Up @@ -166,11 +176,13 @@ def generate_random_value_with_cos(par: ParValueSet, module_id):
value = 0.0
if par.mode == Mode.COSINE:
value = par.offset + par.amp * math.cos(
module_id * 4 * math.pi / par.period
module_id * 2 * math.pi / par.period
)
elif par.mode == Mode.CLOCK:
value = square(2 * np.pi * module_id / par.period) * par.amp + par.offset
else:
value = random.uniform(par.offset - par.amp, par.offset + par.amp)
return round(value + noise, 3)
return round(value + noise, 6)

def set_run_id(self, val: int):
"""Set the run id in the parameter file
Expand Down Expand Up @@ -200,9 +212,7 @@ def __assign_random_values(self, module_id: int):
energy_gain = self.generate_random_value_with_cos(self.energy_gain, module_id)
pedestal = self.generate_random_value_with_cos(self.pedestal, module_id)
pmt_thresh = self.generate_random_value_with_cos(self.pmt_thresh, module_id)
saturation_coefficient = self.generate_random_value_with_cos(
self.saturation_coefficient, module_id
)
saturation_coefficient = energy_gain * (1.75*10**(-3))

# Werte im ROOT-Objekt setzen
one_module_par.effectiveSpeed.value = effective_speed
Expand Down

0 comments on commit f8a7f95

Please sign in to comment.