9#ifndef GLAMER_particle_halo_h 
   10#define GLAMER_particle_halo_h 
   14#include "simpleTree.h" 
   16#include "utilities_slsim.h" 
   17#include "lens_halos.h" 
   18#include "quadTreeHalos.h" 
   39template<
typename PType>
 
   54                    ,PosType rescale_mass = 1.0   
 
   65                    ,
double max_range = -1
 
   67  ):
LensHalo(redshift,cosmo),min_size(MinPSize),multimass(true),inv_area(my_inv_area)
 
   69    Npoints = pvector.size();
 
   71    std::swap(pvector,trash_collector);
 
   72    pp = trash_collector.data();
 
   74    set_up(redshift,cosmo,theta_rotate,max_range,recenter,verbose);
 
 
   87                    ,
double max_range = -1
 
   89  ):
LensHalo(redshift,cosmo),min_size(MinPSize),multimass(true),inv_area(my_inv_area),Npoints(n)
 
   92    set_up(redshift,cosmo,theta_rotate,max_range,recenter,verbose);
 
 
   98    densest_point = h.densest_point;
 
   99    trash_collector =std::move(h.trash_collector);
 
  100    pp = trash_collector.data();
 
  103    min_size = h.min_size;
 
  104    multimass = h.multimass;
 
  108    sizefile = h.sizefile;
 
  109    inv_area = h.inv_area;
 
  117  void force_halo(
double *alpha,KappaType *kappa,KappaType *gamma,KappaType *phi,
double const *xcm
 
  118                  ,
bool subtract_point=
false,PosType screening = 1.0);
 
  120  size_t getN()
 const { 
return Npoints; };
 
  135                      std::string new_filename  
 
  137                      ,
double particle_mass 
 
  150            ,
