Jpp 21.0.0-rc.1-88-g0130508c4
the software that should make you happy
Loading...
Searching...
No Matches
JMatrix_sol.cc File Reference

Auxiliary program to determine best inter-DU time offsets from hit time correlations. More...

#include <string>
#include <iostream>
#include <set>
#include <TVectorD.h>
#include <TMatrixD.h>
#include "TF2.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TMath.h"
#include "TMatrixDSym.h"
#include "TROOT.h"
#include "TGraph.h"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "Jeep/JParser.hh"
#include "JTools/JCombinatorics.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to determine best inter-DU time offsets from hit time correlations.

Author
dsamtleben

Definition in file JMatrix_sol.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 33 of file JMatrix_sol.cc.

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}
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#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
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Detector file.
Definition JHead.hh:227