Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JFindBadChannels.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <vector>
4 
6 
7 #include "JDetector/JDetector.hh"
11 
12 #include "JSupport/JSupport.hh"
13 #include "JSupport/JMeta.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  * Auxiliary program to update the PMT status (bad channel) in the detector file
22  * based on the small ToT fraction computation (i.e. the noise to signal ratio).
23  * \author acreusot
24  */
25 
26 int main(const int argc, const char * const argv[])
27 {
28  using namespace std;
29  using namespace JPP;
30 
31  string detectorFile;
32  string inputFile;
33  double stfCut;
34  int debug;
35  bool overwriteDetector;
36 
37  try {
38  JParser<> zap("Auxiliary program to find the bad channels (PMTs) according to the small ToT fraction (i.e. the noise to signal ratio).");
39  zap['a'] = make_field(detectorFile, "detector file");
40  zap['f'] = make_field(inputFile, "output file of JIntegrateToT");
41  zap['t'] = make_field(stfCut, "small ToT fraction cut-off") = 0.5;
42  zap['d'] = make_field(debug) = 1;
43  zap['A'] = make_field(overwriteDetector, "overwrite detector file with bad channel boolean.");
44  zap(argc, argv);
45  }
46  catch(const exception& error) {
47  FATAL(error.what() << endl);
48  }
49 
50  // Load detector file and update it to latest version
52  try {
53  load(detectorFile, detector);
54  }
55  catch(const JException& error) {
56  FATAL(error);
57  }
58  detector.comment.add(JMeta(argc,argv));
59  if (detector.setToLatestVersion()) {
60  NOTICE("Set detector version to " << detector.getVersion() << endl);
61  }
62  const JModuleRouter moduleRouter(detector);
63 
64  // read PMT ToT parameters from the data file
65  ifstream istr(inputFile.c_str());
66  vector<JParameters> vParameters;
67  for (JParameters curPar; istr >> curPar;) {
68  DEBUG("Computing small ToT fraction for DOM" << curPar.domId << " - PMT " << curPar.pmtId << endl);
69  vParameters.push_back(curPar);
70  }
71  istr.close();
72 
73  // find and store the bad channels
74  if (overwriteDetector) {
75  for (vector<JParameters>::const_iterator par = vParameters.begin(); par != vParameters.end(); ++par) {
76  if (moduleRouter.hasModule(par->domId)) {
77  // if the histogram is empty (HRV or PMT off) then ratio is set to 1
78  const double ratio = par->signal ? par->noise/par->signal : 1;
79  const bool status = ratio > stfCut ? true : false;
80  const JModule& module = moduleRouter.getModule(par->domId);
81  detector.getModule(module).getPMT(par->pmtId).setStatus(status);
82  if (status == true) {
83  NOTICE("bad channel: pmt " << par->pmtId << ", dom "
84  << par->domId << " with a STF of " << ratio << endl);
85  }
86  }
87  }
88  NOTICE("Store calibration data on file " << detectorFile << endl);
89  store(detectorFile, detector);
90  }
91 }
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
ROOT TTree parameter settings of various packages.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
Data structure for a composite optical module.
Definition: JModule.hh:57
Detector data structure.
Definition: JDetector.hh:80
Router for direct addressing of module data in detector data structure.
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.
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.
#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.
bool hasModule(const JObjectID &id) const
Has module.
do set_variable DETECTOR_TXT $WORKDIR detector
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
int main(int argc, char *argv[])
Definition: Main.cpp:15