Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JEditDetector.cc File Reference

Auxiliary program to modify detector calibration. More...

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "TRandom3.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorHeader.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTIdentifier.hh"
#include "JGeometry3D/JVector3D.hh"
#include "JTools/JConstants.hh"
#include "JTools/JRange.hh"
#include "JLang/JException.hh"
#include "JSupport/JMeta.hh"
#include "Jeep/JeepToolkit.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 modify detector calibration.

Syntax:

    -M "<module identifier> (set|add|sub|randset|randadd|randsub) x0 [x1 [x2]]"
    -S "<string number>     (set|add|sub|randset|randadd|randsub) x0 [x1 [x2]]"
    -M "<module identifier> (rot|randrot) phi"
    -S "<string number>     (rot|randrot) phi"
    -M "<module identifier> (mul|randmul) factor"
    -S "<string number>     (mul|randmul) factor"
    -M "<module identifier> (via|randvia) factor"
    -S "<string number>     (via|randvia) factor"
    -M "<module identifier> (reset)
    -S "<string number>="">     (reset)
    -M "<module identifier>  =  identifier"
    -P "<PMT identifier>    (set|reset)   (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE)"
    -k "<string number>[-<string number>"
    -r "<string number>[-<string number>"
    -@ "<key>=<value>[;<key>=<value>"

Options -M and -S refer to a module and a string, respectively.
The values provided for a string modification coherently apply to the specified string number.

The options randXXX correspond to a randomisation of the specified option.

If the module identifier or string number is -1, the action is applied to all modules or strings in the detector, respectively.

For options [rand]set [rand]add [rand]sub, the number of values apply to position or time calibration in the following way:

  1. time calibration (t = x0)
  2. position calibration (x = x0, y = x1, z = 0)
  3. position calibration (x = x0, y = x1, z = x2)

For options [rand]rot, the angle phi refers to an anti-clockwise rotation around the z-axis.
The rotation angle is defined in radians.

For options [rand]mul, the multiplication factor applies to the z-coordinates.
This factor is defined as a fraction; the actual multiplication factor is (1 + factor).

For options [rand]via, The factor applies to the time calibration as a function of floor number.

Note that for string modifiers with option randxxx, the action is coherently applied to the modules in the specified string. Only one type of action (defined by xxx and the number of values) is then allowed per string.

Option -@ refers to the header information.
The list of possible keys can be obtained using JPrintDetector.cc with option -O header.

Multiple options -M, -S or -@ will be processed in order of appearance.

Options -k and -r can be used to keep and remove a range of string numbers, respectively.

Note that if the output file name is the same as the input file name, the original file will be overwritten.

Author
mdejong

Definition in file JEditDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 541 of file JEditDetector.cc.

