Skip to content

Commit

Permalink
Merge branch 'master' into edm4hep-mcp-momentum-double
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch authored Jan 9, 2024
2 parents 492e3bb + ec1b92a commit 0e3b3bf
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
coverity-project: 'AIDASoft%2FDD4hep'
coverity-project-token: ${{ secrets.DD4HEP_COVERITY_TOKEN }}
github-pat: ${{ secrets.READ_COVERITY_IMAGE }}
release-platform: "LCG_102b/x86_64-centos7-gcc11-opt"
release-platform: "LCG_104a/x86_64-el9-gcc13-opt"
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SET_PROPERTY(DIRECTORY . PROPERTY PACKAGE_NAME DD4hep)

SET( DD4hep_VERSION_MAJOR 1 )
SET( DD4hep_VERSION_MINOR 27 )
SET( DD4hep_VERSION_PATCH 1 )
SET( DD4hep_VERSION_PATCH 2 )

#######################
# Basic project setup #
Expand Down
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 */
2 changes: 1 addition & 1 deletion DDG4/include/DDG4/Geant4InputHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace dd4hep {
Geant4Particle* createPrimary(int particle_id, const Geant4Vertex* v, const G4PrimaryParticle* g4p);

/// Create a DDG4 interaction record from a Geant4 interaction defined by a primary vertex
Geant4PrimaryInteraction* createPrimary(int mask, Geant4PrimaryMap* pm, const G4PrimaryVertex* gv);
Geant4PrimaryInteraction* createPrimary(int mask, Geant4PrimaryMap* pm, std::set<G4PrimaryVertex*>const& primaries);

/// Initialize the generation of one event
int generationInitialization(const Geant4Action* caller,const Geant4Context* context);
Expand Down
16 changes: 6 additions & 10 deletions DDG4/src/Geant4GeneratorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,14 @@ void Geant4GeneratorWrapper::operator()(G4Event* event) {
Geant4PrimaryMap* primaryMap = context()->event().extension<Geant4PrimaryMap>();
set<G4PrimaryVertex*> primaries;

// Now generate the new interaction
generator()->GeneratePrimaryVertex(event);

/// Collect all existing interactions (primary vertices)
for(G4PrimaryVertex* v=event->GetPrimaryVertex(); v; v=v->GetNext())
primaries.insert(v);

// Now generate the new interaction
generator()->GeneratePrimaryVertex(event);

/// Add all the missing interactions (primary vertices) to the primary event record.
for(G4PrimaryVertex* gv=event->GetPrimaryVertex(); gv; gv=gv->GetNext()) {
if ( primaries.find(gv) == primaries.end() ) {
Geant4PrimaryInteraction* inter = createPrimary(m_mask, primaryMap, gv);
prim->add(m_mask, inter);
}
}
// Add all the missing interactions (primary vertices) to the primary event record.
Geant4PrimaryInteraction* inter = createPrimary(m_mask, primaryMap, primaries);
prim->add(m_mask, inter);
}
30 changes: 18 additions & 12 deletions DDG4/src/Geant4InputHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ static void collectPrimaries(Geant4PrimaryMap* pm,
Geant4Vertex* particle_origine,
G4PrimaryParticle* gp)
{
//if the particle is in the map, we do not have to do anything
if ( pm->get(gp) ) {
return;
}

int pid = int(interaction->particles.size());
Geant4Particle* p = createPrimary(pid,particle_origine,gp);
G4PrimaryParticle* dau = gp->GetDaughter();
Expand All @@ -103,14 +108,13 @@ static void collectPrimaries(Geant4PrimaryMap* pm,

if ( dau ) {
Geant4Vertex* dv = new Geant4Vertex(*particle_origine);
int vid = int(interaction->vertices.size());
PropertyMask reason(p->reason);
reason.set(G4PARTICLE_HAS_SECONDARIES);

dv->mask = mask;
dv->in.insert(p->id);

interaction->vertices[vid].emplace_back(dv) ;
interaction->vertices[mask].emplace_back(dv) ;

for(; dau; dau = dau->GetNext())
collectPrimaries(pm, interaction, dv, dau);
Expand All @@ -121,18 +125,19 @@ static void collectPrimaries(Geant4PrimaryMap* pm,
Geant4PrimaryInteraction*
dd4hep::sim::createPrimary(int mask,
Geant4PrimaryMap* pm,
const G4PrimaryVertex* gv)
std::set<G4PrimaryVertex*>const& primaries)
{
Geant4PrimaryInteraction* interaction = new Geant4PrimaryInteraction();
Geant4Vertex* v = createPrimary(gv);
int vid = int(interaction->vertices.size());
interaction->locked = true;
interaction->mask = mask;
v->mask = mask;
interaction->vertices[vid].emplace_back(v);

for (G4PrimaryParticle *gp = gv->GetPrimary(); gp; gp = gp->GetNext() )
collectPrimaries(pm, interaction, v, gp);
for (auto const& gv: primaries) {
Geant4Vertex* v = createPrimary(gv);
v->mask = mask;
interaction->vertices[mask].emplace_back(v);
for (G4PrimaryParticle *gp = gv->GetPrimary(); gp; gp = gp->GetNext()) {
collectPrimaries(pm, interaction, v, gp);
}
}
return interaction;
}

Expand Down Expand Up @@ -180,13 +185,14 @@ static void appendInteraction(const Geant4Action* caller,
}
Geant4PrimaryInteraction::VertexMap::iterator ivfnd, iv, ivend;
for( iv=input->vertices.begin(), ivend=input->vertices.end(); iv != ivend; ++iv ) {
ivfnd = output->vertices.find((*iv).first) ; //(*iv).second->mask);
int theMask = input->mask;
ivfnd = output->vertices.find(theMask);
if ( ivfnd != output->vertices.end() ) {
caller->abortRun("Duplicate primary interaction identifier!",
"Cannot handle 2 interactions with identical identifiers!");
}
for(Geant4Vertex* vtx : (*iv).second )
output->vertices[(*iv).first].emplace_back( vtx->addRef() );
output->vertices[theMask].emplace_back( vtx->addRef() );
}
}

Expand Down
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

0 comments on commit 0e3b3bf

Please sign in to comment.