Jpp  15.0.0-rc.2
the software that should make you happy
 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 <map>
#include <algorithm>
#include "TRandom3.h"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorHeader.hh"
#include "JDetector/JModuleStatus.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JPMTIdentifier.hh"
#include "JDetector/JPMTPhysicalAddress.hh"
#include "JDetector/JPMTStatus.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 "JLang/JComparator.hh"
#include "JLang/JComparison.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|s) "<string number>         (set|add|sub|randset|randadd|randsub) x0 [x1 x2]"
    -M     "<module identifier>     (rot|randrot) phi"
    -(S|s) "<string number>         (rot|randrot) phi"
    -M     "<module identifier>     (mul|randmul) factor"
    -(S|s) "<string number>         (mul|randmul) factor"
    -M     "<module identifier>     (div|randdiv) factor"
    -(S|s) "<string number>         (div|randdiv) factor"
    -M     "<module identifier>     (reset)"
    -(S|s) "<string number>         (reset)"
    -M     "<module identifier>     (assign)  identifier"
    -M     "<module identifier>     (locate)  <string> <floor>"
    -M     "<module identifier>     (swap)    <PMT>    <PMT>"
    -M     "<module identifier>     (SET|ADD|SUB|) x0 [x1 x2 x3]"
    -(S|s) "<string number>         (SET|ADD|SUB|) x0 [x1 x2 x3]"
    -M     "<module identifier>     (ROT) phi"
    -(S|s) "<string number>         (ROT) phi"
    -M     "<module identifier>     (SET)"
    -(S|s) "<string number>         (SET)"
    -(S|s) "<string number>         (tilt|randtilt) Tx Ty"
    -W     "<module identifier>     (set|reset)  (MODULE_DISABLE|COMPASS_DISABLE|HYDROPHONE_DISABLE|PIEZO_DISABLE|MODULE_OUT_OF_SYNC)"
    -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 option -s is equivalent to option -S except that the action applies only to the optical modules in the string and not the base module.

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. invalid
  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 and [rand]div, the multiplication/division factor (a.k.a. "stretching") applies to the z-coordinates of the modules.
The factor is defined as a fraction; the actual multiplication/division factor is (1 + factor).

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

  1. time calibration of piezo sensor or hydrophone (t = x0)
  2. invalid
  3. invalid
  4. quaternion calibration of compass (qa = x0, qb = x1, qc = x2, qd = x3)

For options ROT, the angle phi refers to an anti-clockwise rotation around the z-axis of the quaternion calibration of the compass.
The rotation angle is defined in radians.

If no values are given at the option SET,

In this, the time calibration is corrected for the delay time of the piezo sensor and hydrophone
which are defined by JDETECTOR::PIEZO_DELAYTIME_US and JDETECTOR::HYDROPHONE_DELAYTIME_US, respectively.
The units of all positions and time values are m and ns, respectively.

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, -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 877 of file JEditDetector.cc.

