TGraphAntarctica.cxx
1 #include "TGraphAntarctica.h"
2 #include "TROOT.h"
3 #include "TVirtualPad.h"
4 #include "Adu5Pat.h"
5 #include "AnitaDataset.h"
6 #include "TVirtualPad.h"
7 
8 ClassImp(TGraphAntarctica)
9 
10 
11 
18 TString makeSanitizedName(const char* name){
19  TString sanitizedName(name);
20 
21  // try to remove anything that would confuse getting this name
22  // from a file by typing the name on the command line
23  sanitizedName.ReplaceAll(" ", "_");
24  sanitizedName.ReplaceAll("-", "_");
25  sanitizedName.ReplaceAll("(", "");
26  sanitizedName.ReplaceAll(")", "");
27  sanitizedName.ReplaceAll(")", "");
28  sanitizedName.ReplaceAll(";", "");
29  sanitizedName.ReplaceAll(".", "");
30  return sanitizedName;
31 }
32 
33 
34 
43 void TGraphAntarctica::SetPoint(Int_t i, Double_t lon, Double_t lat){
44  Double_t easting, northing;
45  RampdemReader::LonLatToEastingNorthing(lon, lat, easting, northing);
46  TGraph::SetPoint(i, easting, northing);
47 }
48 
49 
50 
57 void TGraphAntarctica::SetPoint(Int_t i, const AntarcticCoord& coord){
58  AntarcticCoord stereo = coord.as(AntarcticCoord::STEREOGRAPHIC);
59  TGraph::SetPoint(i, stereo.x, stereo.y);
60 }
61 
62 
63 
64 
76 TGraphAntarctica* TGraphAntarctica::makeGpsGraph(int firstRun, int lastRun, int gpsTreeStride,bool quiet){
77  if (!quiet) std::cout << "makeGpsGraph(): starting..." << std::endl;
78 
79  // handle default tree stride
80  gpsTreeStride = gpsTreeStride <= 0 ? defaultGpsTreeStride : gpsTreeStride;
81 
83 
84  for(int run=firstRun; run<=lastRun; run++){
85  if (AnitaVersion::get() == 3) {
86  if (run > 256 && run < 264) {
87  std::cout << "makeGpsGraph(): In ANITA3 runs 257 through 263 are broken, skipping to 264..." << std::endl;
88  run = 264;
89  }
90  }
91 
92  AnitaDataset d(run);
93  if (!quiet) std::cout << "makeGpsGraph(): starting run" << run << " - d.N()=" << d.N() << std::endl;
94  for(int entry=0; entry < d.N(); entry+=gpsTreeStride){
95  if (!quiet) std::cout << "makeGpsGraph(): run:" << run << " entry:" << entry << std::endl;
96  d.getEntry(entry);
97  Adu5Pat* pat = d.gps();
98 
99  gr->SetPoint(gr->GetN(), pat->longitude, pat->latitude);
100 
101  }
102  }
103  return gr;
104 }
105 
106 
107 
108 TGraphAntarctica::TGraphAntarctica(TChain* chain, TString lonSelector, TString latSelector, TCut cut) : TGraph(){
109 
110  TString command = lonSelector + ":" + latSelector;
111 
112  const int n = chain->Draw(command, cut, "goff"); // "goff" means graphics off
113  Set(n);
114  Double_t* lons = chain->GetV1();
115  Double_t* lats = chain->GetV2();
116 
117  for(int i=0; i < n; i++){
118  fX[i] = lons[i];
119  fY[i] = lats[i];
120  // std::cout << i << "\t" << fX[i] << "\t" << fY[i] << std::endl;
121  }
122  init();
123 }
124 
125 TGraphAntarctica::TGraphAntarctica(TTree* tree, TString lonSelector, TString latSelector, TCut cut) : TGraph(){
126 
127  TString command = lonSelector + ":" + latSelector;
128 
129  const int n = tree->Draw(command, cut, "goff"); // "goff" means graphics off
130  Set(n);
131  Double_t* lons = tree->GetV1();
132  Double_t* lats = tree->GetV2();
133 
134  for(int i=0; i < n; i++){
135  fX[i] = lons[i];
136  fY[i] = lats[i];
137  // std::cout << i << "\t" << fX[i] << "\t" << fY[i] << std::endl;
138  }
139  init();
140 }
141 
142 
143 
150 TGraphAntarctica::TGraphAntarctica(const BaseList::path& p, UInt_t interpSeconds){
151  init();
152  if(interpSeconds == 0){
153  for(UInt_t i=0; i < p.ps.size(); i++){
154  SetPoint(i, p.ps.at(i));
155  }
156  }
157  else{
158  UInt_t time = p.ts.at(0);
159  while(time < p.ts.back()){
160  SetPoint(GetN(), p.getPosition(time));
161  time += interpSeconds;
162  }
163  }
164  SetEditable(false);
165  SetNameTitle(makeSanitizedName(p.getName()), p.getName());
166 }
167 
168 
169 
170 
171 void TGraphAntarctica::Draw(Option_t* option){
172 
173  TString opt = option;
174  opt.ToLower();
175 
176  // I'm going to go for defaulting to pretty-ish points?
177  opt = opt.Length() == 0 ? "p" : opt;
178 
179  Bool_t drawAntarctica = false;
180 
181  if(!gPad){
182  // No current canvas, so create one
183  gROOT->MakeDefCanvas();
184  }
185  TList* prims = gPad->GetListOfPrimitives();
186 
187  // If "same" is specified... do not draw an AntarcticaBackground.
188  if(opt.Contains("same")){
189  opt.ReplaceAll("same", "");
190  drawAntarctica = false;
191  }
192 
193  // Else if "a" is specified but not in "same", then do draw AntarcticaBackground.
194  else if(opt.Contains("a")){
195  opt.ReplaceAll("a", "");
196  drawAntarctica = true;
197  }
198 
199  else{
200  // std::cout << "prims " << prims->GetEntries() << std::endl;
201  if(prims->GetEntries() <= 1){
202  drawAntarctica = true;
203  }
204  }
205 
206  if(drawAntarctica){
207  fBackground = new AntarcticaBackground();
208  fBackground->Draw();
209  }
210  else{
211  for(int i=0; i < prims->GetEntries(); i++){
212  TString primName = prims->At(i)->GetName();
213  if(primName.Contains(AntarcticaBackground::getDefaultName())){
214  fBackground = (AntarcticaBackground*) prims->At(i);
215  break;
216  }
217  }
218  }
219 
220  TGraph::Draw(opt);
221 
222 }
223 
224 
225 
226 void TGraphAntarctica::init(){
227  fMarkerStyle = 8; // big points by default
228  doneConversion = false;
229  convertArrays();
230  fBackground = NULL;
231 }
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 void TGraphAntarctica::convertArrays(){
242  if(!doneConversion){
243  for(Int_t i=0; i < GetN(); i++){
244  RampdemReader::LonLatToEastingNorthing(fX[i], fY[i], fX[i], fY[i]);
245  }
246  }
247 
248  doneConversion = true;
249 }
250 
251 
252 
253 
261 void TGraphAntarctica::ExecuteEvent(Int_t event, Int_t x, Int_t y){
262 
263  if(fBackground){
264 
265  const char* extraText = fTitle.Length() > 0 ? fTitle.Data() : NULL;
266  fBackground->updateToolTip(event, x, y, extraText);
267  }
268 
269  TGraph::ExecuteEvent(event, x, y);
270 }
271 
272 
273 
274 TGraphAntarctica::TGraphAntarctica(const BaseList::base& b){
275  init();
276  SetPoint(0, b.getPosition(0));
277  SetNameTitle(makeSanitizedName(b.getName()), b.getName());
278  SetEditable(false);
279 }
280 
281 
282 
283 
284 // enum EColorPalette {kDeepSea=51, kGreyScale=52, kDarkBodyRadiator=53,
285 // kBlueYellow= 54, kRainBow=55, kInvertedDarkBodyRadiator=56,
286 // kBird=57, kCubehelix=58, kGreenRedViolet=59,
287 // kBlueRedYellow=60, kOcean=61, kColorPrintableOnGrey=62,
288 // kAlpine=63, kAquamarine=64, kArmy=65,
289 // kAtlantic=66, kAurora=67, kAvocado=68,
290 // kBeach=69, kBlackBody=70, kBlueGreenYellow=71,
291 // kBrownCyan=72, kCMYK=73, kCandy=74,
292 // kCherry=75, kCoffee=76, kDarkRainBow=77,
293 // kDarkTerrain=78, kFall=79, kFruitPunch=80,
294 // kFuchsia=81, kGreyYellow=82, kGreenBrownTerrain=83,
295 // kGreenPink=84, kIsland=85, kLake=86,
296 // kLightTemperature=87, kLightTerrain=88, kMint=89,
297 // kNeon=90, kPastel=91, kPearl=92,
298 // kPigeon=93, kPlum=94, kRedBlue=95,
299 // kRose=96, kRust=97, kSandyTerrain=98,
300 // kSienna=99, kSolar=100, kSouthWest=101,
301 // kStarryNight=102, kSunset=103, kTemperatureMap=104,
302 // kThermometer=105, kValentine=106, kVisibleSpectrum=107,
303 // kWaterMelon=108, kCool=109, kCopper=110,
304 // kGistEarth=111, kViridis=112};
305 
306 
307 
308 TAxis* TGraphAntarctica::GetXaxis(){
310  if(b){
311  return b->GetXaxis();
312  }
313  else{
314  return fHistogram->GetXaxis();
315  }
316 }
317 
318 TAxis* TGraphAntarctica::GetYaxis(){
320  if(b){
321  return b->GetYaxis();
322  }
323  else{
324  return fHistogram->GetYaxis();
325  }
326 }
327 
335 void TGraphAntarctica::SetPointEastingNorthing(Int_t i, Double_t easting, Double_t northing){
336  TGraph::SetPoint(i, easting, northing);
337 }
static TGraphAntarctica * makeGpsGraph(int firstRun, int lastRun, int gpsTreeStride=defaultGpsTreeStride, bool quiet=true)
Adu5Pat – The ADU5 Position and Attitude Data.
Definition: Adu5Pat.h:26
Float_t latitude
In degrees.
Definition: Adu5Pat.h:42
int getEntry(int entryNumber)
void ExecuteEvent(Int_t event, Int_t x, Int_t y)
Float_t longitude
In degrees.
Definition: Adu5Pat.h:43
ClassDef(TGraphAntarctica, 1) private AntarcticaBackground * getBackground() const
Don&#39;t persist.
int N() const
virtual void SetPointEastingNorthing(Int_t i, Double_t easting, Double_t northing)
Adu5Pat * gps(bool force_reload=false)
static void LonLatToEastingNorthing(Double_t lon, Double_t lat, Double_t &easting, Double_t &northing)
std::vector< AntarcticCoord > ps
true for flight, false for traverse
Definition: BaseList.h:65
virtual void SetPoint(Int_t i, Double_t lon, Double_t lat)