GLAMERDOC++
Gravitational Lensing Code Library
sourceAnaGalaxy.h
1 /*
2  * souceAnaLens.h
3  *
4  * Created on: Aug 13, 2012
5  * Author: bmetcalf
6  */
7 
8 #ifndef SOURCE_ANA_H_
9 #define SOURCE_ANA_H_
10 
11 #include "source.h"
12 #include "overzier_source.h"
13 #include "simpleTreeVec.h"
14 #include "utilities.h"
15 
33 public:
34  SourceMultiAnaGalaxy(PosType mag,PosType mag_bulge,Band band,PosType zero_point, PosType Reff, PosType Rdisk, PosType PA, PosType inclination,PosType my_z,PosType *my_theta
37  //SourceMultiAnaGalaxy(InputParams& params,Utilities::RandomNumbers_NR &ran);
39 
41  PosType SurfaceBrightness(const PosType* x) const {
42  PosType sb = galaxies[index].SurfaceBrightness(x);
43  if (sb < sb_limit) return 0.;
44  return sb;
45  }
46 
48  PosType getTotalFlux() const {return mag_to_flux(galaxies[index].getMag(),mag_zero_point);}
49 
50  void printSource();
51  // Add a pre-constructed galaxy to the source collection
52  void AddAGalaxy(SourceOverzierPlus *my_galaxy){galaxies.push_back(*my_galaxy);}
53 
57  SourceOverzierPlus& setIndex (std::size_t i){
58  if(i < galaxies.size())
59  index = i;
60  return galaxies[index];
61  }
66  if(i < galaxies.size())
67  return galaxies[i];
68  return galaxies[index];
69  }
70 
71  const SourceOverzierPlus& operator[] (std::size_t i) const {
72  if(i < galaxies.size())
73  return galaxies[i];
74  return galaxies[index];
75  }
76 
77  SourceOverzierPlus& CurrentGalaxy(){
78  return galaxies[index];
79  }
80 
82  //PosType getZ() const {return galaxies[index].getZ();}
83  PosType getZ() const {return galaxies[index].getZ();}
84  //PosType getRadius() const {return max(galaxies[index]->Reff,galaxies[index]->Rdisk);}
85  PosType getRadius() const {return galaxies[index].getRadius();}
87  void setZ(PosType my_z){ galaxies[index].setZ(my_z);}
88  void resetBand(Band my_band){
89  for(size_t i=0;i<galaxies.size();++i) galaxies[i].changeBand(my_band);
90  band = my_band;
91  }
92 
93  unsigned long getID(){return galaxies[index].getID();}
94 
95 
97  Point_2d getTheta() const{return galaxies[index].getTheta();}
99  void setTheta(PosType my_theta[2]){galaxies[index].setTheta(my_theta);}
100  void setTheta(PosType my_x,PosType my_y){galaxies[index].setTheta(my_x, my_y);}
101  void setTheta(const Point_2d &p){galaxies[index].setTheta(p);}
102 
103  std::size_t getNumberOfGalaxies() const {return galaxies.size();}
104 
105  void multiplier(PosType z,PosType mag_cut,int Multiplicity,Utilities::RandomNumbers_NR &ran);
106  void sortInRedshift();
107  void sortInMag(Band tmp_band);
108  void sortInID();
110  PosType getFOV(){return (rangex[1]-rangex[0])*(rangey[1]-rangey[0])*180*180/PI/PI;}
111 
115  std::size_t findclosestonsky(PosType theta[],PosType *radius){
116  size_t index;
117  searchtree->NearestNeighbor(theta,*radius,index);
118  return index;
119  }
120 
123  void findclosestonsky(PosType theta[],std::vector<PosType> &radius,std::vector<size_t> &indexes){
124  indexes.resize(radius.size());
125  searchtree->NearestNeighbors(theta,radius.size(),radius,indexes);
126  return;
127  }
128 
130  void findonsky(PosType theta[],float radius,std::list<size_t> &indexes){
131  indexes.clear();
132  searchtree->PointsWithinCircle(theta,radius,indexes);
133  return;
134  }
135 
137  void findnear(PosType theta[],float radius,std::list<size_t> &indexes,PosType z_range[]){
138  indexes.clear();
139  searchtree->PointsWithinCircle(theta,radius,indexes);
140 
141  PosType z;
142  // make redshift cut for lens sources
143  for(std::list<size_t>::iterator itt = indexes.begin();
144  itt != indexes.end(); ++itt){
145  z = galaxies[*itt].getZ();
146  if(z < z_range[0] || z > z_range[1]){
147  indexes.erase(itt);
148  if(itt != indexes.begin()) --itt;
149  }
150  }
151 
152  return;
153  }
154 
155 private:
156  // make it uncopyable
157  //SourceMultiAnaGalaxy(SourceMultiAnaGalaxy &s){};
158  SourceMultiAnaGalaxy & operator=(SourceMultiAnaGalaxy &s){return s;}
159 
160  Band band;
161  float mag_limit;
162  std::size_t index;
163 
164  std::vector<SourceOverzierPlus> galaxies;
166  std::string input_gal_file;
167 
168  void readDataFileMillenn(std::map<Band,double> zeropoints,Utilities::RandomNumbers_NR &ran);
169  void assignParams(InputParams& params);
170 
171  PosType rangex[2],rangey[2];
172 };
173 
174 bool redshiftcompare(SourceOverzierPlus s1,SourceOverzierPlus s2);
175 bool magcompare(SourceOverzierPlus s1,SourceOverzierPlus s2);
176 bool idcompare(SourceOverzierPlus s1,SourceOverzierPlus s2);
177 
185 public:
186 
187  //SourceMultiShapelets(InputParams& params);
188 
189  SourceMultiShapelets(double mag_zero_point):Source(0,Point_2d(0,0),0,-1,mag_zero_point){};
190 
192  SourceMultiShapelets(const std::string &my_shapelets_folder
193  ,Band my_band
194  ,double my_max_mag_limit
195  ,double my_min_mag_limit
196  ,double my_z_max
197  ,double my_sb_limit
198  ,double maximum_radius
199  ,double zero_point
200  );
201 
202  void input(const std::string &my_shapelets_folder
203  ,Band my_band
204  ,double my_max_mag_limit
205  ,double my_min_mag_limit
206  ,double my_z_max
207  ,double my_sb_limit
208  ,double maximum_radius
209  ,double zero_point
210  );
211 
213  void sortInRedshift();
214  void sortInMag();
216  PosType SurfaceBrightness(const PosType* x)const {
217  PosType sb = galaxies[index].SurfaceBrightness(x);
218  if (sb < sb_limit) return 0.;
219  return sb;
220  }
221 
222  void printSource();
223  std::size_t getNumberOfGalaxies() const {return galaxies.size();}
225  std::size_t size() const {return galaxies.size();}
226 
228  PosType getTotalFlux() const {return mag_to_flux(galaxies[index].getMag(),mag_zero_point);}
229 
231  Point_2d getTheta() const {return galaxies[index].getTheta();}
233  void setTheta(PosType my_theta[2]){galaxies[index].setTheta(my_theta);}
234  void setTheta(PosType my_x,PosType my_y){galaxies[index].setTheta(my_x, my_y);}
235  void setTheta(const Point_2d &p){galaxies[index].setTheta(p);}
236 
238  PosType getZ() const {return galaxies[index].getZ();}
239  //PosType getRadius() const {return max(galaxies[index]->Reff,galaxies[index]->Rdisk);}
240  PosType getRadius() const {return galaxies[index].getRadius();}
241 
245  SourceShapelets& setIndex (std::size_t i){
246  if(i < galaxies.size())
247  index = i;
248  return galaxies[index];
249  }
250  size_t getIndex() const {return index;}
251 
255  SourceShapelets& operator[] (std::size_t i){
256  if(i < galaxies.size())
257  return galaxies[i];
258  return galaxies[index];
259  }
260  const SourceShapelets &operator[](std::size_t i) const{
261  if (i < galaxies.size())
262  return galaxies[i];
263  return galaxies[index];
264  }
265 
266  SourceShapelets& back(){
267  return galaxies.back();
268  }
269 
270  SourceShapelets& CurrentGalaxy(){
271  return galaxies[index];
272  }
273 
275  SourceShapelets& setBand (Band b,double zeropoint){
276  band = b;
277  for (int i = 0; i < galaxies.size(); i++)
278  galaxies[i].setActiveBand(band);
279  return galaxies[index];
280  }
281 
283  int locateZ(PosType z) const {
284  return Utilities::locate<SourceShapelets,PosType>(galaxies, z, [](PosType z,const SourceShapelets &s){return (z < s.getZ());});
285  }
286 
287  int getCurrentID(){
288  return galaxies[index].id;
289  }
290 
291  std::vector<SourceShapelets> galaxies;
292 
293 private:
294  void assignParams(InputParams& params);
295  std::size_t index;
296  float max_mag_limit;
297  float min_mag_limit;
298  float z_max; // maximum redshift allowed
299  Band band;
300  double radius_max;
301 
302  void readCatalog();
303  std::string shapelets_folder;
304 };
305 
306 bool redshiftcompare_shap(SourceShapelets s1,SourceShapelets s2);
307 bool magcompare_shap(SourceShapelets s1,SourceShapelets s2);
308 
309 #endif /* SOURCE_H_ */
SourceMultiShapelets::operator[]
SourceShapelets & operator[](std::size_t i)
Definition: sourceAnaGalaxy.h:255
SourceMultiAnaGalaxy::SurfaceBrightness
PosType SurfaceBrightness(const PosType *x) const
Surface brightness of current galaxy.
Definition: sourceAnaGalaxy.h:41
SourceMultiAnaGalaxy::getFOV
PosType getFOV()
returns field-of-view in deg^2 assuming region is square
Definition: sourceAnaGalaxy.h:110
SourceMultiAnaGalaxy::multiplier
void multiplier(PosType z, PosType mag_cut, int Multiplicity, Utilities::RandomNumbers_NR &ran)
Artificially increase the number of sources to increase the incidence of strong lenses.
Definition: sourceAnaGalaxy.cpp:338
SourceMultiAnaGalaxy::sortInMag
void sortInMag(Band tmp_band)
Sort the sources by magnitude in assending order.
Definition: sourceAnaGalaxy.cpp:393
SourceMultiAnaGalaxy::findclosestonsky
std::size_t findclosestonsky(PosType theta[], PosType *radius)
Finds the closest source to the position theta[] on the sky in Cartesian distance....
Definition: sourceAnaGalaxy.h:115
Source
Base class for all sources.
Definition: source.h:44
SourceMultiAnaGalaxy::operator[]
SourceOverzierPlus & operator[](std::size_t i)
The indexing operator can be used to change the "current" source that is returned when the surface br...
Definition: sourceAnaGalaxy.h:65
SourceMultiShapelets::sortInMag
void sortInMag()
Sort the sources by magnitude in assending order.
Definition: source.cpp:934
SourceMultiShapelets::locateZ
int locateZ(PosType z) const
If the sources are already sorted by redshift this will find the index of the first galaxy with redsh...
Definition: sourceAnaGalaxy.h:283
Source::getZ
PosType getZ() const
Redshift of source.
Definition: source.h:100
Band
Band
Photometric bands.
Definition: InputParams.h:79
SourceMultiAnaGalaxy
Source that represents an analytic galaxy surface brightness model. It encapsulates a OverzierSource ...
Definition: sourceAnaGalaxy.h:32
SourceMultiAnaGalaxy::setIndex
SourceOverzierPlus & setIndex(std::size_t i)
Used to change the "current" source that is returned when the surface brightness is subsequently call...
Definition: sourceAnaGalaxy.h:57
Point_2d
Class for representing points or vectors in 2 dimensions. Not that the dereferencing operator is over...
Definition: point.h:48
SourceMultiShapelets::getTotalFlux
PosType getTotalFlux() const
Total flux coming from the current galaxy in erg/sec/Hz/cm^2.
Definition: sourceAnaGalaxy.h:228
SourceMultiShapelets
Class for reading in and handling an array of SourceShapelets, made on the model of SourceMultiAnaGal...
Definition: sourceAnaGalaxy.h:184
Utilities::RandomNumbers_NR
This is a class for generating random numbers. It simplifies and fool proofs initialization and allow...
Definition: utilities_slsim.h:1068
SourceMultiShapelets::getTheta
Point_2d getTheta() const
Return angular position of current source.
Definition: sourceAnaGalaxy.h:231
SourceMultiShapelets::setTheta
void setTheta(PosType my_theta[2])
Set angular position of current source.
Definition: sourceAnaGalaxy.h:233
SourceMultiShapelets::printSource
void printSource()
Print info on current source parameters.
Definition: source.cpp:921
SourceOverzierPlus
Adds some extra features to the SourceOverzier source like spiral arms, and randomizations.
Definition: overzier_source.h:155
TreeSimpleVec< SourceOverzierPlus >
TreeSimpleVec::PointsWithinCircle
void PointsWithinCircle(D center[2], float radius, std::list< unsigned long > &neighborkist)
Finds the points within a circle around center and puts their index numbers in a list.
Definition: simpleTreeVec.h:316
SourceMultiAnaGalaxy::setTheta
void setTheta(PosType my_theta[2])
Set angular position of current source.
Definition: sourceAnaGalaxy.h:99
TreeSimpleVec::NearestNeighbors
void NearestNeighbors(D *ray, int Nneighbors, std::vector< D > &radii, std::vector< IndexType > &neighbors)
Finds the nearest N neighbors and puts their index numbers in an array, also returns the distance to ...
Definition: simpleTreeVec.h:463
SourceMultiShapelets::getZ
PosType getZ() const
Return redshift of current source.
Definition: sourceAnaGalaxy.h:238
SourceMultiAnaGalaxy::setZ
void setZ(PosType my_z)
Set redshift of current source. Only changes the redshift while leaving position fixed.
Definition: sourceAnaGalaxy.h:87
SourceMultiAnaGalaxy::printSource
void printSource()
Print info on current source parameters.
Definition: sourceAnaGalaxy.cpp:432
SourceMultiAnaGalaxy::findnear
void findnear(PosType theta[], float radius, std::list< size_t > &indexes, PosType z_range[])
finds objects within radios of theta[] on unlensed sky and within a redshift range.
Definition: sourceAnaGalaxy.h:137
SourceMultiAnaGalaxy::getZ
PosType getZ() const
Return redshift of current source.
Definition: sourceAnaGalaxy.h:83
SourceMultiShapelets::setBand
SourceShapelets & setBand(Band b, double zeropoint)
Sets the active band for all the objects.
Definition: sourceAnaGalaxy.h:275
SourceMultiAnaGalaxy::findclosestonsky
void findclosestonsky(PosType theta[], std::vector< PosType > &radius, std::vector< size_t > &indexes)
finds closest sources to theta on umlensed sky. "radius" should have a size equal ti the number wante...
Definition: sourceAnaGalaxy.h:123
SourceMultiShapelets::input
void input(const std::string &my_shapelets_folder, Band my_band, double my_max_mag_limit, double my_min_mag_limit, double my_z_max, double my_sb_limit, double maximum_radius, double zero_point)
Definition: source.cpp:750
SourceMultiAnaGalaxy::SourceMultiAnaGalaxy
SourceMultiAnaGalaxy(PosType mag, PosType mag_bulge, Band band, PosType zero_point, PosType Reff, PosType Rdisk, PosType PA, PosType inclination, PosType my_z, PosType *my_theta, Utilities::RandomNumbers_NR &ran)
Source model for a single analytic galaxy model.
Definition: sourceAnaGalaxy.cpp:15
TreeSimpleVec::NearestNeighbor
void NearestNeighbor(D *ray, D &radius, IndexType &neighbor)
finds the nearest neighbors in whatever dimensions tree is defined in
Definition: simpleTreeVec.h:529
SourceMultiAnaGalaxy::getTheta
Point_2d getTheta() const
Return angular position of current source.
Definition: sourceAnaGalaxy.h:97
SourceMultiShapelets::sortInRedshift
void sortInRedshift()
Sort the sources by redshift in assending order.
Definition: source.cpp:926
SourceMultiShapelets::SurfaceBrightness
PosType SurfaceBrightness(const PosType *x) const
Surface brightness of current galaxy.
Definition: sourceAnaGalaxy.h:216
SourceMultiAnaGalaxy::findonsky
void findonsky(PosType theta[], float radius, std::list< size_t > &indexes)
finds objects within radios of theta[] on umlensed sky.
Definition: sourceAnaGalaxy.h:130
Source::Source
Source(PosType r, Point_2d x, PosType z, PosType SBlimit, PosType zero_point)
shell constructor
Definition: source.h:48
SourceShapelets
Class for sources described by shapelets.
Definition: source.h:368
SourceMultiShapelets::size
std::size_t size() const
number of galaxies
Definition: sourceAnaGalaxy.h:225
InputParams
Structure for reading and writing parameters to and from a parameter file as well as a container for ...
Definition: InputParams.h:99
SourceMultiAnaGalaxy::sortInRedshift
void sortInRedshift()
Sort the sources by redshift in assending order.
Definition: sourceAnaGalaxy.cpp:382
SourceMultiShapelets::setIndex
SourceShapelets & setIndex(std::size_t i)
Definition: sourceAnaGalaxy.h:245
SourceMultiAnaGalaxy::getTotalFlux
PosType getTotalFlux() const
Total flux coming from the current galaxy in erg/sec/Hz/cm^2.
Definition: sourceAnaGalaxy.h:48
SourceMultiAnaGalaxy::sortInID
void sortInID()
Sort the sources by magnitude in assending order.
Definition: sourceAnaGalaxy.cpp:415