12 #include <analysis/modules/ParticleCombiner/ParticleCombinerModule.h>
15 #include <framework/logging/Logger.h>
18 #include <analysis/dataobjects/Particle.h>
21 #include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
24 #include <analysis/DecayDescriptor/ParticleListName.h>
25 #include <analysis/utility/EvtPDLUtil.h>
26 #include <analysis/utility/PCmsLabTransform.h>
53 setDescription(
"Makes particle combinations");
54 setPropertyFlags(c_ParallelProcessingCertified);
57 addParam(
"decayString", m_decayString,
58 "Input DecayDescriptor string (see :ref:`DecayString`).");
59 addParam(
"cut", m_cutParameter,
"Selection criteria to be applied", std::string(
""));
60 addParam(
"maximumNumberOfCandidates", m_maximumNumberOfCandidates,
61 "Max. number of candidates reconstructed. By default, if the limit is reached no candidates will be produced.\n"
62 "This behaviour can be changed by \'ignoreIfTooManyCandidates\' flag.", 10000);
64 addParam(
"ignoreIfTooManyCandidates", m_ignoreIfTooManyCandidates,
65 "Don't reconstruct channel if more candidates than given by \'maximumNumberOfCandidates\' are produced.",
true);
67 addParam(
"decayMode", m_decayModeID,
"User-specified decay mode identifier (saved in 'decayModeID' extra-info for each Particle)",
69 addParam(
"writeOut", m_writeOut,
70 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.",
false);
71 addParam(
"recoilParticleType", m_recoilParticleType,
72 "If not equal 0, the mother Particle is reconstructed in the recoil against the daughter particles.\n"
73 "In the case of the following decay chain M -> D1 D2 ... Dn and\n\n"
75 " a) recoilParticleType = 1: \n\n"
76 " - the mother momentum is given by: p(M) = p(e+e-) - p(D1) - p(D2) - ... - p(DN)\n"
77 " - D1, D2, ..., DN are attached as daughters of M\n\n"
78 " b) recoilParticleType = 2: \n\n"
79 " - the mother momentum is given by: p(M) = p(D1) - p(D2) - ... - p(DN)\n"
80 " - D1, D2, ..., DN are attached as daughters of M\n\n" , 0);
81 addParam(
"chargeConjugation", m_chargeConjugation,
82 "If true, the charge-conjugated mode will be reconstructed as well",
true);
83 addParam(
"allowChargeViolation", m_allowChargeViolation,
84 "If true the decay string does not have to conserve electric charge",
false);
88 m_isSelfConjugatedParticle =
false;
89 m_generator =
nullptr;
92 void ParticleCombinerModule::initialize()
99 bool valid = m_decaydescriptor.init(m_decayString);
101 B2ERROR(
"Invalid input DecayString: " << m_decayString);
106 m_pdgCode = mother->getPDGCode();
107 m_listName = mother->getFullName();
109 m_antiListName = ParticleListName::antiParticleListName(m_listName);
110 m_isSelfConjugatedParticle = (m_listName == m_antiListName);
113 int nProducts = m_decaydescriptor.getNDaughters();
114 int daughtersNetCharge = 0;
115 for (
int i = 0; i < nProducts; ++i) {
117 m_decaydescriptor.getDaughter(i)->getMother();
119 int daughterPDGCode = daughter->getPDGCode();
120 if (m_recoilParticleType == 2 && i == 0) {
121 daughtersNetCharge -= EvtPDLUtil::charge(daughterPDGCode);
123 daughtersNetCharge += EvtPDLUtil::charge(daughterPDGCode);
127 if (daughtersNetCharge != EvtPDLUtil::charge(m_pdgCode)) {
128 if (!m_allowChargeViolation) {
129 B2FATAL(
"Your decay string " << m_decayString <<
" violates electric charge conservation!\n"
130 "If you want to allow this you can set the argument 'allowChargeViolation' to True. Something like:\n"
131 "modularAnalysis.reconstructDecay(" << m_decayString <<
", your_cuts, allowChargeViolation=True, path=mypath)");
133 B2WARNING(
"Your decay string " << m_decayString <<
" violates electric charge conservation!\n"
134 "Processing is continued assuming that you allowed this deliberately, e.g. for systematic studies etc.");
137 m_generator = std::make_unique<ParticleGenerator>(m_decayString, m_cutParameter);
141 particleList.registerInDataStore(flags);
142 if (!m_isSelfConjugatedParticle && m_chargeConjugation) {
144 antiParticleList.registerInDataStore(flags);
147 if (m_recoilParticleType != 0 && m_recoilParticleType != 1 && m_recoilParticleType != 2)
148 B2FATAL(
"Invalid recoil particle type = " << m_recoilParticleType <<
149 "! Valid values are 0 (not a recoil), 1 (recoiling against e+e- and daughters), 2 (daughter of a recoil)");
152 void ParticleCombinerModule::event()
158 outputList->initialize(m_pdgCode, m_listName);
160 if (!m_isSelfConjugatedParticle && m_chargeConjugation) {
162 outputAntiList.create();
163 outputAntiList->initialize(-1 * m_pdgCode, m_antiListName);
165 outputList->bindAntiParticleList(*(outputAntiList));
170 int numberOfCandidates = 0;
171 while (m_generator->loadNext(m_chargeConjugation)) {
173 Particle&& particle = m_generator->getCurrentParticle();
184 if (m_recoilParticleType == 1) {
187 particle.set4Vector(recoilMomentum);
188 }
else if (m_recoilParticleType == 2) {
189 const std::vector<Particle*> daughters = particle.getDaughters();
191 if (daughters.size() < 2)
192 B2FATAL(
"Reconstructing particle as a daughter of a recoil with less then 2 daughters!");
194 TLorentzVector pDaughters;
195 for (
unsigned i = 1; i < daughters.size(); i++) {
196 pDaughters += daughters[i]->get4Vector();
199 TLorentzVector mom = daughters[0]->get4Vector() - pDaughters;
200 particle.set4Vector(mom);
203 numberOfCandidates++;
205 if (m_maximumNumberOfCandidates > 0 and numberOfCandidates > m_maximumNumberOfCandidates) {
206 if (m_ignoreIfTooManyCandidates) {
207 B2WARNING(
"Maximum number of " << m_maximumNumberOfCandidates <<
" candidates reached, skipping event");
210 B2WARNING(
"Maximum number of " << m_maximumNumberOfCandidates <<
" candidates reached. Ignoring others");
215 Particle* newParticle = particles.appendNew(particle);
217 outputList->addParticle(newParticle);
220 newParticle->
addExtraInfo(
"decayModeID", m_decayModeID);