diff --git a/DDG4/src/Geant4SensitiveDetector.cpp b/DDG4/src/Geant4SensitiveDetector.cpp index 9132bb6428f382bec45f61d8633a0cd4051dddc8..bc411403ae387aba98bcae507ce361e284e73d57 100644 --- a/DDG4/src/Geant4SensitiveDetector.cpp +++ b/DDG4/src/Geant4SensitiveDetector.cpp @@ -172,54 +172,92 @@ void Geant4SensitiveDetector::dumpStep(G4Step* st, G4TouchableHistory* /* histor } -long long Geant4SensitiveDetector::getVolumeID(G4Step* step ){ +long long Geant4SensitiveDetector::getVolumeID(G4Step* aStep ){ - Geant4Mapping& mapping = Geant4Mapping::instance(); + Geant4Mapping& mapping = Geant4Mapping::instance(); + + Geant4StepHandler step(aStep); - const G4NavigationHistory* hist = step->GetPreStepPoint()->GetTouchableHandle()->GetHistory() ; - int depth = hist->GetDepth() ; - //------------ get the cellID description string ----------------------------------- - - const G4VPhysicalVolume* g4v = hist->GetVolume( depth ) ; - Geometry::PlacedVolume place = mapping.placement( g4v ) ; - - if( ! place.isValid() || ! place.volume().isSensitive() ) { - G4cout << " **** Error in Geant4SensitiveDetector::getVolumeID: invalid first sensitive volume in buildHits is not sensitive !!! " << std::endl ; + Geant4VolumeManager volMgr = Geant4Mapping::instance().volumeManager(); + + VolumeID id = volMgr.volumeID( step.preTouchable() ); + + +#if 0 // additional checks ... + + const G4VPhysicalVolume* g4v = step.volume( step.pre ); + + if ( id == Geant4VolumeManager::InvalidPath ) { + ::printf(" --> Severe ERROR: Invalid placement path: touchable corrupted?\n"); + } + else if ( id == Geant4VolumeManager::Insensitive ) { + ::printf(" --> WARNING: Only sensitive volumes may be decoded. %s\n" , g4v->GetName().c_str() ); + } + else if ( id == Geant4VolumeManager::NonExisting ) { + ::printf(" --> WARNING: non existing placement path.\n"); + } + else { + + std::stringstream str; + Geant4VolumeManager::VolIDDescriptor dsc; + Geant4VolumeManager::VolIDFields& fields = dsc.second; + volMgr.volumeDescriptor( step.preTouchable(), dsc ); + for(Geant4VolumeManager::VolIDFields::iterator i=fields.begin(); i!=fields.end();++i){ + str << (*i).first->name() << "=" << (*i).second << " "; + } + ::printf(" --> CellID: %X [%X] -> %s\n",id,dsc.first,str.str().c_str()); + } - Geometry::Volume vol = place.volume(); - Geometry::SensitiveDetector sd = vol.sensitiveDetector(); - Geometry::Readout ro = sd.readout(); - - std::string idDescStr = ro.idSpec().fieldDescription() ; - - // G4cout << "----------- Geant4SensitiveDetector::getVolumeID - idDescStr = " << idDescStr << std::endl ; +#endif + + return id ; + + + // // old way of lookup ----------- does not work for assemblies .... + + // //------------ get the cellID description string ----------------------------------- + + // Geometry::PlacedVolume place = mapping.placement( g4v ) ; - BitField64 bf( idDescStr ) ; + // if( ! place.isValid() || ! place.volume().isSensitive() ) { + // G4cout << " **** Error in Geant4SensitiveDetector::getVolumeID: invalid first sensitive volume in buildHits is not sensitive !!! " << std::endl ; + // } + // Geometry::Volume vol = place.volume(); + // Geometry::SensitiveDetector sd = vol.sensitiveDetector(); + // Geometry::Readout ro = sd.readout(); - //------------ now fill the cellID from the volIDs of the complete path ----------------------------------- + // std::string idDescStr = ro.idSpec().fieldDescription() ; + // BitField64 bf( idDescStr ) ; + + // //------------ now fill the cellID from the volIDs of the complete path ----------------------------------- + + // const G4NavigationHistory* hist = aStep->GetPreStepPoint()->GetTouchableHandle()->GetHistory() ; + // int depth = hist->GetDepth() ; + // //const G4VPhysicalVolume* g4v = hist->GetVolume( depth ) ; - for(int i=depth ; i>0 ; --i ) { + // for(int i=depth ; i>0 ; --i ) { - g4v = hist->GetVolume(i) ; - Geometry::PlacedVolume place = mapping.placement( g4v ) ; + // g4v = hist->GetVolume(i) ; + // Geometry::PlacedVolume place = mapping.placement( g4v ) ; - if( ! place.isValid() ) { - G4cout << " **** WARNING in Geant4SensitiveDetector::getVolumeID: ingnoring invalid PlacedVolume for : " << g4v->GetName() << std::endl ; - continue ; - } + // if( ! place.isValid() ) { + // G4cout << " **** WARNING in Geant4SensitiveDetector::getVolumeID: ingnoring invalid PlacedVolume for : " << g4v->GetName() << std::endl ; + // continue ; + // } - // G4cout << "--- VolIDs : " << std::endl ; - Geometry::PlacedVolume::VolIDs ids = place.volIDs() ; + // // G4cout << "--- VolIDs : " << std::endl ; + // Geometry::PlacedVolume::VolIDs ids = place.volIDs() ; - for( Geometry::PlacedVolume::VolIDs::const_iterator it = ids.begin() ; it != ids.end() ; ++it ){ + // for( Geometry::PlacedVolume::VolIDs::const_iterator it = ids.begin() ; it != ids.end() ; ++it ){ - // G4cout << "--- " << it->first << " -- " << it->second << std:: - bf[ it->first ] = it->second ; - } - } + // // G4cout << "--- " << it->first << " -- " << it->second << std:: + // bf[ it->first ] = it->second ; + // } + // } + + // return bf.getValue() ; - return bf.getValue() ; }