00001
00006
00007 #include "node.h"
00008
00009 #ifdef TOOLBOX
00010
00011 local void get_mass_dist(node* b, int num_of_bins, bool verbose)
00012 {
00013 int n = b->n_leaves();
00014 real * mass = new real[n];
00015
00016 real min_mass = VERY_LARGE_NUMBER;
00017 real max_mass = -VERY_LARGE_NUMBER;
00018 real mean_mass = 0;
00019
00020 int i = 0;
00021 int j = 0;
00022
00023 for_all_leaves(node, b, bb) {
00024
00025 mass[i] = bb->get_mass();
00026 if ( mass[i] <= min_mass ) min_mass = mass[i];
00027 if ( mass[i] >= max_mass ) max_mass = mass[i];
00028 mean_mass += mass[i];
00029
00030 mass[i] = log10(mass[i]);
00031 i++;
00032
00033 }
00034
00035 if (verbose) {
00036 PRL(min_mass);
00037 PRL(max_mass);
00038 mean_mass /= i;
00039 PRL(mean_mass);
00040 }
00041
00042 if (num_of_bins <= 0) return;
00043
00044 min_mass = log10(min_mass);
00045 max_mass = log10(max_mass);
00046
00047
00048
00049 real range = max_mass - min_mass;
00050 real width = range / (float)num_of_bins;
00051
00052 real * bin = new real[num_of_bins + 1];
00053 int * n_in_bin = new int[num_of_bins];
00054
00055 bin[0] = min_mass;
00056 for ( j = 1; j <= num_of_bins; j++ ) {
00057 bin[j] = bin[0] + (real)j * width;
00058 }
00059
00060
00061
00062
00063
00064
00065
00066 for ( i = 0; i < n; i++ )
00067 for ( j = 0; j < num_of_bins; j++ )
00068 if ( mass[i] >= bin[j] && mass[i] <= bin[j+1] ) {
00069 n_in_bin[j]++;
00070 break;
00071 }
00072
00073
00074
00075
00076
00077
00078 for ( j = 0; j < num_of_bins; j++ ) {
00079 real m = 0.5 * (bin[j] + bin[j+1]);
00080 real dm = pow(10.0, bin[j+1]) - pow(10.0, bin[j]);
00081 cerr << m << " ";
00082 if (n_in_bin[j] > 0)
00083 cerr << log10(n_in_bin[j]/(n*dm));
00084 else
00085 cerr << "---";
00086 cerr << endl;
00087 }
00088
00089 delete mass;
00090 delete bin;
00091 delete n_in_bin;
00092 }
00093
00094 void main(int argc, char ** argv)
00095 {
00096 node* b;
00097 int num_of_bins = 25;
00098 bool verbose = false;
00099
00100 check_help();
00101
00102 extern char *poptarg;
00103 int c;
00104 char* param_string = "b:v";
00105
00106 while ((c = pgetopt(argc, argv, param_string)) != -1)
00107 switch(c) {
00108
00109 case 'b': num_of_bins = atoi(poptarg);
00110 break;
00111 case 'v': verbose = !verbose;
00112 break;
00113 case '?': params_to_usage(cerr, argv[0], param_string);
00114 get_help();
00115 exit(1);
00116 }
00117
00118 while ((b = get_node(cin))) {
00119 get_mass_dist(b, num_of_bins, verbose);
00120 delete b;
00121 }
00122 }
00123 #endif
00124