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 "JDetector/JPMTPhysicalAddress.hh"
#include "JDetector/JModuleAddressMap.hh"
#include "JDetector/JDetectorAddressMap.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "JGeometry3D/JVector3D.hh"
#include "JMath/JConstants.hh"
#include "JMath/JMath.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>     (assign)  identifier"
    -M "<module identifier>     (SET|ADD|SUB|) x0 [x1 x2 x3]"
    -S "<string number>         (SET|ADD|SUB|) x0 [x1 x2 x3]"
    -M "<module identifier>     (SET)"
    -S "<string number>         (SET)"
    -P "<PMT identifier>        (set|reset)   (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
    -p "<PMT physical address>  (set|reset)   (PMT_DISABLE|HIGH_RATE_VETO_DISABLE|FIFO_FULL_DISABLE|UDP_COUNTER_DISABLE|UDP_TRAILER_DISABLE|OUT_OF_SYNC)"
    -k "<string number>[-<string number>"
    -r "<string number>[-<string number>"
    -m "<module identifier>"
    -D "<string number> <floor>"
    -@ "<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 modules of 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 and [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 (a.k.a. "stretching") applies to the z-coordinates of the optical modules and not to the base module (read anchor).
The factor is defined as a fraction; the actual multiplication factor is (1 + factor).

For options [rand]via, the factor is multiplied with the floor number and then added to the time calibration.

For options SET ADD SUB, the number of values apply to time or quaternion calibration of the module in the following way:

  1. time calibration (t = x0)
  2. invalid
  3. invalid
  4. quaternion calibration (qa = x0, qb = x1, qc = x2, qd = x3)

If no values are given at the option SET, the time calibration of the module is set to the average time calibration of the PMTs in that module, corrected for the delay time of the pieze sensor (JDETECTOR::PIEZO_DELAYTIME_US).
For the base module, the time calibration is set to 0, corrected for the delay time of the hydrophone (JDETECTOR::HYDROPHONE_DELAYTIME_US).
The unit of time calibration is ns.

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.

The options -m and -D can be used to maintain a specific module (and remove all others) and to delete a floor from a string, respectively.

Note finally 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 650 of file JEditDetector.cc.

