Jpp  15.0.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPMTStatus.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 
4 #include "TROOT.h"
5 #include "TFile.h"
6 #include "TH2D.h"
7 
9 
10 #include "JDetector/JDetector.hh"
13 #include "JTools/JRange.hh"
14 #include "JLang/JLangToolkit.hh"
15 #include "JSupport/JMeta.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 
21 /**
22  * \file
23  * Auxiliary program to update the PMT status in the detector file based on the fraction of short time-over-threshold values.
24  *
25  * \author acreusot, mdejong
26  */
27 int main(const int argc, const char * const argv[])
28 {
29  using namespace std;
30  using namespace JPP;
31 
32  typedef JRange<double> JRange_t;
33 
34  string inputFile;
35  string detectorFile;
36  JRange_t range;
37  double fraction;
38  bool overwriteDetector;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Auxiliary program to update the PMT status in the detector file based on the fraction of short time-over-threshold values.");
44 
45  zap['f'] = make_field(inputFile, "input file (output from JCalibrateToT).");
46  zap['a'] = make_field(detectorFile, "detector file.");
47  zap['x'] = make_field(range, "integration range for noise.") = JRange_t(0.0, 8.0);
48  zap['t'] = make_field(fraction, "maximal fraction of signal allowed for noise.") = 0.5;
49  zap['A'] = make_field(overwriteDetector, "overwrite detector file.");
50  zap['d'] = make_field(debug, "debug.") = 1;
51 
52  zap(argc, argv);
53  }
54  catch(const exception& error) {
55  FATAL(error.what() << endl);
56  }
57 
58 
60 
61  try {
62  load(detectorFile, detector);
63  }
64  catch(const JException& error) {
65  FATAL(error);
66  }
67 
68  detector.comment.add(JMeta(argc,argv));
69 
70  if (detector.setToLatestVersion()) {
71  NOTICE("Set detector version to " << detector.getVersion() << endl);
72  }
73 
74 
75  gErrorIgnoreLevel = kError;
76 
77  TFile* in = TFile::Open(inputFile.c_str(), "exist");
78 
79  if (in == NULL || !in->IsOpen()) {
80  FATAL("File: " << inputFile << " not opened." << endl);
81  }
82 
83 
84  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
85 
86  if (!module->empty()) {
87 
88  TH2D* h2s = (TH2D*) in->Get(MAKE_CSTRING(module->getID() << _2SToT));
89 
90  if (h2s != NULL) {
91 
92  for (int ix = 1; ix <= h2s->GetXaxis()->GetNbins(); ++ix) {
93 
94  double noise = 0.0;
95  double signal = 0.0;
96 
97  for (int iy = 1; iy <= h2s->GetYaxis()->GetNbins(); ++iy) {
98 
99  const double x = h2s->GetYaxis()->GetBinCenter(iy);
100  const double y = h2s->GetBinContent(ix, iy);
101 
102  signal += y;
103 
104  if (range(x)) {
105  noise += y;
106  }
107  }
108 
109  const bool disable = noise > fraction * signal;
110 
111  if (debug >= debug_t || disable) {
112  cout << "PMT " << FILL(10,'0') << module->getID() << "." << FILL(2,'0') << (ix - 1) << FILL()
113  << " noise/signal " << FIXED(7,0) << noise << "/" << FIXED(7,0) << signal << (disable ? " *" : "") << endl;
114  }
115 
116  if (overwriteDetector) {
117  if (disable) {
118  module->getPMT(ix - 1).getStatus().set(PMT_DISABLE);
119  }
120  }
121  }
122 
123  } else {
124 
125  WARNING("No histogram for module " << module->getID() << "; skip." << endl);
126  }
127  }
128  }
129 
130  in->Close();
131 
132  if (overwriteDetector) {
133 
134  NOTICE("Store PMT status on file " << detectorFile << endl);
135 
136  store(detectorFile, detector);
137  }
138 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
#define WARNING(A)
Definition: JMessage.hh:65
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
Detector data structure.
Definition: JDetector.hh:89
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Data structure for detector geometry and calibration.
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
static const int PMT_DISABLE
KM3NeT Data Definitions v2.1.0-7-g97845ea https://git.km3net.de/common/km3net-dataformat.
Definition: pmt_status.hh:12
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxiliary class to define a range between two values.
Utility class to parse command line options.
static const char *const _2SToT
Histogram naming.
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41