File indexing completed on 2025-01-18 09:15:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <TError.h>
0021 #include <TInterpreter.h>
0022
0023
0024 #include <DD4hep/Detector.h>
0025 #include <DD4hep/Printout.h>
0026 #include <DD4hep/DD4hepUnits.h>
0027 #include <DDRec/MaterialScan.h>
0028 #include "main.h"
0029
0030 using namespace dd4hep;
0031 using namespace dd4hep::rec;
0032
0033 int main_wrapper(int argc, char** argv) {
0034 struct Handler {
0035 Handler() { SetErrorHandler(Handler::print); }
0036 static void print(int level, Bool_t abort, const char *location, const char *msg) {
0037 if ( level > kInfo || abort ) ::printf("%s: %s\n", location, msg);
0038 }
0039 static void usage() {
0040 std::cout << " usage: materialScan compact.xml x0 y0 z0 x1 y1 z1 [-interactive]" << std::endl
0041 << " or: materialScan compact.xml -interactive" << std::endl
0042 << " -> prints the materials on a straight line between the two given points (unit is cm) " << std::endl
0043 << " -interactive Load geometry once, then allow for shots from the ROOT prompt" << std::endl
0044 << " NOTE: ALL lengths in units of [cm]"
0045 << std::endl;
0046 exit(EINVAL);
0047 }
0048 } _handler;
0049
0050 bool do_scan = true, interactive = false;
0051 double x0, y0, z0, x1, y1, z1;
0052
0053 if( argc == 3 && ::strncmp(argv[2],"-interactive",5) == 0 ) {
0054 interactive = true;
0055 do_scan = false;
0056 }
0057 else if ( argc == 9 && ::strncmp(argv[8],"-interactive",5) == 0 ) {
0058 interactive = true;
0059 do_scan = true;
0060 }
0061 else if ( argc < 8 ) {
0062 Handler::usage();
0063 }
0064
0065 std::string inFile = argv[1];
0066 if ( do_scan ) {
0067 std::stringstream sstr;
0068 sstr << argv[2] << " " << argv[3] << " " << argv[4] << " "
0069 << argv[5] << " " << argv[6] << " " << argv[7] << " " << "NONE";
0070 sstr >> x0 >> y0 >> z0 >> x1 >> y1 >> z1;
0071 if ( !sstr.good() ) Handler::usage();
0072 }
0073 setPrintLevel(WARNING);
0074 Detector& description = Detector::getInstance();
0075 description.fromXML(inFile);
0076 MaterialScan scan(description);
0077 if ( do_scan ) {
0078 scan.print(x0*dd4hep::cm, y0*dd4hep::cm, z0*dd4hep::cm, x1*dd4hep::cm, y1*dd4hep::cm, z1*dd4hep::cm);
0079 }
0080 if ( interactive ) {
0081 char cmd[256];
0082 description.apply("DD4hep_InteractiveUI",0,0);
0083 ::snprintf(cmd,sizeof(cmd),
0084 "dd4hep::rec::MaterialScan* gMaterialScan = "
0085 "(dd4hep::rec::MaterialScan*)%p",(void*)&scan);
0086 gInterpreter->ProcessLine(cmd);
0087 printout(ALWAYS,"materialScan","Use the ROOT interpreter variable "
0088 "\"dd4hep::rec::MaterialScan* gMaterialScan\" to interact "
0089 "with the material scanner");
0090 gInterpreter->ProcessLine(".class dd4hep::rec::MaterialScan");
0091 description.apply("DD4hep_Rint",0,0);
0092 }
0093 return 0;
0094 }