878 {
879  using namespace std;
880  using namespace JPP;
881 
882  typedef JToken<';'> JToken_t;
883 
884  string inputFile;
885  string outputFile;
886  vector<JToken_t> hdr;
890  vector< pair<int,
891  JModuleModifier> > wip;
893  JPMTModifier> > pmt;
895  JPMTModifier> > alt;
896  vector<JRange_t> keep;
898  vector<int> id;
899  multimap<int, int> del;
900  int option;
901  int debug;
902 
903  try {
904 
905  JParser<> zap("Auxiliary program to modify detector.");
906 
907  zap['a'] = make_field(inputFile);
908  zap['o'] = make_field(outputFile);
909  zap['@'] = make_field(hdr, "header modification") = JPARSER::initialised();
910  zap['M'] = make_field(mod, "module modification") = JPARSER::initialised();
911  zap['S'] = make_field(str, "string modification (optical modules and base module") = JPARSER::initialised();
912  zap['s'] = make_field(dos, "string modification (optical modules only)") = JPARSER::initialised();
913  zap['W'] = make_field(wip, "module status modification") = JPARSER::initialised();
914  zap['P'] = make_field(pmt, "PMT status modification by PMT logical address") = JPARSER::initialised();
915  zap['p'] = make_field(alt, "PMT status modification by PMT physical address") = JPARSER::initialised();
916  zap['k'] = make_field(keep, "keep string[s]") = JPARSER::initialised();
917  zap['r'] = make_field(rm, "remove string[s]") = JPARSER::initialised();
918  zap['m'] = make_field(id, "remove module by identifier") = JPARSER::initialised();
919  zap['D'] = make_field(del, "remove module by location") = JPARSER::initialised();
920  zap['O'] = make_field(option, "sort modules") = 0, 1, 2;
921  zap['d'] = make_field(debug) = 2;
922 
923  zap(argc, argv);
924  }
925  catch(const exception &error) {
926  FATAL(error.what() << endl);
927  }
928 
930 
931  try {
932  load(inputFile, detector);
933  }
934  catch(const JException& error) {
935  FATAL(error);
936  }
937 
938 
939  gRandom->SetSeed(0);
940 
941 
942  if ((keep.empty() ? 0 : 1 +
943  rm .empty() ? 0 : 1 +
944  id .empty() ? 0 : 1) > 1) {
945  FATAL("Use either option -k, -r or -m." << endl);
946  }
947 
948 
949  detector.comment.add(JMeta(argc,argv));
950 
951  if (detector.setToLatestVersion()) {
952  NOTICE("Set detector version to " << detector.getVersion() << endl);
953  }
954 
955 
956  if (!hdr.empty()) {
957 
958  int id = -1;
959 
960  JProperties helper = detector.getProperties();
961 
962  helper["id"] = id;
963 
964  for (vector<JToken_t>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
965 
966  istringstream is(*i);
967 
968  is >> helper;
969  }
970 
971  if (id != -1) {
972  detector.setID(id);
973  }
974  }
975 
976 
977  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
978 
979  bool __rm__ = !keep.empty() && rm.empty();
980 
981  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
982  if (module->getString() >= i->first && module->getString() <= i->second) {
983  __rm__ = false;
984  }
985  }
986 
987  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
988  if (module->getString() >= i->first && module->getString() <= i->second) {
989  __rm__ = true;
990  }
991  }
992 
993  if (!id.empty()) {
994  __rm__ = find(id.begin(), id.end(), module->getID()) == id.end();
995  }
996 
997  const auto range = del.equal_range(module->getString());
998 
999  for (auto i = range.first; i != range.second; ++i) {
1000  if (i->second == module->getFloor()) {
1001  __rm__ = true;
1002  }
1003  }
1004 
1005  if (__rm__)
1006  module = detector.erase(module);
1007  else
1008  ++module;
1009  }
1010 
1011 
1012  for (vector< pair<int, JModifier> >::const_iterator i = mod.begin(); i != mod.end(); ++i) {
1013 
1014  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1015 
1016  if (module->getID() == i->first || i->first == WILDCARD ){
1017 
1018  if (debug >= debug_t) {
1019  print(cout, *module, i->second);
1020  }
1021 
1022  if (!i->second.apply(*module)) {
1023  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1024  }
1025  }
1026  }
1027  }
1028 
1029 
1030  for (vector< pair<int, JModifier> >::const_iterator i = str.begin(); i != str.end(); ++i) {
1031 
1032  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1033 
1034  if (module->getString() == i->first || i->first == WILDCARD) {
1035 
1036  const JModifier modifier = getModifier(module->getString(), i->second);
1037 
1038  if (debug >= debug_t) {
1039  print(cout, *module, i->second);
1040  }
1041 
1042  if (!modifier.apply(*module)) {
1043  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1044  }
1045  }
1046  }
1047  }
1048 
1049 
1050  for (vector< pair<int, JModifier> >::const_iterator i = dos.begin(); i != dos.end(); ++i) {
1051 
1052  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1053 
1054  if (module->getFloor() != 0) {
1055 
1056  if (module->getString() == i->first || i->first == WILDCARD) {
1057 
1058  const JModifier modifier = getModifier(module->getString(), i->second);
1059 
1060  if (debug >= debug_t) {
1061  print(cout, *module, i->second);
1062  }
1063 
1064  if (!modifier.apply(*module)) {
1065  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1066  }
1067  }
1068  }
1069  }
1070  }
1071 
1072 
1073  for (vector< pair<int, JModuleModifier> >::const_iterator i = wip.begin(); i != wip.end(); ++i) {
1074 
1075  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1076 
1077  if (module->getID() == i->first || i->first == WILDCARD ){
1078 
1079  if (debug >= debug_t) {
1080  print(cout, *module, i->second);
1081  }
1082 
1083  if (!i->second.apply(*module)) {
1084  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1085  }
1086  }
1087  }
1088  }
1089 
1090 
1091  for (vector< pair<JPMTIdentifier, JPMTModifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
1092 
1093  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1094 
1095  if (module->getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
1096 
1097  if (debug >= debug_t) {
1098  print(cout, i->first, i->second);
1099  }
1100 
1101  if (i->first.getPMTAddress() == WILDCARD) {
1102 
1103  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
1104  if (!i->second.apply(module->getPMT(pmt))) {
1105  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1106  }
1107  }
1108 
1109  } else if (i->first.getPMTAddress() < 0 ||
1110  i->first.getPMTAddress() >= getNumberOfPMTs(*module) ||
1111  !i->second.apply(module->getPMT(i->first.getPMTAddress()))) {
1112  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1113  }
1114  }
1115  }
1116  }
1117 
1118 
1119  if (!alt.empty()) {
1120 
1121  if (!hasDetectorAddressMap(detector.getID())) {
1122  FATAL("Invalid detector identifier " << detector.getID() << endl);
1123  }
1124 
1125  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
1126 
1127  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
1128 
1129  const JModuleAddressMap memo = demo.get(module->getID());
1130 
1131  for (vector< pair<JPMTPhysicalAddress, JPMTModifier> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
1132 
1133  const JPMTIdentifier id(module->getID(), memo.getAddressTranslator(i->first).tdc);
1134 
1135  if (debug >= debug_t) {
1136  print(cout, id, i->second);
1137  }
1138 
1139  if (!i->second.apply(module->getPMT(id.getPMTAddress()))) {
1140  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
1141  }
1142  }
1143  }
1144  }
1145 
1146 
1147  switch (option) {
1148  case 1:
1149  sort(detector.begin(), detector.end(), make_comparator(&JModule::getID));
1150  break;
1151 
1152  case 2:
1153  sort(detector.begin(), detector.end(), make_comparator(&JModule::getLocation));
1154  break;
1155 
1156  default:
1157  break;
1158  };
1159 
1160 
1161  try {
1163  }
1164  catch(const JException& error) {
1165  FATAL(error);
1166  }
1167 }
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
debug
Definition: JMessage.hh:29
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
Definition: JComparator.hh:185
Detector data structure.
Definition: JDetector.hh:89
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
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
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
Data structure for PMT physical address.
do set_variable DETECTOR_TXT $WORKDIR detector