-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfpfscanmes.cc
141 lines (132 loc) · 5.32 KB
/
fpfscanmes.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* -----------------------------------------
class and functions to scan and analyze forced photometry output files -
R. Ansari - September 2013
---------------------------------------------------- */
#include "fpfscanmes.h"
// namespace ANALSSTDC {
//--------------------------------------------------------------------------
// ---- Class FPObjectListBuilder methods
//--------------------------------------------------------------------------
/* --Methode-- */
void FPObjectListBuilder::PrepareScan()
{
int k=0;
for(size_t i=0; i<filters_.size(); i++) {
int filtid=FilterId(filters_[i]);
if (filtid<1) continue;
filtindex_[filtid]=k; k++;
}
nfilt_=k;
for(int i=0; i<radec_.nbra*radec_.nbdec; i++) {
vmeslist_.push_back( FPMesList() );
}
if (prtlev_>1)
cout << "FPObjectListBuilder::PrepareScan() vmeslist_.size()=" << vmeslist_.size() << " NFilt=" << nfilt_
<< "\n ra:" << radec_.ramin<<","<<radec_.ramax << " dec:" << radec_.decmin<<","<<radec_.decmax
<< " nb:" << radec_.nbra<<","<<radec_.nbdec << " -> del:" << radec_.delra<<","<<radec_.deldec << endl;
return;
}
/* --Methode-- */
int FPObjectListBuilder::ProcessFile(const char * filename, char filter, char camcol, int field, int run)
{
map<int, int>::iterator it=filtindex_.find( FilterId(filter) );
if (it==filtindex_.end()) {
cout << " FPObjectListBuilder::ProcessFile()/ERROR filterId not found in filtindex_ map " << endl;
return 0;
}
int jf = (*it).second;
DataTable dts;
string fitsflnm=filename; fitsflnm += "[1]";
fitsflnm += "[col id ; coord ; flux_psf ; refFlux ; objectId]";
FitsInOutFile fis(fitsflnm, FitsInOutFile::Fits_RO);
fis >> dts;
if (dts.NRows() < 1) {
if (prtlev_>1)
cout << " FPObjectListBuilder::ProcessFile(" << run << "," << field << "," << camcol << "," << filter << ") NRows=0"
<< " TotNbObjects=" << TotNbObjects() << endl;
return 1;
}
DataTableRowPtr rsp=dts.EmptyRowPtr();
double flx, refflx;
double ra, dec;
int_8 id, oid;
for(size_t k=0; k<dts.NRows(); k++) {
dts.GetCstRowPtr(k,rsp);
id = rsp(0); oid=rsp(4);
ra=rsp(1)[0]; dec=rsp(1)[1];
ra *= (180./M_PI); dec *= (180./M_PI); // convert radian to degree
flx=rsp(2); refflx=rsp(3);
UpdateList(jf, id, oid, ra, dec, flx, refflx);
}
if (prtlev_>1)
cout << " FPObjectListBuilder::ProcessFile(" << run << "," << field << "," << camcol << "," << filter << ") NRows= "
<< dts.NRows() << " TotNbObjects=" << TotNbObjects() << endl;
return 0;
}
/* --Methode-- */
int FPObjectListBuilder::UpdateList(int jf, int_8 id, int_8 oid, double ra, double dec, double flx, double refflx)
{
/* DBG
if ((jf<0)||(jf>=nfilt_)) {
cout << " !!!BUG!!! FPObjectListBuilder::UpdateList() out of range jf=" << jf << " nfilt=" << nfilt_ << endl;
return -999;
}
*/
totnmes_++;
if (!isfinite(flx)) { totbadmes_++; return -9; }
// (kra,kdec) identifie la case en (ra,dec) dans lequel on se trouve
int kdec=(dec-radec_.decmin)/radec_.deldec;
int kra=(ra-radec_.ramin)/radec_.delra;
// On verifie qu'on est dans la zone en alpha,delta selectionne
if ((kra<0)||(kdec<0)||(kra>=radec_.nbra)||(kdec>=radec_.nbdec)) return -1;
totnmes_in_++;
size_t rdidx = kdec*radec_.nbra+kra;
FPMesList& fpml=vmeslist_[rdidx];
FPMesList::iterator it = fpml.find(oid);
if (it==fpml.end()) { // adding a new source / object
FPMesures nsrc(id,oid,ra,dec,nfilt_);
nsrc.AddMes(jf,flx);
fpml[oid]=nsrc;
// fpml.insert( pair<int_8, FPMesures> (id,FPMesures(id,oid,ra,dec,nfilt_)) );
totnobjs_++;
return 1;
}
else {
// if (id!=(*it).second.id_) nerr_id_++;
if ((fabs((*it).second.ra_-ra)>2./3600.)||(fabs((*it).second.dec_-dec)>2./3600.)) nerr_radec_++;
(*it).second.AddMes(jf,flx);
return 0;
}
return 0;
}
/* --Methode-- */
void FPObjectListBuilder::FinalizeScan()
{
bool fg_path_only=false;
if (outp_.length()>0)
if (outp_[outp_.length()-1]=='/') fg_path_only=true;
string flnm = outp_;
if (fg_path_only) flnm += "srclist.txt";
cout << "ForcedPhotFileScan::FinalizeScan() : saving object/source list to \n ->" << flnm << endl;
cout << " ... Total number of objects= " << TotNbObjects() << " NbMes=" << TotNbMes() << " NbMesIn=" << TotNbMesInRADecRegion()
<< " BadMes=" << TotNbBadMes() << " NErrOId=" << nerr_oid_ << " NErrRADEC=" << nerr_radec_ << endl;
ofstream of(flnm.c_str());
of << "# id oid ra dec flxmean_1 flxsigma_1 nmes_1 flxmean_2 flxsigma_2 nmes_2 ... " << endl;
size_t nsrc_wrt=0;
// Boucle sur toutes les cellules en alpha, delta
for(size_t i=0; i<vmeslist_.size(); i++) {
FPMesList& fpml=vmeslist_[i];
cout << " ra_dec_cell["<<i<<"] ra,dec="
<< radec_.ramin+radec_.delra*((i%radec_.nbra)+0.5)<<","<<radec_.decmin+radec_.deldec*((i%radec_.nbdec)+0.5)
<< " -> NbSrc=" << fpml.size() << endl;
// boucle sur les sources de chaque cellule
for(FPMesList::iterator it=fpml.begin(); it!=fpml.end(); it++) {
(*it).second.ComputeMean();
if (((*it).second.vsflx_[0].sum_mean<minflxok_)||((*it).second.vsflx_[0].sum_mean>maxflxok_)) continue;
(*it).second.Print(of); // or (*it).second.Print(of," ; ");
of << endl; nsrc_wrt++;
}
}
cout << "ForcedPhotFileScan::FinalizeScan() " << nsrc_wrt << " sources written to file out of total=" << TotNbObjects() << endl;
}
// } Fin du namespace