Exemple #1
0
 static long dump(DetElement de,int level, bool sensitive_only) {
   const DetElement::Children& c = de.children();
   if ( !sensitive_only || 0 != de.volumeID() )  {
     PlacedVolume place = de.placement();
     const TGeoNode* node = place.ptr();
     char sens = place.volume().isSensitive() ? 'S' : ' ';
     int value = flag;
     char fmt[128];
     switch(value)  {
     case 0:
       ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s #Dau:%%d VolID:%%08X Place:%%p  %%c",level+1,2*level+1);
       printout(INFO,"DetectorDump",fmt,"",de.path().c_str(),int(c.size()),
                (unsigned long)de.volumeID(), (void*)node, sens);
       break;
     case 1:
       ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds Detector: %%s #Dau:%%d VolID:%%p",level+1,2*level+1);
       printout(INFO,"DetectorDump", fmt, "", de.path().c_str(),
                int(c.size()), (void*)de.volumeID());
       ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds Placement: %%s   %%c",level+1,2*level+3);
       printout(INFO,"DetectorDump",fmt,"", de.placementPath().c_str(), sens);
       break;
     default:
       break;
     }
   }
   for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i)
     dump((*i).second,level+1,sensitive_only);
   return 1;
 }
Exemple #2
0
// helper method to get the closest daughter DetElement to the position starting from the given DetElement
DetElement IDDecoder::getClosestDaughter(const DetElement& det, const Position& position) {
	DetElement result;

	// check if we have a shape and see if we are inside
	if (det.volume().isValid() and det.volume().solid().isValid()) {
		double globalPosition[3] = { position.x(), position.y(), position.z() };
		double localPosition[3] = { 0., 0., 0. };
		det.worldTransformation().MasterToLocal(globalPosition, localPosition);
		if (det.volume().solid()->Contains(localPosition)) {
			result = det;
		} else {
			// assuming that any daughter shape would be inside this shape
			return DetElement();
		}
	}

	const DetElement::Children& children = det.children();
	DetElement::Children::const_iterator it = children.begin();
	while (it != children.end()) {
		DetElement daughterDet = getClosestDaughter(it->second, position);
		if (daughterDet.isValid()) {
			result = daughterDet;
			break;
		}
		++it;
	}
	return result;
}
Exemple #3
0
 static long cache(DetElement de) {
   const DetElement::Children& c = de.children();
   de.worldTransformation();
   de.parentTransformation();
   de.placementPath();
   de.path();
   for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i)
     cache((*i).second);
   return 1;
 }
 /// Dump method.
 virtual int operator()(DetElement de,int level)  const  {
   const DetElement::Children& children = de.children();
   PlacedVolume place = de.placement();
   char sens = place.volume().isSensitive() ? 'S' : ' ';
   char fmt[128], tmp[32];
   ::snprintf(tmp,sizeof(tmp),"%03d/",level+1);
   ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s #Dau:%%d VolID:%%08X %%c",level+1,2*level+1);
   printout(INFO,"DetectorDump",fmt,"",de.path().c_str(),int(children.size()),
            (unsigned long)de.volumeID(), sens);
   printer.prefix = string(tmp)+de.name();
   (printer)(de, level);
   return 1;
 }
