10 #ifndef Pythia8_UserHooks_H
11 #define Pythia8_UserHooks_H
13 #include "Pythia8/Event.h"
14 #include "Pythia8/PartonSystems.h"
15 #include "Pythia8/PhysicsBase.h"
16 #include "Pythia8/PythiaStdlib.h"
17 #include "Pythia8/SigmaProcess.h"
31 class UserHooks :
public PhysicsBase {
36 virtual ~UserHooks() {}
39 virtual bool initAfterBeams() {
return true; }
42 virtual bool canModifySigma() {
return false;}
45 virtual double multiplySigmaBy(
const SigmaProcess* sigmaProcessPtr,
46 const PhaseSpace* phaseSpacePtr,
bool inEvent);
49 virtual bool canBiasSelection() {
return false;}
52 virtual double biasSelectionBy(
const SigmaProcess* sigmaProcessPtr,
53 const PhaseSpace* phaseSpacePtr,
bool inEvent);
56 virtual double biasedSelectionWeight() {
return 1./selBias;}
59 virtual bool canVetoProcessLevel() {
return false;}
63 virtual bool doVetoProcessLevel(
Event& ) {
return false;}
66 virtual bool canVetoResonanceDecays() {
return false;}
70 virtual bool doVetoResonanceDecays(
Event& ) {
return false;}
74 virtual bool canVetoPT() {
return false;}
77 virtual double scaleVetoPT() {
return 0.;}
83 virtual bool doVetoPT(
int ,
const Event& ) {
return false;}
87 virtual bool canVetoStep() {
return false;}
90 virtual int numberVetoStep() {
return 1;}
95 virtual bool doVetoStep(
int ,
int ,
int ,
const Event& ) {
return false;}
99 virtual bool canVetoMPIStep() {
return false;}
102 virtual int numberVetoMPIStep() {
return 1;}
106 virtual bool doVetoMPIStep(
int ,
const Event& ) {
return false;}
110 virtual bool canVetoPartonLevelEarly() {
return false;}
114 virtual bool doVetoPartonLevelEarly(
const Event& ) {
return false;}
119 virtual bool retryPartonLevel() {
return false;}
122 virtual bool canVetoPartonLevel() {
return false;}
126 virtual bool doVetoPartonLevel(
const Event& ) {
return false;}
129 virtual bool canSetResonanceScale() {
return false;}
134 virtual double scaleResonance(
int,
const Event& ) {
return 0.;}
137 virtual bool canVetoISREmission() {
return false;}
143 virtual bool doVetoISREmission(
int,
const Event&,
int ) {
return false;}
146 virtual bool canVetoFSREmission() {
return false;}
154 virtual bool doVetoFSREmission(
int,
const Event&,
int,
bool =
false )
158 virtual bool canVetoMPIEmission() {
return false; }
163 virtual bool doVetoMPIEmission(
int,
const Event &) {
return false; }
166 virtual bool canReconnectResonanceSystems() {
return false; }
173 virtual bool doReconnectResonanceSystems(
int,
Event &) {
return true;}
176 virtual bool canEnhanceEmission() {
return false;}
177 virtual double enhanceFactor(
string ) {
return 1.;}
178 virtual double vetoProbability(
string ) {
return 0.;}
179 void setEnhancedEventWeight(
double wt) { enhancedEventWeight = wt;}
180 double getEnhancedEventWeight() {
return enhancedEventWeight;}
184 virtual bool canEnhanceTrial() {
return false;}
185 void setEnhancedTrial(
double pTIn,
double wtIn) { pTEnhanced = pTIn;
187 double getEnhancedTrialPT() {
return pTEnhanced;}
188 double getEnhancedTrialWeight() {
return wtEnhanced;}
191 virtual bool canChangeFragPar() {
return false;}
196 virtual void setStringEnds(
const StringEnd*,
const StringEnd*,
202 virtual bool doChangeFragPar( StringFlav*, StringZ*, StringPT*,
int,
203 double, vector<int>,
const StringEnd* ) {
return false;}
208 virtual bool doVetoFragmentation( Particle,
const StringEnd *)
213 virtual bool doVetoFragmentation(Particle, Particle,
214 const StringEnd*,
const StringEnd* ) {
return false;}
217 virtual bool canSetImpactParameter()
const {
return false; }
220 virtual double doSetImpactParameter() {
return 0.0; }
228 virtual void onInitInfoPtr()
override {
230 userHooksPtr =
nullptr;
231 workEvent.init(
"(work event)", particleDataPtr);
235 void omitResonanceDecays(
const Event& process,
bool finalOnly =
false);
238 void subEvent(
const Event& event,
bool isHardest =
true);
241 Event workEvent = {};
247 double enhancedEventWeight = {}, pTEnhanced = {}, wtEnhanced = {};
258 class SuppressSmallPT :
public UserHooks {
263 SuppressSmallPT(
double pT0timesMPIIn = 1.,
int numberAlphaSIn = 0,
264 bool useSameAlphaSasMPIIn =
true) : pT20(0.) {isInit =
false;
265 pT0timesMPI = pT0timesMPIIn; numberAlphaS = numberAlphaSIn;
266 useSameAlphaSasMPI = useSameAlphaSasMPIIn;}
269 virtual bool canModifySigma() {
return true;}
273 virtual double multiplySigmaBy(
const SigmaProcess* sigmaProcessPtr,
274 const PhaseSpace* phaseSpacePtr,
bool );
279 bool isInit, useSameAlphaSasMPI;
281 double pT0timesMPI, pT20;
292 class UserHooksVector:
public UserHooks {
298 UserHooksVector() {};
302 virtual ~UserHooksVector() {}
306 virtual bool initAfterBeams() {
307 int nCanSetResonanceScale = 0;
308 int nCanChangeFragPar = 0;
309 int nCanSetImpactParameter = 0;
310 for (
int i = 0, N = hooks.size(); i < N; ++i ) {
311 registerSubObject(*hooks[i]);
312 if ( !hooks[i]->initAfterBeams() )
return false;
313 if (hooks[i]->canSetResonanceScale()) ++nCanSetResonanceScale;
314 if (hooks[i]->canChangeFragPar()) ++nCanChangeFragPar;
315 if (hooks[i]->canSetImpactParameter()) ++nCanSetImpactParameter;
317 if (nCanSetResonanceScale > 1) {
318 infoPtr->errorMsg(
"Error in UserHooksVector::initAfterBeams "
319 "multiple UserHooks with canSetResonanceScale() not allowed");
322 if (nCanChangeFragPar > 1) {
323 infoPtr->errorMsg(
"Error in UserHooksVector::initAfterBeams "
324 "multiple UserHooks with canChangeFragPar() not allowed");
327 if (nCanSetImpactParameter > 1) {
328 infoPtr->errorMsg(
"Error in UserHooksVector::initAfterBeams "
329 "multiple UserHooks with canSetImpactParameter() not allowed");
336 virtual bool canModifySigma() {
337 for (
int i = 0, N = hooks.size(); i < N; ++i )
338 if ( hooks[i]->canModifySigma() )
return true;
343 virtual double multiplySigmaBy(
const SigmaProcess* sigmaProcessPtr,
344 const PhaseSpace* phaseSpacePtr,
bool inEvent) {
346 for (
int i = 0, N = hooks.size(); i < N; ++i )
347 if ( hooks[i]->canModifySigma() )
348 f *= hooks[i]->multiplySigmaBy(sigmaProcessPtr, phaseSpacePtr,inEvent);
353 virtual bool canBiasSelection() {
354 for (
int i = 0, N = hooks.size(); i < N; ++i )
355 if ( hooks[i]->canBiasSelection() )
return true;
360 virtual double biasSelectionBy(
const SigmaProcess* sigmaProcessPtr,
361 const PhaseSpace* phaseSpacePtr,
bool inEvent) {
363 for (
int i = 0, N = hooks.size(); i < N; ++i )
364 if ( hooks[i]->canBiasSelection() )
365 f *= hooks[i]->biasSelectionBy(sigmaProcessPtr, phaseSpacePtr,
371 virtual double biasedSelectionWeight() {
373 for (
int i = 0, N = hooks.size(); i < N; ++i )
374 if ( hooks[i]->canBiasSelection() )
375 f *= hooks[i]->biasedSelectionWeight();
380 virtual bool canVetoProcessLevel() {
381 for (
int i = 0, N = hooks.size(); i < N; ++i )
382 if ( hooks[i]->canVetoProcessLevel() )
return true;
388 virtual bool doVetoProcessLevel(
Event& e) {
389 for (
int i = 0, N = hooks.size(); i < N; ++i )
390 if ( hooks[i]->canVetoProcessLevel() &&
391 hooks[i]->doVetoProcessLevel(e) )
return true;
396 virtual bool canVetoResonanceDecays() {
397 for (
int i = 0, N = hooks.size(); i < N; ++i )
398 if ( hooks[i]->canVetoResonanceDecays() )
return true;
404 virtual bool doVetoResonanceDecays(
Event& e) {
405 for (
int i = 0, N = hooks.size(); i < N; ++i )
406 if ( hooks[i]->canVetoResonanceDecays() &&
407 hooks[i]->doVetoResonanceDecays(e) )
return true;
413 virtual bool canVetoPT() {
414 for (
int i = 0, N = hooks.size(); i < N; ++i )
415 if ( hooks[i]->canVetoPT() )
return true;
420 virtual double scaleVetoPT() {
422 for (
int i = 0, N = hooks.size(); i < N; ++i )
423 if ( hooks[i]->canVetoPT() ) s = max(s, hooks[i]->scaleVetoPT());
431 virtual bool doVetoPT(
int iPos,
const Event& e) {
432 for (
int i = 0, N = hooks.size(); i < N; ++i )
433 if ( hooks[i]->canVetoPT() && hooks[i]->doVetoPT(iPos, e) )
return true;
439 virtual bool canVetoStep() {
440 for (
int i = 0, N = hooks.size(); i < N; ++i )
441 if ( hooks[i]->canVetoStep() )
return true;
446 virtual int numberVetoStep() {
448 for (
int i = 0, N = hooks.size(); i < N; ++i )
449 if ( hooks[i]->canVetoStep() ) n = max(n, hooks[i]->numberVetoStep());
456 virtual bool doVetoStep(
int iPos,
int nISR,
int nFSR,
const Event& e) {
457 for (
int i = 0, N = hooks.size(); i < N; ++i )
458 if ( hooks[i]->canVetoStep()
459 && hooks[i]->doVetoStep(iPos, nISR, nFSR, e) )
return true;
465 virtual bool canVetoMPIStep() {
466 for (
int i = 0, N = hooks.size(); i < N; ++i )
467 if ( hooks[i]->canVetoMPIStep() )
return true;
472 virtual int numberVetoMPIStep() {
474 for (
int i = 0, N = hooks.size(); i < N; ++i )
475 if ( hooks[i]->canVetoMPIStep() )
476 n = max(n, hooks[i]->numberVetoMPIStep());
482 virtual bool doVetoMPIStep(
int nMPI,
const Event& e) {
483 for (
int i = 0, N = hooks.size(); i < N; ++i )
484 if ( hooks[i]->canVetoMPIStep() && hooks[i]->doVetoMPIStep(nMPI, e) )
491 virtual bool canVetoPartonLevelEarly() {
492 for (
int i = 0, N = hooks.size(); i < N; ++i )
493 if ( hooks[i]->canVetoPartonLevelEarly() )
return true;
499 virtual bool doVetoPartonLevelEarly(
const Event& e) {
500 for (
int i = 0, N = hooks.size(); i < N; ++i )
501 if ( hooks[i]->canVetoPartonLevelEarly()
502 && hooks[i]->doVetoPartonLevelEarly(e) )
return true;
509 virtual bool retryPartonLevel() {
510 for (
int i = 0, N = hooks.size(); i < N; ++i )
511 if ( hooks[i]->retryPartonLevel() )
return true;
516 virtual bool canVetoPartonLevel() {
517 for (
int i = 0, N = hooks.size(); i < N; ++i )
518 if ( hooks[i]->canVetoPartonLevel() )
return true;
524 virtual bool doVetoPartonLevel(
const Event& e) {
525 for (
int i = 0, N = hooks.size(); i < N; ++i )
526 if ( hooks[i]->canVetoPartonLevel()
527 && hooks[i]->doVetoPartonLevel(e) )
return true;
532 virtual bool canSetResonanceScale() {
533 for (
int i = 0, N = hooks.size(); i < N; ++i )
534 if ( hooks[i]->canSetResonanceScale() )
return true;
541 virtual double scaleResonance(
int iRes,
const Event& e) {
543 for (
int i = 0, N = hooks.size(); i < N; ++i )
544 if ( hooks[i]->canSetResonanceScale() )
545 s = max(s, hooks[i]->scaleResonance(iRes, e));
550 virtual bool canVetoISREmission() {
551 for (
int i = 0, N = hooks.size(); i < N; ++i )
552 if ( hooks[i]->canVetoISREmission() )
return true;
560 virtual bool doVetoISREmission(
int sizeOld,
const Event& e,
int iSys) {
561 for (
int i = 0, N = hooks.size(); i < N; ++i )
562 if ( hooks[i]->canVetoISREmission()
563 && hooks[i]->doVetoISREmission(sizeOld, e, iSys) )
return true;
568 virtual bool canVetoFSREmission() {
569 for (
int i = 0, N = hooks.size(); i < N; ++i )
570 if ( hooks[i]->canVetoFSREmission() )
return true;
580 virtual bool doVetoFSREmission(
int sizeOld,
const Event& e,
581 int iSys,
bool inResonance =
false ) {
582 for (
int i = 0, N = hooks.size(); i < N; ++i )
583 if ( hooks[i]->canVetoFSREmission()
584 && hooks[i]->doVetoFSREmission(sizeOld, e, iSys, inResonance) )
590 virtual bool canVetoMPIEmission() {
591 for (
int i = 0, N = hooks.size(); i < N; ++i )
592 if ( hooks[i]->canVetoMPIEmission() )
return true;
599 virtual bool doVetoMPIEmission(
int sizeOld,
const Event & e) {
600 for (
int i = 0, N = hooks.size(); i < N; ++i )
601 if ( hooks[i]->canVetoMPIEmission()
602 && hooks[i]->doVetoMPIEmission(sizeOld, e) )
608 virtual bool canReconnectResonanceSystems() {
609 for (
int i = 0, N = hooks.size(); i < N; ++i )
610 if ( hooks[i]->canReconnectResonanceSystems() )
return true;
619 virtual bool doReconnectResonanceSystems(
int j,
Event & e) {
620 for (
int i = 0, N = hooks.size(); i < N; ++i )
621 if ( hooks[i]->canReconnectResonanceSystems()
622 && hooks[i]->doReconnectResonanceSystems(j, e) )
return true;
627 virtual bool canEnhanceEmission() {
628 for (
int i = 0, N = hooks.size(); i < N; ++i )
629 if ( hooks[i]->canEnhanceEmission() )
return true;
632 virtual double enhanceFactor(
string s) {
634 for (
int i = 0, N = hooks.size(); i < N; ++i )
635 if ( hooks[i]->canEnhanceEmission() ) f *= hooks[i]->enhanceFactor(s);
638 virtual double vetoProbability(
string s) {
640 for (
int i = 0, N = hooks.size(); i < N; ++i )
641 if ( hooks[i]->canEnhanceEmission() )
642 keep *= 1.0 - hooks[i]->vetoProbability(s);
648 virtual bool canEnhanceTrial() {
649 for (
int i = 0, N = hooks.size(); i < N; ++i )
650 if ( hooks[i]->canEnhanceTrial() )
return true;
655 virtual bool canChangeFragPar() {
656 for (
int i = 0, N = hooks.size(); i < N; ++i )
657 if ( hooks[i]->canChangeFragPar() )
return true;
662 virtual bool doVetoFragmentation(Particle p,
const StringEnd* nowEnd) {
663 for (
int i = 0, N = hooks.size(); i < N; ++i )
664 if ( hooks[i]->canChangeFragPar()
665 && hooks[i]->doVetoFragmentation(p, nowEnd) )
return true;
669 virtual bool doVetoFragmentation(Particle p1, Particle p2,
670 const StringEnd* e1,
const StringEnd* e2) {
671 for (
int i = 0, N = hooks.size(); i < N; ++i )
672 if ( hooks[i]->canChangeFragPar()
673 && hooks[i]->doVetoFragmentation(p1, p2, e1, e2) )
return true;
678 virtual bool canSetImpactParameter()
const {
679 for (
int i = 0, N = hooks.size(); i < N; ++i )
680 if ( hooks[i]->canSetImpactParameter() )
return true;
685 virtual double doSetImpactParameter() {
686 for (
int i = 0, N = hooks.size(); i < N; ++i )
687 if ( hooks[i]->canSetImpactParameter() )
688 return hooks[i]->doSetImpactParameter();
693 vector< shared_ptr<UserHooks> > hooks = {};
701 #endif // Pythia8_UserHooks_H