10 #include <generators/modules/GeneratorPreselectionModule.h>
11 #include <framework/gearbox/Unit.h>
29 setDescription(
"Preselection based on generator truth information. Returns 0 if no cut have been passed, 1 if only the charged cut has been passed, 10 if only the photon cut has been passed, and 11 if both charged and photon cuts have been passed.");
30 setPropertyFlags(c_ParallelProcessingCertified);
32 addParam(
"nChargedMin", m_nChargedMin,
"minimum number of charged particles", 0);
33 addParam(
"nChargedMax", m_nChargedMax,
"maximum number of charged particles", 999);
34 addParam(
"MinChargedP", m_MinChargedP,
"minimum charged momentum [GeV]", 0.25);
35 addParam(
"MinChargedPt", m_MinChargedPt,
"minimum charged transverse momentum (pt) [GeV]", 0.1);
36 addParam(
"MinChargedTheta", m_MinChargedTheta,
"minimum polar angle of charged particle [deg]", 17.);
37 addParam(
"MaxChargedTheta", m_MaxChargedTheta,
"maximum polar angle of charged particle [deg]", 150.);
38 addParam(
"applyInCMS", m_applyInCMS,
"if true apply the P,Pt,theta, and energy cuts in the center of mass frame",
false);
39 addParam(
"stableParticles", m_stableParticles,
"if true apply the selection criteria for stable particles in the generator",
false);
41 addParam(
"nPhotonMin", m_nPhotonMin,
"minimum number of photons", 0);
42 addParam(
"nPhotonMax", m_nPhotonMax,
"maximum number of photons", 999);
43 addParam(
"MinPhotonEnergy", m_MinPhotonEnergy,
"minimum photon energy [GeV]", -1.);
44 addParam(
"MinPhotonTheta", m_MinPhotonTheta,
"minimum polar angle of photon [deg]", 15.);
45 addParam(
"MaxPhotonTheta", m_MaxPhotonTheta,
"maximum polar angle of photon [deg]", 165.);
48 void GeneratorPreselectionModule::initialize()
50 B2DEBUG(29,
"GeneratorPreselectionModule initialize");
53 m_MinChargedTheta *= Unit::deg;
54 m_MaxChargedTheta *= Unit::deg;
55 m_MinPhotonTheta *= Unit::deg;
56 m_MaxPhotonTheta *= Unit::deg;
58 m_mcparticles.isRequired(m_particleList);
60 m_initial.isRequired();
65 void GeneratorPreselectionModule::event()
70 for (
int i = 0; i < m_mcparticles.getEntries(); i++) {
76 B2DEBUG(250,
"number of charged passing cuts: " << m_nCharged);
77 B2DEBUG(250,
"number of photons passing cuts: " << m_nPhoton);
81 setReturnValue(retvalue);
82 if (m_nCharged >= m_nChargedMin && m_nCharged <= m_nChargedMax) {
85 if (m_nPhoton >= m_nPhotonMin && m_nPhoton <= m_nPhotonMax) {
89 B2DEBUG(250,
"return value: " << retvalue);
90 setReturnValue(retvalue);
92 if (m_resultCounter.find(retvalue) == m_resultCounter.end()) {
93 m_resultCounter[retvalue] = 1;
95 m_resultCounter[retvalue] += 1;
99 void GeneratorPreselectionModule::checkParticle(
const MCParticle& mc)
101 if (!mc.hasStatus(MCParticle::c_PrimaryParticle))
return;
102 if (mc.hasStatus(MCParticle::c_Initial) or mc.hasStatus(MCParticle::c_IsVirtual))
return;
103 if (m_stableParticles)
104 if (!mc.hasStatus(MCParticle::c_StableInGenerator))
return;
106 const TVector3& p = mc.getMomentum();
107 double energy = mc.getEnergy();
108 double mom = p.Mag();
109 double theta = p.Theta();
112 const TLorentzVector p_cms = m_initial->getLabToCMS() * mc.get4Vector();
115 theta = p_cms.Theta();
118 if (mc.getPDG() == 22) {
119 B2DEBUG(250,
"E = " << energy <<
" theta=" << theta <<
" thetamin=" << m_MinPhotonTheta <<
" thetamax=" << m_MaxPhotonTheta);
120 if (energy >= m_MinPhotonEnergy && theta >= m_MinPhotonTheta && theta <= m_MaxPhotonTheta) {
125 if (abs(mc.getCharge()) > 0.) {
126 B2DEBUG(250,
"pt = " << p.Pt() <<
" p=" << mom <<
" theta=" << theta <<
" thetamin=" << m_MinChargedTheta <<
" thetamax=" <<
128 if (mom >= m_MinChargedP && p.Pt() >= m_MinChargedPt && theta >= m_MinChargedTheta && theta <= m_MaxChargedTheta) {
135 void GeneratorPreselectionModule::terminate()
137 B2RESULT(
"Final results of the preselection module:");
138 for (
const auto& finalResult : m_resultCounter) {
139 B2RESULT(
"\tPreselection with result " << finalResult.first <<
": " << finalResult.second <<
" times.");
141 const unsigned int sumCounters = std::accumulate(m_resultCounter.begin(), m_resultCounter.end(), 0, [](
auto lhs,
auto rhs) {
142 return lhs + rhs.second;
145 B2RESULT(
"Total number of tested events: " << sumCounters);
A Class to store the Monte Carlo particle information.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.