Jpp  17.3.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JPMTStatus.cc File Reference

Auxiliary program to update the PMT status in the detector file based on the fraction of short time-over-threshold values. More...

#include <string>
#include <iostream>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "km3net-dataformat/definitions/pmt_status.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JCalibrate/JCalibrateToT.hh"
#include "JTools/JRange.hh"
#include "JLang/JLangToolkit.hh"
#include "JSupport/JMeta.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (const int argc, const char *const argv[])
 

Detailed Description

Auxiliary program to update the PMT status in the detector file based on the fraction of short time-over-threshold values.

Author
acreusot, mdejong

Definition in file JPMTStatus.cc.

Function Documentation

int main ( const int  argc,
const char *const  argv[] 
)

Definition at line 27 of file JPMTStatus.cc.

28 {
29  using namespace std;
30  using namespace JPP;
31 
32  typedef JRange<double> JRange_t;
33 
34  string inputFile;
35  string detectorFile;
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:1517
General exception.
Definition: JException.hh:23
debug
Definition: JMessage.hh:29
Detector data structure.
Definition: JDetector.hh:89
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
Type definition of range.
Definition: JHead.hh:41
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
static const int PMT_DISABLE
KM3NeT Data Definitions v3.0.0-3-gef79250 https://git.km3net.de/common/km3net-dataformat.
Definition: pmt_status.hh:12
#define NOTICE(A)
Definition: JMessage.hh:64
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.
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 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
then echo WARNING
Definition: JTuneHV.sh:91
int debug
debug level