Skip to content

Commit

Permalink
Merge pull request #52 from project8/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pslocum authored Feb 15, 2019
2 parents 61301c9 + 3e1afda commit 74350e1
Show file tree
Hide file tree
Showing 16 changed files with 690 additions and 24 deletions.
2 changes: 1 addition & 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.9.6)
project( locust_mc VERSION 1.9.7)

list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/Scarab/cmake )
include( PackageBuilder )
Expand Down
65 changes: 65 additions & 0 deletions Config/Tutorial/LocustPlaneWaveTemplate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"generators":
[
"planewave-signal",
"lpf-fft",
"decimate-signal",
"digitizer"
],

"planewave-signal":
{
"lo-frequency": 25.8781e9,
"planewave-frequency": 25.9281e9,
"array-radius": 0.05,
"npatches-per-strip": 22,
"patch-spacing": 0.0068,
"feed": "quadrature",
"phase-delay": 0
},

"kass-signal":
{
"lo-frequency": 25.3106e9,
"pitchangle-filename": "/home/hep/baker/ps48/locust_mc/cbuild/bin/pitchangles.txt",
"xml-filename": "/home/hep/baker/ps48/locust_mc/Config/Tutorial/Project8Phase1_WithRoot_Template.xml"
},

"patch-signal":
{
"lo-frequency": 25.8781e9,
"array-radius": 0.05,
"npatches-per-strip": 21,
"patch-spacing": 0.0054,
"feed": "corporate",
"xml-filename": "/home/hep/baker/ps48/locust_mc/Config/Tutorial/Project8Phase3_WithRoot_Template.xml"
},

"freefield-signal":
{
"lo-frequency": 25.2814e9,
"xml-filename": "/home/penny/locust_mc/Config/Tutorial/Project8Phase3_WithRoot_Template.xml"
},

"simulation":
{
"egg-filename": "/home/penny/locust_mc/cbuild/bin/locust_mc.egg",
"n-records": 1,
"record-size": 81920,
"n-channels": 1
},

"gaussian-noise":
{
"noise-floor": 4.2e-22,
"domain": "time"
},

"digitizer":
{
"v-range": 3.0e-6,
"v-offset": -1.5e-6
}

}

2 changes: 1 addition & 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.9.6
ENV LOCUST_TAG=v1.9.7
ENV LOCUST_BUILD_PREFIX=/usr/local/p8/locust/$LOCUST_TAG

