Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCombinatoricsK40.cc File Reference

Auxiliary program to project single PMT data from 2D histogram. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTIdentifier.hh"
#include "JCalibrate/JCalibrateK40.hh"
#include "JROOT/JRootToolkit.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)
 

Detailed Description

Auxiliary program to project single PMT data from 2D histogram.

Author
mdejong

Definition in file JCombinatoricsK40.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JCombinatoricsK40.cc.

30 {
31  using namespace std;
32  using namespace JPP;
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 
62  JDetector detector;
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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
debug
Definition: JMessage.hh:29
Data structure for a pair of indices.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
string outputFile
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
static const char *const _2R
Name extension for 2D rate measured.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
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.