Jpp  debug
the software that should make you happy
Functions
JEqualizer.cc File Reference

Example program to equalize QE of PMTs based on summary data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TProfile.h"
#include "JDAQ/JDAQSummarysliceIO.hh"
#include "JDAQ/JSupport.hh"
#include "JROOT/JManager.hh"
#include "JDetector/JDetectorAddressMap.hh"
#include "JDetector/JDetectorSupportkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTParametersToolkit.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to equalize QE of PMTs based on summary data.

Author
mdejong

Definition in file JEqualizer.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 36 of file JEqualizer.cc.

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 
101  const JDetectorAddressMap& demo = getDetectorAddressMap(summary->getDetectorID());
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 
161  setAxisLabels(*H1, "X", demo.getDefaultModuleAddressMap());
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
#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:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Lookup table for PMT addresses in detector.
virtual const JModuleAddressMap & getDefaultModuleAddressMap() const =0
Get default module address map.
const JModuleAddressMap & get(const int id) const
Get 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.
char ring
ring number ['A','F']
Utility class to parse command line options.
Definition: JParser.hh:1714
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition: JManager.hh:47
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.
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
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).
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
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
Definition: JSTDTypes.hh:14
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