RUN mkdir -p $LOCUST_BUILD_PREFIX &&\
Expand Down
5 changes: 4 additions & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set( LOCUST_MC_HEADER_FILES
Generators/LMCTestSignalGenerator.hh
Generators/LMCDecimateSignalGenerator.hh
Generators/LMCLowPassFilterFFTGenerator.hh
Generators/LMCHighPassFilterFFTGenerator.hh
Generators/LMCLocalOscillatorGenerator.hh
Generators/LMCButterworthLPFGenerator.hh

Expand All @@ -66,9 +67,9 @@ set( LOCUST_MC_SOURCE_FILES
Generators/LMCDigitizer.cc
Generators/LMCGaussianNoiseGenerator.cc
Generators/LMCFakeTrackSignalGenerator.cc
Generators/LMCTestSignalGenerator.cc
Generators/LMCDecimateSignalGenerator.cc
Generators/LMCLowPassFilterFFTGenerator.cc
Generators/LMCHighPassFilterFFTGenerator.cc
Generators/LMCLocalOscillatorGenerator.cc
Generators/LMCButterworthLPFGenerator.cc

Expand All @@ -91,6 +92,7 @@ if (locust_mc_BUILD_WITH_KASSIOPEIA)
Generators/LMCFreeFieldSignalGenerator.hh
Generators/LMCPatchSignalGenerator.hh
Generators/LMCKassSignalGenerator.hh
Generators/LMCPlaneWaveSignalGenerator.hh

Core/LMCChannel.hh
Core/LMCGlobalsDeclaration.hh
Expand All @@ -115,6 +117,7 @@ if (locust_mc_BUILD_WITH_KASSIOPEIA)
Generators/LMCFreeFieldSignalGenerator.cc
Generators/LMCPatchSignalGenerator.cc
Generators/LMCKassSignalGenerator.cc
Generators/LMCPlaneWaveSignalGenerator.cc

Core/LMCChannel.cc
Core/LMCHFSSReader.cc
Expand Down
26 changes: 21 additions & 5 deletions Source/Core/LMCPowerCombiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "LMCPowerCombiner.hh"
#include <iostream>


namespace locust
Expand All @@ -25,18 +26,33 @@ namespace locust
double PowerCombiner::GetVoltageDamping(int njunctions)
{
// test: clobber voltage with 0.6 at each junction.
return njunctions*0.6;
return pow(1.0, njunctions);
}

double PowerCombiner::GetLinePhaseCorr(unsigned z_index, double DopplerFrequency)
{
double D = 0.007711*0.95; // m. 18.0 keV 90 degree electron, lambda in kapton.
double c_n = LMCConst::C()/1.5; // speed of light in Kapton.
double lambda = c_n/(DopplerFrequency/(2.*LMCConst::Pi()));
double dphi = 2.*LMCConst::Pi() * D * z_index / lambda;
int njunctions = z_index; // series feed
double D = 0.0068; // m. 18.6 keV 90 degree electron, lambda in kapton.
double c_n = LMCConst::C()/1.704; // speed of light in Kapton.
double lambda = c_n/(DopplerFrequency/(2.*LMCConst::Pi())); // any pitch angle
double dphi = 2.*LMCConst::Pi() * D * njunctions / lambda;
return dphi;
}

double PowerCombiner::GetCenterFedLinePhaseCorr(int NPatchesPerStrip, unsigned z_index, double DopplerFrequency, double PatchSpacing)
{
int njunctions = fabs((double)z_index - (double)NPatchesPerStrip/2.);
if (z_index >= NPatchesPerStrip/2) njunctions += 1;

double D = PatchSpacing; // m. 18.0 keV 90 degree electron, lambda in kapton.
double c_n = LMCConst::C()/1.704; // speed of light in Kapton.
double lambda = c_n/DopplerFrequency;
double dphi = 2.*LMCConst::Pi() * D * njunctions / lambda;
// printf("2PI*D/lambda is %g\n", 2.*LMCConst::Pi()*D/lambda); getchar();
return dphi;
}





Expand Down
2 changes: 1 addition & 1 deletion Source/Core/LMCPowerCombiner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace locust
virtual ~PowerCombiner();

double GetLinePhaseCorr(unsigned z_index, double DopplerFrequency);

double GetCenterFedLinePhaseCorr(int NPatchesPerStrip, unsigned z_index, double DopplerFrequency, double PatchSpacing);
double GetVoltageDamping(int njunctions);


Expand Down
14 changes: 14 additions & 0 deletions Source/Core/LMCRunLengthCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ namespace locust
return;
}

void RunLengthCalculator::Visit( const HighPassFilterFFTGenerator* )
{
// nothing to see here, move along, please
return;
}



void RunLengthCalculator::Visit( const PlaneWaveSignalGenerator* )
{
// nothing to see here, move along, please
return;
}

void RunLengthCalculator::Visit( const TestSignalGenerator* )
{
// nothing to see here, move along, please
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/LMCRunLengthCalculator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ namespace locust
void Visit( const TrappedElectronGenerator* );
void Visit( const GaussianNoiseGenerator* );
void Visit( const FakeTrackSignalGenerator* );
void Visit( const PlaneWaveSignalGenerator* );
void Visit( const TestSignalGenerator* );
void Visit( const BasebandTrackGenerator* );
void Visit( const LowPassFilterFFTGenerator* );
void Visit( const HighPassFilterFFTGenerator* );
void Visit( const LocalOscillatorGenerator* );
void Visit( const DecimateSignalGenerator* );
void Visit( const Digitizer* );
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/LMCVisitor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ namespace locust
class Generator;
class GaussianNoiseGenerator;
class FakeTrackSignalGenerator;
class PlaneWaveSignalGenerator;
class TestSignalGenerator;
class BasebandTrackGenerator;
class LowPassFilterFFTGenerator;
class HighPassFilterFFTGenerator;
class Digitizer;
class TrappedElectronGenerator;
class KassSignalGenerator;
Expand All @@ -38,9 +40,11 @@ namespace locust
virtual void Visit( const GaussianNoiseGenerator* ) = 0;
virtual void Visit( const TrappedElectronGenerator* ) = 0;
virtual void Visit( const FakeTrackSignalGenerator* ) = 0;
virtual void Visit( const PlaneWaveSignalGenerator* ) = 0;
virtual void Visit( const TestSignalGenerator* ) = 0;
virtual void Visit( const BasebandTrackGenerator* ) = 0;
virtual void Visit( const LowPassFilterFFTGenerator* ) = 0;
virtual void Visit( const HighPassFilterFFTGenerator* ) = 0;
virtual void Visit( const LocalOscillatorGenerator* ) = 0;
virtual void Visit( const DecimateSignalGenerator* ) = 0;
virtual void Visit( const Digitizer* ) = 0;
Expand Down
134 changes: 134 additions & 0 deletions Source/Generators/LMCHighPassFilterFFTGenerator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* LMCHighPassFilterFFTGenerator.cc
*
* Created on: Feb. 14 2019
* Author: plslocum
*/

#include "LMCHighPassFilterFFTGenerator.hh"

#include "logger.hh"


using std::string;

namespace locust
{
LOGGER( lmclog, "HighPassFilterFFTGenerator" );

MT_REGISTER_GENERATOR(HighPassFilterFFTGenerator, "hpf-fft");

HighPassFilterFFTGenerator::HighPassFilterFFTGenerator( const std::string& aName ) :
Generator( aName ),
fDoGenerateFunc( &HighPassFilterFFTGenerator::DoGenerateTime ),
fThreshold ( 1.0e6 ) // 1 MHz
{
fRequiredSignalState = Signal::kTime;
}

HighPassFilterFFTGenerator::~HighPassFilterFFTGenerator()
{
}

bool HighPassFilterFFTGenerator::Configure( const scarab::param_node* aParam )
{
if( aParam == NULL) return true;

if( aParam->has( "threshold" ) )
{
SetThreshold( aParam->get_value< double >( "threshold", fThreshold ) );
}
return true;
}

double HighPassFilterFFTGenerator::GetThreshold() const
{
return fThreshold;
}

void HighPassFilterFFTGenerator::SetThreshold( double aThreshold )
{
fThreshold = aThreshold;
return;
}


void HighPassFilterFFTGenerator::Accept( GeneratorVisitor* aVisitor ) const
{
aVisitor->Visit( this );
return;
}


bool HighPassFilterFFTGenerator::DoGenerate( Signal* aSignal )
{
return (this->*fDoGenerateFunc)( aSignal );
}

bool HighPassFilterFFTGenerator::DoGenerateTime( Signal* aSignal )
{
const unsigned nchannels = fNChannels;
double CutoffFreq = fThreshold;
int nwindows = 10;
int windowsize = aSignal->TimeSize()/nwindows;


fftw_complex *SignalComplex;
SignalComplex = (fftw_complex*)fftw_malloc( sizeof(fftw_complex) * windowsize );
fftw_complex *FFTComplex;
FFTComplex = (fftw_complex*)fftw_malloc( sizeof(fftw_complex) * windowsize );

fftw_plan ForwardPlan;
ForwardPlan = fftw_plan_dft_1d(windowsize, SignalComplex, FFTComplex, FFTW_FORWARD, FFTW_ESTIMATE);
fftw_plan ReversePlan;
ReversePlan = fftw_plan_dft_1d(windowsize, FFTComplex, SignalComplex, FFTW_BACKWARD, FFTW_ESTIMATE);

for (int ch=0; ch<nchannels; ch++)
{
for (int nwin = 0; nwin < nwindows; nwin++)
{
// Construct complex voltage.
for( unsigned index = 0; index < windowsize; ++index )
{
SignalComplex[index][0] = aSignal->SignalTimeComplex()[ ch*aSignal->TimeSize() + nwin*windowsize + index ][0];
SignalComplex[index][1] = aSignal->SignalTimeComplex()[ ch*aSignal->TimeSize() + nwin*windowsize + index ][1];
}

fftw_execute(ForwardPlan);

// High Pass FilterFFT
for( unsigned index = 0; index < windowsize; ++index )
{
if ((index < CutoffFreq/(fAcquisitionRate*1.e6)*windowsize)||(index>0.5*windowsize))
{
FFTComplex[index][0] = 0.;
FFTComplex[index][1] = 0.;
}
}

fftw_execute(ReversePlan);

double norm = (double)(windowsize);

for( unsigned index = 0; index < windowsize; ++index )
{
// normalize
aSignal->SignalTimeComplex()[ ch*aSignal->TimeSize() + nwin*windowsize + index ][0] = SignalComplex[index][0]/norm;
aSignal->SignalTimeComplex()[ ch*aSignal->TimeSize() + nwin*windowsize + index ][1] = SignalComplex[index][1]/norm;
}
} // nwin
} // NCHANNELS

delete [] SignalComplex;
delete [] FFTComplex;


return true;
}

bool HighPassFilterFFTGenerator::DoGenerateFreq( Signal* aSignal )
{
return true;
}

} /* namespace locust */
Loading

0 comments on commit 74350e1

Please sign in to comment.