291{
292
293
298 HCE->GetHC(SDman->GetCollectionID("edep")));
299
302 HCE->GetHC(SDman->GetCollectionID("current_electron")));
303
306 HCE->GetHC(SDman->GetCollectionID("current_proton")));
307
310 HCE->GetHC(SDman->GetCollectionID("current_gamma")));
311
312
313
314 G4double totEdep=0;
315 std::size_t i;
316 for (i=0;i<edepCollection->entries();++i)
317 totEdep+=(*edepCollection)[i]->GetValue()*
318 (*edepCollection)[i]->GetWeight();
319
320
321
322
324 G4AdjointSimManager::GetInstance();
325
326 size_t nb_adj_track =
327 theAdjointSimManager->GetNbOfAdointTracksReachingTheExternalSurface();
328 G4double total_normalised_weight = 0.;
329
330
331
332 for (std::size_t j=0;j<nb_adj_track;++j) {
333
334 G4int pdg_nb =theAdjointSimManager
335 ->GetFwdParticlePDGEncodingAtEndOfLastAdjointTrack(j);
336 G4double prim_ekin=theAdjointSimManager
337 ->GetEkinAtEndOfLastAdjointTrack(j);
338 G4double adj_weight=theAdjointSimManager
339 ->GetWeightAtEndOfLastAdjointTrack(j);
340
341
342
343
344 G4double normalised_weight = 0.;
347 normalised_weight =
349 total_normalised_weight += normalised_weight;
350
351
352
353 G4H1* edep_rmatrix =0;
354 G4H2* electron_current_rmatrix =0;
355 G4H2* gamma_current_rmatrix =0;
356 G4H2* proton_current_rmatrix =0;
357
358 if (pdg_nb == G4Electron::Electron()->GetPDGEncoding()){
360 electron_current_rmatrix =
363 }
364 else if (pdg_nb == G4Gamma::Gamma()->GetPDGEncoding()){
365
369 }
370 else if (pdg_nb == G4Proton::Proton()->GetPDGEncoding()){
371
373 electron_current_rmatrix =
377 }
378
379
381 ->fill(prim_ekin,totEdep*normalised_weight);
382
383
384 edep_rmatrix->fill(prim_ekin,totEdep*adj_weight/cm2);
385
386
387
388
389 for (i=0;i<electronCurrentCollection->entries();++i) {
390 G4double ekin =(*electronCurrentCollection)[i]->GetValue();
391 G4double weight=(*electronCurrentCollection)[i]->GetWeight();
393 electron_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/cm2);
394 }
395 for (i=0;i<protonCurrentCollection->entries();++i) {
396 G4double ekin =(*protonCurrentCollection)[i]->GetValue();
397 G4double weight=(*protonCurrentCollection)[i]->GetWeight();
399 proton_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/cm2);
400 }
401 for (i=0;i<gammaCurrentCollection->entries();++i) {
402 G4double ekin =(*gammaCurrentCollection)[i]->GetValue();
403 G4double weight=(*gammaCurrentCollection)[i]->GetWeight();
405 gamma_current_rmatrix->fill(prim_ekin,ekin,weight*adj_weight/cm2);
406 }
407 }
408
409
410
411 G4bool new_mean_computed=false;
412 if (totEdep>0.){
413 if (total_normalised_weight>0.){
414 G4double edep=totEdep* total_normalised_weight;
415
416
417
418 G4double new_mean(0.0), new_error(0.0);
423 G4double new_relative_error = 1.;
424 if ( new_error >0) new_relative_error = new_error/ new_mean;
426 G4cout<<"Potential wrong adjoint weight!"<<std::endl;
427 G4cout<<"The results of this event will not be registered!"
428 <<std::endl;
429 G4cout<<
"previous mean edep [MeV] "<<
fMean_edep<<std::endl;
431 G4cout<<"new rejected mean edep [MeV] "<< new_mean<<std::endl;
432 G4cout<<"new rejected relative error "<< new_relative_error
433 <<std::endl;
437 return;
438 }
439 else {
443 new_mean_computed=true;
444 }
445
446 }
447
448 if (!new_mean_computed){
451 }
452 }
453}
G4double PrimDiffAndDirFluxForAdjointSim(G4double prim_energy)