UsefulAnitaEvent.cxx
1 
10 #include "UsefulAnitaEvent.h"
11 #include "CalibratedAnitaEvent.h"
12 #include "AnitaGeomTool.h"
13 #include "PrettyAnitaHk.h"
14 #include "RawAnitaHeader.h"
15 #include "AnitaEventCalibrator.h"
16 #include <TGraph.h>
17 #include <iostream>
18 #include <fstream>
19 #include <cstring>
20 #include "AnitaVersion.h"
21 
22 ClassImp(UsefulAnitaEvent);
23 
24 
25 AnitaEventCalibrator* fCalibrator = NULL;
26 
27 
29  : RawAnitaEvent()
30 {
31  gotCalibTemp=0;
33  fC3poNum=0;
35  fCalibrator=0;
36  fRFSpike = 0;
37  setAlfaFilterFlag(false);
38 
39  //Default Constructor
40 }
41 
42 
44  : RawAnitaEvent(*calibratedPtr)
45 {
46 
47  // std::cout << __PRETTY_FUNCTION__ << std::endl;
48  fCalibrator=0;
50  // fC3poNum=calibratedPtr->fC3poNum;
51  fLastEventGuessed=calibratedPtr->eventNumber;
52  gotCalibTemp=0;
53  fClockProblem = calibratedPtr->fClockProblem;
54  fClockSpike = calibratedPtr->fClockSpike;
55  fRFSpike = calibratedPtr->fRFSpike;
56  for(int surf=0;surf<NUM_SURF;surf++) {
57  fRcoArray[surf]=calibratedPtr->fRcoArray[surf];
58  fClockPhiArray[surf]=calibratedPtr->fClockPhiArray[surf];
59  fTempFactorGuesses[surf]=calibratedPtr->fTempFactorGuesses[surf];
60  }
61  fCalType=calType;
63  setAlfaFilterFlag(AnitaVersion::get() == 3);
64 }
65 
66 
67 UsefulAnitaEvent::UsefulAnitaEvent(RawAnitaEvent *eventPtr,WaveCalType::WaveCalType_t calType, RawAnitaHeader* theHd, std::vector<Double_t>* rcoInfo, std::vector<Double_t>* clockPhiInfo, std::vector<Double_t>* tempFactorInfo, Int_t clockProblemInfo, Int_t clockSpikeInfo, Int_t rfSpikeInfo)
68  : RawAnitaEvent(*eventPtr)
69 {
70 
71  AnitaVersion::setVersionFromUnixTime(theHd->realTime);
72  // std::cout << __PRETTY_FUNCTION__ << std::endl;
73  fCalibrator=0;
75  // fC3poNum=calibratedPtr->fC3poNum;
77  gotCalibTemp=0;
78  fClockProblem = clockProblemInfo;
79  fClockSpike = clockSpikeInfo;
80  fRFSpike = rfSpikeInfo;
81  for(int surf=0;surf<NUM_SURF;surf++) {
82  fRcoArray[surf]=rcoInfo->at(surf);
83  fClockPhiArray[surf]=clockPhiInfo->at(surf);
84  fTempFactorGuesses[surf]=tempFactorInfo->at(surf);
85  }
86  fCalType=calType;
88  setAlfaFilterFlag(AnitaVersion::get() == 3);
89 }
90 
91 
93  : RawAnitaEvent(*eventPtr)
94 {
95 
96 
97  if(theHk){
98  //In this case, we can automatically detect the ANITA version
99  AnitaVersion::setVersionFromUnixTime(theHk->realTime);
100  }
101 
102  checkIfTreatingCalibratedEventAsRawEvent(eventPtr, __PRETTY_FUNCTION__);
103 
104  fCalibrator=0;
107  if(theHk) {
108  gotCalibTemp=1;
109  calibTemp=theHk->intTemps[2];
110  }
111  else{
112  gotCalibTemp=0;
113  }
114  fRFSpike = 0;
115 
116  setAlfaFilterFlag(AnitaVersion::get() == 3);
117  calibrateEvent(calType);
118 }
119 
121  : RawAnitaEvent(*eventPtr)
122 {
123 
124  //In this case, we can automatically detect the ANITA version
125  AnitaVersion::setVersionFromUnixTime(theHd->realTime);
126 
127  checkIfTreatingCalibratedEventAsRawEvent(eventPtr, __PRETTY_FUNCTION__);
128 
129  fCalibrator=0;
131  fC3poNum=theHd->c3poNum;
133  gotCalibTemp=0;
134  fClockProblem = 0;
135  fClockSpike = 0;
136  fRFSpike = 0;
137 
138 
139  setAlfaFilterFlag(AnitaVersion::get() == 3);
140 
141  if(theHd->eventNumber != eventPtr->eventNumber){
142  std::cerr << "Warning! eventNumber mismatch in " << __FILE__ << " line " << __LINE__ << "." << std::endl;
143  std::cerr << "RawAnitaHeader->eventNumber = " << theHd->eventNumber << " but "
144  << "UsefulAnitaEvent->eventNumber = " << eventPtr->eventNumber
145  << std::endl;
146  }
147 
148  calibrateEvent(calType);
149 }
150 
152  : RawAnitaEvent(*eventPtr)
153 {
154 
155  checkIfTreatingCalibratedEventAsRawEvent(eventPtr, __PRETTY_FUNCTION__);
156 
157  fCalibrator=0;
159  gotCalibTemp=1;
160  calibTemp=surfTemp;
161  fRFSpike = 0;
162  setAlfaFilterFlag(false);
163 
164  calibrateEvent(calType);
165 }
166 
168  //Default Destructor
169 }
170 
172 {
173  fCalibrator=AnitaEventCalibrator::Instance();
174  fCalibrator->calibrateUsefulEvent(this,calType);
175  return 0;
176 }
177 
178 TGraph *UsefulAnitaEvent::getGraphFromSurfAndChan(int surf, int chan) const
179 {
180  return getGraph(getChanIndex(surf,chan));
181 }
182 
183 TGraph *UsefulAnitaEvent::getGraph(int chanIndex) const
184 {
185  if(chanIndex<0 || chanIndex>=NUM_DIGITZED_CHANNELS)
186  return NULL;
187  // std::cout << chanIndex << std::endl;
188 
189  int N = TMath::Min(fNumPoints[chanIndex], NUM_SAMP);
190 
191  TGraph *grPtr=new TGraph(N,
192  fTimes[chanIndex],
193  fVolts[chanIndex]);
194 
195 #ifdef USE_FFT_TOOLS
196  // let's try the simplest thing first
197  const int alfaChannelIndex = 11*NUM_CHAN + 5;
198  if(fFilterAlfaChannel==true && chanIndex==alfaChannelIndex){
199  const double lowPassFreq = 700; // MHz
200  TGraph* grFiltered = FFTtools::simplePassBandFilter(grPtr, 0, lowPassFreq);
201  delete grPtr;
202  grPtr = grFiltered;
203  }
204 #endif
205  return grPtr;
206 }
207 
208 
209 TGraph *UsefulAnitaEvent::getDeconvolvedALFA()
210 {
211  // todo...
212 
213  // You should put the code that uses FFTtools inside the include guard.
214 #ifdef USE_FFT_TOOLS
215  //
216 #endif
217 
218  return NULL;
219 }
220 
221 
223  //Antenna numbers count from 0
225 
226 }
227 
229  int phi,
230  AnitaPol::AnitaPol_t pol) const{
231  //Phi numbers count from 0
233 
234 }
235 
236 
237 Int_t UsefulAnitaEvent::guessRco(int chanIndex){
238  // deprecated...
239 
240  Int_t surf = chanIndex / NUM_CHAN;
241  return fRcoArray[surf];
242 
243  //RJN removed clock guessing for now.
244  // if(fLastEventGuessed!=this->eventNumber)
245  // analyseClocksForGuesses();
246  // // if(
247  // return fRcoArray[chanIndex/9];
248  //return getRCO(chanIndex);
249  return -1;
250 }
251 
253 
254 {
255  int rcoFirm = this->getRCO(chanIndex);
256  int rcoSoft = 1-rcoFirm;
257  return rcoSoft;
258 }
259 
260 
261 // std::vector<std::vector<Double_t> > UsefulAnitaEvent::getNeighbouringClockCorrelations(Double_t lowPassClockFilterFreq, Int_t giveGraphsToInputArrays, TGraph* grInterpClocksArray[NUM_SURF], TGraph* grCorClocksArray[NUM_SURF][2]){
262 // return fCalibrator->getNeighbouringClockCorrelations(this, lowPassClockFilterFreq,
263 // giveGraphsToInputArrays,
264 // grInterpClocksArray,
265 // grCorClocksArray);
266 // }
267 
268 
269 // std::vector<std::vector<Double_t> > UsefulAnitaEvent::getNeighbouringClockCorrelations2(bool writeGraphs){
270 // return fCalibrator->getNeighbouringClockCorrelations2(this, writeGraphs);
271 // }
272 
273 
274 std::vector<Double_t> UsefulAnitaEvent::getClockAlignment(std::vector<Int_t> listOfClockNums){
275  // std::cout << __PRETTY_FUNCTION__ << "\t" << fCalibrator->numPointsArray << std::endl;
276  // for(Int_t surf=0; surf<NUM_SURF; surf++){
277  // std::cout << fCalibrator->numPointsArray[surf] << std::endl;
278  // }
279  return fCalibrator->getClockAlignment(this,
280  fCalibrator->numPointsArray,
281  fCalibrator->voltsArray,
282  fCalibrator->timeArray,
283  listOfClockNums);
284 }
285 
286 
288  // This function is a check that you're not treating a CalibratedAnitaEvent as a RawAnitaEvent.
289  // If you are then it will print a warning.
290 
291  // There is probably some alternative that could cause things to fail to compile... would that be better?
292  // Is a it better to turn a bug into a run-time warning or a compile time error?
293  // Anyway, enough philosophising...
294 
295 
296  // This line should return NULL if you can't dynamically cast the rawEventPtr as a pointer to a CalibratedAnitaEvent.
297  // i.e. if the pointer really is of type RawAnitaEvent this will return NULL.
298 
299  CalibratedAnitaEvent* calEventPtr = dynamic_cast<CalibratedAnitaEvent*>(rawEventPtr);
300 
301  // If you can cast it as a pointer to a CalibratedAnitaEvent...
302  if(calEventPtr){
303  // ... then this is a calibratedAnitaEvent getting treated like a RawAnitaEvent, i.e. being calibrated on the fly.
304  // At best this slow. At worst this will mess up things like the rolling temperature correction.
305  // Now I will fill your terminal with warnings so verbose you will hate me.
306 
307  std::cerr << "WARNING in " << funcName << ":" << std::endl;
308  std::cerr << "\tCalling constructor that that takes a RawAnitaEvent* with a CalibratedAnitaEvent*. " << std::endl;
309  std::cerr << "\tThe CalibratedAnitaEvent numbers are not being applied but are being recalculated on the fly." << std::endl;
310  std::cerr << "\tAt best this is slow. At worst this could change rolling averages." << std::endl;
311  std::cerr << "\tPlease use the constructor that takes a CalibratedAnitaEvent* instead." << std::endl;
312  return 1;
313  }
314  else{
315  // If it really is a RawAnitaEvent, then that's fine.
316  return 0;
317  }
318 }
319 
320 
322 #ifdef USE_FFT_TOOLS
323  return fFilterAlfaChannel;
324 #else
325  return false;
326 #endif
327 }
328 
329 Bool_t UsefulAnitaEvent::setAlfaFilterFlag(Bool_t newBoolianFlag){
330 #ifdef USE_FFT_TOOLS
331  fFilterAlfaChannel = newBoolianFlag;
332 #else
333  fFilterAlfaChannel = false;
334 #endif
335  return fFilterAlfaChannel;
336 }
UInt_t eventNumber
Event number from software.
Definition: RawAnitaEvent.h:33
Double_t fClockPhiArray[12]
An array to store the clock offsets.
Double_t fTempFactorGuesses[12]
A holder variable to cling on to the temperature correction factor that we are guessing at...
Int_t numPointsArray[12]
Number of samples in each channel.
Int_t checkIfTreatingCalibratedEventAsRawEvent(RawAnitaEvent *rawEventPtr, const char *funcName)
Prints a verbose error message if you&#39;re calling the wrong constructor type.
Float_t intTemps[19]
Internal temperatures, includes extra sbsTemps.
Definition: PrettyAnitaHk.h:54
UInt_t fLastEventGuessed
Internal variable to see if we&#39;ve already tried to guess the RCO and temp correction factors for this...
Int_t getRcoCorrected(int chanIndex)
Returns firmware RCO after correcting for latch delay (and factor of -1 for different definitions of ...
enum WaveCalType::EWaveCalType WaveCalType_t
The calibration enumeration type.
PrettyAnitaHk – The prettified ANITA Hk.
Definition: PrettyAnitaHk.h:22
static AnitaEventCalibrator * Instance(int version=0)
Instance generator.
double fVolts[12 *9][260]
Array of unwrapped (unless kNoCalib) voltages for each channel.
static Int_t getChanIndexFromAntPol(Int_t ant, AnitaPol::AnitaPol_t pol)
Convert ant-pol to logical index.
static Int_t getChanIndexFromRingPhiPol(AnitaRing::AnitaRing_t ring, Int_t phi, AnitaPol::AnitaPol_t pol)
Convert ring-phi-pol to logical index.
int fNumPoints[12 *9]
Number of poins per channel.
UsefulAnitaEvent()
Default constructor.
Int_t calibrateUsefulEvent(UsefulAnitaEvent *eventPtr, WaveCalType::WaveCalType_t calType)
Calibration Routine The routine that is used to calibrate the voltage time waveforms in a UsefulAnita...
Int_t gotCalibTemp
Flag to check if we are using the temperature calibration.
Int_t getRCO(Int_t chanIndex) const
Returns the RCO phase.
Definition: RawAnitaEvent.h:71
std::vector< Double_t > getClockAlignment(std::vector< Int_t > listOfClockNums)
For calibration.
RawAnitaHeader – The Raw ANITA Event Header.
AnitaEventCalibrator – The ANITA Event Calibrator.
Double_t voltsArray[12][9][260]
Channel volts in mV.
TGraph * getGraphFromSurfAndChan(int surf, int chan) const
Returns a voltage-time waveform for given SURF and channel.
int calibrateEvent(WaveCalType::WaveCalType_t calType)
Work horse member function called by constructor.
enum AnitaRing::EAnitaRing AnitaRing_t
Ring enumeration.
UInt_t realTime
Time in unixTime.
Definition: PrettyAnitaHk.h:51
virtual ~UsefulAnitaEvent()
Destructor.
Bool_t getAlfaFilterFlag()
a list to store the spikey RF channel.
Int_t fClockProblem
Flag raised if more than 4 upgoing zero crossings in clock, won&#39;t update temp correction. RCO guessing may also be negatively affected by this.
TGraph * getGraph(int chanIndex) const
Returns a voltage-time waveform for given channel index.
UsefulAnitaEvent – The Calibrated Useful Anita Event object.
UInt_t c3poNum
Number of TURF clock ticks between GPS pulse per seconds.
Double_t calibTemp
Value for the temperature calibration.
Int_t fRcoArray[12]
An array to store the guessed at RCO values;.
CalibratedAnitaEvent – The Calibrated Calibrated Anita Event object.
UInt_t fC3poNum
Used to monitor the clock period.
static int getChanIndex(int surf, int chan)
Utility function.
Double_t fTempFactorGuesses[12]
A holder variable to cling on to the temperature correction factor that we are guessing at...
Double_t timeArray[12][260]
Channel times in ns.
Int_t fRFSpike
Flag raised if the ADC value is too large or small in RF.
WaveCalType::WaveCalType_t fCalType
The calibration type requested.
Int_t fRcoArray[12]
An array to store the guessed at RCO values.
Int_t guessRco(int chanIndex)
Looks at clock channel to try and guess which RCO phase we are in.
TGraph * simplePassBandFilter(const TGraph *grWave, Double_t minFreq, Double_t maxFreq)
This returns a TGraph which has had a simple pass band filter applied.
Definition: FFTtools.cxx:1938
Int_t fFromCalibratedAnitaEvent
Flag used in determining whether the event came from a CalibratedAnitaEvent.
UInt_t realTime
unixTime of readout
enum AnitaPol::EAnitaPol AnitaPol_t
Polarisation enumeration.
Double_t fClockPhiArray[12]
An array to store the derived clock calibration numbers (from aligning the clocks) ...
Int_t fClockSpike
Flag raised if the ADC value is too large or small in clock.
double fTimes[12 *9][260]
Array of unwrapped (unless kNoCalib) times for each channel.
RawAnitaEvent – The Raw ANITA Event Data.
Definition: RawAnitaEvent.h:22