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 "JLang/JToken.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 651 of file JEditDetector.cc.

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