Exemple #5
0
/// Load 'levels' Children into the geometry scene
void Display::LoadGeoChildren(TEveElement* start, int levels, bool redraw)  {
  using namespace DD4hep::Geometry;
  DetElement world = m_lcdd->world();
  if ( world.children().size() == 0 )   {
    MessageBox(INFO,"It looks like there is no\nGeometry loaded.\nNo event display availible.\n");
  }
  else if ( levels > 0 )   {
    if ( 0 == start )     {
      TEveElementList& sens = GetGeoTopic("Sensitive");
      TEveElementList& struc = GetGeoTopic("Structure");
      const DetElement::Children& c = world.children();
      
      printout(INFO,"Display","+++ Load children of %s to %d levels", 
               world.placement().name(), levels);
      for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) {
        DetElement de = (*i).second;
        SensitiveDetector sd = m_lcdd->sensitiveDetector(de.name());
        TEveElementList& parent = sd.isValid() ? sens : struc;
        pair<bool,TEveElement*> e = Utilities::LoadDetElement(de,levels,&parent);
        if ( e.second && e.first )  {
          parent.AddElement(e.second);
        }
      }
    }
    else    {
      TGeoNode* n = (TGeoNode*)start->GetUserData();
      printout(INFO,"Display","+++ Load children of %s to %d levels",Utilities::GetName(start),levels);
      if ( 0 != n )   {
        TGeoHMatrix mat;
        const char* node_name = n->GetName();
        int level = Utilities::findNodeWithMatrix(lcdd().world().placement().ptr(),n,&mat);
        if ( level > 0 )   {
          pair<bool,TEveElement*> e(false,0);
          const DetElement::Children& c = world.children();
          for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) {
            DetElement de = (*i).second;
            if ( de.placement().ptr() == n )  {
              e = Utilities::createEveShape(0, levels, start, n, mat, de.name());
              break;
            }
          }
          if ( !e.first && !e.second )  {
            e = Utilities::createEveShape(0, levels, start, n, mat, node_name);
          }
          if ( e.first )  { // newly created
            start->AddElement(e.second);
          }
          printout(INFO,"Display","+++ Import geometry node %s with %d levels.",node_name, levels);
        }
        else   {
          printout(INFO,"Display","+++ FAILED to import geometry node %s with %d levels.",node_name, levels);
        }
      }
      else  {
        LoadGeoChildren(0,levels,false);
      }
    }
  }
  if ( redraw )   {
    manager().Redraw3D();
  }
}
Exemple #6
0
    void SurfaceHelper::initialize() {
      
      // have to populate the volume manager once in order to have 
      // the volumeIDs attached to the DetElements
      LCDD& lcdd = LCDD::getInstance();
      static VolumeManager volMgr( lcdd  , "volMan" , lcdd.world() ) ;

 
      //------------------ breadth first tree traversal ---------
      std::list< DetElement > dets ;
      std::list< DetElement > daugs ; 
      std::list< DetElement > gdaugs ; 
      
      daugs.push_back( _det ) ;
      
      while( ! daugs.empty() ) {
	
	for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){
	  DetElement dau = *li ;
	  DetElement::Children chMap = dau.children() ;
	  for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){
	    DetElement de = (*it).second ;
	    gdaugs.push_back( de ) ;
	  }  
	}
	dets.splice( dets.end() , daugs ) ;
	daugs.splice( daugs.end() , gdaugs ) ;
      }
      //------------------ end tree traversal ---------
      
      //      std::cout << " **** SurfaceHelper::initialize() : # DetElements found  " << dets.size() << std::endl ;
      
      for( std::list< DetElement >::iterator li=dets.begin() ; li != dets.end() ; ++li ) {
	
	DetElement det = (*li) ;
	


	// create surfaces
	DetectorSurfaces ds( det ) ;
	
	const SurfaceList& detSL = ds.surfaceList() ;


	// // ---------------------- debug printout
	// std::cout << " ---- DetElement id: " << det.volumeID() << " name : " << det.name() << "  #surfaces : " << detSL.size() << std::endl ; 
	// PlacedVolume pv = det.placement() ;
	// if( pv.isValid() ) {
	//   try{ // needed as above is also true for world whcih has invalid placment ...
	//     PlacedVolume::VolIDs volIDs = pv.volIDs() ;
	//     for(unsigned i=0,n=volIDs.size(); i<n ; ++i){
	//       std::cout << "        " << volIDs[i].first << " : " << volIDs[i].second << std::endl ;
	//     }
	//   }catch(...){}
	// }else{
	//   std::cout << "        invalid placement for DetElement ??? !! " << std::endl ;
	// }
	// // ------------------------- end debug printout


	// and add copy them to this list
	_sL.insert( _sL.end(), detSL.begin(), detSL.end() );
      }
      
    }