# Multi target in the B1 example

Hi everyone,I should simulate a multitarget system. i.e. currently I’ve a single carbon target 6cm thikness.

`````` // Envelope parameters
//
G4double env_sizeXY = 20*cm, env_sizeZ = 6*cm;
G4Material* env_mat = nist->FindOrBuildMaterial("G4_GRAPHITE");
``````

I would like to simulate a multitarget system (for example 5 targets 0.5 cm thikness spaced 0.5 cm).
How can I add more targets in my code?

Thanks

Hello Faca,

You can do this in a few different ways that are shown in some examples… But one simple way is to use a for loop over the G4PVPlacement function. If j is your iterator, make sure you put j + 1 in the copy input. There are some examples as such in advanced.

Best,

Paul

Hi @marmolRBG, thank you for your reply. This is my G4PVPlacement function in my B1 example:

``````G4VPhysicalVolume* physWorld =
new G4PVPlacement(0,                     //no rotation
G4ThreeVector(),       //at (0,0,0)
logicWorld,            //its logical volume
"World",               //its name
0,                     //its mother  volume
false,                 //no boolean operation
0,                     //copy number
checkOverlaps);        //overlaps checking
``````

I found this code in the amsEcal advanced example:

``````for (G4int k=0; k<nbOfLayers; k++) {
Xcenter += layerThickness;
Ycenter  = - Ycenter;
new G4PVPlacement(0,		   		//no rotation
G4ThreeVector(Xcenter,Ycenter,0.),    //position
lvol_layer,     		   	//logical volume
"layer",	   			//name
lvol_module,        		//mother
false,             		//no boulean operat
k+1);               		//copy number

}
``````

So, to get 5 targets, I wrote

``````for (G4int k=0; k<5; k++) {
G4VPhysicalVolume* physWorld =
new G4PVPlacement(0,                     //no rotation
G4ThreeVector(),       //at (0,0,0)
logicWorld,            //its logical volume
"World",               //its name
0,                     //its mother  volume
false,                 //no boolean operation
k+1,                     //copy number
checkOverlaps);        //overlaps checking
}
``````

but I get the error in the printscreen. In italian, it means that physWorld isn’t declared, but isnt’t it declared in this line

`G4VPhysicalVolume* physWorld`

Moreover, withoud the for cycle, it works…

Hi,

I think you need to check the “return” part, it seems “physWorld” should be return to “Construct” in the geometry setting. If you put “G4VPhysicalVolume* physWorld” in the your loop scope, it will show this error.

Hope this is helpful for you.
Cheers,
Ye

Hi @ychen871027, you are right there was

``````return  physWorld
``````

at the end of the code, so I added it in the for cycle in this way

``````for (G4int k=0; k<5; k++) {
G4VPhysicalVolume* physWorld =
new G4PVPlacement(0,                     //no rotation
G4ThreeVector(),       //at (0,0,0)
logicWorld,            //its logical volume
"World",               //its name
0,                     //its mother  volume
false,                 //no boolean operation
k+1,                     //copy number
checkOverlaps);        //overlaps checking
return physWorld;
}
``````

But I fot this warning (it means theare are some paths not returning values!

The I saw there is one other function in which there is the G4VPhysicalVolume and it is

``````     G4LogicalVolume* logicEnv =
new G4LogicalVolume(solidEnv,            //its solid
env_mat,             //its material
"Envelope");         //its name

new G4PVPlacement(0,                       //no rotation
G4ThreeVector(),         //at (0,0,0)
logicEnv,                //its logical volume
"Envelope",              //its name
logicWorld,              //its mother  volume
false,                   //no boolean operation
0,                       //copy number
checkOverlaps);          //overlaps checking
``````

so I putted it in a for cycle too in this way

``````  new G4Box("Envelope",                    //its name
0.5*env_sizeXY, 0.5*env_sizeXY, 0.5*env_sizeZ); //its size

G4LogicalVolume* logicEnv =
new G4LogicalVolume(solidEnv,            //its solid
env_mat,             //its material
"Envelope");         //its name
for (G4int j=0; j<5; j++) {
new G4PVPlacement(0,                       //no rotation
G4ThreeVector(),         //at (0,0,0)
logicEnv,                //its logical volume
"Envelope",              //its name
logicWorld,              //its mother  volume
false,                   //no boolean operation
j+1,                       //copy number
checkOverlaps);          //overlaps checking
}
``````

But I also get a warning

B1DetectorConstruction.cc (9.4 KB)

Hi,

If you put that into your loop scope, you will be trying to return multiple world.
It is meaningless.

The geometry construction is like below.

1. you build a “world” like our real world.
2. In the world, you build your detector
3. In your detector, you could build sub-detector