Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix teveDisplay: restore behaviour (issue https://github.com/AIDASoft/DD4hep/issues/1208) #1209

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions DDCore/src/segmentations/CartesianGridXY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ CartesianGridXY::CartesianGridXY(const std::string& cellEncoding) :
_description = "Cartesian segmentation in the local XY-plane";

// register all necessary parameters
registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
}
Expand All @@ -35,10 +35,10 @@ CartesianGridXY::CartesianGridXY(const BitFieldCoder* decode) :
_description = "Cartesian segmentation in the local XY-plane";

// register all necessary parameters
registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
registerParameter("grid_size_x", "Cell size in X", _gridSizeX, 1., SegmentationParameter::LengthUnit);
registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
}
Expand All @@ -57,14 +57,16 @@ Vector3D CartesianGridXY::position(const CellID& cID) const {
}

/// determine the cell ID based on the position
CellID CartesianGridXY::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
CellID cID = vID ;
CellID CartesianGridXY::cellID(const Vector3D& localPosition,
const Vector3D& /* globalPosition */,
const VolumeID& vID) const {
CellID cID = vID;
_decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX) );
_decoder->set( cID,_yId, positionToBin(localPosition.Y, _gridSizeY, _offsetY) );
return cID ;
return cID;
}

std::vector<double> CartesianGridXY::cellDimensions(const CellID&) const {
std::vector<double> CartesianGridXY::cellDimensions(const CellID& /* cellID */) const {
#if __cplusplus >= 201103L
return {_gridSizeX, _gridSizeY};
#else
Expand Down
41 changes: 21 additions & 20 deletions DDCore/src/segmentations/CartesianGridXYStaggered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace dd4hep {
namespace DDSegmentation {

/// default constructor using an encoding string
CartesianGridXYStaggered::CartesianGridXYStaggered(const std::string& cellEncoding) :
CartesianGrid(cellEncoding) {
CartesianGridXYStaggered::CartesianGridXYStaggered(const std::string& cellEncoding)
: CartesianGrid(cellEncoding)
{
// define type and description
_type = "CartesianGridXYStaggered";
_description = "Cartesian segmentation in the local XY-plane, with options for staggering";
Expand All @@ -22,14 +23,14 @@ CartesianGridXYStaggered::CartesianGridXYStaggered(const std::string& cellEncodi
registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
registerParameter("stagger_x", "Option to stagger the layers in x (ie, add grid_size_x/2 to offset_x for odd layers)", _staggerX, 0,
SegmentationParameter::NoUnit, true);
registerParameter("stagger_y", "Option to stagger the layers in y (ie, add grid_size_y/2 to offset_y for odd layers)", _staggerY, 0,
SegmentationParameter::NoUnit, true);
registerParameter("stagger_x", "Option to stagger the layers in x (ie, add grid_size_x/2 to offset_x for odd layers)",
_staggerX, 0, SegmentationParameter::NoUnit, true);
registerParameter("stagger_y", "Option to stagger the layers in y (ie, add grid_size_y/2 to offset_y for odd layers)",
_staggerY, 0, SegmentationParameter::NoUnit, true);
registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
registerParameter("stagger_keyword", "Volume ID identifier used for determining which volumes to stagger", _staggerKeyword, (std::string)"layer",
SegmentationParameter::NoUnit, true);
registerParameter("stagger_keyword", "Volume ID identifier used for determining which volumes to stagger",
_staggerKeyword, (std::string)"layer", SegmentationParameter::NoUnit, true);
}

/// Default constructor used by derived classes passing an existing decoder
Expand All @@ -45,14 +46,14 @@ CartesianGridXYStaggered::CartesianGridXYStaggered(const BitFieldCoder* decode)
registerParameter("grid_size_y", "Cell size in Y", _gridSizeY, 1., SegmentationParameter::LengthUnit);
registerParameter("offset_x", "Cell offset in X", _offsetX, 0., SegmentationParameter::LengthUnit, true);
registerParameter("offset_y", "Cell offset in Y", _offsetY, 0., SegmentationParameter::LengthUnit, true);
registerParameter("stagger_x", "Option to stagger the layers in x (ie, add grid_size_x/2 to offset_x for odd layers)", _staggerX, 0,
SegmentationParameter::NoUnit, true);
registerParameter("stagger_y", "Option to stagger the layers in y (ie, add grid_size_y/2 to offset_y for odd layers)", _staggerY, 0,
SegmentationParameter::NoUnit, true);
registerParameter("stagger_x", "Option to stagger the layers in x (ie, add grid_size_x/2 to offset_x for odd layers)",
_staggerX, 0, SegmentationParameter::NoUnit, true);
registerParameter("stagger_y", "Option to stagger the layers in y (ie, add grid_size_y/2 to offset_y for odd layers)",
_staggerY, 0, SegmentationParameter::NoUnit, true);
registerIdentifier("identifier_x", "Cell ID identifier for X", _xId, "x");
registerIdentifier("identifier_y", "Cell ID identifier for Y", _yId, "y");
registerParameter("stagger_keyword", "Volume ID identifier used for determining which volumes to stagger", _staggerKeyword, (std::string)"layer",
SegmentationParameter::NoUnit, true);
registerParameter("stagger_keyword", "Volume ID identifier used for determining which volumes to stagger",
_staggerKeyword, (std::string)"layer", SegmentationParameter::NoUnit, true);
}

/// destructor
Expand All @@ -73,10 +74,12 @@ Vector3D CartesianGridXYStaggered::position(const CellID& cID) const {
}
return cellPosition;
}

/// determine the cell ID based on the position
CellID CartesianGridXYStaggered::cellID(const Vector3D& localPosition, const Vector3D& /* globalPosition */, const VolumeID& vID) const {
CellID cID = vID ;
CellID CartesianGridXYStaggered::cellID(const Vector3D& localPosition,
const Vector3D& /* globalPosition */,
const VolumeID& vID) const {
CellID cID = vID ;
if (_staggerX || _staggerY){
int layer= _decoder->get(cID,_staggerKeyword);
_decoder->set( cID,_xId, positionToBin(localPosition.X, _gridSizeX, _offsetX+_staggerX*_gridSizeX*(layer%2)/2) );
Expand All @@ -88,11 +91,9 @@ Vector3D CartesianGridXYStaggered::position(const CellID& cID) const {
return cID ;
}


std::vector<double> CartesianGridXYStaggered::cellDimensions(const CellID& cellID) const {
std::vector<double> CartesianGridXYStaggered::cellDimensions(const CellID& /* cellID */) const {
return {_gridSizeX, _gridSizeY};
}


} /* namespace DDSegmentation */
} /* namespace dd4hep */
7 changes: 3 additions & 4 deletions UtilityApps/src/run_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,15 @@ namespace dd4hep {
return 0;
}

void usage_plugin_runner() {
std::cout <<
"geoPluginRun -opt [-opt] \n"
void usage_plugin_runner(const char* runner="geoPluginRun", bool exit_program=true) {
std::cout << runner << " -opt [-opt] \n"
" -input <file> [OPTIONAL] Specify geometry input file. \n"
" -plugin <name> <args> [args] [-end-plugin] \n"
" [REQUIRED] Plugin to be executed and applied. \n"
" -plugin <name> <args> [args] -end-plugin \n"
" [OPTIONAL] Next plugin with arguments. \n";
print_default_args() << std::endl;
::exit(EINVAL);
if ( exit_program ) ::exit(EINVAL);
}

//______________________________________________________________________________
Expand Down
61 changes: 37 additions & 24 deletions UtilityApps/src/teve_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,30 @@ void make_gui();
TEveStraightLineSet* getSurfaces(int col=kRed, const SurfaceType& type=SurfaceType(), TString name="Surfaces" ) ;
TEveStraightLineSet* getSurfaceVectors(bool addO=true, bool addU= true, bool addV=true, bool addN=true,TString name="SurfaceVectors",int color=kGreen) ;

//=====================================================================================
static void print_teve_help() {
std::cout <<
"Usage: teveDisplay -arg [-arg] \n\n"
" Invoke TEve display using the factory mechanism. \n\n"
" -input <file> [OPTIONAL] Specify geometry input file. \n";
print_default_args() << std::endl <<
" -level <number> Visualization level [TGeoManager::SetVisLevel] Default: 4 \n"
" -visopt <number> Visualization option [TGeoManager::SetVisOption] Default: 0 \n"
" -help Print this help output" << std::endl << std::flush;
::exit(EINVAL);
}

//=====================================================================================

static long teve_display(Detector& description, int argc, char** argv) {
int level = 4, visopt = 0, help = 0;

for( int i=0; i<argc; ++i ) {
if ( strncmp(argv[i],"-visopt",4) == 0 ) visopt = ::atol(argv[++i]);
else if ( strncmp(argv[i],"-level", 4) == 0 ) level = ::atol(argv[++i]);
else help = 1;
}
if ( help ) {
std::cout <<
"Usage: teveDisplay -arg [-arg] \n\n"
" Invoke TEve display using the factory mechanism. \n\n"
" -level <number> Visualization level [TGeoManager::SetVisLevel] Default: 4 \n"
" -visopt <number> Visualization option [TGeoManager::SetVisOption] Default: 0 \n"
" -help Print this help output" << std::endl << std::flush;
::exit(EINVAL);
print_teve_help();
}

TGeoManager* mgr = &description.manager();
Expand Down Expand Up @@ -149,20 +155,27 @@ static long teve_display(Detector& description, int argc, char** argv) {
}
DECLARE_APPLY(DD4hepTEveDisplay,teve_display)


//=====================================================================================================================

int main(int argc,char** argv) {
std::vector<const char*> av;
std::string level, visopt, opt;
bool help = false;
for( int i=0; i<argc; ++i ) {
if ( i==1 && argv[i][0] != '-' ) av.emplace_back("-input");
else if ( strncmp(argv[i],"-help",4) == 0 ) help = true, av.emplace_back(argv[i]);
else if ( strncmp(argv[i],"-visopt",4) == 0 ) visopt = argv[++i];
else if ( strncmp(argv[i],"-level", 4) == 0 ) level = argv[++i];
else if ( strncmp(argv[i],"-option",4) == 0 ) opt = argv[++i];
else av.emplace_back(argv[i]);
bool help = (argc == 1);

for( int i=0; i < argc; ++i ) {
if ( i == 1 && argv[i][0] != '-' ) av.emplace_back("-input");
else if ( strncmp(argv[i],"-help", 4) == 0 ) help = true;
else if ( strncmp(argv[i],"--help", 5) == 0 ) help = true;
else if ( strncmp(argv[i],"-visopt", 4) == 0 ) visopt = argv[++i];
else if ( strncmp(argv[i],"--visopt",5) == 0 ) visopt = argv[++i];
else if ( strncmp(argv[i],"-level", 4) == 0 ) level = argv[++i];
else if ( strncmp(argv[i],"--level", 5) == 0 ) level = argv[++i];
else if ( strncmp(argv[i],"-option", 4) == 0 ) opt = argv[++i];
else if ( strncmp(argv[i],"--option",5) == 0 ) opt = argv[++i];
else if ( argc > 2 ) av.emplace_back(argv[i]);
}
if ( !help && argc == 2 ) { // Single argument given --> geometry file
av.emplace_back("-input");
av.emplace_back(argv[1]);
}
av.emplace_back("-interactive");
av.emplace_back("-plugin");
Expand All @@ -171,22 +184,22 @@ int main(int argc,char** argv) {
if ( !opt.empty() ) av.emplace_back("-opt"), av.emplace_back(opt.c_str());
if ( !level.empty() ) av.emplace_back("-level"), av.emplace_back(level.c_str());
if ( !visopt.empty() ) av.emplace_back("-visopt"), av.emplace_back(visopt.c_str());
if ( help ) {
print_teve_help();
}
return dd4hep::execute::main_plugins("DD4hepTEveDisplay", av.size(), (char**)&av[0]);
}

//=====================================================================================================================
TEveStraightLineSet* getSurfaceVectors(bool addO, bool addU, bool addV, bool addN, TString name,int color) {
TEveStraightLineSet* getSurfaceVectors(bool addO, bool addU, bool addV, bool addN, TString name,int color) {
TEveStraightLineSet* ls = new TEveStraightLineSet(name);
Detector& description = Detector::getInstance();
DetElement world = description.world() ;
DetElement world = description.world();

// create a list of all surfaces in the detector:
SurfaceHelper surfMan( world ) ;

SurfaceHelper surfMan( world );
const SurfaceList& sL = surfMan.surfaceList() ;

for( SurfaceList::const_iterator it = sL.begin() ; it != sL.end() ; ++it ){

ISurface* surf = *it ;
const Vector3D& u = surf->u() ;
const Vector3D& v = surf->v() ;
Expand Down
Loading