Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:20:03

0001 
0002 /***********************************************************************
0003 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors       *
0004 *                                                                      *
0005 * This file is part of EvtGen.                                         *
0006 *                                                                      *
0007 * EvtGen is free software: you can redistribute it and/or modify       *
0008 * it under the terms of the GNU General Public License as published by *
0009 * the Free Software Foundation, either version 3 of the License, or    *
0010 * (at your option) any later version.                                  *
0011 *                                                                      *
0012 * EvtGen is distributed in the hope that it will be useful,            *
0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
0015 * GNU General Public License for more details.                         *
0016 *                                                                      *
0017 * You should have received a copy of the GNU General Public License    *
0018 * along with EvtGen.  If not, see <https://www.gnu.org/licenses/>.     *
0019 ***********************************************************************/
0020 
0021 #ifndef EVTPARTICLE_HH
0022 #define EVTPARTICLE_HH
0023 
0024 //#include <iostream.h>
0025 #include "EvtGenBase/EvtId.hh"
0026 #include "EvtGenBase/EvtSpinDensity.hh"
0027 #include "EvtGenBase/EvtSpinType.hh"
0028 #include "EvtGenBase/EvtVector4R.hh"
0029 
0030 #include <assert.h>
0031 #include <map>
0032 #include <string>
0033 #include <vector>
0034 
0035 class EvtDiracSpinor;
0036 class EvtVector4C;
0037 class EvtTensor4C;
0038 class EvtStdHep;
0039 class EvtSecondary;
0040 class EvtRaritaSchwinger;
0041 
0042 const int MAX_DAUG = 100;
0043 const int MAX_LEVEL = 10;
0044 const int MAX_TRIES = 10000;
0045 
0046 class EvtParticle {
0047   public:
0048     /**
0049   * Default constructor.
0050   */
0051     EvtParticle();
0052 
0053     /**
0054   * Destructor.
0055   */
0056     virtual ~EvtParticle();
0057 
0058     /**
0059   * Returns polarization vector in the parents restframe.
0060   */
0061     virtual EvtVector4C epsParent( int i ) const;
0062 
0063     /**
0064   * Returns polarization vector in the particles own restframe.
0065   */
0066     virtual EvtVector4C eps( int i ) const;
0067 
0068     /**
0069   * Returns polarization vector in the parents restframe for a photon.
0070   */
0071     virtual EvtVector4C epsParentPhoton( int i );
0072 
0073     /**
0074   * Returns polarization vector in the particles own restframe for a photon.
0075   */
0076     virtual EvtVector4C epsPhoton( int i );
0077 
0078     /**
0079   * Returns Dirac spinor in the parents restframe for a Dirac particle.
0080   */
0081     virtual EvtDiracSpinor spParent( int ) const;
0082 
0083     /**
0084   * Returns Dirac spinor in the particles own restframe for a Dirac particle.
0085   */
0086     virtual EvtDiracSpinor sp( int ) const;
0087 
0088     /**
0089   * Returns Dirac spinor in the parents restframe for a Neutrino particle.
0090   */
0091     virtual EvtDiracSpinor spParentNeutrino() const;
0092 
0093     /**
0094   * Returns Dirac spinor in the particles own restframe for a
0095   * Neutrino particle.
0096   */
0097     virtual EvtDiracSpinor spNeutrino() const;
0098 
0099     /**
0100   * Returns tensor in the parents restframe for a spin 2 particle.
0101   */
0102     virtual EvtTensor4C epsTensorParent( int i ) const;
0103 
0104     /**
0105   * Returns tensor in the particles own restframe for a spin 2 particle.
0106   */
0107     virtual EvtTensor4C epsTensor( int i ) const;
0108 
0109     /**
0110    * Returns Rarita-Schwinger spinor in the parents restframe for a 
0111    * Rarita-Schwinger particle.
0112    */
0113     virtual EvtRaritaSchwinger spRSParent( int ) const;
0114 
0115     /**
0116    * Returns Rarita-Schwinger spinor in the particles own restframe for a 
0117    * Rarita-Schwinger particle.
0118    */
0119     virtual EvtRaritaSchwinger spRS( int ) const;
0120 
0121     /**
0122   * Initialiaze particle with id and 4momentum.
0123   */
0124     virtual void init( EvtId part_n, const EvtVector4R& p4 ) = 0;
0125 
0126     /**
0127   * Add another daughter to the particle
0128   */
0129     void addDaug( EvtParticle* node );
0130 
0131     /**
0132   * Decay particle
0133   */
0134     void decay();
0135 
0136     /** 
0137   * Delete a decay chain
0138   */
0139     void deleteTree();
0140     void deleteDaughters( bool keepChannel = false );
0141 
0142     /**
0143   * Should only be used internally.
0144   */
0145     void setChannel( int i );
0146 
0147     /**
0148   * Creates the daughters in the list of ids and 
0149   * adds them to the parent. Note that momentum
0150   * is left uninitialized, this is _only_ creation.
0151   */
0152     void makeDaughters( unsigned int ndaug, EvtId* id );
0153 
0154     /**
0155   * Creates the daughters in the list of ids and 
0156   * adds them to the parent. Note that momentum
0157   * is left uninitialized, this is _only_ creation.
0158   */
0159     void makeDaughters( unsigned int ndaug, std::vector<EvtId> idVector );
0160 
0161     /**
0162   * Similar to the routine above except that here 
0163   * momentum is generated according to phase space 
0164   * daughters are filled with this momentum.
0165   */
0166     double initializePhaseSpace( unsigned int numdaughter, EvtId* daughters,
0167                                  bool forceResetMasses = false,
0168                                  double poleSize = -1., int whichTwo1 = 0,
0169                                  int whichTwo2 = 1 );
0170 
0171     /**
0172   * Get pointer the the i:th daugther.
0173   */
0174     EvtParticle* getDaug( int i );
0175 
0176     /**
0177   * Iterates over the particles in a decay chain.
0178   */
0179     EvtParticle* nextIter( EvtParticle* rootOfTree = 0 );
0180 
0181     /**
0182   * Makes stdhep list
0183   */
0184     void makeStdHep( EvtStdHep& stdhep, EvtSecondary& secondary,
0185                      EvtId* stable_parent_ihep );
0186     void makeStdHep( EvtStdHep& stdhep );
0187 
0188     /**
0189   * Gets 4vector in the labframe, i.e., the frame in which the root
0190   * particles momentum is measured.
0191   */
0192     EvtVector4R getP4Lab() const;
0193 
0194     /**
0195   * Gets 4vector in the labframe for the 4-momentum before FSR was 
0196   * generated in the parents decay. The lab frame is where the root
0197   * particles momentum is measured.
0198   */
0199     EvtVector4R getP4LabBeforeFSR();
0200 
0201     /**
0202   * Gets 4vector in the particles restframe, i.e. this functiont will
0203   * return (m,0,0,0)
0204   */
0205     EvtVector4R getP4Restframe() const;
0206 
0207     /**
0208   * Returns the 4position of the particle in the lab frame.
0209   */
0210     EvtVector4R get4Pos() const;
0211 
0212     /**
0213   * Returns pointer to parent particle.
0214   */
0215     EvtParticle* getParent() const;
0216 
0217     /**
0218   * Makes partptr the idaug:th daugther.
0219   */
0220     void insertDaugPtr( int idaug, EvtParticle* partptr )
0221     {
0222         _daug[idaug] = partptr;
0223         partptr->_parent = this;
0224     }
0225     /**
0226   * Returns mass of particle.
0227   */
0228     double mass() const;
0229 
0230     /**
0231   * Used internally to decide if first time particle is decayed.
0232   */
0233     int firstornot() const;
0234     void setFirstOrNot();
0235     void resetFirstOrNot();
0236 
0237     /**
0238   * Returns Id of particle.
0239   */
0240     EvtId getId() const;
0241 
0242     /**
0243   * Returns the PDG id of the particle
0244   */
0245 
0246     int getPDGId() const;
0247 
0248     /** 
0249   * Returns particle type.
0250   */
0251 
0252     EvtSpinType::spintype getSpinType() const;
0253 
0254     /**
0255   * Returns number of spin states of the particle.
0256   */
0257     int getSpinStates() const;
0258 
0259     /**
0260   * Returns 4momentum in parents restframe.
0261   */
0262     const EvtVector4R& getP4() const;
0263 
0264     /**
0265   * Sets the 4momentum in the parents restframe.
0266   */
0267     void setP4( const EvtVector4R& p4 )
0268     {
0269         _p = p4;
0270         _pBeforeFSR = p4;
0271     }
0272 
0273     void setP4WithFSR( const EvtVector4R& p4 ) { _p = p4; }
0274 
0275     void setFSRP4toZero() { _pBeforeFSR.set( 0.0, 0.0, 0.0, 0.0 ); }
0276 
0277     /**
0278   * Retunrs the decay channel.
0279   */
0280     int getChannel() const;
0281 
0282     /**
0283   * Returns number of daugthers.
0284   */
0285     size_t getNDaug() const;
0286     void resetNDaug()
0287     {
0288         _ndaug = 0;
0289         return;
0290     }
0291 
0292     /**
0293   * Prints out the particle "tree" of a given particle.  The
0294   * tree consists of all daughters (and their daughters, etc)
0295   * and their properties.
0296   */
0297     void printTree() const;
0298 
0299     void printTreeRec( unsigned int level ) const;
0300 
0301     std::string treeStr() const;
0302     std::string treeStrRec( unsigned int level ) const;
0303 
0304     /**
0305   * Prints information for the particle.
0306   */
0307     void printParticle() const;
0308 
0309     /**
0310   * Set lifetime of the particle in parents restframe.
0311   */
0312     void setLifetime( double tau );
0313 
0314     /**
0315   * Generate lifetime according to pure exponential.
0316   */
0317     void setLifetime();
0318 
0319     /**
0320   * Returns the lifetime.
0321   */
0322     double getLifetime();
0323 
0324     /** 
0325   * Set diagonal spindensity matrix.
0326   */
0327     void setDiagonalSpinDensity();
0328 
0329     /** 
0330   * Set spindensity matrix for e+e- -> V
0331   */
0332     void setVectorSpinDensity();
0333 
0334     /**
0335   * Set forward spin density matrix.
0336   */
0337     void setSpinDensityForward( const EvtSpinDensity& rho )
0338     {
0339         _rhoForward = rho;
0340     }
0341 
0342     /**
0343   * Set forward spin density matrix according to the density matrix
0344   * rho in the helicity amplitude basis.
0345   */
0346     void setSpinDensityForwardHelicityBasis( const EvtSpinDensity& rho );
0347     void setSpinDensityForwardHelicityBasis( const EvtSpinDensity& rho,
0348                                              double alpha, double beta,
0349                                              double gamma );
0350 
0351     /**
0352   * Returns a rotation matrix need to rotate the basis state
0353   * to the helicity basis. The EvtSpinDensity matrix is just use
0354   * as a matrix here. This function is to be implemented in each
0355   * derived class.
0356   */
0357     virtual EvtSpinDensity rotateToHelicityBasis() const = 0;
0358     virtual EvtSpinDensity rotateToHelicityBasis( double alpha, double beta,
0359                                                   double gamma ) const = 0;
0360 
0361     /**
0362   * Get forward spin density matrix.
0363   */
0364     EvtSpinDensity getSpinDensityForward() { return _rhoForward; }
0365 
0366     /**
0367   * Set backward spin density matrix.
0368   */
0369     void setSpinDensityBackward( const EvtSpinDensity& rho )
0370     {
0371         _rhoBackward = rho;
0372     }
0373 
0374     /**
0375   * Get backward spin density matrix.
0376   */
0377     EvtSpinDensity getSpinDensityBackward() { return _rhoBackward; }
0378 
0379     //Hacks will be removed when better solutions are thought of!
0380     //This is used to suppress use of random numbers when doing initialization
0381     //of some models.
0382     void noLifeTime() { _genlifetime = 0; }
0383 
0384     //lange - April 29, 2002
0385     void setId( EvtId id ) { _id = id; }
0386     void initDecay( bool useMinMass = false );
0387     bool generateMassTree();
0388 
0389     double compMassProb();
0390 
0391     //setMass will blow away any existing 4vector
0392     void setMass( double m ) { _p = EvtVector4R( m, 0.0, 0.0, 0.0 ); }
0393 
0394     //void setMixed() {_mix=true;}
0395     //void setUnMixed() {_mix=false;}
0396     //bool getMixed() {return _mix;}
0397 
0398     //void takeCConj() {EvtGenReport(EVTGEN_INFO,"EvtGen") << "should take conj\n";}
0399 
0400     //this means that the particle has gone through initDecay
0401     // and thus has a mass
0402     bool isInitialized() { return _isInit; }
0403     bool hasValidP4() { return _validP4; }
0404     bool isDecayed() { return _isDecayed; }
0405 
0406     // decay prob - only relevent if already decayed
0407     // and is a scalar particle
0408     // returned is a double* that should be prob/probMax
0409     double* decayProb() { return _decayProb; }
0410     void setDecayProb( double p );
0411 
0412     // Return the name of the particle (from the EvtId number)
0413     std::string getName();
0414 
0415     // Specify whether the particle has a special named attribute with
0416     // a set value. By default, nothing is set, but derived classes
0417     // can set this to mean something specific, e.g. if a photon is FSR
0418     void setAttribute( std::string attName, int attValue )
0419     {
0420         _intAttributes[attName] = attValue;
0421     }
0422 
0423     // Retrieve the integer value for the given attribute name
0424     int getAttribute( std::string attName );
0425 
0426     // Specify if the particle has a double attribute value, e.g. amplitude weight.
0427     // By default, nothing is set, but derived classes can set this to mean something specific
0428     void setAttributeDouble( std::string attName, double attValue )
0429     {
0430         _dblAttributes[attName] = attValue;
0431     }
0432 
0433     // Retrieve the double value for the given attribute name
0434     double getAttributeDouble( std::string attName );
0435 
0436   protected:
0437     void setp( double e, double px, double py, double pz )
0438     {
0439         _p.set( e, px, py, pz );
0440         _pBeforeFSR = _p;
0441     }
0442 
0443     void setp( const EvtVector4R& p4 )
0444     {
0445         _p = p4;
0446         _pBeforeFSR = _p;
0447     }
0448 
0449     void setpart_num( EvtId particle_number )
0450     {
0451         assert( _channel == -10 || _id.getId() == particle_number.getId() ||
0452                 _id.getId() == -1 );
0453         _id = particle_number;
0454     }
0455     bool _validP4;
0456 
0457     // A typedef to define the attribute (name, integer) map
0458     typedef std::map<std::string, int> EvtAttIntMap;
0459     EvtAttIntMap _intAttributes;
0460 
0461     // A typedef to define the attribute (name, double) map
0462     typedef std::map<std::string, double> EvtAttDblMap;
0463     EvtAttDblMap _dblAttributes;
0464 
0465   private:
0466     EvtParticle* _daug[MAX_DAUG];
0467     size_t _ndaug;
0468     EvtParticle* _parent;
0469     int _channel;
0470     int _first;
0471     EvtId _id;
0472     EvtVector4R _p;
0473     EvtVector4R _pBeforeFSR;
0474     double _t;
0475     bool _isInit;
0476     bool _isDecayed;
0477 
0478     //bool _mix;
0479 
0480     EvtSpinDensity _rhoForward;
0481     EvtSpinDensity _rhoBackward;
0482 
0483     void makeStdHepRec( int firstparent, int lastparent, EvtStdHep& stdhep,
0484                         EvtSecondary& secondary, EvtId* stable_parent_ihep );
0485     void makeStdHepRec( int firstparent, int lastparent, EvtStdHep& stdhep );
0486 
0487     //This is a hack until things gets straightened out. (Ryd)
0488     int _genlifetime;
0489 
0490     //should never be used, therefor is private.
0491     //these does _not_ have an implementation
0492     EvtParticle& operator=( const EvtParticle& p );
0493     EvtParticle( const EvtParticle& p );
0494 
0495     double* _decayProb;
0496 };
0497 
0498 #endif