Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
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 */
27int 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}
Data structure for detector geometry and calibration.
General purpose messaging.
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define WARNING(A)
Definition JMessage.hh:65
ROOT I/O of application specific meta data.
int main(const int argc, const char *const argv[])
Definition JPMTStatus.cc:27
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
Auxiliary class to define a range between two values.
Detector data structure.
Definition JDetector.hh:96
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Range of values.
Definition JRange.hh:42
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72