Jpp
Functions
JEditDetector.cc File Reference
#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)
    -P "<PMT identifier>    (set|reset)   PMT_STATUS"
    -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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 536 of file JEditDetector.cc.

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