Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "TH2D.h"
9 
10 #include "JDetector/JDetector.hh"
14 
16 #include "JROOT/JRootToolkit.hh"
17 
18 #include "Jeep/JPrint.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 /**
23  * \file
24  *
25  * Auxiliary program to project single PMT data from 2D histogram.
26  * \author mdejong
27  */
28 int main(int argc, char **argv)
29 {
30  using namespace std;
31  using namespace JPP;
32 
33  string detectorFile;
34  string inputFile;
35  string outputFile;
36  JPMTIdentifier pmt;
37  string extension;
38  int debug;
39 
40  try {
41 
42  JParser<> zap("Auxiliary program to project single PMT data from 2D histogram.");
43 
44  zap['a'] = make_field(detectorFile, "detector file.");
45  zap['f'] = make_field(inputFile, "input file.");
46  zap['o'] = make_field(outputFile, "output file.") = "k40.root";
47  zap['P'] = make_field(pmt, "PMT identifier");
48  zap['e'] = make_field(extension, "histogram name extension") = _2R, _2S, _2F;
49  zap['d'] = make_field(debug, "debug flag.") = 1;
50 
51  zap(argc, argv);
52  }
53  catch(const exception &error) {
54  FATAL(error.what() << endl);
55  }
56 
57 
58  gErrorIgnoreLevel = kError;
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 JModuleRouter router(detector);
71 
72  const JModule& module = router.getModule(pmt.getModuleID());
73 
74  JCombinatorics combinatorics;
75 
76  combinatorics.configure(module.size());
77 
78  combinatorics.sort(JPairwiseComparator(module));
79 
80  TFile in(inputFile.c_str(), "read");
81 
82  TH2D* h2 = (TH2D*) in.Get(MAKE_CSTRING(pmt.getModuleID() << extension));
83 
84  if (h2 == NULL) {
85  FATAL("Missing histogram for module " << pmt.getModuleID() << endl);
86  }
87 
88  TH1D h1(MAKE_CSTRING(pmt.getModuleID() << '.' << FILL(2,'0') << pmt.getTDC()), NULL, h2->GetYaxis()->GetNbins(), h2->GetYaxis()->GetXmin(), h2->GetYaxis()->GetXmax());
89 
90  for (size_t i = 0; i != module.size(); ++i) {
91 
92  const Int_t ix = combinatorics.getIndex(pmt.getTDC(), i) + 1;
93 
94  for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
95  h1.SetBinContent(iy, h2->GetBinContent(ix,iy));
96  h1.SetBinError (iy, h2->GetBinError (ix,iy));
97  }
98  }
99 
100  TFile out(outputFile.c_str(), "recreate");
101 
102  out << h1;
103 
104  out.Write();
105  out.Close();
106 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
string outputFile
Data structure for detector geometry and calibration.
static const char *const _2F
Name extension for 2F rate fitted.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
static const char *const _2R
Name extension for 2D rate measured.
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
Direct access to module in detector data structure.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
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
static const char *const _2S
Name extension for 2D counts.