Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // HPDiagram.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_HPDiagram_H
0010 #define HERWIG_HPDiagram_H
0011 //
0012 // This is the declaration of the HPDiagram struct.
0013 //
0014 
0015 #include "ThePEG/Persistency/PersistentOStream.h"
0016 #include "ThePEG/Persistency/PersistentIStream.h"
0017 #include "ThePEG/Helicity/Vertex/VertexBase.h"
0018 
0019 namespace Herwig {
0020 using namespace ThePEG;
0021 using Helicity::VertexBasePtr;
0022 
0023   /** Pair of particle ids. */
0024   typedef pair<long, long> IDPair;
0025   
0026   /** Pair of bool's*/
0027   typedef pair<bool, bool> BPair;
0028 
0029   /** Convenient typedef of VertexBasePtr */
0030   typedef VertexBasePtr VBPtr;
0031 
0032   /** Pair of VertexBasePtrs */
0033   typedef pair<VBPtr, VBPtr> VBPair;
0034   
0035   /** Pair of int,double */
0036   typedef pair<unsigned int, double> CFPair;
0037   
0038   /**
0039    * The HPDiagram struct contains information about a 2->2 hard-process that 
0040    * has been automatically generated by HardProcessConstructor.
0041    */  
0042 struct HPDiagram {
0043 
0044   /** Enumeration for channel type */
0045   enum Channel {UNDEFINED = -1, sChannel, tChannel, fourPoint};
0046 
0047   /** Standard Constructor */
0048   HPDiagram() : incoming(make_pair(0, 0)), outgoing(make_pair(0, 0)),
0049         ordered(make_pair(true,true)), channelType(UNDEFINED),
0050         colourFlow(0), ids(4, 0) {}
0051   
0052   /** Constructor taking ids as arguments.*/
0053   HPDiagram(IDPair a, IDPair b) 
0054   : incoming(a), outgoing(b), ordered(make_pair(true,true)), 
0055     channelType(UNDEFINED), colourFlow(0), ids(4, 0){
0056     ids[0] = incoming.first;
0057     ids[1] = incoming.second;
0058     ids[2] = outgoing.first;
0059     ids[3] = outgoing.second;
0060   }
0061   
0062   /** Incoming particle id's */
0063   IDPair incoming;
0064   
0065   /** Outgoing particle id's */
0066   IDPair outgoing;
0067 
0068   /** Particle ordering for t-channel diagrams */
0069   BPair ordered;
0070 
0071   /** ParticleData pointer to intermediate, null for 4-point vertices */
0072   PDPtr intermediate;
0073 
0074   /** The two vertices for the diagram */
0075   VBPair vertices;
0076   
0077   /** Enum of channel type */
0078   Channel channelType;
0079 
0080   /** Store colour flow information */
0081   vector<CFPair> colourFlow;
0082 
0083   /** Store the ids in a vector for easy use of comparison operator. */
0084   vector<long> ids;
0085 
0086   /**
0087    * Test whether this and x are the same process
0088    * @param x The other process to check
0089    */
0090   bool sameProcess(const HPDiagram & x) const  {
0091     return ( x.incoming == incoming && x.outgoing == outgoing );
0092   }
0093 };
0094 
0095   /**
0096    * Test whether two diagrams are identical.
0097    */
0098   inline bool operator==(const HPDiagram & x, const HPDiagram & y)  {
0099     // check incoming
0100     if( x.incoming != y.incoming) return false;
0101     // check type of diagram
0102     if( x.channelType != y.channelType ) return false;
0103     if( x.outgoing == y.outgoing &&
0104     x.ordered == y.ordered ) {
0105       // 4 point
0106       if(x.channelType==HPDiagram::fourPoint) {
0107     // check vertex
0108     return x.vertices.first==y.vertices.first;
0109       }
0110       // all others
0111       else {
0112     // check vertex
0113     if(x.vertices.first  != y.vertices.first ||
0114        x.vertices.second != y.vertices.second )
0115       return false;
0116     // check intermediate
0117     return x.intermediate == y.intermediate;
0118       }
0119     }
0120     //diagram is also the same if the outgoing particles are
0121     //swapped and the ordering is opposite
0122     else if( x.outgoing.first != x.outgoing.second &&
0123          y.outgoing.first != y.outgoing.second &&
0124          x.outgoing.first == y.outgoing.second && 
0125          x.outgoing.second == y.outgoing.first &&
0126             x.channelType == y.channelType) {
0127       // 4 point
0128       if(x.channelType==HPDiagram::fourPoint) {
0129     // check vertex
0130     return x.vertices.first==y.vertices.first;
0131       }
0132       // t/u channel
0133       else if(x.channelType==HPDiagram::tChannel) {
0134     // check vertex and intermediate
0135     if(x.vertices.first  == y.vertices.first  &&
0136        x.vertices.second == y.vertices.second &&
0137        x.intermediate == y.intermediate )
0138         return true;
0139     tPDPtr inter = x.intermediate;
0140     if(inter->CC()) inter = inter->CC();
0141     if(x.vertices.first  == y.vertices.second &&
0142        x.vertices.second == y.vertices.first  &&
0143        inter == y.intermediate )
0144         return true;
0145       }
0146       // s-channel
0147       else {
0148     // check vertex
0149     if(x.vertices.first  != y.vertices.first ||
0150        x.vertices.second != y.vertices.second )
0151       return false;
0152     // check intermediate
0153     return x.intermediate == y.intermediate;
0154       }
0155     }
0156     return false;
0157   }
0158   
0159   /**
0160    * Test whether one diagram is 'less' than another. Does a 
0161    * lexicographic comparison of the external states.
0162    */
0163   inline bool operator<(const HPDiagram & x, const HPDiagram & y) {
0164     for( size_t i = 0; i < 4; ++i ) {
0165       if( x.ids[i] < y.ids[i] )
0166     return true;
0167       else if( x.ids[i] > y.ids[i] )
0168     return false;
0169     }
0170     return false;
0171   }
0172   
0173   /**
0174    * Output to a stream 
0175    */
0176   inline ostream & operator<<(ostream & os, const HPDiagram & diag) {
0177     os << diag.incoming.first << " " << diag.incoming.second << " -> ";
0178     if(diag.intermediate)
0179       os << diag.intermediate->id() << " -> ";
0180     os << diag.outgoing.first << " " << diag.outgoing.second
0181        << "  channel: " << diag.channelType << "  ";
0182     if(diag.channelType == HPDiagram::tChannel)
0183       os << "ordering " << diag.ordered.first << " " 
0184      << diag.ordered.second << "  ";
0185     for(size_t cf = 0; cf < diag.colourFlow.size(); ++cf) 
0186       os << "(" << diag.colourFlow[cf].first << "," 
0187      <<diag.colourFlow[cf].second << ")";
0188     os << '\n';
0189     return os;
0190   }
0191   
0192   /** 
0193    * Output operator to allow the structure to be persistently written
0194    * @param os The output stream
0195    * @param x The HPDiagram 
0196    */
0197   inline PersistentOStream & operator<<(PersistentOStream & os, 
0198                     const HPDiagram  & x) {
0199     os << x.incoming << x.outgoing << x.ordered << x.intermediate
0200        << x.vertices << x.channelType << x.colourFlow << x.ids;
0201     return os;
0202   }
0203 
0204   /** 
0205    * Input operator to allow persistently written data to be read in
0206    * @param is The input stream
0207    * @param x The HPDiagram 
0208    */
0209   inline PersistentIStream & operator>>(PersistentIStream & is,
0210                     HPDiagram & x) {
0211     int chan = -1;
0212     is >> x.incoming >> x.outgoing >> x.ordered >> x.intermediate
0213        >> x.vertices >> chan >> x.colourFlow >> x.ids;
0214     x.channelType = HPDiagram::Channel(chan);
0215     return is;
0216   }
0217 }
0218 
0219 #endif /* HERWIG_HPDiagram_H */