Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JSTDevK40.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <array>
5
6#include "TROOT.h"
7#include "TFile.h"
8#include "TH1D.h"
9#include "TH2D.h"
10
12
17
18#include "JROOT/JRootToolkit.hh"
19
21
23
24#include "Jeep/JPrint.hh"
25#include "Jeep/JParser.hh"
26#include "Jeep/JMessage.hh"
27
28
29/**
30 */
31int main(int argc, char **argv)
32{
33 using namespace std;
34 using namespace JPP;
35 using namespace KM3NETDAQ;
36
37 const char* const address_t = "address";
38 const char* const index_t = "index";
39
40 array<string, 2> inputFile;
41 string outputFile;
42 string detectorFile;
43 string option;
44 int debug;
45
46 try {
47
48 JParser<> zap;
49
50 zap['f'] = make_field(inputFile, "1st output of JMergeCalibrateK40 and 2nd output of JFitK40");
51 zap['o'] = make_field(outputFile, "output file.") = "stdevk40.root";
52 zap['a'] = make_field(detectorFile, "detector file.");
53 zap['O'] = make_field(option, "axis label") = address_t, index_t;
54 zap['d'] = make_field(debug, "debug.") = 1;
55
56 zap(argc, argv);
57 }
58 catch(const exception &error) {
59 FATAL(error.what() << endl);
60 }
61
62
64
65 try {
66 load(detectorFile, detector);
67 }
68 catch(const JException& error) {
69 FATAL(error);
70 }
71
72 const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
73
74
75 TFile* in[] = { NULL, NULL };
76
77 for (int i = 0; i != 2; ++i) {
78
79 in[i] = TFile::Open(inputFile[i].c_str(), "exist");
80
81 if (in[i] == NULL || !in[i]->IsOpen()) {
82 FATAL("File: " << inputFile[i] << " not opened." << endl);
83 }
84 }
85
86
87 TFile out(outputFile.c_str(), "recreate");
88
89 for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
90
91 if (module->getFloor() == 0) {
92 continue;
93 }
94
95 TH2D* h2[] = {
96 (TH2D*) in[0]->Get(MAKE_CSTRING(module->getID() << _2R)),
97 (TH2D*) in[1]->Get(MAKE_CSTRING(module->getID() << _2F))
98 };
99
100 if (h2[0] == NULL || h2[0]->GetEntries() == 0 ||
101 h2[1] == NULL || h2[1]->GetEntries() == 0) {
102 continue;
103 }
104
105 DEBUG("Module " << setw(10) << module->getID() << ' ' << getLabel(module->getLocation()) << endl);
106
107 const JCombinatorics_t combinatorics(*module);
108
109 const JModuleAddressMap memo = demo.get(module->getID());
110
111 TH1D h1(MAKE_CSTRING(module->getID() << ".1D"), NULL,
112 h2[0]->GetXaxis()->GetNbins(), h2[0]->GetXaxis()->GetXmin(), h2[0]->GetXaxis()->GetXmax());
113
114 TH2D hx(MAKE_CSTRING(module->getID() << ".2X"), NULL,
115 NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5,
116 NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5);
117
118 for (int ix = 1; ix <= h2[0]->GetXaxis()->GetNbins(); ++ix) {
119
120 const pair_type pair = combinatorics.getPair(ix - 1);
121
122 double Y = 0.0; // summed data
123 double F = 0.0; // summed function value
124 double V = 0.0; // summed standard deviation
125 int N = 0;
126
127 for (int iy = 1; iy <= h2[0]->GetYaxis()->GetNbins(); ++iy) {
128
129 const double y1 = h2[0]->GetBinContent(ix,iy);
130 const double w1 = h2[0]->GetBinError (ix,iy);
131 const double f1 = h2[1]->GetBinContent(ix,iy);
132
133 if (w1 > 0.0) {
134 Y += y1;
135 F += f1;
136 V += (y1 - f1) / w1;
137 N += 1;
138 }
139 }
140
141 if (N != 0) {
142
143 V /= N;
144
145 h1.SetBinContent(ix, V);
146
147 hx.Fill(pair.first, pair.second, V);
148 hx.Fill(pair.second, pair.first, V);
149 }
150
151 DEBUG(setw(3) << ix << ' '
152 << "(" << FILL(2,'0') << pair.first << "," << FILL(2,'0') << pair.second << ")" << FILL() << ' '
153 << "(" << memo.getPMTPhysicalAddress(pair.first) << "," << memo.getPMTPhysicalAddress(pair.second) << ")" << FILL() << ' '
154 << FIXED(9,2) << Y << ' '
155 << FIXED(9,2) << F << ' '
156 << FIXED(9,2) << V << ' ' << (fabs(V) > 3.0 ? "***" : "") <<endl);
157 }
158
159 if (option == address_t) {
160 setAxisLabels(hx, "X", memo);
161 setAxisLabels(hx, "Y", memo);
162 }
163
164 out << h1 << hx;
165 }
166
167 for (int i = 0; i != 2; ++i) {
168 in[i]->Close();
169 }
170
171 out.Write();
172 out.Close();
173}
string outputFile
KM3NeT DAQ constants, bit handling, etc.
Detector support kit.
Data structure for detector geometry and calibration.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
int main(int argc, char **argv)
Definition JSTDevK40.cc:31
Lookup table for PMT addresses in detector.
const JModuleAddressMap & get(const int id) const
Get module address map.
Detector data structure.
Definition JDetector.hh:96
Lookup table for PMT addresses in optical module.
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
const pair_type & getPair(const int index) const
Get pair of indices for given index.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
PMT combinatorics for optical module.
Data structure for a pair of indices.