Ejemplo n.º 1
0
// Process hits.
G4bool base_SD::ProcessHits( G4Step * step, G4TouchableHistory * /*ROhist*/ ) {

  MCDetectorHit hit;

  hit.Edep=step->GetTotalEnergyDeposit();
  
  G4StepPoint * prestep = step->GetPreStepPoint();
  G4StepPoint * poststep = step->GetPostStepPoint();

  G4TouchableHandle touchable = prestep->GetTouchableHandle();

  hit.id=touchable->GetCopyNumber();
  if (hit.id>=2000)
    {
      plugin->debug(0,"Hit id is too large... bailing out \n");
      exit(-1);
    }

  G4Track * track = step->GetTrack();

  hit.time = prestep->GetGlobalTime();
  hit.track = track->GetTrackID();

   // Get the true world and local coordinate positions.
  
   G4ThreeVector trueworld =
      ( prestep->GetPosition() + poststep->GetPosition() ) / 2.0;

   // If this first time store transformation and inverse.

   if( !transformValid[hit.id] ) {
     if (WorldtoLocal.size()<hit.id+1) //too small
       {
	 WorldtoLocal.resize(hit.id+1);
	 LocaltoWorld.resize(hit.id+1);
       }
      WorldtoLocal[hit.id] = touchable->GetHistory()->GetTopTransform();
      LocaltoWorld[hit.id] = WorldtoLocal[hit.id].Inverse();
      transformValid[hit.id] = true;
   }

   G4ThreeVector Tmp = WorldtoLocal[hit.id].TransformPoint(trueworld);

   hit.world=TVector3(trueworld.x(),trueworld.y(),trueworld.z());
   hit.local=TVector3(Tmp.x(),Tmp.y(),Tmp.z());

   // find average momentum

   G4ThreeVector mom=0.5*(prestep->GetMomentum()+poststep->GetMomentum());
   hit.fourmomentum.SetXYZM(mom.x()/MeV,mom.y()/MeV,mom.z()/MeV,prestep->GetMass()/MeV);
   mom=WorldtoLocal[hit.id].TransformAxis(mom);
   hit.localmomentum=TVector3(mom.x(),mom.y(),mom.z());
   data->hits.push_back(hit);
   return true;
}
Ejemplo n.º 2
0
//---------------------------------------------------------------------------
G4int SteppingAction::IsBoxSurfaceFlux(const G4Step* aStep) //returns 1(in), 2(out), or -1
{  //G4PSFlatSurfaceFlux
	
	G4StepPoint* preStep = aStep->GetPreStepPoint();
	
	G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume();
	G4VPVParameterisation* physParam = physVol->GetParameterisation();
	G4VSolid * solid = 0;
	if(physParam)
	{ // for parameterized volume
	//G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
	//->GetReplicaNumber(indexDepth);//TODO find indexDepth and use these
	//solid = physParam->ComputeSolid(idx, physVol);
	//solid->ComputeDimensions(physParam,idx,physVol);
	}
	else
	{ // for ordinary volume
		solid = physVol->GetLogicalVolume()->GetSolid();
	}
	
	G4Box* boxSolid = (G4Box*)(solid);
	
	G4TouchableHandle theTouchable = 
	aStep->GetPreStepPoint()->GetTouchableHandle();
	G4double kCarTolerance=G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
	
	if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary ){
		// Entering Geometry
		G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
		G4ThreeVector localpos1 = 
		theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
		if(std::fabs( localpos1.z() + boxSolid->GetZHalfLength())<kCarTolerance 
			||std::fabs( localpos1.z() - boxSolid->GetZHalfLength())<kCarTolerance
			||std::fabs( localpos1.y() + boxSolid->GetYHalfLength())<kCarTolerance 
			||std::fabs( localpos1.y() - boxSolid->GetYHalfLength())<kCarTolerance 
			||std::fabs( localpos1.x() + boxSolid->GetXHalfLength())<kCarTolerance 
			||std::fabs( localpos1.x() - boxSolid->GetXHalfLength())<kCarTolerance 
		){
			return 1;//fFlux_In; _InOut =0 		
		}
		
	}
	
	if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary ){
		// Exiting Geometry
		G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
		G4ThreeVector localpos2 = 
		theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
		if(std::fabs( localpos2.z() + boxSolid->GetZHalfLength())<kCarTolerance 
			||std::fabs( localpos2.z() - boxSolid->GetZHalfLength())<kCarTolerance
			||std::fabs( localpos2.y() + boxSolid->GetYHalfLength())<kCarTolerance 
			||std::fabs( localpos2.y() - boxSolid->GetYHalfLength())<kCarTolerance 
			||std::fabs( localpos2.x() + boxSolid->GetXHalfLength())<kCarTolerance 
			||std::fabs( localpos2.x() - boxSolid->GetXHalfLength())<kCarTolerance 			
		){
			return 2;//fFlux_Out;
		}
	}
	
	return -1;
}
Ejemplo n.º 3
0
G4int SteppingAction::IsCylSurfaceFlux(const G4Step* aStep, G4double fRadius, G4double fHalfHt)
{  //from G4PSCylinderSurfaceFlux        //returns 1(in), 2(out), or -1
	
	G4StepPoint* preStep = aStep->GetPreStepPoint(); //?????
	G4VPhysicalVolume* physVol = preStep->GetPhysicalVolume();
	G4VPVParameterisation* physParam = physVol->GetParameterisation();
	//G4VSolid* solid = NULL;
	if(physParam)
	{ // for parameterized volume
		//G4int idx = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
		//->GetReplicaNumber(indexDepth);//TODO get indexdepth and uncomment these
		//solid = physParam->ComputeSolid(idx, physVol);
		//solid->ComputeDimensions(physParam,idx,physVol);
	}
	else
	{ // for ordinary volume
	//	solid = physVol->GetLogicalVolume()->GetSolid();
		//G4cout << " logvol " << physVol->GetLogicalVolume()->GetName() << G4endl;
		//NOTE this is wrong
	}
	
	//G4Tubs* tubsSolid = (G4Tubs*)(solid);  //NOTE solid dimensions are all 0
	//now it is bypassed by passing in ht and rad. TODO correct it
	
	G4TouchableHandle theTouchable = aStep->GetPreStepPoint()->GetTouchableHandle();
	G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();  
	
	if (aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary )
	{
		// Entering Geometry. Prestep point is at the Outer surface. 
		G4ThreeVector stppos1= aStep->GetPreStepPoint()->GetPosition();
		G4ThreeVector localpos1 = 
		theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos1);
		//if ( std::fabs(localpos1.z()) > tubsSolid->GetZHalfLength()) return -1;			
		if ( std::fabs(localpos1.z()) > (fHalfHt+ kCarTolerance))//tubsSolid->GetZHalfLength()
		{//G4cout << " preGeom:-1:z " << localpos1.z() << " halfz " << tubsSolid->GetZHalfLength() 
		 //      <<" tol " << kCarTolerance << G4endl; // NOTE solid dimensions are all 0
			return -1; 												
		}
		G4double localR2 = localpos1.x()*localpos1.x()+localpos1.y()*localpos1.y();
		G4double outerRad = fRadius;//tubsSolid->GetOuterRadius();// GetInnerRadius();//NOTE
		if( (localR2 > (outerRad-kCarTolerance)*(outerRad-kCarTolerance)
			&& localR2 < (outerRad+kCarTolerance)*(outerRad+kCarTolerance))
			||
			( std::fabs( localpos1.z())< (fHalfHt +kCarTolerance)//tubsSolid->GetZHalfLength() 
			&&	localR2 < (outerRad+kCarTolerance)*(outerRad+kCarTolerance) )
		){
			//G4cout << " preGeom:1 " << G4endl;
			return 1;//fFlux_In;
		}
	}
	
	if (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary )
	{
		// Exiting Geometry. Post step point is at the outer surface.
		G4ThreeVector stppos2= aStep->GetPostStepPoint()->GetPosition();
		G4ThreeVector localpos2 = 
		theTouchable->GetHistory()->GetTopTransform().TransformPoint(stppos2);
		//if ( std::fabs(localpos2.z()) > tubsSolid->GetZHalfLength() )	return -1;
		if ( std::fabs(localpos2.z()) > (fHalfHt+ kCarTolerance))//tubsSolid->GetZHalfLength() 
		{
			return -1;
		}
		G4double localR2 = localpos2.x()*localpos2.x()+localpos2.y()*localpos2.y();
		G4double outerRad = fRadius;//tubsSolid->GetOuterRadius();//GetInnerRadius();//NOTE
		if( (localR2 > (outerRad-kCarTolerance)*(outerRad-kCarTolerance)
			&& localR2 < (outerRad+kCarTolerance)*(outerRad+kCarTolerance))
			||
			( std::fabs( localpos2.z())< ( fHalfHt+kCarTolerance)// tubsSolid->GetZHalfLength()
			&&	localR2 < (outerRad+kCarTolerance)*(outerRad+kCarTolerance) )
		){
			//G4cout << " postGeom:2 " << G4endl;
			return 2;//fFlux_Out;
		}
	}
	
	return -1;
}