Position problem in targets

Hello, in the B1DetectorConstruction I definend 2 circular targets along the z-axis. They have radius 0.75cm, thikness 0.3cm and the distance betwenn them is 2cm.

This is my code

G4double pi = 3.14159265358979323846;
  G4double pRMin = 0., pRMax = 0.75*cm, pDz = 1.5*mm, pSPhi = 0., pDPhi = 2*pi;

G4Tubs* solidEnv =    
new G4Tubs("Envelope",                    //its name
    pRMin, pRMax, pDz, pSPhi, pDPhi);    //its size*/
    
G4Tubs* solidEnv2 =    
new G4Tubs("Envelope2",                    //its name
    pRMin, pRMax, pDz, pSPhi, pDPhi);    //its size*/
    
G4LogicalVolume* logicEnv =                         
new G4LogicalVolume(solidEnv,            //its solid
                    env_mat,             //its material
                    "Envelope");         //its name
                    
G4LogicalVolume* logicEnv2 =                         
new G4LogicalVolume(solidEnv,            //its solid
                    env_mat,             //its material
                    "Envelope2");         //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
                    
     new G4PVPlacement(0,                       //no rotation
                        G4ThreeVector(0,0,2.3*cm),         //at (0,0,2.3) 2.3= 0.3*cm+2*cm
                        logicEnv2,                //its logical volume
                        "Envelope2",              //its name
                        logicWorld,              //its mother  volume
                        false,                   //no boolean operation
                        0,                       //copy number
                        checkOverlaps);          //overlaps checking

 fScoringVolume = logicEnv;
  fScoringVolume2 = logicEnv2;

B1DetectorConstruction.cc (10.0 KB)

Given that the thickness of the targets is 0.3cm and the the 2 targets are placed at at z=0cm and z=2.3cm, I expect that the volumes are defined in the range z€[0, 0.3]cm for the first target adn z€[2.3, 2.6]cm for the second… but when I store the z position in the stepping action,

double PosDirz = step->GetTrack()->GetPosition().z();

I get these plots having positions out of my z range

First target

Second target

and also when I plot the released energy in function of the endstepposition along the z axis
double EndStepPosz2 = step->GetPostStepPoint()->GetPosition().z();
I get points out of my z-range…

@anna you helped me to write the code for the detector construction…maybe, do you know the reason because of I get points out of the z-range?
Thank you

The default unit of length in Geant4 is mm, so that is what you probably plot (not cm despite the label).
Also, the placement of volumes refers to the centre of volume, so you have volumes located around z=0 and z=2.3 cm (so ±0.15cm).

Thank you @anna but if they are mm, why in the volume2 do I get hits at z=0 ? By your message I understand that my volume 2 is in the range [2.15; 2.45]…

Please don’t ask the same question in multiple forums.

Hi @mkelsey thank you. I didn’t ask the same question in multiple topics. This is the topic about this problem in the other topic, you said me to plot the released energy vs the hit point and I said you that I did hit but I noticed this problem linking you this topic. Anyway, regarding of your questions:

  1. I used double PosDirz = step->GetTrack()->GetPosition().z();
  2. The targets are named Envelope and Envelope2

you can see the code in the first post. Thank you

You have exactly 5 x 0 entries in both histograms, which corresponds to the number of events. I’d suggest you check if you always fill in the ntuple column before adding a row. It may be that you add one additional row per each event (with unfilled columns).

Thank you @anna do you mean to replace

