Skip to content

Commit a9a6f3b

Browse files
committed
Merge pull request cms-sw#2565 from mkirsano/fix_residualdecay71
Generators updates -- Fix ResidualDecay port from 62X
2 parents ab1084c + ea29541 commit a9a6f3b

File tree

3 files changed

+91
-82
lines changed

3 files changed

+91
-82
lines changed

GeneratorInterface/Pythia8Interface/interface/Py8InterfaceBase.h

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace gen {
2525

2626
virtual bool generatePartonsAndHadronize() = 0;
2727
bool decay() { return true; } // NOT used - let's call it "design imperfection"
28-
virtual bool residualDecay();
2928
bool readSettings( int ); // common func
3029
virtual bool initializeForInternalPartons() = 0;
3130
bool declareStableParticles( const std::vector<int>& ); // common func

GeneratorInterface/Pythia8Interface/plugins/Pythia8Hadronizer.cc

+91
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class Pythia8Hadronizer : public BaseHadronizer, public Py8InterfaceBase {
6363

6464
bool generatePartonsAndHadronize() override;
6565
bool hadronize();
66+
67+
virtual bool residualDecay();
68+
6669
void finalizeEvent() override;
6770

6871
void statistics() override;
@@ -308,6 +311,12 @@ bool Pythia8Hadronizer::initializeForInternalPartons()
308311
fMasterGen->particleData.listAll();
309312
}
310313

314+
// init decayer
315+
fDecayer->readString("ProcessLevel:all = off"); // trick
316+
fDecayer->readString("Standalone:allowResDec=on");
317+
// pythia->readString("ProcessLevel::resonanceDecays=on");
318+
fDecayer->init();
319+
311320
return true;
312321
}
313322

@@ -376,6 +385,12 @@ bool Pythia8Hadronizer::initializeForExternalPartons()
376385
fMasterGen->particleData.listAll();
377386
}
378387

388+
// init decayer
389+
fDecayer->readString("ProcessLevel:all = off"); // trick
390+
fDecayer->readString("Standalone:allowResDec=on");
391+
// pythia->readString("ProcessLevel::resonanceDecays=on");
392+
fDecayer->init();
393+
379394
return true;
380395
}
381396

@@ -444,6 +459,82 @@ bool Pythia8Hadronizer::hadronize()
444459
}
445460

446461

