Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JOMGsim.cc File Reference

Auxiliary program to determine PMT parameters from OMGSim data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TRandom3.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTParameters.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JTools/JCombinatorics.hh"
#include "JTools/JRouter.hh"
#include "JAAnet/JHead.hh"
#include "JCalibrate/JCalibrateK40.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JRootFileWriter.hh"
#include "Jeep/JPrint.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

Auxiliary program to determine PMT parameters from OMGSim data.

Author
mdejong

Definition in file JOMGsim.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file JOMGsim.cc.

50 {
51  using namespace std;
52  using namespace JPP;
53  using namespace KM3NETDAQ;
54 
55  JMultipleFileScanner<Evt> inputFile;
56  JLimit_t& numberOfEvents = inputFile.getLimit();
57  string outputFile;
58  string detectorFile;
59  Double_t TMax_ns;
60  double R;
62  UInt_t seed;
63  int debug;
64 
65  parameters.TTS_ns = 0.0;
66  parameters.gainSpread = 0.0;
67  parameters.PunderAmplified = 0.0;
68  parameters.slewing = false;
69 
70  try {
71 
72  JProperties properties = parameters.getProperties();
73 
74  JParser<> zap("Auxiliary program to determine PMT parameters from OMGsim data.");
75 
76  zap['f'] = make_field(inputFile, "input file.");
77  zap['o'] = make_field(outputFile, "output file.") = "omgsim.root";
78  zap['n'] = make_field(numberOfEvents) = JLimit::max();
79  zap['a'] = make_field(detectorFile, "detector file.");
80  zap['T'] = make_field(TMax_ns, "time window [ns].") = 20.0;
81  zap['R'] = make_field(R, "radioactivity [Bq]");
82  zap['P'] = make_field(properties, "PMT parameters") = JPARSER::initialised();
83  zap['S'] = make_field(seed, "seed") = 0;
84  zap['d'] = make_field(debug, "debug flag.") = 1;
85 
86  zap(argc, argv);
87  }
88  catch(const exception &error) {
89  FATAL(error.what() << endl);
90  }
91 
92 
93  gRandom->SetSeed(seed);
94 
95 
97 
98  try {
99  load(detectorFile, detector);
100  }
101  catch(const JException& error) {
102  FATAL(error);
103  }
104 
105  if (detector.size() != 1u) {
106  FATAL("Wrong number of modules " << detector.size() << endl);
107  }
108 
109 
110  const JModule& module = detector[0];
111 
112  JCombinatorics combinatorics(module.size());
113 
114  combinatorics.sort(JPairwiseComparator(module));
115 
116  const Int_t nx = combinatorics.getNumberOfPairs();
117  const Double_t xmin = -0.5;
118  const Double_t xmax = nx - 0.5;
119 
120  const Double_t ymin = -floor(TMax_ns) + 0.125;
121  const Double_t ymax = +floor(TMax_ns) - 0.125;
122  const Int_t ny = (Int_t) ((ymax - ymin) / 0.25);
123 
124  TH2D h2s(MAKE_CSTRING(module.getID() << _2S), NULL, nx, xmin, xmax, ny, ymin, ymax);
125 
126  h2s.Sumw2();
127 
128 
129  JRouter<int> router;
130 
131  for (size_t i = 0; i != module.size(); ++i) {
132  router.put(module[i].getID(), i);
133  }
134 
135  double numberOfPrimaries = 0.0;
136 
137  Head header;
138 
139  try {
140 
141  STATUS("Extracting header data... " << flush);
142 
143  header = getHeader(inputFile);
144 
145  const JHead buffer(header);
146 
147  if (buffer.is_valid(&JHead::norma))
148  numberOfPrimaries = buffer.norma.numberOfPrimaries;
149  else
150  THROW(JException, "Missing header information.");
151 
152  STATUS("OK" << endl);
153 
154  } catch(const exception& error) {
155  FATAL(error.what() << endl);
156  }
157 
158  if (numberOfPrimaries == 0.0) {
159  FATAL("Number of primaries " << numberOfPrimaries << endl);
160  }
161 
162 
164 
165  JPMTData<JPMTSignal> input;
166  JPMTData<JPMTPulse> output;
167 
168  struct hit_type {
169  int pmt;
170  double t1;
171  };
172 
173  vector<hit_type> buffer;
174 
175 
176  TFile out(outputFile.c_str(), "recreate");
177 
178  putObject(out, JMeta(argc, argv));
179 
180  while (inputFile.hasNext()) {
181 
182  if (inputFile.getCounter()%10000== 0) {
183  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
184  }
185 
186  const Evt* evt = inputFile.next();
187 
188  if (evt->mc_hits.size() >= 2u) {
189 
190  buffer.clear();
191 
192  for (const auto& hit : evt->mc_hits) {
193 
194  if (router.has(hit.pmt_id)) {
195 
196  const int pmt = router.get(hit.pmt_id);
197 
198  input .clear();
199  output.clear();
200 
201  input.push_back(JPMTSignal(hit.t, hit.a));
202 
203  cpu(module[pmt].getCalibration(), input, output);
204 
205  for (const auto& hit : output) {
206  buffer.push_back({pmt, hit.t_ns});
207  }
208  }
209  }
210 
211 
212  for (vector<hit_type>::const_iterator p = buffer.begin(); p != buffer.end(); ++p) {
213  for (vector<hit_type>::const_iterator q = buffer.begin(); p != q; ++q) {
214  h2s.Fill((double) combinatorics.getIndex(p->pmt,q->pmt),
215  JCombinatorics::getSign(p->pmt,q->pmt) * (q->t1 - p->t1));
216  }
217  }
218  }
219  }
220  STATUS(endl);
221 
222 
223  const double W = R / numberOfPrimaries;
224 
225  h2s.Scale(W);
226 
227  out << h2s;
228 
229  out.Write();
230  out.Close();
231 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
General exception.
Definition: JException.hh:24
Data structure for PMT analogue signal.
Auxiliary class to convert pair of indices to unique index and back.
Data structure for a composite optical module.
Definition: JModule.hh:67
#define STATUS(A)
Definition: JMessage.hh:63
Detector data structure.
Definition: JDetector.hh:89
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Utility class to parse parameter values.
Definition: JProperties.hh:497
*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
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
string outputFile
void sort(JComparator_t comparator)
Sort address pairs.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Auxiliary class to sort pairs of PMT addresses within optical module.
Detector file.
Definition: JHead.hh:226
Monte Carlo run header.
Definition: JHead.hh:1234
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
#define FATAL(A)
Definition: JMessage.hh:67
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
const double xmin
Definition: JQuadrature.cc:23
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
General purpose class for object reading from a list of file names.
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition: Evt.hh:48
Template data structure for PMT I/O.
void clear()
Reset event.
Definition: Evt.hh:88
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
Data structure for PMT parameters.
do set_variable DETECTOR_TXT $WORKDIR detector
double u[N+1]
Definition: JPolint.hh:865
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
static const char *const _2S
Name extension for 2D counts.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62