Skip to content

Commit

Permalink
Merge pull request #62 from project8/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pslocum authored Mar 26, 2019
2 parents 49fa27d + 3eff19f commit a7c784b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_minimum_required( VERSION 3.1 )

# Define the project
cmake_policy( SET CMP0048 NEW ) # version in project()
project( locust_mc VERSION 1.10.2)
project( locust_mc VERSION 1.10.3)

list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake )
include( PackageBuilder )
Expand All @@ -20,6 +20,7 @@ option( locust_mc_BUILD_WITH_KASSIOPEIA "Option to build with Kassiopeia" FALSE
option( locust_mc_BUILD_WITH_ROOT "Option to build with ROOT" TRUE )

if (locust_mc_BUILD_WITH_KASSIOPEIA)

# Keep KasperDefaults from overriding the install prefix
set( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE )

Expand All @@ -32,6 +33,7 @@ if (locust_mc_BUILD_WITH_KASSIOPEIA)
set( KEMField_DIR ${PROJECT_BINARY_DIR}/kassiopeia/KEMField )

set( CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
set( DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/data )

endif (locust_mc_BUILD_WITH_KASSIOPEIA)

Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM project8/p8compute_dependencies:v0.4.0 as locust_common
ARG build_type=Release
ENV LOCUST_BUILD_TYPE=$build_type

ENV LOCUST_TAG=v1.10.2
ENV LOCUST_TAG=v1.10.3
ENV LOCUST_BUILD_PREFIX=/usr/local/p8/locust/$LOCUST_TAG

RUN mkdir -p $LOCUST_BUILD_PREFIX &&\
Expand Down Expand Up @@ -34,13 +34,16 @@ RUN source $LOCUST_BUILD_PREFIX/setup.sh &&\
cd build &&\
cmake -D CMAKE_BUILD_TYPE=$LOCUST_BUILD_TYPE \
-D CMAKE_INSTALL_PREFIX:PATH=$LOCUST_BUILD_PREFIX \
-D DATA_INSTALL_DIR=$LOCUST_BUILD_PREFIX/data \
-D locust_mc_BUILD_WITH_KASSIOPEIA=TRUE .. &&\
cmake -D CMAKE_BUILD_TYPE=$LOCUST_BUILD_TYPE \
-D CMAKE_INSTALL_PREFIX:PATH=$LOCUST_BUILD_PREFIX \
-D DATA_INSTALL_DIR=$LOCUST_BUILD_PREFIX/data \
-D locust_mc_BUILD_WITH_KASSIOPEIA=TRUE .. &&\
make -j3 install &&\
/bin/true


########################
FROM locust_common

Expand Down
41 changes: 35 additions & 6 deletions Source/Generators/LMCGaussianNoiseGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "LMCGaussianNoiseGenerator.hh"

#include "logger.hh"
#include <random>


using std::string;
Expand All @@ -23,7 +24,7 @@ namespace locust
fDoGenerateFunc( &GaussianNoiseGenerator::DoGenerateFreq ),
fMean( 0. ),
fSigma( 1. ),
fUniDist( 0., 360. ),
fRandomSeed(0),
fNormDist( fMean, fSigma )
{
fRequiredSignalState = Signal::kFreq;
Expand Down Expand Up @@ -51,6 +52,12 @@ namespace locust

// SetMeanAndSigma( aParam->get_value< double >( "mean", fMean ), tSigma );

if (aParam->has( "random-seed") )
{
SetRandomSeed( aParam->get_value< int >( "random-seed",fRandomSeed) );
}


if( aParam->has( "domain" ) )
{
string domain = aParam->get_value( "domain" );
Expand Down Expand Up @@ -104,11 +111,21 @@ namespace locust
void GaussianNoiseGenerator::SetMeanAndSigma( double aMean, double aSigma, double aSampledSigma )
{
fNormDist = std::normal_distribution< double >( aMean, aSampledSigma );
fUniDist = std::uniform_real_distribution< double >(0.,360.);
//fUniDist = std::uniform_real_distribution< double >(0.,360.);
fMean = aMean;
fSigma = aSigma;
return;
}
int GaussianNoiseGenerator::GetRandomSeed() const
{
return fRandomSeed;
}

void GaussianNoiseGenerator::SetRandomSeed( int aRandomSeed )
{
fRandomSeed = aRandomSeed;
return;
}

Signal::State GaussianNoiseGenerator::GetDomain() const
{
Expand Down Expand Up @@ -142,22 +159,34 @@ namespace locust

bool GaussianNoiseGenerator::DoGenerateTime( Signal* aSignal )
{
int random_seed_val;

if ( fRandomSeed != 0 )
{
random_seed_val = fRandomSeed;
}
else
{
std::random_device rd;
random_seed_val = rd();
}
std::default_random_engine generator(random_seed_val);

SetMeanAndSigma( fMean, fSigma, fSigma * sqrt(fAcquisitionRate * 1.e6) );

double gain=1.;
const unsigned nchannels = fNChannels;
double phi = 0.; // voltage phase
//double phi = 0.; // voltage phase
double mag_r = 0.; // voltage mag
double mag_i = 0.;

for (int ch=0; ch<nchannels; ch++)
{
for( unsigned index = 0; index < aSignal->TimeSize(); ++index )
{
phi = fUniDist( fRNG );
mag_r = fNormDist( fRNG ) * sqrt(0.5);
mag_i = fNormDist( fRNG ) * sqrt(0.5);
//phi = fUniDist( fRNG );
mag_r = fNormDist( generator ) * sqrt(0.5);
mag_i = fNormDist( generator ) * sqrt(0.5);
aSignal->SignalTimeComplex()[ch*aSignal->TimeSize() + index][0] += gain*sqrt(50.)* mag_r;
aSignal->SignalTimeComplex()[ch*aSignal->TimeSize() + index][1] += gain*sqrt(50.)* mag_i;
// printf("noise signal is %g\n", aSignal->SignalTimeComplex()[ch*aSignal->TimeSize() + index][1]); getchar();
Expand Down
7 changes: 6 additions & 1 deletion Source/Generators/LMCGaussianNoiseGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ namespace locust

void SetMeanAndSigma( double aMean, double aSigma, double aSampledSigma);

int GetRandomSeed() const;
void SetRandomSeed( int aRandomSeed );


Signal::State GetDomain() const;
void SetDomain( Signal::State aDomain );

Expand All @@ -72,9 +76,10 @@ namespace locust

double fMean;
double fSigma;
int fRandomSeed;

mutable std::normal_distribution< double > fNormDist;
mutable std::uniform_real_distribution<double> fUniDist;
//mutable std::uniform_real_distribution<double> fUniDist;


};
Expand Down

0 comments on commit a7c784b

Please sign in to comment.