9 #ifndef CROSSCORRELATOR_H 10 #define CROSSCORRELATOR_H 13 #include "UsefulAnitaEvent.h" 14 #include "AnitaEventCalibrator.h" 15 #include "AnitaGeomTool.h" 16 #include "UsefulAdu5Pat.h" 19 #include "FancyFFTs.h" 22 #include "RootTools.h" 33 #define DELTA_PHI_SECT 2 36 #define NUM_COMBOS 336 40 #define NUM_SAMPLES 256 41 #define UPSAMPLE_FACTOR 40 42 #define NOMINAL_SAMPLING_DELTAT (1./2.6f) 44 #define GETNUMFREQS(n)((n)/2+1) 47 #define NUM_BINS_THETA 100 48 #define NUM_BINS_PHI 15 49 #define THETA_RANGE 150 50 #define PHI_RANGE 22.5 52 #define NUM_BINS_THETA_ZOOM 100 53 #define NUM_BINS_PHI_ZOOM 100 58 #define ZOOM_BIN_SIZE_PHI 0.2 59 #define ZOOM_BIN_SIZE_THETA 0.2 62 #define THETA_RANGE_ZOOM (NUM_BINS_THETA_ZOOM*ZOOM_BIN_SIZE_THETA) 63 #define PHI_RANGE_ZOOM (NUM_BINS_PHI_ZOOM*ZOOM_BIN_SIZE_PHI) 67 #define NUM_BINS_PHI_ZOOM_TOTAL 7269 68 #define NUM_BINS_THETA_ZOOM_TOTAL 3069 73 #define NUM_POL AnitaPol::kNotAPol 74 #define NUM_RING AnitaRing::kNotARing 75 #define DEGREES_IN_CIRCLE 360 77 #define MAX_NUM_PEAKS 2 78 #define PEAK_PHI_DEG_RANGE 10 79 #define PEAK_THETA_DEG_RANGE 10 81 #define SPEED_OF_LIGHT 2.99792458e8 82 #define SPEED_OF_LIGHT_NS 0.299792458 84 #define ALL_PHI_TRIGS 0xffff 137 void simpleNotch(AnitaPol::AnitaPol_t pol, Int_t ant, Double_t notchLowEdgeMHz, Double_t notchHighEdgeMHz);
142 void doFFTs(AnitaPol::AnitaPol_t pol);
144 void correlateEvent(UsefulAnitaEvent* realEvent, AnitaPol::AnitaPol_t pol);
145 void reconstructEvent(UsefulAnitaEvent* usefulEvent, Int_t numFinePeaks=MAX_NUM_PEAKS, Int_t numCoarsePeaks=MAX_NUM_PEAKS);
146 void findPeakValues(AnitaPol::AnitaPol_t pol, Int_t numPeaks, Double_t* peakValues,
147 Double_t* phiDegs, Double_t* thetaDegs);
162 Double_t phiWave, Double_t thetaWave);
166 Double_t
relativeOffAxisDelay(AnitaPol::AnitaPol_t pol, Int_t ant1, Int_t ant2, Double_t phiDeg);
170 Bool_t
useCombo(Int_t ant1, Int_t ant2, Int_t phiSector, Int_t deltaPhiSect);
186 void getCoarsePeakInfo(AnitaPol::AnitaPol_t pol, Int_t peakIndex, Double_t& value,
187 Double_t& phiDeg, Double_t& thetaDeg);
188 void getFinePeakInfo(AnitaPol::AnitaPol_t pol, Int_t peakIndex, Double_t& value,
189 Double_t& phiDeg, Double_t& thetaDeg);
195 TH2D*
getMap(AnitaPol::AnitaPol_t pol, Double_t& peakValue,
196 Double_t& peakPhiDeg, Double_t& peakThetaDeg,
197 UShort_t l3TrigPattern=ALL_PHI_TRIGS);
202 void reconstruct(AnitaPol::AnitaPol_t pol, Double_t& imagePeak,
203 Double_t& peakPhiDeg, Double_t& peakThetaDeg);
205 Double_t& imagePeak, Double_t& peakPhiDeg,
206 Double_t& peakThetaDeg, Double_t zoomCenterPhiDeg=0, Double_t zoomCenterThetaDeg=0);
209 Double_t& peakPhiDeg, Double_t& peakThetaDeg);
212 TH2D*
makeTriggeredImage(AnitaPol::AnitaPol_t pol, Double_t& imagePeak, Double_t& peakPhiDeg,
213 Double_t& peakThetaDeg, UShort_t l3TrigPattern);
215 TH2D*
makeZoomedImage(AnitaPol::AnitaPol_t pol, UShort_t l3TrigPattern,
216 Double_t zoomCenterPhiDeg, Double_t zoomCenterThetaDeg);
217 TH2D*
makeZoomedImage(AnitaPol::AnitaPol_t pol, Double_t& imagePeak, Double_t& peakPhiDeg,
218 Double_t& peakThetaDeg, UShort_t l3TrigPattern, Double_t zoomCenterPhiDeg,
219 Double_t zoomCenterThetaDeg);
220 TH2D*
makeZoomedImage(AnitaPol::AnitaPol_t pol, Double_t& imagePeak, Double_t& peakPhiDeg,
221 Double_t& peakThetaDeg, Double_t zoomCenterPhiDeg, Double_t zoomCenterThetaDeg);
225 Double_t thetaDeg, Int_t maxDeltaPhiSect, Double_t& snr);
227 Double_t thetaDeg, Int_t maxDeltaPhiSect, Double_t& snr);
228 TGraph*
makeCoherentWorker(AnitaPol::AnitaPol_t pol, Double_t phiDeg, Double_t thetaDeg,
229 Int_t maxDeltaPhiSect, Double_t& snr, Int_t nSamp);
240 Int_t ant1, Int_t ant2);
250 Int_t
offsetLows[NUM_POL][NUM_COMBOS][NUM_PHI*NUM_BINS_PHI][NUM_BINS_THETA];
253 Double_t
coarseMap[NUM_POL][NUM_BINS_PHI*NUM_PHI][NUM_BINS_THETA];
255 std::set<std::vector<int> >::iterator
comboSetIterator[NUM_BINS_THETA][NUM_BINS_PHI*NUM_PHI];
257 Double_t
partBAsZoom[NUM_POL][NUM_COMBOS][NUM_BINS_THETA_ZOOM_TOTAL];
258 Double_t
part21sZoom[NUM_POL][NUM_COMBOS][NUM_BINS_PHI_ZOOM_TOTAL];
261 Double_t
fineMap[NUM_POL][NUM_BINS_THETA_ZOOM][NUM_BINS_PHI_ZOOM];
263 std::complex<Double_t>
fftsPadded[NUM_POL][NUM_SEAVEYS][GETNUMFREQS(NUM_SAMPLES*PAD_FACTOR*UPSAMPLE_FACTOR)];
265 std::complex<Double_t>
ffts[NUM_POL][NUM_SEAVEYS][GETNUMFREQS(NUM_SAMPLES*PAD_FACTOR)];
266 TGraph*
grs[NUM_POL][NUM_SEAVEYS];
326 std::vector<threadArgs> threadArgsVec;
328 Double_t aftForeOffset;
329 Double_t minThetaDegZoom;
330 Double_t minPhiDegZoom;
332 Double_t zoomThetaMin;
TH2D * makeGlobalImage(AnitaPol::AnitaPol_t pol, Double_t &imagePeak, Double_t &peakPhiDeg, Double_t &peakThetaDeg)
Creates an interferometric map using plane wave deltaTs and antenna pairs from all phi-sectors...
Double_t singleAntennaOffAxisDelay(Double_t deltaPhiDeg)
Get the off-axis delay for an off boresight angle.
Int_t numSamplesUpsampled
Number of samples in waveform after padding and up sampling.
void findPeakValues(AnitaPol::AnitaPol_t pol, Int_t numPeaks, Double_t *peakValues, Double_t *phiDegs, Double_t *thetaDegs)
Goes through the coarseMap and finds the top N values.
TString zoomModeNames[kNumZoomModes]
Maps text to the zoomMode_t enum, used for histogram names/titles.
void fillCombosToUse()
Creates vectors of antenna combo indices and puts them in the combosToUseGlobal map.
void deleteAllWaveforms(AnitaPol::AnitaPol_t pol)
Deletes the waveform TGraphs in memory and removes dangling pointers.
UInt_t lastEventNormalized[NUM_POL]
Prevents cross-correlation of the same event twice.
Double_t fineMap[NUM_POL][NUM_BINS_THETA_ZOOM][NUM_BINS_PHI_ZOOM]
Internal storage for the finely binned map.
A class to take in UsefulAnitaEvents and get interferometric maps with a single function.
Int_t comboIndices[NUM_SEAVEYS][NUM_SEAVEYS]
Array mapping ant1+ant2 to combo index.
Int_t offsetLows[NUM_POL][NUM_COMBOS][NUM_PHI *NUM_BINS_PHI][NUM_BINS_THETA]
The interpolation factor for neighbouring samples.
std::vector< TThread * > upsampledCorrThreads
TThreads for doing upsampled cross correlations.
Double_t threadImagePeak[NUM_THREADS]
Store image peaks found by different threads.
static void * doSomeCrossCorrelationsThreaded(void *voidPtrArgs)
Static member function which generates the coarsely binned set of cross correlations from the FFTs he...
TGraph * getCrossCorrelationGraphWorker(Int_t numSamps, AnitaPol::AnitaPol_t pol, Int_t ant1, Int_t ant2)
Called by wrapper functions. Turns internal correlation arrays into TGraphs to be seen by humans...
Int_t kDeltaPhiSect
Specifies how many phi-sectors around peak use in reconstruction.
TGraph * getUpsampledCrossCorrelationGraph(AnitaPol::AnitaPol_t pol, Int_t ant1, Int_t ant2)
Turns internal upsampled correlation arrays into TGraphs to be seen by humans.
std::vector< Double_t > rArray[NUM_POL]
Vector of antenna radial positions.
std::vector< TThread * > corrThreads
TThreads for doing cross correlations.
Double_t zoomedPhiWaveLookup[NUM_BINS_PHI_ZOOM_TOTAL]
Cached phi for zoomed image.
Int_t threadPhiSector
phi-sector to use in thread functions.
TGraph * grs[NUM_POL][NUM_SEAVEYS]
Raw waveforms obtained from the UsefulAnitaEvent.
void reconstructEvent(UsefulAnitaEvent *usefulEvent, Int_t numFinePeaks=MAX_NUM_PEAKS, Int_t numCoarsePeaks=MAX_NUM_PEAKS)
Reconstruct event.
Double_t coarseMapPeakThetaDegs[NUM_POL][MAX_NUM_PEAKS]
Stores the peak theta (degrees) of the interally stored map.
Double_t coarseMap[NUM_POL][NUM_BINS_PHI *NUM_PHI][NUM_BINS_THETA]
Internal storage for the coarsely binned map.
~CrossCorrelator()
Destructor.
TH2D * getZoomMap(AnitaPol::AnitaPol_t pol)
Gets an actual histogram of the zoomed in map.
TGraph * grsResampled[NUM_POL][NUM_SEAVEYS]
Evenly resampled TGraphs.
void do5PhiSectorCombinatorics()
Function to index all possible antenna pairs for use in reconstuction.
TString mapModeNames[kNumMapModes]
Maps text to the mapMode_t enum, used for histogram names/titles.
TH2D * getMap(AnitaPol::AnitaPol_t pol, Double_t &peakValue, Double_t &peakPhiDeg, Double_t &peakThetaDeg, UShort_t l3TrigPattern=ALL_PHI_TRIGS)
Gets an actual histogram of the zoomed in map.
Int_t kDoSimpleSatelliteFiltering
Does a simple 52MHz wide notch at 260 if flag is greater than 0.
void printInfo()
Prints some summary information about the CrossCorrelator to stdout.
Double_t threadPeakPhiDeg[NUM_THREADS]
Store phi of image peaks found by different threads.
void correlateEvent(UsefulAnitaEvent *realEvent)
Correlate the event.
Int_t kUseOffAxisDelay
Flag for whether or not to apply off axis delay to deltaT expected.
static void * makeSomeOfZoomImageThreaded(void *voidPtrArgs)
Static member function which fills the interferometric maps.
Int_t getPhiSectorOfAntennaClosestToPhiDeg(AnitaPol::AnitaPol_t pol, Double_t phiDeg)
Finds the phi-sector closest to a particular phi direction.
Double_t part21sZoom[NUM_POL][NUM_COMBOS][NUM_BINS_PHI_ZOOM_TOTAL]
Yet more geometric caching.
Double_t interpRMS[NUM_POL][NUM_SEAVEYS]
RMS of interpolated TGraphs.
UInt_t eventNumber[NUM_POL]
For tracking event number.
void reconstruct(AnitaPol::AnitaPol_t pol, Double_t &imagePeak, Double_t &peakPhiDeg, Double_t &peakThetaDeg)
Wrapper function which launches the threaded functions, which fill the interferometric maps...
std::vector< TThread * > mapThreads
TThreads for doing interferometric map making.
std::complex< Double_t > ffts[NUM_POL][NUM_SEAVEYS][GETNUMFREQS(NUM_SAMPLES *PAD_FACTOR)]
FFTs of evenly resampled waveforms.
void getFinePeakInfo(AnitaPol::AnitaPol_t pol, Int_t peakIndex, Double_t &value, Double_t &phiDeg, Double_t &thetaDeg)
Gets the results from the fine reconstruction.
UInt_t threadL3TrigPattern
l3TrigPattern to use in thread functions.
Double_t zoomedCosPartLookup[NUM_POL][NUM_SEAVEYS][NUM_BINS_PHI_ZOOM_TOTAL]
Cached part of the deltaT calculation.
std::complex< Double_t > fftsPadded[NUM_POL][NUM_SEAVEYS][GETNUMFREQS(NUM_SAMPLES *PAD_FACTOR *UPSAMPLE_FACTOR)]
FFTs of evenly resampled waveforms, padded with zeros so that the inverse fourier transform is interp...
Double_t offAxisDelays[NUM_POL][NUM_COMBOS][NUM_BINS_PHI_ZOOM_TOTAL]
Off-axis delays for fine binned images.
static void * makeSomeOfImageThreaded(void *voidPtrArgs)
Static member function which fills the interferometric maps.
CrossCorrelator()
Constructor.
zoomMode_t
Flag to pass to CrossCorrelator when making a map telling it whether to reconstruct all arrival direc...
Double_t crossCorrelations[NUM_POL][NUM_COMBOS][NUM_SAMPLES *PAD_FACTOR]
Cross correlations.
void renormalizeFourierDomain(AnitaPol::AnitaPol_t pol, Int_t ant)
Scales the fft such that the inverse fft would have mean=0 and rms=1. For use after notching...
Double_t zoomedThetaWaves[NUM_BINS_THETA_ZOOM_TOTAL]
Cached theta for zoomed image.
void doAllCrossCorrelationsThreaded(AnitaPol::AnitaPol_t pol)
Wrapper function which launches the threads for generating all the cross correlations.
TGraph * getCrossCorrelationGraph(AnitaPol::AnitaPol_t pol, Int_t ant1, Int_t ant2)
Turns internal correlation arrays into TGraphs to be seen by humans.
TH2D * makeTriggeredImage(AnitaPol::AnitaPol_t pol, Double_t &imagePeak, Double_t &peakPhiDeg, Double_t &peakThetaDeg, UShort_t l3TrigPattern)
Creates an interferometric map using plane wave deltaTs and l3Triggered pairs from all phi-sectors...
CrossCorrelator * ptr
Pointer to the CrossCorrelator.
Double_t getDeltaTExpected(AnitaPol::AnitaPol_t pol, Int_t ant1, Int_t ant2, Double_t phiWave, Double_t thetaWave)
Function to calculate the time taken by a plane wave to cross the payload.
void simple370MHzSatelliteNotch(AnitaPol::AnitaPol_t pol, Int_t ant)
Applies a 40MHz wide notch centered at 370 MHz to filter another satellite frequency.
std::vector< Int_t > combosToUseGlobal[NUM_PHI]
Depends on L3 trigger for global image.
Double_t interpRMS2[NUM_POL][NUM_SEAVEYS]
RMS of interpolated TGraphs with extra zero padding.
Double_t correlationDeltaT
nominalSamplingDeltaT/UPSAMPLE_FACTOR, deltaT of for interpolation.
Double_t partBAsZoom[NUM_POL][NUM_COMBOS][NUM_BINS_THETA_ZOOM_TOTAL]
Yet more geometric caching.
Double_t getBin0PhiDeg()
Single function to get the angle of the first bin of the interferometric histogram.
void doFFTs(AnitaPol::AnitaPol_t pol)
Takes FFTs of the normalized, evenly resampled waveforms and puts them in memory. ...
Long_t threadInd
The thread index.
Double_t fineMapPeakValues[NUM_POL][MAX_NUM_PEAKS]
Stores the peak of the interally stored map.
void fillDeltaTLookup()
Fills in an array of cached deltaTs between antenna pairs as a function of arrival direction...
std::set< std::vector< int > >::iterator comboSetIterator[NUM_BINS_THETA][NUM_BINS_PHI *NUM_PHI]
Pointer to a vector of combo indices (actually an iterator over a set, but you know what I mean)...
Int_t kOnlyThisCombo
For debugging, only fill histograms with one particular antenna pair.
std::vector< Int_t > comboToAnt1s
Vector mapping combo index to ant1.
TGraph * makeCoherentlySummedWaveform(AnitaPol::AnitaPol_t pol, Double_t phiDeg, Double_t thetaDeg, Int_t maxDeltaPhiSect, Double_t &snr)
Creates the coherently summed waveform from the FFTs held in memory.
AnitaPol::AnitaPol_t threadPol
Polarization to use in thread functions.
std::vector< Double_t > zArray[NUM_POL]
Vector of antenna heights.
void getCoarsePeakInfo(AnitaPol::AnitaPol_t pol, Int_t peakIndex, Double_t &value, Double_t &phiDeg, Double_t &thetaDeg)
Gets the results from the coarse reconstruction.
std::vector< Int_t > comboToAnt2s
Vector mapping combo index to ant2.
TGraph * interpolateWithStartTimeAndZeroMean(TGraph *grIn, Double_t startTime, Double_t dt, Int_t nSamp)
Creates an interpolated TGraph with zero mean.
Double_t coarseMapPeakValues[NUM_POL][MAX_NUM_PEAKS]
Stores the peak of the interally stored map.
Int_t numSamples
Number of samples in waveform after padding.
TH2D * initializeNewCombinatorics()
static Int_t directlyInsertGeometry(TString pathToLindasFile, AnitaPol::AnitaPol_t pol)
Used to insert phase center geometry files from Linda.
Double_t relativeOffAxisDelay(AnitaPol::AnitaPol_t pol, Int_t ant1, Int_t ant2, Double_t phiDeg)
Get the relative off-axis delay between an antenna pair.
TH2D * makeZoomedImage(AnitaPol::AnitaPol_t pol, UShort_t l3TrigPattern, Double_t zoomCenterPhiDeg, Double_t zoomCenterThetaDeg)
Creates an interferometric map using plane wave deltaTs centered around a particular phi/theta...
Double_t coarseMapPeakPhiDegs[NUM_POL][MAX_NUM_PEAKS]
Stores the peak phi (degrees) of the interally stored map.
void simpleNotch(AnitaPol::AnitaPol_t pol, Int_t ant, Double_t notchLowEdgeMHz, Double_t notchHighEdgeMHz)
Applies a simple notch between the given frequencies.
Container required to get threading to work inside a class, includes the thread index and the pointer...
Int_t numCombos
Number of possible antenna pairs, counted during initialization. Should equal NUM_COMBOS.
void getNormalizedInterpolatedTGraphs(UsefulAnitaEvent *realEvent, AnitaPol::AnitaPol_t pol)
Makes evenly re-sampled, normalized waveform graphs from the UsefulAnitaEvent.
void initializeVariables()
Workhorse function to set internal variables.
void getMaxUpsampledCorrelationTimeValue(AnitaPol::AnitaPol_t pol, Int_t combo, Double_t &time, Double_t &value)
Get the maximum upsampled correlation time and value from a polarization and antenna combo index...
Double_t phiWaveLookup[NUM_BINS_PHI *NUM_PHI]
Cached phi for image.
static void * doSomeUpsampledCrossCorrelationsThreaded(void *voidPtrArgs)
Static member function which generates the finely binned set of cross correlations from the FFTs held...
void insertPhotogrammetryGeometry()
Inserts the photogrammetry geometry into the CrossCorrelator internals AND the AnitaEventCalibrator i...
Double_t nominalSamplingDeltaT
ANITA-3 => 1./2.6 ns, deltaT for evenly resampling.
Double_t interpPreFactors[NUM_POL][NUM_COMBOS][NUM_PHI *NUM_BINS_PHI][NUM_BINS_THETA]
The interpolation factor for neighbouring samples.
Double_t thetaWaves[NUM_BINS_THETA]
Cached theta for image.
TGraph * makeUpsampledCoherentlySummedWaveform(AnitaPol::AnitaPol_t pol, Double_t phiDeg, Double_t thetaDeg, Int_t maxDeltaPhiSect, Double_t &snr)
Creates the coherently summed waveform from the zero padded FFTs held in memory.
void doUpsampledCrossCorrelationsThreaded(AnitaPol::AnitaPol_t pol, Int_t phiSector)
Static member function which generates the finely binned set of cross correlations from the FFTs held...
Double_t zoomedTanThetaWaves[NUM_BINS_THETA_ZOOM_TOTAL]
Cached tan(theta) for zoomed image.
Double_t maxDPhiDeg
Variable for testing how wide an off axis angle is used in reconstruction.
Double_t threadPeakThetaDeg[NUM_THREADS]
Store theta of image peaks found by different threads.
mapMode_t
Flag to pass to CrossCorrelator when making a map telling it whether to use all phi-sectors or trigge...
TGraph * makeCoherentWorker(AnitaPol::AnitaPol_t pol, Double_t phiDeg, Double_t thetaDeg, Int_t maxDeltaPhiSect, Double_t &snr, Int_t nSamp)
Worker function to create the coherently summed waveform from either the regular ffts or the padded f...
void getMaxCorrelationTimeValue(AnitaPol::AnitaPol_t pol, Int_t combo, Double_t &time, Double_t &value)
Get the maximum correlation time and value from a polarization and antenna combo index.
std::vector< Double_t > phiArrayDeg[NUM_POL]
Vector of antenna azimuth positions.
void reconstructZoom(AnitaPol::AnitaPol_t pol, Double_t &imagePeak, Double_t &peakPhiDeg, Double_t &peakThetaDeg, Double_t zoomCenterPhiDeg=0, Double_t zoomCenterThetaDeg=0)
Wrapper function which launches the threaded functions, which fill the zoomed maps.
void simple260MHzSatelliteNotch(AnitaPol::AnitaPol_t pol, Int_t ant)
Applies a 52MHz wide notch centered at 260 MHz to filter the most problematic satellite frequency...
Double_t crossCorrelationsUpsampled[NUM_POL][NUM_COMBOS][NUM_SAMPLES *PAD_FACTOR *UPSAMPLE_FACTOR *PAD_FACTOR]
Upsampled cross correlations.
Bool_t useCombo(Int_t ant1, Int_t ant2, Int_t phiSector, Int_t deltaPhiSect)
This function encodes whether a pair of antennas should be used in a particular phi sector...
Double_t fineMapPeakThetaDegs[NUM_POL][MAX_NUM_PEAKS]
Stores the peak theta (degrees) of the interally stored map.
Double_t getInterpolatedUpsampledCorrelationValue(AnitaPol::AnitaPol_t pol, Int_t combo, Double_t deltaT)
Linearly interpolates between upsampled correlation points.
Double_t zoomedCosThetaWaves[NUM_BINS_THETA_ZOOM_TOTAL]
Cached cos(theta) for zoomed image.
Double_t fineMapPeakPhiDegs[NUM_POL][MAX_NUM_PEAKS]
Stores the peak phi (degrees) of the interally stored map.