9 #include "TFitResult.h"
30 const char*
const _F2 =
".f2";
39 int main(
int argc,
char **argv)
63 JParser<> zap(
"Auxiliary application to determine tilt angles of seabed based on measured tilt angles.");
65 zap[
'f'] =
make_field(inputFile,
"input file (output of JKatoomba[.sh]/JFremantle[.sh])");
66 zap[
'n'] =
make_field(numberOfEvents) = JLimit::max();
72 zap[
'Z'] =
make_field(
Z,
"detector height (for 2nd order tilt correction)") = 0.0;
73 zap[
'O'] =
make_field(option,
"ROOT fit option, see TH1::Fit.") =
"L";
74 zap[
'w'] =
make_field(writeFits,
"write fit function(s) to ROOT file " <<
"(\"<name>" << _F2 <<
"\")");
79 catch(
const exception &error) {
80 FATAL(error.what() << endl);
85 if (option.find(
'O') == string::npos) { option +=
"O"; }
86 if (option.find(
"R") == string::npos) { option +=
"R"; }
87 if (option.find(
"S") == string::npos) { option +=
"S"; }
89 if (
debug == 0 && option.find(
'Q') == string::npos) { option +=
"Q"; }
92 X.getNumberOfBins(),
X.getLowerLimit(),
X.getUpperLimit(),
93 Y.getNumberOfBins(),
Y.getLowerLimit(),
Y.getUpperLimit());
97 for (
counter_type counter = 0; in.hasNext() && counter != inputFile.getLimit(); ++counter) {
99 STATUS(
"event: " << setw(10) << counter <<
'\r');
DEBUG(endl);
101 const JEvt* evt = in.next();
108 for (JEvt::const_iterator
i = evt->begin();
i != evt->end(); ++
i) {
110 const double tx = (
i->tx +
i->tx2 *
Z) * 1.0e3;
111 const double ty = (
i->ty +
i->ty2 *
Z) * 1.0e3;
130 for (Int_t ix = 1; ix <= H2.GetXaxis()->GetNbins(); ++ix) {
131 for (Int_t iy = 1; iy <= H2.GetYaxis()->GetNbins(); ++iy) {
132 if (H2.GetBinContent(ix,iy) > z0) {
133 x0 = H2.GetXaxis()->GetBinCenter(ix);
134 y0 = H2.GetYaxis()->GetBinCenter(iy);
135 z0 = H2.GetBinContent(ix,iy);
143 TF2 f2(
"f2",
"[0] * exp(-0.5 * (x-[1])*(x-[1]) / ([2]*[2])) * exp(-0.5 * (y-[3])*(y-[3]) / ([4]*[4])) + [5] + [6]*x + [7]*y");
145 f2.SetParameter(0, z0 * 0.7);
146 f2.SetParameter(1, x0);
147 f2.SetParameter(2, 0.5);
148 f2.SetParameter(3, y0);
149 f2.SetParameter(4, 0.5);
150 f2.SetParameter(5, 0.0);
151 f2.SetParameter(6, 0.0);
152 f2.SetParameter(7, 0.0);
154 f2.SetParError(0, 0.1);
155 f2.SetParError(1, 0.02);
156 f2.SetParError(2, 0.02);
157 f2.SetParError(3, 0.02);
158 f2.SetParError(4, 0.02);
159 f2.SetParError(5, 0.001);
160 f2.SetParError(6, 0.001);
161 f2.SetParError(7, 0.001);
163 f2.SetRange(x0 +
x.getLowerLimit(), y0 +
y.getLowerLimit(), x0 +
x.getUpperLimit(), y0 +
y.getUpperLimit());
165 H2.GetXaxis()->SetRangeUser(x0 +
x.getLowerLimit(), x0 +
x.getUpperLimit());
166 H2.GetYaxis()->SetRangeUser(y0 +
y.getLowerLimit(), y0 +
y.getUpperLimit());
168 TFitResultPtr
result = H2.Fit(&f2, option.c_str(),
"same");
170 H2.GetXaxis()->SetRangeUser(H2.GetXaxis()->GetXmin(), H2.GetXaxis()->GetXmax());
171 H2.GetYaxis()->SetRangeUser(H2.GetYaxis()->GetXmin(), H2.GetYaxis()->GetXmax());
173 if (
result.Get() == NULL) {
174 FATAL(
"Invalid TFitResultPtr " << H2.GetName() << endl);
178 cout <<
"chi2/NDF " <<
FIXED(7,3) <<
result->Chi2() <<
'/' <<
result->Ndf() <<
' ' << (
result->IsValid() ?
"" :
"failed") << endl;
181 cout <<
"tilt: " <<
FIXED(9,6) << f2.GetParameter(1)*1.0e-3 <<
' ' <<
FIXED(9,6) << f2.GetParameter(3)*1.0e-3 << endl;
190 TH2D* h2 = (TH2D*) H2.Clone(
MAKE_CSTRING(H2.GetName() << _F2));
194 for (Int_t ix = 1; ix <= h2->GetXaxis()->GetNbins(); ++ix) {
195 for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
197 const Double_t
x = h2->GetXaxis()->GetBinCenter(ix);
198 const Double_t
y = h2->GetYaxis()->GetBinCenter(iy);
200 h2->SetBinContent(ix, iy, f2.Eval(x,y));
201 h2->SetBinError (ix, iy, 0.0);
Utility class to parse command line options.
int main(int argc, char *argv[])
ROOT TTree parameter settings.
#define MAKE_CSTRING(A)
Make C-string.
Long64_t counter_type
Type definition for counter.
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Auxiliary data structure for floating point format specification.
Auxiliary class for multiplexing object iterators.
Auxiliary class for defining the range of iterations of objects.
Type definition of range.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
General purpose messaging.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Auxiliary class to define a range between two values.
General purpose class for object reading from a list of file names.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Utility class to parse command line options.
no fit printf nominal n $STRING awk v X
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
const JLimit & getLimit() const
Get limit.
JAbstractHistogram< double > JHistogram_t
Type definition for scan along axis.
#define DEBUG(A)
Message macros.