Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JCombinatoricsK40.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5
6#include "TROOT.h"
7#include "TFile.h"
8#include "TH1D.h"
9#include "TH2D.h"
10
15
17#include "JROOT/JRootToolkit.hh"
18
19#include "Jeep/JPrint.hh"
20#include "Jeep/JParser.hh"
21#include "Jeep/JMessage.hh"
22
23/**
24 * \file
25 *
26 * Auxiliary program to project single PMT data from 2D histogram.
27 * \author mdejong
28 */
29int main(int argc, char **argv)
30{
31 using namespace std;
32 using namespace JPP;
33
34 string detectorFile;
35 string inputFile;
36 string outputFile;
38 string extension;
39 int debug;
40
41 try {
42
43 JParser<> zap("Auxiliary program to project single PMT data from 2D histogram.");
44
45 zap['a'] = make_field(detectorFile, "detector file.");
46 zap['f'] = make_field(inputFile, "input file.");
47 zap['o'] = make_field(outputFile, "output file.") = "k40.root";
48 zap['P'] = make_field(pmt, "PMT identifier");
49 zap['e'] = make_field(extension, "histogram name extension") = _2R, _2S, _2F;
50 zap['d'] = make_field(debug, "debug flag.") = 1;
51
52 zap(argc, argv);
53 }
54 catch(const exception &error) {
55 FATAL(error.what() << endl);
56 }
57
58
59 gErrorIgnoreLevel = kError;
60
61
63
64 try {
65 load(detectorFile, detector);
66 }
67 catch(const JException& error) {
68 FATAL(error);
69 }
70
71 const JModuleRouter router(detector);
72
73 const JModule& module = router.getModule(pmt.getModuleID());
74
75 JCombinatorics combinatorics;
76
77 combinatorics.configure(module.size());
78
79 combinatorics.sort(JPairwiseComparator(module));
80
81 if (debug >= debug_t) {
82
83 for (size_t i = 0; i != combinatorics.getNumberOfPairs(); ++i) {
84
85 const JCombinatorics::pair_type pair = combinatorics.getPair(i);
86
87 cout << setw(3) << i << " -> (" << FILL(2,'0') << pair.first << "," << FILL(2,'0') << pair.second << FILL() << ")" << endl;
88 }
89 }
90
91 TFile in(inputFile.c_str(), "read");
92
93 TH2D* h2 = (TH2D*) in.Get(MAKE_CSTRING(pmt.getModuleID() << extension));
94
95 if (h2 == NULL) {
96 FATAL("Missing histogram for module " << pmt.getModuleID() << endl);
97 }
98
99 TH1D ha(MAKE_CSTRING(pmt.getModuleID() << '.' << FILL(2,'0') << pmt.getTDC() << ".1D"), NULL,
100 h2->GetYaxis()->GetNbins(), h2->GetYaxis()->GetXmin(), h2->GetYaxis()->GetXmax());
101
102 TH2D hb(MAKE_CSTRING(pmt.getModuleID() << '.' << FILL(2,'0') << pmt.getTDC() << ".2D"), NULL,
103 module.size(), -0.5, module.size() - 0.5,
104 h2->GetYaxis()->GetNbins(), h2->GetYaxis()->GetXmin(), h2->GetYaxis()->GetXmax());
105
106 for (int i = 0; i != (int) module.size(); ++i) {
107
108 if (i != pmt.getTDC()) {
109
110 const Int_t ix = combinatorics.getIndex(pmt.getTDC(), i) + 1;
111
112 for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
113
114 ha.SetBinContent(iy, ha.GetBinContent(iy) + h2->GetBinContent(ix,iy));
115 ha.SetBinError (iy, hypot(ha.GetBinError (iy), h2->GetBinError (ix,iy)));
116
117 hb.SetBinContent(i + 1, iy, h2->GetBinContent(ix,iy));
118 hb.SetBinError (i + 1, iy, h2->GetBinError (ix,iy));
119 }
120 }
121 }
122
123 TFile out(outputFile.c_str(), "recreate");
124
125 out << ha << hb;
126
127 out.Write();
128 out.Close();
129}
int main(int argc, char **argv)
string outputFile
Data structure for detector geometry and calibration.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Direct access to module in detector data structure.
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
Detector data structure.
Definition JDetector.hh:96
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition JModule.hh:75
int getModuleID() const
Get module identifier.
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to convert pair of indices to unique index and back.
const pair_type & getPair(const int index) const
Get pair of indices for given index.
void configure(const int numberOfIndices)
Configure.
int getIndex(const int first, const int second) const
Get index of pair of indices.
void sort(JComparator_t comparator)
Sort address pairs.
size_t getNumberOfPairs() const
Get number of pairs.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Detector file.
Definition JHead.hh:227
Auxiliary class to sort pairs of PMT addresses within optical module.
Data structure for a pair of indices.