Jpp  17.0.0
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  using namespace KM3NETDAQ;
33 
34  string detectorFile;
35  string inputFile;
36  string outputFile;
37  JPMTIdentifier pmt;
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  TFile in(inputFile.c_str(), "read");
82 
83  TH2D* h2 = (TH2D*) in.Get(MAKE_CSTRING(pmt.getModuleID() << extension));
84 
85  if (h2 == NULL) {
86  FATAL("Missing histogram for module " << pmt.getModuleID() << endl);
87  }
88 
89  TH1D h1(MAKE_CSTRING(pmt.getModuleID() << '.' << FILL(2,'0') << pmt.getTDC()), NULL, h2->GetYaxis()->GetNbins(), h2->GetYaxis()->GetXmin(), h2->GetYaxis()->GetXmax());
90 
91  for (size_t i = 0; i != module.size(); ++i) {
92 
93  const Int_t ix = combinatorics.getIndex(pmt.getTDC(), i) + 1;
94 
95  for (Int_t iy = 1; iy <= h2->GetYaxis()->GetNbins(); ++iy) {
96  h1.SetBinContent(iy, h2->GetBinContent(ix,iy));
97  h1.SetBinError (iy, h2->GetBinError (ix,iy));
98  }
99  }
100 
101  TFile out(outputFile.c_str(), "recreate");
102 
103  out << h1;
104 
105  out.Write();
106  out.Close();
107 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
Auxiliary class to convert pair of indices to unique index and back.
int main(int argc, char *argv[])
Definition: Main.cc:15
void configure(const int numberOfIndices)
Configure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:68
Detector data structure.
Definition: JDetector.hh:89
Router for direct addressing of module data in detector data structure.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
string outputFile
Data structure for detector geometry and calibration.
static const char *const _2F
Name extension for 2F rate fitted.
I/O formatting auxiliaries.
Auxiliary class to sort pairs of PMT addresses within optical module.
Detector file.
Definition: JHead.hh:224
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
static const char *const _2R
Name extension for 2D rate measured.
int debug
debug level
Definition: JSirene.cc:66
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
static const char *const _2S
Name extension for 2D counts.