Files
geant4/examples/novice/N05/src/ExN05PionShowerModel.cc
T
2016-06-08 16:18:25 +02:00

223 lines
7.2 KiB
C++

//
// ********************************************************************
// * DISCLAIMER *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// ********************************************************************
//
//
// $Id: ExN05PionShowerModel.cc,v 1.7 2001/11/08 10:21:29 radoone Exp $
// GEANT4 tag $Name: geant4-04-00 $
//
#include "ExN05PionShowerModel.hh"
#include "ExN05EnergySpot.hh"
#include "Randomize.hh"
#include "G4PionMinus.hh"
#include "G4PionPlus.hh"
#include "G4TransportationManager.hh"
#include "G4VSensitiveDetector.hh"
#include "G4TouchableHistory.hh"
#include "G4Colour.hh"
ExN05PionShowerModel::ExN05PionShowerModel(G4String modelName, G4LogicalVolume* envelope)
: G4VFastSimulationModel(modelName, envelope)
{
fFakeStep = new G4Step();
fFakePreStepPoint = fFakeStep->GetPreStepPoint();
fFakePostStepPoint = fFakeStep->GetPostStepPoint();
fTouchableHandle = new G4TouchableHistory();
fpNavigator = new G4Navigator();
fNaviSetup = false;
}
ExN05PionShowerModel::ExN05PionShowerModel(G4String modelName)
: G4VFastSimulationModel(modelName)
{
fFakeStep = new G4Step();
fFakePreStepPoint = fFakeStep->GetPreStepPoint();
fFakePostStepPoint = fFakeStep->GetPostStepPoint();
fTouchableHandle = new G4TouchableHistory();
fpNavigator = new G4Navigator();
fNaviSetup = false;
}
ExN05PionShowerModel::~ExN05PionShowerModel()
{
delete fFakeStep;
delete fpNavigator;
}
G4bool ExN05PionShowerModel::IsApplicable(const G4ParticleDefinition& particleType)
{
return
&particleType == G4PionMinus::PionMinusDefinition() ||
&particleType == G4PionPlus::PionPlusDefinition();
}
G4bool ExN05PionShowerModel::ModelTrigger(const G4FastTrack& fastTrack)
{
// Applies the parameterisation always: ie as soon as the pion enters the envelope
return true;
}
void ExN05PionShowerModel::DoIt(const G4FastTrack& fastTrack,
G4FastStep& fastStep)
{
G4cout << "ExN05PionShowerModel::DoIt" << G4endl;
// Kill the parawmeterised particle:
fastStep.KillPrimaryTrack();
fastStep.SetPrimaryTrackPathLength(0.0);
fastStep.SetTotalEnergyDeposited(fastTrack.GetPrimaryTrack()->GetKineticEnergy());
// split into "energy spots" energy according to the shower shape:
Explode(fastTrack);
// and put those energy spots into the crystals:
BuildDetectorResponse();
}
void ExN05PionShowerModel::Explode(const G4FastTrack& fastTrack)
{
//-----------------------------------------------------
// Non-physical shower generated: exp along z and
// transverse.
//-----------------------------------------------------
// center of the shower, we put at the middle of the ghost:
G4ThreeVector showerCenter;
G4double distOut;
distOut = fastTrack.GetEnvelopeSolid()->
DistanceToOut(fastTrack.GetPrimaryTrackLocalPosition(),
fastTrack.GetPrimaryTrackLocalDirection());
showerCenter = fastTrack.GetPrimaryTrackLocalPosition() +
(distOut/2.)*fastTrack.GetPrimaryTrackLocalDirection();
showerCenter = fastTrack.GetInverseAffineTransformation()->
TransformPoint(showerCenter);
// axis of the shower, in global reference frame:
G4ThreeVector xShower, yShower, zShower;
zShower = fastTrack.GetPrimaryTrack()->GetMomentumDirection();
xShower = zShower.orthogonal();
yShower = zShower.cross(xShower);
// shoot the energy spots:
G4double Energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy();
G4int nSpot = 50;
G4double deposit = Energy/double(nSpot);;
ExN05EnergySpot eSpot;
eSpot.SetEnergy(deposit);
G4ThreeVector ePoint;
G4double z, r, phi;
for (int i = 0; i < nSpot; i++)
{
z = G4RandGauss::shoot(0,20*cm);
r = G4RandGauss::shoot(0,10*cm);
phi = RandFlat::shoot()*twopi;
ePoint = showerCenter +
z*zShower +
r*cos(phi)*xShower + r*sin(phi)*yShower;
eSpot.SetPosition(ePoint);
feSpotList.push_back(eSpot);
}
}
void ExN05PionShowerModel::BuildDetectorResponse()
{
// Does the assignation of the energy spots to the sensitive volumes:
for (size_t i = 0; i < feSpotList.size(); i++)
{
// Draw the energy spot:
G4Colour red(1.,0.,0.);
feSpotList[i].Draw(&red);
// feSpotList[i].Print();
// "converts" the energy spot into the fake
// G4Step to pass to sensitive detector:
AssignSpotAndCallHit(feSpotList[i]);
}
}
void ExN05PionShowerModel::AssignSpotAndCallHit(const ExN05EnergySpot &eSpot)
{
//
// "converts" the energy spot into the fake
// G4Step to pass to sensitive detector:
//
FillFakeStep(eSpot);
//
// call sensitive part: taken/adapted from the stepping:
// Send G4Step information to Hit/Dig if the volume is sensitive
//
G4VPhysicalVolume* pCurrentVolume =
fFakeStep->GetPreStepPoint()->GetPhysicalVolume();
G4VSensitiveDetector* pSensitive;
if( pCurrentVolume != 0 )
{
pSensitive = pCurrentVolume->GetLogicalVolume()->
GetSensitiveDetector();
if( pSensitive != 0 )
{
pSensitive->Hit(fFakeStep);
}
}
}
void ExN05PionShowerModel::FillFakeStep(const ExN05EnergySpot &eSpot)
{
//-----------------------------------------------------------
// find in which volume the spot is.
//-----------------------------------------------------------
if (!fNaviSetup)
{
fpNavigator->
SetWorldVolume(G4TransportationManager::GetTransportationManager()->
GetNavigatorForTracking()->GetWorldVolume());
fpNavigator->
LocateGlobalPointAndUpdateTouchable(eSpot.GetPosition(),
fTouchableHandle(),
false);
fNaviSetup = true;
}
else
{
fpNavigator->
LocateGlobalPointAndUpdateTouchable(eSpot.GetPosition(),
fTouchableHandle());
}
//--------------------------------------
// Fills attribute of the G4Step needed
// by our sensitive detector:
//-------------------------------------
// set touchable volume at PreStepPoint:
fFakePreStepPoint->SetTouchableHandle(fTouchableHandle);
// set total energy deposit:
fFakeStep->SetTotalEnergyDeposit(eSpot.GetEnergy());
}