DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
materialScan.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 //==========================================================================
11 //
12 // Simple program to print all the materials in a detector on
13 // a straight line between two given points
14 //
15 // Author : F.Gaede, DESY
16 // Author : M.Frank, CERN
17 //
18 //==========================================================================
19 
20 #include <TError.h>
21 #include <TInterpreter.h>
22 
23 // Framework include files
24 #include <DD4hep/Detector.h>
25 #include <DD4hep/Printout.h>
26 #include <DD4hep/DD4hepUnits.h>
27 #include <DDRec/MaterialScan.h>
28 #include "main.h"
29 
30 using namespace dd4hep;
31 using namespace dd4hep::rec;
32 
33 int main_wrapper(int argc, char** argv) {
34  struct Handler {
35  Handler() { SetErrorHandler(Handler::print); }
36  static void print(int level, Bool_t abort, const char *location, const char *msg) {
37  if ( level > kInfo || abort ) ::printf("%s: %s\n", location, msg);
38  }
39  static void usage() {
40  std::cout << " usage: materialScan compact.xml x0 y0 z0 x1 y1 z1 [-interactive]" << std::endl
41  << " or: materialScan compact.xml -interactive" << std::endl
42  << " -> prints the materials on a straight line between the two given points (unit is cm) " << std::endl
43  << " -interactive Load geometry once, then allow for shots from the ROOT prompt" << std::endl
44  << " NOTE: ALL lengths in units of [cm]"
45  << std::endl;
46  exit(EINVAL);
47  }
48  } _handler;
49 
50  bool do_scan = true, interactive = false;
51  double x0, y0, z0, x1, y1, z1;
52 
53  if( argc == 3 && ::strncmp(argv[2],"-interactive",5) == 0 ) {
54  interactive = true;
55  do_scan = false;
56  }
57  else if ( argc == 9 && ::strncmp(argv[8],"-interactive",5) == 0 ) {
58  interactive = true;
59  do_scan = true;
60  }
61  else if ( argc < 8 ) {
63  }
64 
65  std::string inFile = argv[1];
66  if ( do_scan ) {
67  std::stringstream sstr;
68  sstr << argv[2] << " " << argv[3] << " " << argv[4] << " "
69  << argv[5] << " " << argv[6] << " " << argv[7] << " " << "NONE";
70  sstr >> x0 >> y0 >> z0 >> x1 >> y1 >> z1;
71  if ( !sstr.good() ) Handler::usage();
72  }
73  setPrintLevel(WARNING);
74  Detector& description = Detector::getInstance();
75  description.fromXML(inFile);
76  MaterialScan scan(description);
77  if ( do_scan ) {
78  scan.print(x0*dd4hep::cm, y0*dd4hep::cm, z0*dd4hep::cm, x1*dd4hep::cm, y1*dd4hep::cm, z1*dd4hep::cm);
79  }
80  if ( interactive ) {
81  char cmd[256];
82  description.apply("DD4hep_InteractiveUI",0,0);
83  ::snprintf(cmd,sizeof(cmd),
84  "dd4hep::rec::MaterialScan* gMaterialScan = "
85  "(dd4hep::rec::MaterialScan*)%p",(void*)&scan);
86  gInterpreter->ProcessLine(cmd);
87  printout(ALWAYS,"materialScan","Use the ROOT interpreter variable "
88  "\"dd4hep::rec::MaterialScan* gMaterialScan\" to interact "
89  "with the material scanner");
90  gInterpreter->ProcessLine(".class dd4hep::rec::MaterialScan");
91  description.apply("DD4hep_Rint",0,0);
92  }
93  return 0;
94 }
dd4hep::rec
Namespace for the reconstruction part of the AIDA detector description toolkit.
Definition: SurfaceInstaller.h:28
Detector.h
dd4hep::Detector::getInstance
static Detector & getInstance(const std::string &name="default")
—Factory method----—
Definition: DetectorImp.cpp:150
dd4hep::Detector::apply
virtual long apply(const char *factory, int argc, char **argv) const =0
Manipulate geometry using factory converter.
main_wrapper
int main_wrapper(int argc, char **argv)
Definition: materialScan.cpp:33
dd4hep::rec::MaterialScan::print
void print(const Vector3D &start, const Vector3D &end, double epsilon=1e-4) const
Scan along a line and print the materials traversed.
Definition: MaterialScan.cpp:177
MaterialScan.h
main.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector::fromXML
virtual void fromXML(const std::string &fname, DetectorBuildType type=BUILD_DEFAULT)=0
Read any geometry description or alignment file.
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
usage
void usage(std::string argv0)
Definition: listcomponents.cpp:41
DD4hepUnits.h
dd4hep::rec::MaterialScan
Class to perform material scans along a straight line.
Definition: MaterialScan.h:52
Printout.h