Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:21

0001 // -*- C++ -*-
0002 //
0003 // GenericMassGenerator.h is a part of Herwig - A multi-purpose Monte Carlo event generator
0004 // Copyright (C) 2002-2019 The Herwig Collaboration
0005 //
0006 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef HERWIG_GenericMassGenerator_H
0010 #define HERWIG_GenericMassGenerator_H
0011 //
0012 // This is the declaration of the GenericMassGenerator class.
0013 //
0014 #include "ThePEG/PDT/MassGenerator.h" 
0015 #include "ThePEG/Repository/EventGenerator.h"
0016 #include "ThePEG/PDT/ParticleData.h"
0017 #include "GenericMassGenerator.fh"
0018 #include "ThePEG/PDT/WidthGenerator.h"
0019 #include "GenericWidthGenerator.fh"
0020 #include "ThePEG/Repository/CurrentGenerator.h"
0021 
0022 namespace Herwig {
0023 using namespace ThePEG;
0024 
0025   /**
0026    *  Declare ModelGenerator class as must be friend to set the particle
0027    */
0028   class ModelGenerator;
0029 
0030 /** \ingroup PDT
0031  *
0032  *  The <code>GenericMassGenerator</code> class is a simple class for the
0033  *  generation of particle masses in Herwig. It inherits from the 
0034  *  <code>MassGenerator</code> class of ThePEG and implements a Breit-Wigner
0035  *  using the width generator to give the running width. 
0036  *
0037  *  In general the width generator will be an instance of the
0038  *  <code>GenericWidthGenerator</code> class which uses the Herwig decayers
0039  *  based on the <code>DecayIntegrator</code> class to define the shape of the
0040  *  running width.
0041  *
0042  *  This class is designed so that the weight
0043  *
0044  *  \f[\int dm^2 \frac{m\Gamma(m)}{(m^2-M^2)^2+m^2\Gamma^2(m)}\f]
0045  *
0046  *  can be included in the production of the particle to take off-shell effects into
0047  *  account. This is the default form of the weight. 
0048  *  The numerator and running of the width can 
0049  *  be changed using the BreitWignerShape interface.
0050  *
0051  *  @see MassGenerator
0052  *  @see DecayIntegrator
0053  *  @see GenericWidthGenerator
0054  * 
0055  */
0056 class GenericMassGenerator: public MassGenerator {
0057 
0058   /**
0059    *  ModelGenerator class as must be friend to set the particle
0060    */
0061   friend class ModelGenerator;
0062 
0063 public:
0064 
0065   /**
0066    * Default constructor
0067    */
0068   GenericMassGenerator();
0069 
0070   /**
0071    *  Destructor
0072    */
0073   virtual ~GenericMassGenerator();
0074 
0075   /** @name Functions used by the persistent I/O system. */
0076   //@{
0077   /**
0078    * Function used to write out object persistently.
0079    * @param os the persistent output stream written to.
0080    */
0081   void persistentOutput(PersistentOStream & os) const;
0082 
0083   /**
0084    * Function used to read in object persistently.
0085    * @param is the persistent input stream read from.
0086    * @param version the version number of the object when written.
0087    */
0088   void persistentInput(PersistentIStream & is, int version);
0089   //@}
0090 
0091   /**
0092    * Standard Init function used to initialize the interfaces.
0093    */
0094   static void Init();
0095 
0096 public:
0097 
0098   /**
0099    * Return true if this mass generator can handle the given particle type.
0100    * @param part The particle data pointer of the particle.
0101    * @return True ig this class can handle the particle and false otherwise
0102    */
0103   bool accept(const ParticleData & part) const;
0104 
0105   /** @name Members to generate the mass of a particle instance */
0106   //@{
0107   /**
0108    * Generate a mass using the default limits.
0109    * @param part The particle data pointer of the particle.
0110    * @return The mass of the particle instance.
0111    */
0112   Energy mass(const ParticleData & part) const {
0113     return mass(part,lowerMass_,upperMass_);
0114   }
0115 
0116   /**
0117    * Generate a mass using specified limits
0118    * @param part The particle data pointer of the particle.
0119    * @param low The lower limit on the particle's mass.
0120    * @param upp The upper limit on the particle's mass.
0121    * @return The mass of the particle instance.
0122    */
0123   Energy mass(const ParticleData & part,
0124           const Energy low,const Energy upp) const {
0125     if(upp<low) return low;
0126     Energy output;
0127     int ntry=0; double wgt=0.;
0128     do {
0129       ++ntry;
0130       output=mass(wgt,part,low,upp,3);
0131       if(wgt>maxWgt_) maxWgt_=wgt;
0132     }
0133     while(maxWgt_*(UseRandom::rnd())>wgt&&ntry<nGenerate_);
0134     return (ntry>=nGenerate_) ? mass_ : output;
0135   }
0136 
0137   /**
0138    * Return a mass with the weight using the default limits.
0139    * @param part The particle data pointer of the particle.
0140    * @param wgt The weight for this mass.
0141    * @param r   The random number used for the weight
0142    * @return The mass of the particle instance.
0143    */
0144   Energy mass(double & wgt, const ParticleData & part, 
0145           double r=UseRandom::rnd()) const {
0146     return mass(wgt,part,lowerMass_,upperMass_,r);
0147   }
0148   
0149   /**
0150    * Return a mass with the weight using the specified limits.
0151    * @param part The particle data pointer of the particle.
0152    * @param low The lower limit on the particle's mass.
0153    * @param upp The upper limit on the particle's mass.
0154    * @param wgt The weight for this mass.
0155    * @param r   The random number used for the weight
0156    * @return The mass of the particle instance.
0157    */
0158   Energy mass(double & wgt, const ParticleData & part,
0159           const Energy low,const Energy upp,
0160           double r=UseRandom::rnd()) const {
0161     return mass(wgt,part,low,upp,BWShape_,r);
0162   }
0163   
0164   /**
0165    * Weight for the factor.
0166    * @param q The mass of the instance
0167    * @return The weight.
0168    */
0169   virtual double weight(Energy q) const {
0170     return weight(q,BWShape_);
0171   }
0172 
0173   /**
0174    *  Return the full weight
0175    */
0176   virtual InvEnergy2 BreitWignerWeight(Energy q) {
0177     return BreitWignerWeight(q,BWShape_);
0178   }
0179   //@}
0180 
0181   /**
0182    * Output the initialisation info for the database
0183    */
0184   virtual void dataBaseOutput(ofstream &,bool);
0185 
0186 public:
0187 
0188   /** @name Access to particle properties */
0189   //@{
0190   /**
0191    * The running width.
0192    * @param q The mass for the calculation of the running width
0193    * @return The running width.
0194    */
0195   pair<Energy,Energy> width(Energy q,int shape) const;
0196 
0197   /**
0198    * Lower limit on the mass
0199    */
0200   Energy lowerLimit() const {return lowerMass_;}
0201 
0202   /**
0203    * Upper limit on the mass
0204    */
0205   Energy upperLimit() const {return upperMass_;}
0206 
0207   /**
0208    * Default mass
0209    */
0210   Energy nominalMass() const {return mass_;}
0211 
0212   /**
0213    * Default Width
0214    */
0215   Energy nominalWidth() const {return width_;}
0216 
0217 protected:
0218 
0219   /**
0220    * Return a mass with the weight using the specified limits.
0221    * @param low The lower limit on the particle's mass.
0222    * @param upp The upper limit on the particle's mass.
0223    * @param wgt The weight for this mass.
0224    * @param shape The type of shape to use
0225    * @param r   The random number used for the weight
0226    * @return The mass of the particle instance.
0227    */
0228   virtual Energy mass(double & wgt, const ParticleData & ,
0229               const Energy low,const Energy upp, int shape,
0230               double r=UseRandom::rnd()) const {
0231     // calculate the mass square using fixed width BW
0232     Energy  lo=max(low,lowerMass_),up=min(upp,upperMass_);
0233     double  rhomin=atan2((lo*lo-mass2_),mWidth_);
0234     double  rhomax=atan2((up*up-mass2_),mWidth_)-rhomin;
0235     double  rho=rhomin+rhomax*r;
0236     Energy2 q2 = mass2_+mWidth_*tan(rho);
0237     Energy  q = sqrt(q2);  
0238     wgt = rhomax*weight(q,shape);
0239     // return the mass
0240     return q;
0241   }
0242 
0243   /**
0244    * Return a mass with the weight using the default limits.
0245    * @param part The particle data pointer of the particle.
0246    * @param wgt The weight for this mass.
0247    * @param shape The type of shape to use
0248    * @param r   The random number used for the weight
0249    * @return The mass of the particle instance.
0250    */
0251   Energy mass(double & wgt, const ParticleData & part, int shape,
0252           double r=UseRandom::rnd()) const {
0253     return mass(wgt,part,lowerMass_,upperMass_,shape,r);
0254   }
0255 
0256   /**
0257    * Weight for the factor.
0258    * @param q The mass of the instance
0259    * @param shape The type of shape to use as for the BreitWignerShape interface
0260    * @return The weight.
0261    */
0262   inline virtual double weight(Energy q, int shape) const {
0263     Energy2 q2 = q*q;
0264     Energy4 sq=sqr(q2-mass2_);
0265     pair<Energy,Energy> gam=width(q,shape);
0266     // finish the calculation of the width
0267     Energy2 num;
0268     if(shape==2)      num = mass_*gam.first;
0269     else if(shape==3) num = mass_*gam.first;
0270     else              num = q    *gam.first;
0271     Energy4 den = (shape==2) ? sq+mass2_*gam.second*gam.second : sq+q2*gam.second*gam.second;
0272     return num/den*(sq+mWidth_*mWidth_)/Constants::pi/mWidth_;
0273   }
0274 
0275   /**
0276    *  Return the full weight
0277    */
0278   virtual InvEnergy2 BreitWignerWeight(Energy q, int shape) const {
0279     Energy2 q2 = q*q;
0280     Energy4 sq=sqr(q2-mass2_);
0281     pair<Energy,Energy> gam=width(q,shape);
0282     // finish the calculation of the width
0283     Energy2 num;
0284     if(shape==2)      num = mass_*gam.first;
0285     else if(shape==3) num = mass_*gam.first;
0286     else              num = q    *gam.first;
0287     Energy4 den = (shape==2) ? sq+mass2_*gam.second*gam.second : sq+q2*gam.second*gam.second;
0288     return num/den/Constants::pi;
0289   }
0290 
0291   /**
0292    *  Accesss to the particle
0293    */
0294   tcPDPtr particle() const {return particle_;}
0295 
0296   /**
0297    * Set the particle
0298    */
0299   void particle(tPDPtr in) {particle_ = in;}
0300 
0301 protected:
0302 
0303   /** @name Clone Methods. */
0304   //@{
0305   /**
0306    * Make a simple clone of this object.
0307    * @return a pointer to the new object.
0308    */
0309   virtual IBPtr clone() const;
0310 
0311   /** Make a clone of this object, possibly modifying the cloned object
0312    * to make it sane.
0313    * @return a pointer to the new object.
0314    */
0315   virtual IBPtr fullclone() const;
0316   //@}
0317 
0318 protected:
0319 
0320   /** @name Standard Interfaced functions. */
0321   //@{
0322   /**
0323    * Initialize this object after the setup phase before saving and
0324    * EventGenerator to disk.
0325    * @throws InitException if object could not be initialized properly.
0326    */
0327   virtual void doinit();
0328 
0329   /**
0330    * Finalize this object. Called in the run phase just after a
0331    * run has ended. Used eg. to write out statistics.
0332    */
0333   virtual void dofinish();
0334 
0335   /**
0336    * Rebind pointer to other Interfaced objects. Called in the setup phase
0337    * after all objects used in an EventGenerator has been cloned so that
0338    * the pointers will refer to the cloned objects afterwards.
0339    * @param trans a TranslationMap relating the original objects to
0340    * their respective clones.
0341    * @throws RebindException if no cloned object was found for a given
0342    * pointer.
0343    */
0344   virtual void rebind(const TranslationMap & trans)
0345    ;
0346 
0347   /**
0348    * Return a vector of all pointers to Interfaced objects used in this
0349    * object.
0350    * @return a vector of pointers.
0351    */
0352   virtual IVector getReferences();
0353   //@}
0354 
0355 private:
0356 
0357   /**
0358    * Private and non-existent assignment operator.
0359    */
0360   GenericMassGenerator & operator=(const GenericMassGenerator &) = delete;
0361 
0362 private:
0363  
0364   /**
0365    * Helper function for the interface
0366    */
0367   void setParticle(string);
0368 
0369   /**
0370    * Helper function for the interface
0371    */
0372   string getParticle() const;
0373 
0374 private:
0375 
0376   /**
0377    * The maximum weight for unweighting when generating the mass.
0378    */
0379   mutable double maxWgt_;
0380 
0381   /**
0382    * parameter controlling the shape of the Breit-Wigner
0383    */
0384   int BWShape_;
0385 
0386   /**
0387    * Number of attempts to generate the mass.
0388    */
0389   int nGenerate_;
0390 
0391 private:
0392 
0393   /**
0394    * Pointer to the particle
0395    */
0396   tPDPtr particle_;
0397 
0398   /**
0399    * Lower limit on the particle's mass
0400    */
0401   Energy lowerMass_;
0402 
0403   /**
0404    * Upper limit on the particle's mass
0405    */
0406   Energy upperMass_;
0407 
0408   /**
0409    * Mass of the particle
0410    */
0411   Energy mass_;
0412 
0413   /**
0414    * Width of the particle
0415    */
0416   Energy width_; 
0417 
0418   /**
0419    * Mass of the particle squared.
0420    */
0421   Energy2 mass2_;
0422 
0423   /**
0424    * Mass of the particle times the width.
0425    */
0426   Energy2 mWidth_;
0427 
0428   /**
0429    * Number of weights to generate when initializing
0430    */
0431   int nInitial_;
0432 
0433   /**
0434    * Whether or not to initialize the GenericMassGenerator
0435    */
0436   bool initialize_;
0437 
0438   /**
0439    * Whether or not to output the data to a file
0440    */
0441   bool output_;
0442 
0443   /**
0444    * Pointer to the width generator
0445    */
0446   WidthGeneratorPtr widthGen_;
0447 
0448   /**
0449    * Pointer to the width generator
0450    */
0451   GenericWidthGeneratorPtr widthGenB_;
0452 
0453   /**
0454    *  Option for the treatment of the width
0455    */
0456   bool widthOpt_;
0457 
0458 };
0459 
0460 }
0461 
0462 
0463 #endif /* HERWIG_GenericMassGenerator_H */