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

Add basic geometrical accessors to shapes. #697

Merged
merged 13 commits into from
Sep 4, 2020

Conversation

MarkusFrankATcernch
Copy link
Contributor

@MarkusFrankATcernch MarkusFrankATcernch commented Aug 20, 2020

BEGINRELEASENOTES

ENDRELEASENOTES

Copy link
Contributor

@ianna ianna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkusFrankATcernch - thanks for taking care of it! Just a few points:

  • I think, we should avoid the unit conversions. We ought to leave it to a user IMHO.
  • I do not care much if the API is close to G4 or ROOT as long as it is well documented.
  • Also, I cannot tell if CMS IB checks will be happy with using size_t in place of int which is the most commonly used type. Perhaps, you could try to run clang-tidy with a narrowing conversion check?
    Thanks!

@@ -829,6 +945,27 @@ namespace dd4hep {
Trap& setDimensions(double z, double theta, double phi,
double h1, double bl1, double tl1, double alpha1,
double h2, double bl2, double tl2, double alpha2);

/// Accessor: phi value
double phi() const { return access()->GetPhi()*dd4hep::deg; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkusFrankATcernch - IMHO we need to avoid double conversion, e.g. converting everything to radians (e.g. G4 definition) and then back to degrees (e.g. ROOT definition). We will definitely see some precision loss.

@@ -1271,6 +1471,27 @@ namespace dd4hep {
PolyhedraRegular& operator=(PolyhedraRegular&& copy) = default;
/// Copy Assignment operator
PolyhedraRegular& operator=(const PolyhedraRegular& copy) = default;

/// Accessor: Number of edges
size_t numEdge() const { return access()->GetNedges(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are converting signed to an unsigned here. I'd add an s:

int numEdges() const

double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; }

/// Accessor: r-min value
double z(size_t which) const { return access()->GetZ(which); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it should be int

@MarkusFrankATcernch
Copy link
Contributor Author

@ianna

  • size_t --> int OK taken into account.
  • degree-> radians. We sort of have to stay consistent. The constructors also take radians. I would prefer to do the conversion.

More importantly:
Should we check if the object is valid ? This probably really costs. Using ptr()-> instead of access()-> is much cheaper, but also causes SEGV if the object is invalid. The optimizer actually directly leaves code as if the raw pointer is used.

@ianna
Copy link
Contributor

ianna commented Aug 20, 2020

@ianna

  • size_t --> int OK taken into account.
  • degree-> radians. We sort of have to stay consistent. The constructors also take radians. I would prefer to do the conversion.

More importantly:
Should we check if the object is valid ? This probably really costs. Using ptr()-> instead of access()-> is much cheaper, but also causes SEGV if the object is invalid. The optimizer actually directly leaves code as if the raw pointer is used.

I'd leave the optimisation for later. Most of the CMSSW code uses a dimensions vector any way...

@cvuosalo
Copy link

The standard has been that DD4hep returns angles as radians. Let's keep that convention.

Copy link
Member

@andresailer andresailer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly comments for the docstrings

/// Accessor: delta-phi value
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; }

/// Accessor: r-min value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Accessor: r-min value
/// Accessor: z value

template <typename SOLID> std::vector<double> _extract_vector(const SOLID* solid,
double (SOLID::*extract)(Int_t) const,
Int_t (SOLID::*len)() const) {
std::vector<double> result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reserve the size (count)


/// Accessor: delta-z value
double dZ() const { return access()->GetDz(); }
/// Accessor: r-min value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Accessor: r-min value
/// Accessor: a value

double dZ() const { return access()->GetDz(); }
/// Accessor: r-min value
double a() const { return access()->GetA(); }
/// Accessor: r-max value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Accessor: r-max value
/// Accessor: b value

/// Accessor: delta-phi value
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; }

/// Accessor: r-min value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this is, but different than r-min

/// Accessor: delta-phi value
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; }

/// Accessor: r-min value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Accessor: r-min value
/// Accessor: z value

/// Accessor: delta-phi value
double deltaPhi() const { return access()->GetDphi()*dd4hep::deg; }

/// Accessor: r-min value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Accessor: r-min value
/// Accessor: z value

const double* values = access()->GetVertices();
return detail::_make_vector(values, 8*2);
}
/// Accessor: singlke vertex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Accessor: singlke vertex
/// Accessor: single vertex

@cvuosalo
Copy link

Concerning TruncatedTube, "The construction parameters of the TruncatedTube are stored as a string in the object's title" Since the parameters are stored, could you please provide named accessor methods that return each of the construction parameters?

double phi() const { return access()->GetPhi()*dd4hep::deg; }
/// Accessor: theta value
double theta() const { return access()->GetTheta()*dd4hep::deg; }
/// Angle between centers of x edges an y axis at low z

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Angle between centers of x edges an y axis at low z
/// Angle between centers of x edges and y axis at low z

double theta() const { return access()->GetTheta()*dd4hep::deg; }
/// Angle between centers of x edges an y axis at low z
double alpha1() const { return access()->GetAlpha1()*dd4hep::deg; }
/// Angle between centers of x edges an y axis at low z

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Angle between centers of x edges an y axis at low z
/// Angle between centers of x edges and y axis at high z

@ianna
Copy link
Contributor

ianna commented Aug 28, 2020

@MarkusFrankATcernch - I think, you could introduce a nested namespace for units, for example dd4hep::units::m

[119/607] Building CXX object DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o
1232FAILED: DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o 
1233/cvmfs/sft.cern.ch/lcg/releases/clang/8.0.0-ed577/x86_64-centos7/bin/clang++  -DBOOST_SPIRIT_USE_PHOENIX_V3 -DDD4HEP_USE_TINYXML -DDDCore_EXPORTS -I../DDCore/include -I../DDParsers/include -ftls-model=global-dynamic -Wheader-hygiene -Wno-c++1z-extensions -Winconsistent-missing-override -fdiagnostics-color=auto -Wshadow -Wdeprecated -Wno-long-long -Wformat-security -Wshadow -pedantic -Wextra -Wall -fdiagnostics-color=always -Werror              -pthread -O3 -DNDEBUG -fPIC   -std=c++17 -MD -MT DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o -MF DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o.d -o DDCore/CMakeFiles/DDCore.dir/src/Conditions.cpp.o -c ../DDCore/src/Conditions.cpp
1234../DDCore/src/Conditions.cpp:177:23: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1235  const BasicGrammar* g = access()->data.grammar;
1236                      ^
1237../DDParsers/include/Evaluator/DD4hepUnits.h:191:29: note: previous declaration is here
1238    static constexpr double g = gram;
1239                            ^
1240../DDCore/src/Conditions.cpp:193:12: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1241  KeyMaker m(detector.key(), detail::hash32(value));
1242           ^
1243../DDParsers/include/Evaluator/DD4hepUnits.h:98:29: note: previous declaration is here
1244    static constexpr double m = meter;
1245                            ^
1246../DDCore/src/Conditions.cpp:199:12: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1247  KeyMaker m(detector.key(), item_key);
1248           ^
1249../DDParsers/include/Evaluator/DD4hepUnits.h:98:29: note: previous declaration is here
1250    static constexpr double m = meter;
1251                            ^
1252../DDCore/src/Conditions.cpp:205:12: error: declaration shadows a variable in namespace 'dd4hep' [-Werror,-Wshadow]
1253  KeyMaker m(det, detail::hash32(value));
1254           ^
1255../DDParsers/include/Evaluator/DD4hepUnits.h:98:29: note: previous declaration is here
1256    static constexpr double m = meter;
1257                            ^
12584 errors generated.
1259[121/607] Building CXX object DDCore/C...s/DDCore.dir/src/ConditionsDebug.cpp.o
1260ninja: build stopped: subcommand failed.
1261The command "if [[ "$PYTHON_CHECK" == "yes" ]]; then docker exec -ti CI_container /bin/bash -c "./DD4hep/.dd4hep-ci.d/runPythonChecks.sh"; else docker exec -ti CI_container /bin/bash -c "./DD4hep/.dd4hep-ci.d/compile_and_test.sh"; fi" exited with 1.
1262
1263
1264Done. Your build exited with 1.

@cvuosalo
Copy link

@MarkusFrankATcernch Thanks for the additions. This pull request will be very helpful for us in CMS.

@MarkusFrankATcernch
Copy link
Contributor Author

@cvuosalo Yes, but we first have to discuss in the dd4hep meeting the issue of putting the units into a separate namespace - ideally in a user-transparent way.

@@ -36,7 +36,7 @@ endmacro(dd4hep_to_parent_scope)
macro(dd4hep_set_compiler_flags)
include(CheckCXXCompilerFlag)

SET(COMPILER_FLAGS -Wall -Wextra -pedantic -Wshadow -Wformat-security -Wno-long-long -Wdeprecated -fdiagnostics-color=auto)
SET(COMPILER_FLAGS -Wshadow -Wformat-security -Wno-long-long -Wdeprecated -fdiagnostics-color=auto -Wall -Wextra -pedantic)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this re-shuffling change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently nothing. I had the suspicion that -Wall or -Wextra after -Wshadow disables -Wshadow.
Note that the real order when compiling is inverted.
Net result is that -Wshadow does not work at all for gcc. Only for clang.

@MarkusFrankATcernch MarkusFrankATcernch removed the request for review from gaede September 4, 2020 08:42
@MarkusFrankATcernch MarkusFrankATcernch merged commit 8ecaf54 into AIDASoft:master Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants