Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadSparseMapFromJobFile.C
Go to the documentation of this file.
1 //
2 // Read & Plot Sparse Map From Job Files
3 // Author : Gabriele Vedovato
4 
5 #define JFILE "data/supercluster_931158223_75_ADV_SIM_EOBNRv2_L1H1V1_2G_OVERLAP_job1.root"
6 
7 //#define SAVE_PLOT // save plot to disk
8 
10 
11 void
12 ReadSparseMapFromJobFile(int ifoId=0, int resId=0, bool build_core=true, bool mask_core=false) {
13 
15 
16  detector* pD[NIFO_MAX]; //! pointers to detectors
17  WSeries<double>* pTF[NIFO_MAX]; //! pointers to WSeries
18  network NET; //! network
19  CWB::config cfg; //! configuration
20 
21  TFile* jfile = new TFile(fName);
22  if(jfile==NULL) {cout << "Error opening root file : " << fName.Data() << endl;exit(1);}
23  // read network object
24  if(jfile->Get("network")!=NULL) {
25  // read network object
26  NET = *(network*)jfile->Get("network");
27  } else {
28  cout << "Error : net is not contained in root file " << fName.Data() << endl;
29  exit(1);
30  }
31  // read config object
32  CWB::config* pcfg = (CWB::config*)jfile->Get("config");
33  cfg = *pcfg;
34 
35  int nIFO=cfg.nIFO; // number of detectors
36  int nRES = cfg.l_high-cfg.l_low+1; // number of frequency resolution levels
37 
38  if((ifoId<0)||(ifoId>=nIFO)) {
39  cout << "ifoId non available - must be [0:" << nIFO-1 << "]" << endl;
40  cout << "root 'ReadSparseMapFromJobFile(ifoId, resId, build_core=true/false, mask_core=false/true)'" << endl;
41  exit(1);
42  }
43  if((resId<0)||(resId>=nRES)) {
44  cout << "resId non available - must be [0:" << nRES-1 << "]" << endl;
45  cout << "root 'ReadSparseMapFromJobFile(ifoId, resId, build_core=true/false, mask_core=false/true)'" << endl;
46  exit(1);
47  }
48 
49  for(int n=0; n<nIFO; n++) pD[n] = NET.getifo(n); // get detectors
50  //for(int n=0; n<nIFO; n++) pD[n]->print();
51 
52  int ifactor = 0;
53 
54  // read sparse map from job file
55  cout << "Loading sparse TF map ... " << endl;
56  for(int n=0; n<nIFO; n++) {
57  pD[n]->sclear(); // clear vector with sparse maps
58  for(int i=0; i<nRES; i++) {
59  char swname[32];
60  if(cfg.simulation) sprintf(swname,"sparse/%s-level:%d:%d",cfg.ifo[n],ifactor,i+cfg.l_low);
61  else sprintf(swname,"sparse/%s-level:%d",cfg.ifo[n],i+cfg.l_low);
62  SSeries<double>* psw = (SSeries<double>*)jfile->Get(swname);
63  if(psw==NULL) {
64  cout << "sparse map " << swname << " not exist in job file" << endl;exit(1);
65  }
66  SSeries<double> SS = *psw;
67  pD[n]->vSS.push_back(SS);
68  delete psw;
69  }
70  cout<<endl;
71  }
72 
73  // plot sparse maps
74  WTS = new watplot(const_cast<char*>("WTS"));
75  for(int n=0; n<nIFO; n++) {
76  if(n!=ifoId) continue;
77  for(int i=0; i<nRES; i++) {
78  if(i!=resId) continue;
79  // bild_core=true -> rebuild TF map using only core pixels
80  // bild_core=false -> rebuild TF map using all pixels
81  pD[n]->vSS[i].Expand(build_core);
82  SSeries<double>* vSS = &pD[n]->vSS[i];
83  cout << "Num Slices : " << vSS->GetSlices() << endl;
84  cout << "Num Layers : " << vSS->GetLayers() << endl;
85  cout << "Halo Slice : " << vSS->GetHaloSlice() << endl;
86  cout << "Halo Layer : " << vSS->GetHaloLayer() << endl;
87 
88  // Plot WDM Scalogram
89  double start = vSS->start();
90  double stop = vSS->start()+vSS->size()/vSS->rate();
91  double flow = cfg.fLow;
92  double fhigh = cfg.fHigh;
93  WTS->plot(vSS, 2, start, stop,const_cast<char*>("COLZ"));
94  WTS->hist2D->GetYaxis()->SetRangeUser(flow, fhigh);
95 
96  char title[128];
97  sprintf(title,"IFO = %s - Level = %d - dT = %g (sec) - dF = %g (Hz)",
98  cfg.ifo[n],i+cfg.l_low,vSS->GetTimeResolution(),vSS->GetFreqResolution());
99  WTS->hist2D->SetTitle(title);
100 
101  if(mask_core) {
102  // set core pixels to white
103  int xsize=WTS->hist2D->GetNbinsX();
104  int ysize=WTS->hist2D->GetNbinsY();
106  cout << "index size : " << index.size() << endl;
107  for(int m=0;m<index.size();m++) {
108  int k = vSS->GetSlice(index[m]);
109  int j = vSS->GetLayer(index[m]);
110  // write pixel 2 times because in watplot is duplicated
111  // hist2D start from 1
112  WTS->hist2D->SetBinContent(2*k+0,j+1,0);
113  WTS->hist2D->SetBinContent(2*k+1,j+1,0);
114  }
115  }
116 
117 #ifdef SAVE_PLOT
118  // dump spectrum to disk
119  char h2name[32];sprintf(h2name,"h%s-level:%d.png",cfg.ifo[n],cfg.l_high-i);
120  WTS->canvas->Print(h2name);
121  exit(0);
122 #endif
123 
124  if(i==resId) return;
125  }
126  }
127 
128  jfile->Close();
129 
130 }
detector * getifo(size_t n)
param: detector index
Definition: network.hh:418
CWB::config * cfg
Definition: TestCWB_Plugin.C:5
virtual size_t size() const
Definition: wavearray.hh:127
float GetFreqResolution()
Definition: sseries.hh:116
virtual void rate(double r)
Definition: wavearray.hh:123
int GetLayers()
Definition: sseries.hh:111
int n
Definition: cwb_net.C:10
wavearray< int > GetSparseIndex(bool bcore=true)
Definition: sseries.cc:327
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
TString("c")
double fLow
Definition: config.hh:122
int GetLayer(int index)
Definition: sseries.hh:104
std::vector< SSeries< double > > vSS[NIFO_MAX]
int m
Definition: cwb_net.C:10
virtual void start(double s)
Definition: wavearray.hh:119
int j
Definition: cwb_net.C:10
i drho i
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
TH2F * hist2D
Definition: watplot.hh:175
#define nIFO
TCanvas * canvas
Definition: watplot.hh:174
jfile
Definition: cwb_job_obj.C:25
int simulation
Definition: config.hh:181
int l_high
Definition: config.hh:138
network NET
Definition: cwb_dump_inj.C:12
const int NIFO_MAX
Definition: wat.hh:4
#define JFILE
double fhigh
WSeries< double > pTF[nRES]
Definition: revMonster.cc:8
int k
int GetSlices()
Definition: sseries.hh:113
float GetTimeResolution()
Definition: sseries.hh:118
void ReadSparseMapFromJobFile(int ifoId=0, int resId=0, bool build_core=true, bool mask_core=false)
double flow
int l_low
Definition: config.hh:137
int GetHaloLayer()
Definition: sseries.hh:69
char title[256]
Definition: SSeriesExample.C:1
void sclear()
Definition: detector.hh:173
int GetHaloSlice(bool eslice=false)
Definition: sseries.hh:67
double fHigh
Definition: config.hh:123
watplot * WTS
wavearray< int > index
char ifo[NIFO_MAX][8]
Definition: config.hh:106
int ifactor
int GetSlice(int index)
Definition: sseries.hh:101
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
int nIFO
Definition: config.hh:102
const int nRES
Definition: revMonster.cc:7
std::vector< SSeries< double > > vSS
Definition: detector.hh:334
char fName[256]
detector ** pD
exit(0)