Multiple Primary Vertices per event and Primitive Scorer

Hi,
for my application, I found it to be much faster to generate multiple primary vertices per event, as only a very small fraction of particles find their way to the sensitive parts of the geometry.

void myPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) {
    for(G4int i=0; i<fPackageSize; i++) {
        fGeneralParticleSource->GeneratePrimaryVertex(anEvent);
    }
}

now using MultiFunctionalDetector / primitive scorer inspired by example B3a, to get the dose in some object in EndOfEventAction:

//Dose deposit
G4double dose = 0.;

G4THitsMap<G4double>* evtMap = (G4THitsMap<G4double>*)(HCE->GetHC(fCollID_dose));

std::map<G4int,G4double*>::iterator itr;
for (itr = evtMap->GetMap()->begin(); itr != evtMap->GetMap()->end(); itr++) {
  dose = *(itr->second);
}

it seems there is either 0 or a maximum of 1 entry in evtMap (evtMap->GetMap()->size())
is that to be expected? The for-loop seems to me to suggests otherwise…

Thanks in advance :slight_smile:

the loop is not necessary in the example, looks like it was just convenient to copy the structure from the codeblock before. for multiple placements, it would then iterate over all copy numbers (///G4int copyNb = (itr->first); is literally the line before :smiley:), but require extra treatment of each *(itr->second) value…