Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pslocum committed Jul 31, 2023
2 parents 8fe4fd8 + d452d34 commit f169dd9
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 15 deletions.
64 changes: 55 additions & 9 deletions Source/Core/LMCHFSSResponseFileHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,73 @@ namespace locust
fIsFIRCreated=true;
return true;
}

bool HFSSResponseFileHandlerCore::WriteRootHisto( std::vector<double> aFilter, bool bIQ )
{
#ifdef ROOT_FOUND
char fbuffer[60];
if (!bIQ)
{
int a = sprintf(fbuffer, "FIR_I");
}
else
{
int a = sprintf(fbuffer, "FIR_Q");
}
fRootHistoWriter->OpenFile("UPDATE");
const char *hName = fbuffer;
TH1D* aHisto = new TH1D(hName, "FIR coefficients; index; coefficient", fFIRNBins, 0., (double)fFIRNBins);
aHisto->SetDirectory(0);

for (unsigned i=0; i<fFIRNBins; i++)
{
aHisto->SetBinContent(i+1, aFilter[i]);
}

fRootHistoWriter->Write1DHisto(aHisto);
fRootHistoWriter->CloseFile();
delete aHisto;
#endif
return true;
}


void HFSSResponseFileHandlerCore::PrintFIR( std::vector<double> aFilter )
{
LDEBUG( lmclog, "Printing FIR coefficients to file ... ");
FILE * fFIRout = fopen("output/FIR.txt", "w");
for (int i = 0; i < fFIRNBins; i++)
LDEBUG( lmclog, "Printing FIR coefficients to file ... ");
FILE * fFIRout = fopen("output/FIR.txt", "w");
for (int i = 0; i < fFIRNBins; i++)
{
fprintf(fFIRout,"%g\n", aFilter[i]);
}
fclose(fFIRout);
#ifdef ROOT_FOUND
WriteRootHisto( aFilter, 0 );
#endif

}

void HFSSResponseFileHandlerCore::PrintFIR( fftw_complex* aFilter )
{
LDEBUG( lmclog, "Printing FIR coefficients to file ... ");
FILE * fFIRout = fopen("output/FIR.txt", "w");
for (int i = 0; i < fFIRNBins; i++)
{
std::vector<double> vecFilter0;
std::vector<double> vecFilter1;
LDEBUG( lmclog, "Printing FIR coefficients to file ... ");
FILE * fFIRout = fopen("output/FIR.txt", "w");
for (int i = 0; i < fFIRNBins; i++)
{
fprintf(fFIRout,"%g %g\n", aFilter[i][0], aFilter[i][1]);
}
fclose(fFIRout);
vecFilter0.push_back(aFilter[i][0]);
vecFilter1.push_back(aFilter[i][1]);
}
fclose(fFIRout);
#ifdef ROOT_FOUND
fRootHistoWriter = RootHistoWriter::get_instance();
fRootHistoWriter->SetFilename("output/FIRhisto.root");
fRootHistoWriter->OpenFile("RECREATE");
fRootHistoWriter->CloseFile();
WriteRootHisto( vecFilter0, 0 );
WriteRootHisto( vecFilter1, 1 );
#endif
}

FIRFileHandlerCore::FIRFileHandlerCore():HFSSResponseFileHandlerCore()
Expand Down
9 changes: 9 additions & 0 deletions Source/Core/LMCHFSSResponseFileHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "param.hh"
#include "LMCComplexFFT.hh"

#ifdef ROOT_FOUND
#include "LMCRootHistoWriter.hh"
#endif

namespace locust
{
/*!
Expand Down Expand Up @@ -33,6 +37,7 @@ namespace locust
double GetFilterResolution() const;//Get the resolution of the filter
void PrintFIR( std::vector<double> );
void PrintFIR( fftw_complex* aFilter );
bool WriteRootHisto( std::vector<double> aFilter, bool bIQ );


protected:
Expand All @@ -51,6 +56,10 @@ namespace locust
std::string fWindowName;
double fWindowParam;
bool fPrintFIR;
#ifdef ROOT_FOUND
FileWriter* fRootHistoWriter;
#endif



//Member functions
Expand Down
32 changes: 32 additions & 0 deletions Source/Fields/LMCPozarCylindricalCavity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ namespace locust

double z = zKass + L/2.;

if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity
{
return {0.,0.};
}
else
{

// from Pozar
std::vector<double> TE_E;
double x_lm = GetBesselNKPrimeZeros(l,m);
Expand All @@ -51,13 +58,21 @@ namespace locust
TE_E.push_back(tEtheta);

return TE_E;
}
}

std::vector<double> PozarCylindricalCavity::TE_H(double R, double L, int l, int m, int n, double r, double theta, double zKass, bool includeOtherPols)
{

double z = zKass + L/2.;

if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity
{
return {0.,0.,0.};
}
else
{

// from Pozar
std::vector<double> TE_H;
double x_lm = GetBesselNKPrimeZeros(l,m);
Expand All @@ -83,12 +98,20 @@ namespace locust
TE_H.push_back(tHz); // z
TE_H.push_back(tHtheta); // theta
return TE_H; // r, z, theta
}
}

std::vector<double> PozarCylindricalCavity::TM_E(double R, double L, int l, int m, int n, double r, double theta, double zKass, bool includeOtherPols)
{
double z = zKass + L/2.;

if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity
{
return {0.,0.,0.};
}
else
{

// from Pozar
std::vector<double> TM_E;
double x_lm = GetBesselNKZeros(l,m);
Expand All @@ -115,12 +138,20 @@ namespace locust
TM_E.push_back(tEz); // z
TM_E.push_back(tEtheta); // theta
return TM_E; // r, z, theta
}
}

std::vector<double> PozarCylindricalCavity::TM_H(double R, double L, int l, int m, int n, double r, double theta, double zKass, bool includeOtherPols)
{
double z = zKass + L/2.;

if ((r > R) || (fabs(zKass) > L/2.)) // outside the cavity
{
return {0.,0.};
}
else
{

// from Pozar
std::vector<double> TM_H;
double x_lm = GetBesselNKZeros(l,m);
Expand All @@ -144,6 +175,7 @@ namespace locust
TM_H.push_back(tHr); // r
TM_H.push_back(tHtheta); // theta
return TM_H;
}
}

} /* namespace locust */
Expand Down
32 changes: 32 additions & 0 deletions Source/Fields/LMCPozarRectangularWaveguide.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ namespace locust
double x = xKass + dimX/2.;
double y = yKass + dimY/2.;

if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.))
{
return {0.,0.};
}
else
{

// from Pozar
std::vector<double> TE_E;
double k1 = m * LMCConst::Pi() / dimX;
Expand All @@ -35,6 +42,7 @@ namespace locust
TE_E.push_back(tEx);
TE_E.push_back(tEy);
return TE_E;
}
}


