Jpp  18.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEqualizer.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <limits>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 #include "TProfile.h"
11 
13 #include "JDAQ/JSupport.hh"
14 
15 #include "JROOT/JManager.hh"
16 
22 
23 #include "JGizmo/JGizmoToolkit.hh"
24 
26 
27 #include "Jeep/JParser.hh"
28 #include "Jeep/JMessage.hh"
29 
30 
31 /**
32  * \file
33  *
34  * Example program to equalize QE of PMTs based on summary data.
35  * \author mdejong
36  */
37 int main(int argc, char **argv)
38 {
39  using namespace std;
40  using namespace JPP;
41  using namespace KM3NETDAQ;
42 
44  JLimit_t& numberOfEvents = inputFile.getLimit();
45  string outputFile;
46  string pmtFile;
47  double rate_kHz;
48  string rings;
49  int debug;
50 
51  try {
52 
53  JParser<> zap("Example program to equalize QE of PMTs based on summary data.");
54 
55  zap['f'] = make_field(inputFile);
56  zap['o'] = make_field(outputFile) = "summaryslice.root";
57  zap['n'] = make_field(numberOfEvents) = JLimit::max();
58  zap['P'] = make_field(pmtFile, "specify PMT file name that can be given to JTriggerEfficiency.") = "";
59  zap['R'] = make_field(rate_kHz, "specify expected singles rate [Hz]") = 0.0;
60  zap['r'] = make_field(rings, "rings, e.g. \"AB\"") = "ABCDEF";
61  zap['d'] = make_field(debug) = 2;
62 
63  zap(argc, argv);
64  }
65  catch(const exception& error) {
66  FATAL(error.what() << endl);
67  }
68 
69 
70  const double factor = 1.0e-3; // [kHz]
71 
72  rings = to_upper(rings);
73 
74 
76 
77  if (pmtFile != "") {
78  parameters.load(pmtFile.c_str());
79  }
80 
81 
83 
84  for (JPMTParametersMap::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
85  QE[i->first] = getSurvivalProbability(i->second) * i->second.QE;
86  }
87 
88 
89  JManager<int, TH1D> H0(new TH1D ("H0[%]", NULL, JDAQRate::getN(), JDAQRate::getData(factor)));
90  JManager<int, TProfile> H1(new TProfile("H1[%]", NULL, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
91 
92  int detector = -1;
93 
94  while (inputFile.hasNext()) {
95 
96  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
97 
98  const JDAQSummaryslice* summary = inputFile.next();
99 
100  detector = summary->getDetectorID();
101 
102  const JDetectorAddressMap& demo = getDetectorAddressMap(summary->getDetectorID());
103 
104  for (JDAQSummaryslice::const_iterator frame = summary->begin(); frame != summary->end(); ++frame) {
105 
106  const JModuleAddressMap& memo = demo.get(frame->getModuleID());
107 
108  TH1D* h0 = H0[frame->getModuleID()];
109  TProfile* h1 = H1[frame->getModuleID()];
110 
111  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
112 
113  if (rings.find(memo.getPMTPhysicalAddress(pmt).ring) != string::npos) {
114 
115  const JPMTIdentifier id(frame->getModuleID(), pmt);
116 
118 
119  double R = frame->getRate (pmt, factor);
120  double W = frame->getWeight(pmt, factor);
121  double P = 1.0;
122 
123  if (p != QE.end()) {
124  P = p->second;
125  }
126 
127  if (P > 0.0) {
128 
129  h0->Fill(R / P, W);
130  H0->Fill(R / P, W);
131 
132  h1->Fill(pmt, R / P);
133  H1->Fill(pmt, R / P);
134  }
135  }
136  }
137  }
138  }
139  STATUS(endl);
140 
141 
142  if (pmtFile != "" && rate_kHz > 0.0) {
143 
144  NOTICE("Write QEs in PMT file " << pmtFile << endl);
145 
146  for (JManager<int, TProfile>::const_iterator i = H1.begin(); i != H1.end(); ++i) {
147 
148  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
149 
150  const JPMTIdentifier id(i->first, pmt);
151 
152  parameters[id].QE *= i->second->GetBinContent(pmt + 1) / rate_kHz;
153  }
154  }
155 
156  parameters.store(pmtFile.c_str());
157  }
158 
159 
161 
162  setAxisLabels(*H1, "X", demo.getDefaultModuleAddressMap());
163 
164  for (JManager<int, TProfile>::const_iterator i = H1.begin(); i != H1.end(); ++i) {
165  setAxisLabels(*(i->second), "X", demo.get(i->first));
166  }
167 
168 
169  TFile out(outputFile.c_str(), "recreate");
170 
171  H0.Write(out, true);
172  H1.Write(out, true);
173 
174  out.Write();
175  out.Close();
176 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
double getN(const JRange< T > &range, const double R)
Get expected number of occurrences due to given rate within specified interval.
Definition: JRange.hh:704
int getDetectorID() const
Get detector identifier.
#define STATUS(A)
Definition: JMessage.hh:63
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Lookup table for PMT addresses in detector.
Dynamic ROOT object management.
string outputFile
const JModuleAddressMap & get(const int id) const
Get module address map.
ROOT TTree parameter settings.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Lookup table for PMT addresses in optical module.
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
Set axis with PMT address labels.
#define NOTICE(A)
Definition: JMessage.hh:64
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
Auxiliary class for map of PMT parameters.
char ring
ring number [&#39;A&#39;,&#39;F&#39;]
std::string to_upper(const std::string &value)
Convert all character to upper case.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
Utility class to parse command line options.
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
int debug
debug level
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62