651 {
652  using namespace std;
653  using namespace JPP;
654 
655  string inputFile;
656  string outputFile;
657  vector<JModifier> mod;
658  vector<JModifier> str;
659  vector<string> hdr;
662  vector<JRange_t> keep;
663  vector<JRange_t> rm;
664  vector<int> id;
665  multimap<int, int> del;
666  int debug;
667 
668  try {
669 
670  JParser<> zap("Auxiliary program to modify detector.");
671 
672  zap['a'] = make_field(inputFile);
673  zap['M'] = make_field(mod) = JPARSER::initialised();
674  zap['S'] = make_field(str) = JPARSER::initialised();
675  zap['@'] = make_field(hdr) = JPARSER::initialised();
676  zap['P'] = make_field(pmt) = JPARSER::initialised();
677  zap['p'] = make_field(alt) = JPARSER::initialised();
678  zap['o'] = make_field(outputFile);
679  zap['k'] = make_field(keep) = JPARSER::initialised();
680  zap['r'] = make_field(rm) = JPARSER::initialised();
681  zap['m'] = make_field(id) = JPARSER::initialised();
682  zap['D'] = make_field(del) = JPARSER::initialised();
683  zap['d'] = make_field(debug) = 2;
684 
685  zap(argc, argv);
686  }
687  catch(const exception &error) {
688  FATAL(error.what() << endl);
689  }
690 
692 
693  try {
694  load(inputFile, detector);
695  }
696  catch(const JException& error) {
697  FATAL(error);
698  }
699 
700 
701  gRandom->SetSeed(0);
702 
703 
704  if ((keep.empty() ? 0 : 1 +
705  rm .empty() ? 0 : 1 +
706  id .empty() ? 0 : 1) > 1) {
707  FATAL("Use either option -k, -r or -m." << endl);
708  }
709 
710 
711  detector.comment.add(JMeta(argc,argv));
712 
713  if (detector.setToLatestVersion()) {
714  NOTICE("Set detector version to " << detector.getVersion() << endl);
715  }
716 
717  if (!hdr.empty()) {
718 
719  JProperties helper = detector.getProperties();
720 
721  for (vector<string>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
722 
723  istringstream is(*i);
724 
725  is >> helper;
726  }
727  }
728 
729 
730  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
731 
732  bool __rm__ = !keep.empty() && rm.empty();
733 
734  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
735  if (module->getString() >= i->first && module->getString() <= i->second) {
736  __rm__ = false;
737  }
738  }
739 
740  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
741  if (module->getString() >= i->first && module->getString() <= i->second) {
742  __rm__ = true;
743  }
744  }
745 
746  if (!id.empty()) {
747  __rm__ = find(id.begin(), id.end(), module->getID()) == id.end();
748  }
749 
750  const auto range = del.equal_range(module->getString());
751 
752  for (auto i = range.first; i != range.second; ++i) {
753  if (i->second == module->getFloor()) {
754  __rm__ = true;
755  }
756  }
757 
758  if (__rm__)
759  module = detector.erase(module);
760  else
761  ++module;
762  }
763 
764 
765  for (vector<JModifier>::const_iterator i = mod.begin(); i != mod.end(); ++i) {
766 
767  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
768 
769  if (module->getID() == i->id || i->id == WILDCARD ){
770 
771  DEBUG("Modifier" << ' '
772  << "(" << FILL(4,'0') << module->getString() << "," << FILL(2,'0') << module->getFloor() << FILL() << ")" << ' '
773  << setw(10) << module->getID() << ' '
774  << "action" << ' ' << i->action << JEEPZ() << i->data << endl);
775 
776  if (!i->apply(*module)) {
777  ERROR("No valid action: " << *i << endl);
778  }
779  }
780  }
781  }
782 
783 
784  for (vector<JModifier>::const_iterator i = str.begin(); i != str.end(); ++i) {
785 
786  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
787 
788  if (module->getString() == i->id || i->id == WILDCARD) {
789 
790  const JModifier& modifier = getModifier(module->getString(), *i);
791 
792  DEBUG("Modifier" << ' '
793  << "(" << FILL(4,'0') << module->getString() << "," << FILL(2,'0') << module->getFloor() << FILL() << ")" << ' '
794  << setw(10) << module->getID() << ' '
795  << "action" << ' ' << modifier.action << JEEPZ() << modifier.data << endl);
796 
797  if (!modifier.apply(*module)) {
798  ERROR("No valid action: " << *i << endl);
799  }
800  }
801  }
802  }
803 
804 
805  for (vector< JPMTModifier<JPMTIdentifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
806 
807  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
808 
809  if (module->getID() == i->getModuleID() || i->getModuleID() == WILDCARD) {
810 
811  DEBUG("PMT modifier" << ' '
812  << "(" << setw(10) << module->getID() << "," << setw(2) << i->getPMTAddress() << ")" << ' '
813  << "action" << ' ' << i->action << ' '
814  << "value" << ' ' << i->value << endl);
815 
816  if (i->getPMTAddress() == WILDCARD) {
817 
818  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
819  if (!i->apply(module->getPMT(pmt))) {
820  ERROR("No valid action: " << *i << endl);
821  }
822  }
823 
824  } else if (i->getPMTAddress() < 0 ||
825  i->getPMTAddress() >= getNumberOfPMTs(*module) ||
826  !i->apply(module->getPMT(i->getPMTAddress()))) {
827  ERROR("No valid action: " << *i << endl);
828  }
829  }
830  }
831  }
832 
833  if (!alt.empty()) {
834 
835  if (!hasDetectorAddressMap(detector.getID())) {
836  FATAL("Invalid detector identifier " << detector.getID() << endl);
837  }
838 
839  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
840 
841  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
842 
843  const JModuleAddressMap memo = demo.get(module->getID());
844 
845  for (vector< JPMTModifier<JPMTPhysicalAddress> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
846 
847  const int tdc = memo.getAddressTranslator(*i).tdc;
848 
849  DEBUG("PMT modifier" << ' '
850  << "(" << setw(10) << module->getID() << "," << setw(2) << tdc << ")" << ' '
851  << "action" << ' ' << i->action << ' '
852  << "value" << ' ' << i->value << endl);
853 
854  if (!i->apply(module->getPMT(tdc))) {
855  ERROR("No valid action: " << *i << endl);
856  }
857  }
858  }
859  }
860 
861 
862  try {
864  }
865  catch(const JException& error) {
866  FATAL(error);
867  }
868 }
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:80
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
Utility class to parse parameter values.
Definition: JProperties.hh:496
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
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
is
Definition: JDAQCHSM.chsm:167
const JModuleAddressMap & get(const int id) const
Get module address map.
Lookup table for PMT addresses in optical module.
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
Auxiliary data structure for streaming of STL containers.
Definition: JPrint.hh:65
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:327
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi mv $WORKDIR/fit.root $MODULE_ROOT typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
Definition: module-Z:fit.sh:84
#define FATAL(A)
Definition: JMessage.hh:67
const JPMTAddressTranslator & getAddressTranslator(const int tdc) const
Get PMT address translator.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
do set_variable DETECTOR_TXT $WORKDIR detector
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62