Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wavegraph_demo.C
Go to the documentation of this file.
1 #define XIFO 4
2 
3 #pragma GCC system_header
4 
5 #include <vector>
6 #include <algorithm>
7 #include <stdexcept>
8 #include <iterator>
9 
10 void
12 
13  // load wavegraph library
14  if(!gROOT->GetClass("wavegraph")) {
15  TString wat_path = gSystem->Getenv("HOME_WAT");
16  TString wavegraph_path = wat_path+"/tools/wavegraph/lib/wavegraph.so";
17  printf("Loading wavegraph : %s ...\n",wavegraph_path.Data());
18  if(gSystem->Load(wavegraph_path)) {
19  cout << "error loading wavegraph library" << endl;
20  gSystem->Exit(1);
21  }
22  }
23 
24  // load data
25  TFile inputfile("wavegraph_demo_data.root");
26  if(!inputfile.IsOpen()) {
27  cout << "File .root not exist" << endl;
28  gSystem->Exit(1);
29  }
30  inputfile.ls();
31 
32  // WSeries<double>* test=(WSeries<double>*)inputfile.Get("V1:7");
33  // cout << "time bins="<<num_of_time_bins(test)<<" freq bins="<<num_of_freq_bins(test)<<"\n";
34  // double mytest=get_map00(test,3231,13);
35  // cout << mytest << "\n";
36  // exit(0);
37 
38  // store data in STL vectors
39  const int nscales=6;
40  Int_t my_scales[nscales]={3,4,5,6,7,8};
41 
42  std::vector<int> scales;
43  for (int n=0; n<nscales; n++)
44  scales.push_back(my_scales[n]);
45 
46  std::vector< WSeries<double>* > data;
47  ostringstream convert_str;
48  for (int n=0; n != nscales; ++n) {
49  convert_str << "V1:" << my_scales[n];
50  std::string label=convert_str.str();
51  cout << "" << label << "\n";
52  data.push_back((WSeries<double>*)inputfile.Get(label.c_str()));
53  cout << "pointer to data[" << n << "] is " << data[n] << endl;
54  label.clear();
55  convert_str.clear();
56  convert_str.str("");
57  }
58 
59  // load graph
61  graph.create("wavegraph_demo.txt");
62 
63  if ( !graph.is_topologically_sorted() ) {
64  std::cerr << "the graph is not topologically sorted\n";
65  exit(0);
66  }
67 
68  // apply clustering
69  std::vector<cluster> clusters = graph.clustering(400.0,data,8.0);
70  std::cout << "found " << clusters.size() << " clusters\n";
71 
72  // make plots
74  WSeries<double>* WS = data.at(4);
75 
76  int layers = WS->maxLayer()+1; // numbers of frequency bins (first & last bins have df/2)
77  int slices = WS->sizeZero(); // number of time bins
78  float df = WS->resolution(); // frequency bin resolution (hz)
79  float dt = 1./(2*df); // time bin resolution (sec)
80 
81  // draw TF maps
82 
83  double start = WS->start();
84  double stop = WS->start()+slices*dt;
85  double flow = 0;
86  double fhigh = (layers-1)*df;
87  cout.precision(14);
88  cout << "start " << start << " stop " << stop << " flow " << flow << " fhigh " << fhigh << endl;
89  WTS.plot(*WS, 2, start, stop, const_cast<char*>("COLZ"));
90 
91  // set frequency range
92  WTS.hist2D->GetYaxis()->SetRangeUser(flow, fhigh);
93 
94  // draw clusters
95  int colors[8]={kWhite, kYellow, kOrange, kMagenta, kGreen, kBlue, kRed, kCyan};
96  std::vector<TPolyLine> clusters_lines (clusters.size());
97  std::vector<TPolyMarker> clusters_points (clusters.size());
98 
99  for (int n=0; n<clusters.size(); ++n) {
100 
101  int N = clusters[n].size();
105 
106  for (int k = N; k-- > 0;) {
107  (*t)[k]=(clusters[n])[k].time;
108  (*f)[k]=(clusters[n])[k].freq;
109  (*scale)[n]=(clusters[n])[k].log2scale;
110  //cout << "t=" << t[n] << " sec, f=" << f[n] << " Hz, scale=" << scale[n] << endl;
111  }
112  clusters_lines[n].SetPolyLine(N,t->data,f->data);
113 
114  clusters_lines[n].SetLineColor(colors[n%8]);
115  clusters_lines[n].SetLineStyle(2);
116  clusters_lines[n].SetLineWidth(4);
117  clusters_lines[n].Draw("same");
118 
119  clusters_points[n].SetPolyMarker(N,t->data,f->data);
120  clusters_points[n].SetMarkerSize(8);
121  clusters_points[n].SetMarkerStyle(kDot);
122  clusters_points[n].SetMarkerColor(colors[n%8]);
123  clusters_points[n].Draw("same");
124 
125  //delete t;
126  //delete f;
127  //delete scale;
128 
129  }
130 
131  // write plots and data to file
132  char fname[1024];
133  sprintf(fname,"wavegraph_demo_plots.root");
134  WTS.canvas->cd();
135  WTS.canvas->Print(fname);
136 
137 }
wavearray< double > t(hp.size())
void graph(TString ifile)
Definition: Average.C:543
int slices
std::vector< cluster > clustering(const double threshold, const std::vector< WSeries< double > * > &data, const double strip_edges, const int path_halfwidth, const double penal_factor, const std::vector< double > &energy_thresholds)
Definition: wavegraph.cc:475
TString wavegraph_path
Definition: loadlib.C:5
tuple f
Definition: cwb_online.py:91
printf("total live time: non-zero lags = %10.1f \n", liveTot)
int n
Definition: cwb_net.C:10
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
TString("c")
int layers
Color_t colors[16]
virtual void start(double s)
Definition: wavearray.hh:119
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
Definition: watplot.cc:132
#define N
TH2F * hist2D
Definition: watplot.hh:175
TCanvas * canvas
Definition: watplot.hh:174
double time[6]
Definition: cbc_plots.C:435
void wavegraph_demo()
watplot * WTS
Definition: ChirpMass.C:115
bool is_topologically_sorted()
Definition: wavegraph.cc:305
TString label
Definition: MergeTrees.C:21
double fhigh
char fname[1024]
int k
void create(const std::string &srcfile)
Definition: wavegraph.cc:99
double dt
double flow
double resolution(int=0)
Definition: wseries.hh:137
double df
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
DataType_t * data
Definition: wavearray.hh:301
size_t sizeZero()
Definition: wseries.hh:126
int maxLayer()
Definition: wseries.hh:121
exit(0)