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"
43 for(
int i = 0;
i < *lenv;
i++)
58 fIsInitialized(
false),
60 fSelectDecayByEvent(
false),
64 dolheBosonCorr(
false),
67 if (
fPSet != 0 )
throw cms::Exception(
"TauolappInterfaceError") <<
"Attempt to override Tauola an existing ParameterSet\n" << std::endl;
75 if (
fPSet == 0 )
throw cms::Exception(
"TauolappInterfaceError") <<
"Attempt to initialize Tauola with an empty ParameterSet\n" << std::endl;
81 Tauolapp::Tauola::setDecayingParticle(15);
97 fMDTAU = cards.getParameter<
int >(
"mdtau" );
99 if ( fMDTAU == 0 || fMDTAU == 1 )
101 Tauolapp::Tauola::setSameParticleDecayMode( cards.getParameter<
int >(
"pjak1" ) ) ;
102 Tauolapp::Tauola::setOppositeParticleDecayMode( cards.getParameter<
int >(
"pjak2" ) ) ;
105 Tauolapp::Tauola::spin_correlation.setAll(fPolarization);
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") Tauolapp::Tauola::setNewCurrents(
fPSet->
getParameter<
int>(curSet));
129 Tauolapp::Tauola::spin_correlation.setAll(fPolarization);
132 std::vector<std::string> par =
fPSet->
getParameter< std::vector<std::string> >(
"parameterSets");
133 for (
unsigned int ip=0; ip<par.size(); ++ip ){
135 if(curSet==
"spinCorrelationSetAll") Tauolapp::Tauola::spin_correlation.setAll(
fPSet->
getParameter<
bool>(curSet));
136 if(curSet==
"spinCorrelationGAMMA") Tauolapp::Tauola::spin_correlation.GAMMA=
fPSet->
getParameter<
bool>(curSet);
137 if(curSet==
"spinCorrelationZ0") Tauolapp::Tauola::spin_correlation.Z0=
fPSet->
getParameter<
bool>(curSet);
138 if(curSet==
"spinCorrelationHIGGS") Tauolapp::Tauola::spin_correlation.HIGGS=
fPSet->
getParameter<
bool>(curSet);
139 if(curSet==
"spinCorrelationHIGGSH") Tauolapp::Tauola::spin_correlation.HIGGS_H=
fPSet->
getParameter<
bool>(curSet);
140 if(curSet==
"spinCorrelationHIGGSA") Tauolapp::Tauola::spin_correlation.HIGGS_A=
fPSet->
getParameter<
bool>(curSet);
141 if(curSet==
"spinCorrelationHIGGSPLUS") Tauolapp::Tauola::spin_correlation.HIGGS_PLUS=
fPSet->
getParameter<
bool>(curSet);
142 if(curSet==
"spinCorrelationHIGGSMINUS") Tauolapp::Tauola::spin_correlation.HIGGS_MINUS=
fPSet->
getParameter<
bool>(curSet);
143 if(curSet==
"spinCorrelationWPLUS") Tauolapp::Tauola::spin_correlation.W_PLUS=
fPSet->
getParameter<
bool>(curSet);
144 if(curSet==
"spinCorrelationWMINUS") Tauolapp::Tauola::spin_correlation.W_MINUS=
fPSet->
getParameter<
bool>(curSet);
146 if(curSet==
"setHiggsScalarPseudoscalarPDG") Tauolapp::Tauola::setHiggsScalarPseudoscalarPDG(
fPSet->
getParameter<
int>(curSet));
147 if(curSet==
"setHiggsScalarPseudoscalarMixingAngle") Tauolapp::Tauola::setHiggsScalarPseudoscalarMixingAngle(
fPSet->
getParameter<
double>(curSet));
149 if(curSet==
"setRadiation") Tauolapp::Tauola::setRadiation(
fPSet->
getParameter<
bool>(curSet));
150 if(curSet==
"setRadiationCutOff") Tauolapp::Tauola::setRadiationCutOff(
fPSet->
getParameter<
double>(curSet));
152 if(curSet==
"setEtaK0sPi"){
154 if(vpar.size()==3) Tauolapp::Tauola::setEtaK0sPi(vpar[0],vpar[1],vpar[2]);
155 else {
std::cout <<
"WARNING invalid size for setEtaK0sPi: " << vpar.size() <<
" Require 3 elements " << std::endl;}
158 if(curSet==
"setTaukle"){
160 if(vpar.size()==4) Tauolapp::Tauola::setTaukle(vpar[0], vpar[1], vpar[2], vpar[3]);
161 else {
std::cout <<
"WARNING invalid size for setTaukle: " << vpar.size() <<
" Require 4 elements " << std::endl;}
164 if(curSet==
"setTauBr"){
166 std::vector<int> vJAK = cfg.
getParameter<std::vector<int> >(
"JAK");
167 std::vector<double> vBR = cfg.
getParameter<std::vector<double> >(
"BR");
168 if(vJAK.size() == vBR.size()){
169 for(
unsigned int i=0;
i<vJAK.size();
i++) Tauolapp::Tauola::setTauBr(vJAK[
i],vBR[i]);
171 else {
std::cout <<
"WARNING invalid size for setTauBr - JAK: " << vJAK.size() <<
" BR: " << vBR.size() << std::endl;}
180 if ( fMDTAU != 0 && fMDTAU != 1 )
185 Tauolapp::Log::LogWarning(
false);
194 <<
"TauolaInterface::flat: Attempt to generate random number when engine pointer is null\n"
195 <<
"This might mean that the code was modified to generate a random number outside the\n"
196 <<
"event and beginLuminosityBlock methods, which is not allowed.\n";
204 int NPartBefore = evt->particles_size();
205 int NVtxBefore = evt->vertices_size();
216 std::vector<HepMC::GenParticle> particles;
217 std::vector<int> m_idx;
220 for(
unsigned int i=0;
i<spinup.size();
i++){
223 particles.at(particles.size()-1).set_generated_mass(
lhe->
getHEPEUP()->
PUP.at(
i)[4]);
224 particles.at(particles.size()-1).set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
229 std::vector<HepMC::GenParticle*>
match;
230 for(HepMC::GenEvent::particle_const_iterator
iter = evt->particles_begin();
iter != evt->particles_end();
iter++) {
231 if(
abs((*iter)->pdg_id())==15){
235 for(HepMC::GenVertex::particle_iterator mother=(*iter)->production_vertex()->particles_begin(
HepMC::parents); mother!=(*iter)->production_vertex()->particles_end(
HepMC::parents); mother++) {
236 mother_pid = (*mother)->pdg_id();
237 if(mother_pid!=(*iter)->pdg_id()){
239 if(
abs(mother_pid) == 24 ||
240 abs(mother_pid) == 37 ||
241 abs(mother_pid) == 23 ||
242 abs(mother_pid) == 22 ||
243 abs(mother_pid) == 25 ||
244 abs(mother_pid) == 35 ||
245 abs(mother_pid) == 36
248 for(
unsigned int k=0;
k<match.size();
k++){
249 if((*mother)==match.at(
k))isfound=
true;
251 if(!isfound) match.push_back(*mother);
262 auto * t_event =
new Tauolapp::TauolaHepMCEvent(evt);
263 t_event->undecayTaus();
264 t_event->decayTaus();
266 for(
unsigned int j=0;
j<spinup.size();
j++){
267 if(
abs(pdg.at(
j))==15){
268 double diffhelminus=(-1.0*(double)Tauolapp::Tauola::getHelMinus()-spinup.at(
j));
269 double diffhelplus=((double)Tauolapp::Tauola::getHelPlus()-spinup.at(
j));
270 if(pdg.at(
j)==15 && diffhelminus>0.5) ismatch=
false;
271 if(pdg.at(
j)==-15 && diffhelplus>0.5) ismatch=
false;
281 auto * t_event =
new Tauolapp::TauolaHepMCEvent(evt);
282 t_event->undecayTaus();
285 for(HepMC::GenEvent::particle_const_iterator
iter = evt->particles_begin();
iter != evt->particles_end();
iter++) {
287 TLorentzVector ltau((*iter)->momentum().px(),(*iter)->momentum().py(),(*iter)->momentum().pz(),(*iter)->momentum().e());
289 TLorentzVector mother(m->momentum().px(),m->momentum().py(),m->momentum().pz(),m->momentum().e());
290 TVector3 boost=-1.0*mother.BoostVector();
291 TLorentzVector ltau_lab=ltau;
296 Tauolapp::TauolaParticle *tp =
new Tauolapp::TauolaHepMCParticle(p);
298 if((*iter)->pdg_id()==15) helicity*=-1.0;
301 Tauolapp::Tauola::decayOne(tp,
true,0,0,((
double)helicity)*0.999999);
315 auto * t_event =
new Tauolapp::TauolaHepMCEvent(evt);
317 t_event->decayTaus();
321 for (
int iv=NVtxBefore+1; iv<=evt->vertices_size(); iv++ ){
322 HepMC::GenVertex* GenVtx = evt->barcode_to_vertex(-iv);
328 std::vector<int> BCodes;
330 for (HepMC::GenVertex::particle_iterator pitr= GenVtx->particles_begin(HepMC::children);
331 pitr != GenVtx->particles_end(HepMC::children); ++pitr){
332 if ( (*pitr)->barcode() > 10000 ){
333 BCodes.push_back( (*pitr)->barcode() );
336 if ( BCodes.size() > 0 ){
337 for (
size_t ibc=0; ibc<BCodes.size(); ibc++ ){
339 int nbc = p1->barcode() - 10000 + NPartBefore;
340 p1->suggest_barcode( nbc );
345 for (HepMC::GenEvent::particle_const_iterator
p= evt->particles_begin();
p != evt->particles_end(); ++
p){
346 if((*p)->end_vertex() && (*p)->status() == 1)(*p)->set_status(2);
347 if((*p)->end_vertex() && (*p)->end_vertex()->particles_out_size()==0)
edm::LogWarning(
"TauolappInterface::decay error: empty end vertex!");
379 if ( mdtau == 101 || mdtau == 201 )
383 Tauolapp::jaki_.jak1 = 1;
384 Tauolapp::jaki_.jak2 = 1;
385 Tauolapp::Tauola::setSameParticleDecayMode( 1 ) ;
386 Tauolapp::Tauola::setOppositeParticleDecayMode( 1 ) ;
390 if ( mdtau == 102 || mdtau == 202 )
394 Tauolapp::jaki_.jak1 = 2;
395 Tauolapp::jaki_.jak2 = 2;
396 Tauolapp::Tauola::setSameParticleDecayMode( 2 ) ;
397 Tauolapp::Tauola::setOppositeParticleDecayMode( 2 ) ;
401 if ( mdtau == 111 || mdtau == 211 )
406 Tauolapp::jaki_.jak1 = 1;
407 Tauolapp::jaki_.jak2 = 0;
408 Tauolapp::Tauola::setSameParticleDecayMode( 1 ) ;
409 Tauolapp::Tauola::setOppositeParticleDecayMode( 0 ) ;
413 if ( mdtau == 112 || mdtau == 212 )
418 Tauolapp::jaki_.jak1 = 2;
419 Tauolapp::jaki_.jak2 = 0;
420 Tauolapp::Tauola::setSameParticleDecayMode( 2 ) ;
421 Tauolapp::Tauola::setOppositeParticleDecayMode( 0 ) ;
425 if ( mdtau == 121 || mdtau == 221 )
430 Tauolapp::jaki_.jak1 = 0;
431 Tauolapp::jaki_.jak2 = 1;
432 Tauolapp::Tauola::setSameParticleDecayMode( 0 ) ;
433 Tauolapp::Tauola::setOppositeParticleDecayMode( 1 ) ;
437 if ( mdtau == 122 || mdtau == 222 )
442 Tauolapp::jaki_.jak1 = 0;
443 Tauolapp::jaki_.jak2 = 2;
444 Tauolapp::Tauola::setSameParticleDecayMode( 0 ) ;
445 Tauolapp::Tauola::setOppositeParticleDecayMode( 2 ) ;
449 if ( mdtau == 140 || mdtau == 240 )
453 Tauolapp::jaki_.jak1 = 3;
454 Tauolapp::jaki_.jak2 = 3;
455 Tauolapp::Tauola::setSameParticleDecayMode( 3 ) ;
456 Tauolapp::Tauola::setOppositeParticleDecayMode( 3 ) ;
460 if ( mdtau == 141 || mdtau == 241 )
465 Tauolapp::jaki_.jak1 = 3;
466 Tauolapp::jaki_.jak2 = 0;
467 Tauolapp::Tauola::setSameParticleDecayMode( 3 ) ;
468 Tauolapp::Tauola::setOppositeParticleDecayMode( 0 ) ;
472 if ( mdtau == 142 || mdtau == 242 )
477 Tauolapp::jaki_.jak1 = 0;
478 Tauolapp::jaki_.jak2 = 3;
479 Tauolapp::Tauola::setSameParticleDecayMode( 0 ) ;
480 Tauolapp::Tauola::setOppositeParticleDecayMode( 3 ) ;
497 for (
int i=0;
i<22;
i++ )
501 if ( sumBra == 0. )
return ;
502 for (
int i=0;
i<22;
i++ )
505 Tauolapp::Tauola::setTauBr(
i+1, newBra );
510 double sumHadronBra = sumBra - sumLeptonBra;
512 for (
int i=0;
i<2;
i++ )
517 for (
int i=2;
i<22;
i++ )
535 Tauolapp::jaki_.jak1 =
mode;
536 Tauolapp::Tauola::setSameParticleDecayMode( mode );
538 Tauolapp::jaki_.jak2 =
mode;
539 Tauolapp::Tauola::setOppositeParticleDecayMode( mode );
548 Tauolapp::jaki_.jak1 = modeL;
549 Tauolapp::jaki_.jak2 = 0;
550 Tauolapp::Tauola::setSameParticleDecayMode( modeL );
551 Tauolapp::Tauola::setOppositeParticleDecayMode( 0 );
557 Tauolapp::jaki_.jak1 = 0;
558 Tauolapp::jaki_.jak2 = modeL;
559 Tauolapp::Tauola::setSameParticleDecayMode( 0 );
560 Tauolapp::Tauola::setOppositeParticleDecayMode( modeL );
566 Tauolapp::jaki_.jak1 = modeL;
567 Tauolapp::jaki_.jak2 = modeH;
568 Tauolapp::Tauola::setSameParticleDecayMode( modeL );
569 Tauolapp::Tauola::setOppositeParticleDecayMode( modeH );
575 Tauolapp::jaki_.jak1 = modeH;
576 Tauolapp::jaki_.jak2 = modeL;
577 Tauolapp::Tauola::setSameParticleDecayMode( modeH );
578 Tauolapp::Tauola::setOppositeParticleDecayMode( modeL );
584 Tauolapp::jaki_.jak1 = 1;
585 Tauolapp::jaki_.jak2 = modeH;
586 Tauolapp::Tauola::setSameParticleDecayMode( 1 );
587 Tauolapp::Tauola::setOppositeParticleDecayMode( modeH );
593 Tauolapp::jaki_.jak1 = modeH;
594 Tauolapp::jaki_.jak2 = 1;
595 Tauolapp::Tauola::setSameParticleDecayMode( modeH );
596 Tauolapp::Tauola::setOppositeParticleDecayMode( 1 );
602 Tauolapp::jaki_.jak1 = 2;
603 Tauolapp::jaki_.jak2 = modeH;
604 Tauolapp::Tauola::setSameParticleDecayMode( 2 );
605 Tauolapp::Tauola::setOppositeParticleDecayMode( modeH );
611 Tauolapp::jaki_.jak1 = modeH;
612 Tauolapp::jaki_.jak2 = 2;
613 Tauolapp::Tauola::setSameParticleDecayMode( modeH );
614 Tauolapp::Tauola::setOppositeParticleDecayMode( 2 );
620 Tauolapp::jaki_.jak1 = modeH;
622 Tauolapp::Tauola::setSameParticleDecayMode( modeH );
623 Tauolapp::Tauola::setOppositeParticleDecayMode( Tauolapp::jaki_.
jak2 );
629 Tauolapp::jaki_.jak1 = modeH;
630 Tauolapp::jaki_.jak2 = 0;
631 Tauolapp::Tauola::setSameParticleDecayMode( modeH );
632 Tauolapp::Tauola::setOppositeParticleDecayMode( 0 );
638 Tauolapp::jaki_.jak1 = 0;
639 Tauolapp::jaki_.jak2 = modeH;
640 Tauolapp::Tauola::setSameParticleDecayMode( 0 );
641 Tauolapp::Tauola::setOppositeParticleDecayMode( modeH );
650 Tauolapp::Tauola::setSameParticleDecayMode( 0 );
651 Tauolapp::Tauola::setOppositeParticleDecayMode( 0 );
683 if ( prob > 0. && prob <= sumBra )
690 for (
int i=1;
i<NN;
i++ )
705 HepMC::GenEvent *
event =
new HepMC::GenEvent();
707 HepMC::FourVector momentum_tau1(l.Px(),l.Py(),l.Pz(),l.E());
711 HepMC::GenVertex *vertex =
new HepMC::GenVertex();
712 vertex->add_particle_out(tau1);
713 event->add_vertex(vertex);
718 partHep->set_status(p->status());
720 if(!partHep->end_vertex()){
721 HepMC::GenVertex* vtx =
new HepMC::GenVertex(p->end_vertex()->position());
722 theEvent->add_vertex(vtx);
723 vtx->add_particle_in(partHep);
725 if(p->end_vertex()->particles_out_size()!=0){
726 for(HepMC::GenVertex::particles_out_const_iterator
d=p->end_vertex()->particles_out_const_begin();
d!=p->end_vertex()->particles_out_const_end();
d++){
728 TLorentzVector
l((*d)->momentum().px(),(*d)->momentum().py(),(*d)->momentum().pz(),(*d)->momentum().e());
730 HepMC::FourVector momentum(
l.Px(),
l.Py(),
l.Pz(),
l.E());
732 daughter->suggest_barcode(theEvent->particles_size()+1);
733 partHep->end_vertex()->add_particle_out(daughter);
741 if ( tau->end_vertex() ) {
742 HepMC::GenVertex::particle_iterator dau;
743 for (dau = tau->end_vertex()->particles_begin(HepMC::children); dau!= tau->end_vertex()->particles_end(HepMC::children); dau++ ) {
744 int dau_pid = (*dau)->pdg_id();
745 if(dau_pid == tau->pdg_id())
return false;
752 std::vector<int> &m_idx){
755 TLorentzVector
t(tau->momentum().px(),tau->momentum().py(),tau->momentum().pz(),tau->momentum().e());
756 TLorentzVector
m(mother->momentum().px(),mother->momentum().py(),mother->momentum().pz(),mother->momentum().e());
757 for(
unsigned int i=0;
i<p.size();
i++){
758 if(tau->pdg_id()==p.at(
i).pdg_id()){
759 if(mother->pdg_id()==p.at(m_idx.at(
i)).pdg_id()){
760 TLorentzVector pm(p.at(m_idx.at(
i)).momentum().px(),p.at(m_idx.at(
i)).momentum().py(),p.at(m_idx.at(
i)).momentum().pz(),p.at(m_idx.at(
i)).momentum().e());
761 if(fabs(
m.M()-pm.M())<
dmMatch)
return spinup.at(
i);
769 if ( tau->production_vertex() ) {
770 HepMC::GenVertex::particle_iterator mother;
771 for (mother = tau->production_vertex()->particles_begin(
HepMC::parents); mother!= tau->production_vertex()->particles_end(
HepMC::parents); mother++ ) {
772 if((*mother)->pdg_id()==tau->pdg_id())
return FirstTauInChain(*mother);
779 if ( tau->production_vertex() ) {
780 HepMC::GenVertex::particle_iterator mother;
781 for (mother = tau->production_vertex()->particles_begin(
HepMC::parents); mother!= tau->production_vertex()->particles_end(
HepMC::parents); mother++ ) {
782 if((*mother)->pdg_id() == tau->pdg_id())
return GetMother(*mother);
790 if(p->end_vertex() && p->production_vertex()){
791 HepMC::GenVertex* PGenVtx=p->production_vertex();
792 HepMC::GenVertex* EGenVtx=p->end_vertex();
793 double VxDec = PGenVtx->position().x()+lab.Px()/prod.Px()*(EGenVtx->position().x()-PGenVtx->position().x());
794 double VyDec = PGenVtx->position().y()+lab.Py()/prod.Py()*(EGenVtx->position().y()-PGenVtx->position().y());
795 double VzDec = PGenVtx->position().z()+lab.Pz()/prod.Pz()*(EGenVtx->position().z()-PGenVtx->position().z());
796 double VtDec = PGenVtx->position().t()+lab.Pt()/prod.Pt()*(EGenVtx->position().t()-PGenVtx->position().t());
797 EGenVtx->set_position(HepMC::FourVector(VxDec,VyDec,VzDec,VtDec));
798 for(HepMC::GenVertex::particle_iterator dau=p->end_vertex()->particles_begin(HepMC::children); dau!=p->end_vertex()->particles_end(HepMC::children); dau++){
T getParameter(std::string const &) const
static AlgebraicMatrix initialize()
TauolappInterface(const edm::ParameterSet &)
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet * fPSet
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)
void rmarin_(int *, int *, int *)
const HEPEUP * getHEPEUP() const
void getData(T &iHolder) const
std::vector< std::pair< int, int > > MOTHUP
void BoostProdToLabLifeTimeInDecays(HepMC::GenParticle *p, TLorentzVector &lab, TLorentzVector &prod)
std::vector< int > fLeptonModes
std::vector< FiveVector > PUP
std::vector< double > SPINUP
Abs< T >::type abs(const T &t)
void ranmar_(float *rvec, int *lenv)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
HepPDT::ParticleData ParticleData
void update_particles(HepMC::GenParticle *partHep, HepMC::GenEvent *theEvent, HepMC::GenParticle *p, TVector3 &boost)
void init(const edm::EventSetup &)
HepMC::GenParticle * FirstTauInChain(HepMC::GenParticle *tau)
HepMC::GenEvent * decay(HepMC::GenEvent *)
bool isLastTauInChain(const HepMC::GenParticle *tau)
std::vector< double > fScaledLeptonBrRatios
static CLHEP::HepRandomEngine * fRandomEngine
std::vector< int > fHadronModes
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
volatile std::atomic< bool > shutdown_flag false
double MatchedLHESpinUp(HepMC::GenParticle *tau, std::vector< HepMC::GenParticle > &p, std::vector< double > &spinup, std::vector< int > &m_idx)
void selectDecayByMDTAU()