if (volume == fScoringVolume) {
			int pdg = step->GetTrack()->GetParticleDefinition()->GetPDGEncoding();
			 analysisManager->FillNtupleDColumn(0,0, pdg);
			 double kinEnergy = step->GetTrack()->GetDynamicParticle()->GetKineticEnergy();
			 analysisManager->FillNtupleDColumn(0,1, kinEnergy);
			 double MomDirx = step->GetTrack()->GetMomentumDirection().x();
			 analysisManager->FillNtupleDColumn(0,2, MomDirx);
			 double MomDiry = step->GetTrack()->GetMomentumDirection().y();
			 analysisManager->FillNtupleDColumn(0,3, MomDiry);
			 double MomDirz = step->GetTrack()->GetMomentumDirection().z();
			 analysisManager->FillNtupleDColumn(0,4, MomDirz); 
			 double PosDirx = step->GetTrack()->GetPosition().x();
			 analysisManager->FillNtupleDColumn(0,5, PosDirx); 
			 double PosDiry = step->GetTrack()->GetPosition().y();
			 analysisManager->FillNtupleDColumn(0,6, PosDiry); 
			 double PosDirz = step->GetTrack()->GetPosition().z();
			 analysisManager->FillNtupleDColumn(0,7, PosDirz); 
			 double EndStepPosx = step->GetPostStepPoint()->GetPosition().x();
			 analysisManager->FillNtupleDColumn(0,8, EndStepPosx); 
			 double EndStepPosy = step->GetPostStepPoint()->GetPosition().y();
			 analysisManager->FillNtupleDColumn(0,9, EndStepPosy); 
			 double EndStepPosz = step->GetPostStepPoint()->GetPosition().z();
			 analysisManager->FillNtupleDColumn(0,10, EndStepPosz); 
			  analysisManager->AddNtupleRow();  

}