Expand All @@ -43,6 +51,13 @@ namespace locust
double x = xKass + dimX/2.;
double y = yKass + dimY/2.;

if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.))
{
return {0.,0.};
}
else
{

// from Pozar
std::vector<double> TE_H;
double k1 = m * LMCConst::Pi() / dimX;
Expand All @@ -57,6 +72,7 @@ namespace locust
TE_H.push_back(tHx);
TE_H.push_back(tHy);
return TE_H;
}
}


Expand All @@ -65,6 +81,13 @@ namespace locust
double x = xKass + dimX/2.;
double y = yKass + dimY/2.;

if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.))
{
return {0.,0.};
}
else
{

// from Pozar
std::vector<double> TM_E;
double k1 = m * LMCConst::Pi() / dimX;
Expand All @@ -78,13 +101,21 @@ namespace locust
TM_E.push_back(tEx);
TM_E.push_back(tEy);
return TM_E;
}
}

std::vector<double> PozarRectangularWaveguide::TM_H(double dimX, double dimY, int m, int n, double xKass, double yKass, double fcyc)
{
double x = xKass + dimX/2.;
double y = yKass + dimY/2.;

if ((fabs(xKass) > dimX/2.) || (fabs(yKass) > dimY/2.))
{
return {0.,0.};
}
else
{

// from Pozar
std::vector<double> TM_H;
double k1 = m * LMCConst::Pi() / dimX;
Expand All @@ -96,6 +127,7 @@ namespace locust
TM_H.push_back(tHx);
TM_H.push_back(tHy);
return TM_H;
}
}


Expand Down
15 changes: 11 additions & 4 deletions Source/Kassiopeia/LMCFieldCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,19 @@ namespace locust
double tVx = tKassParticleXP[3];
double tVy = tKassParticleXP[4];
double vMag = pow(tVx*tVx + tVy*tVy,0.5);
double zLocation = tKassParticleXP[2];
double dimZ = fInterface->fField->GetDimL();
double orbitPhase = tKassParticleXP[6]; // radians
double cycFrequency = tKassParticleXP[7];
double amplitude = 0.;
if (fabs(zLocation) < dimZ/2.)
{
amplitude = 1.;
}


if ( !BypassTF )
{
double orbitPhase = tKassParticleXP[6]; // radians
double cycFrequency = tKassParticleXP[7]; // rad/s

// populate FIR filter with frequency for just this sample interval:
for (int i=0; i < fNFilterBinsRequired; i++)
{
Expand All @@ -415,7 +422,7 @@ namespace locust

if (*it != 0.)
{
fFIRBuffer.push_back(cos(orbitPhase));
fFIRBuffer.push_back(amplitude * cos(orbitPhase));
}
else
{
Expand Down
17 changes: 15 additions & 2 deletions Source/RxComponents/LMCAnalyticResponseFunction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,26 @@ namespace locust
{
return fTFarray;
}

void AnalyticResponseFunction::SetGFarray( std::vector<std::pair<double,std::pair<double,double> > > aGFarray )
{
for (unsigned index=0; index<aGFarray.size(); index++)
if (fGFarray.size() > 0)
{
for (unsigned index=0; index<aGFarray.size(); index++)
{
fGFarray[index].second.first = aGFarray[index].second.first;
fGFarray[index].second.second = aGFarray[index].second.second;
}
}
else
{
fGFarray.push_back(std::make_pair(aGFarray[index].first, aGFarray[index].second));
for (unsigned index=0; index<aGFarray.size(); index++)
{
fGFarray.push_back(std::make_pair(aGFarray[index].first, aGFarray[index].second));
}
}
}

std::vector<std::pair<double,std::pair<double,double> > > AnalyticResponseFunction::GetGFarray()
{
return fGFarray;
Expand Down

0 comments on commit f169dd9

Please sign in to comment.