Jpp - 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 "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|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>     (reset)"
    -(S|s) "<string number>         (reset)"
    -M     "<module identifier>     (assign)  identifier"
    -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"
    -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, 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 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 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 722 of file JEditDetector.cc.

723 {
724  using namespace std;
725  using namespace JPP;
726 
727  typedef JToken<';'> JToken_t;
728 
729  string inputFile;
730  string outputFile;
731  vector<JToken_t> hdr;
736  JPMTModifier> > pmt;
738  JPMTModifier> > alt;
739  vector<JRange_t> keep;
740  vector<JRange_t> rm;
741  vector<int> id;
742  multimap<int, int> del;
743  int debug;
744 
745  try {
746 
747  JParser<> zap("Auxiliary program to modify detector.");
748 
749  zap['a'] = make_field(inputFile);
750  zap['o'] = make_field(outputFile);
751  zap['@'] = make_field(hdr) = JPARSER::initialised();
752  zap['M'] = make_field(mod) = JPARSER::initialised();
753  zap['S'] = make_field(str) = JPARSER::initialised();
754  zap['s'] = make_field(dos) = JPARSER::initialised();
755  zap['P'] = make_field(pmt) = JPARSER::initialised();
756  zap['p'] = make_field(alt) = JPARSER::initialised();
757  zap['k'] = make_field(keep) = JPARSER::initialised();
758  zap['r'] = make_field(rm) = JPARSER::initialised();
759  zap['m'] = make_field(id) = JPARSER::initialised();
760  zap['D'] = make_field(del) = JPARSER::initialised();
761  zap['d'] = make_field(debug) = 2;
762 
763  zap(argc, argv);
764  }
765  catch(const exception &error) {
766  FATAL(error.what() << endl);
767  }
768 
770 
771  try {
772  load(inputFile, detector);
773  }
774  catch(const JException& error) {
775  FATAL(error);
776  }
777 
778 
779  gRandom->SetSeed(0);
780 
781 
782  if ((keep.empty() ? 0 : 1 +
783  rm .empty() ? 0 : 1 +
784  id .empty() ? 0 : 1) > 1) {
785  FATAL("Use either option -k, -r or -m." << endl);
786  }
787 
788 
789  detector.comment.add(JMeta(argc,argv));
790 
791  if (detector.setToLatestVersion()) {
792  NOTICE("Set detector version to " << detector.getVersion() << endl);
793  }
794 
795 
796  if (!hdr.empty()) {
797 
798  int id = -1;
799 
800  JProperties helper = detector.getProperties();
801 
802  helper["id"] = id;
803 
804  for (vector<JToken_t>::const_iterator i = hdr.begin(); i != hdr.end(); ++i) {
805 
806  istringstream is(*i);
807 
808  is >> helper;
809  }
810 
811  if (id != -1) {
812  detector.setID(id);
813  }
814  }
815 
816 
817  for (JDetector::iterator module = detector.begin(); module != detector.end(); ) {
818 
819  bool __rm__ = !keep.empty() && rm.empty();
820 
821  for (vector<JRange_t>::const_iterator i = keep.begin(); i != keep.end(); ++i) {
822  if (module->getString() >= i->first && module->getString() <= i->second) {
823  __rm__ = false;
824  }
825  }
826 
827  for (vector<JRange_t>::const_iterator i = rm.begin(); i != rm.end(); ++i) {
828  if (module->getString() >= i->first && module->getString() <= i->second) {
829  __rm__ = true;
830  }
831  }
832 
833  if (!id.empty()) {
834  __rm__ = find(id.begin(), id.end(), module->getID()) == id.end();
835  }
836 
837  const auto range = del.equal_range(module->getString());
838 
839  for (auto i = range.first; i != range.second; ++i) {
840  if (i->second == module->getFloor()) {
841  __rm__ = true;
842  }
843  }
844 
845  if (__rm__)
846  module = detector.erase(module);
847  else
848  ++module;
849  }
850 
851 
852  for (vector< pair<int, JModifier> >::const_iterator i = mod.begin(); i != mod.end(); ++i) {
853 
854  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
855 
856  if (module->getID() == i->first || i->first == WILDCARD ){
857 
858  if (debug >= debug_t) {
859  print(cout, *module, i->second);
860  }
861 
862  if (!i->second.apply(*module)) {
863  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
864  }
865  }
866  }
867  }
868 
869 
870  for (vector< pair<int, JModifier> >::const_iterator i = str.begin(); i != str.end(); ++i) {
871 
872  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
873 
874  if (module->getString() == i->first || i->first == WILDCARD) {
875 
876  const JModifier modifier = getModifier(module->getString(), i->second);
877 
878  if (debug >= debug_t) {
879  print(cout, *module, i->second);
880  }
881 
882  if (!modifier.apply(*module)) {
883  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
884  }
885  }
886  }
887  }
888 
889 
890  for (vector< pair<int, JModifier> >::const_iterator i = dos.begin(); i != dos.end(); ++i) {
891 
892  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
893 
894  if (module->getFloor() != 0) {
895 
896  if (module->getString() == i->first || i->first == WILDCARD) {
897 
898  const JModifier modifier = getModifier(module->getString(), i->second);
899 
900  if (debug >= debug_t) {
901  print(cout, *module, i->second);
902  }
903 
904  if (!modifier.apply(*module)) {
905  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
906  }
907  }
908  }
909  }
910  }
911 
912 
913  for (vector< pair<JPMTIdentifier, JPMTModifier> >::const_iterator i = pmt.begin(); i != pmt.end(); ++i) {
914 
915  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
916 
917  if (module->getID() == i->first.getModuleID() || i->first.getModuleID() == WILDCARD) {
918 
919  if (debug >= debug_t) {
920  print(cout, i->first, i->second);
921  }
922 
923  if (i->first.getPMTAddress() == WILDCARD) {
924 
925  for (int pmt = 0; pmt != getNumberOfPMTs(*module); ++pmt) {
926  if (!i->second.apply(module->getPMT(pmt))) {
927  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
928  }
929  }
930 
931  } else if (i->first.getPMTAddress() < 0 ||
932  i->first.getPMTAddress() >= getNumberOfPMTs(*module) ||
933  !i->second.apply(module->getPMT(i->first.getPMTAddress()))) {
934  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
935  }
936  }
937  }
938  }
939 
940 
941  if (!alt.empty()) {
942 
943  if (!hasDetectorAddressMap(detector.getID())) {
944  FATAL("Invalid detector identifier " << detector.getID() << endl);
945  }
946 
947  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
948 
949  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
950 
951  const JModuleAddressMap memo = demo.get(module->getID());
952 
953  for (vector< pair<JPMTPhysicalAddress, JPMTModifier> >::const_iterator i = alt.begin(); i != alt.end(); ++i) {
954 
955  const JPMTIdentifier id(module->getID(), memo.getAddressTranslator(i->first).tdc);
956 
957  if (debug >= debug_t) {
958  print(cout, id, i->second);
959  }
960 
961  if (!i->second.apply(module->getPMT(id.getPMTAddress()))) {
962  ERROR("No valid action: " << i->first << ' ' << i->second << endl);
963  }
964  }
965  }
966  }
967 
968 
969  try {
971  }
972  catch(const JException& error) {
973  FATAL(error);
974  }
975 }
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
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
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