ComPWA
Common Partial-Wave-Analysis Framework
EvtGenGenerator.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015, 2017 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
5 #include "EvtGenGenerator.hpp"
6 
7 #include "Core/Properties.hpp"
8 #include "Core/Random.hpp"
10 
11 #include "ThirdParty/EvtGen/EvtGenKine.hh"
12 #include "ThirdParty/EvtGen/EvtRandom.hh"
13 #include "ThirdParty/EvtGen/EvtVector4R.hh"
14 
15 namespace ComPWA {
16 namespace Data {
17 namespace EvtGen {
18 
20  const ComPWA::FourMomentum &CMSP4_,
21  const std::vector<double> &FinalStateMasses_,
22  const std::vector<ComPWA::pid> &FinalStatePIDs_)
23  : CMSP4(CMSP4_), FinalStateMasses(FinalStateMasses_),
24  FinalStatePIDs(FinalStatePIDs_),
25  RandomEngine(new EvtGenStdRandomEngine()) {
26  if (FinalStateMasses.size() < 2)
27  throw std::runtime_error("EvtGenGenerator::EvtGenGenerator() | at least "
28  "two final state particles are required!");
29  EvtRandom::setRandomEngine(RandomEngine.get());
30 }
31 
34  : EvtGenGenerator(KinematicsInfo.getInitialStateFourMomentum(),
35  KinematicsInfo.getFinalStateMasses(),
36  KinematicsInfo.getFinalStatePIDs()) {}
37 
39 EvtGenGenerator::generate(unsigned int NumberOfEvents,
40  UniformRealNumberGenerator &RandomGenerator) const {
41  RandomEngine->setRandomNumberGenerator(RandomGenerator);
42 
43  EventCollection GeneratedPhsp{FinalStatePIDs};
44 
45  for (unsigned int i = 0; i < NumberOfEvents; ++i) {
46  std::vector<EvtVector4R> FourVectors(FinalStateMasses.size());
47 
48  double weight = EvtGenKine::PhaseSpace(
49  FinalStateMasses.size(), (double *)(&FinalStateMasses[0]), // const cast
50  &(FourVectors[0]), CMSP4.invariantMass());
51 
52  double ampRnd = RandomGenerator();
53  if (ampRnd > weight) {
54  --i;
55  continue;
56  }
57 
58  std::vector<FourMomentum> FourMomenta;
59  for (auto const &p4 : FourVectors) {
60  FourMomenta.push_back(
61  FourMomentum(p4.get(1), p4.get(2), p4.get(3), p4.get(0)));
62  }
63 
64  // Reset weights: weights are taken into account by hit&miss. The
65  // resulting sample is therefore unweighted
66  GeneratedPhsp.Events.push_back(ComPWA::Event{FourMomenta, 1.0});
67  }
68  return GeneratedPhsp;
69 }
70 
71 EvtGenStdRandomEngine::EvtGenStdRandomEngine() : NumberGenerator(nullptr) {}
72 
74  UniformRealNumberGenerator &NumberGenerator_) {
75  NumberGenerator = &NumberGenerator_;
76 }
77 double EvtGenStdRandomEngine::random() { return NumberGenerator->operator()(); }
78 
79 } // namespace EvtGen
80 } // namespace Data
81 } // namespace ComPWA
ComPWA four momentum class.
std::vector< ComPWA::pid > FinalStatePIDs
double invariantMass() const
void setRandomNumberGenerator(UniformRealNumberGenerator &NumberGenerator_)
EvtGenGenerator(const ComPWA::FourMomentum &CMSP4_, const std::vector< double > &FinalStateMasses_, const std::vector< ComPWA::pid > &FinalStatePIDs_)
UniformRealNumberGenerator * NumberGenerator
ComPWA::EventCollection generate(unsigned int NumberOfEvents, UniformRealNumberGenerator &RandomGenerator) const final
Data structure containing all kinematic information of a physics event.
Definition: Event.hpp:20
std::unique_ptr< ComPWA::Data::EvtGen::EvtGenStdRandomEngine > RandomEngine