diff --git a/DDRec/include/DDRec/CellIDPositionConverter.h b/DDRec/include/DDRec/CellIDPositionConverter.h index 6fcb4f3da5f1788e6138e543d63ec684f115ac10..801b8e6b25fd3584b58b6b7aee243ed315cfc70c 100644 --- a/DDRec/include/DDRec/CellIDPositionConverter.h +++ b/DDRec/include/DDRec/CellIDPositionConverter.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef CellIDPositionConverter_H_ #define CellIDPositionConverter_H_ diff --git a/DDRec/include/DDRec/DDGear.h b/DDRec/include/DDRec/DDGear.h index e24f6c75f4f93a2ec9271623922e008e2c495f05..8e97aef70be23c3cd66807e4ba564de33b1f788a 100644 --- a/DDRec/include/DDRec/DDGear.h +++ b/DDRec/include/DDRec/DDGear.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef DDGear_H #define DDGear_H diff --git a/DDRec/include/DDRec/DetectorData.h b/DDRec/include/DDRec/DetectorData.h index f7815294057b3ab2bdf65ef105d6eb54564b849e..eb90b741cee89b6537b0c8cc709e69d74e965a80 100644 --- a/DDRec/include/DDRec/DetectorData.h +++ b/DDRec/include/DDRec/DetectorData.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef rec_DetectorData_H_ #define rec_DetectorData_H_ diff --git a/DDRec/include/DDRec/DetectorSurfaces.h b/DDRec/include/DDRec/DetectorSurfaces.h index 4c31e737fefae01f5cf7bd09898aeebe73d3a9ce..fc364dacc08e06caade9660781642986b4a4eab3 100644 --- a/DDRec/include/DDRec/DetectorSurfaces.h +++ b/DDRec/include/DDRec/DetectorSurfaces.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef rec_DetectorSurfaces_H_ #define rec_DetectorSurfaces_H_ diff --git a/DDRec/include/DDRec/IMaterial.h b/DDRec/include/DDRec/IMaterial.h index c93afa51d052b11acae919a17d33a0e88f1bf9bd..95c378cd3e79008566a2e6a3a83843ef66f7bab7 100644 --- a/DDRec/include/DDRec/IMaterial.h +++ b/DDRec/include/DDRec/IMaterial.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef DDRec_IMaterial_H_ #define DDRec_IMaterial_H_ diff --git a/DDRec/include/DDRec/ISurface.h b/DDRec/include/DDRec/ISurface.h index 4ad311c35810b6a64652f861d3919190cbbdba3a..e1ed9631770a91aa241afecda584a19f4e1a6230 100644 --- a/DDRec/include/DDRec/ISurface.h +++ b/DDRec/include/DDRec/ISurface.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef DDRec_ISurface_H #define DDRec_ISurface_H diff --git a/DDRec/include/DDRec/Material.h b/DDRec/include/DDRec/Material.h index 4c470c54373c117f44118d8501ddbe795093e535..02acf1071eb6316f83520e98cd1d30bc402ac203 100644 --- a/DDRec/include/DDRec/Material.h +++ b/DDRec/include/DDRec/Material.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef rec_Material_H #define rec_Material_H diff --git a/DDRec/include/DDRec/MaterialManager.h b/DDRec/include/DDRec/MaterialManager.h index c84a03188643b813d12c76f8207661514f4bb3ed..25078e5610672e8ecb981337d0b905d39d45a3df 100644 --- a/DDRec/include/DDRec/MaterialManager.h +++ b/DDRec/include/DDRec/MaterialManager.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef rec_MaterialManager_H_ #define rec_MaterialManager_H_ @@ -15,7 +27,8 @@ class TGeoManager ; namespace dd4hep { namespace rec { - typedef std::vector< std::pair< Material, double > > MaterialVec ; + typedef std::vector< std::pair< Material, double > > MaterialVec; + typedef std::vector< std::pair< PlacedVolume, double > > PlacementVec; /** Material manager provides access to the material properties of the detector. * Material can be accessed either for a given point or as a list of materials along a straight @@ -45,12 +58,19 @@ namespace dd4hep { * are ignored. Avoid calling this method in inner loops as the computation is not cheap. Ideally the result should be cached, * for example as an averaged material @see createAveragedMaterial(). */ - const MaterialVec& materialsBetween(const Vector3D& p0, const Vector3D& p1 , double epsilon=1e-4 ) ; + const MaterialVec& materialsBetween(const Vector3D& p0, const Vector3D& p1 , double epsilon=1e-4 ); + /** Get a vector with all the placements between the two points p0 and p1 + */ + const PlacementVec& placementsBetween(const Vector3D& p0, const Vector3D& p1 , double epsilon=1e-4 ); + /** Get the material at the given position. */ const Material& materialAt(const Vector3D& pos ); + /** Get the placed volume at the given position. + */ + PlacedVolume placementAt(const Vector3D& pos ); /** Create a material with averaged properties from all materials in the list. * A and Z are averaged by relative number of atoms(molecules), rho is averaged by relative volume @@ -59,32 +79,30 @@ namespace dd4hep { MaterialData createAveragedMaterial( const MaterialVec& materials ) ; protected : - - //cached materials + /// Cached materials MaterialVec _mV ; - Material _m ; - - // cached last points - Vector3D _p0 , _p1, _pos ; - + Material _m ; + /// Cached nodes + PlacedVolume _pv; + PlacementVec _placeV; + /// cached last points + Vector3D _p0 , _p1, _pos ; + /// Reference to the TGeoManager TGeoManager* _tgeoMgr ; }; - /// dump Material operator inline std::ostream& operator<<( std::ostream& os , const Material& m ) { os << " " << m.name() << " Z: " << m.Z() << " A: " << m.A() << " density: " << m.density() - << " radiationLength: " << m.radLength() - << " interactionLength: " << m.intLength() ; + << " radiationLength: " << m.radLength() + << " interactionLength: " << m.intLength() ; return os ; } - /// dump MaterialVec operator inline std::ostream& operator<<( std::ostream& os , const MaterialVec& m ) { - for( unsigned i=0,n=m.size() ; i<n ; ++i ) { - os << " material: " << m[i].first << " thickness: " << m[i].second << std::endl ; + os << " material: " << m[i].first << " thickness: " << m[i].second << std::endl ; } return os ; } diff --git a/DDRec/include/DDRec/MaterialScan.h b/DDRec/include/DDRec/MaterialScan.h index 03286c577870c409d2ec6934158f2633ec755f04..cfaf469066834add5114a0ba3e1e7517f06dbe0a 100644 --- a/DDRec/include/DDRec/MaterialScan.h +++ b/DDRec/include/DDRec/MaterialScan.h @@ -29,6 +29,21 @@ namespace dd4hep { /// Class to perform material scans along a straight line /** + * Examples: from DDDetectors/compact/SiD.xml + * $> materialScan file:checkout/DDDetectors/compact/SiD.xml -interactive + * + * 1) Simple scan: + * root [0] gMaterialScan->print(5,5,0,5,5,400) + * 2) Scan a given subdetector: + * root [0] de=gDD4hepUI->instance()->detector("LumiCal"); + * root [1] gMaterialScan->setDetector(de); + * root [2] gMaterialScan->print(5,5,0,5,5,400) + * 3) Scan by material: + * root [0] gMaterialScan->setMaterial("Silicon"); + * root [1] gMaterialScan->print(5,5,0,5,5,400) + * 4) Scan by region: + * root [0] gMaterialScan->setRegion("SiTrackerBarrelRegion"); + * root [1] gMaterialScan->print(0,0,0,100,100,0) * * \author M.Frank * \version 1.0 @@ -38,10 +53,11 @@ namespace dd4hep { private: /// Reference to detector setup - Detector& m_detector; + Detector& m_detector; /// Material manager std::unique_ptr<MaterialManager> m_materialMgr; //! - + /// Local cache: subdetector placements + std::set<const TGeoNode*> m_placements; /// Default constructor MaterialScan(); @@ -53,8 +69,20 @@ namespace dd4hep { /// Default destructor virtual ~MaterialScan(); - /// Set a specific detector volume to limit the scan + /// Set a specific detector volume to limit the scan (resets other selection criteria) void setDetector(DetElement detector); + /// Set a specific detector volume to limit the scan (resets other selection criteria) + void setDetector(const char* detector); + + /// Set a specific volume material to limit the scan (resets other selection criteria) + void setMaterial(const char* material); + /// Set a specific volume material to limit the scan (resets other selection criteria) + void setMaterial(Material material); + + /// Set a specific region to limit the scan (resets other selection criteria) + void setRegion(const char* region); + /// Set a specific region to limit the scan (resets other selection criteria) + void setRegion(Region region); /// Scan along a line and store the matrials internally const MaterialVec& scan(double x0, double y0, double z0, double x1, double y1, double z1, double epsilon=1e-4) const; diff --git a/DDRec/include/DDRec/Surface.h b/DDRec/include/DDRec/Surface.h index a7c10f18d2970a78bff1ca56655fc78a4d5c283c..0b010d9072b53bba4bdc87aad9c1662dc21a63aa 100644 --- a/DDRec/include/DDRec/Surface.h +++ b/DDRec/include/DDRec/Surface.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef rec_Surface_H #define rec_Surface_H diff --git a/DDRec/include/DDRec/SurfaceHelper.h b/DDRec/include/DDRec/SurfaceHelper.h index d612ad5ebeac92aa542c53eddac794854038eb88..c9e23ab750d08746266ca59a99d031d18bab9211 100644 --- a/DDRec/include/DDRec/SurfaceHelper.h +++ b/DDRec/include/DDRec/SurfaceHelper.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef rec_SurfaceHelper_H_ #define rec_SurfaceHelper_H_ diff --git a/DDRec/include/DDRec/SurfaceManager.h b/DDRec/include/DDRec/SurfaceManager.h index afd59c67fac5afdb2078340eb0b002150cce7fb4..7e52a840bbbc55aa9e88718dd438f8e46455ded6 100644 --- a/DDRec/include/DDRec/SurfaceManager.h +++ b/DDRec/include/DDRec/SurfaceManager.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef rec_SurfaceManager_H_ #define rec_SurfaceManager_H_ diff --git a/DDRec/include/DDRec/Vector2D.h b/DDRec/include/DDRec/Vector2D.h index 84a9ca408c73d4164d94111b9843adff277ff500..410d3231643c03a3438a8b8dba597cf5194a5761 100644 --- a/DDRec/include/DDRec/Vector2D.h +++ b/DDRec/include/DDRec/Vector2D.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef DDRec_Vector2D_h #define DDRec_Vector2D_h 1 diff --git a/DDRec/include/DDRec/Vector3D.h b/DDRec/include/DDRec/Vector3D.h index 789e787cadb08c0f65738e31e93b8228b296f53a..8f5dd3d603959b876576c1f8cdc71b1d3728cdac 100644 --- a/DDRec/include/DDRec/Vector3D.h +++ b/DDRec/include/DDRec/Vector3D.h @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #ifndef DDRec_Vector3D_h #define DDRec_Vector3D_h 1 diff --git a/DDRec/src/CellIDPositionConverter.cpp b/DDRec/src/CellIDPositionConverter.cpp index 77c650b33736670d40be91e31c10e5fded603e7c..c3a4e3ad939200631fdd4b3416e236a156ef8fd0 100644 --- a/DDRec/src/CellIDPositionConverter.cpp +++ b/DDRec/src/CellIDPositionConverter.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/CellIDPositionConverter.h" diff --git a/DDRec/src/DetectorData.cpp b/DDRec/src/DetectorData.cpp index c3ea7d2d52fcffdff0538a9b6ce6638e389abc70..bb6a2aaf83b984f88de35a99b7e2da14ae60030a 100644 --- a/DDRec/src/DetectorData.cpp +++ b/DDRec/src/DetectorData.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/DetectorData.h" #include <boost/io/ios_state.hpp> diff --git a/DDRec/src/DetectorSurfaces.cpp b/DDRec/src/DetectorSurfaces.cpp index a6c104a2d37e7fb17b41f377a0c53fa8959611d9..ca3cdd20cc12ff8713e18cda5894232ceb2d4047 100644 --- a/DDRec/src/DetectorSurfaces.cpp +++ b/DDRec/src/DetectorSurfaces.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/DetectorSurfaces.h" namespace dd4hep { diff --git a/DDRec/src/MaterialManager.cpp b/DDRec/src/MaterialManager.cpp index d786bd824cdeabf5d72346bbaf24caade1c25663..7d73acdee728326fb370e557d8b9041f55f04cb6 100644 --- a/DDRec/src/MaterialManager.cpp +++ b/DDRec/src/MaterialManager.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/MaterialManager.h" #include "DD4hep/Exceptions.h" #include "DD4hep/Detector.h" @@ -23,13 +35,16 @@ namespace dd4hep { } - const MaterialVec&MaterialManager:: materialsBetween(const Vector3D& p0, const Vector3D& p1 , double epsilon) { - - if( ( p0 != _p0 ) || ( p1 != _p1 ) ) { - + const PlacementVec& MaterialManager::placementsBetween(const Vector3D& p0, const Vector3D& p1 , double epsilon) { + materialsBetween(p0,p1,epsilon); + return _placeV; + } + + const MaterialVec& MaterialManager::materialsBetween(const Vector3D& p0, const Vector3D& p1 , double epsilon) { + if( ( p0 != _p0 ) || ( p1 != _p1 ) ) { //--------------------------------------- _mV.clear() ; - + _placeV.clear(); // // algorithm copied from TGeoGearDistanceProperties.cc (A.Munnich): // @@ -55,7 +70,7 @@ namespace dd4hep { //check if there is a node at startpoint if(!node1) throw std::runtime_error("No geometry node found at given location. Either there is no node placed here or position is outside of top volume."); - + while ( !_tgeoMgr->IsOutside() ) { // TGeoNode *node2; @@ -113,18 +128,20 @@ namespace dd4hep { track->AddPoint( endpoint[0], endpoint[1], endpoint[2], 0. ); - if( length > epsilon ) + if( length > epsilon ) { _mV.push_back( std::make_pair( Material( node1->GetMedium() ) , length ) ) ; - + _placeV.push_back(std::make_pair(node1,length)); + } break; } track->AddPoint( position[0], position[1], position[2], 0.); - if( length > epsilon ) + if( length > epsilon ) { _mV.push_back( std::make_pair( Material( node1->GetMedium() ), length ) ) ; - - node1 = node2 ; + _placeV.push_back(std::make_pair(node1,length)); + } + node1 = node2; } @@ -144,30 +161,38 @@ namespace dd4hep { _p1 = p1 ; } - return _mV ; ; + return _mV ; } - const Material& MaterialManager::materialAt(const Vector3D& pos ){ - + const Material& MaterialManager::materialAt(const Vector3D& pos ) { if( pos != _pos ) { - - TGeoNode *node=_tgeoMgr->FindNode( pos[0], pos[1], pos[2] ) ; - + TGeoNode *node = _tgeoMgr->FindNode( pos[0], pos[1], pos[2] ) ; if( ! node ) { std::stringstream err ; err << " MaterialManager::material: No geometry node found at location: " << pos ; throw std::runtime_error( err.str() ); } - - // std::cout << " @@@ MaterialManager::material @ " << pos << " found volume : " << node->GetName() << std::endl ; - - _m = Material( node->GetMedium() ) ; - + _m = Material( node->GetMedium() ); + _pv = node; _pos = pos ; } - - return _m ; ; + return _m ; + } + + PlacedVolume MaterialManager::placementAt(const Vector3D& pos ) { + if( pos != _pos ) { + TGeoNode *node = _tgeoMgr->FindNode( pos[0], pos[1], pos[2] ) ; + if( ! node ) { + std::stringstream err ; + err << " MaterialManager::material: No geometry node found at location: " << pos ; + throw std::runtime_error( err.str() ); + } + _m = Material( node->GetMedium() ); + _pv = node; + _pos = pos; + } + return _pv; } MaterialData MaterialManager::createAveragedMaterial( const MaterialVec& materials ) { diff --git a/DDRec/src/MaterialScan.cpp b/DDRec/src/MaterialScan.cpp index 2453fff0e1d1f750264bd4638d6636259de75f6d..84647c7cb7461bb64cd4db9f4eecf8b172da3bad 100644 --- a/DDRec/src/MaterialScan.cpp +++ b/DDRec/src/MaterialScan.cpp @@ -46,11 +46,121 @@ MaterialScan::~MaterialScan() { } +/// Set a specific region to limit the scan (resets the subdetector selection) +void MaterialScan::setRegion(const char* region) { + Region reg; + if ( region ) { + reg = m_detector.region(region); + } + setRegion(reg); +} + +/// Set a specific region to limit the scan (resets the subdetector selection) +void MaterialScan::setRegion(Region region) { + struct PvCollector { + Region rg; + std::set<const TGeoNode*>& cont; + PvCollector(Region r, std::set<const TGeoNode*>& c) : rg(r), cont(c) {} + void collect(TGeoNode* pv) { + cont.insert(pv); + for (Int_t idau = 0, ndau = pv->GetNdaughters(); idau < ndau; ++idau) + collect(pv->GetDaughter(idau)); + } + void operator()(TGeoNode* pv) { + Volume v = pv->GetVolume(); + Region r = v.region(); + if ( r.isValid() ) { + collect(pv); + return; + } + for (Int_t idau = 0, ndau = pv->GetNdaughters(); idau < ndau; ++idau) + (*this)(pv->GetDaughter(idau)); + } + }; + m_placements.clear(); + if ( region.isValid() ) { + PvCollector coll(region, m_placements); + coll(m_detector.world().placement().ptr()); + printout(ALWAYS,"MaterialScan","+++ Set new scanning region to: %s [%ld placements]", + region.name(), m_placements.size()); + } + else { + printout(ALWAYS,"MaterialScan","+++ No region restrictions set. Back to full scanning mode."); + } +} + +/// Set a specific detector volume to limit the scan +void MaterialScan::setDetector(const char* detector) { + DetElement det; + if ( detector ) { + det = m_detector.detector(detector); + } + setDetector(det); +} + /// Set a specific detector volume to limit the scan void MaterialScan::setDetector(DetElement detector) { + struct PvCollector { + std::set<const TGeoNode*>& cont; + PvCollector(std::set<const TGeoNode*>& c) : cont(c) {} + void operator()(TGeoNode* pv) { + cont.insert(pv); + for (Int_t idau = 0, ndau = pv->GetNdaughters(); idau < ndau; ++idau) { + TGeoNode* daughter = pv->GetDaughter(idau); + (*this)(daughter); + } + } + }; if ( detector.isValid() ) { - printout(ALWAYS,"MaterialScan","+++ Set new scanning volume to: %s",detector.path().c_str()); - m_materialMgr.reset(new MaterialManager(detector.volume())); + PlacedVolume pv = detector.placement(); + m_placements.clear(); + if ( pv.isValid() ) { + PvCollector coll(m_placements); + coll(pv.ptr()); + } + printout(ALWAYS,"MaterialScan","+++ Set new scanning volume to: %s [%ld placements]", + detector.path().c_str(), m_placements.size()); + } + else { + printout(ALWAYS,"MaterialScan","+++ No subdetector restrictions set. Back to full scanning mode."); + m_placements.clear(); + } +} + +/// Set a specific volume material to limit the scan +void MaterialScan::setMaterial(const char* material) { + Material mat; + if ( material ) { + mat = m_detector.material(material); + } + setMaterial(mat); +} + +/// Set a specific volume material to limit the scan +void MaterialScan::setMaterial(Material material) { + struct PvCollector { + Material material; + std::set<const TGeoNode*>& cont; + PvCollector(Material m, std::set<const TGeoNode*>& c) : material(m), cont(c) {} + void operator()(TGeoNode* pv) { + Volume v = pv->GetVolume(); + Material m = v.material(); + if ( m.ptr() == material.ptr() ) { + cont.insert(pv); + } + for (Int_t idau = 0, ndau = pv->GetNdaughters(); idau < ndau; ++idau) + (*this)(pv->GetDaughter(idau)); + } + }; + m_placements.clear(); + if ( material.isValid() ) { + PvCollector coll(material, m_placements); + coll(m_detector.world().placement().ptr()); + printout(ALWAYS,"MaterialScan","+++ Set new scanning material to: %s [%ld placements]", + material.name(), m_placements.size()); + } + else { + printout(ALWAYS,"MaterialScan","+++ No material restrictions set. Back to full scanning mode."); } } @@ -62,12 +172,12 @@ const MaterialVec& MaterialScan::scan(double x0, double y0, double z0, double x1 /// Scan along a line and print the materials traversed void MaterialScan::print(const Vector3D& p0, const Vector3D& p1, double epsilon) const { - const auto& materials = m_materialMgr->materialsBetween(p0, p1, epsilon); + const auto& placements = m_materialMgr->placementsBetween(p0, p1, epsilon); auto& matMgr = *m_materialMgr; Vector3D end, direction; double sum_x0 = 0; double sum_lambda = 0; - double path_length = 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* line = " +--------------------------------------------------------------------------------------------------------------------------------------------------\n"; @@ -80,16 +190,30 @@ void MaterialScan::print(const Vector3D& p0, const Vector3D& p1, double epsilon) ::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("%s",line); - - for( unsigned i=0,n=materials.size();i<n;++i){ - TGeoMaterial* mat = materials[i].first->GetMaterial(); - double length = materials[i].second; - double nx0 = length / mat->GetRadLen(); - sum_x0 += nx0; + MaterialVec materials; + for( unsigned i=0,n=placements.size(); i<n; ++i){ + TGeoNode* pv = placements[i].first.ptr(); + double length = placements[i].second; + total_length += length; + end = p0 + total_length * direction; + if ( !m_placements.empty() && m_placements.find(pv) == m_placements.end() ) { +#if 0 + ::printf("%p %s %s %s\n", + placements[i].first.ptr(), + placements[i].first->GetName(), + placements[i].first->GetVolume()->GetName(), + placements[i].first->GetMedium()->GetName()); +#endif + continue; + } + TGeoMaterial* mat = placements[i].first->GetMedium()->GetMaterial(); + double nx0 = length / mat->GetRadLen(); double nLambda = length / mat->GetIntLen(); - sum_lambda += nLambda; - path_length += length; - end = p0 + path_length * direction; + + sum_x0 += nx0; + sum_lambda += nLambda; + path_length += length; + materials.push_back(std::make_pair(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(), @@ -99,7 +223,6 @@ void MaterialScan::print(const Vector3D& p0, const Vector3D& p1, double epsilon) printf("%s",line); const MaterialData& avg = matMgr.createAveragedMaterial(materials); const char* fmt = avg.radiationLength() >= 1e5 ? fmt2 : fmt1; - end = p0 + path_length * direction; ::printf(fmt,0,"Average Material",avg.Z(),avg.A(),avg.density(), avg.radiationLength(), avg.interactionLength(), path_length, path_length, diff --git a/DDRec/src/Surface.cpp b/DDRec/src/Surface.cpp index bdbd1cd6ad3da1ec4f01e97967794a02c442cb9c..fcc9872275a929d9201f0eefe5ba411774f2f88b 100644 --- a/DDRec/src/Surface.cpp +++ b/DDRec/src/Surface.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/Surface.h" #include "DD4hep/detail/DetectorInterna.h" #include "DD4hep/Memory.h" diff --git a/DDRec/src/SurfaceHelper.cpp b/DDRec/src/SurfaceHelper.cpp index 9b8ab42d4438ef8c5d6bf6e92cf61825e713eaa0..c31c3857f916e3536900085538161af0e4560b1d 100644 --- a/DDRec/src/SurfaceHelper.cpp +++ b/DDRec/src/SurfaceHelper.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/SurfaceHelper.h" #include "DDRec/DetectorSurfaces.h" diff --git a/DDRec/src/SurfaceManager.cpp b/DDRec/src/SurfaceManager.cpp index ee703d227aa5615001fe247b07350db28c4eaef7..1fe1d2e4809e1d6c127f4d2eb4f8dfd365a9221f 100644 --- a/DDRec/src/SurfaceManager.cpp +++ b/DDRec/src/SurfaceManager.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/SurfaceManager.h" #include "DDRec/SurfaceHelper.h" diff --git a/DDRec/src/convertToGear.cc b/DDRec/src/convertToGear.cc index 4ac0e62e3eabf248696ea5e53c19ecb3f239dcde..1d26cda3b3f900c8285197339d7363b9a8be60c7 100644 --- a/DDRec/src/convertToGear.cc +++ b/DDRec/src/convertToGear.cc @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" #include "DD4hep/Fields.h" diff --git a/DDRec/src/gear/DDGear.cpp b/DDRec/src/gear/DDGear.cpp index db649e700d2f04262e5ad120e61c449ba5e40acd..7c946da85d37c0072cda9804e76072c4ae476050 100644 --- a/DDRec/src/gear/DDGear.cpp +++ b/DDRec/src/gear/DDGear.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DDRec/DDGear.h" #include "DD4hep/Detector.h" diff --git a/DDRec/src/gear/createGearForCLIC.cpp b/DDRec/src/gear/createGearForCLIC.cpp index b7ce1cf024bc1296e502ecb42e1cd16eacf63405..c76dd0edd3480f2f199af4370ed3dcbca8f182a9 100644 --- a/DDRec/src/gear/createGearForCLIC.cpp +++ b/DDRec/src/gear/createGearForCLIC.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DD4hep/Detector.h" #include "DD4hep/Factories.h" #include "DD4hep/DD4hepUnits.h" diff --git a/DDRec/src/gear/createGearForILD.cpp b/DDRec/src/gear/createGearForILD.cpp index d2e37d0f5a0bb515b860da91901440145d6b2a3c..307d47b35e18577dab1cd65a1714c39aa1e8fecf 100644 --- a/DDRec/src/gear/createGearForILD.cpp +++ b/DDRec/src/gear/createGearForILD.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DD4hep/Detector.h" #include "DD4hep/Factories.h" #include "DD4hep/DD4hepUnits.h" diff --git a/DDRec/src/gear/createGearForSiD.cpp b/DDRec/src/gear/createGearForSiD.cpp index 6fd5251ca9e3fbfa1952010aea94b964128c52c5..518b0ae35071954557d6e502682dfd0c6ddfe15f 100644 --- a/DDRec/src/gear/createGearForSiD.cpp +++ b/DDRec/src/gear/createGearForSiD.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DD4hep/Detector.h" #include "DD4hep/Factories.h" #include "DD4hep/DD4hepUnits.h" diff --git a/DDRec/src/plugins/createSurfaceManager.cpp b/DDRec/src/plugins/createSurfaceManager.cpp index 03f54a213ffe33d2e862584d0f4c4a323dc3ea57..4ebc8d5b39cc672fe3ca357c6b792375e93d212b 100644 --- a/DDRec/src/plugins/createSurfaceManager.cpp +++ b/DDRec/src/plugins/createSurfaceManager.cpp @@ -1,3 +1,15 @@ +//========================================================================== +// AIDA Detector description implementation +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : F.Gaede +// +//========================================================================== #include "DD4hep/Detector.h" #include "DD4hep/Factories.h" #include "DD4hep/Printout.h" diff --git a/UtilityApps/src/materialScan.cpp b/UtilityApps/src/materialScan.cpp index 0d4bcc859f105e3981cbabc27903da55e8903178..208f77db3c73b1ff67a726e81f879e2ff8671d3c 100644 --- a/UtilityApps/src/materialScan.cpp +++ b/UtilityApps/src/materialScan.cpp @@ -37,35 +37,54 @@ int main_wrapper(int argc, char** argv) { } static void usage() { std::cout << " usage: materialScan compact.xml x0 y0 z0 x1 y1 z1 [-interactive]" << std::endl - << " -> prints the materials on a straight line between the two given points ( unit is cm) " << 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" << std::endl; - exit(1); + exit(EINVAL); } } _handler; - if( argc < 8 ) Handler::usage(); - bool interactive = argc == 9 && ::strncmp(argv[8],"-interactive",5) == 0; + bool do_scan = true, interactive = false; double x0, y0, z0, x1, y1, z1; - std::string inFile = argv[1]; - std::stringstream sstr; - sstr << argv[2] << " " << argv[3] << " " << argv[4] << " " << argv[5] << " " << argv[6] << " " << argv[7] << " " << "NONE"; - sstr >> x0 >> y0 >> z0 >> x1 >> y1 >> z1; - if ( !sstr.good() ) Handler::usage(); + if( argc == 3 && ::strncmp(argv[2],"-interactive",5) == 0 ) { + interactive = true; + do_scan = false; + } + else if ( argc == 9 && ::strncmp(argv[8],"-interactive",5) == 0 ) { + interactive = true; + do_scan = true; + } + else if ( argc < 8 ) { + Handler::usage(); + } + + std::string inFile = argv[1]; + if ( do_scan ) { + std::stringstream sstr; + sstr << argv[2] << " " << argv[3] << " " << argv[4] << " " + << argv[5] << " " << argv[6] << " " << argv[7] << " " << "NONE"; + sstr >> x0 >> y0 >> z0 >> x1 >> y1 >> z1; + if ( !sstr.good() ) Handler::usage(); + } setPrintLevel(WARNING); Detector& description = Detector::getInstance(); description.fromXML(inFile); MaterialScan scan(description); - scan.print(x0, y0, z0, x1, y1, z1); + if ( do_scan ) { + scan.print(x0, y0, z0, x1, y1, z1); + } if ( interactive ) { char cmd[256]; description.apply("DD4hep_InteractiveUI",0,0); ::snprintf(cmd,sizeof(cmd), - "dd4hep::rec::MaterialScan& gMaterialScan = " - "*(dd4hep::rec::MaterialScan*)%p",(void*)&scan); + "dd4hep::rec::MaterialScan* gMaterialScan = " + "(dd4hep::rec::MaterialScan*)%p",(void*)&scan); gInterpreter->ProcessLine(cmd); - printout(ALWAYS,"materialScan","Use the ROOT interpreter variable gMaterialScan to interact with the material scanner"); + printout(ALWAYS,"materialScan","Use the ROOT interpreter variable " + "\"dd4hep::rec::MaterialScan* gMaterialScan\" to interact " + "with the material scanner"); gInterpreter->ProcessLine(".class dd4hep::rec::MaterialScan"); description.apply("DD4hep_Rint",0,0); }