Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Step.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG 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 ThePEG_BasicStep_H
0010 #define ThePEG_BasicStep_H
0011 // This is the declaration of the Step class.
0012 
0013 #include "ThePEG/EventRecord/Particle.h"
0014 #include "ThePEG/EventRecord/StandardSelectors.h"
0015 
0016 namespace ThePEG {
0017 
0018 /**
0019  * The Step class contains information of all particles present after
0020  * certain step in the event generation. There is also information
0021  * about particles which were introduced as intermediate ones in the
0022  * generation of the step. The Step may also contain one or more
0023  * SubProcesses which were generated in the step. The Step is linked
0024  * back to the Collision to which it belongs, and there may be a
0025  * pointer to the StepHandler which generated the step.
0026  *
0027  * @see Event
0028  * @see Collision
0029  * @see SubProcess
0030  * @see Particle
0031  * @see SelectorBase
0032  * @see SelectorBase
0033  */
0034 class Step: public EventRecordBase {
0035 
0036 public:
0037 
0038   /** Most of the Event classes are friends with each other. */
0039   friend class Collision;
0040   /** Most of the Event classes are friends with each other. */
0041   friend class Event;
0042 
0043 public:
0044 
0045   /**
0046    * Standard constructor.
0047    * @param newCollision the Collision to which this Step belongs.
0048    * @param newHandler the handler object in charge of the generation
0049    * of this Step.
0050    */
0051   Step(tCollPtr newCollision = tCollPtr(),
0052        tcEventBasePtr newHandler = tcEventBasePtr())
0053     : theCollision(newCollision), theHandler(newHandler) {}
0054 
0055   /**
0056    * The copy constructor.
0057    */
0058   Step(const Step &);
0059 
0060   /**
0061    * The destructor.
0062    */
0063   ~Step();
0064 
0065   /**
0066    * Return a pointer to the step handler which performed the
0067    * generation of this step.
0068    */
0069   tcEventBasePtr handler() const { return theHandler; }
0070 
0071   /**
0072    * Return a pointer to the Collision to which this step belongs.
0073    */
0074   tCollPtr collision() const { return theCollision; }
0075 
0076   /**
0077    * Extract particles from this Step which satisfies the
0078    * requirements given by an object of the SelectorBase class.
0079    * @param r an output iterator specifying where the extracted
0080    * (pointers to) particles will be appended.
0081    * @param s SelectorBase object defining which particles should be
0082    * extracted.
0083    */
0084   template <typename OutputIterator>
0085   void select(OutputIterator r, const SelectorBase & s) const;
0086 
0087   /**
0088    * Extract all final state particles in this Step.
0089    * @param r an output iterator specifying where the extracted
0090    * (pointers to) particles will be appended.
0091    */
0092   template <typename OutputIterator>
0093   void selectFinalState(OutputIterator r) const {
0094     select(r, SelectFinalState());
0095   }
0096 
0097   /**
0098    * Extract all final state particles in this Step.
0099    * @return a vector of pointers to the extracted particles.
0100    */
0101   tPVector getFinalState() const {
0102     tPVector ret;
0103     selectFinalState(back_inserter(ret));
0104     return ret;
0105   }
0106 
0107   /**
0108    * Return a vector of particle vectors with colour-connected
0109    * partons, where each particle vector is in a colour singlet state.
0110    * @deprecated Use the corresponding functions in ColourLine instead.
0111    */
0112   template <typename PIterator>
0113   static vector<tPVector> getSinglets(PIterator first, PIterator last) {
0114     tParticleSet left(first, last);
0115     return getSinglets(left);
0116   }
0117 
0118   /**
0119    * A reference to the set of all particles in this step.
0120    */
0121   const ParticleSet & all() const { return allParticles; }
0122 
0123   /**
0124    * A reference to the set of outgoing particles in this step.
0125    */
0126   const ParticleSet & particles() const { return theParticles; }
0127 
0128   /**
0129    * A reference to the set of intermediate particles in this step.
0130    */
0131   const ParticleSet & intermediates() const { return theIntermediates; }
0132 
0133   /**
0134    * A reference to the vector of sub-processes introduced in this
0135    * step.
0136    */
0137   const SubProcessVector & subProcesses() const {
0138     return theSubProcesses;
0139   }
0140 
0141   /**
0142    * Returns the colliding particles in the collision to which this
0143    * step belongs. (If this step does not belong to a collision, this
0144    * method will probably cause a segmentation fault - This should be
0145    * fixed. @deprecated Maybe this method is not needed at all.)
0146    */
0147   const PPair & incoming() const;
0148 
0149   /**
0150    * Get mutable particle. If the given particle is present in this
0151    * step, return its pointer otherwise return the null pointer;
0152    */
0153   tPPtr find(tcPPtr p) const {
0154     tPPtr r = const_ptr_cast<tPPtr>(p);
0155     if ( !member(all(), r) ) return tPPtr();
0156     return r;
0157   }
0158 
0159 
0160   /**
0161    * Copy a particle. If the given Particle is present in this step,
0162    * insert a copy and remove the original (or make it intermediate if
0163    * it was initially added to this step). Returns the new Particle if
0164    * the copy succeeded. If the copy fails, nothing is changed. For a
0165    * successful call <code>copyParticle(p)->previous() == p</code> is
0166    * true.
0167    */
0168   tPPtr copyParticle(tcPPtr p);
0169 
0170   /**
0171    * Make particles copies of eachother. Declare that pold and pnew
0172    * are two instances of the same particle. If pnew is not present in
0173    * the step it will be afterwars. Afterwards <code>pold ==
0174    * pnew->previous() && pnew == pold->next()</code> is true. Returns
0175    * false if something went wrong.
0176    */
0177   bool setCopy(tcPPtr pold, tPPtr pnew);
0178 
0179   /**
0180    * Insert a copy. If the given particle is present in the current
0181    * Collision, insert copy of that particle 'before' the particle. If
0182    * the particle does not belong to the current collision or if the
0183    * copy failed, nothing is changed and the null pointer is
0184    * returned. If successful <code>insertCopy(p)->next() == p</code>
0185    * is true. The parents of the original particle will become the
0186    * parents of the copy.
0187    */
0188   tPPtr insertCopy(tcPPtr p);
0189 
0190   /**
0191    * Add decay product. If the \a parent is present in this step or if
0192    * it has immediate children in this step, insert the \a child and
0193    * fix up references between the two. If the parent is among the
0194    * final state particles, remove it (or make it intermediate if it
0195    * was initially added to this step). The parent/child pointers of
0196    * the affected particles will be set accordingly. If both the
0197    * parent and child/children are coloured and \a fixColour is true,
0198    * the colour flow will be set.
0199    * @return true iff the addition succeeded.
0200    */
0201   bool addDecayProduct(tcPPtr parent, tPPtr child, bool fixColour = true);
0202 
0203   /**
0204    * Add decay products. If the \a parent is present in this step or if
0205    * it has immediate children in this step, insert the range of
0206    * children and fix up references between the two. If the parent is
0207    * among the final state particles, remove it (or make it
0208    * intermediate if it was initially added to this step). The
0209    * parent/child pointers of the affected particles will be set
0210    * accordingly. If both the parent and children are coloured and \a
0211    * fixColour is true, the colour flow will be set. The colour of the
0212    * parent will then flow to the first added child, while the anti
0213    * colour will flow to the last added child.
0214    * @return true iff the addition succeeded.
0215    */
0216   template <typename CIterator>
0217   bool addDecayProduct(tcPPtr parent,
0218                CIterator firstChild, CIterator lastChild,
0219                bool fixColour = true) {
0220     for ( ; firstChild != lastChild; ++firstChild )
0221       if ( !addDecayProduct(parent, *firstChild, fixColour) ) return false;
0222     return true;
0223   }
0224 
0225   /**
0226    * Add a particle to this Step. It is assumed to be already setup as
0227    * a child to a parent particle. The parent is removed from the list
0228    * of final state particles in this step. No consistency checks are
0229    * performed. @deprecated Use addDecayProduct(tPPtr child) instead.
0230    */
0231   void addDecayNoCheck(tPPtr parent, tPPtr child);
0232 
0233   /**
0234    * Add a particle to this Step. It is assumed to be already setup as
0235    * a child to parent particles. The parents are removed from the
0236    * list of final state particles in this step. No consistency checks
0237    * are performed.
0238    */
0239   void addDecayProduct(tPPtr child);
0240 
0241   /**
0242    * Remove the \a child form the given \a parent. The \a child is not
0243    * removed from the decay record.
0244    */
0245   bool removeDecayProduct(tcPPtr parent, tPPtr child);
0246 
0247   /**
0248    * Remove children form the given \a parent. The children are not
0249    * removed from the decay record.
0250    */
0251   template <typename CIterator>
0252   bool removeDecayProduct(tcPPtr parent,
0253               CIterator firstChild, CIterator lastChild) {
0254     bool success = true;
0255     for ( ; firstChild != lastChild; ++firstChild )
0256       if ( !removeDecayProduct(parent, *firstChild) ) success = false;
0257     return success;
0258   }
0259 
0260   /**
0261    * Add decay product. Add the \a child as a decay product of all the
0262    * listed parents. The parents must satisfy the same requirements as
0263    * in the addDecayProduct(tcPPtr,tPPtr,bool) function. If any of the
0264    * parents fail false is returned and nothing is changed. The
0265    * parent/child pointers of the affected particles will be set
0266    * accordingly, but no colour flow wll be set. If \a checkfinal is
0267    * true the parents or its immediate children must be in the final
0268    * state.
0269    */
0270   template <typename Iterator>
0271   bool addDecayProduct(Iterator firstParent, Iterator lastParent, tPPtr child,
0272                bool checkfinal = true);
0273 
0274   /**
0275    * Add the children as a decay products of all the listed
0276    * particles. The parents must satisfy the same requirements as in
0277    * the addDecayProduct(tcPPtr,tPPtr,bool) function. If any of the
0278    * parents fail false is returned and nothing is changed. The
0279    * parent/child pointers of the affected particles will be set
0280    * accordingly, but no colour flow wll be set.
0281    */
0282   template <typename PIterator, typename CIterator>
0283   bool addDecayProduct(PIterator firstParent, PIterator lastParent,
0284                CIterator firstChild, CIterator lastChild);
0285 
0286   /**
0287    * Fix the colour flow of particles which have been added to this
0288    * step and which have not already had their colour neighbours set.
0289    * If a neighbor is found which has not been added in this step, it
0290    * is first cloned in order not to compromise the colour flow of
0291    * previous steps. @deprecated This method should not be needed with
0292    * the current ColourLine representation of colour.
0293    */
0294   void fixColourFlow();
0295 
0296   /**
0297    * Return the (\a anti-)colour neighbour of the given \a particle if
0298    * one exists in the final state of this Step. The colour neighbour
0299    * has its colour connected to the same colour line as the given \a
0300    * particles anti-colour. Will return null if the given \a particle
0301    * is not in the final state of this Step.
0302    */
0303   tPPtr colourNeighbour(tcPPtr particle, bool anti = false) const;
0304 
0305   /**
0306    * Return the anti-colour neighbour of the given \a particle if one
0307    * exists in the final state of this Step. The anti-colour neighbour
0308    * has its anti-colour connected to the same colour line as the
0309    * given \a particles colour. Will return null if the given \a
0310    * particle is not in the final state of this Step.
0311    */
0312   tPPtr antiColourNeighbour(tcPPtr particle) const;
0313 
0314   /**
0315    * Add a range of particles to this Step. If this step belongs
0316    * to a Collision, the paticle will also be added to the
0317    * Collision. If this particle has not previously been in a Step,
0318    * the birthStep pointer of the particle will be set.
0319    */
0320   template <typename Iterator>
0321   void addParticles(Iterator first, Iterator last);
0322 
0323   /**
0324    * Add a particle to this step. If this step belongs to a Collision,
0325    * the paticle will also be added to the Collision. If this particle
0326    * has not previously been in a Step, the birthStep pointer of the
0327    * particle will be set.
0328    */
0329   void addParticle(tPPtr p);
0330 
0331   /**
0332    * Add a range of intermediate particles in this step. If this step
0333    * belongs to a Collision, the particles will also be added to the
0334    * Collision. If any particle has not previously been in a Step,
0335    * the birthStep pointer of the particle will be set. The particles
0336    * will be removed from the list of final state particles if
0337    * present.
0338    */
0339   template <typename Iterator>
0340   void addIntermediates(Iterator first, Iterator last);
0341 
0342   /**
0343    * Add an intermediate particle in this Step. If this Step belongs
0344    * to a Collision, the particle will also be added to the
0345    * Collision. If this particle has not previously been in a step,
0346    * the birthStep pointer of the particle will be set. The particle
0347    * will be removed from the list of final state particles if
0348    * present.
0349    */
0350   void addIntermediate(tPPtr p);
0351 
0352   /**
0353    * Add an intermediate particle. Particle \a p is added so that if
0354    * \a child previously was the child of \a parent, afterwards \a p
0355    * will be the child of \a parent and \a child will be the child of
0356    * \a p.
0357    */
0358   void insertIntermediate(tPPtr p, tPPtr parent, tPPtr child);
0359 
0360   /**
0361    * Add a sub-process. All outgoing particles are added to the list
0362    * of outgoing particles in the step. All other particles in the
0363    * sub-process will be added to the list of intermediates.
0364    */
0365   void addSubProcess(tSubProPtr);
0366 
0367   /**
0368    * Remove a sub-process. All incoming and outgoing particles are
0369    * removed as well.
0370    */
0371   void removeSubProcess(tSubProPtr);
0372 
0373   /**
0374    * Remove (recursively) the given Particle from the Step. If
0375    * this was the last daughter of the mother Particle, the latter is
0376    * added to the list of final state particles.  
0377    */
0378   void removeParticle(tPPtr p);
0379 
0380   /**
0381    * Return true if no new particles were introduced in this step.
0382    */
0383   bool nullStep() const;
0384 
0385   /**
0386    * Get final state particles. Given a container, return the ones
0387    * which belongs to the final state of this step. If a particle does
0388    * not belong to these, it's children (or next instance) will be
0389    * checked and possibly added instead (recursively).
0390    */
0391   template <typename Cont>
0392   tParticleSet getCurrent(const Cont & c) const {
0393     return getCurrent(c.begin(), c.end());
0394   }
0395 
0396   /**
0397    * Get final state particles. Given a range of particles, return the
0398    * ones which belongs to the final state of this step. If a particle
0399    * does not belong to these, it's children (or next instance) will
0400    * be checked and possibly added instead (recursively)
0401    */
0402   template <typename Iterator>
0403   tParticleSet getCurrent(Iterator first, Iterator last) const;
0404 
0405   /**
0406    * Return a clone of this step.
0407    */
0408   StepPtr clone() const;
0409 
0410 public:
0411 
0412   /**
0413    * Standard function for writing to a persistent stream.
0414    */
0415   void persistentOutput(PersistentOStream &) const;
0416   /**
0417    * Standard function for reading from a persistent stream.
0418    */
0419   void persistentInput(PersistentIStream &, int);
0420 
0421   /**
0422    * Standard Init function. @see Base::Init().
0423    */
0424   static void Init();
0425 
0426 protected:
0427 
0428   /**
0429    * Used internally by the public getSinglets(...); @deprecated Use
0430    * the corresponding functions in ColourLine instead.
0431    */
0432   static vector<tPVector> getSinglets(tParticleSet &);
0433 
0434   /**
0435    * Remove a particle entry from the step. Make its ancesters (if
0436    * any) present in this step.
0437    */
0438   void removeEntry(tPPtr p);
0439 
0440   /**
0441    * Rebind to cloned objects. When a Step is cloned, a shallow copy
0442    * is done first, then all <code>Particle</code>s etc, are cloned,
0443    * and finally this method is used to see to that the pointers in
0444    * the cloned Step points to the cloned <code>Particle</code>s etc.
0445    */
0446   void rebind(const EventTranslationMap & trans);
0447 
0448   /**
0449    * Get final state particles. Insert particle \a p into with the
0450    * Inserter \a o if \a p is a member of the final state of this
0451    * Step. Otherwise call the method for the children of \a p if any.
0452    */
0453   template <typename Inserter, typename PPointer>
0454   void addIfFinal(Inserter o, PPointer p);
0455 
0456 private:
0457 
0458   /**
0459    * Assignement is not allowed.
0460    */
0461   Step & operator=(const Step &) = delete;
0462 
0463   /**
0464    * Setup pointer to the Collision.
0465    */
0466   void collision(tCollPtr c) { theCollision = c; }
0467 
0468   /**
0469    * Setup pointer to the step handler.
0470    */
0471   void handler(tcEventBasePtr sh) { theHandler = sh; }
0472 
0473 private:
0474 
0475   /**
0476    * The set of all outgoing particle in this step.
0477    */
0478   ParticleSet theParticles;
0479 
0480   /**
0481    * The set of all intermediate particle in this step.
0482    */
0483   ParticleSet theIntermediates;
0484 
0485   /**
0486    * The vector of all sub-processes introduced in this step.
0487    */
0488   SubProcessVector theSubProcesses;
0489 
0490   /**
0491    * The set of all particles available in this step.
0492    */
0493   ParticleSet allParticles;
0494 
0495   /**
0496    * Pointer to the collision to which this step belongs.
0497    */
0498   tCollPtr theCollision;
0499 
0500   /**
0501    * Pointer ot the step handler which performed this step.
0502    */
0503   tcEventBasePtr theHandler;
0504 
0505 public:
0506 
0507   /**
0508    * Print out debugging information for this object on std::cerr. To
0509    * be called from within a debugger via the debug() function.
0510    */
0511   virtual void debugme() const;
0512 
0513 private:
0514 
0515   /**
0516    * Describe concrete class with persistent data.
0517    */
0518   static ClassDescription<Step> initStep;
0519 
0520 };
0521 
0522 /** Output a Step to an ostream */
0523 ostream & operator<<(ostream &, const Step &);
0524 
0525 /** @cond TRAITSPECIALIZATIONS */
0526 ThePEG_DECLARE_CLASS_TRAITS(Step,EventRecordBase);
0527 /** @endcond */
0528 
0529 }
0530 
0531 #include "Collision.h"
0532 
0533 inline const ThePEG::PPair & ThePEG::Step::incoming() const {
0534   return collision()->incoming(); 
0535 }
0536 
0537 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
0538 #include "Step.tcc"
0539 #endif
0540 
0541 #endif /* ThePEG_BasicStep_H */
0542 /**
0543  * Write a Step object to a stream
0544  */