Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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 
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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
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.
string outputFile
const JModuleAddressMap & get(const int id) const
Get module address map.
virtual const JModuleAddressMap & getDefaultModuleAddressMap() const =0
Get default module address map.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Lookup table for PMT addresses in optical module.
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
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.
#define FATAL(A)
Definition: JMessage.hh:67
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
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