AnitaAveragePowerSpectrum.cxx
1 #include "AnitaAveragePowerSpectrum.h"
2 
3 
4 
5 
6 //---------------------------------------------------------------------------------------------------------
13 
14  fName = "AnitaAveragePowerSpectrum";
15  fTitle = "Anita Average Power Spectrum";
16 
17  // Default constructor, just zero internals
18  for(Int_t polInd = 0; polInd < AnitaPol::kNotAPol; polInd++){
19  for(Int_t ant=0; ant<NUM_SEAVEYS; ant++){
20  avePowSpecs[polInd][ant] = NULL;
21  }
22  }
23 
24 }
25 
26 
27 
28 
29 //---------------------------------------------------------------------------------------------------------
37 
38  // Record initialization options for contained AveragePowerSpectra
39  fName = name;
40  fTitle = title;
41 
42  // Initialize them.
43  initAllAvePowSpecs();
44 }
45 
46 
47 
48 
49 
50 //---------------------------------------------------------------------------------------------------------
55  deleteAllAvePowSpecs();
56 }
57 
58 
59 
60 
61 
62 //---------------------------------------------------------------------------------------------------------
66 void AnitaAveragePowerSpectrum::deleteAllAvePowSpecs(){
67  // Delete all non-null internals
68  for(Int_t polInd = 0; polInd < AnitaPol::kNotAPol; polInd++){
69  for(Int_t ant=0; ant<NUM_SEAVEYS; ant++){
70 
71  if(avePowSpecs[polInd][ant]!=NULL){
72  delete avePowSpecs[polInd][ant];
73  avePowSpecs[polInd][ant] = NULL;
74  }
75  }
76  }
77 }
78 
79 
80 
81 
82 
83 //---------------------------------------------------------------------------------------------------------
89 void AnitaAveragePowerSpectrum::initAllAvePowSpecs(){
90  // Initialize the power spectra from options recorded in constructor
91 
92  for(Int_t polInd = 0; polInd < AnitaPol::kNotAPol; polInd++){
93  for(Int_t ant=0; ant<NUM_SEAVEYS; ant++){
94 
95  TString name = fName + TString::Format("_%d_%d", polInd, ant);
96 
97  TString title = RootTools::getAntName(AnitaPol::AnitaPol_t(polInd), ant);
98 
99  avePowSpecs[polInd][ant] = new AveragePowerSpectrum(name, title);
100  }
101  }
102 }
103 
104 
105 
106 
107 
108 
109 //---------------------------------------------------------------------------------------------------------
116 AveragePowerSpectrum* AnitaAveragePowerSpectrum::get(AnitaPol::AnitaPol_t pol, Int_t ant){
117  // Getter function with array size checks
118  AveragePowerSpectrum* avePowSpecPtr = NULL;
119  if(ant >= 0 && ant < NUM_SEAVEYS){
120  avePowSpecPtr = avePowSpecs[pol][ant];
121  }
122  return avePowSpecPtr;
123 }
124 
125 
126 
127 
128 
129 //---------------------------------------------------------------------------------------------------------
137 void AnitaAveragePowerSpectrum::add(AnitaPol::AnitaPol_t pol, Int_t ant, TGraph* gr){
138  // Wrapper for adding waveform to particular channels power spectrum
139  AveragePowerSpectrum* avePowSpecPtr = get(pol, ant);
140  avePowSpecPtr->add(gr);
141 }
142 
143 
144 
145 
146 
147 //---------------------------------------------------------------------------------------------------------
152  // Function to delete and reinitialize all contained AveragePowerSpectra
153  deleteAllAvePowSpecs();
154  initAllAvePowSpecs();
155 }
156 
157 
158 
159 
160 
161 //---------------------------------------------------------------------------------------------------------
171 TMultiGraph* AnitaAveragePowerSpectrum::drawSpectralSummary(AnitaPol::AnitaPol_t pol, AnitaRing::AnitaRing_t ring){
172  TMultiGraph* mg = new TMultiGraph();
173 
174  TString grTitle = TString::Format("%s PSDs", fTitle.Data());
175 
176  switch (ring){
177  case AnitaRing::kTopRing:
178  grTitle += " Top ring";
179  break;
180  case AnitaRing::kMiddleRing:
181  grTitle += " Middle ring";
182  break;
183  case AnitaRing::kBottomRing:
184  grTitle += " Bottom ring";
185  break;
186  case AnitaRing::kNotARing:
187  break;
188  }
189 
190  grTitle += pol == AnitaPol::kHorizontal ? " HPol " : " VPol ";
191 
192  grTitle += ";Frequency (MHz); PSD (mV^{2}/MHz)";
193 
194  // std::cout << grTitle.Data() << std::endl;
195  mg->SetTitle(grTitle);
196  for(int phi=0; phi<NUM_PHI; phi++){
197  Int_t ant = ring*NUM_PHI + phi;
198  AveragePowerSpectrum* aps = get(pol, ant);
199  TGraph* gr = aps->makeAvePowSpecTGraph_dB();
200  gr->SetLineColor(gStyle->GetColorPalette(phi*Int_t(254./(NUM_PHI-1))));
201  gr->SetFillColorAlpha(0, 0);
202  mg->Add(gr);
203  }
204 
205  return mg;
206 }
void add(AnitaPol::AnitaPol_t pol, Int_t ant, TGraph *gr)
Add a waveform TGraph to an internal AveragePowerSpectrum.
void reset()
Deletes and reinitializes all internal AveragePowerSpectrums.
AveragePowerSpectrum * get(AnitaPol::AnitaPol_t pol, Int_t ant)
Access internal AveragePowerSpectrum.
TMultiGraph * drawSpectralSummary(AnitaPol::AnitaPol_t pol, AnitaRing::AnitaRing_t ring)
Get a ring of TGraphs of a single polarization as a TMultiGraph.
TGraph * makeAvePowSpecTGraph_dB()
Creates a TGraph of the average power spectrum with a dB scale.
size_t add(TGraph *gr)
Function for the user to add the voltage/time waveform to all the stored averages.
Takes in waveforms and averages averages their power spectra.
TString getAntName(AnitaPol::AnitaPol_t pol, Int_t antInd)
Use polarization and index to get the antenna name (1st phi-sector called 1, not 0).
Definition: RootTools.cxx:1365