Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JMatrix_sol.cc
Go to the documentation of this file.
4#include "Jeep/JParser.hh"
6
7#include <TVectorD.h>
8#include <TMatrixD.h>
9
10#include "TF2.h"
11#include "TFile.h"
12#include "TH1D.h"
13#include "TH2D.h"
14#include "TMath.h"
15#include "TMatrixDSym.h"
16#include "TROOT.h"
17#include "TVectorD.h"
18#include "TGraph.h"
19
20#include <string>
21#include <iostream>
22#include <set>
23
24
25/**
26 * \file
27 *
28 * Auxiliary program to determine best inter-DU time offsets from hit time correlations
29 *
30 * \author dsamtleben
31 */
32int main(int argc, char **argv)
33{
34 using namespace std;
35 using namespace JPP;
36 using namespace JMATH;
37
38 string inputFile;
39 string detectorFile;
40 string option;
41 double min_cont;
42 int idu_ref;
43 int debug;
44
45
46 try {
47
48 JParser<> zap("Program to calculate time offsets from FitL1dtSlices output");
49
50 zap['f'] = make_field(inputFile, "input file") = "nall.txt";
51 zap['a'] = make_field(detectorFile, "detector file");
52 zap['r'] = make_field(idu_ref, "reference DU set to t=0") = 0;
53 zap['m'] = make_field(min_cont, "minimal content" ) = 5;
54 zap['d'] = make_field(debug) = 0;
55
56
57 if (zap.read(argc, argv) != 0) {
58 return 1;
59 }
60 }
61 catch(const exception &error) {
62 FATAL(error.what() << endl);
63 }
64
66
67 try {
68 load(detectorFile, detector);
69 }
70 catch(const JException& error) {
71 FATAL(error);
72 }
73
74 const int number_of_strings = getNumberOfStrings(detector);
75
76 TVectorD means(1);
77 TMatrixD variance(1,1);
78 TMatrixD combimatrix(1,number_of_strings);
79
80 int du1,du2,du1_name,du2_name,nei;
81 int duarr[number_of_strings];
82 double off1,off2,offset,max1,max2;
83
84 means[0]=0.;
85 combimatrix(0,idu_ref)=1;
86
87 int npairs = 1;
88
89 std::ifstream file(inputFile);
90
91// --- read line with DU pair du1 & du2 and offset
92 while (file >> du1 >> du2 >> off1 >> off2 >> offset >> max1 >> max2 >> du1_name >> du2_name >> nei)
93 {
94 if (max1 > min_cont and max2 > min_cont and max1 < 50. and max2 < 50.){
95
96 combimatrix.ResizeTo(npairs+1,number_of_strings);
97 combimatrix(npairs,du1) = +1;
98 combimatrix(npairs,du2) = -1;
99
100 means.ResizeTo(npairs+1);
101 means[npairs]=offset;
102
103 duarr[du1]=du1_name;
104 duarr[du2]=du2_name;
105 npairs+=1;
106 }
107 }
108
109
110// Solve matrix equation:
111//
112// combimatrix: A
113// means: b
114//
115// A * string_time_offsets = b
116// string_time_offset = (A^T * A)^(-1) * (A^T * b)
117
118 TMatrixD combimatrix_T(number_of_strings,npairs);
119
120 combimatrix_T.Transpose(combimatrix); // A^T
121
122 TMatrixD pseudo = combimatrix_T * combimatrix; // A^T * A
123
124 TMatrixD pseudoinverse = pseudo.Invert(); // (A^T * A)^(-1)
125
126 TVectorD offsets = pseudoinverse * combimatrix_T * means; // (A^T * A)^(-1) * (A^T * b)
127
128 TVectorD residues = (combimatrix * offsets) - means;
129
130 std::cout.precision(3);
131
132 for (int ii=0;ii<number_of_strings;ii++){
133 cout << duarr[ii] << " " << offsets[ii] << endl;
134 }
135
136 double sumres=0.;
137 for (int ii=0;ii<npairs;ii++){
138 sumres+=fabs(residues[ii]);
139 }
140 cout << -1 << " " << sumres/double(npairs) << endl;
141
142 return 1;
143
144
145}
KM3NeT DAQ constants, bit handling, etc.
Data structure for detector geometry and calibration.
int main(int argc, char **argv)
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Detector data structure.
Definition JDetector.hh:96
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
int read(const int argc, const char *const argv[])
Parse the program's command line options.
Definition JParser.hh:1992
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Detector file.
Definition JHead.hh:227