Jpp  18.0.0-rc.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JOffset_extract.cc File Reference

Auxiliary program to extract string-string correlation information from the output created with JMonitorL1dt. More...

#include <iostream>
#include <string>
#include <map>
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TF1.h"
#include "TMath.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JStringRouter.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to extract string-string correlation information from the output created with JMonitorL1dt.

Author
dsamtleben

Definition in file JOffset_extract.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 28 of file JOffset_extract.cc.

29 {
30  using namespace std;
31  using namespace JPP;
32 
33  string inputFile;
34  string outputFile;
35  string detectorFile;
36  int neighbour, setmax;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Program to extract time offsets of DOM-DOM correlations");
42 
43  zap['f'] = make_field(inputFile, "input file") = "monitor.root";
44  zap['o'] = make_field(outputFile, "output file") = "corr_max.root";
45  zap['a'] = make_field(detectorFile, "detector file");
46  zap['n'] = make_field(neighbour, "neighbour level") = 5;
47  zap['m'] = make_field(setmax, "minimal entries") = 5;
48  zap['d'] = make_field(debug) = 0;
49 
50  if (zap.read(argc, argv) != 0) {
51  return 1;
52  }
53  }
54  catch(const exception &error) {
55  FATAL(error.what() << endl);
56  }
57 
58 
59  JDetector detector;
60 
61  try {
62  load(detectorFile, detector);
63  }
64  catch(const JException& error) {
65  FATAL(error);
66  }
67 
68 
69  const JStringRouter string(detector);
70 
72 
73  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
74  zmap[module->getString()][module->getFloor()] = module->getID();
75  }
76 
77  struct h1_t {
78  h1_t() :
79  p(NULL) // pointer must be initialised
80  {}
81 
82  TH1D* p;
83  };
84 
85  TF1 f1("f1", "[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2])) + [3]");
86 
87  const int number_of_strings = getNumberOfStrings(detector);
88 
89 // cout << "number of strings " << number_of_strings << endl;
90 
91  double maxarr[number_of_strings][number_of_strings][3];
92  int duarr[number_of_strings];
93 
95 
96  TFile* in = TFile::Open(inputFile.c_str(), "exist");
97 
98  if (in == NULL || !in->IsOpen()) {
99  FATAL("File: " << inputFile << " not opened." << endl);
100  }
101 
102 
103  for (const auto& string_1 : zmap) {
104  duarr[string.getIndex(string_1.first)]=string_1.first;
105 
106  for (const auto& floor_1 : string_1.second) {
107 
108  const int module_1 = floor_1.second; // parent module
109 
110  TH2D* h2 = (TH2D*) in->Get(MAKE_CSTRING(module_1 << ".2S"));
111 
112  if (h2 == NULL) {
113  continue;
114  }
115 
116  for (const auto& string_2 : zmap) {
117  duarr[string.getIndex(string_2.first)]=string_2.first;
118 
119  if (string_1.first != string_2.first) {
120 
121  TH1D* h1 = H1[string_1.first][string_2.first].p;
122 
123  if (h1 == NULL) {
124 
125  h1 = new TH1D(MAKE_CSTRING(string_1.first << "_" << string_2.first << "_" << neighbour << ".2T"), NULL,
126  h2->GetYaxis()->GetNbins(), h2->GetYaxis()->GetXmin(), h2->GetYaxis()->GetXmax());
127 
128  H1[string_1.first][string_2.first].p = h1; // book keeping
129  }
130 
131  for (const auto& floor_2 : string_2.second) {
132  if (floor_1.first > floor_2.first && (floor_1.first - floor_2.first) == neighbour) { // floor condition
133 
134  const int module_2 = floor_2.second; // daughter module
135 
136  TH1D* py = h2->ProjectionY("__py",
137  h2->GetXaxis()->FindBin(TString(Form("%i", module_2))),
138  h2->GetXaxis()->FindBin(TString(Form("%i", module_2))), "e");
139 
140  h1->Add(py); // add data
141 
142  delete py;
143  }
144  }
145 //------------
146  if (floor_1.first == 18){
147 
148  double mm=h1->GetXaxis()->GetBinCenter(h1->GetMaximumBin());
149 
150  f1.SetParameter(0, double(h1->GetMaximum()));
151  f1.SetParameter(1, double(mm));
152  f1.SetParameter(2, 50.);
153 
154  // fit
155 
156  if (h1->GetMaximum()>0){
157 // cout << "we are fitting " << string_1.first << " " << string_2.first << endl;
158  h1->Fit(&f1,"LQ", "same");
159 
160 // maxarr[ string.getIndex(string_1.first) ][ string.getIndex(string_2.first) ][0] = h1->GetXaxis()->GetBinCenter(h1->GetMaximumBin());
161 // maxarr[ string.getIndex(string_1.first) ][ string.getIndex(string_2.first) ][1] = h1->GetMaximum();
162  maxarr[ string.getIndex(string_1.first) ][ string.getIndex(string_2.first) ][0] = h1->GetFunction("f1")->GetParameter(1);
163  maxarr[ string.getIndex(string_1.first) ][ string.getIndex(string_2.first) ][1] = h1->GetFunction("f1")->GetParameter(0);
164  maxarr[ string.getIndex(string_1.first) ][ string.getIndex(string_2.first) ][2] = h1->GetFunction("f1")->GetParameter(2);
165  }
166  }
167  } // if string 1 != string 2
168  } // loop over string 2
169  } // loop over modules of string 1
170  } // loop over string 1
171 
172 
173  for (int i=0;i<number_of_strings;i++){
174  for (int j=i+1;j<number_of_strings;j++){
175  if (maxarr[i][j][1]>setmax && maxarr[j][i][1]>setmax && maxarr[i][j][2]>20. && maxarr[j][i][2]>20.){
176  cout << i << " " << j << " " << maxarr[i][j][0] << " " << maxarr[j][i][0] << " " << (maxarr[i][j][0]-maxarr[j][i][0])/2. << " " << maxarr[i][j][1] << " " << maxarr[j][i][1] << " " << " " << duarr[i] << " " << duarr[j] << " " << neighbour << endl;
177  }
178  }
179  }
180 
181 
182 
183  TFile out(outputFile.c_str(), "recreate");
184 
185  out.cd();
186 
187  for (auto& h1 : H1) {
188  for (auto& h2 : h1.second) {
189  h2.second.p->Write();
190  }
191  }
192 
193  out.Close();
194 }
Utility class to parse command line options.
Definition: JParser.hh:1514
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
string outputFile
const JPolynome f1(1.0, 2.0, 3.0)
Function.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
then awk string
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.
int j
Definition: JPolint.hh:703
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] 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
Definition: JCanberra.sh:46
int debug
debug level