Jpp  18.2.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSTDevK40.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <array>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JROOT/JRootToolkit.hh"
#include "JCalibrate/JCalibrateK40.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JSTDevK40.cc.

30 {
31  using namespace std;
32  using namespace JPP;
33  using namespace KM3NETDAQ;
34 
35  const char* const address_t = "address";
36  const char* const index_t = "index";
37 
38  array<string, 2> inputFile;
39  string outputFile;
40  string detectorFile;
41  string option;
42  int debug;
43 
44  try {
45 
46  JParser<> zap;
47 
48  zap['f'] = make_field(inputFile, "1st output of JMergeCalibrateK40 and 2nd output of JFitK40");
49  zap['o'] = make_field(outputFile, "output file.") = "stdevk40.root";
50  zap['a'] = make_field(detectorFile, "detector file.");
51  zap['O'] = make_field(option, "axis label") = address_t, index_t;
52  zap['d'] = make_field(debug, "debug.") = 1;
53 
54  zap(argc, argv);
55  }
56  catch(const exception &error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
61  JDetector detector;
62 
63  try {
64  load(detectorFile, detector);
65  }
66  catch(const JException& error) {
67  FATAL(error);
68  }
69 
70  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
71 
72 
73  TFile* in[] = { NULL, NULL };
74 
75  for (int i = 0; i != 2; ++i) {
76 
77  in[i] = TFile::Open(inputFile[i].c_str(), "exist");
78 
79  if (in[i] == NULL || !in[i]->IsOpen()) {
80  FATAL("File: " << inputFile[i] << " not opened." << endl);
81  }
82  }
83 
84 
85  TFile out(outputFile.c_str(), "recreate");
86 
87  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
88 
89  if (module->getFloor() == 0) {
90  continue;
91  }
92 
93  TH2D* h2[] = {
94  (TH2D*) in[0]->Get(MAKE_CSTRING(module->getID() << _2R)),
95  (TH2D*) in[1]->Get(MAKE_CSTRING(module->getID() << _2F))
96  };
97 
98  if (h2[0] == NULL || h2[0]->GetEntries() == 0 ||
99  h2[1] == NULL || h2[1]->GetEntries() == 0) {
100  continue;
101  }
102 
103  DEBUG("Module " << setw(10) << module->getID() << ' ' << getLabel(module->getLocation()) << endl);
104 
105  const JCombinatorics_t combinatorics(*module);
106 
107  const JModuleAddressMap memo = demo.get(module->getID());
108 
109  TH1D h1(MAKE_CSTRING(module->getID() << ".1D"), NULL,
110  h2[0]->GetXaxis()->GetNbins(), h2[0]->GetXaxis()->GetXmin(), h2[0]->GetXaxis()->GetXmax());
111 
112  TH2D hx(MAKE_CSTRING(module->getID() << ".2X"), NULL,
113  NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5,
114  NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5);
115 
116  for (int ix = 1; ix <= h2[0]->GetXaxis()->GetNbins(); ++ix) {
117 
118  const pair_type pair = combinatorics.getPair(ix - 1);
119 
120  double Y = 0.0; // summed data
121  double F = 0.0; // summed function value
122  double V = 0.0; // summed standard deviation
123  int N = 0;
124 
125  for (int iy = 1; iy <= h2[0]->GetYaxis()->GetNbins(); ++iy) {
126 
127  const double y1 = h2[0]->GetBinContent(ix,iy);
128  const double w1 = h2[0]->GetBinError (ix,iy);
129  const double f1 = h2[1]->GetBinContent(ix,iy);
130 
131  if (w1 > 0.0) {
132  Y += y1;
133  F += f1;
134  V += (y1 - f1) / w1;
135  N += 1;
136  }
137  }
138 
139  if (N != 0) {
140 
141  V /= N;
142 
143  h1.SetBinContent(ix, V);
144 
145  hx.Fill(pair.first, pair.second, V);
146  hx.Fill(pair.second, pair.first, V);
147  }
148 
149  DEBUG(setw(3) << ix << ' '
150  << "(" << FILL(2,'0') << pair.first << "," << FILL(2,'0') << pair.second << ")" << FILL() << ' '
151  << "(" << memo.getPMTPhysicalAddress(pair.first) << "," << memo.getPMTPhysicalAddress(pair.second) << ")" << FILL() << ' '
152  << FIXED(9,2) << Y << ' '
153  << FIXED(9,2) << F << ' '
154  << FIXED(9,2) << V << ' ' << (fabs(V) > 3.0 ? "***" : "") <<endl);
155  }
156 
157  if (option == address_t) {
158  setAxisLabels(hx, "X", memo);
159  setAxisLabels(hx, "Y", memo);
160  }
161 
162  out << h1 << hx;
163  }
164 
165  for (int i = 0; i != 2; ++i) {
166  in[i]->Close();
167  }
168 
169  out.Write();
170  out.Close();
171 }
Utility class to parse command line options.
Definition: JParser.hh:1514
JCombinatorics::pair_type pair_type
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
Definition: JLocation.hh:246
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
string outputFile
const JPolynome f1(1.0, 2.0, 3.0)
Function.
static const char *const _2F
Name extension for 2F rate fitted.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
Set axis with PMT address labels.
static const char *const _2R
Name extension for 2D rate measured.
then awk F
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
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
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62