462+
bool Pythia8Hadronizer::residualDecay()
463+
{
464+
465+
Event* pythiaEvent = &(fMasterGen->event);
466+
467+
int NPartsBeforeDecays = pythiaEvent->size();
468+
int NPartsAfterDecays = event().get()->particles_size();
469+
int NewBarcode = NPartsAfterDecays;
470+
471+
for ( int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
472+
{
473+
474+
HepMC::GenParticle* part = event().get()->barcode_to_particle( ipart );
475+
476+
if ( part->status() == 1 )
477+
{
478+
fDecayer->event.reset();
479+
Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
480+
part->momentum().x(),
481+
part->momentum().y(),
482+
part->momentum().z(),
483+
part->momentum().t(),
484+
part->generated_mass() );
485+
HepMC::GenVertex* ProdVtx = part->production_vertex();
486+
py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
487+
ProdVtx->position().z(), ProdVtx->position().t() );
488+
py8part.tau( (fDecayer->particleData).tau0( part->pdg_id() ) );
489+
fDecayer->event.append( py8part );
490+
int nentries = fDecayer->event.size();
491+
if ( !fDecayer->event[nentries-1].mayDecay() ) continue;
492+
fDecayer->next();
493+
int nentries1 = fDecayer->event.size();
494+
// fDecayer->event.list(std::cout);
495+
if ( nentries1 <= nentries ) continue; //same number of particles, no decays...
496+
497+
part->set_status(2);
498+
499+
Particle& py8daughter = fDecayer->event[nentries]; // the 1st daughter
500+
HepMC::GenVertex* DecVtx = new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
501+
py8daughter.yProd(),
502+
py8daughter.zProd(),
503+
py8daughter.tProd()) );
504+
505+
DecVtx->add_particle_in( part ); // this will cleanup end_vertex if exists, replace with the new one
506+
// I presume (vtx) barcode will be given automatically
507+
508+
HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
509+
510+
HepMC::GenParticle* daughter =
511+
new HepMC::GenParticle( pmom, py8daughter.id(), 1 );
512+
513+
NewBarcode++;
514+
daughter->suggest_barcode( NewBarcode );
515+
DecVtx->add_particle_out( daughter );
516+
517+
for ( int ipart1=nentries+1; ipart1<nentries1; ipart1++ )
518+
{
519+
py8daughter = fDecayer->event[ipart1];
520+
HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
521+
HepMC::GenParticle* daughterN =
522+
new HepMC::GenParticle( pmomN, py8daughter.id(), 1 );
523+
NewBarcode++;
524+
daughterN->suggest_barcode( NewBarcode );
525+
DecVtx->add_particle_out( daughterN );
526+
}
527+
528+
event().get()->add_vertex( DecVtx );
529+
// fCurrentEventState->add_vertex( DecVtx );
530+
531+
}
532+
}
533+
return true;
534+
535+
}
536+
537+
447538
void Pythia8Hadronizer::finalizeEvent()
448539
{
449540
bool lhe = lheEvent() != 0;

GeneratorInterface/Pythia8Interface/src/Py8InterfaceBase.cc

-81
Original file line numberDiff line numberDiff line change
@@ -82,87 +82,6 @@ bool Py8InterfaceBase:: declareSpecialSettings( const std::vector<std::string>&
8282
return true;
8383
}
8484

85-
bool Py8InterfaceBase::residualDecay()
86-
{
87-
88-
/*
89-
Event* pythiaEvent = &(fMasterPtr->event);
90-
91-
assert(fCurrentEventState);
92-
93-
int NPartsBeforeDecays = pythiaEvent->size();
94-
// int NPartsAfterDecays = event().get()->particles_size();
95-
int NPartsAfterDecays = fCurrentEventState->particles_size();
96-
int NewBarcode = NPartsAfterDecays;
97-
98-
for ( int ipart=NPartsAfterDecays; ipart>NPartsBeforeDecays; ipart-- )
99-
{
100-
101-
// HepMC::GenParticle* part = event().get()->barcode_to_particle( ipart );
102-
HepMC::GenParticle* part = fCurrentEventState->barcode_to_particle( ipart );
103-
104-
if ( part->status() == 1 )
105-
{
106-
fDecayerPtr->event.reset();
107-
Particle py8part( part->pdg_id(), 93, 0, 0, 0, 0, 0, 0,
108-
part->momentum().x(),
109-
part->momentum().y(),
110-
part->momentum().z(),
111-
part->momentum().t(),
112-
part->generated_mass() );
113-
HepMC::GenVertex* ProdVtx = part->production_vertex();
114-
py8part.vProd( ProdVtx->position().x(), ProdVtx->position().y(),
115-
ProdVtx->position().z(), ProdVtx->position().t() );
116-
py8part.tau( (fDecayerPtr->particleData).tau0( part->pdg_id() ) );
117-
fDecayerPtr->event.append( py8part );
118-
int nentries = fDecayerPtr->event.size();
119-
if ( !fDecayerPtr->event[nentries-1].mayDecay() ) continue;
120-
fDecayerPtr->next();
121-
int nentries1 = fDecayerPtr->event.size();
122-
// --> fDecayerPtr->event.list(std::cout);
123-
if ( nentries1 <= nentries ) continue; //same number of particles, no decays...
124-
125-
part->set_status(2);
126-
127-
Particle& py8daughter = fDecayerPtr->event[nentries]; // the 1st daughter
128-
HepMC::GenVertex* DecVtx = new HepMC::GenVertex( HepMC::FourVector(py8daughter.xProd(),
129-
py8daughter.yProd(),
130-
py8daughter.zProd(),
131-
py8daughter.tProd()) );
132-
133-
DecVtx->add_particle_in( part ); // this will cleanup end_vertex if exists, replace with the new one
134-
// I presume (vtx) barcode will be given automatically
135-
136-
HepMC::FourVector pmom( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
137-
138-
HepMC::GenParticle* daughter =
139-
new HepMC::GenParticle( pmom, py8daughter.id(), 1 );
140-
141-
NewBarcode++;
142-
daughter->suggest_barcode( NewBarcode );
143-
DecVtx->add_particle_out( daughter );
144-
145-
for ( ipart=nentries+1; ipart<nentries1; ipart++ )
146-
{
147-
py8daughter = fDecayerPtr->event[ipart];
148-
HepMC::FourVector pmomN( py8daughter.px(), py8daughter.py(), py8daughter.pz(), py8daughter.e() );
149-
HepMC::GenParticle* daughterN =
150-
new HepMC::GenParticle( pmomN, py8daughter.id(), 1 );
151-
NewBarcode++;
152-
daughterN->suggest_barcode( NewBarcode );
153-
DecVtx->add_particle_out( daughterN );
154-
}
155-
156-
// event().get()->add_vertex( DecVtx );
157-
fCurrentEventState->add_vertex( DecVtx );
158-
159-
}
160-
}
161-
*/
162-
return true;
163-
164-
}
165-
16685

16786
void Py8InterfaceBase::statistics()
16887
{

0 commit comments

Comments
 (0)