Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMatrix_sol.cc File Reference

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

#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "Jeep/JParser.hh"
#include "JTools/JCombinatorics.hh"
#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 <string>
#include <iostream>
#include <set>

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

int main ( int  argc,
char **  argv 
)

Definition at line 32 of file JMatrix_sol.cc.

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 
65  JDetector detector;
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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
Definition: JDataQuality.sh:19
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
do set_variable DETECTOR_TXT $WORKDIR detector
int debug
debug level