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