542 {
543  using namespace std;
544  using namespace JPP;
545 
546  string inputFile;
547  string outputFile;
548  vector<JModifier> mod;
549  vector<JModifier> str;
550  vector<string> hdr;
552  vector<JRange_t> keep;
553  vector<JRange_t> rm;
554  int debug;
555 
556  try {
557 
558  JParser<> zap("Auxiliary program to modify detector.");
559 
560  zap['a'] = make_field(inputFile);
561  zap['M'] = make_field(mod) = JPARSER::initialised();
562  zap['S'] = make_field(str) = JPARSER::initialised();
563  zap['@'] = make_field(hdr) = JPARSER::initialised();
564  zap['P'] = make_field(pmt) = JPARSER::initialised();
565  zap['o'] = make_field(outputFile);
566  zap['k'] = make_field(keep) = JPARSER::initialised();
567  zap['r'] = make_field(rm) = JPARSER::initialised();
568  zap['d'] = make_field(debug) = 2;
569 
570  zap(argc, argv);
571  }
572  catch(const exception &error) {
573  FATAL(error.what() << endl);
574  }
575 
577 
578  try {
579  load(inputFile, detector);
580  }
581  catch(const JException& error) {
582  FATAL(error);
583  }
584 
585 
586  gRandom->SetSeed(0);
587 
588 
589  if (!keep.empty() && !rm.empty()) {
590  FATAL("Use either option -k or -r." << endl);
591  }
592 
593 
594  detector.comment.add(JMeta(argc,argv));
595 
596  if (!pmt.empty()) {
597 
598  if (detector.setVersion(JDetectorVersion::V3)) {
599  NOTICE("Set detector version to " << JDetectorVersion::V3 << endl);
600  }
601  }
602 
603  if (!hdr.empty()) {
604 
605  JProperties helper = detector.getProperties();
606 
607  for (vector<string>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
608 
609  istringstream is(*i);
610 
611  is >> helper;
612  }
613  }
614 
615 
616  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
617 
618  bool __rm__ = !keep.empty() && rm.empty();
619 
620  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
621  if (module->getString() >= i->first && module->getString() <= i->second) {
622  __rm__ = false;
623  }
624  }
625 
626  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
627  if (module->getString() >= i->first && module->getString() <= i->second) {
628  __rm__ = true;
629  }
630  }
631 
632  if (__rm__)
633  module = detector.erase(module);
634  else
635  ++module;
636  }
637 
638 
639  for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
640 
641  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
642 
643  if (module->getID() == i->id || i->id == WILD_CARD ){
644 
645  DEBUG("Modifier" << ' '
646  << "(" << setw(3) << module->getString() << "," << setw(2) << module->getFloor() << ")" << ' '
647  << setw(8) << module->getID() << ' '
648  << "action" << ' ' << i->action << JEEPZ() << i->data << endl);
649 
650  if (!i->apply(*module)) {
651  ERROR("No valid action: " << *i << endl);
652  }
653  }
654  }
655  }
656 
657 
658  for (vector<JModifier>::const_iterator i = str.begin(); i != str.end(); ++i) {
659 
660  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
661 
662  if (module->getString() == i->id || i->id == WILD_CARD) {
663 
664  const JModifier& modifier = getModifier(module->getString(), *i);
665 
666  DEBUG("Modifier" << ' '
667  << "(" << setw(3) << module->getString() << "," << setw(2) << module->getFloor() << ")" << ' '
668  << setw(8) << module->getID() << ' '
669  << "action" << ' ' << modifier.action << JEEPZ() << modifier.data << endl);
670 
671  if (!modifier.apply(*module)) {
672  ERROR("No valid action: " << *i << endl);
673  }
674  }
675  }
676  }
677 
678 
679  for (vector<JPMTModifier>::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
680 
681  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
682 
683  if (module->getID() == i->getModuleID() || i->getModuleID() == WILD_CARD) {
684 
685  DEBUG("PMT modifier" << ' '
686  << "(" << setw(8) << module->getID() << "," << setw(2) << i->getPMTAddress() << ")" << ' '
687  << "action" << ' ' << i->action << ' '
688  << "value" << ' ' << i->value << endl);
689 
690  if (i->getPMTAddress() == WILD_CARD) {
691 
692  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
693  if (!i->apply(module->getPMT(pmt))) {
694  ERROR("No valid action: " << *i << endl);
695  }
696  }
697 
698  } else if (i->getPMTAddress() < 0 ||
699  i->getPMTAddress() >= getNumberOfPMTs(*module) ||
700  !i->apply(module->getPMT(i->getPMTAddress()))) {
701  ERROR("No valid action: " << *i << endl);
702  }
703  }
704  }
705  }
706 
707  try {
709  }
710  catch(const JException& error) {
711  FATAL(error);
712  }
713 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Detector data structure.
Definition: JDetector.hh:80
Utility class to parse parameter values.
Definition: JProperties.hh:496
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:63
string outputFile
is
Definition: JDAQCHSM.chsm:167
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
Detector file.
Definition: JHead.hh:130
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:558
#define FATAL(A)
Definition: JMessage.hh:67
static const char WILD_CARD
Definition: JDAQTags.hh:34
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62