47 cbl::catalogue::Catalogue::Catalogue (
const RandomType type,
const string WField,
const bool isSpectroscopic,
const Catalogue catalogue,
const Catalogue catalogue_for_nz,
const double N_R,
const cosmology::Cosmology &cosm,
const int step_redshift,
const vector<double> lim,
const double redshift_min,
const double redshift_max,
const bool do_convol,
const double sigma,
const bool use_venice,
const bool do_zdistr_with_venice,
const string file_random,
const string mask,
const string pointing_file,
const string dir_venice,
const int seed)
49 if (type!=RandomType::_createRandom_VIPERS_)
ErrorCBL(
"the random catalogue has to be of type _VIPERS_ !",
"Catalogue",
"RandomCatalogueVIPERS.cpp");
56 vector<double> xx, yy, err;
59 string file_nz = path.
DirLoc()+
"/file_nz";
61 if (isSpectroscopic) {
62 vector<double> redshift = catalogue_for_nz.var(Var::_Redshift_);
63 vector<double> weight = catalogue_for_nz.var(Var::_Weight_);
64 const double weightedN = catalogue_for_nz.weightedN();
65 distribution(xx, yy, err, redshift, weight, step_redshift,
true, file_nz, weightedN,
cbl::Min(redshift),
cbl::Max(redshift),
"Linear", do_convol, sigma);
71 vector<string> field, pointing;
73 char WW = (WField==
"W1") ?
'1' :
'4';
75 if (isSpectroscopic) {
77 string file_pointings = path.
DirCosmo()+
"/External/VIPERS/masks/pointings/"+pointing_file;
78 ifstream fin_pointings(file_pointings);
checkIO(fin_pointings, file_pointings);
80 string line, Field, Quadrant;
82 while (getline(fin_pointings, line)) {
83 stringstream ss(line);
84 ss >> Field; ss >> Quadrant;
86 if (Field.at(1)==WW || WField==
"W1W4") {
87 field.emplace_back(Field);
88 pointing.emplace_back(Field+Quadrant);
93 fin_pointings.clear(); fin_pointings.close();
99 vector<string> file_input;
103 vector<string> where = {
"inside"};
104 if (!isSpectroscopic) where.push_back(
"outside");
106 const int nRandom = catalogue.nObjects()*N_R*10.;
107 const string Dir_venice = path.
DirCosmo()+
"/External/VIPERS/"+dir_venice+
"/";
110 const string MAKE =
"make CC=gcc -C "+Dir_venice+
" ; ";
111 coutCBL << endl <<
"--> " << MAKE << endl << endl;
112 if (system(MAKE.c_str())) {}
114 if (!isSpectroscopic) {
115 for (
size_t i=0; i<where.size(); ++i) {
118 if (do_zdistr_with_venice && isSpectroscopic) DO +=
" -nz "+file_nz;
119 coutCBL << endl <<
"--> " << MAKE << endl << endl;
120 if (system(DO.c_str())) {}
126 for (
size_t i=0; i<where.size(); ++i) {
135 vector<int> rnd_pnt(pointing.size(), 0);
137 for (
int i=0; i<nRandom; ++i)
138 rnd_pnt[random()] ++;
143 string filelist, file, Mask;
145 for (
size_t mm=0; mm<pointing.size(); ++mm) {
149 Mask = mask+
"mask_"+pointing[mm]+
".reg";
151 string DO = path.
DirCosmo()+
"/External/VIPERS/"+dir_venice+
"/venice -m "+Mask+
" -r -f "+where[i]+
" -npart "+
conv(rnd_pnt[mm],
par::fINT)+
" -o "+file;
152 if (do_zdistr_with_venice && isSpectroscopic) DO +=
" -nz "+file_nz;
155 if (system(DO.c_str())) {}
157 filelist += file+
" ";
162 ifstream fin(file);
checkIO(fin, file);
163 string line; vector<string> Line;
164 while (getline(fin, line))
165 if (line.find(
"#") == string::npos)
166 Line.emplace_back(line);
167 fin.clear(); fin.close();
169 ofstream fout(file);
checkIO(fout, file);
170 for (
auto &&LL : Line)
171 fout << LL <<
" " << pointing[mm] << endl;
172 fout.clear(); fout.close();
177 if (system(Merge.c_str())) {}
184 file_input.emplace_back(file_random);
189 for (
size_t ff=0; ff<file_input.size(); ++ff) {
191 coutCBL <<
"reading the field " << file_input[ff] <<
"..." << endl;
193 ifstream fin(file_input[ff].c_str());
checkIO(fin, file_input[ff]);
197 double RA, DEC, REDSHIFT;
200 if (do_zdistr_with_venice && isSpectroscopic) {
201 while (getline(fin, line))
202 if (line.find(
"#") == string::npos) {
203 stringstream ss(line);
204 ss >> RA; ss >> DEC; ss >> REDSHIFT; ss >> FIELD;
205 if (redshift_min<REDSHIFT && REDSHIFT<redshift_max && lim[0]<RA && RA<lim[1] && lim[2]<DEC && DEC<lim[3]) {
206 observedCoordinates coord = {RA, DEC, REDSHIFT};
207 m_object.push_back(move(Object::Create(ObjectType::_Random_, coord, CoordinateUnits::_degrees_, cosm, 1., 0, -1, FIELD)));
214 vector<double> random_ra, random_dec, random_redshift;
215 vector<string> field;
218 while (getline(fin, line))
219 if (line.find(
"#") == string::npos) {
220 stringstream ss(line);
221 ss >> RA; ss >> DEC; ss >> FIELD;
222 if (lim[0]<RA && RA<lim[1] && lim[2]<DEC && DEC<lim[3]) {
223 random_ra.push_back(RA);
224 random_dec.push_back(DEC);
225 field.emplace_back(FIELD);
229 if (isSpectroscopic) {
231 vector<double> redshift = catalogue_for_nz.var(Var::_Redshift_);
232 double zmin = max(
cbl::Min(redshift), redshift_min);
233 double zmax = min(
cbl::Max(redshift), redshift_max);
237 for (
size_t i=0; i<random_ra.size(); ++i)
238 random_redshift.emplace_back(1.);
241 for (
size_t i=0; i<random_ra.size(); ++i) {
242 observedCoordinates coord = {random_ra[i], random_dec[i], random_redshift[i]};
243 m_object.push_back(move(Object::Create(ObjectType::_Random_, coord, CoordinateUnits::_degrees_, cosm, 1., 0, -1, field[i])));
248 fin.clear(); fin.close();
253 computeComovingCoordinates(cosm);
258 size_t nFieldsB = nFields();
260 std::shuffle(begin(m_object), end(m_object), default_random_engine{});
261 m_object.resize(N_R*catalogue.nObjects());
266 if (nFields() != nFieldsB)
267 ErrorCBL(
"nFields() = "+
conv(nFields(),
par::fINT)+
" != nFieldsB = "+
conv(nFieldsB,
par::fINT)+
" --> the random sample should be probably enlarged",
"Catalogue",
"RandomCatalogueVIPERS.cpp");
269 if (catalogue.nFields()>nFields())
270 ErrorCBL(
"catalogue.nFields() = "+
conv(catalogue.nFields(),
par::fINT)+
" > nFields = "+
conv(nFields(),
par::fINT)+
" --> the random sample should be probably enlarged",
"Catalogue",
"RandomCatalogueVIPERS.cpp");
272 coutCBL <<
"total number of fields in the catalogue = "<<catalogue.nFields() << endl;
273 coutCBL <<
"total number of fields in the random = "<<nFields()<<endl;
278 string RM =
"rm -rf "+path.
DirLoc()+
"/temp* "+file_nz;
279 if (system(RM.c_str())) {}
#define coutCBL
CBL print message.
std::string DirCosmo()
get the directory where the CosmoBolognaLbi are stored
std::string DirLoc()
get the local directory
Catalogue()=default
default constructor
static const std::string col_green
green colour (used when printing something on the screen)
static const std::string col_default
default colour (used when printing something on the screen)
static const char fINT[]
conversion symbol for: int -> std::string
RandomType
the type of random catalogue
The global namespace of the CosmoBolognaLib
void distribution(std::vector< double > &xx, std::vector< double > &fx, std::vector< double > &err, const std::vector< double > FF, const std::vector< double > WW, const int nbin, const bool linear=true, const std::string file_out=par::defaultString, const double fact=1., const double V1=par::defaultDouble, const double V2=par::defaultDouble, const std::string bin_type="Linear", const bool conv=false, const double sigma=0.)
derive and store the number distribution of a given std::vector
T Min(const std::vector< T > vect)
minimum element of a std::vector
std::string conv(const T val, const char *fact)
convert a number to a std::string
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
T Max(const std::vector< T > vect)
maximum element of a std::vector
std::vector< double > vector_from_distribution(const int nRan, const std::vector< double > xx, const std::vector< double > fx, const double xmin, const double xmax, const int seed)
return a std::vector of numbers sampled from a given distribution