# How to use if conditions in geant4, restricting it to a certain volume of the world?

Let’s suppose i want that some information, maybe electric field, maybe magnetic field or other field, be restricted only to a certain region of the world volume. How could i achieve this?

I have read a code that is like this:

``````if (20.003*mm >= sqrt(pow(Point[0]*mm,2)+pow(Point[1]*mm,2))) {
.... //where ... here would contain the information to be restricted only at the positions above.
}
``````

So, is that the right way to restrict a information under some region of the space? In this case, a disk. What does it means Point[0] or Point[1]?
Could it be something like that?

``````if (20.003*mm >= sqrt(pow(x,2)+pow(y,2))) {
.... //where ... here would contain the information to be restricted only at the positions above.
}
``````

Generally I do that in post-processing/analysis of the file generated by G4. In your case, may be you can implement that in `SteppingAction.cc` and use `step->GetPreStepPoint()` or `step->GetPostStepPoint()` and restrict the fetched point (`x,y,z`) to the physical domain of your interest?

See following URLs:

``````G4bool Mensdec::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
{
G4Track *track = aStep->GetTrack();
G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
G4ThreeVector particle = preStepPoint->GetPosition();
float x = particle[0]*mm;
float y = particle[1]*mm;
float z = particle[2]*mm;
}

void Campo::GetFieldValue(const G4double Point[4], G4double field[6]) const{

field[0]=0.*tesla;
field[1]=0.*tesla;
field[2]=0.*tesla;
field[5]=0.*volt/mm;

if (20.003*mm >= sqrt(pow(x,2)+pow(y,2))) {
field[3]=0;
field[4]=0;
}
else if (sqrt(pow(x,2)+pow(y,2))>20.003*mm and 91.003*mm>=sqrt(pow(x,2)+pow(y,2))) {
auto V = -2530*volt;
auto a = (1800*volt+V)/(log(20.003/91.003));
field[3]=a*(x/(pow(y,2)+pow(x,2)));
field[4]=a*(y/(pow(y,2)+pow(x,2)));
}
else if(sqrt(pow(x,2)+pow(y,2))>91.003*mm){
auto V = -2530*volt;
auto b = -(2550*volt+V)/(log(91.003/96.003));
field[3]=b*(x/(pow(y,2)+pow(x,2)));
field[4]=b*(y/(pow(y,2)+pow(x,2)));
}
}
``````

Thank you.
I have writed this. Do you think is it right? The compiler run and the visualization open as well.