mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-26 12:18:51 -05:00
Compare commits
No commits in common. "7fca02119e0771ceac684144b7dee4e70deb8ebd" and "10462c1eab50a293a46dca64c6ddefddfef9d1f7" have entirely different histories.
7fca02119e
...
10462c1eab
|
@ -84,20 +84,16 @@ namespace Specter {
|
|||
{
|
||||
sabreFlag = true;
|
||||
if (hit.longEnergy > iter->second.GetValue())
|
||||
iter->second.SetValue(hit.longEnergy + RandomGenerator::GetUniformFraction());
|
||||
iter->second.SetValue(hit.longEnergy);
|
||||
continue;
|
||||
}
|
||||
|
||||
//Note randomization of values. In general, we want to plot/calculate as floating point.
|
||||
//Especially for histograms, care has to be taken to randomize the decimal to account for binning.
|
||||
//For timestamps from PSD, since we reduce accuracy by 3 orders of mag, no randomization needed.
|
||||
//For timestamps from PHA, need randomization on interval from 0 to digitizer sampling period.
|
||||
switch (hit.id)
|
||||
{
|
||||
case s_scintLeftID:
|
||||
{
|
||||
if (hit.longEnergy > scintLeft.GetValue())
|
||||
scintLeft.SetValue(hit.longEnergy + RandomGenerator::GetUniformFraction());
|
||||
scintLeft.SetValue(hit.longEnergy);
|
||||
break;
|
||||
}
|
||||
case s_beamIntID:
|
||||
|
@ -108,7 +104,7 @@ namespace Specter {
|
|||
case s_cathodeID:
|
||||
{
|
||||
if (hit.longEnergy > cathode.GetValue())
|
||||
cathode.SetValue(hit.longEnergy + RandomGenerator::GetUniformFraction());
|
||||
cathode.SetValue(hit.longEnergy);
|
||||
break;
|
||||
}
|
||||
case s_delayFrontLeftID:
|
||||
|
@ -138,13 +134,13 @@ namespace Specter {
|
|||
case s_anodeFrontID:
|
||||
{
|
||||
if (hit.longEnergy > anodeFront.GetValue())
|
||||
anodeFront.SetValue(hit.longEnergy + RandomGenerator::GetUniformFraction());
|
||||
anodeFront.SetValue(hit.longEnergy);
|
||||
break;
|
||||
}
|
||||
case s_anodeBackID:
|
||||
{
|
||||
if (hit.longEnergy > anodeBack.GetValue())
|
||||
anodeBack.SetValue(hit.longEnergy + RandomGenerator::GetUniformFraction());
|
||||
anodeBack.SetValue(hit.longEnergy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +148,6 @@ namespace Specter {
|
|||
|
||||
//If you want to use parameters to calculate another parameter, you
|
||||
//need to check that the parameter is valid (set in this event)!
|
||||
//Note subsequent calculations no longer need randomization.
|
||||
if(delayFLTime.IsValid() && delayFRTime.IsValid())
|
||||
x1.SetValue((delayFLTime.GetValue() - delayFRTime.GetValue())*0.5*0.4762);
|
||||
|
||||
|
|
|
@ -105,7 +105,6 @@ target_sources(Specter PRIVATE
|
|||
Specter/Physics/Daqromancy/DYOnlineSource.cpp
|
||||
Specter/Utils/Functions.h
|
||||
Specter/Utils/Functions.cpp
|
||||
Specter/Utils/RandomGenerator.h
|
||||
)
|
||||
|
||||
#ImPlot sources
|
||||
|
|
|
@ -35,6 +35,5 @@
|
|||
#include "Specter/Utils/TestServerLayer.h"
|
||||
#include "Specter/Utils/Instrumentor.h"
|
||||
#include "Specter/Utils/Functions.h"
|
||||
#include "Specter/Utils/RandomGenerator.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
RandomGenerator.h
|
||||
Thread-safe implementation of stl random number generator library. A single Mersenne-Twister generator is created for
|
||||
each thread. The paramters for the distributions are passed in to the function call, and a random number is calculated
|
||||
for the requested distribution. Note that distributions are templated so that one can specify the type of distributions,
|
||||
but most distributions only support a limited range of types. The valid types are commented for each case.
|
||||
|
||||
Oct 2022 -- GWM
|
||||
*/
|
||||
|
||||
#ifndef RANDOM_GENERATOR_H
|
||||
#define RANDOM_GENERATOR_H
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace Specter {
|
||||
|
||||
class RandomGenerator
|
||||
{
|
||||
public:
|
||||
|
||||
//Valid for float, double, long double
|
||||
template<typename T>
|
||||
static T GetUniformReal(T min, T max)
|
||||
{
|
||||
std::uniform_real_distribution<T> distribution(min, max);
|
||||
return distribution(GetGenerator());
|
||||
}
|
||||
|
||||
//Valid for any integer type (signed or unsigned)
|
||||
template<typename T>
|
||||
static T GetUniformInt(T min, T max)
|
||||
{
|
||||
std::uniform_int_distribution<T> distribution(min, max);
|
||||
return distribution(GetGenerator());
|
||||
}
|
||||
|
||||
//Valid for float, double, long double
|
||||
template<typename T>
|
||||
static T GetNormal(T mean, T sigma)
|
||||
{
|
||||
std::normal_distribution<T> distribution(mean, sigma);
|
||||
return distribution(GetGenerator());
|
||||
}
|
||||
|
||||
//This is the most common use case, so we eliminate recreation of distribution, templating.
|
||||
//For randomization of decimals in conversion from integer -> floating point for histograming
|
||||
static double GetUniformFraction()
|
||||
{
|
||||
static std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
||||
return distribution(GetGenerator());
|
||||
}
|
||||
|
||||
private:
|
||||
static std::mt19937& GetGenerator()
|
||||
{
|
||||
static thread_local std::mt19937 generator((std::random_device())());
|
||||
return generator;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user