Jpp  debug
the software that should make you happy
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

◆ main()

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;
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 }
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define WARNING(A)
Definition: JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Detector data structure.
Definition: JDetector.hh:96
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1714
static const char *const _2SToT
Histogram naming.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
@ debug_t
debug
Definition: JMessage.hh:29
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JSTDTypes.hh:14
static const int PMT_DISABLE
KM3NeT Data Definitions v3.4.0-8-ge14cb17 https://git.km3net.de/common/km3net-dataformat.
Definition: pmt_status.hh:12
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:448
Type definition of range.
Definition: JHead.hh:43
Detector file.
Definition: JHead.hh:227
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72