diff --git a/DDExamples/ILDExDet/compact/ILDEx.xml b/DDExamples/ILDExDet/compact/ILDEx.xml index d2600a6f95ddc5035608f7640e0cf98c2ef371f3..678b6cdbc3c21ccaee3ae6d8097d4e14c40aac31 100644 --- a/DDExamples/ILDExDet/compact/ILDEx.xml +++ b/DDExamples/ILDExDet/compact/ILDEx.xml @@ -145,7 +145,7 @@ </detector> - <detector name="TPC" type="ILDExTPC" vis="TPCVis" id="3" limits="TPC_limits" readout="TPCCollection" insideTrackingVolume="true"> + <detector name="TPC" type="XX_ILDExTPC" vis="TPCVis" id="3" limits="TPC_limits" readout="TPCCollection" insideTrackingVolume="true"> <tubs rmin="TPC_inner_radius" rmax="TPC_outer_radius" zhalf="TPC_zhalf"/> <!-- GEAR Data--> <driftlength value="TPC_zhalf*0.9"/> diff --git a/DDExamples/ILDExDet/src/compact/ILDExSIT_geo.cpp b/DDExamples/ILDExDet/src/compact/ILDExSIT_geo.cpp index f5f46187f3480c364632bddf7786ab8cfa4c39b0..6bdcabe158fa190937f95e421edc42f560ed9f31 100644 --- a/DDExamples/ILDExDet/src/compact/ILDExSIT_geo.cpp +++ b/DDExamples/ILDExDet/src/compact/ILDExSIT_geo.cpp @@ -10,7 +10,7 @@ #include "DD4hep/DetFactoryHelper.h" // -- lcio -#include <UTIL/BitField64.h> +//#include <UTIL/BitField64.h> #include <UTIL/ILDConf.h> using namespace std; @@ -24,14 +24,13 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { Assembly assembly( name + "assembly" ) ; PlacedVolume pv; - // setup the encoder - UTIL::BitField64 encoder( ILDCellID0::encoder_string ) ; - encoder.reset() ; // reset to 0 - - encoder[ILDCellID0::subdet] = ILDDetID::SIT ; - encoder[ILDCellID0::side] = 0 ; - encoder[ILDCellID0::module] = 0 ; - encoder[ILDCellID0::sensor] = 0 ; + // // setup the encoder + // UTIL::BitField64 encoder( ILDCellID0::encoder_string ) ; + // encoder.reset() ; // reset to 0 + // encoder[ILDCellID0::subdet] = ILDDetID::SIT ; + // encoder[ILDCellID0::side] = 0 ; + // encoder[ILDCellID0::module] = 0 ; + // encoder[ILDCellID0::sensor] = 0 ; for(xml_coll_t c(e,_U(layer)); c; ++c) { @@ -64,7 +63,7 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { pv = laddervol.placeVolume(sensvol,senspos) ; laddervol.placeVolume(suppvol,supppos); sit.setVisAttributes(lcdd, x_det.visStr(),laddervol); - encoder[ILDCellID0::layer] = layer_id ; + // encoder[ILDCellID0::layer] = layer_id ; for(int j=0; j<nLadders; ++j) { @@ -73,15 +72,20 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { Position pos(radius*cos(j*dphi),radius*sin(j*dphi),0.); // place the volume and set the cellID0 - will be set to the copyNo in Geant4Converter - encoder[ILDCellID0::module] = j ; - int cellID0 = encoder.lowWord() ; + // encoder[ILDCellID0::module] = j ; + // int cellID0 = encoder.lowWord() ; pv = assembly.placeVolume(laddervol,Transform3D(RotationZ(j*dphi),pos)); - pv.addPhysVolID("layer",layer_id).addPhysVolID("module",j); + + // this will result int the correct cellID to be set... + pv.addPhysVolID("layer",layer_id).addPhysVolID("module",j).addPhysVolID("sensor",0 ) ; + } } pv = lcdd.pickMotherVolume(sit).placeVolume(assembly) ; - pv.addPhysVolID("system", x_det.id()); + + pv.addPhysVolID("system", x_det.id()).addPhysVolID("side",0 ) ; + sit.setPlacement( pv ); return sit; } diff --git a/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp b/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp index 4fbdf6715abe1dbcc436649d73661657289309fd..c2aef3c5d096554efaed4515efb8bb99e1071ca8 100644 --- a/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp +++ b/DDExamples/ILDExDet/src/compact/ILDExVXD_geo.cpp @@ -10,7 +10,7 @@ #include "VXDData.h" // -- lcio -#include <UTIL/BitField64.h> +//#include <UTIL/BitField64.h> #include <UTIL/ILDConf.h> using namespace std; @@ -28,14 +28,12 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { vxd.assign(vxd_data,name,x_det.typeStr()); vxd_data->id = x_det.id(); - // setup the encoder - UTIL::BitField64 encoder( ILDCellID0::encoder_string ) ; - encoder.reset() ; // reset to 0 - - encoder[ILDCellID0::subdet] = ILDDetID::VXD ; - encoder[ILDCellID0::side] = 0 ; - encoder[ILDCellID0::sensor] = 0 ; - + // // setup the encoder + // UTIL::BitField64 encoder( ILDCellID0::encoder_string ) ; + // encoder.reset() ; // reset to 0 + // encoder[ILDCellID0::subdet] = ILDDetID::VXD ; + // encoder[ILDCellID0::side] = 0 ; + // encoder[ILDCellID0::sensor] = 0 ; for(xml_coll_t c(e,_U(layer)); c; ++c) { @@ -106,7 +104,7 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { layer.RadLength = sensmat->GetMaterial()->GetRadLen(); vxd_data->_sVec.push_back(layer); - encoder[ILDCellID0::layer] = layer_id ; + // encoder[ILDCellID0::layer] = layer_id ; // Assembly layer_assembly( name + _toString( layer_id,"layer_assembly_%d" ) ) ; @@ -136,15 +134,13 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { // if( dj < 3 ) // place the volume and set the cellID0 - will be set to the copyNo in Geant4Converter - encoder[ILDCellID0::module] = j ; - int cellID0 = encoder.lowWord() ; + // encoder[ILDCellID0::module] = j ; + // int cellID0 = encoder. + // lcdd.pickMotherVolume(vxd).placeVolume(laddervol,pos, rot ).addPhysVolID("CellID0", cellID0 ) ; - // lcdd.pickMotherVolume(vxd).placeVolume(laddervol,pos, rot ).addPhysVolID("CellID0", cellID0 ) ; pv = assembly.placeVolume( laddervol,Transform3D(RotationZ(phi),pos)); - pv.addPhysVolID("layer", layer_id ).addPhysVolID( "module" , j ) ; - - //.addPhysVolID("CellID0", cellID0 ) ; + pv.addPhysVolID("layer", layer_id ).addPhysVolID( "module" , j ).addPhysVolID("sensor", 0 ) ; //pv = assembly.placeVolume( sensvol, pos, rot ) ; @@ -154,7 +150,8 @@ static Ref_t create_element(LCDD& lcdd, xml_h e, SensitiveDetector sens) { Volume mother = lcdd.pickMotherVolume(vxd) ; pv = mother.placeVolume(assembly); - pv.addPhysVolID( "system", x_det.id() ) ; + + pv.addPhysVolID( "system", x_det.id() ).addPhysVolID("side",0 ) ; vxd.setPlacement(pv); return vxd; diff --git a/DDG4/src/Geant4TrackerSD.cpp b/DDG4/src/Geant4TrackerSD.cpp index 42c392493f76f13576aa7a31d747538362a2eb58..cc95dc495e2cb4da3563f6826b934581ed5303ca 100644 --- a/DDG4/src/Geant4TrackerSD.cpp +++ b/DDG4/src/Geant4TrackerSD.cpp @@ -9,6 +9,13 @@ // Framework include files #include "DDG4/Geant4SensitiveDetector_inline.h" #include "DDG4/Factories.h" +#include "DDG4/Geant4StepHandler.h" +#include "DDG4/Geant4Mapping.h" + +#include "DD4hep/BitField64.h" + +//#include "G4Step.hh" + /* * DD4hep::Simulation namespace declaration @@ -20,48 +27,127 @@ namespace DD4hep { namespace Simulation { /// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ struct Tracker {}; /// Method for generating hit(s) using the information of G4Step object. - template <> bool Geant4GenericSD<Tracker>::buildHits(G4Step* step,G4TouchableHistory* /* hist */) { - StepHandler h(step); - Position prePos = h.prePos(); - Position postPos = h.postPos(); - Position direction = postPos - prePos; - Position position = mean_direction(prePos,postPos); - double hit_len = direction.R(); - if (hit_len > 0) { - double new_len = mean_length(h.preMom(),h.postMom())/hit_len; - direction *= new_len/hit_len; - } + template <> bool Geant4GenericSD<Tracker>::buildHits(G4Step* step,G4TouchableHistory* /*hist*/ ) { + + StepHandler h(step); + + + //------------ get the cellID ----------------------------------- + + Geant4Mapping& mapping = Geant4Mapping::instance(); + Geant4StepHandler stepH(step); + const G4VPhysicalVolume* pv = stepH.volume(stepH.pre); + + int cellID = 0 ; + + Geometry::PlacedVolume place = mapping.placement(pv); + + if ( place.isValid() ) { + if ( place.volume().isSensitive() ) { + + // G4cout << "----------- Geant4GenericSD<Tracker>::buildHits - get volumeID from " << place.toString() << std::endl ; + + Geometry::VolumeManager vm = mapping.lcdd().volumeManager(); + + Geometry::VolumeManager::VolumeID cell_id = vm.lookupID( place ); + + // const Geometry::PlacedVolume::VolIDs& ids = place.volIDs(); + // printf(" Found Sensitive TGeoNode:%s CellID: %llx #VolIDs: %d --- at level: %d \n", place.name(), cell_id , ids.size() , i ); + // for( Geometry::PlacedVolume::VolIDs::const_iterator it = ids.begin() ; it != ids.end() ; ++it ){ + // G4cout << "--- " << it->first << " -- " << it->second << std::endl ; + // } + + Geometry::Volume vol = place.volume(); + Geometry::SensitiveDetector sd = vol.sensitiveDetector(); + Geometry::Readout ro = sd.readout(); + Geometry::IDDescriptor iddesc = ro.idSpec(); + + + //----- use a BitField64 object to store the cellID in the Linear collider convention + BitField64 bf( iddesc.toString() ) ; + + for( unsigned i=0, N=bf.size() ;i<N;++i){ + + BitFieldValue& v = bf[i] ; + + long val = iddesc.field( v.name() ).decode( cell_id ) ; + + if( v.isSigned() && ( val & ( 1LL << ( v.width() - 1 ) ) ) != 0 ) { // negative value + + val -= ( 1LL << v.width() ); + } + v = val ; - // G4cout << "----------- Geant4GenericSD<Tracker>::buildHits : position : " << prePos << G4endl ; - - Geant4TrackerHit* hit = - new Geant4TrackerHit(h.track->GetTrackID(), - h.track->GetDefinition()->GetPDGEncoding(), - step->GetTotalEnergyDeposit(), - h.track->GetGlobalTime()); - - - HitContribution contrib = Geant4Hit::extractContribution(step); - - // get the copy number of the parent volume - - // we need a more generic way of finding the volume that has the right copy number assigned... - // otherwise we couple detector construction sensitive detector !! - G4StepPoint* preStepPoint = step->GetPreStepPoint(); - G4TouchableHistory* theTouchable = (G4TouchableHistory*)( preStepPoint->GetTouchable() ); - // G4int copyNo = theTouchable->GetVolume()->GetCopyNo(); - G4int motherCopyNo = theTouchable->GetVolume(1)->GetCopyNo(); - hit->cellID = motherCopyNo ; - - - hit->energyDeposit = contrib.deposit ; - - hit->position = position; - hit->momentum = direction; - hit->length = hit_len; - collection(0)->insert(hit); - return hit != 0; - } - typedef Geant4GenericSD<Tracker> Geant4Tracker; -}} // End namespace DD4hep::Simulation + // this does not work as the IDDescriptor does not handle signed (negative) values correctly + // b[i] = iddesc.field( b[i].name() ).decode( cell_id ) ; + } + + // G4cout << "--- IDDescriptor: " << iddesc.toString() + // << " BitField64 : " << bf + // << std::endl ; + + // Geometry::IDDescriptor::Field modFld = iddesc.field("module"); + // int mod_id = modFld.decode( cell_id ); + // int layer = iddesc.field("layer").decode( cell_id ) ; + // G4cout << "--- layer " << layer << " ---- module: " << mod_id << std::endl ; + + + cellID = bf.lowWord() ; + + } else { + + G4cerr << "**ERROR** Geant4GenericSD<Tracker>::buildHits - called for insensitive volume: " + << place.toString() + << std::endl ; + + } + + } else{ + + G4cerr << "----------- Geant4GenericSD<Tracker>::buildHits - invalid Volume found: " << std::endl ; + } + + Position prePos = h.prePos(); + Position postPos = h.postPos(); + Position direction = postPos - prePos; + Position position = mean_direction(prePos,postPos); + double hit_len = direction.R(); + if (hit_len > 0) { + double new_len = mean_length(h.preMom(),h.postMom())/hit_len; + direction *= new_len/hit_len; + } + + // G4cout << "----------- Geant4GenericSD<Tracker>::buildHits : position : " << prePos << G4endl ; + + Geant4TrackerHit* hit = + new Geant4TrackerHit(h.track->GetTrackID(), + h.track->GetDefinition()->GetPDGEncoding(), + step->GetTotalEnergyDeposit(), + h.track->GetGlobalTime()); + + + HitContribution contrib = Geant4Hit::extractContribution(step); + + // get the copy number of the parent volume - + // we need a more generic way of finding the volume that has the right copy number assigned... + // otherwise we couple detector construction sensitive detector !! + // G4StepPoint* preStepPoint = step->GetPreStepPoint(); + // G4TouchableHistory* theTouchable = (G4TouchableHistory*)( preStepPoint->GetTouchable() ); + // G4int copyNo = theTouchable->GetVolume()->GetCopyNo(); + // G4int motherCopyNo = theTouchable->GetVolume(1)->GetCopyNo(); + + hit->cellID = cellID ; + + + hit->energyDeposit = contrib.deposit ; + + hit->position = position; + hit->momentum = direction; + hit->length = hit_len; + collection(0)->insert(hit); + return hit != 0; + } + typedef Geant4GenericSD<Tracker> Geant4Tracker; + }} // End namespace DD4hep::Simulation DECLARE_GEANT4SENSITIVEDETECTOR(Geant4Tracker)