Jpp  15.0.0
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/JDetectorAddressMapToolkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTParametersToolkit.hh"
#include "JDetector/JDetectorAddressMap.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 37 of file JEqualizer.cc.

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 
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:1500
int getDetectorID() const
Get detector identifier.
do rm f tmp H1
#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
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
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:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
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.
int debug
debug level
Definition: JSirene.cc:63
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
#define FATAL(A)
Definition: JMessage.hh:67
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const JPMTPhysicalAddress & getPMTPhysicalAddress(const int tdc) const
Get PMT physical address.
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
then $DIR JPlotNPE PDG P
Definition: JPlotNPE-PDG.sh:62