AnitaEventCalibrator.h
1 
9 #ifndef ANITAEVENTCALIBRATOR_H
10 #define ANITAEVENTCALIBRATOR_H
11 
12 // ROOT
13 #include <TObject.h>
14 #include <TF1.h>
15 #include <TH1.h>
16 #include <TMath.h>
17 #include <TGraph.h>
18 
19 #ifdef USE_FFT_TOOLS
20 #include "FFTtools.h"
21 #endif
22 
23 // std lib
24 #include <fstream>
25 #include <map>
26 #include <bitset>
27 
28 // Anita
29 #include "AnitaConventions.h"
30 #include "simpleStructs.h"
31 #include "AnitaClock.h"
32 #include "AnitaGeomTool.h"
33 #include "RingBuffer.h"
34 #include "RawAnitaHeader.h"
35 
36 
37 
38 class TGraph;
39 class UsefulAnitaEvent;
40 
42 
46 class AnitaEventCalibrator : public TObject
47 {
48  public:
49 
50  virtual ~AnitaEventCalibrator();
51  static AnitaEventCalibrator* Instance(int version = 0);
52 
60  Int_t calibrateUsefulEvent(UsefulAnitaEvent *eventPtr,
62 
63  void guessRco(UsefulAnitaEvent* eventPtr);
64  void getTempFactors(UsefulAnitaEvent* eventPtr);
66  Int_t unwrapChannel(UsefulAnitaEvent* eventPtr, Int_t surf, Int_t chan, Int_t rco,
67  Bool_t fApplyTempCorrection, Bool_t fAddPedestal,
68  Double_t* voltsArray, Double_t* timeArray, Int_t* scaArray);
69  void applyVoltageCalibration(UsefulAnitaEvent* eventPtr);
70  void keepOnlySomeTimeAfterClockUptick(TGraph* grClock, Double_t deltaClockKeepNs);
71 
72  std::vector<Double_t> getClockAlignment(UsefulAnitaEvent* eventPtr,
73  Int_t numPoints[NUM_SURF],
74  Double_t volts[NUM_SURF][NUM_CHAN][NUM_SAMP],
75  Double_t times[NUM_SURF][NUM_SAMP]);
76  std::vector<Double_t> getClockAlignment(UsefulAnitaEvent* eventPtr,
77  Int_t numPoints[NUM_SURF],
78  Double_t volts[NUM_SURF][NUM_CHAN][NUM_SAMP],
79  Double_t times[NUM_SURF][NUM_SAMP],
80  std::vector<Int_t> listOfClockNums);
81  void deleteClockAlignmentTGraphs();
82  void zeroMeanNonClockChannels();
83 
84  Double_t getTimeOfZeroCrossing(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
85  Int_t getTimeOfUpwardsClockTicksCrossingZero(Int_t numPoints, Int_t surf, Double_t* times,
86  Double_t* volts,
87  std::vector<Double_t>& timeZeroCrossings,
88  std::vector<Int_t>& sampZeroCrossings,
89  bool raiseFlagIfClocksAreWeird);
90 
91  void findExtremaSamples(Int_t length, Double_t* volts,
92  std::vector<Int_t>& maximaSamps,
93  std::vector<Int_t>& minimaSamps);
94 
95 
96  void initializeVectors();
97 
101 
102  // Primary event data: voltage and time arrays
103  Double_t voltsArray[NUM_SURF][CHANNELS_PER_SURF][NUM_SAMP];
104  Double_t timeArray[NUM_SURF][NUM_SAMP];
105  Int_t numPointsArray[NUM_SURF];
106  Int_t scaArray[NUM_SURF][NUM_SAMP];
107 
108  // Secondary event data
109  std::vector<std::vector<RingBuffer> > clockPeriodRingBuffers;
110  // RingBuffer* clockPeriodRingBuffer; ///< Holds rolling average of temperature correction
111  std::vector<Double_t> tempFactors;
112 
113 
114  // Int_t rcoArray[NUM_SURF]; ///< The output of AnitaEvenCalibrator::guessRco() goes here.
115  // Double_t measuredClockPeriods[NUM_SURF][NUM_RCO][AnitaClock::maxNumZcs]; ///< For guessRco and getTempFactor
116  std::vector<Int_t> rcoVector;
117  std::vector<std::vector<std::vector<Double_t> > > measuredClockPeriods;
118 
119  // Constants for timing/voltage calibration
120  Double_t relativeCableDelays[NUM_SURF][NUM_CHAN][NUM_CHIP];
121  Double_t relativePhaseCenterToAmpaDelays[NUM_SURF][NUM_CHAN];
122  Double_t deltaTs[NUM_SURF][NUM_CHIP][NUM_RCO][NUM_SAMP];
123  Double_t epsilons[NUM_SURF][NUM_CHIP][NUM_RCO];
124  Double_t mvCalibVals[NUM_SURF][NUM_CHAN][NUM_CHIP];
125 
126  // Constants for calibration algorithms
127  Double_t clockKeepTime[NUM_SURF][NUM_CHIP];
128  Int_t firstHitBusRcoLatchLimit;
129 
130 
131  std::vector<Int_t> defaultClocksToAlign;
132  std::vector<TGraph*> grClockInterps;
133  std::map<Double_t, TGraph*> grClock0s;
134  std::vector<TGraph*> grCorClock;
135  std::vector<TGraph*> grClocks;
136 
137 
138  std::vector<Double_t> clockAlignment;
139  Double_t dtInterp;
140  Double_t nominalDeltaT;
142  Int_t fClockSpike;
143 
144 
145  //Ben Rotter's rfPower calibration :)
146  Double_t convertRfPowTodBm(int surf, int chan, int adc);
147  Double_t convertRfPowToKelvin(int surf, int chan, int adc);
148 
149  Double_t RfPowYInt[NUM_SURF][NUM_CHAN];
150  Double_t RfPowSlope[NUM_SURF][NUM_CHAN];
151 
152 
153 
154  AnitaEventCalibrator(); // don't want multiple calibrators lying around for no reason
155 
156  private:
157 
158  // AnitaEventCalibrator(); // don't want multiple calibrators lying around for no reason
159  void loadCalib();
160  PedestalStruct_t fPedStruct;
161  ClassDef(AnitaEventCalibrator,0);
162 
163 };
164 
165 
166 #endif //ANITAEVENTCALIBRATOR_H
Int_t numPointsArray[12]
Number of samples in each channel.
std::vector< std::vector< RingBuffer > > clockPeriodRingBuffers
Holds rolling average of temperature correction.
Pedestal utility.
Double_t clockKeepTime[12][4]
How much time after clock up-tick to keep, calib food.
enum WaveCalType::EWaveCalType WaveCalType_t
The calibration enumeration type.
static AnitaEventCalibrator * Instance(int version=0)
Instance generator.
std::map< Double_t, TGraph * > grClock0s
Need to process clock 0 depending on needs of other SURF.
Double_t epsilons[12][4][2]
Calib constants: time (ns) for write pointer to go from sample 255 -> 0 (in ANITA-2 and ANITA-3 with ...
Double_t deltaTs[12][4][2][260]
Calib constants: The time for the write pointer to travel between successove capacitors.
Double_t dtInterp
Interpolating clock for alignment step.
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...
AnitaEventCalibrator – The ANITA Event Calibrator.
std::vector< Int_t > defaultClocksToAlign
List of SURFs for getClockAlignment() (for calibration progs)
void updateTemperatureCorrection(UsefulAnitaEvent *eventPtr)
Update RingBuffer for this event.
Double_t voltsArray[12][9][260]
Channel volts in mV.
void getTempFactors(UsefulAnitaEvent *eventPtr)
Interface to RingBuffer of clock periods for temperature correction.
std::vector< TGraph * > grClockInterps
Interpolated clocks.
UsefulAnitaEvent – The Calibrated Useful Anita Event object.
void guessRco(UsefulAnitaEvent *eventPtr)
Guess RCO from clock.
Double_t relativeCableDelays[12][9][4]
From AMPA inputs to digizier delays.
Int_t fClockSpike
Flag raised if the voltage is too large or too small in Surf clock.
Int_t unwrapChannel(UsefulAnitaEvent *eventPtr, Int_t surf, Int_t chan, Int_t rco, Bool_t fApplyTempCorrection, Bool_t fAddPedestal, Double_t *voltsArray, Double_t *timeArray, Int_t *scaArray)
Double_t nominalDeltaT
If we don&#39;t want bin-to-bin deltaTs.
Double_t relativePhaseCenterToAmpaDelays[12][9]
From phase center to AMPAs (hopefully)
Double_t timeArray[12][260]
Channel times in ns.
Int_t fClockProblem
Flag raised if more than 4 or less than 2 upgoing zero crossings in a SURF clock. ...
Int_t scaArray[12][260]
Capacitor numbers for each sample.
Double_t mvCalibVals[12][9][4]
Calib constants: converts from ADC counts to millivolts.
std::vector< Double_t > tempFactors
Multiplicative factor for deltaTs & epsilons accounting for temperature.
std::vector< Int_t > rcoVector
The output of AnitaEventCalibrator::guessRco() goes here.