Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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
21
23
25
26#include "Jeep/JParser.hh"
27#include "Jeep/JMessage.hh"
28
29
30/**
31 * \file
32 *
33 * Example program to equalize QE of PMTs based on summary data.
34 * \author mdejong
35 */
36int main(int argc, char **argv)
37{
38 using namespace std;
39 using namespace JPP;
40 using namespace KM3NETDAQ;
41
43 JLimit_t& numberOfEvents = inputFile.getLimit();
44 string outputFile;
45 string pmtFile;
46 double rate_kHz;
47 string rings;
48 int debug;
49
50 try {
51
52 JParser<> zap("Example program to equalize QE of PMTs based on summary data.");
53
54 zap['f'] = make_field(inputFile);
55 zap['o'] = make_field(outputFile) = "summaryslice.root";
56 zap['n'] = make_field(numberOfEvents) = JLimit::max();
57 zap['P'] = make_field(pmtFile, "specify PMT file name that can be given to JTriggerEfficiency.") = "";
58 zap['R'] = make_field(rate_kHz, "specify expected singles rate [Hz]") = 0.0;
59 zap['r'] = make_field(rings, "rings, e.g. \"AB\"") = "ABCDEF";
60 zap['d'] = make_field(debug) = 2;
61
62 zap(argc, argv);
63 }
64 catch(const exception& error) {
65 FATAL(error.what() << endl);
66 }
67
68
69 const double factor = 1.0e-3; // [kHz]
70
71 rings = to_upper(rings);
72
73
74 JPMTParametersMap parameters;
75
76 if (pmtFile != "") {
77 parameters.load(pmtFile.c_str());
78 }
79
80
82
83 for (JPMTParametersMap::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
84 QE[i->first] = getSurvivalProbability(i->second) * i->second.QE;
85 }
86
87
88 JManager<int, TH1D> H0(new TH1D ("H0[%]", NULL, JDAQRate::getN(), JDAQRate::getData(factor)));
89 JManager<int, TProfile> H1(new TProfile("H1[%]", NULL, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
90
91 int detector = -1;
92
93 while (inputFile.hasNext()) {
94
95 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
96
97 const JDAQSummaryslice* summary = inputFile.next();
98
99 detector = summary->getDetectorID();
100
102
103 for (JDAQSummaryslice::const_iterator frame = summary->begin(); frame != summary->end(); ++frame) {
104
105 const JModuleAddressMap& memo = demo.get(frame->getModuleID());
106
107 TH1D* h0 = H0[frame->getModuleID()];
108 TProfile* h1 = H1[frame->getModuleID()];
109
110 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
111
112 if (rings.find(memo.getPMTPhysicalAddress(pmt).ring) != string::npos) {
113
114 const JPMTIdentifier id(frame->getModuleID(), pmt);
115
117
118 double R = frame->getRate (pmt, factor);
119 double W = frame->getWeight(pmt, factor);
120 double P = 1.0;
121
122 if (p != QE.end()) {
123 P = p->second;
124 }
125
126 if (P > 0.0) {
127
128 h0->Fill(R / P, W);
129 H0->Fill(R / P, W);
130
131 h1->Fill(pmt, R / P);
132 H1->Fill(pmt, R / P);
133 }
134 }
135 }
136 }
137 }
138 STATUS(endl);
139
140
141 if (pmtFile != "" && rate_kHz > 0.0) {
142
143 NOTICE("Write QEs in PMT file " << pmtFile << endl);
144
145 for (JManager<int, TProfile>::const_iterator i = H1.begin(); i != H1.end(); ++i) {
146
147 for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
148
149 const JPMTIdentifier id(i->first, pmt);
150
151 parameters[id].QE *= i->second->GetBinContent(pmt + 1) / rate_kHz;
152 }
153 }
154
155 parameters.store(pmtFile.c_str());
156 }
157
158
160
162
163 for (JManager<int, TProfile>::const_iterator i = H1.begin(); i != H1.end(); ++i) {
164 setAxisLabels(*(i->second), "X", demo.get(i->first));
165 }
166
167
168 TFile out(outputFile.c_str(), "recreate");
169
170 H0.Write(out, true);
171 H1.Write(out, true);
172
173 out.Write();
174 out.Close();
175}
string outputFile
ROOT TTree parameter settings.
Detector support kit.
int main(int argc, char **argv)
Definition JEqualizer.cc:36
Dynamic ROOT object management.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Lookup table for PMT addresses in detector.
const JModuleAddressMap & get(const int id) const
Get module address map.
virtual const JModuleAddressMap & getDefaultModuleAddressMap() const =0
Get default module address map.
Lookup table for PMT addresses in optical module.
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
Auxiliary class for map of PMT parameters.
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition JManager.hh:47
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition JManager.hh:304
General purpose class for object reading from a list of file names.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
int getDetectorID() const
Get detector identifier.
static int getN()
Get number of bins.
static const double * getData(const double factor=1.0)
Get abscissa values.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
Set axis with PMT address labels.
std::string to_upper(const std::string &value)
Convert all character to upper case.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition JDAQ.hh:26
Detector file.
Definition JHead.hh:227
void store(const char *file_name) const
Store to output file.
void load(const char *file_name)
Load from input file.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128