File indexing completed on 2025-01-18 09:15:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include "DD4hep/Detector.h"
0014
0015 #include "DDRec/Surface.h"
0016 #include "DDRec/DetectorSurfaces.h"
0017 #include "DDRec/SurfaceManager.h"
0018 #include "DDRec/SurfaceHelper.h"
0019 #include "DD4hep/DDTest.h"
0020
0021 #include "DD4hep/DD4hepUnits.h"
0022
0023 #include "lcio.h"
0024 #include "IO/LCReader.h"
0025 #include "EVENT/LCEvent.h"
0026 #include "EVENT/LCCollection.h"
0027 #include "EVENT/SimTrackerHit.h"
0028 #include "UTIL/ILDConf.h"
0029
0030 #include <map>
0031 #include <sstream>
0032
0033 using namespace std ;
0034 using namespace dd4hep ;
0035 using namespace dd4hep::detail;
0036 using namespace dd4hep::rec ;
0037
0038
0039 static DDTest test( "surfaces" ) ;
0040
0041
0042
0043 int main_wrapper(int argc, char** argv ){
0044
0045 if( argc < 3 ) {
0046 std::cout << " usage: test_surfaces compact.xml lcio_file.slcio" << std::endl ;
0047 exit(1) ;
0048 }
0049
0050 std::string inFile = argv[1] ;
0051
0052 Detector& description = Detector::getInstance();
0053
0054 description.fromCompact( inFile );
0055
0056
0057 #if 0
0058
0059 DetElement world = description.world() ;
0060
0061 SurfaceHelper surfMan( world ) ;
0062
0063 const SurfaceList& sL = surfMan.surfaceList() ;
0064
0065
0066 std::map< dd4hep::long64, Surface* > surfMap ;
0067
0068 for( SurfaceList::const_iterator it = sL.begin() ; it != sL.end() ; ++it ){
0069
0070 Surface* surf = *it ;
0071
0072
0073
0074
0075
0076
0077 surfMap[ surf->id() ] = surf ;
0078 }
0079 #else
0080
0081 SurfaceManager& surfMan = *description.extension< SurfaceManager >() ;
0082 const SurfaceMap& surfMap = *surfMan.map( "world" ) ;
0083
0084 #endif
0085
0086
0087
0088
0089
0090 std::string lcioFileName = argv[2] ;
0091
0092 IO::LCReader* rdr = IOIMPL::LCFactory::getInstance()->createLCReader() ;
0093 rdr->open( lcioFileName ) ;
0094
0095 EVENT::LCEvent* evt = 0 ;
0096
0097
0098 while( ( evt = rdr->readNextEvent() ) != 0 ){
0099
0100 const std::vector< std::string >& colNames = *evt->getCollectionNames() ;
0101
0102 for(unsigned icol=0, ncol = colNames.size() ; icol < ncol ; ++icol ){
0103
0104 EVENT::LCCollection* col = evt->getCollection( colNames[ icol ] ) ;
0105
0106 std::string typeName = col->getTypeName() ;
0107
0108 if( typeName != lcio::LCIO::SIMTRACKERHIT )
0109 continue ;
0110
0111 std::cout << " -- testing collection : " << colNames[ icol ] << std::endl ;
0112
0113 std::string cellIDEcoding = col->getParameters().getStringVal("CellIDEncoding") ;
0114
0115 lcio::BitField64 idDecoder( cellIDEcoding ) ;
0116
0117 int nHit = col->getNumberOfElements() ;
0118
0119 for(int i=0 ; i< nHit ; ++i){
0120
0121 EVENT::SimTrackerHit* sHit = (EVENT::SimTrackerHit*) col->getElementAt(i) ;
0122
0123 dd4hep::FieldID id = sHit->getCellID0() ;
0124
0125 idDecoder.setValue( id ) ;
0126
0127
0128 #if 0
0129 Surface* surf = surfMap[ id ] ;
0130 #else
0131 SurfaceMap::const_iterator si = surfMap.find( id ) ;
0132
0133 ISurface* surf = ( si != surfMap.end() ? si->second : 0 ) ;
0134 #endif
0135
0136 std::stringstream sst ;
0137 sst << " surface found for id : " << std::hex << id << std::dec << " " << idDecoder.valueString() << std ::endl ;
0138
0139
0140
0141
0142 test( surf != 0 , true , sst.str() ) ;
0143
0144
0145 if( surf != 0 ){
0146
0147
0148
0149 Vector3D point( sHit->getPosition()[0]* dd4hep::mm , sHit->getPosition()[1]* dd4hep::mm , sHit->getPosition()[2]* dd4hep::mm ) ;
0150
0151 double dist = surf->distance( point ) ;
0152
0153 bool isInside = surf->insideBounds( point ) ;
0154
0155
0156 sst.str("") ;
0157 sst << " point " << point << " is on surface " ;
0158
0159
0160
0161 test( isInside , true , sst.str() ) ;
0162
0163 if( ! isInside ) {
0164
0165 std::cout << " found surface " << *surf << std::endl
0166 << " id : " << idDecoder.valueString()
0167 << " point : " << point
0168 << " is inside : " << isInside
0169 << " distance from surface : " << dist << " (units: cm) " << std::endl
0170 << std::endl ;
0171 }
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196 Vector3D point3 = point + 1e-3 * surf->normal() ;
0197 sst.str("") ;
0198 sst << " point3 " << point3 << " is not on surface " ;
0199 isInside = surf->insideBounds( point3) ;
0200 test( isInside , false , sst.str() ) ;
0201
0202
0203
0204 } else {
0205
0206 std::cout << "ERROR: no surface found for id: " << idDecoder << std::endl ;
0207 }
0208
0209 }
0210
0211 }
0212
0213
0214 }
0215 return 0;
0216 }
0217
0218
0219 #include "main.h"