Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RootsSkyMap2Fits.C
Go to the documentation of this file.
1 //
2 // This example show how to convert skymap probability from a list of output/root files to fits files
3 // Author : Gabriele Vedovato
4 
5 {
6  #include <vector>
7 
8  #define WAVE_FILE "data/wave_931158008_600_ADV_SIM_BRST_LF_GWGC_L1H1_1G_run3_14.1421_job1.root"
9  #define NETRHO 4
10  #define NETCC 0.6
11  #define ODIR "fits"
12  //#define PRINT_DETECTORS
13 
14 
16  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
17  TString cwb_parameter_name = gSystem->Getenv("CWB_PARAMETERS_FILE");
18  gROOT->Macro(cwb_parameter_name);
19 
20  // read root file list from output directory
21  vector<TString> fileList = TB.getFileListFromDir(output_dir, ".root", "wave_");
22  if(fileList.size()==0) {
23  cout << "No root files in the directory : " << output_dir << endl;
24  gSystem->Exit(1);
25  }
26 
27  // create output directory
28  char cmd[256];
29  sprintf(cmd,"mkdir -p %s",ODIR);
30  cout << cmd << endl;
31  gSystem->Exec(cmd);
32 
33  for(int n=0;n<fileList.size();n++) {
34 
35  cout << fileList[n].Data() << endl;
36  netevent event(fileList[n].Data()); // open wave root file
37  int nevt = event.GetEntries(); // get number of detected events
38  if(nevt==0) continue;
39  else cout << "nevt : " << nevt << endl;
40 
41 #ifdef PRINT_DETECTORS
42  // print detectors infos
43  TList* ifoList = event.fChain->GetUserInfo();
44  int nIFO = ifoList->GetSize();
45  for (int m=0;m<nIFO;m++) {
46  detector* pDetector = (detector*)ifoList->At(m);
47  detectorParams dParams = pDetector->getDetectorParams();
48  cout << dParams.name << endl;
49  pDetector->print();
50  }
51 #endif
52 
53  for(int i=0;i<nevt;i++) { // loop over the detected events
54 
55  event.GetEntry(i); // load event #n
56 
57  skymap* Psm = event.Psm; // probability skymap
58 
59  cout << "--------------------------------------------------" << endl;
60  cout << "gps : " << int(event.time[0]) << endl;
61  cout << "rho : " << event.rho[1] << endl;
62  cout << "cc : " << event.netcc[0] << endl;
63  cout << "network snr : " << sqrt(event.likelihood) << endl;
64  cout << "--------------------------------------------------" << endl<<endl;
65 
66  if(Psm->size()!=0) {
67 
68  if(Psm->getType()==1) { // check if it is healpix
69  // dump skymap to fits (event.time[0] is the gps time of the first detector)
70  if((event.rho[1]>NETRHO) && (event.netcc[0]>NETCC)) { // filter output events
71  char fits_name[256];sprintf(fits_name,"%s/probability_skymap_%d.fits.gz",ODIR,int(event.time[0]));
72  cout << "--------------------------------------------------" << endl<<endl;
73  cout << "Dump fits file : " << fits_name << endl;
74  Psm->Dump2fits(fits_name,event.time[0]);
75 
76  // compute total probability (Psm->get(l) return the probability for index l)
77  int ml=0;
78  double prob=0; // probability
79  double mprob=0; // max probability
80  double cprob=0; // cumulative probability
81  for(int l=0;l<Psm->size();l++) {prob=Psm->get(l);cprob+=prob;if(prob>mprob) {mprob=prob;ml=l;}}
82  cout << "cprob : " << cprob << endl;
83  cout << "mprob : " << mprob << " ml " << ml << endl;
84 
85  // print RA,Dec form maximum probability
86  // mRA & event.phi[2] are not equal because of approximations
87  double mRA = Psm->getPhi(ml);
88  double mDec = Psm->getTheta(ml);
89  cout << "max prob RA : " << mRA << " RA (root) : " << event.phi[2] << endl;
90  cout << "max prob Dec : " << 90-mDec << " Dec (root) : " << event.theta[2] << endl;
91  cout << "--------------------------------------------------" << endl<<endl;
92  }
93  }
94  }
95  }
96  }
97 
98  exit(0);
99 }
TString cwb_parameter_name
detectorParams getDetectorParams()
Definition: detector.cc:201
Float_t * rho
biased null statistics
Definition: netevent.hh:93
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:4333
char name[32]
Definition: detector.hh:32
sprintf(cmd,"mkdir -p %s", ODIR)
int n
Definition: cwb_net.C:10
TString("c")
vector< TString > fileList
double getTheta(size_t i)
Definition: skymap.hh:206
int nevt
int m
Definition: cwb_net.C:10
char cmd[256]
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
CWB::Toolbox TB
Definition: ComputeSNR.C:5
#define nIFO
exit(0)
i() int(T_cor *100))
Definition: skymap.hh:45
double getPhi(size_t i)
Definition: skymap.hh:146
Double_t * time
beam pattern coefficients for hx
Definition: netevent.hh:75
int getType()
Definition: skymap.hh:278
#define NETRHO
void print()
Definition: detector.cc:1768
#define ODIR
Float_t likelihood
Definition: netevent.hh:105
#define NETCC
int l
Definition: cbc_plots.C:434
double get(size_t i)
param: sky index
Definition: skymap.cc:681
size_t size()
Definition: skymap.hh:118
char output_dir[512]
Definition: test_config1.C:146