Jpp  18.2.1
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  JRange_t QE;
218  string outputFile;
219  bool squash;
220  int debug;
221 
222  try {
223 
224  JParser<> zap("Auxiliary program to edit PMT parameters map.");
225 
226  zap['a'] = make_field(detectorFile, "detector file.") = "";
227  zap['D'] = make_field(detectorID, "detector identifier (in absence of detector file).") = 0;
228  zap['P'] = make_field(parameters, "PMT simulation data (or corresponding file name)") = JPARSER::initialised();
229  zap['@'] = make_field(hdr, "PMT parameter modifier for default values.") = JPARSER::initialised();
230  zap['A'] = make_field(mod, "PMT parameter modifier by physical address (e.g. B1).") = JPARSER::initialised();
231  zap['M'] = make_field(daq, "PMT parameter modifier by DAQ address (e.g. <module> <channel>.") = JPARSER::initialised();
232  zap['E'] = make_field(mu, "expectation value for npe given two-fold coincidence") = 0.0;
233  zap['T'] = make_field(T_ns, "time-over-threshold range.") = JRange_t();
234  zap['Q'] = make_field(QE, "QE range.") = JRange_t();
235  zap['o'] = make_field(outputFile, "output file.");
236  zap['q'] = make_field(squash, "squash meta data");
237  zap['d'] = make_field(debug, "debug level") = 2;
238 
239  zap(argc, argv);
240  }
241  catch(const exception &error) {
242  FATAL(error.what() << endl);
243  }
244 
245 
246  if (squash) {
247  parameters.comment.clear();
248  }
249 
250  parameters.comment.add(JMeta(argc,argv));
251 
252 
253  for (vector< JModifier<> >::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
254 
255  DEBUG("Modifying default PMT parameters " << i->action << ' ' << i->key << ' ' << i->value << endl);
256 
257  if (!i->apply(parameters.getDefaultPMTParameters())) {
258  ERROR("No valid action: " << *i << endl);
259  }
260  }
261 
262  if (detectorFile != "") {
263 
264  // Setting default PMT parameters for given detector.
265 
267 
268  try {
269  load(detectorFile, detector);
270  }
271  catch(const JException& error) {
272  FATAL(error);
273  }
274 
275  if (detectorID == 0) {
276 
277  detectorID = detector.getID();
278 
279  } else if (detectorID != detector.getID()) {
280 
281  FATAL("Inconsistent detector identifier " << detectorID << " != " << detector.getID() << endl);
282  }
283 
284 
285  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
286 
287  for (unsigned int pmt = 0; pmt != module->size(); ++pmt) {
288 
289  const JPMTIdentifier id(module->getID(), pmt);
290 
291  if (parameters.find(id) == parameters.end()) {
292 
293  DEBUG("Setting default parameters for PMT " << id << endl);
294 
295  parameters[id] = parameters.getDefaultPMTParameters();
296  }
297  }
298  }
299  }
300 
301  if (!mod.empty()) {
302 
303  if (!hasDetectorAddressMap(detectorID)) {
304  FATAL("Invalid detector identifier " << detectorID << endl);
305  }
306 
307  const JDetectorAddressMap& demo = getDetectorAddressMap(detectorID);
308 
309  for (JPMTParametersMap::iterator ps = parameters.begin(); ps != parameters.end(); ++ps) {
310 
311  const JPMTPhysicalAddress& address = demo.get(ps->first);
312 
313  for (vector< JModifier<JPMTPhysicalAddress> >::const_iterator i = mod.begin(); i != mod.end(); ++i) {
314 
315  if (compare(i->address, address)) {
316 
317  DEBUG("Modifying parameters for PMT " << ps->first << ' ' << i->action << ' ' << i->key << ' ' << i->value << endl);
318 
319  if (!i->apply(ps->second)) {
320  ERROR("No valid action: " << *i << endl);
321  }
322  }
323  }
324  }
325  }
326 
327  if (!daq.empty()) {
328 
329  for (JPMTParametersMap::iterator ps = parameters.begin(); ps != parameters.end(); ++ps) {
330 
331  for (vector< JModifier<JPMTIdentifier> >::const_iterator i = daq.begin(); i != daq.end(); ++i) {
332 
333  if (compare(ps->first, i->address)) {
334 
335  DEBUG("Modifying parameters for PMT " << ps->first << ' ' << i->action << ' ' << i->key << ' ' << i->value << endl);
336 
337  if (!i->apply(ps->second)) {
338  ERROR("No valid action: " << *i << endl);
339  }
340  }
341  }
342  }
343  }
344 
345 
346  if (mu > 0.0) {
347 
348  DEBUG("Correct measured QE for two-hit probability " << mu << endl);
349 
350  try {
351  parameters.convertHitProbabilityToQE(mu);
352  }
353  catch(const JException& error) {
354  FATAL(error.what());
355  }
356 
357  } else if (mu < 0.0) {
358 
359  FATAL("Invalid expection value for two-hit probability " << mu << endl);
360  }
361 
362 
363  if (T_ns != JRange_t()) {
364 
365  DEBUG("Correct measured QE for time-over-threshold range " << T_ns << endl);
366 
367  const int NPE = 1;
368 
369  for (JPMTParametersMap::iterator i = parameters.begin(); i != parameters.end(); ++i) {
370 
371  const JPMTAnalogueSignalProcessor cpu(i->second);
372 
373  i->second.QE *= (cpu.getIntegralOfChargeProbability(i->second.threshold,
374  cpu.getNPE(T_ns.getUpperLimit()),
375  NPE)
376  /
377  cpu.getIntegralOfChargeProbability(cpu.getNPE(T_ns.getLowerLimit()),
378  cpu.getNPE(T_ns.getUpperLimit()),
379  NPE));
380  }
381  }
382 
383 
384  if (QE != JRange_t()) {
385 
386  for (JPMTParametersMap::iterator i = parameters.begin(); i != parameters.end(); ++i) {
387  i->second.QE = QE.constrain(i->second.QE);
388  }
389  }
390 
391 
392  if (outputFile != "") {
393 
394  parameters.comment.add(JMeta(argc, argv));
395 
396  ofstream out(outputFile.c_str());
397 
398  out << parameters << endl;
399 
400  out.close();
401  }
402 }
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:1514
General exception.
Definition: JException.hh:24
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:83
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:1989
int getID() const
Get identifier.
Definition: JObjectID.hh:50
#define ERROR(A)
Definition: JMessage.hh:66
Auxiliary class for map of PMT parameters.
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:64
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
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62