by something like this?

   if (volume == fScoringVolume) {
    			int pdg = step->GetTrack()->GetParticleDefinition()->GetPDGEncoding();
    			 analysisManager->FillNtupleDColumn(0,0, pdg);
  analysisManager->AddNtupleRow();   
    			 double kinEnergy = step->GetTrack()->GetDynamicParticle()->GetKineticEnergy();
    			 analysisManager->FillNtupleDColumn(0,1, kinEnergy);
  analysisManager->AddNtupleRow();   
    			 double MomDirx = step->GetTrack()->GetMomentumDirection().x();
    			 analysisManager->FillNtupleDColumn(0,2, MomDirx);
  analysisManager->AddNtupleRow();   
    			 double MomDiry = step->GetTrack()->GetMomentumDirection().y();
    			 analysisManager->FillNtupleDColumn(0,3, MomDiry);
  analysisManager->AddNtupleRow();   
    			 double MomDirz = step->GetTrack()->GetMomentumDirection().z();
    			 analysisManager->FillNtupleDColumn(0,4, MomDirz); 
  analysisManager->AddNtupleRow();   
    			 double PosDirx = step->GetTrack()->GetPosition().x();
    			 analysisManager->FillNtupleDColumn(0,5, PosDirx); 
  analysisManager->AddNtupleRow();   
    			 double PosDiry = step->GetTrack()->GetPosition().y();
    			 analysisManager->FillNtupleDColumn(0,6, PosDiry); 
  analysisManager->AddNtupleRow();   
    			 double PosDirz = step->GetTrack()->GetPosition().z();
    			 analysisManager->FillNtupleDColumn(0,7, PosDirz); 
  analysisManager->AddNtupleRow();   
    			 double EndStepPosx = step->GetPostStepPoint()->GetPosition().x();
    			 analysisManager->FillNtupleDColumn(0,8, EndStepPosx); 
  analysisManager->AddNtupleRow();   
    			 double EndStepPosy = step->GetPostStepPoint()->GetPosition().y();
    			 analysisManager->FillNtupleDColumn(0,9, EndStepPosy); 
  analysisManager->AddNtupleRow();   
    			 double EndStepPosz = step->GetPostStepPoint()->GetPosition().z();
    			 analysisManager->FillNtupleDColumn(0,10, EndStepPosz); 
    			  analysisManager->AddNtupleRow();

Did you try it out? It’s quite the opposite. What I meant is that you should check carefully where you call analysisManager->AddNtupleRow() and given that you have multiple ntuples, to check if you add rows to a correct ntuple (with all columns filled in first), not only in the stepping action.

Thank you @anna I filled the 2 Ntuples also in the B1EventAction

 //fill ntupla 0
  analysisManager->FillNtupleDColumn(0,11, fEdep);
 analysisManager->AddNtupleRow(); 
   // fill ntupla 1
  analysisManager->FillNtupleDColumn(1,11, fEdep2Tar);
  analysisManager->AddNtupleRow(1);  

so, I moved this code to the SteppingAction inside the and now I get 7 events (instead of 12) and I don’t get hits @z=0.

As I said in this topic 2 circular targets 7 events is according to the verbosity, but in this way I get 0 released energy in the 2 volumes for these 7 events


Instead, in the Ntupla for the events I get 5 events and a NO 0 released energy. So I don’t understand:

  1. Why do I get 7 events in the stepping action and 5 in the eventsaction?
  2. Do I get 0 energy in the stepping action because of some error?

You fill your ntuple in the stepping action for each step that fulfils a condition (step within a volume of interest). Getting 7 entries means that 5 steps happened within the volume.
Event action is invoked once per event, and you run 5 events (/run/beamOn 5), hence you were getting additional 5 entries, one per each event.
I am not sure what is plotted on those histograms and how do you fill them in, so it’s hard to say why do you have only 0 entries (I’d suggest checking if you fill in the appropriate column of ntuple).

Thank you @anna
This is my ntupla in the RunAction

analysisManager->CreateNtuple("B1Volume1", "Volume 1");
  analysisManager->CreateNtupleDColumn("ParticleID");
  analysisManager->CreateNtupleDColumn("kinEnergy");
  analysisManager->CreateNtupleDColumn("MomentumDirection.x");
  analysisManager->CreateNtupleDColumn("MomentumDirection.y");
  analysisManager->CreateNtupleDColumn("MomentumDirection.z");
  analysisManager->CreateNtupleDColumn("PositionDirection.x");
  analysisManager->CreateNtupleDColumn("PositionDirection.y");
  analysisManager->CreateNtupleDColumn("PositionDirection.z");
  analysisManager->CreateNtupleDColumn("EndStepPos.x");
  analysisManager->CreateNtupleDColumn("EndStepPos.y");
  analysisManager->CreateNtupleDColumn("EndStepPos.z");
  analysisManager->CreateNtupleDColumn("ReleasedEnergy");
  analysisManager->FinishNtuple(); 

So, the branch to store the Released Energy is the branch number 11, indeed, in the SteppingAction I wrote
analysisManager->FillNtupleDColumn(1,11, fEdep2Tar);

Anyway, maybe I understood the problem

In the B1SteppingAction, I’ve this code

    if (volume == fScoringVolume) {
  G4double edepStep = step->GetTotalEnergyDeposit();
  fEventAction->AddEdep(edepStep);
	}
	if (volume == fScoringVolume2) {
  G4double edepStep2 = step->GetTotalEnergyDeposit();
  fEventAction->AddEdep2(edepStep2);
	}

and in the B1EventAction
so it looks like to me that I increase the energy ONLY in the eventaction and NOT in the steppingAction too! So maybe I need a code to increase the released energy in the stepping action too…

Then I did this way (just an example for the target one)

if (volume == fScoringVolume) {

G4double edepStep = step->GetTotalEnergyDeposit();
fEventAction->AddEdep(edepStep);
int pdg = step->GetTrack()->GetParticleDefinition()->GetPDGEncoding();
analysisManager->FillNtupleDColumn(0,0, pdg);
double kinEnergy = step->GetTrack()->GetDynamicParticle()->GetKineticEnergy();
analysisManager->FillNtupleDColumn(0,1, kinEnergy);
double MomDirx = step->GetTrack()->GetMomentumDirection().x();
analysisManager->FillNtupleDColumn(0,2, MomDirx);
double MomDiry = step->GetTrack()->GetMomentumDirection().y();
analysisManager->FillNtupleDColumn(0,3, MomDiry);
double MomDirz = step->GetTrack()->GetMomentumDirection().z();
analysisManager->FillNtupleDColumn(0,4, MomDirz);
double PosDirx = step->GetTrack()->GetPosition().x();
analysisManager->FillNtupleDColumn(0,5, PosDirx);
double PosDiry = step->GetTrack()->GetPosition().y();
analysisManager->FillNtupleDColumn(0,6, PosDiry);
double PosDirz = step->GetTrack()->GetPosition().z();
analysisManager->FillNtupleDColumn(0,7, PosDirz);
double EndStepPosx = step->GetPostStepPoint()->GetPosition().x();
analysisManager->FillNtupleDColumn(0,8, EndStepPosx);
double EndStepPosy = step->GetPostStepPoint()->GetPosition().y();
analysisManager->FillNtupleDColumn(0,9, EndStepPosy);
double EndStepPosz = step->GetPostStepPoint()->GetPosition().z();
analysisManager->FillNtupleDColumn(0,10, EndStepPosz);
analysisManager->FillNtupleDColumn(0,11, edepStep);
analysisManager->AddNtupleRow();
}

and now I get no zero energy! Is it ok?