Hi, I’m pretty new to C++ and Geant4 with only about a months experience. I’ve been tasked with creating a Silicon detector of 10mmx10mm in area and 0.3mm thickness which registers energy deposited and track length. I am using basic example, B4c as a template.
I have only edited the 2 cc files uploaded. In PrimaryGeneratorAction the source is an isotropic source of alpha particles, generated 10cm away from the origin which produces momenta values for px,py and pz to txt file. This is so I can plot them to prove they are isotropic. I don’t have any problems with this cc file.
The main issue comes with getting the Detector Construction(DC) right. The simulation compiles fine but as soon as the “beamOn” command is entered for any number of particles i.e. 1,10,100 etc the simulation crashes. I have copied the error messages in Ubuntu. There seems to be a problem with the “Hits” collection. I have also uploaded the current output in Geant4 which shows the 2 boxes (red and green). I have also uploaded a separate screenshot which is what I have been tasked to aim for where the beam of particles is working.
The advice I got to get the code working was “You can get rid of the parts that define the “calorimeter” and “layer”, and just make the “Absorber” and “Gap” boxes have the world logical volume as their mother volume. You can set the number of layers equal to one and then you don’t need to worry about this. I just did it myself and it took about 5 minutes, I have two boxes, one made of silicon, the other made of vacuum.”
I am struggling a lot to get this working. Also for B4c the values for energy deposited and track length are saved to a root file which I can then open using root to look at the histograms and ntuple files. But I haven’t been able to get onto this yet.
Any advice and help would be greatly appreciated.
Thanks
Sam Sharp
Ubuntu Error Message
Adding task 0 to task-group…
Adding task 1 to task-group…
Adding task 2 to task-group…
Adding task 3 to task-group…
Adding task 4 to task-group…
Adding task 5 to task-group…
Adding task 6 to task-group…
Adding task 7 to task-group…
Adding task 8 to task-group…
Adding task 9 to task-group…
G4WT3 > ### Run 0 starts on worker thread 3.
G4WT3 > … set ntuple merging row mode : row-wise - done
G4WT1 > ### Run 0 starts on worker thread 1.
G4WT1 > … set ntuple merging row mode : row-wise - done
G4WT3 > Using
G4WT3 > → Event 0 starts with initial seeds (13049039,61775110).
G4WT1 > Using
G4WT7 > ### Run 0 starts on worker thread 7.
G4WT3 > Event ID: 0 px: -0.0961084 py: -0.714342 pz: -0.693166
G4WT7 > … set ntuple merging row mode : row-wise - done
G4WT3 > is not found.
G4WT1 > Event ID: 10 px: 0.274454 py: 0.718181 pz: -0.639445
G4WT3 > is not found.
Segmentation fault (core dumped)
The problem is not in the detector construction. It looks more like it is trying to find a value that does not exist. You deleted/redefined geometry, did you make sure that those logical volumes weren’t referenced anywhere else or assume a certain number of layers?
Have you modified B4c’s EventAction.cc and/or RunAction.cc? This example uses custom hits collections with its own “Hit” classes, so it could be looking for these and not finding them as they are no longer added in the DetectorConstruction::ConstructSDandField member function.
The addition of your own primitive scorers looks o.k., so I think updating the EventAction.cc and RunAction.cc as appropriate to use these would be all that’s needed. Example B3a shows extraction of data from these at the Event/Run levels.
I suspect the idea was that in example B4c you would be able to edit only a few values to get you started. For example the “fNofLayers”, " absorberMaterial", and “gapMaterial” variables get you most of the way there already. You have changed the detector construction quite dramatically and so I suspect that fixing your issues as you have them now would require editting more than just the PrimaryGeneratorAction and DetectorConstruction files.
This was the original B4c Detector Construction File. Do u think you could walk me through exactly what needs editing in order to achieve the screenshot ? I
I suspect this is meant as a learning exercise so probably not a great idea to walk through how to do it. Your original instructions from your supervisor are correct. Everything you need to do is contained is DetectorConstruction and specifically DefineVolumes(). You only need to tweak parameters and possibly delete some function calls. You do not need to define new detectors. If you do so, that will almost certainly cause the kinds of problems you are seeing.
Probably where all of the problems originate with what you have done from your first attempt (which is way harder than just modifying parameters) stems likely from substitutions like this line:
G4MultiFunctionalDetector* absorberDetector = new G4MultiFunctionalDetector(absorberSDName);
which you are functionally replacing from B4C:
auto absoSD
= new CalorimeterSD("AbsorberSD", "AbsorberHitsCollection", fNofLayers);
CalorimeterSD is a custom class defined in CalorimeterSD.cc which is assumed in EventAction and RunAction. It is simply not possible to only tweak this one file and have the rest of the program function. You can certainly visualize the geometry of course because the issue will be when a particle enters those volumes.
DetectorConstruction.cc (3.3 KB)
This is where I’m at currently at however the ubuntu output is exactly the same with the absorber and gap hits not found. I’ve tried to keep it close to original and remove what was advised but it’s not working. Any help would be appreciated thanks.
It isn’t pretty but putting print statements in the code would be useful for telling you when the code fails if the program itself doesn’t give you any outputs as to why. At the very least it can help you isolate where the issue is since Geant4 programs tend to be fairly complex and interconnected.
One issue with your current detector construction is probably here in the EventAction:
// Get hits collections IDs (only once)
if (fAbsHCID == -1) {
fAbsHCID = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection");
fGapHCID = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection");
}
The collections are referenced explicitly by name to get their indexing IDs (and they are assumed to point to valid SDs with these names). If they do not exist, they will return null. And using null to index vectors will always lead to erratic behavior. You can either tweak EventAction or your DetectorConstruction.
I’d also keep the SD construction in SDConstructAndField method. It is a good habit to keep. When debugging it is usually a good idea to turn on verbose flags like uncommenting this line:
DetectorConstruction.cc (3.6 KB)
Thanks for the help guys my simulation is now working and isn’t crashing. I need to check if the detector is picking up energy deposited and track length but it should be ok.