double particle_mass 
 
  159  static void calculate_smoothing(
int Nsmooth
 
  162                                  ,
bool verbose = 
false);
 
  166  static void writeSizes(
const std::string &filename
 
  172  static bool readSizesFile(
const std::string &filename
 
  178  friend class MakeParticleLenses;
 
  195                    ,
bool verbose = 
false 
  196  ):
LensHalo(redshift,cosmo),pp(pdata),min_size(0),multimass(true),Npoints(Nparticles),inv_area(my_inv_area)
 
  198    set_up(redshift,cosmo,theta_rotate,-1,recenter,verbose);
 
 
  201  void rotate_particles(PosType theta_x,PosType theta_y);
 
  206  Point_3d<> densest_point;
 
  209  std::vector<PType> trash_collector;
 
  220  std::string sizefile;
 
  227template<
typename PType>
 
  241:
LensHalo(redshift,cosmo),min_size(MinPSize),multimass(my_multimass),simfile(simulation_filename),inv_area(my_inv_area)
 
  246  LensHalo::set_flag_elliptical(
false);
 
  252  LensHalo::setRsize(Rmax);
 
  259      std::cerr << 
"LensHaloParticles does not accept format of particle data file." << std::endl;
 
  260      throw std::invalid_argument(
"bad format");
 
  263  sizefile = simfile + 
"." + std::to_string(Nsmooth) + 
"sizes";
 
  265  if(!readSizesFile(sizefile,pp,Npoints,Nsmooth,min_size)){
 
  268    calculate_smoothing(Nsmooth,pp,Npoints);
 
  271    writeSizes(sizefile,Nsmooth,pp,Npoints);
 
  273    for(
size_t i=0; i<Npoints ; ++i) 
if(pp[i].size() < min_size) pp[i].Size = min_size;
 
  276  double min_s = pp[0].Size;
 
  277  size_t smallest_part = 0;
 
  278  for(
size_t i = 1 ; i<Npoints ; ++i){
 
  279    if(pp[i].Size < min_s){
 
  283    pp[i].Mass *= massscaling;
 
  286  densest_point[0] = pp[smallest_part].x[0];
 
  287  densest_point[1] = pp[smallest_part].x[1];
 
  288  densest_point[2] = pp[smallest_part].x[2];
 
  292  PosType scale_factor = 1/(1+redshift);
 
  294  PosType max_mass = 0.0,min_mass = HUGE_VALF,mass=0;
 
  295  for(
size_t i=0;i<Npoints;++i){
 
  296    pp[i][0] *= scale_factor;
 
  297    pp[i][1] *= scale_factor;
 
  298    pp[i][2] *= scale_factor;
 
  300    mcenter[0] += pp[i][0]*pp[multimass*i].mass();
 
  301    mcenter[1] += pp[i][1]*pp[multimass*i].mass();
 
  302    mcenter[2] += pp[i][2]*pp[multimass*i].mass();
 
  304    mass += pp[multimass*i].mass();
 
  306    max_mass = (pp[multimass*i].mass() > max_mass) ? pp[multimass*i].mass() : max_mass;
 
  307    min_mass = (pp[multimass*i].mass() < min_mass) ? pp[multimass*i].mass() : min_mass;
 
  309  LensHalo::setMass(mass);
 
  313  if(verbose) std::cout << 
"   Particle mass range : " << min_mass << 
" to " << max_mass << 
"  ratio of : " << max_mass/min_mass << std::endl;
 
  318    for(
size_t i=0;i<Npoints;++i){
 
  319      pp[i][0] -= mcenter[0];
 
  320      pp[i][1] -= mcenter[1];
 
  321      pp[i][2] -= mcenter[2];
 
  323      r2 = pp[i][0]*pp[i][0] + pp[i][1]*pp[i][1] + pp[i][2]*pp[i][2];
 
  324      if(r2 > r2max) r2max = r2;
 
  327    LensHalo::setRsize( sqrt(r2max) );
 
  329    densest_point -= mcenter;
 
  335  rotate_particles(theta_rotate[0],theta_rotate[1]);
 
 
  341template<
typename PType>
 
  353  LensHalo::set_flag_elliptical(
false);
 
  359  LensHalo::setRsize(Rmax);
 
  361  double min_s = pp[0].Size;
 
  362  size_t smallest_part = 0;
 
  363  for(
size_t i =0 ; i<Npoints ; ++i){
 
  364    if(pp[i].Size < min_s){
 
  370  densest_point[0] = pp[smallest_part].x[0];
 
  371  densest_point[1] = pp[smallest_part].x[1];
 
  372  densest_point[2] = pp[smallest_part].x[2];
 
  377  PosType max_mass = 0.0,min_mass = HUGE_VALF,mass=0;
 
  378  for(
size_t i=0;i<Npoints;++i){
 
  380    mcenter[0] += pp[i][0]*pp[i].mass();
 
  381    mcenter[1] += pp[i][1]*pp[i].mass();
 
  382    mcenter[2] += pp[i][2]*pp[i].mass();
 
  384    mass += pp[i].mass();
 
  386    max_mass = (pp[i].mass() > max_mass) ? pp[i].mass() : max_mass;
 
  387    min_mass = (pp[i].mass() < min_mass) ? pp[i].mass() : min_mass;
 
  389  LensHalo::setMass(mass);
 
  393  if(verbose) std::cout << 
"   Particle mass range : " << min_mass << 
" to " << max_mass << 
"  ratio of : " << max_mass/min_mass << std::endl;
 
  397    for(
size_t i=0;i<Npoints;++i){
 
  398      pp[i][0] -= mcenter[0];
 
  399      pp[i][1] -= mcenter[1];
 
  400      pp[i][2] -= mcenter[2];
 
  402      r2 = pp[i][0]*pp[i][0] + pp[i][1]*pp[i][1] + pp[i][2]*pp[i][2];
 
  403      if(r2 > r2max) r2max = r2;
 
  405      densest_point -= mcenter;
 
  410    LensHalo::setRsize( sqrt(r2max) );
 
  414  rotate_particles(theta_rotate[0],theta_rotate[1]);
 
 
 
  421template<
typename PType>
 
  422LensHaloParticles<PType>::~LensHaloParticles(){
 
  426template<
typename PType>
 
  427void LensHaloParticles<PType>::force_halo(
double *alpha,KappaType *kappa,KappaType *gamma,KappaType *phi
 
  429                                          ,
bool subtract_point,PosType screening){
 
  430  qtree->force2D_recur(xcm,alpha,kappa,gamma,phi);
 
  437template<
typename PType>
 
  439  rotate_particles(theta[0],theta[1]);
 
 
  452template<
typename PType>
 
  457  if(!multimass && ncoll != 3 ){
 
  458    std::cerr << filename << 
" should have three columns!" << std::endl;
 
  460  if(multimass && ncoll != 4 ){
 
  461    std::cerr << filename << 
" should have four columns!" << std::endl;
 
  464  std::ifstream myfile(filename);
 
  470  if (myfile.is_open()){
 
  472    float tmp_mass = 0.0;
 
  473    std::string str,label;
 
  475    while(std::getline(myfile, str)){
 
  476      std::stringstream ss(str);
 
  480        if(label == 
"nparticles"){
 
  491      if(multimass && count == 1 ) 
break;
 
  492      if(!multimass && count == 2 ) 
break;
 
  496      if(multimass) std::cerr << 
"File " << filename << 
" must have the header lines: " << std::endl
 
  497        << 
"# nparticles   ****" << std::endl << 
"# mass   ****" << std::endl;
 
  498      if(!multimass) std::cerr << 
"File " << filename << 
" must have the header lines: " << std::endl
 
  499        << 
"# nparticles   ****" << std::endl;
 
  500      throw std::runtime_error(
"file reading error");
 
  503    trash_collector.resize(Npoints);  
 
  504    pp = trash_collector.data();
 
  513      while(std::getline(myfile, str) && row < Npoints){
 
  514        if(str[0] == 
'#') 
continue; 
 
  515        std::stringstream ss(str);
 
  518        if(!(ss >> pp[row][1])) std::cerr << 
"3 columns are expected in line " << row
 
  519          << 
" of " << filename << std::endl;
 
  520        if(!(ss >> pp[row][2])) std::cerr << 
"3 columns are expected in line " << row
 
  521          << 
" of " << filename << std::endl;
 
  526      while(std::getline(myfile, str) && row < Npoints){
 
  527        if(str[0] == 
'#') 
continue; 
 
  528        std::stringstream ss(str);
 
  531        if(!(ss >> pp[row][1])) std::cerr << 
"4 columns are expected in line " << row
 
  532          << 
" of " << filename << std::endl;
 
  533        if(!(ss >> pp[row][2])) std::cerr << 
"4 columns are expected in line " << row
 
  534          << 
" of " << filename << std::endl;
 
  535        if(!(ss >> pp[row].Mass)) std::cerr << 
"4 columns are expected in line " << row
 
  536          << 
" of " << filename << std::endl;
 
  543      std::cerr << 
"Number of data rows in " << filename << 
" does not match expected number of particles." 
  545      throw std::runtime_error(
"file reading error");
 
  548    std::cerr << 
"Unable to open file " << filename << std::endl;
 
  549    throw std::runtime_error(
"file reading error");
 
  552  std::cout << Npoints << 
" particle positions read from file " << filename << std::endl;
 
 
 
  556template<
typename PType>
 
  557bool LensHaloParticles<PType>::readSizesFile(
const std::string &filename
 
  563  std::ifstream myfile(filename);
 
  567  PosType min=HUGE_VALF,max=0.0;
 
  568  if (myfile.is_open()){
 
  570    std::string str,label;
 
  574    while(std::getline(myfile, str)){
 
  575      std::stringstream ss(str);
 
  579        if(label == 
"nparticles"){
 
  582            std::cerr << 
"Number of particles in " << filename << 
" does not match expected number" << std::endl;
 
  583            throw std::runtime_error(
"file reading error");
 
  587        if(label == 
"nsmooth"){
 
  589          if(NStmp != Nsmooth) 
return false;
 
  594      if(count == 2) 
break;
 
  598      std::cerr << 
"File " << filename << 
" must have the header lines: " << std::endl
 
  599      << 
"# nparticles   ****" << std::endl;
 
  600      throw std::runtime_error(
"file reading error");
 
  605    std::cout << 
"reading in particle sizes from " << filename << 
"..." << std::endl;
 
  608    while(std::getline(myfile, str)){
 
  609      if(str[0] == 
'#') 
continue; 
 
  610      std::stringstream ss(str);
 
  613      if(min_size > pp[row].size() ) pp[row].Size = min_size;
 
  614      min = min < pp[row].size() ? min : pp[row].size();
 
  615      max = max > pp[row].size() ? max : pp[row].size();
 
  620      std::cerr << 
"Number of data rows in " << filename << 
" does not match expected number of particles." 
  622      throw std::runtime_error(
"file reading error");
 
  628  std::cout << Npoints << 
" particle sizes read from file " << filename << std::endl;
 
  629  std::cout << 
"   maximun particle sizes " << max << 
" minimum " << min << 
" Mpc" << std::endl;
 
  634template<
typename PType>
 
  635void LensHaloParticles<PType>::rotate_particles(PosType theta_x,PosType theta_y){
 
  637  if(theta_x == 0.0 && theta_y == 0.0) 
return;
 
  642  cx = cos(theta_x); sx = sin(theta_x);
 
  643  cy = cos(theta_y); sy = sin(theta_y);
 
  645  coord[0][0] = cy;  coord[1][0] = -sy*sx; coord[2][0] = cx;
 
  646  coord[0][1] = 0;   coord[1][1] = cx;     coord[2][1] = sx;
 
  647  coord[0][2] = -sy; coord[1][2] = -cy*sx; coord[2][2] = cy*cx;
 
  653  for(
size_t i=0;i<Npoints;++i){
 
  656      tmp[0] += coord[0][j]*pp[i][j];
 
  657      tmp[1] += coord[1][j]*pp[i][j];
 
  658      tmp[2] += coord[2][j]*pp[i][j];
 
  660    for(j=0;j<3;++j) pp[i][j]=tmp[j];
 
  666    tmp[0] += coord[0][j]*mcenter[j];
 
  667    tmp[1] += coord[1][j]*mcenter[j];
 
  668    tmp[2] += coord[2][j]*mcenter[j];
 
  675    tmp[0] += coord[0][j]*densest_point[j];
 
  676    tmp[1] += coord[1][j]*densest_point[j];
 
  677    tmp[2] += coord[2][j]*densest_point[j];
 
  682template<
typename PType>
 
  683void LensHaloParticles<PType>::calculate_smoothing(
int Nsmooth,PType *pp
 
  690  if(verbose) std::cout << 
"Calculating smoothing of particles ..." << std::endl
 
  691  << Nsmooth << 
" neighbors.  If there are a lot of particles this could take a while." << std::endl;
 
  701    for(
size_t i=0;i<Npoints;++i){
 
  702      pp[i].Size = tree3d.NNDistance(&pp[i][0],Nsmooth + 1);
 
  705    size_t chunksize = Npoints/nthreads;
 
  706    std::vector<std::thread> thr(nthreads);
 
  709    for(
int ii = 0; ii < nthreads ;++ii){
 
  710      if(ii == nthreads - 1){
 
  711        N = Npoints - ii*chunksize;
 
  714      thr[ii] = std::thread(LensHaloParticles<PType>::smooth_,&tree3d
 
  715                            ,&(pp[ii*chunksize]),N,Nsmooth);
 
  717    for(
int ii = 0; ii < nthreads ;++ii) thr[ii].join();
 
  720  if(verbose) std::cout << 
"done in " << difftime(t,to) << 
" secs" << std::endl;
 
  723template<
typename PType>
 
  724void LensHaloParticles<PType>::smooth_(
TreeSimple<PType> *tree3d,PType *pp,
size_t N,
int Nsmooth){
 
  727  for(
size_t i=0;i<N;++i){
 
  728    pp[i].Size = tree3d->
NNDistance(&(pp[i][0]),Nsmooth + 1);
 
  733template<
typename PType>
 
  734void LensHaloParticles<PType>::writeSizes(
const std::string &filename,
int Nsmooth
 
  735                                          ,
const PType *pp,
size_t Npoints
 
  738  std::ofstream myfile(filename);
 
  742  if (myfile.is_open()){
 
  744    std::cout << 
"Writing particle size information to file " << filename << 
" ...." << std::endl;
 
  746    myfile << 
"# nparticles " << Npoints << std::endl;
 
  747    myfile << 
"# nsmooth " << Nsmooth << std::endl;
 
  748    for(
size_t i=0;i<Npoints;++i){
 
  749      myfile << pp[i].Size << std::endl;
 
  751        std::cerr << 
"Unable to write to file " << filename << std::endl;
 
  752        throw std::runtime_error(
"file writing error");
 
  756    std::cout << 
"done" << std::endl;
 
  759    std::cerr << 
"Unable to write to file " << filename << std::endl;
 
  760    throw std::runtime_error(
"file writing error");
 
  764template<
typename PType>
 
  766                                       std::string new_filename  
 
  768                                       ,
double particle_mass 
 
  775  size_t Npoints = total_mass/particle_mass;
 
  776  PosType Rmax = (1+redshift)*total_mass*Grav*lightspeed*lightspeed/sigma/sigma/2;
 
  780  std::ofstream datafile;
 
  781  datafile.open(new_filename);
 
  783  datafile << 
"# nparticles " << Npoints << std::endl;
 
  784  datafile << 
"# mass " << particle_mass << std::endl;
 
  786  for(
size_t i=0; i< Npoints ;++i){
 
  787    point[0] = ran.
gauss();
 
  788    point[1] = ran.
gauss();
 
  789    point[2] = ran.
gauss();
 
  791    point *= Rmax*ran()/point.length();
 
  796    datafile << point[0] << 
" " << point[1] << 
" " 
  797    << point[2] << 
" " << std::endl;
 
 
  804  template<
typename PType>
 
  807           ,
double particle_mass 
 
  816    size_t Npoints = total_mass/particle_mass;
 
  817    PosType Rmax = total_mass*Grav*lightspeed*lightspeed/sigma/sigma/2;
 
  821    std::cout << 
"making SIE LensHaloParticles..." << std::endl;
 
  822    std::cout << 
"# nparticles " << Npoints << std::endl;
 
  823    std::cout << 
"# mass " << particle_mass << std::endl;
 
  825    std::vector<ParticleTypeSimple> parts(Npoints);
 
  827    for(
auto &p : parts){
 
  832      double s = Rmax*ran()/sqrt(p[0]*p[0] + p[1]*p[1] + p[2]*p[2] );
 
  840      p.Mass = particle_mass;
 
 
 
  849template<
typename PType>
 
  851  if(
this == &h) 
return *
this;
 
  854  densest_point = h.densest_point;
 
  855  trash_collector =std::move(h.trash_collector);
 
  859  min_size = h.min_size;
 
  860  multimass = h.multimass;
 
  864  sizefile = h.sizefile;
 
  865  inv_area = h.inv_area;
 
  969  std::vector<LensHaloParticles<ParticleType<float> > *> 
halos;
 
  972  std::vector<size_t> 
getnp(){
return nparticles;}
 
  975  std::vector<float> 
getmp(){
return masses;}
 
  985                     ,
bool ignore_type_in_smoothing = 
false  
  994    for(
auto p : 
halos) 
delete p;
 
 1001  void CreateHalos(
const COSMOLOGY &cosmo,
double redshift,
double inv_area);
 
 1004  void radialCut(Point_3d<> center,
double radius);
 
 1020  double getZoriginal(){
return z_original;}
 
 1022  std::vector<ParticleType<float> > data;
 
 1024  const std::string filename;
 
 1031  double z_original = -1;
 
 1032  std::vector<size_t> nparticles;
 
 1033  std::vector<float> masses;
 
 1037  static void writeSizesB(
const std::string &filename
 
 1038                   ,std::vector<ParticleType<float> > &pv
 
 1039                   ,
int Nsmooth,std::vector<size_t> numbytype,
double redshift){
 
 1041    assert(numbytype.size() == 6);
 
 1042    size_t ntot = pv.size();
 
 1043    std::ofstream myfile(filename, std::ios::out | std::ios::binary);
 
 1044    if(!myfile.write((
char*)&Nsmooth,
sizeof(
int))){
 
 1045      std::cerr << 
"Unable to write to file " << filename << std::endl;
 
 1046      throw std::runtime_error(
"file writing error");
 
 1048      myfile.write((
char*)&ntot,
sizeof(
size_t));
 
 1049      myfile.write((
char*)(numbytype.data()),
sizeof(
size_t)*6);
 
 1050      myfile.write((
char*)&redshift,
sizeof(
double));
 
 1051      myfile.write((
char*)(pv.data()),
sizeof(ParticleType<float>)*ntot);
 
 1056  static bool readSizesB(
const std::string &filename
 
 1057                   ,std::vector<ParticleType<float> > &pv
 
 1058                  ,
int &Nsmooth,std::vector<size_t> &numbytype,
double &redshift){
 
 1060    numbytype.resize(6);
 
 1061    size_t ntot = pv.size();
 
 1062    std::ifstream myfile(filename, std::ios::in | std::ios::binary);
 
 1063    if(!myfile.read((
char*)&Nsmooth,
sizeof(
int))){
 
 1066      myfile.read((
char*)&ntot,
sizeof(
size_t));
 
 1067      myfile.read((
char*)(numbytype.data()),
sizeof(
size_t)*6);
 
 1068      myfile.read((
char*)&redshift,
sizeof(
double));
 
 1070      myfile.read((
char*)(pv.data()),
sizeof(ParticleType<float>)*ntot);
 
 1076  bool readGadget2(
bool ignore_type);
 
 1079  bool readCSV(
int columns_used);
 
 
 1091template<
typename HType>
 
 1092class LensHaloHalos : 
public LensHalo 
 1096  LensHaloHalos(std::vector<HType> &pvector 
 
 1098                    ,
const COSMOLOGY& cosmo  
 
 1100                    ,
float my_theta_force=0.1
 
 1101                    ,
bool mu_periodic_buffer = 
false 
 1103  ):
LensHalo(redshift,cosmo),inv_area(inv_area),theta_force(my_theta_force),periodic_buffer(mu_periodic_buffer)
 
 1105    std::swap(pvector,trash_collector);
 
 1106    Nhalos = trash_collector.size();
 
 1109    for(
size_t ii = 0 ; ii < Nhalos ; ++ii) vpp[ii] = &trash_collector[ii];
 
 1110    set_up(redshift,cosmo,verbose);
 
 1114  LensHaloHalos(LensHaloHalos &&h):
LensHalo(std::move(h)){
 
 1115    mcenter = h.mcenter;
 
 1116    trash_collector =std::move(h.trash_collector);
 
 1117    vpp = std::move(h.vpp);
 
 1125    inv_area = h.inv_area;
 
 1127  LensHaloHalos & operator=(LensHaloHalos &&h);
 
 1130  void force_halo(
double *alpha,KappaType *kappa,KappaType *gamma,KappaType *phi
 
 1132                  ,
bool subtract_point=
false,PosType screening = 1.0);
 
 1134  size_t getN()
 const { 
return Nhalos; };
 
 1137  Point_2d CenterOfMass(){
return mcenter;}
 
 1143  std::vector<HType *> vpp;
 
 1144  std::vector<HType> trash_collector;
 
 1146  Utilities::Geometry::SphericalPoint<> center;
 
 1151  bool periodic_buffer;
 
 1153  TreeQuadHalos<HType> * qtree;
 
 1155  void set_up(
float redshift,
const COSMOLOGY& cosmo,
bool verbose);
 
 1158template<
typename HType>
 
 1159void LensHaloHalos<HType>::set_up(
 
 1165  LensHalo::set_flag_elliptical(
false);
 
 1168  LensHalo::setRsize(Rmax);
 
 1173  PosType max_mass = 0.0,min_mass = HUGE_VALF,mass=0;
 
 1175  for(HType &h : trash_collector){
 
 1177    mcenter[0] += h[0]*h.get_mass();
 
 1178    mcenter[1] += h[1]*h.get_mass();
 
 1180    mass += h.get_mass();
 
 1182    max_mass = (h.get_mass() > max_mass) ? h.get_mass() : max_mass;
 
 1183    min_mass = (h.get_mass() < min_mass) ? h.get_mass() : min_mass;
 
 1185  LensHalo::setMass(mass);
 
 1189  if(verbose) std::cout << 
"   Particle mass range : " << min_mass << 
" to " << max_mass << 
"  ratio of : " << max_mass/min_mass << std::endl;
 
 1191  qtree = 
new TreeQuadHalos<HType>(vpp.data(),Nhalos,inv_area,5,theta_force,periodic_buffer);
 
 1194template<
typename HType>
 
 1195LensHaloHalos<HType>::~LensHaloHalos(){
 
 1199template<
typename HType>
 
 1200void LensHaloHalos<HType>::force_halo(
double *alpha,KappaType *kappa
 
 1201                               ,KappaType *gamma,KappaType *phi
 
 1203                                          ,
bool subtract_point,PosType screening){
 
 1204  qtree->force2D(xcm,alpha,kappa,gamma,phi);
 
 1211template<
typename HType>
 
 1212LensHaloHalos<HType> & LensHaloHalos<HType>::operator=(LensHaloHalos<HType> &&h){
 
 1213  if(
this == &h) 
return *
this;
 
 1215  mcenter = h.mcenter;
 
 1217  trash_collector =std::move(h.trash_collector);
 
 1218  vpp = std::move(h.vpp);  
 
 
 
 
 
The cosmology and all the functions required to calculated quantities based on the cosmology.
Definition cosmo.h:52
 
A base class for all types of lensing "halos" which are any mass distribution that cause lensing.
Definition lens_halos.h:56
 
void setZlens(PosType my_zlens, const COSMOLOGY &cosmo)
set redshift
Definition lens_halos.h:137
 
LensHalo()
Shell constructor.
Definition lens_halos.cpp:14
 
LensHalo & operator=(const LensHalo &h)
Definition lens_halos.cpp:169
 
virtual void setCosmology(const COSMOLOGY &cosmo)
used for elliptical NFWs only, in that case get_switch_flag==true
Definition lens_halos.h:163
 
A class that represents the lensing by a collection of simulation particles.
Definition particle_halo.h:41
 
Point_3d DensestPoint()
get the densistt point in input coordinates
Definition particle_halo.h:128
 
LensHaloParticles(float redshift, const COSMOLOGY &cosmo)
Definition particle_halo.h:182
 
LensHaloParticles(PType *pdata, size_t Nparticles, float redshift, const COSMOLOGY &cosmo, Point_2d theta_rotate, bool recenter, double my_inv_area, bool verbose=false)
Definition particle_halo.h:188
 
static LensHaloParticles< ParticleTypeSimple > SIE(PosType redshift, double particle_mass, double total_mass, double sigma, double q, int Nneighbors, COSMOLOGY &cosmo, Utilities::RandomNumbers_NR &ran)
This is a test static function that makes a truncated SIE out of particles and puts it into a file in...
Definition particle_halo.h:805
 
LensHaloParticles(PType *begin, size_t n, float redshift, const COSMOLOGY &cosmo, Point_2d theta_rotate, bool recenter, double my_inv_area, float MinPSize=0, double max_range=-1, bool verbose=false)
this constructor does not take possession of the particles
Definition particle_halo.h:78
 
void readPositionFileASCII(const std::string &filename)
Reads number of particle and particle positons into Npoint and xp from a ASCII file.
Definition particle_halo.h:453
 
Point_3d CenterOfMass()
get current center of mass in input coordinates
Definition particle_halo.h:126
 
void rotate(Point_2d theta)
rotate the simulation around the origin of the simulation coordinates, (radians)
Definition particle_halo.h:438
 
static void makeSIE(std::string new_filename, PosType redshift, double particle_mass, double total_mass, double sigma, double q, Utilities::RandomNumbers_NR &ran)
This is a test static function that makes a truncated SIE out of particles and puts it into a file in...
Definition particle_halo.h:765
 
void set_up(float redshift, const COSMOLOGY &cosmo, Point_2d theta_rotate, double max_range, bool recenter, bool verbose)
Definition particle_halo.h:342
 
LensHaloParticles(const std::string &simulation_filename, SimFileFormat format, PosType redshift, int Nsmooth, const COSMOLOGY &cosmo, Point_2d theta_rotate, bool recenter, bool my_multimass, double inv_area, PosType MinPSize=0, PosType rescale_mass=1.0, bool verbose=false)
Definition particle_halo.h:228
 
LensHaloParticles(std::vector< PType > &pvector, float redshift, const COSMOLOGY &cosmo, Point_2d theta_rotate, bool recenter, double my_inv_area, float MinPSize=0, double max_range=-1, bool verbose=false)
Definition particle_halo.h:58
 
A class for constructing LensHalos from particles in a data file.
Definition particle_halo.h:964
 
Point_3d getCenterOfMass() const
returns the original center of mass of all the particles
Definition particle_halo.h:1009
 
std::vector< size_t > getnp()
returns number of particles of each type
Definition particle_halo.h:972
 
double sim_redshift()
returns original redshift of snapshot, redshifts of the halos can be changed
Definition particle_halo.h:978
 
MakeParticleLenses(const std::string &filename, SimFileFormat format, int Nsmooth, bool recenter, bool ignore_type_in_smoothing=false)
Definition particle_lens.cpp:22
 
std::vector< LensHaloParticles< ParticleType< float > > * > halos
vector of LensHalos, one for each type of particle type
Definition particle_halo.h:969
 
Point_3d densest_particle()
returns the location of the densest particle in (Mpc/h)
Definition particle_lens.cpp:480
 
void cylindricalCut(Point_2d center, double radius)
remove particles that are beyond cylindrical radius (Mpc/h) of center
Definition particle_lens.cpp:497
 
void CreateHalos(const COSMOLOGY &cosmo, double redshift, double inv_area)
Definition particle_lens.cpp:153
 
std::vector< float > getmp()
returns mass of particles of each type, if 0 they can have different masses
Definition particle_halo.h:975
 
void Recenter(Point_3d<> x)
recenter the particles to 3d point in physical Mpc/h units If the halos have already been created the...
Definition particle_lens.cpp:139
 
void radialCut(Point_3d<> center, double radius)
remove particles that are beyond radius (Mpc/h) from center
Definition particle_lens.cpp:447
 
void getBoundingBox(Point_3d<> &Xmin, Point_3d<> &Xmax) const
return the maximum and minimum coordinates of the particles in each dimension in for the original sim...
Definition particle_halo.h:1015
 
TreeQuadParticles is a class for calculating the deflection, kappa and gamma by tree method.
Definition quadTree.h:47
 
A C++ class wrapper for the bianary treeNB used in the Nbody force calculation, but also useful for g...
Definition simpleTree.h:86
 
T NNDistance(T *ray, int Nneighbors) const
Finds the nearest N neighbors and puts their index numbers in an array, also returns the distance to ...
Definition simpleTree.h:483
 
represents a point in spherical coordinates, theta = 0 is equator
Definition geometry.h:30
 
This is a class for generating random numbers. It simplifies and fool proofs initialization and allow...
Definition utilities_slsim.h:1059
 
PosType gauss()
generates a Gaussian distributed number with unit variance by polar Box-Muller transform
Definition utilities_slsim.h:1068
 
int CountColumns(std::string filename, char comment_char='#', char deliniator=' ')
Count the number of columns in a ASCII data file.
Definition utilities.cpp:614
 
int GetNThreads()
returns the compiler variable N_THREADS that is maximum number of threads to be used.
Definition utilities.cpp:553
 
SimFileFormat
Definition particle_types.h:32
 
@ ascii
the original ascii GLAMER format.
Definition particle_types.h:42
 
Class for representing points or vectors in 2 dimensions. Not that the dereferencing operator is over...
Definition point.h:48