7 #include "Tauola/Tauola.h"
8 #include "Tauola/TauolaHepMCEvent.h"
9 #include "Tauola/Log.h"
10 #include "Tauola/TauolaHepMCParticle.h"
11 #include "Tauola/TauolaParticle.h"
17 #include "CLHEP/Random/RandomEngine.h"
19 #include "HepMC/GenEvent.h"
20 #include "HepMC/IO_HEPEVT.h"
21 #include "HepMC/HEPEVT_Wrapper.h"
42 for (
int i = 0;
i < *lenv;
i++)
51 : fPolarization(
false),
54 fIsInitialized(
false),
56 fSelectDecayByEvent(
false),
60 dolheBosonCorr(
false),
74 throw cms::Exception(
"TauolappInterfaceError") <<
"Attempt to initialize Tauola with an empty ParameterSet\n"
81 Tauolapp::Tauola::setDecayingParticle(15);
97 fMDTAU = cards.getParameter<
int>(
"mdtau");
99 if (fMDTAU == 0 || fMDTAU == 1) {
100 Tauolapp::Tauola::setSameParticleDecayMode(cards.getParameter<
int>(
"pjak1"));
101 Tauolapp::Tauola::setOppositeParticleDecayMode(cards.getParameter<
int>(
"pjak2"));
104 Tauolapp::Tauola::spin_correlation.setAll(fPolarization);
111 fPDGTable->particle(HepPDT::ParticleID(
abs(Tauolapp::Tauola::getDecayingParticle())));
112 double lifetime = PData->lifetime().value();
113 Tauolapp::Tauola::setTauLifetime(lifetime);
115 fPDGs.push_back(Tauolapp::Tauola::getDecayingParticle());
120 std::vector<std::string> par =
fPSet->
getParameter<std::vector<std::string> >(
"parameterSets");
121 for (
unsigned int ip = 0; ip < par.size(); ++ip) {
123 if (curSet ==
"setNewCurrents")
130 Tauolapp::Tauola::spin_correlation.setAll(
134 std::vector<std::string> par =
fPSet->
getParameter<std::vector<std::string> >(
"parameterSets");
135 for (
unsigned int ip = 0; ip < par.size(); ++ip) {
137 if (curSet ==
"spinCorrelationSetAll")
139 if (curSet ==
"spinCorrelationGAMMA")
141 if (curSet ==
"spinCorrelationZ0")
143 if (curSet ==
"spinCorrelationHIGGS")
145 if (curSet ==
"spinCorrelationHIGGSH")
147 if (curSet ==
"spinCorrelationHIGGSA")
149 if (curSet ==
"spinCorrelationHIGGSPLUS")
150 Tauolapp::Tauola::spin_correlation.HIGGS_PLUS =
fPSet->
getParameter<
bool>(curSet);
151 if (curSet ==
"spinCorrelationHIGGSMINUS")
152 Tauolapp::Tauola::spin_correlation.HIGGS_MINUS =
fPSet->
getParameter<
bool>(curSet);
153 if (curSet ==
"spinCorrelationWPLUS")
155 if (curSet ==
"spinCorrelationWMINUS")
158 if (curSet ==
"setHiggsScalarPseudoscalarPDG")
159 Tauolapp::Tauola::setHiggsScalarPseudoscalarPDG(
fPSet->
getParameter<
int>(curSet));
160 if (curSet ==
"setHiggsScalarPseudoscalarMixingAngle")
161 Tauolapp::Tauola::setHiggsScalarPseudoscalarMixingAngle(
fPSet->
getParameter<
double>(curSet));
163 if (curSet ==
"setRadiation")
165 if (curSet ==
"setRadiationCutOff")
168 if (curSet ==
"setEtaK0sPi") {
170 if (vpar.size() == 3)
171 Tauolapp::Tauola::setEtaK0sPi(vpar[0], vpar[1], vpar[2]);
173 std::cout <<
"WARNING invalid size for setEtaK0sPi: " << vpar.size() <<
" Require 3 elements " << std::endl;
177 if (curSet ==
"setTaukle") {
179 if (vpar.size() == 4)
180 Tauolapp::Tauola::setTaukle(vpar[0], vpar[1], vpar[2], vpar[3]);
182 std::cout <<
"WARNING invalid size for setTaukle: " << vpar.size() <<
" Require 4 elements " << std::endl;
186 if (curSet ==
"setTauBr") {
188 std::vector<int> vJAK = cfg.
getParameter<std::vector<int> >(
"JAK");
189 std::vector<double> vBR = cfg.
getParameter<std::vector<double> >(
"BR");
190 if (vJAK.size() == vBR.size()) {
191 for (
unsigned int i = 0;
i < vJAK.size();
i++)
192 Tauolapp::Tauola::setTauBr(vJAK[
i], vBR[i]);
194 std::cout <<
"WARNING invalid size for setTauBr - JAK: " << vJAK.size() <<
" BR: " << vBR.size() << std::endl;
204 if (fMDTAU != 0 && fMDTAU != 1) {
216 <<
"TauolaInterface::flat: Attempt to generate random number when engine pointer is null\n"
217 <<
"This might mean that the code was modified to generate a random number outside the\n"
218 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
226 Tauolapp::Tauola::setRandomGenerator(
228 int NPartBefore = evt->particles_size();
229 int NVtxBefore = evt->vertices_size();
240 std::vector<HepMC::GenParticle> particles;
241 std::vector<int> m_idx;
244 for (
unsigned int i = 0;
i < spinup.size();
i++) {
251 particles.at(particles.size() - 1).set_generated_mass(
lhe->
getHEPEUP()->
PUP.at(
i)[4]);
252 particles.at(particles.size() - 1).set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
257 std::vector<HepMC::GenParticle*>
match;
258 for (HepMC::GenEvent::particle_const_iterator iter = evt->particles_begin(); iter != evt->particles_end(); iter++) {
259 if (
abs((*iter)->pdg_id()) == 15) {
263 for (HepMC::GenVertex::particle_iterator mother = (*iter)->production_vertex()->particles_begin(
HepMC::parents);
264 mother != (*iter)->production_vertex()->particles_end(
HepMC::parents);
266 mother_pid = (*mother)->pdg_id();
267 if (mother_pid != (*iter)->pdg_id()) {
269 if (
abs(mother_pid) == 24 ||
270 abs(mother_pid) == 37 ||
271 abs(mother_pid) == 23 ||
272 abs(mother_pid) == 22 ||
273 abs(mother_pid) == 25 ||
274 abs(mother_pid) == 35 ||
275 abs(mother_pid) == 36
277 bool isfound =
false;
278 for (
unsigned int k = 0;
k < match.size();
k++) {
279 if ((*mother) == match.at(
k))
283 match.push_back(*mother);
294 auto* t_event =
new Tauolapp::TauolaHepMCEvent(evt);
295 t_event->undecayTaus();
296 t_event->decayTaus();
298 for (
unsigned int j = 0;
j < spinup.size();
j++) {
299 if (
abs(pdg.at(
j)) == 15) {
300 double diffhelminus = (-1.0 * (double)Tauolapp::Tauola::getHelMinus() -
302 double diffhelplus = ((double)Tauolapp::Tauola::getHelPlus() - spinup.at(
j));
303 if (pdg.at(
j) == 15 && diffhelminus > 0.5)
305 if (pdg.at(
j) == -15 && diffhelplus > 0.5)
316 auto* t_event =
new Tauolapp::TauolaHepMCEvent(evt);
317 t_event->undecayTaus();
320 for (HepMC::GenEvent::particle_const_iterator iter = evt->particles_begin(); iter != evt->particles_end();
324 (*iter)->momentum().px(), (*iter)->momentum().py(), (*iter)->momentum().pz(), (*iter)->momentum().e());
326 TLorentzVector mother(m->momentum().px(), m->momentum().py(), m->momentum().pz(), m->momentum().e());
327 TVector3 boost = -1.0 * mother.BoostVector();
328 TLorentzVector ltau_lab = ltau;
333 Tauolapp::TauolaParticle*
tp =
new Tauolapp::TauolaHepMCParticle(p);
335 if ((*iter)->pdg_id() == 15)
339 Tauolapp::Tauola::decayOne(tp,
true, 0, 0, ((
double)helicity) * 0.999999);
352 auto* t_event =
new Tauolapp::TauolaHepMCEvent(evt);
354 t_event->decayTaus();
358 for (
int iv = NVtxBefore + 1;
iv <= evt->vertices_size();
iv++) {
359 HepMC::GenVertex* GenVtx = evt->barcode_to_vertex(-
iv);
365 std::vector<int> BCodes;
367 for (HepMC::GenVertex::particle_iterator pitr = GenVtx->particles_begin(HepMC::children);
368 pitr != GenVtx->particles_end(HepMC::children);
370 if ((*pitr)->barcode() > 10000) {
371 BCodes.push_back((*pitr)->barcode());
374 if (!BCodes.empty()) {
375 for (
size_t ibc = 0; ibc < BCodes.size(); ibc++) {
377 int nbc = p1->barcode() - 10000 + NPartBefore;
378 p1->suggest_barcode(nbc);
383 for (HepMC::GenEvent::particle_const_iterator
p = evt->particles_begin();
p != evt->particles_end(); ++
p) {
384 if ((*p)->end_vertex() && (*p)->status() == 1)
386 if ((*p)->end_vertex() && (*p)->end_vertex()->particles_out_size() == 0)
414 if (mdtau == 101 || mdtau == 201) {
417 Tauolapp::jaki_.jak1 = 1;
418 Tauolapp::jaki_.jak2 = 1;
419 Tauolapp::Tauola::setSameParticleDecayMode(1);
420 Tauolapp::Tauola::setOppositeParticleDecayMode(1);
424 if (mdtau == 102 || mdtau == 202) {
427 Tauolapp::jaki_.jak1 = 2;
428 Tauolapp::jaki_.jak2 = 2;
429 Tauolapp::Tauola::setSameParticleDecayMode(2);
430 Tauolapp::Tauola::setOppositeParticleDecayMode(2);
434 if (mdtau == 111 || mdtau == 211) {
438 Tauolapp::jaki_.jak1 = 1;
439 Tauolapp::jaki_.jak2 = 0;
440 Tauolapp::Tauola::setSameParticleDecayMode(1);
441 Tauolapp::Tauola::setOppositeParticleDecayMode(0);
445 if (mdtau == 112 || mdtau == 212) {
449 Tauolapp::jaki_.jak1 = 2;
450 Tauolapp::jaki_.jak2 = 0;
451 Tauolapp::Tauola::setSameParticleDecayMode(2);
452 Tauolapp::Tauola::setOppositeParticleDecayMode(0);
456 if (mdtau == 121 || mdtau == 221) {
460 Tauolapp::jaki_.jak1 = 0;
461 Tauolapp::jaki_.jak2 = 1;
462 Tauolapp::Tauola::setSameParticleDecayMode(0);
463 Tauolapp::Tauola::setOppositeParticleDecayMode(1);
467 if (mdtau == 122 || mdtau == 222) {
471 Tauolapp::jaki_.jak1 = 0;
472 Tauolapp::jaki_.jak2 = 2;
473 Tauolapp::Tauola::setSameParticleDecayMode(0);
474 Tauolapp::Tauola::setOppositeParticleDecayMode(2);
478 if (mdtau == 140 || mdtau == 240) {
481 Tauolapp::jaki_.jak1 = 3;
482 Tauolapp::jaki_.jak2 = 3;
483 Tauolapp::Tauola::setSameParticleDecayMode(3);
484 Tauolapp::Tauola::setOppositeParticleDecayMode(3);
488 if (mdtau == 141 || mdtau == 241) {
492 Tauolapp::jaki_.jak1 = 3;
493 Tauolapp::jaki_.jak2 = 0;
494 Tauolapp::Tauola::setSameParticleDecayMode(3);
495 Tauolapp::Tauola::setOppositeParticleDecayMode(0);
499 if (mdtau == 142 || mdtau == 242) {
503 Tauolapp::jaki_.jak1 = 0;
504 Tauolapp::jaki_.jak2 = 3;
505 Tauolapp::Tauola::setSameParticleDecayMode(0);
506 Tauolapp::Tauola::setOppositeParticleDecayMode(3);
523 for (
int i = 0;
i < 22;
i++) {
524 sumBra += Tauolapp::taubra_.gamprt[
i];
528 for (
int i = 0;
i < 22;
i++) {
529 double newBra = Tauolapp::taubra_.gamprt[
i] / sumBra;
530 Tauolapp::Tauola::setTauBr(
i + 1, newBra);
534 double sumLeptonBra = Tauolapp::taubra_.gamprt[0] + Tauolapp::taubra_.gamprt[1];
535 double sumHadronBra = sumBra - sumLeptonBra;
537 for (
int i = 0;
i < 2;
i++) {
541 for (
int i = 2;
i < 22;
i++) {
553 Tauolapp::jaki_.jak1 =
mode;
554 Tauolapp::Tauola::setSameParticleDecayMode(mode);
556 Tauolapp::jaki_.jak2 =
mode;
557 Tauolapp::Tauola::setOppositeParticleDecayMode(mode);
565 Tauolapp::jaki_.jak1 = modeL;
566 Tauolapp::jaki_.jak2 = 0;
567 Tauolapp::Tauola::setSameParticleDecayMode(modeL);
568 Tauolapp::Tauola::setOppositeParticleDecayMode(0);
573 Tauolapp::jaki_.jak1 = 0;
574 Tauolapp::jaki_.jak2 = modeL;
575 Tauolapp::Tauola::setSameParticleDecayMode(0);
576 Tauolapp::Tauola::setOppositeParticleDecayMode(modeL);
581 Tauolapp::jaki_.jak1 = modeL;
582 Tauolapp::jaki_.jak2 = modeH;
583 Tauolapp::Tauola::setSameParticleDecayMode(modeL);
584 Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
589 Tauolapp::jaki_.jak1 = modeH;
590 Tauolapp::jaki_.jak2 = modeL;
591 Tauolapp::Tauola::setSameParticleDecayMode(modeH);
592 Tauolapp::Tauola::setOppositeParticleDecayMode(modeL);
597 Tauolapp::jaki_.jak1 = 1;
598 Tauolapp::jaki_.jak2 = modeH;
599 Tauolapp::Tauola::setSameParticleDecayMode(1);
600 Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
605 Tauolapp::jaki_.jak1 = modeH;
606 Tauolapp::jaki_.jak2 = 1;
607 Tauolapp::Tauola::setSameParticleDecayMode(modeH);
608 Tauolapp::Tauola::setOppositeParticleDecayMode(1);
613 Tauolapp::jaki_.jak1 = 2;
614 Tauolapp::jaki_.jak2 = modeH;
615 Tauolapp::Tauola::setSameParticleDecayMode(2);
616 Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
621 Tauolapp::jaki_.jak1 = modeH;
622 Tauolapp::jaki_.jak2 = 2;
623 Tauolapp::Tauola::setSameParticleDecayMode(modeH);
624 Tauolapp::Tauola::setOppositeParticleDecayMode(2);
629 Tauolapp::jaki_.jak1 = modeH;
631 Tauolapp::Tauola::setSameParticleDecayMode(modeH);
632 Tauolapp::Tauola::setOppositeParticleDecayMode(Tauolapp::jaki_.jak2);
637 Tauolapp::jaki_.jak1 = modeH;
638 Tauolapp::jaki_.jak2 = 0;
639 Tauolapp::Tauola::setSameParticleDecayMode(modeH);
640 Tauolapp::Tauola::setOppositeParticleDecayMode(0);
645 Tauolapp::jaki_.jak1 = 0;
646 Tauolapp::jaki_.jak2 = modeH;
647 Tauolapp::Tauola::setSameParticleDecayMode(0);
648 Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
657 Tauolapp::Tauola::setSameParticleDecayMode(0);
658 Tauolapp::Tauola::setOppositeParticleDecayMode(0);
681 if (prob > 0. && prob <= sumBra) {
685 for (
int i = 1;
i < NN;
i++) {
699 HepMC::FourVector momentum_tau1(l.Px(), l.Py(), l.Pz(), l.E());
703 HepMC::GenVertex* vertex =
new HepMC::GenVertex();
704 vertex->add_particle_out(tau1);
705 event->add_vertex(vertex);
713 partHep->set_status(p->status());
714 if (p->end_vertex()) {
715 if (!partHep->end_vertex()) {
716 HepMC::GenVertex* vtx =
new HepMC::GenVertex(p->end_vertex()->position());
717 theEvent->add_vertex(vtx);
718 vtx->add_particle_in(partHep);
720 if (p->end_vertex()->particles_out_size() != 0) {
721 for (HepMC::GenVertex::particles_out_const_iterator
d = p->end_vertex()->particles_out_const_begin();
722 d != p->end_vertex()->particles_out_const_end();
725 TLorentzVector
l((*d)->momentum().px(), (*d)->momentum().py(), (*d)->momentum().pz(), (*d)->momentum().e());
727 HepMC::FourVector momentum(
l.Px(),
l.Py(),
l.Pz(),
l.E());
729 daughter->suggest_barcode(theEvent->particles_size() + 1);
730 partHep->end_vertex()->add_particle_out(daughter);
731 if ((*d)->end_vertex())
739 if (tau->end_vertex()) {
740 HepMC::GenVertex::particle_iterator dau;
741 for (dau = tau->end_vertex()->particles_begin(HepMC::children);
742 dau != tau->end_vertex()->particles_end(HepMC::children);
744 int dau_pid = (*dau)->pdg_id();
745 if (dau_pid == tau->pdg_id())
753 std::vector<HepMC::GenParticle>&
p,
754 std::vector<double>& spinup,
755 std::vector<int>& m_idx) {
758 TLorentzVector
t(tau->momentum().px(), tau->momentum().py(), tau->momentum().pz(), tau->momentum().e());
759 TLorentzVector
m(mother->momentum().px(), mother->momentum().py(), mother->momentum().pz(), mother->momentum().e());
760 for (
unsigned int i = 0;
i < p.size();
i++) {
761 if (tau->pdg_id() == p.at(
i).pdg_id()) {
762 if (mother->pdg_id() == p.at(m_idx.at(
i)).pdg_id()) {
763 TLorentzVector pm(p.at(m_idx.at(
i)).momentum().px(),
764 p.at(m_idx.at(
i)).momentum().py(),
765 p.at(m_idx.at(
i)).momentum().pz(),
766 p.at(m_idx.at(
i)).momentum().e());
776 if (tau->production_vertex()) {
777 HepMC::GenVertex::particle_iterator mother;
778 for (mother = tau->production_vertex()->particles_begin(
HepMC::parents);
779 mother != tau->production_vertex()->particles_end(
HepMC::parents);
781 if ((*mother)->pdg_id() == tau->pdg_id())
789 if (tau->production_vertex()) {
790 HepMC::GenVertex::particle_iterator mother;
791 for (mother = tau->production_vertex()->particles_begin(
HepMC::parents);
792 mother != tau->production_vertex()->particles_end(
HepMC::parents);
794 if ((*mother)->pdg_id() == tau->pdg_id())
804 TLorentzVector& prod) {
805 if (p->end_vertex() && p->production_vertex()) {
806 HepMC::GenVertex* PGenVtx = p->production_vertex();
807 HepMC::GenVertex* EGenVtx = p->end_vertex();
808 double VxDec = PGenVtx->position().x() + lab.Px() / prod.Px() * (EGenVtx->position().x() - PGenVtx->position().x());
809 double VyDec = PGenVtx->position().y() + lab.Py() / prod.Py() * (EGenVtx->position().y() - PGenVtx->position().y());
810 double VzDec = PGenVtx->position().z() + lab.Pz() / prod.Pz() * (EGenVtx->position().z() - PGenVtx->position().z());
811 double VtDec = PGenVtx->position().t() + lab.Pt() / prod.Pt() * (EGenVtx->position().t() - PGenVtx->position().t());
812 EGenVtx->set_position(HepMC::FourVector(VxDec, VyDec, VzDec, VtDec));
813 for (HepMC::GenVertex::particle_iterator dau = p->end_vertex()->particles_begin(HepMC::children);
814 dau != p->end_vertex()->particles_end(HepMC::children);
static AlgebraicMatrix initialize()
T getUntrackedParameter(std::string const &, T const &) const
void statistics() override
edm::ParameterSet * fPSet
HepMC::GenEvent * decay(HepMC::GenEvent *) override
std::vector< double > fScaledHadronBrRatios
bool exists(std::string const ¶meterName) const
checks if a parameter exists
HepMC::GenEvent * make_simple_tau_event(const TLorentzVector &l, int pdgid, int status)
TauolappInterface(const edm::ParameterSet &, edm::ConsumesCollector)
const HEPEUP * getHEPEUP() const
void init(const edm::EventSetup &) override
void BoostProdToLabLifeTimeInDecays(HepMC::GenParticle *p, TLorentzVector &lab, TLorentzVector &prod)
std::vector< int > fLeptonModes
~TauolappInterface() override
edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > fPDGTableToken
std::vector< FiveVector > PUP
std::vector< double > SPINUP
Abs< T >::type abs(const T &t)
void rmarin_(int *, int *, int *)
std::vector< std::pair< int, int > > MOTHUP
HepPDT::ParticleData ParticleData
static std::vector< std::string > checklist lhe
void update_particles(HepMC::GenParticle *partHep, HepMC::GenEvent *theEvent, HepMC::GenParticle *p, TVector3 &boost)
HepMC::GenParticle * FirstTauInChain(HepMC::GenParticle *tau)
T getParameter(std::string const &) const
bool isLastTauInChain(const HepMC::GenParticle *tau)
std::vector< double > fScaledLeptonBrRatios
static CLHEP::HepRandomEngine * fRandomEngine
std::vector< int > fHadronModes
void ranmar_(float *rvec, int *lenv)
HepMC::GenParticle * GetMother(HepMC::GenParticle *tau)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Log< level::Warning, false > LogWarning
double MatchedLHESpinUp(HepMC::GenParticle *tau, std::vector< HepMC::GenParticle > &p, std::vector< double > &spinup, std::vector< int > &m_idx)
void selectDecayByMDTAU()