Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JEditPMTParameters.cc File Reference

Auxiliary program to edit PMT parameters map. More...

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include "JLang/JLangToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTReadoutAddress.hh"
#include "JDetector/JPMTPhysicalAddress.hh"
#include "JDetector/JModuleAddressMap.hh"
#include "JDetector/JDetectorAddressMap.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.hh"
#include "JSupport/JMeta.hh"
#include "JTools/JRange.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 edit PMT parameters map.

Syntax:

    -@ "(set|add|sub|mul|div) <key> <value>"
    -A "<PMT physical address> (set|add|sub|mul|div) <key> <value>"
    -M "<PMT identifier>       (set|add|sub|mul|div) <key> <value>"

In this, the PMT physical address corresponds to the data structure JDETECTOR::JPMTPhysicalAddress and the PMT identifier to JDETECTOR::JPMTIdentifier.
The key corresponds to one of the data members of the JDETECTOR::JPMTParameters data structure.
The option -@ corresponds to the default PMT values.

Note that in the absence of option -a, the detector identifier should be specified using option -D so to obtain the correct PMT address mapping.

Multiple options -@, -A and -M will be processed in order of appearance.

Author
mdejong

Definition in file JEditPMTParameters.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 202 of file JEditPMTParameters.cc.

203 {
204  using namespace std;
205  using namespace JPP;
206 
207  typedef JRange<double> JRange_t;
208 
209  string detectorFile;
210  int detectorID;
212  vector< JModifier<> > hdr;
215  double mu;
216  JRange_t T_ns;
217  string outputFile;
218  bool squash;
219  int debug;
220 
221  try {
222 
223  JParser<> zap("Auxiliary program to edit PMT parameters map.");
224 
225  zap['a'] = make_field(detectorFile, "detector file.") = "";
226  zap['D'] = make_field(detectorID, "detector identifier (in absence of detector file).") = 0;
227  zap['P'] = make_field(parameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
228  zap['@'] = make_field(hdr, "PMT parameter modifier for default values.") = JPARSER::initialised();
229  zap['A'] = make_field(mod, "PMT parameter modifier by physical address (e.g. B1).") = JPARSER::initialised();
230  zap['M'] = make_field(daq, "PMT parameter modifier by DAQ address (e.g. <module> <channel>.") = JPARSER::initialised();
231  zap['E'] = make_field(mu, "expectation value for npe given two-fold coincidence") = 0.0;
232  zap['T'] = make_field(T_ns, "time-over-threshold range.") = JRange_t();
233  zap['o'] = make_field(outputFile, "output file.");
234  zap['q'] = make_field(squash, "squash meta data");
235  zap['d'] = make_field(debug, "debug level") = 2;
236 
237  zap(argc, argv);
238  }
239  catch(const exception &error) {
240  FATAL(error.what() << endl);
241  }
242 
243 
244  if (squash) {
245  parameters.comment.clear();
246  }
247 
248  parameters.comment.add(JMeta(argc,argv));
249 
250 
251  for (vector< JModifier<> >::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
252 
253  DEBUG("Modifying default PMT parameters " << i->action << ' ' << i->key << ' ' << i->value << endl);
254 
255  if (!i->apply(parameters.getDefaultPMTParameters())) {
256  ERROR("No valid action: " << *i << endl);
257  }
258  }
259 
260  if (detectorFile != "") {
261 
262  // Setting default PMT parameters for given detector.
263 
265 
266  try {
267  load(detectorFile, detector);
268  }
269  catch(const JException& error) {
270  FATAL(error);
271  }
272 
273  if (detectorID == 0) {
274 
275  detectorID = detector.getID();
276 
277  } else if (detectorID != detector.getID()) {
278 
279  FATAL("Inconsistent detector identifier " << detectorID << " != " << detector.getID() << endl);
280  }
281 
282 
283  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
284 
285  for (unsigned int pmt = 0; pmt != module->size(); ++pmt) {
286 
287  const JPMTIdentifier id(module->getID(), pmt);
288 
289  if (parameters.find(id) == parameters.end()) {
290 
291  DEBUG("Setting default parameters for PMT " << id << endl);
292 
293  parameters[id] = parameters.getDefaultPMTParameters();
294  }
295  }
296  }
297  }
298 
299  if (!mod.empty()) {
300 
301  if (!hasDetectorAddressMap(detectorID)) {
302  FATAL("Invalid detector identifier " << detectorID << endl);
303  }
304 
305  const JDetectorAddressMap& demo = getDetectorAddressMap(detectorID);
306 
307  for (JPMTParametersMap::iterator ps = parameters.begin(); ps != parameters.end(); ++ps) {
308 
309  const JPMTPhysicalAddress& address = demo.get(ps->first);
310 
311  for (vector< JModifier<JPMTPhysicalAddress> >::const_iterator i = mod.begin(); i != mod.end(); ++i) {
312 
313  if (compare(i->address, address)) {
314 
315  DEBUG("Modifying parameters for PMT " << ps->first << ' ' << i->action << ' ' << i->key << ' ' << i->value << endl);
316 
317  if (!i->apply(ps->second)) {
318  ERROR("No valid action: " << *i << endl);
319  }
320  }
321  }
322  }
323  }
324 
325  if (!daq.empty()) {
326 
327  for (JPMTParametersMap::iterator ps = parameters.begin(); ps != parameters.end(); ++ps) {
328 
329  for (vector< JModifier<JPMTIdentifier> >::const_iterator i = daq.begin(); i != daq.end(); ++i) {
330 
331  if (compare(ps->first, i->address)) {
332 
333  DEBUG("Modifying parameters for PMT " << ps->first << ' ' << i->action << ' ' << i->key << ' ' << i->value << endl);
334 
335  if (!i->apply(ps->second)) {
336  ERROR("No valid action: " << *i << endl);
337  }
338  }
339  }
340  }
341  }
342 
343 
344  if (mu > 0.0) {
345 
346  DEBUG("Correct measured QE for two-hit probability " << mu << endl);
347 
348  try {
349  parameters.convertHitProbabilityToQE(mu);
350  }
351  catch(const JException& error) {
352  FATAL(error.what());
353  }
354 
355  } else if (mu < 0.0) {
356 
357  FATAL("Invalid expection value for two-hit probability " << mu << endl);
358  }
359 
360 
361  if (T_ns != JRange_t()) {
362 
363  DEBUG("Correct measured QE for time-over-threshold range " << T_ns << endl);
364 
365  const int NPE = 1;
366 
367  for (JPMTParametersMap::iterator i = parameters.begin(); i != parameters.end(); ++i) {
368 
369  const JPMTAnalogueSignalProcessor cpu(i->second);
370 
371  i->second.QE *= (cpu.getIntegralOfChargeProbability(i->second.threshold,
372  cpu.getNPE(T_ns.getUpperLimit()),
373  NPE)
374  /
375  cpu.getIntegralOfChargeProbability(cpu.getNPE(T_ns.getLowerLimit()),
376  cpu.getNPE(T_ns.getUpperLimit()),
377  NPE));
378  }
379  }
380 
381 
382  if (outputFile != "") {
383 
384  parameters.comment.add(JMeta(argc, argv));
385 
386  ofstream out(outputFile.c_str());
387 
388  out << parameters << endl;
389 
390  out.close();
391  }
392 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
Detector data structure.
Definition: JDetector.hh:89
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
*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.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
string outputFile
const JModuleAddressMap & get(const int id) const
Get module address map.
Type definition of range.
Definition: JHead.hh:41
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int getID() const
Get identifier.
Definition: JObjectID.hh:50
#define ERROR(A)
Definition: JMessage.hh:66
Auxiliary class for map of PMT parameters.
int debug
debug level
Definition: JSirene.cc:67
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
#define FATAL(A)
Definition: JMessage.hh:67
virtual const char * what() const override
Get error message.
Definition: JException.hh:48
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Data structure for PMT physical address.
do set_variable DETECTOR_TXT $WORKDIR detector
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62