LDMX Software
BertiniExactlyNProductsModel.cxx
1#include "SimCore/PhotoNuclearModels/BertiniExactlyNProductsModel.h"
2
3#include <G4Gamma.hh>
4#include <G4HadronInelasticProcess.hh>
5#include <numeric>
6
7namespace simcore {
8
9bool BertiniExactlyNProductsProcess::acceptEvent() const {
10 int secondaries{theParticleChange.GetNumberOfSecondaries()};
11 int n_hard{0};
12 std::vector<int> matching_count(pdg_ids_.size(), 0);
13
14 for (int i{0}; i < secondaries; ++i) {
15 const auto secondary{theParticleChange.GetSecondary(i)->GetParticle()};
16 const auto pdg_code{secondary->GetDefinition()->GetPDGEncoding()};
17 const auto energy{secondary->GetKineticEnergy()};
18
19 if (energy > threshold_) {
20 ++n_hard;
21 for (size_t j{0}; j < matching_count.size(); ++j) {
22 if (pdg_code == pdg_ids_[j]) ++matching_count[j];
23 }
24 }
25 }
26
27 int total_matched =
28 std::accumulate(matching_count.begin(), matching_count.end(), 0);
29
30 bool all_matched =
31 std::find(std::begin(matching_count), std::end(matching_count), 0) ==
32 std::end(matching_count);
33
34 if (total_matched == n_products_ && n_hard == total_matched &&
35 (!check_allmatch_ || all_matched)) {
36 return true;
37 }
38
39 return false;
40}
41
43 G4ProcessManager* process_manager) {
44 auto photo_nuclear_process{
45 new G4HadronInelasticProcess("photonNuclear", G4Gamma::Definition())};
46
47 auto model{new BertiniExactlyNProductsProcess{
48 threshold_, zmin_, emin_, pdg_ids_, check_allmatch_, n_products_}};
49 model->SetMaxEnergy(15 * CLHEP::GeV);
50 addPNCrossSectionData(photo_nuclear_process);
51 photo_nuclear_process->RegisterMe(model);
52 process_manager->AddDiscreteProcess(photo_nuclear_process);
53}
54} // namespace simcore
55
56DECLARE_PHOTONUCLEAR_MODEL(simcore::BertiniExactlyNProductsModel)
void constructGammaProcess(G4ProcessManager *processManager)
The primary part of the model interface, responsible for adding the desired G4HadronicInteraction to ...
virtual void addPNCrossSectionData(G4HadronInelasticProcess *process) const
Default implementation for adding XS data for the process.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...