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

Update dd4hep material scan to be unit-aware #1213

Merged
merged 3 commits into from
Jan 15, 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
7 changes: 4 additions & 3 deletions DDCore/src/plugins/GeometryWalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,20 @@ void GeometryWalk::walk(DetElement e, PlacedVolume::VolIDs ids) const {
/// Action routine to execute the test
long GeometryWalk::run(Detector& description,int argc,char** argv) {
cout << "++ Processing plugin....GeometryWalker.." << endl;
DetElement world = description.world();
for(int in=1; in < argc; ++in) {
string name = argv[in]+1;
if ( name == "all" || name == "All" || name == "ALL" ) {
const _C& children = description.world().children();
const _C& children = world.children();
for (_C::const_iterator i=children.begin(); i!=children.end(); ++i) {
DetElement sdet = (*i).second;
cout << "++ Processing subdetector: " << sdet.name() << endl;
GeometryWalk test(description,sdet);
GeometryWalk test(description, sdet);
}
return 1;
}
cout << "++ Processing subdetector: " << name << endl;
GeometryWalk test(description,description.detector(name));
GeometryWalk test(description, description.detector(name));
}
return 1;
}
Expand Down
3 changes: 2 additions & 1 deletion DDDetectors/src/PolyhedraEndcapCalorimeter2_surfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVo
}
else if ( !handleUsingCache(component,comp_vol) ) {
dd4hep::DetElement par = component.parent();
const TGeoHMatrix& m = par.nominal().worldTransformation();
dd4hep::Alignment nom = par.nominal();
const TGeoHMatrix& m = nom.worldTransformation();
double dz = m.GetTranslation()[2];
const double* trans = placementTranslation(component);
double half_mod_thickness = (mod_shape->GetZ(1)-mod_shape->GetZ(0))/2.0;
Expand Down
10 changes: 6 additions & 4 deletions DDDigi/src/DigiSegmentationTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ namespace {
const string& split_by,
map<dd4hep::VolumeID, pair<dd4hep::DetElement, dd4hep::VolumeID> >& splits,
dd4hep::DetElement de, dd4hep::VolumeID vid, dd4hep::VolumeID mask) {
const auto& new_ids = de.placement().volIDs();
dd4hep::VolumeID new_vid = vid;
dd4hep::VolumeID new_msk = mask;
dd4hep::PlacedVolume plc = de.placement();
const auto& new_ids = plc.volIDs();
dd4hep::VolumeID new_vid = vid;
dd4hep::VolumeID new_msk = mask;
if ( !new_ids.empty() ) {
new_vid |= tool.iddescriptor.encode(new_ids);
new_msk |= tool.iddescriptor.get_mask(new_ids);
Expand Down Expand Up @@ -185,7 +186,8 @@ DigiSegmentationTool::split_context(const string& split_by) const {
/// Create full set of detector segments which can be split according to the context
set<uint32_t> DigiSegmentationTool::split_segmentation(const string& split_by) const {
map<VolumeID, pair<DetElement, VolumeID> > segmentation_splits;
const auto& ids = this->detector.placement().volIDs();
PlacedVolume place = this->detector.placement();
const auto& ids = place.volIDs();
VolumeID vid = this->iddescriptor.encode(ids);
VolumeID msk = this->iddescriptor.get_mask(ids);
const auto* fld = this->iddescriptor.field(split_by);
Expand Down
6 changes: 4 additions & 2 deletions DDDigi/src/noise/DigiSubdetectorSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void DigiSubdetectorSequence::initialize() {
if ( m_detector.isValid() && m_sensDet.isValid() ) {
m_idDesc = m_sensDet.readout().idSpec();
m_segmentation = m_sensDet.readout().segmentation();
const VolIDs& ids = m_detector.placement().volIDs();
PlacedVolume plc = m_detector.placement();
const VolIDs& ids = plc.volIDs();
VolumeID vid = m_idDesc.encode(ids);
VolumeID msk = m_idDesc.get_mask(ids);
scan_detector(m_detector, vid, msk);
Expand Down Expand Up @@ -88,7 +89,8 @@ void DigiSubdetectorSequence::scan_sensitive(PlacedVolume pv, VolumeID vid, Volu
}

void DigiSubdetectorSequence::scan_detector(DetElement de, VolumeID vid, VolumeID mask) {
const VolIDs& new_ids = de.placement().volIDs();
PlacedVolume place = m_detector.placement();
const VolIDs& new_ids = place.volIDs();
VolumeID new_vid = vid;
VolumeID new_msk = mask;
if ( !new_ids.empty() ) {
Expand Down
3 changes: 2 additions & 1 deletion DDEve/src/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ void View::ConfigureGeometry(const DisplayConfiguration::ViewConfig& config)
string dets;
DisplayConfiguration::Configurations::const_iterator ic;
float legend_y = Annotation::DefaultTextSize()+Annotation::DefaultMargin();
const DetElement::Children& c = m_eve->detectorDescription().world().children();
DetElement world = m_eve->detectorDescription().world();
const DetElement::Children& c = world.children();
for( ic=config.subdetectors.begin(); ic != config.subdetectors.end(); ++ic) {
const DisplayConfiguration::Config& cfg = *ic;
string nam = cfg.name;
Expand Down
4 changes: 2 additions & 2 deletions DDG4/src/Geant4Converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,8 @@ void* Geant4Converter::handlePlacement(const string& name, const TGeoNode* node)
double width = 0e0, offset = 0e0;
auto flags = pv_data->params->flags;
auto count = pv_data->params->trafo1D.second;
const auto& start = pv_data->params->start.Translation().Vect();
const auto& delta = pv_data->params->trafo1D.first.Translation().Vect();
auto start = pv_data->params->start.Translation().Vect();
auto delta = pv_data->params->trafo1D.first.Translation().Vect();

if ( flags&Volume::X_axis )
{ axis = kXAxis; width = delta.X(); offset = start.X(); }
Expand Down
4 changes: 2 additions & 2 deletions DDRec/include/DDRec/MaterialScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace dd4hep {
private:

/// Reference to detector setup
const Detector& m_detector;
Detector& m_detector;
/// Material manager
std::unique_ptr<MaterialManager> m_materialMgr; //!
/// Local cache: subdetector placements
Expand All @@ -64,7 +64,7 @@ namespace dd4hep {
public:

/// Standard constructor for the master instance
MaterialScan(const Detector& description);
MaterialScan(Detector& description);

/// Default destructor
virtual ~MaterialScan();
Expand Down
69 changes: 46 additions & 23 deletions DDRec/src/MaterialScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
//
//==========================================================================
// Framework include files
#include "DDRec/MaterialScan.h"
#include "DD4hep/Detector.h"
#include "DD4hep/Printout.h"
#include <DDRec/MaterialScan.h>
#include <DD4hep/DD4hepUnits.h>
#include <DD4hep/Detector.h>
#include <DD4hep/Printout.h>

/// C/C++ include files
#include <cstdio>

using namespace dd4hep;
Expand All @@ -35,7 +37,7 @@ MaterialScan::MaterialScan()
}

/// Default constructor
MaterialScan::MaterialScan(const Detector& description)
MaterialScan::MaterialScan(Detector& description)
: m_detector(description)
{
m_materialMgr.reset(new MaterialManager(m_detector.world().volume()));
Expand Down Expand Up @@ -178,20 +180,20 @@ void MaterialScan::print(const Vector3D& p0, const Vector3D& p1, double epsilon)
double sum_x0 = 0;
double sum_lambda = 0;
double path_length = 0, total_length = 0;
const char* fmt1 = " | %5d %-20s %3.0f %8.3f %8.4f %11.4f %11.4f %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n";
const char* fmt2 = " | %5d %-20s %3.0f %8.3f %8.4f %11.6g %11.6g %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n";
const char* fmt1 = " | %7s %-25s %3.0f %8.3f %8.4f %11.4f %11.4f %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n";
const char* fmt2 = " | %7s %-25s %3.0f %8.3f %8.4f %11.6g %11.6g %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n";
const char* line = " +--------------------------------------------------------------------------------------------------------------------------------------------------\n";

direction = (p1-p0).unit();

::printf("%s + Material scan between: x_0 = (%7.2f,%7.2f,%7.2f) [cm] and x_1 = (%7.2f,%7.2f,%7.2f) [cm] : \n%s",
line,p0[0],p0[1],p0[2],p1[0],p1[1],p1[2],line);
::printf(" | \\ %-11s Atomic Radiation Interaction Path Integrated Integrated Material\n","Material");
::printf(" | Num. \\ %-11s Number/Z Mass/A Density Length Length Thickness Length X0 Lambda Endpoint \n","Name");
::printf(" | Layer \\ %-11s [g/mole] [g/cm3] [cm] [cm] [cm] [cm] [cm] [cm] ( cm, cm, cm)\n","");
::printf(" | \\ %-16s Atomic Radiation Interaction Path Integrated Integrated Material\n","Material");
::printf(" | Num. \\ %-16s Number/Z Mass/A Density Length Length Thickness Length X0 Lambda Endpoint/Startpoint\n","Name");
::printf(" | Layer \\ %-16s [g/mole] [g/cm3] [cm] [cm] [cm] [cm] [cm] [cm] ( cm, cm, cm)\n","");
::printf("%s",line);
MaterialVec materials;
for( unsigned i=0,n=placements.size(); i<n; ++i){
for( unsigned i=0, n=placements.size(); i<n; ++i){
TGeoNode* pv = placements[i].first.ptr();
double length = placements[i].second;
total_length += length;
Expand All @@ -206,34 +208,55 @@ void MaterialScan::print(const Vector3D& p0, const Vector3D& p1, double epsilon)
#endif
continue;
}
TGeoMaterial* mat = placements[i].first->GetMedium()->GetMaterial();
double nx0 = length / mat->GetRadLen();
double nLambda = length / mat->GetIntLen();
TGeoMaterial* curr_mat = placements[i].first->GetMedium()->GetMaterial();
TGeoMaterial* next_mat = (i+1)<n ? placements[i+1].first->GetMedium()->GetMaterial() : nullptr;
double nx0 = length / curr_mat->GetRadLen();
double nLambda = length / curr_mat->GetIntLen();

sum_x0 += nx0;
sum_lambda += nLambda;
path_length += length;
materials.emplace_back(placements[i].first->GetMedium(),length);
const char* fmt = mat->GetRadLen() >= 1e5 ? fmt2 : fmt1;
::printf(fmt, i+1, mat->GetName(), mat->GetZ(), mat->GetA(),
mat->GetDensity(), mat->GetRadLen(), mat->GetIntLen(),
length, path_length, sum_x0, sum_lambda, end[0], end[1], end[2]);
//mat->Print();
const char* fmt = curr_mat->GetRadLen() >= 1e5 ? fmt2 : fmt1;
std::string mname = curr_mat->GetName();
if ( next_mat && (i+1)<n ) {
mname += " -> ";
mname += next_mat->GetName();
}
if ( 0 == i ) {
::printf(fmt, "(start)" , curr_mat->GetName(), curr_mat->GetZ(), curr_mat->GetA(),
curr_mat->GetDensity(), curr_mat->GetRadLen()/dd4hep::cm, curr_mat->GetIntLen()/dd4hep::cm,
0e0, 0e0, 0e0, 0e0,
p0[0]/dd4hep::cm, p0[1]/dd4hep::cm, p0[2]/dd4hep::cm);
}
// No else here!
if ( (n-1) == i ) {
::printf(fmt, "(end)", curr_mat->GetName(), curr_mat->GetZ(), curr_mat->GetA(),
curr_mat->GetDensity(), curr_mat->GetRadLen()/dd4hep::cm, curr_mat->GetIntLen()/dd4hep::cm,
0e0, 0e0, 0e0, 0e0,
p0[0]/dd4hep::cm, p0[1]/dd4hep::cm, p0[2]/dd4hep::cm);
}
else {
::printf(fmt, std::to_string(i+1).c_str(), mname.c_str(), next_mat->GetZ(), next_mat->GetA(),
next_mat->GetDensity(), next_mat->GetRadLen()/dd4hep::cm, next_mat->GetIntLen()/dd4hep::cm,
length/dd4hep::cm, path_length/dd4hep::cm, sum_x0, sum_lambda,
end[0]/dd4hep::cm, end[1]/dd4hep::cm, end[2]/dd4hep::cm);
}
}
printf("%s",line);
const MaterialData& avg = matMgr.createAveragedMaterial(materials);
const char* fmt = avg.radiationLength() >= 1e5 ? fmt2 : fmt1;
::printf(fmt,0,"Average Material",avg.Z(),avg.A(),avg.density(),
avg.radiationLength(), avg.interactionLength(),
path_length, path_length,
::printf(fmt,"","Average Material",avg.Z(),avg.A(),avg.density(),
avg.radiationLength()/dd4hep::cm, avg.interactionLength()/dd4hep::cm,
path_length/dd4hep::cm, path_length/dd4hep::cm,
path_length/avg.radiationLength(),
path_length/avg.interactionLength(),
end[0], end[1], end[2]);
end[0]/dd4hep::cm, end[1]/dd4hep::cm, end[2]/dd4hep::cm);
printf("%s",line);
}

/// Scan along a line and print the materials traversed
void MaterialScan::print(double x0, double y0, double z0, double x1, double y1, double z1, double epsilon) const {
Vector3D p0(x0, y0, z0), p1(x1, y1, z1);
print(p0, p1, epsilon);
this->print(p0, p1, epsilon);
}
6 changes: 3 additions & 3 deletions DDRec/src/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ namespace dd4hep {
// first we need to find the right volume for the local surface in the DetElement's volumes
std::list< PlacedVolume > pVList ;
PlacedVolume pv = _det.placement() ;
Volume theVol = _volSurf.volume() ;
Volume theVol = _volSurf.volume() ;

if( ! findVolume( pv, theVol , pVList ) ){
theVol = _volSurf.volume() ;
Expand All @@ -730,8 +730,8 @@ namespace dd4hep {
}

//=========== compute and cache world transform for surface ==========

const TGeoHMatrix& wm = _det.nominal().worldTransformation() ;
Alignment nominal = _det.nominal();
const TGeoHMatrix& wm = nominal.worldTransformation() ;

#if 0 // debug
wm.Print() ;
Expand Down
16 changes: 9 additions & 7 deletions UtilityApps/src/materialScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
//
//==========================================================================

#include "TError.h"
#include "TInterpreter.h"
#include <TError.h>
#include <TInterpreter.h>

// Framework include files
#include "DD4hep/Detector.h"
#include "DD4hep/Printout.h"
#include "DDRec/MaterialScan.h"
#include <DD4hep/Detector.h>
#include <DD4hep/Printout.h>
#include <DD4hep/DD4hepUnits.h>
#include <DDRec/MaterialScan.h>
#include "main.h"

using namespace dd4hep;
Expand All @@ -39,7 +40,8 @@ int main_wrapper(int argc, char** argv) {
std::cout << " usage: materialScan compact.xml x0 y0 z0 x1 y1 z1 [-interactive]" << std::endl
<< " or: materialScan compact.xml -interactive" << std::endl
<< " -> prints the materials on a straight line between the two given points (unit is cm) " << std::endl
<< " -interactive Load geometry once, then allow for shots from the ROOT prompt"
<< " -interactive Load geometry once, then allow for shots from the ROOT prompt" << std::endl
<< " NOTE: ALL lengths in units of [cm]"
<< std::endl;
exit(EINVAL);
}
Expand Down Expand Up @@ -73,7 +75,7 @@ int main_wrapper(int argc, char** argv) {
description.fromXML(inFile);
MaterialScan scan(description);
if ( do_scan ) {
scan.print(x0, y0, z0, x1, y1, z1);
scan.print(x0*dd4hep::cm, y0*dd4hep::cm, z0*dd4hep::cm, x1*dd4hep::cm, y1*dd4hep::cm, z1*dd4hep::cm);
}
if ( interactive ) {
char cmd[256];
Expand Down
2 changes: 1 addition & 1 deletion examples/DDCMS/src/DDCMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ xml_h AlgoArguments::raw_arg(const string& nam) const {
for(xml_coll_t p(element,_U(star)); p; ++p) {
string n = p.attr<string>(_U(name));
if ( n == nam ) {
return std::move(p);
return p;
}
}
except("DDCMS","+++ Attempt to access non-existing algorithm option %s[%s]",name.c_str(),nam.c_str());
Expand Down
Loading