Skip to content

Commit

Permalink
Merge pull request #320 from project8/feature/addPaths
Browse files Browse the repository at this point in the history
Feature/add paths
  • Loading branch information
pslocum authored Sep 23, 2024
2 parents 2010ae3 + e1317d4 commit 458fb1f
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and Test Locust
on:
pull_request:
push:
branches: [master, develop, feature/pileupChecks]
branches: [master, develop]
tags: ['*']
workflow_dispatch:

Expand Down
12 changes: 10 additions & 2 deletions Source/Fields/LMCCylindricalCavity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ namespace locust
}
if (!fFieldCore->ReadModeMapTE_E((dataDir / aParam["upload-modemap-filename"]().as_string()).string(), aParam))
{
LERROR(lmclog,"There was a problem uploading the mode map.");
exit(-1);
LWARN(lmclog,"The mode map was not in the data/ subdirectory. Trying another path ... ");
if (!fFieldCore->ReadModeMapTE_E(aParam["upload-modemap-filename"]().as_string(), aParam))
{
LERROR(lmclog, "There was a problem uploading the mode map.");
exit(-1);
}
else
{
LPROG(lmclog, "Reading in the mode map now ...");
}
}
SetNormFactors(SetUnityNormFactors(GetNModes(), 0)); // Temporary quick normalization factors of 1.0
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Fields/LMCModeMapCavity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ namespace locust
std::fstream modeMapFile(aFilename.c_str(),std::ios::in);
if (modeMapFile.fail())
{
LERROR(lmclog,"The mode map file \"" << aFilename <<"\" was not found.");
LWARN(lmclog,"The mode map file \"" << aFilename <<"\" was not found.");
return false;
}
else
{
LWARN(lmclog,"Reading mode map file \"" << aFilename <<"\" .");
LPROG(lmclog,"Reading mode map file \"" << aFilename <<"\" .");
}

fModeMapTE_E.resize(fnPixel1);
Expand Down
1 change: 0 additions & 1 deletion Source/Generators/LMCCavitySignalGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ namespace locust
fInterface->aRunParameter->fSamplingRateMHz = fAcquisitionRate;
fInterface->aRunParameter->fDecimationFactor = aSignal->DecimationFactor();
fInterface->aRunParameter->fLOfrequency = fLO_Frequency;
fInterface->aRunParameter->fRandomSeed = fTrackDelaySeed;
#endif
return true;
}
Expand Down
53 changes: 47 additions & 6 deletions Source/IO/LMCEvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,52 @@ namespace locust
}
Event::~Event() {}

void Event::AddTrack(const Track aTrack)
bool Event::Initialize(long int aSeed)
{
time_t rawtime;
struct tm * timeInfo;
time (&rawtime);
timeInfo = localtime (&rawtime);

struct timeval tv;
gettimeofday(&tv, NULL);

int tDay = timeInfo->tm_mday;
int tMonth = timeInfo->tm_mon + 1;
int tYear = timeInfo->tm_year - 100;
int tMicrosec = tv.tv_usec;

fEventID = 1e12 + tDay*1e10 + tMonth*1e8 + tYear*1e6 + tMicrosec;
fRandomSeed = aSeed;
fLOFrequency = -99.;
return true;
}


void Event::AddTrack(const Track* aTrack) // Phase III structure
{
fTrackIDs.push_back( aTrack->TrackID );
fStartingEnergies_eV.push_back( aTrack->StartingEnergy_eV );
fOutputStartFrequencies.push_back( aTrack->OutputStartFrequency );
fStartFrequencies.push_back( aTrack->StartFrequency );
fEndFrequencies.push_back( aTrack->EndFrequency );
fAvgFrequencies.push_back( aTrack->AvgFrequency );
fOutputAvgFrequencies.push_back( aTrack->OutputAvgFrequency );
fAvgAxialFrequencies.push_back( aTrack->AvgAxialFrequency );
fTrackPowers.push_back( aTrack->TrackPower );
fStartTimes.push_back( aTrack->StartTime );
fTrackLengths.push_back( aTrack->TrackLength );
fEndTimes.push_back( aTrack->EndTime );
fSlopes.push_back( aTrack->Slope );
fPitchAngles.push_back( aTrack->PitchAngle );
fRadii.push_back( aTrack->Radius );
fRadialPhases.push_back( aTrack->RadialPhase );

// Update size.
fNTracks = fStartFrequencies.size();
}

void Event::AddTrack(const Track aTrack) // Phase II structure
{
fStartingEnergies_eV.push_back( aTrack.StartingEnergy_eV );
fOutputStartFrequencies.push_back( aTrack.OutputStartFrequency );
Expand All @@ -40,11 +85,7 @@ namespace locust
fPitchAngles.push_back( aTrack.PitchAngle );
fRadii.push_back( aTrack.Radius );
fRadialPhases.push_back( aTrack.RadialPhase );

// Update size. And, record fLOFrequency for compatibility with previous work. The LO frequency is
// now also recorded in the RunParameters Tree.
fNTracks = fStartFrequencies.size();
fLOFrequency = aTrack.LOFrequency;
fRandomSeed = aTrack.RandomSeed;
}

}
12 changes: 10 additions & 2 deletions Source/IO/LMCEvent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include "TObject.h"
#include "LMCTrack.hh"
#include <vector>
#include "time.h"
#include <sys/time.h>




namespace locust
{
Expand All @@ -27,12 +32,15 @@ namespace locust
Event();
virtual ~Event();

bool Initialize(long int aSeed);
void AddTrack(const Track* aTrack);
void AddTrack(const Track aTrack);

int fEventID;
long int fEventID;
double fLOFrequency;
int fRandomSeed;
long int fRandomSeed;

std::vector<int> fTrackIDs;
std::vector<double> fStartingEnergies_eV;
std::vector<double> fOutputStartFrequencies;
std::vector<double> fStartFrequencies;
Expand Down
11 changes: 6 additions & 5 deletions Source/IO/LMCRootTreeWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ namespace locust

void RootTreeWriter::WriteEvent(Event* anEvent)
{
char buffer[100];
int n=sprintf(buffer, "Event_%d", anEvent->fEventID);
char* treename = buffer;
char buffer[100];
int n=sprintf(buffer, "Event_%ld", anEvent->fEventID);
char* treename = buffer;

TTree *aTree = new TTree(treename,"Locust Tree");
aTree->Branch("EventID", &anEvent->fEventID, "EventID/I");
aTree->Branch("EventID", &anEvent->fEventID, "EventID/L");
aTree->Branch("ntracks", &anEvent->fNTracks, "ntracks/I");
aTree->Branch("TrackIDs", "std::vector<int>", &anEvent->fTrackIDs);
aTree->Branch("StartingEnergieseV", "std::vector<double>", &anEvent->fStartingEnergies_eV);
aTree->Branch("OutputStartFrequencies", "std::vector<double>", &anEvent->fOutputStartFrequencies);
aTree->Branch("StartFrequencies", "std::vector<double>", &anEvent->fStartFrequencies);
Expand All @@ -68,7 +69,7 @@ namespace locust
aTree->Branch("TrackLengths", "std::vector<double>", &anEvent->fTrackLengths);
aTree->Branch("Slopes", "std::vector<double>", &anEvent->fSlopes);
aTree->Branch("LOFrequency", &anEvent->fLOFrequency, "LOFrequency/D");
aTree->Branch("RandomSeed", &anEvent->fRandomSeed, "RandomSeed/I");
aTree->Branch("RandomSeed", &anEvent->fRandomSeed, "RandomSeed/L");
aTree->Branch("TrackPower", "std::vector<double>", &anEvent->fTrackPowers);
aTree->Branch("PitchAngles", "std::vector<double>", &anEvent->fPitchAngles);
aTree->Branch("Radii", "std::vector<double>", &anEvent->fRadii);
Expand Down
1 change: 0 additions & 1 deletion Source/IO/LMCRunParameters.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace locust
double fLOfrequency;
double fSamplingRateMHz;
double fDecimationFactor;
int fRandomSeed;

ClassDef(RunParameters,1) // Root syntax.

Expand Down
7 changes: 3 additions & 4 deletions Source/IO/LMCTrack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ ClassImp(locust::Track);
namespace locust
{

Track::Track()
Track::Track() :
TrackID( -2 )
{
}

Expand All @@ -22,8 +23,7 @@ namespace locust

bool Track::Initialize()
{
EventID = -99;
RandomSeed = -99.;
TrackID += 1;
StartTime = -99.;
EndTime = -99.;
TrackLength = -99.;
Expand All @@ -34,7 +34,6 @@ namespace locust
AvgFrequency = 0.;
OutputAvgFrequency = 0.;
AvgAxialFrequency = 0.;
LOFrequency = -99.;
TrackPower = -99.;
Slope = -99.;
PitchAngle = -99.;
Expand Down
3 changes: 1 addition & 2 deletions Source/IO/LMCTrack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ namespace locust
Track();
virtual ~Track();
bool Initialize();
int EventID = -99;
int RandomSeed = -99.;
int TrackID;
double StartTime = -99.;
double EndTime = -99.;
double TrackLength = -99.;
Expand Down
30 changes: 14 additions & 16 deletions Source/Kassiopeia/LMCCyclotronRadiationExtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ namespace locust
if (bStart)
{
fStartingIndex = index;
fInterface->aTrack.StartTime = tTime;
fInterface->aTrack->StartTime = tTime;
double tX = aFinalParticle.GetPosition().X();
double tY = aFinalParticle.GetPosition().Y();
fInterface->aTrack.Radius = pow(tX*tX + tY*tY, 0.5);
fInterface->aTrack.RadialPhase = calcOrbitPhase(tX, tY);
fInterface->aTrack.StartingEnergy_eV = LMCConst::kB_eV() / LMCConst::kB() * aFinalParticle.GetKineticEnergy();
fInterface->aTrack->Radius = pow(tX*tX + tY*tY, 0.5);
fInterface->aTrack->RadialPhase = calcOrbitPhase(tX, tY);
fInterface->aTrack->StartingEnergy_eV = LMCConst::kB_eV() / LMCConst::kB() * aFinalParticle.GetKineticEnergy();
}
else
{
fInterface->aTrack.EndTime = tTime;
fInterface->aTrack->EndTime = tTime;
unsigned nElapsedSamples = index - fStartingIndex;
fInterface->aTrack.AvgFrequency = ( fInterface->aTrack.AvgFrequency * nElapsedSamples + aFinalParticle.GetCyclotronFrequency() ) / ( nElapsedSamples + 1);
fInterface->aTrack.OutputAvgFrequency = fInterface->aTrack.AvgFrequency + tOffset;
fInterface->aTrack.TrackLength = tTime - fInterface->aTrack.StartTime;
fInterface->aTrack.Slope = (fInterface->aTrack.EndFrequency - fInterface->aTrack.StartFrequency) / (fInterface->aTrack.TrackLength);
fInterface->aTrack->AvgFrequency = ( fInterface->aTrack->AvgFrequency * nElapsedSamples + aFinalParticle.GetCyclotronFrequency() ) / ( nElapsedSamples + 1);
fInterface->aTrack->OutputAvgFrequency = fInterface->aTrack->AvgFrequency + tOffset;
fInterface->aTrack->TrackLength = tTime - fInterface->aTrack->StartTime;
fInterface->aTrack->Slope = (fInterface->aTrack->EndFrequency - fInterface->aTrack->StartFrequency) / (fInterface->aTrack->TrackLength);
}
#endif

Expand Down Expand Up @@ -145,20 +145,18 @@ namespace locust
fPitchAngle = aFinalParticle.GetPolarAngleToB();
fT0trapMin = aFinalParticle.GetTime();
#ifdef ROOT_FOUND
fInterface->aTrack.PitchAngle = aFinalParticle.GetPolarAngleToB();
fInterface->aTrack.StartFrequency = aFinalParticle.GetCyclotronFrequency();
fInterface->aTrack->PitchAngle = aFinalParticle.GetPolarAngleToB();
fInterface->aTrack->StartFrequency = aFinalParticle.GetCyclotronFrequency();
double tLOfrequency = fInterface->aRunParameter->fLOfrequency; // Hz
double tSamplingRate = fInterface->aRunParameter->fSamplingRateMHz; // MHz
fInterface->aTrack.LOFrequency = tLOfrequency;
fInterface->aTrack.RandomSeed = fInterface->aRunParameter->fRandomSeed;
fInterface->aTrack.OutputStartFrequency = fInterface->aTrack.StartFrequency - tLOfrequency + tSamplingRate * 1.e6 / 2.;
fInterface->aTrack->OutputStartFrequency = fInterface->aTrack->StartFrequency - tLOfrequency + tSamplingRate * 1.e6 / 2.;
#endif
}
else
{
#ifdef ROOT_FOUND
fInterface->aTrack.EndFrequency = aFinalParticle.GetCyclotronFrequency();
fInterface->aTrack.AvgAxialFrequency = fNCrossings / 2. / ( aFinalParticle.GetTime() - fT0trapMin );
fInterface->aTrack->EndFrequency = aFinalParticle.GetCyclotronFrequency();
fInterface->aTrack->AvgAxialFrequency = fNCrossings / 2. / ( aFinalParticle.GetTime() - fT0trapMin );
#endif
}
}
Expand Down
21 changes: 14 additions & 7 deletions Source/Kassiopeia/LMCEventHold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace locust
fTruthOutputFilename("LocustEventProperties.root"),
fAccumulateTruthInfo( false ),
fConfigurationComplete( false ),
fEventSeed( 0 ),
fInterface( KLInterfaceBootstrapper::get_instance()->GetInterface() )
{
}
Expand All @@ -26,6 +27,7 @@ namespace locust
fTruthOutputFilename("LocustEventProperties.root"),
fAccumulateTruthInfo( false ),
fConfigurationComplete( false ),
fEventSeed( 0 ),
fInterface( aOrig.fInterface )
{
}
Expand All @@ -41,7 +43,6 @@ namespace locust

bool EventHold::ConfigureByInterface()
{
OpenEvent();

if (!fConfigurationComplete)
{
Expand Down Expand Up @@ -72,7 +73,11 @@ namespace locust
{
if ( aParam.has( "random-track-seed" ) )
{
fInterface->anEvent->fRandomSeed = aParam["random-track-seed"]().as_int();
fEventSeed = aParam["random-track-seed"]().as_int();
}
else
{
fEventSeed = -99;
}
if ( aParam.has( "truth-output-filename" ) )
{
Expand All @@ -93,11 +98,9 @@ namespace locust
{
#ifdef ROOT_FOUND
fInterface->anEvent = new Event();
fInterface->anEvent->fEventID = 0;
fInterface->anEvent->fRandomSeed = -99;
fInterface->anEvent->fLOFrequency = -99.;
fInterface->anEvent->fRandomSeed = -99;
fInterface->aTrack.Initialize();
fInterface->anEvent->Initialize( fEventSeed );
fInterface->aTrack = new Track();
fInterface->aTrack->Initialize();
#endif

return true;
Expand Down Expand Up @@ -152,6 +155,8 @@ namespace locust
return false;
}

OpenEvent(); // for recording event properties to file.

LPROG( lmclog, "Kass is waiting for event trigger" );

fInterface->fDigitizerCondition.notify_one(); // unlock if still locked.
Expand Down Expand Up @@ -180,6 +185,8 @@ namespace locust
fInterface->fEventInProgress = false;
fInterface->fDigitizerCondition.notify_one(); // unlock
LPROG( lmclog, "Kass is waking after event" );
delete fInterface->anEvent;
delete fInterface->aTrack;
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/Kassiopeia/LMCEventHold.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "KSEventModifier.h"
#include "KSComponentTemplate.h"


#include "LMCKassLocustInterface.hh"

#ifdef ROOT_FOUND
Expand Down Expand Up @@ -49,6 +50,7 @@ namespace locust

private:
bool fConfigurationComplete;
long int fEventSeed;

};

Expand Down
2 changes: 1 addition & 1 deletion Source/Kassiopeia/LMCKassLocustInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace locust

#ifdef ROOT_FOUND
Event* anEvent;
Track aTrack;
Track* aTrack;
RunParameters* aRunParameter;
#endif

Expand Down
12 changes: 11 additions & 1 deletion Source/Kassiopeia/LMCRunPause.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,17 @@ namespace locust
&& aParam.has( "ks-starting-energy-min" ) && aParam.has( "ks-starting-energy-max" )
&& aParam.has( "ks-starting-pitch-min" ) && aParam.has( "ks-starting-pitch-max" ) )
{
KRandom::GetInstance().SetSeed(time(NULL));
int tSeed = 0;
if ( aParam.has( "random-track-seed" ) )
{
tSeed = aParam["random-track-seed"]().as_int();
KRandom::GetInstance().SetSeed(tSeed);
}
else
{
KRandom::GetInstance().SetSeed(time(NULL));
}

auto tGen = fToolbox.GetAll<Kassiopeia::KSGenerator>();
for (unsigned i=0; i<tGen.size(); i++)
{
Expand Down
Loading

0 comments on commit 458fb1f

Please sign in to comment.