19 #include "DD4hep/DDTest.h"
24 #include "IO/LCReader.h"
25 #include "EVENT/LCEvent.h"
26 #include "EVENT/LCCollection.h"
27 #include "EVENT/SimTrackerHit.h"
28 #include "UTIL/ILDConf.h"
39 static DDTest test(
"surfaces" ) ;
46 std::cout <<
" usage: test_surfaces compact.xml lcio_file.slcio" << std::endl ;
50 std::string inFile = argv[1] ;
52 Detector& description = Detector::getInstance();
66 std::map< dd4hep::long64, Surface* > surfMap ;
68 for( SurfaceList::const_iterator it = sL.begin() ; it != sL.end() ; ++it ){
77 surfMap[ surf->
id() ] = surf ;
90 std::string lcioFileName = argv[2] ;
92 IO::LCReader* rdr = IOIMPL::LCFactory::getInstance()->createLCReader() ;
93 rdr->open( lcioFileName ) ;
95 EVENT::LCEvent* evt = 0 ;
98 while( ( evt = rdr->readNextEvent() ) != 0 ){
100 const std::vector< std::string >& colNames = *evt->getCollectionNames() ;
102 for(
unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){
104 EVENT::LCCollection* col = evt->getCollection( colNames[ icol ] ) ;
106 std::string typeName = col->getTypeName() ;
108 if( typeName != lcio::LCIO::SIMTRACKERHIT )
111 std::cout <<
" -- testing collection : " << colNames[ icol ] << std::endl ;
113 std::string cellIDEcoding = col->getParameters().getStringVal(
"CellIDEncoding") ;
115 lcio::BitField64 idDecoder( cellIDEcoding ) ;
117 int nHit = col->getNumberOfElements() ;
119 for(
int i=0 ; i< nHit ; ++i){
121 EVENT::SimTrackerHit* sHit = (EVENT::SimTrackerHit*) col->getElementAt(i) ;
125 idDecoder.setValue(
id ) ;
129 Surface* surf = surfMap[ id ] ;
131 SurfaceMap::const_iterator si = surfMap.find(
id ) ;
133 ISurface* surf = ( si != surfMap.end() ? si->second : 0 ) ;
136 std::stringstream sst ;
137 sst <<
" surface found for id : " << std::hex <<
id << std::dec <<
" " << idDecoder.valueString() << std ::endl ;
142 test( surf != 0 ,
true , sst.str() ) ;
149 Vector3D point( sHit->getPosition()[0]* dd4hep::mm , sHit->getPosition()[1]* dd4hep::mm , sHit->getPosition()[2]* dd4hep::mm ) ;
157 sst <<
" point " << point <<
" is on surface " ;
161 test( isInside ,
true , sst.str() ) ;
165 std::cout <<
" found surface " << *surf << std::endl
166 <<
" id : " << idDecoder.valueString()
167 <<
" point : " << point
168 <<
" is inside : " << isInside
169 <<
" distance from surface : " <<
dist <<
" (units: cm) " << std::endl
198 sst <<
" point3 " << point3 <<
" is not on surface " ;
200 test( isInside ,
false , sst.str() ) ;
206 std::cout <<
"ERROR: no surface found for id: " << idDecoder << std::endl ;