1 | #include "machdefs.h" |
---|
2 | |
---|
3 | //---- System et stdc++ include files |
---|
4 | #include <stdio.h> |
---|
5 | #include <stdlib.h> |
---|
6 | #include <math.h> |
---|
7 | #include <ctype.h> |
---|
8 | #include <string.h> |
---|
9 | #include <iostream> |
---|
10 | #include <fstream> |
---|
11 | #include <complex> |
---|
12 | |
---|
13 | #include <typeinfo> |
---|
14 | #include <string> |
---|
15 | #include <vector> |
---|
16 | #include <map> |
---|
17 | #include <functional> |
---|
18 | #include <list> |
---|
19 | |
---|
20 | //---- Sophya include files |
---|
21 | #include "sopnamsp.h" |
---|
22 | #include "basetools.h" |
---|
23 | #include "systools.h" |
---|
24 | #include "sutils.h" |
---|
25 | #include "ntools.h" |
---|
26 | #include "array.h" |
---|
27 | #include "histats.h" |
---|
28 | |
---|
29 | //---- Spiapp include files |
---|
30 | #include "nobjmgr.h" |
---|
31 | #include "servnobjm.h" |
---|
32 | |
---|
33 | //---- Include files from additionnal modules |
---|
34 | |
---|
35 | //---- function to compare bits on double |
---|
36 | int_8 BitCmp64(double v,int_8 flg) |
---|
37 | {return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;} |
---|
38 | |
---|
39 | //---- function for Adding and displaying Objects |
---|
40 | void Keep_Object(AnyDataObj & obj, string const & nom) |
---|
41 | { |
---|
42 | string name = nom; |
---|
43 | NamedObjMgr om; |
---|
44 | if (om.GetObj(name)) |
---|
45 | cerr << "KeepObj()/Warning Already kept object " << endl; |
---|
46 | else om.AddObj(obj, name); |
---|
47 | } |
---|
48 | |
---|
49 | void Display_Object(AnyDataObj & obj, string const & opt, string const & nom) |
---|
50 | { |
---|
51 | string name = nom; |
---|
52 | NamedObjMgr om; |
---|
53 | if (!om.GetObj(name)) |
---|
54 | om.AddObj(obj, name); |
---|
55 | om.DisplayObj(name, opt); |
---|
56 | } |
---|
57 | |
---|
58 | //---- function for getting and setting ObjectManager variables |
---|
59 | void Set_ObjMgrVar(MuTyV v, string const & nom) |
---|
60 | { |
---|
61 | NamedObjMgr om; |
---|
62 | om.SetVar(nom, (string)v); |
---|
63 | } |
---|
64 | |
---|
65 | MuTyV Get_ObjMgrVar(const char * nom) |
---|
66 | { |
---|
67 | string name = nom; NamedObjMgr om; |
---|
68 | MuTyV v = om.GetVar(name); |
---|
69 | return v; |
---|
70 | } |
---|
71 | |
---|
72 | //---- Macro for Objects and variables saving |
---|
73 | #define KeepObj(obj) Keep_Object(obj, #obj) |
---|
74 | #define GetOMVar(var) Get_ObjMgrVar( #var ) |
---|
75 | #define SetOMVar(var) Set_ObjMgrVar(var, #var ) |
---|
76 | |
---|
77 | //---- Macro Displaying objects and command execution |
---|
78 | #define DispObj(obj, att) Display_Object(obj, att, #obj); |
---|
79 | |
---|
80 | #define ExecCmd(cmd) srvo.ExecuteCommand(cmd); |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | //-------------------------------------------------// |
---|
85 | //----------------- User Functions ----------------// |
---|
86 | //-------------------------------------------------// |
---|
87 | |
---|
88 | extern "C" { |
---|
89 | int meanSigSum( vector<string>& args ); |
---|
90 | } |
---|
91 | |
---|
92 | int meanSigSum( vector<string>& args ) |
---|
93 | { |
---|
94 | // Some definitions to help using spiapp; |
---|
95 | NamedObjMgr omg; |
---|
96 | Services2NObjMgr& srvo = *omg.GetServiceObj(); |
---|
97 | |
---|
98 | //-------------- Object List -------------- |
---|
99 | //Number of objects = 2 |
---|
100 | string ___nomobj; |
---|
101 | |
---|
102 | ___nomobj = "invec"; |
---|
103 | TVector< r_4 > * ___invec = dynamic_cast< TVector< r_4 > * >(omg.GetObj(___nomobj)); |
---|
104 | |
---|
105 | ___nomobj = "inmat"; |
---|
106 | TMatrix< r_4 > * ___inmat = dynamic_cast< TMatrix< r_4 > * >(omg.GetObj(___nomobj)); |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | //--------------------------------------------// |
---|
112 | //----------------- User Code ----------------// |
---|
113 | //--------------------------------------------// |
---|
114 | |
---|
115 | sa_size_t NUMBER_OF_FREQ = 8192; |
---|
116 | sa_size_t bandWidth = 250; |
---|
117 | r_4 lowestFreq = 1250.; |
---|
118 | |
---|
119 | r_4 lowFreq = atof(args[0].c_str()); |
---|
120 | sa_size_t lowBin= (sa_size_t)(((lowFreq-lowestFreq)/bandWidth)*NUMBER_OF_FREQ); |
---|
121 | r_4 highFreq = atof(args[1].c_str()); |
---|
122 | sa_size_t highBin= (sa_size_t)(((highFreq-lowestFreq)/bandWidth)*NUMBER_OF_FREQ); |
---|
123 | |
---|
124 | cout << "Results for Freq Range: [" << lowFreq << ", " |
---|
125 | << highFreq << "]" << endl; |
---|
126 | |
---|
127 | if (___inmat!=NULL) { |
---|
128 | TMatrix< r_4 > & inmat = (*___inmat); |
---|
129 | for (sa_size_t iCh=0;iCh<inmat.NRows(); ++iCh){ |
---|
130 | TMatrix<r_4> tmp = inmat.SubMatrix(Range(iCh),Range(lowBin,highBin)); |
---|
131 | double mean; |
---|
132 | double sigma; |
---|
133 | MeanSigma(tmp,mean,sigma); |
---|
134 | double sum = tmp.Sum(); |
---|
135 | cout << "Ch [" << iCh <<"]: " |
---|
136 | << " mean/sigma: " << mean << " +/- " << sigma |
---|
137 | << " sum: " << sum |
---|
138 | << endl; |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | if (___invec!=NULL) { |
---|
143 | TVector< r_4 > & invec = (*___invec); |
---|
144 | TVector<r_4> tmp = invec.SubVector(Range(lowBin,highBin)); |
---|
145 | double mean; |
---|
146 | double sigma; |
---|
147 | MeanSigma(tmp,mean,sigma); |
---|
148 | double sum = tmp.Sum(); |
---|
149 | cout << " mean/sigma: " << mean << " +/- " << sigma |
---|
150 | << " sum: " << sum |
---|
151 | << endl; |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | return 0; |
---|
157 | } |
---|